:root {
  --accent: #2c5ea8; --accent-ink: #ffffff; --accent-soft: #e8eef8;
  --bg: #f6f7f9; --surface: #ffffff; --ink: #1d1a1f; --muted: #5b6676; --line: #dfe3ea;
  --ok: #17803d; --ok-soft: #e6f4ea; --warn: #9a5b00; --warn-soft: #fdf3e1; --bad: #b42318; --bad-soft: #fdecea;
  --radius: 12px; --tap: 48px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); line-height: 1.45;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11151c; --surface: #1a2029; --ink: #e8ecf2; --muted: #9aa6b6; --line: #2c3542;
    --accent: #7aa5ec; --accent-ink: #0f1a2c; --accent-soft: #1d2a40; --ok-soft: #13301e; --warn-soft: #33270f; --bad-soft: #3a1714; --ok: #5cc27f; --warn: #e2a540; --bad: #f2786d; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
header.top { background: var(--surface); border-bottom: 1px solid var(--line); padding: 12px 16px; display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 5; }
header.top .brand { font-weight: 700; color: var(--accent); font-size: 1.1rem; text-decoration: none; }
header.top nav { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; }
header.top nav a { padding: 8px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; font-size: .95rem; }
header.top nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
main { max-width: 760px; margin: 0 auto; padding: 16px; }
main.wide { max-width: 1180px; }
h1 { font-size: 1.5rem; margin: 8px 0 12px; } h2 { font-size: 1.15rem; margin: 20px 0 8px; } h3 { font-size: 1rem; margin: 12px 0 6px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.muted { color: var(--muted); } .small { font-size: .875rem; }
label { display: block; font-weight: 600; font-size: .92rem; margin: 12px 0 4px; }
input, select, textarea { width: 100%; min-height: var(--tap); padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font: inherit; background: var(--surface); color: var(--ink); }
textarea { min-height: 90px; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .row { grid-template-columns: 1fr; } }
button, .btn { min-height: var(--tap); padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { color: var(--bad); border-color: var(--bad); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.block { width: 100%; margin-top: 16px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
.check input { width: 22px; min-height: 22px; margin-top: 2px; flex: none; }
.vehicle { display: grid; grid-template-columns: 96px 1fr; gap: 12px; align-items: start; }
.vehicle img, .vehicle .ph { width: 96px; height: 72px; object-fit: cover; border-radius: 8px; background: var(--accent-soft); }
.price { font-size: 1.25rem; font-weight: 700; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; font-weight: 600; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .85rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
/* Status always carries text, never colour alone */
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .82rem; font-weight: 600; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); } .pill.warn { background: var(--warn-soft); color: var(--warn); } .pill.bad { background: var(--bad-soft); color: var(--bad); }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); margin: 12px 0; }
.notice.warn { background: var(--warn-soft); } .notice.bad { background: var(--bad-soft); } .notice.ok { background: var(--ok-soft); }
.steps { display: flex; gap: 6px; margin: 4px 0 12px; } .steps span { flex: 1; height: 4px; border-radius: 4px; background: var(--line); } .steps span.on { background: var(--accent); }
.list-item { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; } @media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }
.timeline { list-style: none; padding: 0; margin: 0; } .timeline li { padding: 6px 0 6px 14px; border-left: 2px solid var(--line); font-size: .9rem; }
.hidden { display: none !important; }
#toast { position: fixed; left: 16px; right: 16px; bottom: 16px; max-width: 520px; margin: 0 auto; padding: 12px 16px; border-radius: 10px; background: var(--ink); color: var(--bg); z-index: 50; }
footer { text-align: center; padding: 24px 16px; color: var(--muted); font-size: .85rem; }
.terms-box { max-height: 220px; overflow: auto; white-space: pre-wrap; }
.mt { margin-top: 12px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.inline-form > * { flex: 1 1 160px; }
.inline-form button { flex: 0 0 auto; }
.photos { display: flex; gap: 6px; flex-wrap: wrap; } .photos img { width: 84px; height: 64px; object-fit: cover; border-radius: 6px; }
.checklist li { list-style: none; margin: 4px 0; } .checklist { padding: 0; }
.login-card { max-width: 420px; margin: 40px auto; }
.roles { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; }
.roles .check { margin: 0; font-size: .9rem; }
.roles button { margin-left: auto; }
.steps-list { padding-left: 20px; display: grid; gap: 6px; margin: 8px 0 4px; }
.copy { font-family: ui-monospace, Menlo, monospace; font-size: 1.05em; user-select: all; }
.group-rates input.rate { width: 96px; min-height: 40px; padding: 6px 8px; text-align: right; }
.group-rates td { vertical-align: middle; }
header.top .brand { display: inline-flex; align-items: center; gap: 10px; line-height: 0; }
header.top .brand img { height: 42px; width: auto; display: block; }
.brand-tag { line-height: 1; font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); border-left: 1px solid var(--line); padding-left: 10px; }
.login-logo img { display: block; width: 100%; max-width: 300px; height: auto; margin: 4px auto 12px; }
@media (max-width: 420px) { header.top .brand img { height: 36px; } header.top > .muted { display: none; } }
footer strong { color: var(--ink); }

