        :root {
            --bg-main: #18181b;
            --bg-sidebar: #131316;
            --bg-chat: #27272a;
            --bg-card: #202024;
            --text-main: #f4f4f5;
            --text-muted: #a1a1aa;
            --accent: #3b82f6;
            --accent-hover: #2563eb;
            --fire: #f97316;
            --emerald: #10b981;
            --purple: #a855f7;
            --user-bubble: #2d3748;
            --border: #3f3f46;
        }

        #login-overlay {
            position: fixed;
            inset: 0;
            z-index: 9999;
            display: none;
            align-items: center;
            justify-content: center;
            background: rgba(9, 9, 11, 0.92);
            backdrop-filter: blur(8px);
        }

        .login-card {
            width: min(380px, calc(100vw - 32px));
            padding: 28px;
            border: 1px solid var(--border);
            border-radius: 16px;
            background: var(--bg-panel);
            box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
        }

        .login-card h2 { margin: 0 0 8px; }
        .login-card p { color: var(--text-muted); margin: 0 0 18px; }
        .login-card input {
            box-sizing: border-box;
            width: 100%;
            margin-bottom: 10px;
            padding: 11px 12px;
            border: 1px solid var(--border);
            border-radius: 8px;
            background: #18181b;
            color: var(--text);
        }
        .login-card button { width: 100%; padding: 11px; }
        #login-error { min-height: 22px; color: #f87171; font-size: 0.85rem; }

        .message-actions {
            display: flex;
            flex-wrap: wrap;
            gap: 6px;
            margin-top: 10px;
        }

        .message-actions button {
            padding: 4px 8px;
            border-radius: 6px;
            font-size: 0.74rem;
        }
        * { box-sizing: border-box; margin: 0; padding: 0; }
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
            background-color: var(--bg-main);
            color: var(--text-main);
            height: 100vh;
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }
        header {
            background-color: var(--bg-card);
            border-bottom: 1px solid var(--border);
            padding: 8px 16px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            flex-wrap: wrap;
            gap: 10px;
            z-index: 10;
        }
        .header-left {
            display: flex;
            align-items: center;
            gap: 10px;
        }
        .btn-sidebar-toggle {
            background: #27272a;
            border: 1px solid var(--border);
            color: var(--text-main);
            padding: 6px 10px;
            border-radius: 8px;
            font-size: 1.1rem;
            cursor: pointer;
        }
        .header-title {
            font-weight: 700;
            font-size: 1.05rem;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .token-badge {
            background: #064e3b;
            color: #6ee7b7;
            border: 1px solid #059669;
            padding: 4px 10px;
            border-radius: 9999px;
            font-size: 0.82rem;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 6px;
            cursor: pointer;
            transition: all 0.2s;
            text-decoration: none;
        }
        .token-badge:hover {
            background: #047857;
            color: #fff;
        }
        .controls {
            display: flex;
            align-items: center;
            gap: 8px;
            flex-wrap: wrap;
        }
        select, button {
            background: #27272a;
            color: #f4f4f5;
            border: 1px solid var(--border);
            padding: 6px 12px;
            border-radius: 8px;
            font-size: 0.88rem;
            cursor: pointer;
            outline: none;
            transition: all 0.2s;
        }
        select:focus, button:hover {
            border-color: var(--accent);
        }
        .view-toggle {
            background: #27272a;
            border: 1px solid #a855f7;
            color: #d8b4fe;
            font-weight: 600;
        }
        .view-toggle.active {
            background: #6b21a8;
            color: #fff;
        }
        .mode-select {
            background: #27272a;
            color: #fdba74;
            font-weight: 600;
            border: 1px solid #f97316;
        }
        .btn-key {
            background: #27272a;
            border: 1px solid #eab308;
            color: #fde047;
            font-weight: 600;
        }
        .btn-key:hover {
            background: #713f12;
            color: #fff;
        }
        .shield-toggle {
            background: #064e3b;
            color: #6ee7b7;
            border: 1px solid #059669;
            font-weight: 600;
        }
        .shield-toggle.active {
            background: #065f46;
            color: #a7f3d0;
            border-color: #10b981;
            box-shadow: 0 0 10px rgba(16, 185, 129, 0.25);
        }
        .shield-toggle.off {
            background: #27272a;
            color: #71717a;
            border-color: #3f3f46;
        }
        .btn-test-shield {
            background: #27272a;
            border: 1px dashed #60a5fa;
            color: #93c5fd;
            font-size: 0.8rem;
            padding: 5px 10px;
        }
        .btn-test-shield:hover {
            background: #1e3a8a;
            color: #fff;
        }

        /* App Body: Sidebar + Main Content */
        #app-body {
            flex: 1;
            display: flex;
            overflow: hidden;
            position: relative;
        }

        /* Sidebar */
        #sidebar {
            width: 260px;
            background: var(--bg-sidebar);
            border-right: 1px solid var(--border);
            display: flex;
            flex-direction: column;
            transition: margin-left 0.25s ease-in-out;
            z-index: 5;
            flex-shrink: 0;
        }
        #sidebar.collapsed {
            margin-left: -260px;
        }
        .sidebar-top {
            padding: 12px;
            border-bottom: 1px solid var(--border);
            display: flex;
            gap: 8px;
        }
        .btn-new-chat {
            flex: 1;
            background: #2563eb;
            color: #fff;
            font-weight: 600;
            border: none;
            border-radius: 8px;
            padding: 8px;
            text-align: center;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
        }
        .btn-new-chat:hover {
            background: #1d4ed8;
        }
        .sessions-list {
            flex: 1;
            overflow-y: auto;
            padding: 8px;
            display: flex;
            flex-direction: column;
            gap: 4px;
        }
        .session-item {
            padding: 8px 10px;
            border-radius: 8px;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: space-between;
            font-size: 0.85rem;
            color: #d4d4d8;
            transition: all 0.15s;
            border: 1px solid transparent;
        }
        .session-item:hover {
            background: #202024;
            color: #fff;
        }
        .session-item.active {
            background: #27272a;
            border-color: #3f3f46;
            color: #fff;
            font-weight: 600;
        }
        .session-title {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            flex: 1;
            margin-right: 6px;
        }
        .session-item .btn-del-session {
            background: transparent;
            border: none;
            color: #a1a1aa;
            padding: 0 4px;
            font-size: 0.9rem;
            opacity: 0.4;
            transition: opacity 0.15s;
        }
        .session-item:hover .btn-del-session {
            opacity: 1;
        }
        .session-item .btn-del-session:hover {
            color: #ef4444;
        }
        .sidebar-bottom {
            padding: 10px;
            border-top: 1px solid var(--border);
            font-size: 0.75rem;
            color: var(--text-muted);
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        /* Main Chat View */
        #content-area {
            flex: 1;
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }

        #main-view {
            flex: 1;
            display: flex;
            overflow: hidden;
            position: relative;
        }
        .chat-col {
            flex: 1;
            display: flex;
            flex-direction: column;
            overflow: hidden;
            border-right: 1px solid var(--border);
        }
        .chat-col:last-child {
            border-right: none;
        }
        .col-header {
            background: #1f1f23;
            border-bottom: 1px solid var(--border);
            padding: 6px 14px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            font-size: 0.88rem;
            font-weight: 600;
        }
        .col-messages {
            flex: 1;
            overflow-y: auto;
            padding: 16px;
            display: flex;
            flex-direction: column;
            gap: 14px;
        }

        .message {
            display: flex;
            flex-direction: column;
            max-width: 92%;
            line-height: 1.55;
            animation: fadeIn 0.2s ease-in-out;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(4px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .message.user {
            align-self: flex-end;
            background: var(--user-bubble);
            padding: 10px 14px;
            border-radius: 14px 14px 4px 14px;
            border: 1px solid #4a5568;
            font-size: 0.92rem;
        }
        .message.assistant {
            align-self: flex-start;
            background: var(--bg-card);
            padding: 14px 18px;
            border-radius: 14px 14px 14px 4px;
            border: 1px solid var(--border);
            width: 100%;
        }
        .message-meta {
            font-size: 0.72rem;
            color: var(--text-muted);
            margin-bottom: 4px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .message-content {
            font-size: 0.92rem;
            word-break: break-word;
        }
        .message-content pre {
            background: #111113;
            padding: 10px;
            border-radius: 6px;
            overflow-x: auto;
            margin: 8px 0;
            border: 1px solid #27272a;
        }
        .message-content code {
            font-family: Consolas, monospace;
            font-size: 0.9em;
            background: #27272a;
            padding: 2px 4px;
            border-radius: 4px;
        }
        .message-content pre code {
            background: transparent;
            padding: 0;
        }
        .message-content p {
            margin-bottom: 6px;
        }
        .message-content p:last-child {
            margin-bottom: 0;
        }
        .msg-image {
            max-width: 280px;
            max-height: 200px;
            border-radius: 6px;
            margin-bottom: 6px;
            display: block;
            border: 1px solid var(--border);
        }
        .msg-doc-badge {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            background: #1e293b;
            color: #93c5fd;
            padding: 4px 8px;
            border-radius: 6px;
            font-size: 0.8rem;
            margin-bottom: 6px;
            border: 1px solid #3b82f6;
        }

        #input-panel {
            background: var(--bg-card);
            border-top: 1px solid var(--border);
            padding: 8px 16px 12px 16px;
        }
        .quick-chips {
            max-width: 1200px;
            margin: 0 auto 6px auto;
            display: flex;
            gap: 6px;
            overflow-x: auto;
            padding-bottom: 4px;
        }
        .chip {
            background: #27272a;
            border: 1px solid var(--border);
            color: #e4e4e7;
            padding: 3px 8px;
            border-radius: 9999px;
            font-size: 0.76rem;
            cursor: pointer;
            white-space: nowrap;
            transition: all 0.2s;
        }
        .chip:hover {
            border-color: var(--fire);
            color: var(--fire);
            background: #2d2420;
        }
        .attachments-preview {
            max-width: 1200px;
            margin: 0 auto 6px auto;
            display: flex;
            flex-wrap: wrap;
            gap: 6px;
        }
        .attachment-item {
            background: #27272a;
            border: 1px solid var(--border);
            border-radius: 6px;
            padding: 4px 8px;
            display: flex;
            align-items: center;
            gap: 6px;
            font-size: 0.8rem;
            color: var(--text-main);
        }
        .attachment-thumb {
            width: 20px;
            height: 20px;
            object-fit: cover;
            border-radius: 4px;
        }
        .attachment-item .remove-btn {
            background: transparent;
            border: none;
            color: #ef4444;
            cursor: pointer;
            padding: 0 4px;
            font-weight: bold;
            font-size: 1rem;
        }
        .input-wrapper {
            max-width: 1200px;
            margin: 0 auto;
            display: flex;
            gap: 8px;
            align-items: flex-end;
        }
        .btn-attach {
            background: #27272a;
            color: var(--text-main);
            border: 1px solid var(--border);
            border-radius: 10px;
            padding: 0;
            width: 44px;
            height: 44px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.2rem;
            flex-shrink: 0;
        }
        .btn-attach:hover {
            border-color: var(--accent);
            background: #3f3f46;
        }
        textarea {
            flex: 1;
            background: #18181b;
            color: #fff;
            border: 1px solid var(--border);
            border-radius: 10px;
            padding: 10px 14px;
            font-size: 0.95rem;
            resize: none;
            outline: none;
            font-family: inherit;
            max-height: 180px;
            min-height: 44px;
            line-height: 1.4;
        }
        textarea:focus {
            border-color: var(--accent);
        }
        .btn-send {
            background: var(--accent);
            color: white;
            font-weight: 600;
            border: none;
            border-radius: 10px;
            padding: 10px 16px;
            height: 44px;
            flex-shrink: 0;
            font-size: 0.9rem;
        }
        .btn-send:hover {
            background: var(--accent-hover);
        }
        .btn-send:disabled {
            background: #52525b;
            cursor: not-allowed;
        }
        .typing {
            display: inline-block;
            font-style: italic;
            color: var(--text-muted);
        }

        /* Modal */
        .modal-overlay {
            position: fixed;
            top: 0; left: 0; right: 0; bottom: 0;
            background: rgba(0,0,0,0.7);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 1000;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.2s;
        }
        .modal-overlay.open {
            opacity: 1;
            pointer-events: auto;
        }
        .modal-card {
            background: #202024;
            border: 1px solid var(--border);
            border-radius: 12px;
            padding: 20px;
            max-width: 520px;
            width: 90%;
            box-shadow: 0 10px 30px rgba(0,0,0,0.5);
        }
        .modal-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 14px;
        }
        .modal-title {
            font-size: 1.1rem;
            font-weight: 700;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .key-list {
            margin: 12px 0;
            display: flex;
            flex-direction: column;
            gap: 8px;
            max-height: 200px;
            overflow-y: auto;
        }
        .key-item {
            background: #27272a;
            border: 1px solid var(--border);
            padding: 8px 12px;
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            font-size: 0.85rem;
        }
        .key-item.active {
            border-color: #10b981;
            background: #064e3b33;
        }
