/* 08-pages/_stats.css - stats page-specific layout for the fleet aggregate surface. */

.p-stats__eyebrow {
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}

.p-stats__availability {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.p-stats__status-title {
  color: var(--text-bright);
  font-size: var(--text-xl);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
}

.p-stats__section-head {
  display: flex;
  align-items: center;
  gap: 1.2ch;
  margin-block-end: var(--space-md);
}

/* Each section is its own subject, so its header gets air above it — but not the first
   one, which already sits below the page's own header. */
.p-article__section + .p-article__section > .p-stats__section-head {
  margin-block-start: var(--space-xl);
}

.p-stats__section-title {
  color: var(--text-bright);
  font-size: var(--text-sm);
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}

.p-stats__section-rule {
  flex: 1;
  border-top: var(--bw) solid var(--line);
}

.p-stats__section-note {
  color: var(--text-dim);
  font-size: var(--text-xs);
}

/* The corpus totals read as lines of figures rather than boxes, matching the intro
   stats on /replays: each group is one wrapping row of measures with a dim note
   under it carrying that group's breakdown. */
/* The corpus figures are a caption to the page header rather than a section of their
   own, so they sit closer to it than the measured sections below the page's own rhythm. */
[data-stats-section="corpus"] {
  margin-block: calc(var(--space-xs) - var(--space-lg));
}

/* The corpus figure groups use the shared c-figures component (06-components/_figures.css). */

.p-stats__stat-grid,
.p-stats__hero-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 18ch), 1fr));
  gap: var(--space-md);
}

/* Every measured section from supporting roles down is one box per row, and they all
   share this measure so their edges line up as a single column down the page. The
   tables inside carry their own min-width and scroll within their frame, so the cap
   lifts on narrow viewports rather than squeezing them. */
.p-stats__stack {
  display: grid;
  grid-template-columns: minmax(0, 1fr);   /* a wide table must scroll in its own frame, not
                                              widen the track and drag the boxes beside it out
                                              past the viewport — grid tracks size to content
                                              by default, which is what stretched the callouts. */
  gap: var(--space-md);
  max-width: 66%;
}

.p-stats__stack > * { min-width: 0; }

@media (max-width: 72rem) {
  .p-stats__stack { max-width: 100%; }
}

/* A callout in the stack is a one-line figure, not prose, so it takes the stack's
   measure rather than the narrower site-wide reading measure it defaults to. */
.p-stats__stack > .c-callout {
  max-width: none;
}

.p-stats__hero {
  border: 3px double var(--accent);
  padding: var(--space-lg) var(--gutter-page) var(--space-xl);
  min-width: 0;
}

.p-stats__hero-lead {
  max-width: 64ch;
  color: var(--text-bright);
  font-size: var(--text-xl);
  line-height: 1.35;
}

.p-stats__hero-lead + .p-stats__hero-lead {
  margin-top: var(--space-md);
}

.p-stats__hero-lead b,
.p-stats__accent { color: var(--accent); }

.p-stats__good { color: var(--good); }
.p-stats__muted { color: var(--text-muted); }

.p-stats__hero-sub {
  max-width: 70ch;
  margin-top: var(--space-xs);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.p-stats__hero-stats { margin-top: var(--space-lg); }

.p-stats__harnesses {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 28rem), 1fr));
  gap: var(--space-md);
  margin-top: var(--space-lg);
}

.p-stats__panel-caption {
  max-width: 56ch;
  margin-bottom: var(--space-md);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.p-stats__chart-frame {
  max-width: 100%;
  overflow-x: auto;
}

.p-stats__histogram {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 0.6ch;
  height: 210px;
  min-width: 28rem;
  padding-top: var(--space-sm);
  border-bottom: var(--bw) solid var(--line);
}

.p-stats__histogram-bar {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 0.4ch;
}

.p-stats__histogram-column {
  width: 100%;
  min-height: 2px;
  background: var(--accent);
}

.p-stats__histogram-column.is-over { background: var(--warn); }

.p-stats__histogram-label {
  color: var(--text-dim);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
}

.p-stats__histogram-marker {
  position: absolute;
  top: 0;
  bottom: 1.4rem;
  border-left: var(--bw) dashed var(--warn);
}

.p-stats__histogram-marker span {
  position: absolute;
  top: -0.1rem;
  left: 0.6ch;
  padding-inline: 0.4ch;
  background: var(--surface-raised);
  color: var(--warn);
  font-size: 0.7rem;
  font-weight: var(--fw-bold);
}

.p-stats__histogram-marker--secondary {
  border-left-color: var(--text-muted);
}

.p-stats__histogram-marker--secondary span {
  color: var(--text-muted);
}

/* Narrow screens — the 28rem floor above is what forces the chart frame to scroll on a
   phone. Drop it and let the 13 bins share whatever width there is: the bars are flex:1
   so they shrink on their own, and only the gaps and the bin labels need help to keep
   the row legible at ~1/13th of the viewport. The tick labels scale with the viewport
   down to a floor that still sets "300+" inside its own column. */
@media (max-width: 40rem) {
  .p-stats__histogram {
    min-width: 0;
    gap: 0.25ch;
  }

  .p-stats__histogram-label {
    font-size: clamp(0.45rem, 1.9vw, 0.7rem);
  }

  .p-stats__histogram-marker span {
    font-size: 0.6rem;
  }
}

.p-stats__harness-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1ch;
  margin-bottom: var(--space-sm);
}

