:root {
  /* ---------- Design tokens ---------- */
  --bg: #f4f6fa;
  --bg-2: #eceff5;
  --panel: #ffffff;
  --panel-2: #fafbfd;
  --line: #e2e6ee;
  --line-soft: #edf0f5;
  --text: #16202e;
  --text-2: #2c3646;
  --muted: #667085;
  --muted-2: #98a2b3;

  --brand: #0b3d91;
  --brand-2: #1656c9;
  --brand-soft: #eaf1ff;
  --on-brand: #ffffff;

  --ok: #14804a;
  --ok-bg: #e0f7ea;
  --ok-ink: #0d5c37;
  --warn: #9a6200;
  --warn-bg: #fef1d6;
  --warn-ink: #7a4d00;
  --bad: #b3261e;
  --bad-bg: #fbe4e2;
  --bad-ink: #8c1d17;
  --info: #175cd3;
  --info-bg: #e3edfd;
  --info-ink: #17458c;
  --neutral-bg: #eef1f6;
  --neutral-ink: #475467;

  --focus-ring: #a9c4f7;

  --radius: 14px;
  --radius-sm: 9px;
  --radius-lg: 18px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 6px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);

  --sp-1: 8px;
  --sp-2: 12px;
  --sp-3: 16px;
  --sp-4: 24px;
  --sp-5: 32px;
  --sp-6: 48px;

  /* Type scale */
  --fs-display: 24px;   /* page titles */
  --fs-title: 16px;     /* section titles / h2 */
  --fs-body: 14px;      /* default running text, table body */
  --fs-small: 13px;     /* secondary table text */
  --fs-meta: 12px;      /* metadata, timestamps, labels */
  --fs-micro: 11px;     /* pills / tags */
  --lh-body: 1.5;

  /* ---------- Enhance redesign additions (Task A) ---------- */
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, "SFMono-Regular", Menlo, monospace;

  --accent-cyan: oklch(0.72 0.17 200);
  --accent-amber: oklch(0.72 0.17 95);
  --accent-amber-bg: #fef3c7;
  --accent-amber-ink: #92400e;
  --accent-green-strong: #1a7f4b;
  --accent-blue-strong: #175cd3;

  --radius-xl: 20px;
  --radius-hero: 26px;
  --radius-pill: 999px;

  --warm-bg: #fbfaf7;
  --warm-muted: #8a8578;

  color-scheme: light;
}

