:root {
  --ink: #1b1a17;
  --ink-2: #4a4740;
  --muted: #76716a;
  --cream: #f7f2e8;
  --cream-2: #ece3d2;
  --card: #ffffff;
  --line: #e2d9c7;
  --olive: #52532e;
  --green: #2f8a3c;
  --green-bg: #e3f3e2;
  --amber: #8a5a00;
  --amber-bg: #fdf0d2;
  --blue: #1d5fb4;
  --blue-bg: #e2edfb;
  --purple: #6a3fb0;
  --purple-bg: #efe7fb;
  --red: #b42318;
  --red-bg: #fde7e4;
  --radius: 14px;
  --tap: 52px;
  --shadow: 0 1px 2px rgba(27, 26, 23, .06), 0 2px 8px rgba(27, 26, 23, .05);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--cream); }
body { font-size: 17px; line-height: 1.45; min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }
a { color: var(--blue); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }

/* ---------- layout */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--ink); color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex; align-items: center; gap: 12px;
}
.brand { font-weight: 800; font-size: 19px; letter-spacing: -.01em; white-space: nowrap; }
.brand small { font-weight: 500; opacity: .75; margin-left: 6px; font-size: 14px; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 13px; opacity: .8; text-align: right; line-height: 1.2; }
.icon-btn {
  background: transparent; border: 1px solid rgba(255,255,255,.25); color: #fff;
  min-height: 40px; min-width: 40px; border-radius: 10px; padding: 0 12px; cursor: pointer; font-size: 15px;
}
.wrap { max-width: 980px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 620px; }
.page-head { display: flex; align-items: center; gap: 10px; margin: 4px 0 14px; }
.page-head h1 { font-size: 22px; margin: 0; flex: 1; }
.back { text-decoration: none; font-weight: 600; color: var(--ink); display: inline-flex; align-items: center; min-height: 44px; }

