/* ===========================================================================
   allaigate Gateway Console — design system (build-free, no framework)
   Ported from cortiq-console, extended with light theme, charts, KPIs, modal.
   =========================================================================== */
:root,
:root[data-theme="dark"] {
  --bg: #0a0e1a;
  --bg-2: #0e1424;
  --panel: #131a2c;
  --card: #151d31;
  --card-2: #121a2c;
  --border: #243049;
  --border-soft: #1d2740;
  --text: #e6ecf7;
  --muted: #8b97b0;
  --faint: #5e6b85;
  --accent: #6366f1;
  --accent-2: #5eead4;
  --gold: #f59e0b;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --grid: #ffffff14;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --hover: #ffffff0a;
  --bg-grad: radial-gradient(1200px 700px at 80% -10%, #16203a 0%, var(--bg) 55%);
  --radius: 14px;
  --radius-sm: 9px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

:root[data-theme="light"] {
  --bg: #f5f7fb;
  --bg-2: #ffffff;
  --panel: #ffffff;
  --card: #ffffff;
  --card-2: #f7f9fc;
  --border: #d8e0ee;
  --border-soft: #e6ebf4;
  --text: #0f172a;
  --muted: #5a6781;
  --faint: #8a96ad;
  --accent: #5457e6;
  --accent-2: #0ea5a4;
  --gold: #d97706;
  --good: #10b981;
  --warn: #d97706;
  --bad: #ef4444;
  --grid: #0f172a14;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  --hover: #0f172a08;
  --bg-grad: radial-gradient(1200px 700px at 80% -10%, #e7edf9 0%, var(--bg) 55%);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg-grad);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 20px; margin: 0 0 4px; }
h3 { font-size: 15px; margin: 0 0 10px; }
code, .mono { font-family: var(--mono); }
.boot { padding: 60px; text-align: center; color: var(--faint); }

/* ---- layout -------------------------------------------------------------- */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-right: 1px solid var(--border-soft);
  padding: 18px 14px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.main { display: flex; flex-direction: column; min-width: 0; }
.content { padding: 24px 32px 64px; max-width: 1220px; width: 100%; }

/* ---- brand + nav --------------------------------------------------------- */
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; }
.brand img { width: 30px; height: 30px; }
.brand b { font-size: 16px; }
.brand .sub { color: var(--muted); font-weight: 500; font-size: 13px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--muted); cursor: pointer; font-weight: 500;
  border: 1px solid transparent; user-select: none;
}
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--text); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.nav-item .ico { width: 18px; text-align: center; opacity: 0.95; font-size: 15px; }
.nav-spacer { flex: 1; }
.nav-foot { font-size: 11px; color: var(--faint); padding: 8px; }

/* ---- topbar -------------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 32px; border-bottom: 1px solid var(--border-soft);
  position: sticky; top: 0; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px); z-index: 5;
}
.topbar .title { font-weight: 600; font-size: 15px; }
.topbar .right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.icon-btn {
  background: var(--panel); border: 1px solid var(--border); color: var(--muted);
  width: 34px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }
.lang-select {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 6px 8px; font-size: 12px; font-weight: 600; width: auto;
}

/* ---- status pill --------------------------------------------------------- */
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 11px; border-radius: 999px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border); background: var(--panel);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.dot.ok { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 18%, transparent); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 18%, transparent); }
.dot.warn { background: var(--warn); }

/* ---- cards --------------------------------------------------------------- */
.card {
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.card .card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card .card-head .sub { color: var(--muted); font-weight: 400; font-size: 13px; }
.card .card-head .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 980px) { .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; } .app { grid-template-columns: 1fr; } .sidebar { display: none; } }

.page-head { margin-bottom: 20px; }
.page-head .flex { justify-content: space-between; align-items: flex-start; }
.page-head p { color: var(--muted); margin: 6px 0 0; max-width: 74ch; }

/* ---- KPI ----------------------------------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 620px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi {
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 14px 16px;
}
.kpi .big { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.kpi .lbl { color: var(--muted); font-size: 12px; margin-top: 3px; }

/* ---- forms --------------------------------------------------------------- */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; font-weight: 600; }
input, select, textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm); padding: 10px 12px;
  font-family: inherit; font-size: 14px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
