[hidden] { display: none !important; }
:root {
  --ink: #10202b;
  --ink2: #4a5a66;
  --mute: #8a97a1;
  --line: #e3e8ec;
  --bg: #f3f5f7;
  --card: #ffffff;
  --load: #f07f1a;
  --load-soft: #fff1e3;
  --unload: #0f9f86;
  --unload-soft: #e0f6f1;
  --accent: var(--load);
  --accent-soft: var(--load-soft);
  --bad: #e0453a;
  --ok: #14a05a;
  --r: 18px;
  --shadow: 0 1px 2px rgba(16,32,43,.06), 0 6px 20px rgba(16,32,43,.07);
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
body.m-unload { --accent: var(--unload); --accent-soft: var(--unload-soft); }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { min-height: 100dvh; font-size: 17px; line-height: 1.45; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: 'Kanit', 'IBM Plex Sans Thai', sans-serif; font-weight: 600; margin: 0; line-height: 1.2; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
  background: var(--ink); color: #fff;
}
.top-back { width: 44px; height: 44px; border: 0; border-radius: 12px; background: rgba(255,255,255,.1); display: grid; place-items: center; flex: none; }
.top-back svg { width: 24px; height: 24px; fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.brand img { width: 36px; height: 36px; border-radius: 9px; }
.brand b { display: block; font-family: 'Kanit', sans-serif; font-weight: 600; font-size: 18px; line-height: 1.1; }
.brand small { display: block; font-size: 11.5px; opacity: .6; letter-spacing: .02em; }
.net { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 6px 10px; border-radius: 99px; background: rgba(255,255,255,.1); white-space: nowrap; }
.net i { width: 8px; height: 8px; border-radius: 50%; background: #3ddc84; }
.net.off i { background: #ff6b5e; }
.net.wait i { background: #ffc233; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }

main { max-width: 560px; margin: 0 auto; padding: 18px 16px calc(120px + var(--safe-b)); }

/* ---------- common ---------- */
.step { font-size: 13px; font-weight: 600; letter-spacing: .04em; color: var(--accent); text-transform: uppercase; margin-bottom: 4px; }
.title { font-size: 26px; margin-bottom: 6px; }
.sub { color: var(--ink2); margin: 0 0 18px; }
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; }
.label { font-weight: 600; margin: 20px 0 8px; display: block; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; min-height: 60px; padding: 12px 18px; border: 0; border-radius: 16px;
  font-family: 'Kanit', sans-serif; font-weight: 600; font-size: 20px;
  background: var(--accent); color: #fff; box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: transform .08s, opacity .2s;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .35; box-shadow: none; }
.btn.ghost { background: #fff; color: var(--ink); box-shadow: inset 0 0 0 2px var(--line); }
.btn.dark { background: var(--ink); box-shadow: none; }
.btn.small { min-height: 48px; font-size: 17px; border-radius: 14px; }
.btn svg { width: 26px; height: 26px; flex: none; }

.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  padding: 12px 16px calc(12px + var(--safe-b));
  background: linear-gradient(to top, var(--bg) 70%, rgba(243,245,247,0));
}
.dock > div { max-width: 560px; margin: 0 auto; display: grid; gap: 10px; }

/* ---------- home ---------- */
.hello { margin: 4px 0 18px; }
.hello h1 { font-size: 28px; }
.hello p { margin: 4px 0 0; color: var(--ink2); }
.mode {
  position: relative; display: grid; grid-template-columns: 76px 1fr; gap: 16px; align-items: center;
  width: 100%; text-align: left; padding: 20px 18px; margin-bottom: 14px;
  border: 0; border-radius: 22px; color: #fff; overflow: hidden;
  box-shadow: var(--shadow); transition: transform .08s;
}
.mode:active { transform: scale(.985); }
.mode.load { background: linear-gradient(135deg, #f7952f, #e46a0c); }
.mode.unload { background: linear-gradient(135deg, #17b497, #0b8570); }
.mode .ico { width: 76px; height: 76px; border-radius: 20px; background: rgba(255,255,255,.18); display: grid; place-items: center; }
.mode .ico svg { width: 50px; height: 50px; }
.mode h2 { font-size: 24px; }
.mode p { margin: 3px 0 0; opacity: .9; font-size: 15px; }
.mode::after { content: ''; position: absolute; right: -30px; bottom: -40px; width: 140px; height: 140px; border-radius: 50%; background: rgba(255,255,255,.08); }

.status-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.stat { background: #fff; border-radius: 16px; padding: 12px 14px; box-shadow: var(--shadow); }
.stat b { font-family: 'Kanit', sans-serif; font-size: 26px; display: block; line-height: 1.1; }
.stat span { font-size: 13px; color: var(--ink2); }
.stat.warn b { color: #d98a00; }

.recent { margin-top: 22px; }
.recent h3 { font-size: 17px; margin-bottom: 8px; color: var(--ink2); font-weight: 500; }
.rec { display: flex; gap: 12px; align-items: center; background: #fff; border-radius: 14px; padding: 10px 12px; margin-bottom: 8px; box-shadow: var(--shadow); font-size: 14.5px; }
.rec .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.rec .dot.load { background: var(--load); } .rec .dot.unload { background: var(--unload); }
.rec .grow { flex: 1; min-width: 0; }
.rec .grow b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec .grow small { color: var(--mute); }
.pill { font-size: 12.5px; padding: 3px 9px; border-radius: 99px; background: var(--bg); white-space: nowrap; font-weight: 600; }
.pill.ok { background: #e3f6ea; color: var(--ok); }
.pill.wait { background: #fff4d6; color: #a86d00; }
.pill.bad { background: #fde6e4; color: var(--bad); }

.install { margin-top: 18px; display: flex; gap: 12px; align-items: center; padding: 14px; border-radius: 16px; background: #fff; box-shadow: var(--shadow); }
.install svg { width: 34px; height: 34px; flex: none; }
.install p { margin: 0; flex: 1; font-size: 14.5px; }
.install button { border: 0; background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 12px; font-weight: 600; }
.foot-link { display: block; text-align: center; margin-top: 26px; color: var(--mute); font-size: 14px; }

/* ---------- choice tiles ---------- */
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 18px 10px;
  border: 0; border-radius: 18px; background: #fff; box-shadow: inset 0 0 0 2px var(--line), var(--shadow);
  font-weight: 600; font-size: 17px; text-align: center;
}
.choice svg { width: 54px; height: 54px; }
.choice small { font-weight: 400; color: var(--mute); font-size: 13px; line-height: 1.3; }
.choice.on { box-shadow: inset 0 0 0 3px var(--accent), 0 6px 16px color-mix(in srgb, var(--accent) 25%, transparent); background: var(--accent-soft); }

.field {
  width: 100%; min-height: 58px; padding: 12px 16px; border-radius: 16px; font-size: 19px;
  border: 2px solid var(--line); background: #fff; outline: none;
}
.field:focus { border-color: var(--accent); }

/* ---------- list picker ---------- */
.list { display: grid; gap: 10px; }
.opt {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  min-height: 62px; padding: 12px 16px; border: 0; border-radius: 16px;
  background: #fff; box-shadow: inset 0 0 0 2px var(--line); font-size: 18px; font-weight: 500;
}
.opt .pin { width: 38px; height: 38px; flex: none; border-radius: 12px; display: grid; place-items: center; background: var(--bg); }
.opt .pin svg { width: 22px; height: 22px; }
.opt .tick { margin-left: auto; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); flex: none; }
.opt.on { box-shadow: inset 0 0 0 3px var(--accent); background: var(--accent-soft); }
.opt.on .tick { border-color: var(--accent); background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 12.5l4 4 8-9' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/70% no-repeat; }
.opt.add { color: var(--accent); background: transparent; box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 45%, transparent); border: 0; justify-content: center; font-weight: 600; }
.opt.add svg { width: 24px; height: 24px; }
.addrow { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.addrow .btn { width: auto; min-height: 58px; padding: 0 22px; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; background: #e7ebee; border-radius: 16px; padding: 5px; }
.seg button { border: 0; min-height: 52px; border-radius: 12px; background: transparent; font-weight: 600; font-size: 17px; color: var(--ink2); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.seg button small { display: block; font-weight: 400; font-size: 12.5px; color: var(--mute); }

/* ---------- trip picker (unload) ---------- */
.trip {
  display: grid; grid-template-columns: 58px 1fr; gap: 12px; align-items: center; width: 100%; text-align: left;
  padding: 14px; border: 0; border-radius: 18px; background: #fff; box-shadow: inset 0 0 0 2px var(--line);
}
.trip .no { width: 58px; height: 58px; border-radius: 14px; background: var(--ink); color: #fff; display: grid; place-items: center; text-align: center; line-height: 1; }
.trip .no small { display: block; font-size: 11px; opacity: .7; }
.trip .no b { font-family: 'Kanit', sans-serif; font-size: 24px; }
.trip h3 { font-size: 18px; }
.trip p { margin: 2px 0 0; color: var(--ink2); font-size: 14px; }
.trip .chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.trip.on { box-shadow: inset 0 0 0 3px var(--accent); background: var(--accent-soft); }
.empty { text-align: center; padding: 36px 16px; color: var(--ink2); background: #fff; border-radius: 18px; box-shadow: var(--shadow); }
.empty svg { width: 70px; height: 70px; opacity: .5; }

/* ---------- boxes ---------- */
.ctx { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.ctx span { font-size: 13.5px; padding: 5px 11px; border-radius: 99px; background: #fff; box-shadow: inset 0 0 0 1.5px var(--line); }
.ctx span b { font-weight: 600; }
.counter { display: flex; align-items: center; gap: 14px; background: var(--ink); color: #fff; border-radius: 20px; padding: 16px 18px; margin-bottom: 14px; }
.counter .big { font-family: 'Kanit', sans-serif; font-size: 46px; font-weight: 600; line-height: 1; }
.counter .big small { font-size: 22px; opacity: .6; }
.counter p { margin: 0; font-size: 14.5px; opacity: .8; }
.counter .bar { height: 8px; border-radius: 4px; background: rgba(255,255,255,.15); margin-top: 8px; overflow: hidden; }
.counter .bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.boxlist { display: grid; gap: 10px; }
.boxrow { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center; background: #fff; border-radius: 16px; padding: 10px 12px; box-shadow: var(--shadow); }
.boxrow .n { font-family: 'Kanit', sans-serif; font-size: 22px; text-align: center; color: var(--accent); font-weight: 600; }
.boxrow .thumbs { display: flex; gap: 6px; }
.boxrow .thumbs img { width: 58px; height: 58px; border-radius: 10px; object-fit: cover; background: var(--bg); }
.boxrow .thumbs img.lbl { outline: 3px solid var(--accent); outline-offset: -3px; }
.boxrow .del { width: 44px; height: 44px; border: 0; border-radius: 12px; background: var(--bg); display: grid; place-items: center; }
.boxrow .del svg { width: 22px; height: 22px; stroke: var(--mute); }

/* ---------- box editor (sheet) ---------- */
.sheet { position: fixed; inset: 0; z-index: 40; background: var(--bg); overflow-y: auto; padding: calc(env(safe-area-inset-top, 0px) + 16px) 16px calc(160px + var(--safe-b)); animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet .inner { max-width: 560px; margin: 0 auto; }
.shots { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.shot {
  position: relative; aspect-ratio: 3/4; border: 0; border-radius: 18px; padding: 0; overflow: hidden;
  background: #fff; box-shadow: inset 0 0 0 2.5px var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center;
}
.shot.wide { grid-column: 1 / -1; aspect-ratio: 16/9; }
.shot svg { width: 46px; height: 46px; }
.shot b { font-size: 16.5px; }
.shot small { color: var(--mute); font-size: 13px; padding: 0 10px; }
.shot.need { box-shadow: inset 0 0 0 3px var(--accent); background: var(--accent-soft); }
.shot.next::before { content: 'ถัดไป'; position: absolute; top: 10px; left: 10px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; }
.shot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.shot .retake { position: absolute; right: 8px; bottom: 8px; background: rgba(16,32,43,.8); color: #fff; font-size: 13px; padding: 6px 10px; border-radius: 10px; }
.shot .req { position: absolute; top: 10px; right: 10px; font-size: 11.5px; font-weight: 700; color: var(--bad); }
.busy { position: absolute; inset: 0; background: rgba(255,255,255,.8); display: grid; place-items: center; font-weight: 600; }

/* ---------- done ---------- */
.done { text-align: center; padding-top: 8px; }
.done .check { width: 96px; height: 96px; margin: 6px auto 12px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; box-shadow: 0 10px 30px color-mix(in srgb, var(--accent) 40%, transparent); animation: pop .35s cubic-bezier(.2,1.6,.4,1); }
@keyframes pop { from { transform: scale(.4); } }
.done .check svg { width: 54px; height: 54px; stroke: #fff; stroke-width: 3.5; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.ticket { text-align: left; margin: 18px 0; background: #fff; border-radius: 20px; box-shadow: var(--shadow); overflow: hidden; }
.ticket .head { background: var(--ink); color: #fff; padding: 16px 18px; display: flex; align-items: center; gap: 14px; }
.ticket .head .no { font-family: 'Kanit', sans-serif; font-size: 40px; font-weight: 600; line-height: 1; }
.ticket .head small { display: block; opacity: .65; font-size: 13px; }
.ticket .head b { font-size: 18px; }
.ticket dl { margin: 0; padding: 8px 18px 14px; display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; }
.ticket dt { color: var(--mute); font-size: 14.5px; }
.ticket dd { margin: 0; font-weight: 600; }
.ticket .strip { display: flex; gap: 6px; padding: 0 18px 16px; overflow-x: auto; }
.ticket .strip img { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; flex: none; }
.cmp { margin: 0 18px 16px; border-radius: 14px; padding: 12px 14px; font-weight: 600; display: flex; gap: 10px; align-items: center; }
.cmp.ok { background: #e3f6ea; color: #0d7a43; }
.cmp.bad { background: #fde6e4; color: #b3261e; }
.cmp.wait { background: #fff4d6; color: #8a5a00; }

.toast { position: fixed; left: 50%; bottom: calc(150px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 14px; font-size: 15px; opacity: 0; pointer-events: none; transition: .25s; z-index: 60; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%); }

.modal { position: fixed; inset: 0; z-index: 70; background: rgba(16,32,43,.55); display: grid; place-items: end center; padding: 16px; }
.modal .box { width: 100%; max-width: 520px; background: #fff; border-radius: 22px; padding: 20px; margin-bottom: var(--safe-b); animation: up .2s; }
.modal h3 { font-size: 21px; margin-bottom: 6px; }
.modal p { margin: 0 0 16px; color: var(--ink2); }
.modal .btns { display: grid; gap: 10px; }