/* ---------- Dark mode: system preference ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #10151f;
    --bg-2: #131a26;
    --panel: #171f2c;
    --panel-2: #1b2432;
    --line: #2a3546;
    --line-soft: #232d3d;
    --text: #eaeef5;
    --text-2: #cbd4e1;
    --muted: #93a0b4;
    --muted-2: #6c7a90;

    --brand: #4d7fe0;
    --brand-2: #7aa2ec;
    --brand-soft: #1c2c4a;
    --on-brand: #0a1220;

    --ok: #4ade95;
    --ok-bg: #123626;
    --ok-ink: #7cf0b3;
    --warn: #f2c14b;
    --warn-bg: #3a2c0c;
    --warn-ink: #f6d27a;
    --bad: #f2867d;
    --bad-bg: #3a1715;
    --bad-ink: #ffb0a8;
    --info: #7aaefb;
    --info-bg: #142a4a;
    --info-ink: #a9cbfd;
    --neutral-bg: #212b3a;
    --neutral-ink: #aab6c8;

    --focus-ring: #3a598f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 1px 6px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);

    --accent-amber-bg: #3a2c0c;
    --accent-amber-ink: #f6d27a;
    --warm-bg: #131a26;
    --warm-muted: #93a0b4;
  }
}

/* ---------- Dark mode: explicit manual override wins either direction ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #10151f;
  --bg-2: #131a26;
  --panel: #171f2c;
  --panel-2: #1b2432;
  --line: #2a3546;
  --line-soft: #232d3d;
  --text: #eaeef5;
  --text-2: #cbd4e1;
  --muted: #93a0b4;
  --muted-2: #6c7a90;

  --brand: #4d7fe0;
  --brand-2: #7aa2ec;
  --brand-soft: #1c2c4a;
  --on-brand: #0a1220;

  --ok: #4ade95;
  --ok-bg: #123626;
  --ok-ink: #7cf0b3;
  --warn: #f2c14b;
  --warn-bg: #3a2c0c;
  --warn-ink: #f6d27a;
  --bad: #f2867d;
  --bad-bg: #3a1715;
  --bad-ink: #ffb0a8;
  --info: #7aaefb;
  --info-bg: #142a4a;
  --info-ink: #a9cbfd;
  --neutral-bg: #212b3a;
  --neutral-ink: #aab6c8;

  --focus-ring: #3a598f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 1px 6px rgba(0, 0, 0, .3);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);

  --accent-amber-bg: #3a2c0c;
  --accent-amber-ink: #f6d27a;
  --warm-bg: #131a26;
  --warm-muted: #93a0b4;
}

:root[data-theme="light"] {
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font: var(--fs-body)/var(--lh-body) var(--font-sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
[x-cloak] { display: none !important; }
h1, h2, h3 { font-weight: 700; color: var(--text); }
:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

/* ---------- Legacy top bar (login page only now) ---------- */
.topbar { background: var(--brand); color: var(--on-brand); display: flex; align-items: center; gap: 16px; padding: 10px 18px; position: sticky; top: 0; z-index: 10; }
.topbar .title { font-weight: 700; font-size: var(--fs-title); }
.topbar .spacer { flex: 1; }
.topbar a, .topbar button.link { color: #dbe6ff; background: none; border: 0; cursor: pointer; font: inherit; }
.topbar a:hover, .topbar button.link:hover { color: #fff; }

.pill { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: var(--fs-micro); font-weight: 700; letter-spacing: .02em; text-transform: uppercase; }
.pill.demo { background: var(--warn-bg); color: var(--warn-ink); }
.pill.live { background: var(--ok-bg); color: var(--ok-ink); }
.pill.division { background: var(--brand-soft); color: var(--brand); }
.pill.disabled { background: var(--neutral-bg); color: var(--muted); }
.pill.warn { background: var(--warn-bg); color: var(--warn-ink); }

.row-inactive { opacity: .5; }

.conflicts-warn { margin: -4px 0 var(--sp-2); font-size: var(--fs-small); }
.conflicts-warn a { color: var(--warn-ink); font-weight: 700; }

.conflict-group { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--sp-2) var(--sp-3); margin-bottom: var(--sp-3); background: var(--panel); }
.conflict-group-head { display: flex; align-items: baseline; gap: var(--sp-2); margin-bottom: var(--sp-2); flex-wrap: wrap; }
.conflict-group .tablewrap { margin: 0; }

.source-tag { display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 4px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; background: var(--neutral-bg); color: var(--neutral-ink); }
.source-tag.live { background: var(--info-bg); color: var(--info-ink); }

/* ---------- Page shell ---------- */
.wrap { max-width: 1320px; margin: 0 auto; padding: var(--sp-4); }

.pagehead {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-4);
}
.pagehead h1 { margin: 0; font-size: var(--fs-display); font-weight: 700; letter-spacing: -.01em; }
.pagehead .meta { color: var(--muted); font-size: var(--fs-meta); text-align: right; }
.pagehead .meta b { color: var(--text); font-weight: 600; }
.pagehead .meta-row { display: flex; gap: var(--sp-1); flex-wrap: wrap; align-items: center; justify-content: flex-end; }

