/* The performance scorecard, layered over performance.css.
 *
 * A charcoal band carries the title and the filters; under it, white panels
 * on the page colour, one per measure group -- the driver-scorecard layout
 * Tom liked, in this site's own orange. Colours come from performance.css's
 * tokens wherever one exists, so dark mode follows the rest of the site; the
 * few that are this page's own are defined here for both themes.
 *
 * Every grid child carries min-width: 0. Without it a long route name or a
 * wide table sets the column's width and pushes the whole page sideways on a
 * phone -- the trap the overview's filters already hit once.
 */

.viz-root {
  --sc-band: #2b2a27;
  --sc-band-text: #ffffff;
  --sc-band-muted: #c3c2b7;
  --sc-th: #2b2a27;
  --sc-ontime: #33322f;
  --sc-late: #cf5f12;
  --sc-early: #e9a878;
  --sc-good: #2f6b3a;
  --sc-bad: #b42318;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    --sc-band: #1a1a18;
    --sc-th: #33322f;
    --sc-ontime: #d9d8d0;
    --sc-late: #ff8f45;
    --sc-early: #8a5a36;
    --sc-good: #7fc28c;
    --sc-bad: #f97066;
  }
}

:root[data-theme="dark"] .viz-root {
  --sc-band: #1a1a18;
  --sc-th: #33322f;
  --sc-ontime: #d9d8d0;
  --sc-late: #ff8f45;
  --sc-early: #8a5a36;
  --sc-good: #7fc28c;
  --sc-bad: #f97066;
}

/* ---------- Header band ---------- */

.sc-head {
  background: var(--sc-band);
  color: var(--sc-band-text);
  border-bottom: 4px solid var(--brand-orange);
}

.sc-head-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 22px 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 18px 32px;
  align-items: flex-end;
  justify-content: space-between;
}

.sc-title { min-width: 0; }

.sc-kicker {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--brand-orange);
}

.sc-title h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
  color: var(--sc-band-text);
  overflow-wrap: anywhere;
}

.sc-window {
  margin: 6px 0 0;
  font-size: 13.5px;
  color: var(--sc-band-muted);
}

.sc-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  align-items: flex-end;
  min-width: 0;
}

.sc-filter {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.sc-filter > span {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--sc-band-muted);
}

.sc-filter input,
.sc-filter select {
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--sc-band-text);
  font: inherit;
  font-size: 13.5px;
  max-width: 220px;
  color-scheme: dark;
}

.sc-filter select option { color: #0b0b0b; background: #ffffff; }

/* ---------- Panels ---------- */

.sc-body {
  max-width: 1440px;
  margin: 0 auto;
  padding: 22px 24px 40px;
}

.sc-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

/* Chart and table each keep their own height: stretched to the table's,
   the chart panel was half empty. */
.sc-grid-2 { grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.35fr); align-items: start; }

@media (max-width: 1080px) {
  .sc-grid, .sc-grid-2 { grid-template-columns: minmax(0, 1fr); }
}

.sc-panel {
  min-width: 0;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
}

.sc-panel-head {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}

.sc-panel-head h2 {
  margin: 0;
  font-size: 17px;
  color: var(--text-primary);
}

.sc-panel-sub {
  font-size: 12.5px;
  color: var(--text-muted);
}

#panels.loading .sc-panel { opacity: 0.55; }

/* A headline measure: label, big number, what it rests on, and its
   comparison. The number takes the brand orange, the way First's scorecard
   colours its headline. */
.sc-measure + .sc-measure {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.sc-measure-top {
  display: flex;
  gap: 12px;
  align-items: baseline;
  justify-content: space-between;
}

.sc-label {
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.sc-basis {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  text-align: right;
}

.sc-value {
  margin: 4px 0 8px;
  font-size: 40px;
  line-height: 1;
  font-weight: 700;
  color: var(--brand-orange);
  font-variant-numeric: tabular-nums;
}

.sc-value.small { font-size: 28px; }

/* Early / on time / late, as one bar. The shares are printed under it too:
   colour is never the only way to read a figure. */
.sc-bar {
  display: flex;
  height: 10px;
  border-radius: 5px;
  overflow: hidden;
  background: var(--grid);
}

.sc-bar span { display: block; height: 100%; }
.sc-bar .early { background: var(--sc-early); }
.sc-bar .ontime { background: var(--sc-ontime); }
.sc-bar .late { background: var(--sc-late); }

.sc-bar-key {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: 5px 0 0;
  font-size: 12px;
  color: var(--text-secondary);
}

.sc-compare {
  margin: 8px 0 0;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.sc-delta { font-weight: 700; font-variant-numeric: tabular-nums; }
.sc-delta.up { color: var(--sc-good); }
.sc-delta.down { color: var(--sc-bad); }

/* Small figures in a row, like the scorecard's activity block. */
.sc-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 16px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.sc-stat p { margin: 0; }
.sc-stat .k { font-size: 12px; color: var(--text-muted); }
.sc-stat .v {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.sc-stat .s { font-size: 11.5px; color: var(--text-muted); }

.sc-note {
  margin: 12px 0 0;
  padding: 8px 10px;
  border-left: 3px solid var(--brand-orange);
  background: var(--accent-soft);
  font-size: 12.5px;
  color: var(--text-secondary);
}

/* ---------- Chart ---------- */

.sc-chart { position: relative; min-height: 260px; }
.sc-chart svg { display: block; width: 100%; height: auto; }
.sc-chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.sc-chart .axis-text { fill: var(--text-muted); font-size: 11px; }
.sc-chart .s-origin { fill: none; stroke: var(--brand-orange); stroke-width: 2.25; }
.sc-chart .s-mid { fill: none; stroke: var(--sc-ontime); stroke-width: 2; stroke-dasharray: 5 4; }

.sc-key { display: inline-flex; align-items: center; gap: 6px; margin-left: 12px; }
.sc-key i { display: inline-block; width: 18px; height: 0; border-top: 2.5px solid var(--brand-orange); }
.sc-key i.mid { border-top: 2px dashed var(--sc-ontime); }

/* ---------- Route table ---------- */

.sc-table { overflow-x: auto; max-height: 520px; overflow-y: auto; }

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

.sc-table th {
  position: sticky;
  top: 0;
  background: var(--sc-th);
  color: var(--sc-band-text);
  font-weight: 600;
  text-align: right;
  padding: 8px 7px;
  white-space: nowrap;
}

.sc-table th:first-child, .sc-table td:first-child { text-align: left; }
.sc-table td {
  padding: 7px 7px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  color: var(--text-primary);
  white-space: nowrap;
}
.sc-table td .op { display: block; font-size: 11.5px; color: var(--text-muted); }

.sc-foot {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
  max-width: 900px;
}

.sc-empty { color: var(--text-muted); font-size: 13px; margin: 0; }

@media (max-width: 640px) {
  .sc-head-inner, .sc-body { padding-left: 16px; padding-right: 16px; }
  .sc-title h1 { font-size: 23px; }
  .sc-value { font-size: 34px; }
  .sc-filter input, .sc-filter select { max-width: 100%; }
}

/* The route column wraps, so a long operator name ("Stagecoach East
   Midlands") cannot push the last figure out of a 1440px panel. */
.sc-table td:first-child { white-space: normal; min-width: 110px; max-width: 150px; }
