:root {
  --bg: #070b14;
  --bg-2: #0b1220;
  --panel: #0f1828;
  --panel-2: #131e31;
  --line: #1e2a40;
  --line-2: #273650;
  --fg: #e6ebf5;
  --fg-2: #a7b2c7;
  --muted: #6f7d96;
  --accent: #4cc9f0;
  --accent-2: #f8961e;
  --up: #22c55e;
  --down: #f43f5e;
  --warn: #f59e0b;
  --up-bg: rgba(34, 197, 94, .12);
  --down-bg: rgba(244, 63, 94, .12);
  --warn-bg: rgba(245, 158, 11, .12);
  --radius: 10px;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 8px 24px rgba(0,0,0,.25);
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color-scheme: dark;
}
:root[data-theme='light'] {
  --bg: #f3f5f9;
  --bg-2: #ffffff;
  --panel: #ffffff;
  --panel-2: #f6f8fb;
  --line: #e3e8f0;
  --line-2: #d3dae6;
  --fg: #0f172a;
  --fg-2: #334155;
  --muted: #64748b;
  --accent: #0284c7;
  --up: #16a34a;
  --down: #e11d48;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.05);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--sans); font-size: 14px; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }
svg { flex: none; }
button, select, input { font: inherit; color: inherit; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 20px; background: color-mix(in srgb, var(--bg-2) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand svg { width: 30px; height: 30px; }
.brand-bg { fill: var(--panel-2); stroke: var(--line-2); }
.brand-line { stroke: var(--accent); stroke-width: 3; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line-2); font-size: 12px; color: var(--fg-2); white-space: nowrap; }
.pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.pill.open::before { background: var(--up); box-shadow: 0 0 0 3px var(--up-bg); }
.pill.closed::before { background: var(--down); }
.pill.ext::before { background: var(--warn); }
.pill-demo { border-color: var(--warn); color: var(--warn); }
.pill-demo::before { background: var(--warn); }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--panel); cursor: pointer; font-size: 13px; }
.btn:hover { border-color: var(--accent); }
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-icon { padding: 6px; }
.btn.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--fg-2); cursor: pointer; }
.switch input { accent-color: var(--accent); }

/* Ticker tape */
.tape { display: flex; gap: 0; overflow-x: auto; border-bottom: 1px solid var(--line); background: var(--bg-2); scrollbar-width: none; }
.tape::-webkit-scrollbar { display: none; }
.tape-item { display: flex; align-items: baseline; gap: 8px; padding: 8px 16px; border-right: 1px solid var(--line); white-space: nowrap; cursor: pointer; }
.tape-item:hover { background: var(--panel); }
.tape-item .sym { font-weight: 600; font-size: 12px; color: var(--fg-2); }
.tape-item .px { font-family: var(--mono); font-size: 13px; }
.tape-item .ch { font-family: var(--mono); font-size: 12px; }

/* Layout */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 100px); }
.sidenav { position: sticky; top: 92px; align-self: start; display: flex; flex-direction: column; gap: 2px; padding: 16px 10px; height: calc(100vh - 92px); overflow-y: auto; border-right: 1px solid var(--line); }
.sidenav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--fg-2); text-decoration: none; font-weight: 500; }
.sidenav a svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; opacity: .8; }
.sidenav a:hover { background: var(--panel); color: var(--fg); }
.sidenav a.on { background: var(--panel-2); color: var(--fg); box-shadow: inset 2px 0 0 var(--accent); }
main { padding: 22px 26px 40px; min-width: 0; display: flex; flex-direction: column; gap: 18px; }
.tab[hidden] { display: none; }
.tab { display: flex; flex-direction: column; gap: 16px; animation: fade .25s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .tab { animation: none; } }
.section-head { display: flex; flex-direction: column; gap: 4px; }
.section-head p { margin: 0; max-width: 72ch; }

/* Cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-head.spaced { margin-top: 6px; }
.card-head select { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 6px; padding: 4px 8px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 16px; }
.grid-overview { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.tiles-sm { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.tile { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 10px; cursor: pointer; transition: border-color .15s, transform .15s; overflow: hidden; display: flex; flex-direction: column; gap: 4px; min-height: 108px; }
.tile:hover { border-color: var(--line-2); transform: translateY(-1px); }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.tile-name { font-size: 12px; color: var(--fg-2); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-sym { font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.tile-val { font-family: var(--mono); font-size: 21px; font-weight: 500; letter-spacing: -.02em; }
.tile-chg { font-family: var(--mono); font-size: 12px; display: flex; gap: 8px; }
.tile .spark { width: 100%; height: 30px; margin-top: auto; }
.tile-note { font-size: 11px; color: var(--muted); line-height: 1.35; }
.tile.err .tile-val { color: var(--muted); font-size: 14px; }
.tile.loading .tile-val, .tile.loading .tile-chg { background: var(--panel-2); color: transparent; border-radius: 4px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }
.badge { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge.up { background: var(--up-bg); }
.badge.down { background: var(--down-bg); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.flat { background: var(--panel-2); }

/* Regime */
.regime { gap: 14px; }
.regime-top { display: flex; align-items: center; gap: 18px; }
.gauge { width: 120px; height: 72px; }
.gauge .track { stroke: var(--line-2); }
.regime-label { font-size: 22px; font-weight: 700; }
.regime-sub { color: var(--muted); font-size: 12px; }
.signals { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px 14px; margin: 0; padding: 0; list-style: none; }
.signals li { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; padding: 6px 0; border-top: 1px solid var(--line); }
.signals .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex: none; }
.signals .dot.ok { background: var(--up); }
.signals .dot.bad { background: var(--down); }
.signals .dot.na { background: var(--muted); }
.signals .sig-val { margin-left: auto; font-family: var(--mono); color: var(--fg-2); white-space: nowrap; }