.row { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--sp-3); box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 var(--sp-2); font-size: var(--fs-title); font-weight: 700; }
.panel + .panel { margin-top: var(--sp-3); }
.muted { color: var(--muted); }
.small { font-size: var(--fs-small); }
.help { font-size: var(--fs-meta); color: var(--muted); margin: 4px 0 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

/* ---------- Forms ---------- */
input, select, textarea, button { font: inherit; }
input[type=text], input[type=password], input[type=number], input[type=url], input[type=search], select, textarea {
  width: 100%; height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel); color: var(--text);
}
textarea { height: auto; padding: 10px 12px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus-ring); outline-offset: 1px; border-color: var(--brand-2); }
label { display: block; font-size: var(--fs-meta); color: var(--muted); margin: var(--sp-2) 0 4px; font-weight: 600; }
input[type=checkbox] { width: auto; height: auto; }
label:has(input[type=checkbox]) { display: flex; align-items: center; gap: 6px; font-weight: 500; color: var(--text); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 42px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--brand); background: var(--brand); color: var(--on-brand);
  cursor: pointer; font-weight: 600; font-size: var(--fs-small); transition: background .12s ease, box-shadow .12s ease;
}
.btn:hover { background: var(--brand-2); border-color: var(--brand-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--panel); color: var(--brand); border-color: var(--line); }
.btn.secondary:hover { background: var(--brand-soft); border-color: var(--brand-2); color: var(--brand-2); }
.btn.danger { background: var(--panel); color: var(--bad); border-color: var(--bad); }
.btn.danger:hover { background: var(--bad-bg); }
.btn.sm { height: 32px; padding: 0 10px; font-size: var(--fs-meta); }

/* ---------- Search ---------- */
.search { position: relative; }
.search input {
  height: 48px; padding: 0 44px 0 44px; font-size: 15px; border-radius: var(--radius-sm);
  background-color: var(--panel);
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="%23667085" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="7"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>');
  background-repeat: no-repeat; background-position: 14px center;
}
.search .btn.secondary {
  position: absolute; right: 6px; top: 6px; height: 36px; padding: 0 12px;
}

/* ---------- Status pills ---------- */
.status { display: inline-block; padding: 3px 9px; border-radius: 6px; font-size: var(--fs-meta); font-weight: 700; white-space: nowrap; }
.status.new { background: var(--neutral-bg); color: var(--neutral-ink); }
.status.in-progress { background: var(--info-bg); color: var(--info-ink); }
.status.completed { background: var(--ok-bg); color: var(--ok-ink); }
.status.partially-completed { background: var(--warn-bg); color: var(--warn-ink); }
.status.incomplete, .status.damaged { background: var(--bad-bg); color: var(--bad-ink); }
.status.resolved { background: var(--info-bg); color: var(--info-ink); }
.status.cancelled { background: var(--neutral-bg); color: var(--muted); text-decoration: line-through; }

/* ---------- Cards (search results / stop detail) ---------- */
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--sp-3); background: var(--panel); box-shadow: var(--shadow); }
.card + .card { margin-top: var(--sp-2); }
.card .head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.card .name { font-weight: 700; font-size: var(--fs-title); }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 4px 10px; margin-top: var(--sp-2); font-size: var(--fs-small); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.eta { font-size: 18px; font-weight: 700; }
.eta.live { color: var(--info); }

/* ---------- Route cards ---------- */
.routes { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: var(--sp-3); }
.route { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; box-shadow: var(--shadow); }
.route .rhead { padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--line); background: var(--panel-2); }
.route .rhead .v { font-weight: 700; font-size: var(--fs-title); }
.route .rhead .d { color: var(--muted); font-size: var(--fs-meta); margin-top: 2px; }
.progress { height: 6px; background: var(--neutral-bg); border-radius: 3px; margin-top: var(--sp-2); overflow: hidden; display: flex; }
.progress > div { height: 100%; background: var(--ok); }
.progress.tri { display: flex; }
.progress.tri > .seg-done { background: var(--ok); }
.progress.tri > .seg-progress { background: var(--info); }
.progress.tri > .seg-pending { background: var(--muted-2); }

