/* Stride — training analytics. Theme tokens follow the validated reference palette. */
:root {
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --delta-good: #006300;
  --delta-bad: #d03b3b;

  --series-1: #2a78d6; /* blue */
  --series-2: #1baf7a; /* aqua */
  --series-3: #eda100; /* yellow */
  --series-4: #008300; /* green */
  --series-5: #4a3aa7; /* violet */
  --series-6: #e34948; /* red */
  --series-7: #e87ba4; /* magenta */
  --series-8: #eb6834; /* orange */

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

  --accent: var(--series-1);
  --accent-wash: rgba(42, 120, 214, 0.10);
  --hover-wash: rgba(11, 11, 11, 0.045);
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --radius: 10px;
}
:root[data-theme="dark"] { color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light; }
/* native controls (date/time pickers, spinners) inherit the theme so their text
   isn't dark-on-dark — this is what made the workout-builder date unreadable */
input[type="date"], input[type="time"], input[type="number"], select { color-scheme: inherit; }

:root[data-theme="dark"] {
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --delta-good: #0ca30c;

  --series-1: #3987e5;
  --series-2: #199e70;
  --series-3: #c98500;
  --series-4: #008300;
  --series-5: #9085e9;
  --series-6: #e66767;
  --series-7: #d55181;
  --series-8: #d95926;

  --accent: var(--series-1);
  --accent-wash: rgba(57, 135, 229, 0.14);
  --hover-wash: rgba(255, 255, 255, 0.06);
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
}

@font-face {
  font-family: 'Norwester';
  src: url('fonts/norwester.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }

.app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 208px; flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--surface-1);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 8px; padding: 18px 18px 14px; font-weight: 700; font-size: 1.1rem; }
.settings-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.settings-tabs button { background: none; border: none; border-bottom: 2px solid transparent; color: var(--text-secondary);
  padding: 8px 14px; cursor: pointer; font-size: 0.9rem; font-weight: 500; transition: color .12s, border-color .12s; margin-bottom: -1px; }
.settings-tabs button:hover { color: var(--text-primary); }
.settings-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* Section-shell tab bar: the consolidated IA renders related views as tabs. */
.shell-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.shell-tabs a { border-bottom: 2px solid transparent; color: var(--text-secondary); text-decoration: none;
  padding: 8px 14px; cursor: pointer; font-size: 0.95rem; font-weight: 500; transition: color .12s, border-color .12s; margin-bottom: -1px; }
