/* ==========================================================================
   Road Monitor BG — UI v4
   All colours, radii, spacing and font sizes come from the tokens below.
   ========================================================================== */

/* ---------- Design tokens (dark = default) ---------- */
:root {
    color-scheme: dark;

    /* Surfaces */
    --bg: #0b0b0d;
    --s1: #141417;
    --s2: #1c1c21;
    --s3: #26262d;
    --border: #2e2e36;
    --border-strong: #3d3d47;

    /* Text (solid colours only, no opacity) */
    --text: #f2f2f5;
    --text-2: #b4b4bf;
    --text-3: #8a8a96;          /* only on bg / s1 / s2 (>= 4.5:1) */

    /* Accent */
    --accent: #4c8dff;          /* text / icons on dark surfaces */
    --accent-fill: #2a66d6;     /* filled buttons: white text 5.3:1 */
    --accent-fill-hover: #2459bd;
    --on-accent: #ffffff;
    --accent-tonal: #17233b;
    --accent-tonal-hover: #1d2d4b;
    --route-underlay: #0f2a5e;

    /* Status */
    --ok: #34c77b;
    --ok-bg: #0f271b;
    --warn: #f5b93d;
    --warn-bg: #2b220f;
    --danger: #ff6b6b;
    --danger-bg: #331618;
    --info: #5ac8fa;
    --info-bg: #0d2431;
    --on-status: #0b0b0d;

    /* Translucent layers (backgrounds only) */
    --appbar-bg: rgba(11, 11, 13, .82);
    --scrim: rgba(11, 11, 13, .8);
    --shadow: 0 8px 28px rgba(0, 0, 0, .45);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, .3);
    --pin-stroke: #0b0b0d;
    --pin-shadow: rgba(0, 0, 0, .45);

    /* Radii */
    --r-8: 8px;
    --r-12: 12px;
    --r-14: 14px;
    --r-16: 16px;
    --r-20: 20px;
    --r-pill: 999px;

    /* Spacing */
    --sp-4: 4px;
    --sp-8: 8px;
    --sp-12: 12px;
    --sp-16: 16px;
    --sp-20: 20px;
    --sp-24: 24px;
    --sp-32: 32px;

    /* Type scale */
    --fs-12: 12px;
    --fs-13: 13px;
    --fs-15: 15px;
    --fs-16: 16px;
    --fs-18: 18px;
    --fs-22: 22px;
    --fs-28: 28px;
    --fs-34: 34px;
    --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;

    /* Motion */
    --dur-fast: 150ms;
    --dur: 180ms;
    --dur-slow: 220ms;
    --ease: cubic-bezier(.2, .8, .2, 1);

    /* Layout */
    --appbar-h: 56px;
    --tabbar-h: 64px;
    --safe-t: env(safe-area-inset-top, 0px);
    --safe-r: env(safe-area-inset-right, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-l: env(safe-area-inset-left, 0px);
}

@media (prefers-color-scheme: light) {
    :root {
        color-scheme: light;
        --bg: #f5f5f7;
        --s1: #ffffff;
        --s2: #f0f0f3;
        --s3: #e7e7ec;
        --border: #d9d9e0;
        --border-strong: #c4c4ce;
        --text: #111114;
        --text-2: #45454f;
        --text-3: #5f5f6b;
        --accent: #1f5fd0;
        --accent-fill: #1f5fd0;
        --accent-fill-hover: #1a50b0;
        --on-accent: #ffffff;
        --accent-tonal: #e4ecfb;
        --accent-tonal-hover: #d6e2f8;
        --route-underlay: #0d2c66;
        --ok: #146c41;
        --ok-bg: #e2f3e9;
        --warn: #7f5300;
        --warn-bg: #fbf0d7;
        --danger: #b42318;
        --danger-bg: #fde8e6;
        --info: #0a6399;
        --info-bg: #e0eff9;
        --on-status: #ffffff;
        --appbar-bg: rgba(245, 245, 247, .85);
        --scrim: rgba(255, 255, 255, .88);
        --shadow: 0 8px 28px rgba(17, 17, 20, .14);
        --shadow-sm: 0 2px 8px rgba(17, 17, 20, .08);
        --pin-stroke: #ffffff;
    }
}

