/*
  Batosathi design tokens (ADR-0010, ui-refresh phase 2). Light is the default; a dark theme
  follows the OS, and a manual choice in a cookie overrides both. The road vernacular stays:
  asphalt, enamel road signs and a painted yellow lane. Status colours follow DHM and mean status
  only, never decoration. Mukta is self-hosted (wwwroot/fonts/mukta, OFL).
*/
:root {
    color-scheme: light;
    --paper: #F7F8FA;
    --surface: #FFFFFF;
    --ink: #1F2A37;
    --ink-muted: #5B6774;
    --asphalt: #2E353B;
    --enamel: #1B6CE0;
    --enamel-dark: #1556B0;
    --lane: #F2B21B;
    --rule: #E4E8EC;
    --border: #E4E8EC;
    --white: #FFFFFF;
    --on-enamel: #FFFFFF;
    --header-ink: #E4E8E5;

    --status-green: #1F9D55;
    --status-yellow: #EAB308;
    --status-orange: #EA7A1B;
    --status-red: #D64545;

    /* Destructive actions: a darker red than the DHM status, so white text clears 4.5:1. */
    --danger: #B42318;
    --on-danger: #FFFFFF;

    /* Three radius tiers, not one. */
    --radius-s: 6px;
    --radius-m: 10px;
    --radius-l: 16px;
    --radius: var(--radius-m);

    --shadow-card: 0 1px 2px rgba(15, 23, 27, 0.06);
    --shadow-sheet: 0 -12px 32px rgba(15, 23, 27, 0.18);

    /* 1.25 ratio from a 15 px body. */
    --text-xs: 0.75rem;
    --text-s: 0.8125rem;
    --text-m: 0.9375rem;
    --text-l: 1.125rem;
    --text-xl: 1.375rem;
    --text-xxl: 1.75rem;
    --text-display: clamp(2.5rem, 7vw, 3.6rem);

    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 1rem;
    --space-4: 1.5rem;
    --space-5: 2.5rem;
    --space-6: 4rem;
    --space-7: 6rem;

    --measure: 40rem;
    --shell: 72rem;
    --font: Mukta, "Noto Sans Devanagari", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

:root[data-theme="dark"] {
    /* White on the dark theme's light blue is 2.6:1; the page ink is over 7:1. */
    color-scheme: dark;
    --paper: #0E1217;
    --surface: #161C23;
    --ink: #E8EDF2;
    --ink-muted: #9AA6B2;
    --asphalt: #1B2024;
    --enamel: #63A2FF;
    --enamel-dark: #8FBDFF;
    --on-enamel: #0E1217;
    --lane: #F5C43A;
    --rule: #232B34;
    --border: #232B34;
    /* A lighter red with dark ink, for the same 4.5:1 on the dark surface. */
    --danger: #E5484D;
    --on-danger: #0E1217;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sheet: 0 -12px 32px rgba(0, 0, 0, 0.5);
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --paper: #0E1217;
        --surface: #161C23;
        --ink: #E8EDF2;
        --ink-muted: #9AA6B2;
        --asphalt: #1B2024;
        --enamel: #63A2FF;
        --enamel-dark: #8FBDFF;
        --on-enamel: #0E1217;
        --lane: #F5C43A;
        --rule: #232B34;
        --border: #232B34;
        --danger: #E5484D;
        --on-danger: #0E1217;
        --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4);
        --shadow-sheet: 0 -12px 32px rgba(0, 0, 0, 0.5);
    }
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font);
    font-size: var(--text-m);
    line-height: 1.5;
}

h1, h2, legend { line-height: 1.2; font-weight: 700; }
h1 { font-size: var(--text-xl); margin: 0 0 var(--space-3); letter-spacing: -0.015em; }
h2 { font-size: var(--text-l); margin: 0 0 var(--space-2); }
h3 { font-size: var(--text-m); margin: 0 0 var(--space-1); }
p { margin: 0 0 var(--space-3); }

a { color: var(--enamel); text-underline-offset: 0.15em; }
a:hover { color: var(--enamel-dark); }

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

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

/* Icons from the Lucide sprite: stroke follows currentColor. */
.icon { width: 1.25rem; height: 1.25rem; flex: none; }
.icon-sm { width: 1rem; height: 1rem; flex: none; }

/*
  Shell: one width for header, page and footer. The header is an asphalt band with a painted lane
  line under it, the only road motif outside the watch page's strip.
*/

