/* AI Chat Styles - Pure CSS, no frameworks */

/* Mobile: prevent pull-to-refresh on the AI chat by isolating scroll to the chat pane */
@media (max-width: 767px) {
    html {
        overscroll-behavior-y: none;
    }

    body.ai-chat-route {
        overflow: hidden;
        height: 100vh;
        overscroll-behavior-y: none;
    }

    body.ai-chat-route main {
        height: 100vh;
        overflow: hidden;
    }

    body.ai-chat-route .ai-container {
        height: calc(100vh - 106px);
        overflow: hidden;
    }

    body.ai-chat-route .ai-main-content {
        height: 100%;
        overflow: hidden;
        margin-top: 0;
    }

    body.ai-chat-route .chat-actions {
        height: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
    }

    body.ai-chat-route #chat-history {
        overscroll-behavior-y: contain;
    }
}

/* Prevent body scroll on AI chat page */
body {
    overflow: visible;
    height: 100vh;
    overscroll-behavior-x: none; /* Prevent swipe-to-navigate */
    /* margin-top: 225px; */
}

/* Hide footer, social share, and disclaimer on AI page */
.social-share-container,
footer,
.disclaimer {
    display: none !important;
}

/* Prevent header from hiding on scroll on AI pages */
header.header-hidden {
    transform: translateY(0) !important;
}

/* Move header up to top when banner is hidden */
body.ai-route header { top: 0 !important; }

/* Keep breadcrumbs below the fixed header */

