/* ═══════════════════════════════════════════════════════════════════
   wbal.io APP LAYER: dark everywhere in the signed-in app
   ───────────────────────────────────────────────────────────────────
   Loaded after style.css (and after a page's own <style>) on the
   signed-in pages only: app.html, tt-planner.html, threshold.html,
   account.html, coach.html, and the share page e.html. Public pages
   never load it and stay on the warm paper look of site.css.

   How it works: style.css and the page styles colour almost everything
   through a handful of older names (--bg, --white, --text, --muted,
   --border, --blue, --blue-light). This file points those at the dark
   ramp in tokens.css, and points --blue at the current tool's accent,
   so existing rules turn dark without being rewritten. What follows
   that is the shell (header, page header, About drawer), the layout
   primitives and the figure components the redesign builds on, then
   fixes for the light colours some rules still hard-code.

   See DESIGN-PLAN.md. Components are shown on /components.html.
   ═══════════════════════════════════════════════════════════════════ */

/* ── 1. The dark ramp under the old names ─────────────────────────── */
:root {
  color-scheme: dark;
  --bg:         var(--surface-0);
  --white:      var(--surface-1);
  --text:       var(--fg);
  --muted:      var(--fg-lo);
  --border:     var(--line);
  --gray-bg:    var(--surface-0);
  --gray-border: var(--line);
  --gray-text:  var(--fg);
  --gray-muted: var(--fg-lo);
  --paper:      var(--surface-1);
  --soft:       var(--line);
  --ink:        var(--fg);
  --ink-mid:    var(--fg-lo);
  --surface-page:  var(--surface-0);
  --surface-card:  var(--surface-1);
  --surface-paper: var(--surface-1);
  --border-hairline: var(--line);
  --red:        #F87171;
  --red-tint:   rgba(248, 113, 113, .12);
  --success:    #4ADE80;
  --success-tint: rgba(74, 222, 128, .12);
  --shadow-card:  0 1px 0 rgba(255,255,255,.02), 0 10px 28px rgba(0,0,0,.28);
  --shadow-hover: 0 1px 0 rgba(255,255,255,.03), 0 14px 34px rgba(0,0,0,.36);
  --shadow-btn:   0 6px 16px rgba(0,0,0,.35);

  /* The light-surface tool colours, re-pointed at their dark-surface
     versions, so every older rule that names var(--tool-diary) and so on
     reads on the dark ramp too. */
  --tool-analyse:   var(--tool-analyse-hi);
  --tool-cp:        var(--tool-cp-hi);
  --tool-calc:      var(--tool-calc-hi);
  --tool-diary:     var(--tool-diary-hi);
  --tool-planner:   var(--tool-planner-hi);
  --tool-coach:     var(--tool-coach-hi);
  --tool-account:   var(--tool-account-hi);
  --tool-threshold: var(--tool-threshold-hi);

  /* The current tool's accent. Set per page and per tab below. */
  --accent: var(--tool-analyse-hi);

  /* Read by ui.js (dialogs, toasts) and chart-theme.js. Pages without this
     file leave them unset and keep their light defaults. */
  --ui-surface: var(--surface-1);
  --ui-raised:  var(--surface-2);
  --ui-fg:      var(--fg-hi);
  --ui-muted:   var(--fg-lo);
  --ui-line:    var(--line-strong);
  --ui-accent:  var(--accent);
  --ui-on-accent: var(--surface-0);
  --ui-choice:  color-mix(in srgb, var(--accent) 12%, transparent);
  --chart-ink:  var(--fg-lo);
  --chart-grid: rgba(141, 160, 184, .14);
  --chart-tooltip: var(--surface-3);
}

/* Each surface names its tool; everything inside follows its accent. */
body[data-page="planner"]   { --accent: var(--tool-planner-hi); }
body[data-page="threshold"] { --accent: var(--tool-threshold-hi); }
body[data-page="account"]   { --accent: var(--tool-account-hi); }
body[data-page="coach"]     { --accent: var(--tool-coach-hi); }
body[data-page="share"]     { --accent: var(--tool-analyse-hi); }
#tab-analyse      { --accent: var(--tool-analyse-hi); }
#tab-cp-determine { --accent: var(--tool-cp-hi); }
#tab-calculator   { --accent: var(--tool-calc-hi); }
#tab-diary        { --accent: var(--tool-diary-hi); }

body,
body[data-page],
#tab-analyse, #tab-cp-determine, #tab-calculator, #tab-diary {
  --blue:       var(--accent);
  --blue-mid:   var(--accent);
  --blue-dark:  color-mix(in srgb, var(--accent) 70%, #000);
  --blue-light: color-mix(in srgb, var(--accent) 12%, transparent);
  --ui-accent:  var(--accent);
  --ui-choice:  color-mix(in srgb, var(--accent) 12%, transparent);
}

/* One page background for every tool: the dark ramp with a faint wash of
   the tool's colour from the top. Replaces the per-tool light papers. */
body, body[data-page] {
  background:
    radial-gradient(90% 60% at 50% -10%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 60%),
    var(--surface-0);
  background-attachment: fixed;
  background-size: auto;
  color: var(--fg);
}
#tab-analyse, #tab-cp-determine, #tab-calculator, #tab-diary {
  background:
    radial-gradient(90% 520px at 50% 0, color-mix(in srgb, var(--accent) 8%, transparent), transparent 70%),
    linear-gradient(color-mix(in srgb, var(--accent) 3%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--accent) 3%, transparent) 1px, transparent 1px),
    var(--surface-0);
  background-size: 100% 100%, 48px 48px, 48px 48px, auto;
  min-height: calc(100vh - 96px);
}

