:root {
  --bg: #f2f4f7; --card: #ffffff; --text: #101828; --muted: #5b6676; --line: #e1e5eb;
  --primary: #1554b0; --primary-soft: #e8f0fc; --primary-text: #ffffff;
  --ok: #067647; --ok-soft: #dcfae6; --warn: #b54708; --warn-soft: #fef0c7; --danger: #b42318; --danger-soft: #fee4e2;
  --s-draft: #667085; --s-assigned: #1554b0; --s-submitted: #7a5af8; --s-closed: #067647;
  --s-pending_close: #b54708; --s-cancel: #98a2b3;
  --radius: 16px; --shadow: 0 1px 2px rgba(16,24,40,.05), 0 2px 6px rgba(16,24,40,.06);
}
/* ธีมสีขาวอย่างเดียว (ไม่เปลี่ยนตามโหมดมืดของมือถือ) */
:root { color-scheme: light; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.5 "IBM Plex Sans Thai", system-ui, sans-serif; -webkit-text-size-adjust: 100%; }
main { max-width: 600px; margin: 0 auto; padding: 12px 16px calc(110px + env(safe-area-inset-bottom)); }
h1 { font-size: 24px; margin: 0; line-height: 1.3; } h2 { font-size: 20px; margin: 0; line-height: 1.3; }
.muted { color: var(--muted); } .small { font-size: 14px; } .center { text-align: center; padding: 48px 0; }
a { color: var(--primary); }
#mode-banner { position: sticky; top: 0; z-index: 30; background: var(--warn-soft); color: var(--warn);
  text-align: center; font-size: 13px; font-weight: 600; padding: 5px 12px; }
#mode-banner.live { background: var(--ok-soft); color: var(--ok); }
.row { display: flex; gap: 10px; align-items: center; } .between { justify-content: space-between; } .wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line);
  padding: 16px; margin-bottom: 12px; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; padding: 3px 10px;
  border-radius: 999px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.state { color: #fff; } .badge.type { background: var(--primary); color: var(--primary-text); }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.warn { background: var(--warn-soft); color: var(--warn); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 600;
  border: 0; border-radius: 14px; padding: 12px 18px; min-height: 52px; background: var(--primary); color: var(--primary-text);
  cursor: pointer; text-decoration: none; text-align: center; }
.btn.big { min-height: 60px; font-size: 19px; width: 100%; }
.btn.soft { background: var(--primary-soft); color: var(--primary); }
.btn.ghost { background: transparent; color: var(--primary); border: 1.5px solid var(--line); }
.btn.ok { background: var(--ok); color: #fff; } .btn.warn { background: var(--warn); color: #fff; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.block { width: 100%; }
button.link { background: none; border: 0; color: var(--primary); font: inherit; font-weight: 600; padding: 8px; cursor: pointer; min-height: 44px; }

/* list */
.hello { margin: 8px 0 14px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 4px; gap: 4px; margin-bottom: 12px; }
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: 15px;
  padding: 10px 4px; border-radius: 10px; cursor: pointer; }
.seg button.on { background: var(--primary); color: var(--primary-text); }
.seg button .n { display: block; font-size: 20px; line-height: 1.1; }
.search { position: relative; margin-bottom: 12px; }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--card);
  border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; min-height: 52px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); }
