:root {
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #eef1f5; --line: #d9dee6; --text: #18212d; --muted: #5d6878;
  --brand: #1f3a5f; --brand-ink: #ffffff; --accent: #2563eb;
  --ok: #15803d; --ok-bg: #dcfce7; --warn: #a16207; --warn-bg: #fef3c7; --bad: #b91c1c; --bad-bg: #fee2e2; --info-bg: #dbeafe;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: "Noto Sans Thai", "Leelawadee UI", "Sukhumvit Set", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b; --surface: #171e28; --surface-2: #1f2834; --line: #2c3746; --text: #e6ebf2; --muted: #98a3b3;
    --brand: #23466f; --accent: #60a5fa; --ok: #4ade80; --ok-bg: #12301f; --warn: #fbbf24; --warn-bg: #352a0c;
    --bad: #f87171; --bad-bg: #3a1515; --info-bg: #172a4a; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%; min-width: 0; }
textarea { min-height: 70px; resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 3px; }
h1, h2, h3 { margin: 0 0 10px; line-height: 1.25; }
h1 { font-size: 20px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
.ic { width: 1.15em; height: 1.15em; vertical-align: -0.2em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.btn .ic, .chip .ic { width: 1.05em; height: 1.05em; }
.tabbar .ic { width: 22px; height: 22px; display: block; margin: 0 auto 2px; }
.search-wrap { position: relative; }
.search-wrap .ic { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); pointer-events: none; }
.search-wrap input { padding-left: 32px; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .mono { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 14px; }
.full { grid-column: 1 / -1; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.stack > * + * { margin-top: 12px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 12px; cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.big { padding: 14px 16px; font-size: 17px; width: 100%; border-radius: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.st-planned { background: var(--surface-2); color: var(--muted); }
.st-assigned { background: var(--info-bg); color: var(--accent); }
.st-en_route { background: var(--warn-bg); color: var(--warn); }
.st-done { background: var(--ok-bg); color: var(--ok); }
.st-failed, .st-cancelled { background: var(--bad-bg); color: var(--bad); }
.st-rescheduled { background: #ede9fe; color: #6d28d9; }
.flag-bad { background: var(--bad-bg); color: var(--bad); font-weight: 600; }
.flag-warn { background: var(--warn-bg); color: var(--warn); }

/* ---------- planner shell ---------- */
.top { display: flex; align-items: center; gap: 14px; padding: 8px 16px; background: var(--brand); color: var(--brand-ink); flex-wrap: wrap; }
.top .logo { font-weight: 700; font-size: 16px; }
.top nav { display: flex; gap: 2px; flex-wrap: wrap; }
.top nav a { color: #dbe5f2; text-decoration: none; padding: 6px 10px; border-radius: 7px; }
.top nav a.on, .top nav a:hover { background: rgba(255, 255, 255, .14); color: #fff; }
.top .btn { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .25); color: #fff; }
.top .who { font-size: 13px; opacity: .9; }
.badge { background: #ef4444; color: #fff; border-radius: 999px; padding: 0 6px; font-size: 11px; margin-left: 3px; }
main.page { padding: 16px; max-width: 1500px; margin: 0 auto; }

/* ---------- board ---------- */
.board { display: grid; grid-template-columns: 300px 1fr; gap: 14px; align-items: start; }
.inbox { position: sticky; top: 10px; max-height: calc(100vh - 140px); display: flex; flex-direction: column; }
.inbox .list { overflow-y: auto; flex: 1; }
.cols { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; }
.col { flex: 0 0 240px; background: var(--surface-2); border-radius: var(--radius); padding: 8px; display: flex; flex-direction: column; min-height: 220px; border-top: 4px solid var(--c, var(--line)); }
.col h3 { margin: 0; font-size: 14px; }
.col .meta { font-size: 12px; color: var(--muted); margin: 2px 0 8px; }
.col .list, .inbox .list { min-height: 60px; display: flex; flex-direction: column; gap: 6px; }
.col.drag-over, .inbox.drag-over { outline: 2px dashed var(--accent); outline-offset: -2px; }
.empty { border: 1px dashed var(--line); border-radius: 8px; padding: 14px; text-align: center; font-size: 13px; color: var(--muted); }
.jc { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font-size: 13px; cursor: pointer; box-shadow: var(--shadow); border-left: 4px solid var(--c, var(--line)); }
.jc[draggable="true"] { cursor: grab; }
.jc.dragging { opacity: .4; }
.jc.voided { border-color: var(--bad); background: var(--bad-bg); }
.jc .l1 { display: flex; gap: 6px; align-items: center; justify-content: space-between; }
.jc .name { font-weight: 600; margin: 2px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.jc .tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.jc .name { font-size: 14px; }
.jc .ell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.jc .docno { font-family: ui-monospace, Consolas, monospace; font-weight: 700; font-size: 13px; color: var(--accent); }
.ready-btn { padding: 1px 8px; font-size: 12px; border-radius: 999px; }
.ready-btn.on { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.st-ready { background: var(--ok-bg); color: var(--ok); }
.jc .no {font-size: 11.5px; color: var(--muted); font-family: ui-monospace, Consolas, monospace; }
.stopn { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--c, var(--muted)); color: #fff; font-size: 11px; font-weight: 700; flex: none; }
#map, .map { height: 340px; border-radius: var(--radius); border: 1px solid var(--line); z-index: 0; }
.map-fallback { display: grid; place-items: center; color: var(--muted); background: var(--surface-2); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12.5px; margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }

table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.t th, table.t td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { color: var(--muted); font-weight: 600; font-size: 12.5px; }
table.t tr.click { cursor: pointer; } table.t tr.click:hover td { background: var(--surface-2); }
table.t input, table.t select { padding: 5px 7px; }

.split { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-left: 2px solid var(--line); padding: 0 0 12px 12px; position: relative; font-size: 13.5px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.photos { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.photos img { width: 84px; height: 84px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: var(--surface-2); cursor: zoom-in; }
.notice { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 9px 11px; font-size: 13.5px; }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.notice.info { background: var(--info-bg); color: var(--accent); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }

/* ---------- driver (phone) ---------- */
.phone { max-width: 520px; margin: 0 auto; min-height: 100vh; background: var(--bg); padding-bottom: 84px; }
.phone header { position: sticky; top: 0; z-index: 5; background: var(--brand); color: #fff; padding: 10px 14px; display: flex; align-items: center; gap: 10px; }
.phone header .btn { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .25); color: #fff; padding: 5px 10px; }
.phone .body { padding: 12px 14px; }
.netbar { font-size: 13px; padding: 6px 14px; display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.netbar.off { background: var(--bad-bg); color: var(--bad); }
.netbar.on { background: var(--ok-bg); color: var(--ok); }
.stop { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; display: flex; gap: 12px; box-shadow: var(--shadow); }
.stop .num { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--brand); color: #fff; font-weight: 700; }
.stop.finished { opacity: .6; }
.stop .job { padding: 6px 0; border-top: 1px solid var(--line); cursor: pointer; }
.stop .job:first-of-type { border-top: 0; }
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; display: flex; justify-content: center; background: var(--surface); border-top: 1px solid var(--line); padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); z-index: 6; }
.tabbar a { flex: 0 1 200px; text-align: center; text-decoration: none; color: var(--muted); font-size: 13px; padding: 6px; }
.tabbar a.on { color: var(--accent); font-weight: 600; }
.tabbar a span { display: block; font-size: 20px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: 14.5px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.slot { border: 2px dashed var(--line); border-radius: 12px; padding: 12px; text-align: center; background: var(--surface); }
.slot img { max-width: 100%; max-height: 220px; border-radius: 8px; display: block; margin: 0 auto 8px; }
.slot.filled { border-style: solid; border-color: var(--ok); }
.reasons label { display: flex; gap: 10px; align-items: center; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 6px; color: var(--text); font-size: 15px; }
.reasons input { width: auto; }
.pull { text-align: center; font-size: 12px; color: var(--muted); padding: 4px; }

#toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: #111827; color: #fff; padding: 9px 16px; border-radius: 999px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: calc(100% - 32px); text-align: center; }
#toast.show { opacity: .95; }
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .75); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal-bg img { max-width: 100%; max-height: 90vh; border-radius: 8px; }

/* ---------- job form steps and address picker ---------- */
.job-form.stack > * + * { margin-top: 14px; }
.box h3 { font-size: 14.5px; color: var(--accent); margin: 0 0 10px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.box.stack > h3 + * { margin-top: 0; }
.ready-check { color: var(--text); margin: 0; font-size: 15px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); width: fit-content; cursor: pointer; }
.save-bar { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; z-index: 2; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg label { display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 8px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); font-size: 14px; cursor: pointer; }
.seg label.on { border-color: var(--accent); background: var(--info-bg); color: var(--accent); font-weight: 600; }
.seg input { display: none; }
/* Inbox filters: four identical compact dropdowns in a 2×2 grid */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.filters select { font-size: 12.5px; padding: 4px 6px; border-radius: 6px; min-width: 0; }
.co-list { border: 1px solid var(--line); border-radius: 8px; margin-top: 4px; max-height: 300px; overflow-y: auto; background: var(--surface); }
.co-opt { display: flex; gap: 8px; align-items: center; width: 100%; text-align: left; padding: 8px 10px; border: 0; border-bottom: 1px solid var(--line); background: transparent; cursor: pointer; font-size: 14px; }
.co-opt:last-child { border-bottom: 0; }
.co-opt:hover { background: var(--surface-2); }
.co-list .empty { border: 0; }
.co-picked { display: flex; gap: 8px; align-items: center; padding: 9px 11px; border: 1px solid var(--accent); border-radius: 8px; background: var(--info-bg); flex-wrap: wrap; }
.seg-sm label { padding: 5px 9px; font-size: 12.5px; }
.cheque { display: grid; grid-template-columns: auto 1.2fr 1fr 1fr 1fr auto; gap: 6px; align-items: center; margin-bottom: 6px; }
@media (max-width: 700px) { .cheque { grid-template-columns: 1fr 1fr; } .cheque > span { grid-column: 1 / -1; } }
.phone .cheque { grid-template-columns: 1fr 1fr; }
.phone .cheque > span { grid-column: 1 / -1; }
.seg label.locked { opacity: .55; cursor: not-allowed; }
.person { display: grid; grid-template-columns: 1fr 1fr 1.2fr auto; gap: 6px; margin-bottom: 6px; }
@media (max-width: 560px) { .person { grid-template-columns: 1fr 1fr; } }
.addr-group { margin-top: 8px; }
.addr-group + .addr-group { margin-top: 14px; }
.addr-co { font-weight: 600; font-size: 13px; margin: 8px 0 4px; }
.addr { display: flex; gap: 10px; align-items: flex-start; margin: 4px 0 0; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); font-size: 14px; cursor: pointer; }
.addr.on { border-color: var(--accent); background: var(--info-bg); }
.addr input { width: auto; margin-top: 3px; }

.login { max-width: 560px; margin: 40px auto; padding: 0 16px; }
.login .u { display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left; padding: 12px 14px; margin-bottom: 8px; }

@media (max-width: 900px) {
  .board, .split { grid-template-columns: minmax(0, 1fr); }
  .board > *, .split > * { min-width: 0; }
  .inbox { position: static; max-height: none; }
  .grid3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .grid2, .grid3 { grid-template-columns: 1fr; }
  main.page { padding: 12px; }
}

/* two-tap confirm */
.btn.armed { background: #b91c1c; border-color: #b91c1c; color: #fff; }
