:root {
    --bg: #f6f7f9;
    --fg: #1d2024;
    --muted: #6b7380;
    --line: #dfe3ea;
    --card-bg: #fff;
    --accent: #2453d4;
    --mod: #b58400;
    /* A hard error that is not a comparison finding — a failed job.
       Kept separate from the drift/missing scale on purpose. */
    --fail: #c0392b;
    --warn-bg: #fff7e0;
    /* "Present on only one side" — MISSING. Purple, and only purple:
       it is a different KIND of fact from a drift, not a worse one, so
       it gets its own hue rather than the strongest shade of red.
       Named for the concept, not for a side, so the standard is
       enforced by CSS rather than asserted in a comment. */
    --miss: #7a3fa8;
    --miss-bg: #ecdcf5;
    --miss-soft: #f7f0fb;
    --miss-line: #d3b3e6;
    /* Drift — a time difference on a stop that exists on BOTH sides.
       Severity by intensity: yellow small, red large. */
    --drift-lo: #fff1b8;
    --drift-lo-fg: #8a6500;
    --drift-hi: #ffd9d4;
    --drift-hi-fg: #a02619;
}
* { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0; background: var(--bg); color: var(--fg);
    font: 14px/1.45 -apple-system, "Segoe UI", system-ui, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 20px; background: #fff; border-bottom: 1px solid var(--line);
}
.topbar .brand a { font-weight: 600; color: var(--fg); }
.topbar nav { display: flex; gap: 16px; align-items: center; }
.topbar .who { color: var(--muted); }
.logout-form { margin: 0; padding: 0; }
.logout-form button {
    background: none; border: 0; padding: 0; margin: 0; cursor: pointer;
    color: var(--accent); font: inherit; text-decoration: none;
}
.logout-form button:hover { text-decoration: underline; }

/* Inline form-button used for destructive actions (e.g. delete-job
   in the recent-jobs table and carriers-page header). Matches the
   logout-form style: looks like an inline link, but a real <button>
   so the underlying POST stays CSRF-safe. */
.link-button {
    background: none; border: 0; padding: 0; margin: 0; cursor: pointer;
    color: var(--accent); font: inherit; text-decoration: none;
}
.link-button:hover { text-decoration: underline; }

main { padding: 24px; max-width: 1240px; margin: 0 auto; }

.card {
    background: var(--card-bg); border: 1px solid var(--line); border-radius: 6px;
    padding: 20px; margin-bottom: 18px;
}
.card.narrow { max-width: 380px; margin-inline: auto; }
.card h1, .card h2 { margin-top: 0; }
.hint { color: var(--muted); }
.error {
    background: #fde7e7; color: #882020; padding: 8px 12px; border-radius: 4px;
    margin-bottom: 10px;
}
.warn {
    background: var(--warn-bg); padding: 8px 12px; border-radius: 4px;
    margin-top: 10px;
}

form label { display: block; margin: 12px 0; }
form input[type="text"], form input[type="password"], form input { display: block; width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px; }
form input[type="file"] { padding: 4px 0; }
form select { display: block; width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px; background: #fff; font: inherit; }
.server-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .server-pick { grid-template-columns: 1fr; } }
button, .btn {
    display: inline-block; padding: 8px 14px; border: 0; border-radius: 4px;
    background: var(--accent); color: #fff; cursor: pointer; font-size: 14px;
}
button:hover, .btn:hover { filter: brightness(1.05); text-decoration: none; }
.btn-small { padding: 3px 8px; font-size: 12px; border-radius: 3px; }

/* Outcome banner for a completed action (Lost & Found push / clear).
   Green because it reports success; `.warn` next to it carries the
   caveats. `.lf-pickbar` lived here until 2026-08-12, styling the old
   date-picker form that the curated-list rewrite removed. */
