*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ===== CSS VARS — DARK (default post-login) ===== */
:root {
    --bg:        #0b0710;
    --bg2:       #100c18;
    --panel:     #140e1e;
    --panel2:    #1a1228;
    --border:    #1e1630;
    --border2:   #2a1e42;
    --accent:    #8b5cf6;
    --accent2:   #a78bfa;
    --accent3:   #7c3aed;
    --green:     #10b981;
    --amber:     #f59e0b;
    --red:       #ef4444;
    --text:      #e2e8f0;
    --muted:     #64748b;
    --muted2:    #94a3b8;
    --mono:      'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    --sans:      -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --topbar-h:  56px;
    --sidebar-w: 240px;
}

/* ===== LIGHT MODE (public/home pages) ===== */
[data-theme="light"], .light-theme {
    --bg:        #faf9fb;
    --bg2:       #f3f0f8;
    --panel:     #ffffff;
    --panel2:    #f8f5ff;
    --border:    #e8e0f5;
    --border2:   #d4c8ee;
    --text:      #1a1235;
    --muted:     #7c6fa0;
    --muted2:    #9d8fc0;
}

/* Auto light for public pages */
@media (prefers-color-scheme: light) {
    .public-page {
        --bg:        #faf9fb;
        --bg2:       #f3f0f8;
        --panel:     #ffffff;
        --panel2:    #f8f5ff;
        --border:    #e8e0f5;
        --border2:   #d4c8ee;
        --text:      #1a1235;
        --muted:     #7c6fa0;
        --muted2:    #9d8fc0;
    }
}
/* Force light on public pages when no media query detected (JS sets class) */

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 14px;
    line-height: 1.6;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* ===== TOPBAR ===== */
.topbar {
    position: fixed; top: 0; left: 0; right: 0;
    height: var(--topbar-h);
    background: rgba(11,7,16,.97);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 20px; gap: 12px;
    z-index: 100;
    backdrop-filter: blur(16px);
}
.topbar::after {
    content: '';
    position: absolute; bottom: 0; left: 0; right: 0; height: 1px;
    background: linear-gradient(90deg, transparent 0%, var(--accent) 30%, var(--accent2) 60%, transparent 100%);
    opacity: .5;
}
.light-theme .topbar, .public-page .topbar {
    background: rgba(250,249,251,.97);
}
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.topbar-brand img { height: 32px; }
.topbar-brand .brand-name {
    font-family: var(--mono); font-weight: 700; font-size: 15px; color: var(--accent);
    letter-spacing: -.5px;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.topbar-btn {
    padding: 6px 14px; border-radius: 6px; font-size: 13px; font-weight: 500;
    border: 1px solid var(--border2); background: transparent; color: var(--text);
    cursor: pointer; text-decoration: none; transition: all .15s;
}
.topbar-btn:hover { background: var(--border); }
.topbar-btn.primary {
    background: var(--accent); border-color: var(--accent); color: #fff;
}
.topbar-btn.primary:hover { background: var(--accent3); }

/* ===== LAYOUT ===== */
.app-layout {
    display: flex; height: 100vh; padding-top: var(--topbar-h);
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-w); flex-shrink: 0;
    background: var(--bg2); border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    overflow: hidden;
}
.sidebar-header {
    padding: 14px 16px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 8px;
}
.sidebar-conversations { flex: 1; overflow-y: auto; padding: 8px; }
.conv-item {
    padding: 10px 12px; border-radius: 6px; cursor: pointer;
    font-size: 13px; color: var(--muted2); transition: all .12s;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-bottom: 2px;
}
.conv-item:hover { background: var(--panel); color: var(--text); }
.conv-item.active { background: var(--panel2); color: var(--text); border-left: 2px solid var(--accent); }

