/* ==========================================================================
   Stats page — the few things datapages.css does not already provide.

   Nearly everything here is borrowed: .racedata gives the palette, .tabs the
   tab bar, .tile the stat band, .tablewrap and th[data-sort] the sortable
   table, .chip and .disc the small pieces. This file is only the parts that
   are new, which is why it is short — and it stays that way on purpose. A
   second copy of a shared style is a second thing to change when the site's
   colours move.
   ========================================================================== */

/* The four tiles above the combos table. datapages.css lays .tiles out as four
   equal columns, which is right on a desktop and unreadable on a phone. */
.racedata .st-tiles { margin: 22px 0 18px; }

@media (max-width: 720px) {
  .racedata .st-tiles { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 420px) {
  .racedata .st-tiles { grid-template-columns: 1fr; }
}

/* ⚠ THE NAME COLUMNS WRAP. datapages.css sets `white-space: nowrap` on every
   table cell, which sizes a column to its LONGEST value across all 786 rows --
   not the ones on screen. Track came out at 454px and Car / class at 334px,
   788px of a 1326px table inside a 1057px box, and the table simply ran off the
   right: adding Avg drivers pushed Last and Discipline off the end entirely.
   The data was there, 269px into a horizontal scroll nobody thinks to use.

   Wrapping instead of scrolling. Two or three lines on "[Retired] WeatherTech
   Raceway at Laguna Seca - [Retired] Full Course" is a far better answer than a
   date that cannot be seen. Measured in Edge at every width from 390 to 2560.

   The dates and the numbers keep nowrap -- "26 Jun" over "2026" would be worse
   than useless, and they are narrow anyway. */
.racedata #p-combos tbody td:nth-child(1),
.racedata #p-combos tbody td:nth-child(2),
.racedata #p-combos tbody td:nth-child(7),
.racedata #p-tracks tbody td:nth-child(1),
.racedata #p-cars tbody td:nth-child(1) {
  white-space: normal;
}
.racedata #p-combos tbody td:nth-child(1) { max-width: 290px; }
.racedata #p-combos tbody td:nth-child(2) { max-width: 210px; }
.racedata #p-combos tbody td:nth-child(7) { max-width: 160px; }
.racedata #p-tracks tbody td:nth-child(1),
.racedata #p-cars tbody td:nth-child(1) { max-width: 320px; }

