/* CryptoTrack — design tokens and layout.
   Color values are the validated reference palette: categorical slots 1–3 (the
   all-pairs colorblind-safe window), the blue<->red diverging pair for signed
   marks, and the delta text roles for signed text. Dark values are that
   palette's own dark steps, not an automatic flip. */

.viz-root {
  color-scheme: light;

  --page:            #f9f9f7;
  --surface-1:       #fcfcfb;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #898781;
  --grid:            #e1e0d9;
  --axis:            #c3c2b7;
  --border:          rgba(11, 11, 11, 0.10);
  --wash:            rgba(11, 11, 11, 0.04);
  --wash-strong:     rgba(11, 11, 11, 0.08);

  --series-1:        #2a78d6;
  --series-2:        #eb6834;
  --series-3:        #1baf7a;

  /* Diverging poles: warm/cool, neutral gray midpoint. */
  --pole-up:         #2a78d6;
  --pole-down:       #e34948;
  --pole-mid:        #f0efec;

  /* Signed *text* deltas only (always shipped with an arrow glyph and a sign,
     so color is never the sole channel). */
  --delta-up:        #006300;
  --delta-down:      #d03b3b;

  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;
    --page:           #0d0d0d;
    --surface-1:      #1a1a19;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --axis:           #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --wash:           rgba(255, 255, 255, 0.05);
    --wash-strong:    rgba(255, 255, 255, 0.10);
    --series-1:       #3987e5;
    --series-2:       #d95926;
    --series-3:       #199e70;
    --pole-up:        #3987e5;
    --pole-down:      #e66767;
    --pole-mid:       #383835;
    --delta-up:       #0ca30c;
    --delta-down:     #d03b3b;
    --shadow: none;
  }
}

:root[data-theme="dark"] .viz-root {
  color-scheme: dark;
  --page:           #0d0d0d;
  --surface-1:      #1a1a19;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --grid:           #2c2c2a;
  --axis:           #383835;
  --border:         rgba(255, 255, 255, 0.10);
  --wash:           rgba(255, 255, 255, 0.05);
  --wash-strong:    rgba(255, 255, 255, 0.10);
  --series-1:       #3987e5;
  --series-2:       #d95926;
  --series-3:       #199e70;
  --pole-up:        #3987e5;
  --pole-down:      #e66767;
  --pole-mid:       #383835;
  --delta-up:       #0ca30c;
  --delta-down:     #d03b3b;
  --shadow: none;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.45;
}

.shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

/* ---------------------------------------------------------------- header --- */

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.masthead h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}

.masthead .sub {
  color: var(--text-secondary);
  font-size: 12.5px;
  margin: 3px 0 0;
}

.masthead-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stamp {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- filters --- */
/* One row, above everything it scopes. No chart card carries its own filter. */

.filters {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 12px 14px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.segmented button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 12.5px;
  padding: 5px 11px;
  min-height: 28px;
  cursor: pointer;
  border-right: 1px solid var(--border);
}

.segmented button:last-child { border-right: 0; }
.segmented button:hover { background: var(--wash); }

.segmented button[aria-pressed="true"] {
  background: var(--wash-strong);
  color: var(--text-primary);
  font-weight: 600;
}

.segmented button:focus-visible,
.chip:focus-visible,
.ghost-btn:focus-visible,
.chart-svg:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 1px;
}

.chips { display: flex; gap: 7px; flex-wrap: wrap; }

.chip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 12.5px;
  padding: 4px 11px 4px 9px;
  min-height: 28px;
  cursor: pointer;
}

.chip:hover:not(:disabled) { background: var(--wash); }
.chip:disabled { opacity: 0.42; cursor: not-allowed; }

.chip[aria-pressed="true"] {
  background: var(--wash-strong);
  color: var(--text-primary);
  font-weight: 600;
  border-color: var(--axis);
}

/* The chip's swatch is the coin's series color — identity rides a mark beside
   the text, never the text itself. */
.chip .swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: var(--axis);
  flex: none;
}

.chip[aria-pressed="true"] .swatch { background: var(--chip-color, var(--axis)); }

.ghost-btn {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 12.5px;
  padding: 5px 11px;
  min-height: 28px;
  cursor: pointer;
}

.ghost-btn:hover { background: var(--wash); }
.ghost-btn[aria-pressed="true"] {
  background: var(--wash-strong);
  color: var(--text-primary);
  font-weight: 600;
}

/* ---------------------------------------------------------------- banner --- */

.banner {
  display: none;
  align-items: center;
  gap: 9px;
  padding: 9px 13px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-1);
  color: var(--text-secondary);
  font-size: 12.5px;
}

.banner.show { display: flex; }
.banner .icon { flex: none; font-size: 13px; }

/* ------------------------------------------------------------------ hero --- */

