/* ── Design tokens ─────────────────────────────── */
:root {
    --bg:                  #0c0a1a;
    --surface:             rgba(20, 16, 40, 0.6);
    --surface-hover:       rgba(255,255,255,0.08);
    --border:              rgba(255,255,255,0.08);
    --accent:              #8b5cf6;
    --accent-dark:         #7c3aed;
    --accent-glow:         rgba(139,92,246,0.25);
    --cyan:                #06b6d4;
    --green:               #10b981;
    --red:                 #ef4444;
    --text-1:              #f3f4f6;
    --text-2:              #9ca3af;
    --text-3:              #6b7280;
    --bubble-user:         rgba(139,92,246,0.22);
    --bubble-ai:           rgba(255,255,255,0.04);
    --radius-sm:           8px;
    --radius-md:           14px;
    --radius-lg:           20px;
    --shadow-panel:        0 20px 60px rgba(0,0,0,0.5);
    --font-display:        'Outfit', sans-serif;
    --font-sans:           'Inter', sans-serif;
    --sidebar-w:           260px;
    --sidebar-collapsed-w: 60px;
    --transition:          0.25s ease;
}

/* ── Reset ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; overflow: hidden; }

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text-1);
    height: 100%;
    overflow: hidden;
    display: flex;
}

/* ── Background glows ──────────────────────────── */
body::before,
body::after {
    content: '';
    position: fixed;
    border-radius: 50%;
    filter: blur(120px);
    pointer-events: none;
    z-index: 0;
}
body::before {
    width: 45vw; height: 45vw;
    background: var(--accent);
    opacity: 0.18;
    top: -10%; left: -10%;
}
body::after {
    width: 50vw; height: 50vw;
    background: var(--cyan);
    opacity: 0.12;
    bottom: -15%; right: -10%;
}

/* ── Auth overlay ──────────────────────────────── */
#auth-screen {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(8, 6, 20, 0.92);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
    transition: opacity var(--transition), visibility var(--transition);
}
#auth-screen.hidden,
.authed #auth-screen {
    display: none;
}

.auth-logo {
    font-family: var(--font-display);
    font-size: clamp(3rem, 8vw, 5rem);
    font-weight: 800;
    letter-spacing: 6px;
    background: linear-gradient(135deg, #fff 0%, var(--accent) 50%, var(--cyan) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 12px;
}
.auth-subtitle {
    color: var(--text-2);
    font-size: clamp(0.85rem, 2vw, 1rem);
    max-width: 380px;
    line-height: 1.7;
    margin-bottom: 40px;
}
.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: clamp(24px, 5vw, 40px);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: var(--shadow-panel);
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.auth-card label {
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-3);
    letter-spacing: 1.2px;
    text-transform: uppercase;
}
.google-login-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 12px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), transform 0.1s;
    box-shadow: none;
}
.google-login-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
}
.google-login-btn:active {
    transform: scale(0.98);
}
.plans-link {
    display: inline-block;
    color: var(--accent);
    font-size: 0.82rem;
    text-decoration: none;
    font-weight: 600;
    opacity: 0.85;
    transition: opacity var(--transition), color var(--transition);
    text-align: center;
    margin-top: 2px;
}
.plans-link:hover {
    opacity: 1;
    color: var(--cyan);
}
.consent-checkbox-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 10px 0 6px;
    text-align: left;
}
.consent-checkbox-wrapper input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.03);
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    margin-top: 0px;
    transition: border-color var(--transition);
}
.consent-checkbox-wrapper input[type="checkbox"]:checked {
    background-color: var(--accent);
    border-color: var(--accent);
    background-image: url("data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220%200%2024%2024%22%20fill=%22none%22%20stroke=%22white%22%20stroke-width=%224.5%22%20stroke-linecap=%22round%22%20stroke-linejoin=%22round%22%3E%3Cpolyline%20points=%2220%206%209%2017%204%2012%22/%3E%3C/svg%3E");
    background-size: 11px 11px;
    background-position: center;
    background-repeat: no-repeat;
}
.consent-checkbox-wrapper label {
    font-size: 0.78rem !important;
    line-height: 1.45;
    color: var(--text-2) !important;
    font-weight: normal !important;
    text-transform: none !important;
    letter-spacing: normal !important;
    cursor: pointer;
    user-select: none;
}
.consent-checkbox-wrapper label a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    border-bottom: 1px dashed rgba(139, 92, 246, 0.4);
    padding-bottom: 1px;
    transition: all var(--transition);
}
.consent-checkbox-wrapper label a:hover {
    color: var(--cyan);
    border-bottom: 1px solid var(--cyan);
}
.uuid-input {
    width: 100%;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.04);
    color: var(--text-1);
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    outline: none;
    text-align: left;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.uuid-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.uuid-input::placeholder { color: var(--text-3); }
.auth-btn {
    padding: 14px;
    border-radius: var(--radius-sm);
    border: none;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: #fff;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: filter var(--transition), transform var(--transition), box-shadow var(--transition);
    box-shadow: 0 6px 20px var(--accent-glow);
}
.auth-btn:hover {
    filter: brightness(1.12);
    transform: translateY(-1px);
    box-shadow: 0 10px 28px var(--accent-glow);
}
.auth-btn:active { transform: translateY(0); }
.auth-error {
    font-size: 0.8rem;
    color: var(--red);
    text-align: left;
    display: flex;
    align-items: center;
    gap: 6px;
}
.auth-error:empty {
    display: none;
}

/* ── App shell — full screen ───────────────────── */
#app {
    position: relative;
    z-index: 1;
    flex: 1;
    height: 100%;
    display: flex;
    overflow: hidden;
    background: var(--surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

/* ── Sidebar ───────────────────────────────────── */
#sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: rgba(10, 8, 22, 0.92);
    overflow: hidden;
    transition: width var(--transition), min-width var(--transition);
}

/* Prevent text wrapping during width transition */
.sidebar-logo, .nav-item, .nav-label, .history-item,
.history-item-title, .logout-btn, .section-label,
.conn-label, .uid-badge {
    white-space: nowrap;
}

