/* ============================================
   VEIX Derived Intelligence Engine — Design System
   ============================================ */

/* --- CSS Custom Properties (Dark Theme Default) --- */
:root {
    --bg: #0a0a0f;
    --surface: #12121a;
    --surface-2: #1a1a25;
    --surface-3: #22222f;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.14);
    --text: #f0f0f5;
    --text-muted: #9394a5;
    --text-dim: #5d5e72;
    --accent: #7c5cfc;
    --accent-hover: #9b82fc;
    --accent-soft: rgba(124, 92, 252, 0.12);
    --accent-glow: rgba(124, 92, 252, 0.25);
    --gradient-accent: linear-gradient(135deg, #7c5cfc, #5eead4);
    --gradient-hero: linear-gradient(135deg, #7c5cfc 0%, #a78bfa 40%, #5eead4 100%);
    --success: #34d399;
    --warning: #fbbf24;
    --error: #f87171;
    --glass: rgba(18, 18, 26, 0.6);
    --glass-border: rgba(255, 255, 255, 0.06);
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 18px;
    --radius-xl: 26px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.45);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.55);
    --shadow-glow: 0 0 20px rgba(124, 92, 252, 0.15);
    --sidebar-width: 260px;
    --mobile-header-height: 56px;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Light Theme --- */
[data-theme="light"] {
    --bg: #f8f9fc;
    --surface: #ffffff;
    --surface-2: #f0f1f5;
    --surface-3: #e5e6ed;
    --border: rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.14);
    --text: #0f0f18;
    --text-muted: #6b6c80;
    --text-dim: #9e9fb5;
    --accent: #6d4afc;
    --accent-hover: #5538d4;
    --accent-soft: rgba(109, 74, 252, 0.08);
    --accent-glow: rgba(109, 74, 252, 0.15);
    --glass: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(0, 0, 0, 0.06);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.1);
    --shadow-glow: 0 0 20px rgba(109, 74, 252, 0.08);
}

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 14px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    overflow: hidden;
    height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

a {
    color: var(--accent);
    text-decoration: none;
}
a:hover {
    color: var(--accent-hover);
}

h1, h2, h3, h4 {
    font-weight: 600;
    line-height: 1.3;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* --- App Layout --- */
.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: width 0.25s ease, min-width 0.25s ease, transform 0.25s ease;
    backdrop-filter: blur(12px);
    overflow: hidden;
}

.sidebar-header {
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* --- Sidebar Collapse --- */
.sidebar-collapse-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    flex-shrink: 0;
}
.sidebar-collapse-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}

.sidebar.collapsed {
    width: 56px;
    min-width: 56px;
}
.sidebar.collapsed .logo-text,
.sidebar.collapsed .badge,
.sidebar.collapsed .nav-label {
    display: none;
}
.sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: 16px 8px 12px;
}
.sidebar.collapsed .sidebar-collapse-btn {
    transform: rotate(180deg);
}
.sidebar.collapsed .nav-btn {
    justify-content: center;
    padding: 10px 0;
    gap: 0;
}
.sidebar.collapsed .nav-icon {
    width: auto;
}
.sidebar.collapsed .sidebar-nav {
    padding: 12px 4px;
}
.sidebar.collapsed .sidebar-footer {
    padding: 12px 4px 16px;
}
.sidebar.collapsed .theme-toggle {
    justify-content: center;
    padding: 8px 0;
    gap: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    filter: drop-shadow(0 0 8px color-mix(in srgb, var(--accent) 50%, transparent));
}

.logo-text {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 2px;
    background: var(--gradient-hero);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.badge {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent);
    background: var(--accent-soft);
    padding: 3px 8px;
    border-radius: 4px;
}

/* --- Sidebar Nav --- */
.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 14px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
}

.nav-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}

.nav-btn.active {
    background: var(--accent-soft);
    color: var(--accent-hover);
    font-weight: 600;
    box-shadow: inset 3px 0 0 var(--accent);
}

.nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

/* --- Sidebar Footer --- */
.sidebar-footer {
    padding: 12px 8px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.theme-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 14px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition);
}
.theme-toggle:hover {
    background: var(--surface-2);
    color: var(--text);
}


/* ============================================
   MOBILE HEADER
   ============================================ */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--mobile-header-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 90;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
}

.hamburger {
    background: none;
    border: none;
    color: var(--text);
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}
.hamburger:hover {
    background: var(--surface-2);
}

.mobile-title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 2px;
    background: var(--gradient-hero);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.theme-toggle-mobile {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}
.theme-toggle-mobile:hover {
    background: var(--surface-2);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 95;
    opacity: 0;
    transition: opacity var(--transition);
}
.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* ============================================
   MAIN CONTENT
   ============================================ */
.content {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    position: relative;
}