.ok-banner {
    background: #e8f3ea; border-left: 3px solid #1c8a3a;
    padding: 8px 12px; border-radius: 4px; margin-top: 10px;
}
/* `.stop-name` and `.est` lived here until 2026-08-17, styling the naryad
   stop labels and the "~ estimated" marker in the schedule detail's
   from / to cells. Both went when that timetable became schedule-only —
   it now shows scheduled times for every рейс, so there is no measured
   row to tell them apart from. */

/* Registry number (реестр, naryad col 19). Half of the route's identity —
   the other half is the name — so it gets a monospace, slightly recessed
   treatment that reads as an identifier rather than a count. */
code.reestr {
    font-size: 12px; color: var(--muted);
    background: #f2f4f7; border-radius: 3px; padding: 1px 5px;
    white-space: nowrap;
}

/* Garage badge. The garage (naryad col 2) stopped being a drill-down
   level on 2026-08-02 — the oversight unit took its place — so it rides
   along as a compact label on route / bus / variant rows. Left-aligned
   and normal-weight (unlike the count badges, which are centered and
   bold) because it's an identifier to read, not a number to scan. */
.badge.garage {
    font-weight: 400; text-align: left; min-width: 0;
    max-width: 15em; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; vertical-align: bottom;
}

.summary-grid, .progress-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px; margin: 16px 0;
}
.progress-grid > div {
    background: #f0f3f7; border-radius: 4px; padding: 10px;
    display: flex; flex-direction: column;
}
.progress-grid .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.progress-grid .v { font-size: 22px; font-weight: 600; }

.progress-bar {
    width: 100%; height: 10px; background: #e0e6ee; border-radius: 5px;
    overflow: hidden; margin: 18px 0 8px 0;
}
.progress-fill {
    width: 5%; height: 100%; background: var(--accent);
    transition: width 0.6s ease;
}
.progress-fill.failed { background: var(--fail); }
.summary-grid > div {
    background: #f0f3f7; border-radius: 4px; padding: 10px;
    display: flex; flex-direction: column;
}
.summary-grid .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
/* A tile's value may be a short_uuid, which wraps in <code> — inherit the
   tile's own type so the uuid tiles don't render smaller and monospaced
   than their plain-text siblings in the same row. */
.summary-grid .v code { font: inherit; letter-spacing: inherit; }
.summary-grid .v { font-size: 22px; font-weight: 600; }
.summary-grid .v.mod { color: var(--mod); }