/* Semantic tone helpers: components read --tone / --tone-bg */
.tone-ok { --tone: var(--ok); --tone-bg: var(--ok-bg); }
.tone-warn { --tone: var(--warn); --tone-bg: var(--warn-bg); }
.tone-danger { --tone: var(--danger); --tone-bg: var(--danger-bg); }
.tone-info { --tone: var(--info); --tone-bg: var(--info-bg); }
.tone-accent { --tone: var(--accent); --tone-bg: var(--accent-tonal); }
.tone-neutral { --tone: var(--text-2); --tone-bg: var(--s2); }
/* P5: speed-feed traffic status (PLAN A.5 status_styles); unknown is grey, never green */
.ts-normal { --tone: #22c55e; --tone-bg: rgba(34, 197, 94, .14); }
.ts-busy { --tone: #eab308; --tone-bg: rgba(234, 179, 8, .16); }
.ts-slowdown { --tone: #f97316; --tone-bg: rgba(249, 115, 22, .16); }
.ts-likely_congestion { --tone: #ef4444; --tone-bg: rgba(239, 68, 68, .16); }
.ts-unknown { --tone: #94a3b8; --tone-bg: rgba(148, 163, 184, .18); }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-padding-top: calc(var(--appbar-h) + var(--safe-t) + var(--sp-16));
}
body {
    margin: 0;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: var(--fs-16);
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p, ul, dl, dd { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.num, .hero-duration, .hero-meta, .metric-value, .tr-big, .tr-rows dd, .leg-meta, .appbar-status, .st-dist {
    font-variant-numeric: tabular-nums;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.input:focus-visible { outline: none; }

.sr-only {
    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: var(--sp-16);
    top: -100px;
    z-index: 100;
    padding: var(--sp-12) var(--sp-16);
    border-radius: var(--r-12);
    background: var(--accent-fill);
    color: var(--on-accent);
    font-weight: 600;
    text-decoration: none;
}
.skip-link:focus { top: calc(var(--safe-t) + var(--sp-8)); }

/* ---------- Icons ---------- */
.i {
    width: 20px;
    height: 20px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: middle;
}
.i-sm { width: 16px; height: 16px; }
.i-lg { width: 24px; height: 24px; }
.i-xl { width: 28px; height: 28px; }

/* ---------- App bar ---------- */
.appbar {
    position: sticky;
    top: 0;
    z-index: 50;
    padding-top: var(--safe-t);
    background: var(--appbar-bg);
    -webkit-backdrop-filter: saturate(1.5) blur(18px);
    backdrop-filter: saturate(1.5) blur(18px);
    border-bottom: 1px solid var(--border);
}
.appbar-inner {
    display: flex;
    align-items: center;
    gap: var(--sp-12);
    height: var(--appbar-h);
    max-width: 640px;
    margin: 0 auto;
    padding: 0 calc(var(--sp-8) + var(--safe-r)) 0 calc(var(--sp-16) + var(--safe-l));
}
.brand-mark {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    flex: none;
    border-radius: var(--r-8);
    background: var(--accent-tonal);
    color: var(--accent);
}
.appbar-text { flex: 1; min-width: 0; }
.appbar-title {
    font-size: var(--fs-16);
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -.01em;
}
.appbar-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: var(--fs-12);
    color: var(--text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.status-dot {
    width: 6px;
    height: 6px;
    flex: none;
    border-radius: 50%;
    background: var(--tone);
}
.appbar-actions { display: flex; gap: var(--sp-4); }

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    flex: none;
    padding: 0;
    border: 0;
    border-radius: var(--r-12);
    background: none;
    color: var(--text-2);
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur-fast) var(--ease);
}
.icon-btn:hover { background: var(--s2); color: var(--text); }
.icon-btn:active { transform: scale(.94); }
.icon-btn[aria-pressed="true"] { color: var(--warn); }

.offline-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-8);
    padding: var(--sp-8) var(--sp-16);
    background: var(--warn-bg);
    color: var(--warn);
    font-size: var(--fs-13);
    font-weight: 600;
    border-top: 1px solid var(--border);
    animation: fade-in var(--dur) var(--ease);
}

/* P2: data freshness */
.src-status { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: var(--fs-12); color: var(--text-2); }
.src { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.src.tone-warn, .src.tone-danger { color: var(--tone); font-weight: 600; }
.stale-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-8);
    padding: var(--sp-8) var(--sp-16);
    background: var(--danger-bg);
    color: var(--danger);
    font-size: var(--fs-13);
    font-weight: 700;
    border-top: 1px solid var(--border);
}
.st-card.is-stale .metrics, .st-card.is-stale .chips { opacity: .55; filter: grayscale(1); }
.st-stale { color: var(--warn); font-weight: 600; }
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: var(--sp-16);
    background: rgba(0, 0, 0, .6);
}
.modal { width: 100%; max-width: 420px; padding: var(--sp-24); display: flex; flex-direction: column; gap: var(--sp-12); }
.modal-title { display: flex; align-items: center; gap: var(--sp-8); font-size: var(--fs-18); font-weight: 700; }
.modal-note { font-size: var(--fs-13); color: var(--text-2); }

/* ---------- Layout ---------- */
.layout {
    max-width: 640px;
    margin: 0 auto;
    padding: var(--sp-16) calc(var(--sp-16) + var(--safe-r)) calc(var(--tabbar-h) + var(--safe-b) + var(--sp-24)) calc(var(--sp-16) + var(--safe-l));
}
.main { min-width: 0; }
.map-pane { display: none; }

.tab-panel {
    display: flex;
    flex-direction: column;
    gap: var(--sp-12);
    animation: fade-in var(--dur) var(--ease);
}
.tab-panel:focus-visible { outline-offset: 4px; border-radius: var(--r-16); }
.results, .skeleton-wrap { display: flex; flex-direction: column; gap: var(--sp-12); }

/* ---------- Bottom tab bar (mobile) / segmented control (desktop) ---------- */
.tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding: 0 var(--safe-r) var(--safe-b) var(--safe-l);
    background: var(--appbar-bg);
    -webkit-backdrop-filter: saturate(1.5) blur(18px);
    backdrop-filter: saturate(1.5) blur(18px);
    border-top: 1px solid var(--border);
}
.tab {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--sp-4);
    min-height: var(--tabbar-h);
    padding: var(--sp-8) var(--sp-4);
    border: 0;
    background: none;
    color: var(--text-3);
    font-size: var(--fs-12);
    font-weight: 600;
    transition: color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.tab-ico {
    position: relative;
    display: grid;
    place-items: center;
    width: 56px;
    height: 30px;
    border-radius: var(--r-pill);
    transition: background-color var(--dur) var(--ease);
}
.tab:hover { color: var(--text-2); }
.tab[aria-selected="true"] { color: var(--accent); }
.tab[aria-selected="true"] .tab-ico { background: var(--accent-tonal); }
.tab-badge {
    position: absolute;
    top: -3px;
    right: 6px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: var(--r-pill);
    background: var(--tone);
    color: var(--on-status);
    font-size: var(--fs-12);
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* ---------- Cards ---------- */
.card {
    background: var(--s1);
    border: 1px solid var(--border);
    border-radius: var(--r-16);
    padding: var(--sp-16);
}
.card-title {
    display: flex;
    align-items: center;
    gap: var(--sp-8);
    font-size: var(--fs-13);
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: var(--sp-8);
}
.section-label {
    font-size: var(--fs-13);
    font-weight: 600;
    color: var(--text-2);
    margin: 0 0 var(--sp-8);
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-8);
    min-height: 44px;
    padding: 0 var(--sp-16);
    border: 1px solid transparent;
    border-radius: var(--r-12);
    font-size: var(--fs-15);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn-block { width: 100%; }
.btn-primary {
    min-height: 52px;
    border-radius: var(--r-14);
    background: var(--accent-fill);
    color: var(--on-accent);
    font-size: var(--fs-16);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-fill-hover); }
.btn-primary:disabled {
    background: var(--s3);
    color: var(--text-2);
    cursor: not-allowed;
}
.btn-tonal { background: var(--accent-tonal); color: var(--accent); }
.btn-tonal:hover { background: var(--accent-tonal-hover); }
.btn-secondary { background: var(--s2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--s3); }
.btn-text { background: none; color: var(--accent); padding: 0 var(--sp-12); }
.btn-text:hover { background: var(--accent-tonal); }

/* ---------- Favourites ---------- */
.favs {
    display: flex;
    gap: var(--sp-8);
    overflow-x: auto;
    margin: 0 calc(-1 * var(--sp-16));
    padding: 6px var(--sp-16);
    scrollbar-width: none;
    overscroll-behavior-x: contain;
}
.favs::-webkit-scrollbar { display: none; }
.fav-chip {
    display: inline-flex;
    align-items: center;
    flex: none;
    max-width: 85%;
    padding-right: 6px;
    background: var(--s1);
    border: 1px solid var(--border);
    border-radius: var(--r-pill);
}
.fav-load {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-8);
    min-width: 0;
    min-height: 44px;
    padding: 0 var(--sp-8) 0 var(--sp-12);
    border: 0;
    border-radius: var(--r-pill);
    background: none;
    color: var(--text);
    font-size: var(--fs-15);
    font-weight: 500;
}
.fav-load span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fav-star { color: var(--warn); }
.fav-remove {
    position: relative;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    flex: none;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--s2);
    color: var(--text-2);
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.fav-remove::before { content: ""; position: absolute; inset: -6px; border-radius: 50%; }
.fav-remove:hover { background: var(--danger-bg); color: var(--danger); }