/* --- View Management --- */
.view {
    display: none;
    height: 100%;
    overflow-y: auto;
}
.view.active {
    display: flex;
    flex-direction: column;
    animation: viewFadeIn 0.25s ease;
}

@keyframes viewFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================
   VIEW 1: CHAT
   ============================================ */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* --- Welcome Screen --- */
.welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    animation: welcomeFade 0.5s ease;
}

@keyframes welcomeFade {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

.welcome h1 {
    font-size: 52px;
    font-weight: 800;
    letter-spacing: 6px;
    background: var(--gradient-hero);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 12px;
    filter: drop-shadow(0 0 24px var(--accent-glow));
}

.welcome .subtitle {
    font-size: 16px;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 8px;
}

.welcome .description {
    font-size: 14px;
    color: var(--text-dim);
    max-width: 400px;
    margin-bottom: 32px;
}

.examples {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    max-width: 500px;
}

.example-chip {
    padding: 10px 20px;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    backdrop-filter: blur(8px);
}
.example-chip:hover {
    background: var(--accent-soft);
    color: var(--text);
    border-color: var(--accent);
    box-shadow: var(--shadow-glow);
    transform: translateY(-1px);
}

/* --- Chat Messages --- */
.message {
    display: flex;
    gap: 12px;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    animation: msgSlideIn 0.3s ease;
}

@keyframes msgSlideIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    justify-content: flex-end;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    font-weight: 600;
}

.message.user .message-avatar {
    background: var(--accent);
    color: white;
    order: 2;
}

.message.bot .message-avatar {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--accent);
}

.message-body {
    max-width: 680px;
    min-width: 0;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    line-height: 1.65;
    word-wrap: break-word;
}

.message.user .message-bubble {
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 12px var(--accent-glow);
}

.message.bot .message-bubble {
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-bottom-left-radius: 4px;
    backdrop-filter: blur(8px);
}

.message-bubble p {
    margin-bottom: 8px;
}
.message-bubble p:last-child {
    margin-bottom: 0;
}

.message-bubble code {
    background: var(--surface-2);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}

.message-bubble pre {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    overflow-x: auto;
    margin: 8px 0;
}
.message-bubble pre code {
    background: none;
    padding: 0;
    font-size: 13px;
    line-height: 1.5;
}

.message-bubble ul, .message-bubble ol {
    padding-left: 20px;
    margin: 8px 0;
}
.message-bubble li {
    margin-bottom: 4px;
}

.message-bubble strong {
    font-weight: 600;
}

/* Citation markers [1], [2] rendered as bold via cleanAnswer */
.message-bubble strong:has(+ strong) {
    /* Fallback handled by font-weight */
}

/* Make bot bubbles more readable */
.message.bot .message-bubble {
    font-size: 14.5px;
    letter-spacing: 0.01em;
    max-width: 720px;
}

.message-bubble h1, .message-bubble h2, .message-bubble h3 {
    margin: 12px 0 6px;
}
.message-bubble h1 { font-size: 18px; }
.message-bubble h2 { font-size: 16px; }
.message-bubble h3 { font-size: 15px; }

.message-bubble blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 12px;
    color: var(--text-muted);
    margin: 8px 0;
}

/* --- Message Metadata --- */
.message-meta {
    margin-top: 8px;
}

.confidence-bar-wrapper {
    margin: 8px 0;
}
.confidence-label {
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
}
.confidence-bar {
    height: 4px;
    background: var(--surface-2);
    border-radius: 2px;
    overflow: hidden;
}
.confidence-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.8s ease;
    width: 0;
}

.tool-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--accent-soft);
    color: var(--accent);
    margin-right: 4px;
    margin-bottom: 4px;
}

/* --- Sources --- */
.sources-section {
    margin-top: 10px;
}
.sources-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    padding: 4px 0;
    transition: color var(--transition);
}
.sources-toggle:hover {
    color: var(--text);
}
.sources-toggle .arrow {
    transition: transform var(--transition);
    display: inline-block;
    font-size: 10px;
}
.sources-toggle.expanded .arrow {
    transform: rotate(90deg);
}

.sources-list {
    display: none;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}
.sources-list.expanded {
    display: flex;
}

.source-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    font-size: 12px;
    transition: border-color var(--transition);
}
.source-card:hover {
    border-color: var(--accent);
}

.source-score {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    flex-shrink: 0;
}
.source-score.high { background: rgba(34,197,94,0.15); color: var(--success); }
.source-score.medium { background: rgba(245,158,11,0.15); color: var(--warning); }
.source-score.low { background: rgba(239,68,68,0.15); color: var(--error); }

.source-title {
    color: var(--text);
    font-weight: 500;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.source-url {
    color: var(--text-dim);
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
}

/* --- Typing Indicator --- */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}
.typing-indicator span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typingBounce 1.2s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* --- Chat Input Area --- */
.chat-input-area {
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding: 12px 16px 16px;
}

