:root {
  --bg: #E9EDF1;
  --surface: #FFFFFF;
  --surface-2: #F3F6F8;
  --ink: #152A4E;
  --ink-soft: #5C6E86;
  --ink-faint: #90A0B4;
  --line: #DCE3EB;
  --green: #2FA524;
  --green-deep: #1E7D17;
  --lime: #8DC63F;
  --navy: #152A4E;
  --danger: #D64545;
  --danger-soft: #FBECEC;
  --warn: #C77A00;
  --grad: linear-gradient(135deg, #9BD34A 0%, #34AC26 55%, #1E8F19 100%);
  --shadow: 0 1px 2px rgba(21,42,78,.06), 0 8px 24px rgba(21,42,78,.08);
  --radius: 16px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0A1524; --surface: #13233A; --surface-2: #0F1D30; --ink: #EAF1F8;
    --ink-soft: #9DB0C7; --ink-faint: #6E8199; --line: #24384F; --green: #46C233;
    --green-deep: #46C233; --lime: #A8DB5A; --navy: #0A1524; --danger: #F0736F;
    --danger-soft: #2A1A1E; --warn: #E6A93B;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
  }
}
:root[data-theme="light"] {
  --bg: #E9EDF1; --surface: #FFFFFF; --surface-2: #F3F6F8; --ink: #152A4E;
  --ink-soft: #5C6E86; --ink-faint: #90A0B4; --line: #DCE3EB; --green: #2FA524;
  --green-deep: #1E7D17; --lime: #8DC63F; --navy: #152A4E; --danger: #D64545;
  --danger-soft: #FBECEC; --warn: #C77A00;
  --shadow: 0 1px 2px rgba(21,42,78,.06), 0 8px 24px rgba(21,42,78,.08);
}
:root[data-theme="dark"] {
  --bg: #0A1524; --surface: #13233A; --surface-2: #0F1D30; --ink: #EAF1F8;
  --ink-soft: #9DB0C7; --ink-faint: #6E8199; --line: #24384F; --green: #46C233;
  --green-deep: #46C233; --lime: #A8DB5A; --navy: #0A1524; --danger: #F0736F;
  --danger-soft: #2A1A1E; --warn: #E6A93B;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--sans);
  font-size: 15.5px; line-height: 1.45; -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, select { font: inherit; }
a { color: var(--green-deep); }

.frame { max-width: 460px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
.frame.wide { max-width: 960px; }

/* ---- header ---- */
header {
  padding: 15px 18px 13px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.brand-mark { height: 26px; width: auto; flex: none; display: block; }
.brand .wm { display: flex; flex-direction: column; line-height: 1; }
.brand .wm small { font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-soft); font-weight: 600; }
.brand .wm b { font-size: 14.5px; letter-spacing: .04em; color: var(--ink); font-weight: 800; }
.doc { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .1em; }

/* ---- offline banner ---- */
.banner {
  display: flex; align-items: center; gap: 9px; padding: 10px 18px; font-size: 13px; font-weight: 600;
  background: color-mix(in srgb, var(--warn) 16%, var(--surface)); color: var(--warn);
  border-bottom: 1px solid color-mix(in srgb, var(--warn) 30%, var(--line));
}
.banner .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }

main { padding: 16px 16px 130px; display: flex; flex-direction: column; gap: 14px; flex: 1; }

/* ---- car card ---- */
.car {
  position: relative; overflow: hidden; border-radius: var(--radius); padding: 16px 18px;
  background: var(--navy); color: #fff; box-shadow: var(--shadow);
}
.car::after {
  content: ""; position: absolute; right: -30px; top: -40px; width: 160px; height: 160px;
  background: var(--grad); opacity: .22; border-radius: 50%; filter: blur(6px);
}
.car .scan { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--lime); }
.car .name { font-size: 22px; font-weight: 800; margin: 6px 0 2px; position: relative; z-index: 1; }
.car .id { font-family: var(--mono); font-size: 12.5px; color: rgba(255,255,255,.72); position: relative; z-index: 1; }

/* ---- fields ---- */
.field { background: var(--surface); border-radius: var(--radius); padding: 15px 16px; box-shadow: var(--shadow); }
label.lbl { display: flex; align-items: center; gap: 8px; font-size: 11.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 10px; }
label.lbl .req { color: var(--green); }
.hint { font-size: 12.5px; color: var(--ink-faint); margin-top: 8px; }

