/* =============================================================
   Workouts — Strava dashboard mini-site
   Design system: tokens, layout, components.
   No framework. Mobile-first. Light + dark via prefers-color-scheme
   with a manual override on <html data-theme="light|dark">.
   ============================================================= */

/* ---------- Design tokens ---------- */
:root {
  color-scheme: light dark;

  /* Neutral surfaces (light) */
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-surface-2: #f1f5f9;
  --color-text: #0f172a;
  --color-muted: #64748b;
  --color-border: #e2e8f0;

  /* Brand + status */
  --color-accent: #fc4c02;        /* Strava orange */
  --color-accent-contrast: #ffffff;
  --color-good: #16a34a;
  --color-warn: #d97706;
  --color-danger: #dc2626;

  /* Sport categorical palette (distinguishable in light + dark) */
  --sport-run: #fc4c02;
  --sport-ride: #2563eb;
  --sport-swim: #0891b2;
  --sport-walk: #16a34a;
  --sport-hike: #65a30d;
  --sport-workout: #7c3aed;
  --sport-other: #64748b;

  /* Shape + depth */
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.05);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.08);

  /* Rhythm */
  --space: 1rem;
  --maxw: 1120px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0b1120;
    --color-surface: #111a2e;
    --color-surface-2: #172136;
    --color-text: #e2e8f0;
    --color-muted: #94a3b8;
    --color-border: #24304a;
    --color-accent: #ff6a33;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --sport-run: #ff6a33;
    --sport-ride: #60a5fa;
    --sport-swim: #22d3ee;
    --sport-walk: #4ade80;
    --sport-hike: #a3e635;
    --sport-workout: #a78bfa;
  }
}

/* Manual theme override (set by the toggle) wins over the media query */
html[data-theme="light"] {
  --color-bg: #f8fafc; --color-surface: #ffffff; --color-surface-2: #f1f5f9;
  --color-text: #0f172a; --color-muted: #64748b; --color-border: #e2e8f0;
  --color-accent: #fc4c02;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.05);
  --sport-run: #fc4c02; --sport-ride: #2563eb; --sport-swim: #0891b2;
  --sport-walk: #16a34a; --sport-hike: #65a30d; --sport-workout: #7c3aed;
}
html[data-theme="dark"] {
  --color-bg: #0b1120; --color-surface: #111a2e; --color-surface-2: #172136;
  --color-text: #e2e8f0; --color-muted: #94a3b8; --color-border: #24304a;
  --color-accent: #ff6a33;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  --sport-run: #ff6a33; --sport-ride: #60a5fa; --sport-swim: #22d3ee;
  --sport-walk: #4ade80; --sport-hike: #a3e635; --sport-workout: #a78bfa;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  background-color: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.6rem; letter-spacing: -0.02em; }
h2 { font-size: 1.2rem; letter-spacing: -0.01em; }
h3 { font-size: 1rem; }
p { margin: 0 0 1rem; }

a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.container { max-width: var(--maxw); margin: 0 auto; padding: 0 1.25rem; }

.muted { color: var(--color-muted); }
.small { font-size: .82rem; }
.mono { font-variant-numeric: tabular-nums; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Header / nav ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--color-surface) 88%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--color-border);
}
.site-header .container {
  display: flex; align-items: center; gap: 1rem;
  height: 60px;
}
.brand {
  display: flex; align-items: center; gap: .55rem;
  font-weight: 700; color: var(--color-text); letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.brand img { width: 26px; height: 26px; }
.brand .tag {
  font-size: .62rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--color-accent-contrast);
  background: var(--color-accent); padding: .1rem .4rem; border-radius: 999px;
}

.nav { display: flex; gap: .25rem; margin-left: auto; align-items: center; }
.nav a {
  color: var(--color-muted); font-weight: 600; font-size: .9rem;
  padding: .45rem .7rem; border-radius: var(--radius-sm);
}
.nav a:hover { color: var(--color-text); background: var(--color-surface-2); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--color-text); background: var(--color-surface-2); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: var(--radius-sm);
  border: 1px solid var(--color-border); background: var(--color-surface);
  color: var(--color-text); cursor: pointer; font-size: 1.05rem;
}
.icon-btn:hover { background: var(--color-surface-2); }

