        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            -webkit-tap-highlight-color: transparent;
        }

        :root {
            --bg: #ffffff;
            --bg-soft: #fafafa;
            --text: #0a0a0a;
            --text-light: #6b7280;
            --text-lighter: #9ca3af;
            --border: #ececec;
            --border-strong: #d4d4d4;
            --accent-bg: #f5f5f5;
            --primary: #0a0a0a;
            --primary-hover: #262626;
            --danger: #dc2626;
            --success: #16a34a;
            --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
            --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
            --radius: 10px;
            --radius-sm: 6px;
            --radius-lg: 14px;
        }

        /* --- Dark theme palette --- */
        [data-theme="dark"] {
            --bg: #0b0d10;
            --bg-soft: #14171c;
            --text: #f3f4f6;
            --text-light: #9ca3af;
            --text-lighter: #6b7280;
            --border: #262a31;
            --border-strong: #3a3f47;
            --accent-bg: #1c2026;
            --primary: #f3f4f6;
            --primary-hover: #e5e7eb;
            --danger: #f87171;
            --success: #34d399;
            --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
            --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
        }

        /* In dark mode, primary buttons need dark text on the light "primary" surface */
        /* Anything painted on --primary needs dark text in dark mode */
        [data-theme="dark"] .btn-primary,
        [data-theme="dark"] .btn-primary:hover,
        [data-theme="dark"] #sendBtn,
        [data-theme="dark"] .choice-custom button,
        [data-theme="dark"] .toast,
        [data-theme="dark"] .message.user .message-content { color: #0b0d10; }
        [data-theme="dark"] .typing-cursor { background: var(--primary); }
        [data-theme="dark"] .message.user .typing-cursor { background: #0b0d10; }
        [data-theme="dark"] .robot-search .magnet-tip-n,
        [data-theme="dark"] .robot-search .magnet-tip-s { fill: #d1d5db; }

        html { transition: background-color 0.2s ease; }
        body { transition: background-color 0.2s ease, color 0.2s ease; }

        /* Theme toggle icon swap */
        #themeToggle .theme-icon-sun  { display: inline-block; }
        #themeToggle .theme-icon-moon { display: none; }
        [data-theme="dark"] #themeToggle .theme-icon-sun  { display: none; }
        [data-theme="dark"] #themeToggle .theme-icon-moon { display: inline-block; }

        /* === Dark mode: override hardcoded light surfaces === */
        [data-theme="dark"] body { background: #07090c; }

        [data-theme="dark"] header           { background: rgba(20, 23, 28, 0.85) !important; }
        [data-theme="dark"] .tabs-bar        { background: rgba(20, 23, 28, 0.9)  !important; }
        [data-theme="dark"] .sidebar         { background: rgba(20, 23, 28, 0.92) !important; }
        [data-theme="dark"] .chat-frame {
            background: rgba(20, 23, 28, 0.95) !important;
            box-shadow:
                0 0 0 1px rgba(255, 255, 255, 0.04) inset,
                0 8px 32px rgba(0, 0, 0, 0.5) !important;
        }
        [data-theme="dark"] .chat-frame .input-container { background: rgba(20, 23, 28, 0.98) !important; }
        [data-theme="dark"] .chat-tab.active             { background: var(--bg-soft); }
        [data-theme="dark"] .chat-tab:hover              { background: rgba(255, 255, 255, 0.04); }

        /* Cursor glow tinted for dark backdrop */
        [data-theme="dark"] .cursor-glow {
            background: radial-gradient(circle 500px at var(--cx, 50%) var(--cy, 50%),
                rgba(var(--accent-rgb), 0.18) 0%,
                rgba(var(--accent-rgb), 0.10) 40%,
                transparent 70%);
        }

        /* Toggle switch knob */
        [data-theme="dark"] .switch .slider::before { background: #f3f4f6; }

        /* Danger button hover background was hard-pink — soften it for dark */
        [data-theme="dark"] .btn-danger:hover { background: rgba(248, 113, 113, 0.12); }

        /* Empty thumbnail / placeholder backgrounds */
        [data-theme="dark"] .empty-state { color: var(--text-light); }

        /* Inputs / textareas / selects fall back to var(--bg) — make sure */
        [data-theme="dark"] input,
        [data-theme="dark"] textarea,
        [data-theme="dark"] select {
            color: var(--text);
            background-color: var(--bg);
        }
        [data-theme="dark"] select option { background: var(--bg); color: var(--text); }

        /* User message bubble: --primary is light in dark mode, so its text/icons must go dark */
        [data-theme="dark"] .message.user .message-content,
        [data-theme="dark"] .message.user .message-content h2,
        [data-theme="dark"] .message.user .message-content h3,
        [data-theme="dark"] .message.user .message-content h4,
        [data-theme="dark"] .message.user .message-content a,
        [data-theme="dark"] .message.user .message-content strong,
        [data-theme="dark"] .message.user .message-content em { color: #0b0d10 !important; }

        [data-theme="dark"] .message.user .message-content code,
        [data-theme="dark"] .message.user .message-content pre {
            background: rgba(0, 0, 0, 0.20);
            border-color: rgba(0, 0, 0, 0.25);
            color: #0b0d10;
        }
        [data-theme="dark"] .message.user .message-content blockquote {
            border-left-color: rgba(0, 0, 0, 0.45);
            color: rgba(0, 0, 0, 0.85);
            background: rgba(0, 0, 0, 0.10);
        }
        [data-theme="dark"] .message.user .message-content li::marker { color: rgba(0, 0, 0, 0.55); }

        /* Code blocks in bot messages */
        [data-theme="dark"] .message.bot .message-content pre,
        [data-theme="dark"] .message.bot .message-content code {
            background: rgba(255, 255, 255, 0.06);
            color: var(--text);
        }

        /* Modals already use var(--bg) for content, but the overlay tint can be deeper */
        [data-theme="dark"] .modal-overlay { background: rgba(0, 0, 0, 0.65); }

        /* Scrollbars */
        [data-theme="dark"] .sidebar-chats::-webkit-scrollbar-thumb,
        [data-theme="dark"] *::-webkit-scrollbar-thumb { background: #2a2f37; }
        [data-theme="dark"] *::-webkit-scrollbar-track { background: transparent; }

        html,
        body {
            height: 100%;
            overscroll-behavior: none;
        }

        body {
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
            background-color: var(--bg);
            color: var(--text);
            line-height: 1.5;
            font-size: 14px;
            overflow: hidden;
            -webkit-font-smoothing: antialiased;
        }

        button,
        input,
        textarea,
        select {
            font-family: inherit;
        }

        .app-container {
            display: flex;
            flex-direction: column;
            height: 100dvh;
            background: var(--bg);
        }

        /* --- Header --- */
        header {
            padding: 14px 20px;
            border-bottom: 1px solid var(--border);
            display: flex;
            justify-content: space-between;
            align-items: center;
            background: var(--bg);
            flex-shrink: 0;
        }

        .header-brand h1 {
            font-size: 0.95rem;
            letter-spacing: 1.5px;
            font-weight: 800;
            text-transform: uppercase;
        }

        #userWelcome {
            font-size: 0.65rem;
            color: var(--text-light);
            margin-top: 2px;
            font-weight: 500;
        }

        .header-actions {
            display: flex;
            gap: 8px;
            align-items: center;
        }

        /* --- Buttons --- */
        .btn {
            background: var(--bg);
            border: 1px solid var(--border);
            padding: 8px 14px;
            font-size: 0.8rem;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.15s ease;
            border-radius: var(--radius-sm);
            color: var(--text);
            display: inline-flex;
            align-items: center;
            gap: 6px;
            white-space: nowrap;
        }

        .btn:hover {
            background: var(--accent-bg);
            border-color: var(--border-strong);
        }

        .btn:active {
            transform: scale(0.98);
        }

        .btn-primary {
            background: var(--primary);
            color: white;
            border-color: var(--primary);
        }

        .btn-primary:hover {
            background: var(--primary-hover);
            border-color: var(--primary-hover);
        }

        .btn-sm {
            padding: 6px 10px;
            font-size: 0.75rem;
        }

        .btn-icon {
            padding: 8px;
            width: 36px;
            height: 36px;
            justify-content: center;
        }

        .btn-danger {
            color: var(--danger);
            border-color: var(--border);
        }

        .btn-danger:hover {
            background: #fef2f2;
            border-color: var(--danger);
        }

        /* --- Sidebar & Layout --- */
        .main-layout {
            display: flex;
            flex: 1;
            overflow: hidden;
        }

        .sidebar {
            width: 260px;
            background: rgba(250, 250, 250, 0.9);
            backdrop-filter: blur(8px);
            -webkit-backdrop-filter: blur(8px);
            border-right: 1px solid var(--border);
            display: flex;
            flex-direction: column;
            flex-shrink: 0;
            z-index: 5;
        }

        .sidebar-header {
            padding: 16px;
            border-bottom: 1px solid var(--border);
        }

        .sidebar-chats {
            flex: 1;
            overflow-y: auto;
            padding: 12px;
            display: flex;
            flex-direction: column;
            gap: 8px;
            scrollbar-width: thin;
        }

        .sidebar-chats::-webkit-scrollbar {
            width: 4px;
        }

        .sidebar-chats::-webkit-scrollbar-thumb {
            background: var(--border-strong);
            border-radius: 4px;
        }

        .chat-tab {
            padding: 12px 14px;
            background: transparent;
            border: 1px solid transparent;
            font-size: 0.85rem;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-radius: var(--radius-sm);
            color: var(--text-light);
            transition: all 0.2s ease;
            font-weight: 500;
        }

        .chat-tab:hover {
            background: rgba(0, 0, 0, 0.03);
            color: var(--text);
            transform: translateY(-1px);
        }

        .chat-tab.active {
            background: white;
            border-color: var(--border);
            color: var(--text);
            font-weight: 600;
            box-shadow: var(--shadow-sm);
        }

        .chat-tab .tab-info {
            display: flex;
            align-items: center;
            gap: 8px;
            overflow: hidden;
            flex: 1;
        }

        .chat-tab .tab-title {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .chat-tab .tab-actions {
            display: flex;
            gap: 4px;
            opacity: 0;
            transition: opacity 0.2s;
        }

        .chat-tab:hover .tab-actions,
        .chat-tab .tab-actions:has(.pinned) {
            opacity: 1;
        }

        .tab-action-btn {
            background: none;
            border: none;
            color: var(--text-light);
            cursor: pointer;
            padding: 4px;
            border-radius: 4px;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.15s;
        }

        .tab-action-btn:hover {
            background: var(--border);
            color: var(--text);
        }

        .tab-action-btn.pinned {
            color: var(--primary);
            opacity: 1;
        }

        /* --- Chat Area --- */
        .chat-main {
            flex: 1;
            display: flex;
            flex-direction: column;
            overflow: hidden;
            min-height: 0;
        }

        .messages {
            flex: 1;
            overflow-y: auto;
            padding: 20px;
            display: flex;
            flex-direction: column;
            gap: 14px;
            background: var(--bg);
            scroll-behavior: smooth;
        }

        .messages::-webkit-scrollbar {
            width: 6px;
        }

        .messages::-webkit-scrollbar-track {
            background: transparent;
        }

        .messages::-webkit-scrollbar-thumb {
            background: var(--border-strong);
            border-radius: 3px;
        }

        .message {
            display: flex;
            flex-direction: column;
            max-width: 75%;
            width: fit-content;
            animation: fadeUp 0.25s ease;
        }

        @keyframes fadeUp {
            from {
                opacity: 0;
                transform: translateY(6px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .message.user {
            align-self: flex-end;
            align-items: flex-end;
        }

        .message.bot {
            align-self: flex-start;
        }

        .message-content {
            padding: 12px 18px;
            border: 1px solid var(--border);
            font-size: 0.875rem;
            border-radius: var(--radius);
            line-height: 1.6;
            word-wrap: break-word;
            overflow-wrap: anywhere;
            background: var(--bg);
            position: relative;
            transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
        }

        /* --- Rich content inside chat bubbles --- */
        .message-content > *:first-child { margin-top: 0; }
        .message-content > *:last-child { margin-bottom: 0; }
        .message-content p { margin: 0 0 10px; }
        .message-content h2,
        .message-content h3,
        .message-content h4 {
            margin: 14px 0 6px;
            font-weight: 800;
            color: var(--text);
            line-height: 1.3;
            letter-spacing: -0.01em;
        }
        .message-content h2 { font-size: 1.1rem; }
        .message-content h3 { font-size: 1rem; }
        .message-content h4 { font-size: 0.94rem; }
        .message.user .message-content h2,
        .message.user .message-content h3,
        .message.user .message-content h4 { color: #fff; }
        .message-content ul,
        .message-content ol {
            margin: 6px 0 10px;
            padding-left: 22px;
        }
        .message-content ul { list-style: disc; }
        .message-content ol { list-style: decimal; }
        .message-content li {
            margin-bottom: 4px;
            line-height: 1.55;
            padding-left: 2px;
        }
        .message-content li::marker { color: var(--text-light); }
        .message-content li > p { margin: 0; }
        .message-content li ul,
        .message-content li ol { margin: 4px 0 4px; }
        .message-content blockquote {
            margin: 8px 0;
            padding: 6px 12px;
            border-left: 3px solid var(--border-strong);
            color: var(--text-light);
            background: var(--bg-soft);
            border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
        }
        .message-content code {
            font-family: 'SF Mono', Menlo, Monaco, Consolas, 'Courier New', monospace;
            background: var(--accent-bg);
            padding: 1px 6px;
            border-radius: 4px;
            font-size: 0.85em;
            border: 1px solid var(--border);
        }
        .message-content pre {
            background: var(--accent-bg);
            padding: 12px 14px;
            border-radius: var(--radius-sm);
            overflow-x: auto;
            margin: 10px 0;
            border: 1px solid var(--border);
        }
        .message-content pre code {
            background: transparent;
            border: none;
            padding: 0;
            font-size: 0.82rem;
            display: block;
            white-space: pre;
            line-height: 1.55;
        }
        .message-content hr {
            border: none;
            height: 1px;
            background: var(--border);
            margin: 14px 0;
        }
        .message-content a {
            color: var(--primary);
            text-decoration: underline;
            text-underline-offset: 2px;
        }
        .message-content strong { font-weight: 700; }
        .message-content em { font-style: italic; }

        /* User-bubble overrides (dark bg) */
        .message.user .message-content code,
        .message.user .message-content pre {
            background: rgba(255,255,255,0.14);
            border-color: rgba(255,255,255,0.2);
            color: #fff;
        }
        .message.user .message-content a { color: #fff; }
        .message.user .message-content blockquote {
            border-left-color: rgba(255,255,255,0.45);
            color: rgba(255,255,255,0.92);
            background: rgba(255,255,255,0.08);
        }
        .message.user .message-content h4 { color: rgba(255,255,255,0.85); }
        .message.user .message-content li::marker { color: rgba(255,255,255,0.6); }

        .message-content:hover {
            transform: translateY(-2px);
            box-shadow: var(--shadow-sm);
            border-color: var(--border-strong);
        }

        .rtl-interface .message-content {
            direction: rtl;
            text-align: right;
            unicode-bidi: plaintext;
        }

        .message.user .message-content {
            background: var(--primary);
            color: white;
            border-color: var(--primary);
            border-bottom-right-radius: 4px;
        }

        .message.bot .message-content {
            background: var(--bg-soft);
            border-bottom-left-radius: 4px;
        }

        .message-meta {
            font-size: 0.62rem;
            color: var(--text-lighter);
            margin-top: 4px;
            text-transform: uppercase;
            font-weight: 600;
            letter-spacing: 0.5px;
            padding: 0 4px;
            display: inline-flex;
            align-items: center;
            gap: 5px;
            line-height: 1;
        }

        /* Tiny robot-face mark that replaces the "MAGNET AI" label under bot answers */
        .message-meta .msg-bot-mark {
            width: 16px;
            height: 16px;
            color: var(--accent);
            opacity: 0.9;
            flex-shrink: 0;
            transition: transform 0.2s var(--ease-out);
        }
        .message-meta .msg-bot-mark:hover {
            transform: scale(1.15) rotate(-4deg);
            opacity: 1;
        }
        /* Tiny gray Magnet wordmark logo */
        .message-meta .msg-bot-wordmark {
            height: 12px;
            width: auto;
            color: #9ca3af;
            opacity: 0.75;
            flex-shrink: 0;
            transition: opacity 0.18s, color 0.18s;
        }
        [data-theme="dark"] .message-meta .msg-bot-wordmark { color: #6b7280; opacity: 0.85; }
        .message-meta .msg-bot-wordmark:hover { opacity: 1; color: var(--text-light); }

        .message-meta .msg-bot-tag {
            font-size: 0.58rem;
            font-weight: 700;
            color: var(--text-lighter);
            letter-spacing: 0.6px;
            padding-left: 4px;
            border-left: 1px solid var(--border-strong);
        }

        .message-actions {
            display: flex;
            opacity: 0;
            gap: 4px;
            margin-top: 4px;
            flex-wrap: wrap;
            transition: opacity 0.15s;
        }

        .message:hover .message-actions,
        .message-actions.active {
            opacity: 1;
        }

        @media (hover: none) {
            .message-actions {
                opacity: 1;
            }
        }

        .rtl-interface .message.user {
            align-self: flex-start;
            align-items: flex-start;
        }

        .rtl-interface .message.bot {
            align-self: flex-end;
            align-items: flex-end;
        }

        .rtl-interface .message-actions {
            flex-direction: row-reverse;
        }

        .action-btn {
            font-size: 0.75rem;
            padding: 4px 8px;
            background: transparent;
            border: 1px solid var(--border);
            cursor: pointer;
            border-radius: var(--radius-sm);
            color: var(--text-light);
            transition: all 0.15s;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            min-width: 28px;
            height: 26px;
        }

        .action-btn:hover {
            background: var(--accent-bg);
            color: var(--text);
            border-color: var(--border-strong);
        }

        .action-btn.save-brain-btn.saved {
            background: var(--success);
            color: #fff;
            border-color: var(--success);
        }

        .action-btn.save-brain-btn.saved:hover {
            background: var(--success);
            color: #fff;
        }

        /* --- Empty State --- */
        .empty-state {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            flex: 1;
            color: var(--text-lighter);
            text-align: center;
            padding: 40px 20px;
        }

        .empty-state svg {
            width: 48px;
            height: 48px;
            stroke-width: 1.5;
            margin-bottom: 12px;
            opacity: 0.5;
        }

        /* Brand logo featured large on the welcome screen */
        .empty-state .brand-logo-hero {
            height: 36px;
            width: auto;
            color: var(--text);
            margin-bottom: 22px;
            opacity: 0;
            animation: empty-fade-in 0.45s var(--ease-out) 0.05s forwards;
        }
        @media (max-width: 600px) {
            .empty-state .brand-logo-hero { height: 28px; margin-bottom: 18px; }
        }

        /* Big animated welcome robot — same identity as .robot-search, scaled up + idle gestures */
        .empty-state .robot-welcome {
            width: 92px;
            height: 92px;
            opacity: 1;
            margin-bottom: 18px;
            color: var(--accent);
            animation: robot-bob 2.4s ease-in-out infinite;
            transform-origin: 50% 80%;
            overflow: visible;
            filter: drop-shadow(0 6px 18px rgba(var(--accent-rgb), 0.28));
        }
        .empty-state .robot-welcome .robot-antenna-dot {
            transform-origin: 16px 3px;
            animation: robot-blink 1.4s ease-in-out infinite;
        }
        .empty-state .robot-welcome .robot-eye {
            transform-origin: center;
            animation: robot-eye-idle 3.2s ease-in-out infinite;
        }
        .empty-state .robot-welcome .robot-eye-right { animation-delay: 0.18s; }
        .empty-state .robot-welcome .robot-mouth {
            fill: none;
            stroke: currentColor;
            stroke-width: 1.6;
            stroke-linecap: round;
            animation: robot-smile 3s ease-in-out infinite;
        }

        /* Slower idle eye movement — looks around like waiting */
        @keyframes robot-eye-idle {
            0%, 30%, 100% { transform: translateX(0); }
            45%           { transform: translateX(-1.4px); }
            60%, 75%      { transform: translateX(1.4px); }
        }

        /* Animated waiting bubble next to the robot */
        .empty-state .robot-bubble {
            position: relative;
            display: inline-flex;
            align-items: center;
            gap: 6px;
            background: var(--bg);
            border: 1px solid var(--border);
            border-radius: 999px;
            padding: 8px 14px;
            margin: 0 0 14px;
            box-shadow: var(--elev-1);
            color: var(--text-light);
            font-size: 0.78rem;
            font-weight: 500;
            animation: bubble-float 3s ease-in-out infinite;
        }
        .empty-state .robot-bubble::before {
            content: '';
            position: absolute;
            left: 50%;
            top: -6px;
            transform: translateX(-50%) rotate(45deg);
            width: 10px;
            height: 10px;
            background: var(--bg);
            border-left: 1px solid var(--border);
            border-top: 1px solid var(--border);
        }
        .empty-state .robot-bubble .bubble-dot {
            width: 5px;
            height: 5px;
            border-radius: 50%;
            background: var(--accent);
            animation: bubble-dot 1.4s ease-in-out infinite;
        }
        .empty-state .robot-bubble .bubble-dot:nth-child(2) { animation-delay: 0.2s; }
        .empty-state .robot-bubble .bubble-dot:nth-child(3) { animation-delay: 0.4s; }

        @keyframes bubble-float {
            0%, 100% { transform: translateY(0); }
            50%      { transform: translateY(-3px); }
        }
        @keyframes bubble-dot {
            0%, 80%, 100% { transform: scale(1);   opacity: 0.4; }
            40%           { transform: scale(1.5); opacity: 1; }
        }

        /* Welcome heading nudge */
        .empty-state h3 { font-size: 1.4rem !important; margin-bottom: 6px !important; }
        .empty-state p  { font-size: 0.88rem; }

        .empty-state h3 {
            font-size: 0.95rem;
            font-weight: 600;
            color: var(--text);
            margin-bottom: 4px;
        }

        .empty-state p {
            font-size: 0.8rem;
        }

        /* --- Input Area --- */
        .input-container {
            padding: 12px 16px 16px;
            background: var(--bg);
            border-top: 1px solid var(--border);
            flex-shrink: 0;
        }

        .mention-preview {
            background: var(--accent-bg);
            border: 1px solid var(--border);
            padding: 8px 12px;
            display: none;
            justify-content: space-between;
            align-items: center;
            font-size: 0.75rem;
            margin-bottom: 8px;
            border-radius: var(--radius-sm);
            border-left: 3px solid var(--primary);
        }

        .mention-preview.active {
            display: flex;
        }

        .mention-text {
            color: var(--text-light);
            flex: 1;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .input-wrapper {
            display: flex;
            gap: 8px;
            align-items: flex-end;
            background: var(--bg-soft);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            padding: 8px;
            transition: border-color 0.15s;
        }

        .input-wrapper:focus-within {
            border-color: var(--primary);
        }

        #userInput {
            flex: 1;
            border: none;
            padding: 6px 8px;
            font-size: 0.9rem;
            outline: none;
            resize: none;
            max-height: 120px;
            min-height: 24px;
            background: transparent;
            color: var(--text);
        }

        #userInput::placeholder {
            color: var(--text-lighter);
        }

        #sendBtn {
            background: var(--primary);
            color: white;
            border: none;
            width: 36px;
            height: 36px;
            border-radius: 8px;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.15s;
            flex-shrink: 0;
        }

        #sendBtn:hover:not(:disabled) {
            background: var(--primary-hover);
        }

        #sendBtn:disabled {
            opacity: 0.4;
            cursor: not-allowed;
        }

        /* --- Describe Image modal --- */
        .describe-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 16px;
        }
        @media (max-width: 720px) { .describe-grid { grid-template-columns: 1fr; } }

        .describe-image-pane, .describe-meta-pane {
            display: flex;
            flex-direction: column;
            gap: 10px;
            min-width: 0;
        }

        .describe-image-frame {
            background: var(--bg-soft);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            overflow: hidden;
            display: flex;
            align-items: center;
            justify-content: center;
            min-height: 220px;
            max-height: 340px;
        }
        .describe-image-frame img {
            max-width: 100%;
            max-height: 340px;
            object-fit: contain;
            display: block;
        }

        .describe-meta-section {
            background: var(--bg-soft);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            padding: 12px 14px;
        }

        .describe-meta-title {
            font-size: 0.72rem;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            color: var(--text-light);
            margin-bottom: 8px;
        }

        .describe-meta-list {
            display: grid;
            grid-template-columns: 110px 1fr;
            gap: 6px 12px;
            font-size: 0.78rem;
            margin: 0;
        }
        .describe-meta-list dt {
            color: var(--text-light);
            font-weight: 600;
        }
        .describe-meta-list dd {
            color: var(--text);
            margin: 0;
            word-break: break-word;
        }

        .describe-actions {
            display: flex;
            flex-direction: column;
            gap: 8px;
        }

        .describe-question-label {
            font-size: 0.72rem;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            color: var(--text-light);
        }

        #describeQuestion {
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            padding: 10px 12px;
            font-size: 0.85rem;
            font-family: inherit;
            background: var(--bg);
            color: var(--text);
            outline: none;
        }
        #describeQuestion:focus { border-color: var(--primary); }

        /* User message image attachment (shown in chat when user sends image for description) */
        .chat-image-attachment {
            margin-bottom: 6px;
            max-width: 280px;
            border-radius: var(--radius-sm);
            overflow: hidden;
            background: var(--bg-soft);
            border: 1px solid var(--border);
        }
        .chat-image-attachment img {
            width: 100%;
            display: block;
            object-fit: cover;
            max-height: 240px;
        }
        .chat-image-attachment .attachment-meta {
            font-size: 0.7rem;
            color: var(--text-light);
            padding: 6px 10px;
            border-top: 1px solid var(--border);
            background: var(--bg-soft);
        }
        .chat-image-attachment .attachment-meta b { color: var(--text); }

        /* --- OCR camera button (next to chat input) --- */
        .ocr-btn {
            background: var(--bg);
            color: var(--text-light);
            border: 1px solid var(--border);
            width: 36px;
            height: 36px;
            border-radius: 8px;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.15s;
            flex-shrink: 0;
        }
        .ocr-btn:hover { background: var(--accent-bg); color: var(--text); border-color: var(--border-strong); }
        .ocr-btn:active { transform: scale(0.94); }
        .ocr-btn svg { width: 18px; height: 18px; }

        /* Interim transcript ghost text removed (Web Speech API removed) */

        /* --- OCR Modal layout --- */
        .ocr-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 16px;
        }
        @media (max-width: 720px) { .ocr-grid { grid-template-columns: 1fr; } }

        .ocr-image-pane, .ocr-text-pane {
            display: flex;
            flex-direction: column;
            gap: 10px;
            min-width: 0;
        }

        .ocr-image-frame {
            position: relative;
            background: var(--bg-soft);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            overflow: hidden;
            min-height: 200px;
            max-height: 360px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .ocr-image-frame img {
            max-width: 100%;
            max-height: 360px;
            object-fit: contain;
            display: block;
        }

        .ocr-progress {
            position: absolute;
            inset: 0;
            background: rgba(255, 255, 255, 0.92);
            display: none;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 10px;
            padding: 20px;
        }
        [data-theme="dark"] .ocr-progress { background: rgba(11, 13, 16, 0.92); }
        .ocr-progress.active { display: flex; }

        .ocr-progress-spinner {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            border: 3px solid var(--border);
            border-top-color: var(--primary);
            animation: ocr-spin 0.8s linear infinite;
        }
        @keyframes ocr-spin { to { transform: rotate(360deg); } }

        .ocr-progress-label {
            font-size: 0.82rem;
            color: var(--text);
            font-weight: 600;
        }
        .ocr-progress-bar {
            width: 80%;
            max-width: 240px;
            height: 6px;
            background: var(--border);
            border-radius: 999px;
            overflow: hidden;
        }
        .ocr-progress-fill {
            height: 100%;
            width: 0%;
            background: var(--primary);
            border-radius: 999px;
            transition: width 0.25s ease;
        }
        .ocr-progress-percent {
            font-size: 0.78rem;
            font-weight: 700;
            color: var(--text-light);
            font-variant-numeric: tabular-nums;
        }

        .ocr-meta {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 8px;
            flex-wrap: wrap;
        }
        .ocr-lang-label {
            font-size: 0.78rem;
            color: var(--text-light);
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .ocr-lang-label select {
            border: 1px solid var(--border);
            background: var(--bg);
            color: var(--text);
            border-radius: var(--radius-sm);
            padding: 5px 8px;
            font-size: 0.78rem;
            font-family: inherit;
            outline: none;
        }

        .ocr-text-label {
            font-size: 0.78rem;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            color: var(--text-light);
        }
        .ocr-confidence {
            margin-left: 8px;
            font-size: 0.72rem;
            font-weight: 600;
            color: var(--success);
            text-transform: none;
            letter-spacing: 0;
        }
        .ocr-confidence.warn { color: #d97706; }
        .ocr-confidence.bad  { color: var(--danger); }

        #ocrResult {
            flex: 1;
            min-height: 180px;
            max-height: 360px;
            resize: vertical;
            border: 1px solid var(--border);
            border-radius: var(--radius);
            padding: 12px;
            font-size: 0.85rem;
            line-height: 1.55;
            font-family: 'SF Mono', Menlo, Consolas, monospace;
            background: var(--bg);
            color: var(--text);
            outline: none;
            white-space: pre-wrap;
            word-break: break-word;
        }
        #ocrResult:focus { border-color: var(--primary); }

        .ocr-actions {
            display: flex;
            gap: 8px;
            flex-wrap: wrap;
            justify-content: flex-end;
        }

        /* --- Slash command menu (above the input) --- */
        .slash-menu {
            position: relative;
            background: var(--bg);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            box-shadow: var(--shadow-md);
            margin: 0 6px 8px;
            padding: 6px;
            display: flex;
            flex-direction: column;
            gap: 2px;
            animation: slash-pop 0.14s ease-out;
            transform-origin: bottom left;
        }
        /* Force-hide overrides the .slash-menu display rule */
        .slash-menu[hidden],
        .intent-chip[hidden],
        .persona-chip[hidden] { display: none !important; }

        /* --- Active persona chip (sits next to the intent chip above the input) --- */
        .persona-chip {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            background: var(--accent-soft);
            border: 1px solid var(--accent);
            border-radius: 999px;
            padding: 5px 6px 5px 12px;
            margin: 0 6px 6px;
            width: fit-content;
            font-size: 0.78rem;
            font-weight: 600;
            color: var(--accent);
            animation: intent-chip-in 0.18s ease-out;
        }
        .persona-chip-icon { font-size: 0.95rem; line-height: 1; }
        .persona-chip-label { white-space: nowrap; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
        .persona-chip-close {
            background: var(--bg);
            border: 1px solid var(--border);
            color: var(--text-light);
            width: 20px;
            height: 20px;
            border-radius: 50%;
            cursor: pointer;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            transition: background 0.12s, color 0.12s, border-color 0.12s;
            flex-shrink: 0;
        }
        .persona-chip-close:hover {
            background: var(--danger);
            color: #fff;
            border-color: var(--danger);
        }

        @keyframes slash-pop {
            from { opacity: 0; transform: translateY(8px) scale(0.96); }
            to   { opacity: 1; transform: translateY(0)   scale(1); }
        }

        .slash-menu-header {
            font-size: 0.65rem;
            font-weight: 700;
            color: var(--text-lighter);
            text-transform: uppercase;
            letter-spacing: 0.6px;
            padding: 4px 10px 6px;
        }

        .slash-item {
            background: transparent;
            border: none;
            padding: 8px 10px;
            display: flex;
            align-items: center;
            gap: 12px;
            cursor: pointer;
            border-radius: var(--radius-sm);
            text-align: left;
            font-family: inherit;
            color: var(--text);
            transition: background 0.1s;
        }

        .slash-item:hover, .slash-item.active {
            background: var(--accent-bg);
        }

        .slash-item-icon {
            line-height: 1;
            flex-shrink: 0;
            width: 30px;
            height: 30px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            background: var(--bg-soft);
            border-radius: 8px;
            color: var(--text);
        }
        .slash-item-icon svg { width: 16px; height: 16px; }

        .slash-item-body {
            display: flex;
            flex-direction: column;
            gap: 1px;
            min-width: 0;
        }

        .slash-item-title {
            font-size: 0.85rem;
            font-weight: 600;
            color: var(--text);
        }

        .slash-item-hint {
            font-size: 0.72rem;
            color: var(--text-light);
        }

        /* --- Active intent chip --- */
        .intent-chip {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            background: var(--bg-soft);
            border: 1px solid var(--border-strong);
            border-radius: 999px;
            padding: 5px 6px 5px 12px;
            margin: 0 6px 6px;
            width: fit-content;
            font-size: 0.78rem;
            font-weight: 600;
            color: var(--text);
            animation: intent-chip-in 0.18s ease-out;
        }

        @keyframes intent-chip-in {
            from { opacity: 0; transform: translateY(4px); }
            to   { opacity: 1; transform: translateY(0); }
        }

        .intent-chip-icon {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 16px;
            height: 16px;
            color: var(--text);
        }
        .intent-chip-icon svg { width: 14px; height: 14px; }

        .intent-chip-close {
            background: var(--bg);
            border: 1px solid var(--border);
            color: var(--text-light);
            width: 20px;
            height: 20px;
            border-radius: 50%;
            cursor: pointer;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            transition: background 0.12s, color 0.12s;
        }

        .intent-chip-close:hover {
            background: var(--accent-bg);
            color: var(--text);
        }

        /* --- AI Data Table embedded in bot messages --- */
        .ai-table-wrapper {
            margin-top: 10px;
            border: 1px solid var(--border);
            border-radius: var(--radius);
            overflow-x: auto;
            background: var(--bg);
        }

        .ai-table {
            border-collapse: collapse;
            width: 100%;
            font-size: 0.83rem;
        }

        .ai-table th {
            background: var(--bg-soft);
            color: var(--text);
            font-weight: 700;
            text-align: left;
            padding: 9px 12px;
            border-bottom: 1.5px solid var(--border-strong);
            white-space: nowrap;
        }

        .ai-table td {
            padding: 8px 12px;
            border-bottom: 1px solid var(--border);
            color: var(--text);
            vertical-align: top;
        }

        .ai-table tr:last-child td { border-bottom: none; }
        .ai-table tr:nth-child(even) td { background: var(--bg-soft); }
        .ai-table tr:hover td { background: var(--accent-bg); }

        /* --- AI Chart card --- */
        .ai-chart {
            margin-top: 10px;
            border: 1px solid var(--border);
            border-radius: var(--radius);
            overflow: hidden;
            background: var(--bg);
        }
        .ai-chart-header {
            padding: 10px 14px;
            background: var(--bg-soft);
            border-bottom: 1px solid var(--border);
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 8px;
        }
        .ai-chart-title {
            font-size: 0.9rem;
            font-weight: 700;
            color: var(--text);
        }
        .ai-chart-type {
            font-size: 0.68rem;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.6px;
            color: var(--accent);
            background: var(--accent-soft);
            padding: 3px 9px;
            border-radius: 999px;
        }
        .ai-chart-body {
            padding: 14px;
            position: relative;
            height: 320px;
        }
        .ai-chart-body canvas { max-width: 100%; max-height: 100%; }
        .ai-chart-error { padding: 14px; font-size: 0.8rem; color: var(--danger); text-align: center; }

        /* --- AI Map card --- */
        .ai-map {
            margin-top: 10px;
            border: 1px solid var(--border);
            border-radius: var(--radius);
            overflow: hidden;
            background: var(--bg);
        }
        .ai-map-header {
            padding: 10px 14px;
            background: var(--bg-soft);
            border-bottom: 1px solid var(--border);
            font-size: 0.75rem;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            color: var(--text-light);
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .ai-map-list {
            display: flex;
            flex-direction: column;
            gap: 0;
        }
        .ai-map-item {
            padding: 12px 14px;
            border-bottom: 1px solid var(--border);
            display: grid;
            grid-template-columns: 1fr auto;
            gap: 6px 12px;
            align-items: start;
        }
        .ai-map-item:last-child { border-bottom: none; }

        .ai-map-name {
            font-size: 0.92rem;
            font-weight: 700;
            color: var(--text);
            grid-column: 1 / 2;
            line-height: 1.3;
        }
        .ai-map-address {
            font-size: 0.78rem;
            color: var(--text-light);
            grid-column: 1 / 2;
            line-height: 1.4;
            display: flex;
            gap: 6px;
            align-items: flex-start;
        }
        .ai-map-address svg { flex-shrink: 0; margin-top: 2px; color: var(--accent); }
        .ai-map-desc {
            font-size: 0.78rem;
            color: var(--text);
            grid-column: 1 / -1;
            line-height: 1.45;
            opacity: 0.85;
            margin-top: 2px;
        }
        .ai-map-actions {
            grid-column: 2 / 3;
            grid-row: 1 / 4;
            display: flex;
            flex-direction: column;
            gap: 6px;
            align-items: flex-end;
            white-space: nowrap;
        }
        .ai-map-btn {
            display: inline-flex;
            align-items: center;
            gap: 5px;
            background: var(--accent);
            color: #fff;
            text-decoration: none;
            font-size: 0.75rem;
            font-weight: 600;
            padding: 6px 10px;
            border-radius: 8px;
            transition: background 0.12s;
        }
        .ai-map-btn:hover { background: var(--accent-2); color: #fff; }
        .ai-map-btn.secondary {
            background: var(--bg-soft);
            color: var(--text);
            border: 1px solid var(--border);
        }
        .ai-map-btn.secondary:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
        .ai-map-coords {
            font-family: 'SF Mono', Menlo, monospace;
            font-size: 0.7rem;
            color: var(--text-lighter);
            grid-column: 1 / 2;
            margin-top: 2px;
        }

        /* --- AI Calculation card --- */
        .ai-calc {
            margin-top: 10px;
            border: 1px solid var(--border);
            border-radius: var(--radius);
            background: var(--bg);
            overflow: hidden;
        }

        .ai-calc-header {
            padding: 10px 14px;
            background: var(--bg-soft);
            border-bottom: 1px solid var(--border);
            font-size: 0.75rem;
            color: var(--text-light);
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .ai-calc-body {
            padding: 12px 14px;
            font-family: 'SF Mono', Menlo, Monaco, Consolas, 'Courier New', monospace;
        }

        .ai-calc-expression {
            font-size: 0.95rem;
            color: var(--text-light);
            margin-bottom: 8px;
            word-wrap: break-word;
        }

        .ai-calc-result {
            font-size: 1.4rem;
            font-weight: 700;
            color: var(--text);
            padding: 8px 0;
            border-top: 1px dashed var(--border);
            border-bottom: 1px dashed var(--border);
            margin: 8px 0;
        }

        .ai-calc-steps {
            font-size: 0.8rem;
            color: var(--text-light);
            list-style: none;
            padding: 0;
            margin-top: 8px;
        }

        .ai-calc-steps li {
            padding: 3px 0;
            border-left: 2px solid var(--border);
            padding-left: 10px;
            margin-bottom: 2px;
        }

        /* --- Mind map embedded in bot messages --- */
        .ai-mindmap {
            margin-top: 12px;
            padding: 16px;
            background: var(--bg-soft);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            overflow-x: auto;
        }

        .ai-mindmap-tree {
            display: flex;
            align-items: center;
            min-width: max-content;
            gap: 12px;
        }

        .ai-mindmap-node {
            background: var(--bg);
            border: 1.5px solid var(--border-strong);
            border-radius: 999px;
            padding: 8px 14px;
            font-size: 0.83rem;
            font-weight: 600;
            color: var(--text);
            white-space: nowrap;
            box-shadow: var(--shadow-sm);
            position: relative;
            transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
            /* Sequential build-up animation — each node gets a unique --mm-i index from JS */
            opacity: 0;
            transform: scale(0.6);
            animation: mm-node-pop 0.42s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
            animation-delay: calc(var(--mm-i, 0) * 90ms);
        }

        @keyframes mm-node-pop {
            0%   { opacity: 0; transform: scale(0.55) translateY(4px); }
            60%  { opacity: 1; transform: scale(1.08) translateY(0); }
            100% { opacity: 1; transform: scale(1) translateY(0); }
        }

        /* The root node deserves a slightly stronger entrance */
        .ai-mindmap-root {
            animation-name: mm-root-pop !important;
            animation-duration: 0.5s !important;
        }
        @keyframes mm-root-pop {
            0%   { opacity: 0; transform: scale(0.4) rotate(-6deg); }
            60%  { opacity: 1; transform: scale(1.12) rotate(2deg); }
            100% { opacity: 1; transform: scale(1) rotate(0); }
        }

        .ai-mindmap-node:hover {
            transform: translateY(-1px);
            box-shadow: var(--shadow-md);
        }

        /* Levels */
        .ai-mindmap-root {
            background: var(--primary);
            color: var(--bg);
            border-color: var(--primary);
            font-size: 0.92rem;
            padding: 10px 18px;
        }
        [data-theme="dark"] .ai-mindmap-root { color: #0b0d10; }

        .ai-mindmap-l1 {
            background: var(--accent-bg);
            border-color: var(--border-strong);
        }

        .ai-mindmap-l2 {
            background: var(--bg);
            font-size: 0.78rem;
            font-weight: 500;
            padding: 6px 12px;
            color: var(--text-light);
        }

        /* The branch container holds children stacked vertically + connector lines */
        .ai-mindmap-branch {
            display: flex;
            align-items: center;
            position: relative;
        }

        .ai-mindmap-children {
            display: flex;
            flex-direction: column;
            gap: 8px;
            margin-left: 24px;
            position: relative;
        }

        .ai-mindmap-child {
            display: flex;
            align-items: center;
            position: relative;
        }

        /* Horizontal line from parent to each child — drawn left→right with a slight delay */
        .ai-mindmap-child::before {
            content: '';
            position: absolute;
            left: -24px;
            top: 50%;
            width: 24px;
            height: 1.5px;
            background: var(--border-strong);
            transform-origin: left center;
            transform: scaleX(0);
            animation: mm-line-draw 0.28s ease-out forwards;
            animation-delay: calc(var(--mm-i, 0) * 90ms + 60ms);
        }

        /* Vertical line connecting all children of a parent — grows from the top */
        .ai-mindmap-children::before {
            content: '';
            position: absolute;
            left: 0;
            top: 14px;
            bottom: 14px;
            width: 1.5px;
            background: var(--border-strong);
            transform-origin: top center;
            transform: scaleY(0);
            animation: mm-line-grow 0.32s ease-out forwards;
            animation-delay: calc(var(--mm-parent-i, 0) * 90ms + 80ms);
        }

        @keyframes mm-line-draw {
            from { transform: scaleX(0); }
            to   { transform: scaleX(1); }
        }
        @keyframes mm-line-grow {
            from { transform: scaleY(0); }
            to   { transform: scaleY(1); }
        }

        /* Hide the vertical line if there's only one child */
        .ai-mindmap-children.single-child::before { display: none; }

        /* For a single child, just extend the horizontal line */
        .ai-mindmap-children.single-child .ai-mindmap-child::before {
            left: -24px;
            width: 24px;
        }

        /* Inline thumbnail inside a mind-map node (used by History mode) */
        .ai-mindmap-node .mm-thumb {
            width: 28px;
            height: 28px;
            border-radius: 6px;
            object-fit: cover;
            margin-right: 8px;
            vertical-align: middle;
            background: var(--bg-soft);
            border: 1px solid var(--border);
        }

        /* User / bot sender styling for history nodes */
        .ai-mindmap-node.mm-node-user {
            border-left: 3px solid #6366f1;
            background: var(--bg);
        }
        .ai-mindmap-node.mm-node-bot {
            border-left: 3px solid #10b981;
            background: var(--bg);
        }

        /* Color tint each branch differently for visual variety */
        .ai-mindmap-color-0 { border-left: 3px solid #6366f1; }
        .ai-mindmap-color-1 { border-left: 3px solid #ec4899; }
        .ai-mindmap-color-2 { border-left: 3px solid #10b981; }
        .ai-mindmap-color-3 { border-left: 3px solid #f59e0b; }
        .ai-mindmap-color-4 { border-left: 3px solid #06b6d4; }
        .ai-mindmap-color-5 { border-left: 3px solid #8b5cf6; }

        .ai-mindmap-error {
            padding: 12px;
            font-size: 0.78rem;
            color: var(--danger);
            text-align: center;
        }

        .ai-mindmap-toolbar {
            display: flex;
            justify-content: flex-end;
            gap: 6px;
            margin-bottom: 10px;
        }

        .ai-mindmap-toolbar button {
            background: var(--bg);
            border: 1px solid var(--border);
            color: var(--text-light);
            font-size: 0.72rem;
            font-weight: 600;
            padding: 5px 10px;
            border-radius: var(--radius-sm);
            cursor: pointer;
            display: inline-flex;
            align-items: center;
            gap: 4px;
            transition: all 0.12s;
        }

        .ai-mindmap-toolbar button:hover {
            background: var(--accent-bg);
            color: var(--text);
            border-color: var(--border-strong);
        }

        /* --- Image gallery embedded in bot messages --- */
        .ai-image-gallery {
            margin-top: 10px;
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
            gap: 6px;
            border-radius: var(--radius);
            overflow: hidden;
        }

        .ai-image-gallery .ai-image-tile {
            position: relative;
            aspect-ratio: 1 / 1;
            background: var(--accent-bg);
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            overflow: hidden;
            cursor: zoom-in;
            transition: transform 0.18s ease, box-shadow 0.18s ease;
        }

        .ai-image-gallery .ai-image-tile:hover {
            transform: translateY(-2px);
            box-shadow: var(--shadow-md);
        }

        .ai-image-gallery .ai-image-tile img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            display: block;
            background: var(--accent-bg);
        }

        .ai-image-gallery .ai-image-loading,
        .ai-image-gallery .ai-image-error {
            grid-column: 1 / -1;
            padding: 14px;
            text-align: center;
            font-size: 0.78rem;
            color: var(--text-light);
            border: 1px dashed var(--border);
            border-radius: var(--radius-sm);
        }

        .ai-image-gallery .ai-image-source {
            font-size: 0.72rem;
            color: var(--text-light);
            margin-top: 6px;
            grid-column: 1 / -1;
        }

        /* Lightbox overlay */
        .ai-lightbox {
            position: fixed;
            inset: 0;
            background: rgba(0, 0, 0, 0.86);
            z-index: 4000;
            display: none;
            align-items: center;
            justify-content: center;
            padding: 20px;
            cursor: zoom-out;
            animation: fadeIn 0.18s ease;
        }
        .ai-lightbox.active { display: flex; }
        .ai-lightbox img {
            max-width: 96vw;
            max-height: 92vh;
            object-fit: contain;
            border-radius: 8px;
            box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
        }
        .ai-lightbox-close {
            position: absolute;
            top: 16px;
            right: 16px;
            width: 36px;
            height: 36px;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.12);
            color: #fff;
            border: none;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            backdrop-filter: blur(6px);
        }
        .ai-lightbox-close:hover { background: rgba(255, 255, 255, 0.22); }

        /* --- AI Choice Sheet (rises from above the chatbox) --- */
        .choice-sheet {
            position: fixed;
            left: 0;
            right: 0;
            bottom: 0;
            z-index: 1500;
            display: flex;
            justify-content: center;
            pointer-events: none;
            padding: 0 14px 8px;
        }

        .choice-sheet-inner {
            width: 100%;
            max-width: 720px;
            background: var(--bg);
            border: 1px solid var(--border);
            border-radius: 16px 16px 12px 12px;
            box-shadow: 0 -10px 32px rgba(0, 0, 0, 0.10), 0 -2px 6px rgba(0, 0, 0, 0.04);
            transform: translateY(110%);
            opacity: 0;
            visibility: hidden;
            transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.22s ease, visibility 0s linear 0.32s;
            pointer-events: none;
            overflow: hidden;
            margin-bottom: 96px; /* sit just above the input bar */
        }

        [data-theme="dark"] .choice-sheet-inner {
            box-shadow: 0 -12px 36px rgba(0, 0, 0, 0.55), 0 -2px 6px rgba(0, 0, 0, 0.35);
        }

        .choice-sheet.active .choice-sheet-inner {
            transform: translateY(0);
            opacity: 1;
            visibility: visible;
            pointer-events: auto;
            transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.22s ease, visibility 0s;
        }

        .choice-sheet-header {
            position: relative;
            padding: 14px 44px 10px 18px;
            border-bottom: 1px solid var(--border);
        }

        .choice-sheet-grabber {
            display: block;
            width: 36px;
            height: 4px;
            background: var(--border-strong);
            border-radius: 999px;
            margin: 0 auto 10px;
            opacity: 0.7;
        }

        .choice-sheet-question {
            font-size: 0.9rem;
            font-weight: 600;
            color: var(--text);
            line-height: 1.45;
        }

        .choice-sheet-close {
            position: absolute;
            top: 12px;
            right: 10px;
            width: 28px;
            height: 28px;
            border: none;
            background: transparent;
            color: var(--text-light);
            border-radius: 8px;
            cursor: pointer;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            transition: background 0.12s, color 0.12s;
        }

        .choice-sheet-close:hover {
            background: var(--accent-bg);
            color: var(--text);
        }

        .choice-sheet-list {
            display: flex;
            flex-direction: column;
            max-height: 50vh;
            overflow-y: auto;
            background: var(--bg);
        }

        .choice-sheet-list .choice-btn {
            background: var(--bg);
            border: none;
            border-bottom: 1px solid var(--border);
            padding: 13px 18px;
            font-size: 0.88rem;
            font-weight: 500;
            cursor: pointer;
            text-align: left;
            color: var(--text);
            transition: background 0.12s, padding-left 0.18s;
            display: flex;
            align-items: center;
            gap: 12px;
            font-family: inherit;
            line-height: 1.4;
        }

        .choice-sheet-list .choice-btn:last-child { border-bottom: none; }

        .choice-sheet-list .choice-btn:hover {
            background: var(--accent-bg);
            padding-left: 22px;
        }

        .choice-sheet-list .choice-btn:active {
            background: var(--border);
        }

        .choice-sheet-list .choice-btn .choice-letter {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 24px;
            height: 24px;
            border-radius: 50%;
            border: 1.5px solid var(--border-strong);
            font-size: 0.74rem;
            font-weight: 700;
            flex-shrink: 0;
            color: var(--text-light);
            transition: background 0.12s, color 0.12s, border-color 0.12s;
        }

        .choice-sheet-list .choice-btn:hover .choice-letter {
            background: var(--primary);
            color: var(--bg);
            border-color: var(--primary);
        }

        [data-theme="dark"] .choice-sheet-list .choice-btn:hover .choice-letter { color: #0b0d10; }

        .choice-sheet-custom {
            display: flex;
            gap: 8px;
            padding: 10px 12px 12px;
            background: var(--bg-soft);
            border-top: 1px solid var(--border);
        }

        .choice-sheet-custom input {
            flex: 1;
            border: 1px solid var(--border);
            border-radius: 999px;
            padding: 9px 14px;
            font-size: 0.85rem;
            font-family: inherit;
            background: var(--bg);
            color: var(--text);
            outline: none;
            transition: border-color 0.15s;
        }

        .choice-sheet-custom input:focus { border-color: var(--primary); }

        .choice-sheet-custom button {
            background: var(--primary);
            color: var(--bg);
            border: none;
            border-radius: 50%;
            width: 36px;
            height: 36px;
            cursor: pointer;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            transition: background 0.12s, transform 0.12s;
            flex-shrink: 0;
        }

        .choice-sheet-custom button:hover { background: var(--primary-hover); }
        .choice-sheet-custom button:active { transform: scale(0.94); }

        [data-theme="dark"] .choice-sheet-custom button { color: #0b0d10; }

        @media (max-width: 600px) {
            .choice-sheet-inner { margin-bottom: 88px; }
            .choice-sheet-list { max-height: 42vh; }
        }

        #sendBtn svg {
            width: 16px;
            height: 16px;
        }

        #modelMode {
            padding: 8px 10px;
            border: 1px solid var(--border);
            background: var(--bg);
            border-radius: var(--radius-sm);
            font-size: 0.75rem;
            cursor: pointer;
            font-weight: 500;
            outline: none;
            color: var(--text);
            height: 36px;
            flex-shrink: 0;
        }

        /* --- Persona Bar --- */
        .persona-bar {
            display: flex;
            align-items: center;
            gap: 8px;
            margin-bottom: 8px;
            flex-wrap: wrap;
        }

        .persona-select {
            flex: 1;
            min-width: 160px;
            padding: 8px 12px;
            border: 1px solid var(--border);
            background: var(--bg);
            border-radius: var(--radius-sm);
            font-size: 0.8rem;
            cursor: pointer;
            font-weight: 500;
            outline: none;
            color: var(--text);
            transition: border-color 0.15s;
            height: 36px;
        }

        .persona-select:focus {
            border-color: var(--primary);
        }

        .persona-badge {
            font-size: 0.7rem;
            font-weight: 600;
            color: var(--primary);
            background: var(--accent-bg);
            border: 1px solid var(--border);
            padding: 4px 10px;
            border-radius: 20px;
            white-space: nowrap;
            display: none;
        }

        .persona-badge.visible {
            display: inline-block;
        }

        .persona-extra-input {
            width: 100%;
            border: 1px solid var(--border);
            padding: 8px 12px;
            font-size: 0.8rem;
            border-radius: var(--radius-sm);
            background: var(--bg-soft);
            color: var(--text);
            outline: none;
            resize: none;
            min-height: 52px;
            max-height: 80px;
            margin-bottom: 8px;
            transition: border-color 0.15s;
            display: none;
            font-family: inherit;
        }

        .persona-extra-input.visible {
            display: block;
        }

        .persona-extra-input:focus {
            border-color: var(--primary);
        }

        .persona-extra-input::placeholder {
            color: var(--text-lighter);
        }

        /* --- Modals --- */
        .modal-overlay {
            position: fixed;
            inset: 0;
            background: rgba(0, 0, 0, 0.4);
            backdrop-filter: blur(4px);
            -webkit-backdrop-filter: blur(4px);
            z-index: 2000;
            display: none;
            align-items: center;
            justify-content: center;
            padding: 16px;
            animation: fadeIn 0.2s ease;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
            }

            to {
                opacity: 1;
            }
        }

        .modal-overlay.active {
            display: flex;
        }

        .modal-content {
            background: var(--bg);
            border: 1px solid var(--border);
            width: 100%;
            max-width: 720px;
            max-height: 90vh;
            display: flex;
            flex-direction: column;
            border-radius: var(--radius-lg);
            box-shadow: var(--shadow-md);
            overflow: hidden;
            animation: slideUp 0.25s ease;
        }

        @keyframes slideUp {
            from {
                opacity: 0;
                transform: translateY(20px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .modal-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 18px 24px;
            border-bottom: 1px solid var(--border);
            flex-shrink: 0;
        }

        .modal-header h2 {
            font-size: 1rem;
            letter-spacing: 1px;
            text-transform: uppercase;
            font-weight: 700;
        }

        .close-btn {
            background: none;
            border: none;
            cursor: pointer;
            color: var(--text-light);
            padding: 0;
            width: 32px;
            height: 32px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: var(--radius-sm);
            transition: all 0.15s;
        }

        .close-btn:hover {
            color: var(--text);
            background: var(--accent-bg);
        }

        .close-btn svg {
            width: 18px;
            height: 18px;
        }

        .modal-body {
            flex: 1;
            overflow-y: auto;
            padding: 20px 24px;
        }

        /* --- Modal Tabs (Icon-based) --- */
        .modal-tabs {
            display: flex;
            gap: 4px;
            padding: 12px 16px 0;
            border-bottom: 1px solid var(--border);
            background: var(--bg-soft);
            overflow-x: auto;
            scrollbar-width: none;
            flex-shrink: 0;
        }

        .modal-tabs::-webkit-scrollbar {
            display: none;
        }

        .modal-tab {
            background: none;
            border: none;
            padding: 10px 14px;
            font-size: 0.75rem;
            cursor: pointer;
            color: var(--text-light);
            position: relative;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
            border-bottom: 2px solid transparent;
            margin-bottom: -1px;
            transition: all 0.15s;
            font-weight: 500;
            min-width: 44px;
        }

        .modal-tab svg {
            width: 18px;
            height: 18px;
            stroke-width: 2;
        }

        .modal-tab:hover {
            color: var(--text);
        }

        .modal-tab.active {
            color: var(--text);
            border-bottom-color: var(--primary);
            font-weight: 600;
        }

        .modal-tab .tab-label {
            display: inline;
        }

        .modal-section {
            display: none;
        }

        .modal-section.active {
            display: block;
        }

        /* --- Form Elements --- */
        .form-group {
            margin-bottom: 14px;
        }

        .form-group label {
            display: block;
            font-size: 0.7rem;
            font-weight: 600;
            text-transform: uppercase;
            margin-bottom: 6px;
            color: var(--text-light);
            letter-spacing: 0.5px;
        }

        input[type="text"],
        input[type="file"],
        textarea {
            width: 100%;
            border: 1px solid var(--border);
            padding: 10px 12px;
            font-size: 0.875rem;
            outline: none;
            border-radius: var(--radius-sm);
            background: var(--bg);
            color: var(--text);
            transition: border-color 0.15s;
        }

        input[type="text"]:focus,
        textarea:focus {
            border-color: var(--primary);
        }

        textarea {
            resize: vertical;
            min-height: 90px;
            font-family: inherit;
        }

        input[type="file"] {
            padding: 8px;
            cursor: pointer;
        }

        /* --- Cards --- */
        .stat-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
            gap: 10px;
            margin-bottom: 20px;
        }

        .stat-card {
            background: var(--bg-soft);
            border: 1px solid var(--border);
            padding: 14px;
            border-radius: var(--radius);
        }

        .stat-card-label {
            font-size: 0.65rem;
            color: var(--text-light);
            margin-bottom: 6px;
            text-transform: uppercase;
            font-weight: 600;
            letter-spacing: 0.5px;
        }

        .stat-card-value {
            font-size: 1.4rem;
            font-weight: 700;
            color: var(--text);
        }

        .doc-item,
        .qa-item {
            border: 1px solid var(--border);
            padding: 14px;
            margin-bottom: 8px;
            border-radius: var(--radius);
            background: var(--bg);
            transition: all 0.15s;
        }

        .doc-item:hover,
        .qa-item:hover {
            border-color: var(--border-strong);
            background: var(--bg-soft);
        }

        .doc-item h4,
        .qa-item h4 {
            font-size: 0.875rem;
            margin-bottom: 6px;
            font-weight: 600;
        }

        .doc-item p,
        .qa-item p {
            font-size: 0.78rem;
            color: var(--text-light);
            margin-bottom: 6px;
        }

        .item-actions {
            margin-top: 8px;
            display: flex;
            gap: 6px;
        }

        /* --- Toast --- */
        .toast {
            position: fixed;
            bottom: 24px;
            left: 50%;
            transform: translateX(-50%) translateY(100px);
            padding: 12px 18px;
            background: var(--primary);
            color: white;
            font-size: 0.8rem;
            border-radius: var(--radius);
            box-shadow: var(--shadow-md);
            z-index: 3000;
            transition: transform 0.3s ease;
            max-width: 90%;
            font-weight: 500;
        }

        .toast.active {
            transform: translateX(-50%) translateY(0);
        }

        .toast.error {
            background: var(--danger);
        }

        /* --- Utilities --- */
        .text-center {
            text-align: center;
        }

        .w-full {
            width: 100%;
        }

        .mt-md {
            margin-top: 16px;
        }

        .mb-md {
            margin-bottom: 16px;
        }

        .divider {
            border: 0;
            border-top: 1px solid var(--border);
            margin: 16px 0;
        }

        /* --- Typing Animation --- */
        .thinking-container {
            display: flex;
            align-items: center;
            gap: 8px;
            color: var(--text-light);
            font-size: 0.8rem;
        }

        .typing-indicator {
            display: flex;
            gap: 3px;
        }

        .typing-indicator span {
            width: 6px;
            height: 6px;
            background: var(--text-light);
            border-radius: 50%;
            animation: bounce 1.4s infinite;
        }

        .typing-indicator span:nth-child(1) {
            animation-delay: -0.32s;
        }

        .typing-indicator span:nth-child(2) {
            animation-delay: -0.16s;
        }

        @keyframes bounce {

            0%,
            80%,
            100% {
                transform: scale(0);
                opacity: 0.5;
            }

            40% {
                transform: scale(1);
                opacity: 1;
            }
        }

        /* --- Smiling Robot Searching Animation --- */
        .robot-search {
            width: 28px;
            height: 28px;
            display: inline-block;
            color: var(--primary);
            animation: robot-bob 1.6s ease-in-out infinite;
            transform-origin: 50% 80%;
        }

        .robot-search .robot-antenna-dot {
            transform-origin: 16px 3px;
            animation: robot-blink 1.2s ease-in-out infinite;
        }

        .robot-search .robot-eye {
            transform-origin: center;
            animation: robot-eye-scan 1.8s ease-in-out infinite;
        }

        .robot-search .robot-eye-right {
            animation-delay: 0.15s;
        }

        .robot-search .robot-mouth {
            fill: none;
            stroke: currentColor;
            stroke-width: 1.6;
            stroke-linecap: round;
            animation: robot-smile 2.4s ease-in-out infinite;
        }

        @keyframes robot-bob {
            0%, 100% { transform: translateY(0) rotate(-2deg); }
            50%      { transform: translateY(-2px) rotate(2deg); }
        }

        @keyframes robot-blink {
            0%, 60%, 100% { opacity: 1; transform: scale(1); }
            70%           { opacity: 0.3; transform: scale(0.6); }
            80%           { opacity: 1; transform: scale(1.15); }
        }

        @keyframes robot-eye-scan {
            0%, 100% { transform: translateX(0); }
            25%      { transform: translateX(-1.2px); }
            75%      { transform: translateX(1.2px); }
        }

        @keyframes robot-smile {
            0%, 100% { d: path('M 11 19 Q 16 22 21 19'); }
            50%      { d: path('M 11 19 Q 16 24 21 19'); }
        }

        /* --- Typewriter effect --- */
        .typing-text {
            white-space: pre-wrap;
            word-wrap: break-word;
        }

        .typing-cursor {
            display: inline-block;
            width: 2px;
            height: 1.05em;
            background: var(--primary);
            margin-left: 2px;
            vertical-align: text-bottom;
            animation: typing-cursor-blink 0.9s steps(2, end) infinite;
        }

        .message.user .typing-cursor { background: #fff; }

        @keyframes typing-cursor-blink {
            50% { opacity: 0; }
        }

        /* --- Toggle Switch --- */
        .switch-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 12px;
            padding: 10px 12px;
            background: var(--bg-soft);
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
        }

        .switch-row .switch-label {
            font-size: 0.85rem;
            color: var(--text);
            display: flex;
            flex-direction: column;
            gap: 2px;
        }

        .switch-row .switch-hint {
            font-size: 0.7rem;
            color: var(--text-light);
            font-weight: 400;
        }

        .switch {
            position: relative;
            display: inline-block;
            width: 40px;
            height: 22px;
            flex-shrink: 0;
        }

        .switch input { opacity: 0; width: 0; height: 0; }

        .switch .slider {
            position: absolute;
            inset: 0;
            background: var(--border-strong);
            border-radius: 22px;
            transition: background 0.2s;
            cursor: pointer;
        }

        .switch .slider::before {
            content: "";
            position: absolute;
            height: 16px;
            width: 16px;
            left: 3px;
            top: 3px;
            background: #fff;
            border-radius: 50%;
            transition: transform 0.2s;
            box-shadow: 0 1px 2px rgba(0,0,0,0.2);
        }

        .switch input:checked + .slider { background: var(--primary); }
        .switch input:checked + .slider::before { transform: translateX(18px); }

        .empty-list {
            text-align: center;
            padding: 40px 20px;
            color: var(--text-lighter);
            font-size: 0.85rem;
        }

        /* --- Responsive Design --- */
        @media (max-width: 768px) {
            header {
                padding: 12px 14px;
            }

            .header-brand h1 {
                font-size: 0.85rem;
                letter-spacing: 1px;
            }

            .messages {
                padding: 14px;
                gap: 10px;
            }

            .message {
                max-width: 88%;
            }

            .input-container {
                padding: 8px 12px 12px;
            }

            .modal-content {
                max-height: 100dvh;
                height: 100dvh;
                max-width: 100%;
                border-radius: 0;
                border: none;
            }

            .modal-overlay {
                padding: 0;
            }

            .modal-tab .tab-label {
                display: none;
            }

            .modal-tab {
                flex: 1;
                min-width: 56px;
                padding: 12px 8px;
            }

            .modal-header {
                padding: 14px 16px;
            }

            .modal-body {
                padding: 16px;
            }
        }

        @media (max-width: 480px) {
            .header-brand h1 {
                font-size: 0.78rem;
            }

            .btn-sm {
                padding: 5px 8px;
                font-size: 0.7rem;
            }

            .message {
                max-width: 92%;
            }

            .message-content {
                font-size: 0.85rem;
                padding: 9px 12px;
            }

            .stat-grid {
                grid-template-columns: 1fr;
            }

            #modelMode {
                font-size: 0.7rem;
                padding: 6px 8px;
                height: 34px;
            }

            #userInput {
                font-size: 16px;
                /* prevents iOS zoom on focus */
            }
        }

        /* iOS safe area */
        @supports (padding: max(0px)) {
            .input-container {
                padding-bottom: max(16px, env(safe-area-inset-bottom));
            }

            header {
                padding-top: max(14px, env(safe-area-inset-top));
            }
        }

        /* --- Cursor Glow Background --- */
        body {
            background: #f4f4f5;
        }

        .cursor-glow {
            position: fixed;
            inset: 0;
            pointer-events: none;
            z-index: 0;
            background: radial-gradient(circle 500px at var(--cx, 50%) var(--cy, 50%),
                    rgba(var(--accent-rgb), 0.08) 0%,
                    rgba(var(--accent-rgb), 0.04) 40%,
                    transparent 70%);
            transition: background 0.05s linear;
        }

        /* --- App Shell (sits above glow) --- */
        .app-container {
            position: relative;
            z-index: 1;
            background: transparent;
        }

        header {
            background: rgba(255, 255, 255, 0.85);
            backdrop-filter: blur(12px);
            -webkit-backdrop-filter: blur(12px);
        }

        .tabs-bar {
            background: rgba(250, 250, 250, 0.9);
            backdrop-filter: blur(8px);
            -webkit-backdrop-filter: blur(8px);
        }

        /* --- Chat Frame --- */
        .chat-frame-wrapper {
            flex: 1;
            display: flex;
            flex-direction: column;
            padding: 12px 16px 0;
            min-height: 0;
            overflow: hidden;
        }

        .chat-frame {
            flex: 1;
            display: flex;
            flex-direction: column;
            min-height: 0;
            background: rgba(255, 255, 255, 0.95);
            border: 1px solid var(--border);
            border-bottom: none;
            border-radius: 16px 16px 0 0;
            overflow: hidden;
            box-shadow:
                0 0 0 1px rgba(255, 255, 255, 0.6) inset,
                0 8px 32px rgba(0, 0, 0, 0.06);
        }

        .chat-frame .messages {
            background: transparent;
        }

        .chat-frame .input-container {
            background: rgba(255, 255, 255, 0.98);
            border-top: 1px solid var(--border);
        }

        @media (max-width: 768px) {
            .chat-frame-wrapper {
                padding: 8px 10px 0;
            }

            .chat-frame {
                border-radius: 12px 12px 0 0;
            }

            .sidebar {
                position: absolute;
                top: 0;
                bottom: 0;
                left: -100%;
                width: 280px;
                transition: left 0.3s ease;
                box-shadow: 4px 0 24px rgba(0, 0, 0, 0.1);
            }

            .sidebar.mobile-open {
                left: 0;
            }

            .sidebar-overlay {
                display: none;
                position: absolute;
                inset: 0;
                background: rgba(0, 0, 0, 0.4);
                z-index: 4;
                opacity: 0;
                transition: opacity 0.3s ease;
            }

            .sidebar-overlay.mobile-open {
                display: block;
                opacity: 1;
            }

            .sidebar-toggle-btn {
                display: inline-flex !important;
            }
        }

        .sidebar-toggle-btn {
            display: none;
            background: none;
            border: none;
            color: var(--text);
            cursor: pointer;
            padding: 4px;
            margin-right: 8px;
            align-items: center;
            justify-content: center;
        }

        /* =========================================================================
           DESIGN REFRESH v2 — MAGNET AI
           Same identity: monochrome, Inter, magnetic accents.
           Refined typography, depth, motion, focus rings, glassmorphism.
           This layer is purely additive — no markup or class changes needed.
           ========================================================================= */
        :root {
            --accent: #f15a29;            /* magnet orange — primary brand accent */
            --accent-2: #f57e54;          /* lighter shade of the primary */
            --accent-rgb: 241, 90, 41;    /* RGB components for alpha-blend mixes */
            --accent-soft: rgba(var(--accent-rgb), 0.10);
            --ring: 0 0 0 3px rgba(var(--accent-rgb), 0.22);
            --elev-1: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 1px rgba(15, 23, 42, 0.03);
            --elev-2: 0 4px 16px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.04);
            --elev-3: 0 20px 48px -12px rgba(15, 23, 42, 0.16), 0 6px 16px rgba(15, 23, 42, 0.06);
            --radius: 12px;
            --radius-sm: 8px;
            --radius-lg: 18px;
            --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
        }
        [data-theme="dark"] {
            --accent: #f47a4d;             /* lighter orange for dark backgrounds */
            --accent-2: #ff9e7a;            /* even lighter shade */
            --accent-rgb: 244, 122, 77;
            --accent-soft: rgba(var(--accent-rgb), 0.16);
            --ring: 0 0 0 3px rgba(var(--accent-rgb), 0.32);
            --elev-1: 0 1px 2px rgba(0, 0, 0, 0.35);
            --elev-2: 0 4px 18px rgba(0, 0, 0, 0.4);
            --elev-3: 0 24px 64px -16px rgba(0, 0, 0, 0.65), 0 8px 20px rgba(0, 0, 0, 0.4);
        }

        /* --- Body: flat color, no gradient (perf) --- */
        body { background: #f6f7f9 !important; }
        [data-theme="dark"] body { background: #0b0d10 !important; }

        /* --- Typography refinement --- */
        body {
            font-feature-settings: "ss01", "cv11", "cv02";
            letter-spacing: -0.005em;
        }
        h1, h2, h3, h4 { letter-spacing: -0.015em; }

        /* Screen-reader-only utility (keeps semantic <h1> accessible while the logo SVG is shown) */
        .sr-only {
            position: absolute !important;
            width: 1px !important; height: 1px !important;
            padding: 0 !important; margin: -1px !important;
            overflow: hidden !important; clip: rect(0,0,0,0) !important;
            white-space: nowrap !important; border: 0 !important;
        }

        /* Brand logo (replaces the text title) */
        .header-brand .brand-logo {
            display: block;
            height: 24px;
            width: auto;
            color: var(--text);
            margin-left: 4px;
            transition: color 0.15s;
            flex-shrink: 0;
        }
        .header-brand .brand-logo:hover { color: var(--accent); }
        @media (max-width: 600px) {
            .header-brand .brand-logo { height: 20px; }
        }

        /* --- Header: flat (no blur for perf) --- */
        header {
            background: var(--bg) !important;
            border-bottom-color: rgba(0, 0, 0, 0.06) !important;
            backdrop-filter: none !important;
            -webkit-backdrop-filter: none !important;
        }
        [data-theme="dark"] header {
            background: #14171c !important;
            border-bottom-color: rgba(255,255,255,0.06) !important;
        }
        .header-brand h1 {
            background: linear-gradient(135deg, var(--text) 0%, var(--text-light) 100%);
            -webkit-background-clip: text;
            background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        /* --- Buttons: snappy --- */
        .btn, .btn-sm {
            border-radius: 10px;
            box-shadow: var(--elev-1);
            transition: background 0.1s, border-color 0.1s, color 0.1s;
        }
        .btn:hover { box-shadow: var(--elev-2); }
        .btn:focus-visible { outline: none; box-shadow: var(--ring), var(--elev-1); }
        .btn-primary {
            background: linear-gradient(135deg, var(--text) 0%, var(--text-light) 140%) !important;
            border-color: transparent !important;
        }
        [data-theme="dark"] .btn-primary {
            background: linear-gradient(135deg, var(--primary) 0%, #d4d4d8 140%) !important;
            color: #0b0d10 !important;
        }

        /* --- Sidebar: flat (no blur) --- */
        .sidebar {
            background: var(--bg-soft) !important;
            border-right-color: rgba(0, 0, 0, 0.06) !important;
            backdrop-filter: none !important;
            -webkit-backdrop-filter: none !important;
        }
        [data-theme="dark"] .sidebar {
            background: #14171c !important;
            border-right-color: rgba(255,255,255,0.06) !important;
        }
        .sidebar-chats::-webkit-scrollbar { width: 6px; }
        .sidebar-chats::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; }

        /* --- Chat tabs (sidebar) --- */
        .chat-tab {
            border-radius: 10px;
            transition: all 0.18s var(--ease-out);
        }
        .chat-tab:hover { background: rgba(0,0,0,0.04); }
        [data-theme="dark"] .chat-tab:hover { background: rgba(255,255,255,0.05); }
        .chat-tab.active {
            background: var(--bg) !important;
            border-color: transparent !important;
            box-shadow: var(--elev-1), inset 0 0 0 1px rgba(var(--accent-rgb), 0.22);
        }
        [data-theme="dark"] .chat-tab.active { box-shadow: var(--elev-1), inset 0 0 0 1px rgba(var(--accent-rgb), 0.36); }

        /* --- Chat frame: solid bg (no blur) --- */
        .chat-frame {
            border-radius: 20px 20px 0 0 !important;
            border-color: rgba(0,0,0,0.06) !important;
            background: var(--bg) !important;
            backdrop-filter: none !important;
            -webkit-backdrop-filter: none !important;
            box-shadow: 0 1px 3px rgba(15,23,42,0.04) !important;
        }
        [data-theme="dark"] .chat-frame {
            background: #14171c !important;
            border-color: rgba(255,255,255,0.06) !important;
            box-shadow: 0 1px 3px rgba(0,0,0,0.3) !important;
        }
        .chat-frame .input-container {
            background: transparent !important;
            border-top: 1px solid rgba(0,0,0,0.05) !important;
        }
        [data-theme="dark"] .chat-frame .input-container { border-top-color: rgba(255,255,255,0.05) !important; }

        /* --- Input wrapper: floating pill with focus glow --- */
        .input-wrapper {
            border-radius: 16px !important;
            background: var(--bg) !important;
            box-shadow: var(--elev-2);
            border-color: transparent !important;
            transition: box-shadow 0.18s var(--ease-out);
        }
        .input-wrapper:focus-within {
            box-shadow: var(--elev-2), var(--ring) !important;
            border-color: transparent !important;
        }

        /* --- Send button: gradient pill --- */
        #sendBtn {
            border-radius: 10px !important;
            background: var(--text) !important;
            box-shadow: var(--elev-1);
            transition: background 0.1s;
        }
        #sendBtn:hover { background: var(--text-light) !important; }
        [data-theme="dark"] #sendBtn {
            background: linear-gradient(135deg, var(--primary) 0%, #d4d4d8 140%) !important;
            color: #0b0d10 !important;
        }

        /* OCR / camera button beside input */
        .ocr-btn {
            border-radius: 10px !important;
            transition: all 0.15s var(--ease-out);
        }
        .ocr-btn:hover { color: var(--accent) !important; border-color: var(--accent) !important; background: var(--accent-soft) !important; }

        /* Mode select */
        #modelMode {
            border-radius: 10px !important;
            background: var(--bg-soft) !important;
            transition: all 0.15s;
        }
        #modelMode:hover { background: var(--accent-soft) !important; color: var(--accent) !important; }

        /* --- Message bubbles: refined, no hover lift (perf) --- */
        .message-content {
            border-radius: 16px !important;
            padding: 13px 16px !important;
            box-shadow: var(--elev-1);
            transition: none !important;
        }
        .message-content:hover { transform: none !important; box-shadow: var(--elev-1) !important; }
        .message.user .message-content {
            background: linear-gradient(135deg, var(--text) 0%, #2a2a2a 100%) !important;
            border: none !important;
            border-bottom-right-radius: 6px !important;
            color: #fff;
        }
        [data-theme="dark"] .message.user .message-content {
            background: linear-gradient(135deg, var(--primary) 0%, #d4d4d8 100%) !important;
        }
        .message.bot .message-content {
            border-color: rgba(0,0,0,0.04) !important;
            border-bottom-left-radius: 6px !important;
        }
        [data-theme="dark"] .message.bot .message-content { border-color: rgba(255,255,255,0.05) !important; }

        /* Action buttons under each message */
        .action-btn {
            border-radius: 8px;
            transition: all 0.15s;
        }
        .action-btn:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

        /* --- Empty state: more inviting --- */
        .empty-state {
            opacity: 0;
            animation: empty-fade-in 0.5s var(--ease-out) 0.1s forwards;
        }
        @keyframes empty-fade-in {
            to { opacity: 1; transform: translateY(0); }
            from { opacity: 0; transform: translateY(10px); }
        }
        .empty-state h3 {
            background: linear-gradient(135deg, var(--text), var(--text-light) 80%);
            -webkit-background-clip: text;
            background-clip: text;
            -webkit-text-fill-color: transparent;
            font-size: 1.05rem !important;
        }

        /* --- Slash menu: solid bg (no blur) --- */
        .slash-menu {
            border-radius: 14px !important;
            box-shadow: var(--elev-2) !important;
            border-color: rgba(0,0,0,0.06) !important;
            background: var(--bg) !important;
            backdrop-filter: none !important;
        }
        [data-theme="dark"] .slash-menu {
            background: #14171c !important;
            border-color: rgba(255,255,255,0.06) !important;
        }
        .slash-item {
            border-radius: 10px;
            transition: all 0.15s var(--ease-out);
        }
        .slash-item:hover, .slash-item.active {
            background: var(--accent-soft) !important;
        }
        .slash-item:hover .slash-item-icon, .slash-item.active .slash-item-icon {
            background: var(--accent) !important;
            color: #fff;
        }
        [data-theme="dark"] .slash-item:hover .slash-item-icon,
        [data-theme="dark"] .slash-item.active .slash-item-icon { color: #0b0d10; }

        /* --- Intent chip --- */
        .intent-chip {
            background: var(--accent-soft) !important;
            border-color: var(--accent) !important;
            color: var(--accent) !important;
        }
        .intent-chip-icon { color: var(--accent) !important; }

        /* --- Modal overlay: lighter backdrop (no blur for perf) --- */
        .modal-overlay {
            background: rgba(15, 23, 42, 0.55) !important;
            backdrop-filter: none !important;
            -webkit-backdrop-filter: none !important;
            animation: none !important;
        }
        [data-theme="dark"] .modal-overlay {
            background: rgba(0, 0, 0, 0.78) !important;
        }
        .modal-content {
            border-radius: 20px !important;
            box-shadow: var(--elev-3) !important;
            border-color: rgba(0,0,0,0.05) !important;
        }
        [data-theme="dark"] .modal-content { border-color: rgba(255,255,255,0.06) !important; }

        /* --- Choice sheet --- */
        .choice-sheet-inner {
            border-radius: 22px 22px 14px 14px !important;
            box-shadow: var(--elev-3) !important;
            border-color: rgba(0,0,0,0.05) !important;
        }
        .choice-sheet-list .choice-btn:hover .choice-letter {
            background: var(--accent) !important;
            border-color: var(--accent) !important;
            color: #fff !important;
        }

        /* --- Form inputs --- */
        input[type="text"], input[type="email"], input[type="number"], select, textarea {
            border-radius: 10px;
            transition: all 0.15s;
        }
        input:focus-visible, textarea:focus-visible, select:focus-visible {
            outline: none;
            border-color: var(--accent) !important;
            box-shadow: var(--ring) !important;
        }

        /* --- Toast --- */
        .toast {
            border-radius: 14px !important;
            box-shadow: var(--elev-3) !important;
            padding: 12px 20px !important;
        }

        /* --- AI image gallery polish (no scale for perf) --- */
        .ai-image-gallery .ai-image-tile {
            border-radius: 12px !important;
            transition: box-shadow 0.12s;
        }
        .ai-image-gallery .ai-image-tile:hover { box-shadow: var(--elev-2); }

        /* --- Mind map polish --- */
        .ai-mindmap {
            border-radius: 16px !important;
            background: linear-gradient(180deg, var(--bg-soft) 0%, rgba(var(--accent-rgb), 0.04) 100%) !important;
        }
        [data-theme="dark"] .ai-mindmap {
            background: linear-gradient(180deg, var(--bg-soft) 0%, rgba(var(--accent-rgb), 0.06) 100%) !important;
        }
        .ai-mindmap-node {
            border-radius: 999px !important;
            box-shadow: var(--elev-1);
            transition: all 0.18s var(--ease-out);
        }
        .ai-mindmap-node:hover { box-shadow: var(--elev-2); }
        .ai-mindmap-root {
            background: linear-gradient(135deg, var(--text) 0%, #2a2a2a 100%) !important;
            color: #fff !important;
            border-color: transparent !important;
            box-shadow: var(--elev-2), 0 0 0 4px rgba(var(--accent-rgb), 0.16) !important;
        }
        [data-theme="dark"] .ai-mindmap-root {
            background: linear-gradient(135deg, var(--primary) 0%, #d4d4d8 100%) !important;
            color: #0b0d10 !important;
        }

        /* --- Data table polish --- */
        .ai-table-wrapper {
            border-radius: 14px !important;
            box-shadow: var(--elev-1);
            border-color: rgba(0,0,0,0.05) !important;
        }
        [data-theme="dark"] .ai-table-wrapper { border-color: rgba(255,255,255,0.05) !important; }
        .ai-table th {
            font-size: 0.74rem;
            text-transform: uppercase;
            letter-spacing: 0.7px;
            color: var(--text-light);
            background: linear-gradient(180deg, var(--bg-soft) 0%, var(--bg) 100%) !important;
        }
        [data-theme="dark"] .ai-table th { background: var(--bg-soft) !important; }

        /* --- Calc card polish --- */
        .ai-calc {
            border-radius: 14px !important;
            box-shadow: var(--elev-1);
            overflow: hidden;
        }
        .ai-calc-result {
            background: linear-gradient(135deg, var(--accent-soft), transparent);
            border-radius: var(--radius-sm);
            padding: 12px !important;
            border: none !important;
            color: var(--accent) !important;
        }

        /* --- Thinking container: subtle pulse glow --- */
        .thinking-container {
            background: var(--accent-soft);
            border-radius: 999px;
            padding: 10px 16px;
            display: inline-flex;
            align-items: center;
            gap: 10px;
            animation: thinking-pulse 1.8s ease-in-out infinite;
        }
        @keyframes thinking-pulse {
            0%, 100% { box-shadow: 0 0 0 0 rgba(var(--accent-rgb), 0.24); }
            50%      { box-shadow: 0 0 0 8px rgba(var(--accent-rgb), 0.0); }
        }

        /* --- Mention preview chip: refined --- */
        .mention-preview.active {
            background: var(--accent-soft) !important;
            border-radius: 10px !important;
            border: 1px solid var(--accent) !important;
        }

        /* --- Tabs bar (top of chat) --- */
        .tabs-bar {
            background: transparent !important;
            backdrop-filter: none !important;
        }

        /* --- Smooth focus ring on everything interactive --- */
        button:focus-visible, a:focus-visible {
            outline: none;
            box-shadow: var(--ring);
        }

        /* --- Cursor glow: disabled (perf hog — re-paints on every mousemove) --- */
        .cursor-glow { display: none !important; }

        /* --- Scrollbar refresh (Firefox + Webkit) --- */
        * { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
        *::-webkit-scrollbar { width: 8px; height: 8px; }
        *::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
        *::-webkit-scrollbar-thumb:hover { background: var(--text-lighter); background-clip: padding-box; border: 2px solid transparent; }

        /* --- Like / Dislike feedback buttons --- */
        .action-btn.like-btn.active {
            background: rgba(16, 185, 129, 0.12);
            color: #10b981;
            border-color: #10b981;
        }
        .action-btn.dislike-btn.active {
            background: rgba(239, 68, 68, 0.12);
            color: #ef4444;
            border-color: #ef4444;
        }
        .action-btn.like-btn.active svg,
        .action-btn.dislike-btn.active svg {
            fill: currentColor;
        }

        /* Tiny inline "why?" prompt that appears after dislike */
        .dislike-reason {
            display: flex;
            gap: 6px;
            align-items: center;
            background: var(--bg-soft);
            border: 1px solid var(--border);
            border-radius: 10px;
            padding: 6px 8px;
            margin-top: 6px;
            max-width: 320px;
            animation: message-in 0.15s ease-out;
        }
        .dislike-reason input {
            flex: 1;
            border: none;
            background: transparent;
            outline: none;
            font-size: 0.78rem;
            color: var(--text);
            padding: 4px 6px;
        }
        .dislike-reason button {
            background: var(--accent);
            color: #fff;
            border: none;
            border-radius: 8px;
            padding: 4px 10px;
            font-size: 0.74rem;
            font-weight: 600;
            cursor: pointer;
            transition: background 0.12s;
        }
        .dislike-reason button:hover { background: var(--accent-2); }
        .dislike-reason .skip {
            background: transparent;
            color: var(--text-light);
            border: 1px solid var(--border);
        }
        .dislike-reason .skip:hover { background: var(--accent-soft); color: var(--accent); }

        /* =========================================================================
           ACCENT THEMES — five color palettes the user can pick from the header.
           Default (no attribute) = Magnet Orange (defined in :root above).
           ========================================================================= */
        [data-accent="blue"] {
            --accent: #2563eb;
            --accent-2: #60a5fa;
            --accent-rgb: 37, 99, 235;
        }
        [data-theme="dark"][data-accent="blue"] {
            --accent: #60a5fa;
            --accent-2: #93c5fd;
            --accent-rgb: 96, 165, 250;
        }

        [data-accent="green"] {
            --accent: #059669;
            --accent-2: #34d399;
            --accent-rgb: 5, 150, 105;
        }
        [data-theme="dark"][data-accent="green"] {
            --accent: #34d399;
            --accent-2: #6ee7b7;
            --accent-rgb: 52, 211, 153;
        }

        [data-accent="purple"] {
            --accent: #7c3aed;
            --accent-2: #a78bfa;
            --accent-rgb: 124, 58, 237;
        }
        [data-theme="dark"][data-accent="purple"] {
            --accent: #a78bfa;
            --accent-2: #c4b5fd;
            --accent-rgb: 167, 139, 250;
        }

        [data-accent="rose"] {
            --accent: #e11d48;
            --accent-2: #fb7185;
            --accent-rgb: 225, 29, 72;
        }
        [data-theme="dark"][data-accent="rose"] {
            --accent: #fb7185;
            --accent-2: #fda4af;
            --accent-rgb: 251, 113, 133;
        }

        /* =========================================================================
           THEME-COLOR DROPDOWN in the header
           ========================================================================= */
        .theme-color-wrapper { position: relative; display: inline-block; }
        .theme-color-toggle {
            background: var(--bg);
            border: 1px solid var(--border);
            width: 36px;
            height: 36px;
            border-radius: 10px;
            cursor: pointer;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            padding: 0;
            transition: background 0.12s, border-color 0.12s, transform 0.1s;
        }
        .theme-color-toggle:hover { background: var(--accent-soft); border-color: var(--accent); }
        .theme-color-toggle:active { transform: scale(0.94); }
        .theme-color-swatch {
            width: 16px;
            height: 16px;
            border-radius: 50%;
            background: var(--accent);
            box-shadow:
                0 0 0 2px var(--bg),
                0 0 0 3px var(--accent),
                inset 0 0 0 1px rgba(0,0,0,0.06);
            transition: background 0.15s, box-shadow 0.15s;
        }

        .theme-color-menu {
            position: absolute;
            top: calc(100% + 6px);
            right: 0;
            min-width: 180px;
            background: var(--bg);
            border: 1px solid var(--border);
            border-radius: 12px;
            box-shadow: var(--elev-3);
            padding: 6px;
            z-index: 100;
            display: flex;
            flex-direction: column;
            gap: 2px;
            animation: slash-pop 0.14s ease-out;
            transform-origin: top right;
        }
        .theme-color-menu[hidden] { display: none !important; }

        .theme-color-menu .menu-header {
            font-size: 0.65rem;
            font-weight: 700;
            color: var(--text-lighter);
            text-transform: uppercase;
            letter-spacing: 0.6px;
            padding: 6px 10px 4px;
        }

        .theme-color-option {
            background: transparent;
            border: none;
            padding: 8px 10px;
            display: flex;
            align-items: center;
            gap: 10px;
            cursor: pointer;
            border-radius: 8px;
            font-family: inherit;
            font-size: 0.83rem;
            font-weight: 500;
            color: var(--text);
            text-align: left;
            transition: background 0.1s;
        }
        .theme-color-option:hover { background: var(--bg-soft); }
        .theme-color-option .dot {
            width: 14px;
            height: 14px;
            border-radius: 50%;
            flex-shrink: 0;
            box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
        }
        .theme-color-option .checkmark {
            margin-left: auto;
            color: var(--accent);
            opacity: 0;
            transition: opacity 0.1s;
        }
        .theme-color-option.active .checkmark { opacity: 1; }
        .theme-color-option.active { background: var(--bg-soft); }

        /* Subtle entrance kept very short to avoid feeling slow */
        .message {
            animation: message-in 0.15s ease-out both;
        }
        @keyframes message-in {
            from { opacity: 0; }
            to   { opacity: 1; }
        }

        /* === Mic / voice input button === */
        .mic-btn {
            position: relative;
            background: var(--bg);
            color: var(--text-light);
            border: 1px solid var(--border);
            width: 36px;
            height: 36px;
            border-radius: 8px;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.15s;
            flex-shrink: 0;
        }
        .mic-btn:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
        .mic-btn:active { transform: scale(0.94); }
        .mic-btn .mic-icon { width: 18px; height: 18px; }
        .mic-btn.recording {
            background: #dc2626;
            color: #fff;
            border-color: #dc2626;
            animation: mic-pulse 1.4s ease-out infinite;
        }
        .mic-btn.recording .mic-icon rect { fill: #fff; stroke: #fff; }
        [data-theme="dark"] .mic-btn.recording { background: #ef4444; border-color: #ef4444; }
        .mic-btn.unsupported { opacity: 0.4; cursor: not-allowed; }
        .mic-btn.unsupported:hover { background: var(--bg); color: var(--text-light); border-color: var(--border); }

        @keyframes mic-pulse {
            0%   { box-shadow: 0 0 0 0   rgba(220, 38, 38, 0.55); }
            70%  { box-shadow: 0 0 0 12px rgba(220, 38, 38, 0);   }
            100% { box-shadow: 0 0 0 0   rgba(220, 38, 38, 0);    }
        }

        .mic-listening-pill {
            position: absolute;
            bottom: calc(100% + 8px);
            left: 50%;
            transform: translateX(-50%);
            background: #dc2626;
            color: #fff;
            font-size: 0.72rem;
            font-weight: 600;
            padding: 5px 12px;
            border-radius: 999px;
            display: inline-flex;
            align-items: center;
            gap: 6px;
            white-space: nowrap;
            box-shadow: 0 6px 16px rgba(220, 38, 38, 0.35);
            z-index: 50;
            pointer-events: none;
        }
        .mic-listening-pill .live-dot {
            width: 6px; height: 6px; border-radius: 50%;
            background: #fff;
            animation: mic-dot 1s ease-in-out infinite;
        }
        @keyframes mic-dot {
            0%, 100% { opacity: 0.4; transform: scale(1); }
            50%      { opacity: 1;   transform: scale(1.4); }
        }
