/* =========================================================================
   Pace Race — dashboard styles. Built on tokens.css.
   Black surfaces, pink accent, sharp corners, flat, uppercase display.
   ========================================================================= */

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; }

.container { width: var(--container); margin: 0 auto; }

a { color: inherit; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: #fff; padding: var(--sp-3) var(--sp-4);
  font-weight: var(--fw-black); text-transform: uppercase; letter-spacing: var(--ls-caps);
}
.skip-link:focus { left: var(--sp-4); top: var(--sp-4); }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.site-header__inner {
  width: var(--container); margin: 0 auto;
  height: 64px; display: flex; align-items: center; justify-content: space-between;
}
.brand { display: inline-flex; align-items: center; text-decoration: none; }
.brand__logo { display: block; height: 20px; width: auto; }
.site-header__status { display: inline-flex; align-items: center; gap: var(--sp-2); }
.site-header__live {
  font-weight: var(--fw-black); text-transform: uppercase;
  letter-spacing: var(--ls-caps); font-size: var(--fs-micro); color: var(--fg);
}
.live-dot {
  width: 8px; height: 8px; border-radius: var(--r-full); background: var(--accent);
  box-shadow: 0 0 0 0 rgba(241, 28, 102, 0.6); animation: live-pulse 2s infinite;
}
@keyframes live-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(241, 28, 102, 0.55); }
  70%  { box-shadow: 0 0 0 8px rgba(241, 28, 102, 0); }
  100% { box-shadow: 0 0 0 0 rgba(241, 28, 102, 0); }
}

/* ---------- Hero ---------- */
.hero { padding: var(--sp-8) 0 var(--sp-6); }
.hero__title {
  font-family: var(--font-body); font-weight: var(--fw-black);
  font-size: var(--fs-display-lg); line-height: var(--lh-display);
  letter-spacing: -0.02em; text-transform: uppercase; margin: var(--sp-3) 0 var(--sp-4);
}
.hero__format {
  color: var(--fg-muted); font-weight: var(--fw-semi); text-transform: uppercase;
  letter-spacing: var(--ls-caps); font-size: var(--fs-body-sm); margin: 0;
}

/* ---------- Controls / filters ---------- */
.controls {
  display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: flex-end;
  padding: var(--sp-5) 0; border-top: 1px solid var(--border);
}
.field { display: flex; flex-direction: column; gap: var(--sp-2); }
.field[hidden] { display: none; }
.field__label {
  font-size: var(--fs-micro); font-weight: var(--fw-bold); text-transform: uppercase;
  letter-spacing: var(--ls-caps); color: var(--fg-muted);
}
/* Search shares the row and grows to fill leftover space; the dropdowns are
   width-capped and the segmented buttons tightened so the whole bar
   (Ansicht · Suche · Altersklasse · Geschlecht · Team · Reset) fits one line. */
.field--search { flex: 1 1 200px; min-width: 160px; }
.controls .select { width: 150px; }