/* ── Icon zone: fixed 60px column, always centered ─ */
.nav-icon-zone {
    width: var(--sidebar-collapsed-w);
    min-width: var(--sidebar-collapsed-w);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ── Labels/body: fade OUT fast, fade IN delayed (after width) ── */
.sidebar-logo {
    position: absolute;     /* out of flex flow — never moves, only fades */
    left: 14px;
    top: 6px;               /* (44px content - 32px logo) / 2 — explicit avoids sub-pixel issues */
    width: 32px;
    height: 32px;
    overflow: hidden;
    transition: opacity 0.15s ease 0.18s; /* expand: same timing as text labels */
}
.nav-label, .conn-label, .uid-badge, .section-label {
    transition: opacity 0.15s ease 0.18s;
    overflow: hidden;
    white-space: nowrap;
}
.sidebar-body {
    transition: opacity 0.15s ease 0.18s;
}

/* ── Sidebar: collapsed state ──────────────────── */
#sidebar.collapsed {
    width: var(--sidebar-collapsed-w);
    min-width: var(--sidebar-collapsed-w);
}

#sidebar.collapsed .sidebar-logo {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.1s ease; /* same timing as text labels */
}
#sidebar.collapsed .nav-label,
#sidebar.collapsed .conn-label,
#sidebar.collapsed .uid-badge,
#sidebar.collapsed .section-label {
    opacity: 0; pointer-events: none;
    transition: opacity 0.1s ease;
}
#sidebar.collapsed .sidebar-body {
    opacity: 0; pointer-events: none;
    transition: opacity 0.1s ease;
}

/* Nav item: icon zone stays 60px, no dimension changes.
   NO justify-content:center here — that would move the icon to the center of the
   260px sidebar at the moment the class is applied, before the width animates. */
#sidebar.collapsed .nav-item {
    padding: 0;
    border-radius: 0;
    background: none;
    position: relative;
}

/* Circular hover via ::before — left:12px is px (not %), so the circle stays
   at x=30px even while the sidebar width is still animating */
#sidebar.collapsed .nav-item::before {
    content: '';
    position: absolute;
    inset: unset;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: transparent;
    transition: background 0.15s ease;
    pointer-events: none;
}
#sidebar.collapsed .nav-item:hover { background: none; }
#sidebar.collapsed .nav-item:hover::before { background: var(--surface-hover); }

/* Footer collapsed: connection-block gets circular hover like nav-item and logout */
#sidebar.collapsed .connection-block { border-bottom: none; position: relative; }
#sidebar.collapsed .connection-block::before {
    content: '';
    position: absolute;
    inset: unset;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: transparent;
    transition: background 0.15s ease;
    pointer-events: none;
}
#sidebar.collapsed .connection-block:hover { background: none; }
#sidebar.collapsed .connection-block:hover::before { background: var(--surface-hover); }
#sidebar.collapsed .logout-btn {
    padding: 0;
    border-radius: 0;
    position: relative;
    /* NO justify-content:center — same reason as nav-item */
}
#sidebar.collapsed .logout-btn::before {
    content: '';
    position: absolute;
    inset: unset;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: transparent;
    transition: background 0.15s ease;
    pointer-events: none;
}
#sidebar.collapsed .logout-btn:hover { background: none; color: #f87171; }
#sidebar.collapsed .logout-btn:hover::before { background: rgba(239,68,68,0.1); }

/* ── Sidebar header ────────────────────────────── */
.sidebar-head {
    height: 45px;       /* fixed — same in both states, no vertical jump */
    padding: 0;         /* no padding in either state → no instant layout change on toggle */
    display: flex;
    align-items: center;
    flex-shrink: 0;
    position: relative; /* containing block for absolutely-positioned logo */
}

/* 60px fixed zone with margin-left:auto — slides with sidebar right edge during animation.
   In collapsed (60px): auto-margin=0, zone fills header, toggle centered at x=30.
   margin-right:8px gives breathing room from sidebar border in expanded state;
   in collapsed it just adds 8px after the zone (sidebar clips it, invisible). */
.sidebar-head-btns {
    width: var(--sidebar-collapsed-w);
    min-width: var(--sidebar-collapsed-w);
    margin-left: auto;
    margin-right: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-3);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    line-height: 0;
    transition: color var(--transition), background var(--transition);
    flex-shrink: 0;
}
.icon-btn:hover { color: var(--text-1); background: var(--surface-hover); }

/* Desktop: toggle visible, close hidden */
.sidebar-toggle { display: flex; }
.sidebar-close  { display: none; }

/* ── Sidebar nav ───────────────────────────────── */
.sidebar-nav {
    padding: 8px 0;
    flex-shrink: 0;
}

.nav-item {
    width: 100%;
    position: relative;
    display: flex;
    align-items: center;
    gap: 0;
    height: 44px;
    padding: 0 10px 0 0;
    border-radius: var(--radius-sm);
    border: none;
    background: none;
    color: var(--text-2);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    transition: color var(--transition);
}
.nav-item::before {
    content: '';
    position: absolute;
    inset: 2px 8px;
    background: transparent;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
    pointer-events: none;
}
.nav-item:hover { color: var(--text-1); }
.nav-item:hover::before { background: var(--surface-hover); }

/* ── Sidebar body (history) ────────────────────── */
.sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
}
.sidebar-body::-webkit-scrollbar { width: 3px; }
.sidebar-body::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.07);
    border-radius: 2px;
}

.section-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-3);
    padding: 0 6px 0 10px;
    margin-bottom: 4px;
    flex-shrink: 0;
}

