/*
 * Rankings tab layout: header, mode toggle + preset select, knob notes, HERO finding sentence,
 * ranked chart, chart caveat, hover strip, compact stat row + comparison rows, sensitivity
 * slope grid, footnote. Every chart is code-drawn SVG (inline elements created by
 * rankings-chart.js and rankings-sensitivity.js), so this file only handles the enclosing
 * chrome and the responsive stack.
 *
 * Round-05 hierarchy (N5-M2): the computed finding sentence is the largest text on the tab,
 * placed directly after the mode toggle above the chart. The four stat tiles now sit AFTER
 * the chart as a compact one-line-per-tile row of secondary numbers, so nothing on the tab
 * competes with the sentence except the chart itself.
 */

.rankings-tab {
  margin-top: var(--gap-l);
  padding: 0 var(--page-side);
  max-width: var(--page-max);
  margin-left: auto;
  margin-right: auto;
  display: flex;
  flex-direction: column;
  gap: var(--gap-l);
  padding-bottom: 60px;
}

.rankings-header {
  display: flex;
  gap: var(--gap-l);
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
}

.rankings-header-text {
  flex: 1 1 320px;
  min-width: 0;
}

.rankings-title {
  font-size: clamp(20px, 2.6vw, 26px);
  margin: 0 0 6px;
  font-weight: 700;
  color: var(--ink);
}

.rankings-lede {
  margin: 0;
  color: var(--ink-soft);
  font-size: 14px;
  max-width: 62ch;
}

.rankings-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
}

.rankings-toggle {
  display: inline-flex;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--paper);
  padding: 3px;
  gap: 2px;
}

.rankings-toggle .seg {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  min-height: var(--tap);
  border-radius: 999px;
  cursor: pointer;
}

.rankings-toggle .seg.on,
.rankings-toggle .seg[aria-checked="true"] {
  background: var(--ink);
  color: var(--paper);
}

.rankings-preset-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.rankings-preset-row select {
  min-height: var(--tap);
  padding: 8px 30px 8px 12px;
  min-width: 220px;
  text-transform: none;
  letter-spacing: 0.01em;
  font-weight: 500;
}

.rankings-status {
  margin: 0;
  padding: 8px 12px;
  color: var(--ink-soft);
  font-size: 13px;
  border-left: 3px solid var(--rule);
  background: var(--paper-2);
  border-radius: var(--radius-s);
}
.rankings-status:empty { display: none; }

.rankings-knob-notes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  color: var(--ink-muted);
  font-size: 12px;
}

.rankings-knob-note {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}
.rankings-knob-note-label {
  color: var(--ink-muted);
  font-weight: 600;
  letter-spacing: 0.02em;
}
.rankings-knob-note-value {
  color: var(--ink);
}
.rankings-knob-note-warn {
  color: var(--ink);
  background: var(--paper-2);
  padding: 4px 8px;
  border-radius: var(--radius-s);
  border: 1px dashed var(--rule);
}

/*
 * When a requested knob has no precomputed sensitivity cell for the current preset the note
 * flags the fallback explicitly. Slightly muted background + dashed border so the reader can
 * pick out at a glance which knobs the chart below was actually run at.
 */
.rankings-knob-note-fallback .rankings-knob-note-value {
  color: var(--ink);
  background: var(--paper-2);
  padding: 2px 6px;
  border-radius: var(--radius-s);
  border: 1px dashed var(--rule);
}
.rankings-knob-note-fallback .rankings-knob-note-label {
  color: var(--ink);
}

.rankings-stat-sublabel-secondary {
  border-top: 0;
  padding-top: 2px;
  margin-top: 2px;
  font-style: italic;
  color: var(--ink-muted);
}

/* ----- Hero finding sentence (N5-M2) ----- */

.rankings-finding {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: clamp(20px, 2.8vw, 30px);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.005em;
  max-width: 62ch;
}
.rankings-finding:empty { display: none; }

.rankings-chart-caveat {
  margin: 0;
  color: var(--ink-muted);
  font-size: 12px;
  font-style: italic;
  max-width: 78ch;
}
.rankings-chart-caveat:empty,
.rankings-chart-caveat[hidden] { display: none; }

/* ----- Stat tiles: compact secondary row (N5-M2) ----- */

.rankings-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.rankings-stat-tile {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-m);
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.rankings-stat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.rankings-stat-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.rankings-stat-number {
  font-variant-numeric: tabular-nums;
  /* Downshifted from 40 px hero to a compact secondary weight. Nothing on this tab is
   * larger than the finding sentence except the chart itself (N5-M2). */
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.1;
  margin-top: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rankings-stat-unit {
  font-size: 11px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rankings-stat-sublabel {
  font-size: 10px;
  color: var(--ink-muted);
  border-top: 1px dashed var(--rule);
  padding-top: 3px;
  margin-top: 4px;
}
.rankings-stats-sub {
  margin: 0;
  color: var(--ink-soft);
  font-size: 12px;
  font-style: italic;
}

/*
 * Comparison rows below the tiles: the three honest per-day scaled comparisons on the
 * boarding tab. Grid: text (head + detail) on the left, value on the right, hairline rule
 * between rows so the block reads as one table without heavy chrome.
 */
.rankings-stats-comparisons {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--rule);
  border-radius: var(--radius-l);
  background: var(--paper);
  overflow: hidden;
}
.rankings-comparison-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule);
}
.rankings-comparison-row:last-child { border-bottom: 0; }
.rankings-comparison-text { display: flex; flex-direction: column; min-width: 0; }
.rankings-comparison-head { font-weight: 600; color: var(--ink); font-size: 13px; }
.rankings-comparison-detail { font-size: 12px; color: var(--ink-muted); }
.rankings-comparison-value {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--ink);
  font-size: 14px;
  white-space: nowrap;
}
/* Emphasize the "average airline vs random order" row: it is the whole thesis as a number. */
.rankings-comparison-row-emphasize {
  background: var(--paper-2);
}
.rankings-comparison-row-emphasize .rankings-comparison-head {
  font-size: 14px;
}
.rankings-comparison-row-emphasize .rankings-comparison-value {
  font-size: 16px;
}
.rankings-stats-comparisons-note {
  margin: 0;
  font-size: 11px;
  color: var(--ink-muted);
  font-style: italic;
}
@media (max-width: 480px) {
  .rankings-comparison-row { flex-direction: column; align-items: flex-start; }
  .rankings-comparison-value { align-self: flex-end; }
}