.shell {
    width: 100%;
    max-width: var(--shell);
    margin-inline: auto;
    padding-inline: var(--space-4);
}

.site-header {
    background: var(--asphalt);
    color: var(--white);
    border-bottom: 4px solid var(--asphalt);
    background-image: repeating-linear-gradient(90deg, var(--lane) 0 2.25rem, transparent 2.25rem 3.5rem);
    background-size: 100% 4px;
    background-repeat: no-repeat;
    background-position: bottom;
}

.site-header-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2) var(--space-4);
    padding-block: var(--space-2) calc(var(--space-2) + 4px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 2.75rem; /* 44 px tap target */
    color: var(--white);
    font-weight: 700;
    font-size: var(--text-l);
    letter-spacing: -0.01em;
    text-decoration: none;
}
.brand:hover { color: var(--white); }

/* A small road-sign plate: enamel blue with a white rim. */
.brand-mark {
    width: 1.35rem;
    height: 1.35rem;
    border: 2px solid var(--white);
    border-radius: 4px;
    background: var(--enamel);
    box-shadow: inset 0 -5px 0 var(--lane);
}

.site-nav { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); }
.site-nav form { margin: 0; }
.site-nav a, .site-nav .quiet-button { display: inline-flex; align-items: center; min-height: 2.75rem; color: var(--header-ink); font-weight: 500; text-decoration: none; }
.site-nav a:hover, .site-nav .quiet-button:hover { color: var(--white); text-decoration: underline; }
.site-nav a[aria-current="page"] { color: var(--white); box-shadow: 0 3px 0 var(--lane); }
.site-header :focus-visible { outline-color: var(--lane); }

main { flex: 1; padding-block: var(--space-4); }

/* The bottom tab bar: the phone's primary navigation. */
.tab-bar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    display: none;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0);
    z-index: 20;
}
.tab-bar ul { display: flex; margin: 0; padding: 0; list-style: none; }
.tab-bar li { flex: 1; }
.tab-bar a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    padding: 0.5rem 0.25rem 0.6rem;
    font-size: var(--text-xs);
    color: var(--ink-muted);
    text-decoration: none;
}
.tab-bar a[aria-current="page"] { color: var(--enamel); font-weight: 600; }
.tab-bar .icon { width: 1.4rem; height: 1.4rem; }

/* Controls that live in the header on desktop and move into the account page on a phone. */
.phone-only { display: none; }

@media (max-width: 40rem) {
    .tab-bar { display: block; }
    body { padding-bottom: 3.5rem; }
    .site-nav a[data-tab-hide] { display: none; }
    /* Signed in, the theme, language and sign-out move to the account page; the phone header keeps
       only the brand and the tab bar. Signed out they stay, so a visitor can still change them. */
    .account-controls { display: none; }
    .phone-only { display: block; }
}

.site-footer {
    padding-block: var(--space-4);
    border-top: 1px solid var(--rule);
    color: var(--ink-muted);
    font-size: var(--text-s);
}
.site-footer p { margin: 0; }
.site-footer-inner { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--space-2) var(--space-4); }
.site-footer .quiet-button { font-size: var(--text-s); }
.language-switch { margin: 0; }
.language-switch button { font-weight: 600; }
/* The toggle writes the other language in its own script. On an English page that one word must
   not fetch Mukta's 100 KB Devanagari slice: the system face has those four glyphs. */
.language-switch button:lang(ne) { font-family: "Noto Sans Devanagari", "Nirmala UI", system-ui, sans-serif; }
.theme-switch { margin: 0; }
.theme-switch button { display: inline-flex; align-items: center; gap: var(--space-1); font-weight: 600; }

.narrow { max-width: var(--measure); }
.narrow-text { max-width: var(--measure); }
.passkey-list { list-style: none; margin: var(--space-4) 0 0; padding: 0; display: grid; gap: var(--space-2); }
.passkey-list li { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding-block: var(--space-2); border-bottom: 1px solid var(--border); }
.passkey-list li:last-child { border-bottom: 0; }
.passkey-list form { margin: 0; }
.section-title { margin-top: var(--space-5); }
.aside-section { margin-top: var(--space-5); padding-top: var(--space-4); border-top: 1px solid var(--rule); }
/* Our "Continue with Google" button (ADR-0016), drawn to Google's brand: the four-colour G, the
   outline and the label. It stays white in the dark theme, as Google's own button does. */
