/* Design tokens. The chart surface and series hue are the validated dark-mode
   values from the reference data-viz palette; keep them in sync if either is
   changed. */
:root {
  color-scheme: dark;

  --surface-0: #0f0f0e;   /* page */
  --surface-1: #1a1a19;   /* cards and chart surface (validator's dark surface) */
  --surface-2: #232320;   /* raised controls */
  --surface-3: #2e2e2a;   /* borders, tracks */

  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #8a897f;

  --series-1: #3987e5;    /* categorical slot 1, dark step */
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;

  --radius: 14px;
  --radius-sm: 10px;
  --tap: 48px;            /* minimum comfortable target with chalky hands */

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

body {
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

a { color: var(--series-1); text-decoration: none; }
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }

.wrap { max-width: 640px; margin: 0 auto; padding: 16px 16px 8px; }

/* ---------- header ---------- */

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px calc(4px);
  max-width: 640px; margin: 0 auto;
}
.topbar h1 { flex: 1; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--surface-2); object-fit: cover;
  display: grid; place-items: center; font-size: 0.85rem; color: var(--text-secondary);
}

/* ---------- bottom nav ---------- */

.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--surface-3);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px; color: var(--text-muted); font-size: 0.68rem;
  min-height: var(--tap); justify-content: center;
}
.nav a[aria-current="page"] { color: var(--text-primary); }
.nav a[aria-current="page"] svg { color: var(--series-1); }
.nav svg { width: 22px; height: 22px; }

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

.card {
  background: var(--surface-1);
  border: 1px solid var(--surface-3);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card-head {
  display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px;
}
.card-head h2 { flex: 1; }

.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.small { font-size: 0.8rem; }
.tabular { font-variant-numeric: tabular-nums; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 20px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  background: var(--surface-2); color: var(--text-primary);
  font: inherit; font-weight: 600; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.985); }
.btn-primary { background: var(--series-1); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--surface-3); color: var(--text-secondary); }
.btn-danger { background: transparent; border-color: var(--critical); color: var(--critical); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }

/* ---------- stat tiles ---------- */

.hero {
  font-size: 2.6rem; font-weight: 700; letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums; line-height: 1;
}
.hero-unit { font-size: 1rem; font-weight: 500; color: var(--text-muted); margin-left: 4px; }

