/* Design tokens. Layout concept: sticky filter bar over a 12-column grid of analysis panels.
   Palette: neutral greys with a slight warm bias, three categorical hues (blue, orange, aqua) validated for
   color-vision deficiency, red reserved for negative values. Both themes define every token. */
:root {
  --bg: #f1f1ee;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6c6b65;
  --line: #e0dfda;
  --grid: #e9e8e3;
  --axis: #b9b8b0;
  --band: #f0efec;
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --neutral: #9b9a93;
  --neg: #e34948;
  --focus: color-mix(in srgb, var(--s1) 11%, transparent);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111110; --surface: #1a1a19; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #99988e;
    --line: #2d2d2a; --grid: #282826; --axis: #4a4a46; --band: #242422;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --neutral: #6f6e68; --neg: #e66767;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111110; --surface: #1a1a19; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #99988e;
  --line: #2d2d2a; --grid: #282826; --axis: #4a4a46; --band: #242422;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --neutral: #6f6e68; --neg: #e66767;
  color-scheme: dark;
}

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
[hidden] { display: none !important; }
/* Paints the phone status-bar area so nothing scrolls into view above the sticky bar. */
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 30; background: var(--bg); }

.gutter { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.shell { max-width: 1440px; margin-inline: auto; }
.filter-bar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--bg); border-bottom: 1px solid var(--line); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 1.25rem; }
:focus-visible { outline: 2px solid var(--s1); outline-offset: 2px; }

/* Controls */
.chip, .btn-ghost, .seg-btn, .sort-btn {
  font: inherit; color: var(--ink-2); background: transparent; cursor: pointer;
}
.chip { height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: 13px; }
.chip:hover, .btn-ghost:hover { border-color: var(--axis); color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.btn-ghost { height: 32px; padding: 0 10px; border: 1px solid transparent; border-radius: 6px; font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg-btn { height: 34px; padding: 0 12px; border: 0; font-size: 13px; white-space: nowrap; }
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn:hover { background: var(--band); color: var(--ink); }
.seg-btn[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
select { font-family: inherit; }
.btn-outline { height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink-2); font: inherit; font-size: 13px; cursor: pointer; }
.btn-outline:hover { border-color: var(--axis); color: var(--ink); }

/* SVG chart text and rows */
.chart { display: block; max-width: 100%; overflow: visible; }
.chart text { font-family: 'IBM Plex Sans', system-ui, sans-serif; font-variant-numeric: tabular-nums; }
.axis-text { fill: var(--muted); font-size: 11px; }
.axis-title { fill: var(--ink-2); font-size: 12px; }
.row-label { fill: var(--ink-2); font-size: 12.5px; }
.row-label.is-focus, .point-label.is-focus { fill: var(--ink); font-weight: 600; }
.value-text { fill: var(--ink-2); font-size: 12px; }
.value-text.muted { fill: var(--muted); }
.ref-text { fill: var(--ink-2); font-size: 11px; }
.corner-text { fill: var(--muted); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; }
.point-label { fill: var(--ink-2); font-size: 11.5px; }
.row-band { fill: transparent; }
.row:hover .row-band { fill: var(--band); }
.row.is-focus .row-band { fill: var(--focus); }
.hit { cursor: pointer; outline: none; }
.hit:focus-visible { outline: 2px solid var(--s1); outline-offset: -2px; }

/* Legend */
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 0; padding: 0; list-style: none; font-size: 13px; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: baseline; gap: 6px; min-width: 0; }
.legend-swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; align-self: center; }

/* Tooltip */
.tt { position: fixed; z-index: 50; pointer-events: none; max-width: 260px; padding: 10px 12px; border-radius: 8px;
  background: var(--ink); color: var(--surface); font-size: 12.5px; box-shadow: 0 6px 24px rgb(0 0 0 / .22); }
.tt-title { font-weight: 600; margin-bottom: 4px; }
.tt-row { display: flex; align-items: center; gap: 8px; line-height: 1.6; }
.tt-dot { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.tt-dot-none { background: transparent; }
.tt-label { flex: 1; opacity: .8; }
.tt-value { font-variant-numeric: tabular-nums; font-weight: 600; }
.tt-note { margin-top: 6px; padding-top: 6px; border-top: 1px solid color-mix(in srgb, var(--surface) 25%, transparent); opacity: .8; }

/* Tables */
.table-wrap { overflow-x: auto; max-width: 100%; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th, .data-table td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.data-table thead th { font-size: 12px; font-weight: 500; color: var(--muted); }
.data-table tbody th { font-weight: 500; color: var(--ink); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.score-table thead th, .score-table tbody th { position: sticky; left: 0; background: var(--surface); }
.score-table thead th:not(:first-child) { position: static; }
.sort-btn { display: inline-flex; align-items: center; gap: 4px; padding: 0; border: 0; font-weight: inherit; font-size: inherit; color: inherit; width: 100%; text-align: left; }
.sort-btn:hover { color: var(--ink); }
.sort-arrow { font-size: 9px; width: 10px; }
.score-row { cursor: pointer; }
.score-row:hover td, .score-row:hover th { background: var(--band); }
.score-row.is-active th { box-shadow: inset 3px 0 0 var(--s1); }
.score-row.is-active td { background: var(--focus); }
.tier-good { background: color-mix(in srgb, var(--s1) 17%, transparent); }
.tier-bad { background: color-mix(in srgb, var(--s2) 20%, transparent); }

/* Market profile */
.profile-scroll { max-height: 31rem; overflow-y: auto; padding-right: 2px; }
.profile-group { position: sticky; top: 0; z-index: 1; margin: 0; padding: 10px 8px 4px; background: var(--surface);
  font-size: 11px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.profile-row { display: grid; grid-template-columns: minmax(0, 1.5fr) 4rem 5.5rem 3.5rem; gap: 8px; align-items: baseline; width: 100%;
  padding: 6px 8px; border: 0; border-radius: 6px; background: transparent; font: inherit; font-size: 13.5px; color: var(--ink-2); cursor: pointer; }
.profile-row:hover { background: var(--band); }
.profile-row.is-active { background: var(--focus); color: var(--ink); }
.delta-good::before, .delta-bad::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 2px; margin-right: 5px; }
.delta-good::before { background: var(--s1); }
.delta-bad::before { background: var(--s2); }
.delta-good, .delta-bad, .delta-neutral { color: var(--ink-2); }

@media (prefers-reduced-motion: no-preference) {
  .chip, .seg-btn, .profile-row { transition: background-color .12s, color .12s, border-color .12s; }
}