/* ---------- Route form (timeline) ---------- */
.form-card { display: flex; flex-direction: column; gap: var(--sp-12); }
.timeline { display: flex; align-items: center; gap: var(--sp-8); }
.tl-rows {
    position: relative;
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: var(--sp-8);
}
.tl-rows::before {
    content: "";
    position: absolute;
    left: 11px;
    top: 24px;
    bottom: 24px;
    border-left: 2px dotted var(--border-strong);
}
.tl-stops { display: flex; flex-direction: column; gap: var(--sp-8); }
.tl-stops:empty { display: none; }
.tl-row {
    display: grid;
    grid-template-columns: 24px 1fr;
    align-items: start;
    column-gap: var(--sp-8);
}
.tl-stop { grid-template-columns: 24px 1fr auto; }
.tl-mark {
    position: relative;
    z-index: 1;
    display: grid;
    place-items: center;
    width: 24px;
    height: 48px;
}
.tl-mark::before { content: ""; display: block; border-radius: 50%; }
.tl-mark-start::before {
    width: 14px;
    height: 14px;
    border: 3px solid var(--accent);
    background: var(--s1);
    box-shadow: 0 0 0 3px var(--s1);
}
.tl-mark-stop::before {
    width: 8px;
    height: 8px;
    background: var(--text-2);
    box-shadow: 0 0 0 4px var(--s1);
}
.tl-mark-end { color: var(--accent); }
.tl-mark-end::before { display: none; }
.tl-mark-end .i { background: var(--s1); box-shadow: 0 0 0 3px var(--s1); border-radius: var(--r-8); }

.field { position: relative; min-width: 0; }
.input {
    display: block;
    width: 100%;
    height: 48px;
    padding: 0 var(--sp-12);
    background: var(--s2);
    border: 1px solid var(--border);
    border-radius: var(--r-12);
    color: var(--text);
    font-size: var(--fs-16);
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
    -webkit-appearance: none;
    appearance: none;
}
.input::placeholder { color: var(--text-3); }
.input:hover { border-color: var(--border-strong); }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tonal); outline: none; }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--danger-bg); }

.field-error {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    color: var(--danger);
    font-size: var(--fs-13);
    font-weight: 500;
    animation: fade-in var(--dur) var(--ease);
}
.form-hint { color: var(--text-2); font-size: var(--fs-13); text-align: center; }

.swap-btn {
    background: var(--s2);
    border: 1px solid var(--border);
    color: var(--text-2);
}
.swap-btn:hover { background: var(--s3); }
.swap-btn .i { transition: transform var(--dur-slow) var(--ease); }
.swap-btn.spin .i { transform: rotate(180deg); }

/* Autocomplete */
.ac-list {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 30;
    display: none;
    max-height: min(320px, 50vh);
    overflow-y: auto;
    margin: 0;
    padding: var(--sp-4);
    list-style: none;
    background: var(--s1);
    border: 1px solid var(--border);
    border-radius: var(--r-12);
    box-shadow: var(--shadow);
}
.ac-list.show { display: block; animation: pop-in var(--dur-fast) var(--ease); }
.ac-item {
    display: flex;
    align-items: center;
    gap: var(--sp-12);
    min-height: 44px;
    padding: 0 var(--sp-12);
    border-radius: var(--r-8);
    color: var(--text);
    font-size: var(--fs-16);
    cursor: pointer;
}
.ac-item .i { color: var(--text-3); }
.ac-item:hover, .ac-item[aria-selected="true"] { background: var(--s2); }
.ac-item mark { background: none; color: var(--accent); font-weight: 700; }

/* Collapsed route summary */
.route-summary {
    display: flex;
    align-items: center;
    gap: var(--sp-12);
    padding: var(--sp-8) var(--sp-8) var(--sp-8) var(--sp-16);
    animation: fade-in var(--dur) var(--ease);
}
.rs-icon { color: var(--accent); }
.rs-text {
    flex: 1;
    min-width: 0;
    font-size: var(--fs-15);
    font-weight: 600;
    line-height: 1.35;
    overflow-wrap: anywhere;
}
.rs-text span { display: block; color: var(--text-2); font-size: var(--fs-13); font-weight: 500; }

