/* h-dash stylesheet.
 *
 * Colour is declared once, as custom properties, in two blocks: light and dark. The
 * SVG marks carry class names (`s1`…`s8`, `grid`, `axis`) and resolve their fill and
 * stroke from those properties, so a theme change is a variable swap rather than a
 * second rendering path on the server.
 *
 * The values are the validated categorical palette from the repository's
 * data-visualisation guidance. Slots 1–3 (blue, orange, aqua) are the set cleared for
 * every pair in both modes, which is what the Baltic zones use. Dark is a selected set
 * of steps for the dark surface, not an automatic inversion of light.
 */

:root {
  color-scheme: light;

  --page:            #f9f9f7;
  --surface:         #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);

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;

  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;

  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:           #0d0d0d;
    --surface:        #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.06);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page:           #0d0d0d;
  --surface:        #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.06);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--series-1); text-decoration-thickness: 1px; text-underline-offset: 2px; }

.skip-link {
  position: absolute; left: -9999px; top: 0; padding: 8px 12px;
  background: var(--surface); border: 1px solid var(--border); z-index: 10;
}
.skip-link:focus { left: 8px; top: 8px; }

/* ---------------------------------------------------------------- shell & menu */

.shell { display: flex; min-height: 100vh; align-items: stretch; }

.sidebar {
  flex: 0 0 216px;
  display: flex; flex-direction: column; gap: 20px;
  padding: 22px 16px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; height: 100vh;
}

.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; letter-spacing: -0.01em; }
.brand-mark {
  width: 11px; height: 11px; border-radius: 3px;
  background: var(--series-1);
}

.nav { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: block; padding: 7px 10px; border-radius: 7px;
  color: var(--text-secondary); text-decoration: none; font-size: 14px;
}
.nav a:hover { background: var(--wash); color: var(--text-primary); }
.nav a[aria-current="page"] { background: var(--wash); color: var(--text-primary); font-weight: 600; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.ghost {
  align-self: flex-start;
  background: none; border: 1px solid var(--border); border-radius: 7px;
  color: var(--text-secondary); font: inherit; font-size: 13px;
  padding: 5px 10px; cursor: pointer;
}
.ghost:hover { background: var(--wash); color: var(--text-primary); }

main { flex: 1 1 auto; padding: 28px 32px 64px; max-width: 1240px; min-width: 0; }

/* ---------------------------------------------------------------------- text */

.page-head { margin-bottom: 22px; }
h1 { font-size: 25px; letter-spacing: -0.02em; margin: 0 0 6px; }
h2 { font-size: 16px; letter-spacing: -0.01em; margin: 0 0 4px; }
h2 .sub { font-weight: 400; color: var(--text-muted); font-size: 13px; margin-left: 6px; }
.lede { color: var(--text-secondary); margin: 0; }
.note { color: var(--text-muted); font-size: 13px; margin: 4px 0 14px; max-width: 78ch; }
.crumb { font-size: 13px; color: var(--text-muted); margin: 0 0 6px; }
.hint { display: block; color: var(--text-muted); font-size: 12px; }
code, .digest, .json { font-family: var(--mono); font-size: 12.5px; }
/* A 64-character digest has no spaces to break on and would otherwise run out
 * past its card. */
.digest { overflow-wrap: anywhere; }

/* --------------------------------------------------------------------- blocks */

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

.empty-state ol { color: var(--text-secondary); padding-left: 20px; }
.empty-state li { margin-bottom: 8px; }

.filters {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end;
  margin-bottom: 18px;
}
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-muted); }
.filters select {
  font: inherit; font-size: 14px; padding: 6px 9px;
  background: var(--surface); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 7px;
}

.banner {
  border: 1px solid var(--border); border-left-width: 3px;
  border-radius: 7px; padding: 10px 13px; margin: 0 0 16px;
  font-size: 13.5px; color: var(--text-secondary);
}
.banner.warning  { border-left-color: var(--warning); }
.banner.critical { border-left-color: var(--critical); }

