/* Coach web face — design system.
   Palette from the dataviz skill's validated reference instance.
   Roles are defined once here; light/dark swap in one place. */

:root {
  color-scheme: light;
  --page:        #f9f9f7;
  --surface:     #fcfcfb;
  --surface-2:   #f2f2ee;
  --ink:         #0b0b0b;
  --ink-2:       #52514e;
  --muted:       #898781;
  --grid:        #e1e0d9;
  --baseline:    #c3c2b7;
  --border:      rgba(11, 11, 11, 0.10);
  --shadow:      0 1px 2px rgba(11,11,11,.04), 0 8px 24px rgba(11,11,11,.05);

  --series-1:    #2a78d6;   /* blue  — primary / trend / deficit */
  --series-1-wash: rgba(42, 120, 214, 0.10);
  --series-2:    #008300;   /* green — goal / target */
  --over:        #e34948;   /* warm  — over allowance (erases deficit) */
  --over-wash:   rgba(227, 73, 72, 0.10);

  --good:        #0ca30c;
  --warning:     #fab219;
  --serious:     #ec835a;
  --critical:    #d03b3b;
  --delta-good:  #006300;
  --delta-bad:   #b3261e;

  --r:   16px;   /* card radius */
  --r-sm: 10px;
  --gap: 14px;
  --maxw: 980px;
}

:root[data-theme="dark"],
:root[data-theme="auto"] {
  /* auto falls through to the media query below for dark */
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] { color-scheme: dark; }
  :root[data-theme="auto"] {
    --page:      #0d0d0d;
    --surface:   #1a1a19;
    --surface-2: #232321;
    --ink:       #ffffff;
    --ink-2:     #c3c2b7;
    --muted:     #898781;
    --grid:      #2c2c2a;
    --baseline:  #383835;
    --border:    rgba(255, 255, 255, 0.10);
    --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
    --series-1:  #3987e5;
    --series-1-wash: rgba(57, 135, 229, 0.14);
    --series-2:  #008300;
    --over:      #e66767;
    --over-wash: rgba(230, 103, 103, 0.14);
    --good:      #0ca30c;
    --delta-good:#0ca30c;
    --delta-bad: #e66767;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page:      #0d0d0d;
  --surface:   #1a1a19;
  --surface-2: #232321;
  --ink:       #ffffff;
  --ink-2:     #c3c2b7;
  --muted:     #898781;
  --grid:      #2c2c2a;
  --baseline:  #383835;
  --border:    rgba(255, 255, 255, 0.10);
  --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  --series-1:  #3987e5;
  --series-1-wash: rgba(57, 135, 229, 0.14);
  --series-2:  #008300;
  --over:      #e66767;
  --over-wash: rgba(230, 103, 103, 0.14);
  --good:      #0ca30c;
  --delta-good:#0ca30c;
  --delta-bad: #e66767;
}

* { box-sizing: border-box; }

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

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

.app {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 2px 18px;
}
.topbar__title { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.wordmark {
  font-size: 20px; font-weight: 700; letter-spacing: -0.02em;
}
.topbar__date { color: var(--muted); font-size: 13px; white-space: nowrap; }
.topbar__right { display: flex; align-items: center; gap: 10px; }

.theme-toggle {
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; color: var(--ink-2);
  transition: background .15s, color .15s;
}
.theme-toggle:hover { color: var(--ink); }
.theme-toggle__icon { width: 15px; height: 15px; border-radius: 50%;
  background: radial-gradient(circle at 32% 32%, var(--ink-2) 48%, transparent 49%),
              conic-gradient(from 210deg, var(--ink-2) 0 50%, transparent 50%);
  box-shadow: inset 0 0 0 1.5px var(--ink-2); }

/* ---------- Pills / status ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; letter-spacing: .02em;
  padding: 5px 11px 5px 9px; border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.pill__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill--ok    { color: var(--delta-good); } .pill--ok    .pill__dot { background: var(--good); }
.pill--watch { color: #8a6d00; }          .pill--watch .pill__dot { background: var(--warning); }
.pill--act   { color: var(--critical); }  .pill--act   .pill__dot { background: var(--critical); }
:root[data-theme="dark"] .pill--watch,
:root[data-theme="auto"] .pill--watch { color: var(--warning); }

/* ---------- Cards & grid ---------- */
.grid { display: grid; gap: var(--gap); }
.cols-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 720px) { .cols-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card__head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.card__title { font-size: 13px; font-weight: 600; color: var(--ink-2); letter-spacing: .01em; }
.card__meta  { font-size: 12px; color: var(--muted); }
.card__note  { font-size: 12.5px; color: var(--muted); margin-top: 12px; line-height: 1.5; }

.block { margin-top: var(--gap); }

/* ---------- Hero ---------- */
.hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 22px 20px 20px;
  display: grid; grid-template-columns: 1fr auto; gap: 18px; align-items: center;
}
@media (max-width: 560px) { .hero { grid-template-columns: 1fr; } }
.hero__label { font-size: 12.5px; color: var(--muted); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.hero__value { font-size: 54px; font-weight: 650; letter-spacing: -0.03em; line-height: 1; margin: 6px 0 2px; }
.hero__value .unit { font-size: 24px; font-weight: 500; color: var(--ink-2); letter-spacing: 0; margin-left: 4px; }
.hero__sub { font-size: 13.5px; color: var(--ink-2); }
.hero__sub b { color: var(--ink); font-weight: 650; }

.hero__meter { min-width: 210px; }
.meter__row { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); margin-bottom: 7px; }
.meter__track {
  position: relative; height: 10px; border-radius: 999px;
  background: var(--surface-2); overflow: hidden; border: 1px solid var(--border);
}
.meter__fill { position: absolute; inset: 0 auto 0 0; border-radius: 999px;
  background: linear-gradient(90deg, var(--series-1), color-mix(in oklab, var(--series-1) 70%, var(--series-2))); }