/* ===== MAIN CHAT ===== */
.chat-main {
    flex: 1; display: flex; flex-direction: column; overflow: hidden;
    background: var(--bg);
}
.messages-area {
    flex: 1; overflow-y: auto; padding: 24px 20px;
    display: flex; flex-direction: column; gap: 16px;
}
.msg-wrap { display: flex; gap: 10px; max-width: 860px; margin: 0 auto; width: 100%; }
.msg-wrap.user { flex-direction: row-reverse; }
.msg-avatar {
    width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700;
}
.msg-wrap.user .msg-avatar { background: var(--accent); color: #fff; }
.msg-wrap.assistant .msg-avatar { background: var(--panel2); color: var(--accent); font-size: 11px; }
.msg-body { max-width: 720px; }
.msg-bubble {
    padding: 12px 16px; border-radius: 10px;
    font-size: 14px; line-height: 1.65;
}
.msg-wrap.user .msg-bubble {
    background: var(--accent3); color: #fff; border-radius: 10px 2px 10px 10px;
}
.msg-wrap.assistant .msg-bubble {
    background: var(--panel); border: 1px solid var(--border); border-radius: 2px 10px 10px 10px;
}
.msg-actions { display: flex; gap: 6px; margin-top: 6px; justify-content: flex-end; }
.msg-wrap.user .msg-actions { justify-content: flex-start; }
.msg-action-btn {
    padding: 3px 8px; border-radius: 4px; font-size: 11px; background: transparent;
    border: 1px solid var(--border); color: var(--muted); cursor: pointer; transition: all .12s;
}
.msg-action-btn:hover { background: var(--panel2); color: var(--text); }
.msg-action-btn.active-up { border-color: var(--green); color: var(--green); }
.msg-action-btn.active-down { border-color: var(--red); color: var(--red); }

/* ===== STREAMING CURSOR ===== */
.streaming-cursor::after { content: '▋'; animation: blink .7s infinite; color: var(--accent); }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

/* ===== INPUT BAR ===== */
.input-bar {
    border-top: 1px solid var(--border);
    padding: 16px 20px; background: var(--bg2);
}
.input-wrap { max-width: 860px; margin: 0 auto; position: relative; }
.chat-input {
    width: 100%; padding: 12px 52px 12px 16px;
    background: var(--panel); border: 1px solid var(--border2); border-radius: 10px;
    color: var(--text); font-family: var(--sans); font-size: 14px; resize: none;
    outline: none; line-height: 1.5; max-height: 180px; min-height: 48px;
    transition: border-color .15s;
}
.chat-input:focus { border-color: var(--accent); }
.chat-input::placeholder { color: var(--muted); }
.send-btn {
    position: absolute; right: 10px; bottom: 10px;
    width: 32px; height: 32px; border-radius: 6px;
    background: var(--accent); border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center; transition: all .15s;
}
.send-btn:hover { background: var(--accent3); }
.send-btn:disabled { background: var(--border2); cursor: not-allowed; }
.send-btn svg { width: 16px; height: 16px; fill: white; }
.input-footer {
    max-width: 860px; margin: 6px auto 0;
    display: flex; align-items: center; gap: 12px; font-size: 11px; color: var(--muted);
}
.disclaimer-text { flex: 1; }
.powered-by { color: var(--muted); white-space: nowrap; }
.powered-by a { color: var(--accent2); text-decoration: none; }

/* ===== MARKDOWN STYLES ===== */
.msg-bubble h1,.msg-bubble h2,.msg-bubble h3 {
    font-weight: 700; margin: 14px 0 6px; color: var(--text);
}
.msg-bubble h1 { font-size: 18px; } .msg-bubble h2 { font-size: 16px; } .msg-bubble h3 { font-size: 14px; }
.msg-bubble p { margin: 6px 0; }
.msg-bubble ul,.msg-bubble ol { margin: 6px 0 6px 20px; }
.msg-bubble li { margin: 3px 0; }
.msg-bubble strong { font-weight: 700; }
.msg-bubble em { font-style: italic; }
.msg-bubble code {
    font-family: var(--mono); font-size: 12px;
    background: var(--panel2); border: 1px solid var(--border);
    padding: 1px 5px; border-radius: 3px;
}
.msg-wrap.user .msg-bubble code { background: rgba(0,0,0,.2); border-color: rgba(255,255,255,.15); }
.code-block { position: relative; margin: 10px 0; border-radius: 8px; overflow: hidden; }
.code-header {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--panel2); border: 1px solid var(--border);
    border-bottom: none; padding: 5px 12px; border-radius: 8px 8px 0 0;
}
.code-lang { font-family: var(--mono); font-size: 11px; color: var(--muted2); }
.copy-btn {
    font-size: 11px; padding: 2px 8px; border-radius: 4px;
    background: transparent; border: 1px solid var(--border2); color: var(--muted);
    cursor: pointer; transition: all .12s;
}
.copy-btn:hover { background: var(--border); color: var(--text); }
.code-block pre {
    background: var(--panel2); border: 1px solid var(--border);
    border-radius: 0 0 8px 8px; padding: 14px; overflow-x: auto;
    font-family: var(--mono); font-size: 12px; line-height: 1.5; color: var(--text);
    margin: 0;
}
/* NOC-CMD block — locked for anon */
.noc-cmd-locked {
    background: var(--panel2); border: 1px solid var(--border2);
    border-left: 3px solid var(--accent); border-radius: 6px;
    padding: 10px 14px; margin: 10px 0;
    font-size: 12px; color: var(--accent2); font-family: var(--mono);
    display: flex; align-items: center; gap: 8px;
}
/* NOC-CMD block — unlocked */
.noc-cmd-block {
    background: #0f0b1a; border: 1px solid var(--accent3);
    border-left: 3px solid var(--accent); border-radius: 6px;
    padding: 10px 14px; margin: 10px 0;
}
.noc-cmd-block pre { background: none; border: none; padding: 0; font-size: 12px; color: #c4b5fd; margin: 0; }

/* ===== EMPTY STATE ===== */
.empty-state {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 12px;
    color: var(--muted); text-align: center; padding: 40px;
}
.empty-state .logo-big { width: 56px; opacity: .4; margin-bottom: 8px; }
.empty-state h2 { font-size: 18px; color: var(--muted2); font-weight: 600; }
.empty-state p { font-size: 13px; }

/* ===== ANON GATE BANNER ===== */
.anon-gate {
    background: linear-gradient(135deg, var(--panel2) 0%, rgba(139,92,246,.1) 100%);
    border: 1px solid var(--accent3); border-radius: 10px;
    padding: 20px 24px; margin: 16px 20px;
    max-width: 860px; margin-left: auto; margin-right: auto;
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.anon-gate h3 { font-size: 15px; color: var(--text); margin-bottom: 4px; }
.anon-gate p { font-size: 13px; color: var(--muted2); }
.anon-gate .cta-btn {
    background: var(--accent); color: #fff; padding: 10px 20px;
    border-radius: 8px; font-weight: 600; text-decoration: none; white-space: nowrap;
    font-size: 13px; transition: background .15s;
}
.anon-gate .cta-btn:hover { background: var(--accent3); }

/* ===== AUTH PAGES ===== */
.auth-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: 80px 20px 40px; background: var(--bg);
}
.auth-box {
    width: 100%; max-width: 440px;
    background: var(--panel); border: 1px solid var(--border2);
    border-radius: 14px; padding: 36px 32px; box-shadow: 0 8px 40px rgba(0,0,0,.3);
}
.auth-logo { display: flex; justify-content: center; margin-bottom: 28px; }
.auth-logo img { height: 36px; }
.auth-title { font-size: 22px; font-weight: 700; text-align: center; margin-bottom: 6px; }
.auth-subtitle { font-size: 13px; color: var(--muted2); text-align: center; margin-bottom: 24px; }
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted2); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px; }
.form-input {
    width: 100%; padding: 10px 14px; background: var(--bg2);
    border: 1px solid var(--border2); border-radius: 8px;
    color: var(--text); font-size: 14px; outline: none; transition: border-color .15s;
}
.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--muted); }
.form-select { width: 100%; padding: 10px 14px; background: var(--bg2); border: 1px solid var(--border2); border-radius: 8px; color: var(--text); font-size: 14px; outline: none; }
.btn-primary {
    width: 100%; padding: 12px; background: var(--accent); border: none;
    border-radius: 8px; color: #fff; font-size: 14px; font-weight: 600;
    cursor: pointer; transition: background .15s; margin-top: 4px;
}
.btn-primary:hover { background: var(--accent3); }
.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.alert-error { background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; }
.alert-success { background: rgba(16,185,129,.1); border: 1px solid rgba(16,185,129,.3); color: #6ee7b7; }
.auth-footer { text-align: center; font-size: 12px; color: var(--muted); margin-top: 20px; }
.auth-footer a { color: var(--accent2); text-decoration: none; }
.form-check { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 12px; }
.form-check input { margin-top: 2px; accent-color: var(--accent); }
.form-check label { font-size: 12px; color: var(--muted2); line-height: 1.4; }
.form-check a { color: var(--accent2); }
.password-field { position: relative; }
.password-suggest {
    font-size: 11px; color: var(--accent2); margin-top: 4px; cursor: pointer;
    font-family: var(--mono);
}
.password-suggest:hover { text-decoration: underline; }

/* ===== HOME / LANDING PAGE ===== */
.home-hero {
    min-height: 100vh; display: flex; flex-direction: column;
    align-items: center; justify-content: center; padding: 100px 20px 60px;
    text-align: center; position: relative; overflow: hidden;
}
.home-hero::before {
    content: '';
    position: absolute; top: -30%; left: 50%; transform: translateX(-50%);
    width: 600px; height: 600px;
    background: radial-gradient(circle, rgba(139,92,246,.12) 0%, transparent 70%);
    pointer-events: none;
}
.hero-logo { width: 180px; margin-bottom: 24px; }
.hero-slogan {
    font-size: 14px; font-family: var(--mono); color: var(--accent2);
    letter-spacing: 1px; text-transform: uppercase; margin-bottom: 16px;
}
.hero-title {
    font-size: clamp(32px, 5vw, 52px); font-weight: 800; line-height: 1.15;
    color: var(--text); margin-bottom: 16px; max-width: 700px;
}
.hero-sub {
    font-size: 16px; color: var(--muted2); max-width: 520px; margin-bottom: 40px;
}
.hero-cta { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.btn-hero {
    padding: 13px 28px; border-radius: 10px; font-weight: 600; font-size: 15px;
    cursor: pointer; text-decoration: none; transition: all .15s;
}
.btn-hero.primary { background: var(--accent); color: #fff; border: none; }
.btn-hero.primary:hover { background: var(--accent3); }
.btn-hero.secondary { background: transparent; color: var(--text); border: 1px solid var(--border2); }
.btn-hero.secondary:hover { background: var(--panel); }

/* Anon question box on landing */
.anon-box {
    background: var(--panel); border: 1px solid var(--border2);
    border-radius: 14px; padding: 28px; max-width: 640px; width: 100%;
    margin: 40px auto 0; text-align: left;
}
.anon-box h3 { font-size: 15px; margin-bottom: 14px; color: var(--text); }
.anon-input-wrap { position: relative; }
.anon-textarea {
    width: 100%; padding: 12px 14px; background: var(--bg2);
    border: 1px solid var(--border2); border-radius: 8px;
    color: var(--text); font-size: 14px; resize: none; min-height: 80px;
    outline: none; font-family: var(--sans); transition: border-color .15s;
}
.anon-textarea:focus { border-color: var(--accent); }
.anon-submit {
    margin-top: 12px; padding: 10px 24px; background: var(--accent);
    border: none; border-radius: 8px; color: #fff; font-weight: 600;
    font-size: 14px; cursor: pointer; transition: background .15s;
}
.anon-submit:hover { background: var(--accent3); }
.anon-submit:disabled { background: var(--border2); cursor: not-allowed; }
.cf-turnstile { margin: 10px 0; }

/* ===== TIER BADGE ===== */
.tier-badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600;
    font-family: var(--mono); text-transform: uppercase;
}
.tier-badge.anon   { background: rgba(100,116,139,.15); color: var(--muted2); }
.tier-badge.free   { background: rgba(139,92,246,.1); color: var(--accent2); border: 1px solid rgba(139,92,246,.2); }
.tier-badge.pro    { background: rgba(16,185,129,.1); color: var(--green); border: 1px solid rgba(16,185,129,.2); }
.tier-badge.teams  { background: rgba(245,158,11,.1); color: var(--amber); border: 1px solid rgba(245,158,11,.2); }

/* ===== ADMIN ===== */
.admin-layout { display: flex; min-height: 100vh; padding-top: var(--topbar-h); }
.admin-sidebar { width: 200px; background: var(--bg2); border-right: 1px solid var(--border); padding: 20px 0; }
.admin-nav a { display: block; padding: 9px 20px; color: var(--muted2); text-decoration: none; font-size: 13px; transition: all .12s; }
.admin-nav a:hover, .admin-nav a.active { background: var(--panel); color: var(--text); border-left: 2px solid var(--accent); }
.admin-content { flex: 1; padding: 28px; overflow-y: auto; }
.admin-title { font-size: 20px; font-weight: 700; margin-bottom: 24px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 28px; }
.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 18px 16px; }
.stat-val { font-size: 28px; font-weight: 800; color: var(--accent2); font-family: var(--mono); }
.stat-label { font-size: 11px; color: var(--muted); margin-top: 2px; text-transform: uppercase; letter-spacing: .5px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { padding: 8px 12px; text-align: left; font-size: 11px; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--border); }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.data-table tr:hover td { background: var(--panel); }

/* ===== UTILS ===== */
.btn { padding: 7px 16px; border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer; border: 1px solid var(--border2); background: transparent; color: var(--text); transition: all .12s; text-decoration: none; display: inline-block; }
.btn:hover { background: var(--panel2); }
.btn.sm { padding: 4px 10px; font-size: 11px; }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn.danger:hover { background: rgba(239,68,68,.1); }
.btn.success { border-color: var(--green); color: var(--green); }
.text-muted { color: var(--muted); }
.text-accent { color: var(--accent); }
.monospace { font-family: var(--mono); }
.badge { padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge-violet { background: rgba(139,92,246,.15); color: var(--accent2); }
.badge-green  { background: rgba(16,185,129,.15); color: var(--green); }
.badge-red    { background: rgba(239,68,68,.15); color: var(--red); }
.badge-amber  { background: rgba(245,158,11,.15); color: var(--amber); }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 16px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 16px; }
.d-flex { display: flex; } .align-center { align-items: center; } .gap-2 { gap: 8px; }
.pagination { display: flex; gap: 6px; align-items: center; margin-top: 16px; }
.page-btn { padding: 5px 10px; border-radius: 5px; font-size: 12px; }
.page-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ===== COOKIES BANNER ===== */
.cookie-banner {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
    background: var(--panel); border-top: 1px solid var(--border2);
    padding: 14px 24px; display: flex; align-items: center;
    justify-content: space-between; gap: 20px; font-size: 12px; color: var(--muted2);
}
.cookie-banner a { color: var(--accent2); }
.cookie-accept {
    padding: 7px 18px; background: var(--accent); border: none;
    border-radius: 6px; color: #fff; font-size: 12px; cursor: pointer;
    white-space: nowrap; transition: background .15s;
}
.cookie-accept:hover { background: var(--accent3); }

/* ===== ANIMATIONS ===== */
@keyframes fadeIn  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pulse   { 0%,100% { opacity: 1; } 50% { opacity: .4; } }
@keyframes spin    { to { transform: rotate(360deg); } }
.fade-in { animation: fadeIn .2s ease forwards; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border2); border-top-color: var(--accent); border-radius: 50%; animation: spin .6s linear infinite; }

/* ===== TYPING INDICATOR ===== */
.typing-dots { display: flex; gap: 4px; align-items: center; padding: 4px 2px; }
.typing-dot  { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s infinite; }
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }

/* ===== MOBILE ===== */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .admin-sidebar { display: none; }
    .msg-body { max-width: 100%; }
    .hero-title { font-size: 28px; }
    .auth-box { padding: 24px 20px; }
}
