/* ── Palette (validated data-viz reference palette) ───────────────────── */
:root {
  --page:        #f9f9f7;
  --surface:     #fcfcfb;
  --text-1:      #0b0b0b;
  --text-2:      #52514e;
  --muted:       #898781;
  --grid:        #e1e0d9;
  --baseline:    #c3c2b7;
  --border:      rgba(11,11,11,0.10);
  --good:        #0ca30c;
  --warning:     #fab219;
  --serious:     #ec835a;
  --critical:    #d03b3b;
  --pos:         #2a78d6;
  --neg:         #e34948;
  --accent:      #2a78d6;
  --shadow:      0 1px 2px rgba(11,11,11,0.04), 0 2px 8px rgba(11,11,11,0.05);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --page:        #0d0d0d;
  --surface:     #1a1a19;
  --text-1:      #ffffff;
  --text-2:      #c3c2b7;
  --muted:       #898781;
  --grid:        #2c2c2a;
  --baseline:    #383835;
  --border:      rgba(255,255,255,0.10);
  --good:        #0ca30c;
  --warning:     #fab219;
  --serious:     #ec835a;
  --critical:    #d03b3b;
  --pos:         #3987e5;
  --neg:         #e66767;
  --accent:      #3987e5;
  --shadow:      0 1px 2px rgba(0,0,0,0.4), 0 2px 10px rgba(0,0,0,0.4);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --page:#0d0d0d; --surface:#1a1a19; --text-1:#fff; --text-2:#c3c2b7;
    --muted:#898781; --grid:#2c2c2a; --baseline:#383835; --border:rgba(255,255,255,0.10);
    --pos:#3987e5; --neg:#e66767; --accent:#3987e5;
    --shadow:0 1px 2px rgba(0,0,0,0.4), 0 2px 10px rgba(0,0,0,0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-1);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}
a { color: var(--accent); }

/* ── Top bar ──────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.1) blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  font-weight: 800; letter-spacing: 0.5px; font-size: 15px;
  color: #fff; background: var(--accent);
  padding: 6px 9px; border-radius: 8px; line-height: 1;
}
.brand-txt h1 { font-size: 16px; margin: 0; font-weight: 650; }
.brand-txt .sub { margin: 1px 0 0; font-size: 12.5px; color: var(--text-2); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
#search {
  font: inherit; font-size: 14px; padding: 8px 12px; width: min(280px, 46vw);
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--page); color: var(--text-1);
}
#search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn-icon {
  font-size: 16px; width: 38px; height: 38px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--border); background: var(--page); color: var(--text-1);
}
.btn-icon:hover { border-color: var(--baseline); }

main { max-width: 1180px; margin: 0 auto; padding: 22px 20px 40px; }

/* ── Overview grid ────────────────────────────────────────────────────── */
.overview-head h2 { margin: 4px 0 2px; font-size: 20px; }
.overview-head .hint { margin: 0 0 14px; color: var(--text-2); font-size: 13.5px; }
.group-head {
  display: flex; align-items: baseline; gap: 10px;
  margin: 22px 2px 10px; font-size: 13px; font-weight: 650;
  text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted);
}
.group-head::after { content: ""; flex: 1; height: 1px; background: var(--grid); }
#grid > .cards {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
}
.card {
  text-align: left; cursor: pointer; font: inherit;
  background: var(--surface); border: 1px solid var(--border); border-radius: 13px;
  padding: 13px 14px; box-shadow: var(--shadow);
  display: grid; gap: 8px; transition: transform .08s ease, border-color .12s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--baseline); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.card-tick { font-weight: 750; font-size: 15px; letter-spacing: 0.3px; }
.card-name { color: var(--text-2); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-net { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.2px; }
.card-cat { font-size: 11px; color: var(--muted); margin-top: -4px; }
.card-bot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.delta { font-size: 12.5px; font-variant-numeric: tabular-nums; font-weight: 600; }
.delta.up { color: var(--good); }
.delta.down { color: var(--critical); }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 650; padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--border);
}
.badge .dot { width: 8px; height: 8px; border-radius: 50%; }
.badge.calm  { color: var(--text-2); }
.badge.calm  .dot { background: var(--baseline); }
.badge.warn  { color: var(--serious); } .badge.warn .dot { background: var(--warning); }
.badge.alert { color: var(--critical); } .badge.alert .dot { background: var(--critical); }