.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; border: 1px solid var(--border); color: var(--text-secondary);
}
.pill.good     { border-color: var(--good); color: var(--text-secondary); }
.pill.critical { border-color: var(--critical); }
.pill.muted    { color: var(--text-muted); }

/* Ingestion tier states. Status colours are reserved for status and never reused as a
 * series hue, and each one ships with its word rather than relying on colour alone. */
.pill.current { border-color: var(--good); }
.pill.stale   { border-color: var(--warning); }
.pill.failing { border-color: var(--critical); }
.pill.never   { border-color: var(--serious); }
.pill.manual  { color: var(--text-muted); }

.banner.good { border-left-color: var(--good); }

/* One tier's state in a table cell: pill, age, and a meter of age against the tier's
 * staleness budget. The meter is the part that shows drift before it becomes a verdict. */
.tier { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 8px; min-width: 132px; }
.tier-age { color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.meter {
  flex: 1 0 100%; height: 3px; border-radius: 2px;
  background: var(--grid); overflow: hidden;
}
.meter-fill { display: block; height: 100%; background: var(--good); border-radius: 2px; }
.meter.stale   .meter-fill { background: var(--warning); }
.meter.failing .meter-fill { background: var(--critical); }
.meter.never   .meter-fill { background: var(--serious); }

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

.tiles {
  display: grid; gap: 14px; margin-bottom: 18px;
  grid-template-columns: repeat(auto-fit, minmax(196px, 1fr));
}
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 15px 17px;
}
.tile-label { display: flex; align-items: center; gap: 7px; margin: 0 0 6px; font-size: 13px; color: var(--text-secondary); }
/* Proportional figures: tabular-nums makes a large standalone number look loose. */
.tile-value { margin: 0; font-size: 27px; font-weight: 600; letter-spacing: -0.02em; }
.tile-value .unit { font-size: 14px; font-weight: 400; color: var(--text-muted); margin-left: 3px; }
.tile-delta { margin: 5px 0 0; font-size: 13px; color: var(--text-secondary); }
.tile-foot  { margin: 3px 0 0; font-size: 12.5px; color: var(--text-muted); }

.facts { display: grid; gap: 12px 28px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin: 10px 0 0; }
.facts > div { min-width: 0; }
.facts dt { font-size: 12px; color: var(--text-muted); }
.facts dd { margin: 2px 0 0; }

/* ---------------------------------------------------------------------- charts */

.chart-wrap { margin: 6px 0 2px; }
.chart { display: block; width: 100%; height: auto; overflow: visible; }

.chart .grid  { stroke: var(--grid); stroke-width: 1; }
.chart .axis  { stroke: var(--axis); stroke-width: 1; }
.chart .tick  { fill: var(--text-muted); font: 11px var(--font); font-variant-numeric: tabular-nums; }
.chart .end-label { fill: var(--text-secondary); font: 11px var(--font); font-weight: 600; }
.chart .leader { stroke: var(--axis); stroke-width: 1; }
.chart .empty-text { fill: var(--text-muted); font: 13px var(--font); }
.chart .panel-title { fill: var(--text-secondary); font: 11px var(--font); font-weight: 600; }
.chart .panel-unit  { fill: var(--text-muted); font-weight: 400; }
/* Area fills are a wash, never a saturated block. */
.chart .fill { stroke: none; opacity: 0.12; }
.chart .fill.s1 { fill: var(--series-1); } .chart .fill.s2 { fill: var(--series-2); }
.chart .fill.s3 { fill: var(--series-3); } .chart .fill.s4 { fill: var(--series-4); }
.chart .fill.s5 { fill: var(--series-5); } .chart .fill.s6 { fill: var(--series-6); }
.chart .fill.s7 { fill: var(--series-7); } .chart .fill.s8 { fill: var(--series-8); }

.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .bar  { stroke: none; }
.chart .mark { stroke: var(--surface); stroke-width: 2; }
.chart .key  { stroke-width: 2; stroke-linecap: round; }

/* "Not computed" reads below the baseline, where a magnitude never goes. */
.chart .gap { fill: var(--text-muted); opacity: 0.45; }

