/* RUNAPP v1.2.0 — dark athletic theme.
   v1.2.0 (2026-09-07): Hidden PBs gained a source column and an
   explanation card (.pb-source, .pb-note) for PBs that come from a race
   certificate rather than the watch.
   v1.1.0 (2026-09-07): Race Calendar gained a Completed section
   (.section-head, .race-stats) and Coach Bru gained the block's
   standing rules (.rule-row). Card values and notes now break inside a
   long unbroken word rather than pushing the page sideways.
   v1.0.1 (2026-07-23): mobile overflow fix — tiles now shrink below
   their content width (min-width:0), tile numbers scale down on narrow
   screens via clamp(), badges wrap, and the page can't scroll
   sideways. Found on Johann's phone right after cutover: the grid's
   third column was pushed off-screen by long content ("244 m/min",
   "days to Linton's Corner Spring Race").
   Signature: race-bib condensed numerals (Barlow Condensed, tabular)
   with a hairline status underline on every tile/card. Status palette
   carried over 1:1 from the Streamlit app so meanings stay learned:
   green #4ade80 good · amber #fbbf24 watch · red #f87171 risk ·
   blue #60a5fa easy · violet #7f77dd coach · route-green #39d98a. */

:root {
  --bg: #0d0f13;
  --surface: #171a20;
  --surface-2: #1e222a;
  --border: #262b33;
  --text: #e8eaed;
  --muted: #8b929c;
  --good: #4ade80;
  --warn: #fbbf24;
  --risk: #f87171;
  --easy: #60a5fa;
  --coach: #7f77dd;
  --route: #39d98a;
  --display: "Barlow Condensed", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
  min-height: 100dvh;
}

.hidden { display: none !important; }

/* ---------- shared bits ---------- */

.eyebrow {
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--muted);
  font-weight: 600;
}

.num {
  font-family: var(--display);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: 600 14px var(--body);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible { outline: 2px solid var(--route); outline-offset: 2px; }
.btn-primary { background: var(--route); border-color: var(--route); color: #08130d; }
.btn-primary:hover { background: #2fc57c; }
.btn-ghost { background: transparent; }
.btn-full { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: default; }

/* ---------- login ---------- */

.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
}
.login-title {
  font-family: var(--display);
  font-size: 42px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1;
  margin: 6px 0 4px;
  border-bottom: 2px solid var(--route);
  display: inline-block;
  padding-bottom: 4px;
}
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.field-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 12px 0 4px;
}
#login-form input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px; /* 16px stops iOS zoom-on-focus */
  padding: 11px 12px;
}
#login-form input:focus-visible { outline: 2px solid var(--route); outline-offset: 1px; }
#login-form button { margin-top: 18px; }
.login-error { color: var(--risk); font-size: 13px; margin-top: 12px; }

/* ---------- app frame ---------- */

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) 14px calc(20px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px 12px;
}
.topbar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 12px;
  letter-spacing: 0.18em;
  font-weight: 700;
}
.topbar-mark { font-size: 16px; }
.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.sync-dot.ok { background: var(--good); }
.sync-dot.busy { background: var(--warn); animation: pulse 1.2s infinite; }
.sync-dot.err { background: var(--risk); }
@keyframes pulse { 50% { opacity: 0.35; } }

.view-root { min-height: 55vh; }

.view {
  animation: viewin 0.18s ease-out;
}
@keyframes viewin {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .view { animation: none; }
  .sync-dot.busy { animation: none; }
}

.view-title {
  font-family: var(--display);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.03em;
  margin: 4px 0 2px;
}
.view-sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }

/* ---------- overview grid ---------- */

.tile-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.tile {
  min-width: 0; /* let grid columns shrink below content width */
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 6px;
  text-align: center;
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s, transform 0.1s;
}
.tile:active { transform: scale(0.97); }
.tile:hover { background: var(--surface-2); }
.tile:focus-visible { outline: 2px solid var(--route); outline-offset: 2px; }

.tile-icon { font-size: 22px; line-height: 1.2; }
.tile-value {
  font-family: var(--display);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: clamp(17px, 6.2vw, 26px);
  max-width: 100%;
  line-height: 1.1;
  padding-bottom: 3px;
  border-bottom: 2px solid transparent; /* status underline — set inline */
}
.tile-badge {
  font-size: 10px;
  font-weight: 600;
  line-height: 1.25;
  max-width: 100%;
  overflow-wrap: break-word;
}
.tile-label { font-size: 10px; color: var(--muted); margin-top: 2px; }