/* ---------- Skeleton ---------- */
.sk {
    background: linear-gradient(90deg, var(--s2) 25%, var(--s3) 50%, var(--s2) 75%);
    background-size: 200% 100%;
    border-radius: var(--r-8);
    animation: shimmer 1.3s linear infinite;
}
.sk-chip { width: 96px; height: 28px; border-radius: var(--r-pill); }
.sk-title { width: 58%; height: 40px; margin-top: var(--sp-16); }
.sk-line { width: 78%; height: 16px; margin-top: var(--sp-12); }
.sk-line.short { width: 44%; }
.sk-btn { height: 44px; margin-top: var(--sp-16); border-radius: var(--r-12); }
.sk-map { height: 300px; border: 0; padding: 0; border-radius: var(--r-16); }
.sk-row { height: 44px; margin: var(--sp-8) 0; }

/* ---------- Hero ---------- */
.hero { padding: var(--sp-20); }
.hero-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--sp-8);
}
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 28px;
    padding: 0 var(--sp-12) 0 var(--sp-8);
    border-radius: var(--r-pill);
    background: var(--tone-bg);
    color: var(--tone);
    font-size: var(--fs-13);
    font-weight: 700;
}
.badge-src {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 28px;
    padding: 0 var(--sp-12);
    border-radius: var(--r-pill);
    background: var(--s2);
    color: var(--text-2);
    font-size: var(--fs-12);
    font-weight: 600;
}
.badge-src.tone-warn { background: var(--tone-bg); color: var(--tone); }
.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ok);
    box-shadow: 0 0 0 3px var(--ok-bg);
    animation: pulse 2s var(--ease) infinite;
}
.hero-duration {
    margin-top: var(--sp-16);
    font-size: var(--fs-34);
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -.02em;
}
.hero-meta { margin-top: var(--sp-4); font-size: var(--fs-16); color: var(--text-2); }
.hero-facts {
    list-style: none;
    padding: var(--sp-16) 0 0;
    margin-top: var(--sp-16);
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: var(--sp-8);
}
.hero-facts li {
    display: grid;
    grid-template-columns: 20px 1fr;
    gap: var(--sp-12);
    font-size: var(--fs-15);
    color: var(--text);
}
.hero-facts li small { display: block; color: var(--text-2); font-size: var(--fs-13); }
.hero-facts .i { color: var(--tone); margin-top: 1px; }
.hero-actions { margin-top: var(--sp-16); display: flex; gap: var(--sp-8); }
.hero-foot { margin-top: var(--sp-12); font-size: var(--fs-12); color: var(--text-2); }