.rankings-stats-empty {
  margin: 0;
  color: var(--ink-muted);
  font-style: italic;
}

/* Phone: stack tiles two-across, then one-across if the screen is very narrow. */
@media (max-width: 899px) {
  .rankings-stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 480px) {
  .rankings-stats-grid { grid-template-columns: 1fr; }
}

/* Anchor labels: pointer cursor set here (not inline) so index.html can ship with a strict
 * Content-Security-Policy that forbids inline styles (security-round-01 n1). */
.rankings-anchor-clickable { cursor: pointer; }
.rankings-anchor-label { cursor: default; }

/* ----- Ranked chart ----- */

.rankings-chart-wrap {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-l);
  padding: 12px;
  overflow-x: auto;
}

.rankings-chart-svg-host {
  min-width: 0;
  width: 100%;
}
.rankings-chart-svg-host svg {
  width: 100%;
  height: auto;
  display: block;
}

/* N6-n11: no dashed box or min-height around the hover panel; on desktop, the empty state
   used to reserve a 1000x66 box holding one italic instruction line between the chart and
   the tiles. Now the hint sits inline; when a row is hovered, the panel expands to hold
   the label, the stats line and the sparkline. */
.rankings-hover-detail {
  padding: 6px 0 0;
  color: var(--ink-soft);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rankings-hover-hint {
  margin: 0;
  color: var(--ink-muted);
  font-style: italic;
}
.rankings-hover-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  align-items: baseline;
}
.rankings-hover-label {
  color: var(--ink);
  font-weight: 600;
  font-size: 13px;
}
.rankings-hover-stats {
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

/* ----- Sensitivity ----- */

.rankings-sensitivity-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rankings-sensitivity-heading {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 6px;
}

.rankings-sensitivity {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 14px;
}

.rankings-slope-chart {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-l);
  padding: 12px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rankings-slope-heading {
  font-size: 13px;
  font-weight: 700;
  margin: 0;
  color: var(--ink);
}

.rankings-slope-title {
  margin: 0;
  color: var(--ink-soft);
  font-size: 12px;
  font-style: italic;
}

.rankings-slope-svg-wrap {
  width: 100%;
  overflow-x: auto;
}

.rankings-slope-svg-wrap svg {
  width: 100%;
  height: auto;
  display: block;
}

.rankings-sensitivity-empty {
  margin: 0;
  color: var(--ink-muted);
  font-style: italic;
  padding: 8px 12px;
  border: 1px dashed var(--rule);
  border-radius: var(--radius-m);
}

/* ----- Footnote ----- */

.rankings-footnote {
  margin: 0;
  color: var(--ink-muted);
  font-size: 11px;
  font-family: var(--font-body);
  word-break: break-all;
}

/* ----- Rankings-tab settings sidebar (N6-m7) --------------------------------
 *
 * A compact settings column that only offers grid values. The race sidebar is a peer widget
 * inside the race tab-panel; on the rankings tab we render this one instead so the tab has
 * its own knobs without inflating the race sidebar into a cross-tab component.
 *
 * Desktop (>= 900 px): the sidebar sits to the right of the main rankings column via a
 * flex row, so a wide reader has both the chart and the knobs on screen at once.
 * Phone (< 900 px): the sidebar collapses to a full-width block above the sensitivity
 * grid (since it comes after every other rankings section in the DOM).
 */
.rankings-settings {
  border: 1px solid var(--rule);
  border-radius: var(--radius-m);
  background: var(--paper-2);
  padding: 12px 14px;
  align-self: start;
  margin-top: var(--gap-m);
}
.rankings-settings-inner {
  display: flex;
  flex-direction: column;
  gap: var(--gap-s);
}
.rankings-settings-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0;
}
.rankings-settings-lede {
  margin: 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.4;
}
.rankings-settings-knobs {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.rankings-settings .rankings-knob {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.rankings-settings .rankings-knob-head {
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.rankings-settings .rankings-knob select {
  width: 100%;
}

@media (min-width: 900px) {
  #tab-panel-rankings {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 260px;
    column-gap: var(--gap-xl);
    max-width: var(--page-max);
    margin: 0 auto;
    padding-right: var(--page-side);
    padding-left: var(--page-side);
    box-sizing: border-box;
  }
  #tab-panel-rankings > .rankings-tab {
    grid-column: 1;
    padding-left: 0;
    padding-right: 0;
    max-width: none;
    margin: 0;
  }
  #tab-panel-rankings > .rankings-settings {
    grid-column: 2;
    margin-top: var(--gap-l);
    position: sticky;
    top: 16px;
    align-self: start;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
  }
}