.google-button {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 2.75rem;
    padding: var(--space-2) var(--space-4);
    background: #FFFFFF;
    border: 1px solid #747775;
    border-radius: var(--radius-m);
    color: #1F1F1F;
    font-weight: 500;
    cursor: pointer;
}
.google-button:hover { background: #F7F7F7; }
.google-button:disabled { cursor: wait; opacity: 0.55; }
.google-button .google-g { width: 1.25rem; height: 1.25rem; flex: none; }
/* Google's rendered button takes the same row, so nothing below moves when it swaps in. */
.google-holder { min-height: 2.75rem; margin-bottom: var(--space-2); }
/* The display above would otherwise beat the hidden attribute, leaving both buttons on screen. */
.google-button[hidden] { display: none; }
/* Until Google's own stylesheet arrives, its placeholder SVG has no size and fills the column. */
.google-holder svg { max-width: 1.25rem; max-height: 1.25rem; }

/* Signed-out home: one statement, then the three things that happen, in order. */
.intro { max-width: 46rem; padding-block: var(--space-4) var(--space-5); }
.intro h1 { font-size: 2.6rem; line-height: 1.1; margin-bottom: var(--space-3); }
.intro .lede { font-size: var(--text-l); }
.intro-steps {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
    gap: var(--space-4);
    margin: 0;
    padding: var(--space-4) 0 0;
    border-top: 6px solid var(--asphalt);
    list-style: none;
    counter-reset: step;
}
.intro-steps li { counter-increment: step; }
.intro-steps h2::before { content: counter(step) ". "; color: var(--ink-muted); }
.intro-steps p { color: var(--ink-muted); }

/* Buttons: one action colour. Primary is enamel fill, secondary is an outline on surface. */

.button, .secondary-button, .quiet-button, button {
    font: inherit;
    cursor: pointer;
    border-radius: var(--radius-m);
}
button:disabled, .button:disabled, .secondary-button:disabled { cursor: not-allowed; opacity: 0.55; }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 2.75rem;
    padding: var(--space-2) var(--space-4);
    border: 1px solid var(--enamel);
    background: var(--enamel);
    color: var(--on-enamel);
    font-weight: 600;
    text-decoration: none;
}
.button:hover { background: var(--enamel-dark); border-color: var(--enamel-dark); color: var(--on-enamel); }
.button .icon { stroke: var(--on-enamel); }

.secondary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 2.75rem;
    padding: var(--space-2) var(--space-4);
    text-decoration: none;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink);
    font-weight: 600;
}
.secondary-button:hover { border-color: var(--enamel); color: var(--enamel); }

.quiet-button {
    min-height: 2.75rem;
    padding: var(--space-1) var(--space-2);
    border: 0;
    background: none;
    color: var(--enamel);
    text-decoration: underline;
    text-underline-offset: 0.15em;
}

.danger-button { background: var(--danger); border-color: var(--danger); color: var(--on-danger); }
.danger-button:hover { background: var(--danger); border-color: var(--danger); color: var(--on-danger); filter: brightness(0.92); }
.danger-link { margin-top: var(--space-4); }
.danger-link a { color: var(--danger); }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin-top: var(--space-4); }

/* Messages */

.notice, .problem, .error-summary {
    padding: var(--space-2) var(--space-3);
    border-left: 6px solid var(--enamel);
    border-radius: var(--radius-s);
    background: var(--surface);
    box-shadow: var(--shadow-card);
}
.problem, .error-summary { border-left-color: var(--status-red); }
.error-summary ul { margin: 0; padding-left: var(--space-4); }
.error-summary h2 { font-size: var(--text-m); }

.field-error { display: block; color: var(--status-red); font-weight: 600; }
.field-error:empty { display: none; }

/* Cards: a surface with soft elevation, the page's unit of content. */
.card {
    background: var(--surface);
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-card);
    padding: var(--space-4);
}

/* Watch list: cards, the status as a small road-sign plate. */

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2) var(--space-3);
}

.empty { max-width: 34rem; padding: var(--space-4) 0; color: var(--ink-muted); text-align: center; }
.empty .icon { width: 3rem; height: 3rem; stroke: var(--enamel); margin-bottom: var(--space-2); }
.empty h2 { color: var(--ink); }