.chart .crosshair, .chart .band-wash { opacity: 0; transition: opacity 90ms ease; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .band-wash { fill: var(--text-primary); }
.chart .band:hover .crosshair, .chart .band:focus-within .crosshair { opacity: 1; }
.chart .band:hover .band-wash, .chart .band:focus-within .band-wash { opacity: 0.05; }
.chart .hit { fill: transparent; outline: none; }

.chart .s1 { stroke: var(--series-1); } .chart .bar.s1, .chart .mark.s1 { fill: var(--series-1); }
.chart .s2 { stroke: var(--series-2); } .chart .bar.s2, .chart .mark.s2 { fill: var(--series-2); }
.chart .s3 { stroke: var(--series-3); } .chart .bar.s3, .chart .mark.s3 { fill: var(--series-3); }
.chart .s4 { stroke: var(--series-4); } .chart .bar.s4, .chart .mark.s4 { fill: var(--series-4); }
.chart .s5 { stroke: var(--series-5); } .chart .bar.s5, .chart .mark.s5 { fill: var(--series-5); }
.chart .s6 { stroke: var(--series-6); } .chart .bar.s6, .chart .mark.s6 { fill: var(--series-6); }
.chart .s7 { stroke: var(--series-7); } .chart .bar.s7, .chart .mark.s7 { fill: var(--series-7); }
.chart .s8 { stroke: var(--series-8); } .chart .bar.s8, .chart .mark.s8 { fill: var(--series-8); }
.chart .bar { stroke: none; }

/* Legend and swatches. Identity rides a coloured mark beside the text; the text
 * itself always wears an ink token. */
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 10px 0 2px; padding: 0; }
.legend li { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-secondary); }

.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; flex: none; }
.swatch.line { width: 14px; height: 2px; border-radius: 2px; }
.swatch.gap  { background: var(--text-muted); opacity: 0.45; height: 6px; width: 12px; }
.swatch.s1 { background: var(--series-1); } .swatch.s2 { background: var(--series-2); }
.swatch.s3 { background: var(--series-3); } .swatch.s4 { background: var(--series-4); }
.swatch.s5 { background: var(--series-5); } .swatch.s6 { background: var(--series-6); }
.swatch.s7 { background: var(--series-7); } .swatch.s8 { background: var(--series-8); }

.gap-key { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-muted); margin: 8px 0 0; }

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

.tooltip {
  position: fixed; z-index: 20; pointer-events: none;
  background: var(--surface); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12.5px; min-width: 130px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
}
.tooltip[hidden] { display: none; }
.tooltip .tt-title { color: var(--text-muted); font-size: 11.5px; margin-bottom: 5px; }
.tooltip .tt-row { display: flex; align-items: baseline; gap: 7px; margin-top: 3px; }
/* Values lead, labels follow: the reader has the series and wants the number. */
.tooltip .tt-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.tooltip .tt-name { color: var(--text-secondary); }
.tooltip .tt-detail { color: var(--text-muted); font-size: 11.5px; margin-left: auto; }

/* --------------------------------------------------------------------- tables */

