/* ============================================================================
   STRIDE Race Lab — Design System (Swiss Athletic Telemetry · Light & Dark)
   100% Vanilla CSS, zero external CSS dependencies
   ============================================================================ */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-subtle: #eff1f5;
  --fg: #111827;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #ea580c;
  --primary-hover: #d94e07;
  --primary-fg: #ffffff;
  --strava: #fc4c02;
  --success: #16a34a;
  --warning: #d97706;
  --error: #dc2626;
  --info: #0284c7;
  --elev: #64748b;
  --ghost: #10b981;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

[data-theme="dark"] {
  --bg: #0d1015;
  --surface: #151921;
  --surface-subtle: #1c222d;
  --fg: #f1f5f9;
  --muted: #94a3b8;
  --border: #262f3e;
  --primary: #f97316;
  --primary-hover: #fb923c;
  --primary-fg: #ffffff;
  --strava: #fc4c02;
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;
  --info: #38bdf8;
  --elev: #94a3b8;
  --ghost: #34d399;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.45);
}

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

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--fg);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.tabular { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Layout containers */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 20px;
  max-width: 1400px;
  margin: 0 auto;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  letter-spacing: -0.02em;
  user-select: none;
}
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--primary);
  color: var(--primary-fg);
  display: flex;
  align-items: center;
  justify-content: center;
}
.brand-sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  display: block;
  margin-top: -2px;
}

/* Navigation Pills */
.nav-pills {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface-subtle);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow-x: auto;
}
.nav-pill {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 140ms ease;
  white-space: nowrap;
}
.nav-pill:hover { color: var(--fg); }
.nav-pill.active {
  background: var(--surface);
  color: var(--fg);
  box-shadow: var(--shadow-sm);
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}
.card-subtle {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.section-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.eyebrow {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* Grids */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-planner { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); align-items: start; }
.grid-gpx { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); }

@media (max-width: 1024px) {
  .grid-planner, .grid-gpx { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .topbar-inner { padding: 10px 14px; }
  .container { padding: 0 14px; }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 9px;
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 110ms ease, filter 130ms ease, border-color 130ms ease, background-color 130ms ease;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-fg); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-strava { background: var(--strava); color: #ffffff; }
.btn-strava:hover { filter: brightness(1.06); }
.btn-secondary {
  background: var(--surface-subtle);
  color: var(--fg);
  border-color: var(--border);
}
.btn-secondary:hover { border-color: var(--primary); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--fg); background: var(--surface-subtle); }
.btn-danger {
  background: color-mix(in srgb, var(--error) 12%, transparent);
  color: var(--error);
  border-color: color-mix(in srgb, var(--error) 28%, transparent);
}
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn-xs { padding: 3px 8px; font-size: 11px; border-radius: 6px; }

/* Inputs */
.input, select.input, textarea.input {
  width: 100%;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  transition: border-color 130ms ease, box-shadow 130ms ease;
}
.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}

/* Badges & Traffic Light Realism Banner */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.badge-good { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }
.badge-warn { background: color-mix(in srgb, var(--warning) 16%, transparent); color: var(--warning); }
.badge-bad  { background: color-mix(in srgb, var(--error) 15%, transparent); color: var(--error); }
.badge-info { background: color-mix(in srgb, var(--info) 15%, transparent); color: var(--info); }
.badge-muted { background: var(--surface-subtle); color: var(--muted); }

.realism-banner {
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.realism-banner.status-realistic {
  background: color-mix(in srgb, var(--success) 8%, var(--surface));
  border-color: color-mix(in srgb, var(--success) 35%, var(--border));
}
.realism-banner.status-ambitious {
  background: color-mix(in srgb, var(--warning) 9%, var(--surface));
  border-color: color-mix(in srgb, var(--warning) 38%, var(--border));
}
.realism-banner.status-unrealistic {
  background: color-mix(in srgb, var(--error) 9%, var(--surface));
  border-color: color-mix(in srgb, var(--error) 42%, var(--border));
}
.realism-banner.status-no_data {
  background: var(--surface-subtle);
}

/* KPI values */
.kpi-val {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.1;
}
.kpi-hero {
  font-size: 42px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
}

/* Tabs */
.subtabs {
  display: flex;
  gap: 18px;
  border-bottom: 1px solid var(--border);
  padding: 0 18px;
  overflow-x: auto;
}
.subtab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 13px 2px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.subtab:hover { color: var(--fg); }
.subtab.active {
  color: var(--fg);
  border-bottom-color: var(--primary);
}

/* Tables */
.table-wrap {
  overflow: auto;
  max-height: 460px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
table.data-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-subtle);
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
table.data-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
}
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: color-mix(in srgb, var(--surface-subtle) 65%, transparent); }

.pace-cell-input {
  width: 58px;
  text-align: center;
  background: transparent;
  color: var(--fg);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 3px 4px;
  font-weight: 700;
  font-size: 12.5px;
}
.pace-cell-input:hover { background: var(--surface-subtle); border-color: var(--border); }
.pace-cell-input:focus { outline: none; background: var(--surface); border-color: var(--primary); }

/* Canvas Boxes */
.canvas-box {
  position: relative;
  width: 100%;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.chart-tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 11.5px;
  box-shadow: var(--shadow-md);
  min-width: 170px;
}

/* Dropzone */
.dropzone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 140ms ease, background-color 140ms ease;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 6%, transparent);
}

/* Dots & Indicators */
.dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  display: inline-block;
  flex-shrink: 0;
}

/* Auth Screen */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 430px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  box-shadow: var(--shadow-md);
}

/* Workout Calendar Cards */
.workout-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 15px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 130ms ease;
}
.workout-card.status-completed {
  border-color: color-mix(in srgb, var(--success) 45%, var(--border));
  background: color-mix(in srgb, var(--success) 4%, var(--surface));
}
.workout-card.type-race {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 7%, var(--surface));
}

/* Week selector strip */
.week-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.week-chip {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.week-chip.active {
  background: var(--primary);
  color: var(--primary-fg);
  border-color: transparent;
}

/* AI Markdown Response Box */
.ai-box {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-size: 13px;
  line-height: 1.55;
}
.ai-box h3 { margin: 10px 0 4px; font-size: 13.5px; }
.ai-box h3:first-child { margin-top: 0; }
.ai-box ul { margin: 4px 0 8px 18px; padding: 0; }

/* Modal & Drawer */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  width: 100%;
  max-width: 680px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

/* Toast */
.toast-host {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 10px 14px;
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn 200ms ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Flex helpers */
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row-wrap { flex-wrap: wrap; }
.stack-xs { display: flex; flex-direction: column; gap: 6px; }
.stack-sm { display: flex; flex-direction: column; gap: 10px; }
.stack-md { display: flex; flex-direction: column; gap: 16px; }
.stack-lg { display: flex; flex-direction: column; gap: 22px; }

/* Print Mode for Pace Band */
@media print {
  body * { visibility: hidden !important; }
  #printArea, #printArea * { visibility: visible !important; }
  #printArea {
    position: fixed !important;
    inset: 0 !important;
    background: #fff !important;
    color: #000 !important;
    padding: 16px !important;
  }
}