/* Announcements bar on AI page */
.ai-announcements {
    padding: 0 5%;
    margin-bottom: 8px;
}
.ai-announcement {
    position: relative;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 0.9rem;
    margin-bottom: 6px;
    border: 1px solid var(--color-border, #e5e7eb);
    background-color: var(--color-card-bg, #fff);
    color: var(--color-text, #111827);
}
.ai-announcement p {
    margin: 0;
    flex: 1;
}
.ai-announcement-close {
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    padding: 0 4px;
    margin-left: 8px;
    font-size: 14px;
    line-height: 1;
    border-radius: 999px;
    min-width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.ai-announcement-close:hover,
.ai-announcement-close:focus-visible {
    background-color: rgba(0,0,0,0.05);
    outline: none;
}
.ai-announcement-info { border-left: 4px solid green; }
.ai-announcement-warning { border-left: 4px solid #f59e0b; }
.ai-announcement-critical { border-left: 4px solid #dc2626; }

.ai-announcement-hidden,
.ai-announcements-hidden {
    display: none !important;
}

[data-theme="dark"] .ai-announcement {
    background-color: #0b1220;
    border-color: rgba(255,255,255,0.14);
    color: #e5e7eb;
}
[data-theme="dark"] .ai-announcement-close:hover,
[data-theme="dark"] .ai-announcement-close:focus-visible {
    background-color: rgba(255,255,255,0.08);
}

body.ai-route .ai-sidebar {
    top: 96px;
    height: calc(100vh - 96px);
}

.ai-sidebar {
    width: 280px;
    min-width: 280px;
    height: calc(100vh - 206px);
    position: fixed;
    top: 206px;
    left: 0;
    background-color: var(--color-sidebar-bg, #fafafa);
    border-right: 1px solid var(--color-border, #ddd);
    display: flex;
    flex-direction: column;
    transition: transform 0.18s ease-in-out;
    will-change: transform;
    z-index: 1100;
    overflow: visible;
}

.ai-sidebar.hidden {
    transform: translateX(-100%);
}
.ai-sidebar.open {
    transform: translateX(0);
}
.ai-sidebar.closing {
    transform: translateX(-100%) !important;
}
/* When sidebar is hidden, expand content to full width */
.ai-sidebar.hidden ~ .ai-main-content {
    margin-left: 0;
}
.ai-sidebar.hidden ~ .ai-main-content.has-messages .chat-input-area {
    left: 0;
}
/* Sidebar toggle button */
.ai-sidebar .ai-sidebar-toggle {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 44px;
    height: 44px;
    border-radius: 0px; /* Square */
    border: 1px solid var(--color-border, #e5e7eb);
    background: var(--color-card-bg, #fff);
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--color-text, #333);
    padding: 0;
    box-sizing: border-box;
    z-index: 3;
}
.ai-sidebar .ai-sidebar-toggle:hover {
    background-color: rgba(0,0,0,0.05);
    border-color: var(--color-border, #d1d5db);
}

/* Hamburger Bars Animation for buttons */
.hamburger-bar {
    display: block;
    width: 24px;
    height: 2px;
    background-color: #000;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

/* Ensure bars are white for the main site nav-toggle */
.hamburger .hamburger-bar {
    background-color: #fff;
}

/* Ensure bars are black for sidebar toggles */
.ai-sidebar-toggle .hamburger-bar,
.ai-fab-toggle .hamburger-bar,
.mobile-toggle .hamburger-bar,
.ai-bc-toggle .hamburger-bar {
    background-color: #000;
}

.ai-sidebar-toggle.active .hamburger-bar:nth-child(1),
.ai-fab-toggle.active .hamburger-bar:nth-child(1),
.ai-bc-toggle.active .hamburger-bar:nth-child(1),
.mobile-toggle.active .hamburger-bar:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
}
.ai-sidebar-toggle.active .hamburger-bar:nth-child(2),
.ai-fab-toggle.active .hamburger-bar:nth-child(2),
.ai-bc-toggle.active .hamburger-bar:nth-child(2),
.mobile-toggle.active .hamburger-bar:nth-child(2) {
    opacity: 0;
}
.ai-sidebar-toggle.active .hamburger-bar:nth-child(3),
.ai-fab-toggle.active .hamburger-bar:nth-child(3),
.ai-bc-toggle.active .hamburger-bar:nth-child(3),
.mobile-toggle.active .hamburger-bar:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
}

[data-theme="dark"] .ai-sidebar .ai-sidebar-toggle {
    background: #0b1220;
    border-color: rgba(255,255,255,0.14);
    color: #e5e7eb;
}
[data-theme="dark"] .ai-sidebar-toggle .hamburger-bar,
[data-theme="dark"] .ai-fab-toggle .hamburger-bar,
[data-theme="dark"] .mobile-toggle .hamburger-bar,
[data-theme="dark"] .ai-bc-toggle .hamburger-bar {
    background-color: #e5e7eb;
}
[data-theme="dark"] .ai-sidebar .ai-sidebar-toggle:hover {
    background-color: rgba(255,255,255,0.08);
}

#ai-sidebar-restore {
    margin-left: 10px;
}

/* Breadcrumbs-left sidebar toggle (AI page only) */
.breadcrumbs .ai-bc-toggle,
.breadcrumbs #ai-sidebar-restore {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 34px;
    height: 34px;
    border-radius: 0px; /* Square */
    border: 1px solid var(--color-border, #e5e7eb);
    background: var(--color-card-bg, #fff);
    color: var(--color-text, #333);
    padding: 0;
    margin-right: 10px;
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, transform .05s ease;
}
.breadcrumbs .ai-bc-toggle:hover,
.breadcrumbs #ai-sidebar-restore:hover {
    background-color: rgba(0,0,0,0.05);
    border-color: var(--color-border, #d1d5db);
}
.breadcrumbs .ai-bc-toggle svg,
.breadcrumbs #ai-sidebar-restore svg {
    width: 20px;
    height: 20px;
}
/* Dark */
[data-theme="dark"] .breadcrumbs .ai-bc-toggle,
[data-theme="dark"] .breadcrumbs #ai-sidebar-restore {
    background: #0b1220;
    border-color: rgba(255,255,255,0.14);
    color: #e5e7eb;
}
[data-theme="dark"] .breadcrumbs .ai-bc-toggle:hover,
[data-theme="dark"] .breadcrumbs #ai-sidebar-restore:hover {
    background-color: rgba(255,255,255,0.08);
}

/* Keep breadcrumbs (and the sidebar toggle inside it) always visible on AI page */
body.ai-route .breadcrumbs {
    position: sticky;
    top: 106px;
    z-index: 1200; /* force above sidebar/header content so toggle is never obscured */
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    padding-left: 10px; /* give room for left-side toggle */
    box-sizing: border-box;
}
body.ai-route .breadcrumbs ul { align-items: center; } /* vertical align with toggle */

.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background-color: var(--color-theme-1);
    color: white;
    border: none;
    padding: 0.5rem 0.625rem;
    cursor: pointer;
    font-size: 0.875rem;
    transition: background-color 0.2s ease;
    outline: none;
}

.new-chat-btn:hover {
    background-color: #1f2937;
}

.new-chat-btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.new-chat-btn span {
    font-weight: 400;
    white-space: nowrap;
}

/* Gallery button - secondary style (no confetti/ripple animations) */
.gallery-btn {
    background-color: transparent;
    color: var(--color-text, #333);
    /* border: 1px solid var(--color-border, #e5e7eb); */
    transition: background-color 0.15s ease, border-color 0.15s ease;
}
.gallery-btn:hover {
    background-color: rgba(0,0,0,0.03);
    border-color: var(--color-border, #d1d5db);
    transform: none;
    box-shadow: none;
}
.gallery-btn:active {
    transform: none;
}
/* Disable all confetti/ripple animations on gallery button */
.ai-sidebar .gallery-btn:hover::after,
.ai-sidebar .gallery-btn:active::before,
.ai-sidebar .gallery-btn:active::after,
.ai-sidebar .gallery-btn:focus::after,
.ai-sidebar .gallery-btn:focus-visible::after,
.ai-sidebar .gallery-btn.is-pressed::before,
.ai-sidebar .gallery-btn.is-pressed::after {
    content: none !important;
    display: none !important;
    animation: none !important;
}
.ai-sidebar .gallery-btn:hover svg {
    transform: none;
}
[data-theme="dark"] .gallery-btn {
    color: #e5e7eb;
    border-color: rgba(255,255,255,0.14);
}
[data-theme="dark"] .gallery-btn:hover {
    background-color: rgba(255,255,255,0.06);
    border-color: rgba(255,255,255,0.2);
    transform: none;
    box-shadow: none;
}

.sidebar-search {
    border-bottom: 1px solid var(--color-border, #ddd);
    background-color: var(--color-card-bg, #fff);
}

.search-input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--color-border, #ddd);
    border-radius: 0.375rem;
    font-size: 0.875rem;
}

[data-theme="dark"] .ai-sidebar .search-input {
    background-color: var(--color-search-bg, #2a2a2a);
    color: var(--color-search-text, #ffffff);
    border-color: var(--color-search-border, var(--color-border, #333));
}

[data-theme="dark"] .ai-sidebar .search-input::placeholder {
    color: rgba(229, 231, 235, 0.7);
}

.chat-nav {
    flex: 1;
    padding: 0.25rem;
    overflow-y: auto;
}

.chat-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
}
.chat-nav li {
    margin: 0 !important;
    padding: 0 !important;
    line-height: 1 !important;
}

.chat-section-header {
    padding: 0.125rem 0.5rem;
    font-size: 0.6rem;
    font-weight: 500;
    color: #6b7280;
    margin-top: 0.25rem;
    line-height: 1;
}

.chat-section-header:first-child {
    margin-top: 0;
}

.chat-item {
    position: relative;
    margin-bottom: 0;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0 0.5rem;
    color: var(--color-text, #333);
    text-decoration: none;
    border-radius: 0.5rem;
    transition: background-color 0.2s;
    overflow: visible;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.9rem;
    line-height: 1rem;
    height: 22px;
    margin-bottom: 2px;
}

.nav-link:hover {
    background-color: #f3f4f6;
}

.nav-link.active {
    background-color: #f3f4f6;
}

[data-theme="dark"] .nav-link:hover {
    background-color: #1f2937;
}

[data-theme="dark"] .nav-link.active {
    background-color: #111827;
}

[data-theme="dark"] .chat-section-header {
    color: #6b7280;
}

.folder-section {
    padding: 1rem;
}

.folder-section h3 {
    padding: 0 1rem 0.5rem;
    font-size: 1rem;
    color: var(--color-text, #333);
    border-bottom: 1px solid var(--color-border, #ddd);
    margin-bottom: 0.5rem;
}

.add-folder-btn {
    background-color: var(--color-theme-2, #2a6d8b);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    margin: 0.5rem 1rem;
    transition: background-color 0.2s;
}

.add-folder-btn:hover {
    background-color: #1e4d6a;
}

.user-auth-section {
    padding: 0.5rem;
    border-top: 1px solid var(--color-border, #ddd);
    background-color: var(--color-card-bg, #fff);
    position: relative;
    flex-shrink: 0;
}

/* Guest State - Get Started */
.auth-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.auth-btn {
    width: 100%;
    padding: 0.625rem 1rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.signup-btn {
    background-color: var(--color-theme-1, #ed7618);
    color: white;
}

.signup-btn:hover {
    background-color: #c55f0d;
}

.auth-hint {
    margin: 0.25rem 0 0;
    font-size: 0.75rem;
    color: var(--color-text-muted, #888);
    text-align: center;
}

/* Logged In State - Profile Button */
.user-profile {
    position: relative;
    display: none;
}

.user-profile.hidden {
    display: none;
}

.user-profile:not(.hidden) {
    display: block;
}

/* Row container for profile + upgrade button on right */
.user-profile .profile-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Make profile button take remaining width so Upgrade sits right */
.user-profile .profile-button {
    flex: 1;
}

.profile-button {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background-color: transparent;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background-color 0.2s;
    gap: 0.5rem;
}

.profile-button:hover {
    background-color: var(--color-theme-4, #f8f4f0);
}

[data-theme="dark"] .profile-button:hover {
    background-color: rgba(255,255,255,0.06);
}

.profile-content {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    flex: 1;
    min-width: 0;
}

.profile-avatar {
    flex-shrink: 0;
}

.profile-img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.profile-details {
    flex: 1;
    min-width: 0;
    text-align: left;
    max-width: 122px;
}

.profile-email {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text, #333);
    overflow: visible;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-tier {
    font-size: 0.75rem;
    color: var(--color-text-secondary, #666);
}

.upgrade-badge {
    flex-shrink: 0;
    padding: 5px 10px;
    background-color: var(--color-theme-1);
    border: 1px solid var(--color-border, #ddd);
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
}

.upgrade-badge:hover {
    background-color: transparent;
    border-color: var(--color-theme-1);
    color: var(--color-theme-1);
}

/* Profile Dropdown Menu */
.profile-dropdown {
    position: absolute;
    bottom: calc(100% + 0.5rem);
    left: 0.5rem;
    right: 0.5rem;
    background-color: var(--color-card-bg, #fff);
    border: 1px solid var(--color-border, #ddd);
    border-radius: 0.75rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    padding: 0.5rem;
    z-index: 1401; /* above breadcrumbs and prompts */
    display: none;
    pointer-events: auto;
}

.profile-dropdown.active {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background-color 0.2s;
    font-size: 0.875rem;
    color: var(--color-text, #333);
}

.dropdown-item:hover {
    background-color: var(--color-theme-4, #f8f4f0);
}

.dropdown-item svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.dropdown-item i {
    flex-shrink: 0;
    opacity: 0.7;
    width: 18px;
    text-align: center;
}

[data-theme="dark"] .dropdown-item {
    color: var(--color-text, #e5e7eb);
}

[data-theme="dark"] .dropdown-item:hover {
    background-color: rgba(255,255,255,0.06);
}

.dropdown-divider {
    height: 1px;
    background-color: var(--color-border, #ddd);
    margin: 0.5rem 0;
}

.ai-main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: hidden;
    margin-left: 280px;
    transition: margin-left 0.18s ease-in-out;
    height: calc(100vh - 200px);
    position: relative;
    /* margin-top: 2%; */
    margin-bottom: 5vh;
}

.chat-header {
    padding: 1rem;
    border-bottom: 1px solid var(--color-border, #ddd);
    background-color: var(--color-card-bg, #fff);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h1 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--color-text, #333);
}

.chat-actions {
    display: block;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
}

/* Hide scrollbar when not needed */
.chat-actions::-webkit-scrollbar {
    width: 8px;
}

.chat-actions::-webkit-scrollbar-track {
    background: transparent;
}

.chat-actions::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
}

.chat-actions::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

.chat-messages {
    padding: 1rem;
    background-color: var(--color-bg, #fff);
    margin-bottom: 175px;
    width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
}

#chat-history {
    max-width: 64rem;
    margin: 0 auto;
    margin-bottom: 100px;
    margin-top: 10px;
}
/* Extra bottom margin when image template strip is visible in active chat (taller input area) */
.ai-main-content.has-messages:has(.chip-row--collapsed) #chat-history {
    margin-bottom: 160px;
}

.message {
    clear: both;
}

.message strong {
    font-weight: 600; /* previously hidden; show strong text to avoid blank table cells */
}

.message.user {
    background-color: var(--color-theme-6);
    border-radius: 12px;
    padding: 1rem;
    float: right;
    max-width: 70%;
    margin-left: 20px;
    margin-right: 20px;
    display: inline-block;
    clear: both;
}

/* 2025-10-16: Attachment bubble has no background and no controls row */
.message.user.attachment { 
    background-color: transparent !important;
    padding: 0px;
    margin: 0px 20px;
 }
.message.user.attachment + .message-controls-row { display: none !important; }

.message.assistant {
    background-color: transparent;
    border-radius: 0;
    /* padding: 1rem; */
    /* float: left; */
    margin-left: 20px;
    margin-right: 20px;
    display: block;
    clear: both;
}

pre {
  background: #2d2d2d;
  color: white;
  padding: 1rem;
  border-radius: 4px;
  font-size: 0.9rem;
  overflow-x: hidden;
  line-height: 1.4;
  font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
  max-width: 100%; /* Ensure code blocks don't exceed container width */
  box-sizing: border-box; /* Include padding in width calculation */
  margin: 0px;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

[data-theme="dark"] pre {
    color: white;
}

[data-theme="dark"] .message.assistant pre {
    background-color: var(--color-code-bg);
}
  

.welcome-message {
    display: none;
}

.guest-chat-header {
    display: none;
}

/* Loading indicator styles */
.message.loading {
    padding: 1rem;
}

.loading-dots {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #9ca3af;
    animation: loading-bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes loading-bounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

.message.error {
    color: #dc3545;
    background-color: #fee;
    border-left: 4px solid #dc3545;
}

/* Markdown styling within messages */
.message.assistant h1,
.message.assistant h2,
.message.assistant h3,
.message.assistant h4,
.message.assistant h5,
.message.assistant h6 {
    margin-top: 1em;
    margin-bottom: 0.5em;
    font-weight: 600;
    line-height: 1.25;
}

.message.assistant h1 {
    font-size: 1.75em;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 0.3em;
}

.message.assistant h2 {
    font-size: 1.5em;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 0.3em;
}

.message.assistant h3 {
    font-size: 1.25em;
}

.message.assistant h4 {
    font-size: 1.1em;
}

.message.assistant h5,
.message.assistant h6 {
    font-size: 1em;
}

.message.assistant p {
    margin: 0.5em 0;
    line-height: 1.6;
}

.message.assistant ul,
.message.assistant ol {
    margin: 0.5em 0;
    padding-left: 2em;
    line-height: 1.6;
}

.message.assistant li {
    margin: 0.25em 0;
    padding: 0; /* prevent global li padding from creating large gaps */
}

.message.assistant pre {
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 1em;
    overflow: auto;           /* allow horizontal scroll instead of clipping */
    margin: 1em 0;
    position: relative;
    white-space: pre;         /* preserve formatting without wrapping */
}

.message.assistant code {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message.assistant pre code {
    background-color: transparent;
    padding: 0;
    border: none;
    white-space: pre-wrap;
}

.message.assistant :not(pre) > code {
    background-color: #f3f4f6;
    color: #111;              /* readable on light background */
    padding: 0.2em 0.4em;
    border-radius: 3px;
}

/* Dark mode for inline code (data-theme toggle) */
[data-theme="dark"] .message.assistant :not(pre) > code {
    background-color: #374151;
    color: #e5e7eb;
}

.message.assistant blockquote {
    border-left: 4px solid #e5e7eb;
    padding-left: 1em;
    margin: 1em 0;
    color: #6b7280;
    font-style: italic;
}

.message.assistant a {
    color: var(--color-theme-1, #ed7618);
    text-decoration: underline;
}

.message.assistant a:hover {
    color: #c55f0d;
}

.message.assistant table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
}

.message.assistant table th,
.message.assistant table td {
    border: 1px solid #e5e7eb;
    padding: 0.5em;
    text-align: left;
}

.message.assistant table th {
    /* background-color: #f9fafb; */
    font-weight: 600;
}

.message.assistant table tr:nth-child(even) {
    /* background-color: #f9fafb; */
}

.message.assistant strong {
    font-weight: 600;
}

.message.assistant em {
    font-style: italic;
}

.message.assistant hr {
    border: none;
    border-top: 1px solid #e5e7eb;
    margin: 1.5em 0;
}

/* Copy code button styling */
.copy-code-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    padding: 4px 8px;
    font-size: 12px;
    cursor: pointer;
    background: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.copy-code-btn:hover {
    background: #e0e0e0;
}

/* Dark mode for copy-code button independent of prefers-color-scheme */
[data-theme="dark"] .copy-code-btn {
    background: #374151;
    border-color: #4b5563;
    color: #f3f4f6;
}
[data-theme="dark"] .copy-code-btn:hover {
    background: #4b5563;
}

/* MathJax (SVG) sizing and containment — prevent giant overflow render */
.message.assistant mjx-container {
    font-size: 1.05em;          /* slightly larger to avoid cramped glyphs */
    line-height: 1.5;
    display: inline-block;
    max-width: 100%;
    overflow: visible;          /* no scrollbars inside each formula */
}
.message.assistant mjx-container[display="true"] {
    display: block;
    text-align: center;
    margin: 0.9em 0;
}

/* SVG output (v3) */
.message.assistant mjx-container[jax="SVG"] { max-width: 100%; overflow: visible; }
.message.assistant mjx-container[jax="SVG"] svg {
    display: inline-block;
    max-width: 100% !important;
    height: auto !important;
    vertical-align: middle;
}

/* CHTML output (v4 default) */
.message.assistant mjx-container[jax="CHTML"] { max-width: 100%; overflow: visible; }
.message.assistant mjx-container[jax="CHTML"] .mjx-chtml { overflow: visible; }

/* Dark theme parity */

/* Dark theme parity for MathJax */
[data-theme="dark"] .message.assistant mjx-container[jax="SVG"] svg {
    color: #e5e7eb;             /* text color for strokes/fills that inherit */
    fill: currentColor;
}

.chat-input-area {
    padding: 1rem 10%;
    background-color: transparent;
    position: absolute;
    left: 0;
    right: 0;
    top: 40%;
    transform: translateY(-50%);
    transition: none; /* snap to position when switching chats to prevent flying animation */
    z-index: 100;
}

/* When there are messages, snap to bottom */
.ai-main-content.has-messages .chat-input-area {
    position: fixed;
    bottom: 10px;
    top: auto;
    transform: none;
    left: 280px;
    right: 0;
    transition: none; 
    background: white;
}

/* Scroll to bottom button */
.scroll-to-bottom {
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    background-color: white;
    border: 1px solid #f3f4f6;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
    z-index: 20;
}

.scroll-to-bottom:hover {
    background-color: #f9fafb;
    transform: translateX(-50%) translateY(-2px);
    box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
}

.scroll-to-bottom.visible {
    display: flex;
}

.scroll-to-bottom svg {
    width: 20px;
    height: 20px;
    color: #374151;
}

.input-wrapper {
    max-width: 1152px;
    margin: 0 auto;
    padding: 0 0.625rem;
}

.input-container {
    position: relative;
    width: 100%;
}

.input-box {
    display: flex;
    flex-direction: column;
    position: relative;
    width: 100%;
    border-radius: 1.5rem;
    background-color: transparent;
    box-shadow: none;
    border: none;
    backdrop-filter: none;
    transition: none;
}

[data-theme="dark"] .input-box {
    background-color: transparent;
    border: none;
    box-shadow: none;
}

.input-box:hover {
    border-color: #e5e7eb;
}

.input-box:focus-within {
    border-color: #f3f4f6;
}

.textarea-wrapper {
    padding: 0 0.625rem;
}

#message-input {
    width: 100%;
    height: 44px;
    padding: 0.625rem 0.25rem 0 0.25rem;
    background-color: transparent;
    border: none;
    resize: none;
    font-size: 1rem;
    /* line-height: 1.5; */
    font-family: inherit;
    box-sizing: border-box;
    min-height: 44px;
    max-height: 384px;
    overflow-y: auto;
    outline: none;
    color: var(--color-text, #333);
}

#message-input::placeholder {
    color: #9ca3af;
}

.input-actions {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    margin: 0.125rem 0.125rem 0.625rem;
    width: 98%;
}

.left-actions {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0;
    margin-left: 0.25rem;
}

.right-actions {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.35rem;
    margin-right: 0.35rem;
}

.action-btn {
    background-color: transparent;
    border: 1px solid rgba(229,231,235,0.7);
    min-width: 34px;
    width: 34px;
    height: 34px;
    border-radius: 20px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
    color: #374151;
    padding: 0;
    flex-shrink: 0;
    box-sizing: border-box;
}

.action-btn:hover {
    background-color: rgba(0,0,0,0.05);
    border-color: rgba(229,231,235,1);
}

.action-btn svg {
    width: 20px;
    height: 20px;
}
/* Memory brain button: force 30x30 icon size */
#memory-brain-btn svg {
    width: 30px !important;
    height: 30px !important;
}

/* Toggled (active) state for action buttons */
.action-btn.active {
    background-color: var(--color-theme-1);
    border-color: var(--color-theme-1);
    color: #ffffff;
}
.action-btn.active svg {
    color: currentColor;
}

/* Locked state for guest users */
.action-btn.locked {
    opacity: 0.5;
    filter: grayscale(1);
    cursor: not-allowed;
}

/* Dark theme parity */
[data-theme="dark"] .action-btn.active {
    background-color: var(--color-theme-1);
    border-color: var(--color-theme-1);
    color: #0b1025; /* keep text legible inside orange – but icons inherit currentColor */
}

/* Labels hidden on desktop — shown on mobile via mobile.css */
.action-label {
    display: none;
}

.divider {
    width: 1px;
    height: 16px;
    background-color: rgba(229, 231, 235, 0.5);
    margin: 0 0.25rem;
    align-self: center;
}

.audio-btn {
    color: #4b5563;
}

.audio-btn:hover {
    color: #1f2937;
}

.audio-btn.recording {
    color: #dc3545;
    background-color: #fee;
}

.audio-btn svg {
    width: 20px;
    height: 20px;
}

.send-btn {
    background-color: var(--color-theme-1);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, transform 0.15s ease, box-shadow 0.2s, filter 0.2s;
    padding: 0;
    box-shadow: 0 2px 10px rgba(237, 118, 24, 0.45);
}

.send-btn:hover {
    background-color: var(--color-theme-1);
    filter: brightness(1.15);
    transform: scale(1.08);
    box-shadow: 0 4px 16px rgba(237, 118, 24, 0.6);
}

.send-btn:active {
    transform: scale(0.95);
}

.send-btn.streaming {
    background-color: #dc3545;
    box-shadow: 0 2px 10px rgba(220, 53, 69, 0.45);
}

.send-btn.streaming:hover {
    background-color: #c82333;
    box-shadow: 0 4px 16px rgba(220, 53, 69, 0.6);
}

.send-btn svg {
    width: 22px;
    height: 22px;
}

.attachments-menu {
    position: absolute;
    bottom: 100%;
    left: 0;
    background-color: var(--color-card-bg, #fff);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 12px;
    padding: 6px;
    margin: 0 0 8px 0;
    min-width: 200px;            /* allow smaller when content is short */
    width: fit-content;          /* shrink-wrap to content */
    max-width: 90vw;             /* never exceed viewport */
    max-height: 420px;
    overflow-y: auto;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
    backdrop-filter: blur(6px);
    z-index: 200;
    display: none;                /* controlled by JS */
    opacity: 0;                   /* animated in via .open */
    transform: translateY(6px) scale(0.98);
    transition: opacity .16s ease, transform .16s ease, box-shadow .16s ease;
    will-change: opacity, transform;
    pointer-events: none;         /* avoid click while hidden */
}
.attachments-menu.open {
    display: block;
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.attachments-menu ul {
    list-style: none;
    padding: 2px;      /* tighter */
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;          /* tighter */
}

.attachments-menu li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;            /* tighter row height */
    border-radius: 10px;
    cursor: pointer;
    color: var(--color-text, #333);
    transition: background-color .12s ease, color .12s ease, transform .04s ease;
    line-height: 1.2;
    font-size: .95rem;
}
.attachments-menu li svg {
    width: 16px;
    height: 16px;
    opacity: .75;
    flex: 0 0 auto;
}
.attachments-menu li span {
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;          /* prevent label wrapping that widens menu */
}
.attachments-menu li:hover {
    background-color: rgba(0,0,0,0.05);
    color: var(--color-text, #111);
}
.attachments-menu li:active {
    transform: scale(0.995);
}


/* 2025-11-20: Removed prefers-color-scheme dark block; dark theme is controlled via [data-theme="dark"] and darkmode.css */
/* 2025-10-02: Fix long messages wrapping inside bubbles */
.message.user,
.message.assistant {       /* preserve newlines + wrap */
    overflow-wrap: anywhere;      /* break long unbroken strings */
    word-wrap: break-word;        /* legacy support */
    word-break: break-word;       /* ensure break on very long tokens */
}

/* Extra safety at container level */

/* Sidebar chat item formatting to match reference */

/* Visual trailing options (three dots) */


/* Reference-like item styling */
.chat-nav .__menu-item {
    position: relative; /* ensure trailing controls layer correctly */
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 2px 8px;
    min-height: 26px;
    border-radius: 8px;
    color: var(--color-text, #333);
    text-decoration: none;
    overflow: visible;
    font-size: 0.9rem;          /* override global nav a */
    letter-spacing: normal;     /* override global nav a */
}

.chat-nav .__menu-item:hover,
.chat-nav .__menu-item.active {
    background-color: #f3f4f6;
}

[data-theme="dark"] .chat-nav .__menu-item:hover,
[data-theme="dark"] .chat-nav .__menu-item.active {
    background-color: #1f2937;
}

/* Title truncation */
.chat-nav .__menu-item .truncate {
    flex: 1;
    min-width: 0;
}

.chat-nav .__menu-item .truncate span {
    display: inline-block;
    max-width: 100%;
    overflow: visible;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Trailing pair (options) */
.chat-nav .trailing-pair {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    opacity: 0.7;
    z-index: 2;
}

.chat-nav .__menu-item:hover .trailing-pair {
    opacity: 1;
}

.chat-nav .__menu-item-trailing-btn {
    border: none;
    background: transparent;
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    cursor: pointer;
    color: inherit;
    position: relative;
    z-index: 3;
}

.chat-nav .__menu-item-trailing-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .chat-nav .__menu-item-trailing-btn:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

/* Tertiary text color */
.chat-nav .text-token-text-tertiary {
    color: #6b7280;
}

[data-theme="dark"] .chat-nav .text-token-text-tertiary {
    color: #9ca3af;
}

/* Utility equivalents for structural classes within chat-nav (tailwind-like) */
.chat-nav .flex { display: flex; }
.chat-nav .items-center { align-items: center; }
.chat-nav .min-w-0 { min-width: 0; }
.chat-nav .grow { flex-grow: 1; }
/* Escape dot in class name */
.chat-nav .gap-2\.5 { gap: 0.625rem; } /* 10px */
.chat-nav .group { /* noop for parity */ }
.chat-nav .hoverable { /* noop for parity */ }

/* 2025-10-02: Voice recording overlay (MediaRecorder UI) */

.voice-overlay {
    position: relative;
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem;
    border-radius: 28px;
    background-color: rgba(99, 102, 241, 0.08); /* indigo-ish */
    border: 1px solid rgba(99, 102, 241, 0.25);
    width: 100%;
    box-sizing: border-box;
    min-height: 44px;
}

.input-box.recording-active .voice-overlay { display: flex; }
.input-box.recording-active .input-group { display: none; }
.input-box.recording-active .textarea-wrapper { display: none; }
.input-box.recording-active .query-bar { display: none; }

.voice-overlay .vo-left,
.voice-overlay .vo-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 0 0 auto;
}

.voice-overlay .vo-middle {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 26px;
    overflow: visible;
    margin: 0 0.25rem;
}

.voice-overlay .vo-wave {
    display: flex;
    align-items: center;
    height: 100%;
    width: 100%;
    gap: 2px;
}

.voice-overlay .vo-slot {
    display: flex;
    align-items: center;
    height: 100%;
}

.voice-overlay .vo-bar {
    width: 2px;
    height: 14%;
    background-color: #6366f1; /* indigo-500 */
    display: inline-block;
    border-radius: 1px;
    transition: height 60ms linear;
}

.voice-overlay .vo-duration {
    font-size: 0.875rem;
    color: #6366f1;
    font-weight: 500;
    min-width: 42px;
    text-align: center;
}

.vo-cancel,
.vo-accept {
    background: rgba(99, 102, 241, 0.2);
    color: #4338ca;
    border: 0;
    border-radius: 9999px;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.vo-accept {
    background: #6366f1;
    color: white;
}

/* Processing state for accept button (spinner + disabled cursor) */
.vo-accept.processing,
.vo-accept[disabled] {
    position: relative;
    cursor: not-allowed;
    opacity: 0.85;
}

.vo-accept.processing svg {
    opacity: 0;
}

.vo-accept.processing::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.55);
    border-top-color: rgba(255,255,255,1);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    animation: dcspin-center 0.8s linear infinite;
}

/* Keep spinner centered while rotating (combine translate + rotate) */
@keyframes dcspin-center {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to   { transform: translate(-50%, -50%) rotate(360deg); }
}

.vo-cancel svg,
.vo-accept svg {
    width: 16px;
    height: 16px;
}

[data-theme="dark"] .voice-overlay {
    background-color: rgba(99, 102, 241, 0.08);
    border-color: rgba(99, 102, 241, 0.3);
}

[data-theme="dark"] .vo-bar {
    background-color: #818cf8; /* indigo-400 */
}

[data-theme="dark"] .vo-duration {
    color: #a5b4fc; /* indigo-300 */
}

[data-theme="dark"] .vo-cancel {
    background: rgba(99, 102, 241, 0.18);
    color: #c7d2fe;
}

[data-theme="dark"] .vo-accept {
    background: #6366f1;
    color: #0b1025;
}

/* Attachments strip (dropped/uploaded files) */
.attachments-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0px 8px;
}

/* Individual attachment card */
.attachment-card {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    border: 1px solid #eaeaea;
    border-radius: 12px;
    padding: 8px 12px;
    min-width: 180px;
    max-width: 300px;
    text-align: left;
    cursor: default;
    margin: 10px 0 5px;
}

.attachment-card.loading { opacity: 0.9; }
.attachment-card.error { border-color: #dc3545; }

.attachment-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.attachment-icon svg {
    width: 24px;
    height: 24px;
}

.attachment-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.attachment-name {
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Image attachment card — compact square thumbnail */
.attachment-card.attachment-card--image {
    width: 80px;
    height: 80px;
    min-width: 80px;
    max-width: 80px;
    padding: 0;
    overflow: hidden;
}
.attachment-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 11px;
}
.attachment-card--image .attachment-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    z-index: 2;
}
.attachment-card--image .attachment-remove button {
    width: 20px;
    height: 20px;
    background: rgba(0,0,0,0.55);
    color: #fff;
    border: none;
    backdrop-filter: blur(4px);
}
.attachment-card--image .attachment-remove button:hover {
    background: rgba(0,0,0,0.75);
}
.attachment-card--image .attachment-spinner {
    right: -4px;
    top: -4px;
}

.attachment-remove button {
    background: #fff;
    color: #111;
    border: 1px solid #eee;
    border-radius: 9999px;
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.attachment-remove button:hover { background: #f3f4f6; }

/* Dark mode for attachments */
[data-theme="dark"] .attachment-card {
    background: #0b1220;
    border-color: rgba(255,255,255,0.14);
    color: #e5e7eb;
}
[data-theme="dark"] .attachment-name { color: #e5e7eb; }
[data-theme="dark"] .attachment-card--image .attachment-remove button {
    background: rgba(255,255,255,0.25);
    color: #fff;
}
[data-theme="dark"] .attachment-card--image .attachment-remove button:hover {
    background: rgba(255,255,255,0.4);
}
[data-theme="dark"] .attachment-remove button {
    background: #0b1220;
    color: #e5e7eb;
    border-color: rgba(255,255,255,0.14);
}
[data-theme="dark"] .attachment-remove button:hover {
    background: rgba(255,255,255,0.08);
}
[data-theme="dark"] .attachment-spinner {
    border-color: rgba(255,255,255,0.18);
    border-top-color: var(--color-theme-1, #ed7618);
}

.attachment-spinner {
    position: absolute;
    right: -6px;
    top: -6px;
    width: 14px;
    height: 14px;
    border: 2px solid #ddd;
    border-top-color: var(--color-theme-1, #ed7618);
    border-radius: 50%;
    animation: dcspin 0.8s linear infinite;
}

@keyframes dcspin { to { transform: rotate(360deg); } }

/* Drag-over highlight on input box */
.input-box.drag-over {
    border-color: var(--color-theme-1, #ed7618);
    box-shadow: 0 0 0 3px rgba(237,118,24,0.15);
}

/* 2025-10-02: AI sidebar font override and actions menu */
.ai-sidebar .chat-nav a,
.ai-sidebar .chat-nav .__menu-item {
    font-size: 0.9rem !important;
    letter-spacing: normal !important;
    font-weight: 400;
}

/* Keep trailing "..." visible and clickable */

/* Context menu (rename/delete) */
.chat-nav .context-menu {
    position: absolute;
    right: 6px;
    top: calc(100% + 6px); /* appear below the trailing button */
    transform: none;
    background-color: var(--color-card-bg, #fff);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.12);
    padding: 4px 0;
    min-width: 140px;
    z-index: 1000;
}

.chat-nav .context-menu button {
    display: block;
    width: 100%;
    background: transparent;
    border: 0;
    padding: 8px 12px;
    text-align: left;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--color-text, #333);
}

.chat-nav .context-menu button:hover { background: #f3f4f6; }

[data-theme="dark"] .chat-nav .context-menu {
    background: #2a2a2a;
    border-color: #4b5563;
}

[data-theme="dark"] .chat-nav .context-menu button { color: #e5e7eb; }

[data-theme="dark"] .chat-nav .context-menu button:hover { background: #374151; }

/* 2025-10-02: User message controls (edit/copy) and inline editor */
.message.user .message-content {
    white-space: pre-wrap;
}
.message-controls {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    margin-top: 6px;
    opacity: 0;
    transition: opacity 0.15s ease-in-out;
}
.message.user:hover .message-controls,
.message.user.editing .message-controls {
    opacity: 1;
}
.message-controls .msg-ctrl {
    background: transparent;
    border: 0;
    padding: 6px;
    border-radius: 8px;
    color: #6b7280;
    cursor: pointer;
}
.message-controls .msg-ctrl:hover {
    background: rgba(0,0,0,0.05);
}
[data-theme="dark"] .message-controls .msg-ctrl:hover {
    background: rgba(255,255,255,0.08);
}
.message-edit {
    margin-top: 8px;
}
.message-edit-textarea {
    width: 100%;
    min-height: 44px;
    max-height: 384px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 8px;
    resize: vertical;
    box-sizing: border-box;
    font: inherit;
    background: #fff;
    color: var(--color-text,#333);
}
.message-edit-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 6px;
}
.message-edit-actions .btn {
    background: #fff;
    color: var(--color-text,#333);
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
}
.message-edit-actions .btn.save {
    background: var(--color-theme-1,#ed7618);
    color: #fff;
    border-color: var(--color-theme-1,#ed7618);
}
[data-theme="dark"] .message-edit-textarea {
    background: #1f2937;
    color: #e5e7eb;
    border-color: #374151;
}
[data-theme="dark"] .message-edit-actions .btn {
    background: #2a2a2a;
    color: #e5e7eb;
    border-color: #4b5563;
}
[data-theme="dark"] .message-edit-actions .btn.save {
    color: #0b1025;
}

/* 2025-10-02: Controls row beneath user bubble (outside bubble background) */
.message-controls-row {
    clear: both;
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    margin: 4px 5% 2px 5%;
    opacity: 1;
    transition: opacity 0.15s ease-in-out;
}
/* always visible */
.message-controls-row .msg-ctrl {
    background: transparent;
    border: 0;
    padding: 6px;
    border-radius: 8px;
    color: #6b7280;
    cursor: pointer;
}
.message-controls-row .msg-ctrl:hover {
    background: rgba(0,0,0,0.05);
}
[data-theme="dark"] .message-controls-row .msg-ctrl:hover {
    background: rgba(255,255,255,0.08);
}

/* Copied badge feedback */
.copied-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 8px;
    border-radius: 9999px;
    font-size: 12px;
    line-height: 1.2;
    color: #111827;
    background: #E5E7EB;
    transition: opacity 0.3s ease;
}
.copied-badge.fade { opacity: 0.0; }

/* 2025-10-02: Full-width edit card below message */
.message-edit-row {
    margin: 6px 5% 8px 5%;
    clear: both;
}
.message-edit-row .edit-card {
    background: var(--color-card-bg, #fff);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 1.5rem; /* rounded-3xl feel */
    padding: 0.75rem 1.25rem; /* px-5 py-3 */
}
.message-edit-row .edit-scroll {
    max-height: 24rem; /* ~max-h-96 */
    overflow: auto;
}
.message-edit-row .message-edit-textarea {
    background: transparent;
    outline: none;
    width: 100%;
    resize: none;
}
.message-edit-actions-split {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
}
.message-edit-actions-split .left,
.message-edit-actions-split .right {
    display: flex;
    align-items: center;
    gap: 0.375rem; /* ~space-x-1.5 */
}
.message-edit-actions-split .btn {
    padding: 0.375rem 0.875rem; /* px-3.5 py-1.5 */
    border-radius: 9999px;
    border: 1px solid #f3f4f6;
    background: #fff;
    color: #111827;
}
.message-edit-actions-split .btn:hover {
    background: #f3f4f6;
}
[data-theme="dark"] .message-edit-row .edit-card {
    background: #1f2937; /* dark:bg-gray-800-ish */
    border-color: #374151;
}
[data-theme="dark"] .message-edit-actions-split .btn {
    background: #111827; /* dark:bg-gray-900 */
    color: #e5e7eb;
    border-color: #374151;
}
/* 2025-10-02: Placement/visibility fixes for user controls and editor */

/* Hide original bubble and its control row while editing */
.message.user.editing { display: none !important; }
.message.user.editing + .message-controls-row { display: none !important; }

/* Full-width editor card alignment and float clearing */

/* Match Send color/hover with main Send button */
.message-edit-actions-split .btn.send {
    background-color: var(--color-theme-1, #ed7618);
    color: #fff;
    border: none;
}
.message-edit-actions-split .btn.send:hover {
    background-color: #1f2937;
    color: #fff;
}

/* Dark mode parity with .send-btn */
[data-theme="dark"] .message-edit-actions-split .btn.send {
    background-color: #ffffff;
    color: #000000;
    border: none;
}
[data-theme="dark"] .message-edit-actions-split .btn.send:hover {
    background-color: #f3f4f6;
    color: #000000;
}
/* 2025-10-02: Assistant controls bar under assistant messages */
.assistant-controls-row {
    display: flex;
    gap: 6px;
    justify-content: flex-start;
    margin: 4px 5% 2px 5%;
    opacity: 1;
    transition: opacity 0.15s ease-in-out;
}
/* always visible */
.ac-btn {
    background: transparent;
    border: 0;
    padding: 6px;
    border-radius: 8px;
    color: #6b7280;
    cursor: pointer;
}
.ac-btn:hover {
    background: rgba(0,0,0,0.05);
}
[data-theme="dark"] .ac-btn:hover {
    background: rgba(255,255,255,0.08);
}
.ac-btn.speaking {
    color: var(--color-theme-1, #ed7618);
}

/* Lock entire assistant controls row for guests */
.assistant-controls-row.locked .ac-btn {
    opacity: 0.5;
    filter: grayscale(1);
    cursor: not-allowed;
}

/* Assistant report panel under assistant messages */
.assistant-report-panel {
    margin: 8px 5% 12px 5%;
    padding: 16px;
    border-radius: 12px;
    background: var(--color-card-bg, #fff);
    border: 1px solid var(--color-border, #e5e7eb);
    font-size: 0.9rem;
    color: var(--color-text, #111827);
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    animation: dc-fade-in-up 0.2s ease-out;
}

.report-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--color-text, #374151);
}

.report-select {
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--color-border, #d1d5db);
    background: var(--color-card-bg, #fff);
    color: var(--color-text, #111827);
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
    transition: border-color 0.15s;
}
.report-select:hover {
    border-color: var(--color-text-secondary, #9ca3af);
}

.report-comment {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--color-border, #d1d5db);
    border-radius: 8px;
    background: #f9fafb;
    color: var(--color-text, #111827);
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
    box-sizing: border-box;
    outline: none;
    min-height: 80px;
    transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
}
.report-comment:focus {
    border-color: var(--color-theme-1, #ed7618);
    background: var(--color-card-bg, #fff);
    box-shadow: 0 0 0 3px rgba(237,118,24,0.1);
}

.report-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    align-items: center;
}

.assistant-report-panel .btn {
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--color-border, #e5e7eb);
    background: #fff;
    color: #374151;
    transition: all 0.15s ease;
}
.assistant-report-panel .btn:hover {
    background: #f3f4f6;
    border-color: #d1d5db;
    transform: translateY(-1px);
}

.assistant-report-panel .submit-btn {
    background: var(--color-theme-1, #ed7618);
    border-color: var(--color-theme-1, #ed7618);
    color: #fff;
    box-shadow: 0 2px 4px rgba(237,118,24,0.2);
}
.assistant-report-panel .submit-btn:hover {
    background: #d86b11;
    border-color: #d86b11;
    box-shadow: 0 4px 6px rgba(237,118,24,0.25);
    color: #fff;
}

.assistant-report-status {
    font-size: 0.8rem;
    color: #6b7280;
    min-height: 1.2em;
    margin-top: -4px;
}

@keyframes dc-fade-in-up {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

[data-theme="dark"] .assistant-report-panel {
    background: #1f2937;
    border-color: #374151;
    color: #e5e7eb;
}
[data-theme="dark"] .report-label {
    color: #e5e7eb;
}
[data-theme="dark"] .report-select {
    background: #111827;
    border-color: #4b5563;
    color: #e5e7eb;
}
[data-theme="dark"] .report-select:hover {
    border-color: #6b7280;
}
[data-theme="dark"] .report-comment {
    background: #111827;
    border-color: #374151;
    color: #e5e7eb;
}
[data-theme="dark"] .report-comment:focus {
    border-color: var(--color-theme-1, #ed7618);
    background: #0b1025;
}
[data-theme="dark"] .assistant-report-panel .btn {
    background: #374151;
    border-color: #4b5563;
    color: #e5e7eb;
}
[data-theme="dark"] .assistant-report-panel .btn:hover {
    background: #4b5563;
    border-color: #6b7280;
}
[data-theme="dark"] .assistant-report-panel .submit-btn {
    background: var(--color-theme-1, #ed7618);
    border-color: var(--color-theme-1, #ed7618);
    color: #fff;
}
[data-theme="dark"] .assistant-report-panel .submit-btn:hover {
    background: #d86b11;
}
[data-theme="dark"] .assistant-report-status {
    color: #9ca3af;
}

/* 2026-02: Follow-up question suggestions */
.followup-questions-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
    margin: 8px 5% 12px 5%;
    animation: dc-fade-in-up 0.25s ease-out;
}
.followup-questions-row.loading {
    opacity: 0.6;
}
.followup-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 18px;
    border: 1px solid var(--color-border, #e5e7eb);
    background: var(--color-card-bg, #fff);
    color: var(--color-text, #374151);
    font-size: 0.875rem;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s, box-shadow 0.15s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    max-width: 100%;
    text-align: left;
    white-space: normal;
    line-height: 1.4;
}
.followup-btn:hover {
    background: #f9fafb;
    border-color: var(--color-theme-1, #ed7618);
    box-shadow: 0 2px 6px rgba(237,118,24,0.12);
}
.followup-btn:active {
    transform: scale(0.98);
}
.followup-btn svg {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    color: var(--color-theme-1, #ed7618);
}
.followup-btn-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Loading skeleton placeholders */
.followup-btn.skeleton {
    width: 180px;
    height: 36px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: followup-shimmer 1.5s infinite;
    border-color: transparent;
    pointer-events: none;
}
@keyframes followup-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
/* Dark mode styles */
[data-theme="dark"] .followup-btn {
    background: #1f2937;
    border-color: #374151;
    color: #e5e7eb;
}
[data-theme="dark"] .followup-btn:hover {
    background: #374151;
    border-color: var(--color-theme-1, #ed7618);
}
[data-theme="dark"] .followup-btn.skeleton {
    background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
    background-size: 200% 100%;
    animation: followup-shimmer 1.5s infinite;
}
/* Hide follow-ups for guests */
.followup-questions-row.locked {
    display: none;
}

/* Guest auth prompt — card redesign */
@keyframes guestCardSlideUp {
    from { opacity: 0; transform: translateY(40px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
.guest-auth-prompt {
    position: fixed;
    inset: 0;
    left: 280px;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    pointer-events: auto;
}
.guest-auth-card {
    position: relative;
    width: 100%;
    max-width: 420px;
    background: var(--color-card-bg, #fff);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 24px;
    padding: 32px 28px 24px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.12), 0 4px 16px rgba(0,0,0,0.06);
    animation: guestCardSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    text-align: center;
}
.guest-auth-header { margin-bottom: 20px; }
.guest-auth-logo {
    width: 56px;
    height: 56px;
    margin: 0 auto 12px;
    border-radius: 16px;
    object-fit: contain;
}
.guest-auth-header h2 {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--color-text, #111);
    margin: 0 0 6px;
}
.guest-auth-header p {
    font-size: 0.92rem;
    color: var(--color-text, #111);
    opacity: 0.7;
    margin: 0;
    line-height: 1.4;
}
/* Feature highlights grid */
.guest-auth-features {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
}
.guest-auth-feature {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 12px;
    background: var(--color-sidebar-bg, #fafafa);
    font-size: 0.82rem;
    color: var(--color-text, #111);
    text-align: left;
}
.guest-auth-feature svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: var(--color-theme-1, #ed7618);
}
/* CTA section */
.guest-auth-cta-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}
#guest-google-signin-btn {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.guest-auth-or-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 80%;
    font-size: 0.78rem;
    color: var(--color-text, #111);
    opacity: 0.5;
}
.guest-auth-or-divider::before,
.guest-auth-or-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--color-border, #ddd);
}
.guest-auth-email-btn {
    width: 100%;
    max-width: 300px;
    padding: 10px 20px;
    border-radius: 9999px;
    background: var(--color-theme-1, #ed7618);
    color: #fff;
    font-size: 0.92rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: opacity 0.15s ease;
}
.guest-auth-email-btn:hover { opacity: 0.9; }
.guest-auth-hint {
    margin: 0.5rem 0 0;
    font-size: 0.8rem;
    color: var(--color-text-muted, #888);
    text-align: center;
}
/* Australian badge */
.guest-auth-aus-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 16px;
    font-size: 0.75rem;
    color: var(--color-text, #111);
    opacity: 0.55;
}
/* Dark mode overrides */
[data-theme="dark"] .guest-auth-card {
    box-shadow: 0 20px 60px rgba(0,0,0,0.4), 0 4px 16px rgba(0,0,0,0.25);
}
[data-theme="dark"] .guest-auth-feature {
    background: rgba(255, 255, 255, 0.06);
}

/* Sidebar visual improvements (New Chat downwards) - 2025-10-03 */
.ai-sidebar .new-chat-btn:hover {
    background-color: #d86b1188;
}
.ai-sidebar .new-chat-btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.ai-sidebar .new-chat-btn span { font-weight: 600; white-space: nowrap; overflow: visible; text-overflow: ellipsis; }


/* Chat list */
.ai-sidebar .chat-nav li { margin: 6px 0; }




/* Folder section tweak */
.ai-sidebar .folder-section { padding: 12px; margin-top: 8px; border-top: 1px solid rgba(0,0,0,0.04); }
.ai-sidebar .folder-section h3 { margin:0 0 8px 0; font-size:0.95rem; font-weight:700; color:var(--color-text); border-bottom:none; padding-bottom:0; }
.ai-sidebar .add-folder-btn:hover {
    background: rgba(42,109,139,0.06);
    border-color: rgba(42,109,139,0.14);
    transform: translateY(-1px);
}

/* Keep room for the auth/footer area so the last chat isn't hidden */
.ai-sidebar .chat-nav {
    padding: 8px 8px 120px 8px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    position: relative;
    overflow-x: hidden;
}








/* Add-folder button adjustments to match the new look */
.ai-sidebar .add-folder-btn {
    width: calc(100% - 24px);
    margin: 8px 12px 12px 12px;
    padding: 10px;
    border-radius: 10px;
    background: transparent;
    border: 1px dashed rgba(0,0,0,0.06);
    color: var(--color-theme-2, #2a6d8b);
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* Search adjustments (icon position + input sizing) */
.ai-sidebar .sidebar-search {
    padding: 12px 12px 12px 12px;
    background: transparent;
    position: relative;
}

.ai-sidebar .new-chat-btn {
    padding: 0.62rem 0.9rem;
    font-size: 1rem;
    font-weight: 700;
    border-left: 3px solid rgba(237,118,24,0.7);
}

/* Compact and breathing space for list items */
.ai-sidebar .chat-nav .__menu-item {
    position: relative;
    transform-origin: left center;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 34px;
    border-radius: 10px;
    background: transparent;
    color: var(--color-text, #333);
    text-decoration: none;
    overflow: visible;
    font-size: 0.95rem;
    transition: background-color 0.12s ease, transform 0.08s ease, box-shadow 0.12s;
    border: 1px solid transparent;
    padding-right: 260px !important;
    transform: none !important;
}
.ai-sidebar .chat-nav .__menu-item + .__menu-item {
    margin-top: 8px;
}

/* Subtle hover card */
.ai-sidebar .chat-nav .__menu-item:hover {
    background: rgba(237,118,24,0.03);
    border-color: rgba(0,0,0,0.03);
    box-shadow: none;
}

/* Title typography + truncation */
.ai-sidebar .chat-nav .__menu-item .truncate span {
    color: #111827;
    line-height: 1.2;
    display: inline-block;
    max-width: calc(100% - 5px);
    vertical-align: middle;
}
[data-theme="dark"] .ai-sidebar .chat-nav .__menu-item .truncate span {
    color: #e5e7eb;
    font-weight: 500;
}

/* Trailing controls */

/* Muted tertiary text */
.ai-sidebar .chat-nav .trailing { color: #9ca3af; font-size: 0.95rem; }


/* Bottom fade so the auth/profile area reads comfortably */
.ai-sidebar::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(56px + 8px);
    height: 64px;
    pointer-events: none;
    background: linear-gradient(to bottom, rgba(255,255,255,0), var(--color-sidebar-bg, #fafafa));
}
[data-theme="dark"] .ai-sidebar::after {
    background: linear-gradient(to bottom, rgba(0,0,0,0), #0b1220);
}

/* Section headers */
.ai-sidebar .chat-section-header {
    color: #9aa0a6;
    font-weight: 700;
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    margin-top: 12px;
    margin-bottom: 8px;
    padding-left: 18px;
    padding-top: 10px;
    padding-bottom: 6px;
}

/* Active indicator (left accent) */
.ai-sidebar .chat-nav .__menu-item.active {
    background-color: rgba(237,118,24,0.06);
    border-color: transparent;
}
.ai-sidebar .chat-nav .__menu-item.active::before {
    content: "";
    position: absolute;
    left: 2px;
    top: 8px;
    bottom: 8px;
    width: 4px;
    border-radius: 6px;
    background: var(--color-theme-1);
    animation: dc-activePulse 2.2s ease-in-out infinite;
}


/* Search input subtle focus */
.ai-sidebar .search-input {
    transition: box-shadow 0.18s ease, border-color 0.12s ease;
}
.ai-sidebar .search-input:focus {
    border-color: var(--color-theme-1);
    box-shadow: 0 8px 24px rgba(237,118,24,0.06);
    animation: dc-focusBreathe 1.4s ease-out 1;
}

/* Thin subtle scrollbar for the list */
.ai-sidebar .chat-nav::-webkit-scrollbar { width: 8px; }
.ai-sidebar .chat-nav::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.05); border-radius: 8px; }
[data-theme="dark"] .ai-sidebar .chat-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.04); }

/* Keyboard focus visibility for accessibility */
.ai-sidebar .chat-nav .__menu-item:focus,
.ai-sidebar .chat-nav .__menu-item:focus-within {
    outline: none;
    background-color: rgba(0,0,0,0.06);
    transition: background-color 150ms ease;
}
[data-theme="dark"] .ai-sidebar .chat-nav .__menu-item:focus,
[data-theme="dark"] .ai-sidebar .chat-nav .__menu-item:focus-within {
    background-color: rgba(255,255,255,0.08);
}

/* Inline rename input styling */
.ai-sidebar .chat-nav .rename-input {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 8px;
    padding: 6px 8px;
    font: inherit;
    color: inherit;
    background: var(--color-card-bg, #fff);
}
[data-theme="dark"] .ai-sidebar .chat-nav .rename-input {
    background: #0b1220;
    border-color: #374151;
    color: #e5e7eb;
}

/* When renaming, remove the excessive padding-right so input can expand */
.ai-sidebar .chat-nav li.chat-item.renaming .__menu-item {
    padding-right: 8px !important;
}
.ai-sidebar .chat-nav li.chat-item.renaming .trailing-pair {
    display: none !important;
}

/* Remove emoji-style first-letter sizing for titles to keep text consistent */
.ai-sidebar .chat-nav .__menu-item .truncate span::first-letter {
    font-size: inherit !important;
    margin-right: 0 !important;
}
/* === Sidebar FUN pack (2025-10-03) ===
   Playful micro-interactions for the AI sidebar
   NOTE: Does NOT modify .sidebar-header or .user-auth-section
*/

/* New Chat: icon wiggle on hover + press colour fade */
.ai-sidebar .new-chat-btn:hover svg {
    transform: rotate(-6deg) scale(1.05);
    transition: transform 160ms ease;
}
.ai-sidebar .new-chat-btn:active {
    background-color: rgba(237,118,24,0.35);
    transition: background-color 120ms ease;
}

/* Confetti burst on press/focus (CSS-only) — no central fill to avoid blob */
.vo-accept:active::before,
.vo-accept:focus::before,
.vo-accept:focus-visible::before,
.vo-accept.is-pressed::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 6px;
    height: 6px;
    background: transparent; /* avoid central blob */
    border-radius: 1px;
    transform: translate(-50%, -50%);
    animation: dc-confettiBurst 600ms ease-out forwards;
    pointer-events: none;
    will-change: transform, opacity;
    /* multiple colored pieces via box-shadows */
    box-shadow:
      0 -10px 0 0 #FFD166,
      8px -6px 0 0 #06D6A0,
      12px  4px 0 0 #118AB2,
      0  10px 0 0 #EF476F,
      -12px 4px 0 0 #FCA311,
      -8px -6px 0 0 #2A9D8F,
      14px 0 0 0 #8E44AD,
      -14px 0 0 0 #F39C12;
}


/* Chat items: no movement on hover */

.ai-sidebar .chat-nav .__menu-item:active {
    transform: none;
}



/* Trailing action buttons: micro-lift on hover */
.ai-sidebar .chat-nav .__menu-item .__menu-item-trailing-btn {
    transition: transform 120ms ease, background-color 120ms ease, opacity 120ms ease;
}
.ai-sidebar .chat-nav .__menu-item .__menu-item-trailing-btn:hover {
    transform: translateY(-1px);
}



/* Keyframes */
@keyframes dc-confettiBurst {
    0%   { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(12); opacity: 0; }
}
@keyframes dc-sparkle {
    0%   { transform: translateY(-50%) scale(0.85) rotate(0deg);   opacity: 0.6; }
    50%  { transform: translateY(-50%) scale(1.05) rotate(180deg); opacity: 1; }
    100% { transform: translateY(-50%) scale(0.85) rotate(360deg); opacity: 0.6; }
}
@keyframes dc-activePulse {
    0%,100% { width: 4px;  opacity: 0.95; }
    50%     { width: 6px;  opacity: 1; }
}
@keyframes dc-focusBreathe {
    0%   { box-shadow: 0 0 0 0 rgba(237,118,24,0.12); }
    70%  { box-shadow: 0 0 0 8px rgba(237,118,24,0.06); }
    100% { box-shadow: 0 0 0 0 rgba(237,118,24,0.00); }
}

/* Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    /* Allow subtle ring animation; disable others */
    .ai-sidebar .chat-nav .__menu-item:hover,
    .ai-sidebar .chat-nav .__menu-item:hover::after,
    .ai-sidebar .chat-nav .__menu-item.active::before,
    .ai-sidebar .search-input:focus {
        animation: none !important;
        transition: none !important;
    }
}
/* === FUN pack precedence overrides (keep at end) === */
/* === Trailing button rework (always visible, right-fixed square) — 2025-10-03 === */

/* Pin trailing controls to the right, always visible */
.ai-sidebar .chat-nav .trailing-pair {
    position: absolute !important;
    right: 10px;
    top: 50%;
    transform: translateY(-50%) !important;
    opacity: 1 !important;
    gap: 0 !important;
    z-index: 3;
}

/* Square ... button */

/* Force visible centered ellipsis without relying on inner markup */


/* Dark mode */
[data-theme="dark"] .ai-sidebar .chat-nav .__menu-item-trailing-btn {
    background: #0b1220;
    border-color: rgba(255,255,255,0.14);
    color: #e5e7eb;
}
[data-theme="dark"] .ai-sidebar .chat-nav .__menu-item-trailing-btn:hover {
    background-color: rgba(255,255,255,0.08);
}

/* Ensure any previous "hide until hover" rules are neutralized */
.ai-sidebar .chat-nav .__menu-item:hover .trailing-pair { opacity: 1 !important; transform: translateY(-50%) !important; }
/* === Trailing button static + single ellipsis fix — 2025-10-03 === */

/* 1) No tilt/movement on chat items */
@media (hover: hover) and (pointer: fine) {
  .ai-sidebar .chat-nav .__menu-item:hover { transform: none !important; }
  .ai-sidebar .chat-nav .__menu-item:hover .truncate {
      transform: none;
  }
}



/* === Finalize trailing button: static + single glyph — 2025-10-03 === */
/* Hide any inner text/content to prevent double ellipsis */

/* Render our single centered ellipsis */

/* Ensure item hover never moves the trailing area */

/* === Trailing menu final lock — single, static, right-fixed (2025-10-03 C) === */

/* Show only one trailing button even if multiple are rendered */
.ai-sidebar .chat-nav .trailing-pair > *:not(:first-child) {
    display: none !important;
}

/* Keep trailing group pinned and immune to item hover effects */

/* Single centered ellipsis inside a square; hide any inner markup to avoid doubles */
.ai-sidebar .chat-nav .__menu-item-trailing-btn {
    width: 32px; height: 32px;
    border-radius: 8px;
    border: 1px solid var(--color-border, #e5e7eb);
    background: var(--color-card-bg, #fff);
    color: var(--color-text, #333);
    display: inline-flex; align-items: center; justify-content: center;
    box-sizing: border-box;
    cursor: pointer;
    font-size: 0 !important;   /* hide inner "..." or svg to prevent duplicates */
    line-height: 0 !important;
    transform: none !important; /* never ride along transforms */
    transition: background-color 120ms ease, border-color 120ms ease;
}
.ai-sidebar .chat-nav .__menu-item-trailing-btn::after {
    content: "⋯";
    font-size: 18px; line-height: 1;
    color: inherit;
}
.ai-sidebar .chat-nav .__menu-item-trailing-btn > * {
    display: none !important; /* hide any child nodes completely */
}

/* Dark mode parity */


/* === Section headers spacing + hide utilities — 2025-10-03 === */
/* Add space only between a chat item and the next section header */
.ai-sidebar .chat-nav li.chat-item + li.chat-section-header {
    margin-top: 10px !important;
}

/* Utility to hide empty headers (used by JS filter) */
.ai-sidebar .chat-nav li.chat-section-header[hidden],
.ai-sidebar .chat-nav li.chat-section-header.is-empty {
    display: none !important;
}

/* Grok-like hero header above query bar (visible until first send) */
.hero-header {
    position: relative;
    z-index: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0 0 12px 0;
    pointer-events: none;
}
/* Allow clicks on the hero content even when the wrapper ignores pointer events */
.hero-header .hero-logo,
.hero-header .hero-logo *,
#hero-title,
#hero-logo-img {
    pointer-events: auto;
    cursor: pointer;
}
.hero-logo {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}
.hero-logo img { max-height: 175px; width: auto; cursor: pointer; }
.hero-title { font-size: 28px; margin: 0; }

/* --- Hero jump animation (kangaroo bounce + dust) --- */
.hero-logo .hero-logo-wrap {
    position: relative;
    display: flex;
    flex-direction: row;
}
.hero-logo #hero-logo-img.hero-logo-jump {
    animation: heroLogoJump 1.1s cubic-bezier(0.22, 0.61, 0.36, 1) 1;
}
@keyframes heroLogoJump {
    0%, 18% { transform: translateY(0); }
    42%     { transform: translateY(-50px); }
    70%     { transform: translateY(0); }
    100%    { transform: translateY(0); }
}
.hero-logo .hero-landing-effect {
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 65px;
    height: 18px;
    transform: translateX(-25%);
    pointer-events: none;
    opacity: 0;
    filter: blur(0.2px);
    z-index: -1;
}
.hero-logo .hero-logo-wrap.is-landing .hero-landing-effect {
    animation: heroLandingDust 1.05s ease-out forwards;
}
.hero-logo .hero-landing-effect::before,
.hero-logo .hero-landing-effect::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50% 50% 45% 45%;
    background: radial-gradient(circle at 50% 50%, rgba(26, 28, 38, 0.55), rgba(32, 35, 48, 0.25) 40%, rgba(44, 36, 28, 0.0) 70%);
    mix-blend-mode: multiply;
}
.hero-logo .hero-landing-effect::after {
    inset: 6px;
    border-radius: 50%;
    border: 2px solid rgba(90, 76, 58, 0.45);
    box-shadow: 0 0 24px rgba(14, 16, 24, 0.35), 0 0 40px rgba(10, 12, 18, 0.4);
    background: radial-gradient(circle at 50% 50%, rgba(110, 92, 70, 0.35), rgba(32, 28, 24, 0.05) 55%, transparent 75%);
}
@keyframes heroLandingDust {
    0%   { opacity: 0; transform: translateX(-50%) scale(0.7); filter: blur(2px); }
    20%  { opacity: 0.9; transform: translateX(-50%) scale(1.05); filter: blur(0.6px); }
    55%  { opacity: 0.7; transform: translateX(-50%) scale(1.15); filter: blur(0.4px); }
    100% { opacity: 0; transform: translateX(-50%) scale(1.35); filter: blur(1.2px); }
}

/* --- Thought bubble (tip display) --- */
.hero-thought-bubble {
    position: absolute;
    top: 0;
    left: calc(100% + 18px);
    width: 250px;
    padding: 10px 14px;
    background: var(--color-surface, #fff);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 16px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    font-size: 13px;
    line-height: 1.4;
    color: var(--color-text, #333);
    pointer-events: none;
    z-index: 10;
    animation: thoughtBubbleFadeIn 0.4s ease-out forwards;
}
.hero-thought-bubble::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 18px;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-right-color: var(--color-surface, #fff);
    border-left: 0;
}
.hero-thought-bubble::after {
    content: '';
    position: absolute;
    left: -10px;
    top: 17px;
    width: 0;
    height: 0;
    border: 9px solid transparent;
    border-right-color: var(--border-color, #e0e0e0);
    border-left: 0;
    z-index: -1;
}
.hero-thought-bubble p {
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
@keyframes thoughtBubbleFadeIn {
    from { opacity: 0; transform: translateY(-5px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes thoughtBubbleFadeOut {
    from { opacity: 1; transform: scale(1); }
    to   { opacity: 0; transform: scale(0.95); }
}
.hero-thought-bubble.is-dismissing {
    animation: thoughtBubbleFadeOut 0.3s ease-in forwards;
}
@media (max-width: 600px) {
    /* Smaller jump so the kangaroo stays on-screen */
    @keyframes heroLogoJump {
        0%, 18% { transform: translateY(0); }
        42%     { transform: translateY(-28px); }
        70%     { transform: translateY(0); }
        100%    { transform: translateY(0); }
    }
    /* Position bubble above the kangaroo, centered on the viewport */
    .hero-thought-bubble {
        position: fixed !important;
        left: 50% !important;
        right: auto !important;
        bottom: auto !important;
        top: var(--hero-bubble-top, -20%) !important;
        transform: translateX(-50%) !important;
        width: 75vw;
        max-width: 320px;
        font-size: 13px;
        padding: 10px 14px;
        text-align: center;
        z-index: 9999;
    }
    /* Tail points down toward the kangaroo */
    .hero-thought-bubble::before {
        left: 50% !important;
        right: auto !important;
        top: auto !important;
        bottom: -7px !important;
        transform: translateX(-50%) !important;
        border: 8px solid transparent !important;
        border-top-color: var(--color-surface, #fff) !important;
        border-bottom: 0 !important;
        border-right-color: transparent !important;
    }
    .hero-thought-bubble::after {
        left: 50% !important;
        right: auto !important;
        top: auto !important;
        bottom: -10px !important;
        transform: translateX(-50%) !important;
        border: 9px solid transparent !important;
        border-top-color: var(--border-color, #e0e0e0) !important;
        border-bottom: 0 !important;
        border-right-color: transparent !important;
    }
}

/* Hero CTA for logged-out users */
.hero-get-started {
    margin-top: 1rem;
    padding: 0.75rem 2rem;
    background: var(--color-theme-1, #ed7618);
    color: #fff;
    border: none;
    border-radius: 2rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    pointer-events: auto;
}
.hero-get-started:hover {
    background: #c55f0d;
}

/* Guest chip banner — replaces chip row for logged-out users */
.guest-chip-banner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 0;
}
.guest-chip-banner .hero-get-started {
    margin-top: 0;
    padding: 0.6rem 1.5rem;
    font-size: 0.9rem;
}
.guest-chip-features {
    margin: 0;
    font-size: 0.78rem;
    color: var(--color-text-muted, #888);
    text-align: center;
}

/* Input group wrapper (Textarea + Buttons share a border) */
.input-group {
    width: 100%;
    border: 1px solid var(--color-border, #e5e7eb);
    background: var(--color-card-bg, #fff);
    border-radius: 25px;
    padding: 8px 10px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input-group:focus-within {
    border-color: var(--color-theme-1, #ed7618);
    box-shadow: 0 4px 12px rgba(237,118,24,0.12);
}
[data-theme="dark"] .input-group {
    background: #0b1220;
    border-color: rgba(255,255,255,0.12);
}

/* Textarea wrapper inside group (no borders) */
.textarea-wrapper.single-line {
    width: 100%;
    border: none;
    background: transparent;
    padding: 0;
    margin: 0;
    box-shadow: none;
}
.textarea-wrapper.single-line:focus-within {
    box-shadow: none;
}
.textarea-wrapper.single-line #message-input {
    height: 44px;
    min-height: 44px;
    max-height: 384px;
    line-height: 24px;
    overflow-y: hidden;
    padding: 8px 0;
}

/* While empty (placeholder visible), keep composer locked to one line.
   Prevents refresh-time transient growth before chat hydration finishes. */
.textarea-wrapper.single-line #message-input:placeholder-shown {
    height: 44px !important;
    min-height: 44px !important;
    max-height: 44px !important;
    overflow-y: hidden !important;
}

/* Query bar inside group (Buttons) */
.query-bar {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    padding-top: 4px; /* Slight separation from text */
    background: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
}
.query-bar .query-left {
    display: flex;
    align-items: center;
    gap: 8px;
}
.query-bar .attach-btn { min-width: 36px; width: 36px; height: 36px; border-radius: 9999px; }

.query-trailing {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.model-select {
    border: 1px solid transparent;
    background: transparent;
    border-radius: 9999px;
    cursor: pointer;
    padding: 4px 8px;
}
.model-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--color-text, #111827);
}
/* Desktop default: hide avatar in chip; mobile.css will show it */
.model-chip .model-avatar { display: none; }
.model-name { font-size: 0.9rem; font-weight: 600; }
.query-trailing .send-btn { display: none; }

/* Aspect ratio visual selector */
.ar-visual { display:inline-flex; gap:4px; align-items:center; margin-right: 2px; }
.ar-btn {
    display:inline-flex; align-items:center; justify-content:center;
    width:32px; height:32px; padding:0;
    border:1px solid rgba(229,231,235,0.7);
    border-radius:10px; background: transparent; color: #374151;
    cursor:pointer; transition: background-color .15s ease, border-color .15s ease, transform .05s ease;
}
.ar-btn:hover { background: rgba(0,0,0,0.05); border-color: rgba(229,231,235,1); }
.ar-btn.active, .ar-btn[aria-pressed="true"] { background: var(--color-theme-1); border-color: var(--color-theme-1); color:#fff; }
.ar-icon { width:20px; height:20px; display:flex; align-items:center; justify-content:center; }
.ar-box { border-radius:2px; border:2px solid var(--color-theme-1, #ed7618); background: rgba(237,118,24,0.15); box-sizing: content-box; }
.ar-btn.active .ar-box, .ar-btn[aria-pressed="true"] .ar-box { background: rgba(237,118,24,0.18); border-color: var(--color-border, #d1d5db); }

/* Dark theme parity */
[data-theme="dark"] .ar-btn { color:#e5e7eb; border-color: rgba(255,255,255,0.14); }
[data-theme="dark"] .ar-btn:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.2); }
[data-theme="dark"] .ar-box { border-color: var(--color-theme-1, #ed7618); background: rgba(237,118,24,0.2); }
[data-theme="dark"] .ar-btn.active .ar-box, [data-theme="dark"] .ar-btn[aria-pressed="true"] .ar-box { background: rgba(237,118,24,0.24); }

/* Aspect ratio dropdown (custom select) */
.ar-select { position: relative; display: inline-flex; align-items: center; }
.ar-trigger {
  display: inline-flex; 
  align-items: center; 
  gap: 6px;
  height: 32px; padding: 0 8px;
  border: 0px;
  border-radius: 10px; 
  background: transparent; 
  color: #374151;
  cursor: pointer; 
  transition: background-color .15s ease, border-color .15s ease;
}
.ar-trigger:hover { background: rgba(0,0,0,0.05); border-color: rgba(229,231,235,1); }
.ar-trigger .ar-icon { width:20px; height:20px; display:flex; align-items:center; justify-content:center; }

.ar-menu {
  position: absolute; top: calc(100% + 6px); left: 0;
  background: var(--color-card-bg, #fff);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 12px; padding: 6px; min-width: 140px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.12);
  z-index: 1250; display: none;
}
.ar-select.open .ar-menu { display: block; }

/* Mobile: show AR menu above the bar to prevent off-screen overflow */
@media (max-width: 767px) {
  /* Keep the AR dropdown from increasing the composer height on mobile */
  .query-bar .ar-select {
    height: 32px;
    align-self: center;
  }
  .query-bar .ar-trigger {
    -webkit-appearance: none;
    appearance: none;
    box-sizing: border-box;
    height: 32px !important;
    min-height: 32px !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    line-height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
  }
  .ar-menu {
    top: auto;
    bottom: calc(100% + 6px);
  }
}

.ar-option {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 6px 8px; border: 0;
  background: transparent; color: var(--color-text,#111);
  border-radius: 8px; cursor: pointer;
}
.ar-option .ar-icon { width:20px; height:20px; display:flex; align-items:center; justify-content:center; }
.ar-option:hover { background: rgba(0,0,0,0.05); }
.ar-option.active, .ar-option[aria-selected="true"] { background: rgba(237,118,24,0.10); }

/* Dark theme parity for dropdown */
[data-theme="dark"] .ar-trigger { color:#e5e7eb; border-color: rgba(255,255,255,0.14); }
[data-theme="dark"] .ar-trigger:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.2); }
[data-theme="dark"] .ar-menu { background: #0b1220; border-color: rgba(255,255,255,0.14); }
[data-theme="dark"] .ar-option:hover { background: rgba(255,255,255,0.08); }

/* Chips row — repositioned below input in empty state, above in active chat */
.input-actions-bar {
    display: flex;
    justify-content: center;
    position: relative;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.input-actions-bar::-webkit-scrollbar {
    display: none;
}

.input-actions-bar .chip-row {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    padding-top: 6px;
    padding-bottom: 2px;
    width: max-content;
    gap: 6px;
    position: relative;
}

/* Desktop empty state: chips below the input bar */
.ai-main-content:not(.has-messages) .input-actions-bar {
    order: 2;
    margin-top: 14px;
    overflow: visible;  /* allow hover scale to expand beyond container */
}
.ai-main-content:not(.has-messages) .chip-row {
    overflow: visible;
}
.ai-main-content:not(.has-messages) .input-group {
    order: 1;
}
/* Active chat: chips above input (default) */
.ai-main-content.has-messages .input-actions-bar {
    order: -1;
}

.chip-btn {
    display: inline-flex;
    align-items: center;
    padding: 8px 14px;
    gap: 6px;
    border-radius: 25px;
    border: 1px solid var(--color-border, #e5e7eb);
    background: var(--color-card-bg, #fff);
    color: var(--color-text, #111827);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background-color .2s ease, border-color .2s ease, transform .2s ease, box-shadow .2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    box-sizing: border-box;
}

/* Per-chip accent icon colors */
.chip-btn[data-accent="blue"] svg    { color: #3b82f6; }
.chip-btn[data-accent="orange"] svg  { color: #ed7618; }
.chip-btn[data-accent="purple"] svg  { color: #8b5cf6; }
.chip-btn[data-accent="teal"] svg    { color: #14b8a6; }

/* Empty state: subtle accent background tints + colored borders */
.ai-main-content:not(.has-messages) .chip-btn[data-accent="blue"]   { background: rgba(59,130,246,0.06);  border-color: rgba(59,130,246,0.25); }
.ai-main-content:not(.has-messages) .chip-btn[data-accent="orange"] { background: rgba(237,118,24,0.06);  border-color: rgba(237,118,24,0.25); }
.ai-main-content:not(.has-messages) .chip-btn[data-accent="purple"] { background: rgba(139,92,246,0.06);  border-color: rgba(139,92,246,0.25); }
.ai-main-content:not(.has-messages) .chip-btn[data-accent="teal"]   { background: rgba(20,184,166,0.06);  border-color: rgba(20,184,166,0.25); }

/* Active state: white icon overrides accent */
.chip-btn.active svg,
.chip-btn[aria-pressed="true"] svg {
    color: #fff !important;
}

/* Staggered entrance animation (empty state only) */
@keyframes chipFadeUp {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}
.ai-main-content:not(.has-messages) .chip-btn {
    animation: chipFadeUp 0.4s ease-out both;
}
.ai-main-content:not(.has-messages) .image-chip-container .chip-btn { animation-delay: 0.05s; }
.ai-main-content:not(.has-messages) .chip-row > .chip-btn:nth-child(2) { animation-delay: 0.10s; }
.ai-main-content:not(.has-messages) .chip-row > .chip-btn:nth-child(3) { animation-delay: 0.15s; }

@media (prefers-reduced-motion: reduce) {
    .chip-btn { animation: none !important; }
}

/* --- Chip collapse / expand animation --- */

/* Collapsed state: left-align selected chip, fill width for future right-side content */
.chip-row--collapsed {
    justify-content: flex-start !important;
    width: 100% !important;
}
@media (max-width: 767px) {
    .chip-row--collapsed { justify-content: flex-start !important; }
    body.edit-mode-active .chip-row--collapsed { justify-content: center !important; }
}
/* When collapsed to one chip, no scrolling needed — allow hover effects to overflow */
.input-actions-bar:has(.chip-row--collapsed) {
    overflow: visible;
}

/* Leaving chips: fly toward selected chip */
.chip-leaving {
    position: absolute !important;
    pointer-events: none;
    transition: transform 420ms cubic-bezier(0.4, 0, 0.2, 1),
                opacity 350ms cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform, opacity;
    z-index: 0;
}

/* Entering chips: appear from selected chip position */
.chip-entering {
    position: absolute !important;
    pointer-events: none;
    transition: transform 450ms cubic-bezier(0.0, 0.0, 0.2, 1),
                opacity 350ms cubic-bezier(0.0, 0.0, 0.2, 1);
    will-change: transform, opacity;
    z-index: 0;
}

/* Absorb pulse on the selected chip when others merge in */
@keyframes chipAbsorbPulse {
    0%   { filter: brightness(1); transform: scale(1); }
    35%  { filter: brightness(1.3); transform: scale(1.12); }
    100% { filter: brightness(1); transform: scale(1); }
}
.chip-absorb-pulse {
    animation: chipAbsorbPulse 450ms ease-out !important;
}

/* Reduced motion: skip collapse/expand animation */
@media (prefers-reduced-motion: reduce) {
    .chip-leaving,
    .chip-entering { transition: none !important; }
    .chip-absorb-pulse { animation: none !important; }
}

/* Attach Images CTA — pink pill with shimmer, contrasts against purple Edit Image chip */
.img-attach-cta {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: 9999px;
    border: none;
    background: linear-gradient(135deg, #ec4899 0%, #f472b6 40%, #a855f7 80%, #ec4899 100%);
    background-size: 250% 250%;
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    box-shadow: 0 2px 14px rgba(236,72,153,0.45), inset 0 1px 0 rgba(255,255,255,0.25);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background-position 0.4s ease;
    animation: attachShimmer 3s ease-in-out infinite;
}
.img-attach-cta[style*="inline-flex"] {
    display: inline-flex;
}
@keyframes attachShimmer {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}
.img-attach-cta:hover {
    transform: translateY(-1px) scale(1.04);
    box-shadow: 0 4px 16px rgba(236,72,153,0.50), inset 0 1px 0 rgba(255,255,255,0.30);
}
.img-attach-cta:active {
    transform: scale(0.97);
}
.img-attach-cta svg {
    width: 18px;
    height: 18px;
    color: #fff;
    stroke: #fff;
}
[data-theme="dark"] .img-attach-cta {
    background: linear-gradient(135deg, #db2777 0%, #ec4899 40%, #8b5cf6 80%, #db2777 100%);
    background-size: 250% 250%;
    box-shadow: 0 2px 14px rgba(236,72,153,0.50), inset 0 1px 0 rgba(255,255,255,0.15);
}
[data-theme="dark"] .img-attach-cta:hover {
    box-shadow: 0 4px 18px rgba(236,72,153,0.55), inset 0 1px 0 rgba(255,255,255,0.20);
}
/* Hover: lift + accent-colored glow */
.chip-btn:hover {
    background: rgba(0,0,0,0.02);
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 8px 20px rgba(0,0,0,0.10);
}
.chip-btn[data-accent="blue"]:hover   { box-shadow: 0 8px 20px rgba(59,130,246,0.18); border-color: rgba(59,130,246,0.3); }
.chip-btn[data-accent="orange"]:hover { box-shadow: 0 8px 20px rgba(237,118,24,0.18); border-color: rgba(237,118,24,0.3); }
.chip-btn[data-accent="purple"]:hover { box-shadow: 0 8px 20px rgba(139,92,246,0.18); border-color: rgba(139,92,246,0.3); }
.chip-btn[data-accent="teal"]:hover   { box-shadow: 0 8px 20px rgba(20,184,166,0.18); border-color: rgba(20,184,166,0.3); }
/* Per-chip active state: accent-colored backgrounds (overrides empty-state tints) */
.chip-btn.active,
.chip-btn[aria-pressed="true"] {
    color: #fff;
}
.chip-btn[data-accent="blue"].active,
.chip-btn[data-accent="blue"][aria-pressed="true"]   { background: #3b82f6 !important; border-color: #3b82f6 !important; color: #fff; }
.chip-btn[data-accent="orange"].active,
.chip-btn[data-accent="orange"][aria-pressed="true"] { background: #ed7618 !important; border-color: #ed7618 !important; color: #fff; }
.chip-btn[data-accent="purple"].active,
.chip-btn[data-accent="purple"][aria-pressed="true"] { background: #8b5cf6 !important; border-color: #8b5cf6 !important; color: #fff; }
.chip-btn[data-accent="teal"].active,
.chip-btn[data-accent="teal"][aria-pressed="true"]   { background: #14b8a6 !important; border-color: #14b8a6 !important; color: #fff; }
/* Fallback for chips without data-accent */
.chip-btn.active:not([data-accent]) { background: var(--color-theme-1) !important; border-color: var(--color-theme-1) !important; color: #fff; }
.chip-btn svg { width: 16px; height: 16px; }
.chip-btn.locked,
.chip-btn[aria-disabled="true"] {
    opacity: 0.5;
    filter: grayscale(1);
    cursor: not-allowed;
}
/* Force storage-full visual even if classes toggle later */
.chip-btn[data-lock-reason="storage"] {
    opacity: 0.5;
    filter: grayscale(1);
    cursor: not-allowed;
}

/* Dark mode parity for query bar + chips */
[data-theme="dark"] .query-bar { background: #0b1220; border-color: rgba(255,255,255,0.12); }
[data-theme="dark"] .chip-btn { background: #0b1220; border-color: rgba(255,255,255,0.12); color: #e5e7eb; }
[data-theme="dark"] .chip-btn:hover { background: rgba(255,255,255,0.06); }
[data-theme="dark"] .model-chip { color: #e5e7eb; }

/* Dark mode: lighter accent icon tints */
[data-theme="dark"] .chip-btn[data-accent="blue"] svg    { color: #60a5fa; }
[data-theme="dark"] .chip-btn[data-accent="orange"] svg  { color: #fb923c; }
[data-theme="dark"] .chip-btn[data-accent="purple"] svg  { color: #a78bfa; }
[data-theme="dark"] .chip-btn[data-accent="teal"] svg    { color: #2dd4bf; }

/* Dark mode: empty-state accent background tints */
[data-theme="dark"] .ai-main-content:not(.has-messages) .chip-btn[data-accent="blue"]   { background: rgba(96,165,250,0.10);  border-color: rgba(96,165,250,0.25); }
[data-theme="dark"] .ai-main-content:not(.has-messages) .chip-btn[data-accent="orange"] { background: rgba(251,146,60,0.10);  border-color: rgba(251,146,60,0.25); }
[data-theme="dark"] .ai-main-content:not(.has-messages) .chip-btn[data-accent="purple"] { background: rgba(167,139,250,0.10); border-color: rgba(167,139,250,0.25); }
[data-theme="dark"] .ai-main-content:not(.has-messages) .chip-btn[data-accent="teal"]   { background: rgba(45,212,191,0.10);  border-color: rgba(45,212,191,0.25); }

/* Dark mode: accent-colored glow on hover */
[data-theme="dark"] .chip-btn[data-accent="blue"]:hover   { box-shadow: 0 8px 20px rgba(96,165,250,0.15); border-color: rgba(96,165,250,0.3); }
[data-theme="dark"] .chip-btn[data-accent="orange"]:hover { box-shadow: 0 8px 20px rgba(251,146,60,0.15); border-color: rgba(251,146,60,0.3); }
[data-theme="dark"] .chip-btn[data-accent="purple"]:hover { box-shadow: 0 8px 20px rgba(167,139,250,0.15); border-color: rgba(167,139,250,0.3); }
[data-theme="dark"] .chip-btn[data-accent="teal"]:hover   { box-shadow: 0 8px 20px rgba(45,212,191,0.15); border-color: rgba(45,212,191,0.3); }

/* Touch devices: prevent sticky :hover from leaving chips in a grey/lifted state after tap */
@media (hover: none), (pointer: coarse) {
    /* Default: neutralize hover fill + transform so it doesn't "stick" after tap */
    .chip-btn:hover {
        background: var(--color-card-bg, #fff);
        transform: none;
        box-shadow: 0 2px 8px rgba(0,0,0,0.06);
        border-color: var(--color-border, #e5e7eb);
    }
    [data-theme="dark"] .chip-btn:hover {
        background: #0b1220;
        border-color: rgba(255,255,255,0.12);
    }

    /* If the chip is actually active/pressed, keep the active styling even if :hover sticks */
    .chip-btn.active:hover,
    .chip-btn[aria-pressed="true"]:hover {
        background: var(--color-theme-1);
        border-color: var(--color-theme-1);
        color: #fff;
    }
    [data-theme="dark"] .chip-btn.active:hover,
    [data-theme="dark"] .chip-btn[aria-pressed="true"]:hover {
        background: var(--color-theme-1);
        border-color: var(--color-theme-1);
        color: #fff;
    }

}

/* ===== Unified Image Chip Container + Mode Toggle ===== */
.image-chip-container {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    position: relative;
}
.ai-main-content:not(.has-messages) .chip-row .chip-btn,
.ai-main-content:not(.has-messages) .chip-row .image-chip-container { width: 180px; }
.ai-main-content:not(.has-messages) .chip-row .chip-btn { justify-content: center; }
.ai-main-content:not(.has-messages) #image-chip-btn { width: 100%; }
.image-proxy { display: none !important; }

.image-mode-toggle {
    align-items: center;
    gap: 0;
    background: var(--color-card-bg, #f3f4f6);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 20px;
    padding: 2px;
    flex-shrink: 0;
    animation: imgToggleFadeIn 0.25s ease-out;
}
@keyframes imgToggleFadeIn {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
}
.image-mode-opt {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    border: none;
    border-radius: 18px;
    background: transparent;
    color: var(--color-text-secondary, #6b7280);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
    white-space: nowrap;
    line-height: 1.4;
    font-family: inherit;
}
.image-mode-opt svg { width: 14px; height: 14px; flex-shrink: 0; }

.image-mode-opt:hover:not(.is-active) {
    background: rgba(0, 0, 0, 0.04);
    color: var(--color-text, #111);
}

/* Active sub-mode colours */
.image-mode-opt.is-active[data-mode="generate"] {
    background: #ed7618; color: #fff;
    box-shadow: 0 1px 4px rgba(237,118,24,0.3);
}
.image-mode-opt.is-active[data-mode="generate"] svg { color: #fff; }
.image-mode-opt.is-active[data-mode="edit"] {
    background: #8b5cf6; color: #fff;
    box-shadow: 0 1px 4px rgba(139,92,246,0.3);
}
.image-mode-opt.is-active[data-mode="edit"] svg { color: #fff; }

/* Inactive icons keep accent tint */
.image-mode-opt:not(.is-active)[data-mode="generate"] svg { color: #ed7618; }
.image-mode-opt:not(.is-active)[data-mode="edit"] svg     { color: #8b5cf6; }

/* Dark mode */
[data-theme="dark"] .image-mode-toggle {
    background: #0f1724;
    border-color: rgba(255,255,255,0.12);
}
[data-theme="dark"] .image-mode-opt { color: #9ca3af; }
[data-theme="dark"] .image-mode-opt:hover:not(.is-active) {
    background: rgba(255,255,255,0.06); color: #e5e7eb;
}
[data-theme="dark"] .image-mode-opt:not(.is-active)[data-mode="generate"] svg { color: #fb923c; }
[data-theme="dark"] .image-mode-opt:not(.is-active)[data-mode="edit"] svg     { color: #a78bfa; }

/* Mobile compact */
@media (max-width: 767px) {
    .image-mode-opt { padding: 4px 8px; font-size: 0.75rem; }
}
/* Touch: neutralize sticky hover */
@media (hover: none), (pointer: coarse) {
    .image-mode-opt:hover:not(.is-active) {
        background: transparent;
        color: var(--color-text-secondary, #6b7280);
    }
}

/* Knowledge attach popover (query bar) */
.knowledge-popover {
  position: absolute;
  left: 50%;
  transform: translateX(-50%) translateY(6px) scale(0.98);
  bottom: calc(100% + 10px);
  width: min(92vw, 440px);
  max-height: min(530px, 70vh);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 16px;
  background: var(--color-card-bg, #fff);
  box-shadow: 0 12px 30px rgba(0,0,0,0.14);
  padding: 10px;
  z-index: 2005;
  display: none;
  overflow: hidden;
  opacity: 0;
  box-sizing: border-box;
  transition: opacity .16s ease, transform .16s ease;
}
.knowledge-popover.open {
  display: block;
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
}
[data-theme="dark"] .knowledge-popover {
  background: #0b1220;
  border-color: rgba(255,255,255,0.14);
}

/* Mobile: full-screen modal overlay with backdrop */
@media (max-width: 767px) {
  .knowledge-popover {
    position: fixed;
    left: 50% !important;
    top: 50% !important;
    bottom: auto !important;
    transform: translate(-50%, -50%) scale(0.98);
    width: min(calc(100vw - 16px), 420px);
    max-height: min(85vh, 600px);
    border: 2px solid var(--color-border, #d1d5db);
    box-shadow: 0 16px 48px rgba(0,0,0,0.32);
    z-index: 2010;
  }

  .knowledge-popover-actions {
    gap: 4px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .knowledge-popover-actions-left {
    gap: 4px;
    min-width: 0;
    flex: 1 1 100%;
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }

  .knowledge-popover-actions-left::-webkit-scrollbar {
    display: none;
  }

  .knowledge-attach-desc-toggle {
    height: 34px;
    padding: 0 8px;
    font-size: 0.75rem;
    white-space: nowrap;
  }

  .knowledge-attach-desc-toggle .desc-text-long {
    display: none;
  }

  .knowledge-popover-clear {
    height: 34px;
    padding: 0 8px;
    font-size: 0.8rem;
  }

  .knowledge-popover-accept {
    height: 34px;
    padding: 0 16px;
    font-size: 0.85rem;
    margin-left: auto;
    max-width: 100%;
  }

  .knowledge-popover-settings {
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
  }
  .knowledge-popover.open {
    transform: translate(-50%, -50%) scale(1);
  }
  [data-theme="dark"] .knowledge-popover {
    border-color: rgba(255,255,255,0.30);
    box-shadow: 0 16px 48px rgba(0,0,0,0.55);
  }
  /* Backdrop overlay */
  .knowledge-popover-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 2005;
    display: none;
  }
  .knowledge-popover-backdrop.open {
    display: block;
  }
  [data-theme="dark"] .knowledge-popover-backdrop {
    background: rgba(0,0,0,0.65);
  }
}

/* Backdrop: hidden by default (desktop), only shown on mobile when open */
.knowledge-popover-backdrop {
  display: none;
}

.knowledge-popover-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.knowledge-popover-close {
  width: 34px;
  height: 34px;
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  border: 1px solid var(--color-border, #e5e7eb);
  background: var(--color-card-bg, #fff);
  color: var(--color-text, #6b7280);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
  flex: 0 0 auto;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.knowledge-popover-close:hover {
  background: rgba(0,0,0,0.04);
  border-color: var(--color-border, #d1d5db);
}

[data-theme="dark"] .knowledge-popover-close {
  background: #0b1220;
  border-color: rgba(255,255,255,0.14);
  color: #e5e7eb;
}

[data-theme="dark"] .knowledge-popover-close:hover {
  background: rgba(255,255,255,0.06);
}

.knowledge-popover-search {
  flex: 1 1 auto;
  height: 34px;
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 9999px;
  padding: 0 12px;
  background: transparent;
  color: var(--color-text, #111827);
  outline: none;
  font-size: 0.9rem;
}
.knowledge-popover-search:focus {
  border-color: var(--color-theme-1, #ed7618);
  box-shadow: 0 0 0 3px rgba(237,118,24,0.10);
}
[data-theme="dark"] .knowledge-popover-search {
  border-color: rgba(255,255,255,0.14);
  color: #e5e7eb;
}
[data-theme="dark"] .knowledge-popover-search::placeholder {
  color: rgba(229,231,235,0.7);
}

.knowledge-popover-settings {
  width: 38px;
  height: 38px;
  min-width: 38px;
  min-height: 38px;
  padding: 0;
  aspect-ratio: 1 / 1;
  border-radius: 9999px;
  border: 1px solid var(--color-border, #e5e7eb);
  background: var(--color-card-bg, #fff);
  color: var(--color-text, #6b7280);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
  flex: 0 0 auto;
}
.knowledge-popover-settings svg {
  width: 18px;
  height: 18px;
}
.knowledge-popover-settings:hover {
  background: rgba(0,0,0,0.04);
  border-color: var(--color-border, #d1d5db);
}
[data-theme="dark"] .knowledge-popover-settings {
  background: #0b1220;
  border-color: rgba(255,255,255,0.14);
  color: #e5e7eb;
}
[data-theme="dark"] .knowledge-popover-settings:hover {
  background: rgba(255,255,255,0.06);
}

.knowledge-popover-list {
  margin-top: 8px;
  max-height: calc(min(520px, 70vh) - 102px);
  overflow-y: auto;
  padding-right: 2px;
}

.knowledge-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--color-border, #e5e7eb);
  background: transparent;
  color: var(--color-text, #111827);
  text-align: left;
  transition: background-color 0.15s ease, border-color 0.15s ease;
  margin-bottom: 6px;
}
.knowledge-item:hover { background: rgba(0,0,0,0.04); }
.knowledge-item.selected {
  border-color: rgba(237,118,24,0.70);
  background: rgba(237,118,24,0.08);
  box-shadow: inset 0 0 0 1px rgba(237,118,24,0.20);
}
[data-theme="dark"] .knowledge-item {
  border-color: rgba(255,255,255,0.14);
  color: #e5e7eb;
}
[data-theme="dark"] .knowledge-item:hover { background: rgba(255,255,255,0.06); }
[data-theme="dark"] .knowledge-item.selected {
  border-color: rgba(237,118,24,0.80);
  background: rgba(237,118,24,0.16);
  box-shadow: inset 0 0 0 1px rgba(237,118,24,0.24);
}

.knowledge-item-main {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: none;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: 11px;
}
.knowledge-item-main:active { transform: scale(0.995); }

.knowledge-item-tree .knowledge-item-main {
  padding-left: calc(10px + (var(--tree-depth, 0) * 16px));
}

.knowledge-item-tree .knowledge-tree-caret {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  width: 20px;
  height: 20px;
  min-width: 20px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-right: 2px;
}

.knowledge-item-tree .knowledge-tree-caret:hover {
  background: rgba(0,0,0,0.05);
}

.knowledge-item-tree .knowledge-tree-caret.is-empty {
  opacity: 0.35;
  cursor: default;
}

[data-theme="dark"] .knowledge-item-tree .knowledge-tree-caret:hover {
  background: rgba(255,255,255,0.08);
}

.knowledge-attach-desc-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 12px;
  border-radius: 9999px;
  border: 1px solid var(--color-border, #e5e7eb);
  background: transparent;
  color: var(--color-text-secondary, #6b7280);
  font-size: 0.82rem;
  font-weight: 600;
  user-select: none;
  box-sizing: border-box;
}

.knowledge-attach-desc-toggle input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--color-theme-1, #ed7618);
  margin: 0;
}

[data-theme="dark"] .knowledge-attach-desc-toggle {
  border-color: rgba(255,255,255,0.14);
  color: #9ca3af;
}

.knowledge-check {
  width: 20px;
  height: 20px;
  min-width: 20px;
  border-radius: 8px;
  border: 1px solid var(--color-border, #e5e7eb);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  color: var(--color-theme-1, #ed7618);
}
[data-theme="dark"] .knowledge-check { border-color: rgba(255,255,255,0.14); }

.knowledge-meta { min-width: 0; flex: 1 1 auto; }
.knowledge-name {
  font-size: 0.92rem;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.knowledge-desc {
  margin-top: 2px;
  font-size: 0.78rem;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.knowledge-count {
  min-width: 28px;
  text-align: right;
  font-size: 0.82rem;
  opacity: 0.75;
}

.knowledge-empty {
  font-size: 0.9rem;
  color: #6b7280;
  padding: 6px 2px 2px 2px;
}

.knowledge-popover-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.knowledge-popover-actions-left {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.knowledge-popover-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  appearance: none;
  border: 1px solid var(--color-border, #e5e7eb);
  background: transparent;
  color: var(--color-text-secondary, #6b7280);
  padding: 0 12px;
  border-radius: 9999px;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.85rem;
  box-sizing: border-box;
}

.knowledge-popover-clear:hover {
  background: rgba(0,0,0,0.04);
  color: var(--color-text, #111827);
}

.knowledge-popover-accept {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  padding: 0 24px;
  flex-shrink: 0;
  border-radius: 9999px;
  border: 1px solid transparent;
  background: var(--color-theme-1, #ed7618);
  color: #fff;
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.05s ease;
  box-sizing: border-box;
}
.knowledge-popover-accept:hover {
  background: #d86b11;
}
.knowledge-popover-accept:active {
  transform: scale(0.98);
}

[data-theme="dark"] .knowledge-popover-clear {
  border-color: rgba(255,255,255,0.14);
  color: #9ca3af;
}
[data-theme="dark"] .knowledge-popover-clear:hover {
  background: rgba(255,255,255,0.06);
  color: #e5e7eb;
}
[data-theme="dark"] .knowledge-popover-accept {
  background: #ffffff;
  color: #000000;
}
[data-theme="dark"] .knowledge-popover-accept:hover {
  background: #f3f4f6;
  color: #000000;
}

/* Prompt toggle checkbox in folder items */
.knowledge-prompt-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--color-text-secondary, #6b7280);
  background: transparent;
  transition: background-color 0.12s ease;
}
.knowledge-prompt-toggle:hover {
  background: rgba(0,0,0,0.04);
}
.knowledge-prompt-toggle input[type="checkbox"] {
  width: 14px;
  height: 14px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--color-theme-1, #ed7618);
}
.knowledge-prompt-toggle-label {
  white-space: nowrap;
  user-select: none;
}
[data-theme="dark"] .knowledge-prompt-toggle {
  color: #9ca3af;
}
[data-theme="dark"] .knowledge-prompt-toggle:hover {
  background: rgba(255,255,255,0.06);
}

/* Dark: ensure Create/Edit Image chips turn orange when active */
[data-theme="dark"] #image-gen-btn.active,
[data-theme="dark"] #image-gen-btn[aria-pressed="true"],
[data-theme="dark"] #image-edit-btn.active,
[data-theme="dark"] #image-edit-btn[aria-pressed="true"] {
    background: var(--color-theme-1);
    border-color: var(--color-theme-1);
    color: #fff;
}

/* 2025-11-08: Image download overlay for generated images */
.ai-image-figure {
  position: relative;
  margin: 0 0 10px 0;
  overflow: visible;
}

/* The image wrapper is the positioning context so the button always pins to the image corner */
.ai-image-figure .ai-img-wrap {
  position: relative;
  display: block;
  width: 100%;
}

/* Pin the button to the image (wrapper), not the grid cell/figure */
.ai-image-figure .ai-img-wrap > .ai-img-dl {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  border-radius: 9999px;
  border: 1px solid var(--color-border, #e5e7eb);
  background: var(--color-card-bg, #fff);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
  transform: scale(0.75);
  opacity: 0;
  transition: transform .2s ease, opacity .2s ease, background-color .15s ease, border-color .15s ease;
  z-index: 2;
}

.ai-image-figure:hover .ai-img-wrap > .ai-img-dl,
.ai-image-figure:focus-within .ai-img-wrap > .ai-img-dl {
  transform: scale(1);
  opacity: 1;
}

.ai-image-figure .ai-img-wrap > .ai-img-dl:hover {
  background: var(--color-bg, #f9fafb);
  border-color: var(--color-border, #d1d5db);
}

.ai-image-figure .ai-img-wrap > .ai-img-dl svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
}

/* Ensure image fills the figure so the button pins to the real top-right corner */
.ai-image-figure img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  cursor: zoom-in;
}

/* Dark mode parity for image download button */
[data-theme="dark"] .ai-image-figure .ai-img-wrap > .ai-img-dl {
  background: #0b1220;
  border-color: rgba(255,255,255,0.14);
  color: #e5e7eb;
}
[data-theme="dark"] .ai-image-figure .ai-img-wrap > .ai-img-dl:hover {
  background: rgba(255,255,255,0.08);
}

/* Share button next to download button */
.ai-image-figure .ai-img-wrap > .ai-img-share {
  position: absolute;
  right: 48px;
  top: 8px;
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  border-radius: 9999px;
  border: 1px solid var(--color-border, #e5e7eb);
  background: var(--color-card-bg, #fff);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
  transform: scale(0.75);
  opacity: 0;
  transition: transform .2s ease, opacity .2s ease, background-color .15s ease, border-color .15s ease;
  z-index: 2;
}

.ai-image-figure:hover .ai-img-wrap > .ai-img-share,
.ai-image-figure:focus-within .ai-img-wrap > .ai-img-share {
  transform: scale(1);
  opacity: 1;
}

.ai-image-figure .ai-img-wrap > .ai-img-share:hover {
  background: var(--color-bg, #f9fafb);
  border-color: var(--color-border, #d1d5db);
}

.ai-image-figure .ai-img-wrap > .ai-img-share svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
}

/* Dark mode parity for image share button */
[data-theme="dark"] .ai-image-figure .ai-img-wrap > .ai-img-share {
  background: #0b1220;
  border-color: rgba(255,255,255,0.14);
  color: #e5e7eb;
}
[data-theme="dark"] .ai-image-figure .ai-img-wrap > .ai-img-share:hover {
  background: rgba(255,255,255,0.08);
}

/* 2026-01-15: AI image lightbox (gallery-style) */

.ai-lightbox {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-lightbox.hidden { display: none; }

.ai-lightbox .lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.9);
}

.ai-lightbox .lightbox-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-lightbox .lightbox-content {
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#ai-lightbox-image {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 8px;
  user-select: none;
  -webkit-user-drag: none;
}

.ai-lightbox .lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.1);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  z-index: 10;
}

.ai-lightbox .lightbox-close:hover {
  background: rgba(255,255,255,0.2);
  transform: scale(1.05);
}

.ai-lightbox .lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.1);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  z-index: 10;
}

.ai-lightbox .lightbox-nav:hover {
  background: rgba(255,255,255,0.2);
  transform: translateY(-50%) scale(1.05);
}

.ai-lightbox .lightbox-nav:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.ai-lightbox .lightbox-prev { left: 20px; }
.ai-lightbox .lightbox-next { right: 20px; }

.ai-lightbox .lightbox-actions {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  z-index: 10;
}

.ai-lightbox .lightbox-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 9999px;
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.15s ease;
  backdrop-filter: blur(8px);
}

.ai-lightbox .lightbox-action-btn:hover {
  background: rgba(255,255,255,0.25);
  transform: translateY(-1px);
}

.ai-lightbox .lightbox-counter {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,0.7);
  font-size: 0.9rem;
  z-index: 10;
}

@media (max-width: 767px) {
  .ai-lightbox .lightbox-nav { width: 40px; height: 40px; }
  .ai-lightbox .lightbox-prev { left: 10px; }
  .ai-lightbox .lightbox-next { right: 10px; }
  .ai-lightbox .lightbox-actions {
    flex-wrap: wrap;
    justify-content: center;
    padding: 0 10px;
    gap: 8px;
  }
  .ai-lightbox .lightbox-action-btn { padding: 8px 14px; font-size: 0.85rem; }
  .ai-lightbox .lightbox-action-btn span { display: none; }
  .ai-lightbox .lightbox-close { top: 10px; right: 10px; width: 40px; height: 40px; }
}

/* Show download button on touch devices */
@media (hover: none), (pointer: coarse) {
  .ai-image-figure .ai-img-wrap > .ai-img-dl {
    opacity: 1;
    transform: scale(1);
  }
  .ai-image-figure .ai-img-wrap > .ai-img-share {
    opacity: 1;
    transform: scale(1);
  }
}

/* 2025-11-08: Image generation placeholders (occupy final image position) */
.ai-img-ph {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  background: #f3f4f6;
  border: 1px solid rgba(0,0,0,0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.ai-img-ph-spinner {
  position: absolute;
  width: 26px;
  height: 26px;
  border: 3px solid rgba(0,0,0,0.18);
  border-top-color: var(--color-theme-1, #ed7618);
  border-radius: 50%;
  animation: dcspin 0.9s linear infinite;
}
/* Dark mode */
[data-theme="dark"] .ai-img-ph {
  background: #0b1220;
  border-color: rgba(255,255,255,0.12);
}
[data-theme="dark"] .ai-img-ph-spinner {
  border-color: rgba(255,255,255,0.18);
  border-top-color: var(--color-theme-1, #ed7618);
}
/* 2025-11-08: Delete message button styles - Visible except first controls row */
/* Delete icon visibility: show by default, hide on the first real controls row */
.message-controls-row.first-controls .msg-ctrl.delete { display: none !important; }

/* 2025-11-08: Desktop — center generated images at 66% width */
@media (min-width: 768px) {
  /* Applies to generated images rendered by image.js inside assistant messages */
  #chat-history .message.assistant .ai-image-figure {
    width: 66%;
    margin-left: auto;
    margin-right: auto;
    justify-self: center; /* center within grid track */
  }
  #chat-history .message.assistant .ai-image-figure img {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    height: auto;
  }
}
/* 2025-11-08: Backfill — center previously-rendered generated images on desktop */
@media (min-width: 768px) {
  /* Handle older messages that may not have the figure wrapper */
  #chat-history .message.assistant img[alt="Generated image"],
  #chat-history .message.assistant img[data-s3-key] {
    margin-left: auto;
    margin-right: auto;
    display: block;
  }

  /* If there's only one generated image, ensure its figure centers too */
  #chat-history .message.assistant .ai-image-figure:only-child {
    margin-left: auto;
    margin-right: auto;
    justify-self: center;
  }
}
/* Nicer assistant system banners (errors/warnings/info) */
.message.assistant.error,
#quota-banner {
  position: relative;
  margin: 8px 20px !important;         /* override any inline margins */
  padding: 10px 12px 10px 38px;         /* room for icon */
  border-radius: 12px;
  background: rgba(237,118,24,0.06);
  border: 1px solid rgba(237,118,24,0.35);
  border-left: 4px solid var(--color-theme-1,#ed7618) !important;
  color: var(--color-text,#111);
  line-height: 1.35;
  font-size: .95rem;
  box-shadow: 0 2px 10px rgba(0,0,0,0.04);
}

.message.assistant.error::before,
#quota-banner::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  background: url('data:image/svg+xml;utf8,&lt;svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23ed7618"&gt;&lt;path d="M12 2a10 10 0 100 20 10 10 0 000-20zm1 14h-2v2h2v-2zm0-8h-2v6h2V8z"/&gt;&lt;/svg&gt;') no-repeat center/contain;
  opacity: .95;
}

.message.assistant.error a,
#quota-banner a {
  color: var(--color-theme-1,#ed7618);
  font-weight: 700;
  text-decoration: underline;
}
.message.assistant.error a:hover,
#quota-banner a:hover { text-decoration: none; }

/* Dark mode adjustments */
[data-theme="dark"] .message.assistant.error,
[data-theme="dark"] #quota-banner {
  background: rgba(237,118,24,0.12);
  border-color: rgba(237,118,24,0.5);
  color: #e5e7eb;
}
/* Override assistant error look (placed at end to win cascade) */
@keyframes dc-banner-in { from { opacity:.0; transform: translateY(-3px); } to { opacity:1; transform: translateY(0); } }

#chat-history .message.assistant.error,
.ai-main-content .message.assistant.error,
#quota-banner {
  background-color: rgba(237,118,24,0.06) !important;
  border: 1px solid rgba(237,118,24,0.35) !important;
  border-left: 4px solid var(--color-theme-1,#ed7618) !important;
  color: var(--color-text,#111) !important;
  margin: 8px 20px !important;
  padding: 10px 12px 10px 38px !important;
  border-radius: 12px !important;
  box-shadow: 0 2px 10px rgba(0,0,0,0.04) !important;
  position: relative;
  animation: dc-banner-in .22s ease-out;
}

#chat-history .message.assistant.error::before,
.ai-main-content .message.assistant.error::before,
#quota-banner::before {
  content: "";
  position: absolute;
  left: 12px; top: 50%;
  width: 18px; height: 18px;
  transform: translateY(-50%);
  background: url('data:image/svg+xml;utf8,&lt;svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23ed7618"&gt;&lt;path d="M12 2a10 10 0 100 20 10 10 0 000-20zm1 14h-2v2h2v-2zm0-8h-2v6h2V8z"/&gt;&lt;/svg&gt;') no-repeat center/contain;
  opacity: .95;
}

#chat-history .message.assistant.error a,
.ai-main-content .message.assistant.error a,
#quota-banner a {
  color: var(--color-theme-1,#ed7618) !important;
  font-weight: 700;
  text-decoration: underline;
}
#chat-history .message.assistant.error a:hover,
.ai-main-content .message.assistant.error a:hover,
#quota-banner a:hover { text-decoration: none; }

/* Dark mode */
[data-theme="dark"] #chat-history .message.assistant.error,
[data-theme="dark"] .ai-main-content .message.assistant.error,
[data-theme="dark"] #quota-banner {
  background-color: rgba(237,118,24,0.12) !important;
  border-color: rgba(237,118,24,0.5) !important;
  color: #e5e7eb !important;
}
/* Feedback modal and toast */
.dc-modal.hidden { display: none !important; }
.dc-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.dc-modal-content {
  width: 100%;
  max-width: 520px;
  background: var(--color-card-bg, #fff);
  color: var(--color-text, #111);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.18);
  overflow: hidden;
}
.dc-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--color-border, #e5e7eb);
}
.dc-modal-close {
  background: transparent;
  border: 0;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: inherit;
}
.dc-modal-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.dc-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dc-field span {
  font-weight: 600;
  font-size: 0.95rem;
}
.dc-field input,
.dc-field select,
.dc-field textarea {
  border: 1px solid var(--color-border,#e5e7eb);
  background: var(--color-card-bg,#fff);
  color: var(--color-text,#111);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
}
.dc-field textarea { min-height: 120px; resize: vertical; }
.dc-modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 6px;
}
.btn-primary {
  background: var(--color-theme-1,#ed7618);
  color: #fff;
  border: 1px solid var(--color-theme-1,#ed7618);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}
.btn-primary:hover { background: #1f2937; border-color: #1f2937; }
.btn-secondary {
  background: transparent;
  color: var(--color-text,#111);
  border: 1px solid var(--color-border,#ddd);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}
.feedback-status { margin-top: 4px; font-size: 0.9rem; color: #4b5563; }
.feedback-status.error { color: #dc3545; }

/* Toast */
.dc-toast.hidden { display: none !important; }
.dc-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--color-card-bg,#fff);
  color: var(--color-text,#111);
  border: 1px solid var(--color-border,#e5e7eb);
  border-radius: 10px;
  padding: 10px 14px;
  z-index: 2050;
  box-shadow: 0 10px 30px rgba(0,0,0,0.12);
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
}
.dc-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

/* Dark mode parity */
[data-theme="dark"] .dc-modal-content {
  background: #0b1220;
  color: #e5e7eb;
  border-color: rgba(255,255,255,0.14);
}
[data-theme="dark"] .dc-field input,
[data-theme="dark"] .dc-field select,
[data-theme="dark"] .dc-field textarea {
  background: #0b1220;
  color: #e5e7eb;
  border-color: rgba(255,255,255,0.14);
}
[data-theme="dark"] .btn-secondary {
  color: #e5e7eb;
  border-color: rgba(255,255,255,0.14);
}
[data-theme="dark"] .dc-toast {
  background: #0b1220;
  color: #e5e7eb;
  border-color: rgba(255,255,255,0.14);
}
/* Mobile New Chat FAB - hidden by default, shown on mobile when conversation has messages */
.ai-newchat-fab {
  display: none;
  position: fixed;
  top: 10px;
  right: 10px;
  width: 50px;
  height: 50px;
  min-width: 50px;
  min-height: 50px;
  border-radius: 50%;
  border: 1px solid var(--color-border, #e5e7eb);
  background: var(--color-card-bg, #fff);
  color: var(--color-text, #374151);
  cursor: pointer;
  z-index: 1350;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  transition: background-color .15s ease, border-color .15s ease, transform .1s ease, box-shadow .15s ease;
}
.ai-newchat-fab svg {
  width: 25px;
  height: 25px;
}
.ai-newchat-fab:hover {
  background: var(--color-theme-1, #ed7618);
  border-color: var(--color-theme-1, #ed7618);
  color: #fff;
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(237,118,24,0.25);
}
.ai-newchat-fab:active {
  transform: scale(0.95);
}
.ai-newchat-fab:focus-visible {
  outline: 2px solid var(--color-theme-1, #ed7618);
  outline-offset: 2px;
}

/* Dark mode */
[data-theme="dark"] .ai-newchat-fab {
  background: #0b1220;
  border-color: rgba(255,255,255,0.14);
  color: #e5e7eb;
}
[data-theme="dark"] .ai-newchat-fab:hover {
  background: var(--color-theme-1, #ed7618);
  border-color: var(--color-theme-1, #ed7618);
  color: #fff;
}

/* Mobile only: show FAB when conversation has messages */
@media (max-width: 767px) {
  .ai-main-content.has-messages .ai-newchat-fab {
    display: flex;
  }
}

/* Image edit templates (AI page) */
.img-tpl-chip-wrap {
  position: relative;
}

/* User bubble: image-edit template display */
.message.user .msg-imgtpl {
  display: block;
}

.message.user .msg-imgtpl-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.message.user .msg-imgtpl-template {
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.2;
}

.message.user .msg-imgtpl-prompt {
  font-weight: 500;
  font-size: 0.95rem;
  line-height: 1.25;
  word-break: break-word;
  opacity: 0.9;
}

.message.user .msg-imgtpl-prompt::before {
  content: "-";
  opacity: 0.55;
  margin-right: 8px;
}

/* Template chip label + clear (×) */
#image-edit-templates-btn .img-tpl-chip-label {
  display: inline-block;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (max-width: 420px) {
  #image-edit-templates-btn .img-tpl-chip-label { max-width: 110px; }
}
#image-edit-templates-btn .img-tpl-chip-clear {
  display: none;
  width: 18px;
  height: 18px;
  min-width: 18px;
  border-radius: 9999px;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  margin-left: -4px;
}

/* NOTE: use an id-qualified selector so it overrides the base "display:none" above */
#image-edit-templates-btn.chip-btn.active .img-tpl-chip-clear,
#image-edit-templates-btn.chip-btn[aria-pressed="true"] .img-tpl-chip-clear {
  display: inline-flex;
}

#image-edit-templates-btn.chip-btn.active .img-tpl-chip-clear:hover,
#image-edit-templates-btn.chip-btn[aria-pressed="true"] .img-tpl-chip-clear:hover {
  background: rgba(0,0,0,0.10);
}

[data-theme="dark"] #image-edit-templates-btn.chip-btn.active .img-tpl-chip-clear:hover,
[data-theme="dark"] #image-edit-templates-btn.chip-btn[aria-pressed="true"] .img-tpl-chip-clear:hover {
  background: rgba(255,255,255,0.14);
}

.img-tpl-popover {
  position: fixed;
  left: 50%;
  top: 20%;
  transform: translateX(-50%);
  width: min(92vw, 520px);
  max-height: min(500px, 70vh);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 16px;
  background: var(--color-card-bg, #fff);
  box-shadow: 0 12px 30px rgba(0,0,0,0.14);
  padding: 10px;
  z-index: 2005;
  display: none;
  overflow: hidden;
}
.img-tpl-popover.open {
  display: block;
}
[data-theme="dark"] .img-tpl-popover {
  background: #0b1220;
  border-color: rgba(255,255,255,0.14);
}

.img-tpl-popover.busy {
  opacity: 0.85;
  pointer-events: none;
}

.img-tpl-popover-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.img-tpl-popover-close {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 9999px;
  border: 1px solid var(--color-border, #e5e7eb);
  background: transparent;
  color: var(--color-text, #6b7280);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
}
.img-tpl-popover-close:hover {
  background: rgba(0,0,0,0.04);
}
[data-theme="dark"] .img-tpl-popover-close {
  border-color: rgba(255,255,255,0.14);
  color: #e5e7eb;
}
[data-theme="dark"] .img-tpl-popover-close:hover {
  background: rgba(255,255,255,0.06);
}

.img-tpl-search {
  flex: 1 1 auto;
  height: 34px;
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 9999px;
  padding: 0 12px;
  background: transparent;
  color: var(--color-text, #111827);
  outline: none;
  font-size: 0.9rem;
}
.img-tpl-search:focus {
  border-color: var(--color-theme-1, #ed7618);
  box-shadow: 0 0 0 3px rgba(237,118,24,0.10);
}
[data-theme="dark"] .img-tpl-search {
  border-color: rgba(255,255,255,0.14);
  color: #e5e7eb;
}
[data-theme="dark"] .img-tpl-search::placeholder {
  color: rgba(229, 231, 235, 0.7);
}

.img-tpl-list {
  margin-top: 8px;
  max-height: calc(min(500px, 70vh) - 52px);
  overflow-y: auto;
  padding-right: 2px;
}

.img-tpl-loading,
.img-tpl-empty {
  font-size: 0.9rem;
  color: #6b7280;
  padding: 6px 2px 2px 2px;
}

.img-tpl-group + .img-tpl-group { margin-top: 8px; }
.img-tpl-group-title {
  font-size: 0.7rem;
  font-weight: 800;
  color: #6b7280;
  margin: 8px 2px 4px 2px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.img-tpl-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.img-tpl-row {
  position: relative;
}

.img-tpl-row-apply {
  width: 100%;
  min-height: 44px;
  padding: 10px 42px 10px 10px;
  border-radius: 12px;
  border: 1px solid var(--color-border, #e5e7eb);
  background: transparent;
  color: var(--color-text, #111827);
  text-align: left;
  font-size: 0.92rem;
  line-height: 1.1;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}
.img-tpl-row-apply:hover {
  background: rgba(0,0,0,0.04);
}
.img-tpl-row-apply:active {
  transform: scale(0.995);
}

/* Active (selected) template highlight */
.img-tpl-row-apply.is-active,
.img-tpl-row-apply[aria-pressed="true"] {
  border-color: rgba(237,118,24,0.70);
  background: rgba(237,118,24,0.08);
  box-shadow: inset 0 0 0 1px rgba(237,118,24,0.20);
}

[data-theme="dark"] .img-tpl-row-apply {
  border-color: rgba(255,255,255,0.14);
  color: #e5e7eb;
}
[data-theme="dark"] .img-tpl-row-apply:hover {
  background: rgba(255,255,255,0.06);
}
[data-theme="dark"] .img-tpl-row-apply.is-active,
[data-theme="dark"] .img-tpl-row-apply[aria-pressed="true"] {
  border-color: rgba(237,118,24,0.80);
  background: rgba(237,118,24,0.16);
  box-shadow: inset 0 0 0 1px rgba(237,118,24,0.24);
}

.img-tpl-row-fav {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  min-width: 30px;
  border-radius: 9999px;
  border: 1px solid var(--color-border, #e5e7eb);
  background: var(--color-card-bg, #fff);
  color: #9ca3af;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
}

/* Mobile: ensure popover circle buttons remain perfect circles (Android/iOS can apply min-size/padding to <button>) */
@media (max-width: 767px) {
  #image-edit-templates-popover .img-tpl-row-fav,
  #image-edit-templates-popover .img-tpl-popover-close {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    padding: 0 !important;
    aspect-ratio: 1 / 1;
    border-radius: 50% !important;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
    flex: 0 0 auto;
  }
}
.img-tpl-row-fav:hover {
  background: rgba(0,0,0,0.04);
}
.img-tpl-row-fav.is-fav,
.img-tpl-row-fav[aria-pressed="true"] {
  color: var(--color-theme-1, #ed7618);
  border-color: rgba(237,118,24,0.55);
}
[data-theme="dark"] .img-tpl-row-fav {
  border-color: rgba(255,255,255,0.14);
  background: #0b1220;
}
[data-theme="dark"] .img-tpl-row-fav:hover {
  background: rgba(255,255,255,0.06);
}

/* Small screens: keep popover within viewport even when chip row is scrolled */
@media (max-width: 420px) {
  .img-tpl-popover {
    width: min(96vw, 420px);
  }
}

/* --- Inline template thumbnail strip (chip row, right of Edit Image chip) --- */

.img-tpl-strip {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
}

.img-tpl-strip-scroll {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    flex: 1 1 auto;
    min-width: 0;
    padding: 4px 0;
    cursor: grab;
    /* Fade-out hint on right edge */
    -webkit-mask-image: linear-gradient(to right, black calc(100% - 36px), transparent);
    mask-image: linear-gradient(to right, black calc(100% - 36px), transparent);
}
.img-tpl-strip-scroll.is-dragging {
    cursor: grabbing;
    user-select: none;
}
.img-tpl-strip-scroll::-webkit-scrollbar { display: none; }

.img-tpl-thumb {
    flex: 0 0 auto;
    width: 110px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 12px;
    padding: 4px;
    background: transparent;
    transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
    color: var(--color-text, #6b7280);
}
.img-tpl-thumb:hover {
    border-color: rgba(139,92,246,0.35);
    background: rgba(139,92,246,0.06);
    transform: translateY(-1px);
}
.img-tpl-thumb.is-active {
    border-color: #8b5cf6;
    background: rgba(139,92,246,0.10);
}
.img-tpl-thumb img {
    width: 100px;
    height: 100px;
    border-radius: 10px;
    object-fit: cover;
}
.img-tpl-thumb-label {
    font-size: 0.7rem;
    font-weight: 500;
    line-height: 1.15;
    text-align: center;
    color: inherit;
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Selected template label (shown when active template is not in strip) */
.img-tpl-strip-selected {
    flex: 0 0 auto;
    display: none;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 16px;
    background: rgba(139,92,246,0.10);
    border: 1px solid rgba(139,92,246,0.30);
    color: #8b5cf6;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}
.img-tpl-strip-selected.is-visible {
    display: inline-flex;
}
.img-tpl-strip-selected:hover {
    background: rgba(139,92,246,0.16);
}
[data-theme="dark"] .img-tpl-strip-selected {
    background: rgba(139,92,246,0.16);
    border-color: rgba(139,92,246,0.35);
    color: #a78bfa;
}

.img-tpl-strip-see-all {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--color-border, #e5e7eb);
    background: transparent;
    color: var(--color-text, #6b7280);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.img-tpl-strip-see-all:hover {
    background: rgba(139,92,246,0.06);
    border-color: rgba(139,92,246,0.35);
    color: #8b5cf6;
}

[data-theme="dark"] .img-tpl-thumb:hover {
    background: rgba(139,92,246,0.12);
}
[data-theme="dark"] .img-tpl-thumb.is-active {
    background: rgba(139,92,246,0.18);
}
[data-theme="dark"] .img-tpl-strip-see-all {
    border-color: rgba(255,255,255,0.14);
}
[data-theme="dark"] .img-tpl-strip-see-all:hover {
    background: rgba(139,92,246,0.14);
    border-color: rgba(139,92,246,0.4);
    color: #a78bfa;
}

/* --- Visual template cards in popover (2-column grid) --- */

.img-tpl-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.img-tpl-card {
    position: relative;
}

.img-tpl-card-apply {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px;
    border-radius: 12px;
    border: 1px solid var(--color-border, #e5e7eb);
    background: transparent;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}
.img-tpl-card-apply img {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 8px;
    object-fit: cover;
}
.img-tpl-card-label {
    margin-top: 6px;
    font-size: 0.82rem;
    font-weight: 500;
    line-height: 1.2;
    text-align: center;
    color: var(--color-text, #111827);
}
.img-tpl-card-apply:hover {
    background: rgba(0,0,0,0.04);
}
.img-tpl-card-apply:active {
    transform: scale(0.98);
}
.img-tpl-card-apply.is-active,
.img-tpl-card-apply[aria-pressed="true"] {
    border-color: rgba(237,118,24,0.70);
    background: rgba(237,118,24,0.08);
    box-shadow: inset 0 0 0 1px rgba(237,118,24,0.20);
}

.img-tpl-card .img-tpl-row-fav {
    position: absolute;
    top: 6px;
    right: 6px;
}

[data-theme="dark"] .img-tpl-card-apply {
    border-color: rgba(255,255,255,0.14);
}
[data-theme="dark"] .img-tpl-card-apply:hover {
    background: rgba(255,255,255,0.06);
}
[data-theme="dark"] .img-tpl-card-apply.is-active,
[data-theme="dark"] .img-tpl-card-apply[aria-pressed="true"] {
    border-color: rgba(237,118,24,0.80);
    background: rgba(237,118,24,0.16);
    box-shadow: inset 0 0 0 1px rgba(237,118,24,0.24);
}
[data-theme="dark"] .img-tpl-card-label {
    color: #e5e7eb;
}
