/* Norn dashboard. Tokens match the site's "Signal Spectrum" system (DESIGN.md). */
@font-face { font-family: "Plus Jakarta Sans"; src: url("fonts/plus-jakarta-var.woff2") format("woff2"); font-weight: 400 800; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("fonts/jetbrains-mono-var.woff2") format("woff2"); font-weight: 400 700; font-display: swap; }

:root {
  --bg: #0B0D14; --surface: #121725; --surface-2: #18202F; --surface-3: #222B3D;
  --text: #F3E9D2; --muted: #B9B3C4; --control: #6E6A7C; --hair: rgba(243,233,210,.12);
  --model: #FF5D6C; --on-model: #0B0D14; --market: #7CB7FF; --up: #39D98A; --down: #FF6B5A; --ref: #F0643C; --lilac: #B9A2FF;
  --model-a: rgba(255,93,108,.14); --up-a: rgba(57,217,138,.14); --down-a: rgba(255,107,90,.14); --market-a: rgba(124,183,255,.14); --ref-a: rgba(240,100,60,.14);
  --cream: #F3E9D2;
  --sans: "Plus Jakarta Sans", system-ui, sans-serif; --mono: "JetBrains Mono", ui-monospace, monospace;
  --ease: cubic-bezier(.2,.7,.2,1);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #F7F3EA; --surface: #FFFFFF; --surface-2: #F1EBDD; --surface-3: #E6DECC;
  --text: #14161F; --muted: #5B5668; --control: #8A8496; --hair: #E2D9C6;
  --model: #B3243A; --on-model: #FFFFFF; --market: #1D63C4; --up: #00754F; --down: #B3330F; --ref: #9A4A00; --lilac: #6440D0;
  --model-a: rgba(179,36,58,.10); --up-a: rgba(0,117,79,.10); --down-a: rgba(179,51,15,.10); --market-a: rgba(29,99,196,.10); --ref-a: rgba(154,74,0,.10);
  color-scheme: light;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
.num, .mono, td.n, code { font-family: var(--mono); font-variant-numeric: tabular-nums; }
a { color: inherit; }
button, a[href], summary, label[for], select, input[type=checkbox], input[type=radio] { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
:focus-visible { outline: 2px solid var(--model); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.up { color: var(--up); } .down { color: var(--down); } .model { color: var(--model); } .market { color: var(--market); } .ref { color: var(--ref); } .muted { color: var(--muted); }
.ph, .ph-fill { font-size: 18px; line-height: 1; vertical-align: -3px; }

/* Shell */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); grid-template-rows: 56px minmax(0, 1fr); height: 100vh; }
.top { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 16px; border-bottom: 1px solid var(--hair); background: var(--surface); position: relative; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: -0.03em; min-width: 200px; text-decoration: none; }
.brand svg { width: 26px; height: 26px; }
.badge { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 4px; font: 600 12px var(--mono); letter-spacing: .04em; }
.badge.paper { background: var(--market-a); color: var(--market); }
.badge.live { background: var(--down-a); color: var(--down); }
.status { display: inline-flex; align-items: center; gap: 8px; font: 500 13px var(--mono); color: var(--muted); }
.status i.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--up); }
.status[data-s="paused"] i.dot, .status[data-s="halted"] i.dot { background: var(--ref); }
.status[data-s="degraded"] i.dot, .status[data-s="offline"] i.dot { background: var(--down); }
.top .spacer { flex: 1; }
.tick { display: flex; gap: 18px; font: 500 13px var(--mono); color: var(--muted); }
.tick b { color: var(--text); font-weight: 600; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--control); background: transparent; color: var(--text); font: 600 13px var(--sans); transition: background-color 120ms var(--ease); text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--cream, var(--text)); border-color: transparent; color: #0B0D14; }
:root[data-theme="light"] .btn.primary { background: var(--text); color: var(--bg); }
.btn.primary:hover { background: color-mix(in srgb, var(--model) 85%, var(--text)); }
.btn.danger { border-color: var(--down); color: var(--down); }
.btn.danger:hover { background: var(--down-a); }
.btn.icon { width: 36px; padding: 0; }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: 12px; }

