:root {
  color-scheme: light dark;
  /* Corporate palette */
  --c-blue: #0077cd;
  --c-sky: #8bbff3;
  --c-navy: #004b8b;
  --c-leaf: #7dce73;
  --c-forest: #00694b;
  --c-black: #202621;
  --c-slate: #5a6675;
  --c-silver: #a2aab6;
  --c-mist: #d0d4e3;
  --c-yellow: #e4ea40;
  /* Corporate red (#e03c39) darkened slightly so white text on it stays readable. */
  --c-alarm: #c92f2c;

  --bg: #f3f4f8;
  --surface: #ffffff;
  --surface-2: #e6e8f0;
  --ink: var(--c-black);
  --muted: var(--c-slate);
  --line: var(--c-mist);
  --field: #7d8796;
  --brand: var(--c-blue);
  --brand-text: var(--c-navy);
  --on-brand: #ffffff;
  --select: var(--c-navy);
  --on-select: #ffffff;
  --go: var(--c-forest);
  --on-go: #ffffff;
  --good: var(--c-forest);
  --warn: #5c6000;
  --bad: var(--c-alarm);
  --warn-bg: var(--c-yellow);
  --on-warn-bg: var(--c-black);
  --hero-outbound: var(--c-navy);
  --hero-on_site: var(--c-black);
  --hero-returning: var(--c-forest);
  --hero-late: var(--c-alarm);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151a16;
    --surface: #202621;
    --surface-2: #2d352f;
    --ink: #f3f4f8;
    --muted: var(--c-silver);
    --line: #3b463f;
    --field: #768292;
    --brand: var(--c-sky);
    --brand-text: var(--c-sky);
    --on-brand: var(--c-black);
    --select: var(--c-sky);
    --on-select: var(--c-black);
    --go: var(--c-leaf);
    --on-go: var(--c-black);
    --good: var(--c-leaf);
    --warn: var(--c-yellow);
    --bad: #ff8f8c;
    --hero-on_site: #2d352f;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, p { margin: 0; }
h1 { font-size: 1.35rem; line-height: 1.2; }
h2 { font-size: 1.25rem; line-height: 1.25; }
a { color: inherit; }
.muted { color: var(--muted); font-size: .94rem; }
.small { font-size: .85rem; }
.eyebrow { font-size: .78rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }

.staff #app { max-width: 560px; margin: 0 auto; min-height: 100dvh; padding-bottom: env(safe-area-inset-bottom); }
.loading { padding: 40vh 16px; text-align: center; color: var(--muted); }
.page { padding: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }

/* Header */
.bar { display: flex; align-items: center; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; }
.bar.home { justify-content: space-between; }
.icon-btn {
  width: 44px; height: 44px; flex: none; border: 0; border-radius: 50%;
  background: var(--surface-2); color: var(--ink); font-size: 1.15rem; cursor: pointer;
}
.icon-btn.on-dark { background: rgba(255, 255, 255, .16); color: #fff; }

/* Forms */
label, .label, legend { display: block; font-weight: 600; font-size: .95rem; }
input, select, textarea {
  display: block; width: 100%; margin-top: 6px; min-height: 52px; padding: 12px 14px;
  border: 1.5px solid var(--field); border-radius: 12px; background: var(--surface); color: var(--ink);
  font: 400 1.05rem var(--font);
}
textarea { min-height: 90px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid var(--brand); outline-offset: 2px;
}
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 6px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg legend { grid-column: 1 / -1; }
.seg.three { grid-template-columns: 1fr 1fr 1fr; }
.seg label { position: relative; margin: 0; }
.seg input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.seg span {
  display: flex; align-items: center; justify-content: center; min-height: 52px; padding: 6px; text-align: center;
  border: 1.5px solid var(--field); border-radius: 12px; background: var(--surface); font-weight: 600;
}
.seg input:checked + span { background: var(--select); border-color: var(--select); color: var(--on-select); }
.seg input:focus-visible + span { outline: 3px solid var(--brand); outline-offset: 2px; }

.field { display: flex; flex-direction: column; gap: 8px; }
.leaving-from { margin: 0; font-weight: 600; }
.leaving-from .label { display: block; font-weight: 600; color: var(--muted); font-size: .9rem; }
.inspect-heading { margin: 12px 0 0; font-size: 1.05rem; }
.inspect-section { display: flex; flex-direction: column; }
.check-row { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.check-row .check-comment { grid-column: 1 / -1; }
.check-comment[hidden], [data-expired][hidden] { display: none; }
.yn { display: flex; gap: 6px; }
.yn label { position: relative; }
.yn input { position: absolute; inset: 0; margin: 0; opacity: 0; }
.yn span { display: inline-flex; align-items: center; justify-content: center; min-width: 58px; min-height: 44px; border: 1.5px solid var(--field); border-radius: 10px; background: var(--surface); font-weight: 600; cursor: pointer; }
.yn input:checked + span { background: var(--select); border-color: var(--select); color: var(--on-select); }
.yn input[value="no"]:checked + span { background: var(--bad); border-color: var(--bad); color: #fff; }
.yn input:focus-visible + span { outline: 2px solid var(--brand-text); outline-offset: 2px; }
fieldset.checks { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
fieldset.checks legend { font-weight: 600; margin-bottom: 4px; }
.inspect-details { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 8px 0 0; }
.inspect-details dt { color: var(--muted); }
.inspect-details dd { margin: 0; }
ul.inspect-flag, .inspect-all { margin: 4px 0 0; padding-left: 18px; }
.photo-pick { position: relative; overflow: hidden; }
.photo-pick input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.licence-preview { display: block; width: 100%; max-height: 320px; object-fit: contain; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.inspect-flag { margin: 4px 0 0; color: var(--bad); font-weight: 700; }
.inspect-summary p { margin: 4px 0 0; }
.chips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.chip {
  position: relative; display: flex; align-items: center; justify-content: center; min-height: 52px; padding: 6px;
  border: 1.5px solid var(--field); border-radius: 12px; background: var(--surface); color: var(--ink);
  font: 600 1rem var(--font); cursor: pointer;
}
.chip.on { background: var(--select); border-color: var(--select); color: var(--on-select); }
.chip-time { grid-column: 1 / -1; }
.custom-time { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.custom-time[hidden] { display: none; }
.custom-hint { grid-column: 1 / -1; margin: 0; }
details summary { min-height: 44px; display: flex; align-items: center; font-weight: 600; color: var(--brand-text); cursor: pointer; }
details .stack { padding-top: 8px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; width: 100%; min-height: 56px; padding: 12px 18px;
  border: 1.5px solid transparent; border-radius: 14px; font: 700 1.08rem var(--font); text-align: center; text-decoration: none; cursor: pointer;
}
.btn:disabled { opacity: .65; cursor: progress; }
.btn.primary { background: var(--brand); color: var(--on-brand); }
.btn.go { background: var(--go); color: var(--on-go); }
.btn.go.armed { background: var(--ink); color: var(--bg); }
.btn.ghost { background: transparent; border-color: var(--field); color: var(--ink); }
.btn.light { background: #fff; color: var(--c-alarm); }
.btn.outline-light { background: transparent; border-color: #fff; color: #fff; }
.btn.huge { min-height: 76px; font-size: 1.3rem; border-radius: 18px; }
.btn.small { width: auto; min-height: 44px; padding: 8px 14px; font-size: .95rem; border-radius: 10px; }
.actions { display: flex; flex-direction: column; gap: 10px; }
.dock {
  position: sticky; bottom: 0; margin: 0 -16px -16px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 78%, transparent);
}

/* Sign in */
.auth { display: flex; flex-direction: column; gap: 10px; padding: 12vh 20px 24px; }
.auth h1 { font-size: 2rem; }
.auth-options { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.signin-error { margin-top: 8px; padding: 12px 14px; border-radius: 12px; background: var(--c-alarm); color: #fff; font-weight: 600; }
.copy-value { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); font: 600 .88rem ui-monospace, Consolas, monospace; overflow-wrap: anywhere; user-select: all; }
.brand-mark img { display: block; border-radius: 18px; }

/* Trip hero */
.hero { padding: calc(10px + env(safe-area-inset-top)) 16px 20px; background: var(--hero-on_site); color: #fff; }
.hero.s-outbound { background: var(--hero-outbound); }
.hero.s-returning { background: var(--hero-returning); }
.hero.late { background: var(--hero-late); }
.hero-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.hero-kicker { font-size: 1rem; }
.hero-title { font-size: 2rem; line-height: 1.12; overflow-wrap: anywhere; }
.hero-due { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-top: 16px; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, .28); }
.hero-due strong { font-size: 1.3rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Journey rail */
.rail { list-style: none; margin: 8px 0 0; padding: 0; }
.rail li { position: relative; display: flex; justify-content: space-between; gap: 12px; padding: 0 0 18px 30px; color: var(--muted); }
.rail li:last-child { padding-bottom: 0; }
.rail li::before {
  content: ""; position: absolute; left: 3px; top: 6px; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--line); background: var(--bg); z-index: 1;
}
.rail li::after { content: ""; position: absolute; left: 9px; top: 12px; bottom: -6px; width: 2px; background: var(--line); }
.rail li:last-child::after { display: none; }
.rail li.done { color: var(--ink); }
.rail li.done::before { background: var(--good); border-color: var(--good); }
.rail li.done::after { background: var(--good); }
.rail li.current { color: var(--ink); font-weight: 700; }
.rail li.current::before { border-color: var(--brand); border-width: 4px; }
.rail li.skipped .rail-label { text-decoration: line-through; }
.rail time { font-variant-numeric: tabular-nums; flex: none; }

.gps { font-size: .9rem; font-weight: 600; }
.gps::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 8px; border-radius: 50%; background: currentColor; }
.gps.good { color: var(--good); }
.gps.warn { color: var(--warn); }
.gps.bad { color: var(--bad); }

.banner { padding: 10px 16px; font-size: .94rem; font-weight: 600; }
.banner.warn { background: var(--warn-bg); color: var(--on-warn-bg); }

.card { padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.tip { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.page > .tip, body > .tip { margin: 0; }
#app > .tip { margin: 0 16px 4px; }

/* SOS */
.sos-wrap { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; padding-top: 18px; border-top: 1px solid var(--line); }
.sos-btn {
  position: relative; overflow: hidden; width: 100%; min-height: 64px; border: 2px solid var(--c-alarm); border-radius: 16px;
  background: transparent; color: var(--bad); font: 800 1.1rem var(--font); cursor: pointer;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.sos-fill { position: absolute; inset: 0; background: var(--c-alarm); transform: scaleX(0); transform-origin: left; }
.sos-text { position: relative; }
.sos-btn.holding .sos-fill { transform: scaleX(1); transition: transform 2s linear; }
.sos-btn.holding { color: #fff; }
.sos-panel { display: flex; flex-direction: column; gap: 10px; padding: 16px; background: var(--c-alarm); color: #fff; }
.sos-panel .btn { flex: 1 1 200px; width: auto; }

/* Done */
.done-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; min-height: 100dvh; padding: 24px; text-align: center; }
.done-mark { display: grid; place-items: center; width: 104px; height: 104px; margin-bottom: 10px; border-radius: 50%; background: var(--go); color: var(--on-go); font-size: 3.4rem; font-weight: 800; }
.done-screen h1 { font-size: 2rem; }
.done-screen .btn { margin-top: 20px; max-width: 320px; }

/* Lists */
.list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.list > * {
  display: flex; justify-content: space-between; align-items: center; min-height: 52px; padding: 10px 14px; border: 0;
  border-bottom: 1px solid var(--line); background: none; color: var(--ink); font: 600 1rem var(--font); text-decoration: none; cursor: pointer;
}
.list > *:last-child { border-bottom: 0; }
.history { list-style: none; margin: 0; padding: 0; }
.history li { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.history li div { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.history li > .muted { flex: none; }

#toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 2000;
  max-width: 520px; margin: 0 auto; padding: 14px 16px; border-radius: 12px; background: var(--ink); color: var(--bg);
  font-weight: 600; opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .18s, transform .18s;
}
#toast.show { opacity: 1; transform: none; }
#toast.bad { background: var(--c-alarm); color: #fff; }
#toast.good { background: var(--c-forest); color: #fff; }
#toast.warn { background: var(--c-yellow); color: var(--c-black); }

@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
}

/* ---------- Manager dashboard ---------- */

.admin { font-size: 15px; }
.admin-top { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; padding: 10px 20px; background: var(--c-black); color: #fff; }
.admin-top strong { font-size: 1.1rem; }
.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.tabs a { padding: 10px 14px; border-radius: 8px; color: var(--c-mist); font-weight: 600; text-decoration: none; white-space: nowrap; }
.tabs a.on { background: var(--c-blue); color: #fff; }
.admin-top .who { display: flex; align-items: center; gap: 10px; color: var(--c-mist); font-size: .9rem; }
.admin-top .who button, .admin-top .who a { padding: 7px 10px; border: 1px solid var(--c-slate); border-radius: 8px; background: none; color: #fff; font: 600 .85rem var(--font); text-decoration: none; cursor: pointer; }
.admin-main { padding: 20px; max-width: 1500px; margin: 0 auto; }
.admin-main h2 { margin-bottom: 12px; }

.live { display: grid; grid-template-columns: minmax(340px, 440px) minmax(0, 1fr); gap: 16px; align-items: start; }
#map { height: calc(100dvh - 110px); min-height: 420px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface-2); position: sticky; top: 16px; z-index: 0; }
.summary { display: flex; gap: 22px; margin-bottom: 14px; }
.summary div { display: flex; flex-direction: column; }
.summary b { font-size: 1.7rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.summary .alarm b { color: var(--bad); }
.notice { margin-bottom: 12px; padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--on-warn-bg); font-weight: 600; }

.trip-card { display: block; width: 100%; margin-bottom: 10px; padding: 12px 14px; border: 1px solid var(--line); border-left: 5px solid var(--good); border-radius: 10px; background: var(--surface); color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.trip-card.selected { outline: 2px solid var(--ink); }
.trip-card.late { border-left-color: var(--c-yellow); }
.trip-card.overdue, .trip-card.escalated, .trip-card.sos { border-left-color: var(--c-alarm); }
.trip-card header { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.region-filter { display: block; margin-bottom: 12px; font-size: .85rem; }
.region-filter select { min-height: 44px; padding: 8px 10px; font-size: .95rem; }
.region-tag { display: inline-block; padding: 0 7px; border: 1px solid var(--line); border-radius: 999px; font-size: .78rem; font-weight: 600; }
.region-set { display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 10px 12px 12px; border: 1px solid var(--line); border-radius: var(--radius); }
.region-set legend { padding: 0 6px; font-weight: 700; }
.trip-card p { margin-top: 3px; }
.trip-card .foot { display: flex; justify-content: space-between; gap: 10px; margin-top: 6px; color: var(--muted); font-size: .88rem; }
.pill { flex: none; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); font-size: .78rem; font-weight: 700; white-space: nowrap; }
.pill.overdue, .pill.escalated, .pill.sos { background: var(--c-alarm); color: #fff; }
.pill.late { background: var(--c-yellow); color: var(--c-black); }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 10px; }

.map-pin { display: grid; place-items: center; width: 34px !important; height: 34px !important; margin: -17px 0 0 -17px !important; border: 3px solid #fff; border-radius: 50%; background: var(--c-navy); color: #fff; font: 700 12px var(--font); box-shadow: 0 1px 5px rgba(0, 0, 0, .5); }
.map-pin.late { background: var(--c-yellow); color: var(--c-black); }
.map-pin.overdue, .map-pin.escalated, .map-pin.sos { background: var(--c-alarm); }
.site-pin { width: 12px !important; height: 12px !important; margin: -6px 0 0 -6px !important; border: 2px solid #fff; border-radius: 3px; background: var(--c-slate); box-shadow: 0 1px 3px rgba(0, 0, 0, .5); }

.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 14px; }
.toolbar label { flex: 0 1 200px; font-size: .85rem; }
.toolbar input, .toolbar select { min-height: 44px; padding: 8px 10px; font-size: .95rem; }
.admin .btn { width: auto; min-height: 44px; padding: 8px 14px; font-size: .95rem; border-radius: 10px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
td .row { flex-wrap: nowrap; }
.link-btn { padding: 0; border: 0; background: none; color: var(--brand-text); font: 600 inherit var(--font); font-size: inherit; text-decoration: underline; cursor: pointer; }
.off { opacity: .55; }

.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; max-width: 1100px; }
.settings .card { display: flex; flex-direction: column; gap: 14px; }
.settings h3 { margin: 0; font-size: 1.05rem; }
.settings ol { margin: 0; padding-left: 20px; color: var(--muted); }
.settings input, .settings select, dialog input, dialog select, dialog textarea { min-height: 44px; padding: 8px 10px; font-size: .98rem; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

dialog { width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(10, 15, 20, .55); }
dialog form, dialog .stack { display: flex; flex-direction: column; gap: 14px; }
.secret { padding: 12px; border-radius: 10px; background: var(--surface-2); font: 700 1.15rem ui-monospace, Consolas, monospace; overflow-wrap: anywhere; user-select: all; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 58px 1fr auto; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.timeline a { color: var(--brand-text); font-weight: 600; }
.check { display: flex; align-items: center; gap: 10px; }
.check input { flex: none; width: 22px; height: 22px; min-height: 0; margin: 0; padding: 0; }
.timeline li:last-child { border-bottom: 0; }
.timeline time { color: var(--muted); font-variant-numeric: tabular-nums; }

@media (max-width: 860px) {
  .admin-main { padding: 16px; }
  .live { grid-template-columns: minmax(0, 1fr); }
  #map { position: static; height: 50dvh; min-height: 300px; order: -1; }
}
