/* Athletics Workbench — single dark theme shared by every page. */
:root {
  color-scheme: dark;
  --bg: #0e1113;
  --surface: #161a1c;
  --surface-2: #1c2123;
  --raised: #242a2c;
  --line: #2a3133;
  --line-soft: #1f2527;
  --line-strong: #3a4345;
  --ink: #e8ecea;
  --ink-2: #c3ccc8;
  --muted: #8a9692;
  --accent: #57f1db;
  --accent-soft: rgba(87, 241, 219, 0.16);
  --gold: #f2bf54;
  --silver: #c5ccd5;
  --bronze: #d8ac91;
  --top8: #57f1db;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 8px;
  --gutter: 24px;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 13px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3 { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Top bar: brand, page tabs and data meta in one sticky row */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: stretch;
  gap: 32px;
  height: 56px;
  padding: 0 var(--gutter);
  background: rgba(14, 17, 19, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 600;
  letter-spacing: 0.01em;
  text-decoration: none;
  white-space: nowrap;
}
.brand-mark {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.page-tabs { display: flex; gap: 4px; }
.page-tabs a {
  display: flex;
  align-items: center;
  padding: 0 12px;
  margin-bottom: -1px;
  color: var(--muted);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color 0.15s;
}
.page-tabs a:hover { color: var(--ink); }
.page-tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }
.page-tabs a:focus-visible { outline-offset: -8px; border-radius: 6px; }
.header-meta {
  margin-left: auto;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Filter bar */
.layout { display: block; }
.filters {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(100px, 0.7fr) minmax(120px, 0.8fr) minmax(210px, 1.6fr);
  gap: 16px;
  padding: 16px var(--gutter);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.filters label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
}
select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 36px;
  padding: 0 34px 0 12px;
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238a9692' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center / 10px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font: 500 13px var(--sans);
  text-overflow: ellipsis;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
select:hover { border-color: var(--line-strong); }
select:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
option { background: var(--surface-2); color: var(--ink); }
.filters input {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font: 500 13px var(--sans);
  color-scheme: dark;
}
.filters input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.filters > button {
  align-self: end;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--ink);
  font: 500 13px var(--sans);
  cursor: pointer;
}
.filters > button:hover { border-color: var(--line-strong); background: var(--raised); }

.filter-button {
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--ink);
  font: 500 13px var(--sans);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s;
}
.filter-button:hover { border-color: var(--line-strong); background: var(--raised); }
.filter-button:disabled { opacity: 0.45; cursor: default; }
#openFilters { display: none; }

/* Page content */
.content { max-width: 1440px; margin: 0 auto; padding: 28px var(--gutter) 56px; }
.event-context {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.event-context > div { display: grid; gap: 4px; min-width: 0; }
.event-context h1 { font-size: 22px; font-weight: 600; line-height: 1.25; letter-spacing: -0.015em; }
.event-context span, .event-context p { margin: 0; color: var(--muted); font-size: 13px; }

/* Stat cards */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(0, 0.8fr);
  gap: 12px;
  margin-bottom: 40px;
}
.metric {
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.metric[data-tone="gold"] { --tone: var(--gold); }
.metric[data-tone="silver"] { --tone: var(--silver); }
.metric[data-tone="bronze"] { --tone: var(--bronze); }
.metric[data-tone="top8"] { --tone: var(--top8); }
.metric-label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 500; }
.dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--tone, var(--muted)); }
.metric strong {
  color: var(--ink);
  font: 500 24px/1.2 var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.metric-sub { min-height: 18px; color: var(--muted); font-size: 12px; }
.metric-sub.is-delta { font-family: var(--mono); font-size: 11.5px; }
.metric--aside { background: transparent; border-style: dashed; }

/* Panels & charts */
.panel { margin-bottom: 40px; }
.panel-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}
.panel-heading h2 { font-size: 15px; font-weight: 600; letter-spacing: -0.005em; }
.panel-heading span { color: var(--muted); font-size: 12px; text-align: right; }

