/* ==========================================================================
   AiExpress — console for a self-hosted OmniRoute gateway
   Design concept: an airport/rail departure board reimagined as an AI
   control tower. Ink-dark panels, hairline dividers, one amber signal
   colour, monospace readouts for anything that is data (ids, timestamps,
   status). See README for the rest of the brief.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; }

/* ---------- Theme tokens ---------- */
:root, [data-theme="express"] {
    --ink-0: #080b10;
    --ink-1: #0d131a;
    --ink-2: #131b24;
    --ink-3: #1a2530;
    --line: #212c38;
    --line-soft: #182028;
    --paper: #eaedf1;
    --ash: #93a0af;
    --dim: #576270;
    --amber: #ffb020;
    --amber-ink: #1a1200;
    --green: #2fd8a6;
    --blue: #4fa3ff;
    --red: #ff5d5d;
    --violet: #9b8cff;
    --shadow: 0 20px 50px rgba(0,0,0,0.45);
    --board-stripe: rgba(255,255,255,0.015);
}

[data-theme="slate"] {
    --ink-0: #0a0c10;
    --ink-1: #101318;
    --ink-2: #171b22;
    --ink-3: #1f2530;
    --line: #262c36;
    --line-soft: #1a1f27;
    --paper: #e8eaef;
    --ash: #8f97a5;
    --dim: #565d69;
    --amber: #8fb8ff;
    --amber-ink: #071022;
    --green: #35d0a0;
    --blue: #8fb8ff;
    --red: #ff6b6b;
    --violet: #b79bff;
    --shadow: 0 20px 50px rgba(0,0,0,0.45);
    --board-stripe: rgba(255,255,255,0.015);
}

[data-theme="daylight"] {
    --ink-0: #f4f2ec;
    --ink-1: #ffffff;
    --ink-2: #fbf9f4;
    --ink-3: #f0ede4;
    --line: #ddd7c8;
    --line-soft: #e8e3d6;
    --paper: #1c1a15;
    --ash: #63594a;
    --dim: #948a76;
    --amber: #b5790a;
    --amber-ink: #fff8ea;
    --green: #158a63;
    --blue: #1d5fbf;
    --red: #c23f3f;
    --violet: #6b52c8;
    --shadow: 0 16px 40px rgba(60,50,20,0.12);
    --board-stripe: rgba(0,0,0,0.015);
}

body {
    background: var(--ink-0);
    color: var(--paper);
    font-family: var(--font-ui);
    -webkit-font-smoothing: antialiased;
    font-size: 14.5px;
    line-height: 1.5;
}

:root {
    --font-ui: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
    --r-xs: 5px;
    --r-sm: 7px;
    --r-md: 10px;
    --r-lg: 14px;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }
input, textarea, select { font-family: inherit; color: inherit; }
::selection { background: var(--amber); color: var(--amber-ink); }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--dim); background-clip: padding-box; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* Focus visibility */
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible,
select:focus-visible, [tabindex]:focus-visible {
    outline: 2px solid var(--amber);
    outline-offset: 2px;
}

/* Constrain every icon glyph to a square em-box and clip overflow, so a
   slow/blocked icon-font load renders an empty slot instead of fallback
   text that could spill into and cover neighbouring controls. */
.material-symbols-outlined {
    display: inline-flex; width: 1em; height: 1em; flex: none;
    align-items: center; justify-content: center;
    overflow: hidden; white-space: nowrap; vertical-align: middle;
}

.mono { font-family: var(--font-mono); }
.hidden { display: none !important; }
.text-ash { color: var(--ash); }
.text-dim { color: var(--dim); }

/* Faint grid backdrop behind everything, like a runway/board grid */
.grid-overlay {
    position: fixed; inset: 0; z-index: 0; pointer-events: none;
    background-image:
        linear-gradient(var(--board-stripe) 1px, transparent 1px),
        linear-gradient(90deg, var(--board-stripe) 1px, transparent 1px);
    background-size: 34px 34px;
    mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 30%, transparent 75%);
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    height: 38px; padding: 0 16px; border-radius: var(--r-sm);
    border: 1px solid var(--line); background: var(--ink-2); color: var(--paper);
    font-size: 13.5px; font-weight: 500; cursor: pointer;
    transition: border-color .15s ease, background .15s ease, transform .08s ease;
    white-space: nowrap;
}
.btn:hover { border-color: var(--dim); background: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn .material-symbols-outlined { font-size: 18px; }

.btn-primary { background: var(--amber); border-color: var(--amber); color: var(--amber-ink); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); background: var(--amber); border-color: var(--amber); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ash); }
.btn-ghost:hover { background: var(--ink-2); color: var(--paper); }
.btn-outline { background: transparent; }
.btn-danger { background: transparent; border-color: var(--line); color: var(--red); }
.btn-danger:hover { background: rgba(255,93,93,0.10); border-color: var(--red); }
.btn-sm { height: 31px; padding: 0 12px; font-size: 12.5px; border-radius: var(--r-xs); }
.btn-block { width: 100%; }
.btn-icon { width: 38px; height: 38px; padding: 0; flex: none; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: var(--r-sm);
    border: 1px solid transparent; background: transparent; color: var(--ash);
    cursor: pointer; transition: background .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--ink-2); color: var(--paper); }