/* ── 2. Shell: the two-row header ─────────────────────────────────── */
.app-header.site-header {
  background: linear-gradient(180deg, #050C17 0%, #08121F 100%);
  border-bottom: 1px solid var(--line);
  box-shadow: inset 0 -2px 0 var(--accent), 0 8px 24px rgba(0,0,0,.35);
}
body[data-tab="analyse"]      .app-header.site-header { box-shadow: inset 0 -2px 0 var(--tool-analyse-hi), 0 8px 24px rgba(0,0,0,.35); }
body[data-tab="cp-determine"] .app-header.site-header { box-shadow: inset 0 -2px 0 var(--tool-cp-hi), 0 8px 24px rgba(0,0,0,.35); }
body[data-tab="calculator"]   .app-header.site-header { box-shadow: inset 0 -2px 0 var(--tool-calc-hi), 0 8px 24px rgba(0,0,0,.35); }
body[data-tab="diary"]        .app-header.site-header { box-shadow: inset 0 -2px 0 var(--tool-diary-hi), 0 8px 24px rgba(0,0,0,.35); }

.app-header .header-inner {
  max-width: none;
  height: auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
}
.app-header .header-top {
  display: flex;
  align-items: center;
  gap: 18px;
  height: 52px;
}
.app-header .header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 20px;
}
.app-header .header-link {
  color: var(--fg-lo);
  font-size: 13px;
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
}
.app-header .header-link:hover { color: var(--fg-hi); }
.app-header .header-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 44px;
  overflow-x: auto;
  scrollbar-width: none;
}
.app-header .header-nav::-webkit-scrollbar { display: none; }
.app-header .tab-nav {
  margin-left: 0;
  display: flex;
  gap: 4px;
  padding: 0;
  border: none;
  overflow: visible;
  width: auto;
}
.app-header .tool-links {
  display: flex;
  gap: 4px;
  padding-left: 10px;
  margin-left: 6px;
  border-left: 1px solid var(--line);
}

/* A tool in the nav: a dot in its colour, lit as a pill when current. */
.app-header .tab-btn,
.app-header .tool-link {
  --dot: var(--fg-lo);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 99px;
  border: 1px solid transparent;
  background: none;
  color: var(--fg-lo);
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.app-header .tab-btn::before,
.app-header .tool-link::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
  flex: none;
  background: var(--dot);
  box-shadow: 0 0 8px color-mix(in srgb, var(--dot) 60%, transparent);
}
.app-header [data-tab="analyse"],      .app-header .tool-link[data-tool="analyse"]   { --dot: var(--tool-analyse-hi); }
.app-header [data-tab="cp-determine"], .app-header .tool-link[data-tool="cp"]        { --dot: var(--tool-cp-hi); }
.app-header [data-tab="calculator"],   .app-header .tool-link[data-tool="calc"]      { --dot: var(--tool-calc-hi); }
.app-header [data-tab="diary"],        .app-header .tool-link[data-tool="diary"]     { --dot: var(--tool-diary-hi); }
.app-header .tool-link[data-tool="planner"]   { --dot: var(--tool-planner-hi); }
.app-header .tool-link[data-tool="threshold"] { --dot: var(--tool-threshold-hi); }
.app-header .tool-link[data-tool="coach"]     { --dot: var(--tool-coach-hi); }
.app-header .tab-btn:hover,
.app-header .tool-link:hover { color: var(--fg-hi); background: rgba(148,163,184,.10); }
.app-header .tab-btn.active,
.app-header .tool-link[aria-current="page"] {
  color: var(--fg-hi);
  background: color-mix(in srgb, var(--dot) 16%, transparent);
  border-color: color-mix(in srgb, var(--dot) 45%, transparent);
}
/* style.css lights the active tab as a solid pill; the outline version
   above replaces it so every tool's colour reads the same way. */
body[data-tab] .app-header .tab-btn.active { color: var(--fg-hi); background: color-mix(in srgb, var(--dot) 16%, transparent); }
.app-header .tab-btn.active::before { background: var(--dot) !important; box-shadow: 0 0 10px var(--dot); }
.app-header .tab-btn .pro-badge,
.app-header .tab-btn .tab-badge {
  background: rgba(148,163,184,.14);
  color: var(--fg-lo);
  border: none;
  font-size: 9.5px;
  margin-left: 0;
}

.nav-toggle {
  display: none;
  margin-left: auto;
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--fg-hi);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.nav-toggle svg { width: 18px; height: 18px; }

/* Below 768 px the actions and the tool nav fold into a menu. */
@media (max-width: 767px) {
  .app-header .header-inner { padding: 0 16px; }
  .app-header .header-top { height: 56px; }
  .nav-toggle { display: inline-flex; }
  .app-header .header-actions,
  .app-header .header-nav { display: none; }
  .app-header.menu-open .header-nav,
  .app-header.menu-open .header-actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    height: auto;
    gap: 4px;
    padding: 6px 0 12px;
  }
  .app-header.menu-open .header-nav { border-top: 1px solid var(--line); padding-top: 12px; }
  /* The account links wrap onto their own row under the brand. */
  .app-header.menu-open .header-top { flex-wrap: wrap; height: auto; min-height: 56px; padding-top: 8px; }
  .app-header.menu-open .header-actions {
    order: 3; width: 100%; flex-direction: row; gap: 22px;
    border-top: 1px solid var(--line); margin: 8px 0 0; padding: 4px 0;
  }
  .app-header.menu-open .header-actions .header-link { padding: 10px 0; font-size: 15px; }
  .app-header .tab-nav,
  .app-header .tool-links { flex-direction: column; gap: 4px; padding: 0; margin: 0; border: none; }
  .app-header .tool-links { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 4px; }
  .app-header .tab-btn,
  .app-header .tool-link { padding: 11px 14px; font-size: 15px; border-radius: 10px; }
}

/* ── 3. Page header: the slim masthead and the About drawer ───────── */
.masthead {
  --mast-accent: var(--accent);
  min-height: 0;
  padding: 18px 26px;
  border-radius: 14px;
  align-items: center;
  background:
    radial-gradient(80% 220% at 100% 0%, color-mix(in srgb, var(--mast-accent) 22%, transparent) 0%, transparent 60%),
    linear-gradient(110deg, var(--surface-1) 45%, color-mix(in srgb, var(--mast-accent) 14%, var(--surface-1)) 100%);
  border: 1px solid color-mix(in srgb, var(--mast-accent) 30%, var(--line));
  box-shadow: 0 10px 30px rgba(0,0,0,.30);
  gap: 18px;
}
.masthead .mast-copy { max-width: none; flex: 1 1 auto; min-width: 0; }
.masthead .mast-eyebrow { margin-bottom: 4px; font-size: 11px; }
.masthead .mast-title { font-size: clamp(22px, 2.4vw, 28px); margin: 0; }
.masthead .mast-sub { font-size: 13.5px; color: var(--fg-lo); margin-top: 4px; max-width: 80ch; }
.masthead .mast-motif { height: 150%; max-height: 120px; opacity: .45; bottom: -18px; }
.masthead.mast-slim .mast-sub { display: none; }