/* --- Engine Selector --- */
.engine-selector {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
}
.engine-btn {
    padding: 4px 13px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    letter-spacing: 0.02em;
}
.engine-btn:hover {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--text-dim);
}
.engine-btn.active {
    background: rgba(124, 92, 252, 0.14);
    border-color: var(--primary, #7c5cfc);
    color: var(--primary, #7c5cfc);
    font-weight: 600;
}

.input-controls {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 10px;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
}

.control-select {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 10px;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    outline: none;
    transition: border-color var(--transition);
}
.control-select:focus {
    border-color: var(--accent);
}

.control-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}
.control-checkbox input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--accent);
    cursor: pointer;
}

.input-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    max-width: 900px;
    margin: 0 auto;
}

#chat-input {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    color: var(--text);
    resize: none;
    outline: none;
    line-height: 1.5;
    max-height: 200px;
    overflow-y: auto;
    transition: border-color var(--transition), box-shadow var(--transition);
}
#chat-input::placeholder {
    color: var(--text-dim);
}
#chat-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.send-btn {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
    box-shadow: 0 2px 10px var(--accent-glow);
}
.send-btn:hover {
    background: linear-gradient(135deg, var(--accent-hover), var(--accent));
    transform: scale(1.05);
    box-shadow: 0 4px 16px var(--accent-glow);
}
.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ── Stop button ───────────────────────────────────────────────────────── */
.stop-btn {
    padding: 8px 14px;
    background: rgba(239, 68, 68, 0.10);
    border: 1px solid rgba(239, 68, 68, 0.28);
    border-radius: 10px;
    color: #ef4444;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
}
.stop-btn:hover {
    background: rgba(239, 68, 68, 0.20);
}

/* ── Session panel ─────────────────────────────────────────────────────── */
.session-panel {
    padding: 8px 10px 6px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.new-session-btn {
    width: 100%;
    padding: 6px 10px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
    margin-bottom: 5px;
}
.new-session-btn:hover {
    background: var(--border);
}
.session-list {
    max-height: 180px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.session-item {
    width: 100%;
    display: flex;
    align-items: center;
    border-radius: 5px;
    transition: background 0.15s;
}
.session-item:hover {
    background: var(--border);
}
.session-item.active {
    background: rgba(124, 92, 252, 0.14);
}
.session-item.active .session-name-btn {
    color: var(--primary, #7c5cfc);
    font-weight: 500;
}
.session-name-btn {
    flex: 1;
    min-width: 0;
    padding: 5px 8px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.15s;
}
.session-item:hover .session-name-btn {
    color: var(--text);
}
.session-delete-btn {
    flex-shrink: 0;
    padding: 3px 7px;
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 14px;
    cursor: pointer;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
    line-height: 1;
}
.session-item:hover .session-delete-btn {
    opacity: 1;
}
.session-delete-btn:hover {
    background: rgba(220, 50, 50, 0.12);
    color: #e05555;
}
.session-rename-input {
    flex: 1;
    min-width: 0;
    padding: 3px 6px;
    margin: 2px 4px;
    background: var(--surface-2, #2a2a3a);
    border: 1px solid var(--primary, #7c5cfc);
    border-radius: 4px;
    color: var(--text);
    font-size: 12px;
    outline: none;
}
/* --- Tooltip System --- */
[data-tooltip] {
    position: relative;
}
[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #1a1a2e;
    color: #e8e8f0;
    font-size: 11.5px;
    line-height: 1.45;
    padding: 6px 10px;
    border-radius: 6px;
    white-space: normal;
    width: max-content;
    max-width: 220px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.35);
    border: 1px solid rgba(124,92,252,0.18);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    transition-delay: 0.25s;
    z-index: 9999;
    text-align: center;
}
[data-tooltip]:hover::after {
    opacity: 1;
}
/* Arrow pointing down toward the element */
[data-tooltip]::before {
    content: "";
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #1a1a2e;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    transition-delay: 0.25s;
    z-index: 9999;
}
[data-tooltip]:hover::before {
    opacity: 1;
}
/* Tooltips that should appear below the element */
[data-tooltip-pos="below"]::after {
    bottom: auto;
    top: calc(100% + 8px);
}
[data-tooltip-pos="below"]::before {
    bottom: auto;
    top: calc(100% + 2px);
    border-top-color: transparent;
    border-bottom-color: #1a1a2e;
}
/* Hide tooltips on touch devices */
@media (hover: none) {
    [data-tooltip]::after,
    [data-tooltip]::before {
        display: none;
    }
}

/* --- Engine Hint Line --- */
.engine-hint {
    text-align: center;
    font-size: 11.5px;
    color: var(--text-dim);
    margin: 0 auto 8px;
    max-width: 900px;
    min-height: 16px;
    transition: color 0.2s;
    letter-spacing: 0.01em;
}

/* --- Mic Button --- */
.mic-btn {
    width: 44px;
    height: 44px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
}
.mic-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.mic-btn.listening {
    background: color-mix(in srgb, var(--error) 15%, transparent);
    border-color: var(--error);
    color: var(--error);
    animation: mic-pulse 1.2s ease-in-out infinite;
}
.mic-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--error) 40%, transparent); }
    50%       { box-shadow: 0 0 0 8px color-mix(in srgb, var(--error) 0%, transparent); }
}