/* ---------- Map ---------- */
.map-card { padding: 0; overflow: hidden; }
.map-host { position: relative; height: 300px; isolation: isolate; z-index: 0; }
.route-map { position: absolute; inset: 0; background: var(--s2); }
/* P9: route = white casing + accent line; alternatives grey (P10) */
.leaflet-overlay-pane path.route-casing { stroke: #ffffff; }
.map-dark .leaflet-overlay-pane path.route-casing { stroke: rgba(255, 255, 255, .92); }
.leaflet-overlay-pane path.route-line { stroke: var(--accent-fill, var(--accent)); }
.leaflet-overlay-pane path.route-alt { stroke: #9aa3ae; }
.map-legend {
    position: absolute;
    top: var(--sp-8);
    left: var(--sp-8);
    right: 64px;
    z-index: 450;
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-4);
    pointer-events: none;
}
.lg-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px var(--sp-8);
    border-radius: 999px;
    background: var(--scrim);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: var(--text);
    font-size: var(--fs-12);
    font-weight: 500;
    box-shadow: var(--shadow-sm);
}
.lg-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--text-3)); box-shadow: 0 0 0 1.5px #fff; }
.lg-chip[data-st="normal"] { --c: #22c55e; }
.lg-chip[data-st="busy"] { --c: #eab308; }
.lg-chip[data-st="slowdown"] { --c: #f97316; }
.lg-chip[data-st="likely_congestion"] { --c: #ef4444; }
.lg-chip[data-st="unknown"] { --c: #94a3b8; }
.map-empty {
    position: absolute;
    left: 50%;
    bottom: var(--sp-32);
    z-index: 500;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: var(--sp-12);
    max-width: calc(100% - 48px);
    padding: var(--sp-12) var(--sp-16);
    border-radius: var(--r-16);
    background: var(--scrim);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: var(--fs-15);
    box-shadow: var(--shadow);
}
.map-empty .i { color: var(--accent); }

/* Leaflet theme overrides */
.leaflet-container { background: var(--s2); font-family: var(--font); font-size: var(--fs-13); }
.leaflet-control-attribution.leaflet-control {
    margin: 0;
    padding: 2px var(--sp-8);
    border-radius: var(--r-8) 0 0 0;
    background: var(--scrim);
    color: var(--text-2);
    font-size: var(--fs-12);
    line-height: 1.5;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}
.leaflet-control-attribution a { color: var(--text); }
.leaflet-touch .leaflet-bar, .leaflet-bar {
    border: 1px solid var(--border);
    border-radius: var(--r-12);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    background-clip: padding-box;
}
.leaflet-touch .leaflet-bar a, .leaflet-bar a {
    width: 44px;
    height: 44px;
    line-height: 44px;
    background: var(--scrim);
    color: var(--text);
    border-bottom: 1px solid var(--border);
    font-size: var(--fs-22);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    transition: background-color var(--dur) var(--ease);
}
.leaflet-touch .leaflet-bar a:first-child, .leaflet-bar a:first-child { border-radius: 0; }
.leaflet-touch .leaflet-bar a:last-child, .leaflet-bar a:last-child { border-radius: 0; border-bottom: 0; }
.leaflet-bar a:hover, .leaflet-bar a:focus { background: var(--s3); color: var(--text); }
.leaflet-bar a.leaflet-disabled { background: var(--s2); color: var(--text-3); }
.leaflet-popup-content-wrapper {
    background: var(--s1);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-12);
    box-shadow: var(--shadow);
}
.leaflet-popup-tip { background: var(--s1); box-shadow: none; }
.leaflet-popup-content { margin: var(--sp-12) var(--sp-16); font-size: var(--fs-13); line-height: 1.4; }
.leaflet-container a.leaflet-popup-close-button { color: var(--text-2); width: 32px; height: 32px; font-size: var(--fs-18); line-height: 30px; }
.leaflet-container a.leaflet-popup-close-button:hover { color: var(--text); }
.pop-title { font-weight: 700; font-size: var(--fs-15); }
.pop-meta { color: var(--text-2); margin-top: 2px; }
.pop-risk { color: var(--tone); font-weight: 600; margin-top: var(--sp-4); }

.pin-wrap, .hz-wrap { background: none; border: 0; }
.rpin { display: block; width: 100%; height: 100%; border-radius: 50%; box-sizing: border-box; box-shadow: 0 2px 4px var(--pin-shadow); }
.rpin-start { background: #fff; border: 6px solid var(--accent-fill, var(--accent)); }
.rpin-stop { background: #fff; border: 4px solid #475569; }
.rpin-end { background: var(--accent-fill, var(--accent)); border: 4px solid #fff; }
.leaflet-overlay-pane path.me-acc { fill: #2a66d6; fill-opacity: .14; stroke: #2a66d6; stroke-opacity: .4; }

/* P9: hazard markers (36 px SVG, white border + shadow) */
.hz-mk { position: relative; display: block; width: 36px; height: 36px; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .35)); cursor: pointer; }
.hz-shape { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.hz-shape path, .hz-shape circle { fill: var(--hz, #64748b); stroke: #fff; stroke-width: 2.5; stroke-linejoin: round; }
.hz-gl { position: absolute; left: 50%; top: 50%; width: 18px; height: 18px; margin: -9px 0 0 -9px; color: #fff; stroke: #fff; }
.hz-triangle .hz-gl { margin-top: -5px; width: 16px; height: 16px; margin-left: -8px; }
.hz-danger { --hz: #dc2626; }
.hz-warn { --hz: #d97706; }
.hz-info { --hz: #2563eb; }
.hz-neutral { --hz: #64748b; }
.hz-count {
    position: absolute; top: -6px; right: -8px; min-width: 18px; height: 18px; padding: 0 4px;
    border-radius: 9px; background: #111827; color: #fff; border: 2px solid #fff;
    font-size: 11px; font-weight: 700; line-height: 14px; text-align: center;
}

/* P9: map tools (fullscreen / locate / layers) */
.map-tools { position: absolute; right: var(--sp-12); bottom: 36px; z-index: 460; display: flex; flex-direction: column; align-items: flex-end; gap: var(--sp-8); }
.map-fab {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-width: 44px; height: 44px; padding: 0 var(--sp-12);
    border: 1px solid var(--border); border-radius: 22px;
    background: var(--s1); color: var(--text); font: inherit; font-size: var(--fs-13); font-weight: 600;
    box-shadow: var(--shadow-sm); cursor: pointer;
}
.map-fab:hover { background: var(--s2); }
.map-fab:focus-visible, .mm-pill:focus-visible, .mm-grab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.map-fab .i { width: 20px; height: 20px; }
#locateBtn, #layersBtn, #avgBtn, #mmBack { padding: 0; width: 44px; }
#avgBtn[aria-pressed="true"] { background: var(--accent-fill); color: var(--on-accent); border-color: var(--accent-fill); }
.layers-menu { position: absolute; right: 52px; bottom: 0; min-width: 210px; padding: var(--sp-8) var(--sp-12); margin: 0; }
.layer-opt { display: flex; align-items: center; gap: var(--sp-8); min-height: 40px; font-size: var(--fs-13); cursor: pointer; }
.layer-opt input { width: 18px; height: 18px; accent-color: var(--accent); }

/* P9: full-screen map mode + bottom sheet (peek / half / full) */
html.mm-open, html.mm-open body { overflow: hidden; }
.map-mode { position: fixed; inset: 0; z-index: 900; background: var(--bg); }
.map-mode[hidden] { display: none; }
.mm-stage, .mm-stage .map-host { position: absolute; inset: 0; height: auto; }
.mm-stage .map-tools { bottom: calc(100% - var(--mm-sheet-y, 100%) + var(--sp-12)); }
.map-mode[data-snap="full"] .map-tools { display: none; }
.mm-stage #mapFullBtn { display: none; }
@media (max-width: 480px) { .map-card #mapFullBtn { padding: 0; width: 44px; } .map-card .map-fab-txt { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; } }
.mm-stage .map-legend { top: calc(var(--safe-t) + 64px); right: var(--sp-12); }
.mm-stage .leaflet-top { top: calc(var(--safe-t) + 56px); }
.mm-top { position: absolute; left: 0; right: 0; top: 0; z-index: 470; display: flex; gap: var(--sp-8); padding: calc(var(--safe-t) + var(--sp-8)) var(--sp-12) 0; pointer-events: none; }
.mm-top > * { pointer-events: auto; }
.mm-pill {
    flex: 1; min-width: 0; display: inline-flex; align-items: center; gap: var(--sp-8); height: 44px; padding: 0 var(--sp-16);
    border: 1px solid var(--border); border-radius: 22px; background: var(--s1); color: var(--text);
    font: inherit; font-size: var(--fs-15); font-weight: 600; box-shadow: var(--shadow-sm); cursor: pointer; text-align: left;
}
.mm-pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mm-sheet {
    position: absolute; left: 0; right: 0; top: 0; bottom: 0; z-index: 480;
    display: flex; flex-direction: column;
    background: var(--s1); color: var(--text);
    border-radius: var(--r-16) var(--r-16) 0 0; box-shadow: 0 -4px 24px rgba(0, 0, 0, .25);
    transform: translate3d(0, 100%, 0); will-change: transform; touch-action: none;
}
.mm-sheet.mm-anim { transition: transform .28s cubic-bezier(.2, .8, .2, 1); }
.mm-grab { flex: none; display: flex; justify-content: center; padding: var(--sp-8) 0 var(--sp-4); cursor: grab; touch-action: none; }
.mm-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--text-3); }
.mm-peek { flex: none; padding: 0 var(--sp-16) var(--sp-8); }
.mm-eta { display: flex; align-items: baseline; gap: var(--sp-8); margin-bottom: var(--sp-8); }
.mm-eta strong { font-size: var(--fs-22); }
.mm-eta span { color: var(--text-2); font-size: var(--fs-13); }
.mm-half { flex: none; max-height: 40vh; overflow-y: auto; padding: 0 var(--sp-16); touch-action: pan-y; }
.mm-h { font-size: var(--fs-13); color: var(--text-2); font-weight: 600; margin: var(--sp-8) 0 var(--sp-4); text-transform: uppercase; letter-spacing: .04em; }
.mm-hz {
    display: flex; align-items: center; gap: var(--sp-12); width: 100%; padding: var(--sp-8) 0; min-height: 48px;
    border: 0; border-bottom: 1px solid var(--border); background: none; color: inherit; font: inherit; text-align: left;
}
button.mm-hz { cursor: pointer; }
.mm-hz .risk-ico { color: var(--tone); }
.mm-hz-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mm-hz-t { font-weight: 600; font-size: var(--fs-15); }
.mm-hz-d { color: var(--text-2); font-size: var(--fs-13); }
.mm-tabs { flex: none; display: none; gap: var(--sp-4); padding: var(--sp-8) var(--sp-12); border-bottom: 1px solid var(--border); overflow-x: auto; }
.mm-tab { flex: 1; min-height: 40px; padding: 0 var(--sp-8); border: 0; border-radius: var(--r-8); background: none; color: var(--text-2); font: inherit; font-size: var(--fs-13); font-weight: 600; cursor: pointer; white-space: nowrap; }
.mm-tab[aria-selected="true"] { background: var(--s3); color: var(--text); }
.mm-body { flex: 1; min-height: 0; overflow-y: auto; padding: var(--sp-12) var(--sp-16) calc(var(--safe-b, 0px) + var(--sp-24)); touch-action: pan-y; display: none; }
.map-mode[data-snap="peek"] .mm-half { display: none; }
.map-mode[data-snap="full"] .mm-half { display: none; }
.map-mode[data-snap="full"] .mm-tabs, .map-mode[data-snap="full"] .mm-body { display: flex; }
.map-mode[data-snap="full"] .mm-body { display: block; }
.mm-body > .tab-panel, .mm-body > .card { margin: 0; }
@media (prefers-reduced-motion: reduce) { .mm-sheet.mm-anim { transition: none; } }

/* ---------- Legs ---------- */
.legs-card { padding: var(--sp-12) var(--sp-16) var(--sp-4); }
.legs { list-style: none; padding: 0; }
.leg + .leg { border-top: 1px solid var(--border); }
.leg-head {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: var(--sp-12);
    width: 100%;
    min-height: 56px;
    padding: var(--sp-8) 0;
    border: 0;
    background: none;
    text-align: left;
    border-radius: var(--r-8);
}
.leg-num {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--tone-bg);
    color: var(--tone);
    font-size: var(--fs-13);
    font-weight: 700;
}
.leg-main { min-width: 0; display: flex; flex-direction: column; }
.leg-title { font-size: var(--fs-15); font-weight: 600; }
.leg-meta { font-size: var(--fs-13); color: var(--text-2); }
.leg-chev { color: var(--text-2); transition: transform var(--dur) var(--ease); }
.leg-head[aria-expanded="true"] .leg-chev { transform: rotate(180deg); }
.leg-body {
    display: flex;
    flex-direction: column;
    gap: var(--sp-8);
    padding: 0 0 var(--sp-16) 40px;
    animation: fade-in var(--dur) var(--ease);
}
.leg-note { display: flex; align-items: center; gap: var(--sp-8); color: var(--text-2); font-size: var(--fs-13); }
.leg-note .i { color: var(--tone, var(--text-2)); }

/* ---------- Risks ---------- */
.risk-summary { display: flex; flex-direction: column; gap: var(--sp-12); }
.risk-summary h2 { font-size: var(--fs-18); font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: var(--sp-8); }
.risk-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: var(--sp-8); }
.risk {
    display: grid;
    grid-template-columns: 40px 1fr auto;
    align-items: center;
    gap: var(--sp-12);
    padding: var(--sp-12);
    background: var(--s1);
    border: 1px solid var(--border);
    border-radius: var(--r-12);
}
.risk.compact { grid-template-columns: 32px 1fr auto; padding: var(--sp-8) var(--sp-12); background: var(--s2); border-color: transparent; }
.risk-ico {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: var(--r-12);
    background: var(--tone-bg);
    color: var(--tone);
}
.risk.compact .risk-ico { width: 32px; height: 32px; border-radius: var(--r-8); }
.risk-body { min-width: 0; }
.risk-station { font-size: var(--fs-15); font-weight: 600; }
.risk-detail { font-size: var(--fs-13); color: var(--text-2); }
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-4);
    min-height: 24px;
    padding: 0 var(--sp-8);
    border-radius: var(--r-pill);
    background: var(--tone-bg);
    color: var(--tone);
    font-size: var(--fs-12);
    font-weight: 700;
    white-space: nowrap;
}
.list-more { text-align: center; color: var(--text-2); font-size: var(--fs-13); padding: var(--sp-8); }

/* ---------- Weather ---------- */
.st-card { padding: var(--sp-16); }
.st-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-8); }
.st-name { font-size: var(--fs-16); font-weight: 600; }
.st-dist { font-size: var(--fs-13); color: var(--text-2); white-space: nowrap; }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-8); margin-top: var(--sp-12); }
.metric {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px var(--sp-12);
    background: var(--s2);
    border-radius: var(--r-12);
}
.metric-label { display: flex; align-items: center; gap: 6px; font-size: var(--fs-12); color: var(--text-2); }
.metric-value { font-size: var(--fs-18); font-weight: 600; }
.metric-value.is-empty { color: var(--text-2); }
.st-foot { display: flex; flex-wrap: wrap; gap: var(--sp-4) var(--sp-16); margin-top: var(--sp-12); font-size: var(--fs-13); color: var(--text-2); }
.st-foot span { display: inline-flex; align-items: center; gap: 6px; }
.st-card .chips { margin-top: var(--sp-12); }

/* ---------- Traffic ---------- */
.intro-card { display: flex; gap: var(--sp-12); align-items: flex-start; }
.intro-card .i { color: var(--accent); margin-top: 2px; }
.intro-card b { font-weight: 600; }
.intro-card p { font-size: var(--fs-15); }
.intro-card small { display: block; font-size: var(--fs-13); color: var(--text-2); margin-top: 2px; }
.tr-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-12); }
.tr-name { font-size: var(--fs-16); font-weight: 600; margin-bottom: 6px; }
.tr-big { text-align: right; font-size: var(--fs-22); font-weight: 700; line-height: 1.1; white-space: nowrap; }
.tr-unit { display: block; font-size: var(--fs-12); font-weight: 500; color: var(--text-2); }
.tr-speed { margin-top: 6px; font-size: var(--fs-13); font-weight: 600; color: var(--text); }
.loadbar {
    height: 8px;
    margin: var(--sp-12) 0;
    overflow: hidden;
    border-radius: var(--r-pill);
    background: var(--s3);
}
.loadbar > span {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: var(--tone);
    transition: width var(--dur-slow) var(--ease);
}
.loadbar > span[data-w="1"] { width: 10%; }
.loadbar > span[data-w="2"] { width: 20%; }
.loadbar > span[data-w="3"] { width: 30%; }
.loadbar > span[data-w="4"] { width: 40%; }
.loadbar > span[data-w="5"] { width: 50%; }
.loadbar > span[data-w="6"] { width: 60%; }
.loadbar > span[data-w="7"] { width: 70%; }
.loadbar > span[data-w="8"] { width: 80%; }
.loadbar > span[data-w="9"] { width: 90%; }
.loadbar > span[data-w="10"] { width: 100%; }
.tr-rows { display: grid; grid-template-columns: 1fr auto; gap: 6px var(--sp-12); font-size: var(--fs-13); }
.tr-rows dt { color: var(--text-2); }
.tr-rows dd { text-align: right; font-weight: 600; color: var(--text); }

/* ---------- Recommendation ---------- */
.reco-head { display: flex; align-items: center; gap: var(--sp-12); }
.reco-head h2 { font-size: var(--fs-16); font-weight: 700; }
.reco-ico {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: var(--r-8);
    background: var(--tone-bg);
    color: var(--tone);
}
.reco-list { list-style: none; padding: 0; margin-top: var(--sp-12); display: flex; flex-direction: column; gap: 10px; }
.reco-list li { display: grid; grid-template-columns: 20px 1fr; gap: var(--sp-12); font-size: var(--fs-15); }
.reco-list .i { color: var(--tone); margin-top: 1px; }
.reco-list small { display: block; color: var(--text-2); font-size: var(--fs-13); }

/* ---------- States ---------- */
.error-card { display: flex; flex-direction: column; gap: var(--sp-12); border-color: var(--danger); }
.ec-head { display: flex; align-items: center; gap: var(--sp-12); }
.ec-ico {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex: none;
    border-radius: var(--r-12);
    background: var(--danger-bg);
    color: var(--danger);
}
.ec-head h2 { font-size: var(--fs-16); font-weight: 700; }
.error-card p { color: var(--text-2); font-size: var(--fs-15); }
.ec-actions { display: flex; flex-wrap: wrap; gap: var(--sp-8); }
.ec-actions .btn-primary { min-height: 48px; }

.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-8);
    padding: var(--sp-32) var(--sp-24);
    text-align: center;
}
.empty-ico {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    margin-bottom: var(--sp-8);
    border-radius: 50%;
    background: var(--tone-bg, var(--s2));
    color: var(--tone, var(--text-2));
}
.empty h2 { font-size: var(--fs-18); font-weight: 700; }
.empty p { max-width: 32ch; color: var(--text-2); font-size: var(--fs-15); }
.empty .btn { margin-top: var(--sp-8); }

/* Toasts */
.toast-region {
    position: fixed;
    left: 50%;
    bottom: calc(var(--tabbar-h) + var(--safe-b) + var(--sp-12));
    z-index: 60;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-8);
    width: min(420px, calc(100% - 32px));
    transform: translateX(-50%);
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 100%;
    min-height: 48px;
    padding: var(--sp-12) var(--sp-16);
    border-radius: var(--r-14);
    background: var(--s3);
    border: 1px solid var(--border-strong);
    color: var(--text);
    font-size: var(--fs-15);
    font-weight: 500;
    box-shadow: var(--shadow);
    pointer-events: auto;
    animation: toast-in var(--dur-slow) var(--ease);
}
.toast .i { color: var(--tone); }
.toast.leaving { animation: toast-out var(--dur) var(--ease) forwards; }