/* ── History items ─────────────────────────────── */
#history-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.history-item {
    width: 100%;
    position: relative;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    border: none;
    background: none;
    color: var(--text-2);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    cursor: pointer;
    text-align: left;
    overflow: visible;
    transition: background var(--transition), color var(--transition);
}
.history-item > svg { flex-shrink: 0; opacity: 0.6; }
.history-item-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}
.history-item:hover {
    background: var(--surface-hover);
    color: var(--text-1);
}
.history-item:hover > svg { opacity: 1; }
.history-item.active {
    background: rgba(139,92,246,0.12);
    color: var(--text-1);
    border: 1px solid rgba(139,92,246,0.2);
}
.history-item.active > svg { opacity: 1; color: var(--accent); }

.history-menu-btn {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--text-3);
    cursor: pointer;
    padding: 3px 4px;
    border-radius: 5px;
    line-height: 0;
    opacity: 0;
    transition: opacity var(--transition), background var(--transition), color var(--transition);
}
.history-item:hover .history-menu-btn,
.history-item.active .history-menu-btn { opacity: 1; }
.history-menu-btn:hover { background: rgba(255,255,255,0.1); color: var(--text-1); }

.history-dropdown {
    display: none;
    position: absolute;
    right: 4px;
    top: calc(100% + 2px);
    background: #1a1530;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    z-index: 200;
    min-width: 140px;
    padding: 4px;
}
.history-dropdown.open { display: block; }
.history-dropdown-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: none;
    background: none;
    color: var(--text-2);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    cursor: pointer;
    border-radius: 6px;
    transition: background var(--transition), color var(--transition);
}
.history-dropdown-item:hover { background: var(--surface-hover); color: var(--text-1); }
.history-dropdown-item.delete-item:hover { background: rgba(239,68,68,0.12); color: var(--red); }

.history-rename-input {
    flex: 1;
    background: rgba(255,255,255,0.08);
    border: 1px solid var(--accent);
    border-radius: 4px;
    color: var(--text-1);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    padding: 2px 6px;
    outline: none;
    min-width: 0;
}

.history-empty {
    font-size: 0.78rem;
    color: var(--text-3);
    padding: 8px 10px;
    font-style: italic;
    white-space: nowrap;
}

/* ── Sidebar footer ────────────────────────────── */
.sidebar-footer {
    padding: 8px 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.connection-block {
    padding: 4px 0;
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: color var(--transition);
    text-align: left;
}
.connection-block::before {
    content: '';
    position: absolute;
    inset: 2px 8px;
    background: transparent;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
    pointer-events: none;
}
.connection-block:hover { color: var(--text-1); }
.connection-block:hover::before { background: var(--surface-hover); }
.user-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
    overflow: hidden;
}
.conn-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-3);
}
.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-family: var(--font-sans);
    font-size: 0.72rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
    border: 1px solid rgba(255,255,255,0.12);
}
.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}
.uid-badge {
    font-family: 'Courier New', monospace;
    font-size: 0.7rem;
    color: var(--text-3);
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border);
    padding: 3px 8px;
    border-radius: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: fit-content;
    max-width: 100%;
}