/* Events */
.events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.events li { display: grid; grid-template-columns: 74px 1fr auto; gap: 10px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); font-size: 13px; }
.events li:first-child { border-top: 0; }
.ev-date { font-family: var(--mono); font-size: 12px; color: var(--fg-2); }
.ev-when { font-size: 11px; color: var(--muted); }

/* Charts */
.chart { position: relative; }
.chart-empty { height: 200px; display: grid; place-items: center; color: var(--muted); font-size: 12px; border: 1px dashed var(--line-2); border-radius: 8px; }
.linechart .grid { stroke: var(--line); stroke-width: 1; }
.linechart .refline, .rrg .refline { stroke: var(--muted); stroke-dasharray: 4 4; stroke-width: 1; }
.axis-label { fill: var(--muted); font-size: 11px; font-family: var(--mono); }
.ref-label { fill: var(--fg-2); }
.crosshair { stroke: var(--line-2); stroke-width: 1; }
.tip { position: absolute; z-index: 5; pointer-events: none; background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 10px; font-size: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.35); min-width: 140px; }
.tip-head { color: var(--muted); margin-bottom: 3px; }
.tip-row { display: flex; align-items: center; gap: 6px; }
.tip-row i { width: 8px; height: 8px; border-radius: 2px; }
.tip-row b { margin-left: auto; font-family: var(--mono); font-weight: 500; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--fg-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 3px; border-radius: 2px; }
.rrg .q-lead { fill: var(--up); opacity: .06; }
.rrg .q-weak { fill: var(--warn); opacity: .06; }
.rrg .q-lag { fill: var(--down); opacity: .06; }
.rrg .q-imp { fill: var(--accent); opacity: .06; }
.quad-label { fill: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.rrg-label { fill: var(--fg); font-size: 11px; font-weight: 600; font-family: var(--mono); }

/* Stats */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.stat { background: var(--panel-2); border-radius: 8px; padding: 10px 12px; }
.stat-label { font-size: 11.5px; color: var(--muted); }
.stat-val { font-family: var(--mono); font-size: 20px; margin-top: 2px; }
.meter { height: 6px; border-radius: 3px; background: var(--line); margin-top: 8px; overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }

/* Tables */
.table-wrap { overflow: auto; max-height: 640px; }
.table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table th { position: sticky; top: 0; background: var(--panel); text-align: left; font-weight: 500; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line-2); white-space: nowrap; cursor: default; z-index: 1; }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--fg); }
.table th[aria-sort]::after { content: ' ↓'; }
.table th[aria-sort='ascending']::after { content: ' ↑'; }
.table td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:hover td { background: var(--panel-2); }
.table .r { text-align: right; }
.table .tk { font-weight: 600; font-family: var(--mono); }
.table tr.hl td { background: color-mix(in srgb, var(--panel) 85%, var(--accent)); }
.table tr.past td { color: var(--muted); }
.wbar { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.wbar i { display: block; height: 6px; border-radius: 3px; background: var(--accent); }
.cotbar { position: relative; width: 120px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--down-bg), var(--panel-2) 40%, var(--panel-2) 60%, var(--up-bg)); }
.cotbar i { position: absolute; top: -3px; width: 3px; height: 14px; border-radius: 2px; background: var(--fg); transform: translateX(-50%); }
.mini-spark { width: 90px; height: 24px; }

.ranges { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.ranges button { background: transparent; border: 0; padding: 5px 10px; cursor: pointer; font-size: 12px; color: var(--fg-2); }
.ranges button.on { background: var(--panel-2); color: var(--fg); }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(3, 6, 12, .65); backdrop-filter: blur(3px); padding: 16px; }
.modal[hidden] { display: none; }
.modal-box { width: min(980px, 100%); background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px; padding: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.5); display: flex; flex-direction: column; gap: 14px; }
.modal-head { display: flex; align-items: flex-start; gap: 14px; justify-content: space-between; flex-wrap: wrap; }
.modal-head h2 { font-size: 18px; }

.foot { padding-top: 10px; border-top: 1px solid var(--line); }

@media (max-width: 1100px) {
  .grid-overview { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidenav { position: sticky; top: 92px; z-index: 10; flex-direction: row; height: auto; overflow-x: auto; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--line); background: var(--bg); }
  .sidenav a { white-space: nowrap; padding: 7px 10px; }
  .sidenav a.on { box-shadow: inset 0 -2px 0 var(--accent); }
  main { padding: 16px; }
  .topbar { padding: 10px 14px; }
  .brand-sub, #updated { display: none; }
  .hide-sm { display: none; }
}
.table td.num, .table td.r { white-space: nowrap; }
@media (max-width: 560px) {
  .tiles, .tiles-sm { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile { padding: 10px; min-height: 96px; }
  .tile-val { font-size: 17px; }
  .tile-chg { flex-direction: column; gap: 0; font-size: 11px; }
  .tile-note { display: none; }
  .sidenav { top: 0; position: relative; }
  .events li { grid-template-columns: 64px 1fr auto; }
}