input[type="text"], input[type="password"], input[type="number"], input[type="datetime-local"],
input[type="search"], input[type="date"], select, textarea {
  width: 100%; border: 1.5px solid var(--line); background: var(--surface-2); color: var(--ink);
  border-radius: 11px; padding: 12px 13px; font-size: 16px;
}
textarea { font-family: inherit; resize: vertical; min-height: 46px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 22%, transparent); }
input[type="number"] { font-variant-numeric: tabular-nums; }

/* ---- driver ---- */
.driver { display: flex; align-items: center; gap: 12px; }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--grad); color: var(--navy); display: grid; place-items: center; font-weight: 800; font-size: 15px; flex: none; }
.driver .who b { display: block; font-size: 16.5px; font-weight: 700; }
.driver .who span { font-size: 12.5px; color: var(--ink-faint); }
.link { margin-left: auto; background: none; border: 0; color: var(--green-deep); font-weight: 700; font-size: 13.5px; cursor: pointer; padding: 6px; }

/* ---- chips + search menu ---- */
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 11px; }
.chips:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: color-mix(in srgb, var(--green) 12%, var(--surface)); color: var(--green-deep); border: 1px solid color-mix(in srgb, var(--green) 28%, transparent); border-radius: 999px; padding: 5px 6px 5px 11px; font-size: 13.5px; font-weight: 600; }
.chip button { border: 0; background: color-mix(in srgb, var(--green) 22%, transparent); color: var(--green-deep); width: 18px; height: 18px; border-radius: 50%; cursor: pointer; font-size: 12px; line-height: 1; display: grid; place-items: center; }
.search { position: relative; }
.menu { list-style: none; margin: 6px 0 0; padding: 6px; max-height: 210px; overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); display: none; }
.menu.open { display: block; }
.menu li { padding: 10px 11px; border-radius: 8px; cursor: pointer; font-size: 15px; display: flex; align-items: center; gap: 9px; }
.menu li:hover, .menu li.active { background: var(--surface-2); }
.menu li .mini { width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--ink-soft); }
.menu li.empty { color: var(--ink-faint); cursor: default; justify-content: center; }

.warnmsg { display: none; align-items: center; gap: 7px; margin-top: 9px; font-size: 12.5px; font-weight: 600; color: var(--warn); }
.warnmsg.show { display: flex; }