.logout-btn {
    width: 100%;
    position: relative;
    background: none;
    border: none;
    color: var(--text-3);
    height: 44px;
    padding: 0 10px 0 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0;
    transition: color var(--transition);
    white-space: nowrap;
}
.logout-btn::before {
    content: '';
    position: absolute;
    inset: 2px 8px;
    background: transparent;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
    pointer-events: none;
}
.logout-btn:hover { color: #f87171; }
.logout-btn:hover::before { background: rgba(239,68,68,0.14); }

/* ── Quota bar ─────────────────────────────────── */
#quota-block {
    padding: 2px 10px 4px;
}
.quota-bar-track {
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 4px;
}
.quota-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent) 0%, var(--cyan) 100%);
    border-radius: 2px;
    transition: width 0.4s ease;
}
.quota-bar-fill.quota-warning { background: linear-gradient(90deg, #f59e0b 0%, #d97706 100%); }
.quota-bar-fill.quota-full    { background: linear-gradient(90deg, #ef4444 0%, #b91c1c 100%); }
.quota-text {
    font-size: 0.68rem;
    color: var(--text-3);
    white-space: nowrap;
}
#sidebar.collapsed #quota-block { display: none !important; }

/* ── Upgrade button (sidebar) ───────────────────── */
#upgrade-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 2px 10px 4px;
    padding: 6px 10px;
    background: rgba(139,92,246,0.15);
    color: #a78bfa;
    border: 1px solid rgba(139,92,246,0.3);
    border-radius: 7px;
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
    overflow: hidden;
}
#upgrade-btn:hover { background: rgba(139,92,246,0.28); border-color: rgba(139,92,246,0.5); }
#sidebar.collapsed #upgrade-btn { display: none !important; }


/* ── Account button (sidebar) ───────────────────── */
.account-btn {
    width: 100%;
    background: none;
    border: none;
    color: var(--text-3);
    height: 36px;
    padding: 0 10px 0 0;
    display: flex;
    align-items: center;
    gap: 0;
    cursor: pointer;
    font-size: 0.85rem;
    border-radius: 8px;
    transition: background var(--transition), color var(--transition);
    white-space: nowrap;
}
.account-btn:hover { background: var(--surface-hover); color: var(--text-1); }
#sidebar.collapsed .account-btn { justify-content: flex-start; }

/* ── Account modal ──────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(8, 6, 20, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    transition: all 0.3s ease;
}
.modal-card {
    background: #1a1630;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 420px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-shadow: var(--shadow-panel);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-title {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-1);
    margin: 0;
    letter-spacing: -0.02em;
}
.modal-close-btn {
    background: none;
    border: none;
    color: var(--text-3);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition), color var(--transition);
}
.modal-close-btn:hover {
    background: var(--surface-hover);
    color: var(--text-1);
}
.modal-section { display: flex; flex-direction: column; gap: 12px; }
.modal-label { 
    font-size: 0.72rem; 
    font-weight: 700; 
    color: var(--text-3); 
    text-transform: uppercase; 
    letter-spacing: 0.12em; 
    margin: 0; 
}
.modal-plan-card {
    background: rgba(139, 92, 246, 0.04);
    border: 1px solid rgba(139, 92, 246, 0.16);
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}
.modal-plan-row { display: flex; align-items: center; gap: 10px; }
.plan-badge {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 20px;
    background: rgba(139, 92, 246, 0.15);
    color: #a78bfa;
    border: 1px solid rgba(139, 92, 246, 0.3);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.plan-badge.plan-free { 
    background: rgba(100, 116, 139, 0.15); 
    color: var(--text-3); 
    border-color: rgba(100, 116, 139, 0.3); 
}
.modal-quota-text {
    font-family: 'Courier New', monospace;
    font-size: 0.82rem;
    color: var(--text-1);
    font-weight: 700;
}
.infinity-symbol {
    font-family: var(--font-sans);
    font-size: 1.1rem;
    font-weight: 600;
    vertical-align: middle;
    line-height: 1;
}
.modal-quota-bar { 
    margin-top: 6px; 
    height: 10px !important; 
    border-radius: 8px !important; 
    background: rgba(255, 255, 255, 0.06) !important; 
    border: 1px solid rgba(255, 255, 255, 0.02);
    overflow: hidden;
    position: relative;
}
.modal-quota-bar .quota-bar-fill {
    border-radius: 8px !important;
    background: linear-gradient(90deg, var(--accent) 0%, var(--cyan) 100%) !important;
    position: relative;
    height: 100%;
}
.modal-quota-bar .quota-bar-fill::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.15), transparent);
    animation: shine-pulse 2.5s infinite linear;
}
@keyframes shine-pulse {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}
.modal-quota-bar .quota-bar-fill.quota-warning {
    background: linear-gradient(90deg, #f59e0b 0%, #d97706 100%) !important;
}
.modal-quota-bar .quota-bar-fill.quota-full {
    background: linear-gradient(90deg, #ef4444 0%, #b91c1c 100%) !important;
}
.modal-upgrade-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 18px;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: #fff;
    border-radius: 10px;
    font-family: var(--font-display);
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    transition: all var(--transition);
    box-shadow: 0 4px 15px var(--accent-glow);
}
.modal-upgrade-btn:hover { 
    transform: translateY(-1px);
    box-shadow: 0 6px 20px var(--accent-glow);
    filter: brightness(1.1);
}
.modal-upgrade-btn:active {
    transform: translateY(0);
}
.modal-upgrade-desc { font-size: 0.78rem; color: var(--text-3); margin: 8px 0 0; text-align: center; }
.modal-pro-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.88rem;
    color: #a78bfa;
    font-weight: 600;
    margin: 0;
}
.modal-divider { height: 1px; background: var(--border); margin: 0 -4px; }
#modal-admin-section { padding: 0 0 4px; }
.modal-admin-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 18px;
    background: rgba(99, 102, 241, 0.12);
    color: #818cf8;
    border: 1px solid rgba(99, 102, 241, 0.28);
    border-radius: 10px;
    font-family: var(--font-display);
    font-size: 0.88rem;
    font-weight: 600;
    text-decoration: none;
    transition: all var(--transition);
}
.modal-admin-btn:hover { 
    background: rgba(99, 102, 241, 0.22); 
    border-color: rgba(99, 102, 241, 0.5); 
    transform: translateY(-1px);
}
.modal-admin-btn:active {
    transform: translateY(0);
}
.modal-delete-btn {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    padding: 11px 16px;
    border-radius: 10px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: all var(--transition);
}
.modal-delete-btn:hover { 
    background: #ef4444; 
    border-color: #ef4444;
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.25);
}
.modal-delete-desc { font-size: 0.75rem; color: var(--text-3); margin: 0; text-align: center; }
.modal-confirm-box {
    background: rgba(239, 68, 68, 0.05);
    border: 1px solid rgba(239, 68, 68, 0.15);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    animation: alert-slide 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes alert-slide {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.modal-confirm-box p { font-size: 0.85rem; color: var(--text-2); margin: 0; line-height: 1.5; text-align: center; }
.modal-confirm-btns { display: flex; gap: 10px; margin-top: 6px; }
.modal-cancel-delete-btn {
    flex: 1;
    padding: 10px;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    color: var(--text-2);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all var(--transition);
}
.modal-cancel-delete-btn:hover { background: rgba(255, 255, 255, 0.12); color: var(--text-1); }
.modal-confirm-delete-btn {
    flex: 1;
    padding: 10px;
    background: #ef4444;
    border: none;
    color: #fff;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all var(--transition);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.25);
}
.modal-confirm-delete-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.modal-confirm-delete-btn:active { transform: translateY(0); }

/* ── Onboarding modal ──────────────────────────── */
.onboarding-card { max-width: 460px; gap: 18px; }
.onboarding-subtitle { font-size: 0.88rem; color: var(--text-2); margin: 0; line-height: 1.5; }
.onboarding-steps { display: flex; flex-direction: column; gap: 14px; }
.onboarding-step {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 12px;
    background: rgba(139,92,246,0.05);
    border: 1px solid rgba(139,92,246,0.1);
    border-radius: 10px;
}
.onboarding-icon {
    width: 40px;
    height: 40px;
    min-width: 40px;
    background: rgba(139,92,246,0.12);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
}
.onboarding-step-text { display: flex; flex-direction: column; gap: 3px; }
.onboarding-step-text strong { font-size: 0.88rem; color: var(--text-1); font-weight: 600; }
.onboarding-step-text span { font-size: 0.82rem; color: var(--text-2); line-height: 1.45; }
.onboarding-step-text em { color: var(--accent); font-style: normal; font-weight: 500; }
.onboarding-btn {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    border: none;
    border-radius: 9px;
    color: #fff;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}
.onboarding-btn:hover { opacity: 0.88; }

/* ── Chat workspace ────────────────────────────── */
#chat-workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}
#chat-workspace.is-scrolled #messages {
    -webkit-mask-image: linear-gradient(to bottom, transparent 0px, black 56px);
    mask-image: linear-gradient(to bottom, transparent 0px, black 56px);
}

/* ── Empty state: input + welcome centered ─────── */
#chat-workspace:not(.has-messages) {
    justify-content: center;
    align-items: center;
    padding-top: 48px;
    padding-bottom: 12vh;
}
#chat-workspace:not(.has-messages) .chat-topbar {
    position: absolute;
    top: 0; left: 0; right: 0;
    border-bottom: none;
    background: transparent;
}
#chat-workspace:not(.has-messages) #messages {
    flex: 0 0 auto;
    overflow: visible;
    padding: 0;
    mask-image: none;
    -webkit-mask-image: none;
    width: min(680px, calc(100% - 48px));
}
#chat-workspace:not(.has-messages) #empty-state {
    padding: 0 0 24px;
}
#chat-workspace:not(.has-messages) #input-area {
    border-top: none;
    width: min(760px, calc(100% - 48px));
    padding: 0;
}