/* ---------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-weight: 650; font-size: 17px; text-decoration: none;
  cursor: pointer; -webkit-tap-highlight-color: transparent; transition: transform .05s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn[disabled], .btn.is-busy { opacity: .55; pointer-events: none; }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.go { background: var(--green); color: #fff; border-color: var(--green); }
.btn.road { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn.danger { background: #fff; color: var(--red); border-color: #f0b9b3; }
.btn.block { width: 100%; }
.btn.xl { min-height: 64px; font-size: 19px; border-radius: 16px; }
.btn.small { min-height: 40px; font-size: 15px; padding: 0 12px; }
.btn .spinner { width: 18px; height: 18px; border-width: 2px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 160px; }
.new-btn {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 30;
  box-shadow: 0 6px 18px rgba(27,26,23,.28); min-height: 60px; font-size: 18px; border-radius: 30px; padding: 0 24px;
}
@media (min-width: 760px) { .new-btn { position: static; box-shadow: none; } }

/* ---------- cards & stats */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 16px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
@media (max-width: 520px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { padding: 12px 14px; cursor: pointer; text-align: left; border: 2px solid transparent; }
.stat.active { border-color: var(--ink); }
.stat .n { font-size: 30px; font-weight: 800; line-height: 1.1; }
.stat .l { font-size: 14px; color: var(--muted); font-weight: 600; }
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 8px; margin-bottom: 14px; }
@media (max-width: 760px) { .filters { grid-template-columns: 1fr 1fr; } .filters .search { grid-column: 1 / -1; } }
.list { display: grid; gap: 10px; }
.dcard { display: block; padding: 14px 16px; text-decoration: none; color: inherit; }
.dcard:active { background: #fbf8f2; }
.dcard .top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.dcard .title { font-weight: 750; font-size: 18px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dcard .addr { color: var(--ink-2); }
.meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 14px; margin-top: 6px; }
.meta b { color: var(--ink-2); font-weight: 650; }

/* ---------- badges */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 750; white-space: nowrap; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.s-preparing { color: var(--amber); background: var(--amber-bg); }
.s-on_road { color: var(--blue); background: var(--blue-bg); }
.s-arrived { color: var(--purple); background: var(--purple-bg); }
.s-delivered { color: var(--green); background: var(--green-bg); }
.s-failed { color: var(--red); background: var(--red-bg); }
.badge.big { font-size: 16px; padding: 7px 14px; }

/* ---------- forms */
label.f { display: block; margin-bottom: 14px; }
label.f > span, .f-label { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 15px; margin-bottom: 6px; color: var(--ink-2); }
input[type=text], input[type=tel], input[type=password], input[type=date], input[type=search], input[type=number], select, textarea {
  width: 100%; min-height: var(--tap); padding: 12px 14px; border: 1px solid #cfc5b1; border-radius: 12px; background: #fff; font-size: 17px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(29,95,180,.25); border-color: var(--blue); }
.f.flag-check input, .f.flag-check textarea { border-color: #e0a100; background: #fffaeb; }
.f.flag-missing input { border-color: #e9887d; background: #fff6f5; }
.chip { font-size: 12px; font-weight: 750; padding: 2px 8px; border-radius: 999px; }
.chip.check { background: var(--amber-bg); color: var(--amber); }
.chip.missing { background: var(--red-bg); color: var(--red); }
.chip.ok { background: var(--green-bg); color: var(--green); }
.err-text { color: var(--red); font-size: 14px; margin-top: 4px; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stepper { display: flex; align-items: center; border: 1px solid #cfc5b1; border-radius: 12px; background: #fff; overflow: hidden; }
.stepper button { width: 56px; min-height: var(--tap); border: 0; background: var(--cream); font-size: 26px; font-weight: 700; cursor: pointer; }
.stepper input { border: 0; text-align: center; font-weight: 800; font-size: 22px; min-height: var(--tap); border-radius: 0; }
.stepper input:focus { outline: none; }

/* ---------- receipt capture */
.capture { display: grid; gap: 10px; }
.receipt-preview { position: relative; border-radius: 12px; overflow: hidden; background: #222; max-height: 360px; }
.receipt-preview img { width: 100%; max-height: 360px; object-fit: contain; }
.scan-status { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px; font-weight: 600; }
.scan-status.info { background: var(--blue-bg); color: var(--blue); }
.scan-status.warn { background: var(--amber-bg); color: var(--amber); }
.scan-status.bad { background: var(--red-bg); color: var(--red); }
.scan-status.good { background: var(--green-bg); color: var(--green); }
.progress { height: 6px; background: var(--cream-2); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: var(--blue); width: 0; transition: width .2s; }

/* ---------- detail */
.section { margin-bottom: 14px; }
.section h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 8px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; font-weight: 600; word-break: break-word; }
.big-address { font-size: 22px; font-weight: 800; line-height: 1.25; }
.photo-thumb { border-radius: 12px; overflow: hidden; border: 1px solid var(--line); cursor: zoom-in; background: #111; }
.photo-thumb img { width: 100%; max-height: 420px; object-fit: contain; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--olive); }
.timeline li:last-child { border-left-color: transparent; }
.timeline .t { font-size: 13px; color: var(--muted); }
.notice { padding: 12px 14px; border-radius: 12px; background: var(--cream-2); color: var(--ink-2); font-size: 15px; }
.notice.warn { background: var(--amber-bg); color: var(--amber); }
.notice.bad { background: var(--red-bg); color: var(--red); }
.notice.good { background: var(--green-bg); color: var(--green); }
.map-frame { width: 100%; height: 220px; border: 0; border-radius: 12px; margin-top: 8px; }
.instructions { background: #fff8db; border: 1px solid #f0dc8a; border-radius: 12px; padding: 12px 14px; font-weight: 600; white-space: pre-wrap; }

/* ---------- driver */
.driver-actions { display: grid; gap: 12px; }
.pkg { font-size: 20px; font-weight: 800; }
.gps-line { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 10px 12px; border-radius: 10px; background: var(--cream-2); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--green); box-shadow: 0 0 0 4px rgba(47,138,60,.18); }
.dot.off { background: var(--red); }

/* ---------- misc */
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .big { font-size: 40px; }
.center-load { display: flex; align-items: center; justify-content: center; min-height: 60vh; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { height: 92px; border-radius: var(--radius); background: linear-gradient(90deg, #efe8da 25%, #f6f1e7 50%, #efe8da 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.toasts { position: fixed; left: 50%; transform: translateX(-50%); top: calc(64px + env(safe-area-inset-top)); z-index: 100; display: grid; gap: 8px; width: min(92vw, 440px); }
.toast { background: var(--ink); color: #fff; padding: 14px 16px; border-radius: 12px; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: pop .2s ease-out; }
.toast.good { background: var(--green); }
.toast.bad { background: var(--red); }
@keyframes pop { from { transform: translateY(-8px); opacity: 0; } }
.net-banner { position: sticky; top: 0; z-index: 50; background: var(--red); color: #fff; text-align: center; padding: 8px; font-weight: 700; font-size: 14px; }
.modal-back { position: fixed; inset: 0; background: rgba(20,18,15,.55); z-index: 90; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 640px) { .modal-back { align-items: center; } }
.modal { background: #fff; width: min(100%, 520px); border-radius: 20px 20px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); max-height: 92vh; overflow: auto; animation: up .2s ease-out; }
@media (min-width: 640px) { .modal { border-radius: 20px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.modal h2 { margin: 0 0 8px; font-size: 21px; }
.pick-list { display: grid; gap: 8px; margin: 12px 0; }
.pick-list label { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; font-weight: 600; cursor: pointer; }
.pick-list input { width: 22px; height: 22px; }
.lightbox { position: fixed; inset: 0; background: #000; z-index: 120; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.table { width: 100%; border-collapse: collapse; }
.table td, .table th { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; font-size: 15px; vertical-align: top; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.mt { margin-top: 14px; }
.mb0 { margin-bottom: 0; }
.qr { background: #fff; padding: 12px; border-radius: 12px; display: inline-block; }
.login-box { max-width: 420px; margin: 8vh auto 0; }
.logo-word { font-size: 34px; font-weight: 900; letter-spacing: -.02em; }
.logo-sub { color: var(--olive); font-style: italic; font-family: Georgia, serif; margin-top: -4px; }
/* visually hidden but still clickable through its <label> (iOS ignores display:none file inputs in some versions) */
.vh { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; clip: rect(0 0 0 0); pointer-events: none; }
label.btn { position: relative; }
