:root {
  --bg: #0e1014;
  --panel: #161a21;
  --panel-2: #1c212a;
  --border: #272d38;
  --text: #e7e9ee;
  --muted: #8b93a5;
  --accent: #5b8cff;
  --pos: #23c26b;
  --neg: #f0525a;
  --warn: #f2a93b;
  --idle: #6b7385;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f8;
    --panel: #ffffff;
    --panel-2: #f7f8fa;
    --border: #e1e4ea;
    --text: #161a21;
    --muted: #5d6578;
    --accent: #2f6bf0;
    --pos: #12924c;
    --neg: #d4343d;
    --warn: #b9720e;
    --idle: #8b93a5;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, select, input { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; letter-spacing: .2px; margin-right: auto; }
.brand span { color: var(--muted); font-weight: 400; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
select {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; max-width: 280px;
}
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button {
  background: var(--panel-2); border: 0; padding: 6px 11px; cursor: pointer; color: var(--muted);
}
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.user { color: var(--muted); }
.link-button {
  background: none; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; cursor: pointer;
}
.link-button:hover { border-color: var(--muted); }

/* ---------- layout ---------- */
main { max-width: 1280px; margin: 0 auto; padding: 20px; display: grid; gap: 18px; }
.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; min-width: 0;
}
.panel h2 {
  margin: 0 0 12px; font-size: 13px; font-weight: 600; letter-spacing: .4px;
  text-transform: uppercase; color: var(--muted);
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.two-col { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.stack { display: grid; gap: 18px; }
@media (max-width: 520px) {
  main { padding: 12px; }
  .two-col { grid-template-columns: 1fr; }
  .topbar { padding: 10px 12px; }
}

/* ---------- KPI tiles ---------- */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 760px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.kpi .label { font-size: 12px; color: var(--muted); }
.kpi .value { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 20px; margin-top: 4px; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.table-wrap.scroll { max-height: 440px; overflow-y: auto; }
.table-wrap.scroll thead th { position: sticky; top: 0; background: var(--panel); z-index: 1; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--muted); }
td.r, th.r { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover, tbody tr.selected { background: var(--panel-2); }
.empty { color: var(--muted); padding: 14px 4px; }

.status { display: inline-flex; align-items: center; gap: 7px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--idle); flex: none; }
.dot.live { background: var(--pos); box-shadow: 0 0 0 3px color-mix(in srgb, var(--pos) 25%, transparent); }
.dot.delayed { background: var(--warn); }
.dot.silent { background: var(--neg); }

.chart-box { position: relative; height: 300px; }
.legend-note { font-size: 12px; color: var(--muted); }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 28px 26px;
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card p { margin: 0 0 20px; color: var(--muted); }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--muted); }
.field input {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px;
}
.field input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.primary {
  width: 100%; border: 0; border-radius: 8px; padding: 10px; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 600;
}
.primary:disabled { opacity: .6; cursor: default; }
.error { color: var(--neg); min-height: 20px; margin-top: 10px; font-size: 13px; }

/* ---------- navigation ---------- */
.brand { margin-right: 0; }
.nav { display: flex; gap: 4px; margin-right: auto; }
.nav a {
  color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 8px;
}
.nav a:hover { color: var(--text); background: var(--panel-2); }
.nav a[aria-current="page"] { color: var(--text); background: var(--panel-2); }
a.link-button { color: var(--text); text-decoration: none; display: inline-block; }
.link-button:disabled { opacity: .45; cursor: default; }
.panel-link { color: var(--accent); text-decoration: none; font-size: 13px; }
.panel-link:hover { text-decoration: underline; }

/* ---------- trade history ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filter { display: grid; gap: 4px; }
.filter label { font-size: 12px; color: var(--muted); }
.filter input, .filter select {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; min-width: 130px;
}
.filter-actions { display: flex; gap: 8px; margin-left: auto; }
.filter-note { margin: 10px 0 0; }
.pager { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; }
.pager .spacer { flex: 1; }
@media (max-width: 520px) {
  .filter, .filter input, .filter select { width: 100%; }
  .filter-actions { margin-left: 0; }
}