.chat-topbar {
    position: absolute;
    top: 0; left: 0; right: 0;
    z-index: 10;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.menu-btn {
    display: none;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-2);
    border-radius: var(--radius-sm);
    padding: 7px;
    cursor: pointer;
    line-height: 0;
    transition: color var(--transition), border-color var(--transition);
    flex-shrink: 0;
}
.menu-btn:hover { color: var(--text-1); border-color: var(--accent); }

.chat-title-block { flex: 1; min-width: 0; }
.chat-title-block h2 {
    font-family: var(--font-display);
    font-size: clamp(0.95rem, 2.5vw, 1.1rem);
    font-weight: 600;
    color: var(--text-1);
}

/* ── Messages ──────────────────────────────────── */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 28px max(24px, calc((100% - 760px) / 2));
    padding-top: 72px;
    display: flex;
    flex-direction: column;
    gap: 22px;
    scroll-behavior: smooth;
    min-height: 0;
}
#messages::-webkit-scrollbar { width: 5px; }
#messages::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.07);
    border-radius: 2px;
}

/* Empty state */
#empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    color: var(--text-2);
}
#empty-state h3 {
    font-family: var(--font-display);
    font-size: clamp(1.4rem, 3vw, 2rem);
    font-weight: 600;
    color: var(--text-1);
}

/* Bubbles */
.msg {
    display: flex;
    flex-direction: column;
    gap: 0;
    animation: slide-up 0.3s ease forwards;
}
@keyframes slide-up {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.msg.user  { align-self: flex-end; max-width: min(72%, 560px); }
.msg.ai    { align-self: flex-start; max-width: min(88%, 760px); }

.msg-label { display: none; }

.msg-bubble {
    font-size: 1rem;
    line-height: 1.75;
    word-break: break-word;
}
.msg.user .msg-bubble {
    background: var(--bubble-user);
    border: 1px solid rgba(139,92,246,0.28);
    border-radius: var(--radius-md);
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 12px rgba(139,92,246,0.1);
    padding: 10px 15px;
    white-space: pre-wrap;
}
.msg.ai .msg-bubble {
    background: none;
    border: none;
    border-radius: 0;
    padding: 0;
    white-space: normal;
    color: var(--text-1);
}
.msg-bubble.error {
    background: rgba(239,68,68,0.08);
    border-color: rgba(239,68,68,0.25);
    color: #fca5a5;
    font-size: 0.85rem;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}
.msg-bubble.error svg { flex-shrink: 0; margin-top: 1px; }
.msg-bubble.reauth-bubble { display: flex; flex-direction: column; gap: 12px; }
.msg-bubble.reauth-bubble p { margin: 0; }
.reauth-btn {
    display: inline-block;
    padding: 8px 18px;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    align-self: flex-start;
    transition: opacity 0.15s;
}
.reauth-btn:hover { opacity: 0.85; }

/* Typing indicator */
.typing-bubble {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 18px;
}
.dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--text-3);
    animation: pulse 1.4s infinite ease-in-out;
}
.dot:nth-child(2) { animation-delay: .2s; }
.dot:nth-child(3) { animation-delay: .4s; }
@keyframes pulse {
    0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
    40%           { transform: scale(1);   opacity: 1; }
}
.typing-status {
    font-size: 0.8rem;
    color: var(--text-3);
    margin-left: 6px;
    animation: fade-status 0.4s ease;
}
@keyframes fade-status {
    from { opacity: 0; transform: translateY(3px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Markdown inside AI bubbles ───────────────── */
.msg-bubble p { margin-bottom: 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble strong { color: var(--text-1); font-weight: 600; }
.msg-bubble em { color: var(--text-2); font-style: italic; }
.msg-bubble ul, .msg-bubble ol {
    padding-left: 18px;
    margin: 6px 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.msg-bubble li { line-height: 1.5; }
.msg-bubble code {
    font-family: 'Courier New', monospace;
    font-size: 0.82em;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 4px;
    padding: 1px 6px;
}
.msg-bubble pre {
    background: rgba(0,0,0,0.35);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    overflow-x: auto;
    margin: 8px 0;
}
.msg-bubble pre code {
    background: none; border: none;
    padding: 0; font-size: 0.85em;
}

/* ── KaTeX math rendering ──────────────────────── */
.msg-bubble .katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    margin: 8px 0;
}
.msg-bubble .katex { font-size: 1.05em; }

/* ── Input area ────────────────────────────────── */
#input-area {
    padding: 16px 24px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}
#chat-workspace.has-messages .input-row,
#chat-workspace.has-messages .input-disclaimer {
    width: 100%;
    max-width: 760px;
}
.input-disclaimer {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-3);
    padding-top: 8px;
    display: none;
}
#chat-workspace.has-messages .input-disclaimer { display: block; }

.input-row {
    width: 100%;
    position: relative;
    display: flex;
    align-items: flex-end;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.04);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.input-row:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
#upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    min-width: 36px;
    height: 36px;
    margin: 4px 0 4px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-3);
    transition: color var(--transition), background var(--transition);
}
#upload-btn:hover { color: var(--text-1); background: rgba(255,255,255,0.06); }
#upload-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-glow);
}
#upload-btn.uploading { pointer-events: none; opacity: 0.5; }
#upload-progress-bar {
    width: 100%;
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    margin-bottom: 6px;
    overflow: hidden;
}
#upload-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s ease;
}
#upload-status {
    font-size: 0.78rem;
    color: var(--text-3);
    margin-bottom: 4px;
    text-align: center;
}
#chat-input {
    flex: 1;
    min-height: 44px;
    max-height: 140px;
    padding: 11px 52px 11px 8px;
    border-radius: var(--radius-md);
    border: none;
    background: transparent;
    color: var(--text-1);
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.5;
    resize: none;
    outline: none;
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}
#chat-input::placeholder { color: var(--text-3); }
#chat-input::-webkit-scrollbar { width: 4px; }
#chat-input::-webkit-scrollbar-track { background: transparent; }
#chat-input::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

