/* Corridor Performance Dashboard
   Colors are tokens; text/background pairs meet WCAG 2.1 AA (4.5:1 text, 3:1 UI). */

:root {
    --arc-blue: #264796;        /* 8.6:1 with white */
    --arc-blue-dark: #1a3266;
    --ink: #1f2328;             /* 15.8:1 on white */
    --ink-secondary: #4f5560;   /* 7.4:1 on white */
    --surface: #ffffff;
    --plane: #f4f5f7;
    --hairline: #d6d9de;
    --focus: #0b5fff;
    --link: #1a4fb5;            /* 6.9:1 on white */

    /* chart series: one color per analysis period (validated: CVD dE 9.2, normal dE 24.0) */
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --series-3: #1baf7a;

    /* road condition status */
    --good: #0ca30c;
    --fair: #f59100;
    --poor: #d90000;

    --radius: 8px;
    --gap: 1rem;
    font-size: 100%;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    line-height: 1.5;
    color: var(--ink);
    background: var(--plane);
}

img { max-width: 100%; height: auto; }

a { color: var(--link); }
a:hover { text-decoration-thickness: 2px; }

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0);
    white-space: nowrap; border: 0;
}

.skip-link {
    position: absolute; left: 1rem; top: -4rem;
    background: var(--surface); color: var(--link);
    padding: .5rem 1rem; border-radius: var(--radius);
    z-index: 2000;
}
.skip-link:focus { top: 1rem; }

/* ---------- header / footer ---------- */

.site-header {
    display: flex; align-items: center; gap: 1rem;
    padding: 1rem clamp(1rem, 4vw, 3rem);
    background: var(--arc-blue); color: #fff;
}
.site-header h1 { margin: 0; font-size: clamp(1.4rem, 3.5vw, 2.2rem); line-height: 1.2; }
.site-kicker { margin: 0; font-size: .9rem; opacity: .95; }
.site-logo { flex: none; display: block; border-radius: 6px; }
.site-logo img { display: block; width: 48px; height: 48px; }
.site-logo:focus-visible { outline-color: #fff; }

.site-footer {
    background: var(--arc-blue-dark); color: #fff;
    padding: 1.5rem clamp(1rem, 4vw, 3rem);
    font-size: .95rem;
}
.site-footer a { color: #fff; }

main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.5rem clamp(1rem, 4vw, 2rem) 3rem;
}
main:focus { outline: none; }

h2 { font-size: 1.6rem; margin: 0 0 .5rem; line-height: 1.25; }
h3 { font-size: 1.25rem; margin: 0 0 .5rem; line-height: 1.3; }
h4 { font-size: 1.05rem; margin: 1rem 0 .4rem; }
.lead { color: var(--ink-secondary); margin-top: 0; }

/* ---------- picker ---------- */

#picker, .card {
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--radius);
    padding: clamp(1rem, 3vw, 1.5rem);
}

.picker-layout {
    display: grid;
    gap: var(--gap);
    grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 900px) {
    /* the picker fills the window below the site header (--header-h is set by app.js), so the
       report starts just below the fold; the map takes the leftover height */
    #picker { display: flex; flex-direction: column; min-height: calc(100vh - var(--header-h, 6rem) - 1.5rem); }
    .picker-layout { flex: 1 1 auto; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); grid-template-rows: minmax(0, 1fr); }
    .picker-map { display: flex; flex-direction: column; }
    .picker-map .map { flex: 1 1 auto; height: auto; min-height: 24rem; }
    /* the map column sets the row height; the list stretches to it and the table scrolls inside */
    .picker-list { contain: size; display: flex; flex-direction: column; }
    .picker-list .table-scroll { flex: 1 1 0; min-height: 12rem; max-height: none; }
}