.watch-list { list-style: none; margin: var(--space-3) 0 0; padding: 0; display: grid; gap: var(--space-3); }

.watch-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    padding: var(--space-4);
    background: var(--surface);
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-card);
}
.watch-row.is-ended .watch-name { color: var(--ink-muted); }

.watch-name { font-weight: 600; font-size: var(--text-l); }
.watch-meta { display: block; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.watch-delete { font-size: var(--text-s); }

.status-plate {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    border: 1px solid var(--border);
    border-left-width: 6px;
    border-radius: var(--radius-s);
    background: var(--surface);
    color: var(--ink);
    font-size: var(--text-xs);
    font-weight: 600;
    white-space: nowrap;
}
.status-plate .dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; flex: none; }
.status-clear { border-left-color: var(--status-green); }
.status-clear .dot { background: var(--status-green); }
.status-watch { border-left-color: var(--status-yellow); }
.status-watch .dot { background: var(--status-yellow); }
.status-breach { border-left-color: var(--status-red); }
.status-breach .dot { background: var(--status-red); }
.status-unknown, .status-pending { border-left-color: var(--rule); color: var(--ink-muted); }
.status-unknown .dot, .status-pending .dot { background: var(--rule); }

.pager { display: flex; gap: var(--space-3); margin-top: var(--space-3); font-variant-numeric: tabular-nums; }

/* Sessions: a quiet ruled list. The current device is a small enamel plate, not a card grid. */

.session-list {
    list-style: none;
    margin: var(--space-2) 0 0;
    padding: 0;
    border-top: 1px solid var(--rule);
}
.session-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--rule);
}
.session-main { display: grid; gap: var(--space-1); min-width: 0; }
.session-device { font-weight: 600; overflow-wrap: anywhere; }
.session-current {
    justify-self: start;
    padding: 0 var(--space-2);
    border: 1px solid var(--enamel);
    border-radius: var(--radius-s);
    color: var(--enamel);
    font-size: var(--text-xs);
    font-weight: 600;
}
.session-meta { color: var(--ink-muted); font-size: var(--text-s); font-variant-numeric: tabular-nums; }
.session-row form { margin: 0; }
@media (max-width: 480px) {
    .session-row { grid-template-columns: 1fr; }
    .session-row form { justify-self: start; }
}

/* Feedback inbox (maintainer only) */

.filter-switch { display: flex; gap: var(--space-3); }
.filter-switch a { display: inline-flex; align-items: center; min-height: 2.75rem; }
.filter-switch a[aria-current="true"] { font-weight: 600; text-decoration: none; box-shadow: 0 3px 0 var(--lane); }
.feedback-list { list-style: none; margin: var(--space-3) 0 0; padding: 0; display: grid; gap: var(--space-3); }
.feedback-row {
    display: grid;
    gap: var(--space-2);
    padding: var(--space-4);
    background: var(--surface);
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-card);
    border-left: 6px solid transparent;
}
.feedback-row.is-unread { border-left-color: var(--status-yellow); }
.feedback-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-3); color: var(--ink-muted); font-size: var(--text-s); font-variant-numeric: tabular-nums; }
.feedback-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.feedback-row form { margin: 0; }

/* Form */

.watch-form fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.watch-form > fieldset { margin-top: var(--space-4); }
.watch-form > fieldset > legend { font-size: var(--text-l); margin-bottom: var(--space-1); }

.field { display: flex; flex-direction: column; gap: var(--space-1); margin-top: var(--space-3); }
.field label { font-weight: 600; }
/* Two short time fields side by side on wide screens, stacked on phones (ADR-0010). */
.field-pair { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.field-pair .field { flex: 1 1 11rem; margin-top: var(--space-2); }
.field-pair input[type="time"] { width: 100%; }
.hint { color: var(--ink-muted); font-size: var(--text-s); }

input[type="text"], input:not([type]), input[type="date"], input[type="time"], input[type="number"], input[type="email"], input[type="url"], select, textarea {
    width: 100%;
    max-width: 22rem;
    min-height: 2.75rem;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-m);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
}
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--enamel); }
input[type="number"] { max-width: 8rem; font-variant-numeric: tabular-nums; }
input[type="date"] { max-width: 12rem; }
input[type="time"] { max-width: 11rem; font-variant-numeric: tabular-nums; }
.input-validation-error { border-color: var(--status-red) !important; }