.shell-tabs a:hover { color: var(--text-primary); }
.shell-tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.btn-strava { display: inline-flex; align-items: center; gap: 8px; background: #FC4C02; color: #fff; border: none; border-radius: 8px; padding: 10px 16px; font-weight: 600; font-size: 0.95rem; cursor: pointer; }
.btn-strava:hover { background: #e34402; }
.btn-strava:disabled { opacity: 0.6; cursor: default; }
.strava-badge { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 10px; background: rgba(252, 76, 2, 0.15); flex-shrink: 0; }
/* Strava brand-guideline attribution: shown wherever Strava-sourced data appears */
.pwd-strava { display: inline-flex; align-items: center; gap: 6px; font-size: 0.66rem; font-weight: 600;
  letter-spacing: 0.09em; color: var(--text-muted); margin-top: 10px; user-select: none; }
.pwd-strava strong { color: #FC4C02; letter-spacing: 0.09em; }
.strava-link { display: inline-flex; align-items: center; gap: 6px; color: #FC4C02; font-weight: 600;
  font-size: 0.82rem; text-decoration: none; padding: 5px 12px; border: 1px solid rgba(252, 76, 2, 0.45);
  border-radius: 999px; white-space: nowrap; }
.strava-link:hover { background: rgba(252, 76, 2, 0.12); }

.icon-btn { background: none; border: none; cursor: pointer; padding: 3px 6px; border-radius: 6px; opacity: 0.55; line-height: 1; }
.icon-btn:hover { opacity: 1; background: var(--hover-wash); }
.act-del:hover { background: rgba(224, 87, 74, 0.18); }

.cal-mini-wrap { margin-top: 3px; border-radius: 4px; overflow: hidden; background: var(--hover-wash); cursor: pointer; }
.cal-mini { display: block; width: 100%; height: 24px; }
.cal-mini-area { fill: var(--accent-wash); stroke: var(--accent); stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.cal-mini-ftp { stroke: var(--text-secondary); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0.55; }
.cal-mini-hr { fill: none; stroke: var(--series-6); stroke-width: 1.1; opacity: 0.85; }
.cal-mini-hr-area { fill: color-mix(in srgb, var(--series-6) 22%, transparent); stroke: var(--series-6); stroke-width: 1.2; }

.brand-mark { color: var(--accent); }
.brand-name {
  font-family: 'Norwester', 'Arial Narrow', system-ui, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 400;
  font-size: 1.28rem;
  line-height: 1;
}
.nav { display: flex; flex-direction: column; padding: 6px 10px; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  color: var(--text-secondary); text-decoration: none; font-size: 0.94rem;
  transition: background 0.14s ease, color 0.14s ease;
}
.nav a:hover { background: var(--hover-wash); }
.nav a.active { background: var(--accent-wash); color: var(--accent); font-weight: 600; }
.nav-icon { width: 18px; text-align: center; opacity: 0.9; }
.sidebar-footer { margin-top: auto; padding: 12px; }

/* ---------- Main ---------- */
.main { flex: 1; padding: 22px 26px 60px; max-width: 1320px; min-width: 0; }
.view-header { display: flex; align-items: baseline; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.view-header h1 { font-size: 1.35rem; }
.view-header .sub { color: var(--text-muted); font-size: 0.9rem; }
.view-header .spacer { flex: 1; }

h2.section { font-size: 0.98rem; margin: 22px 0 10px; }
h2.section:first-child { margin-top: 0; }

/* ---------- Cards & grids ---------- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card h3 { font-size: 0.92rem; margin-bottom: 2px; }
.card .card-sub { color: var(--text-muted); font-size: 0.8rem; margin-bottom: 10px; }
.grid { display: grid; gap: 14px; }
.grid-tiles { grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.mt { margin-top: 14px; }
@media (max-width: 980px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---------- Stat tiles ---------- */
.tile .label { font-size: 0.8rem; color: var(--text-secondary); }
.tile .value { font-size: 1.65rem; font-weight: 600; margin: 2px 0; }
.tile .value small { font-size: 0.85rem; font-weight: 400; color: var(--text-muted); }
.tile .delta { font-size: 0.78rem; }
.tile .delta.up { color: var(--delta-good); }
.tile .delta.down { color: var(--delta-bad); }
.tile .delta.flat { color: var(--text-muted); }
.tile svg.spark { display: block; margin-top: 6px; }

/* ---------- Hero readiness ---------- */
.hero-num { font-size: 3rem; font-weight: 650; line-height: 1.05; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.78rem; font-weight: 600;
  padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border);
}
.badge .dot { width: 8px; height: 8px; border-radius: 50%; }

/* ---------- Charts ---------- */
.chart-wrap { position: relative; }
/* touch-action: pan-y lets one finger scrub the chart (hover) horizontally while
   vertical page scroll still works; two-finger pinch/zoom is handled in JS. */
.chart-wrap svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 0.78rem; color: var(--text-secondary); margin-bottom: 8px; }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .key-line { width: 14px; height: 2px; border-radius: 1px; }
.legend .key-rect { width: 10px; height: 10px; border-radius: 3px; }

.chart-tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  padding: 8px 10px; font-size: 0.78rem; min-width: 120px; max-width: 260px;
}
.chart-tooltip .tt-title { color: var(--text-muted); margin-bottom: 5px; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 7px; margin: 2px 0; }
.chart-tooltip .tt-key { width: 12px; height: 2px; border-radius: 1px; flex-shrink: 0; }
.chart-tooltip .tt-val { font-weight: 600; }
.chart-tooltip .tt-name { color: var(--text-secondary); }

/* ---------- Filter row ---------- */
.filter-row { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-1); }
.seg button { background: none; border: none; padding: 6px 12px; font-size: 0.82rem; color: var(--text-secondary); cursor: pointer; }
.seg button:hover { background: var(--hover-wash); }
.seg button.active { background: var(--accent-wash); color: var(--accent); font-weight: 600; }

/* ---------- Buttons / forms ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface-1);
  border-radius: 8px; padding: 7px 14px; font-size: 0.86rem; cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, filter 0.14s ease, color 0.14s ease;
}
.btn:hover { background: var(--hover-wash); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-ghost { border: none; background: none; color: var(--text-secondary); cursor: pointer; padding: 6px 10px; border-radius: 8px; }
.btn-ghost:hover { background: var(--hover-wash); }
.btn-danger { color: var(--status-critical); }
.btn-sm { padding: 4px 10px; font-size: 0.78rem; }

label.field { display: block; font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 10px; }
label.field input, label.field select {
  display: block; width: 100%; margin-top: 4px;
  padding: 7px 9px; font: inherit; color: var(--text-primary);
  background: var(--page); border: 1px solid var(--border); border-radius: 8px;
}
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 14px; }

/* ---------- Tables ---------- */
table.data { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.data th {
  text-align: left; font-weight: 600; color: var(--text-muted); font-size: 0.75rem;
  padding: 7px 10px; border-bottom: 1px solid var(--grid);
}
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--grid); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: var(--hover-wash); }

