/* GenBridge Trader console. Token-driven; light and dark are both selected
   (dark values are stepped, not auto-flipped) per the dataviz reference palette. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --ink-1: #0b0b0b;
  --ink-2: #52514e;
  --ink-muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --paper: #1c5cab;
  --paper-bg: #cde2fb;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #232322;
    --ink-1: #ffffff;
    --ink-2: #c3c2b7;
    --ink-muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --good-text: #0ca30c;
    --paper: #86b6ef;
    --paper-bg: #10315c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface-1: #1a1a19; --surface-2: #232322;
  --ink-1: #ffffff; --ink-2: #c3c2b7; --ink-muted: #898781;
  --grid: #2c2c2a; --baseline: #383835; --border: rgba(255,255,255,0.10);
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --good-text: #0ca30c; --paper: #86b6ef; --paper-bg: #10315c;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page); color: var(--ink-1);
}
.hidden { display: none !important; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(400px, 100%); background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; display: flex; flex-direction: column; gap: 14px;
}
.login-card h1 { font-size: 19px; margin: 0; }
.login-card .sub { margin: 2px 0 0; color: var(--ink-2); font-size: 12.5px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--ink-2); }
.login-card input {
  padding: 10px 12px; border-radius: 8px; border: 1px solid var(--baseline);
  background: var(--page); color: var(--ink-1); font-size: 14px;
}
.error { color: var(--critical); font-size: 13px; margin: 0; }

/* ---------- shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 218px; flex: none; background: var(--surface-1); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 12px; padding: 18px 12px; position: sticky; top: 0;
  height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-mark {
  width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 9px;
  background: var(--series-1); color: #fff; font-weight: 700; font-size: 14px; letter-spacing: .5px;
}
.brand-name { font-weight: 650; font-size: 15px; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-link {
  padding: 7px 10px; border-radius: 7px; color: var(--ink-2); text-decoration: none; font-size: 13.5px;
}
.nav-link:hover { background: var(--surface-2); color: var(--ink-1); }
.nav-link.active { background: var(--surface-2); color: var(--ink-1); font-weight: 600; }
.sidebar-foot { display: flex; flex-direction: column; gap: 8px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 22px; border-bottom: 1px solid var(--border); background: var(--surface-1);
  position: sticky; top: 0; z-index: 5;
}
.topbar h2 { margin: 0; font-size: 16px; }
.topbar-right { display: flex; gap: 10px; align-items: center; }
.page { padding: 22px; display: flex; flex-direction: column; gap: 18px; max-width: 1200px; }

/* ---------- badges/pills ---------- */
.env-badge {
  display: inline-block; padding: 4px 12px; border-radius: 999px; font-weight: 700;
  font-size: 12px; letter-spacing: .8px; background: var(--paper-bg); color: var(--paper);
  border: 1px solid var(--paper);
}
.env-badge.big { text-align: center; font-size: 14px; padding: 8px; }
.pill {
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border); color: var(--ink-2);
}
.pill.NORMAL { color: var(--good-text); }
.pill.NORMAL::before { content: "● "; color: var(--good); }
.pill.CAUTION { color: var(--ink-1); }
.pill.CAUTION::before { content: "▲ "; color: var(--warning); }
.pill.HALTED { color: var(--critical); }
.pill.HALTED::before { content: "■ "; color: var(--critical); }

.status-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; }
.status-chip .dot { width: 8px; height: 8px; border-radius: 50%; }

/* ---------- stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.tile {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; display: flex; flex-direction: column; gap: 3px;
}
.tile .k { font-size: 12px; color: var(--ink-muted); }
.tile .v { font-size: 22px; font-weight: 650; }
.tile .v.pos { color: var(--good-text); }
.tile .v.neg { color: var(--critical); }
.tile .d { font-size: 12px; color: var(--ink-2); }

/* ---------- cards, tables ---------- */
.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px;
}
.card h3 { margin: 0 0 10px; font-size: 13.5px; color: var(--ink-2); font-weight: 600; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th {
  text-align: left; color: var(--ink-muted); font-weight: 600; font-size: 12px;
  padding: 7px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap;
}
td { padding: 7px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-muted); }
.small { font-size: 12px; }

/* ---------- feed ---------- */
.feed { display: flex; flex-direction: column; gap: 0; }
.feed-item { display: flex; gap: 12px; padding: 9px 4px; border-bottom: 1px solid var(--grid); }
.feed-item:last-child { border-bottom: none; }
.feed-time { flex: none; width: 130px; color: var(--ink-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.feed-msg { flex: 1; font-size: 13px; }
.feed-item.WARNING .feed-msg::before { content: "⚠ "; color: var(--warning); }
.feed-item.ERROR .feed-msg::before, .feed-item.CRITICAL .feed-msg::before { content: "✕ "; color: var(--critical); }

/* ---------- chart ---------- */
.viz-root { position: relative; }
.viz-root svg { display: block; width: 100%; height: auto; }
.viz-tooltip {
  position: absolute; pointer-events: none; background: var(--surface-2); color: var(--ink-1);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 12px;
  transform: translate(-50%, -110%); white-space: nowrap; display: none;
}

/* ---------- buttons ---------- */
.btn {
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); cursor: pointer;
  background: var(--surface-2); color: var(--ink-1); font-size: 13px; font-weight: 600;
}
.btn:hover { filter: brightness(1.06); }
.btn.primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.btn.danger { background: var(--critical); border-color: var(--critical); color: #fff; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.gates { display: flex; flex-direction: column; gap: 6px; }
.gate { display: flex; gap: 10px; align-items: baseline; font-size: 13px; }
.gate .mark { flex: none; width: 18px; text-align: center; font-weight: 700; }
.gate.pass .mark { color: var(--good-text); }
.gate.fail .mark { color: var(--critical); }

.banner {
  border: 1px solid var(--warning); background: color-mix(in srgb, var(--warning) 12%, var(--surface-1));
  border-radius: 10px; padding: 10px 14px; font-size: 13px;
}
.banner.critical { border-color: var(--critical); background: color-mix(in srgb, var(--critical) 10%, var(--surface-1)); }

@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  nav { flex-direction: row; flex-wrap: wrap; }
  .page { padding: 14px 16px; }
  .feed-time { width: 84px; }
}