#send-btn {
    position: absolute;
    right: 8px;
    bottom: 7px;
    transform-origin: right bottom;
    width: 32px; height: 32px;
    border-radius: 8px;
    border: none;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px var(--accent-glow);
    opacity: 0;
    pointer-events: none;
    transform: scale(0.75);
    transition: opacity 0.15s ease, transform 0.15s ease, background var(--transition), box-shadow var(--transition);
}
#send-btn.visible {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
}
#send-btn:hover {
    background: var(--accent-dark);
    box-shadow: 0 6px 20px var(--accent-glow);
    transform: scale(1) translateY(-1px);
}
#send-btn:active { transform: scale(1) translateY(0); }
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: scale(1); }

/* Control stop/send icons */
#send-btn .stop-icon {
    display: none;
}
#send-btn .send-icon {
    display: block;
}

/* Generating / Stop State */
#send-btn.generating {
    background: var(--accent);
    box-shadow: 0 4px 14px var(--accent-glow);
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
    cursor: pointer;
}
#send-btn.generating .send-icon {
    display: none;
}
#send-btn.generating .stop-icon {
    display: block;
}
#send-btn.generating:hover {
    background: var(--accent-dark);
    box-shadow: 0 6px 20px var(--accent-glow);
    transform: scale(1) translateY(-1px);
}
#send-btn.generating:active {
    transform: scale(1) translateY(0);
}


/* ── Profile Popover ───────────────────────────── */
.profile-popover {
    position: fixed;
    z-index: 900;
    width: 236px;
    background: rgba(18, 15, 36, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}
.profile-popover.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}
:root:not(.sidebar-collapsed) .profile-popover {
    left: 12px;
    bottom: 72px;
}
.sidebar-collapsed .profile-popover {
    left: 72px;
    bottom: 12px;
}
.popover-user-info {
    padding: 10px 12px 6px;
    font-size: 0.82rem;
    color: var(--text-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.popover-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 6px;
}
.popover-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 12px;
    background: none;
    border: none;
    border-radius: 8px;
    color: var(--text-2);
    font-family: var(--font-sans);
    font-size: 0.84rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease;
}
.popover-item:hover {
    background: var(--surface-hover);
    color: var(--text-1);
}
.popover-item svg {
    flex-shrink: 0;
    opacity: 0.7;
    transition: opacity 0.15s ease;
}
.popover-item:hover svg {
    opacity: 1;
}
.popover-item.logout {
    color: #f87171;
}
.popover-item.logout:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
}

/* ── Settings Modal Tabs Layout ────────────────── */
.settings-modal {
    max-width: 680px;
    padding: 0 !important;
    gap: 0;
    overflow: hidden;
    height: 520px;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(20, 16, 40, 0.85);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    box-shadow: 0 30px 70px rgba(0, 0, 0, 0.6);
}
.settings-modal .modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.settings-body {
    display: flex;
    flex: 1;
    min-height: 0;
}
.settings-tabs {
    width: 200px;
    border-right: 1px solid var(--border);
    padding: 20px 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.15);
}
.settings-content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    min-height: 0;
}
.tab-btn {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    background: none;
    border: none;
    border-radius: 8px;
    color: var(--text-2);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: background 0.2s, color 0.2s, transform 0.15s, padding-left 0.2s;
}
.tab-btn:hover {
    background: var(--surface-hover);
    color: var(--text-1);
    padding-left: 18px;
}
.tab-btn:active {
    transform: scale(0.98);
}
.tab-btn::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 50%;
    transform: translateY(-50%);
    height: 16px;
    width: 3px;
    background: transparent;
    border-radius: 4px;
    transition: background-color 0.2s, height 0.2s;
}
.tab-btn.active {
    background: rgba(139, 92, 246, 0.08);
    color: #a78bfa;
    font-weight: 600;
    padding-left: 18px;
}
.tab-btn.active::after {
    background: var(--accent);
    height: 20px;
}
.tab-btn.active svg {
    color: #a78bfa;
}
.tab-btn.danger:hover {
    background: rgba(239, 68, 68, 0.08);
    color: #fca5a5;
    padding-left: 18px;
}
.tab-btn.danger.active {
    background: rgba(239, 68, 68, 0.12);
    color: #f87171;
    padding-left: 18px;
}
.tab-btn.danger.active::after {
    background: #ef4444;
    height: 20px;
}
.tab-btn.danger.active svg {
    color: #f87171;
}

