:root {
  --bg: #f6f7f9; --card: #fff; --ink: #1b1f24; --muted: #5d6673; --line: #dde1e6;
  --accent: #1f5fae; --accent-ink: #fff;
  --ok: #1d7a46; --ok-bg: #e3f4e9; --warn: #8a5a00; --warn-bg: #fbf0d9; --bad: #b42318; --bad-bg: #fde8e6;
  --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121519; --card: #1b1f25; --ink: #e8ebef; --muted: #9aa4b1; --line: #2d333b;
    --accent: #5b9bea; --accent-ink: #0b1220;
    --ok: #6fd39a; --ok-bg: #173323; --warn: #f0c063; --warn-bg: #362a12; --bad: #ff8a80; --bad-bg: #3a1a18;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
h1 { font-size: 1.5rem; margin: 8px 0 12px; }
h2 { font-size: 1.1rem; margin: 22px 0 10px; }
.card h2 { margin-top: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.bad-text { color: var(--bad); }
.nowrap { white-space: nowrap; }

.top { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 600; display: flex; flex-direction: column; line-height: 1.2; }
.brand span { font-weight: 400; font-size: .8rem; color: var(--muted); }
nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
nav a { padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--ink); }
nav a.on { background: var(--accent); color: var(--accent-ink); }
.who { font-size: .9rem; color: var(--muted); }
main { max-width: 960px; margin: 0 auto; padding: 16px; }
main.narrow { max-width: 520px; }
.demo-bar { background: var(--warn-bg); color: var(--warn); text-align: center; padding: 6px 16px; font-size: .875rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 12px; }
.card.overdue { border-left: 5px solid var(--bad); }
.card.attention { border-left: 5px solid var(--warn); }
.card.out { border-left: 5px solid var(--accent); }
.card.back { border-left: 5px solid var(--ok); }
.card-head { display: flex; flex-wrap: wrap; gap: 6px 12px; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.line { color: var(--muted); }
.big { font-size: 1.1rem; }
details summary { cursor: pointer; color: var(--accent); margin: 6px 0; }
details.card summary { color: var(--ink); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 8px 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.today { display: flex; flex-wrap: wrap; gap: 6px 24px; padding: 10px 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.count { color: var(--muted); font-weight: 400; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .8rem; background: var(--line); color: var(--ink); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); font-weight: 600; }

.btn { font: inherit; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; min-height: 44px; text-align: left; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.big { width: 100%; text-align: center; font-size: 1.05rem; }
.link { font: inherit; background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-top: 8px; }
.row .grow { flex: 1; min-width: 180px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; align-items: start; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
input, select { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 44px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
legend { color: var(--muted); font-size: .9rem; }
.help { font-size: .8rem; }

table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; }
tr.gap td { background: var(--warn-bg); }
tr.inactive td { color: var(--muted); }
section.card { overflow-x: auto; }

.consent { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.consent label.check { align-items: flex-start; font-size: 1rem; }
.consent input[type=checkbox] { width: 22px; height: 22px; min-height: 0; margin: 1px 0 0; flex: none; }
.consent .help { margin: 0; }
.notice { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); }
.notice.ok { background: var(--ok-bg); border-color: var(--ok); }
.notice.warn { background: var(--warn-bg); border-color: var(--warn); }
.notice.warn strong { color: var(--warn); }
.notice.ok strong { color: var(--ok); }
footer.legal { text-align: center; padding: 16px 16px 28px; font-size: .875rem; color: var(--muted); }
.doc h2 { margin-top: 28px; }
.doc li { margin: 4px 0; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; max-width: calc(100% - 32px); z-index: 10; }
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 600px) {
  .top { padding: 8px 12px; }
  main { padding: 12px; }
  .facts { grid-template-columns: 1fr; gap: 0; }
  .facts dd { margin-bottom: 6px; }
}

/* cars editor */
fieldset.cars { display: block; grid-column: 1 / -1; }
fieldset.cars table { width: 100%; margin: 6px 0 8px; }
fieldset.cars td input:not([type="radio"]) { width: 100%; }

/* trip activity in a trip card */
details.trip-log { margin-top: 6px; }
.trip-log-list { margin: 6px 0 0; padding-left: 0; list-style: none; display: grid; gap: 3px; font-size: .9em; }
.trip-log-list .nowrap { display: inline-block; min-width: 5.5em; }
.btn.wide { width: 100%; justify-content: center; }

/* "Start tracking by hand": a button that opens the form below it */
details.start-hand { margin-top: 16px; }
details.start-hand > summary.btn { display: inline-flex; gap: 6px; align-items: center; list-style: none; margin: 0; }
details.start-hand > summary.btn::-webkit-details-marker { display: none; }
details.start-hand > summary.btn::before { content: "+"; font-weight: 700; }
details.start-hand[open] > summary.btn::before { content: "−"; }
details.start-hand > form { margin-top: 10px; }

/* message the forecaster, on a trip card */
details.trip-msg { margin-top: 6px; }
.msg-form { display: grid; gap: 8px; margin-top: 6px; }
.msg-form textarea { width: 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); resize: vertical; }
.msg-form .quick { display: flex; flex-wrap: wrap; gap: 6px; }
.msg-form .msg-send { align-items: center; gap: 12px; }
.msg-form .msg-send .btn { margin-left: auto; }
.btn.sm { min-height: 32px; padding: 5px 10px; font-size: .875rem; }

/* trip card: alert actions on top, the dispatcher's own update in a panel of its own */
.card-actions { margin: 8px 0 2px; }
.dispatch-update { margin-top: 10px; padding: 10px 12px; border-radius: 8px; border: 1px dashed var(--accent); background: color-mix(in srgb, var(--accent) 7%, transparent); }
.dispatch-update-head { font-size: .875rem; margin-bottom: 6px; }
.dispatch-update-head strong { text-transform: uppercase; letter-spacing: .04em; font-size: .75rem; color: var(--accent); margin-right: 6px; }
.dispatch-update-head span { color: var(--muted, #666); }
.dispatch-update .row { align-items: end; }

/* pop-up window */
dialog.modal { border: 1px solid var(--line); border-radius: 12px; padding: 16px; width: min(560px, calc(100vw - 32px)); background: var(--card); color: var(--ink); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog.modal::backdrop { background: rgba(0,0,0,.4); }
dialog.modal .modal-head { display: flex; justify-content: space-between; align-items: center; }
dialog.modal .modal-head h2 { margin: 0; font-size: 1.1rem; }
dialog.modal .modal-foot { justify-content: flex-end; }

/* Extend [30 min ▾]: button and amount joined as one control */
.extend { display: inline-flex; align-items: stretch; }
.extend .btn { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.extend select { border: 1px solid var(--line); border-left: 0; border-radius: 0 8px 8px 0; background: var(--card); color: var(--ink); font: inherit; padding: 0 8px; min-height: 44px; cursor: pointer; }

/* Phones: iOS Safari zooms in on any field under 16px and stays zoomed (cards then run off the side).
   Keep every field at 16px, and let nothing in a card force the page wider than the screen. */
input, select, textarea { font-size: 16px; max-width: 100%; }
.card, .dispatch-update, .today { min-width: 0; overflow-wrap: anywhere; }
.row > * { max-width: 100%; }
@media (max-width: 600px) {
  .dispatch-update .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: stretch; }
  .dispatch-update .row > label { grid-column: 1 / -1; }
  .dispatch-update .row > label select { width: 100%; }
  .dispatch-update .extend { width: 100%; }
  .dispatch-update .extend .btn { flex: 1; }
  .card-head .pill { white-space: normal; }
}

/* Menu: a row of links on wide screens, behind a ☰ button on phones */
.menu { display: contents; }
.menu-btn { display: none; }
@media (max-width: 720px) {
  .top { flex-wrap: wrap; justify-content: space-between; }
  .menu-btn { display: inline-flex; gap: 8px; align-items: center; font: inherit; font-size: 1rem; padding: 8px 12px; min-height: 44px;
    border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); cursor: pointer; }
  .menu-btn span { font-size: .9rem; color: var(--muted); }
  .menu { display: none; width: 100%; }
  .top.menu-open .menu { display: block; }
  .top.menu-open nav { flex-direction: column; gap: 2px; margin-top: 4px; }
  .top.menu-open nav a { padding: 12px 10px; }
  .top.menu-open .who { padding: 10px 10px 4px; border-top: 1px solid var(--line); margin-top: 6px; }
}
.confirm-facts { margin: 12px 0; }
@media (max-width: 720px) {
  .top .brand { flex: 1 1 0; min-width: 0; }
  .top .menu-btn { flex: none; }
}

/* Never let one element widen the page on phones (iOS Safari grows the whole layout to fit it). */
html, body { max-width: 100%; overflow-x: hidden; }
main, .top, .card, .today, details, dl, dd, form { min-width: 0; }
select { min-width: 0; }
@media (max-width: 600px) {
  .dispatch-update .row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .dispatch-update .row > * { min-width: 0; }
  .dispatch-update .btn, .extend .btn { overflow-wrap: normal; white-space: nowrap; }
  .dispatch-update .extend select { flex: none; padding: 0 6px; }
  .top .menu-btn span { max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
/* ?debugwidth: outline anything wider than the screen and list it at the bottom */
.debug-wide { outline: 2px solid red !important; }
#debug-width { position: fixed; left: 0; right: 0; bottom: 0; max-height: 40vh; overflow: auto; z-index: 99; background: #300; color: #fff; font: 12px/1.3 ui-monospace, monospace; padding: 6px 8px; white-space: pre-wrap; }
.msg-form .quick-pick { width: 100%; }
label textarea { font: inherit; font-size: 16px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; resize: vertical; }
