:root {
  --bg: #0f1117; --surface: #1a1d27; --surface-hover: #232736; --border: #2a2d3a;
  --text: #e4e4e7; --muted: #9ca3af; --accent: #6366f1;
  --green: #22c55e; --yellow: #eab308; --red: #ef4444;
  --blue: #3b82f6; --orange: #f97316; --purple: #a855f7;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
       background: var(--bg); color: var(--text); line-height: 1.5; }

.nav { background: var(--surface); border-bottom: 1px solid var(--border); display: flex; padding: 1rem 2rem; align-items: center; justify-content: space-between; }
.nav-brand { font-weight: 700; font-size: 1.2rem; }
.nav-links a { color: var(--muted); text-decoration: none; margin-left: 1.5rem; font-weight: 500; transition: color 0.2s; }
.nav-links a:hover { color: var(--text); }

.banner { padding: 0.75rem 2rem; text-align: center; font-weight: 600; font-size: 0.9rem; display: flex; align-items: center; justify-content: center; gap: 0.75rem; flex-wrap: wrap; }
.banner.warning { background: rgba(234, 179, 8, 0.2); color: var(--yellow); }
.banner.ok { background: rgba(34, 197, 94, 0.1); color: var(--green); }
.banner .filter-btn { font-weight: 600; font-size: 0.8rem; padding: 0.3rem 0.9rem; }
.banner .filter-btn:disabled { opacity: 0.6; cursor: default; }

.container { padding: 1.5rem 2rem; max-width: 1400px; margin: 0 auto; }
h1, h2, h3 { margin-bottom: 0.75rem; }
h1 { font-size: 1.8rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; margin-bottom: 1.5rem; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 0.75rem; padding: 1.25rem; }
.card-header { font-size: 0.75rem; text-transform: uppercase; color: var(--muted); letter-spacing: 0.05em; margin-bottom: 0.5rem; font-weight: 600; }
.stat-hero { font-size: 2.5rem; font-weight: 800; line-height: 1; margin-bottom: 0.25rem; }
.stat { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.stat-unit { font-size: 1rem; font-weight: 400; color: var(--muted); margin-left: 0.2rem; }
.stat-label { font-size: 0.85rem; color: var(--muted); margin-top: 0.25rem; }

/* A row of small stat cards that reflows on its own. Unlike .grid-3 / .grid-4
   the column count is not fixed, because the caller does not always know it:
   a segment drops the stats it has no data for, so the same markup renders
   anywhere from four tiles to nine. */
.stat-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  margin-bottom: 2rem;
}

table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th { text-align: left; color: var(--muted); font-weight: 600; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); font-size: 0.8rem; text-transform: uppercase; }
td { padding: 1rem; border-bottom: 1px solid var(--border); }
tr.clickable:hover { background: var(--surface-hover); cursor: pointer; }

.sport-icon { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 0.5rem; vertical-align: middle; }
.sport-running { background: var(--green); }
.sport-cycling { background: var(--blue); }
.sport-strength { background: var(--orange); }
.sport-swimming { background: var(--purple); }
.sport-other { background: var(--muted); }

.badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge-green { background: rgba(34, 197, 94, 0.2); color: var(--green); }
.badge-yellow { background: rgba(234, 179, 8, 0.2); color: var(--yellow); }
.badge-red { background: rgba(239, 68, 68, 0.2); color: var(--red); }
.badge-blue { background: rgba(59, 130, 246, 0.2); color: var(--blue); }
.badge-orange { background: rgba(249, 115, 22, 0.2); color: var(--orange); }
.badge-outline { border: 1px solid var(--border); color: var(--text); }

.workout-box { background: var(--surface); border: 1px solid var(--accent); border-radius: 0.75rem; padding: 1.25rem; font-size: 0.95rem; line-height: 1.6; white-space: pre-wrap; margin-bottom: 1.5rem; }

/* Chart.js canvases, which have to be told to fill their card.
 *
 * Explicitly not Leaflet's. Leaflet draws its tiles' overlays into a canvas it
 * positions inside a zero-size pane, so `width: 100% !important` resolves to
 * zero and `max-height` crops what is left: the heat layer renders every point
 * correctly into a canvas nobody can see, which looks exactly like a heatmap
 * with no data behind it. */
canvas:not([class*="leaflet"]) { width: 100% !important; max-height: 300px; }

.sparkline-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.sparkline-label { font-size: 0.9rem; font-weight: 500; }
.sparkline-val { font-size: 1.1rem; font-weight: 700; }