textarea { min-height: 96px; resize: vertical; }
.day { font-size: 14px; font-weight: 700; color: var(--muted); margin: 18px 4px 8px; text-transform: none; }
.day.late { color: var(--danger); }
.job { display: block; color: inherit; text-decoration: none; }
.job:active { transform: scale(.985); }
.job .cust { font-weight: 600; font-size: 18px; margin: 6px 0 2px; }
.job .addr { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.dots { display: flex; gap: 6px; margin-top: 12px; align-items: center; }
.dots i { width: 28px; height: 6px; border-radius: 99px; background: var(--line); }
.dots i.on { background: var(--ok); }
.next { margin-top: 10px; font-size: 15px; font-weight: 600; color: var(--primary); }

/* detail */
.back { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; text-decoration: none; min-height: 44px; }
.head h1 { font-size: 22px; }
.contact { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.info { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); font-size: 15px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
.clamp.open { display: block; }
.info b { display: block; font-size: 13px; color: var(--muted); font-weight: 600; }
.alert { border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; font-size: 15px; }
.alert.warn { background: var(--warn-soft); color: var(--warn); } .alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.danger { background: var(--danger-soft); color: var(--danger); }
.alert b { font-size: 16px; }

.step { padding: 0; overflow: hidden; }
.step > .sh { display: flex; align-items: center; gap: 14px; padding: 16px; cursor: pointer; }
.step .num { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-weight: 700; background: var(--bg); color: var(--muted); border: 2px solid var(--line); }
.step.done .num { background: var(--ok); color: #fff; border-color: var(--ok); }
.step.current .num { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.step .st { font-size: 14px; color: var(--muted); }
.step.done .st { color: var(--ok); }
.step .chev { color: var(--muted); font-size: 22px; transition: transform .2s; }
.step.open .chev { transform: rotate(90deg); }
.step > .sb { padding: 0 16px 18px; display: none; }
.step.open > .sb { display: block; }

.field { margin-top: 16px; }
.field > .lbl { display: flex; justify-content: space-between; align-items: baseline; font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.field .saved { font-size: 12px; font-weight: 500; color: var(--ok); }
.field .saving { font-size: 12px; font-weight: 500; color: var(--muted); }
.field .err { font-size: 12px; font-weight: 500; color: var(--danger); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1.5px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-size: 15px;
  padding: 10px 14px; border-radius: 12px; cursor: pointer; min-height: 46px; text-align: left; }
.chip.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.chip:disabled { cursor: default; }
.picker { display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left;
  border: 1.5px solid var(--line); background: var(--card); color: var(--text); font: inherit; border-radius: 12px;
  padding: 12px 14px; min-height: 52px; cursor: pointer; }
.picker .ph { color: var(--muted); }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.checks .chip { display: flex; align-items: center; gap: 8px; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.tile { position: relative; border: 2px dashed var(--line); border-radius: 14px; background: var(--bg); min-height: 132px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 10px;
  text-align: center; cursor: pointer; overflow: hidden; font: inherit; color: var(--text); }
.tile .ic { font-size: 30px; }
.tile .nm { font-size: 14px; font-weight: 600; line-height: 1.3; }
.tile .req { font-size: 12px; color: var(--warn); font-weight: 600; }
.tile.has { border-style: solid; border-color: var(--ok); padding: 0; justify-content: flex-end; }
.tile.has img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile.has .cap { position: relative; width: 100%; background: rgba(0,0,0,.6); color: #fff; font-size: 13px; padding: 6px 8px; }
.tile.add { border-style: dashed; color: var(--primary); }
.tile .spin { font-size: 13px; color: var(--muted); }

.sigbox { border: 1.5px solid var(--line); border-radius: 14px; background: #fff; min-height: 150px; display: grid; place-items: center; overflow: hidden; }
.sigbox img { max-width: 100%; max-height: 180px; }

.actionbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--card);
  border-top: 1px solid var(--line); padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); }
.actionbar .inner { max-width: 600px; margin: 0 auto; }
.actionbar .hint { font-size: 13px; color: var(--muted); text-align: center; margin-bottom: 6px; }

.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: flex; align-items: flex-end; }
.sheet { background: var(--card); width: 100%; max-width: 600px; margin: 0 auto; border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto; }
.sheet .grab { width: 44px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 12px; }
.sheet.full { height: 92vh; display: flex; flex-direction: column; }
.opt { display: flex; align-items: center; gap: 12px; padding: 14px 4px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 16px; }
.opt.on { color: var(--primary); font-weight: 600; }
.opt.on::after { content: "✓"; margin-left: auto; }
.choice { display: flex; gap: 14px; align-items: center; border: 2px solid var(--line); border-radius: 16px; padding: 16px;
  margin-bottom: 10px; cursor: pointer; background: var(--card); width: 100%; font: inherit; color: var(--text); text-align: left; }
.choice .ic { font-size: 30px; }
.choice.on { border-color: var(--primary); background: var(--primary-soft); }
.miss li { margin: 6px 0; }
.miss button { background: none; border: 0; color: var(--primary); font: inherit; font-weight: 600; padding: 0; cursor: pointer; text-decoration: underline; }
canvas.sig { width: 100%; flex: 1; min-height: 260px; background: #fff; border: 1.5px solid var(--line); border-radius: 14px; touch-action: none; }

#toast { position: fixed; left: 16px; right: 16px; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 50;
  max-width: 560px; margin: 0 auto; background: #101828; color: #fff; padding: 13px 16px; border-radius: 14px; font-size: 15px; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
#toast.err { background: var(--danger); }