/* A combo row opens to show the nights behind its count. */
.racedata tr.st-row { cursor: pointer; }
.racedata tr.st-row:focus-visible { outline: 2px solid var(--blue-br); outline-offset: -2px; }
.racedata tr.st-row.open td { background: #13203a; }

/* The little triangle that says a row can be opened, and which way it is. */
.racedata tr.st-row td:first-child::before {
  content: "▸";
  color: var(--muted);
  display: inline-block;
  width: 14px;
  transition: transform .12s;
}
.racedata tr.st-row.open td:first-child::before {
  transform: rotate(90deg);
  color: var(--blue-br);
}

.racedata tr.st-nights td { background: #0e1a30; white-space: normal; }

/* ⚠ THE PANEL FOLLOWS THE VISIBLE WIDTH, NOT THE TABLE'S. Measured in Edge,
   2026-08-01, after "22 drivers" went missing twice and neither fix worked.

   The combos table is WIDER THAN ITS WRAPPER BY DESIGN -- six columns of
   `white-space: nowrap` with track names like "[Retired] WeatherTech Raceway at
   Laguna Seca - [Retired] Full Course" come to 1249px inside a 1062px box, and
   `.tablewrap` scrolls horizontally to cope. That predates this panel.

   A `<td>` inherits that full 1249px, so anything laid out to 100% of it puts
   its right-hand end 187px into the scroll region -- visible only if you think
   to scroll a table sideways, which nobody does. The drivers count was there
   the whole time, off the edge of the world.

   So: pin the panel to the left of the scroll viewport with sticky, and size it
   from the PAGE rather than the cell. .racedata is max-width 1100 with 18px
   padding; the wrap adds a 1px border and the cell 14px of padding, each side
   -- 66px in total. max-width: 100% covers the case where the table is narrower
   than the page and the cell is the smaller of the two. */
.racedata tr.st-nights td > .st-nightbox {
  position: sticky;
  left: 0;
  width: calc(min(1100px, 100vw) - 66px);
  max-width: 100%;
}

.racedata .st-nightbox { padding: 4px 2px 10px; }
.racedata .st-nightbox .subhead { margin-bottom: 9px; }
.racedata .st-nightbox .subhead .st-order {
  color: var(--muted); font-size: 12px; margin-left: 10px;
  font-family: ui-sans-serif, system-ui, sans-serif;
}
/* Only ever seen if the list and the count disagree, which build_stats.py
   refuses to write. Loud on purpose -- a quiet version of this is the bug. */
.racedata .st-mismatch { color: #fca5a5; font-weight: 700; }

/* ---- the opened row: header, then one line a night ---------------------- */

/* TRACK FIRST, THEN THE CAR -- Sharky, 2026-08-01.

   BOTH SIDES ARE THE SAME SIZE, and that is structural rather than a pixel
   value: each block is a name, a row of chips, then a 16:9 picture, so the two
   images start and end at the same height and stay that way if either changes.

   minmax(0, 1fr) AND min-width: 0 on the children. A grid item's default
   min-width is auto, which means "as wide as my content" -- a 1280px image in a
   1fr column pushes the column past its share and the second card runs off the
   right edge of the table cell. Both are needed; the column rule alone is not
   enough.

   THE BOXES ARE 40% SMALLER than they started -- Sharky, 2026-08-01. One
   number does it: each column was ~50% of the row and is now 30%, and the 16:9
   box carries the height down with the width. Percent columns rather than `fr`,
   because an `fr` track always absorbs the free space however small you make
   it; `justify-content: start` then parks the pair on the left and leaves the
   rule under them running the full width. */
.racedata .st-header {
  --st-card: 30%;                 /* was ~50% -- the whole size control */
  display: grid;
  grid-template-columns: repeat(2, minmax(0, var(--st-card)));
  justify-content: start;
  gap: 16px; align-items: start;
  padding: 2px 2px 16px; margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.racedata .st-track,
.racedata .st-cars { min-width: 0; }

/* Below this the two would be too narrow to read, so they go full width and
   stack -- the size control above only makes sense while they sit side by side. */
@media (max-width: 980px) {
  .racedata .st-header { --st-card: 46%; }
}
@media (max-width: 780px) {
  .racedata .st-header {
    grid-template-columns: 1fr; gap: 14px;
  }
}

/* The name, and the chip row under it. Used by BOTH sides. */
.racedata .st-tname {
  margin: 0; font-size: 15px; line-height: 1.3; color: var(--ink);
  font-family: ui-sans-serif, system-ui, sans-serif; font-weight: 600;
  /* Two lines' worth, so a long car name and a short track name still leave
     their pictures level. Clipped rather than allowed to push the image down. */
  height: 2.6em; overflow: hidden;
}
.racedata .st-tmeta {
  margin: 2px 0 8px; display: flex; flex-wrap: wrap; gap: 6px;
  font-family: ui-sans-serif, system-ui, sans-serif; font-size: 11px;
  height: 20px; overflow: hidden;
}
.racedata .st-tmeta span,
.racedata .st-ccls {
  padding: 1px 9px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.racedata .st-layout,
.racedata .st-ccls { color: var(--ink-2) !important; border-color: #33507a !important; }

/* Both pictures: identical box, and the image FITS INSIDE it -- Sharky,
   2026-08-01. object-fit: contain letterboxes rather than cropping, and the
   max-* rules stop an image ever setting the box's size. */
.racedata .st-map,
.racedata .st-cpic {
  background: #0a1425; border: 1px solid var(--line); border-radius: 14px;
  overflow: hidden; aspect-ratio: 16 / 9;
  display: grid; place-items: center;
  width: 100%; min-width: 0;
}
.racedata .st-map img,
.racedata .st-cpic img {
  width: 100%; height: 100%;
  max-width: 100%; max-height: 100%;
  object-fit: contain; display: block;
}
.racedata .st-map.ph { color: var(--muted); font-size: 30px; }
.racedata .st-cpic .ph { font-size: 30px; color: var(--muted); }

.racedata .st-cars { position: relative; }

/* The carousel. Bare chevrons at the very edges of the picture, as the
   reference has them -- boxed buttons inside the image read as part of the
   photograph. They span the picture only, not the name above or dots below. */
.racedata .st-cars.multi .st-arrow {
  position: absolute; bottom: 26px;
  top: calc(2.6em + 30px);
  display: grid; place-items: center;
  appearance: none; cursor: pointer; border: 0; background: none; padding: 0 6px;
  width: 38px; color: #fff; font-size: 28px; line-height: 1;
  text-shadow: 0 1px 6px rgba(0, 0, 0, .9);
  opacity: .65; transition: opacity .12s;
}
.racedata .st-cars.multi .st-arrow:hover { opacity: 1; }
.racedata .st-cars.multi .st-arrow:focus-visible {
  outline: 2px solid var(--blue-br); outline-offset: -4px; border-radius: 10px; opacity: 1;
}
.racedata .st-cars.multi .st-arrow.prev { left: 0; }
.racedata .st-cars.multi .st-arrow.next { right: 0; }

/* Dots centred UNDER the picture. */
.racedata .st-dots {
  display: flex; justify-content: center; flex-wrap: wrap; gap: 7px; margin-top: 9px;
}
.racedata .st-dot {
  appearance: none; cursor: pointer; padding: 0;
  width: 7px; height: 7px; border-radius: 50%;
  border: 0; background: #33507a; transition: background .12s;
}
.racedata .st-dot:hover { background: #4d6f9e; }
.racedata .st-dot.on { background: var(--blue-br); }
.racedata .st-dot:focus-visible { outline: 2px solid var(--blue-br); outline-offset: 2px; }

/* ---- one night --------------------------------------------------------- */

/* FOUR COLUMNS, to Sharky's mock-up of 2026-08-01:
 *
 *   29 Apr 2026        Dave Barkley      ☀ 12:00 pm Afternoon    ⚑ 0 cautions  ⊕ 21 drivers
 *   ● Oval [Biggest field]                (Mostly cloudy 64°F 0 mph)
 *
 * The middle column centres and the right column ends, so the numbers line up
 * down the list however long a winner's name is. */
.racedata .st-nights-list { list-style: none; margin: 0; padding: 0; }
.racedata .st-n {
  display: grid;
  /* ⚠ EVERY TRACK HAS A PIXEL CEILING, AND NONE IS `fr`. Measured in Edge on
     2026-08-01 -- this is not a style preference, it is the only thing that
     works here.

     A grid inside a `table-layout: auto` cell contributes its MAX-CONTENT to
     the table's intrinsic width, and an `fr` track's max-content is its
     content's, unbounded. With `1fr`/`1.4fr` the row wanted 1217px inside a
     1062px wrap: the table grew to 1249, and `.st-race` landed at 1212..1412 --
     completely outside the visible area, so "22 drivers" was simply not on the
     page. Twice: first as a leftover `fr` share, then again after the last
     column was fixed, because the middle one was still unbounded.

     132 + 300 + 340 + 200 + (3 x 14 gap) = 1034, which fits the 1034px a
     1100px .racedata column leaves inside the cell. space-between then pins the
     date left and the cautions/drivers pair right, and absorbs any slack in
     between rather than bunching everything to the left. */
  grid-template-columns:
    132px minmax(0, 300px) minmax(0, 340px) 200px;
  justify-content: space-between;
  gap: 6px 14px; align-items: center;
  padding: 8px 10px; border-radius: 9px;
  font-family: ui-sans-serif, system-ui, sans-serif; font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* ⚠ min-width: 0 ON EVERY COLUMN, and it is not optional. A grid item's default
   min-width is `auto` -- "never shrink below my content" -- and these columns
   are full of white-space: nowrap. So the last two refused to shrink, the row
   grew wider than the table cell it lives in, and "21 drivers" was pushed off
   the right-hand edge where nothing showed it was missing.
   The same trap as the header block above; it was fixed there and not here. */
.racedata .st-when,
.racedata .st-who,
.racedata .st-cond,
.racedata .st-race { min-width: 0; }
.racedata .st-n:nth-child(odd) { background: rgba(255,255,255,.022); }
.racedata .st-n:hover { background: rgba(255,255,255,.05); }
.racedata .st-n.marked { background: rgba(96,165,250,.06); }

/* 1. the date, and the night's tags under it -- the discipline and any flags.
      They used to be a full-width row at the bottom of the night, which put
      them closer to the NEXT night than to their own. */
.racedata .st-when { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.racedata .st-when .st-d { color: var(--ink); }
.racedata .st-tags { display: flex; flex-wrap: wrap; gap: 4px; }

/* 2. the winner */
.racedata .st-who { display: flex; align-items: baseline; gap: 9px; min-width: 0; }
.racedata .st-who .st-w {
  font-weight: 700; font-size: 13.5px; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.racedata .st-who .st-w.dim { font-weight: 400; color: var(--muted); font-style: italic; }
/* Out to the full finishing order on Past Winners. Present on the 138 nights
   that page holds and absent on the rest, so it never leads nowhere. */
.racedata .st-pw {
  font-size: 11px; color: var(--blue-br); text-decoration: none;
  white-space: nowrap; opacity: .7;
}
.racedata .st-pw:hover { opacity: 1; text-decoration: underline; }
.racedata .st-pw:focus-visible { outline: 2px solid var(--blue-br); outline-offset: 2px; }

/* 3. the time of day, with the weather pill beneath it */
.racedata .st-cond {
  display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0;
}
.racedata .st-time {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--ink-2); font-size: 13px;
}
.racedata .st-time b { font-weight: 700; color: var(--ink); }
.racedata .st-band { opacity: .6; font-weight: 400; font-size: 11.5px; }

/* The weather, boxed together so it reads as one thing rather than four. */
.racedata .st-wx {
  display: inline-flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 3px 10px; color: var(--muted); font-size: 11px;
  padding: 2px 11px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .018);
}
.racedata .st-wx .st-ico { opacity: .7; width: 12px; height: 12px; }

/* 4. cautions and drivers, the pair Sharky wanted prominent, ending flush right
      so they form a column down the list. */
/* Wrapping rather than nowrap on the group: if the column does get tight the
   pair stacks and stays readable, instead of the second one disappearing. */
.racedata .st-race {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end;
  gap: 3px 14px; color: var(--ink); font-size: 13px; font-weight: 700;
}
.racedata .st-race .st-ico { opacity: .85; }
/* The fastest lap rides with them -- a race fact, not weather -- but quieter,
   because Sharky named three and this is not one of them. */
.racedata .st-race .st-b.quiet { font-weight: 400; color: var(--muted); font-size: 12px; }
.racedata .st-race .st-b.none {
  font-weight: 400; font-style: italic; color: var(--muted);
  font-size: 11.5px; white-space: normal; text-align: right;
}

.racedata .st-b { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }

/* The icons inherit the text colour, so they cannot drift from the theme. */
.racedata .st-ico { width: 14px; height: 14px; flex: none; }

/* The discipline reads as one more small tag about the night, beside the flags. */
.racedata .st-tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10.5px; padding: 1px 8px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}

.racedata .st-mark {
  font-size: 10.5px; padding: 1px 8px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.racedata .st-mark.big { border-color: #3b6ea5; color: #93c5fd; }
.racedata .st-mark.lc  { border-color: #7a5b2e; color: #fcd34d; }
.racedata .st-mark.sof { border-color: #2f6b52; color: #86efac; }
.racedata .st-mark.fl  { border-color: #6b3a5e; color: #f0abfc; }

/* A phone cannot hold four columns of this. The date and the winner keep the
   first line -- they are what the list is scanned for -- and the discipline
   drops below them. The facts and flags lose their indent, or on a 360px screen
   they would have 116px of nothing to the left of a wrapped line. */
/* A phone cannot hold four columns of this. The date and the winner keep the
   top line -- they are what the list is scanned for -- and the conditions and
   the race pair drop below them, left-aligned rather than centred and flush
   right, which only read as columns when there are columns. */
@media (max-width: 760px) {
  .racedata .st-n {
    grid-template-columns: 118px minmax(0, 1fr);
    gap: 6px 12px; align-items: start;
  }
  .racedata .st-cond,
  .racedata .st-race { grid-column: 1 / -1; }
  .racedata .st-cond { align-items: flex-start; }
  .racedata .st-race { justify-content: flex-start; gap: 4px 14px; }
  .racedata .st-race .st-b.none { text-align: left; }
}

.racedata .st-hint { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }

/* The tools row wraps on a phone; without this the search box and the two
   selects squash each other instead. */
@media (max-width: 720px) {
  .racedata .rd-tools input[type="search"],
  .racedata .rd-tools select { min-width: 0; width: 100%; }
  .racedata .rd-tools { display: grid; grid-template-columns: auto 1fr; }
  .racedata .rd-tools .chip.ghost,
  .racedata .rd-tools .rd-label:last-child { grid-column: 1 / -1; }
}

/* .chip.ghost is the Reset button. roster.css styles it, and the Stats page
   does not load roster.css — so it is here too rather than pulling in a whole
   page's stylesheet for one button. */
.racedata .chip.ghost {
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-size: 11.5px;
  background: transparent;
}
.racedata .chip.ghost:hover { color: var(--ink); border-color: #33507a; }
.racedata .chip.ghost:focus-visible { outline: 2px solid var(--blue-br); outline-offset: 2px; }

.racedata .empty { color: var(--muted); font-size: 14px; padding: 20px 0; }