.stoplist { list-style: none; margin: 0; padding: 0; max-height: 380px; overflow: auto; }
.stoplist li { display: grid; grid-template-columns: 26px 1fr auto; gap: var(--sp-2); padding: 10px 14px; border-bottom: 1px solid var(--line-soft); cursor: pointer; align-items: center; }
.stoplist li:nth-child(even) { background: var(--panel-2); }
.stoplist li:hover { background: var(--brand-soft); }
.stoplist li.current { background: var(--brand-soft); }
.stoplist .pos {
  width: 24px; height: 24px; border-radius: 50%; background: var(--neutral-bg); color: var(--neutral-ink);
  font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex: none;
}
.stoplist .pos.done { background: var(--ok-bg); color: var(--ok-ink); }
.stoplist .pos.now { background: var(--info); color: #fff; }
.stoplist .c { overflow: hidden; }
.stoplist .c .n { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stoplist .c .a { color: var(--muted); font-size: var(--fs-meta); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stoplist .t { text-align: right; font-size: var(--fs-meta); white-space: nowrap; }

/* ---------- Notes / activity feed ---------- */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { padding: var(--sp-2) 0; border-bottom: 1px solid var(--line-soft); }
.feed li:last-child { border-bottom: none; }
.feed .ft { font-weight: 600; }
.feed .fm { font-size: var(--fs-meta); color: var(--muted); }
.feed .src { font-size: 10px; text-transform: uppercase; padding: 1px 6px; border-radius: 4px; background: var(--neutral-bg); color: var(--neutral-ink); margin-left: 6px; letter-spacing: .03em; }
.feed .src.user { background: var(--warn-bg); color: var(--warn-ink); }

/* ---------- Legacy in-page tabs (kept for any leftover pages) ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: var(--sp-3); }
.tabs button { background: none; border: 0; padding: 10px 14px; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--brand-2); border-bottom-color: var(--brand-2); }

/* ---------- Tables ---------- */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-small); }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: var(--fs-meta); text-transform: uppercase; letter-spacing: .04em; font-weight: 700; background: var(--panel-2); }
tbody tr:nth-child(even) { background: var(--panel-2); }
tbody tr:hover { background: var(--brand-soft); }
.tablewrap.sticky { max-height: 420px; overflow-y: auto; }
.tablewrap.sticky table thead th { position: sticky; top: 0; z-index: 1; }
.previewwrap { max-height: 280px; overflow-y: auto; }
.previewwrap table thead th { position: sticky; top: 0; z-index: 1; }
td select { min-width: 90px; }
td, th { font-variant-numeric: tabular-nums; }

