:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --ink: #0f172a;
  --ink-muted: #475569;
  --ink-subtle: #64748b;

  --ponds: #059669;
  --ponds-bg: #ecfdf5;
  --parra: #ea580c;
  --parra-bg: #fff7ed;
  --rhodes: #4f46e5;
  --rhodes-bg: #eef2ff;
  --other: #9333ea;
  --other-bg: #faf5ff;
  --gold: #d97706;
  --gold-bg: #fef3c7;

  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.05), 0 4px 14px rgba(15, 23, 42, 0.03);
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.view-stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.view-stack[hidden] {
  display: none;
}

/* Athlete Switcher Bar */
.athlete-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  box-shadow: var(--shadow);
}

.athlete-tabs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.athlete-tab {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-muted);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: all 0.15s ease;
  font-variant-numeric: tabular-nums;
}

.athlete-tab:hover {
  background: var(--surface-subtle);
  color: var(--ink);
  border-color: var(--border);
}

.athlete-tab.active {
  background: var(--ink);
  color: #ffffff;
  border-color: var(--ink);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.14);
}

.athlete-tab .tab-count {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(100, 116, 139, 0.12);
  color: var(--ink-subtle);
}

.athlete-tab.active .tab-count {
  background: rgba(255, 255, 255, 0.2);
  color: #f8fafc;
}

.athlete-tab-group {
  border-left: 1px solid var(--border);
  margin-left: 4px;
  padding-left: 10px;
  display: inline-flex;
}

.athlete-select-wrap {
  flex-shrink: 0;
}

.athlete-select {
  border: 1px solid var(--border-strong);
  background: var(--surface-subtle);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 10px;
  cursor: pointer;
  outline: none;
}

.athlete-select:focus {
  border-color: var(--ponds);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.12);
}

/* Header */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
  box-shadow: var(--shadow);
}

.athlete-block {
  display: flex;
  align-items: center;
  gap: 16px;
}

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: #059669;
  color: #fff;
  font-weight: 700;
  font-size: 1.15rem;
  display: grid;
  place-items: center;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.title-row h1 {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.badge {
  font-size: 0.76rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.id-badge {
  background: #f1f5f9;
  color: var(--ink);
  border: 1px solid var(--border);
}

.cat-badge {
  background: #eef2ff;
  color: #3730a3;
}

.milestone-badge {
  background: var(--ponds-bg);
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.subtitle {
  margin: 4px 0 0;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.subtitle a {
  color: var(--ponds);
  text-decoration: none;
  font-weight: 500;
}

.subtitle a:hover {
  text-decoration: underline;
}

.data-freshness {
  font-size: 0.82rem;
  color: var(--ink-subtle);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
}

/* Controls Bar */
.controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  box-shadow: var(--shadow);
}

.control-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.control-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-subtle);
  margin-right: 4px;
}

.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--ink-muted);
  font-size: 0.84rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.pill:hover {
  border-color: var(--border-strong);
  color: var(--ink);
  background: #fff;
}

.pill.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.dot-ponds { background: var(--ponds); }
.dot-parra { background: var(--parra); }
.dot-rhodes { background: var(--rhodes); }
.dot-other { background: var(--other); }

/* Toggle Switch */
.toggle-switch {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  user-select: none;
  font-size: 0.85rem;
  color: var(--ink-muted);
}

.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  width: 38px;
  height: 22px;
  background: #cbd5e1;
  border-radius: 999px;
  position: relative;
  transition: background 0.18s ease;
  flex-shrink: 0;
}

.toggle-slider::after {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  position: absolute;
  top: 3px;
  left: 3px;
  transition: transform 0.18s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--ponds);
}

.toggle-switch input:checked + .toggle-slider::after {
  transform: translateX(16px);
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-highlight {
  border-color: #a7f3d0;
  background: linear-gradient(180deg, #f0fdf4 0%, #ffffff 70%);
}

.kpi-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-subtle);
}