.side { border-right: 1px solid var(--hair); background: var(--surface); overflow-y: auto; padding: 12px 10px 24px; }
.side h4 { margin: 16px 10px 6px; font: 500 11px var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.side a { display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 0 10px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 500; position: relative; }
.side a:hover { background: var(--surface-2); color: var(--text); }
.side a[aria-current="page"] { background: var(--model-a); color: var(--text); }
.side a[aria-current="page"] .ph { color: var(--model); }
.side a .count { margin-left: auto; font: 500 11px var(--mono); color: var(--muted); }
.side .foot { margin: 20px 10px 0; font: 500 11px var(--mono); color: var(--muted); display: grid; gap: 4px; }

.main { overflow-y: auto; padding: 24px 28px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 26px; font-weight: 600; letter-spacing: -0.02em; }
.page-head p { margin: 4px 0 0; color: var(--muted); max-width: 70ch; }
.banner { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; border: 1px solid; }
.banner.halt { border-color: var(--ref); background: var(--ref-a); }
.banner.err { border-color: var(--down); background: var(--down-a); }
.banner.info { border-color: var(--market); background: var(--market-a); }
.banner .grow { flex: 1; }

.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.c3 { grid-column: span 3; } .c4 { grid-column: span 4; } .c5 { grid-column: span 5; } .c6 { grid-column: span 6; } .c7 { grid-column: span 7; } .c8 { grid-column: span 8; } .c12 { grid-column: 1 / -1; }
.card { background: var(--surface); border: 1px solid var(--hair); border-radius: 16px; padding: 16px; min-width: 0; }
.card > header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card h2 { margin: 0; font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card h2 .ph { color: var(--muted); }
.card .sub { color: var(--muted); font-size: 12.5px; }

.kpis { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 1px; background: var(--hair); border: 1px solid var(--hair); border-radius: 12px; overflow: hidden; margin-bottom: 16px; }
.kpi { background: var(--surface); padding: 12px 14px; display: grid; gap: 2px; min-width: 0; }
.kpi .l { font: 500 11px var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .v { font: 600 20px var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi .d { font: 500 11.5px var(--mono); color: var(--muted); }

table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
.t th { text-align: left; font: 500 11px var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--control); position: sticky; top: 0; background: var(--surface); white-space: nowrap; }
.t td { padding: 9px 10px; border-bottom: 1px solid var(--hair); vertical-align: middle; }
.t td.n, .t th.n { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.t tbody tr { transition: background-color 120ms var(--ease); }
.t tbody tr.click:hover { background: var(--surface-2); }
.t tbody tr.click { cursor: pointer; }
.tablewrap { overflow: auto; max-height: 560px; border-radius: 8px; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 4px; font: 600 11.5px var(--mono); background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.up { background: var(--up-a); color: var(--up); } .pill.down { background: var(--down-a); color: var(--down); } .pill.model { background: var(--model-a); color: var(--model); } .pill.ref { background: var(--ref-a); color: var(--ref); } .pill.market { background: var(--market-a); color: var(--market); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--control); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; color: var(--muted); min-height: 32px; padding: 0 12px; font: 500 12.5px var(--sans); border-right: 1px solid var(--control); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.seg button:hover:not([aria-pressed="true"]) { background: var(--surface-2); color: var(--text); }

/* Live window */
.win { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; }
.chartbox { height: 280px; position: relative; }
.ring { width: 64px; height: 64px; }
.ring circle { fill: none; stroke-width: 6; }
.ring .bg { stroke: var(--surface-3); }
.ring .fg { stroke: var(--ref); stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dashoffset 250ms linear; }
.wtop { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; }
.wtop .big { font: 600 26px var(--mono); letter-spacing: -0.02em; }
.prob { display: grid; grid-template-columns: 120px minmax(0, 1fr) 58px; gap: 10px; align-items: center; font: 500 12.5px var(--mono); margin: 6px 0; }
.prob .bar { height: 10px; border-radius: 5px; background: var(--surface-3); position: relative; overflow: hidden; }
.prob .bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 5px; transition: width 300ms var(--ease); }
.prob .bar::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--control); }
.math { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font: 500 13px var(--mono); }
.math dt { color: var(--muted); font-family: var(--sans); }
.math dd { margin: 0; text-align: right; }
.math .total { border-top: 1px solid var(--control); padding-top: 6px; font-weight: 700; }
.verdict { margin-top: 12px; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); display: flex; gap: 10px; align-items: flex-start; }
.verdict .ph-fill { font-size: 20px; }
.book { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.book .side-b { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; display: grid; gap: 4px; font: 500 12.5px var(--mono); }

/* Meters */
.meter { display: grid; gap: 6px; }
.meter .track { height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.meter .track i { display: block; height: 100%; border-radius: 4px; background: var(--up); transition: width 300ms var(--ease); }
.meter .track i.warn { background: var(--ref); } .meter .track i.bad { background: var(--down); }
.meter .row { display: flex; justify-content: space-between; font: 500 12.5px var(--mono); }

/* Forms */
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.field { display: grid; gap: 6px; }
.field label, .field .lbl { font-weight: 600; font-size: 13px; }
.field .hint { color: var(--muted); font-size: 12px; }
.inp { display: flex; align-items: stretch; border: 1px solid var(--control); border-radius: 6px; background: var(--surface-2); }
.inp:focus-within { outline: 2px solid var(--model); outline-offset: 2px; }
.inp input, .inp select { flex: 1; min-width: 0; min-height: 38px; border: 0; background: transparent; color: var(--text); font: 600 14px var(--mono); padding: 0 10px; }
.inp input:focus, .inp select:focus { outline: none; }
.inp span { display: inline-flex; align-items: center; padding: 0 10px; color: var(--muted); font: 500 12px var(--mono); }
.field[data-invalid] .inp { border-color: var(--down); }
.field .err { color: var(--down); font-size: 12px; font-weight: 600; }
.switch { display: flex; align-items: center; gap: 10px; min-height: 36px; }
.switch input { appearance: none; width: 38px; height: 22px; border-radius: 11px; background: var(--surface-3); border: 1px solid var(--control); position: relative; transition: background-color 150ms var(--ease); flex: none; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--text); transition: transform 150ms var(--ease); }
.switch input:checked { background: var(--model); border-color: var(--model); }
.switch input:checked::after { transform: translateX(16px); background: var(--on-model); }
.formbar { display: flex; gap: 8px; align-items: center; margin-top: 16px; }

/* Drawer and dialog */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); background: var(--surface); border-left: 1px solid var(--hair); z-index: 41; overflow-y: auto; padding: 20px; }
.drawer header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.drawer h3 { margin: 0; font-size: 17px; }
dialog { border: 1px solid var(--hair); border-radius: 14px; background: var(--surface); color: var(--text); padding: 22px; max-width: 460px; width: calc(100vw - 32px); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h3 { margin: 0 0 8px; font-size: 18px; }
dialog p { color: var(--muted); margin: 0 0 16px; }
dialog .row { display: flex; gap: 8px; justify-content: flex-end; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; font: 500 13px var(--mono); }
.kv dt { color: var(--muted); font-family: var(--sans); }
.kv dd { margin: 0; text-align: right; }
.toast { position: fixed; bottom: 18px; right: 18px; z-index: 60; padding: 12px 16px; border-radius: 10px; background: var(--text); color: var(--bg); font-weight: 600; box-shadow: 0 6px 24px rgba(0,0,0,.3); }

.empty, .loading, .error-state { padding: 28px 12px; text-align: center; color: var(--muted); display: grid; gap: 8px; justify-items: center; }
.empty .ph, .error-state .ph { font-size: 28px; }
.skel { height: 14px; border-radius: 4px; background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s linear infinite; }
@keyframes sk { to { background-position: -200% 0; } }

.uplot { font-family: var(--mono) !important; }
.u-legend { font-size: 12px !important; color: var(--muted); }
.u-legend .u-marker { border-radius: 2px; }

.menu-toggle { display: none; }
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .c3, .c4, .c5 { grid-column: span 6; } .c7, .c8 { grid-column: 1 / -1; } .c6 { grid-column: span 6; }
  .win { grid-template-columns: 1fr; }
  .tick { display: none; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .menu-toggle { display: inline-flex; }
  .side { position: fixed; top: 56px; left: 0; bottom: 0; width: 260px; z-index: 30; transform: translateX(-100%); transition: transform 180ms var(--ease); }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.5); }
  .main { padding: 16px 14px 48px; }
  .c3, .c4, .c5, .c6 { grid-column: 1 / -1; }
  .form { grid-template-columns: 1fr; }
  .brand { min-width: 0; }
  .brand span.word { display: none; }
  .top .hide-sm { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* the later media-query-free .brand rule was re-inflating the bar and pushing the page to 499px */
  .banner .grow { min-width: 0; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* ===== "Norns at Dusk" layer: makes the app speak the homepage's language ===== */
:root { --line: rgba(243,233,210,.12); --line-2: rgba(243,233,210,.24); }
:root[data-theme="light"] { --line: #E2D9C6; --line-2: #CFC4AE; }
body { font-size: 15px; }

/* Top bar: the one glass surface, like the homepage header */
.top { height: 64px; background: rgba(11,13,20,.62); backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2); border-bottom: 1px solid var(--line); color: #F3E9D2; }
:root[data-theme="light"] .top { background: rgba(247,243,234,.72); color: var(--text); }
.app { grid-template-rows: 64px minmax(0, 1fr); }
.brand { font-weight: 800; font-size: 21px; letter-spacing: -0.04em; }
.brand svg { width: 28px; height: 28px; flex: none; }
.badge { border-radius: 999px; height: 28px; padding: 0 12px; }
.tick { font-size: 13px; }

/* Sidebar: night ink, pill items */
.side { background: var(--bg); border-right: 1px solid var(--line); padding: 16px 12px 24px; }
.side h4 { color: var(--model); letter-spacing: .1em; margin: 20px 12px 8px; }
.side a { border-radius: 999px; min-height: 40px; padding: 0 14px; font-weight: 600; }
.side a:hover { background: rgba(243,233,210,.06); }
:root[data-theme="light"] .side a:hover { background: var(--surface-2); }
.side a[aria-current="page"] { background: rgba(243,233,210,.1); color: var(--text); }
:root[data-theme="light"] .side a[aria-current="page"] { background: var(--surface-3); }
.side a[aria-current="page"] .ph { color: var(--model); }

/* Page hero: painted art banner with the homepage's headline voice */
.main { padding: 24px 32px 72px; }
.page-hero { position: relative; isolation: isolate; overflow: hidden; border-radius: 22px; min-height: 210px; margin-bottom: 18px;
  display: flex; align-items: flex-end; padding: 30px 32px; color: #F3E9D2; border: 1px solid rgba(243,233,210,.14); }
.page-hero::before { content: ""; position: absolute; inset: 0; z-index: -2; background: var(--art) center 40% / cover no-repeat; transform: scale(1.02); }
.page-hero::after { content: ""; position: absolute; inset: 0; z-index: -1;
  background: linear-gradient(90deg, rgba(11,13,20,.9) 0%, rgba(11,13,20,.66) 45%, rgba(11,13,20,.2) 100%), linear-gradient(0deg, rgba(11,13,20,.55), transparent 60%); }
.page-hero .kick { font: 600 12.5px var(--mono); color: #FF5D6C; display: inline-flex; gap: 8px; align-items: center; }
.page-hero h1 { margin: 8px 0 0; font-size: clamp(2rem, 3.4vw, 3.1rem); font-weight: 700; letter-spacing: -0.04em; line-height: 1; }
.page-hero p { margin: 10px 0 0; color: #D9D2C3; max-width: 60ch; font-size: 15.5px; }
.page-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: flex-end; margin: -4px 0 16px; }
.page-tools:empty { display: none; }

/* Cards, KPIs, banners: the homepage's rounded solid cards */
.card { border-radius: 20px; border-color: var(--line); padding: 20px; }
.card h2 { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.kpis { border-radius: 20px; border-color: var(--line); background: var(--line); }
.kpi { padding: 16px 18px; }
.kpi .v { font-size: 23px; letter-spacing: -0.02em; }
.banner { border-radius: 16px; }
.pill { border-radius: 999px; padding: 2px 10px; }
.seg { border-radius: 999px; padding: 3px; gap: 3px; border-color: var(--line-2); }
.seg button { border-radius: 999px; border-right: 0; min-height: 32px; padding: 0 14px; }
.inp { border-radius: 12px; }
.drawer { border-radius: 22px 0 0 22px; }
dialog { border-radius: 22px; }
.verdict { border-radius: 14px; }
.book .side-b { border-radius: 14px; }
.btn.primary { background: #F3E9D2; color: #0B0D14; }
.btn.primary:hover { background: #FFF6E2; }
:root[data-theme="light"] .btn.primary { background: #14161F; color: #F7F3EA; }
.toast { border-radius: 999px; }

@media (max-width: 860px) {
  .main { padding: 14px 12px 48px; }
  .page-hero { min-height: 170px; padding: 22px 20px; border-radius: 18px; }
  .side { top: 64px; }
}
.brand { font-size: 22px; gap: 11px; color: var(--text); }
.brand svg { width: 34px; height: 34px; }
.brand svg { --logo-thread: var(--text); --logo-gap: var(--bg); width: 36px; height: 36px; }

@media (max-width: 860px) {
  /* a 1fr track is minmax(auto,1fr); the top bar's min-content was widening the whole page */
  .app { grid-template-columns: minmax(0, 1fr); }
  .brand { min-width: 0; }
  .top { gap: 8px; padding: 0 10px; overflow-x: auto; scrollbar-width: none; }
  .top::-webkit-scrollbar { display: none; }
  /* keep the status dot + word from wrapping over the badge once the bar is narrow */
  .top { flex-wrap: nowrap; }
  .brand, .status, .badge, .btn { flex: 0 0 auto; }
  .status { white-space: nowrap; }
  /* the paper/live word only needs to show on wide screens; the badge and dot keep the state */
  #status-text { display: none; }
  #btn-stop { order: 9; }
  #btn-theme { display: none; }
  .top { padding-right: 6px; }
  .main { overflow-x: hidden; }
  .main, .banner, #view { min-width: 0; }
}