.meter__cap { display: flex; justify-content: space-between; margin-top: 7px; font-size: 12px; }
.meter__cap .now { color: var(--ink); font-weight: 650; }
.meter__cap .goal { color: var(--series-2); font-weight: 650; }

/* ---------- KPI stat tiles ---------- */
.kpis { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 720px) { .kpis { grid-template-columns: 1fr 1fr; } }
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow);
  padding: 15px 15px 13px; display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.tile__label { font-size: 12px; color: var(--muted); font-weight: 600; }
.tile__value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; }
.tile__value .unit { font-size: 14px; font-weight: 500; color: var(--ink-2); margin-left: 3px; }
.tile__delta { font-size: 12.5px; font-weight: 600; display: flex; align-items: center; gap: 5px; }
.tile__delta.up   { color: var(--delta-good); }
.tile__delta.down { color: var(--delta-bad); }
.tile__delta.flat { color: var(--muted); }
.tile__spark { margin-top: 8px; height: 30px; }
.tile__foot { font-size: 11.5px; color: var(--muted); }
.tile.calib .tile__value { color: var(--muted); font-size: 20px; font-weight: 600; }

/* ---------- Charts ---------- */
.chart { width: 100%; display: block; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.axis text, .tick text { fill: var(--muted); font-size: 11px; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--baseline); stroke-width: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; font-size: 12.5px; color: var(--ink-2); }
.legend__item { display: inline-flex; align-items: center; gap: 7px; }
.legend__key { width: 14px; height: 3px; border-radius: 2px; background: var(--muted); }
.legend__key.dot { width: 9px; height: 9px; border-radius: 50%; }
.legend__key.dash { background: repeating-linear-gradient(90deg, var(--series-2) 0 5px, transparent 5px 9px); }

/* ---------- Range control (segmented presets + custom dates) ---------- */
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 2px 0 14px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; color: var(--ink-2); font: inherit; font-size: 12.5px; font-weight: 600; line-height: 1; padding: 6px 12px; border-radius: 999px; cursor: pointer; }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--series-1); color: #fff; }
.custom-range { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 12.5px; }
.custom-range__dash { color: var(--muted); }
.custom-range input[type="date"] { font: inherit; font-size: 12px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--ink); color-scheme: light dark; }
.empty { padding: 48px 10px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- Readiness ---------- */
.ready-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 620px) { .ready-grid { grid-template-columns: 1fr 1fr; } }
.metric { border: 1px solid var(--border); border-radius: var(--r-sm); padding: 11px 12px; background: var(--surface); }
.metric__label { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.metric__value { font-size: 19px; font-weight: 650; letter-spacing: -0.01em; }
.metric__value .unit { font-size: 12px; color: var(--ink-2); font-weight: 500; margin-left: 2px; }
.metric__delta { font-size: 11.5px; font-weight: 600; }
.metric__delta.good { color: var(--delta-good); } .metric__delta.bad { color: var(--delta-bad); } .metric__delta.neutral { color: var(--muted); }

/* ---------- Tooltip ---------- */
.tooltip {
  position: fixed; z-index: 40; pointer-events: none;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 9px 11px; font-size: 12.5px; min-width: 120px;
  transform: translate(-50%, -108%);
}
.tooltip__date { color: var(--muted); font-size: 11.5px; margin-bottom: 5px; }
.tooltip__row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.tooltip__row .k { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.tooltip__row .v { font-weight: 650; font-variant-numeric: tabular-nums; }
.tooltip__key { width: 9px; height: 9px; border-radius: 50%; }
.crosshair { stroke: var(--baseline); stroke-width: 1; }
.focus-dot { stroke: var(--surface); stroke-width: 2; }

/* ---------- Table (a11y: every value has a non-color home) ---------- */
details.table { margin-top: 12px; }
details.table > summary { cursor: pointer; font-size: 12.5px; color: var(--ink-2); }
table.data { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 12.5px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { text-align: right; padding: 5px 8px; border-bottom: 1px solid var(--border); }
table.data th:first-child, table.data td:first-child { text-align: left; color: var(--ink-2); }
table.data thead th { color: var(--muted); font-weight: 600; }

/* ---------- Misc ---------- */
.loading, .error { padding: 60px 10px; text-align: center; color: var(--muted); }
.error { color: var(--critical); }
.foot { margin-top: 26px; text-align: center; font-size: 12px; color: var(--muted); }
.foot__sep { margin: 0 8px; }
.hint { font-size: 12px; color: var(--muted); }
.banner {
  border: 1px solid var(--border); background: var(--surface-2);
  border-radius: var(--r-sm); padding: 11px 13px; font-size: 12.5px; color: var(--ink-2);
  display: flex; gap: 9px; align-items: flex-start; margin-bottom: var(--gap);
}
.banner b { color: var(--ink); }

@media (prefers-reduced-motion: no-preference) {
  .tile, .card, .hero { transition: box-shadow .2s; }
}