.input, .select {
  appearance: none; -webkit-appearance: none;
  background: var(--pr-grey-900); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--r-2);
  padding: 0 var(--sp-4); height: 44px; font: inherit; font-size: var(--fs-body-sm);
  font-weight: var(--fw-medium); transition: border-color var(--dur-fast) var(--ease-standard);
}
.input::placeholder { color: var(--fg-subtle); }
.input:focus, .select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.select:disabled { opacity: 0.4; cursor: not-allowed; }
.select {
  padding-right: var(--sp-7); cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--fg-muted) 50%),
                    linear-gradient(135deg, var(--fg-muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 19px, calc(100% - 14px) 19px;
  background-size: 6px 6px, 6px 6px; background-repeat: no-repeat;
}
.btn-reset {
  background: transparent; color: var(--fg-muted);
  border: 1px solid var(--border); border-radius: var(--r-2);
  height: 44px; padding: 0 var(--sp-4); font: inherit; font-size: var(--fs-body-sm);
  font-weight: var(--fw-bold); text-transform: uppercase; letter-spacing: var(--ls-caps);
  cursor: pointer; transition: color var(--dur-fast), border-color var(--dur-fast);
}
.btn-reset:hover { color: var(--fg); border-color: var(--border-strong); }

/* segmented control (gender) */
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--r-2); overflow: hidden; height: 44px; }
.segmented button {
  background: var(--pr-grey-900); color: var(--fg-muted); border: 0; cursor: pointer;
  padding: 0 var(--sp-3); font: inherit; font-size: var(--fs-body-sm); font-weight: var(--fw-bold);
  text-transform: uppercase; letter-spacing: var(--ls-caps);
  border-right: 1px solid var(--border); transition: background var(--dur-fast), color var(--dur-fast);
}
.segmented button:last-child { border-right: 0; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: #fff; }

/* ---------- Team panel (shown only when a team is selected) ---------- */
.team-panel {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-5) var(--sp-7);
  margin: var(--sp-4) 0 var(--sp-2);
  padding: var(--sp-5) var(--sp-6);
  background: var(--pr-grey-900);
  border: 1px solid var(--accent);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-glow-pink);
}
.team-panel[hidden] { display: none; }
/* Back link on the team detail page — own full-width row at the top of the card. */
.team-panel__back {
  flex: 0 0 100%; display: inline-flex; align-items: center; gap: var(--sp-2);
  width: max-content; margin: 0 0 var(--sp-2); padding: 0;
  background: transparent; border: 0; color: var(--fg-muted); font: inherit;
  font-weight: var(--fw-bold); text-transform: uppercase; letter-spacing: var(--ls-caps);
  font-size: var(--fs-micro); cursor: pointer; transition: color var(--dur-fast);
}
.team-panel__back:hover { color: var(--accent); }
.team-panel__back-arrow { font-size: 1.35em; line-height: 0; }
.team-panel__head { flex: 1 1 220px; min-width: 180px; }
.team-panel__name {
  font-family: var(--font-body); font-weight: var(--fw-black); text-transform: uppercase;
  letter-spacing: -0.01em; font-size: var(--fs-h2); line-height: var(--lh-heading); margin: var(--sp-2) 0 4px;
}
.team-panel__count { color: var(--fg-muted); font-size: var(--fs-body-sm); font-weight: var(--fw-semi);
  text-transform: uppercase; letter-spacing: var(--ls-caps); margin: 0; }
.team-panel__stats { display: flex; gap: var(--sp-7); }
.team-stat { display: flex; flex-direction: column; gap: 4px; }
.team-stat__label { font-size: var(--fs-micro); font-weight: var(--fw-bold); text-transform: uppercase;
  letter-spacing: var(--ls-caps); color: var(--fg-muted); }
.team-stat__value { font-family: var(--font-display); font-size: var(--fs-h2); line-height: 1; }
.team-stat--total .team-stat__value { color: var(--accent); }
.team-panel__btn { flex: 0 0 auto; }

@media (max-width: 720px) {
  .team-panel { gap: var(--sp-4); }
  .team-panel__stats { gap: var(--sp-6); width: 100%; }
  .team-panel__btn { width: 100%; }
}

/* ---------- Pre-event / no-data notice ---------- */
.notice {
  margin: var(--sp-6) 0;
  padding: var(--sp-6);
  background: var(--pr-grey-900);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-3);
}
.notice[hidden] { display: none; }
.notice__eyebrow {
  color: var(--accent); font-weight: var(--fw-black); text-transform: uppercase;
  letter-spacing: var(--ls-caps); font-size: var(--fs-body-sm); margin: 0 0 var(--sp-3);
}
.notice__text {
  margin: 0; font-size: var(--fs-body); line-height: var(--lh-body); max-width: 52ch;
}
.notice__text b { color: var(--fg); }
.notice__meta { display: block; margin-top: var(--sp-2); color: var(--fg-muted); font-size: var(--fs-body-sm); }

/* ---------- Meta bar ---------- */
.meta-bar[hidden], .table-wrap[hidden] { display: none; }
.meta-bar {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: var(--sp-3) 0; gap: var(--sp-4);
}
.meta-bar__count { font-weight: var(--fw-black); text-transform: uppercase; letter-spacing: var(--ls-caps); font-size: var(--fs-body-sm); }
.meta-bar__count b { color: var(--accent); }
.meta-bar__updated { color: var(--fg-subtle); font-size: var(--fs-caption); font-variant-numeric: tabular-nums; }