textarea { resize: vertical; min-height: 64px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 150px; }
.inline { display: flex; align-items: center; gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; margin-bottom: 12px; }
.check input { width: auto; }
.hint { color: var(--faint); font-size: 12px; margin-top: 4px; }

/* "?" help badge — hover/focus shows the native title tooltip explaining a setting */
.help {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--panel);
  color: var(--muted); font-size: 10px; font-weight: 700; line-height: 1;
  cursor: help; vertical-align: middle; user-select: none;
  transition: 0.12s;
}
.help:hover, .help:focus { color: var(--accent); border-color: var(--accent); outline: none; }
label.field > span .help { text-transform: none; }

/* ---- buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 16px; cursor: pointer;
  font-weight: 600; font-size: 14px; font-family: inherit; transition: 0.12s;
}
.btn:hover { border-color: var(--accent); background: var(--hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 88%, #fff), var(--accent)); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.gold { background: linear-gradient(180deg, color-mix(in srgb, var(--gold) 85%, #fff), var(--gold)); border-color: var(--gold); color: #1a1206; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.btn.danger:hover { background: color-mix(in srgb, var(--bad) 10%, transparent); }
.btn.sm { padding: 6px 11px; font-size: 12.5px; }

/* ---- badges -------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px;
  border-radius: 999px; font-size: 11.5px; font-weight: 700; border: 1px solid var(--border);
  background: var(--bg-2); color: var(--muted);
}
.badge.tier-low, .badge.cheap, .badge.ok { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, transparent); background: color-mix(in srgb, var(--good) 8%, transparent); }
.badge.tier-medium, .badge.mid, .badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); background: color-mix(in srgb, var(--warn) 8%, transparent); }
.badge.tier-high, .badge.expensive, .badge.bad, .badge.error { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); background: color-mix(in srgb, var(--bad) 8%, transparent); }
.badge.router, .badge.store { color: var(--accent-2); border-color: color-mix(in srgb, var(--accent-2) 40%, transparent); background: color-mix(in srgb, var(--accent-2) 8%, transparent); }
.badge.env { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); background: color-mix(in srgb, var(--accent) 8%, transparent); }

/* ---- tables -------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border-soft); white-space: nowrap; }
th { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 700; }
tr:last-child td { border-bottom: 0; }
td .mono { font-size: 12.5px; color: var(--muted); }
tbody tr:hover td { background: var(--hover); }

/* ---- chips (routing) ----------------------------------------------------- */
.tierrow { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border-soft); }
.tierrow:last-child { border-bottom: 0; }
.tierrow .tname { width: 110px; font-weight: 700; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 7px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 999px; padding: 5px 6px 5px 11px; font-weight: 600; font-size: 13px; }
.chip .ord { width: 16px; height: 16px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 10px; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; }
.chip .arrow { cursor: pointer; color: var(--faint); padding: 0 1px; }
.chip .arrow:hover { color: var(--text); }
.chip .x { cursor: pointer; color: var(--faint); border-radius: 50%; width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center; }
.chip .x:hover { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }

/* ---- toggle list (protocols) --------------------------------------------- */
.togglerow { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--border-soft); }
.togglerow:last-child { border-bottom: 0; }
.togglerow .meta { flex: 1; }
.togglerow .meta .name { font-weight: 600; display: flex; gap: 8px; align-items: center; }
.togglerow .meta .desc { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.switch { position: relative; width: 44px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: 0.15s; cursor: pointer; }
.switch .slider::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: 0.15s; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(20px); }
.switch input:disabled + .slider { opacity: 0.5; cursor: not-allowed; }

/* ---- charts -------------------------------------------------------------- */
.chart { width: 100%; height: 180px; display: block; }
.chart .axis { stroke: var(--grid); stroke-width: 1; }
.chart .area { fill: color-mix(in srgb, var(--accent) 16%, transparent); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart .bar { fill: var(--accent); }
.barlist { display: flex; flex-direction: column; gap: 10px; }
.barlist .b { display: grid; grid-template-columns: 130px 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.barlist .b .track { background: var(--bg-2); border-radius: 5px; height: 10px; overflow: hidden; }
.barlist .b .track > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); }
.barlist .b .val { color: var(--muted); font-weight: 600; min-width: 56px; text-align: right; }