/* ---------- Alerts ---------- */
.alert { padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-sm); margin: var(--sp-2) 0; font-size: var(--fs-small); border-left: 3px solid transparent; }
.alert.ok { background: var(--ok-bg); color: var(--ok-ink); border-left-color: var(--ok); }
.alert.bad { background: var(--bad-bg); color: var(--bad-ink); border-left-color: var(--bad); }
.alert.warn { background: var(--warn-bg); color: var(--warn-ink); border-left-color: var(--warn); }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 12px; z-index: 50; overflow: auto; }
.modal { background: var(--panel); border-radius: var(--radius); max-width: 640px; width: 100%; padding: var(--sp-4); box-shadow: var(--shadow-lg); }
.modal .x { float: right; background: none; border: 0; font-size: 20px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal .x:hover { color: var(--text); }

/* ---------- Stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--sp-3); margin-bottom: var(--sp-3); }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--sp-3); box-shadow: var(--shadow); }
.tile .n { font-size: 30px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile .l { color: var(--muted); font-size: var(--fs-meta); margin-top: 4px; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.tile.completed .n { color: var(--ok); }
.tile.in_progress .n { color: var(--info); }
.tile.problem .n { color: var(--bad); }
.tile.cancelled .n { color: var(--muted); }

/* ---------- Login ---------- */
body.loginpage { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.login { max-width: 380px; width: 100%; margin: 0 auto; padding: var(--sp-4); }
.login .logo { text-align: center; margin-bottom: var(--sp-4); }
.login .logo .t { font-size: var(--fs-display); font-weight: 700; color: var(--brand); }
.login .logo .tag { color: var(--muted); font-size: var(--fs-small); margin-top: 4px; }
.login .panel { padding: var(--sp-4); }
code.url { background: var(--neutral-bg); padding: 3px 6px; border-radius: 4px; font-size: var(--fs-meta); word-break: break-all; }

/* ---------- Ask page ---------- */
.ask-page {
  display: flex; flex-direction: column;
  height: 100vh; height: var(--ask-vh, 100vh);
  background: var(--bg);
}
.ask-header {
  flex: none; display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-2); flex-wrap: wrap; padding: var(--sp-2) var(--sp-4);
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.ask-header h1 { margin: 0; font-size: var(--fs-title); font-weight: 700; }
.ask-header-controls { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.ask-lang { width: auto; height: 34px; padding: 0 8px; font-size: var(--fs-meta); border-radius: var(--radius-sm); }
.ask-speak-toggle { display: flex; align-items: center; gap: 6px; margin: 0; font-size: var(--fs-meta); font-weight: 500; color: var(--muted); white-space: nowrap; }
.ask-speak-toggle input[type=checkbox] { width: 15px; height: 15px; }

.ask-messages {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: var(--sp-3) var(--sp-3) var(--sp-4);
  display: flex; flex-direction: column; gap: var(--sp-3);
}

.ask-empty { max-width: 560px; margin: var(--sp-4) auto 0; text-align: center; }
.ask-empty p { margin: 0 0 var(--sp-3); }

.ask-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.ask-chips.center { justify-content: center; }
.ask-followups { margin-top: 10px; }
.ask-chip {
  border: 1px solid var(--line); background: var(--panel); color: var(--brand-2);
  border-radius: 999px; padding: 0 14px; min-height: 40px; display: inline-flex; align-items: center;
  font-size: var(--fs-small); font-weight: 600; cursor: pointer; text-align: left;
}
.ask-chip:hover { background: var(--brand-soft); border-color: var(--brand-2); }

.ask-msg { display: flex; flex-direction: column; max-width: 84%; }
.ask-msg-user { align-self: flex-end; align-items: flex-end; }
.ask-msg-answer { align-self: flex-start; align-items: flex-start; width: 84%; }

.ask-bubble {
  padding: 10px 14px; border-radius: 16px; font-size: var(--fs-body); line-height: 1.45;
  white-space: pre-wrap; word-break: break-word; box-shadow: var(--shadow); max-width: 100%;
}
.ask-msg-user .ask-bubble { background: var(--brand); color: var(--on-brand); border-bottom-right-radius: 4px; }
.ask-msg-answer .ask-bubble { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.ask-bubble.ask-bubble-error { background: var(--bad-bg); color: var(--bad-ink); border-color: var(--bad-bg); }

.ask-thinking { display: inline-flex; gap: 5px; align-items: center; padding: 4px 2px; }
.ask-thinking span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); display: inline-block; animation: ask-bounce 1.2s infinite ease-in-out; }
.ask-thinking span:nth-child(2) { animation-delay: .15s; }
.ask-thinking span:nth-child(3) { animation-delay: .3s; }
@keyframes ask-bounce { 0%, 80%, 100% { transform: scale(.6); opacity: .5; } 40% { transform: scale(1); opacity: 1; } }

.ask-stops { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; width: 100%; }
.ask-stop-card {
  display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px 12px; text-decoration: none; color: var(--text);
}
.ask-stop-card:hover { border-color: var(--brand-2); background: var(--brand-soft); text-decoration: none; }
.ask-stop-main { flex: 1; min-width: 0; }
.ask-stop-name { font-weight: 700; font-size: var(--fs-small); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ask-stop-sub { font-size: var(--fs-meta); color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ask-stop-side { text-align: right; flex: none; }
.ask-stop-eta { font-size: var(--fs-meta); font-weight: 700; color: var(--text); margin-top: 4px; white-space: nowrap; }

.ask-composer {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: var(--sp-2) var(--sp-3);
  padding-bottom: calc(var(--sp-2) + env(safe-area-inset-bottom, 0px));
  background: var(--panel); border-top: 1px solid var(--line);
}
.ask-mic {
  flex: none; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel); color: var(--brand); display: flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0;
}
.ask-mic svg { width: 20px; height: 20px; }
.ask-mic:hover { background: var(--brand-soft); }
.ask-mic.listening { background: var(--bad); border-color: var(--bad); color: #fff; animation: ask-pulse 1.4s infinite; }
@keyframes ask-pulse {
  0% { box-shadow: 0 0 0 0 rgba(180, 35, 24, .4); }
  70% { box-shadow: 0 0 0 10px rgba(180, 35, 24, 0); }
  100% { box-shadow: 0 0 0 0 rgba(180, 35, 24, 0); }
}
.ask-input { flex: 1; min-width: 0; min-height: 44px; height: 44px; border-radius: 22px; padding: 0 16px; font-size: 15px; }
.ask-send { min-height: 44px; height: 44px; border-radius: 22px; padding: 0 20px; flex: none; }

@media (max-width: 720px) {
  .ask-header { padding: var(--sp-2) var(--sp-3); }
  .ask-header h1 { font-size: var(--fs-small); }
  .ask-msg, .ask-msg-answer { max-width: 94%; }
}

/* Sortable table headers (board: "My deliveries today"). */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--brand-2); }
th.sortable .sortcaret { margin-left: 4px; font-size: 10px; color: var(--brand-2); }

/* Map tab (§19). */
.map-wrap { max-width: none; padding: var(--sp-3); }
.map-mine-toggle { display: flex; align-items: center; gap: 6px; font-size: var(--fs-small); color: var(--muted); font-weight: 500; }
.map-mine-toggle input { width: auto; margin: 0; }
.map-panel { padding: 0; overflow: hidden; position: relative; }
.map-canvas { width: 100%; height: 70vh; min-height: 420px; background: var(--bg-2); }
.map-empty { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: var(--panel); padding: 10px 18px; border-radius: var(--radius-sm); box-shadow: var(--shadow); color: var(--muted); font-weight: 600; z-index: 500; pointer-events: none; }
.map-note { margin-top: 10px; }

/* §19.4 marker pins, truck badge and legend. */
.map-pin { display: block; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.35); }
.map-pin.done { background: var(--muted-2); }
.map-pin.next { background: var(--bad); }
.map-pin.upcoming { background: var(--ok); }

.map-truck-badge { display: flex; align-items: center; gap: 4px; }
.map-truck-badge-icon { width: 26px; height: 26px; border-radius: 8px; background: var(--brand); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; }
.map-truck-badge-icon svg { width: 16px; height: 16px; fill: #fff; }
.map-truck-badge-label { font-size: 11px; font-weight: 700; color: #fff; background: rgba(11,61,145,.9); padding: 1px 6px; border-radius: 6px; white-space: nowrap; box-shadow: 0 1px 3px rgba(0,0,0,.35); }

.map-legend { position: absolute; right: 10px; bottom: 10px; z-index: 600; background: var(--panel); color: var(--text); border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 8px 10px; font-size: var(--fs-meta); line-height: 1.7; }
.map-legend-row { display: flex; align-items: center; gap: 7px; }
.map-legend-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 2px solid #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); flex: none; }
.map-legend-dot.done { background: var(--muted-2); }
.map-legend-dot.next { background: var(--bad); }
.map-legend-dot.upcoming { background: var(--ok); }
.map-legend-truck { width: 16px; height: 16px; border-radius: 5px; background: var(--brand); display: flex; align-items: center; justify-content: center; flex: none; }
.map-legend-truck svg { width: 10px; height: 10px; fill: #fff; }

@media (max-width: 720px) {
  .map-canvas { height: 60vh; min-height: 320px; }
  .map-legend { font-size: 11px; padding: 6px 8px; }
}

/* A truck placed at its last completed delivery, not a live GPS fix. */
.map-truck-badge.derived { background: var(--muted-2); border-style: dashed; }

/* ---------- Loading skeletons ---------- */
.skeleton { position: relative; overflow: hidden; background: var(--neutral-bg); border-radius: var(--radius-sm); }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.35), transparent);
  animation: skeleton-sheen 1.4s infinite;
}
:root[data-theme="dark"] .skeleton::after { background: linear-gradient(90deg, transparent, rgba(255,255,255,.08), transparent); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .skeleton::after { background: linear-gradient(90deg, transparent, rgba(255,255,255,.08), transparent); }
}
@keyframes skeleton-sheen { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: var(--sp-5) var(--sp-3); color: var(--muted); }
.empty-state .empty-title { font-weight: 700; color: var(--text); font-size: var(--fs-title); margin-bottom: 4px; }

/* ---------- Mobile delivery cards (board, phones) ---------- */
.mobile-stops { display: none; }
@media (max-width: 720px) {
  .mine-table-desktop { display: none; }
  .mobile-stops { display: flex; flex-direction: column; gap: var(--sp-2); }
  .mstop { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); padding: var(--sp-3); }
  .mstop-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
  .mstop-name { font-weight: 700; font-size: var(--fs-body); }
  .mstop-sub { color: var(--muted); font-size: var(--fs-meta); margin-top: 2px; }
  .mstop-row { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: var(--fs-small); }
  .mstop-eta { font-weight: 700; }
}