/* Mobile nav toggle */
.nav-toggle { display: none; }
@media (max-width: 720px) {
  .nav-toggle { display: inline-flex; }
  .nav {
    position: absolute; top: 60px; left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: .1rem;
    background: var(--color-surface); border-bottom: 1px solid var(--color-border);
    padding: .5rem 1.25rem 1rem; margin: 0;
    display: none;
  }
  .nav.open { display: flex; }
  .nav a { padding: .7rem .5rem; }
}

/* ---------- Page scaffolding ---------- */
main { padding: 1.75rem 0 3rem; }
.page-head { margin-bottom: 1.5rem; }
.page-head .eyebrow {
  text-transform: uppercase; letter-spacing: .09em; font-size: .7rem;
  font-weight: 700; color: var(--color-accent); margin-bottom: .35rem;
}
.page-head .lede { color: var(--color-muted); max-width: 60ch; margin: 0; }

.section { margin: 2rem 0; }
.section > .section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; margin-bottom: .85rem;
}
.section-head a { font-size: .85rem; font-weight: 600; }

/* Demo banner */
.banner {
  display: flex; gap: .6rem; align-items: flex-start;
  background: color-mix(in srgb, var(--color-warn) 12%, var(--color-surface));
  border: 1px solid color-mix(in srgb, var(--color-warn) 40%, var(--color-border));
  color: var(--color-text);
  border-radius: var(--radius); padding: .7rem .9rem; margin-bottom: 1.5rem;
  font-size: .88rem;
}
.banner strong { color: var(--color-warn); }

/* ---------- Grid ---------- */
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.dashboard { grid-template-columns: repeat(12, 1fr); }
.span-4 { grid-column: span 4; }
.span-6 { grid-column: span 6; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }

@media (max-width: 900px) {
  .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.dashboard { grid-template-columns: repeat(6, 1fr); }
  .span-4 { grid-column: span 3; }
  .span-6, .span-8 { grid-column: span 6; }
}
@media (max-width: 560px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .grid.dashboard { grid-template-columns: 1fr; }
  .span-4, .span-6, .span-8, .span-12 { grid-column: 1 / -1; }
}

/* ---------- Card ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.15rem;
}
.card .card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; margin-bottom: .85rem;
}
.card .card-head h3 { margin: 0; font-size: .95rem; }
.card .card-head .muted { font-size: .8rem; }

/* ---------- Stat tile ---------- */
.stat { display: flex; flex-direction: column; gap: .15rem; }
.stat .stat-label {
  font-size: .74rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--color-muted); font-weight: 600;
}
.stat .stat-value {
  font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat .stat-value .unit { font-size: .9rem; font-weight: 600; color: var(--color-muted); margin-left: .15rem; }
.stat .stat-sub { font-size: .8rem; color: var(--color-muted); }
.delta { font-weight: 600; font-size: .8rem; }
.delta.up { color: var(--color-good); }
.delta.down { color: var(--color-danger); }
.delta.flat { color: var(--color-muted); }

/* ---------- Sport chips / badges ---------- */
.chip {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .74rem; font-weight: 700; letter-spacing: .01em;
  padding: .2rem .55rem; border-radius: 999px;
  background: var(--color-surface-2); color: var(--color-text);
  border: 1px solid var(--color-border);
}
.chip .dot { width: .55rem; height: .55rem; border-radius: 50%; background: var(--sport-other); }
.chip[data-sport="Run"] .dot { background: var(--sport-run); }
.chip[data-sport="Ride"] .dot { background: var(--sport-ride); }
.chip[data-sport="Swim"] .dot { background: var(--sport-swim); }
.chip[data-sport="Walk"] .dot { background: var(--sport-walk); }
.chip[data-sport="Hike"] .dot { background: var(--sport-hike); }
.chip[data-sport="Workout"] .dot,
.chip[data-sport="WeightTraining"] .dot { background: var(--sport-workout); }

.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .72rem; font-weight: 700; padding: .15rem .5rem; border-radius: 999px;
}
.badge.good { background: color-mix(in srgb, var(--color-good) 16%, transparent); color: var(--color-good); }
.badge.warn { background: color-mix(in srgb, var(--color-warn) 18%, transparent); color: var(--color-warn); }
.badge.danger { background: color-mix(in srgb, var(--color-danger) 16%, transparent); color: var(--color-danger); }

