:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #17202a;
  --muted: #6b7682;
  --line: #e2e5e9;
  --brand: #1d3b5a;
  --accent: #2b6cb0;
  --accent-soft: #e5eef8;
  --warn: #d9822b;
  --warn-soft: #fdf1e4;
  --bad: #c4342d;
  --ok: #1f8a4c;
  --radius: 12px;
  --tabs-h: 60px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #18202a;
    --text: #e6eaef;
    --muted: #93a0ad;
    --line: #2a3542;
    --brand: #9cc3ea;
    --accent: #6aa8e8;
    --accent-soft: #1c2c3e;
    --warn: #f0a050;
    --warn-soft: #33261a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
}
body.noscroll { overflow: hidden; }
main { max-width: 760px; margin: 0 auto; padding: 0 16px; }
h1 { font-size: 24px; margin: 0; color: var(--brand); }
h2, h3, h4 { margin: 0; }
h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
button { font: inherit; color: inherit; }
input, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.muted { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 0; }
.nowrap { white-space: nowrap; }

.top { display: flex; align-items: center; justify-content: space-between; padding: calc(14px + env(safe-area-inset-top)) 0 12px; }

.btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn.danger { color: var(--bad); }
.btn.wide { width: 100%; padding: 14px; font-size: 16px; }
.link { background: none; border: 0; color: var(--accent); padding: 4px 0; cursor: pointer; text-align: left; }
li > .link { display: inline; padding: 0; }
.icon { background: none; border: 0; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; color: var(--muted); flex: none; }
.icon:hover { background: var(--accent-soft); }
.icon:disabled { opacity: .3; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 12px; white-space: nowrap; cursor: pointer; font-size: 14px; }
.chip.on { background: var(--brand); color: var(--bg); border-color: var(--brand); }

.datebar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.presets { margin-top: 8px; }
.rangelabel { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sortbtn { padding: 9px 12px; font-weight: 500; }
.daterow { display: flex; gap: 6px; align-items: center; width: 100%; }
.daterow input { flex: 1; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 12px 0; }
.filterbar { margin-top: 10px; padding: 8px 12px; background: var(--accent-soft); border-radius: 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.issues { padding: 0; border-color: var(--warn); background: var(--warn-soft); }
.issues-head { display: flex; gap: 8px; align-items: center; width: 100%; background: none; border: 0; padding: 12px 14px; cursor: pointer; font-weight: 600; text-align: left; }
.issues-head .muted { margin-left: auto; font-weight: 400; }
.issues ul { margin: 0; padding: 0 14px 12px 32px; }
.issues li { margin: 4px 0; }
.warn-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }

.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 4px; }
.summary div { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.summary b { display: block; font-size: 18px; }
.summary span { color: var(--muted); font-size: 12px; }

.day { margin-top: 18px; }
.day h2 { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; font-weight: 600; padding: 0 2px 6px; }
.day h2 span:first-child { text-transform: capitalize; }
.rides { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }

.ride {
  display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left; background: none; border: 0;
  border-top: 1px solid var(--line); padding: 11px 12px; cursor: pointer;
}
.ride:first-child { border-top: 0; }
.ride:hover { background: var(--accent-soft); }
.ride.unassigned .route, .ride.unassigned .km { color: var(--muted); }
.ride.sel { background: var(--accent-soft); }
.ride.flash { animation: flash 1.2s ease; }
@keyframes flash { 0%, 40% { background: var(--warn-soft); } }
.ride .check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; font-size: 13px; margin-top: 2px; }
.ride.sel .check { background: var(--accent); border-color: var(--accent); color: #fff; }
.ride .time { font-variant-numeric: tabular-nums; font-weight: 600; width: 44px; flex: none; font-size: 14px; }
.ride .time small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.ride .main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ride .route { font-size: 14px; overflow-wrap: anywhere; }
.ride .sub { font-size: 12px; color: var(--muted); }
.plate { font-weight: 600; margin-right: 6px; color: var(--text); }
.edited { color: var(--accent); }
.chiprow { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.ochip { background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 1px 7px; font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ochip.none { background: var(--bg); color: var(--muted); font-weight: 400; }
.ride .km { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; display: flex; gap: 6px; align-items: center; }
.ride .km small { color: var(--muted); font-weight: 400; margin-left: 2px; }

.selbar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line); padding: 10px 16px; z-index: 20;
  box-shadow: 0 -6px 20px rgb(0 0 0 / .08);
}
.selbar > * { max-width: 728px; margin: 0 auto; }
.selinfo { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.selform { display: flex; gap: 8px; }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); display: flex; background: var(--surface); border-top: 1px solid var(--line); z-index: 30;
}
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-decoration: none; color: var(--muted); font-size: 12px; gap: 2px; }
.tabs a.active { color: var(--accent); font-weight: 600; }
.ti { font-size: 19px; line-height: 1; }