/* The legs as a road: a line with a stop for each leg, the one bold element of the form. */
.legs {
    list-style: none;
    margin: var(--space-3) 0;
    padding: 0 0 0 var(--space-4);
    border-left: 6px solid var(--asphalt);
}

.leg { position: relative; padding-bottom: var(--space-4); }
.leg:last-child { padding-bottom: var(--space-2); }
.leg::before {
    content: "";
    position: absolute;
    left: calc(-1 * var(--space-4) - 13px);
    top: 0.2rem;
    width: 20px;
    height: 20px;
    border: 4px solid var(--asphalt);
    border-radius: 50%;
    background: var(--paper);
}
.leg > fieldset > legend { font-size: var(--text-m); }

.leg-places, .leg-details, .limit-fields { display: flex; flex-wrap: wrap; gap: 0 var(--space-3); }
.leg-places .field, .leg-details .field { flex: 1 1 12rem; }
.leg-details .field-date { flex: 0 1 12rem; }
.leg .quiet-button { margin-top: var(--space-2); font-size: var(--text-s); }

@media (max-width: 30rem) {
    .watch-row { grid-template-columns: 1fr auto; }
    .watch-delete { grid-column: 1 / -1; }
    .legs { padding-left: var(--space-3); }
    .leg::before { left: calc(-1 * var(--space-3) - 13px); }
}

/* Watch form with its map (Y06). On a wide screen the map fills the viewport height beside a
   fixed-width form panel, and stays while the form scrolls. On a phone the map sits on top at
   about 55vh and the form is the sheet below it. */
.watch-layout.has-map {
    display: grid;
    grid-template-columns: minmax(0, 28rem) minmax(0, 1fr);
    gap: var(--space-4);
    align-items: start;
}

.map-panel {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    padding-top: var(--space-3);
}
.map-panel h2 { margin-top: 0; flex: none; }
.map-panel .hint { flex: none; }

.map {
    flex: 1;
    min-height: 12rem;
    margin-top: var(--space-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-l);
    background: var(--surface);
    overflow: hidden;
}

/* The field a map click fills: the same enamel as focus, so it reads as "this one". */
input.is-map-target { border-color: var(--enamel); box-shadow: inset 0 0 0 1px var(--enamel); }

/* The road route under a leg: a short asphalt stub off the legs' road line. */
.leg-route {
    margin-top: var(--space-2);
    padding-left: var(--space-3);
    border-left: 3px solid var(--rule);
}
.leg-route.is-routed { border-left-color: var(--asphalt); }
.leg-route p { margin: 0; }
.route-summary { font-weight: 600; font-variant-numeric: tabular-nums; }
.leg-route .secondary-button { margin-top: var(--space-1); }
.leg-route .htmx-request { opacity: 0.6; cursor: progress; }

@media (max-width: 64rem) {
    .watch-layout.has-map { display: flex; flex-direction: column; }
    .map-panel { position: static; height: auto; order: -1; padding-top: 0; }
    .map { height: 55vh; flex: none; border-radius: 0; border-width: 0 0 1px 0; }
}

/* Channels: the ways to add one sit side by side on wide screens. */
.channel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
    gap: var(--space-4) var(--space-5);
}
.channel-grid .channel-add { margin-top: 0; max-width: none; }
.channel-grid input { max-width: none; }

.channel-row { grid-template-columns: 1fr auto auto; }
.channel-hint { font-variant-numeric: tabular-nums; }
.channel-stopped { display: block; color: var(--status-red); }
.channel-add { margin-top: var(--space-4); max-width: 36rem; }
.channel-add h3 { margin-bottom: var(--space-1); font-size: var(--text-l); }

/* Watch page. The route strip is the one loud element: the rest stays quiet. */

.watch-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-2) var(--space-3);
}
.watch-head h1 { margin-bottom: 0; }
.watch-dates { margin: var(--space-1) 0 0; color: var(--ink-muted); font-variant-numeric: tabular-nums; }