.p-stats__harness-name {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--text-bright);
  font-size: var(--text-lg);
  font-weight: var(--fw-bold);
}

.p-stats__harness-count {
  color: var(--text-dim);
  font-size: var(--text-xs);
}

.p-stats__harness-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--space-xs);
  margin-top: var(--space-md);
  padding-top: var(--space-sm);
  border-top: var(--bw) solid var(--line);
}

.p-stats__harness-stat {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.p-stats__harness-value {
  color: var(--text-bright);
  font-size: var(--text-lg);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.p-stats__harness-key {
  color: var(--text-dim);
  font-size: 0.68rem;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.p-stats__bars {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-width: 0;
}

.p-stats__bar-row {
  display: grid;
  grid-template-columns: 13ch minmax(0, 1fr) 8ch;
  align-items: center;
  gap: 1ch;
}

.p-stats__bar-label {
  overflow: hidden;
  color: var(--text-muted);
  font-size: var(--text-sm);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.p-stats__bar-track {
  height: 0.7rem;
  min-width: 6rem;
  background: var(--surface-sunken);
  border: var(--bw) solid var(--line);
}

.p-stats__bar-track--stacked {
  display: flex;
  flex-direction: column;
  gap: 1px;
  height: auto;
  padding-block: 1px;
}

.p-stats__bar-fill {
  display: block;
  height: 100%;
  background: var(--accent);
}

.p-stats__bar-fill--role {
  height: 0.5rem;
}

/* The flat bucket is a different population from the milestone-split ones, not a bin
   of the same series, so it does not carry the accent. */
.p-stats__bar-fill.is-muted { background: var(--text-muted); }

.p-stats__bar-value {
  color: var(--text-bright);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.p-stats__bar-value small {
  margin-left: 0.5ch;
  color: var(--text-dim);
}

.p-stats__table-frame {
  max-width: 100%;
  overflow-x: auto;
}

.p-stats__data-table {
  min-width: 34rem;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.p-stats__data-table th {
  text-align: right;
}

.p-stats__data-table th:first-child,
.p-stats__data-table td:first-child {
  text-align: left;
}

.p-stats__data-table td {
  text-align: right;
}

.p-stats__data-table td:first-child {
  color: var(--text-muted);
}

.p-stats__data-table .is-median {
  color: var(--text-bright);
  font-weight: var(--fw-bold);
}

.p-stats__data-table .is-highlight {
  color: var(--accent);
}

/* The role bars ride in the table's last column, one stacked track per row, so the
   numbers and their shape read as a single figure rather than two facing boxes. */
.p-stats__chart-column {
  width: 34%;
  padding-left: 2ch;
}

.p-stats__data-table td.p-stats__chart-column {
  text-align: left;
}

.p-stats__data-table .is-good,
.p-stats__harness-value.is-good { color: var(--good); }

.p-stats__data-table .is-warn,
.p-stats__harness-value.is-warn { color: var(--warn); }

@media (max-width: 56rem) {
  .p-stats__section-head {
    align-items: flex-start;
    flex-direction: column;
    gap: var(--space-2xs);
  }

  .p-stats__section-rule { display: none; }
  .p-stats__bar-row { grid-template-columns: 11ch minmax(0, 1fr) 7ch; }

  /* The five figures stay on one row at every width, so they read as one line of
     numbers rather than a grid with an orphan. They only get smaller. */
  .p-stats__harness-value { font-size: var(--text-sm); }
  .p-stats__harness-key { font-size: 0.6rem; letter-spacing: normal; }
}

/* Phones — the data tables carry a 34rem floor that makes every frame scroll sideways. Rather
   than shrink the type until the figures are unreadable, drop the columns that are secondary to
   each table's point: the per-role sample counts and its median-peak bars, and the mean/p90
   columns of the decomposition table. What is left (the role, its medians, and the extremes)
   fits the viewport, so the floor comes off and the frames stop scrolling. */
@media (max-width: 40rem) {
  .p-stats__data-table {
    min-width: 0;
    font-size: var(--text-xs);
  }

  .p-stats__count-column,
  .p-stats__chart-column,
  .p-stats__data-table td.p-stats__chart-column { display: none; }

  /* Role names are the widest cell left; let them wrap rather than push the table wide. */
  .p-stats__data-table td:first-child { overflow-wrap: anywhere; }

  /* The bucket bars: the track's 6rem floor plus both gutters overruns a phone, so the
     track gives up its floor and the gutters tighten to what the text actually needs. */
  .p-stats__bar-row { grid-template-columns: 8ch minmax(0, 1fr) 5ch; gap: 0.6ch; }
  .p-stats__bar-track { min-width: 0; }
}