/* ---------- Board / table ---------- */
.table-wrap { padding-bottom: var(--sp-9); }
.board { width: 100%; border-collapse: collapse; }
.board thead th {
  position: sticky; top: 64px; z-index: 10;
  background: var(--bg);
  text-align: left; padding: var(--sp-3) var(--sp-3);
  font-size: var(--fs-micro); font-weight: var(--fw-black); text-transform: uppercase;
  letter-spacing: var(--ls-caps); color: var(--fg-muted);
  border-bottom: 1px solid var(--border-strong); white-space: nowrap; cursor: pointer;
  user-select: none;
}
.board thead th.is-num { text-align: right; }
.board thead th[aria-sort] .sort-caret { color: var(--accent); }
.sort-caret {
  display: inline-block; margin-left: 5px; vertical-align: middle;
  font-size: 17px; line-height: 0; opacity: 0.9;
}
.board thead th:not([aria-sort]) .sort-caret { opacity: 0; }
.board thead th.th-static { cursor: default; } /* non-sortable column header */

.board tbody td {
  padding: var(--sp-3) var(--sp-3); border-bottom: 1px solid var(--border);
  font-size: var(--fs-body-sm); vertical-align: middle;
}
.board tbody tr { transition: background var(--dur-fast) var(--ease-standard); cursor: pointer; }
.board tbody tr:hover { background: rgba(255, 255, 255, 0.04); }
.board tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.cell-rank { width: 72px; }
td.cell-rank, th.cell-rank { text-align: center; }
.rank-num { font-weight: var(--fw-black); font-size: var(--fs-body); font-variant-numeric: tabular-nums; }
.rank-num.rank-medal { color: var(--accent); }
.cell-name { font-weight: var(--fw-bold); text-transform: uppercase; letter-spacing: -0.01em; }
.cell-name .sub { display: block; font-weight: var(--fw-medium); text-transform: none; color: var(--fg-subtle); font-size: var(--fs-caption); letter-spacing: 0; }
.row-meta { display: none; }
.cell-ak { color: var(--fg-muted); white-space: nowrap; }
.is-num { text-align: right; font-variant-numeric: tabular-nums; }
.cell-level b, .cell-total b { color: var(--accent); font-weight: var(--fw-black); }
.cell-count { color: var(--fg-muted); }
.tag {
  display: inline-block; padding: 2px var(--sp-2); border: 1px solid var(--border);
  border-radius: var(--r-full); font-size: var(--fs-micro); font-weight: var(--fw-bold);
  text-transform: uppercase; letter-spacing: var(--ls-caps); color: var(--fg-muted);
}
.btn-finisher {
  background: transparent; border: 1px solid var(--border-strong); color: var(--fg);
  border-radius: var(--r-2); padding: 6px var(--sp-3); font: inherit; font-size: var(--fs-micro);
  font-weight: var(--fw-black); text-transform: uppercase; letter-spacing: var(--ls-caps);
  cursor: pointer; white-space: nowrap; transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.btn-finisher:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

.board__empty, .board__loading { padding: var(--sp-7) 0; color: var(--fg-subtle); text-align: center; text-transform: uppercase; letter-spacing: var(--ls-caps); font-weight: var(--fw-bold); font-size: var(--fs-body-sm); }

.site-footer {
  padding: var(--sp-6) 0 var(--sp-8); border-top: 1px solid var(--border);
  color: var(--fg-muted); font-weight: var(--fw-bold); text-transform: uppercase;
  letter-spacing: var(--ls-caps); font-size: var(--fs-caption);
}
.site-footer a { color: var(--fg-muted); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }

/* hide secondary columns on small screens */
/* On phones, fold the wordy columns (age class + fastest lap) into a sub-line
   under the name, but KEEP both rank columns. Tighten everything so the table
   fits the viewport — no page-level horizontal scroll. */
@media (max-width: 820px) {
  .col-time, .cell-time, .col-ak, .cell-ak,
  .cell-total, .cell-avg { display: none; } /* teams: total + Ø fold into row-meta */
  .row-meta {
    display: block; margin-top: 3px; font-size: var(--fs-caption);
    color: var(--fg-subtle); font-weight: var(--fw-medium);
    text-transform: none; letter-spacing: 0;
  }
  .board thead th, .board tbody td { padding: var(--sp-3) var(--sp-1); }
  .cell-rank { width: 34px; }
  .cell-name { word-break: break-word; }
  .btn-finisher { padding: 6px var(--sp-2); font-size: 10px; }
}
@media (max-width: 720px) {
  .hero__title { font-size: var(--fs-display-md); }
  .board thead th { font-size: 9px; letter-spacing: 0.04em; }
}

/* ---------- Finisher modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.78); padding: var(--sp-4); animation: fade var(--dur-base) var(--ease-enter);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal__dialog {
  background: var(--pr-grey-900); border: 1px solid var(--border-strong); border-radius: var(--r-3);
  /* explicit width capped to the viewport so it can never overflow the screen */
  width: min(460px, calc(100vw - 2 * var(--sp-4)));
  min-width: 0; max-height: 92vh; overflow: auto; padding: var(--sp-5);
  display: flex; flex-direction: column; gap: var(--sp-4);
}
.modal__head { display: flex; align-items: center; justify-content: space-between; }
.modal__title { font-weight: var(--fw-black); text-transform: uppercase; letter-spacing: var(--ls-caps); font-size: var(--fs-body-sm); color: var(--fg-muted); margin: 0; }
.modal__close {
  background: transparent; border: 1px solid var(--border); color: var(--fg); border-radius: var(--r-2);
  width: 36px; height: 36px; font-size: 18px; cursor: pointer; line-height: 1;
}
.modal__close:hover { border-color: var(--accent); color: var(--accent); }
/* keep the header, toggle and buttons at full size; only the preview flexes */
.modal__head, .format-toggle, .modal__actions { flex-shrink: 0; }
.finisher-preview {
  display: block; margin: 0 auto; border-radius: var(--r-2); border: 1px solid var(--border);
  background: var(--pr-black);
  /* fit the whole graphic within the dialog — height-bound so the tall Story
     is never cut off; width follows the canvas's intrinsic aspect ratio */
  max-width: 100%; max-height: 60vh; width: auto; height: auto; min-height: 0; min-width: 0;
}
.format-toggle { display: inline-flex; gap: 0; border: 1px solid var(--border); border-radius: var(--r-2); overflow: hidden; align-self: center; }
.format-toggle button {
  background: var(--pr-grey-800); color: var(--fg-muted); border: 0; border-right: 1px solid var(--border);
  padding: var(--sp-2) var(--sp-4); font: inherit; font-size: var(--fs-micro); font-weight: var(--fw-black);
  text-transform: uppercase; letter-spacing: var(--ls-caps); cursor: pointer;
}
.format-toggle button:last-child { border-right: 0; }
.format-toggle button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.modal__actions { display: flex; gap: var(--sp-3); }
.btn {
  flex: 1; min-width: 0; border: 0; border-radius: var(--r-2); padding: var(--sp-4); font: inherit; font-weight: var(--fw-black);
  text-transform: uppercase; letter-spacing: var(--ls-caps); font-size: var(--fs-body-sm); cursor: pointer;
  white-space: nowrap;
}
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { box-shadow: inset 0 0 0 999px rgba(0, 0, 0, 0.12); }
.btn--ghost { background: transparent; color: var(--fg); border: 1px solid var(--border-strong); }
.btn--ghost:hover { border-color: var(--accent); color: var(--accent); }

/* phones: smaller preview so the toggle + actions always fit */
@media (max-width: 560px), (max-height: 740px) {
  .finisher-preview { max-height: 50vh; }
  .modal__dialog { padding: var(--sp-4); gap: var(--sp-3); }
}
/* narrow phones: stack the action buttons full-width so they never get cut off */
@media (max-width: 480px) {
  .modal__actions { flex-direction: column; gap: var(--sp-2); }
  .modal__actions .btn { flex: 0 0 auto; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
  html { scroll-behavior: auto; }
}