.mast-about {
  position: relative;
  z-index: 2;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 8px 8px;
  border-radius: 99px;
  border: 1px solid color-mix(in srgb, var(--mast-accent) 40%, var(--line));
  background: color-mix(in srgb, var(--surface-0) 70%, transparent);
  color: var(--fg);
  font: 500 13px/1 var(--font-ui);
  cursor: pointer;
  backdrop-filter: blur(6px);
}
.mast-about:hover { color: var(--fg-hi); border-color: var(--mast-accent); }
.mast-about .q {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--mast-accent);
  color: var(--surface-0);
  font-weight: 700;
  font-size: 13px;
}
@media (max-width: 720px) {
  .masthead { padding: 14px 16px; }
  .mast-about .label { display: none; }
  .mast-about { padding: 6px; }
}

.about-drawer-backdrop {
  position: fixed; inset: 0; z-index: 2900;
  background: rgba(2, 6, 14, .6);
  opacity: 0; transition: opacity .2s;
}
.about-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 2901;
  width: min(560px, 100vw);
  overflow-y: auto;
  background: var(--surface-1);
  border-left: 1px solid var(--line-strong);
  box-shadow: -20px 0 60px rgba(0,0,0,.45);
  padding: 22px 26px 40px;
  transform: translateX(100%);
  transition: transform .25s cubic-bezier(.16,.84,.44,1);
  color: var(--fg);
}
.about-drawer.open { transform: none; }
.about-drawer-backdrop.open { opacity: 1; }
.about-drawer header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  border-bottom: 1px solid var(--line); padding-bottom: 14px; margin-bottom: 18px;
}
.about-drawer .eyebrow {
  font: 500 11px/1 var(--font-mono); letter-spacing: .16em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 8px;
}
.about-drawer h2 { font: 700 22px/1.15 var(--font-display); color: var(--fg-hi); letter-spacing: -.02em; }
.about-drawer .lede { font-size: 15px; line-height: 1.6; color: var(--fg); margin-bottom: 18px; }
.about-drawer .close {
  flex: none; width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--fg-hi);
  font-size: 20px; line-height: 1; cursor: pointer;
}
.about-drawer .intro-lead { color: var(--fg); }
.about-drawer .intro-grid { display: grid; grid-template-columns: 1fr; gap: 18px; }
.about-drawer .intro-block h4 { color: var(--accent); }
.about-drawer .intro-block li { color: var(--fg-lo); }
@media (prefers-reduced-motion: reduce) {
  .about-drawer, .about-drawer-backdrop { transition: none; }
}

/* ── 4. Layout primitives ─────────────────────────────────────────── */
/* .workspace: rail | main | aside, each optional. Above 1280 px it fills
   the viewport under the header and each area scrolls on its own. */
.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr) minmax(300px, 380px);
  grid-template-areas: "rail main aside";
  gap: 16px;
  padding: 16px 24px;
  max-width: 2400px;
  margin: 0 auto;
}
.workspace.no-rail  { grid-template-columns: minmax(0, 1fr) minmax(300px, 380px); grid-template-areas: "main aside"; }
.workspace.no-aside { grid-template-columns: minmax(260px, 320px) minmax(0, 1fr); grid-template-areas: "rail main"; }
.ws-rail  { grid-area: rail;  display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.ws-main  { grid-area: main;  display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.ws-aside { grid-area: aside; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
@media (min-width: 1280px) {
  .workspace.fill { height: calc(100vh - 96px); }
  .workspace.fill > * { overflow-y: auto; scrollbar-width: thin; padding-right: 2px; }
}
@media (max-width: 1279px) {
  .workspace, .workspace.no-aside {
    grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
    grid-template-areas: "rail main" "rail aside";
  }
  .workspace.no-rail { grid-template-columns: 1fr; grid-template-areas: "main" "aside"; }
}
@media (max-width: 1023px) {
  .workspace, .workspace.no-rail, .workspace.no-aside {
    grid-template-columns: 1fr;
    grid-template-areas: "rail" "main" "aside";
    padding: 12px 16px;
  }
}

/* .panel: a rounded surface with a header row (eyebrow title, actions). */
.panel {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-card);
  min-width: 0;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px 0;
}
.panel-title {
  display: flex; align-items: center; gap: 10px;
  font: 500 11px/1 var(--font-mono);
  letter-spacing: .16em; text-transform: uppercase;
  color: var(--fg-lo);
}
.panel-title::before {
  content: ''; width: 3px; height: 14px; border-radius: 2px; background: var(--accent);
}
.panel-body { padding: 14px 18px 18px; }

/* ── 5. Figure components ─────────────────────────────────────────── */
/* .stat: eyebrow, large mono value with a smaller unit, a context line,
   and optionally a meter or a delta chip. */
.stat {
  --tone: var(--accent);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  min-width: 0;
}
.stat-label {
  display: flex; align-items: center; gap: 8px;
  font: 500 10.5px/1.2 var(--font-mono);
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--fg-lo);
}
.stat-label::before { content: ''; width: 3px; height: 12px; border-radius: 2px; background: var(--tone); flex: none; }
.stat-value {
  margin-top: 8px;
  display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap;
  font: 500 30px/1.05 var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  color: var(--fg-hi);
}
.stat-value .unit { font-size: 15px; color: var(--fg-lo); letter-spacing: 0; }
.stat-sub { margin-top: 6px; font-size: 12.5px; line-height: 1.45; color: var(--fg-lo); }
.stat.big .stat-value { font-size: 44px; }
.stat .meter { margin-top: 10px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.stat.good    { --tone: var(--data-good); }
.stat.caution { --tone: var(--data-caution); }
.stat.empty   { --tone: var(--data-empty); }

/* .meter: a thin bar, filled to --v (0 to 1). */
.meter {
  height: 6px; border-radius: 99px;
  background: rgba(148,163,184,.14);
  overflow: hidden;
}
.meter > span {
  display: block; height: 100%; border-radius: inherit;
  width: calc(var(--v, 0) * 100%);
  background: var(--tone, var(--accent));
  box-shadow: 0 0 10px color-mix(in srgb, var(--tone, var(--accent)) 50%, transparent);
}

/* .meter-row: label, inline bar, value, percentage. */
.meter-rows { display: flex; flex-direction: column; gap: 10px; }
.meter-row {
  display: grid;
  grid-template-columns: minmax(80px, 1.2fr) minmax(60px, 1.4fr) auto auto;
  align-items: center;
  gap: 12px;
  font-size: 13.5px;
}
.meter-row .name { display: flex; align-items: center; gap: 8px; color: var(--fg); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meter-row .name::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--tone, var(--accent)); flex: none; }
.meter-row .value { font: 500 13px var(--font-mono); font-variant-numeric: tabular-nums; color: var(--fg-hi); text-align: right; }
.meter-row .pct { font: 500 12px var(--font-mono); font-variant-numeric: tabular-nums; color: var(--tone, var(--accent)); text-align: right; min-width: 3.5em; }

/* .mix-bar: one stacked bar, segments sized by flex-grow, plus legend rows. */
.mix-bar {
  display: flex; height: 14px; border-radius: 99px; overflow: hidden; gap: 2px;
  background: rgba(148,163,184,.10);
}
.mix-bar > span { flex: var(--v, 1) 1 0; background: var(--tone, var(--accent)); min-width: 2px; }

/* .chip: a small status pill in a meaning colour. */
.chip {
  --tone: var(--fg-lo);
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 99px;
  font: 600 11px/1.4 var(--font-ui);
  letter-spacing: .02em;
  color: var(--tone);
  background: color-mix(in srgb, var(--tone) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--tone) 40%, transparent);
  white-space: nowrap;
}
.chip.good    { --tone: var(--data-good); }
.chip.caution { --tone: var(--data-caution); }
.chip.empty   { --tone: var(--data-empty); }
.chip.accent  { --tone: var(--accent); }