/* --- Confidence boost notice (injected inline) --- */
.confidence-boost-notice {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--warning);
    margin-top: 6px;
    opacity: 0.85;
}

/* ============================================
   VIEW 5: FEEDBACK
   ============================================ */
.feedback-layout {
    padding: 32px 24px;
    max-width: 700px;
    overflow-y: auto;
    height: 100%;
}

.feedback-view-header {
    margin-bottom: 24px;
}
.feedback-view-header h2 {
    font-size: 24px;
    margin-bottom: 4px;
}
.feedback-view-header p {
    color: var(--text-muted);
    font-size: 14px;
}

.feedback-view-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 24px;
    backdrop-filter: blur(8px);
}

.feedback-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}
.feedback-field label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.feedback-form-row {
    display: flex;
    gap: 12px;
}

#feedback-comment,
#feedback-steps {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    color: var(--text);
    resize: vertical;
    min-height: 80px;
    font-size: 14px;
    line-height: 1.5;
}
#feedback-comment:focus,
#feedback-steps:focus {
    border-color: var(--accent);
    outline: none;
}

.feedback-extra-fields {
    display: none;
    flex-direction: column;
    gap: 16px;
}
.feedback-extra-fields.visible {
    display: flex;
}

.feedback-screenshot-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.feedback-screenshot-label {
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px 14px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    transition: border-color var(--transition), background var(--transition);
}
.feedback-screenshot-label:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}
.feedback-screenshot-name {
    font-size: 12px;
    color: var(--text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 250px;
}

.feedback-submit-btn {
    align-self: flex-start;
    padding: 12px 28px;
    border: none;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: 0 2px 10px var(--accent-glow);
}
.feedback-submit-btn:hover {
    background: linear-gradient(135deg, var(--accent-hover), var(--accent));
    box-shadow: 0 4px 16px var(--accent-glow);
    transform: translateY(-1px);
}

.feedback-history {
    margin-top: 32px;
}
.feedback-history h3 {
    font-size: 16px;
    margin-bottom: 12px;
    color: var(--text);
}
.feedback-history-empty {
    color: var(--text-dim);
    font-size: 13px;
}
.feedback-history-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 8px;
}
.feedback-history-item .fh-type {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 4px;
}
.feedback-history-item .fh-text {
    font-size: 13px;
    color: var(--text-muted);
}

/* ============================================
   VIEW 2: RESEARCH
   ============================================ */
.research-layout {
    display: flex;
    height: 100%;
    overflow: hidden;
}

.research-main {
    flex: 1;
    padding: 32px 24px;
    overflow-y: auto;
}

.research-header {
    max-width: 700px;
    margin-bottom: 24px;
}
.research-header h2 {
    font-size: 24px;
    margin-bottom: 4px;
}
.research-header p {
    color: var(--text-muted);
    font-size: 14px;
}

.research-search {
    display: flex;
    gap: 8px;
    max-width: 700px;
    margin-bottom: 24px;
}

.research-input {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color var(--transition);
}
.research-input:focus {
    border-color: var(--accent);
}

.research-btn {
    padding: 12px 24px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    box-shadow: 0 2px 10px var(--accent-glow);
}
.research-btn:hover {
    box-shadow: 0 4px 16px var(--accent-glow);
    transform: translateY(-1px);
}
.research-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.research-results {
    max-width: 700px;
}

.research-result-card {
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 24px;
    margin-bottom: 16px;
    animation: viewFadeIn 0.3s ease;
    backdrop-filter: blur(8px);
}
.research-result-card h3 {
    font-size: 16px;
    margin-bottom: 12px;
    color: var(--accent-hover);
}
.research-result-card .answer-text {
    line-height: 1.7;
    color: var(--text);
}
.research-result-card .answer-text .citation {
    color: var(--accent);
    font-weight: 600;
    font-size: 12px;
    vertical-align: super;
    cursor: pointer;
}
.research-result-card .answer-text .citation:hover {
    text-decoration: underline;
}

/* --- Research Sources Panel --- */
.research-sources {
    width: 300px;
    min-width: 300px;
    border-left: 1px solid var(--border);
    background: var(--surface);
    padding: 24px 16px;
    overflow-y: auto;
}
.research-sources h3 {
    font-size: 14px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 16px;
}