/* ---------- Enhance redesign: shared keyframes (Task A) ---------- */
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,.45); } 70% { box-shadow: 0 0 0 9px rgba(34,197,94,0); } 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes slidein { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .hero-card, .hero-status-pill, .kpi-card, .stop-row-mobile, .route-card, .growbar,
  [style*="animation"] {
    animation: none !important;
  }
  .growbar { transition: none !important; }
}

/* ---------- Enhance redesign: hero card (mobile next-stop) ---------- */
.hero-card {
  position: relative;
  overflow: hidden;
  background: var(--brand);
  color: var(--on-brand);
  border-radius: var(--radius-hero);
  padding: var(--sp-4);
  box-shadow: var(--shadow-lg);
}
.hero-card::before {
  content: "";
  position: absolute;
  top: -60px;
  right: -60px;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: var(--accent-cyan);
  opacity: .16;
  pointer-events: none;
}
.hero-card > * { position: relative; z-index: 1; }

.hero-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: var(--fs-micro);
  font-weight: 700;
  color: rgba(255, 255, 255, .78);
}

.hero-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--radius-pill);
  padding: 3px 10px;
  font-size: var(--fs-micro);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  background: rgba(255, 255, 255, .14);
  color: #fff;
}
.hero-status-pill .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ok);
  animation: pulse 1.8s infinite;
}