.hero {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.hero .label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

/* Hero figure: same system sans as everything else, proportional figures. */
.hero .figure {
  font-size: 52px;
  line-height: 1.05;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.hero .meta {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 9px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

/* ------------------------------------------------------------- stat tiles --- */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(224px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 15px 16px 12px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.tile .tile-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.tile .key {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: none;
}

.tile .label {
  font-size: 12.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile .value {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.tile .row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-top: 3px;
}

.tile .spark { margin-top: 8px; }

.delta {
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.delta .arrow { font-weight: 400; }
.delta.up { color: var(--delta-up); }
.delta.down { color: var(--delta-down); }
.delta.flat { color: var(--text-secondary); }

.delta-period {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 400;
}

/* ----------------------------------------------------------------- cards --- */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px 14px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.card-head h2 {
  font-size: 14.5px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.005em;
}

.card-head .note {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 3px 0 0;
  max-width: 62ch;
}

.card-tools { display: flex; align-items: center; gap: 8px; flex: none; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
  .hero .figure { font-size: 40px; }
}

/* Refetch holds the previous render at reduced opacity — no skeleton, no jump. */
.is-loading .chart-host,
.is-loading .tile-body { opacity: 0.55; transition: opacity 120ms ease; }

/* ---------------------------------------------------------------- legend --- */
/* Always present for >= 2 series; absent for one (the title names it). */

.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin: 2px 0 10px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.legend-item { display: inline-flex; align-items: center; gap: 7px; }

.legend-item .line-key {
  width: 16px;
  height: 2px;
  border-radius: 1px;
  flex: none;
}

.legend-item .rect-key {
  width: 11px;
  height: 11px;
  border-radius: 2px;
  flex: none;
}

/* ----------------------------------------------------------------- chart --- */

.chart-host { position: relative; }

.chart-svg {
  display: block;
  width: 100%;
  overflow: visible;
  touch-action: pan-y;
}

.chart-svg text {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 11px;
  fill: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.chart-svg .end-label {
  font-size: 11.5px;
  font-weight: 600;
  fill: var(--text-secondary);
}

.chart-svg .bar-label {
  font-size: 11.5px;
  font-weight: 600;
  fill: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.chart-svg .cat-label {
  font-size: 11.5px;
  fill: var(--text-secondary);
  font-variant-numeric: normal;
}

.chart-svg .gridline { stroke: var(--grid); stroke-width: 1; }
.chart-svg .baseline  { stroke: var(--axis); stroke-width: 1; }
.chart-svg .crosshair { stroke: var(--axis); stroke-width: 1; }

.chart-svg .series-line {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-svg .series-area { stroke: none; opacity: 0.10; }

/* 2px surface ring keeps markers legible where they overlap a line. */
.chart-svg .marker { stroke: var(--surface-1); stroke-width: 2; }

.chart-svg .bar { transition: opacity 100ms ease; }
.chart-svg .hit { fill: transparent; cursor: pointer; }
.chart-svg .bar-row.dim .bar { opacity: 0.55; }

@media (prefers-reduced-motion: reduce) {
  .chart-svg .bar, .is-loading .chart-host, .is-loading .tile-body { transition: none; }
}

/* --------------------------------------------------------------- tooltip --- */

.tooltip {
  position: absolute;
  z-index: 20;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -100%);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  box-shadow: 0 4px 14px rgba(11, 11, 11, 0.13);
  min-width: 132px;
  transition: opacity 90ms ease;
}

.tooltip.show { opacity: 1; }

.tooltip .tip-head {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 5px;
  white-space: nowrap;
}

.tooltip .tip-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
}

.tooltip .tip-row + .tip-row { margin-top: 3px; }

/* Tooltip rows key their series with a short stroke, not a filled box. */
.tooltip .line-key {
  width: 12px;
  height: 2px;
  border-radius: 1px;
  flex: none;
  align-self: center;
}

/* Values lead, labels follow — the legend's hierarchy, inverted. */
.tooltip .tip-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}

.tooltip .tip-name { font-size: 12px; color: var(--text-secondary); }

/* ----------------------------------------------------------------- table --- */

.table-wrap { overflow-x: auto; margin-top: 4px; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

table.data caption {
  text-align: left;
  color: var(--text-muted);
  font-size: 11.5px;
  padding-bottom: 7px;
}

table.data th, table.data td {
  text-align: right;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.data th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  position: sticky;
  top: 0;
  background: var(--surface-1);
}

table.data th:first-child, table.data td:first-child {
  text-align: left;
  font-variant-numeric: normal;
}

table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--text-secondary); }
table.data th[aria-sort] { color: var(--text-primary); }
table.data tbody tr:hover { background: var(--wash); }

.coin-cell { display: inline-flex; align-items: center; gap: 8px; }
.coin-cell img { width: 18px; height: 18px; border-radius: 50%; flex: none; }
.coin-cell .sym { color: var(--text-muted); font-size: 11.5px; }

.num.up { color: var(--delta-up); }
.num.down { color: var(--delta-down); }

.small-mult { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 18px; }
.small-mult .panel-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 2px;
}
.small-mult .panel-title .key { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.small-mult .panel-sub { font-size: 11.5px; color: var(--text-muted); margin-bottom: 6px; }

.footnote {
  color: var(--text-muted);
  font-size: 11.5px;
  margin-top: 22px;
  text-align: center;
}

.footnote a { color: var(--text-secondary); }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Texture is the backup identity channel: opt-in, or forced by the platform.
   45 degrees and its 135 mirror only. */
@media (forced-colors: active) {
  .chart-svg .series-area { opacity: 0.2; }
  .card, .tile, .hero, .filters { border-color: CanvasText; }
}

@media print {
  body { background: #fff; }
  .filters, .card-tools, .masthead-right { display: none; }
  .card, .tile, .hero { break-inside: avoid; box-shadow: none; }
}