/* ---------- Activity list ---------- */
.activity-list { display: flex; flex-direction: column; }
.activity {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: .8rem; align-items: center;
  padding: .7rem 0; border-top: 1px solid var(--color-border);
}
.activity:first-child { border-top: 0; }
.activity .a-icon {
  width: 40px; height: 40px; border-radius: 11px;
  display: grid; place-items: center; font-size: 1.15rem;
  background: var(--color-surface-2);
}
.activity .a-title { font-weight: 600; }
.activity .a-meta { font-size: .8rem; color: var(--color-muted); }
.activity .a-stats { text-align: right; font-variant-numeric: tabular-nums; }
.activity .a-stats .big { font-weight: 700; }
.activity .a-stats .sub { font-size: .78rem; color: var(--color-muted); }

/* ---------- Progress bar / goal meter ---------- */
.meter { margin: .75rem 0; }
.meter .meter-top {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: .85rem; margin-bottom: .35rem;
}
.meter .meter-top .val { font-weight: 700; font-variant-numeric: tabular-nums; }
.meter .track {
  height: 10px; border-radius: 999px; background: var(--color-surface-2);
  overflow: hidden; border: 1px solid var(--color-border);
}
.meter .fill {
  height: 100%; border-radius: 999px;
  background: var(--color-accent);
  transition: width .6s ease;
}
.meter .fill.good { background: var(--color-good); }
.meter .fill.warn { background: var(--color-warn); }
.meter .pace-hint { font-size: .76rem; color: var(--color-muted); margin-top: .3rem; }

/* Progress ring */
.ring-wrap { display: flex; align-items: center; gap: 1rem; }
.ring { --size: 96px; width: var(--size); height: var(--size); flex: none; position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track-c { stroke: var(--color-surface-2); }
.ring .fill-c { stroke: var(--color-accent); stroke-linecap: round; transition: stroke-dashoffset .7s ease; }
.ring .ring-label {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums;
}

/* ---------- Mini bar chart (weekly volume) ---------- */
.barchart { display: flex; align-items: flex-end; gap: 6px; height: 90px; }
.barchart .bar {
  flex: 1; min-width: 4px; border-radius: 5px 5px 2px 2px;
  background: var(--color-accent); opacity: .85;
  align-self: flex-end;
}
.barchart .bar:hover { opacity: 1; }
.barchart-labels { display: flex; gap: 6px; margin-top: .4rem; }
.barchart-labels span { flex: 1; text-align: center; font-size: .68rem; color: var(--color-muted); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--color-border); }
table.data th { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--color-muted); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: var(--color-surface-2); }

/* ---------- Gear ---------- */
.gear-item { display: grid; grid-template-columns: 44px 1fr; gap: .8rem; padding: .8rem 0; border-top: 1px solid var(--color-border); }
.gear-item:first-child { border-top: 0; }
.gear-item .g-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--color-surface-2); font-size: 1.3rem; }
.gear-item .g-name { font-weight: 600; }
.gear-item .g-mileage { font-size: .82rem; color: var(--color-muted); }

/* ---------- Restricted / lock ---------- */
.lock-card { text-align: center; padding: 2.5rem 1.5rem; }
.lock-card .lock-icon { font-size: 2.4rem; }
.access-links { display: flex; flex-wrap: wrap; gap: .6rem; justify-content: center; margin-top: 1rem; }
.btn {
  display: inline-flex; align-items: center; gap: .45rem;
  font-weight: 600; font-size: .9rem; padding: .6rem 1rem;
  border-radius: var(--radius-sm); border: 1px solid var(--color-border);
  background: var(--color-surface); color: var(--color-text); cursor: pointer;
}
.btn:hover { background: var(--color-surface-2); text-decoration: none; }
.btn.primary { background: var(--color-accent); color: var(--color-accent-contrast); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.05); }

/* ---------- Prose (about/docs) ---------- */
.prose { max-width: 72ch; }
.prose h2 { margin-top: 2rem; }
.prose ul { padding-left: 1.2rem; }
.prose li { margin: .3rem 0; }
.prose code {
  background: var(--color-surface-2); padding: .1rem .35rem; border-radius: 5px;
  font-size: .88em;
}

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--color-border);
  color: var(--color-muted); font-size: .85rem;
  padding: 1.5rem 0; margin-top: 2rem;
}
.site-footer .container { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; align-items: center; }
.site-footer a { color: var(--color-muted); }
.site-footer a:hover { color: var(--color-text); }
.site-footer .spacer { margin-left: auto; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