/* ---------- Calendar ---------- */
/* minmax(0,…) so a day's content (a long name, a nowrap TSS) can never force its
   column wider than the others — that was the "squished weirdly depending on which
   days have activities" bug. Columns stay exactly equal; content ellipsizes. */
.cal-head { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)) 92px; gap: 4px; font-size: 0.72rem; color: var(--text-muted); margin-bottom: 4px; }
.cal-head div { padding: 0 6px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)) 92px; gap: 4px; }
.cal-day {
  min-height: 96px; background: var(--surface-1); border: 1px solid var(--border);
  border-left: 3px solid transparent; border-radius: 8px; padding: 5px 6px; font-size: 0.72rem;
  cursor: pointer; position: relative;
}
.cal-day[style*="--day-int"] { border-left-color: var(--day-int); }
.cal-day:hover { background: var(--hover-wash); }
.cal-day .dnum { color: var(--text-muted); }
.cal-day .dnum-row { display: flex; justify-content: space-between; align-items: baseline; gap: 4px; }
.cal-day .d-tss { font-size: 0.64rem; color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cal-welldot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-left: 5px; vertical-align: middle; }
.cal-day.other { opacity: 0.42; }
.cal-day.today { border-color: var(--accent); border-width: 2px; }
.cal-week-total { min-height: 96px; border-radius: 8px; background: none; border: 1px dashed var(--grid); padding: 6px; font-size: 0.72rem; color: var(--text-secondary); }
.cal-item { border-radius: 5px; padding: 2px 5px; margin-top: 3px; line-height: 1.25; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cal-item.done { background: var(--accent-wash); color: var(--text-primary); }
.cal-item.planned { border: 1px dashed var(--axis); color: var(--text-secondary); }
.cal-item.missed { border: 1px dashed var(--status-serious); color: var(--text-secondary); opacity: 0.8; }
.cal-item .ci-icon { margin-right: 3px; }

/* ---------- Activity detail ---------- */
.back-link { color: var(--accent); text-decoration: none; font-size: 0.86rem; }
.metric-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.metric-row .m { background: var(--page); border-radius: 8px; padding: 8px 10px; }
.metric-row .m .label { font-size: 0.7rem; color: var(--text-muted); }
.metric-row .m .value { font-size: 1.05rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Zone bars ---------- */
.zone-row { display: grid; grid-template-columns: 44px 1fr 84px; align-items: center; gap: 10px; font-size: 0.8rem; margin: 5px 0; }
.zone-row .zr-track { height: 14px; border-radius: 4px; background: var(--page); overflow: hidden; }
.zone-row .zr-fill { height: 100%; border-radius: 0 4px 4px 0; }
.zone-row .zr-val { color: var(--text-secondary); font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- Plan / workout builder ---------- */
.week-card { display: flex; align-items: center; gap: 14px; padding: 9px 12px; border-bottom: 1px solid var(--grid); font-size: 0.85rem; }
.week-card:last-child { border-bottom: none; }
.week-card .wk-label { width: 76px; font-weight: 600; }
.week-card .wk-type { width: 90px; }
.week-card .wk-bar { flex: 1; height: 12px; border-radius: 4px; background: var(--page); overflow: hidden; }
.week-card .wk-fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }
.week-card .wk-tss { width: 90px; text-align: right; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.pill { font-size: 0.68rem; padding: 2px 8px; border-radius: 999px; background: var(--accent-wash); color: var(--accent); font-weight: 600; }
.pill.recovery { background: rgba(12,163,12,0.12); color: var(--status-good); }
.pill.peak { background: rgba(236,131,90,0.14); color: var(--status-serious); }

.workout-steps { display: block; height: var(--wsteps-h, 88px); margin: 10px 0; }
.workout-steps svg { display: block; width: 100%; height: 100%; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-backdrop[hidden] { display: none; }
.chart-tooltip[hidden] { display: none; }
.modal {
  background: var(--surface-1); border-radius: 12px; border: 1px solid var(--border);
  width: min(520px, 92vw); max-height: 86vh; overflow: auto; padding: 20px;
}
.modal h3 { margin-bottom: 12px; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* ---------- Misc ---------- */
.muted { color: var(--text-muted); }
.small { font-size: 0.8rem; }
.flex { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.right { margin-left: auto; }

/* ---------- Account, auth gate & import ---------- */
.btn-block { display: block; width: 100%; text-align: center; margin-top: 6px; }
label.field.row { display: flex; align-items: center; gap: 8px; }
label.field.row input { width: auto; margin-top: 0; }

.user-chip { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px;
  color: var(--text-secondary); text-decoration: none; margin-bottom: 8px; }
.user-chip:hover { background: var(--hover-wash); }
.user-avatar { display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff;
  font-size: 0.8rem; font-weight: 700; flex: 0 0 auto; }
.user-avatar.lg { width: 40px; height: 40px; font-size: 1.1rem; }
.user-name { font-size: 0.86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-row { display: flex; align-items: center; gap: 12px; margin-top: 6px; }

.auth-err { color: var(--status-critical); font-size: 0.82rem; margin: 4px 0 10px; }

.auth-overlay { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center;
  justify-content: center; padding: 20px; background: var(--page); }
.auth-card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 28px; width: 100%; max-width: 380px; }
.auth-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; margin-bottom: 14px; }
.auth-card h2 { font-size: 1.15rem; margin-bottom: 6px; }
.auth-card > p.small { color: var(--text-muted); margin-bottom: 16px; }
.auth-switch { font-size: 0.82rem; color: var(--text-muted); margin-top: 14px; text-align: center; }
.auth-switch a { color: var(--accent); text-decoration: none; }
.auth-guest { display: block; text-align: center; margin-top: 12px; font-size: 0.82rem; color: var(--text-muted); text-decoration: none; }
.auth-guest:hover { color: var(--text-secondary); }

.dropzone { border: 2px dashed var(--axis); border-radius: var(--radius); padding: 22px;
  text-align: center; cursor: pointer; color: var(--text-secondary); transition: background 0.12s, border-color 0.12s; }
.dropzone:hover, .dropzone.dragover { background: var(--accent-wash); border-color: var(--accent); }
.dropzone .dz-icon { font-size: 1.6rem; color: var(--accent); margin-bottom: 6px; }
.import-status { font-size: 0.86rem; background: var(--page); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.import-status ul { margin-left: 16px; list-style: disc; color: var(--status-critical); }
details summary { cursor: pointer; font-size: 0.84rem; color: var(--text-secondary); }
details p { margin: 6px 0; }
details code { background: var(--page); padding: 1px 5px; border-radius: 4px; font-size: 0.82em; }
.note {
  border-left: 3px solid var(--accent); background: var(--accent-wash);
  padding: 10px 12px; border-radius: 0 8px 8px 0; font-size: 0.84rem; margin: 10px 0;
}
.empty { color: var(--text-muted); font-size: 0.86rem; padding: 18px 0; text-align: center; }

@media print {
  .sidebar, .filter-row, .btn { display: none !important; }
  .main { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
}

@media (max-width: 760px) {
  .app { flex-direction: column; }
  /* Sidebar becomes a sticky, horizontally-scrolling top bar. The safe-area insets
     keep the nav clear of the notch / status bar when launched from the home
     screen (standalone PWA with viewport-fit=cover). */
  .sidebar {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 30;
    flex-direction: row; align-items: center; gap: 2px;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    border-right: none; border-bottom: 1px solid var(--border);
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .brand { padding: 10px 12px; flex-shrink: 0; }
  .brand-name { font-size: 1.05rem; }
  .nav { flex-direction: row; padding: 6px 4px; gap: 2px; }
  .nav a { padding: 8px 10px; white-space: nowrap; font-size: 0.86rem; }
  .nav-icon { display: none; }
  .sidebar-footer { margin: 0; padding: 6px 8px; display: flex; gap: 6px; flex-shrink: 0; }
  .main { padding: 14px 14px calc(60px + env(safe-area-inset-bottom)); }
  .view-header h1 { font-size: 1.18rem; }

  /* Calendar on mobile is week-view only (Views.calendar forces it), so the
     month grid never renders here — the week's day-cards (.vd-weekgrid) have
     their own responsive layout below. */

  /* Wide data tables scroll horizontally instead of overflowing the viewport. */
  table.data { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
  .metric-row { gap: 12px 18px; }
}

@media (max-width: 460px) {
  .view-header .sub { font-size: 0.8rem; }
}
