/* Palette. Every hue here was measured, not chosen by eye: OKLab ΔE under
   simulated protanopia/deuteranopia, WCAG contrast against the surface it
   actually renders on. `tools/validate_palette.py` reruns the checks.

   The set this replaced failed them. In dark mode the old --strain (#6f9cf5)
   and --sleep (#a892ea) measured ΔE 1.7 under protanopia and 7.5 under normal
   vision, against a floor of 15 — the Strain and Sleep rings were the same
   colour at night for everyone. The old green/yellow/red measured 4.5. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f3f4f7;
  --text: #101215;
  --muted: #61656e;
  --border: #e6e8ec;
  --accent: #2a78d6;
  --error: #9e0015;
  --track: #eceef2;

  /* Identity hues. Three, and only three: Strain, Sleep and Fitness. They all
     appear on the day view at once, so they are validated as a trio all-pairs —
     worst CVD ΔE 9.2, worst normal-vision 24.0.

     Do not add violet back as a fourth. Blue and violet collapse in dark mode
     (#3987e5 vs #9085e9 measures CVD ΔE 1.9) — that pairing is the bug above,
     relocated. Anything new folds into an existing hue or wears a status band. */
  --strain: #eb6834;   /* also ATL: fatigue *is* accumulated strain */
  --sleep: #2a78d6;
  --fitness: #1baf7a;  /* also CTL */

  /* Status bands, for the scores that render a verdict rather than an identity:
     Recovery, Energy Bank, Fitness status. Reserved — never reused as a series
     hue. Worst CVD ΔE 8.0, which is the target boundary, so the text label that
     ships beside every band is load-bearing, not decoration. */
  --green: #4ba746;
  --yellow: #9d6d00;
  --red: #9e0015;
  --neutral: #8b9099;

  /* Sleep stages: a one-hue blue ordinal ramp anchored on --sleep, so the stage
     bar reads as part of the Sleep card. Monotone lightness, ΔL >= 0.06/step. */
  --stage-deep: #184f95;
  --stage-rem: #2a78d6;
  --stage-light: #86b6ef;

  --r-card: 18px;
  --r-inner: 12px;
  --shadow: 0 1px 2px rgb(16 18 21 / 0.04), 0 8px 24px -12px rgb(16 18 21 / 0.10);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0c0e;
    --surface: #16181c;
    --surface-2: #1d2026;
    --text: #f2f3f5;
    --muted: #9aa0aa;
    --border: #262a31;
    --accent: #3987e5;
    --error: #d34442;
    --track: #242830;

    /* Stepped for the dark surface, not flipped from the light values — each
       re-validated against #16181c rather than assumed to carry over. */
    --strain: #d95926;
    --sleep: #3987e5;
    --fitness: #199e70;

    --green: #1d7e1a;
    --yellow: #bd8b31;
    --red: #d34442;
    --neutral: #6b727c;

    --stage-deep: #184f95;
    --stage-rem: #2a78d6;
    --stage-light: #86b6ef;

    /* A black shadow on a near-black page is invisible and the cards dissolve
       into the background. Dark mode gets a top highlight instead. */
    --shadow: 0 1px 2px rgb(0 0 0 / 0.5), inset 0 1px 0 rgb(255 255 255 / 0.04);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.center {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.page { max-width: 64rem; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.login { width: min(22rem, 100%); }
.login h1 { margin: 0 0 1.25rem; font-size: 1.25rem; font-weight: 600; }

.field {
  width: 100%;
  padding: 0.7rem 0.85rem;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
}

.field:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  margin-top: 0.75rem;
  width: 100%;
  padding: 0.7rem 1rem;
  font: inherit;
  font-weight: 600;
  color: var(--bg);
  background: var(--accent);
  border: 0;
  border-radius: 9px;
  cursor: pointer;
}

button:hover { filter: brightness(1.07); }

.hint { margin: 0.9rem 0 0; font-size: 0.8125rem; color: var(--muted); }

.error {
  margin: 0 0 1rem;
  font-size: 0.875rem;
  color: var(--error);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 600; }

button.link {
  width: auto;
  margin: 0;
  padding: 0;
  font-weight: 400;
  font-size: 0.875rem;
  color: var(--muted);
  background: none;
}

a.brand { color: inherit; text-decoration: none; }

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


/* --- day navigator ---------------------------------------------------- */

.daynav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.daynav__center { text-align: center; }

.daynav__date {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.daynav__meta {
  margin: 0.15rem 0 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

.daynav__meta a { color: var(--muted); }

.daynav__arrow {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 2.5rem; height: 2.5rem;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--text);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
}

.daynav__arrow:hover { border-color: var(--accent); }

/* Today's right-hand arrow: present so the layout stays centred, but inert. */
.daynav__arrow--off {
  color: var(--border);
  border-style: dashed;
  cursor: default;
}

.daynav__arrow--off:hover { border-color: var(--border); }

.daynav__jump {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.daynav__jump input {
  font: inherit;
  font-size: 0.8125rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.25rem 0.5rem;
}

.tag {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  font-size: 0.75rem;
  color: var(--bg);
  background: var(--accent);
  border-radius: 999px;
}


/* --- gauges ------------------------------------------------------------ */

.gauges {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

@media (max-width: 44rem) {
  .gauges { grid-template-columns: 1fr; }
}

.gauge {
  display: grid;
  justify-items: center;
  gap: 0.35rem;
  padding: 1.5rem 1rem 1.25rem;
  color: inherit;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
}

.gauge:hover { border-color: var(--dial, var(--accent)); }

.gauge:focus-visible {
  outline: 2px solid var(--dial, var(--accent));
  outline-offset: 2px;
}

/* The ring and the number share one grid cell so the readout sits inside the
   arc without absolute positioning. */
.gauge__ring,
.gauge__readout { grid-area: 1 / 1; }

.gauge__ring {
  width: 9rem; height: 9rem;
  /* Start the arc at 12 o'clock rather than 3. */
  transform: rotate(-90deg);
}

.gauge__track,
.gauge__fill {
  fill: none;
  stroke-width: 9;
}

.gauge__track { stroke: var(--track); }

.gauge__fill {
  stroke: var(--dial, var(--neutral));
  stroke-linecap: round;
  transition: stroke-dasharray 0.4s ease;
}

.gauge__readout {
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
}

/* Proportional figures, deliberately. Tabular numerals exist to make columns
   line up; on a big standalone number they just look gappy. --track/--detail
   tables keep tabular-nums where alignment actually matters. */
.gauge__value {
  font-size: 2.125rem;
  font-weight: 650;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.gauge__label {
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.gauge__sub {
  font-size: 0.8125rem;
  color: var(--muted);
}

/* The generated comment is the link affordance the rest of the card inherits. */
.gauge__comment {
  font-size: 0.8125rem;
  text-align: center;
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 3px;
}

.gauge:hover .gauge__comment { text-decoration-color: var(--dial, var(--accent)); }

.gauge--strain  { --dial: var(--strain); }
.gauge--sleep   { --dial: var(--sleep); }
.gauge--fitness { --dial: var(--fitness); }
.gauge--green   { --dial: var(--green); }
.gauge--yellow  { --dial: var(--yellow); }
.gauge--red     { --dial: var(--red); }
.gauge--neutral { --dial: var(--neutral); }


/* --- summary strip ----------------------------------------------------- */

.strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

.strip__item {
  flex: 1 1 7rem;
  padding: 0.75rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-inner);
  box-shadow: var(--shadow);
}

.strip__label,
.figure__label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
}

.strip__value,
.figure__value {
  display: block;
  font-size: 1.15rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.strip__note { font-size: 0.6875rem; color: var(--muted); }


/* --- detail pages ------------------------------------------------------ */

.crumb { margin: 0 0 1rem; font-size: 0.8125rem; }

.detail {
  margin-bottom: 1.25rem;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
}

.detail__title { margin: 0 0 0.5rem; font-size: 1.35rem; }
.detail__sub { margin: 1.25rem 0 0.6rem; font-size: 0.95rem; }
.detail__sub:first-child { margin-top: 0; }
.detail__lede { margin: 0 0 1rem; color: var(--muted); font-size: 0.9375rem; }
.detail__note { margin: 0.75rem 0 0; font-size: 0.8125rem; color: var(--muted); }

.figures {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
  gap: 0.75rem;
}

.figure {
  padding: 0.65rem 0.85rem;
  background: var(--surface-2);
  border-radius: var(--r-inner);
}

/* Wide tables scroll inside their own box; the page never scrolls sideways. */
.table-scroll { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.table th,
.table td {
  padding: 0.45rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table th { font-size: 0.75rem; color: var(--muted); font-weight: 600; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .wrap { white-space: normal; min-width: 12rem; }
.table tfoot th { border-bottom: 0; font-size: 0.875rem; color: var(--text); }

.row--muted td { color: var(--muted); }

.row--reason td {
  padding-top: 0;
  font-size: 0.75rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.muted { color: var(--muted); }

.chip {
  display: inline-block;
  padding: 0.05rem 0.4rem;
  font-size: 0.75rem;
  border-radius: 999px;
  color: var(--bg);
}

.chip--green  { background: var(--green); }
.chip--yellow { background: var(--yellow); }
.chip--red    { background: var(--red); }


/* --- 30-day bar strip --------------------------------------------------- */

.bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 7rem;
  margin-top: 0.5rem;
}

.bars__slot {
  flex: 1 1 0;
  display: flex;
  align-items: flex-end;
  height: 100%;
}

.bars__bar {
  width: 100%;
  min-height: 2px;
  background: var(--strain);
  border-radius: 2px 2px 0 0;
}

.bars__bar--empty { background: var(--border); }
.bars__bar--green  { background: var(--green); }
.bars__bar--yellow { background: var(--yellow); }
.bars__bar--red    { background: var(--red); }
.bars__bar--fitbit { background: var(--sleep); }
.bars__bar--garmin { background: var(--neutral); }

/* Recovery's 30-day strip used to paint every bar green/amber/red. Thirty
   adjacent status-coloured bars with no per-bar label is precisely the case
   those colours fail: they clear the CVD floor but not the target, so they are
   only legal beside a text label, and a bar strip has none. It now draws in one
   ink with threshold rules at the band edges — which is also easier to read,
   since you can see where a day sits rather than only which bucket it landed
   in. See views.recovery_detail. */
.bars--ruled { position: relative; }

.bars__rule {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px dashed var(--border);
  pointer-events: none;
}

.bars__rule span {
  position: absolute;
  right: 0;
  top: -0.9em;
  font-size: 0.6875rem;
  color: var(--muted);
}

.bars__slot--current .bars__bar { outline: 2px solid var(--text); outline-offset: 1px; }

.bars__axis {
  display: flex;
  justify-content: space-between;
  margin-top: 0.3rem;
  font-size: 0.6875rem;
  color: var(--muted);
}


/* --- sleep stages ------------------------------------------------------- */

.stages {
  display: flex;
  height: 1.5rem;
  overflow: hidden;
  border-radius: 6px;
  background: var(--track);
}

.stages__seg--deep  { background: var(--stage-deep); }
.stages__seg--rem   { background: var(--stage-rem); }
.stages__seg--light { background: var(--stage-light); }
.stages__seg--awake { background: var(--border); }

/* A hairline of surface between segments so adjacent stages stay countable
   without relying on the hue difference alone. */
.stages__seg + .stages__seg { box-shadow: inset 2px 0 0 var(--surface); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  margin: 0.6rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.8125rem;
  color: var(--muted);
}

.legend__item { display: flex; align-items: center; gap: 0.4rem; }

.legend__swatch {
  width: 0.7rem; height: 0.7rem;
  border-radius: 3px;
  background: var(--border);
}

.legend__swatch--deep  { background: var(--stage-deep); }
.legend__swatch--rem   { background: var(--stage-rem); }
.legend__swatch--light { background: var(--stage-light); }
.legend__swatch--awake { background: var(--border); }


/* --- notices ------------------------------------------------------------ */

.notice {
  margin: 1rem 0;
  padding: 0.8rem 1rem;
  font-size: 0.875rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.notice--warn {
  color: var(--text);
  border-left: 3px solid var(--yellow);
}


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

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 0.875rem;
  margin-top: 0.875rem;
}

.card-metric {
  display: grid;
  align-content: start;
  gap: 0.35rem;
  padding: 1.25rem;
  color: inherit;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
}

.card-metric:hover { border-color: var(--dial, var(--accent)); }

.card-metric:focus-visible {
  outline: 2px solid var(--dial, var(--accent));
  outline-offset: 2px;
}

.card-metric--fitness { --dial: var(--fitness); }
.card-metric--body    { --dial: var(--sleep); }
.card-metric--food    { --dial: var(--strain); }

.card-metric__label {
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.card-metric__value {
  font-size: 1.75rem;
  font-weight: 620;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.card-metric__unit {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--muted);
}

.card-metric__sub { font-size: 0.8125rem; color: var(--muted); }

.card-metric__comment {
  margin-top: 0.15rem;
  font-size: 0.8125rem;
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 3px;
}

.card-metric:hover .card-metric__comment {
  text-decoration-color: var(--dial, var(--accent));
}

/* A status word, never a bare colour. The status hues clear the CVD floor but
   not the target, so the text is what carries the reading. */
.statuschip {
  justify-self: start;
  display: inline-block;
  padding: 0.1rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  border-radius: 999px;
  background: var(--neutral);
}

.statuschip--green  { background: var(--green); }
.statuschip--yellow { background: var(--yellow); }
.statuschip--red    { background: var(--red); }


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

.chart { margin-top: 0.75rem; }

.chart__svg { display: block; width: 100%; height: auto; }

.chart__line {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart__dot { stroke: var(--surface); stroke-width: 2; }

.chart__grid { stroke: var(--border); stroke-width: 1; }

.chart__zero { stroke: var(--neutral); stroke-width: 1; stroke-dasharray: 3 3; }

.chart__slot { fill: transparent; }
.chart__slot:hover { fill: var(--text); fill-opacity: 0.04; }

.chart__tick {
  font-size: 11px;
  fill: var(--muted);
}

.series--ctl    { stroke: var(--fitness); fill: var(--fitness); }
.series--atl    { stroke: var(--strain);  fill: var(--strain); }
.series--weight { stroke: var(--sleep);   fill: var(--sleep); }

.chart__area--up   { fill: var(--fitness); fill-opacity: 0.22; }
.chart__area--down { fill: var(--red);     fill-opacity: 0.22; }

.legend__swatch--ctl { background: var(--fitness); }
.legend__swatch--atl { background: var(--strain); }


/* --- energy bank hero ---------------------------------------------------- */

.hero {
  display: grid;
  gap: 0.6rem;
  /* Sits below the gauge row, so the gap goes above it. The gap to the cards
     below comes from .cards' own margin-top. */
  margin-top: 0.875rem;
  padding: 1.35rem 1.5rem;
  color: inherit;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
}

.hero:hover { border-color: var(--dial, var(--accent)); }

.hero:focus-visible {
  outline: 2px solid var(--dial, var(--accent));
  outline-offset: 2px;
}

.hero--green   { --dial: var(--green); }
.hero--yellow  { --dial: var(--yellow); }
.hero--red     { --dial: var(--red); }
.hero--neutral { --dial: var(--neutral); }

.hero__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.hero__label {
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.hero__value {
  font-size: 2.75rem;
  font-weight: 660;
  line-height: 1;
  letter-spacing: -0.03em;
}

.hero__track {
  display: block;
  height: 0.625rem;
  background: var(--track);
  border-radius: 999px;
  overflow: hidden;
}

.hero__fill {
  display: block;
  height: 100%;
  background: var(--dial, var(--neutral));
  border-radius: 999px;
  transition: width 0.4s ease;
}

.hero__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.8125rem;
}

/* The band word, not the bar colour, is what carries the verdict. */
.hero__band { font-weight: 600; }

.hero__comment {
  color: var(--muted);
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 3px;
}

.hero:hover .hero__comment { text-decoration-color: var(--dial, var(--accent)); }

/* Macro segments reuse the identity hues rather than adding new ones: three
   more colours on this page would put the palette past what stays separable. */
.stages__seg--protein { background: var(--fitness); }
.stages__seg--carbs   { background: var(--sleep); }
.stages__seg--fat     { background: var(--strain); }

.legend__swatch--protein { background: var(--fitness); }
.legend__swatch--carbs   { background: var(--sleep); }
.legend__swatch--fat     { background: var(--strain); }

/* Inside a card the stack is a supporting detail, not the subject. */
.card-metric .stages { height: 0.5rem; margin-top: 0.35rem; }
.card-metric .legend { gap: 0.25rem 0.75rem; font-size: 0.75rem; }