.tab-panel {
    display: none;
    flex-direction: column;
    gap: 16px;
    animation: fade-in 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.tab-panel.active {
    display: flex;
}
@keyframes fade-in {
    from { opacity: 0; transform: translateY(6px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── General Panel Settings ────────────────────── */
.user-profile-header {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
}
.user-profile-header::before {
    content: '';
    position: absolute;
    top: -50%; left: -50%;
    width: 200%; height: 200%;
    background: radial-gradient(circle at 10% 10%, rgba(139, 92, 246, 0.08) 0%, transparent 55%);
    pointer-events: none;
}
.user-avatar-large {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    box-shadow: 0 0 0 3px var(--accent-glow);
    overflow: hidden;
    flex-shrink: 0;
    transition: transform var(--transition);
}
.user-avatar-large:hover {
    transform: scale(1.05);
}
.user-avatar-large img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}
.user-profile-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    position: relative;
    z-index: 1;
}
.user-profile-name {
    font-family: var(--font-display);
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-1);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.user-profile-email {
    font-size: 0.82rem;
    color: var(--text-3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Theme Option Cards ────────────────────────── */
.theme-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.theme-option-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    text-align: center;
    transition: border-color 0.25s, background 0.25s, transform 0.25s, box-shadow 0.25s;
}
.theme-option-card:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateY(-3px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.3);
}
.theme-option-card.active {
    border-color: var(--accent);
    background: rgba(139, 92, 246, 0.06);
    box-shadow: 0 0 0 3px var(--accent-glow), 0 12px 24px rgba(139, 92, 246, 0.12);
}
.theme-option-card span {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-2);
}
.theme-option-card.active span {
    color: var(--text-1);
}
.theme-preview {
    width: 100%;
    height: 80px;
    border-radius: 10px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
    overflow: hidden;
    transition: transform var(--transition);
}
.theme-option-card:hover .theme-preview {
    transform: scale(1.02);
}
.theme-preview.dark {
    background: #0c0a1a;
    border: 1px solid rgba(255, 255, 255, 0.08);
}
.theme-preview.light {
    background: #f8fafc;
    border: 1px solid rgba(15, 23, 42, 0.08);
}
.preview-bubble {
    width: 60%;
    height: 14px;
    border-radius: 5px;
}
.theme-preview.dark .preview-bubble.user {
    background: rgba(139, 92, 246, 0.25);
    align-self: flex-end;
}
.theme-preview.dark .preview-bubble.ai {
    background: rgba(255, 255, 255, 0.06);
    align-self: flex-start;
}
.theme-preview.light .preview-bubble.user {
    background: rgba(139, 92, 246, 0.15);
    align-self: flex-end;
}
.theme-preview.light .preview-bubble.ai {
    background: rgba(0, 0, 0, 0.05);
    align-self: flex-start;
}
/* ── Light Theme Styles ────────────────────────── */
.light-theme {
    --bg:                  #f8fafc;
    --surface:             #ffffff;
    --surface-hover:       rgba(99, 102, 241, 0.05); /* Soft indigo/slate */
    --border:              #e2e8f0; /* Fine Slate 200 */
    --text-1:              #0f172a; /* Slate 900 */
    --text-2:              #334155; /* Slate 700 */
    --text-3:              #64748b; /* Slate 500 */
    --bubble-user:         rgba(124, 58, 237, 0.08); /* Brand Purple wash */
    --bubble-ai:           #ffffff; /* AI bubble white for clean cards look */
    --shadow-panel:        0 10px 40px rgba(15, 23, 42, 0.04), 0 1px 2px rgba(15, 23, 42, 0.02);
}
.light-theme body::before {
    opacity: 0.06;
}
.light-theme body::after {
    opacity: 0.05;
}
.light-theme #sidebar {
    background: #ffffff;
    border-right: 1px solid #e2e8f0;
}
.light-theme #sidebar.collapsed .nav-item::before,
.light-theme #sidebar.collapsed .connection-block::before,
.light-theme #sidebar.collapsed .logout-btn::before {
    background: transparent;
}
.light-theme #sidebar.collapsed .nav-item:hover::before,
.light-theme #sidebar.collapsed .connection-block:hover::before {
    background: rgba(15, 23, 42, 0.05);
}
.light-theme .nav-item {
    color: #334155;
    font-weight: 500;
}
.light-theme .nav-item:hover {
    background: rgba(99, 102, 241, 0.05);
    color: #0f172a;
}
.light-theme .history-item {
    color: #334155;
}
.light-theme .history-item:hover {
    background: rgba(99, 102, 241, 0.05);
    color: #0f172a;
}
.light-theme .history-item.active {
    background: rgba(124, 58, 237, 0.06);
    border-color: rgba(124, 58, 237, 0.18);
    color: #7c3aed;
}
.light-theme .history-item.active > svg {
    color: #7c3aed;
}
.light-theme #upgrade-btn {
    background: rgba(124, 58, 237, 0.06);
    border-color: rgba(124, 58, 237, 0.18);
    color: #7c3aed;
}
.light-theme #upgrade-btn:hover {
    background: rgba(124, 58, 237, 0.12);
    border-color: rgba(124, 58, 237, 0.3);
}
.light-theme *::-webkit-scrollbar-thumb {
    background: rgba(15, 23, 42, 0.12) !important;
}
.light-theme .profile-popover {
    background: #ffffff;
    border-color: #cbd5e1;
    box-shadow: 0 15px 40px rgba(15, 23, 42, 0.08);
}
.light-theme .popover-user-info {
    color: #475569;
}
.light-theme .popover-item {
    color: #334155;
}
.light-theme .popover-item:hover {
    background: rgba(99, 102, 241, 0.05);
    color: #0f172a;
}
.light-theme .popover-divider {
    background: #e2e8f0;
}
.light-theme .settings-modal {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 30px 70px rgba(15, 23, 42, 0.1);
}
.light-theme .settings-tabs {
    background: rgba(15, 23, 42, 0.02);
    border-right-color: rgba(15, 23, 42, 0.06);
}
.light-theme .tab-btn {
    color: #475569;
}
.light-theme .tab-btn:hover {
    background: rgba(15, 23, 42, 0.04);
    color: #0f172a;
}
.light-theme .tab-btn.active {
    background: rgba(124, 58, 237, 0.06);
    color: #7c3aed;
}
.light-theme .tab-btn.active::after {
    background: #7c3aed;
}
.light-theme .user-profile-header {
    background: #ffffff;
    border-color: #cbd5e1;
    box-shadow: 0 4px 20px rgba(15, 23, 42, 0.02);
}
.light-theme .user-profile-header::before {
    background: radial-gradient(circle at 10% 10%, rgba(139, 92, 246, 0.04) 0%, transparent 40%);
}
.light-theme .user-avatar-large {
    border-color: #ffffff;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.12), 0 8px 20px rgba(139, 92, 246, 0.15);
}
.light-theme .theme-option-card {
    background: #ffffff;
    border-color: #cbd5e1;
}
.light-theme .theme-option-card span {
    color: #475569;
}
.light-theme .theme-option-card:hover {
    background: #ffffff;
    border-color: #cbd5e1;
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.06);
}
.light-theme .theme-option-card.active {
    background: rgba(124, 58, 237, 0.04);
    border-color: #7c3aed;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.12), 0 12px 24px rgba(124, 58, 237, 0.06);
}
.light-theme .modal-plan-card {
    background: rgba(124, 58, 237, 0.03);
    border-color: rgba(124, 58, 237, 0.14);
    box-shadow: 0 4px 20px rgba(15, 23, 42, 0.02);
}
.light-theme .modal-quota-bar {
    background: rgba(15, 23, 42, 0.06) !important;
    border: 1px solid rgba(15, 23, 42, 0.02);
}
.light-theme .google-login-btn {
    background: #ffffff !important;
    color: #1f2937 !important;
    border: 1px solid #d1d5db !important;
}
.light-theme .msg.user .msg-bubble {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.05) 0%, rgba(139, 92, 246, 0.12) 100%);
    border: 1px solid rgba(139, 92, 246, 0.16);
    box-shadow: 0 2px 12px rgba(139, 92, 246, 0.04);
}
.light-theme .msg-bubble pre {
    background: #0f172a;
    border-color: #1e293b;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
}
.light-theme .msg-bubble code {
    font-family: 'Courier New', monospace;
    font-weight: 600;
    background: rgba(139, 92, 246, 0.08);
    border-color: rgba(139, 92, 246, 0.12);
    color: #7c3aed;
}
.light-theme .msg-bubble pre code {
    font-weight: normal;
    color: #f8fafc;
    background: none;
    border: none;
}
.light-theme #input-area {
    background: linear-gradient(180deg, rgba(248, 250, 252, 0) 0%, #f8fafc 40%);
}
.light-theme .input-row {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-color: #cbd5e1;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.02);
}
.light-theme .input-row:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.14), 0 10px 30px rgba(139, 92, 246, 0.04);
}
.light-theme #chat-input {
    color: #0f172a;
}
.light-theme .tab-panel#panel-danger .modal-delete-btn {
    background: rgba(239, 68, 68, 0.05);
    border-color: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}