.icon-btn .material-symbols-outlined { font-size: 21px; }

/* ==========================================================================
   FORM FIELDS
   ========================================================================== */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field-row { display: flex; gap: 12px; }
.field-row > .field { flex: 1; min-width: 0; }
.field label {
    font-size: 12px; font-weight: 600; color: var(--ash);
    letter-spacing: 0.02em;
}
.field .hint { font-size: 11.5px; color: var(--dim); line-height: 1.4; }

input[type="text"], input[type="password"], input[type="number"],
input[type="search"], input[type="url"], textarea, select {
    width: 100%; background: var(--ink-2); border: 1px solid var(--line);
    color: var(--paper); border-radius: var(--r-sm); padding: 10px 12px;
    font-size: 13.5px; transition: border-color .15s ease, background .15s ease;
    resize: none;
}
input::placeholder, textarea::placeholder { color: var(--dim); }
input:focus, textarea:focus, select:focus {
    border-color: var(--amber); background: var(--ink-1); outline: none;
}
textarea { line-height: 1.5; min-height: 46px; }
select {
    appearance: none; -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2393a0af' stroke-width='2.4'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center;
    padding-right: 32px; cursor: pointer;
}

.reveal-wrap { position: relative; }
.reveal-wrap input { padding-right: 42px; }
.reveal-wrap .reveal-btn {
    position: absolute; right: 4px; top: 4px; bottom: 4px; width: 34px;
    display: flex; align-items: center; justify-content: center;
    background: transparent; border: none; color: var(--dim); cursor: pointer; border-radius: var(--r-xs);
}
.reveal-wrap .reveal-btn:hover { color: var(--ash); background: var(--ink-3); }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; }
.switch-row + .switch-row { border-top: 1px solid var(--line-soft); }
.switch-row .lbl { font-size: 13.5px; font-weight: 500; }
.switch-row .desc { font-size: 12px; color: var(--dim); margin-top: 2px; }
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
    position: absolute; inset: 0; background: var(--ink-3); border: 1px solid var(--line);
    border-radius: 22px; cursor: pointer; transition: background .15s ease;
}
.switch .track::before {
    content: ''; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px;
    background: var(--ash); border-radius: 50%; transition: transform .18s ease, background .15s ease;
}
.switch input:checked + .track { background: rgba(255,176,32,0.25); border-color: var(--amber); }
.switch input:checked + .track::before { transform: translateX(16px); background: var(--amber); }

.range-row { display: flex; align-items: center; gap: 12px; }
input[type="range"] {
    flex: 1; -webkit-appearance: none; appearance: none; height: 4px;
    background: var(--line); border-radius: 4px; outline: none;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%;
    background: var(--amber); cursor: pointer; border: 2px solid var(--ink-0);
}
input[type="range"]::-moz-range-thumb {
    width: 15px; height: 15px; border-radius: 50%; background: var(--amber); cursor: pointer; border: 2px solid var(--ink-0);
}
.range-val { font-family: var(--font-mono); font-size: 12.5px; color: var(--ash); width: 40px; text-align: right; flex: none; }

.file-drop {
    border: 1.5px dashed var(--line); border-radius: var(--r-md); padding: 22px 16px;
    text-align: center; cursor: pointer; transition: border-color .15s ease, background .15s ease;
    color: var(--ash); font-size: 12.5px;
}
.file-drop:hover, .file-drop.drag { border-color: var(--amber); background: rgba(255,176,32,0.05); }
.file-drop .material-symbols-outlined { font-size: 26px; color: var(--dim); display: block; margin: 0 auto 6px; }
.file-preview { position: relative; display: inline-block; margin-top: 10px; }
.file-preview img, .file-preview audio { max-width: 100%; max-height: 180px; border-radius: var(--r-sm); border: 1px solid var(--line); }
.file-preview .clear-file {
    position: absolute; top: -8px; right: -8px; width: 24px; height: 24px; border-radius: 50%;
    background: var(--red); color: #fff; border: 2px solid var(--ink-1); display: flex; align-items: center;
    justify-content: center; cursor: pointer;
}
.file-preview .clear-file .material-symbols-outlined { font-size: 15px; }