.filters {
    display: grid; gap: .75rem;
    grid-template-columns: repeat(auto-fit, minmax(min(11rem, 100%), 1fr));
}
.field { display: flex; flex-direction: column; gap: .25rem; }
.field label { font-weight: 600; font-size: .95rem; }
input[type="search"], select {
    font: inherit;
    min-height: 44px;
    padding: .4rem .6rem;
    border: 1px solid #767b85;   /* 4.5:1 boundary */
    border-radius: 6px;
    background: var(--surface); color: var(--ink);
}
.result-count { margin: .5rem 0; color: var(--ink-secondary); font-size: .95rem; }

.table-scroll {
    max-height: 26rem;
    overflow: auto;
    border: 1px solid var(--hairline);
    border-radius: 6px;
}
.corridor-table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.corridor-table thead th {
    position: sticky; top: 0; z-index: 1;
    background: #e9ecf3;
    text-align: left; padding: 0;
}
.corridor-table th button {
    all: unset; box-sizing: border-box;
    display: block; width: 100%;
    padding: .55rem .6rem; font-weight: 600; cursor: pointer;
}
.corridor-table th button::after { content: " ↕"; color: var(--ink-secondary); }
.corridor-table th[aria-sort="ascending"] button::after { content: " ↑"; color: var(--ink); }
.corridor-table th[aria-sort="descending"] button::after { content: " ↓"; color: var(--ink); }
.corridor-table th button:focus-visible { outline-offset: -3px; }
.corridor-table td { padding: .3rem .6rem; border-top: 1px solid var(--hairline); }
.corridor-table td:last-child, .corridor-table th:last-child { text-align: right; }
.corridor-table tr.is-selected { background: #e3ebfb; }
.corridor-link {
    font: inherit; color: var(--link);
    background: none; border: 0; padding: .35rem 0;
    min-height: 32px; text-align: left; cursor: pointer;
    text-decoration: underline; text-underline-offset: 2px;
}
.corridor-link[aria-current="true"] { font-weight: 700; }

.map {
    height: 26rem;
    border-radius: 6px;
    border: 1px solid var(--hairline);
}
@media (max-width: 600px) { .map { height: 18rem; } }
.leaflet-container:focus-visible { outline: 3px solid var(--focus); }
.leaflet-bar a:focus-visible { outline: 3px solid var(--focus); outline-offset: 0; }

.map-legend {
    display: flex; flex-wrap: wrap; gap: .25rem 1rem;
    margin-top: .5rem; font-size: .9rem; color: var(--ink-secondary);
}
.map-legend i { display: inline-block; width: 1.4rem; height: 4px; border-radius: 2px; margin-right: .35rem; vertical-align: middle; }
.map-legend-title { font-weight: 600; color: var(--ink); }

/* ---------- report ---------- */

#report { margin-top: 2rem; }
.report-header {
    background: var(--arc-blue); color: #fff;
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 1.25rem clamp(1rem, 3vw, 1.5rem);
}
.report-header h2 { margin: 0; font-size: clamp(1.5rem, 4vw, 2rem); }
.report-header h2:focus { outline: none; }
.report-header h2:focus-visible { outline: 3px solid #fff; }
.report-kicker, .report-subtitle { margin: 0; }
.report-kicker { font-size: .9rem; }
.report-subtitle { font-size: 1.05rem; }
.report-roads { margin: .15rem 0 .35rem; font-size: 1.2rem; font-weight: 600; }

.report-header { border-radius: var(--radius); margin-bottom: 1.25rem; scroll-margin-top: 1rem; }

#report-body { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1fr); }
.card { scroll-margin-top: 1rem; }
.card > h3 { display: flex; align-items: baseline; flex-wrap: wrap; gap: .25rem .75rem; }
.period-note { font-size: .9rem; font-weight: 400; color: var(--ink-secondary); }

.grid-2 { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
/* profile: the map stretches to the height of the stats and traffic table beside it */
@media (min-width: 900px) {
    .profile-grid > div:last-child { display: flex; flex-direction: column; }
    .profile-grid .map { flex: 1 1 auto; height: auto; min-height: 26rem; }
}

.summary li { margin-bottom: .25rem; }

figure { margin: 0; }
figure img { display: block; border: 1px solid var(--hairline); border-radius: 6px; background: #fff; }
figcaption { font-size: .95rem; color: var(--ink-secondary); margin-top: .4rem; }

/* congestion scan heat maps (drawn by scanChart in charts.js), one per direction */
.scan-heading { margin: 1.25rem 0 .25rem; }
.scan-heading:first-of-type { margin-top: .5rem; }
.scan-chart { position: relative; margin: .5rem 0 1rem; touch-action: pan-y; }
.scan-chart canvas { display: block; }
.scan-earlier { display: none; margin: -.25rem 0 1rem; }
@media (max-width: 700px) { .scan-earlier { display: block; } }
.scan-legend-title { margin: .5rem 0 .25rem; font-weight: 600; font-size: .9rem; }
.scan-legend { display: flex; flex-wrap: wrap; gap: .25rem .9rem; margin: 0; padding: 0; list-style: none; font-size: .85rem; }
.scan-legend li { display: flex; align-items: center; gap: .35rem; }
.scan-legend i { width: .95rem; height: .95rem; border-radius: 2px; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .25); }
.scan-legend i.peak-key { width: 0; border-left: 2px dashed var(--ink); border-radius: 0; box-shadow: none; margin: 0 .4rem; }
.chart-note { font-size: .95rem; color: var(--ink-secondary); margin: .75rem 0 0; }

.unavailable {
    padding: 1rem; border: 1px dashed #8a8f98; border-radius: 6px;
    color: var(--ink-secondary); font-style: italic;
}

/* stat tiles */
.stats { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(min(12rem, 100%), 1fr)); margin: .5rem 0; }
.stat { border: 1px solid var(--hairline); border-radius: 6px; padding: .75rem 1rem; }
/* eight tiles: 4 × 2 on wide screens, 2 per row on phones */
.stats-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 900px) { .stats-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat-label { display: block; font-size: .9rem; color: var(--ink-secondary); }
.stat-value { display: block; font-size: 1.6rem; font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.stat-note { display: block; font-size: .85rem; color: var(--ink-secondary); }
.stat-text { font-size: 1.15rem; line-height: 1.35; }
@media (min-width: 900px) { .stat-wide { grid-column: span 2; } }
details.definition ul { margin: .25rem 0 .5rem; padding-left: 1.25rem; color: var(--ink-secondary); }
details.definition li { margin-bottom: .2rem; }

/* data tables */
.data-table { border-collapse: collapse; font-size: .95rem; font-variant-numeric: tabular-nums; min-width: 100%; }
.data-table caption { text-align: left; font-weight: 600; padding: .25rem 0 .5rem; }
.data-table th, .data-table td { padding: .4rem .6rem; border-bottom: 1px solid var(--hairline); text-align: right; white-space: nowrap; }
.data-table th:first-child, .data-table td:first-child { text-align: left; white-space: normal; }
.data-table thead th { background: #e9ecf3; }
.table-wrap { overflow-x: auto; }
.table-source { font-size: .85rem; color: var(--ink-secondary); margin: .4rem 0 0; }
@media (max-width: 700px) {
    .data-table th, .data-table td { white-space: normal; padding: .35rem .4rem; }
    .data-table { font-size: .9rem; }
}

details { margin-top: .75rem; }
summary { cursor: pointer; color: var(--link); font-weight: 600; padding: .25rem 0; min-height: 32px; }
details.definition summary { font-weight: 400; }
details.definition p { margin: .25rem 0 .5rem; color: var(--ink-secondary); }

/* chart containers include the axis band, so nothing scrolls inside */
.chart { position: relative; height: 18rem; }
@media (max-width: 600px) { .chart { height: 15rem; } }
.svg-chart { height: auto; min-height: 10rem; }
.svg-chart svg { display: block; }
.chart-title { margin: .5rem 0 .25rem; font-weight: 600; }
/* direction icon before a direction name (dirIcon in sections.js) */
.dir-title { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .25em .5em; }
.dir-name { display: inline-flex; align-items: center; gap: .4em; white-space: nowrap; }
.dir-icon { flex: none; width: 1.2em; height: 1.2em; color: var(--arc-blue); }
.dir-sep { color: var(--ink-secondary); font-weight: 400; }
.chart-legend { display: flex; flex-wrap: wrap; gap: .25rem 1rem; margin: .25rem 0 .5rem; font-size: .9rem; }
.chart-legend span { display: inline-flex; align-items: center; gap: .35rem; }
.chart-legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* legend buttons show/hide a year in every chart of the section */
.legend-toggle {
    font: inherit; color: var(--ink);
    display: inline-flex; align-items: center; gap: .4rem;
    min-height: 36px; padding: .25rem .7rem;
    background: var(--surface); border: 1px solid #767b85; border-radius: 999px; cursor: pointer;
}
.legend-toggle[aria-pressed="false"] { color: var(--ink-secondary); text-decoration: line-through; border-style: dashed; }
.legend-toggle[aria-pressed="false"] i { background: transparent !important; outline: 2px solid #767b85; outline-offset: -2px; }
.chart-legend[role="group"]::before { content: "Show:"; align-self: center; color: var(--ink-secondary); }

.chart-tooltip {
    position: fixed; z-index: 3000; pointer-events: none;
    max-width: min(20rem, calc(100vw - 16px));
    background: var(--surface); color: var(--ink);
    border: 1px solid #c3c2b7; border-radius: 6px; padding: .5rem .65rem;
    box-shadow: 0 4px 14px rgb(0 0 0 / .14);
    font-size: .9rem; line-height: 1.4;
}
.chart-tooltip span { display: block; }
.tooltip-hint { color: var(--ink-secondary); font-style: italic; margin-top: .2rem; }

/* candlestick key */
.candle-key { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .5rem; font-size: .9rem; color: var(--ink-secondary); margin: 0 0 .25rem; }
.candle-key svg { flex: none; margin-left: .5rem; }

/* equity radar */
.chart-radar { height: 26rem; max-width: 36rem; margin: 0 auto; }
@media (max-width: 600px) { .chart-radar { height: 20rem; } }
.chart-legend i.dash-key { width: 22px; height: 0; border-radius: 0; border-top: 2px dashed var(--ink-secondary); }

.selection {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .75rem 1.5rem;
    margin: 1.25rem 0 0; padding: .9rem 1rem;
    background: #e3ebfb; border-radius: 8px;
    font-size: 1.1rem; text-align: center;
}
.selection[hidden] { display: none; }

.button {
    font: inherit; font-weight: 600; color: #fff; background: var(--arc-blue);
    border: 0; border-radius: 6px; min-height: 44px; padding: .4rem 1rem; cursor: pointer;
}
.button:hover { background: var(--arc-blue-dark); }
.button-primary {
    font-size: 1.15rem; padding: .65rem 1.75rem; min-height: 52px; border-radius: 999px;
    box-shadow: 0 3px 10px rgb(38 71 150 / .35);
    display: inline-flex; align-items: center; gap: .5rem;
}
.button-primary::after { content: "↓"; font-size: 1.2em; line-height: 1; }

/* back to top: desktop only (wide screen with a mouse or trackpad), never on tablets or phones */
.back-to-top { display: none; }
@media (min-width: 1200px) and (hover: hover) and (pointer: fine) {
    .back-to-top:not([hidden]) {
        display: inline-flex; align-items: center; gap: .4rem;
        position: fixed; right: 1.5rem; bottom: 1.5rem; z-index: 1000;
        font: inherit; font-weight: 600; color: #fff; background: var(--arc-blue);
        border: 0; border-radius: 999px; padding: .6rem 1.1rem; min-height: 44px; cursor: pointer;
        box-shadow: 0 3px 10px rgb(38 71 150 / .35);
    }
    .back-to-top:hover { background: var(--arc-blue-dark); }
    .back-to-top:focus-visible { outline-offset: 3px; }
}
.button-primary:focus-visible { outline-offset: 3px; }

/* road condition: a donut and a list of buttons; either highlights that class on the map */
.condition-pie { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 1.5rem; margin: .5rem 0 1.25rem; }
.cond-donut { flex: none; overflow: visible; }
.cond-wedge { stroke: #fff; stroke-width: 2; cursor: pointer; transition: opacity .12s ease; }
.cond-wedge.good, .cond-item.good { --seg: var(--good); }
.cond-wedge.fair, .cond-item.fair { --seg: var(--fair); }
.cond-wedge.poor, .cond-item.poor { --seg: var(--poor); }
.cond-wedge { fill: var(--seg); }
.cond-wedge:hover { opacity: .85; }
.condition-pie.has-active .cond-wedge:not(.active) { opacity: .3; }
.cond-wedge.active { stroke: var(--ink); stroke-width: 2.5; }
.cond-total, .cond-total-unit { pointer-events: none; }
.cond-total { font-size: 18px; font-weight: 700; fill: var(--ink); }
.cond-total-unit { font-size: 12px; fill: var(--ink-secondary); }
.cond-items { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.cond-item {
    display: flex; align-items: center; gap: .5rem;
    font: inherit; color: var(--ink); text-align: left;
    background: none; border: 1px solid transparent; border-radius: 6px; padding: .3rem .5rem; cursor: pointer;
}
.cond-item:hover { border-color: var(--hairline); }
.cond-item i { flex: none; width: 1rem; height: 1rem; border-radius: 3px; background: var(--seg); }
.cond-name { font-weight: 700; }
.cond-value { color: var(--ink-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.condition-pie.has-active .cond-item:not([aria-pressed="true"]) { opacity: .55; }
.cond-item[aria-pressed="true"] { border-color: var(--ink); }
.cond-item[aria-pressed="true"] .cond-name::after { content: " ✓"; }
.pothole-icon { border: 2.5px solid var(--ink); border-radius: 50%; background: transparent; box-sizing: border-box; }
.pothole-cluster {
    display: flex; align-items: center; justify-content: center;
    background: rgb(31 35 40 / .85); color: #fff; font-weight: 700; font-size: .85rem;
    border: 3px solid #fff; border-radius: 50%; box-shadow: 0 1px 4px rgb(0 0 0 / .35);
}
.pothole-key { width: .9rem !important; height: .9rem !important; border-radius: 50% !important; border: 2.5px solid var(--ink); background: transparent; }
/* same sizes as the map rings (13, 19, 26 px) */
.pothole-key.s2 { width: 13px !important; height: 13px !important; }
.pothole-key.s3 { width: 19px !important; height: 19px !important; }
.pothole-key.s4 { width: 26px !important; height: 26px !important; }
.pothole-key.grouped { width: 18px !important; height: 18px !important; background: rgb(31 35 40 / .85); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--ink); }
.check { display: inline-flex; align-items: center; gap: .5rem; min-height: 44px; }
.check input { width: 1.2rem; height: 1.2rem; }
.badge { display: inline-flex; align-items: center; gap: .3rem; font-weight: 600; }
.badge::before { content: ""; width: .75rem; height: .75rem; border-radius: 50%; background: currentColor; }
/* text is a darker shade of each class color (4.5:1 on white); the dot uses the map color */
.badge.good { color: #0a7a0a; } .badge.good::before { background: var(--good); }
.badge.fair { color: #a65400; } .badge.fair::before { background: var(--fair); }
.badge.poor { color: #c00000; } .badge.poor::before { background: var(--poor); }
.load-error { border: 2px solid #b42f2f; border-radius: 6px; padding: .75rem 1rem; margin-bottom: 1rem; background: var(--surface); }

.caution { border-left: 4px solid var(--ink-secondary); background: var(--plane); padding: .6rem 1rem; border-radius: 0 6px 6px 0; }
.road-map { height: 29rem; }
@media (max-width: 600px) { .road-map { height: 22rem; } }

@media (prefers-reduced-motion: reduce) {
    * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

@media print {
    .site-header, .site-footer, #picker, details summary { display: none; }
    details { display: block; }
    details > * { display: block; }
}