/* ---------- Footer ---------- */
.footer {
    margin-top: var(--sp-24);
    text-align: center;
    color: var(--text-2);
    font-size: var(--fs-13);
}
.footer a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 44px;
    padding: 0 6px;
    color: var(--accent);
    font-weight: 600;
    text-decoration: none;
}
.footer a:hover { text-decoration: underline; }
.footer small { display: block; font-size: var(--fs-12); }

/* ---------- Motion ---------- */
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes pop-in { from { opacity: 0; transform: scale(.98); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 3px var(--ok-bg); } 50% { box-shadow: 0 0 0 6px var(--ok-bg); } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
    .sk, .live-dot { animation: none !important; }
}

/* ---------- Small phones ---------- */
@media (max-width: 370px) {
    .hero-duration { font-size: var(--fs-28); }
    .tab-ico { width: 48px; }
    .metric { padding: var(--sp-8) 10px; }
}

/* ---------- Landscape phones: compact ---------- */
@media (orientation: landscape) and (max-height: 500px) and (max-width: 899px) {
    :root { --appbar-h: 48px; --tabbar-h: 48px; }
    .layout { max-width: 720px; padding-top: var(--sp-12); }
    .appbar-inner { max-width: 720px; }
    .tab { flex-direction: row; gap: var(--sp-8); font-size: var(--fs-13); padding: 0 var(--sp-8); }
    .tab-ico { display: inline-flex; align-items: center; gap: var(--sp-4); width: auto; height: auto; background: none !important; }
    .tab[aria-selected="true"]::after {
        content: "";
        position: absolute;
        left: 25%;
        right: 25%;
        top: 0;
        height: 3px;
        border-radius: 0 0 3px 3px;
        background: var(--accent);
    }
    .tab-badge { position: static; order: 2; }
    .hero { padding: var(--sp-16); }
    .hero-duration { font-size: var(--fs-28); margin-top: var(--sp-12); }
    .map-host, .sk-map { height: 240px; }
    .btn-primary { min-height: 48px; }
    .empty { padding: var(--sp-16); }
    .empty-ico { width: 48px; height: 48px; }
}