.kpi-row {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.kpi {
  background: var(--surface-1); border: 1px solid var(--surface-3);
  border-radius: var(--radius-sm); padding: 12px 10px;
}
.kpi-value { font-size: 1.25rem; font-weight: 680; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.kpi-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- lift tiles with sparklines ---------- */

.lift-tile {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; min-height: var(--tap);
  border-bottom: 1px solid var(--surface-3);
  color: inherit;
}
.lift-tile:last-child { border-bottom: 0; }
.lift-tile-main { flex: 1; min-width: 0; }
.lift-tile-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lift-tile-sub { font-size: 0.78rem; color: var(--text-muted); }
.lift-tile-value { font-variant-numeric: tabular-nums; font-weight: 640; text-align: right; }
.spark { flex: 0 0 auto; }

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

.chart-wrap { position: relative; }
.chart { display: block; width: 100%; height: auto; touch-action: pan-y; }
.chart-grid { stroke: var(--surface-3); stroke-width: 1; }
.chart-axis-text { fill: var(--text-muted); font-size: 11px; font-family: var(--font); }
.chart-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: url(#areaFade); }
.chart-dot { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.chart-crosshair { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }

.spark-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark-area { fill: var(--series-1); opacity: 0.12; }
.spark-dot { fill: var(--series-1); }

.tooltip {
  position: absolute; pointer-events: none; z-index: 10;
  background: var(--surface-2); border: 1px solid var(--surface-3);
  border-radius: 8px; padding: 6px 9px; font-size: 0.78rem;
  box-shadow: 0 6px 20px rgba(0,0,0,0.45);
  white-space: nowrap; transform: translate(-50%, -120%);
  opacity: 0; transition: opacity 0.1s;
}
.tooltip.on { opacity: 1; }
.tooltip b { font-variant-numeric: tabular-nums; }

/* ---------- workout / warmup tabs ---------- */

/* Radio-driven so the selected tab survives htmx swaps with no JS. */
.tabs { position: relative; }
.tabs > input[type=radio] {
  position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none;
}
.tabbar {
  display: flex; gap: 4px; margin-bottom: 16px;
  background: var(--surface-2); border-radius: 999px; padding: 4px;
}
.tabbar label {
  flex: 1; margin: 0; text-align: center; cursor: pointer;
  padding: 10px 8px; border-radius: 999px;
  font-size: 0.92rem; font-weight: 620; color: var(--text-muted);
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
}
#tab-work:checked ~ .tabbar label[for="tab-work"],
#tab-warm:checked ~ .tabbar label[for="tab-warm"] {
  background: var(--surface-3); color: var(--text-primary);
}
/* The radios are visually hidden, so the focus ring has to live on the label. */
#tab-work:focus-visible ~ .tabbar label[for="tab-work"],
#tab-warm:focus-visible ~ .tabbar label[for="tab-warm"] {
  outline: 2px solid var(--series-1); outline-offset: 2px;
}
.pane { display: none; }
#tab-work:checked ~ .pane-work,
#tab-warm:checked ~ .pane-warm { display: block; }

.warmup-row {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 0; border-bottom: 1px solid var(--surface-3);
}
.warmup-row:last-child { border-bottom: 0; }
.warmup-presc { flex: 1; font-weight: 600; }
.warmup-load { color: var(--text-muted); font-size: 0.85rem; text-align: right; }
/* The work set closes the ramp as a reminder of what it builds to, but it is
   logged on the Workout tab, not here. */
.warmup-row-work { opacity: 0.5; }
.set-ghost { border-style: dashed; cursor: default; }

/* ---------- workout logging ---------- */

.exercise { border-bottom: 1px solid var(--surface-3); padding: 16px 0; }
.exercise:first-child { padding-top: 0; }
.exercise:last-child { border-bottom: 0; padding-bottom: 0; }
.exercise.is-skipped { opacity: 0.45; }

.exercise-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.exercise-head h3 { flex: 1; }
.exercise-target { font-variant-numeric: tabular-nums; color: var(--text-secondary); font-weight: 600; }

.set-row { display: flex; gap: 10px; margin: 12px 0 8px; flex-wrap: wrap; }

.set {
  width: var(--tap); height: var(--tap);
  border-radius: 50%; border: 2px solid var(--surface-3);
  background: var(--surface-2); color: var(--text-secondary);
  font: inherit; font-weight: 700; font-variant-numeric: tabular-nums;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  display: grid; place-items: center;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.set:active { transform: scale(0.94); }
.set.is-done { background: var(--good); border-color: var(--good); color: #fff; }
.set.is-partial { background: transparent; border-color: var(--warning); color: var(--warning); }
.set.is-failed { background: transparent; border-color: var(--critical); color: var(--critical); }

.plates {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  font-size: 0.75rem; color: var(--text-muted);
}
.plate {
  background: var(--surface-2); border: 1px solid var(--surface-3);
  border-radius: 6px; padding: 2px 7px; font-variant-numeric: tabular-nums;
}
.plate-warn { border-color: var(--warning); color: var(--warning); }

.warmups { font-size: 0.78rem; color: var(--text-muted); margin-top: 6px; }

/* ---------- rest timer ---------- */

.rest-bar {
  position: fixed; left: 0; right: 0;
  bottom: calc(72px + env(safe-area-inset-bottom));
  z-index: 60; display: none;
  background: var(--surface-2); border-top: 1px solid var(--surface-3);
  padding: 10px 16px;
}
.rest-bar.on { display: block; }
.rest-inner { max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.rest-time { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 68px; }
.rest-track { flex: 1; height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; }
.rest-fill { height: 100%; background: var(--series-1); border-radius: 3px; width: 100%; }
.rest-bar.overdue .rest-fill { background: var(--good); }
.rest-bar.overdue .rest-time { color: var(--good); }

/* ---------- forms ---------- */

label { display: block; font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 6px; }
input[type=text], input[type=number], input[type=file], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  background: var(--surface-2); color: var(--text-primary);
  border: 1px solid var(--surface-3); border-radius: var(--radius-sm);
  font: inherit;
}
textarea { min-height: 80px; resize: vertical; }
.field { margin-bottom: 14px; }
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; }

/* ---------- misc ---------- */

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 0.7rem; font-weight: 650; letter-spacing: 0.02em;
  background: var(--surface-2); color: var(--text-secondary);
}
.badge-warn { background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--warning); }
.badge-good { background: color-mix(in srgb, var(--good) 20%, transparent); color: #5fd35f; }

.notice {
  border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 12px;
  border: 1px solid var(--surface-3); background: var(--surface-1);
  font-size: 0.88rem;
}
.notice-error { border-color: var(--critical); color: #f0a0a0; }
.notice-good { border-color: var(--good); }

.empty { text-align: center; padding: 40px 20px; color: var(--text-muted); }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.data-table th, .data-table td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--surface-3); }
.data-table th { color: var(--text-muted); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }
.data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }

details.table-view summary {
  cursor: pointer; color: var(--text-muted); font-size: 0.8rem;
  padding: 8px 0; list-style: none;
}
details.table-view summary::-webkit-details-marker { display: none; }
details.table-view summary::before { content: "▸ "; }
details.table-view[open] summary::before { content: "▾ "; }

.login-page {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
}
.login-card { max-width: 380px; width: 100%; text-align: center; }
.btn-google {
  background: #fff; color: #1f1f1f; font-weight: 600;
}

.htmx-request .set { opacity: 0.7; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .btn:active, .set:active { transform: none; }
}