.tile-placeholder {
  border-style: dashed;
  background: transparent;
  color: #4a505a;
  font-size: 11px;
  cursor: default;
}
.tile-placeholder:hover { background: transparent; }

/* ---------- status cards (view pages) ---------- */

.status-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
}
.status-card .card-label { font-size: 12px; color: var(--muted); }
.status-card .card-value {
  font-family: var(--display);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 30px;
  line-height: 1.15;
  /* Race names come from the database and are as long as whoever named
     the race made them. A name with no spaces in it would otherwise
     widen the card and take the whole page sideways with it - the same
     class of bug as the v1.0.1 tile fix above. */
  overflow-wrap: anywhere;
}
.pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  color: #101010;
  border-radius: 999px;
  padding: 3px 10px;
  margin-top: 4px;
}
.card-note { color: var(--muted); font-size: 13px; margin-top: 6px; overflow-wrap: anywhere; }

.card-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card-row .status-card { margin-bottom: 0; }
.card-row { margin-bottom: 10px; }

/* ---------- charts & tables ---------- */

.chart-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
}
.chart-box svg { display: block; width: 100%; height: auto; }
.chart-title { font-size: 12px; color: var(--muted); margin-bottom: 8px; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.data-table tr:last-child td { border-bottom: none; }

.table-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px 4px;
  margin-bottom: 10px;
  overflow-x: auto;
}

details.expand {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 10px;
}
details.expand > summary {
  cursor: pointer;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  list-style: none;
}
details.expand > summary::-webkit-details-marker { display: none; }
details.expand > summary::after { content: " +"; color: var(--muted); }
details.expand[open] > summary::after { content: " −"; }
details.expand .expand-body { padding: 0 16px 14px; }

/* ---------- share card view ---------- */

.run-select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  padding: 11px 12px;
  margin-bottom: 10px;
}
.toggle-row { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.toggle-row label { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.toggle-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--route); }
.share-preview { text-align: center; }
.share-preview img {
  max-width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin: 10px 0;
}
.share-loading { color: var(--muted); font-size: 13px; padding: 16px 0; }

/* ---------- coach view ---------- */

.gauge-box { margin-top: 8px; }
.session-day { font-weight: 700; }

.rule-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 0;
  font-size: 14px;
  border-bottom: 0.5px solid rgba(255, 255, 255, 0.08);
}
.rule-row:last-child { border-bottom: none; }
.rule-num {
  flex: 0 0 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--coach);
  color: #0d0f13;
  font-family: var(--display);
  font-weight: 700;
  font-size: 13px;
  line-height: 22px;
  text-align: center;
}

/* ---------- hidden PBs ---------- */

/* Marks a PB that came from a race certificate rather than the watch.
   Amber, matching the "worth knowing" meaning the palette already
   carries, so the badge reads as a qualifier and not as an alert. */
.pb-source {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--warn);
  border: 1px solid var(--warn);
  border-radius: 999px;
  padding: 1px 7px;
  white-space: nowrap;
}
.pb-note {
  padding: 8px 0;
  border-bottom: 0.5px solid rgba(255, 255, 255, 0.08);
}
.pb-note:last-child { border-bottom: none; }

/* ---------- race calendar ---------- */

/* Upcoming / Completed. Two labelled runs of big cards rather than one
   long undifferentiated list - the split is the whole point of the
   view, and it has to survive at phone width. */
.section-head {
  font-family: var(--display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 18px 0 8px;
}
.view > .section-head:first-of-type { margin-top: 4px; }

/* Result numbers on a completed race, as blocks rather than a row of
   table cells - Jaunn reads these at a glance on a phone. auto-fit
   keeps them one row on a wide screen and reflows to two on a narrow
   one without a media query. */
.race-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(74px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.race-stat { min-width: 0; }
.race-stat-label {
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.race-stat-value {
  font-family: var(--display);
  font-size: clamp(17px, 5vw, 21px);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

/* ---------- footer ---------- */

.footer {
  margin-top: 26px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.footer-actions { display: flex; gap: 10px; margin-top: 10px; }
.footer-actions .btn { flex: 1; }
.footer-caption { color: var(--muted); font-size: 12px; margin-top: 10px; }
.summary-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 14px;
}
.summary-stats .stat-label { font-size: 11px; color: var(--muted); }
.summary-stats .stat-value {
  font-family: var(--display);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 24px;
}
.footer-version { margin-top: 16px; }

/* ---------- desktop ---------- */

@media (min-width: 700px) {
  .app { max-width: 640px; }
  .summary-stats { grid-template-columns: repeat(4, 1fr); }
}