/* ==========================================================================
   CARDS / PANELS
   ========================================================================== */
.card {
    background: var(--ink-1); border: 1px solid var(--line); border-radius: var(--r-md);
    padding: 18px;
}
.card + .card { margin-top: 14px; }
.card-title { font-size: 13px; font-weight: 600; margin-bottom: 3px; }
.card-desc { font-size: 12px; color: var(--dim); margin-bottom: 14px; }
.panel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }

/* ==========================================================================
   BRAND MARK
   ========================================================================== */
.brand-mark {
    width: 34px; height: 34px; border-radius: 9px; flex: none;
    background: var(--amber); display: flex; align-items: center; justify-content: center;
}
.brand-mark svg { width: 18px; height: 18px; }
.brand-row { display: flex; align-items: center; gap: 10px; }
.brand-name { font-family: var(--font-ui); font-weight: 700; font-size: 16.5px; letter-spacing: -0.01em; }
.brand-tag { font-size: 10.5px; color: var(--dim); font-family: var(--font-mono); letter-spacing: 0.04em; text-transform: uppercase; }

/* ==========================================================================
   ONBOARDING OVERLAY
   ========================================================================== */
.onboard {
    position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
    background: var(--ink-0); padding: 24px;
}
.onboard::before {
    content: ''; position: absolute; inset: 0;
    background-image: linear-gradient(var(--board-stripe) 1px, transparent 1px), linear-gradient(90deg, var(--board-stripe) 1px, transparent 1px);
    background-size: 34px 34px;
    mask-image: radial-gradient(ellipse 70% 50% at 50% 20%, #000 30%, transparent 75%);
}
.onboard-card {
    position: relative; width: 100%; max-width: 420px; background: var(--ink-1);
    border: 1px solid var(--line); border-radius: var(--r-lg); padding: 30px 28px;
    box-shadow: var(--shadow);
}
.onboard-card h1 { font-size: 19px; margin: 18px 0 6px; }
.onboard-card .sub { font-size: 13px; color: var(--ash); line-height: 1.55; margin-bottom: 22px; }
.onboard-err {
    display: none; font-size: 12.5px; color: var(--red); background: rgba(255,93,93,0.08);
    border: 1px solid rgba(255,93,93,0.3); border-radius: var(--r-sm); padding: 9px 11px; margin-bottom: 14px;
}
.onboard-err.show { display: block; }
.onboard-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
.onboard-skip { text-align: center; font-size: 12.5px; color: var(--dim); cursor: pointer; margin-top: 4px; }
.onboard-skip:hover { color: var(--ash); }
.onboard-foot {
    display: flex; gap: 16px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line-soft);
    font-size: 11px; color: var(--dim);
}
.onboard-foot span { display: flex; align-items: center; gap: 5px; }
.onboard-foot .material-symbols-outlined { font-size: 14px; }

/* ==========================================================================
   APP SHELL
   ========================================================================== */
.shell { position: relative; z-index: 1; display: flex; height: 100vh; }

.sidebar {
    width: 230px; flex: none; background: var(--ink-1); border-right: 1px solid var(--line);
    display: flex; flex-direction: column; z-index: 40;
}
.sb-brand { padding: 18px 18px 16px; border-bottom: 1px solid var(--line-soft); }
.sb-nav { flex: 1; overflow-y: auto; padding: 10px 10px; }
.sb-section-label {
    font-size: 10.5px; font-weight: 600; color: var(--dim); text-transform: uppercase;
    letter-spacing: 0.07em; padding: 14px 10px 6px;
}
.sb-item {
    display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: var(--r-sm);
    color: var(--ash); font-size: 13.5px; font-weight: 500; cursor: pointer; margin-bottom: 1px;
    transition: background .12s ease, color .12s ease; position: relative;
}
.sb-item .material-symbols-outlined { font-size: 19px; }
.sb-item:hover { background: var(--ink-2); color: var(--paper); }
.sb-item.active { background: var(--ink-2); color: var(--paper); }
.sb-item.active::before {
    content: ''; position: absolute; left: -10px; top: 50%; transform: translateY(-50%);
    width: 3px; height: 16px; background: var(--amber); border-radius: 0 3px 3px 0;
}
.sb-item .gate-no { font-family: var(--font-mono); font-size: 10.5px; color: var(--dim); margin-left: auto; }
.sb-item.active .gate-no { color: var(--amber); }