table.diff {
    width: 100%; border-collapse: collapse; font-family: ui-monospace, "Consolas", monospace; font-size: 12px;
}
table.diff th, table.diff td {
    border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top;
    word-break: break-word;
}
/* Missing rows read purple on both sides — same standard as table.orders. */
table.diff tr.only_a td,
table.diff tr.only_b td { background: var(--miss-bg); }
table.diff tr.mod    td { background: #fffaef; }

pre.textdiff {
    background: #0e1117; color: #e6edf3; padding: 14px; border-radius: 4px;
    overflow: auto; max-height: 70vh; font-size: 12px;
}

.topbar-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; margin: 0 0 14px 0; flex-wrap: wrap;
}
.breadcrumb {
    color: var(--muted); font-size: 13px;
    display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.breadcrumb a { color: var(--accent); }
.breadcrumb .here { color: var(--fg); font-weight: 600; }

.stop-filter { margin: 0; }
.stop-filter label { margin: 0; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.stop-filter select {
    padding: 4px 8px; border: 1px solid var(--line); border-radius: 4px;
    background: #fff; font-size: 13px;
}

table.hier, table.orders {
    width: 100%; border-collapse: collapse; font-size: 13px;
}
table.hier th, table.hier td,
table.orders th, table.orders td {
    border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left;
    vertical-align: top;
}
table.hier th, table.orders th { background: #f0f3f7; font-weight: 600; }
/* Row state follows the same standard as the badges inside it: green
   clean, amber drifting, purple something missing. The row used to be
   one red "has-diff" for both kinds, which contradicted its own purple
   Diffs cell. Missing outranks drift — a row with both reads purple. */
table.hier tr.ok > td:first-child { border-left: 3px solid #1c8a3a; }
table.hier tr.has-drift > td { background: #fffaf0; }
table.hier tr.has-drift > td:first-child {
    border-left: 3px solid var(--drift-lo-fg);
}
table.hier tr.has-miss > td { background: var(--miss-soft); }
table.hier tr.has-miss > td:first-child {
    border-left: 3px solid var(--miss);
}
table.hier td.desc { color: var(--muted); font-size: 12px; }
table.hier a { color: var(--fg); font-weight: 500; }
table.hier a:hover { color: var(--accent); }
table.hier a.more { color: var(--accent); font-weight: 400; }

.badge {
    display: inline-block; min-width: 22px; padding: 2px 8px; border-radius: 11px;
    font-size: 12px; font-weight: 600; text-align: center;
}
/* ── The colour standard ───────────────────────────────────────────────
     green   .badge.ok       no difference
     yellow  .badge.yellow / .drift-yellow   SMALL difference (1-min drift)
     red     .badge.red    / .drift-red      LARGE difference (>1-min drift)
     purple  .badge.miss   / .drift-only     one side is MISSING

   Two axes, not one scale. Drift is "the same run, at a different
   time" and its severity is the size of the gap — yellow then red. A
   diff is "this run exists on one side only", which is a different
   KIND of finding, so it gets its own hue rather than being red-but-
   more-so. A diff is therefore ALWAYS purple and never red, and drift
   is never purple.

   `.badge.miss` and `.badge.drift-only` share a selector so a rollup
   badge and the counts it rolls up cannot drift apart. `.badge.red` is
   kept for large drift only. */
.badge.miss,
.badge.drift-only { background: var(--miss); color: #fff; }
.badge.ok { background: #e3eee5; color: #1c8a3a; }
.badge.neutral { background: #e9ecf2; color: var(--muted); }
.badge.drift-yellow,
.badge.yellow { background: var(--drift-lo); color: var(--drift-lo-fg); }
.badge.red,
.badge.drift-red { background: var(--drift-hi); color: var(--drift-hi-fg); }

/* The per-side "only on A" / "only on B" pills in the bus list — the
   same missing-purple, outlined rather than filled so they sit quietly
   next to a plate. */
.badge.only_a,
.badge.only_b { background: var(--miss-soft); color: var(--miss);
                border: 1px solid var(--miss-line); }

/* Per-stop drift cells in route_detail — the same yellow/red scale as
   the badges, lightened for a whole table row. */
.bus-stops table.orders tr.drift-yellow > td { background: #fff8e0; }
.bus-stops table.orders tr.drift-red > td { background: #ffe3de; }
/* A stop on only one side is MISSING, not drifted — purple plus a left
   accent, so it never reads as "an even worse drift". Not scoped to
   .bus-stops: the generic rule is the one standard. */
table.orders tr.only_a > td,
table.orders tr.only_b > td { background: var(--miss-bg); }
table.orders tr.only_a > td:first-child,
table.orders tr.only_b > td:first-child {
    box-shadow: inset 3px 0 0 var(--miss);
}

/* Bus caption — `[route]{выход|смена}:rnis-id`. Weight and slant are
   load-bearing here: выход and смена are both small integers, so bold
   vs italic is the only thing telling them apart at a glance. */
.bus-caption { font-weight: 400; color: var(--muted); font-size: 15px; }
.bus-caption b { color: var(--fg); font-weight: 700; }
.bus-caption i { color: var(--fg); font-style: italic; }
.bus-caption code { font-size: 13px; }

/* Two-pane bus drilldown */
.bus-split {
    display: grid; grid-template-columns: 280px 1fr; gap: 16px;
    align-items: start;
}
@media (max-width: 800px) { .bus-split { grid-template-columns: 1fr; } }

.bus-list {
    background: var(--card-bg); border: 1px solid var(--line);
    border-radius: 6px; padding: 12px; max-height: 75vh; overflow-y: auto;
}
.bus-list .cp-filter { margin: 0 0 10px 0; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.bus-list .cp-toggle {
    display: inline-block; padding: 4px 10px; border-radius: 4px;
    font-size: 12px; font-weight: 500;
    text-decoration: none; border: 1px solid var(--line);
}
.bus-list .cp-toggle.on { background: #eef3fc; color: var(--accent); border-color: var(--accent); }
.bus-list .cp-toggle.off { background: #f7f9fc; color: var(--muted); }
.bus-list .cp-toggle:hover { text-decoration: none; filter: brightness(0.97); }
.bus-list h3 { margin: 0 0 8px 0; font-size: 14px; color: var(--muted); }
.bus-list ul { list-style: none; padding: 0; margin: 0; }
.bus-list li { border-bottom: 1px solid var(--line); }
.bus-list li:last-child { border-bottom: none; }
.bus-list li a {
    display: block; padding: 8px 10px; color: var(--fg);
    text-decoration: none; border-left: 3px solid transparent;
}
.bus-list li a:hover { background: #f7f9fc; text-decoration: none; }
.bus-list li.active a { background: #eef3fc; border-left-color: var(--accent); }
.bus-list li.has-yellow a { border-left-color: #ddb000; }
.bus-list li.has-red a { border-left-color: var(--drift-hi-fg); }
.bus-list li.active.has-yellow a { background: #fff8e0; }
.bus-list li.active.has-red a { background: #ffe9e4; }
.bus-list li.has-miss a { border-left-color: var(--miss); }
.bus-list li.active.has-miss a { background: var(--miss-soft); }
.bus-list .bus-label { font-weight: 600; font-size: 13px; }
.bus-list .bus-meta { font-size: 11px; margin-top: 2px; display: flex; justify-content: space-between; gap: 8px; align-items: flex-end; }
.bus-list .bus-plate-info { display: flex; flex-direction: column; gap: 1px; flex: 1; min-width: 0; }
.bus-list .bus-plate-info .bus-side { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bus-list .bus-plate-info code { font-size: 10px; color: var(--muted); background: #f0f3f7; padding: 0 4px; border-radius: 3px; }
.bus-list .bus-badges .badge { font-size: 10px; padding: 1px 6px; margin-left: 3px; }

.bus-stops {
    background: var(--card-bg); border: 1px solid var(--line);
    border-radius: 6px; padding: 16px; min-width: 0;
}
.bus-stops h3 { margin: 0 0 12px 0; }
.bus-stops table.orders { font-size: 12px; }

/* Day-of-week badges on schedule pages — render inline next to the turn
   heading so the operator can see at a glance "this is the Mon-Fri schedule"
   vs "this only runs on weekends" without expanding the row. */
.day-badge {
    display: inline-block; padding: 2px 8px; margin-left: 8px;
    font-size: 11px; font-weight: 600; border-radius: 11px;
    vertical-align: middle;
}
.day-badge.known { background: #d6e7ff; color: #1f4b8a; }
.day-badge.unknown { background: #e9ecf2; color: var(--muted); font-style: italic; }
.summary-grid .v.day-known { color: #1f4b8a; }
.summary-grid .v.day-unknown { color: var(--muted); font-style: italic; }

table.orders tr.time_diff > td { background: #fff7e0; }
/* only_a / only_b intentionally NOT restated here — the red rules up in
   the per-stop diff block cover every table.orders. These used to be
   pink-for-A / green-for-B, which is where the second colour standard
   came from: green reads as "fine" for what is a missing run. */
table.orders td.pulse { font-weight: 600; }
table.orders td.rkey { font-family: ui-monospace, "Consolas", monospace; font-size: 11px; color: var(--muted); }
