/* Pinch points.
 *
 * Rides on punctuality.css for the palette, page shell, cards, filters and
 * tables, and adds only what this page has that /punctuality does not: the
 * live board, the ranked link table, the hour profile chart and the formula.
 *
 * Two traps this file is written around, both previously paid for on this
 * site:
 *
 *   [hidden] is an author-level rule like any other, so `.map-holder {
 *   display: block }` silently beats it and the element stays on screen. The
 *   guard below settles it once for every element on the page rather than
 *   relying on each rule remembering.
 *
 *   A flex or grid child defaults to min-width:auto, which refuses to shrink
 *   below its content -- one wide table then pushes the whole page sideways
 *   on a phone rather than scrolling inside its own box. Every flex child
 *   holding wide content here carries min-width: 0.
 */

[hidden] { display: none !important; }

.viz-root {
  /* Two more roles this page needs that the punctuality palette does not
     carry. The spread step is the same hue as the single-series blue at a
     lighter step -- a range around one measure, not a second identity, so it
     stays on the one hue. */
  --series-1-soft: #a9c9ef;
  --lost-time: #7a5bb5;
  /* Second categorical series, for cars against buses. Chosen by running the
     palette validator rather than by eye: against the #cf5f12 series-1 it
     scores CVD dE 25.3 (protan) and 32.2 at normal vision, well clear of the
     8 target. It sits at 2.9:1 on the light surface, just under the 3:1
     contrast floor, which obliges the relief this card already carries -- a
     legend, direct labels on both series, and a table view of the same
     numbers. The dark step is a separate value for the same reason, not an
     automatic lightening: #e07b39 falls outside the dark lightness band. */
  --series-2: #e07b39;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    --series-1-soft: #29456b;
    --lost-time: #a78bda;
    --series-2: #cf7a2c;
  }
}

:root[data-theme="dark"] .viz-root {
  --series-1-soft: #29456b;
  --lost-time: #a78bda;
  --series-2: #cf7a2c;
}

.filter-note {
  align-self: center;
  color: var(--text-muted);
  font-size: 12.5px;
  min-width: 0;
}

/* ---------- Live board ---------- */

.live-card { border-color: color-mix(in srgb, var(--status-critical) 26%, var(--border)); }

.live-badge {
  align-items: center;
  color: var(--text-secondary);
  display: inline-flex;
  font-size: 12px;
  font-weight: 600;
  gap: 6px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.live-dot {
  background: var(--status-good);
  border-radius: 50%;
  height: 8px;
  width: 8px;
}

/* Stale data must look stale. The badge is the only thing on the card that
   says whether the numbers beside it are still arriving. */
.live-badge.stale .live-dot { background: var(--text-muted); }
.live-badge.stale { color: var(--text-muted); }

@media (prefers-reduced-motion: no-preference) {
  .live-badge:not(.stale) .live-dot { animation: pinch-pulse 2.4s ease-in-out infinite; }
}

@keyframes pinch-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.live-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 26px;
  margin: 4px 0 14px;
}

.live-stat { min-width: 0; }

.live-stat .value {
  color: var(--text-primary);
  display: block;
  font-size: 26px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.live-stat .label {
  color: var(--text-secondary);
  display: block;
  font-size: 12.5px;
}

.live-stat.alerting .value { color: var(--status-critical); }

.live-basis { color: var(--text-muted); margin-top: 10px; }

/* ---------- Tables ---------- */

.pinch-table {
  border-collapse: collapse;
  font-size: 13.5px;
  min-width: 100%;
  width: max-content;
}

.pinch-table th,
.pinch-table td {
  border-bottom: 1px solid var(--border);
  padding: 8px 7px;
  text-align: right;
  white-space: nowrap;
}

/* The ranked table carries nine columns and was 107px over its container at
   1280px, which put "lost per day" -- the column the whole business case
   rests on -- off the right edge. It still scrolls if the viewport is
   narrower; this just stops the default desktop case needing it. */
.pinch-table th:first-child,
.pinch-table td:first-child { padding-left: 2px; }
.pinch-table th:last-child,
.pinch-table td:last-child { padding-right: 2px; }

.pinch-table th {
  color: var(--text-secondary);
  font-weight: 600;
  position: sticky;
  top: 0;
  background: var(--surface-1);
  z-index: 1;
}

.pinch-table td.link-name,
.pinch-table th.link-name {
  text-align: left;
  white-space: normal;
  min-width: 190px;
}

.pinch-table td { font-variant-numeric: tabular-nums; }

.pinch-table tbody tr { cursor: pointer; }
.pinch-table tbody tr:hover { background: color-mix(in srgb, var(--series-1) 8%, transparent); }
.pinch-table tbody tr.selected { background: color-mix(in srgb, var(--series-1) 14%, transparent); }

.link-name .to { color: var(--text-secondary); }
.link-name .arrow { color: var(--text-muted); padding: 0 4px; }

.lines-chips { color: var(--text-secondary); font-size: 12px; }

/* The sample count travels with every figure derived from it. A median of six
   buses and a median of six hundred must not look alike on a page someone is
   about to spend money against. */
.samples { color: var(--text-muted); font-size: 12px; }

/* Status is never colour alone -- each carries its own word. */
.ratio-pill {
  border-radius: 999px;
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
}

.ratio-pill.normal {
  background: color-mix(in srgb, var(--status-good) 14%, transparent);
  color: var(--text-primary);
}

.ratio-pill.slower {
  background: color-mix(in srgb, var(--status-warning) 24%, transparent);
  color: var(--text-primary);
}

.ratio-pill.much-slower {
  background: color-mix(in srgb, var(--status-critical) 18%, transparent);
  color: var(--text-primary);
}

.lost-time-value { color: var(--lost-time); font-weight: 600; }

/* ---------- Map ---------- */

.map-holder { margin-bottom: 14px; }

#map {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  height: 420px;
  width: 100%;
}