/* .seg-pills: a segmented pill filter. (Not .seg, which the planner,
   threshold and account pages already use for their own toggles.) */
.seg-pills {
  display: inline-flex; flex-wrap: wrap; gap: 6px;
}
.seg-pills button {
  padding: 7px 14px; border-radius: 99px;
  border: 1px solid var(--line-strong);
  background: transparent; color: var(--fg-lo);
  font: 600 11.5px/1 var(--font-ui); letter-spacing: .08em; text-transform: uppercase;
  cursor: pointer;
}
.seg-pills button:hover { color: var(--fg-hi); border-color: var(--fg-lo); }
.seg-pills button[aria-pressed="true"], .seg-pills button.active {
  color: var(--fg-hi);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent) inset;
}

/* .live: a dot and a short line of provenance. */
.live { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--fg-lo); }
.live::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%;
  background: var(--data-good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--data-good) 25%, transparent);
}
.live.stale::before { background: var(--data-caution); box-shadow: 0 0 0 3px color-mix(in srgb, var(--data-caution) 25%, transparent); }

/* .spark: a tiny chart with no axes (a canvas or an inline svg). */
.spark { display: block; width: 100%; height: 32px; }
.spark path { fill: none; stroke: var(--tone, var(--accent)); stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.spark .area { fill: color-mix(in srgb, var(--tone, var(--accent)) 16%, transparent); stroke: none; }

/* .source: the method or model behind a figure. */
.source { font-size: 11.5px; color: var(--fg-lo); font-family: var(--font-mono); letter-spacing: .01em; }

/* ── 6. Existing components on the dark ramp ──────────────────────── */
.card, .page-intro {
  background: var(--surface-1);
  border-color: var(--line);
}
.card:hover { border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); box-shadow: var(--shadow-hover); }
.section-title { color: var(--accent); }
.section-hint, .meta-line { color: var(--fg-lo); }
.section-hint a, .browse-link { color: var(--accent); }
a { color: var(--accent); }
h1, h2, h3, h4 { color: var(--fg-hi); }

.btn-primary,
#tab-analyse .btn-primary, #tab-cp-determine .btn-primary,
#tab-calculator .btn-primary, #tab-diary .btn-primary,
body[data-page] .btn-primary, body[data-page] .btn-accept {
  background: var(--accent);
  color: var(--surface-0);
  font-weight: 700;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 28%, transparent);
}
.btn-primary:disabled { opacity: .35; box-shadow: none; }
.btn-secondary, .btn-ghost, .btn-icon,
#tab-analyse .btn-secondary {
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--fg);
}
.btn-secondary:hover, .btn-ghost:hover, .btn-icon:hover,
#tab-analyse .btn-secondary:hover, #tab-diary .btn-icon:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-color: var(--accent);
  color: var(--fg-hi);
}
.btn-danger { background: transparent; color: var(--red); border-color: color-mix(in srgb, var(--red) 60%, transparent); }
.btn-danger:hover { background: var(--red-tint); }
.pro-badge, body[data-page] .pro-badge,
#tab-analyse .pro-badge, #tab-cp-determine .pro-badge, #tab-calculator .pro-badge, #tab-diary .pro-badge {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
}
.tab-badge { background: color-mix(in srgb, var(--data-good) 18%, transparent); color: var(--data-good); }

.toggle-btn, .model-tab, .seg button, .tool-tab,
#tab-analyse .toggle-btn, #tab-analyse .model-tab {
  background: transparent;
  color: var(--fg-lo);
  border-color: var(--line-strong);
}
.toggle-btn:hover, .model-tab:hover,
#tab-cp-determine .toggle-btn:hover, #tab-calculator .toggle-btn:hover, #tab-diary .toggle-btn:hover,
#tab-cp-determine .model-tab:hover, #tab-calculator .model-tab:hover { color: var(--fg-hi); border-color: var(--accent); }
.toggle-btn.active, .model-tab.active, .seg button.active,
#tab-analyse .toggle-btn.active, #tab-analyse .model-tab.active,
#tab-cp-determine .toggle-btn.active, #tab-cp-determine .model-tab.active,
#tab-calculator .toggle-btn.active, #tab-calculator .model-tab.active,
#tab-diary .toggle-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--surface-0);
}
.tool-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

input, select, textarea,
.param-input, .bout-input, .range-input, .trial-role, .field input, .field select {
  background: var(--surface-2);
  color: var(--fg-hi);
  border-color: var(--line-strong);
}
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--fg-lo) 70%, transparent); }
input:disabled, select:disabled, textarea:disabled { opacity: .55; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }
.param-input:focus, .bout-input:focus, .field input:focus, .field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
:focus-visible,
#tab-analyse :focus-visible, #tab-cp-determine :focus-visible,
#tab-calculator :focus-visible, #tab-diary :focus-visible { outline-color: var(--accent); }

.summary-card,
#tab-analyse .summary-card, #tab-cp-determine .summary-card,
#tab-calculator .summary-card, #tab-diary .summary-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  padding-left: 14px;
  box-shadow: none;
}
.summary-card:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); border-left-color: var(--accent); }
.metric-label, #tab-analyse .metric-label { color: var(--fg-lo); }
.metric-value, #tab-analyse .metric-value {
  color: var(--fg-hi);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

