:root {
  --bg: #f3f5f7; --card: #fff; --ink: #14212b; --muted: #5d6b76; --line: #dde3e8;
  --brand: #0f3d5e; --brand-2: #1b6a9b; --ok: #12805c; --ok-bg: #e3f4ec; --warn: #b4540a; --warn-bg: #fdf0e1;
  --danger: #b42318; --danger-bg: #fdecea; --wait: #6941c6; --wait-bg: #f0ebfb;
  --radius: 14px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e151b; --card: #17222b; --ink: #e7edf2; --muted: #93a3b0; --line: #2a3a46;
    --brand: #4aa3df; --brand-2: #6cb8ea; --ok: #4cc79a; --ok-bg: #12352a; --warn: #f0a35a; --warn-bg: #3a2814;
    --danger: #f2877d; --danger-bg: #3d1a17; --wait: #b49cf2; --wait-bg: #2a2140;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 'IBM Plex Sans Thai', system-ui, sans-serif; padding-bottom: 84px; }
a { color: var(--brand-2); text-decoration: none; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
.wrap { max-width: 760px; margin: 0 auto; padding: 14px 16px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .center { text-align: center; }
.mono { font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace; letter-spacing: .5px; }
.warn { color: var(--warn); font-weight: 600; }

/* top / tab bars */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 16px; background: var(--brand); color: #fff; }
.topbar a { color: #fff; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.who { font-size: 13px; opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: #fff; color: #0f3d5e; font-weight: 800; }
.logo.big { width: 56px; height: 56px; font-size: 28px; border-radius: 16px; background: var(--brand); color: #fff; }
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 10px; color: var(--muted); font-size: 12px; }
.tabbar a.on { color: var(--brand); font-weight: 600; }
.tabbar svg { width: 24px; height: 24px; }

/* cards & layout */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card h3 { font-size: 16px; color: var(--brand); }
.stack > * { margin-bottom: 14px; }
.page { font-size: 22px; }
.sec { font-size: 16px; margin: 20px 0 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 12px; }
@media (max-width: 420px) { .grid3 { grid-template-columns: 1fr 1fr; } }
.btnrow { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 10px 0; }
.btnrow.center { justify-content: center; }

/* forms */
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 10px; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 11px 12px; font: inherit; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; min-height: 46px; }
input:focus, select:focus { outline: 2px solid var(--brand-2); outline-offset: 0; border-color: transparent; }
label.check { display: flex; gap: 10px; align-items: flex-start; color: var(--ink); font-size: 14px; }
label.check input { width: 22px; height: 22px; min-height: 0; margin: 1px 0 0; flex: none; }
label.check.inline { margin: 0; }
.hp { position: absolute; left: -9999px; }
.inline-form { display: flex; gap: 8px; margin-top: 10px; }
.inline-form input { margin: 0; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.seg label { margin: 0; }
.seg input { position: absolute; opacity: 0; width: 0; height: 0; }
.seg span { display: inline-block; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink); font-size: 14px; }
.seg input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 8px; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 14px; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 16px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.out { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.block { width: 100%; } .btn.lg { min-height: 56px; font-size: 18px; } .btn.sm { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn:disabled { opacity: .6; }

/* dashboard */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.action { display: flex; flex-direction: column; gap: 4px; padding: 16px; border-radius: var(--radius); background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.action.primary { background: var(--brand); color: #fff; }
.action svg { width: 30px; height: 30px; }
.action b { font-size: 17px; } .action small { opacity: .8; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--card); border-radius: 12px; padding: 10px 6px; text-align: center; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 26px; line-height: 1.1; } .stat span { font-size: 12px; color: var(--muted); }
.stat.hi b { color: var(--ok); }

.list { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 12px; background: var(--card); color: var(--ink); padding: 12px 14px; border-radius: 12px; box-shadow: var(--shadow); }
.row b, .row small { display: block; } .row small { color: var(--muted); font-size: 13px; }
.row .grow, .grow { flex: 1; min-width: 0; color: var(--ink); }
.thumb { width: 54px; height: 38px; border-radius: 6px; object-fit: cover; flex: none; background: var(--bg); display: grid; place-items: center; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 24px; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.in { background: var(--ok-bg); color: var(--ok); } .pill.wait { background: var(--wait-bg); color: var(--wait); }
.pill.outp { background: var(--bg); color: var(--muted); }

/* capture */
.shots { display: grid; grid-template-columns: 1.6fr 1fr; gap: 10px; }
.shots.one { grid-template-columns: 1fr; }
.shot { position: relative; aspect-ratio: 1.58; border: 2px dashed var(--line); border-radius: 12px; background: var(--bg); color: var(--muted);
  font: inherit; font-size: 14px; overflow: hidden; padding: 0; cursor: pointer; }
.shot.face { aspect-ratio: auto; }
.shot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; }
.shot.has { border-style: solid; border-color: var(--ok); } .shot.has img { display: block; } .shot.has span { display: none; }

.cam { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column; }
.cam video { flex: 1; width: 100%; object-fit: cover; min-height: 0; }
.cam .guide { position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); border: 3px solid rgba(255,255,255,.9); border-radius: 14px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.cam .guide.card { width: 86vw; max-width: 560px; aspect-ratio: 1.58; }
.cam .guide.face { width: 60vw; max-width: 320px; aspect-ratio: .78; border-radius: 50%; }
.cam .guide span { transform: translateY(150%); color: #fff; font-size: 14px; text-align: center; }
.camctl { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px calc(16px + env(safe-area-inset-bottom)); background: #000; }
.camctl .btn { background: #222; color: #fff; border-color: #333; }
.shutter { width: 72px; height: 72px; border-radius: 50%; border: 5px solid #fff; background: #fff; box-shadow: inset 0 0 0 3px #000; cursor: pointer; }

/* scan result / visit */
.reader { width: 100%; max-width: 420px; margin: 0 auto; border-radius: 12px; overflow: hidden; }
.vhead { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.photos { display: flex; gap: 10px; margin: 8px 0 14px; overflow-x: auto; }
.photos a { flex: none; text-align: center; color: var(--muted); font-size: 12px; }
.photos img { display: block; height: 130px; max-width: 220px; object-fit: cover; border-radius: 10px; box-shadow: var(--shadow); }
.purged { padding: 20px; border-radius: 10px; background: var(--bg); color: var(--muted); font-size: 13px; text-align: center; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; margin: 0; }
.kv dt { color: var(--muted); font-size: 14px; } .kv dd { margin: 0; word-break: break-word; }
.logrow { display: grid; grid-template-columns: 120px 90px 1fr; gap: 6px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.logrow span:last-child { grid-column: 2 / -1; }

.done { text-align: center; padding: 28px 16px; }
.done .ok { width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 50%; background: var(--ok-bg); color: var(--ok); font-size: 34px; display: grid; place-items: center; }
.done .btnrow { justify-content: center; }

/* modal & toast */
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 520px; border-radius: 18px 18px 0 0; padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 600px) { .modal { align-items: center; } .sheet { border-radius: 18px; } }
.sheet .btnrow { justify-content: flex-end; }
.toast { position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 20px); opacity: 0; transition: .2s; z-index: 60;
  background: #14212b; color: #fff; padding: 12px 18px; border-radius: 12px; max-width: 90vw; text-align: center; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); }
.alert { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; }
.alert.err { background: var(--danger-bg); color: var(--danger); } .alert.ok { background: var(--ok-bg); color: var(--ok); }

/* login / public */
.login { max-width: 380px; margin: 8vh auto 0; text-align: center; }
.login .card { text-align: left; margin-top: 16px; }
.public-head { text-align: center; margin: 10px 0 16px; }
.public-head h1 { font-size: 20px; margin-top: 10px; }
.pass { max-width: 380px; margin: 4vh auto; text-align: center; background: var(--card); padding: 24px 18px; border-radius: 18px; box-shadow: var(--shadow); }
.pass h1 { letter-spacing: 4px; color: var(--brand); }
.pass .qr { display: inline-block; padding: 12px; background: #fff; border-radius: 12px; }
.pass .code { font-size: 20px; margin: 6px 0 10px; }
.pass .note { background: var(--bg); border-radius: 12px; padding: 12px; margin-top: 14px; font-size: 14px; }
.userrow .grid2 { margin-top: 8px; }

/* LINE */
.pill.err { background: var(--danger-bg); color: var(--danger); }
.lpill { margin: 3px 0; }
.howto { display: flex; gap: 16px; align-items: center; }
.howto ol { margin: 6px 0; padding-left: 20px; }
.qrbox { flex: none; padding: 8px; background: #fff; border-radius: 10px; min-width: 136px; min-height: 136px; }
@media (max-width: 480px) { .howto { flex-direction: column; text-align: center; } .howto ol { text-align: left; } }
.hostrow { margin: 0; padding: 12px 14px; }
.hostrow summary { display: flex; align-items: center; gap: 10px; cursor: pointer; list-style: none; }
.hostrow summary::-webkit-details-marker { display: none; }
.hostrow summary b, .hostrow summary small { display: block; }
.hostrow form { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
textarea { min-height: 120px; }

/* Blacklist */
.blbox { border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; background: var(--warn-bg); color: var(--warn); border: 1px solid currentColor; }
.blbox.deny { background: var(--danger-bg); color: var(--danger); }
.blbox p { margin: 4px 0; }

/* พนักงานออกนอก */
.empsearch { margin-top: 10px; }
.empsearch .list { margin-top: 8px; }
.triptypes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 12px 0; }
.tbtn { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 14px 8px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.tbtn span { font-size: 28px; line-height: 1.1; }
.tbtn small { font-weight: 400; color: var(--muted); }
.tbtn.main { grid-column: 1 / -1; background: var(--brand); color: #fff; border-color: var(--brand); padding: 18px; font-size: 18px; }
.tbtn.main small { color: #cfe3f2; }
.tripnow { background: var(--wait-bg); color: var(--wait); border-radius: 12px; padding: 12px 14px; margin: 12px 0; font-weight: 600; }
.tripnow.over { background: var(--warn-bg); color: var(--warn); }
.tripnow .small { font-weight: 400; }
