/* AI Chat Styles - Pure CSS, no frameworks */

main {
    padding-top: 106px !important;
}

/* 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;
}

/* Remove top banner on AI pages and fix layout offsets */
body.ai-route .top-banner { display: none !important; }

/* Move header up to top when banner is hidden */
body.ai-route header { top: 0 !important; }

/* Keep breadcrumbs below the fixed header */
body.ai-route .breadcrumbs { top: 106px; }

/* Announcements bar on AI page */
.ai-announcements {
    padding: 0 10%;
    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 #3b82f6; }
.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: 106px;
    height: calc(100vh - 106px);
}
.ai-container {
    display: flex;
    height: 80vh;
    width: 100%;
    overflow: visible;
    position: relative;
}

.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;
    right: 8px;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid var(--color-border, #e5e7eb);
    background: var(--color-card-bg, #fff);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, transform .05s 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);
}
.ai-sidebar .ai-sidebar-toggle svg {
    width: 20px;
    height: 20px;
}
[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 .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;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    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;
    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 */

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* padding: 1rem; */
    border-bottom: 1px solid var(--color-border, #ddd);
    background-color: var(--color-card-bg, #fff);
}

.sidebar-header h2 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--color-text, #333);
}

.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 - Login/Signup Buttons */
.auth-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: space-between;
}

.auth-btn {
    flex: 1;
    padding: 0.625rem 1rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.login-btn {
    background-color: transparent;
    color: var(--color-text, #333);
    border: 1px solid var(--color-border, #ddd);
}

.login-btn:hover {
    background-color: var(--color-theme-4, #f8f4f0);
}

.signup-btn {
    background-color: var(--color-theme-1, #ed7618);
    color: white;
}

.signup-btn:hover {
    background-color: #c55f0d;
}

/* 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%;
}

.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;
}

.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: black;
  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 {
    background-color: #f6f8fa;
    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; /* prevent fly-in when toggling has-messages */
}

/* 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;
    padding: 0.25rem;
    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%;
    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: 18px;
    height: 18px;
}
/* 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 */
}

.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;
    padding: 0;
}

.send-btn:hover {
    background-color: #1f2937;
}

.send-btn.streaming {
    background-color: #dc3545;
}

.send-btn.streaming:hover {
    background-color: #c82333;
}

.send-btn svg {
    width: 20px;
    height: 20px;
}

.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: 9999px;
    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: 220px;
    max-width: 440px;
    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;
}

.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: visible;
    text-overflow: ellipsis;
}

.attachment-size {
    font-size: 0.75rem;
    color: #6b7280;
}

.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-size { color: #9ca3af; }
[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;
}


/* Guest auth prompt styles */
.guest-auth-prompt {
    position: fixed;
    left: 280px;
    right: 0;
    /* bottom: 110px; */
    margin: 20% 0;
    z-index: 1200;
    display: flex;
    justify-content: center;
    pointer-events: auto;
    padding: 0 10%;
}
.guest-auth-prompt-inner {
    width: 100%;
    max-width: 1152px;
    box-sizing: border-box;
}
.guest-auth-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--color-card-bg,#fff);
    border:1px solid var(--color-border,#e5e7eb);
    padding:12px 16px;
    border-radius:18px;
    box-shadow:0 6px 18px rgba(0,0,0,0.06);
}
.guest-auth-text {
    font-size: 0.95rem;
    color: var(--color-text,#111);
}
.guest-auth-actions {
    display:flex;
    gap:8px;
    align-items:center;
}
.guest-auth-actions .btn {
    padding:8px 12px;
    border-radius:12px;
    min-width: 130px
}
.guest-auth-actions .btn-secondary {
    background: transparent;
    border:1px solid var(--color-border,#ddd);
    color: var(--color-text,#111);
}

/* Sidebar visual improvements (New Chat downwards) - 2025-10-03 */
.ai-sidebar .new-chat-btn:hover {
    transform: translateY(-2px);
    background-color: #d86b1188;
    box-shadow: 0 12px 30px rgba(237,118,24,0.18);
}
.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 user-auth-section & sidebar-header untouched as requested */
/* Sidebar refinements appended 2025-10-03 - second pass
   - Improve spacing, active indicator, trailing controls visibility,
   - reserve space above user-auth-section so last chats remain visible
*/

/* 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;
    box-shadow: 0 6px 18px rgba(237,118,24,0.08);
    font-size: 1rem;
    font-weight: 700;
}
.ai-sidebar .new-chat-btn:active {
    transform: translateY(1px) scale(0.98);
}

/* 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;
    box-shadow: 0 0 0 3px rgba(237,118,24,0.07);
    border-color: rgba(237,118,24,0.12);
}

/* 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: pulse ring, icon wiggle, confetti on click */
.ai-sidebar .new-chat-btn:hover svg {
    transform: rotate(-6deg) scale(1.05);
    transition: transform 160ms ease;
}

/* Pulse ring on hover — render as a border ring (no fill blob) */
.ai-sidebar .new-chat-btn:hover::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 140%;
    height: 140%;
    border-radius: 9999px;
    transform: translate(-50%, -50%) scale(0.75);
    border: 3px solid rgba(237,118,24,0.45); /* ring instead of shadow fill */
    background: transparent;
    animation: dc-ringPulse 1.2s ease-out infinite; /* scale + opacity pulse */
    pointer-events: none;
    z-index: 0;
    will-change: transform, opacity;
}

/* 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;
}

/* Click ripple on press/focus — one-shot expanding ring */
.ai-sidebar .new-chat-btn:active::after,
.ai-sidebar .new-chat-btn:focus::after,
.ai-sidebar .new-chat-btn:focus-visible::after,
.ai-sidebar .new-chat-btn.is-pressed::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 120%;
    height: 120%;
    border-radius: 9999px;
    transform: translate(-50%, -50%) scale(0.7);
    border: 3px solid rgba(237,118,24,0.45);
    background: transparent;
    pointer-events: none;
    z-index: 0;
    animation: dc-clickRipple 600ms ease-out 1 forwards;
    will-change: transform, opacity;
}

/* Chat items: magnetic tilt + sparkle on hover */

@media (hover: hover) and (pointer: fine) {
    .ai-sidebar .chat-nav .__menu-item:hover {
        transform: translateX(6px) perspective(700px) rotateY(-6deg);
    }
}

.ai-sidebar .chat-nav .__menu-item:active {
    transform: translateX(2px) scale(0.99);
}


.ai-sidebar .chat-nav .__menu-item:hover::after {
    opacity: 0.9;
    animation: dc-sparkle 1.2s linear infinite;
}


/* 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);
}


/* Dark theme tweak for sparkle color */
[data-theme="dark"] .ai-sidebar .chat-nav .__menu-item:hover::after {
    color: #fbbf24;
}

/* Keyframes */
@keyframes dc-ringPulse {
    0%   { transform: translate(-50%, -50%) scale(0.75); opacity: 0.7; }
    70%  { transform: translate(-50%, -50%) scale(1.08); opacity: 0.0; }
    100% { transform: translate(-50%, -50%) scale(0.75); opacity: 0.7; }
}
@keyframes dc-confettiBurst {
    0%   { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(12); opacity: 0; }
}
/* One-shot ripple for :active ring */
@keyframes dc-clickRipple {
    0%   { transform: translate(-50%, -50%) scale(0.7); opacity: 0.7; }
    60%  { transform: translate(-50%, -50%) scale(1.2); opacity: 0.25; }
    100% { transform: translate(-50%, -50%) scale(1.35); 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 .new-chat-btn:active::before,
    .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) Stop tilting the whole chat item; tilt only the title so the trailing button stays put */
@media (hover: hover) and (pointer: fine) {
  .ai-sidebar .chat-nav .__menu-item:hover { transform: none !important; }
  .ai-sidebar .chat-nav .__menu-item .truncate {
      transform-origin: left center;
      transition: transform 140ms ease;
  }
  .ai-sidebar .chat-nav .__menu-item:hover .truncate {
      transform: translateX(6px) perspective(700px) rotateY(-6deg);
  }
}



/* === 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 */


/* Keep content tilt fun but isolated to the title only (no effect on trailing button) */
@media (hover: hover) and (pointer: fine) {
  .ai-sidebar .chat-nav .__menu-item .truncate {
      transform-origin: left center;
      transition: transform 140ms ease;
  }
  .ai-sidebar .chat-nav .__menu-item:hover .truncate {
      transform: translateX(6px) perspective(700px) rotateY(-6deg);
  }
}
/* === 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;
    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 {
    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; }

/* Hide sidebar header until first send; JS removes this class later */
.ai-sidebar .sidebar-header.initially-hidden { display: none; }

/* 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: 28px;
    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 {
    min-height: 40px;
    max-height: 384px;
    line-height: 24px;
    overflow-y: hidden;
    padding: 8px 0;
}

/* 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-border, #d1d5db); background: rgba(0,0,0,0.06); 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: rgba(255,255,255,0.18); background: rgba(255,255,255,0.08); }
[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); right: 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) {
  .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 above the input */
.input-actions-bar {
    display: flex;
    justify-content: flex-start; /* Start aligned for scrolling */
    margin-bottom: 8px;
    position: relative;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    scrollbar-width: none; /* Firefox: hide scrollbar */
}
.input-actions-bar::-webkit-scrollbar {
    display: none; /* Chrome/Safari: hide scrollbar */
}

.input-actions-bar .chip-row {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap; /* Prevent wrapping */
    padding-bottom: 2px; /* Space for potential scrollbar if visible */
    width: max-content; /* Ensure container expands to fit content */
}

#edit-guard-hint {
    display: block;
    text-align: center;
    line-height: 1.35;
    box-sizing: border-box;
}

/* Desktop/tablet: pin hint below chips without reflow */
@media (min-width: 768px) {
    .input-actions-bar {
        position: relative;
        justify-content: flex-start; /* Or center if preferred on desktop, but user asked for scroll */
        /* overflow-x: hidden; */ /* Maybe keep visible on desktop? User said "goes off the screen to the right on mobile" */
    }
    #edit-guard-hint {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        top: calc(100% + 6px);
        margin: 0;
        white-space: nowrap;
        max-width: none;
        z-index: 1;
    }
}

/* Mobile: subtle inline hint */
@media (max-width: 767px) {
    #edit-guard-hint {
        position: static;
        width: 100%;
        max-width: 100%;
        margin: 6px 0 0 0;
        z-index: 1;
        background: transparent;
        box-shadow: none;
        border: none !important;
        color: #6b7280 !important;
        border-radius: 0 !important;
        padding: 0 !important;
        font-size: 0.8rem !important;
        text-align: center;
        animation: none;
    }
}
.chip-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 9999px;
    border: 1px solid var(--color-border, #e5e7eb);
    background: var(--color-card-bg, #fff);
    color: var(--color-text, #111827);
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color .15s ease, border-color .15s ease, transform .05s ease;
}

/* Attach Images button - blue styling, matches other chip-btn size */
#edit-attach-btn {
    color: #3b82f6;
    border-color: #3b82f6;
    /* Ensure same sizing as other chip buttons */
    padding: 8px 12px;
    font-size: 0.9rem;
    gap: 8px;
}
#edit-attach-btn:hover {
    background: rgba(59, 130, 246, 0.08);
    border-color: #2563eb;
}
#edit-attach-btn svg {
    width: 16px;
    height: 16px;
}
[data-theme="dark"] #edit-attach-btn {
    color: #60a5fa;
    border-color: #60a5fa;
}
[data-theme="dark"] #edit-attach-btn:hover {
    background: rgba(96, 165, 250, 0.12);
    border-color: #93c5fd;
}
.chip-btn:hover { background: rgba(0,0,0,0.04); }
.chip-btn.active {
    background: var(--color-theme-1);
    border-color: var(--color-theme-1);
    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: 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;
  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;
  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;
}

/* 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;
  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;
  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);
}

/* 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: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  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: 22px;
  height: 22px;
}
.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, 440px);
  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;
}
.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);
  }
}