/* The route as a road sign: towns as stops on an asphalt line, the leg under each gap. */
.route-line {
    display: flex;
    list-style: none;
    margin: var(--space-5) 0 var(--space-4);
    padding: 0;
    overflow-x: auto;
}
.route-stop {
    position: relative;
    flex: 1 0 8rem;
    padding-top: var(--space-4);
}
.route-stop:last-child { flex: 0 0 auto; }
.route-stop::before {
    content: "";
    position: absolute;
    top: 0.45rem;
    left: 0;
    right: 0;
    height: 6px;
    background: var(--asphalt);
}
.route-stop:last-child::before { display: none; }
.route-stop::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 1.1rem;
    height: 1.1rem;
    border: 4px solid var(--asphalt);
    border-radius: 50%;
    background: var(--paper);
}
.stop-name { display: block; font-weight: 700; font-size: var(--text-l); }
.stop-leg { display: block; color: var(--ink-muted); font-size: var(--text-s); font-variant-numeric: tabular-nums; }

.strip-section { margin-top: var(--space-4); }

.strip { width: 100%; border-collapse: separate; border-spacing: var(--space-2); margin-inline: calc(-1 * var(--space-2)); }
.strip th { text-align: left; font-weight: 600; font-size: var(--text-s); color: var(--ink-muted); vertical-align: bottom; }
.strip .strip-day { width: 7rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.strip tbody th { vertical-align: top; padding-top: var(--space-2); color: var(--ink); }
.strip td { vertical-align: top; padding: 0; }

/*
  A cell: a status tint behind ink text (AA contrast for every status) and a thick edge in the
  full DHM colour. Model-decided cells are hatched in that colour; official ones are solid (AC-5.2).
*/
.cell {
    --tone: var(--rule);
    --tint: var(--surface);
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-height: 4.5rem;
    padding: var(--space-2) var(--space-3);
    border: 1px solid color-mix(in srgb, var(--tone) 55%, var(--surface));
    border-left: 8px solid var(--tone);
    border-radius: var(--radius-s);
    background: var(--tint);
    color: var(--ink);
}
.cell.status-clear { --tone: var(--status-green); --tint: color-mix(in srgb, var(--status-green) 10%, var(--surface)); }
.cell.status-watch { --tone: var(--status-yellow); --tint: color-mix(in srgb, var(--status-yellow) 22%, var(--surface)); }
.cell.status-breach { --tone: var(--status-red); --tint: color-mix(in srgb, var(--status-red) 14%, var(--surface)); }
.cell.status-unknown { border-style: dashed; border-left-style: solid; background: var(--paper); color: var(--ink-muted); }
.cell.is-model { background: repeating-linear-gradient(135deg, var(--tint) 0 7px, var(--surface) 7px 13px); }
.cell-status { font-weight: 700; }
/* A cell DHM decided wears DHM's colour, so Orange on its map is orange here (after the status rules, same specificity). */
.cell.level-yellow { --tone: var(--status-yellow); --tint: color-mix(in srgb, var(--status-yellow) 22%, var(--surface)); }
.cell.level-orange { --tone: var(--status-orange); --tint: color-mix(in srgb, var(--status-orange) 18%, var(--surface)); }
.cell.level-red { --tone: var(--status-red); --tint: color-mix(in srgb, var(--status-red) 14%, var(--surface)); }
.cell-evidence { font-size: var(--text-s); color: var(--ink-muted); }
a.cell-evidence { text-decoration: underline; text-underline-offset: 2px; }
a.cell-evidence:hover { color: var(--ink); }

/* Dark status text needs more contrast on the light tints; theme ink is enough on dark tints. */
.cell.status-breach .cell-status { color: #8E1B1B; }
.cell.level-yellow .cell-status { color: #6B5600; }
.cell.level-orange .cell-status { color: #8A4A0F; }
.cell.level-red .cell-status { color: #8E1B1B; }
:root[data-theme="dark"] .cell .cell-status,
:root[data-theme="dark"] .cell.level-yellow .cell-status,
:root[data-theme="dark"] .cell.level-orange .cell-status,
:root[data-theme="dark"] .cell.level-red .cell-status { color: var(--ink); }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .cell .cell-status,
    :root:not([data-theme="light"]) .cell.level-yellow .cell-status,
    :root:not([data-theme="light"]) .cell.level-orange .cell-status,
    :root:not([data-theme="light"]) .cell.level-red .cell-status { color: var(--ink); }
}

/* A cell whose answer changed since the page loaded pulses once. */
@keyframes cell-pulse {
    0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--tone) 70%, transparent); }
    100% { box-shadow: 0 0 0 10px transparent; }
}
.cell.is-changed { animation: cell-pulse 1.2s ease-out 1; }
@media (prefers-reduced-motion: reduce) {
    .cell.is-changed { animation: none; outline: 3px solid var(--tone); outline-offset: 2px; }
}

/* The official and model detail inside a cell (AC-5.1); official stays before model (AC-5.2). */
.cell-official { display: flex; flex-direction: column; gap: 0.15rem; margin-top: var(--space-1); font-size: var(--text-s); }
.cell-official-label { font-weight: 700; color: var(--ink-muted); }
.cell-official.problem { color: var(--ink-muted); }
.district-list { margin: 0; }
.district-list ul { margin: 0; padding: 0 0 0 var(--space-3); list-style: none; }
.district-list li { margin: 0; display: flex; justify-content: space-between; gap: var(--space-3); max-width: 22rem; }
ul.district-list { padding: 0; list-style: none; }
.district-level { font-weight: 600; }
.district-level.level-green { font-weight: 400; color: var(--ink-muted); }
.district-list summary { display: inline-flex; align-items: baseline; gap: var(--space-2); cursor: pointer; }
.district-list summary::-webkit-details-marker { display: none; }
.district-list summary::before { content: "+"; width: 1em; text-align: center; color: var(--ink-muted); }
.district-list[open] summary::before { content: "−"; }
.district-worst { font-weight: 700; }
.district-worst.level-yellow { color: #6B5600; }
.district-worst.level-orange { color: #8A4A0F; }
.district-worst.level-red { color: #8E1B1B; }
.district-worst.level-green { color: var(--status-green); }
.district-count { color: var(--ink-muted); }
.cell-issued { color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.cell-model { color: var(--ink-muted); }
:root[data-theme="dark"] .district-worst { color: var(--ink); }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .district-worst { color: var(--ink); }
}

.strip-list { display: none; list-style: none; margin: 0; padding: 0; }
.strip-list li { margin-bottom: var(--space-3); }
.strip-list-head { display: flex; justify-content: space-between; gap: var(--space-2); margin: 0 0 var(--space-1); font-weight: 600; font-variant-numeric: tabular-nums; }

.provenance { display: grid; gap: var(--space-2); margin: var(--space-4) 0 var(--space-2); padding-top: var(--space-3); border-top: 1px solid var(--rule); font-size: var(--text-s); }
.provenance div { display: grid; grid-template-columns: 5.5rem 1fr; gap: var(--space-2); }
.provenance dt { font-weight: 700; }
.provenance dd { margin: 0; font-variant-numeric: tabular-nums; }

/* Phones: the route runs down the page and the strip becomes a list of the same cells. */
@media (max-width: 40rem) {
    .route-line { flex-direction: column; overflow: visible; margin-top: var(--space-4); }
    .route-stop { flex: none; padding: 0 0 var(--space-3) var(--space-5); }
    .route-stop::before { top: 0.6rem; bottom: -0.6rem; left: 0.45rem; right: auto; width: 6px; height: auto; }
    .route-stop::after { top: 0.2rem; }
    .strip { display: none; }
    .strip-list { display: block; }
    .provenance div { grid-template-columns: 1fr; gap: 0; }
}

@media (max-width: 40rem) {
    .shell { padding-inline: var(--space-3); }
    main { padding-block: var(--space-4); }
    .intro h1 { font-size: var(--text-xxl); }
    h1 { font-size: var(--text-l); }
}

/* Map labels: a road-sign plate, not the library's default bubble. */
.map-label .maplibregl-popup-content {
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-s);
    background: var(--asphalt);
    color: var(--white);
    font: 600 var(--text-s) var(--font);
    box-shadow: none;
}
.map-label .maplibregl-popup-tip { display: none; }

/* The map panel's head row and the phone full-screen toggle. */
.map-panel-head { display: flex; align-items: center; gap: var(--space-2); flex: none; }
.map-panel-head h2 { flex: 1; margin: 0; }
.map-expand, .map-close { display: none; }
@media (max-width: 64rem) {
    .map-expand { display: inline-flex; }
}
.map-panel.is-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 30;
    height: 100dvh;
    background: var(--paper);
    padding: var(--space-3);
}
.map-panel.is-fullscreen .map-close { display: inline-flex; }
.map-panel.is-fullscreen .map-expand { display: none; }
.map-panel.is-fullscreen .map { flex: 1; min-height: 0; margin: var(--space-2) 0 0; }
