:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #dfe3e8;
  --text: #1f2933;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --swim: #0891b2;
  --bike: #d97706;
  --run: #16a34a;
  --strength: #7c3aed;
  --danger: #dc2626;
  --warmup: #93c5fd;
  --active: #2563eb;
  --recovery: #a7f3d0;
  --cooldown: #cbd5e1;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

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

/* ---- Chrome ---- */

.topnav {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.6rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topnav .brand { font-weight: 700; color: var(--text); }
.topnav a { color: var(--muted); font-weight: 500; }
.topnav a.current { color: var(--accent); }

main.page { max-width: 1100px; margin: 0 auto; padding: 1.25rem; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.page-head h1 { margin: 0; font-size: 1.4rem; }

.flash {
  margin: 0 0 1rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
}

/* ---- Buttons & forms ---- */

.btn {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-danger { color: var(--danger); }
.btn.confirm-armed { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 700; }
.btn-sm { padding: 0.15rem 0.5rem; font-size: 0.8rem; }

label.field { display: block; margin-bottom: 0.75rem; font-size: 0.9rem; }
label.field span { display: block; margin-bottom: 0.2rem; color: var(--muted); }

input[type="text"], input[type="number"], input[type="date"], select, textarea {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: #fff;
  color: var(--text);
}

/* ---- Cards / panels ---- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
}

/* ---- Sport badges ---- */

.sport-badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.sport-swim { background: var(--swim); }
.sport-bike { background: var(--bike); }
.sport-run { background: var(--run); }
.sport-strength { background: var(--strength); }

/* ---- Workout library ---- */

.workout-table { width: 100%; border-collapse: collapse; }
.workout-table th, .workout-table td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.workout-table th { color: var(--muted); font-weight: 600; }

/* ---- Calendar ---- */

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr) 8.5rem;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.cal-week-summary {
  background: #f8fafc;
  padding: 0.45rem 0.5rem;
  font-size: 0.78rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.cal-week-summary.empty { color: var(--muted); align-items: center; justify-content: center; }
.ws-row { display: flex; justify-content: space-between; align-items: center; gap: 0.4rem; }
.ws-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
}
.ws-planned { color: var(--muted); }

.cal-dow {
  background: var(--surface);
  padding: 0.35rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
}

.cal-day {
  background: var(--surface);
  min-height: 7.5rem;
  padding: 0.35rem 0.4rem;
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  position: relative;
}
.cal-day.detailed { min-height: 24rem; }
.cal-day.other-month { background: #fafbfc; color: var(--muted); }
.cal-day.drag-over { outline: 2px dashed var(--accent); outline-offset: -2px; background: var(--accent-soft); }
.cal-day .day-head { display: flex; align-items: center; justify-content: space-between; }
.cal-day .daynum { font-weight: 600; font-size: 0.75rem; color: var(--muted); }
.cal-day.today .daynum {
  color: #fff;
  background: var(--accent);
  border-radius: 999px;
  width: 1.4rem;
  height: 1.4rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.cal-day .day-add {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.2rem;
  border-radius: 4px;
  opacity: 0;
}
.cal-day:hover .day-add, .cal-day .day-add:focus-visible { opacity: 1; }
.cal-day .day-add:hover { color: var(--accent); background: var(--accent-soft); }

.cal-entry {
  /* Border encodes status (green = done, gray = outstanding); the icon color carries the sport. */
  border-left: 3px solid #cbd5e1;
  background: var(--bg);
  border-radius: 4px;
  padding: 0.25rem 0.4rem;
  line-height: 1.25;
  position: relative;
}
.cal-entry.completed { border-left-color: var(--run); opacity: 0.75; }
.cal-entry.skipped { opacity: 0.45; }
.cal-entry .entry-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.25rem; }
.entry-menu-btn {
  border: none;
  background: none;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0 0.15rem;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0;
}
.cal-entry:hover .entry-menu-btn, .entry-menu-btn:focus-visible { opacity: 1; }
.entry-menu-btn:hover { color: var(--accent); background: var(--accent-soft); }
.entry-menu {
  position: absolute;
  top: 1.5rem;
  right: 0.25rem;
  z-index: 30;
  min-width: 8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(31, 41, 51, 0.18);
  display: flex;
  flex-direction: column;
  padding: 0.25rem;
}
.entry-menu a, .entry-menu button {
  text-align: left;
  padding: 0.35rem 0.6rem;
  font-size: 0.82rem;
  color: var(--text);
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.entry-menu a:hover, .entry-menu button:hover { background: var(--accent-soft); text-decoration: none; }
.entry-menu .menu-danger { color: var(--danger); }
.cal-entry { cursor: grab; }
.cal-entry:active { cursor: grabbing; }
.cal-entry .entry-name {
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  color: var(--text);
}
.cal-entry .entry-icon { display: inline-flex; flex-shrink: 0; }
.sport-text-swim { color: var(--swim); }
.sport-text-bike { color: var(--bike); }
.sport-text-run { color: var(--run); }
.sport-text-strength { color: var(--strength); }
.cal-entry .entry-desc {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 0.2rem;
  white-space: pre-line;
}
.cal-entry .entry-meta { color: var(--muted); font-size: 0.72rem; }

.cal-controls { display: flex; gap: 0.35rem; align-items: center; }
.view-toggle { margin-right: 0.75rem; display: inline-flex; gap: 0.25rem; }

/* ---- Add-workout popover ---- */

.add-popover {
  position: absolute;
  top: 1.8rem;
  right: 0.25rem;
}
.add-popover.align-left { right: auto; left: 0.25rem; }
.add-popover.open-up { top: auto; bottom: 1.6rem; }
.add-popover {
  z-index: 20;
  width: 15rem;
  max-height: 18rem;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(31, 41, 51, 0.18);
  padding: 0.4rem;
}
.add-popover .pop-empty { margin: 0.25rem; font-size: 0.8rem; color: var(--muted); }
.pop-group + .pop-group { margin-top: 0.4rem; }
.pop-group-head {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.3rem;
}
.pop-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  width: 100%;
  border: none;
  background: none;
  padding: 0.3rem 0.4rem;
  border-radius: 5px;
  font-size: 0.82rem;
  cursor: pointer;
  text-align: left;
}
.pop-item:hover { background: var(--accent-soft); }
.pop-item-name { font-weight: 500; }
.pop-item-meta { color: var(--muted); font-size: 0.72rem; white-space: nowrap; }

/* ---- Ride screen ---- */

.chip {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  background: var(--bg);
  border: 1px solid var(--border);
}
.chip-ok { background: #dcfce7; border-color: #16a34a; color: #14532d; font-weight: 600; }

.ride-connect .connect-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}
.ride-connect .connect-row strong { width: 6.5rem; font-size: 0.9rem; }
.ride-note { color: var(--muted); font-size: 0.85rem; }
.ride-start { margin-top: 0.5rem; font-size: 1rem; padding: 0.55rem 1.4rem; }
.ride-totals { display: flex; gap: 1.5rem; margin-top: 0.5rem; color: var(--muted); font-size: 0.9rem; }
.ride-linked { color: var(--run); font-weight: 600; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  display: flex;
  flex-direction: column;
}
.metric-accent { background: #1f2933; border-color: #1f2933; color: #fff; }
.metric-accent .metric-label { color: #9aa5b1; }
.metric-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.metric-value { font-size: 2.1rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.metric-unit { font-size: 0.9rem; font-weight: 500; margin-left: 0.25rem; color: var(--muted); }
.metric-accent .metric-unit { color: #9aa5b1; }
.metric-sub { font-size: 0.78rem; color: var(--muted); }

.ride-chart { margin-bottom: 1rem; }
.ride-stepinfo {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.5rem;
  font-size: 0.9rem;
}
.ride-next { color: var(--muted); }

.ride-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.nav-user {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.nav-signout { display: inline; }

.auth-panel { max-width: 380px; margin: 3rem auto; }
.field-label { display: block; margin-bottom: 0.8rem; font-size: 0.9rem; font-weight: 600; }
.field-input {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.45rem 0.6rem;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.field-check { display: block; margin-bottom: 0.8rem; font-size: 0.9rem; }

.ride-feel {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.ride-feel-label { font-weight: 600; }
.ride-feel-scale { display: inline-flex; gap: 0.35rem; }
.ride-feel-notes {
  flex: 1 1 16rem;
  font: inherit;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  resize: vertical;
}
.bias-group { display: inline-flex; align-items: center; gap: 0.35rem; }
.bias-value { font-size: 0.85rem; color: var(--muted); min-width: 4.5rem; text-align: center; }
.ride-endprompt { font-weight: 600; }

.recovery-banner { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.journey-option { font-size: 0.9rem; }
.ramp-result { font-size: 0.95rem; }
.recovery-actions { display: inline-flex; gap: 0.4rem; margin-left: auto; }

.ride-route-head { margin-bottom: 0.5rem; font-size: 0.9rem; }
.journey-bar {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.2rem;
}
.journey-fill { height: 100%; background: var(--run); border-radius: 999px; }
.journey-label { font-size: 0.75rem; color: var(--muted); }
.route-layout { display: flex; gap: 0.75rem; align-items: stretch; }
.route-map-wrap { flex: 1; position: relative; min-width: 0; }
.route-side {
  width: 9.5rem;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.route-side .metric { padding: 0.5rem 0.7rem; }
.route-side .metric-value { font-size: 1.5rem; }
.map-recenter {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  z-index: 1000; /* above Leaflet panes */
  box-shadow: 0 2px 8px rgba(31, 41, 51, 0.25);
}
@media (max-width: 700px) {
  .route-layout { flex-direction: column; }
  .route-side { width: auto; flex-direction: row; flex-wrap: wrap; }
}
.free-target-panel { display: flex; align-items: center; gap: 0.5rem; }
.free-target-value {
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-left: 0.5rem;
}

/* ---- Charts ---- */

.chart-legend { display: flex; gap: 1rem; margin-bottom: 0.4rem; font-size: 0.8rem; color: var(--muted); }
.chart-legend-item { display: inline-flex; align-items: center; gap: 0.35rem; }
.chart-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  vertical-align: baseline;
}
.chart-title { margin: 0 0 0.5rem; font-size: 0.95rem; }
.chart-note { margin: 0.6rem 0 0; font-size: 0.8rem; color: var(--muted); }

/* ---- Completed activities on the calendar ---- */

.activity-card { cursor: default; border-left-color: var(--run); }
.entry-actual {
  display: block;
  font-size: 0.75rem;
  color: var(--run);
  font-weight: 600;
  margin-top: 0.1rem;
}