.kpi-value {
  font-size: 1.65rem;
  font-weight: 750;
  letter-spacing: -0.025em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.kpi-highlight .kpi-value {
  color: #047857;
}

.kpi-sub {
  font-size: 0.81rem;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.card-header h2 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.card-sub {
  margin: 2px 0 0;
  font-size: 0.84rem;
  color: var(--ink-subtle);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.line-swatch {
  width: 16px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
}

.line-trend {
  background: #0f172a;
}

.line-pb {
  background: transparent;
  border-top: 2px dashed var(--gold);
  height: 0;
}

.canvas-wrap {
  position: relative;
  width: 100%;
}

.hero-canvas-wrap { height: 350px; }
.medium-canvas-wrap { height: 270px; }
.small-canvas-wrap { height: 230px; }

.canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Two column grid */
.two-col-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

/* Venue Breakdown */
.venue-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.venue-row {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--surface-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.venue-row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.venue-name-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  font-size: 0.94rem;
}

.venue-count {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.venue-bar-track {
  height: 7px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.venue-bar-fill {
  height: 100%;
  border-radius: 999px;
}

.venue-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  font-size: 0.79rem;
  color: var(--ink-subtle);
  font-variant-numeric: tabular-nums;
}

.venue-stats strong {
  display: block;
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 650;
}

/* Tables */
.mini-table, .data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
  font-variant-numeric: tabular-nums;
}

.mini-table th, .mini-table td,
.data-table th, .data-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.mini-table th, .data-table th {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-subtle);
  background: var(--surface-subtle);
  font-weight: 650;
}

.mini-table th.num, .mini-table td.num,
.data-table th.num, .data-table td.num {
  text-align: right;
}

.mini-table tbody tr:last-child td {
  border-bottom: none;
}

.table-header {
  align-items: center;
}

.table-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.search-input {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 0.86rem;
  min-width: 220px;
  outline: none;
  color: var(--ink);
}

.search-input:focus {
  border-color: var(--ponds);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.12);
}

.btn-secondary {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-secondary:hover {
  background: var(--surface-subtle);
}

.table-scroll {
  overflow-x: auto;
  max-height: 520px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}

.data-table tbody tr:hover {
  background: #f8fafc;
}

.group-row {
  cursor: pointer;
}

.group-athlete-cell {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
}

.mini-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
}

.sortable {
  cursor: pointer;
  user-select: none;
}

.sortable:hover {
  color: var(--ink);
}

.event-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 0.82rem;
  padding: 3px 9px;
  border-radius: 999px;
}

.tag-ponds { background: var(--ponds-bg); color: #065f46; }
.tag-parra { background: var(--parra-bg); color: #9a3412; }
.tag-rhodes { background: var(--rhodes-bg); color: #3730a3; }
.tag-other { background: var(--other-bg); color: #6b21a8; }

.pb-pill {
  display: inline-block;
  background: var(--gold-bg);
  color: #92400e;
  font-weight: 700;
  font-size: 0.74rem;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid #fde68a;
}

.time-cell {
  font-weight: 650;
  color: var(--ink);
}

/* Tooltip */
.chart-tooltip {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.95);
  color: #f8fafc;
  border-radius: 10px;
  padding: 10px 13px;
  font-size: 0.82rem;
  line-height: 1.45;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.25);
  min-width: 195px;
  font-variant-numeric: tabular-nums;
}

.tt-title {
  font-weight: 700;
  font-size: 0.88rem;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tt-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: #cbd5e1;
}

.tt-row strong {
  color: #ffffff;
}

.footer {
  text-align: center;
  font-size: 0.82rem;
  color: var(--ink-subtle);
  padding-top: 4px;
}

/* Responsive */
@media (max-width: 1080px) {
  .kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .two-col-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .hero-canvas-wrap { height: 280px; }
  .venue-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .athlete-nav { flex-direction: column; align-items: stretch; }
  .athlete-select { width: 100%; }
}