/* bottom sheet */
.sheet { position: fixed; inset: 0; background: rgb(0 0 0 / .4); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.panel {
  background: var(--surface); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
@media (min-width: 700px) { .sheet { align-items: center; } .panel { border-radius: 18px; } }
.grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 8px; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; }
.sheet-head h3 { text-transform: capitalize; font-size: 17px; }
.map { height: 220px; border-radius: 10px; margin: 12px 0 4px; background: var(--bg); z-index: 0; }
.facts { display: grid; grid-template-columns: 96px 1fr; gap: 6px 10px; margin: 12px 0; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.sheet-issues { list-style: none; padding: 0; margin: 0 0 12px; }
.sheet-issues li { background: var(--warn-soft); border-left: 3px solid var(--warn); padding: 8px 10px; border-radius: 6px; margin-bottom: 6px; font-size: 13.5px; }
.sheet-issues li.error { border-color: var(--bad); }
.sheet-issues li.info { background: var(--accent-soft); border-color: var(--accent); }
.billing { border-top: 1px solid var(--line); padding-top: 14px; }
.billing h4 { margin-top: 6px; }
.part { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.part input[name=order] { flex: 1; font-variant-numeric: tabular-nums; font-size: 16px; }
.kmfield { width: 80px; flex: none; text-align: right; font-variant-numeric: tabular-nums; font-size: 16px; }
output.kmfield { padding: 9px 0; font-weight: 600; }
output.kmfield.bad { color: var(--bad); }
.unit { color: var(--muted); font-size: 13px; }
.cust { display: grid; grid-template-columns: 110px 1fr; gap: 8px; align-items: center; margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.actions.sticky { position: sticky; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 8px); }

/* record */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-row label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.form-row .rate { grid-column: 1 / -1; font-size: 14px; }
.warnbox { background: var(--warn-soft); border-color: var(--warn); font-size: 14px; }
.warnbox ul { margin: 6px 0 0; padding-left: 20px; }
.totals { display: grid; grid-template-columns: 1fr 1.3fr .7fr; gap: 8px; margin: 12px 0; }
.totals div { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.totals span { display: block; color: var(--muted); font-size: 12px; }
.totals b { font-size: 18px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.record { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.record th, .record td { padding: 8px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.record th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--bg); }
.record .r { text-align: right; }
.record tbody tr { cursor: pointer; }
.record tbody tr:hover { background: var(--accent-soft); }
.record tfoot td { font-weight: 700; border-bottom: 0; }

/* settings */
.grid { display: grid; gap: 10px; }
.grid label, .inline { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.inline { margin: 12px 0 0; }
.custrow { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.custrow > input { flex: 1; }
.ratein { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.ratein input { width: 70px; text-align: right; }
.radio input { width: 18px; height: 18px; accent-color: var(--accent); }
.plain { list-style: none; padding: 0; margin: 0; }
.plain li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.plain li:last-child { border: 0; }
.warntext { color: var(--warn); }

/* customers */
a.card { display: block; color: inherit; text-decoration: none; }
.custcard:hover { border-color: var(--accent); }
.custtop { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; font-size: 16px; }
.custnums { display: flex; gap: 16px; margin: 8px 0 4px; font-variant-numeric: tabular-nums; font-size: 14px; }
.rule { font-size: 12.5px; color: var(--accent); }
.orow { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; padding: 10px 0; border-top: 1px solid var(--line); align-items: baseline; }
.orow .onum { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.orow .onote { grid-column: 1 / -1; font-size: 13px; overflow-wrap: anywhere; }
.orow select { grid-column: 1 / -1; margin-top: 4px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid3 label { min-width: 0; }
.grid h4 { margin-top: 8px; }
.top .link { font-size: 14px; }
@media (max-width: 480px) { .grid3 { grid-template-columns: 1fr 1fr; } .tabs a { font-size: 11px; } }

.switch { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.switch input { width: 20px; height: 20px; flex: none; margin-top: 1px; accent-color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 90px); transform: translate(-50%, 20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 60; transition: .2s; pointer-events: none; font-size: 14px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 480px) {
  .summary b, .totals b { font-size: 16px; }
  .record { font-size: 12.5px; }
  .record th, .record td { padding: 7px 5px; }
  .record .c-rate, .record .c-no { display: none; }
  .record .yr { display: none; }
}