/* COT index gauge (overview cards): net's position in its 52-week range. */
.cot { display: flex; align-items: center; gap: 8px; margin-top: -2px; }
.cot-bar { position: relative; flex: 1; height: 6px; border-radius: 999px; background: var(--grid); overflow: hidden; }
.cot-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; background: var(--baseline); }
.cot-fill.cot-hot  { background: var(--critical); }
.cot-fill.cot-cold { background: var(--pos); }
.cot-fill.cot-mid  { background: var(--baseline); }
.cot-val { font-size: 11px; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--muted); min-width: 46px; text-align: right; }
.cot-val.cot-hot  { color: var(--critical); }
.cot-val.cot-cold { color: var(--pos); }
/* COT index cell in the snapshot table */
#snap-table td.cot-hot  { color: var(--critical); font-weight: 600; }
#snap-table td.cot-cold { color: var(--pos); font-weight: 600; }

/* ── Detail ───────────────────────────────────────────────────────────── */
.detail-top { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.btn-back {
  font: inherit; font-size: 13px; cursor: pointer; padding: 7px 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-1);
}
.btn-back:hover { border-color: var(--baseline); }
.detail-title { margin-right: auto; }
.detail-title h2 { margin: 0; font-size: 20px; }
.d-meta { font-size: 12.5px; color: var(--text-2); }
.tabs { display: flex; gap: 6px; background: var(--page); padding: 4px; border-radius: 10px; border: 1px solid var(--border); }
.tab {
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  padding: 6px 13px; border-radius: 7px; border: none; background: transparent; color: var(--text-2);
}
.tab[aria-selected="true"] { background: var(--surface); color: var(--text-1); box-shadow: var(--shadow); }

.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 18px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; box-shadow: var(--shadow);
}
.tile .t-lab { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.tile .t-lab .swatch { width: 10px; height: 10px; border-radius: 3px; }
.tile .t-val { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 4px; letter-spacing: -0.3px; }
.tile .t-sub { font-size: 12px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }

.controls { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 16px; }
.ctl { display: grid; gap: 4px; font-size: 12px; color: var(--text-2); }
.ctl select {
  font: inherit; font-size: 13.5px; padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-1); min-width: 150px;
}

.chart-card {
  position: relative;
  margin: 0 0 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 13px; padding: 14px 8px 8px 8px; box-shadow: var(--shadow);
}
.chart-card figcaption { font-size: 13.5px; font-weight: 600; padding: 0 8px 8px; }

/* ── "How to read this chart" info tooltips ───────────────────────────── */
.help { display: inline-flex; vertical-align: middle; }
.info {
  font: inherit; font-size: 11px; font-weight: 700; line-height: 1;
  width: 16px; height: 16px; margin-left: 6px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; cursor: help;
  color: var(--muted); background: transparent; border: 1px solid var(--border);
}
.info:hover, .help.open .info { color: var(--text-1); border-color: var(--baseline); }
.info:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tip {
  position: absolute; top: 36px; left: 12px; right: 12px; z-index: 30;
  max-width: 460px;
  font-size: 12.5px; font-weight: 400; line-height: 1.5; color: var(--text-2);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; box-shadow: var(--shadow);
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: opacity .12s ease, transform .12s ease, visibility .12s;
}
.help:hover .tip, .help:focus-within .tip, .help.open .tip {
  opacity: 1; visibility: visible; transform: translateY(0);
}
@media (max-width: 560px) { .tip { left: 8px; right: 8px; } }
.cap-note { font-weight: 400; color: var(--muted); font-size: 12px; }
.chart { width: 100%; height: 380px; }
.chart-sm { height: 300px; }
.chart-2col { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
@media (max-width: 820px) { .chart-2col { grid-template-columns: 1fr; } }

.table-wrap { overflow-x: auto; padding: 0 8px 6px; }
#snap-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
#snap-table th, #snap-table td { padding: 8px 10px; text-align: right; white-space: nowrap; }
#snap-table th:first-child, #snap-table td:first-child { text-align: left; }
#snap-table thead th { color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--grid); font-size: 12px; }
#snap-table tbody tr { border-bottom: 1px solid var(--grid); }
#snap-table td.cat { display: flex; align-items: center; gap: 8px; }
#snap-table .swatch { width: 10px; height: 10px; border-radius: 3px; }
.num-pos { color: var(--good); } .num-neg { color: var(--critical); }

.foot { max-width: 1180px; margin: 0 auto; padding: 8px 20px 34px; color: var(--muted); font-size: 12px; }
.foot a { color: var(--accent); }

.view[hidden] { display: none; }