/* ---- photos ---- */
.photos { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.thumb { aspect-ratio: 1; border-radius: 11px; position: relative; overflow: hidden; background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button { position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: rgba(10,21,36,.72); color: #fff; cursor: pointer; font-size: 12px; line-height: 1; }
.addphoto { aspect-ratio: 1; border-radius: 11px; border: 1.5px dashed var(--line); background: var(--surface-2); color: var(--ink-soft); display: grid; place-items: center; gap: 3px; cursor: pointer; font-size: 11px; font-weight: 600; }
.addphoto svg { width: 22px; height: 22px; }
.addphoto input { display: none; }

/* ---- submit bar ---- */
.bar { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px); border-top: 1px solid var(--line); }
.bar-inner { max-width: 460px; margin: 0 auto; }
.queued { display: flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 9px; }
.queued b { color: var(--ink); }
.btn-primary { width: 100%; border: 0; border-radius: 13px; padding: 15px; font-size: 16.5px; font-weight: 800; color: var(--navy); background: var(--grad); cursor: pointer; letter-spacing: .01em; box-shadow: 0 6px 18px color-mix(in srgb, var(--green) 40%, transparent); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-primary.offline { background: var(--navy); color: #fff; box-shadow: none; }

/* ---- generic buttons ---- */
.btn { border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 10px; padding: 9px 14px; font-weight: 600; cursor: pointer; font-size: 14px; }
.btn:hover { border-color: var(--ink-faint); }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn.solid { background: var(--grad); color: var(--navy); border: 0; }

/* ---- toast ---- */
.toast { position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%) translateY(20px); background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .3s; display: flex; align-items: center; gap: 9px; max-width: 90%; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }
.toast .ic { width: 20px; height: 20px; border-radius: 50%; background: var(--grad); color: var(--navy); display: grid; place-items: center; font-size: 13px; font-weight: 900; flex: none; }
.toast.err .ic { background: #fff; color: var(--danger); }

/* ---- home / states ---- */
.center-card { margin: auto; text-align: center; padding: 40px 26px; max-width: 360px; }
.center-card .big { width: 64px; height: 64px; margin: 0 auto 18px; border-radius: 18px; background: var(--grad); display: grid; place-items: center; }
.center-card .big svg { width: 34px; height: 34px; color: var(--navy); }
.center-card h1 { font-size: 22px; margin: 0 0 8px; }
.center-card p { color: var(--ink-soft); margin: 0 0 18px; }
.muted { color: var(--ink-soft); }

/* contact block (driver pages) */
.contact { max-width: 460px; margin: 8px auto 0; padding: 16px 18px 22px; text-align: center;
  color: var(--ink-soft); font-size: 12.5px; line-height: 1.8; border-top: 1px solid var(--line); }
.contact .ft-k { color: var(--ink-faint); }
.contact a { color: var(--green-deep); text-decoration: none; }
.contact a:hover { text-decoration: underline; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--green); border-radius: 50%; animation: spin 1s linear infinite; margin: 60px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- success screen ---- */
.done { margin: auto; text-align: center; padding: 40px 26px; }
.done .check { width: 84px; height: 84px; border-radius: 50%; background: var(--grad); display: grid; place-items: center; margin: 0 auto 20px; color: var(--navy); font-size: 42px; font-weight: 900; }
.done h1 { font-size: 24px; margin: 0 0 6px; }
.done p { color: var(--ink-soft); margin: 0 0 24px; }

/* ---- admin ---- */
.tabs { display: flex; gap: 6px; padding: 12px 16px 0; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; color: var(--ink-soft); font-weight: 700; font-size: 14px; padding: 8px 12px; border-radius: 9px; cursor: pointer; }
.tabs button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.panel { padding: 8px 16px 60px; display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; background: var(--surface); border-radius: 12px; padding: 11px 13px; box-shadow: var(--shadow); }
.row .grow { flex: 1; min-width: 0; }
.row .name { font-weight: 600; }
.row .sub { font-size: 12.5px; color: var(--ink-faint); }
.row.inactive { opacity: .55; }
.pill { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: 3px 8px; border-radius: 999px; }
.pill.on { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green-deep); }
.pill.off { background: var(--surface-2); color: var(--ink-faint); }
.addbar { display: flex; gap: 8px; }
.addbar input { flex: 1; }
.member-fields { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.member-fields input[type="email"] { font-size: 13.5px; padding: 8px 11px; color: var(--ink-soft); }
.member-controls { display: flex; align-items: center; gap: 8px; flex: none; }
.row { align-items: flex-start; }

.trip { background: var(--surface); border-radius: 12px; padding: 13px 15px; box-shadow: var(--shadow); }
.trip .top { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.trip .top b { font-size: 15.5px; }
.trip .top .when { margin-left: auto; font-size: 12.5px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.trip .meta { font-size: 13.5px; color: var(--ink-soft); margin-top: 4px; }
.trip .meta .k { color: var(--ink-faint); }
.trip .odo { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }
.trip .pics { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.trip .pics img { width: 58px; height: 58px; border-radius: 8px; object-fit: cover; cursor: pointer; background: var(--surface-2); }
.trip .actions { margin-top: 10px; display: flex; gap: 8px; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar select { width: auto; flex: 1; min-width: 130px; }

.qrcard { background: var(--surface); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); text-align: center; }
.qrcard h3 { margin: 0 0 4px; }
.qrcard .plate { color: var(--ink-faint); font-size: 13px; margin-bottom: 12px; }
.qrcard img { width: 200px; max-width: 70%; height: auto; background: #fff; border-radius: 10px; padding: 8px; }
.qrcard .url { font-family: var(--mono); font-size: 11.5px; color: var(--ink-faint); margin: 10px 0 14px; word-break: break-all; }

.lightbox { position: fixed; inset: 0; background: rgba(10,21,36,.9); display: grid; place-items: center; z-index: 100; padding: 20px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; }

.error-note { background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; font-weight: 600; }

@media print {
  header, .tabs, .toolbar, .btn, .doc { display: none !important; }
  body { background: #fff; }
  .qrcard { box-shadow: none; border: 1px solid #ccc; page-break-inside: avoid; margin-bottom: 20px; }
  .panel { display: block; }
}

/* ---- admin overview ---- */
.overview { display: flex; flex-wrap: wrap; gap: 10px; padding: 14px 16px 0; }
.stat { flex: 1; min-width: 110px; background: var(--surface); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.stat-n { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-l { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.stat.warn { background: color-mix(in srgb, var(--warn) 14%, var(--surface)); }
.stat.warn .stat-n { color: var(--warn); }
.out-list { flex-basis: 100%; display: flex; flex-direction: column; gap: 6px; }
.out-item { display: flex; align-items: center; gap: 8px; background: var(--surface); border-radius: 10px; padding: 9px 12px; box-shadow: var(--shadow); font-size: 13.5px; }

/* ---- filters ---- */
.filters { display: flex; flex-direction: column; gap: 8px; background: var(--surface); border-radius: 12px; padding: 12px; box-shadow: var(--shadow); }
.filter-row { display: flex; gap: 8px; align-items: center; }
.filter-row > * { flex: 1; }
.date-lbl { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-soft); }
.date-lbl input { flex: 1; }
.filters .btn { flex: 1; text-align: center; }

/* ---- trip list (collapsible) ---- */
.trip-list { display: flex; flex-direction: column; gap: 8px; }
.trip-row { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.trip-summary { width: 100%; display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: none; border: 0; cursor: pointer; text-align: left; color: inherit; }
.trip-summary:hover { background: var(--surface-2); }
.ts-driver { font-weight: 700; font-size: 15px; }
.ts-sub { font-size: 12.5px; color: var(--ink-faint); margin-top: 1px; }
.ts-activity { font-size: 13px; color: var(--ink-soft); margin-top: 3px; font-weight: 600; }
.ts-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: 12.5px; }
.ts-dist { font-weight: 700; font-variant-numeric: tabular-nums; }
.ts-photos { color: var(--ink-faint); }
.chev { color: var(--ink-faint); transition: transform .2s; flex: none; }
.trip-row.open .chev { transform: rotate(180deg); }
.trip-detail { display: none; padding: 0 14px 14px; border-top: 1px solid var(--line); }
.trip-row.open .trip-detail { display: block; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; margin: 14px 0; }
.fact { display: flex; flex-direction: column; }
.fact .fk { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); font-weight: 700; }
.fact .fv { font-size: 14px; }
.note { background: var(--surface-2); border-radius: 10px; padding: 9px 12px; font-size: 13.5px; margin-bottom: 10px; }
.ph-group { margin-top: 10px; }
.ph-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); font-weight: 700; margin-bottom: 6px; }
.pics { display: flex; gap: 6px; flex-wrap: wrap; }
.pics img { width: 66px; height: 66px; border-radius: 8px; object-fit: cover; cursor: pointer; background: var(--surface-2); }
.trip-actions { margin-top: 14px; }

/* passenger notification log */
.notif-list { display: flex; flex-direction: column; gap: 7px; }
.notif { display: flex; align-items: center; gap: 8px; font-size: 13px; flex-wrap: wrap; }
.nchip { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 3px 8px; border-radius: 999px; flex: none; }
.nchip.sent { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green-deep); }
.nchip.dry-run { background: color-mix(in srgb, var(--navy) 12%, transparent); color: var(--ink-soft); }
.nchip.failed { background: var(--danger-soft); color: var(--danger); }
.nchip.skipped, .nchip.disabled { background: var(--surface-2); color: var(--ink-faint); border: 1px solid var(--line); }
.notif .nrec { font-weight: 600; }
.notif .nemail { color: var(--ink-faint); font-family: var(--mono); font-size: 12px; }
.notif .nrole { color: var(--green-deep); font-weight: 700; font-size: 12px; }
.notif .ndetail { color: var(--danger); font-size: 12px; }

/* odometer discrepancy alert */
.odo-alert { background: color-mix(in srgb, var(--warn) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 35%, var(--line)); border-radius: 10px; padding: 11px 13px; margin: 14px 0; font-size: 13.5px; }
.odo-alert-title { font-weight: 800; color: var(--warn); margin-bottom: 4px; }
.odo-alert-sub { margin-top: 6px; font-size: 12.5px; color: var(--ink-soft); }
.ts-warn { color: var(--warn); font-weight: 700; }

/* per-car email field labels */
.mini-lbl { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); font-weight: 700; margin-top: 2px; }
.qrcard input[type="email"] { font-size: 13px; padding: 9px 11px; }

.pill.out { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.pill.done { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green-deep); }

@media (min-width: 620px) {
  .facts { grid-template-columns: repeat(3, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .toast { transition: opacity .2s; }
  .btn-primary:active { transform: none; }
  .spinner { animation-duration: 2s; }
  .chev { transition: none; }
}
