/* tradebot dashboard. Dark-first "mission control" look.
   Data colours: the validated reference palette (dataviz skill), re-validated against the dark surface #0f1520
   (series #3987e5 / #d95926: CVD dE 26.8, contrast >= 3:1) and the light surface (#2a78d6 / #eb6834). */
:root {
  color-scheme: dark;
  --page: #070a10;
  --surface: #0f1520;
  --glass-top: rgba(22, 31, 47, 0.78);
  --glass-bot: rgba(12, 18, 28, 0.78);
  --surface-2: rgba(148, 180, 230, 0.06);
  --line: rgba(148, 180, 230, 0.13);
  --line-strong: rgba(148, 180, 230, 0.24);
  --ink: #e8eef8;
  --ink-2: #a9b4c6;
  --muted: #6f7b90;
  --grid: rgba(148, 180, 230, 0.07);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-1-fill: rgba(57, 135, 229, 0.26);
  --glow: #5ad1ff;
  --good: #0ca30c;
  --good-text: #2fc04a;
  --warning: #fab219;
  --critical: #d03b3b;
  --critical-text: #ef6b6b;
  --shadow: 0 18px 40px -22px rgba(0, 0, 0, 0.9);
  --backdrop-a: rgba(57, 135, 229, 0.20);
  --backdrop-b: rgba(217, 89, 38, 0.08);
  --gridline: rgba(148, 180, 230, 0.05);
  --radius: 16px;
  --font: "Space Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  --nav-h: 0px;
}
:root[data-theme="light"] {
  color-scheme: light;
  --page: #f3f5f9;
  --surface: #ffffff;
  --glass-top: rgba(255, 255, 255, 0.86);
  --glass-bot: rgba(250, 251, 253, 0.86);
  --surface-2: rgba(15, 30, 60, 0.04);
  --line: rgba(15, 30, 60, 0.10);
  --line-strong: rgba(15, 30, 60, 0.20);
  --ink: #0b1220;
  --ink-2: #44506a;
  --muted: #7a8599;
  --grid: rgba(15, 30, 60, 0.06);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-1-fill: rgba(42, 120, 214, 0.20);
  --glow: #2a78d6;
  --good-text: #007a00;
  --critical-text: #b42727;
  --shadow: 0 16px 36px -24px rgba(15, 30, 60, 0.35);
  --backdrop-a: rgba(42, 120, 214, 0.12);
  --backdrop-b: rgba(235, 104, 52, 0.06);
  --gridline: rgba(15, 30, 60, 0.04);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; scroll-padding-top: 76px; }
