  /* =========================================================
           THEME VARIABLES (DARK - DEFAULT)
           ========================================================= */
        :root {
            --bg-0: #09101a;
            --bg-1: #0f1a29;
            --bg-2: #162638;
            --bg-grad-end: #10273f;
            
            --glow-1: rgba(125, 180, 255, 0.24);
            --glow-2: rgba(41, 165, 239, 0.26);

            --shell-bg: linear-gradient(180deg, rgba(20, 33, 49, 0.68), rgba(11, 20, 32, 0.88));
            --topbar-bg: linear-gradient(180deg, rgba(10, 18, 30, 0.9), rgba(10, 18, 30, 0.58));
            --composer-bg: linear-gradient(180deg, rgba(10, 18, 30, 0.6), rgba(10, 18, 30, 0.9));
            
            --surface: rgba(9, 19, 31, 0.74);
            --surface-elevated: rgba(20, 33, 49, 0.88);
            --surface-soft: rgba(140, 184, 255, 0.08);
            --line: rgba(164, 193, 234, 0.24);
            --line-strong: rgba(164, 193, 234, 0.42);

            --text-0: #f2f7ff;
            --text-1: #c0d1e8;
            --text-2: #7990ae;

            --brand-0: #9ce2ff;
            --brand-1: #6bc8ff;
            --brand-2: #29a5ef;
            --brand-text: #012133;

            --user-msg-bg: linear-gradient(135deg, #49b6ff, #21a7f0 60%, #0f8fd9);
            --user-msg-text: #062131;
            
            --ai-avatar-bg: linear-gradient(160deg, rgba(156, 226, 255, 0.28), rgba(41, 165, 239, 0.34));
            --quick-btn-bg: rgba(17, 30, 46, 0.8);
            
            --code-bg: rgba(156, 226, 255, 0.08);
            --code-text: #d3ecff;
            --pre-bg: #091624;
            --pre-text: #d7ecff;

            --success: #85ffcb;
            --success-glow: rgba(133, 255, 203, 0.14);

            --font-sans: "Manrope", "Segoe UI", sans-serif;
            --font-mono: "IBM Plex Mono", Consolas, monospace;

            --radius-xl: 26px;
            --radius-lg: 18px;
            --radius-md: 14px;
            --shadow-xl: 0 40px 80px rgba(0, 0, 0, 0.55);
            --shadow-soft: 0 14px 28px rgba(0, 0, 0, 0.25);
        }

        /* =========================================================
           THEME VARIABLES (LIGHT)
           ========================================================= */
        [data-theme="light"] {
            --bg-0: #f8fafc;
            --bg-1: #f1f5f9;
            --bg-2: #e2e8f0;
            --bg-grad-end: #cbd5e1;

            --glow-1: rgba(0, 112, 243, 0.12);
            --glow-2: rgba(0, 112, 243, 0.08);

            --shell-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(248, 250, 252, 0.9));
            --topbar-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.7));
            --composer-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.95));
            
            --surface: rgba(255, 255, 255, 0.85);
            --surface-elevated: #ffffff;
            --surface-soft: rgba(0, 0, 0, 0.04);
            --line: rgba(0, 0, 0, 0.08);
            --line-strong: rgba(0, 0, 0, 0.18);

            --text-0: #0f172a;
            --text-1: #334155;
            --text-2: #64748b;

            --brand-0: #3b82f6;
            --brand-1: #2563eb;
            --brand-2: #1d4ed8;
            --brand-text: #ffffff;

            --user-msg-bg: linear-gradient(135deg, #60a5fa, #3b82f6 60%, #2563eb);
            --user-msg-text: #ffffff;
            
            --ai-avatar-bg: linear-gradient(160deg, rgba(59, 130, 246, 0.15), rgba(37, 99, 235, 0.2));
            --quick-btn-bg: rgba(255, 255, 255, 0.9);
            
            --code-bg: rgba(0, 0, 0, 0.05);
            --code-text: #0369a1;
            --pre-bg: #f1f5f9;
            --pre-text: #334155;

            --success: #10b981;
            --success-glow: rgba(16, 185, 129, 0.2);

            --shadow-xl: 0 40px 80px rgba(0, 0, 0, 0.08);
            --shadow-soft: 0 14px 28px rgba(0, 0, 0, 0.04);
        }

        /* =========================================================
           GLOBAL STYLES & LAYOUT
           ========================================================= */
        * { margin: 0; padding: 0; box-sizing: border-box; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
        html, body { height: 100%; overflow: hidden; }

        body {
            font-family: var(--font-sans); color: var(--text-0);
            background: radial-gradient(850px 460px at 8% -8%, var(--glow-1), transparent 65%),
                        radial-gradient(1000px 620px at 110% 105%, var(--glow-2), transparent 68%),
                        linear-gradient(145deg, var(--bg-0), var(--bg-1) 50%, var(--bg-grad-end) 100%);
            display: grid; place-items: center; padding: clamp(12px, 3vw, 32px);
            transition: background 0.4s ease, color 0.4s ease;
        }

        body::before, body::after { content: ""; position: fixed; pointer-events: none; inset: auto; z-index: 0; }
        body::before { width: 420px; height: 420px; top: -120px; right: -90px; border-radius: 50%; background: radial-gradient(circle, var(--glow-1) 0%, transparent 70%); filter: blur(8px); }
        body::after { width: 340px; height: 340px; bottom: -120px; left: -80px; border-radius: 50%; background: radial-gradient(circle, var(--glow-2) 0%, transparent 70%); filter: blur(10px); }

        #app-container {
            width: 100%; max-width: 1400px; height: min(930px, calc(100vh - 24px));
            display: flex; gap: 16px; position: relative; z-index: 1;
        }

      
        .sidebar {
            width: 300px; background: var(--shell-bg); border: 1px solid var(--line);
            border-radius: var(--radius-xl); backdrop-filter: blur(20px); display: flex; flex-direction: column;
            padding: 16px; transition: transform 0.3s ease, width 0.3s ease, opacity 0.2s ease; z-index: 10;
        }
        .sidebar.hidden { transform: translateX(-110%); position: absolute; width: 0; opacity: 0; pointer-events: none; }

        .sidebar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; color: var(--text-0); }
        .new-chat-btn {
            background: var(--surface-soft); border: 1px solid var(--line); color: var(--text-0);
            padding: 10px; border-radius: var(--radius-md); cursor: pointer; font-weight: 600; margin-bottom: 12px;
            transition: all 0.2s ease;
        }
        .new-chat-btn:hover { background: var(--line); }
        .history-list { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; flex: 1; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
        .history-list::-webkit-scrollbar { width: 6px; }
        .history-list::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; }
        
       .history-item {
            padding: 8px 10px; border-radius: var(--radius-md); background: rgba(255,255,255,0.02);
            border: 1px solid transparent; color: var(--text-1); font-size: 0.85rem; cursor: pointer;
            text-align: left; transition: all 0.2s ease;
            display: flex; justify-content: space-between; align-items: center; gap: 8px;
        }
        .history-item:hover, .history-item.active { background: var(--surface-soft); border-color: var(--line); color: var(--text-0); }
        
        .history-item-title {
            text-overflow: ellipsis; white-space: nowrap; overflow: hidden; flex: 1; pointer-events: none;
        }
        
        .delete-btn {
            background: none; border: none; color: var(--text-2); cursor: pointer;
            padding: 4px; border-radius: 6px; display: grid; place-items: center; 
            transition: all 0.2s; opacity: 0; flex-shrink: 0;
        }
        .history-item:hover .delete-btn { opacity: 1; }
        .delete-btn:hover { color: #ff4757; background: rgba(255, 71, 87, 0.15); }
        .delete-btn svg { width: 14px; height: 14px; fill: currentColor; }
        .delete-btn * { pointer-events: none; }

       
        #app-shell {
            flex: 1; display: grid; grid-template-rows: auto 1fr auto auto;
            background: var(--shell-bg); border: 1px solid var(--line); border-radius: var(--radius-xl);
            box-shadow: var(--shadow-xl); backdrop-filter: blur(20px); overflow: hidden; position: relative;
            transition: background 0.4s ease, border-color 0.4s ease; min-width: 0;
        }

        .topbar {
            position: relative; z-index: 2; display: flex; align-items: center; justify-content: space-between;
            gap: 16px; padding: 18px clamp(14px, 3vw, 28px); border-bottom: 1px solid var(--line);
            background: var(--topbar-bg); transition: background 0.4s ease, border-color 0.4s ease;
        }

        .brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
        .icon-btn { background: none; border: none; color: var(--text-1); cursor: pointer; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; transition: all 0.2s ease; }
        .icon-btn:hover { background: var(--surface-soft); color: var(--text-0); }
        .sidebar-toggle svg { width: 20px; height: 20px; fill: currentColor; }

        .brand-badge {
            width: 34px; height: 34px; border-radius: 11px; background: linear-gradient(145deg, var(--brand-0), var(--brand-2));
            display: grid; place-items: center; box-shadow: 0 8px 18px rgba(41, 165, 239, 0.25); color: var(--brand-text); flex-shrink: 0;
        }
        .brand-badge svg { width: 18px; height: 18px; fill: currentColor; }
        .brand-meta { min-width: 0; }
        .brand-title { font-size: 0.95rem; font-weight: 800; letter-spacing: 0.02em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
        .brand-subtitle { color: var(--text-2); font-size: 0.8rem; letter-spacing: 0.015em; }

        .topbar-actions { display: flex; align-items: center; gap: 10px; }
        .status-group { display: flex; align-items: center; gap: 10px; color: var(--text-1); }
        .status-pill {
            border: 1px solid var(--line); background: var(--surface-soft); border-radius: 999px; padding: 8px 12px;
            font-size: 0.75rem; letter-spacing: 0.03em; text-transform: uppercase; display: inline-flex; align-items: center; gap: 8px;
        }
        .status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 5px var(--success-glow); }

        .theme-toggle-btn {
            background: var(--surface-soft); border: 1px solid var(--line); color: var(--text-1);
            border-radius: 50%; width: 36px; height: 36px; display: grid; place-items: center; cursor: pointer; flex-shrink: 0; transition: all 0.2s ease;
        }
        .theme-toggle-btn:hover { background: var(--line); color: var(--text-0); }
        .theme-toggle-btn svg { width: 16px; height: 16px; fill: currentColor; }
        [data-theme="light"] .icon-moon { display: block; }
        [data-theme="light"] .icon-sun { display: none; }
        [data-theme="dark"] .icon-moon { display: none; }
        [data-theme="dark"] .icon-sun { display: block; }

  
        .chat-stage { position: relative; z-index: 2; min-height: 0; display: grid; grid-template-rows: auto 1fr; }

        .quick-prompts {
            display: flex; gap: 10px; padding: 14px clamp(14px, 3vw, 28px) 8px; overflow-x: auto; scrollbar-width: none;
            mask-image: linear-gradient(90deg, transparent, #000 5%, #000 95%, transparent);
            -webkit-mask-image: linear-gradient(90deg, transparent, #000 5%, #000 95%, transparent);
        }
        .quick-prompts::-webkit-scrollbar { display: none; }
        .quick-btn {
            border: 1px solid var(--line); background: var(--quick-btn-bg); color: var(--text-1); border-radius: 999px;
            padding: 8px 14px; font-size: 0.8rem; white-space: nowrap; cursor: pointer; backdrop-filter: blur(10px); transition: all 0.2s ease;
        }
        .quick-btn:hover { border-color: var(--line-strong); color: var(--text-0); transform: translateY(-1px); }

        #chat-history {
            min-height: 0; overflow-y: auto; padding: 12px clamp(14px, 3vw, 28px) 36px; display: flex; flex-direction: column;
            gap: 20px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; scroll-behavior: smooth;
        }
        #chat-history::-webkit-scrollbar { width: 8px; }
        #chat-history::-webkit-scrollbar-thumb { background: var(--line); border-radius: 20px; }

        .message-block { width: 100%; display: flex; animation: revealMessage 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; }
        @keyframes revealMessage { 0% { opacity: 0; transform: translateY(10px); } 100% { opacity: 1; transform: translateY(0); } }

        .message-block.user { justify-content: flex-end; }
        .message-block.user .content {
            max-width: min(76ch, 76%); background: var(--user-msg-bg); color: var(--user-msg-text); font-weight: 500;
            border-radius: 18px 18px 6px 18px; padding: 12px 16px; box-shadow: 0 12px 20px rgba(0, 0, 0, 0.1); line-height: 1.5; word-wrap: break-word;
        }

        .message-block.bot { justify-content: flex-start; gap: 10px; align-items: flex-start; }
        .ai-avatar {
            width: 32px; height: 32px; border-radius: 10px; flex-shrink: 0; display: grid; place-items: center;
            background: var(--ai-avatar-bg); border: 1px solid var(--line); color: var(--brand-0); box-shadow: var(--shadow-soft); margin-top: 2px;
        }
        .ai-avatar svg { width: 16px; height: 16px; fill: currentColor; }

        .content-wrapper {
            width: min(78ch, 88%); background: var(--surface-elevated); border: 1px solid var(--line); border-radius: 8px 18px 18px 18px;
            padding: 12px 14px; box-shadow: var(--shadow-soft); transition: background 0.4s ease, border-color 0.4s ease;
        }

        .name-tag { color: var(--brand-0); font-size: 0.78rem; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; margin-bottom: 8px; }
        .content { color: var(--text-1); line-height: 1.68; font-size: 0.98rem; }
        .timestamp { margin-top: 8px; color: var(--text-2); font-size: 0.72rem; letter-spacing: 0.02em; }

        .content p { margin: 0 0 12px; }
        .content p:last-child { margin-bottom: 0; }
        .content ul, .content ol { margin: 10px 0 14px 18px; }
        .content li { margin-bottom: 6px; }
        .content a { color: var(--brand-0); text-decoration: none; border-bottom: 1px solid var(--brand-0); }
        .content code { font-family: var(--font-mono); font-size: 0.86rem; }
        .content p code, .content li code { background: var(--code-bg); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; color: var(--code-text); }
        
        /* Enhanced Code Blocks */
        .content pre { position: relative; padding-top: 38px; margin: 12px 0; border-radius: 12px; border: 1px solid var(--line); background: var(--pre-bg); overflow-x: auto; padding-left: 14px; padding-right: 14px; padding-bottom: 14px;}
        .code-header { position: absolute; top: 0; left: 0; right: 0; height: 34px; background: rgba(0, 0, 0, 0.3); display: flex; justify-content: space-between; align-items: center; padding: 0 12px; border-bottom: 1px solid var(--line); }
        .code-lang { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-2); text-transform: uppercase; }
        .content pre code { color: var(--pre-text); }

        /* Utilities */
        .copy-btn { background: var(--surface-soft); border: 1px solid var(--line); color: var(--text-1); font-size: 0.72rem; padding: 3px 8px; border-radius: 6px; cursor: pointer; transition: all 0.15s; }
        .copy-btn:hover { color: var(--text-0); background: var(--line); }
        .action-row { display: flex; gap: 8px; margin-top: 8px; justify-content: flex-start; }

        .typing-loader { display: inline-flex; align-items: center; gap: 5px; color: var(--text-2); font-size: 0.85rem; }
        .typing-loader span { width: 7px; height: 7px; border-radius: 50%; display: inline-block; background: var(--brand-0); animation: pulseDots 1s infinite ease-in-out !important; }
        .typing-loader span:nth-child(2) { animation-delay: 0.15s; }
        .typing-loader span:nth-child(3) { animation-delay: 0.3s; }
        @keyframes pulseDots { 0%, 80%, 100% { opacity: 0.28; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

      
        .composer { position: relative; z-index: 2; border-top: 1px solid var(--line); background: var(--composer-bg); padding: 12px clamp(12px, 2.8vw, 24px) calc(12px + env(safe-area-inset-bottom)); }
        .input-box { display: flex; align-items: flex-end; gap: 10px; padding: 10px; border-radius: 20px; background: var(--surface); border: 1px solid var(--line); backdrop-filter: blur(16px); transition: border-color 0.2s ease, box-shadow 0.2s ease; }
        .input-box:focus-within { border-color: var(--brand-0); box-shadow: 0 0 0 4px var(--glow-1); }
        
        #user-input { width: 100%; min-height: 42px; max-height: 160px; resize: none; overflow-y: auto; border: none; outline: none; background: transparent; color: var(--text-0); font-family: var(--font-sans); font-size: 0.96rem; line-height: 1.45; padding: 10px 12px; }
        #user-input::placeholder { color: var(--text-2); }
        
        .send-btn { width: 42px; height: 42px; border: none; border-radius: 13px; background: linear-gradient(145deg, var(--brand-0), var(--brand-2)); color: var(--brand-text); flex-shrink: 0; cursor: pointer; display: grid; place-items: center; transition: transform 0.2s ease, filter 0.2s ease; }
        .send-btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
        .send-btn:active { transform: translateY(0); }
        .send-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; filter: grayscale(50%); }
        .send-btn svg { width: 18px; height: 18px; fill: currentColor; }

        .app-footer { padding: 10px 16px; text-align: center; font-size: 0.72rem; color: var(--text-2); border-top: 1px solid var(--line); background: var(--composer-bg); display: flex; justify-content: center; align-items: center; z-index: 2; width: 100%; }


        
        @media (max-width: 900px) {
            #app-container { height: 100vh; gap: 0; }
            .sidebar { position: absolute; left: 12px; top: 12px; bottom: 12px; height: calc(100vh - 24px); box-shadow: var(--shadow-xl); }
            .sidebar.hidden { left: -320px; }
            #app-shell { height: min(100vh, 100%); border-radius: 20px; }
            .status-group { display: none; }
            .content-wrapper { width: min(100%, 82ch); }
            .message-block.user .content { max-width: 86%; }
        }

        @media (max-width: 620px) {
            body { padding: 0; }
            #app-shell { width: 100%; height: 100%; border-radius: 0; border-left: none; border-right: none; }
            .sidebar { left: 0; top: 0; bottom: 0; height: 100vh; width: 85vw; border-radius: 0; }
            .sidebar.hidden { left: -100vw; }
            .content, .message-block.user .content, #user-input { font-size: 0.9rem; }
            .quick-btn { font-size: 0.75rem; }
            .topbar { padding-top: calc(14px + env(safe-area-inset-top)); }
            .quick-prompts, #chat-history { padding-inline: 12px; mask-image: none; -webkit-mask-image: none; }
            .composer { padding-inline: 10px; }
            .message-block.bot .ai-avatar { width: 30px; height: 30px; }
            .app-footer { padding: 8px 12px; font-size: 0.65rem; }
        }

        @media (prefers-reduced-motion: reduce) {
            * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
            .message-block { opacity: 1 !important; transform: none !important; }
        }