.chart {
  height: 320px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.compact-chart { height: 260px; }
.chart:has(+ .legend:not(:empty)) { border-radius: var(--radius) var(--radius) 0 0; border-bottom-color: var(--line-soft); }
.chart svg { display: block; }
.chart svg text { fill: var(--muted); font: 11px var(--sans); font-variant-numeric: tabular-nums; }
.chart svg text.value-label { fill: var(--ink-2); font-weight: 500; }
.chart svg text.row-label { fill: var(--ink-2); font-size: 12px; font-weight: 500; }
.chart svg [tabindex]:focus-visible { outline: none; stroke: var(--ink) !important; stroke-width: 2px !important; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 20px;
  padding: 10px 16px;
  color: var(--ink-2);
  font-size: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
}
.legend:empty { display: none; }
.legend-item { display: inline-flex; align-items: center; gap: 8px; }
.legend-swatch { width: 16px; height: 3px; border-radius: 2px; }
.legend-marker { width: 10px; height: 10px; border-radius: 50%; }
.legend-marker.ring { border: 2px solid var(--ink-2); }
.legend-marker.fill { background: var(--ink-2); }

.empty { padding: 24px 16px; color: var(--muted); }
.muted { color: var(--muted); }

.chart-tooltip {
  position: fixed;
  z-index: 1000;
  max-width: min(320px, calc(100vw - 16px));
  padding: 8px 10px;
  background: #232a2c;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font: 12px/1.4 var(--sans);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

/* Tables */
.grid-two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
/* Tables grow with the page; only long explorer lists (.athlete-table) keep their own scroll box. */
.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.athlete-table { max-height: 640px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
th, td { padding: 9px 14px; white-space: nowrap; vertical-align: middle; }
tbody td { color: var(--ink-2); border-bottom: 1px solid var(--line-soft); }
tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.018); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(87, 241, 219, 0.05); }
tbody tr.group-start td { box-shadow: inset 0 1px 0 var(--line-strong); }
.num { text-align: right; }
td.num { font-family: var(--mono); font-size: 12px; }
td.strong { color: var(--ink); font-weight: 500; }
.th-dot { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; vertical-align: 1px; }
.place {
  display: inline-grid;
  place-items: center;
  min-width: 26px;
  height: 20px;
  padding: 0 6px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  color: var(--ink-2);
  font: 500 11px var(--mono);
}
.place-1, .place-2, .place-3 { border-color: transparent; color: #121516; }
.place-1 { background: var(--gold); }
.place-2 { background: var(--silver); }
.place-3 { background: var(--bronze); }
.place-8 { border-color: rgba(87, 241, 219, 0.5); color: var(--accent); }

.plain-panel {
  padding: 16px 18px;
  color: var(--ink-2);
  line-height: 1.65;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.plain-panel p { margin: 0 0 12px; }
.plain-panel p:last-child { margin-bottom: 0; }

/* Mobile filter sheet */
#filterDialog {
  width: 100%;
  max-width: 700px;
  max-height: 90dvh;
  margin: auto auto 0;
  padding: 20px 16px max(20px, env(safe-area-inset-bottom));
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px 12px 0 0;
}
#filterDialog::backdrop { background: rgba(0, 0, 0, 0.65); }
.filter-dialog-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.filter-dialog-heading h2 { font-size: 17px; font-weight: 600; }
#filterDialog .filters { grid-template-columns: 1fr 1fr; gap: 16px 12px; padding: 0; background: transparent; border: 0; }
#filterDialog label:last-child { grid-column: 1 / -1; }
body:has(#filterDialog[open]) { overflow: hidden; }

.data-status {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border, #303835);
  color: var(--text, #e8ecea);
}
.data-status button {
  margin-left: 8px;
  padding: 6px 12px;
  cursor: pointer;
}

@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .metric--aside { grid-column: span 4; grid-template-columns: auto auto 1fr; align-items: baseline; gap: 12px; padding: 12px 16px; }
  .metric--aside strong { font-size: 18px; }
}

@media (max-width: 1000px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric--aside { grid-column: span 2; }
  .grid-two { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  :root { --gutter: 16px; }
  #openFilters { display: block; flex-shrink: 0; }
  .content { padding-top: 20px; }
  .event-context { align-items: center; }
  .event-context h1 { font-size: 18px; }
  .kpis { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding-inline: 16px; gap: 10px; margin: 0 -16px 32px; padding: 0 16px 4px; }
  .metric, .metric--aside { flex: 0 0 180px; scroll-snap-align: start; display: grid; grid-template-columns: none; align-items: start; gap: 6px; padding: 14px; }
  .metric strong, .metric--aside strong { font-size: 20px; }
  .panel { margin-bottom: 32px; }
  .panel-heading { flex-wrap: wrap; gap: 4px; }
  .panel-heading span { text-align: left; }
  .chart { height: 250px; }
  .compact-chart { height: 230px; }

  .table-wrap:has(> #athleteTable) { max-height: 680px; background: transparent; border: 0; border-radius: 0; }
  #athleteTable, #athleteTable tbody { display: block; }
  #athleteTable thead { display: none; }
  #athleteTable tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 8px; margin-bottom: 10px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
  #athleteTable tr.group-start td { box-shadow: none; }
  #athleteTable td { display: block; padding: 0; border: 0; text-align: left; white-space: normal; overflow-wrap: anywhere; }
  #athleteTable td::before { content: attr(data-label); display: block; margin-bottom: 4px; color: var(--muted); font: 11px var(--sans); }
  #athleteTable td[data-label="Athlete"] { grid-column: 1 / -1; order: -1; font-size: 15px; font-weight: 600; }
  #athleteTable td[data-label="Athlete"]::before { display: none; }
  #athleteTable td[data-label="Championship"] { grid-column: span 2; }
  #athleteTable td[data-label="Champs mark"] { color: var(--accent); }
}

@media (max-width: 420px) {
  .header-meta { display: none; }
}

/* Throws pathway */
.metric[data-tone="international"] { --tone: #8fb3ff; }
.throws-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 0.8fr); }
.throws-chart { height: 420px; }
.funnel-swatch { border-radius: 2px; background: rgba(87, 241, 219, 0.14); border: 1px solid rgba(87, 241, 219, 0.35); }
@media (max-width: 1180px) {
  .throws-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .throws-kpis .metric--aside { grid-column: span 3; }
}
@media (max-width: 1000px) {
  .throws-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .throws-kpis .metric--aside { grid-column: span 2; }
}
@media (max-width: 700px) {
  .throws-chart { height: 320px; }
  .event-context > div > span { display: none; }
}

/* "At a glance" summary at the top of a method section */
.method-points { margin: 14px 0 18px; padding: 0; list-style: none; display: grid; gap: 8px; max-width: 95ch; }
.method-points li { padding-left: 14px; border-left: 2px solid var(--line-strong); color: var(--ink-2); font-size: 13px; line-height: 1.55; }
.method-points strong { color: var(--ink); font-weight: 600; }

/* Recent events */
.recent-events { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 18px; }
.recent-label { color: var(--muted); font-size: 12px; }
.recent-chip {
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface);
  color: var(--ink-2);
  font: 500 12px var(--sans);
  cursor: pointer;
  white-space: nowrap;
}
.recent-chip:hover { border-color: var(--line-strong); color: var(--ink); }
.recent-chip[aria-current="true"] { border-color: transparent; background: var(--accent-soft); color: var(--accent); }
@media (max-width: 700px) { .recent-events { gap: 6px; margin-bottom: 14px; } .recent-chip { height: 34px; } }