.map-key {
  color: var(--text-secondary);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 12.5px;
  padding-top: 8px;
}

.map-key span { align-items: center; display: inline-flex; gap: 6px; }

.map-key i {
  border-radius: 50%;
  display: inline-block;
  height: 10px;
  width: 10px;
}

.maplibregl-popup-content {
  background: var(--surface-1);
  border-radius: 10px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
}

.maplibregl-popup-content .pop-title { font-weight: 600; }
.maplibregl-popup-tip { border-top-color: var(--surface-1); }

/* ---------- Link detail ---------- */

.detail-figures {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 26px;
  margin-bottom: 14px;
}

.detail-figures .figure { min-width: 0; }

.detail-figures .value {
  color: var(--text-primary);
  display: block;
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.detail-figures .label { color: var(--text-secondary); display: block; font-size: 12.5px; }

.chart-legend {
  color: var(--text-secondary);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  font-size: 12.5px;
  padding: 6px 0 2px;
}

.chart-legend span { align-items: center; display: inline-flex; gap: 6px; }

.chart-legend i {
  border-radius: 2px;
  display: inline-block;
  height: 10px;
  width: 10px;
}

.chart-legend i.baseline {
  background: none;
  border-top: 2px dashed var(--text-muted);
  border-radius: 0;
  height: 0;
  width: 14px;
}

.bar-median { fill: var(--series-1); }

/* Slowdown comparison: buses against cars, both as a share of the run lost,
   so the two sit on one axis. Never a second y-scale -- the whole reason this
   is a separate chart from the run-time one above it is that seconds and
   ratios do not share an axis. */
.slowdown-bus { stroke: var(--series-1); fill: none; stroke-width: 2; }
.slowdown-car { stroke: var(--series-2); fill: none; stroke-width: 2; }
.slowdown-bus-dot { fill: var(--series-1); }
.slowdown-car-dot { fill: var(--series-2); }
.series-label { font-size: 11px; font-weight: 600; }
.series-label.bus { fill: var(--series-1); }
.series-label.car { fill: var(--series-2); }

.subhead {
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 600;
  margin: 22px 0 2px;
}

.traffic-note {
  border-left: 3px solid var(--border);
  color: var(--text-secondary);
  font-size: 13.5px;
  margin: 10px 0 0;
  padding: 8px 0 8px 12px;
}

.traffic-note strong { color: var(--text-primary); }

.bus-specific {
  color: var(--text-primary);
  font-size: 13.5px;
  padding-top: 8px;
}
.bar-spread { fill: var(--series-1-soft); }
.baseline-line { stroke: var(--text-muted); stroke-dasharray: 4 3; stroke-width: 2; }
.peak-label { fill: var(--text-primary); font-size: 11px; font-weight: 600; }
.hour-tick { fill: var(--text-muted); font-size: 10.5px; }

/* ---------- Method ---------- */

.formula {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.formula .term {
  border: 1px solid color-mix(in srgb, var(--series-1) 45%, var(--border));
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
}

.formula .term.result {
  background: color-mix(in srgb, var(--series-1) 12%, transparent);
  border-color: var(--series-1);
}

.formula .op { color: var(--text-muted); font-weight: 600; }

.method-list { margin: 0; }
.method-list dt { color: var(--text-primary); font-weight: 600; margin-top: 12px; }
.method-list dt:first-child { margin-top: 0; }
.method-list dd { color: var(--text-secondary); font-size: 13.5px; margin: 4px 0 0; }

.method-list code {
  background: color-mix(in srgb, var(--text-primary) 7%, transparent);
  border-radius: 4px;
  font-size: 12.5px;
  padding: 1px 5px;
}

.view-switch { display: inline-flex; gap: 8px; flex-wrap: wrap; }

.table-toggle[aria-pressed="true"] {
  background: color-mix(in srgb, var(--series-1) 14%, transparent);
  border-color: var(--series-1);
  color: var(--text-primary);
}

.corridor-crumb { color: var(--text-primary); }
.corridor-crumb button { margin-left: 8px; }

/* Reserved for links that clear the floor -- most do not. Carries its own
   word, so the marker never depends on colour alone. */
.pinch-badge {
  background: color-mix(in srgb, var(--status-critical) 16%, transparent);
  border-radius: 999px;
  color: var(--text-primary);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  white-space: nowrap;
}

.corridor-name { font-weight: 600; }
.corridor-sub { color: var(--text-secondary); font-size: 12px; }

.empty-note { color: var(--text-muted); font-size: 13.5px; padding: 10px 0; }

@media (max-width: 640px) {
  #map { height: 300px; }
  .live-stat .value { font-size: 22px; }
}