.sb-status {
    margin: 10px; padding: 11px 12px; border-radius: var(--r-sm); background: var(--ink-2);
    border: 1px solid var(--line); display: flex; align-items: center; gap: 9px; cursor: pointer;
}
.sb-status:hover { border-color: var(--dim); }
.sb-footer {
    padding: 4px 20px 16px; font-size: 10.5px; color: var(--dim); text-align: center; line-height: 1.5;
}
.sb-footer span { color: var(--ash); font-weight: 600; }
.sb-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); flex: none; }
.sb-status .dot.on { background: var(--green); box-shadow: 0 0 8px var(--green); }
.sb-status .dot.off { background: var(--red); }
.sb-status .meta { min-width: 0; flex: 1; }
.sb-status .meta .l1 { font-size: 12px; font-weight: 600; }
.sb-status .meta .l2 { font-size: 11px; color: var(--dim); font-family: var(--font-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-scrim { display: none; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    height: 56px; flex: none; display: flex; align-items: center; gap: 12px; padding: 0 20px;
    border-bottom: 1px solid var(--line); background: var(--ink-0);
}
.topbar-title { font-size: 15px; font-weight: 600; }
.topbar .menu-btn { display: none; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.status-pill {
    display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 20px;
    font-size: 11.5px; font-weight: 600; font-family: var(--font-mono); border: 1px solid var(--line);
    color: var(--dim);
}
.status-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-pill.ready { color: var(--green); border-color: rgba(47,216,166,0.35); background: rgba(47,216,166,0.08); }
.status-pill.warn { color: var(--amber); border-color: rgba(255,176,32,0.35); background: rgba(255,176,32,0.08); }
.status-pill.err { color: var(--red); border-color: rgba(255,93,93,0.35); background: rgba(255,93,93,0.08); }
.status-pill.live { color: var(--blue); border-color: rgba(79,163,255,0.35); background: rgba(79,163,255,0.08); }

.views { flex: 1; overflow: hidden; position: relative; }
.view { display: none; height: 100%; overflow-y: auto; }
.view.active { display: block; }
.view-inner { max-width: 900px; margin: 0 auto; padding: 26px 24px 60px; }
.view-inner.wide { max-width: 1120px; }

/* ==========================================================================
   SECTION HEADERS / EMPTY STATES
   ========================================================================== */
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-head h2 { font-size: 16px; }
.section-head .sub { font-size: 12.5px; color: var(--dim); margin-top: 3px; }
.view-lede { font-size: 13px; color: var(--ash); max-width: 560px; margin-bottom: 22px; line-height: 1.6; }

.empty-state {
    text-align: center; padding: 50px 20px; color: var(--dim);
}
.empty-state .material-symbols-outlined { font-size: 34px; margin-bottom: 10px; display: block; opacity: .6; }
.empty-state .t1 { font-size: 13.5px; color: var(--ash); font-weight: 500; margin-bottom: 4px; }
.empty-state .t2 { font-size: 12px; max-width: 320px; margin: 0 auto; line-height: 1.5; }

/* ==========================================================================
   HOME — DEPARTURE BOARD
   ========================================================================== */
.hero {
    display: flex; align-items: flex-end; justify-content: space-between; gap: 20px;
    margin-bottom: 22px; flex-wrap: wrap;
}
.hero h1 { font-size: 23px; margin-bottom: 6px; }
.hero .sub { font-size: 13.5px; color: var(--ash); max-width: 480px; line-height: 1.55; }
.hero-time { font-family: var(--font-mono); font-size: 12px; color: var(--dim); text-align: right; }
.hero-time .clock { font-size: 20px; color: var(--paper); letter-spacing: 0.03em; }

.board {
    border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; background: var(--ink-1);
    margin-bottom: 22px;
}
.board-head {
    display: grid; grid-template-columns: 52px 1fr 140px 100px; gap: 10px; padding: 10px 16px;
    font-family: var(--font-mono); font-size: 10.5px; color: var(--dim); text-transform: uppercase;
    letter-spacing: 0.08em; border-bottom: 1px solid var(--line);
}
.board-row {
    display: grid; grid-template-columns: 52px 1fr 140px 100px; gap: 10px; padding: 13px 16px;
    align-items: center; border-bottom: 1px solid var(--line-soft); cursor: pointer;
    transition: background .12s ease;
}
.board-row:last-child { border-bottom: none; }
.board-row:nth-child(even) { background: var(--board-stripe); }
.board-row:hover { background: var(--ink-2); }
.board-gate { font-family: var(--font-mono); color: var(--dim); font-size: 13px; }
.board-service { display: flex; align-items: center; gap: 10px; min-width: 0; }
.board-service .material-symbols-outlined { font-size: 18px; color: var(--ash); flex: none; }
.board-service .name { font-weight: 600; font-size: 13.5px; }
.board-service .desc { font-size: 11.5px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-endpoint { font-family: var(--font-mono); font-size: 11px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-status { justify-self: end; }

@media (max-width: 640px) {
    .board-head, .board-row { grid-template-columns: 34px 1fr 84px; }
    .board-endpoint { display: none; }
}

.quick-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat-box { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--ink-1); padding: 14px 16px; }
.stat-box .num { font-family: var(--font-mono); font-size: 21px; font-weight: 600; }
.stat-box .lbl { font-size: 11.5px; color: var(--dim); margin-top: 3px; }

/* ==========================================================================
   PILLS / BADGES / TABS
   ========================================================================== */
.pill {
    display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 20px;
    font-size: 11px; font-weight: 600; font-family: var(--font-mono); letter-spacing: 0.02em;
    background: var(--ink-3); color: var(--ash); border: 1px solid var(--line);
}
.pill.green { color: var(--green); background: rgba(47,216,166,0.08); border-color: rgba(47,216,166,0.3); }
.pill.amber { color: var(--amber); background: rgba(255,176,32,0.08); border-color: rgba(255,176,32,0.3); }
.pill.red { color: var(--red); background: rgba(255,93,93,0.08); border-color: rgba(255,93,93,0.3); }
.pill.blue { color: var(--blue); background: rgba(79,163,255,0.08); border-color: rgba(79,163,255,0.3); }

.seg {
    display: inline-flex; padding: 3px; background: var(--ink-2); border: 1px solid var(--line);
    border-radius: var(--r-sm); gap: 2px;
}
.seg button {
    border: none; background: transparent; color: var(--ash); padding: 7px 14px; border-radius: var(--r-xs);
    font-size: 12.5px; font-weight: 500; cursor: pointer; transition: background .12s ease, color .12s ease;
}
.seg button.active { background: var(--ink-3); color: var(--paper); }
.seg button:hover:not(.active) { color: var(--paper); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs button {
    border: none; background: transparent; color: var(--dim); padding: 10px 4px; margin-right: 20px;
    font-size: 13px; font-weight: 500; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button.active { color: var(--paper); border-color: var(--amber); }
.tabs button:hover:not(.active) { color: var(--ash); }

/* ==========================================================================
   CHAT
   ========================================================================== */
.chat-layout { display: flex; height: 100%; }
.chat-convos {
    width: 220px; flex: none; border-right: 1px solid var(--line); display: flex; flex-direction: column;
    background: var(--ink-1);
}
.chat-convos-head { padding: 14px 14px 10px; }
.chat-convos-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.convo-item {
    padding: 9px 10px; border-radius: var(--r-sm); cursor: pointer; margin-bottom: 2px;
    display: flex; align-items: center; gap: 8px; position: relative;
}
.convo-item:hover { background: var(--ink-2); }
.convo-item.active { background: var(--ink-2); }
.convo-item .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
.convo-item .del { opacity: 0; flex: none; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; border-radius: 5px; color: var(--dim); }
.convo-item:hover .del { opacity: 1; }
.convo-item .del:hover { color: var(--red); background: rgba(255,93,93,0.1); }
.convo-item .del .material-symbols-outlined { font-size: 16px; }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-config {
    display: flex; align-items: center; gap: 8px; padding: 10px 18px; border-bottom: 1px solid var(--line);
    flex-wrap: wrap; background: var(--ink-0);
}
.chat-config .cfg-field { display: flex; align-items: center; gap: 6px; }
.chat-config label { font-size: 11px; color: var(--dim); font-weight: 600; }
.chat-config input[type="text"], .chat-config select { width: auto; min-width: 120px; height: 30px; padding: 0 9px; font-size: 12px; }
.chat-config .spacer { flex: 1; }

.chat-scroll { flex: 1; overflow-y: auto; padding: 20px 18px; }
.chat-msgs { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }

.msg { display: flex; gap: 12px; }
.msg-avatar {
    width: 26px; height: 26px; border-radius: 7px; flex: none; display: flex; align-items: center;
    justify-content: center; font-size: 12px; font-weight: 700; margin-top: 2px;
}
.msg.user .msg-avatar { background: var(--ink-3); color: var(--ash); }
.msg.assistant .msg-avatar { background: var(--amber); color: var(--amber-ink); }
.msg-body { flex: 1; min-width: 0; }
.msg-role { font-size: 11.5px; font-weight: 600; color: var(--dim); margin-bottom: 4px; }
.msg-content { font-size: 13.8px; line-height: 1.65; word-wrap: break-word; }
.msg-content p { margin: 0 0 10px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content strong { color: var(--paper); font-weight: 700; }
.msg-content ul, .msg-content ol { margin: 0 0 10px; padding-left: 22px; }
.msg-content li { margin-bottom: 3px; }
.msg-content code {
    font-family: var(--font-mono); font-size: 12.5px; background: var(--ink-3); padding: 1px 5px;
    border-radius: 4px; color: var(--amber);
}
.msg-content pre {
    background: var(--ink-2); border: 1px solid var(--line); border-radius: var(--r-sm);
    padding: 12px 14px; overflow-x: auto; margin: 8px 0 12px; position: relative;
}
.msg-content pre code { background: none; padding: 0; color: var(--paper); font-size: 12.5px; line-height: 1.55; }
.msg-content .code-head {
    display: flex; justify-content: space-between; align-items: center; font-family: var(--font-mono);
    font-size: 10.5px; color: var(--dim); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.04em;
}
.msg-content .code-copy { cursor: pointer; color: var(--dim); display: flex; align-items: center; gap: 4px; }
.msg-content .code-copy:hover { color: var(--amber); }
.msg-content .code-copy .material-symbols-outlined { font-size: 14px; }
.msg-actions { display: flex; gap: 4px; margin-top: 6px; opacity: 0; transition: opacity .12s ease; }
.msg:hover .msg-actions { opacity: 1; }
.msg-actions button {
    border: none; background: transparent; color: var(--dim); cursor: pointer; padding: 4px 6px;
    border-radius: 5px; display: flex; align-items: center; gap: 4px; font-size: 11px;
}
.msg-actions button:hover { color: var(--paper); background: var(--ink-2); }
.msg-actions .material-symbols-outlined { font-size: 14px; }

.typing-dots { display: inline-flex; gap: 4px; align-items: center; padding: 4px 0; }
.typing-dots span {
    width: 6px; height: 6px; border-radius: 50%; background: var(--dim);
    animation: typingBounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes typingBounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

.composer { border-top: 1px solid var(--line); padding: 14px 18px 18px; background: var(--ink-0); }
.composer-inner { max-width: 780px; margin: 0 auto; }
.composer-box {
    display: flex; align-items: flex-end; gap: 8px; background: var(--ink-2); border: 1px solid var(--line);
    border-radius: var(--r-md); padding: 8px 8px 8px 14px; transition: border-color .15s ease;
}
.composer-box:focus-within { border-color: var(--amber); }
.composer-box textarea {
    flex: 1; border: none; background: transparent; resize: none; padding: 6px 0; max-height: 200px;
    font-size: 13.8px;
}
.composer-box textarea:focus { outline: none; }
.composer-send {
    width: 34px; height: 34px; border-radius: var(--r-sm); border: none; background: var(--amber);
    color: var(--amber-ink); display: flex; align-items: center; justify-content: center; cursor: pointer;
    flex: none; transition: filter .12s ease;
}
.composer-send:hover { filter: brightness(1.08); }
.composer-send:disabled { background: var(--ink-3); color: var(--dim); cursor: not-allowed; }
.composer-stop { background: var(--red) !important; color: #fff !important; }
.composer-hint { font-size: 11px; color: var(--dim); margin-top: 8px; text-align: center; }

/* ==========================================================================
   GENERATOR FORM + RESULTS (image / video / music / voice)
   ========================================================================== */
.gen-layout { display: grid; grid-template-columns: 360px 1fr; gap: 20px; align-items: start; }
@media (max-width: 860px) { .gen-layout { grid-template-columns: 1fr; } }

.result-area { min-height: 220px; }
.result-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.result-toolbar .count { font-size: 12px; color: var(--dim); font-family: var(--font-mono); }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.gallery-item {
    border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; background: var(--ink-1);
    position: relative;
}
.gallery-item img { width: 100%; display: block; aspect-ratio: 1 / 1; object-fit: cover; }
.gallery-item .gi-bar {
    display: flex; align-items: center; justify-content: space-between; padding: 8px 10px;
    border-top: 1px solid var(--line);
}
.gallery-item .gi-bar .material-symbols-outlined { font-size: 17px; }

.media-card {
    border: 1px solid var(--line); border-radius: var(--r-md); background: var(--ink-1); padding: 16px;
    margin-bottom: 14px;
}
.media-card .mc-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; }
.media-card .mc-prompt { font-size: 12.5px; color: var(--ash); line-height: 1.5; margin-bottom: 12px; }
.media-card video { width: 100%; border-radius: var(--r-sm); display: block; background: #000; }
.media-card audio { width: 100%; }
.media-card .mc-foot { display: flex; gap: 8px; margin-top: 12px; }
.media-card .mc-meta { font-family: var(--font-mono); font-size: 10.5px; color: var(--dim); }

.job-status {
    display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: var(--r-sm);
    background: var(--ink-2); border: 1px solid var(--line); font-size: 12.5px; color: var(--ash); margin-bottom: 10px;
}
.job-status .spinner { flex: none; }
.raw-json {
    font-family: var(--font-mono); font-size: 11px; background: var(--ink-2); border: 1px solid var(--line);
    border-radius: var(--r-sm); padding: 10px 12px; max-height: 220px; overflow: auto; color: var(--ash);
    white-space: pre-wrap; word-break: break-all;
}
details.raw-wrap summary { cursor: pointer; font-size: 11.5px; color: var(--dim); margin-bottom: 8px; }
details.raw-wrap summary:hover { color: var(--ash); }

.spinner {
    width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line);
    border-top-color: var(--amber); animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner-lg { width: 26px; height: 26px; border-width: 3px; }

/* ==========================================================================
   TABLE (models list)
   ========================================================================== */
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th {
    text-align: left; font-family: var(--font-mono); font-size: 10.5px; color: var(--dim);
    text-transform: uppercase; letter-spacing: 0.06em; padding: 9px 12px; border-bottom: 1px solid var(--line);
    position: sticky; top: 0; background: var(--ink-1);
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.data-table tr:hover td { background: var(--ink-2); }
.data-table .mid { font-family: var(--font-mono); font-size: 12px; }
.table-wrap { border: 1px solid var(--line); border-radius: var(--r-md); overflow: auto; max-height: 62vh; background: var(--ink-1); }
.copy-cell { cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.copy-cell:hover { color: var(--amber); }
.copy-cell .material-symbols-outlined { font-size: 14px; opacity: .5; }

/* ==========================================================================
   HISTORY
   ========================================================================== */
.history-item {
    display: flex; gap: 12px; padding: 13px 14px; border: 1px solid var(--line); border-radius: var(--r-md);
    background: var(--ink-1); margin-bottom: 10px; align-items: flex-start;
}
.history-item .hi-thumb {
    width: 44px; height: 44px; border-radius: var(--r-sm); flex: none; object-fit: cover;
    background: var(--ink-3); display: flex; align-items: center; justify-content: center; color: var(--dim);
}
.history-item .hi-thumb .material-symbols-outlined { font-size: 20px; }
.history-item .hi-body { flex: 1; min-width: 0; }
.history-item .hi-top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.history-item .hi-prompt { font-size: 12.8px; color: var(--paper); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.history-item .hi-meta { font-size: 11px; color: var(--dim); font-family: var(--font-mono); margin-top: 4px; }
.history-item .hi-actions { display: flex; gap: 2px; flex: none; }

/* ==========================================================================
   TOASTS
   ========================================================================== */
.toast-stack { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: 320px; }
.toast {
    display: flex; align-items: center; gap: 9px; background: var(--ink-2); border: 1px solid var(--line);
    border-radius: var(--r-sm); padding: 11px 14px; font-size: 12.5px; box-shadow: var(--shadow);
    animation: toastIn .2s ease;
}
.toast.fade { animation: toastOut .2s ease forwards; }
@keyframes toastIn { from { transform: translateY(6px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes toastOut { to { transform: translateY(6px); opacity: 0; } }
.toast.success { border-color: rgba(47,216,166,0.35); }
.toast.success .material-symbols-outlined { color: var(--green); }
.toast.error { border-color: rgba(255,93,93,0.35); }
.toast.error .material-symbols-outlined { color: var(--red); }
.toast.info .material-symbols-outlined { color: var(--blue); }
.toast .material-symbols-outlined { font-size: 18px; flex: none; }

/* ==========================================================================
   MISC
   ========================================================================== */
.divider { height: 1px; background: var(--line-soft); margin: 16px 0; }
.kv-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; font-size: 12.5px; border-bottom: 1px solid var(--line-soft); }
.kv-row:last-child { border-bottom: none; }
.kv-row .k { color: var(--dim); }
.kv-row .v { font-family: var(--font-mono); color: var(--ash); }
.theme-swatches { display: flex; gap: 18px; }
.theme-opt { display: flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer; }
.theme-swatch {
    width: 58px; height: 44px; border-radius: var(--r-sm); border: 2px solid var(--line);
    overflow: hidden; transition: border-color .15s ease;
}
.theme-opt.active .theme-swatch { border-color: var(--amber); }
.theme-opt .lbl { font-size: 11px; color: var(--dim); }
.theme-opt.active .lbl { color: var(--ash); }

/* ==========================================================================
   TOOLS VIEW (embeddings / rerank / search / moderation)
   ========================================================================== */
.stack-inputs { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.stack-input-row { display: flex; gap: 8px; align-items: center; }
.stack-input-row .idx { font-family: var(--font-mono); font-size: 11px; color: var(--dim); width: 18px; flex: none; }
.stack-input-row .rm { flex: none; width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; color: var(--dim); cursor: pointer; border-radius: 6px; }
.stack-input-row .rm:hover { color: var(--red); background: rgba(255,93,93,0.08); }

.rank-list { display: flex; flex-direction: column; gap: 8px; }
.rank-item { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 12px; background: var(--ink-1); }
.rank-item .ri-top { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.rank-item .ri-text { font-size: 12.8px; }
.rank-item .ri-score { font-family: var(--font-mono); font-size: 11.5px; color: var(--amber); flex: none; }
.rank-bar { height: 4px; border-radius: 3px; background: var(--ink-3); overflow: hidden; }
.rank-bar > span { display: block; height: 100%; background: var(--amber); }

.search-result { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px 14px; background: var(--ink-1); margin-bottom: 10px; }
.search-result .sr-title { font-size: 13px; font-weight: 600; color: var(--blue); margin-bottom: 3px; }
.search-result .sr-url { font-size: 11px; color: var(--green); font-family: var(--font-mono); margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result .sr-snippet { font-size: 12.3px; color: var(--ash); line-height: 1.5; }

.mod-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.mod-cat { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 12px; background: var(--ink-1); display: flex; justify-content: space-between; align-items: center; font-size: 12px; }
.mod-cat.flagged { border-color: rgba(255,93,93,0.4); background: rgba(255,93,93,0.06); }
.mod-cat.flagged .material-symbols-outlined { color: var(--red); }
.mod-cat .material-symbols-outlined { font-size: 16px; color: var(--green); }

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 900px) {
    .sidebar {
        position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%);
        transition: transform .2s ease; box-shadow: var(--shadow);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-scrim.show {
        display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 39;
    }
    .topbar .menu-btn { display: inline-flex; }
    .chat-convos { position: fixed; left: 0; top: 56px; bottom: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); }
    .chat-convos.open { transform: translateX(0); }
    .view-inner { padding: 18px 16px 48px; }
    .gen-layout { grid-template-columns: 1fr; }
    .chat-config { padding: 8px 12px; }
    .hero { flex-direction: column; align-items: flex-start; }
    .hero-time { text-align: left; }
}

@media (max-width: 480px) {
    .board-head { display: none; }
    .board-row { grid-template-columns: 1fr auto; row-gap: 4px; }
    .board-gate { display: none; }
    .quick-stats { grid-template-columns: repeat(2, 1fr); }
}

/* Toggled via the Animations switch in Settings */
.reduce-motion, .reduce-motion *, .reduce-motion *::before, .reduce-motion *::after {
    animation-duration: 0.001ms !important; transition-duration: 0.001ms !important;
}

/* AiExpress managed-auth additions */
.auth-card { max-width: 560px; }
.google-login-wrap { display:flex; justify-content:center; padding:18px 0 10px; min-height:54px; }
.auth-benefits { display:grid; gap:10px; margin:18px 0 8px; }
.auth-benefits > div { display:flex; gap:10px; align-items:center; padding:10px 12px; border:1px solid var(--line, #29303a); border-radius:10px; }
.auth-benefits .material-symbols-outlined { font-size:19px; }
.account-box { display:flex; align-items:center; gap:12px; padding:14px; border:1px solid var(--line, #29303a); border-radius:12px; }
.account-avatar { width:42px;height:42px;border-radius:50%;display:grid;place-items:center;font-weight:700;background:var(--accent,#ffb020);color:#111; }
.account-meta { display:grid; gap:2px; }
.account-meta span { opacity:.68; font-size:.9em; }