table th, .bouts-table th, .losses-table th, .iv-table th, .stage-table th, .method-table th,
#tab-analyse .bouts-table th { color: var(--fg-lo); border-color: var(--line); }
table td, .bouts-table td, .losses-table td, .iv-table td,
#tab-analyse .bouts-table td { color: var(--fg); border-color: var(--line); }
tbody tr:hover td { background: rgba(148,163,184,.04); }

.dropzone, #tab-analyse .dropzone { border-color: var(--line-strong); background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
.dropzone:hover, .dropzone.drag-over,
#tab-analyse .dropzone:hover, #tab-analyse .dropzone.drag-over {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, transparent);
}
.drop-inner p { color: var(--fg-lo); }

.upload-status.success, #tab-analyse .upload-status.success { background: rgba(74,222,128,.10); border-color: rgba(74,222,128,.3); color: #86EFAC; }
.upload-status.error,   #tab-analyse .upload-status.error   { background: rgba(248,113,113,.10); border-color: rgba(248,113,113,.3); color: #FCA5A5; }
.upload-status.loading, #tab-analyse .upload-status.loading { background: color-mix(in srgb, var(--accent) 8%, transparent); border-color: color-mix(in srgb, var(--accent) 30%, transparent); color: var(--accent); }

details.page-intro > summary { color: var(--accent); }
details.page-intro > summary:hover { background: rgba(255,255,255,.03); }
.page-intro, #tab-analyse .page-intro, #tab-cp-determine .page-intro, #tab-calculator .page-intro, #tab-diary .page-intro {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
}
.intro-block h4 { color: var(--accent); }
.intro-block li, .intro-lead { color: var(--fg); }

.werg-row, #tab-calculator .werg-row { background: color-mix(in srgb, var(--accent) 8%, transparent); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.werg-label, .werg-value, #tab-calculator .werg-label, #tab-calculator .werg-value { color: var(--accent); }
.tip-btn { border-color: var(--line-strong); color: var(--fg-lo); }
.tip-btn:hover, #tab-cp-determine .tip-btn:hover, #tab-calculator .tip-btn:hover, #tab-diary .tip-btn:hover {
  border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.rmse-line { background: var(--surface-2); color: var(--fg-lo); border: 1px solid var(--line); }
.checkbox-label { color: var(--fg); }
.formula { color: var(--fg-hi); }
.model-panel p, .model-note { color: var(--fg-lo); }

/* Modals built into the pages (not the ui.js dialog). */
.modal-overlay { background: rgba(2, 6, 14, .65); }
.modal-box { background: var(--surface-1); border: 1px solid var(--line-strong); box-shadow: 0 30px 80px rgba(0,0,0,.55); }