html, body { margin: 0; background: var(--page); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
body { padding: 0 16px calc(48px + var(--nav-h)); min-height: 100vh; }
main { max-width: 1440px; margin: 0 auto; position: relative; z-index: 1; }
h1, h2, h3 { margin: 0; font-weight: 600; }
a { color: var(--series-1); }
button { font: inherit; cursor: pointer; color: inherit; }
em { font-style: normal; color: var(--ink); }
.muted { color: var(--muted); }
.mono, .mono-sm { font-family: var(--mono); }
.mono-sm { font-size: 11.5px; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; font-size: 12.5px; }
.pos { color: var(--good-text); } .neg { color: var(--critical-text); }

/* background: soft glows + a faint blueprint grid */
.backdrop { position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(1100px 620px at 8% -12%, var(--backdrop-a), transparent 62%),
    radial-gradient(900px 520px at 108% 4%, var(--backdrop-b), transparent 60%);
}
.backdrop::after { content: ""; position: absolute; inset: 0;
  background-image: linear-gradient(var(--gridline) 1px, transparent 1px), linear-gradient(90deg, var(--gridline) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: radial-gradient(ellipse at 50% 0%, #000 0%, transparent 75%);
          mask-image: radial-gradient(ellipse at 50% 0%, #000 0%, transparent 75%);
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; margin: 0 -16px 18px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--page) 72%, transparent);
  -webkit-backdrop-filter: blur(16px) saturate(140%); backdrop-filter: blur(16px) saturate(140%);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { max-width: 1440px; margin: 0 auto; display: flex; align-items: center; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); flex-shrink: 0; }
.logo { width: 22px; height: 22px; border-radius: 6px; position: relative;
  background: conic-gradient(from 210deg, var(--series-1), var(--glow), var(--series-1));
  box-shadow: 0 0 18px -2px color-mix(in srgb, var(--glow) 70%, transparent);
}
.logo::after { content: ""; position: absolute; inset: 5px; border-radius: 3px; background: var(--page); }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.instance { font: 600 11px/1 var(--mono); letter-spacing: .08em; padding: 4px 7px; border-radius: 6px;
  border: 1px solid var(--line-strong); color: var(--ink-2); }
.status { display: flex; gap: 8px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.status::-webkit-scrollbar { display: none; }
.badge { display: inline-flex; align-items: center; gap: 7px; padding: 4px 11px; border-radius: 999px; white-space: nowrap;
  font: 500 12px/1.3 var(--mono); border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2); flex-shrink: 0; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.badge.good .dot { background: var(--good-text); box-shadow: 0 0 8px var(--good-text); }
.badge.warn .dot { background: var(--warning); box-shadow: 0 0 8px var(--warning); }
.badge.bad .dot { background: var(--critical-text); box-shadow: 0 0 8px var(--critical-text); }
.badge.live { border-color: var(--critical); color: var(--critical-text); }
.badge.live .dot, #ws-badge.good .dot { animation: pulse 2s ease-in-out infinite; }

.menu-wrap { position: relative; flex-shrink: 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
  border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--ink);
  padding: 8px 14px; border-radius: 10px; font-weight: 600; font-size: 13px; min-height: 38px; transition: background .15s, border-color .15s; }
.btn:hover { background: color-mix(in srgb, var(--series-1) 14%, transparent); border-color: color-mix(in srgb, var(--series-1) 50%, transparent); }
.btn.danger { color: var(--critical-text); border-color: color-mix(in srgb, var(--critical) 60%, transparent); }
.btn.danger:hover { background: color-mix(in srgb, var(--critical) 16%, transparent); }
.btn.ghost { background: transparent; border-color: transparent; justify-content: flex-start; color: var(--ink-2); }
.btn[disabled] { opacity: .4; cursor: default; pointer-events: none; }
.burger { width: 14px; height: 10px; position: relative; border-top: 2px solid currentColor; border-bottom: 2px solid currentColor; }
.burger::after { content: ""; position: absolute; left: 0; right: 0; top: 2px; border-top: 2px solid currentColor; }
.menu { position: absolute; right: 0; top: calc(100% + 10px); width: min(320px, calc(100vw - 32px)); padding: 14px;
  border-radius: 14px; border: 1px solid var(--line-strong); background: var(--surface); box-shadow: var(--shadow), 0 0 0 1px var(--line);
  display: grid; gap: 10px; z-index: 30; }
.menu-title { font: 600 11px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.menu-row { display: grid; gap: 8px; }
.menu-note { margin: 0; font-size: 12px; color: var(--muted); }
.menu-sep { height: 1px; background: var(--line); }
.confirm { display: grid; gap: 8px; }
.confirm span { font-size: 13px; color: var(--critical-text); font-weight: 600; }

/* ---------- layout ---------- */
.grid { display: grid; gap: 18px; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.card {
  position: relative; min-width: 0; padding: 18px; border-radius: var(--radius);
  background: linear-gradient(180deg, var(--glass-top), var(--glass-bot));
  border: 1px solid var(--line); box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.card::before { /* hairline highlight along the top edge */
  content: ""; position: absolute; left: 18px; right: 18px; top: -1px; height: 1px; border-radius: 1px;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--glow) 55%, transparent), transparent); opacity: .55;
}
.card > header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card h2 { display: flex; align-items: center; gap: 8px; font: 600 11.5px/1.2 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--ink-2); }
.card h2::before { content: ""; width: 3px; height: 12px; border-radius: 2px; background: var(--series-1); box-shadow: 0 0 10px var(--series-1); }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-7 { grid-column: span 7; }
.span-6 { grid-column: span 6; } .span-5 { grid-column: span 5; } .span-4 { grid-column: span 4; }
@media (max-width: 1080px) { .span-8, .span-7, .span-6, .span-5, .span-4 { grid-column: span 12; } }
.fine { font-size: 12px; color: var(--muted); margin: 12px 0 0; }
.fine.top { margin: -6px 0 12px; }
.empty { color: var(--muted); font-size: 13px; padding: 14px 0; }

/* ---------- hero ---------- */
.hero { display: grid; grid-template-columns: minmax(260px, auto) 1fr; gap: 22px 40px; align-items: end; }
.eyebrow { font: 500 11.5px/1.2 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.hero-figure { font: 600 clamp(40px, 6vw, 60px)/1 var(--mono); letter-spacing: -0.03em; font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, var(--ink), color-mix(in srgb, var(--ink) 70%, var(--glow)));
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero-unit { font-size: .38em; margin-left: 10px; letter-spacing: .04em; color: var(--muted); -webkit-text-fill-color: var(--muted); }
.delta { display: inline-flex; gap: 6px; align-items: center; margin-top: 10px; padding: 4px 10px; border-radius: 8px;
  font: 600 13px/1.3 var(--mono); background: var(--surface-2); }
.delta:empty { display: none; }
.delta.up { color: var(--good-text); } .delta.down { color: var(--critical-text); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.tile { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); min-width: 0; }
.tile .label { font: 500 10.5px/1.2 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.tile .value { font: 600 19px/1.3 var(--mono); margin-top: 6px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .value small { font-size: 12px; color: var(--muted); font-weight: 500; }
.meter { height: 4px; border-radius: 4px; background: var(--grid); margin-top: 9px; overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 4px; background: var(--series-1); transition: width .6s ease; }
.meter.warn > span { background: var(--warning); } .meter.bad > span { background: var(--critical); }
.tile-sub { font-size: 11px; color: var(--muted); margin-top: 6px; }

/* ---------- equity chart ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12px; color: var(--ink-2); margin: -4px 0 8px; min-height: 20px; }
.legend .item { display: inline-flex; align-items: center; gap: 7px; }
.legend .key { width: 14px; height: 3px; border-radius: 2px; }
.legend .key.dash { background: none !important; border-top: 3px dashed var(--series-2); height: 0; }
.legend strong { font: 600 12.5px/1 var(--mono); color: var(--ink); font-variant-numeric: tabular-nums; }
.legend .when { color: var(--muted); font-family: var(--mono); font-size: 11.5px; }
.chart-box { position: relative; height: 320px; width: 100%; touch-action: pan-y; }
.chart-box .empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 20px; }
.chart-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; font-size: 11.5px; }
.linkbtn { background: none; border: 0; color: var(--series-1); padding: 4px 0; font-size: 12px; font-weight: 600; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; padding: 3px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--line); }
.chip { border: 0; background: transparent; border-radius: 8px; padding: 5px 11px; font: 500 12px/1.2 var(--mono); color: var(--ink-2); min-height: 30px; }
.chip:hover { color: var(--ink); }
.chip[aria-pressed="true"] { background: color-mix(in srgb, var(--series-1) 22%, transparent); color: var(--ink);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--series-1) 55%, transparent); }

/* ---------- funnel (HTML bars: every number visible, no hover needed) ---------- */
.funnel { display: grid; gap: 9px; }
.f-row { display: grid; grid-template-columns: 62px 1fr 52px 40px; gap: 10px; align-items: center; }
.f-name { font: 500 12px/1 var(--mono); color: var(--ink-2); }
.f-track { height: 14px; border-radius: 0 4px 4px 0; background: var(--grid); position: relative; overflow: hidden; }
.f-bar { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 4px 4px 0; background: var(--series-1);
  box-shadow: 0 0 14px -2px var(--series-1); transition: width .6s ease; }
.f-val { font: 600 12.5px/1 var(--mono); text-align: right; font-variant-numeric: tabular-nums; }
.f-rate { font: 500 11px/1 var(--mono); color: var(--muted); text-align: right; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font: 500 10.5px/1.2 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
  padding: 8px 10px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
th.num { text-align: right; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr { transition: background .15s; }
tbody tr:hover { background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 6px; font: 600 10.5px/1.5 var(--mono); letter-spacing: .04em;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.pill.proven { color: var(--good-text); border-color: color-mix(in srgb, var(--good-text) 45%, transparent); }
.pill.failing { color: var(--critical-text); border-color: color-mix(in srgb, var(--critical-text) 45%, transparent); }
.pill.champion, .pill.candidate { color: var(--series-1); border-color: color-mix(in srgb, var(--series-1) 45%, transparent); }
.sym { font-weight: 600; }

/* ---------- decision feed ---------- */
.feed { display: flex; flex-direction: column; gap: 8px; max-height: 760px; overflow-y: auto; padding-right: 2px; overscroll-behavior: contain; }
.feed .more { justify-content: center; color: var(--series-1); }
.decision { border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); transition: border-color .2s; }
.decision[open] { border-color: var(--line-strong); }
.decision.executed { border-color: color-mix(in srgb, var(--good-text) 50%, transparent); box-shadow: 0 0 22px -12px var(--good-text); }
.decision.fresh { animation: slidein .45s ease-out; }
.decision summary { list-style: none; cursor: pointer; padding: 11px 13px; display: grid; gap: 8px; }
.decision summary::-webkit-details-marker { display: none; }
.d-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.d-head .sym { font-size: 14px; }
.d-what { color: var(--ink-2); font-size: 12.5px; }
.d-time { margin-left: auto; color: var(--muted); font: 500 11px/1 var(--mono); }
.pipe { display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; }
.pipe .seg { height: 4px; border-radius: 2px; background: var(--grid); }
.pipe .seg.ok { background: var(--series-1); }
.pipe .seg.fail { background: var(--critical-text); }
.decision.executed .pipe .seg.ok { background: var(--good-text); }
.d-why { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.decision[open] .d-why { display: none; }
.stages { list-style: none; margin: 0; padding: 0 13px 12px; display: grid; gap: 4px; }
.stages li { display: grid; grid-template-columns: 16px 58px 1fr; gap: 8px; font-size: 12.5px; align-items: baseline; }
.stages .icon { font-weight: 700; text-align: center; }
.stages .ok .icon { color: var(--good-text); }
.stages .fail .icon { color: var(--critical-text); }
.stages .name { color: var(--muted); font: 500 11.5px/1.4 var(--mono); }

/* ---------- journal ---------- */
.journal { display: flex; flex-direction: column; gap: 8px; max-height: 460px; overflow-y: auto; }
.journal details { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; background: var(--surface-2); }
.journal summary { cursor: pointer; font-weight: 600; }
.journal summary .when { font: 500 11.5px/1 var(--mono); color: var(--muted); margin-right: 8px; }
.journal pre { white-space: pre-wrap; font: 12px/1.6 var(--mono); margin: 10px 0 0; color: var(--ink-2); }

/* ---------- jev ---------- */
.verdict { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); margin: 12px 0 10px; font-size: 13px; }
.verdict strong { font: 600 11px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); display: block; margin-bottom: 4px; }
.stat-line { font-size: 12px; color: var(--muted); margin: 0 0 10px; }

.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good-text); box-shadow: 0 0 8px var(--good-text); animation: pulse 2s ease-in-out infinite; }
.stale { opacity: .55; transition: opacity .2s; }
.flash { animation: flash .9s ease-out; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes slidein { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@keyframes flash { from { text-shadow: 0 0 18px var(--glow); } to { text-shadow: none; } }

/* ---------- bottom nav (phones only) ---------- */
.bottomnav { display: none; }
@media (max-width: 760px) {
  :root { --nav-h: 64px; }
  html { scroll-padding-top: 120px; }
  .grid { gap: 14px; }
  .card { padding: 15px; border-radius: 14px; }
  .topbar-inner { flex-wrap: wrap; gap: 10px; }
  .status { order: 3; flex-basis: 100%; }
  .menu-wrap { margin-left: auto; }
  .menu-label { display: none; }
  .icon-btn { width: 40px; padding: 0; }
  .hero { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-box { height: 260px; }
  .feed { max-height: none; }
  .bottomnav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; z-index: 20; left: 0; right: 0; bottom: 0;
    padding: 6px 8px calc(env(safe-area-inset-bottom, 0px) + 6px);
    background: color-mix(in srgb, var(--page) 80%, transparent); border-top: 1px solid var(--line);
    -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
  .bottomnav a { display: grid; justify-items: center; gap: 4px; padding: 6px 0; text-decoration: none; color: var(--muted);
    font: 500 10.5px/1 var(--mono); border-radius: 10px; }
  .bottomnav a.active { color: var(--ink); background: var(--surface-2); }
  .bottomnav a.active .ni { background: var(--series-1); box-shadow: 0 0 10px var(--series-1); }
  .ni { width: 18px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: 4px 0; }

  /* tables become stacked cards: each cell shows its column name */
  table.stack thead { display: none; }
  table.stack, table.stack tbody { display: block; }
  table.stack tr { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  table.stack tr:last-child { border-bottom: 0; }
  table.stack tbody tr:hover { background: none; }
  table.stack td { display: block; padding: 0; border: 0; text-align: left; min-width: 0; overflow-wrap: anywhere; }
  table.stack td::before { content: attr(data-label); display: block; font: 500 10px/1.4 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
  table.stack td:first-child { grid-column: 1 / -1; font-size: 15px; }
  table.stack td:first-child::before { display: none; }
  table.stack td.num { text-align: left; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 0; position: relative; z-index: 1; }
.login { width: min(380px, 100%); padding: 28px; }
.login h1 { display: flex; align-items: center; gap: 10px; font-size: 20px; margin-bottom: 6px; }
.login p { margin: 0 0 18px; }
.login label { font: 500 11px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.login input { width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--surface-2);
  color: var(--ink); font: 15px var(--mono); margin: 8px 0 16px; outline: none; }
.login input:focus { border-color: var(--series-1); box-shadow: 0 0 0 3px color-mix(in srgb, var(--series-1) 25%, transparent); }
.login .btn { width: 100%; background: var(--series-1); border-color: var(--series-1); color: #fff; }