.statement-head { display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; border-bottom: 2px solid var(--accent); padding-bottom: 12px; margin-bottom: 12px; }
.statement-head h1 { margin: 0; }
.statement-logo { width: 220px; max-width: 60%; height: auto; }
table.sum td { padding: 8px 6px; }
table.sum tr.total td { font-weight: 700; font-size: 1.1rem; border-top: 2px solid var(--ink); }
.bad { color: var(--bad); }
@media print {
  header.top, footer, .no-print, #toast { display: none !important; }
  body { background: #fff; }
  main, main.wide { max-width: none; padding: 0; }
  .card.statement { border: 0; padding: 0; }
  .pill { border: 1px solid currentColor; }
}
@media (max-width: 480px) { dl.kv { grid-template-columns: 1fr; gap: 2px 0; } dl.kv dd { margin-bottom: 8px; } table.sum td { padding: 6px 2px; } }

/* ---- Mobile hardening ---- */
/* Grid and flex children may shrink below their content, so wide content scrolls inside its own box. */
.grid2 > *, .row > *, .list-item > * { min-width: 0; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
/* Long words, references and phone numbers wrap instead of pushing the page wider. */
dd, .card p, .notice { overflow-wrap: anywhere; }
/* Tables keep whole words: if they don't fit, the table scrolls sideways inside its own box. */
td, th, .pill { overflow-wrap: normal; word-break: normal; }
.table-wrap td button, .table-wrap td .btn { white-space: nowrap; }
/* Buttons with long labels wrap onto two lines rather than overflowing. */
button, .btn { max-width: 100%; white-space: normal; text-align: center; }
header.top { flex-wrap: wrap; }
@media (max-width: 640px) {
  /* Staff menu becomes a single swipeable strip under the logo. */
  header.top nav { order: 3; width: 100%; margin-left: 0; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 2px; }
  header.top nav::-webkit-scrollbar { display: none; }
  header.top nav a { flex: 0 0 auto; padding: 10px 12px; }
  main { padding: 12px; }
  .card { padding: 14px; }
  .inline-form > * { flex: 1 1 100%; }
  .inline-form button { flex: 1 1 auto; }
  h1 { font-size: 1.35rem; }
}

/* ---- Phones: tables become cards, nothing scrolls sideways ---- */
@media (max-width: 640px) {
  /* Inputs at 16px so iPhones don't zoom in when a field is tapped. */
  input, select, textarea { font-size: 16px; }
  /* Tables with a header: one card per row, each value with its column label. */
  table[data-mobile="cards"] thead { display: none; }
  table[data-mobile="cards"], table[data-mobile="cards"] tbody, table[data-mobile="cards"] tr { display: block; width: 100%; }
  table[data-mobile="cards"] tr { border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; margin: 0 0 10px; background: var(--surface); }
  table[data-mobile="cards"] td, table[data-mobile="cards"] tbody th { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); text-align: right; white-space: normal; }
  table[data-mobile="cards"] tr > :last-child { border-bottom: 0; }
  table[data-mobile="cards"] td::before, table[data-mobile="cards"] tbody th::before { content: attr(data-label); flex: 0 0 38%; text-align: left; color: var(--muted); font-size: .82rem; font-weight: 600; }
  table[data-mobile="cards"] td[data-label=""]::before, table[data-mobile="cards"] tbody th[data-label=""]::before { display: none; }
  table[data-mobile="cards"] td[data-label=""] { justify-content: flex-end; }
  table[data-mobile="cards"] td:empty { display: none; }
  /* Cells holding forms or several controls stack under their label. */
  table[data-mobile="cards"] td:has(form, input, select, .roles) { flex-direction: column; align-items: stretch; text-align: left; }
  table[data-mobile="cards"] td:has(form, input, select, .roles)::before { flex: none; }
  table[data-mobile="cards"] .group-rates input.rate, table.group-rates[data-mobile="cards"] input.rate { width: 100%; }
  /* Header-less lists (payments, refunds, ledger): each row wraps inside the card. */
  table[data-mobile="rows"], table[data-mobile="rows"] tbody { display: block; width: 100%; }
  table[data-mobile="rows"] tr { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
  table[data-mobile="rows"] td { display: block; border: 0; padding: 0; text-align: left; }
  table[data-mobile="rows"] td.num { margin-left: auto; font-weight: 600; }
  .table-wrap:has(table[data-mobile="cards"]), .table-wrap:has(table[data-mobile="rows"]) { overflow: visible; }
  td .btn, td button { white-space: normal; }
  /* Menu strip: fade at the edge shows there is more to swipe. */
  header.top nav { -webkit-mask-image: linear-gradient(to right, #000 85%, transparent); mask-image: linear-gradient(to right, #000 85%, transparent); }
}
@media (max-width: 640px) {
  table[data-mobile="cards"] .cell-v { min-width: 0; flex: 1 1 auto; overflow-wrap: anywhere; }
  table[data-mobile="cards"] td:has(form, input, select, .roles) .cell-v { width: 100%; }
}