/* ---------- Desktop: two columns ---------- */
@media (min-width: 900px) {
    :root { --appbar-h: 60px; }
    .appbar-inner { max-width: none; padding: 0 var(--sp-16) 0 var(--sp-24); }
    .appbar-title { font-size: var(--fs-18); }
    .layout {
        display: grid;
        grid-template-columns: 420px minmax(0, 1fr);
        max-width: none;
        padding: 0;
    }
    .main { padding: var(--sp-16) var(--sp-20) var(--sp-24); }
    .map-pane {
        display: block;
        position: sticky;
        top: calc(var(--appbar-h) + var(--safe-t));
        align-self: start;
        height: calc(100dvh - var(--appbar-h) - var(--safe-t));
        border-left: 1px solid var(--border);
    }
    .map-pane .map-host { height: 100%; }
    .map-card { display: none; }
    #mapFullBtn { display: none; }

    .tabbar {
        position: sticky;
        top: calc(var(--appbar-h) + var(--safe-t) + var(--sp-8));
        z-index: 20;
        margin-bottom: var(--sp-16);
        padding: var(--sp-4);
        background: var(--s1);
        border: 1px solid var(--border);
        border-radius: var(--r-12);
        box-shadow: 0 0 0 var(--sp-8) var(--bg);
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }
    .tab {
        flex-direction: row;
        gap: 6px;
        min-height: 44px;
        padding: 0 var(--sp-8);
        border-radius: var(--r-8);
        font-size: var(--fs-13);
        color: var(--text-2);
    }
    .tab:hover { color: var(--text); background: var(--s2); }
    .tab-ico { display: inline-flex; align-items: center; gap: var(--sp-4); width: auto; height: auto; background: none !important; }
    .tab-ico .i { width: 18px; height: 18px; }
    .tab[aria-selected="true"] { background: var(--s3); color: var(--text); }
    .tab[aria-selected="true"] .tab-ico { color: var(--accent); }
    .tab-badge { position: static; order: 2; }

    .toast-region { bottom: var(--sp-24); left: 210px; }
    .favs { margin: 0; padding: 6px 0; flex-wrap: wrap; overflow: visible; }
    .fav-chip { max-width: 100%; }
}