/* Status and verdict tints, re-made for dark. */
.verdict.ok      { background: rgba(74,222,128,.08);  border-color: rgba(74,222,128,.35);  color: #BBF7D0; }
.verdict.warning { background: rgba(251,191,36,.08);  border-color: rgba(251,191,36,.35);  color: #FDE68A; }
.verdict.danger  { background: rgba(248,113,113,.08); border-color: rgba(248,113,113,.35); color: #FECACA; }
.status-ok { color: var(--data-good); }
.status-low { color: var(--data-caution); }
.status-empty { color: var(--data-empty); }
.tag.rec, .tag.yes { background: rgba(74,222,128,.14); color: #86EFAC; }
.tag.weak        { background: rgba(251,191,36,.14); color: #FDE68A; }
.tag.no          { background: rgba(248,113,113,.14); color: #FCA5A5; }
.status-pill.status-pro  { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.status-pill.status-free { background: rgba(148,163,184,.14); color: var(--fg-lo); }
.status-pill.status-inst { background: rgba(74,222,128,.14); color: #86EFAC; }
.pill.pending { background: rgba(251,191,36,.14); color: #FDE68A; }
.seat-note.full { color: var(--data-caution); }
.danger { border-color: rgba(248,113,113,.35); }
.pro-lock { background: color-mix(in srgb, var(--accent) 8%, transparent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.file-chip { background: color-mix(in srgb, var(--accent) 10%, transparent); border-color: var(--accent); color: var(--accent); }
.chip-primary { background: var(--accent); color: var(--surface-0); }
.athlete-card { background: var(--surface-2); }
.athlete-card:hover { box-shadow: 0 8px 24px rgba(0,0,0,.35); }
.feasibility-warning p { color: #FDE68A; }
.cta { background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* Leaflet controls and attribution on the dark ramp, and OpenStreetMap's
   light tiles darkened (DESIGN-PLAN decision: a filter, no new tile host). */
.leaflet-container { background: var(--surface-0); }
.leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.88) saturate(.6); }
.leaflet-control-zoom a, .leaflet-bar a {
  background: var(--surface-2); color: var(--fg-hi); border-color: var(--line-strong);
}
.leaflet-control-attribution { background: rgba(7,15,28,.75) !important; color: var(--fg-lo); }
.leaflet-control-attribution a { color: var(--fg); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface-2); color: var(--fg); }

.site-footer { border-top-color: var(--line); }
.skip-link { background: var(--accent); color: var(--surface-0); }

/* Scrollbars that belong on a dark page. */
* { scrollbar-color: var(--line-strong) transparent; }

/* ═══════════════════════════════════════════════════════════════════
   ANALYSER (phase 2): rail | main | aside across the whole window
   ═══════════════════════════════════════════════════════════════════ */
.analyse-head {
  max-width: 2400px;
  margin: 0 auto;
  padding: 16px 24px 0;
}
.analyse-head .page-intro { margin-top: 12px; }

/* Before a ride: settings and the invitation. With results: all three
   columns. With the rail folded: the ride and its findings only. */
.analyse-ws { grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); grid-template-areas: "rail main"; }
.analyse-ws.has-results { grid-template-columns: minmax(280px, 320px) minmax(0, 1fr) minmax(320px, 400px); grid-template-areas: "rail main aside"; }
.analyse-ws.has-results.rail-folded { grid-template-columns: minmax(0, 1fr) minmax(340px, 420px); grid-template-areas: "main aside"; }
.analyse-ws.rail-folded .ws-rail { display: none; }
@media (min-width: 1800px) {
  .analyse-ws.has-results.rail-folded { grid-template-columns: minmax(0, 1fr) minmax(380px, 480px); }
}
@media (max-width: 1279px) {
  .analyse-ws.has-results { grid-template-columns: minmax(260px, 300px) minmax(0, 1fr); grid-template-areas: "rail main" "rail aside"; }
  .analyse-ws.has-results.rail-folded { grid-template-columns: minmax(0, 1fr); grid-template-areas: "main" "aside"; }
}
@media (max-width: 1023px) {
  .analyse-ws, .analyse-ws.has-results, .analyse-ws.has-results.rail-folded {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "rail" "main" "aside";
  }
  .analyse-head { padding: 12px 16px 0; }
}

/* The rail: settings, compact. Sticky beside the charts on a wide screen. */
.ws-rail .card { padding: 16px 18px; }
.ws-rail .section-title { font-size: 14px; }
.ws-rail .model-tabs, .ws-rail .toggle-group { flex-wrap: wrap; }
.ws-rail .dropzone { padding: 20px 14px; }
.ws-rail .run-section { padding: 12px 18px; }
.ws-rail .run-section .btn-primary { width: 100%; }
.rail-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 2px 4px 0; }
@media (min-width: 1280px) {
  .analyse-ws.has-results .ws-rail {
    position: sticky; top: 108px; align-self: start;
    max-height: calc(100vh - 124px); overflow-y: auto; scrollbar-width: thin; padding-right: 2px;
  }
}

/* The folded rail, as one line above the charts. */
.rail-summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.rail-summary .live { color: var(--fg); font-size: 13px; }

/* The empty state: one large drop target. */
.analyse-empty {
  min-height: min(62vh, 640px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  text-align: center;
  padding: 40px 24px;
  border: 1.5px dashed color-mix(in srgb, var(--accent) 40%, var(--line-strong));
  border-radius: 18px;
  background:
    radial-gradient(60% 70% at 50% 30%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 70%),
    color-mix(in srgb, var(--surface-1) 70%, transparent);
  transition: border-color .15s, background .15s;
}
.analyse-empty.drag-over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface-1)); }
.analyse-empty .empty-motif { width: min(360px, 80%); color: var(--accent); filter: drop-shadow(0 0 14px color-mix(in srgb, var(--accent) 45%, transparent)); }
.analyse-empty h2 { font: 700 clamp(22px, 2.4vw, 30px)/1.15 var(--font-display); letter-spacing: -.02em; max-width: 22ch; }
.analyse-empty > p:not(.source) { color: var(--fg-lo); font-size: 15px; max-width: 52ch; line-height: 1.55; }
.analyse-empty .empty-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 4px; }
.analyse-empty .btn-primary, .analyse-empty .btn-secondary { padding: 11px 20px; font-size: 14.5px; }

/* The ride: figures, then the two charts as tall as the screen allows. */
#results-section { display: flex; flex-direction: column; gap: 16px; }
#results-section.hidden { display: none; }
.kpi-card { padding: 14px; }
.kpi-grid { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.kpi-grid .stat-value { font-size: clamp(24px, 2vw, 32px); }
.kpi-card .feasibility-warning { margin-top: 12px; }
#tab-analyse .chart-wrap { height: clamp(320px, 44vh, 600px); }
#tab-analyse .chart-wrap:has(#power-chart) { height: clamp(280px, 36vh, 480px); }
.wbal-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line);
}
.wbal-bands { flex: 1 1 360px; max-width: 640px; }
.band-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; font-size: 12px; color: var(--fg-lo); }
.band-legend span { display: inline-flex; align-items: center; gap: 6px; }
.band-legend i { width: 8px; height: 8px; border-radius: 50%; background: var(--tone); display: inline-block; }
.band-legend b { color: var(--fg-hi); font: 500 12px var(--font-mono); }

/* The aside: what the ride held. */
.ws-aside .card { padding: 16px 18px; }
.ws-aside .section-title { font-size: 14px; }
.ws-aside .summary-grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.ws-aside .metric-value { font-size: 18px; }
.ws-aside #mmp-chart { max-height: 240px; }
.ws-aside .meter-row { grid-template-columns: minmax(96px, 1.3fr) minmax(50px, 1fr) auto auto; font-size: 13px; }
.efforts-table { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.efforts-table summary { cursor: pointer; color: var(--fg-lo); font-size: 12.5px; }
.efforts-table summary:hover { color: var(--fg-hi); }
.efforts-table .bouts-table { margin-top: 8px; font-size: 12.5px; }
#autocp-banner { background: color-mix(in srgb, var(--accent) 10%, transparent) !important; border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); }
@media (max-width: 600px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-grid .stat { padding: 12px; }
  .kpi-grid .stat:last-child { grid-column: span 2; }
  .kpi-grid .stat-value { font-size: 24px; }
}

/* ═══════════════════════════════════════════════════════════════════
   TRAINING DIARY (phase 3): form band, views, load heatmap
   ═══════════════════════════════════════════════════════════════════ */
.diary-band {
  max-width: 2400px; margin: 0 auto; padding: 16px 24px 0;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px;
}
.diary-band.hidden { display: none; }
.diary-band .stat { background: var(--surface-1); }
.diary-band .stat-value { font-size: clamp(28px, 2.4vw, 38px); align-items: center; }
.diary-band .stat-value .chip { font-size: 12px; letter-spacing: .01em; }
.diary-band .spark { margin-top: 8px; height: 36px; }
@media (max-width: 900px) { .diary-band { grid-template-columns: 1fr 1fr; padding: 12px 16px 0; } }

.diary-ws { padding-top: 16px; }
.diary-views { margin-bottom: 2px; }
.diary-ws[data-view] [data-diary-view] { display: none; }
.diary-ws[data-view="overview"] [data-diary-view="overview"],
.diary-ws[data-view="log"] [data-diary-view="log"],
.diary-ws[data-view="tests"] [data-diary-view="tests"],
.diary-ws[data-view="taper"] [data-diary-view="taper"] { display: block; }
.diary-ws [data-diary-view].hidden { display: none !important; }
#tab-diary .chart-wrap { height: clamp(320px, 42vh, 560px); }

.heatmap-scroll { overflow-x: auto; margin-top: 12px; padding-bottom: 4px; }
.heatmap { display: flex; gap: 8px; min-width: max-content; }
.hm-days { display: grid; grid-template-rows: 16px repeat(7, 13px); row-gap: 3px; font-size: 10.5px; color: var(--fg-lo); }
.hm-days span { line-height: 13px; }
.hm-months { display: grid; grid-template-columns: repeat(var(--weeks), 13px); column-gap: 3px; height: 16px; font-size: 10.5px; color: var(--fg-lo); }
.hm-months span { white-space: nowrap; }
.hm-grid {
  display: grid; grid-auto-flow: column;
  grid-template-rows: repeat(7, 13px); grid-template-columns: repeat(var(--weeks), 13px);
  gap: 3px; margin-top: 3px;
}
.hm-grid i, .heatmap-legend i {
  display: block; width: 13px; height: 13px; border-radius: 3px;
  background: rgba(148,163,184,.10);
}
.hm-grid i.future { background: transparent; }
.hm-grid i[data-l="1"], .heatmap-legend i[data-l="1"] { background: color-mix(in srgb, var(--accent) 28%, transparent); }
.hm-grid i[data-l="2"], .heatmap-legend i[data-l="2"] { background: color-mix(in srgb, var(--accent) 50%, transparent); }
.hm-grid i[data-l="3"], .heatmap-legend i[data-l="3"] { background: color-mix(in srgb, var(--accent) 75%, transparent); }
.hm-grid i[data-l="4"], .heatmap-legend i[data-l="4"] { background: var(--accent); box-shadow: 0 0 6px color-mix(in srgb, var(--accent) 50%, transparent); }
.heatmap-legend { display: flex; align-items: center; gap: 4px; margin-top: 10px; font-size: 11px; color: var(--fg-lo); }
.heatmap-legend span { margin: 0 4px; }
@media (min-width: 1500px) {
  .hm-grid { grid-template-rows: repeat(7, 15px); grid-template-columns: repeat(var(--weeks), 15px); }
  .hm-months { grid-template-columns: repeat(var(--weeks), 15px); }
  .hm-grid i { width: 15px; height: 15px; }
  .hm-days { grid-template-rows: 16px repeat(7, 15px); }
  .hm-days span { line-height: 15px; }
}

.model-settings { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.model-settings > summary { cursor: pointer; color: var(--fg-lo); font-size: 13px; }
.model-settings > summary:hover { color: var(--fg-hi); }
#diary-results { margin-top: 12px !important; border-top: none !important; padding-top: 0 !important; }
/* diary.js draws these two notices with light inline colours. */
#diary-sample-banner, #diary-lapsed-banner {
  margin: 16px 24px 0 !important;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface-1)) !important;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent) !important;
  color: var(--fg) !important;
}

/* ═══════════════════════════════════════════════════════════════════
   PLANNER (phase 3): map first, the strip under it
   ═══════════════════════════════════════════════════════════════════ */
body[data-page="planner"] .pl-wrap { max-width: 2400px; }
body[data-page="planner"] #tab-session { max-width: 1200px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
body[data-page="planner"] #tab-session.hidden { display: none; }
.tt-ws { padding: 0; }
.tt-ws.workspace { grid-template-columns: minmax(280px, 340px) minmax(0, 1fr) minmax(300px, 380px); }
@media (max-width: 1279px) { .tt-ws.workspace { grid-template-columns: minmax(260px, 300px) minmax(0, 1fr); grid-template-areas: "rail main" "rail aside"; } }
@media (max-width: 1023px) { .tt-ws.workspace { grid-template-columns: 1fr; grid-template-areas: "rail" "main" "aside"; } }
.tt-ws .ws-rail .card, .tt-ws .ws-aside .card { padding: 16px 18px; }
.tt-ws .ws-rail .params { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
.tt-ws .ws-aside .stat-grid { grid-template-columns: 1fr 1fr; }
.tt-ws .ws-aside .stat:first-child { grid-column: span 2; }
.tt-ws .ws-aside .stat-value { font-size: 24px; }
.tt-ws .ws-aside .stat:first-child .stat-value { font-size: 34px; }
.tt-ws .ws-aside .meter-row { grid-template-columns: minmax(90px, 1.1fr) minmax(40px, 1fr) auto auto; font-size: 12.5px; }
#tt-empty { min-height: min(56vh, 600px); }
#map { height: clamp(360px, 52vh, 760px); border-radius: 12px; }
.tt-strip { height: clamp(200px, 26vh, 320px) !important; }
.tt-strip-power { height: clamp(160px, 20vh, 260px) !important; }
.chart-legend .legend-label { color: var(--fg); }
.leaflet-interactive { cursor: crosshair; }
.tt-ws .ws-rail .params { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.tt-ws .ws-rail .model-tabs { gap: 5px; }
.tt-ws .ws-rail .model-tab { padding: 5px 9px; }

.tt-views { margin-bottom: -4px; }
.tt-views.hidden { display: none; }
.tt-wind { background: none; border: none; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
.tt-wind-key { display: inline-flex; align-items: center; gap: 6px; }
.tt-wind-key.hidden { display: none; }
.tt-wind-key i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; margin-left: 6px; }
.tt-wind-key i.head { background: #F87171; }
.tt-wind-key i.tail { background: #2DD4BF; }
#tt-map-section > div:last-child { flex-wrap: wrap; row-gap: 6px; }
.tt-wind-key { white-space: nowrap; }
#tt-map-section > div:last-child .source { white-space: nowrap; }


/* ═══════════════════════════════════════════════════════════════════
   PHASE 4: Determine CP, recovery calculator, session planner,
   threshold test, coach, account
   ═══════════════════════════════════════════════════════════════════ */
/* The pages' own wrappers stop capping the width; the workspace inside
   them lays the columns out. */
body[data-page="threshold"] .th-wrap,
body[data-page="coach"] .coach-wrap,
body[data-page="account"] .acct-wrap { max-width: 2400px; }

/* A tool workspace before results: inputs and the invitation. With
   results: all three columns. Same breakpoints as the analyser. */
.tool-ws { padding-left: 24px; padding-right: 24px; }
.tool-ws:not(.no-rail):not(.has-results) { grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); grid-template-areas: "rail main"; }
.tool-ws.has-results { grid-template-columns: minmax(300px, 380px) minmax(0, 1fr) minmax(300px, 400px); grid-template-areas: "rail main aside"; }
body[data-page] .tool-ws { padding-left: 0; padding-right: 0; }
#sess-ws { padding: 0; }
@media (max-width: 1279px) {
  .tool-ws.has-results { grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); grid-template-areas: "rail main" "rail aside"; }
}
@media (max-width: 1023px) {
  .tool-ws, .tool-ws.has-results, .tool-ws:not(.no-rail):not(.has-results) { grid-template-columns: minmax(0, 1fr); grid-template-areas: "rail" "main" "aside"; padding-left: 16px; padding-right: 16px; }
  body[data-page] .tool-ws { padding-left: 0; padding-right: 0; }
}
.tool-ws .ws-rail .card, .tool-ws .ws-aside .card { padding: 16px 18px; }
.tool-ws .ws-rail .section-title, .tool-ws .ws-aside .section-title { font-size: 14px; }
.tool-ws .ws-rail .run-section .btn-primary { width: 100%; }
.tool-ws .ws-rail .param-input { max-width: 100%; }
.tool-ws .ws-rail table { font-size: 12.5px; }
.tool-ws .ws-rail .bouts-table input { width: 100%; min-width: 0; }
.tool-ws .ws-rail > .card { overflow-x: auto; }
.tool-empty { min-height: min(56vh, 600px); }
.tool-ws .ws-aside .stat-grid { grid-template-columns: 1fr 1fr; }
.tool-ws .ws-aside .stat-grid .stat.big, .tool-ws .ws-aside .stat-grid .stat:first-child { grid-column: span 2; }
.tool-ws .ws-aside .stat-value { font-size: 24px; }
.tool-ws .ws-aside .stat.big .stat-value, .tool-ws .ws-aside .stat:first-child .stat-value { font-size: 36px; }
#tab-cp-determine #cpd-chart { min-height: 0; }
#tab-cp-determine .chart-wrap { height: clamp(360px, 56vh, 680px); }
#tab-calculator #tau-chart { min-height: 0; }
#tab-calculator .chart-wrap { height: clamp(320px, 46vh, 560px); }

/* Determine CP: one card per model. */
.model-cards { display: grid; gap: 10px; margin: 10px 0 12px; }
.model-card { background: var(--surface-2); border: 1px solid var(--line); border-left: 3px solid var(--tone, var(--line)); border-radius: 10px; padding: 12px 14px; }
.model-card.active { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); border-left-color: var(--tone); }
.model-card.off { opacity: .6; }
.model-card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.model-card-head strong { color: var(--fg-hi); font-size: 14px; margin-right: auto; }
.model-card-figs { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--fg-lo); margin-bottom: 8px; }
.model-card-figs b { font: 500 18px var(--font-mono); color: var(--fg-hi); font-variant-numeric: tabular-nums; }

/* Session planner: the blocks as a strip above the W′bal chart. */
.sess-blocks { display: flex; gap: 3px; margin-top: 10px; min-height: 44px; }
.sess-blocks.hidden { display: none; }
.sess-blocks > span {
  flex: var(--v, 1) 1 0; min-width: 6px; overflow: hidden;
  border-radius: 6px; padding: 5px 7px;
  background: color-mix(in srgb, var(--tone) 22%, var(--surface-2));
  border: 1px solid color-mix(in srgb, var(--tone) 55%, transparent);
  border-top: 3px solid var(--tone);
  display: flex; flex-direction: column; justify-content: center;
}
.sess-blocks b { font-size: 11.5px; color: var(--fg-hi); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sess-blocks i { font: normal 11px var(--font-mono); color: var(--fg-lo); white-space: nowrap; }
body[data-page="planner"] #tab-session { max-width: 2400px; }
.sess-stats .stat:first-child .stat-value { font-size: 30px; }

/* Threshold test: the tiles on the dark ramp, method agreement, zones bar. */
.thr-tile { background: var(--surface-2); border-color: var(--line); }
.thr-tile .v { font-family: var(--font-mono); font-weight: 500; font-variant-numeric: tabular-nums; color: var(--fg-hi); }
.thr-agree { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 11.5px; color: var(--fg-lo); }
.thr-agree .meter { flex: 1 1 auto; height: 5px; }
.thr-zones-bar { margin: 6px 0 14px; }
.thr-zones-bar .mix-bar { height: 16px; }
#thr-results-aside #thr-summary { grid-template-columns: 1fr 1fr; }
#thr-results-aside .chart-box { height: 220px; }

/* Coach: seats in the page header, the roster as a grid of cards, the
   athlete's detail as a drawer from the right. */
.seat-meter { position: relative; z-index: 2; flex: 0 0 220px; margin-left: auto; padding: 10px 14px; border-radius: 12px;
  background: color-mix(in srgb, var(--surface-0) 70%, transparent); border: 1px solid var(--line-strong); }
.seat-meter .seat-figure { font-size: 13px; color: var(--fg-lo); margin: 4px 0 8px; }
.seat-meter .seat-figure b { font: 500 24px var(--font-mono); color: var(--fg-hi); }
@media (max-width: 720px) { .seat-meter { flex-basis: 100%; margin-left: 0; } .masthead:has(.seat-meter) { flex-wrap: wrap; } }
.coach-ws .roster { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.athlete-card { color: var(--accent); }
.athlete-card .name { color: var(--fg-hi); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.athlete-card .metric .v { font-family: var(--font-mono); font-weight: 500; color: var(--fg-hi); }
.athlete-card .sub { color: var(--fg-lo); }
#detail-overlay { justify-content: flex-end; align-items: stretch; padding: 0; }
#detail-overlay .modal-box { max-width: min(560px, 100vw); width: 100%; height: 100vh; max-height: none; border-radius: 0; overflow-y: auto; border-width: 0 0 0 1px; }

/* Account: settings in the main column, plan, connections and data beside. */
.acct-ws .ws-aside .card { padding: 16px 18px; }
/* style.css paints the CP tab's badges solid emerald; keep the dark-ramp chip. */
#tab-cp-determine .tab-badge, .masthead .tab-badge { background: color-mix(in srgb, var(--data-good) 18%, transparent); color: var(--data-good); border: 1px solid color-mix(in srgb, var(--data-good) 40%, transparent); }
/* Inside the pages' flex-column wrappers a centred workspace would shrink to
   its content; it always takes the full width. */
.workspace { width: 100%; box-sizing: border-box; }


/* ═══════════════════════════════════════════════════════════════════
   PHASE 5: the free calculators and the sign-in pages
   ═══════════════════════════════════════════════════════════════════ */
body[data-page="cp-calc"]   { --accent: var(--tool-cp-hi); }
body[data-page="wbal-calc"] { --accent: var(--tool-calc-hi); }
body[data-page="signin"]    { --accent: var(--tool-analyse-hi); }
.btn-white { background: var(--accent) !important; color: var(--surface-0) !important; }
.explainer { background: var(--surface-1); border-color: var(--line); }
/* The free calculators' closing invitation: a tinted panel, not white on colour. */
.cta-card { background: color-mix(in srgb, var(--accent) 12%, var(--surface-1)) !important; border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); color: var(--fg) !important; }
.cta-card h3 { color: var(--fg-hi) !important; }
.cta-card p { color: var(--fg) !important; }