/* ---- playground ---------------------------------------------------------- */
.pg { display: grid; grid-template-columns: 1fr 340px; gap: 18px; align-items: start; }
@media (max-width: 1024px) { .pg { grid-template-columns: 1fr; } }
.answer { white-space: pre-wrap; word-break: break-word; line-height: 1.55; background: var(--panel); border: 1px solid var(--border-soft); border-radius: 12px; padding: 14px 16px; min-height: 120px; }
.routecard .kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border-soft); }
.routecard .kv:last-child { border-bottom: 0; }
.routecard .kv .k { color: var(--muted); }
.routecard .kv .v { font-weight: 600; text-align: right; }
.scorebar { height: 7px; background: var(--bg-2); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.scorebar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); }

/* ---- modal --------------------------------------------------------------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(3, 7, 18, 0.6); display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; z-index: 40; overflow: auto; }
.modal { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); width: 100%; max-width: 560px; padding: 22px; }
.modal h3 { font-size: 17px; margin-bottom: 16px; }
.modal .modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ---- login --------------------------------------------------------------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 30px; }
.login-card .brand { justify-content: center; padding-top: 0; }
.login-card h2 { text-align: center; }
.login-card p.sub { color: var(--muted); text-align: center; margin: 4px 0 22px; }

/* ---- misc ---------------------------------------------------------------- */
.empty { text-align: center; color: var(--faint); padding: 40px 20px; }
.spinner { width: 16px; height: 16px; border: 2px solid color-mix(in srgb, var(--text) 25%, transparent); border-top-color: var(--text); border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.divider { height: 1px; background: var(--border-soft); margin: 18px 0; }
.muted { color: var(--muted); }
.right-align { text-align: right; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { background: transparent; border: 0; color: var(--muted); padding: 6px 12px; cursor: pointer; font-size: 12.5px; font-weight: 600; }
.seg button.active { background: var(--accent); color: #fff; }

/* ---- toasts -------------------------------------------------------------- */
.toasts { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 60; }
.toast {
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); min-width: 220px;
  animation: slidein 0.18s ease; font-size: 13px;
}
.toast.good { border-left-color: var(--good); }
.toast.bad { border-left-color: var(--bad); }
.toast.warn { border-left-color: var(--warn); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- callout ------------------------------------------------------------- */
.callout { border: 1px solid var(--border); border-left: 3px solid var(--warn); background: color-mix(in srgb, var(--warn) 6%, transparent); border-radius: 10px; padding: 13px 15px; color: var(--muted); margin-bottom: 16px; }
.callout.info { border-left-color: var(--accent-2); background: color-mix(in srgb, var(--accent-2) 6%, transparent); }
.callout b { color: var(--text); }

/* ── Import model (HuggingFace → CMF) ── */
.view-head { margin-bottom: 14px; }
.view-head h2 { margin: 0 0 2px; }
.card-title { font-weight: 600; margin-bottom: 10px; }
.actions { margin-top: 12px; display: flex; gap: 8px; }
.pad { padding: 18px; }
.err { color: #e5534b; }
.btn.sm { padding: 4px 10px; font-size: 12px; }

.hf-search {
  width: 100%; box-sizing: border-box; margin-bottom: 12px;
  padding: 10px 12px; font-size: 15px;
  border: 1px solid var(--border, #2a2f3a); border-radius: 8px;
  background: var(--bg-2, #12151c); color: inherit;
}
.hf-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px; max-height: 420px; overflow-y: auto;
}
.hf-card {
  border: 1px solid var(--border, #2a2f3a); border-radius: 8px;
  padding: 10px 12px; cursor: pointer; transition: border-color .12s, background .12s;
  background: var(--bg-2, #12151c);
}
.hf-card:hover { border-color: var(--accent, #5b8def); }
.hf-card.sel { border-color: var(--accent, #5b8def); background: rgba(91,141,239,.10); }
.hf-id { font-weight: 600; font-size: 13px; word-break: break-all; margin-bottom: 6px; }
.hf-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12px; }
.badge.bad { background: rgba(229,83,75,.15); color: #e5534b; }

.import-form { margin-top: 14px; }
.adv { margin-top: 8px; }
.adv-body { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border, #2a2f3a); }

.pbar {
  height: 8px; border-radius: 6px; overflow: hidden; margin: 10px 0;
  background: var(--bg-2, #12151c); border: 1px solid var(--border, #2a2f3a);
}
.pbar-fill { height: 100%; width: 100%; border-radius: 6px; }
.pbar-fill.run {
  width: 40%;
  background: linear-gradient(90deg, transparent, var(--accent, #5b8def), transparent);
  animation: pbar-slide 1.2s infinite ease-in-out;
}
.pbar-fill.ok { background: #3fb950; }
.pbar-fill.err { background: #e5534b; }
@keyframes pbar-slide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }

.conv-log {
  margin-top: 10px; max-height: 260px; overflow-y: auto;
  background: var(--bg-2, #0d1017); border: 1px solid var(--border, #2a2f3a);
  border-radius: 8px; padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
  white-space: pre-wrap; word-break: break-word; color: var(--muted, #9aa4b2);
}

/* Router-key field: input grows, inline "Save key" button sits beside it */
.key-row { display: flex; gap: 8px; align-items: stretch; }
.key-row input { flex: 1 1 auto; min-width: 0; }
.key-row .btn { flex: 0 0 auto; white-space: nowrap; }

/* Determinate progress fill (known %); .run remains the indeterminate slider */
.pbar-fill.det {
  background: linear-gradient(90deg, var(--accent, #5b8def), #7aa2f7);
  transition: width .4s ease;
}
/* Import job cards (multiple conversions, live) */
.job { padding: 12px 0; border-top: 1px solid var(--border-soft, #232833); }
.job:first-of-type { border-top: 0; }
.job-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.job-head b { word-break: break-all; }
.small { font-size: 12px; }
/* Router usage: readable, wrapping key/value rows (no horizontal overflow) */
.usage-box { max-width: 100%; overflow-x: hidden; }
.mono.kv { display: flex; gap: 6px; padding: 1px 0; white-space: normal; overflow-wrap: anywhere; word-break: break-word; }
.mono.kv .kv-k { color: var(--muted, #9aa4b2); flex: 0 0 auto; }
.mono.kv .kv-v { font-weight: 600; overflow-wrap: anywhere; word-break: break-word; min-width: 0; }

/* ---- responsive shell + touch layout ----------------------------------- */
.menu-toggle, .nav-close, .mobile-nav-backdrop { display: none; }
.hamburger { width: 18px; display: flex; flex-direction: column; gap: 4px; }
.hamburger i { display: block; height: 2px; border-radius: 2px; background: currentColor; }
body.modal-open { overflow: hidden; }

@media (max-width: 980px) {
  .app { display: block; min-height: 100dvh; }
  .main { min-height: 100dvh; }
  .menu-toggle { display: inline-flex; flex: 0 0 auto; }
  .nav-close { display: inline-flex; margin-left: auto; flex: 0 0 auto; font-size: 24px; line-height: 1; }
  .brand-copy { min-width: 0; }

  .sidebar {
    display: flex;
    position: fixed;
    inset: 0 auto 0 0;
    width: min(84vw, 310px);
    height: 100dvh;
    padding: max(18px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
    z-index: 70;
    box-shadow: 18px 0 45px rgba(0, 0, 0, .42);
    transform: translateX(-104%);
    visibility: hidden;
    transition: transform .22s ease, visibility 0s linear .22s;
    overflow-y: auto;
  }
  .app.nav-open .sidebar {
    transform: translateX(0);
    visibility: visible;
    transition: transform .22s ease;
  }
  .mobile-nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 65;
    width: 100%;
    height: 100%;
    border: 0;
    background: rgba(3, 7, 18, .62);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .22s ease, visibility 0s linear .22s;
  }
  .app.nav-open .mobile-nav-backdrop {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity .22s ease;
  }
  body.mobile-nav-open { overflow: hidden; }

  .topbar { padding: 10px 18px; min-height: 58px; gap: 10px; }
  .topbar .title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .right { gap: 8px; min-width: 0; }
  .content { max-width: none; padding: 22px 20px 52px; }
}

@media (max-width: 720px) {
  body { font-size: 14px; }
  .status-pills { display: none; }
  .topbar { padding: 9px 12px; }
  .content { padding: 18px 14px 42px; }

  .page-head { margin-bottom: 16px; }
  .page-head > .flex { align-items: stretch; flex-direction: column; }
  .page-head > .flex > .btn { width: 100%; }
  .page-head p { line-height: 1.45; }

  .card { padding: 15px; margin-bottom: 14px; border-radius: 12px; }
  .card .card-head { align-items: flex-start; flex-wrap: wrap; }
  .card .card-head .right { width: 100%; margin-left: 0; flex-wrap: wrap; }
  .grid { gap: 14px; }
  .kpis { gap: 10px; margin-bottom: 14px; }
  .kpi { padding: 12px; border-radius: 11px; }
  .kpi .big { font-size: 21px; }

  .row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; }
  .row > * { min-width: 0; width: 100%; }
  input, select, textarea { min-height: 44px; font-size: 16px; }
  input[type="checkbox"], input[type="radio"] { min-height: 0; }
  .check { min-height: 36px; margin-bottom: 8px; }
  .btn, .icon-btn { min-height: 44px; }
  .btn { padding: 10px 14px; }
  .btn.sm, .btn.small { min-height: 38px; padding: 8px 11px; }

  .table-wrap {
    width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  .table-wrap table { min-width: max-content; }
  th, td { padding: 10px; }

  .tierrow { align-items: flex-start; flex-direction: column; gap: 8px; }
  .tierrow .tname { width: auto; }
  .chips { width: 100%; }
  .togglerow { align-items: flex-start; }

  .pg { gap: 14px; }
  .routecard .kv { flex-wrap: wrap; }
  .routecard .kv .v { max-width: 100%; overflow-wrap: anywhere; }
  .answer { padding: 12px; }
  .seg { max-width: 100%; overflow-x: auto; }
  .seg button { min-height: 40px; white-space: nowrap; }

  .hf-grid { grid-template-columns: 1fr; max-height: 56dvh; }
  .job-head, .actions { align-items: stretch; flex-wrap: wrap; }
  .actions .btn { flex: 1 1 150px; }
  .key-row { flex-direction: column; }
  .key-row .btn { width: 100%; }
  .cmf-server-row { align-items: stretch !important; padding: 10px; border: 1px solid var(--border-soft); border-radius: 10px; }
  .cmf-server-row > input, .cmf-server-row > select { width: 100% !important; min-width: 0 !important; flex: 1 1 100% !important; }
  .cmf-server-row > .btn { flex: 1 1 calc(50% - 6px); }
  .cmf-server-row > .small { flex: 1 1 100%; }

  .modal-backdrop { align-items: flex-end; padding: 8px 0 0; }
  .modal {
    max-width: none;
    max-height: calc(100dvh - 8px);
    overflow-y: auto;
    padding: 18px 15px max(14px, env(safe-area-inset-bottom));
    border-radius: 18px 18px 0 0;
  }
  .modal .modal-foot {
    position: sticky;
    bottom: calc(-1 * max(14px, env(safe-area-inset-bottom)));
    margin: 12px -15px 0;
    padding: 12px 15px max(14px, env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--card) 94%, transparent);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border-soft);
  }
  .modal .modal-foot .btn { flex: 1; }

  .toasts { left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); }
  .toast { min-width: 0; width: 100%; }
  .login-wrap { align-items: flex-start; padding: max(20px, env(safe-area-inset-top)) 14px; }
  .login-card { padding: 22px 18px; margin-top: 8dvh; }
}

@media (max-width: 480px) {
  .topbar .title { font-size: 14px; }
  .topbar .right { gap: 6px; }
  .lang-select { width: 54px; min-height: 44px; padding: 6px; }
  .icon-btn { width: 42px; height: 42px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .lbl { line-height: 1.25; }
  .barlist .b { grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; }
  .barlist .b .track { grid-column: 1 / -1; grid-row: 2; }
  .barlist .b .val { min-width: 0; }
  .empty { padding: 28px 12px; }
}

@media (max-width: 360px) {
  .topbar .title { display: none; }
  .kpis { grid-template-columns: 1fr; }
}

/* ---- onboarding ------------------------------------------------------------ */
.onb-shell { min-height: 100vh; display: flex; align-items: flex-start; justify-content: center; padding: 32px 20px; background: var(--bg-grad); }
.onb-content { width: 100%; max-width: 860px; }
.onb-wrap { max-width: 860px; margin: 0 auto; }
.onb-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.onb-dots { display: flex; gap: 8px; }
.onb-dots .dot { width: 28px; height: 6px; border-radius: 999px; background: var(--border); }
.onb-dots .dot.on { background: var(--accent); }
.onb-dots .dot.done { background: color-mix(in srgb, var(--accent) 55%, transparent); }
.onb-title { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.onb-step h2 { font-size: 22px; margin-bottom: 6px; }
.onb-langs { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 12px; margin: 18px 0; }
.onb-lang {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 18px 10px; border-radius: 14px; border: 1.5px solid var(--border);
  background: var(--card); cursor: pointer; transition: .15s; font-family: inherit;
}
.onb-lang:hover { border-color: color-mix(in srgb, var(--accent) 45%, transparent); transform: translateY(-1px); }
.onb-lang.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--card)); box-shadow: 0 6px 18px rgba(99,102,241,.18); }
.onb-lang .flag { font-size: 32px; line-height: 1; }
.onb-lang b { font-size: 14px; font-weight: 700; color: var(--text); }
/* Featured gallery: the list grows as new models are published, so give it more
   room than the search grid before it starts scrolling. */
.featured-section .hf-grid { max-height: min(62vh, 760px); }
/* Money: 4 decimals, last two de-emphasized */
.money-tail { font-size: .72em; opacity: .75; margin-left: 1px; }

.seg { flex-wrap: wrap; }

.ok { color: var(--good); }

.pairs { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.pair-row { display: flex; gap: 6px; align-items: center; }
.pair-model { min-width: 220px; max-width: 340px; padding: 4px 8px; font-size: 12.5px; }
.pair-tier { max-width: 150px; padding: 4px 8px; font-size: 12.5px; }

/* Complexity bands slider */
.bands-wrap { margin: 4px 0 16px; }
/* one-line command chip (install commands etc.) — theme-aware */
.cmd-chip { background: var(--panel); border: 1px solid var(--border); color: var(--text); padding: 2px 8px; border-radius: 6px; }

.bands-track { position: relative; height: 14px; border-radius: 8px; background: var(--border); margin: 26px 8px 10px; }
.bands-track.disabled { opacity: .45; pointer-events: none; }
.bands-zone { position: absolute; top: 0; bottom: 0; }
.bands-zone.z-low { left: 0; background: color-mix(in srgb, var(--good) 45%, transparent); border-radius: 8px 0 0 8px; }
.bands-zone.z-med { background: color-mix(in srgb, var(--warn, #f59e0b) 55%, transparent); }
.bands-zone.z-high { background: color-mix(in srgb, #dc2626 65%, transparent); border-radius: 0 8px 8px 0; }
.bands-handle { position: absolute; top: -5px; width: 24px; height: 24px; margin-left: -12px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); cursor: grab; touch-action: none; z-index: 2; }
.bands-handle:active { cursor: grabbing; }
.bands-val { position: absolute; top: -24px; left: 50%; transform: translateX(-50%); font-size: 11.5px;
  font-family: var(--mono, monospace); color: var(--text); background: var(--panel); padding: 1px 6px;
  border-radius: 6px; border: 1px solid var(--border, #333); white-space: nowrap; }
.bands-val.raised { top: -46px; }
.bands-legend { display: flex; gap: 8px; margin: 6px 8px 0; flex-wrap: wrap; }

/* Benchmark view */
@keyframes bm-in { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
tbody tr:last-child { animation: bm-in .25s ease; }
.bm-sum { margin-bottom: 10px; }
.bm-cell { cursor: pointer; white-space: nowrap; }
.bm-cell:hover { background: var(--hover); }
.badge.ok { background: rgba(52,211,153,.15); color: var(--good); }

/* Routing: per-task rule rows */
.taskrow { align-items: flex-start; }
.taskname { min-width: 190px; line-height: 1.35; }
.taskname .mono { font-size: 10.5px; opacity: .75; }
.chips-empty { padding: 4px 0; font-style: italic; }

/* Shell notices (open admin warning, update available) */
.notice {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 18px; font-size: 13px;
  border-bottom: 1px solid var(--border-soft, #232833);
}
.notice.warn { background: color-mix(in srgb, #e5a54b 12%, var(--bg)); }
.notice.info { background: color-mix(in srgb, var(--accent) 10%, var(--bg)); }
.notice .icon-btn { margin-left: auto; }

/* Dashboard host metrics */
.sysgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.sysitem .k { color: var(--muted); font-size: 12px; }
.sysitem .v { font-weight: 600; }
.sysbar {
  height: 8px; border-radius: 6px; overflow: hidden; margin: 6px 0;
  background: var(--bg-2, #12151c); border: 1px solid var(--border, #2a2f3a);
}
.sysbar i { display: block; height: 100%; background: var(--accent, #5b8def); }
.sysbar i.bad { background: #e5534b; }

/* Log viewer */
.logs-view { max-height: 68vh; }

/* Chat dialogue bubbles */
.chat-log { max-height: 56vh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.chat-msg { display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-bubble {
  max-width: 85%; padding: 8px 12px; border-radius: 12px;
  white-space: pre-wrap; word-break: break-word; font-size: 13.5px;
  background: var(--bg-2, #12151c); border: 1px solid var(--border-soft, #232833);
}
.chat-msg.user .chat-bubble {
  background: color-mix(in srgb, var(--accent) 16%, var(--bg-2));
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}

/* Generation gallery */
.gal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.gal-item {
  position: relative; cursor: pointer; border: 1px solid var(--border, #2a2f3a);
  border-radius: 8px; overflow: hidden; background: var(--bg-2, #12151c);
}
.gal-item:hover { border-color: var(--accent, #5b8def); }
.gal-thumb { width: 100%; display: block; min-height: 64px; }
.gal-video { display: flex; align-items: center; justify-content: center; font-size: 28px; height: 72px; }
.gal-cap { font-size: 10px; color: var(--muted); padding: 3px 6px; }
.gal-del {
  position: absolute; top: 2px; right: 2px; z-index: 2;
  border: 0; border-radius: 50%; width: 18px; height: 18px; line-height: 16px;
  background: rgba(0,0,0,.55); color: #fff; cursor: pointer; font-size: 12px;
}

/* Bench + badges */
.bench-row { gap: 10px; padding: 6px 0; border-top: 1px solid var(--border-soft, #232833); }
.bench-row:first-of-type { border-top: 0; }
.badge.warn { background: rgba(229,165,75,.15); color: #e5a54b; }
.snippet { max-height: 260px; }

/* Playground media tabs: generated image / video frame */
.media-out { display: flex; flex-direction: column; gap: 8px; }
.media-canvas {
  max-width: 100%; height: auto; border-radius: 8px;
  border: 1px solid var(--border, #2a2f3a); background: #000;
}
/* Live download progress inside a featured card (empty until a job runs) */
.card-prog:empty { display: none; }
.card-prog { margin-top: 6px; }
.card-prog .pbar { margin: 4px 0; }
.card-prog .btn.sm { padding: 0 6px; line-height: 18px; }

@media (prefers-reduced-motion: reduce) {
  .sidebar, .mobile-nav-backdrop { transition: none; }
}

/* full-screen farewell after "stop everything & power off" */
.shutdown-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; gap: 12px; text-align: center; padding: 24px; }
.shutdown-screen .shutdown-icon { font-size: 64px; color: var(--bad); }
.shutdown-screen .hint { max-width: 480px; }