/* ---------- Enhance redesign: ETA block (hero card, stop detail, desktop) ---------- */
.eta-block { display: flex; flex-direction: column; gap: 2px; }
.eta-block .eta-block-label {
  font-size: var(--fs-micro);
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  font-weight: 700;
}
.eta-block .eta-block-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.hero-card .eta-block .eta-block-label { color: rgba(255, 255, 255, .7); }
.hero-card .eta-block .eta-block-value { color: #fff; }

/* ---------- Enhance redesign: KPI strips ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-2); }
.kpi-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: var(--sp-3);
  box-shadow: var(--shadow);
  animation: fadeUp .3s ease both;
}
.kpi-card .kpi-n { font-size: 24px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-card .kpi-l { color: var(--muted); font-size: var(--fs-micro); text-transform: uppercase; letter-spacing: .04em; font-weight: 700; margin-top: 4px; }

.kpi-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-3); }
@media (max-width: 900px) { .kpi-grid-4 { grid-template-columns: repeat(2, 1fr); } }

/* ---------- Enhance redesign: mobile stop row ---------- */
.stop-row-mobile {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid transparent;
  border-radius: var(--radius);
  animation: fadeUp .3s ease both;
}
.stop-row-mobile.flagged { border-left-color: var(--accent-amber); }
.stop-row-mobile .stop-row-time { font-weight: 700; font-size: var(--fs-small); color: var(--muted); }
.stop-row-mobile .stop-row-card { min-width: 0; }

/* ---------- Enhance redesign: desktop route cards + progress bar ---------- */
.route-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: var(--sp-3);
  box-shadow: var(--shadow);
  animation: fadeUp .3s ease both;
}

.progress-3seg {
  display: flex;
  height: 8px;
  width: 100%;
  border-radius: var(--radius-pill);
  overflow: hidden;
  background: var(--neutral-bg);
  margin-top: var(--sp-2);
}
.progress-3seg .seg-done { background: var(--accent-green-strong); height: 100%; }
.progress-3seg .seg-active { background: var(--accent-blue-strong); height: 100%; }
.progress-3seg .seg-remaining { background: var(--neutral-bg); height: 100%; }
.progress-3seg .growbar { height: 100%; transition: width .5s ease; }

@media (prefers-reduced-motion: reduce) {
  .progress-3seg .growbar { transition: none; }
}