.light-theme .tab-panel#panel-danger .modal-delete-btn:hover {
    background: #ef4444;
    color: #ffffff;
    border-color: #ef4444;
}


/* ── Mobile overlay backdrop ───────────────────── */
#sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 50;
}

/* ── Responsive ────────────────────────────────── */
@media (max-width: 640px) {
    /* Remove backdrop-filter so #app doesn't create a stacking context
       that traps the fixed sidebar inside it */
    #app {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: var(--bg);
        isolation: auto;
    }

    #sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        z-index: 60;
        transform: translateX(-100%);
        width: 280px; min-width: 280px;
        border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
        box-shadow: 4px 0 40px rgba(0,0,0,0.5);
        background: rgba(10, 8, 22, 0.97);
        border-right: 1px solid var(--border);
        transition: transform var(--transition);
        contain: none;
    }
    #sidebar.open  { transform: translateX(0); }
    #sidebar.collapsed { width: 280px; min-width: 280px; }

    #sidebar-backdrop {
        z-index: 50;
    }
    #sidebar-backdrop.open { display: block; }

    .sidebar-toggle { display: none; }
    .sidebar-close  { display: flex !important; }
    .menu-btn       { display: flex !important; }

    /* Logo: vuelve al flujo flex en mobile (no es absolute) */
    #sidebar .sidebar-logo { position: static; transform: none; }
    #sidebar .sidebar-head { justify-content: flex-start; padding: 14px; height: auto; }
    #sidebar .sidebar-head-btns { display: none; }

    /* On mobile sidebar is always expanded — undo ALL collapsed overrides */
    #sidebar.collapsed .sidebar-logo { opacity: 1; pointer-events: auto; }
    #sidebar.collapsed .nav-label,
    #sidebar.collapsed .conn-label,
    #sidebar.collapsed .uid-badge,
    #sidebar.collapsed .section-label {
        opacity: 1;
        pointer-events: auto;
        display: revert;
    }
    #sidebar.collapsed .sidebar-body { display: flex; }
    #sidebar .nav-item { justify-content: flex-start; padding: 9px 10px; margin: 0; }
    #sidebar .sidebar-footer { padding: 12px 10px; }
    #sidebar .connection-block { border-bottom: none; padding: 4px 6px; }
    #sidebar .connection-block { justify-content: flex-start; }
    #sidebar .logout-btn { justify-content: flex-start; padding: 9px 10px; border: none; width: 100%; }

    .msg { max-width: 88%; }
    #messages { padding: 16px 14px; }
    .chat-topbar { padding: 12px 14px; }
    #input-area { padding: 12px 14px; }
    .input-hint { display: none; }

    /* Mobile settings modal responsive layout overrides */
    .settings-modal {
        max-width: 100%;
        height: 85vh;
        max-height: 540px;
    }
    .settings-modal .settings-body {
        flex-direction: column;
    }
    .settings-modal .settings-tabs {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        flex-direction: row;
        overflow-x: auto;
        padding: 8px;
        background: rgba(0, 0, 0, 0.05);
        gap: 6px;
    }
    .settings-modal .tab-btn {
        width: auto;
        white-space: nowrap;
        padding: 8px 12px;
    }
    .settings-modal .settings-content {
        padding: 16px;
    }
    .theme-options {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 360px) {
    .auth-logo { font-size: 2.8rem; }
    .auth-card { padding: 20px; }
}
