/* TREADER: dark, clean, phone-first. No inline styles anywhere (CSP style-src 'self'). */
:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222220;
  --surface-3: #2a2a28;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-ink: #86b6ef;
  --series-2: #d95926;
  --good: #0ca30c;
  --bad: #e66767;
  --warn: #fab219;
  --radius: 10px;
  --gap: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink); font: 15px/1.45 var(--font);
  min-height: 100vh; display: flex; flex-direction: column; overflow-x: hidden;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 8px; font-weight: 600; letter-spacing: 0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; color: var(--ink-2); }
p { margin: 0 0 8px; }
small, .muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
code, .mono { font-family: var(--mono); font-size: 13px; }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 800; letter-spacing: 0.18em; color: var(--ink); font-size: 16px; }
.brand:hover { text-decoration: none; }
.nav { display: flex; flex-wrap: wrap; gap: 2px 4px; flex: 1 1 auto; }
.nav a { color: var(--ink-2); padding: 4px 8px; border-radius: 6px; font-size: 14px; }
.nav a:hover { background: var(--surface-3); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--ink); background: var(--surface-3); }
.logout { margin: 0; }
.linkbtn {
  background: none; border: 1px solid var(--border); color: var(--ink-2); border-radius: 6px;
  padding: 4px 10px; font: inherit; font-size: 13px; cursor: pointer;
}
.linkbtn:hover { color: var(--ink); border-color: var(--muted); }

/* ---------- layout ---------- */
main { width: 100%; max-width: 1240px; margin: 0 auto; padding: 16px; flex: 1 0 auto; }
footer { color: var(--muted); font-size: 12px; text-align: center; padding: 16px; }
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-2 { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.stack > * + * { margin-top: var(--gap); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; min-width: 0;
}
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.row { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.spacer { flex: 1 1 auto; }
.page-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 12px; }
.page-title h1 { margin: 0; }

/* ---------- ticker ---------- */
.ticker { display: grid; gap: 10px 20px; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); align-items: end; }
.hero { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; }
.hero .price { font-size: 34px; font-weight: 650; line-height: 1.1; overflow-wrap: anywhere; }
.hero .ccy { color: var(--muted); font-size: 14px; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.stat .value { font-size: 17px; font-weight: 600; overflow-wrap: anywhere; }
.up { color: var(--good); }
.down { color: var(--bad); }
.badge {
  display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--border);
  color: var(--ink-2); white-space: nowrap; vertical-align: middle;
}
.badge.ok { color: var(--good); border-color: rgba(12, 163, 12, 0.45); }
.badge.bad { color: var(--bad); border-color: rgba(230, 103, 103, 0.45); }
.badge.warn { color: var(--warn); border-color: rgba(250, 178, 25, 0.45); }
.badge.info { color: var(--accent-ink); border-color: rgba(57, 135, 229, 0.45); }

/* ---------- charts ---------- */
.chart { position: relative; width: 100%; height: 420px; }
.chart.small { height: 260px; }
.chart.tiny { height: 200px; }
.chart-wrap { position: relative; }
.readout { font-size: 12px; color: var(--ink-2); min-height: 18px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--ink-2); }
.legend .sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.sw-1 { background: var(--accent); }
.sw-2 { background: var(--series-2); }
.sw-good { background: var(--good); }
.sw-bad { background: var(--bad); }
.chart-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 14px; pointer-events: none; text-align: center; padding: 16px;
}
.loading { opacity: 0.55; transition: opacity 0.15s; }

/* ---------- controls ---------- */
.controls { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: flex-end; margin-bottom: 10px; }
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field > span, .field > label { font-size: 12px; color: var(--muted); }
.field .hint { font-size: 11px; color: var(--muted); }
select, input[type="text"], input[type="number"], input[type="password"] {
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--axis); border-radius: 6px;
  padding: 6px 8px; font: inherit; font-size: 14px; min-width: 0; max-width: 100%;
}
select:focus, input:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg { display: inline-flex; border: 1px solid var(--axis); border-radius: 7px; overflow: hidden; }
.seg button {
  background: var(--surface-2); color: var(--ink-2); border: 0; padding: 6px 10px; font: inherit; font-size: 13px;
  cursor: pointer; border-right: 1px solid var(--axis);
}
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 7px; padding: 8px 14px; font: inherit;
  font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary { background: var(--surface-3); color: var(--ink); border: 1px solid var(--axis); }
.btn.small { padding: 4px 10px; font-size: 13px; font-weight: 500; }
.form-grid { display: grid; gap: 10px 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.form-grid .wide { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px 12px; margin: 0 0 12px; min-width: 0; }
legend { color: var(--ink-2); font-size: 13px; padding: 0 6px; }
progress { width: 100%; height: 8px; accent-color: var(--accent); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.nowrap { white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td, tr.selected td { background: var(--surface-2); }
.kv { display: grid; grid-template-columns: minmax(110px, auto) 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metrics { display: grid; gap: 8px 16px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.metric .label { color: var(--muted); font-size: 12px; }
.metric .value { font-size: 16px; font-weight: 600; }
.pager { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; font-size: 13px; }
pre.json {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px; font-size: 12px;
  white-space: pre-wrap; overflow-wrap: anywhere; max-height: 420px; overflow: auto; margin: 0;
}

/* ---------- messages ---------- */
.flash { border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; border: 1px solid var(--border); background: var(--surface); }
.flash.error { border-color: rgba(230, 103, 103, 0.5); color: #f3b0b0; }
.flash.ok { border-color: rgba(12, 163, 12, 0.5); color: #9fe39f; }
.note { font-size: 12px; color: var(--muted); }
.warnbox { border: 1px solid rgba(250, 178, 25, 0.45); color: #f6d68a; border-radius: 8px; padding: 8px 12px; font-size: 13px; }
.errbox { border: 1px solid rgba(230, 103, 103, 0.5); color: #f3b0b0; border-radius: 8px; padding: 8px 12px; font-size: 13px; }

/* ---------- login ---------- */
.login-body { justify-content: center; align-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 28px 24px 24px;
}
.login-card .brand { display: block; text-align: center; font-size: 24px; margin-bottom: 22px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card input { width: 100%; padding: 10px 12px; font-size: 16px; }
.login-card .btn { width: 100%; padding: 10px; font-size: 15px; }
.login-card .flash { margin: 0; font-size: 13px; }

@media (max-width: 640px) {
  .topbar { padding: 8px 16px; gap: 4px 8px; }
  .logout { order: 2; margin-left: auto; }
  .nav { order: 3; flex-basis: 100%; gap: 2px; }
  .nav a { padding: 3px 7px; font-size: 13px; }
  main { padding: 12px 16px; }
  .chart { height: 320px; }
  .chart.small { height: 220px; }
  .hero .price { font-size: 28px; }
  .card { padding: 12px; }
  th, td { padding: 5px 6px; }
}