.source-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.source-list-item {
    padding: 12px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    transition: border-color var(--transition);
}
.source-list-item:hover {
    border-color: var(--accent);
}
.source-list-item .source-item-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.source-list-item .source-item-url {
    font-size: 11px;
    color: var(--text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.source-list-item .source-item-score {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 4px;
    margin-top: 6px;
}

/* ============================================
   VIEW 3: KNOWLEDGE
   ============================================ */
.knowledge-layout {
    max-width: 900px;
    margin: 0 auto;
    padding: 32px 24px;
}

.knowledge-header {
    margin-bottom: 24px;
}
.knowledge-header h2 {
    font-size: 24px;
    margin-bottom: 4px;
}
.knowledge-header p {
    color: var(--text-muted);
    font-size: 14px;
}

/* --- Upload Zone --- */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    margin-bottom: 24px;
    background: var(--surface);
    backdrop-filter: blur(8px);
}
.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.upload-icon {
    font-size: 36px;
    margin-bottom: 12px;
}

.upload-zone p {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 4px;
}

.upload-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    font-size: 14px;
}
.upload-btn:hover {
    color: var(--accent-hover);
}

.upload-hint {
    font-size: 12px !important;
    color: var(--text-dim) !important;
}

/* Upload progress */
.upload-progress {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.upload-progress-bar {
    height: 4px;
    background: var(--surface-2);
    border-radius: 2px;
    overflow: hidden;
}
.upload-progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0;
}
.upload-progress-text {
    font-size: 12px;
    color: var(--text-muted);
}

/* --- Knowledge Search --- */
.knowledge-search {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
}

.knowledge-search input {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    color: var(--text);
    outline: none;
    transition: border-color var(--transition);
}
.knowledge-search input:focus {
    border-color: var(--accent);
}

.search-btn {
    padding: 10px 20px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}
.search-btn:hover {
    background: var(--accent-hover);
}

/* --- Knowledge List --- */
.knowledge-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.knowledge-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color var(--transition);
    animation: viewFadeIn 0.25s ease;
}
.knowledge-item:hover {
    border-color: var(--accent);
}

.knowledge-item-icon {
    font-size: 20px;
    flex-shrink: 0;
    width: 32px;
    text-align: center;
}

.knowledge-item-info {
    flex: 1;
    min-width: 0;
}
.knowledge-item-name {
    font-weight: 600;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.knowledge-item-meta {
    font-size: 12px;
    color: var(--text-dim);
}

.knowledge-item-status {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 10px;
    flex-shrink: 0;
}
.knowledge-item-status.ready {
    background: rgba(34,197,94,0.15);
    color: var(--success);
}
.knowledge-item-status.processing {
    background: rgba(245,158,11,0.15);
    color: var(--warning);
}
.knowledge-item-status.error {
    background: rgba(239,68,68,0.15);
    color: var(--error);
}

/* ============================================
   VIEW 4: ADMIN
   ============================================ */
.admin-layout {
    max-width: 1100px;
    margin: 0 auto;
    padding: 32px 24px;
}

.admin-layout h2 {
    font-size: 24px;
    margin-bottom: 24px;
}

/* --- Admin Grid --- */
.admin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.admin-card {
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 20px;
    transition: all var(--transition);
    backdrop-filter: blur(8px);
}
.admin-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-glow);
}

.admin-card h3 {
    font-size: 13px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.stats-content {
    font-size: 13px;
    color: var(--text);
}

.stat-number {
    font-size: 32px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 12px;
    color: var(--text-dim);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}
.stat-row:last-child {
    border-bottom: none;
}

.health-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}
.health-dot.green { background: var(--success); }
.health-dot.yellow { background: var(--warning); }
.health-dot.red { background: var(--error); }

/* --- Admin Section --- */
.admin-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
}

.admin-section h3 {
    font-size: 15px;
    margin-bottom: 16px;
}

/* --- Audit Table --- */
.audit-table-wrapper {
    overflow-x: auto;
}

.audit-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.audit-table th {
    text-align: left;
    padding: 10px 12px;
    background: var(--surface-2);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}

.audit-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

.audit-table tbody tr:nth-child(even) {
    background: var(--surface-2);
}
.audit-table tbody tr:hover {
    background: var(--accent-soft);
}

.audit-table tbody tr:last-child td {
    border-bottom: none;
}

/* --- Loading spinner --- */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Toast / Notification --- */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    animation: toastIn 0.3s ease;
}
.toast.error { border-color: var(--error); }
.toast.success { border-color: var(--success); }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-dim);
}
.empty-state-icon {
    font-size: 36px;
    margin-bottom: 12px;
    opacity: 0.5;
}
.empty-state p {
    font-size: 14px;
}

/* ============================================
   RESPONSIVE — MOBILE (<768px)
   ============================================ */
