/* Colour roles (reference data-viz palette): light and dark are separately stepped, not an automatic flip. */
.viz-root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --hairline: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;  /* blue   */
  --series-2: #eb6834;  /* orange */
  --series-3: #1baf7a;  /* aqua   */
  --series-4: #eda100;  /* yellow  (slots 4-7: backtest attribution only) */
  --series-5: #e87ba4;  /* magenta */
  --series-6: #008300;  /* green   */
  --series-7: #4a3aa7;  /* violet  */
  --sel: #eef4fc;
  /* A grid of several hundred returns does not scan without them. Green/red is the convention, but the aqua and
     orange of the series palette are the accessible pair already stepped for both themes, so the same hues are
     reused rather than a second red introduced beside --series-2. */
  --gain: #0f7f58;
  --loss: #c24a1c;
}
@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;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --hairline: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --sel: #1c2a3d;
    --gain: #31c395;
    --loss: #ef7d4b;
  }
}
:root[data-theme="dark"] .viz-root {
  color-scheme: dark;
  --page: #0d0d0d; --surface-1: #1a1a19; --text-primary: #ffffff; --text-secondary: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --hairline: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-5: #d55181;
  --series-6: #008300; --series-7: #9085e9; --sel: #1c2a3d;
}

body.viz-root { background: var(--page); color: var(--text-primary); font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }
.muted { color: var(--text-secondary); }
.hairline { border-color: var(--hairline); }
.card { background: var(--surface-1); border: 1px solid var(--hairline); border-radius: 10px; }

/* controls */
.field { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--text-secondary); }
.input, .btn { background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--hairline); border-radius: 6px;
  padding: 5px 8px; font-size: 14px; }
.btn:hover:not(:disabled) { background: var(--sel); }
.btn:disabled { opacity: 0.4; }

/* refetch keeps the frame: dim, no skeleton */
#content.htmx-request { opacity: 0.55; transition: opacity 120ms; }

/* legend: line keys mirror the line marks */
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--text-secondary); margin: 2px 0 4px; }
.legend li { display: flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 14px; height: 2px; border-radius: 1px; background: var(--k); }
.key.dash { background: repeating-linear-gradient(90deg, var(--k) 0 4px, transparent 4px 7px); }
svg.chart .line.dash { stroke-dasharray: 5 4; }

/* charts */
.chart-wrap { position: relative; }
svg.chart { width: 100%; height: auto; display: block; overflow: visible; outline: none; }
svg.chart:focus-visible { box-shadow: 0 0 0 2px var(--series-1); border-radius: 4px; }
svg.chart .grid { stroke: var(--grid); stroke-width: 1; }
svg.chart .axis { stroke: var(--axis); stroke-width: 1; }
svg.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
svg.chart .tick.sub { font-size: 10px; }
svg.chart .axis-title { fill: var(--text-secondary); font-size: 11px; }
svg.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg.chart .dot { stroke: var(--surface-1); stroke-width: 2; }
svg.chart .ref { stroke: var(--muted); stroke-width: 1; }
svg.chart .ref-label { fill: var(--muted); font-size: 10px; }
svg.chart .end-label { fill: var(--text-secondary); font-size: 11px; }
svg.chart .crosshair { stroke: var(--muted); stroke-width: 1; }
svg.chart .hit { fill: transparent; cursor: crosshair; }
svg.chart .brush { fill: var(--series-1); opacity: 0.16; }
svg.chart .band { fill: var(--text-secondary); opacity: 0.13; }
svg.chart .band.dim { opacity: 0.06; }
svg.chart .band-label { fill: var(--text-secondary); font-size: 10px; }
.empty { color: var(--text-secondary); font-size: 14px; padding: 40px 0; text-align: center; }

.tooltip { position: absolute; pointer-events: none; z-index: 10; min-width: 150px; background: var(--surface-1);
  border: 1px solid var(--hairline); border-radius: 8px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12); padding: 8px 10px; font-size: 12px; }
.tooltip .tt-title { color: var(--text-secondary); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 6px; }
.tooltip .tt-value { font-weight: 600; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.tooltip .tt-label { color: var(--text-secondary); }

/* tables */
table.data { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th { text-align: right; font-weight: 500; color: var(--text-secondary); border-bottom: 1px solid var(--axis); padding: 4px 8px; white-space: nowrap; }
table.data td { text-align: right; padding: 3px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data tr.sel td { background: var(--sel); }

/* navigation and the backtest page */
.navlink { color: var(--text-secondary); }
.navlink:hover { color: var(--text-primary); }
.navlink.active { color: var(--text-primary); font-weight: 600; }
.btn.primary { background: var(--series-1); color: #fff; border-color: transparent; }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--text-primary); }
table.data th[data-dir="asc"]::after { content: " ▲"; font-size: 9px; }
table.data th[data-dir="desc"]::after { content: " ▼"; font-size: 9px; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: var(--sel); }
table.data td.left, table.data th.left { text-align: left; }
.tag { font-size: 11px; padding: 0 5px; border-radius: 4px; border: 1px solid var(--axis); color: var(--text-secondary); }
.tag.event { border-color: var(--series-2); color: var(--text-primary); }
.tag.good { border-color: var(--series-3); color: var(--text-primary); }
.error { color: var(--text-primary); border-left: 3px solid var(--series-2); padding: 4px 8px; font-size: 13px; }
.warn { color: var(--text-secondary); border-left: 3px solid var(--axis); padding: 4px 8px; font-size: 13px; }

/* Returns in the markets grid. Colour is a second encoding: the sign is in the number too, so a reader who does
   not see the hue loses nothing. */
.data td.gain { color: var(--gain); }
.data td.loss { color: var(--loss); }

/* The meerkat (templates/brand.html). Sized by its container's font-size rather than a fixed pixel height, so
   the same markup is a 20px mark next to a nav wordmark and a 40px one next to a hero headline. The eye is
   punched out in --page, so the mark needs a background of that colour behind it - every surface it sits on is. */
.meerkat { width: 1.15em; height: 1.15em; flex: none; color: var(--series-1); }
h1 .meerkat, h2 .meerkat { color: var(--series-1); }
.meerkat-lg { font-size: 34px; line-height: 1; }
/* On a card the punched-out eye has to be the card's colour, not the page's. The two are visibly different
   blacks in dark mode, so a --page eye on a card reads as a hole rather than an eye. */
.card .meerkat { --eye: var(--surface-1); }