@media (min-width: 1280px) {
    .layout { grid-template-columns: 440px minmax(0, 1fr); }
    .toast-region { left: 220px; }
}

/* P8: hazards ordered by distance + trend notices + sparklines */
.hz-list { margin-top: var(--sp-12); }
.hz-list .risk-station { font-size: var(--fs-15); }
.hz-spark:empty { display: none; }
.hz-spark { display: block; margin-top: var(--sp-4); color: var(--tone, var(--text-2)); }
.hz-note { display: flex; align-items: center; gap: var(--sp-8); margin-top: var(--sp-12); font-size: var(--fs-13); color: var(--tone, var(--text-2)); }
.hz-foot { margin-top: var(--sp-8); font-size: var(--fs-13); color: var(--text-2); }
.spark { display: block; overflow: visible; }
.pop-spark { display: flex; align-items: center; gap: var(--sp-8); margin-top: var(--sp-8); color: var(--accent, var(--text-2)); }
.pop-spark span { color: var(--text-2); font-size: var(--fs-13); }

/* P9.3: average-speed sections (map lines, hazards hint, live tracker panel) */
.leaflet-overlay-pane path.avg-sec { stroke: #7c3aed; stroke-opacity: .55; stroke-dasharray: 2 10; stroke-linecap: round; }
.leaflet-overlay-pane path.avg-sec-on { stroke-opacity: .95; stroke-dasharray: none; }
.hz-avg { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-8); margin-top: var(--sp-12); font-size: var(--fs-13); color: var(--text-2); }
.hz-avg > span { flex: 1 1 180px; }
.hz-avg .btn { min-height: 40px; padding: 0 var(--sp-12); font-size: var(--fs-13); }
.avg-panel {
    position: fixed; left: 50%; top: calc(var(--appbar-h, 56px) + var(--safe-t) + var(--sp-8)); z-index: 950;
    width: min(420px, calc(100% - 24px)); transform: translateX(-50%);
    padding: var(--sp-12) var(--sp-16); margin: 0; box-shadow: var(--shadow);
}
.avg-panel[hidden] { display: none; }
html.mm-open .avg-panel { top: calc(var(--safe-t) + 64px); }
.avg-head { display: flex; align-items: center; gap: var(--sp-8); font-weight: 600; font-size: var(--fs-15); }
.avg-t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avg-x { width: 36px; height: 36px; flex: none; }
.avg-main { display: flex; align-items: baseline; gap: var(--sp-8); margin-top: 4px; color: var(--tone); }
.avg-num { font-size: 40px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.avg-unit { font-size: var(--fs-13); color: var(--text-2); }
.avg-lim { margin-left: auto; padding: 2px 10px; border: 3px solid #d92d20; border-radius: 999px; background: #fff; color: #111; font-weight: 700; font-size: var(--fs-15); }
.avg-meta { margin: 4px 0 0; font-size: var(--fs-13); color: var(--text-2); }
.avg-rest { color: var(--tone); font-weight: 600; }
.avg-note { display: flex; align-items: center; gap: 6px; margin: 4px 0 0; font-size: var(--fs-13); color: var(--tone); }
.avg-foot { margin: 4px 0 0; font-size: 12px; color: var(--text-3); }