@media (max-width: 768px) {
    body {
        overflow: hidden;
        height: 100dvh;
    }

    .app {
        height: 100dvh;
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100dvh;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open {
        transform: translateX(0);
    }

    .mobile-header {
        display: flex;
        flex-shrink: 0;
    }

    .content {
        margin-top: var(--mobile-header-height);
        height: calc(100dvh - var(--mobile-header-height));
        overflow: hidden;
    }

    /* Chat view must flex so input stays pinned at bottom */
    #view-chat.active {
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .chat-messages {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 16px 12px;
    }

    .chat-input-area {
        flex-shrink: 0;
        padding: 10px 12px calc(env(safe-area-inset-bottom, 0px) + 14px);
    }

    .welcome h1 {
        font-size: 36px;
    }

    .welcome {
        padding: 28px 12px;
    }

    .examples {
        flex-direction: column;
        align-items: center;
    }

    .example-chip {
        white-space: normal;
        width: min(100%, 280px);
        text-align: center;
    }

    .input-controls {
        flex-wrap: wrap;
        gap: 10px;
    }

    /* Hide sidebar collapse on mobile — use hamburger instead */
    .sidebar-collapse-btn {
        display: none;
    }

    .sidebar.collapsed {
        width: var(--sidebar-width);
        min-width: var(--sidebar-width);
    }
    .sidebar.collapsed .logo-text,
    .sidebar.collapsed .badge,
    .sidebar.collapsed .nav-label {
        display: unset;
    }

    .feedback-form-row {
        flex-direction: column;
    }

    .feedback-submit-btn {
        width: 100%;
    }

    /* Feedback view */
    .feedback-layout {
        padding: 20px 16px;
    }

    .control-select {
        min-height: 36px;
    }

    .control-checkbox {
        min-height: 36px;
    }

    .message {
        gap: 8px;
    }

    .message-avatar {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }

    .message-bubble {
        padding: 10px 12px;
        font-size: 14px;
    }

    .message-body {
        max-width: calc(100vw - 72px);
    }

    .input-form {
        align-items: stretch;
    }

    .send-btn {
        width: 44px;
        height: auto;
        min-height: 44px;
    }

    /* Research view stacks on mobile */
    .research-layout {
        flex-direction: column;
        overflow-y: auto;
    }

    .research-search {
        flex-direction: column;
    }

    .research-btn {
        width: 100%;
    }

    .research-sources {
        width: 100%;
        min-width: unset;
        border-left: none;
        border-top: 1px solid var(--border);
        max-height: 250px;
        padding: 16px;
    }
    .research-main {
        padding: 20px 16px;
    }

    /* Knowledge */
    .knowledge-layout {
        padding: 20px 16px;
    }

    .knowledge-search {
        flex-direction: column;
    }

    .search-btn {
        width: 100%;
    }

    .upload-zone {
        padding: 28px 16px;
    }

    /* Admin */
    .admin-layout {
        padding: 20px 16px;
        overflow-y: auto;
    }
    .admin-grid {
        grid-template-columns: 1fr;
    }

    .audit-table {
        font-size: 12px;
    }

    .audit-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 480px) {
    .mobile-header {
        padding: 0 12px;
    }

    .mobile-title {
        font-size: 16px;
        letter-spacing: 1px;
    }

    .welcome h1 {
        font-size: 30px;
        letter-spacing: 2px;
    }

    .welcome .subtitle {
        font-size: 14px;
    }

    .research-main,
    .knowledge-layout,
    .admin-layout {
        padding-left: 12px;
        padding-right: 12px;
    }

    .knowledge-item,
    .admin-card,
    .admin-section,
    .research-result-card {
        padding: 12px;
    }

    /* Feedback form compact on tiny screens */
    .feedback-toggle-btn {
        font-size: 12px;
        padding: 8px 10px;
    }

    #feedback-comment {
        min-height: 56px;
    }

    .feedback-severity-row,
    .feedback-extra-fields {
        font-size: 12px;
    }
}

/* ============================================
   FOCUS MANAGEMENT
   ============================================ */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
select:focus:not(:focus-visible),
textarea:focus:not(:focus-visible) {
    outline: none;
}

/* ============================================
   SELECTION
   ============================================ */
::selection {
    background: var(--accent-soft);
    color: var(--text);
}

/* ============================================
   AUTH SYSTEM
   ============================================ */

/* Auth modal overlay */
.auth-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(6px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: fadeIn 0.2s ease;
}
.auth-overlay[hidden] { display: none; }

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.auth-modal {
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 32px 28px 28px;
    width: 100%;
    max-width: 400px;
    position: relative;
    box-shadow: 0 24px 64px rgba(0,0,0,0.4);
    animation: slideUp 0.22s ease;
}
@keyframes slideUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

.auth-modal-close {
    position: absolute;
    top: 12px;
    right: 14px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 22px;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
}
.auth-modal-close:hover { color: var(--text); background: var(--surface-2); }

.auth-modal-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 1px;
    background: var(--gradient-hero);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-modal-sub {
    font-size: 13px;
    color: var(--text-muted);
    margin: 0 0 20px;
}

