* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  padding: 24px;
  max-width: 1100px;
  margin: 0 auto;
  color: #222;
  line-height: 1.5;
}

header {
  border-bottom: 1px solid #e5e5e5;
  padding-bottom: 12px;
  margin-bottom: 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

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

h1 { word-wrap: break-word; overflow-wrap: break-word; }

.header-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
  padding-top: 4px;
}
.header-nav a {
  font-size: 13px;
  color: #1971c2;
  text-decoration: none;
  padding: 6px 12px;
  border: 1px solid #1971c2;
  border-radius: 4px;
  white-space: nowrap;
  text-align: center;
}
.header-nav a:hover {
  background: #1971c2;
  color: white;
}
.header-nav a[aria-current="page"] {
  background: #1971c2;
  color: white;
  pointer-events: none;
}

@media (max-width: 480px) {
  header { flex-direction: column; gap: 10px; }
  .header-nav { flex-direction: row; flex-wrap: wrap; padding-top: 0; }
  .header-nav a { font-size: 12px; padding: 4px 8px; }
}

#date-selector { margin-top: 10px; }

.cal { display: inline-block; font-size: 13px; user-select: none; }

.cal-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 5px;
}
.cal-title {
  flex: 1;
  text-align: center;
  font-weight: 600;
  font-size: 13px;
  color: #222;
}
.cal-btn {
  background: none;
  border: 1px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
  padding: 1px 6px;
  font-size: 13px;
  color: #555;
  line-height: 1.4;
}
.cal-btn:hover:not(:disabled) { background: #f0f0f0; }
.cal-btn:disabled { opacity: 0.25; cursor: default; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 28px);
  gap: 2px;
}
.cal-dow {
  text-align: center;
  font-size: 11px;
  color: #aaa;
  padding: 2px 0;
  font-weight: 500;
}
.cal-day {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  border-radius: 4px;
  border: 1px solid transparent;
}
.cal-has {
  border-color: #1971c2;
  color: #1971c2;
  cursor: pointer;
  font-weight: 500;
  background: none;
}
.cal-has:hover { background: #e8f0fe; }
.cal-cur {
  background: #1971c2 !important;
  color: white !important;
  border-color: #1971c2 !important;
}
.cal-none { color: #ccc; }
.cal-empty { border: none; }

h1 { margin: 0 0 4px; font-size: 28px; }
h2 { margin: 0 0 12px; font-size: 18px; }
section { margin-top: 32px; }

.muted {
  color: #6b6b6b;
  font-size: 13px;
}
.defn {
  margin-top: 0;
  margin-bottom: 8px;
  line-height: 1.6;
}
.defn + .defn { margin-top: 4px; }
.defn code {
  background: #eef2f7;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12px;
}
.sub-h {
  margin-top: 24px;
  margin-bottom: 4px;
  font-size: 14px;
  color: #444;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.small-cards .card .val { font-size: 20px; }
.small-cards .card { padding: 10px 12px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.card {
  border: 1px solid #e5e5e5;
  border-radius: 6px;
  padding: 14px 16px;
  background: #fafafa;
}
.card .label {
  font-size: 11px;
  color: inherit;
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.card .val {
  font-size: 26px;
  font-weight: 600;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
th, td {
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid #eee;
}
th {
  background: #f4f4f4;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th.sorted-asc::after  { content: " ▲"; opacity: 0.5; }
th.sorted-desc::after { content: " ▼"; opacity: 0.5; }
tbody tr:hover { background: #fafafa; }

.route-badge {
  display: inline-block;
  min-width: 36px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 13px;
  text-align: center;
  border: 1px solid rgba(0, 0, 0, 0.08);
}
.route-n {
  margin-left: 6px;
  color: #888;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

tr.route-row { cursor: pointer; }
tr.route-row:hover { background: #f4f8fc; }
tr.route-row.is-open { background: #eef4fa; }
tr.route-row.is-open td { border-bottom-color: transparent; }

.expand-cell, .expand-th {
  width: 24px;
  text-align: center;
  color: #888;
  user-select: none;
}

tr.route-detail > td {
  position: relative;
  padding: 8px 16px 14px;
  background: #f6f9fc;
  border-bottom: 1px solid #e5e5e5;
}
tr.route-detail[hidden] { display: none; }

.route-week-btn {
  position: absolute;
  top: 8px;
  right: 16px;
  font-size: 12px;
  font-weight: 600;
  color: #1971c2;
  text-decoration: none;
  white-space: nowrap;
  padding: 4px 10px;
  border: 1px solid #1971c2;
  border-radius: 4px;
  background: #fff;
}
.route-week-btn:hover { background: #1971c2; color: #fff; }

.route-detail-list {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.route-detail-list > div {
  display: flex;
  gap: 12px;
  align-items: baseline;
}
.route-detail-list dt {
  margin: 0;
  flex: 0 0 200px;
  color: #555;
  font-size: 13px;
}
.route-detail-list dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
@media (max-width: 600px) {
  .route-detail-list dt { flex-basis: 140px; font-size: 12px; }
}

.route-controls {
  margin: 8px 0 0;
  display: flex;
  gap: 8px;
}
.route-controls button {
  font-family: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid #c8c8c8;
  border-radius: 4px;
  background: #fafafa;
  color: #444;
  cursor: pointer;
}
.route-controls button:hover { background: #f0f0f0; border-color: #b0b0b0; }
.route-controls button:active { background: #e6e6e6; }
#route-filter {
  font-family: inherit;
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid #c8c8c8;
  border-radius: 4px;
  width: 140px;
}
#route-filter:focus { outline: none; border-color: #1971c2; }

.boxplot {
  display: block;
  vertical-align: middle;
}

canvas { max-width: 100%; height: auto !important; }

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-wrap table { min-width: 700px; }

/* Weekly: heatmap controls (also reused for line-chart toggle) */
.hm-controls {
  margin: 8px 0 12px;
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: #444;
}
.hm-controls label { cursor: pointer; }
.hm-controls input { vertical-align: middle; margin-right: 4px; }

/* Weekly: day × hour heatmap */
.hm-grid {
  display: grid;
  grid-template-columns: 50px repeat(24, 1fr);
  gap: 1px;
  background: #ddd;
  border: 1px solid #ddd;
  font-variant-numeric: tabular-nums;
}
.hm-corner, .hm-hcol, .hm-row, .hm-cell { background: white; }
.hm-hcol {
  font-size: 10px;
  text-align: center;
  padding: 4px 0;
  color: #666;
}
.hm-row {
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  padding: 6px 0;
  cursor: pointer;
}
.hm-row:hover { background: #eef4fa; }
.hm-cell {
  min-height: 26px;
  font-size: 10px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  text-align: center;
  line-height: 26px;
  position: relative;
  transition: transform 0.08s ease, box-shadow 0.08s ease, font-size 0.08s ease;
}
.hm-cell:hover {
  transform: scale(1.6);
  z-index: 10;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  font-size: 13px;
  cursor: default;
}
.hm-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  font-size: 12px;
  color: #555;
}
.hm-legend-cell {
  width: 28px;
  height: 14px;
  border: 1px solid rgba(0, 0, 0, 0.06);
}

/* Weekly: per-route line-chart selection */
.route-select { margin: 12px 0 0; }
.route-select-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.route-select-controls input {
  font-family: inherit;
  font-size: 13px;
  padding: 4px 8px;
  border: 1px solid #c8c8c8;
  border-radius: 4px;
  min-width: 180px;
}
.route-select-controls button {
  font-family: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid #c8c8c8;
  border-radius: 4px;
  background: #fafafa;
  color: #444;
  cursor: pointer;
}
.route-select-controls button:hover {
  background: #f0f0f0;
  border-color: #b0b0b0;
}
.route-select-count { font-size: 12px; }
.route-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid #e5e5e5;
  border-radius: 4px;
  background: #fafafa;
}
.route-chip {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid var(--route-color, #c8c8c8);
  background: white;
  color: var(--route-color, #555);
  cursor: pointer;
  user-select: none;
  min-width: 36px;
  text-align: center;
}
.route-chip:hover {
  box-shadow: 0 0 0 1px var(--route-color, #888);
}
.route-chip.is-selected {
  background: var(--route-color, #888);
  color: var(--route-text, white);
}
.route-chip.hidden { display: none; }

/* Weekly: route × day SD% grid */
.rdgrid {
  display: grid;
  grid-template-columns: minmax(160px, 1.4fr) repeat(7, 1fr);
  gap: 2px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.rdgrid-corner { background: transparent; }
.rdgrid-hcol {
  font-size: 12px;
  text-align: center;
  font-weight: 600;
  padding: 6px 4px;
  background: #f4f4f4;
  cursor: pointer;
  border-radius: 3px;
}
.rdgrid-hcol:hover { background: #e6eef7; }
.rdgrid-hcol small { color: #888; font-weight: 400; }
.rdgrid-rlabel {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  white-space: nowrap;
  overflow: hidden;
  position: relative;
}
.rdgrid-p50 {
  font-size: 11px;
  color: #888;
  white-space: nowrap;
  flex-shrink: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 0.15s, max-width 0.15s;
  max-width: 200px;
  opacity: 1;
}
.rdgrid-rlabel:hover .rdgrid-p50 {
  opacity: 0;
  max-width: 0;
  pointer-events: none;
}
.rdgrid-cell {
  text-align: center;
  padding: 6px 2px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 3px;
  cursor: pointer;
}
.rdgrid-empty {
  background: #f8f8f8;
  color: #999;
  cursor: default;
}
.rdgrid-hidden { display: none; }
.rdgrid-map-btn {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: #1971c2;
  text-decoration: none;
  flex-shrink: 0;
  white-space: nowrap;
  padding: 3px 0;
  border: 1px solid #1971c2;
  border-radius: 3px;
  background: #fff;
  text-align: center;
  max-width: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s, max-width 0.15s, padding 0.15s;
}
.rdgrid-rlabel:hover .rdgrid-map-btn {
  max-width: 120px;
  padding: 3px 8px;
  opacity: 1;
  pointer-events: auto;
}
.rdgrid-map-btn:hover { background: #1971c2; color: #fff; }

footer {
  margin-top: 60px;
  padding-top: 18px;
  border-top: 1px solid #e5e5e5;
  text-align: center;
  font-size: 13px;
  color: #6b6b6b;
}
footer a {
  color: inherit;
  text-decoration: none;
}
footer a:hover {
  color: #1971c2;
  text-decoration: underline;
}

/* ---- report card ---- */
.agency-hero { margin-bottom: 28px; }
.agency-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 26px;
  padding: 24px 28px;
  border-radius: 16px;
  background: linear-gradient(135deg, #ffffff 0%, #f3f7fb 100%);
  border: 1px solid #e2e8f0;
  box-shadow: 0 10px 34px rgba(20, 50, 90, 0.10);
}
.agency-grade {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 158px;
  padding: 20px 26px;
  border-radius: 16px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}
.agency-grade-letter {
  font-size: 68px;
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: -0.02em;
}
.agency-grade-score {
  font-size: 20px;
  font-weight: 700;
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
}
.agency-grade-score span { font-size: 13px; font-weight: 600; opacity: 0.85; }
.agency-body { flex: 1; min-width: 280px; }
.agency-title { font-size: 24px; font-weight: 800; letter-spacing: -0.01em; }
.agency-sub { color: #5a6b7b; font-size: 13px; margin: 4px 0 16px; max-width: 60ch; }
.agency-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 10px;
}
.agency-stat {
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid #e7eef5;
  border-radius: 9px;
}
.as-val { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.as-label {
  font-size: 10.5px;
  color: #6b7b8b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 3px;
}
.as-sub { font-size: 11px; color: #9aa7b3; margin-top: 1px; }

.report-intro {
  margin-bottom: 24px;
}
.report-intro p { margin-top: 0; }
.report-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}
.report-action {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: #1971c2;
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid #1971c2;
  white-space: nowrap;
}
.report-action:hover { background: #145a9e; }

.grade-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.grade-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  min-width: 56px;
  padding: 4px 8px;
  border-radius: 5px;
  font-weight: 700;
  font-size: 14px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}
.grade-chip small {
  font-weight: 500;
  font-size: 10px;
  opacity: 0.85;
}

.grade-badge {
  display: inline-block;
  min-width: 32px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 14px;
  text-align: center;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.metric-pill {
  display: inline-block;
  padding: 2px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
  line-height: 1.5;
  border: 1px solid rgba(0, 0, 0, 0.06);
}

.route-page-btn {
  font-size: 12px;
  font-weight: 600;
  color: #1971c2;
  text-decoration: none;
  white-space: nowrap;
  padding: 3px 8px;
  border: 1px solid #1971c2;
  border-radius: 4px;
}
.route-page-btn:hover { background: #1971c2; color: #fff; }