table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
caption { text-align: left; color: var(--text-muted); font-size: 12.5px; padding-bottom: 8px; }
th, td { text-align: left; padding: 6px 12px 6px 0; border-bottom: 1px solid var(--border); }
thead th { color: var(--text-muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
tbody th { font-weight: 500; white-space: nowrap; }
td { font-variant-numeric: tabular-nums; }
/* The run listing is wider than the viewport on a laptop; let it keep its
 * columns on one line each and scroll inside its own container. */
.wide { width: max-content; min-width: 100%; }
.wide td, .wide tbody th { white-space: nowrap; }
tr.superseded { color: var(--text-muted); }
.na .reason { color: var(--text-muted); font-size: 11.5px; }

.sub-head { font-size: 14px; margin: 20px 0 2px; letter-spacing: -0.01em; }
/* The hour that earned most, marked so the eye lands on it without hunting the column. */
tr.peak th, tr.peak td { background: var(--wash); }
.share { display: inline-block; min-width: 46px; font-variant-numeric: tabular-nums; }
td .meter { display: inline-block; width: 90px; vertical-align: middle; margin-left: 6px; }

.table-view { margin-top: 12px; }
.table-view summary { cursor: pointer; color: var(--text-secondary); font-size: 13px; }
.table-scroll { overflow-x: auto; max-height: 460px; overflow-y: auto; margin-top: 8px; }
.json { white-space: pre-wrap; color: var(--text-secondary); margin: 8px 0 0; }

/* ------------------------------------------------------------ deepdive provenance */

/* The computation strip on the deepdive header: a row of small cells, each carrying
 * one fact, border-divided rather than boxed individually. Ported from the visual
 * spec — the layout is theirs, the palette is ours. */
.prov {
  display: flex; flex-wrap: wrap; gap: 0;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); overflow: hidden;
}
.prov div {
  padding: 9px 15px; border-right: 1px solid var(--border);
  flex: 1 1 auto; min-width: 118px;
}
.prov div:last-child { border-right: 0; }
.prov b { display: block; font-family: var(--mono); font-size: 13px; font-weight: 500; margin-top: 3px; }

/* --------------------------------------------------------------------- share bar */

/* One row of a day's positive revenue, segmented by stream. `charts.share_bar`
 * renders it as an SVG, so ".seg" takes its fill from the same slot tokens every
 * other mark uses — this is not a second colour system beside `.bar`/`.mark`. */
.chart.sbar { height: 12px; }
.chart .seg { stroke: none; }
.chart .seg.s1 { fill: var(--series-1); } .chart .seg.s2 { fill: var(--series-2); }
.chart .seg.s3 { fill: var(--series-3); } .chart .seg.s4 { fill: var(--series-4); }
.chart .seg.s5 { fill: var(--series-5); } .chart .seg.s6 { fill: var(--series-6); }
.chart .seg.s7 { fill: var(--series-7); } .chart .seg.s8 { fill: var(--series-8); }

/* State of charge and a zero-reference line on the deepdive's stacked panels. SoC
 * still carries its slot's colour through `.sN`; this only thickens the stroke a
 * touch, since it is the one line on that panel and reads better a little heavier. */
.chart .line.soc { stroke-width: 1.6; }
.chart line.zero { stroke: var(--axis); stroke-width: 1; }

/* ----------------------------------------------------------- per-market interval table */

/* NULL, zero and negative cells in the per-MTU table are three different facts and
 * must not share a colour. NULL and zero both read muted — neither is a magnitude
 * worth drawing the eye to, and the two are told apart by the class name a test can
 * assert on, not by appearance. Only a negative figure (money going out) borrows the
 * critical token, which is otherwise reserved for a data problem, not a state. */
td.null, td.zero { color: var(--text-muted); }
td.neg            { color: var(--critical); }
td.tot            { font-weight: 600; border-left: 1px solid var(--border); }
tr.neg-row td.tot { color: var(--critical); }

/* A tall per-interval table with its header pinned — the primary view for a market
 * day's 96-odd rows, distinct from `.table-scroll`'s collapsed-by-default twin. */
.scroll {
  overflow-x: auto; overflow-y: auto; max-height: 560px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
}
.scroll thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }

@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .sidebar { position: static; height: auto; flex: none; border-right: none; border-bottom: 1px solid var(--border); }
  main { padding: 20px 16px 48px; }
}

@media (prefers-reduced-motion: reduce) {
  .chart .crosshair, .chart .band-wash { transition: none; }
}

/* ---------------------------------------------------------------------- login */

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { width: min(380px, calc(100vw - 32px)); margin: 0; }
.login-card h1 { margin: 14px 0 6px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.login-card label { display: flex; flex-direction: column; gap: 4px; width: 100%;
  font-size: 12px; color: var(--text-muted); }
.login-card input[type="password"] {
  font: inherit; font-size: 14px; padding: 7px 9px;
  background: var(--page); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 7px;
}