.filter-bar { margin-bottom: 1rem; display: flex; gap: 0.5rem; }
.filter-btn { background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 0.4rem 1rem; border-radius: 999px; cursor: pointer; font-size: 0.85rem; font-weight: 600; transition: all 0.2s; }
.filter-btn:hover { border-color: var(--muted); }
.filter-btn.active { background: var(--text); color: var(--bg); border-color: var(--text); }

#map { height: 400px; border-radius: 0.75rem; margin-bottom: 1.5rem; background: var(--surface); z-index: 1; }

@media (max-width: 768px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}

/* Hover-explain badge, used across pages next to jargon (CTL/ATL/TSS/etc). */
.info-dot {
  display:inline-flex; align-items:center; justify-content:center;
  width:16px; height:16px; border-radius:50%;
  background:var(--border); color:var(--muted);
  font-size:0.7rem; font-weight:700; cursor:help;
  margin-left:0.4rem; position:relative; vertical-align:middle;
}
.info-dot .tip {
  visibility:hidden; opacity:0; position:absolute; z-index:20;
  bottom:130%; left:0; transform:translateX(-10%);
  width:240px; max-width:70vw; background:var(--surface-2,#1a1d29); color:var(--text);
  border:1px solid var(--border); border-radius:0.5rem;
  padding:0.6rem 0.75rem; font-size:0.8rem; font-weight:400;
  line-height:1.4; text-transform:none; letter-spacing:normal;
  box-shadow:0 4px 16px rgba(0,0,0,0.4);
  transition:opacity 0.15s;
}
.info-dot:hover .tip { visibility:visible; opacity:1; }

/* --- Heatmap page -------------------------------------------------------- */

/* Taller than the shared #map: this view is about recognising the shape of a
   whole city's worth of routes, which a 400px strip cannot convey. */
#heatmap { height: min(70vh, 620px); border-radius: 0.75rem; background: var(--surface); z-index: 1; }

/* Calendar grid. Columns are weeks and rows are weekdays, so a year reads
   left-to-right like a timeline and training rhythm shows up as horizontal
   banding. grid-auto-flow:column is what puts the weeks on the x-axis. */
.cal-heatmap { display: flex; gap: 0.75rem; align-items: flex-start; overflow-x: auto; padding-bottom: 0.5rem; }
.cal-weekdays { display: grid; grid-template-rows: repeat(7, 13px); gap: 3px; font-size: 0.65rem; color: var(--muted); padding-top: 18px; flex: none; }
.cal-body { flex: none; }
.cal-months { display: grid; grid-auto-flow: column; font-size: 0.7rem; color: var(--muted); height: 18px; }
.cal-grid { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 13px); gap: 3px; }
.cal-day { width: 13px; height: 13px; border-radius: 3px; background: var(--border); }
/* Five buckets rather than a continuous gradient: an eye cannot rank a
   continuous shade, but it can count categories. */
.cal-day.l0 { background: #1e2130; }
.cal-day.l1 { background: rgba(99, 102, 241, 0.3); }
.cal-day.l2 { background: rgba(99, 102, 241, 0.5); }
.cal-day.l3 { background: rgba(99, 102, 241, 0.72); }
.cal-day.l4 { background: var(--accent); }
/* Days outside the requested range still occupy a cell so the weekday rows
   stay aligned, but must not read as rest days. */
.cal-day.pad { background: transparent; }
.cal-day.today { box-shadow: 0 0 0 1px var(--text); }
.cal-legend { display: flex; align-items: center; gap: 0.3rem; font-size: 0.75rem; color: var(--muted); margin-top: 0.75rem; justify-content: flex-end; }
.cal-legend .cal-day { cursor: default; }

.map-scale { display: flex; align-items: center; gap: 0.5rem; font-size: 0.75rem; color: var(--muted); margin-top: 0.75rem; }
/* Must track the leaflet.heat gradient in heatmap.html: the legend is a lie
   the moment the two drift apart. */
.map-scale .ramp { flex: 1; height: 8px; border-radius: 999px; max-width: 220px;
  background: linear-gradient(90deg, #1d4ed8 0%, #6d28d9 35%, #a21caf 55%, #db2777 75%, #dc2626 100%); }

.hm-note { color: var(--muted); font-size: 0.8rem; margin-top: 0.5rem; line-height: 1.5; }
.hm-empty { color: var(--muted); padding: 2rem; text-align: center; }

/* `hidden` is a UA `display:none`, which a class setting `display:flex` wins
   against — so a hidden filter bar would still render. */
.filter-bar[hidden] { display: none; }
/* Disciplines sit under their sport, visually subordinate to it. */
#subSportFilter { margin-top: -0.5rem; margin-bottom: 1rem; }
#subSportFilter .filter-btn { font-size: 0.75rem; padding: 0.25rem 0.75rem; }