/* Google button */
.google-oauth-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 11px 16px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all var(--transition);
}
.google-oauth-btn:hover {
    border-color: var(--accent);
    background: var(--glass);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Divider */
.auth-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 16px 0;
    color: var(--text-muted);
    font-size: 12px;
}
.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* Tabs */
.auth-tabs {
    display: flex;
    background: var(--surface-2);
    border-radius: var(--radius-md);
    padding: 3px;
    margin-bottom: 18px;
}
.auth-tab {
    flex: 1;
    padding: 8px;
    border: none;
    background: none;
    border-radius: calc(var(--radius-md) - 2px);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}
.auth-tab.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.auth-tab-panel[hidden] { display: none; }

/* Auth form */
.auth-form { display: flex; flex-direction: column; gap: 12px; }

.auth-field { display: flex; flex-direction: column; gap: 5px; }
.auth-field label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.auth-field input {
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    font-size: 14px;
    transition: all var(--transition);
}
.auth-field input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.auth-error {
    font-size: 12px;
    color: var(--error);
    min-height: 16px;
}

.auth-submit-btn {
    width: 100%;
    padding: 11px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    margin-top: 4px;
    box-shadow: 0 2px 10px var(--accent-glow);
}
.auth-submit-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px var(--accent-glow);
}
.auth-submit-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* User profile in sidebar */
.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
}
.user-profile[hidden] { display: none; }
.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: white;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.user-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-logout-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    padding: 0;
    text-align: left;
}
.user-logout-btn:hover { color: var(--error); }

/* Sidebar sign-in button */
.sidebar-signin-btn {
    width: 100%;
    padding: 9px 12px;
    background: var(--accent-soft);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    color: var(--accent);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    margin-bottom: 8px;
    transition: all var(--transition);
}
.sidebar-signin-btn:hover {
    background: var(--accent);
    color: white;
}
.sidebar-signin-btn[hidden] { display: none; }

/* Guest limit bar */
.guest-limit-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 12px;
    background: color-mix(in srgb, var(--warning) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--warning) 30%, transparent);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    font-size: 12px;
    color: var(--warning);
}
.guest-limit-bar[hidden] { display: none; }
.guest-limit-bar.critical {
    background: color-mix(in srgb, var(--error) 10%, transparent);
    border-color: color-mix(in srgb, var(--error) 30%, transparent);
    color: var(--error);
}
.guest-signin-chip {
    background: var(--accent);
    border: none;
    border-radius: 20px;
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition);
}
.guest-signin-chip:hover { opacity: 0.85; }

/* API Keys section */
.admin-section-note {
    font-size: 13px;
    color: var(--text-muted);
    margin: 0 0 14px;
}
.api-keys-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.api-key-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 13px;
}
.api-key-item-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.api-key-item-name { font-weight: 600; color: var(--text); }
.api-key-item-preview { color: var(--text-muted); font-family: monospace; font-size: 12px; }
.api-key-revoke-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 11px;
    padding: 4px 8px;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}
.api-key-revoke-btn:hover { border-color: var(--error); color: var(--error); }

.api-key-create-form {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}
.api-key-name-input {
    flex: 1;
    padding: 9px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    font-size: 13px;
}
.api-key-name-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.api-key-generate-btn {
    padding: 9px 16px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 2px 8px var(--accent-glow);
}
.api-key-generate-btn:hover { opacity: 0.9; }

.api-key-reveal { margin-top: 4px; }
.api-key-reveal[hidden] { display: none; }
.api-key-reveal-note {
    font-size: 12px;
    color: var(--warning);
    margin: 0 0 8px;
}
.api-key-display {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}
.api-key-code {
    flex: 1;
    font-family: monospace;
    font-size: 12px;
    color: var(--accent);
    word-break: break-all;
}
.api-key-copy-btn {
    padding: 5px 12px;
    background: var(--accent-soft);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--accent);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}
.api-key-copy-btn:hover { background: var(--accent); color: white; }

/* Collapsed sidebar: hide sign-in btn and user profile text */
.sidebar.collapsed .sidebar-signin-btn { display: none; }
.sidebar.collapsed .user-info { display: none; }
.sidebar.collapsed .user-profile { justify-content: center; padding: 8px 4px; }

/* ============================================
   DEVELOPER PORTAL
   ============================================ */

.dev-portal-layout {
    padding: 28px 32px;
    max-width: 1200px;
    margin: 0 auto;
    height: 100%;
    overflow-y: auto;
}

/* Header */
.dev-portal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 28px;
    flex-wrap: wrap;
}
.dev-portal-header-text h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
    background: var(--gradient-accent);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.dev-portal-header-text p {
    color: var(--text-muted);
    font-size: 13.5px;
}
.dev-portal-account {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 8px 14px;
    font-size: 13px;
}
.dev-account-name { color: var(--text); font-weight: 600; }
.dev-account-meta { color: var(--text-muted); }

