/* Punctuality dashboard.

   Colour roles come from the validated data-viz palette: one blue for the
   single-series charts, and the fixed status colours for the punctuality mix.
   Status yellow sits below 3:1 on the light surface by design, so every
   segment of the mix bar carries a visible label rather than relying on its
   colour -- and each chart can be switched to a table. */

.viz-root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --series-1: #2a78d6;
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --series-1: #3987e5;
  }
}

:root[data-theme="dark"] .viz-root {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --series-1: #3987e5;
}

body.viz-root {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

.dash-wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 18px 60px;
}

.dash-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.dash-head h1 {
  font-size: 21px;
  margin: 0;
  font-weight: 700;
}

.dash-sub {
  color: var(--text-secondary);
  font-size: 13px;
  margin: 2px 0 18px;
  max-width: 70ch;
}

.dash-back {
  font-size: 13px;
  color: var(--series-1);
  text-decoration: none;
}

/* Filters sit in one row above the charts. */
.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  padding: 12px 14px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.filters label {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.filters select,
.filters input[type="date"] {
  font: inherit;
  font-size: 13px;
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
}

.filter-presets {
  display: flex;
  gap: 4px;
}

.preset-btn,
.export-btn,
.table-toggle {
  font: inherit;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}

.preset-btn[aria-pressed="true"] {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #ffffff;
}

.export-btn {
  margin-left: auto;
  color: var(--series-1);
  border-color: var(--series-1);
}

/* Stat tiles: the headline figures, no plot. */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.tile-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.tile-value {
  font-size: 30px;
  font-weight: 700;
  line-height: 1.05;
  color: var(--text-primary);
}

.tile-note {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 5px;
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 2px;
}

.card h2 {
  font-size: 15px;
  margin: 0;
  font-weight: 600;
}

.card-note {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 12px;
}

/* Composition bar: every segment is labelled, so colour never carries the
   meaning on its own. */
.mix-bar {
  display: flex;
  height: 30px;
  border-radius: 6px;
  overflow: hidden;
  /* 2px of surface between fills */
  gap: 2px;
  background: var(--surface-1);
}

.mix-seg {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #ffffff;
  min-width: 2px;
  overflow: hidden;
  white-space: nowrap;
}

.mix-seg.on-time { background: var(--status-good); }
.mix-seg.early { background: var(--series-1); }
.mix-seg.late { background: var(--status-warning); color: #3a2a00; }
.mix-seg.very-late { background: var(--status-critical); }

.mix-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-secondary);
}

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

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: none;
}

.chart {
  width: 100%;
  overflow-x: auto;
}

.chart svg {
  display: block;
  max-width: 100%;
}

.axis-text {
  font-size: 11px;
  fill: var(--text-muted);
}

.grid-line {
  stroke: var(--grid);
  stroke-width: 1;
}

.axis-line {
  stroke: var(--axis);
  stroke-width: 1;
}

.series-line {
  fill: none;
  stroke: var(--series-1);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.series-dot {
  fill: var(--series-1);
  stroke: var(--surface-1);
  stroke-width: 2;
}

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

.hover-target {
  fill: transparent;
  cursor: crosshair;
}

.crosshair {
  stroke: var(--axis);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  color: var(--text-primary);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
  white-space: nowrap;
  z-index: 5;
}

.chart-holder {
  position: relative;
}

.empty-note {
  color: var(--text-muted);
  font-size: 13px;
  padding: 22px 4px;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

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

table.data th:first-child,
table.data td:first-child {
  text-align: left;
  white-space: normal;
}

table.data th {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
}

/* Inline proportion bar in a league table row: magnitude at a glance
   without a separate chart. */
.bar-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}

.bar-track {
  width: 90px;
  height: 6px;
  border-radius: 3px;
  background: var(--grid);
  overflow: hidden;
  flex: none;
}

.bar-fill {
  height: 100%;
  background: var(--series-1);
  border-radius: 3px;
}

.table-scroll {
  overflow-x: auto;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 16px;
}

.two-col .card {
  margin-bottom: 0;
}

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

.coverage-headline.warn {
  color: var(--status-critical);
  font-weight: 600;
}

.pill-missing {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--status-critical);
  color: #ffffff;
}

/* An operator that runs no buses can't publish AVL, so it's marked as
   out of scope rather than as a failure. */
.pill-exempt {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--grid);
  color: var(--text-secondary);
  cursor: help;
}

/* ---------- Current service level board ---------- */

.status-card {
  /* A live board rather than a view of the selected range, so it sits above
     the filters and is set apart from them. */
  border-left: 3px solid var(--series-1);
}

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

.status-headline.warn {
  color: var(--text-primary);
  font-weight: 600;
}

.status-headline.bad {
  color: var(--status-critical);
  font-weight: 600;
}

/* Multi-column rather than grid: the authority groups are all different
   heights, and a grid forces every group in a row to the tallest one's height,
   stranding a single-area authority above a hand of empty space. Columns let
   the groups flow, and break-inside keeps one from splitting across a gap. */
.status-board {
  columns: 3 320px;
  column-gap: 22px;
  margin-top: 4px;
}

.status-quiet {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

.status-group {
  break-inside: avoid;
  padding: 6px 0 10px;
}

.status-group-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
}

.status-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}

.status-row:last-child {
  border-bottom: none;
}

/* Status colour never carries meaning on its own: every row also spells the
   level out in words, because the warning yellow sits below 3:1 against the
   light surface and a dot alone would be the only cue for it. */
.status-dot {
  flex: none;
  width: 10px;
  height: 10px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-dot.good { background: var(--status-good); }
.status-dot.minor { background: var(--status-warning); }
.status-dot.severe { background: var(--status-critical); }
.status-dot.unknown {
  background: transparent;
  border: 1.5px dashed var(--axis);
}

.status-body {
  flex: 1 1 auto;
  min-width: 0;
}

.status-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.status-detail {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 1px;
}

.status-label {
  flex: none;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
  padding-top: 1px;
  text-align: right;
}

.status-row.severe .status-label { color: var(--status-critical); }
.status-row.unknown { opacity: 0.72; }

/* Marks a status compared against the network rather than the area's own
   history, which is most of them until enough days have accumulated. */
.status-provisional,
.status-note-flag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  background: var(--grid);
  color: var(--text-secondary);
  cursor: help;
  vertical-align: 1px;
}

.status-note-flag {
  cursor: default;
  background: transparent;
  border: 1px solid var(--border);
}

.status-basis {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-muted);
}