/* Two-column grid */
.dev-portal-grid {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 20px;
    align-items: start;
}
@media (max-width: 900px) {
    .dev-portal-grid { grid-template-columns: 1fr; }
    .dev-portal-layout { padding: 16px; }
}

.dev-portal-main, .dev-portal-sidebar { display: flex; flex-direction: column; gap: 20px; }

/* Card */
.dev-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px 24px;
}
.dev-card-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.dev-card-header h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}
.dev-card-note {
    font-size: 12px;
    color: var(--text-muted);
}
.dev-card-note code {
    font-size: 11px;
    background: var(--surface-3);
    padding: 1px 5px;
    border-radius: 4px;
}

/* Spinner placeholder */
.dev-spinner { color: var(--text-muted); font-size: 13px; padding: 8px 0; }

/* Empty state */
.dev-empty { color: var(--text-muted); font-size: 13px; padding: 6px 0; }

/* Key list */
.dev-keys-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
    min-height: 20px;
}
.dev-key-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.dev-key-row-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    min-width: 0;
}
.dev-key-row-name { font-weight: 600; font-size: 13px; color: var(--text); }
.dev-key-row-preview {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 12px;
    color: var(--text-muted);
    background: var(--surface-3);
    padding: 2px 7px;
    border-radius: 5px;
}
.dev-key-row-date { font-size: 11px; color: var(--text-dim); }

/* Key create form */
.dev-key-create-form {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}
.dev-input {
    flex: 1;
    min-width: 160px;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 9px 13px;
    color: var(--text);
    font-size: 13px;
    outline: none;
    transition: border-color var(--transition);
}
.dev-input:focus { border-color: var(--accent); }

/* Buttons */
.dev-btn-primary {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    padding: 9px 18px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
    white-space: nowrap;
}
.dev-btn-primary:hover { background: var(--accent-hover); }
.dev-btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.dev-btn-revoke {
    background: transparent;
    color: var(--error);
    border: 1px solid var(--error);
    border-radius: var(--radius-sm);
    padding: 5px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    white-space: nowrap;
    flex-shrink: 0;
}
.dev-btn-revoke:hover { background: var(--error); color: white; }

/* Key reveal banner */
.dev-key-reveal {
    margin-top: 14px;
    border: 1px solid var(--warning);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.dev-key-reveal-banner {
    background: rgba(251, 191, 36, 0.1);
    padding: 8px 14px;
    font-size: 12px;
    color: var(--warning);
}
.dev-key-reveal-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--surface-2);
}
.dev-key-code {
    flex: 1;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 12px;
    word-break: break-all;
    color: var(--success);
}
.dev-btn-copy {
    background: var(--surface-3);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 5px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: background var(--transition);
    flex-shrink: 0;
}
.dev-btn-copy:hover { background: var(--accent); color: white; border-color: var(--accent); }

/* Usage stats */
.dev-stat-pills {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.dev-stat-pill {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 18px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 100px;
}
.dev-stat-num { font-size: 20px; font-weight: 700; color: var(--accent); }
.dev-stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* Usage table */
.dev-usage-table-wrap { overflow-x: auto; }
.dev-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
}
.dev-table th {
    text-align: left;
    padding: 7px 10px;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.dev-table td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-family: 'JetBrains Mono', monospace;
    font-size: 11.5px;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.dev-table tr:last-child td { border-bottom: none; }
.dev-table tr:hover td { background: var(--surface-2); }

/* Quickstart tabs */
.dev-quickstart { }
.dev-qs-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
}
.dev-qs-tab {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 12.5px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}
.dev-qs-tab:hover { color: var(--text); background: var(--surface-2); }
.dev-qs-tab.active { color: var(--accent); background: var(--accent-soft); }

.dev-code-block {
    display: none;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin: 0;
    overflow-x: auto;
}
.dev-code-block.active { display: block; }
.dev-code-block code {
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 11.5px;
    color: var(--text);
    white-space: pre;
}

/* Endpoint reference */
.dev-endpoints-list { display: flex; flex-direction: column; gap: 12px; }
.dev-endpoint-item {
    padding: 12px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.dev-endpoint-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 5px;
}
.dev-method {
    font-size: 10.5px;
    font-weight: 800;
    padding: 2px 8px;
    border-radius: 4px;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}
.dev-method-get    { background: rgba(52, 211, 153, 0.15); color: var(--success); }
.dev-method-post   { background: rgba(124, 92, 252, 0.15); color: var(--accent); }
.dev-method-delete { background: rgba(248, 113, 113, 0.15); color: var(--error); }
.dev-endpoint-path {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--text);
}
.dev-endpoint-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin: 2px 0 5px;
    line-height: 1.5;
}
.dev-endpoint-auth {
    font-size: 11px;
    color: var(--text-dim);
    font-style: italic;
}

