/* งานเปลี่ยนเราเตอร์ — มือถือเป็นหลัก ตัวหนังสือชัด ปุ่มใหญ่ ใช้กลางแจ้งได้ */
:root {
  --ink: #14202b; --mute: #55626f; --bg: #f3f5f7; --card: #fff; --line: #d3dae1;
  --brand: #0f4c75; --brand-ink: #fff; --focus: #f59e0b;
  --ok: #17703a; --ok-bg: #e0f3e6; --info: #1b56b0; --info-bg: #e1ecfb;
  --warn: #97480a; --warn-bg: #fdefd8; --bad: #b42318; --bad-bg: #fde7e4; --off: #4b5563; --off-bg: #e5e8eb;
  --nav-h: 62px; --radius: 12px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 "Sarabun", "Noto Sans Thai", "Leelawadee UI", "Thonburi", system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow-wrap: anywhere;
}
[hidden] { display: none !important; }
h1 { font-size: 1.4rem; line-height: 1.3; margin: 0 0 12px; }
h2 { font-size: 1.05rem; margin: 24px 0 10px; }
p { margin: 0 0 10px; }
a { color: var(--brand); }
.mute { color: var(--mute); } .small { font-size: .875rem; } .center { text-align: center; margin: 16px 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ── แถบบน + เมนูหลัก ── */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 6px 16px; background: var(--brand); color: var(--brand-ink); }
.brand { color: inherit; text-decoration: none; font-weight: 700; flex: 1; }
.who { font-size: .875rem; opacity: .9; max-width: 40%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(4, 1fr); height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--card); border-top: 1px solid var(--line); }
.tabs a, .tabs button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; border: 0; background: none; color: var(--mute); font: inherit; font-size: .8rem; text-decoration: none; cursor: pointer; min-height: 44px; }
.tabs .ico { font-size: 1.35rem; line-height: 1.2; }
.tabs .on { color: var(--brand); font-weight: 700; }
.tabs .tab-new { color: var(--brand); font-weight: 700; }
.app { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + 32px + env(safe-area-inset-bottom)); }
@media (min-width: 820px) {
  .tabs { position: static; display: flex; height: auto; padding: 0; background: none; border: 0; gap: 4px; order: 2; }
  .tabs a, .tabs button { flex-direction: row; gap: 6px; color: #fff; opacity: .85; font-size: .95rem; padding: 6px 12px; border-radius: 8px; }
  .tabs .on, .tabs .tab-new { color: #fff; opacity: 1; background: rgba(255,255,255,.16); }
  .tabs .ico { font-size: 1.05rem; }
  .who { order: 3; max-width: 160px; }
  .app { padding-bottom: 48px; }
}

/* ── ปุ่มและฟอร์ม ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 10px 18px; border: 1.5px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); border-color: #e7b3ad; }
.btn.big { width: 100%; min-height: 56px; font-size: 1.1rem; }
.btn.sm { min-height: 44px; padding: 6px 12px; font-size: .9rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.stack { display: grid; gap: 10px; } .stack > p { margin: -4px 0 6px; }
.btn-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 12px 0; }
label { display: block; font-weight: 600; margin: 14px 0 4px; }
input, select, textarea { width: 100%; min-height: 48px; padding: 10px 12px; border: 1.5px solid #9aa6b2; border-radius: 10px; background: #fff; color: var(--ink); font: inherit; }
textarea { min-height: 96px; resize: vertical; }
input[type=checkbox] { width: 26px; height: 26px; min-height: 0; flex: none; accent-color: var(--brand); }
.check { display: flex; align-items: center; gap: 12px; font-weight: 600; margin: 16px 0; padding: 12px; border: 1.5px solid var(--line); border-radius: var(--radius); background: #fff; cursor: pointer; }
.form-error { color: var(--bad); background: var(--bad-bg); padding: 10px 12px; border-radius: 10px; margin: 12px 0; font-weight: 600; }
.notice { background: var(--warn-bg); color: var(--warn); padding: 12px; border-radius: var(--radius); margin: 12px 0; font-weight: 600; }
.notice .btn { margin-top: 8px; }
.with-btn { display: flex; gap: 8px; } .with-btn input { flex: 1; min-width: 0; }

/* ── การ์ดและป้ายสถานะ ── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 12px; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .85rem; font-weight: 700; white-space: nowrap; background: var(--off-bg); color: var(--off); }
.st-recorded { --c: var(--warn); --b: var(--warn-bg); } .st-configured { --c: var(--info); --b: var(--info-bg); }
.st-swapped { --c: var(--ok); --b: var(--ok-bg); } .st-cancelled, .st-pending { --c: var(--off); --b: var(--off-bg); }
.st-problem { --c: var(--bad); --b: var(--bad-bg); }
.badge[class*="st-"] { color: var(--c); background: var(--b); }
.warn { color: var(--bad); }
.empty { text-align: center; padding: 40px 12px; color: var(--mute); } .loading { color: var(--mute); padding: 24px 0; text-align: center; }

/* ── ล็อกอิน ── */
.login { max-width: 380px; margin: 8vh auto 0; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 24px 20px; }
.login .btn { margin-top: 20px; }

/* ── รายการจุด ── */
.list-head { position: sticky; top: 48px; z-index: 5; background: var(--bg); padding: 4px 0 8px; margin-top: -4px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 4px 14px; border: 1.5px solid var(--line); border-radius: 999px; background: #fff; color: var(--ink); font: inherit; font-size: .9rem; cursor: pointer; }
.chip b { color: var(--c, var(--mute)); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; } .chip.on b { color: #fff; }
.rows { display: grid; gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); color: inherit; text-decoration: none; min-height: 64px; }
.row-main { flex: 1; min-width: 0; display: grid; }
.code { font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── หน้าสรุป ── */
.big-num { font-size: 1.1rem; } .big-num b { font-size: 2.4rem; line-height: 1.1; color: var(--ok); }
.bar { height: 16px; background: var(--off-bg); border-radius: 999px; overflow: hidden; margin: 8px 0; } .bar span { display: block; height: 100%; background: var(--ok); min-width: 2px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: 8px; }
.tile { display: grid; padding: 12px; background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--c, var(--line)); border-radius: var(--radius); color: inherit; text-decoration: none; }
.tile b { font-size: 1.6rem; line-height: 1.2; } .tile span { font-size: .875rem; color: var(--mute); }
.steps { padding-left: 22px; } .steps li { margin-bottom: 10px; }

/* ── หน้าจุด ── */
.site-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.site-code { font-size: 1.6rem; font-weight: 800; letter-spacing: .02em; }
.site-name { font-size: 1.2rem; font-weight: 700; margin: 2px 0 12px; }
.problem-box { background: var(--bad-bg); color: var(--bad); border-radius: var(--radius); padding: 12px 14px; margin: 0 0 12px; font-weight: 600; }
.old-card { border: 2px solid var(--ink); }
.old-card h2, .group h2 { margin: 0 0 6px; font-size: .9rem; color: var(--mute); font-weight: 700; }
.old-card .kv dd { font-size: 1.15rem; font-weight: 700; }
.kv { display: grid; grid-template-columns: minmax(96px, 36%) 1fr; gap: 6px 12px; margin: 0; }
.kv dt { color: var(--mute); font-size: .9rem; padding-top: 2px; } .kv dd { margin: 0; white-space: pre-wrap; }
.secret { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.secret code { font: 600 1.05rem ui-monospace, Consolas, monospace; letter-spacing: .04em; }
.mini { min-height: 44px; min-width: 44px; padding: 4px 10px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; font: inherit; font-size: .85rem; cursor: pointer; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; margin: 0 0 12px; }
.photos button, .thumb { position: relative; aspect-ratio: 1; padding: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #dfe4e9; cursor: pointer; }
.photos img, .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tag { position: absolute; left: 4px; bottom: 4px; padding: 0 6px; border-radius: 6px; background: rgba(0,0,0,.72); color: #fff; font-size: .7rem; }
.thumb .state { position: absolute; inset: auto 0 0 0; padding: 2px 4px; background: rgba(0,0,0,.72); color: #fff; font-size: .72rem; text-align: center; }
.thumb .rm { position: absolute; top: 2px; right: 2px; width: 32px; height: 32px; border: 0; border-radius: 50%; background: rgba(0,0,0,.72); color: #fff; font-size: 1rem; cursor: pointer; }
.full-photo { max-width: 100%; max-height: 70vh; display: block; margin: 0 auto 12px; }
.meta { color: var(--mute); font-size: .875rem; margin-top: 16px; }
details.hist { margin-top: 12px; } details.hist summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; }
.hist ul { list-style: none; padding: 0; margin: 0; } .hist li { padding: 8px 0; border-top: 1px solid var(--line); font-size: .9rem; }
.confirm-old { border: 2px solid var(--ink); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 4px; }
.confirm-old b { display: block; font-size: 1.5rem; line-height: 1.3; }

/* ── ฟอร์มบันทึก ── */
details.grp { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
details.grp > summary { cursor: pointer; padding: 14px 16px; font-weight: 700; min-height: 52px; display: flex; align-items: center; justify-content: space-between; list-style: none; }
details.grp > summary::-webkit-details-marker { display: none; }
details.grp > summary::after { content: "▾"; color: var(--mute); } details.grp[open] > summary::after { content: "▴"; }
details.grp .fields { padding: 0 16px 16px; } details.grp .fields label:first-child { margin-top: 0; }
.filled { color: var(--ok); font-weight: 600; font-size: .85rem; margin-left: auto; margin-right: 10px; }
.save-bar { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 6; margin: 16px -16px 0; padding: 10px 16px; background: rgba(243,245,247,.96); border-top: 1px solid var(--line); display: flex; gap: 10px; }
.save-bar .btn.primary { flex: 1; }
@media (min-width: 820px) { .save-bar { bottom: 0; } }
.pick { display: flex; align-items: center; justify-content: center; min-height: 56px; border: 2px dashed #8d99a6; border-radius: var(--radius); background: #fff; font-weight: 700; cursor: pointer; margin-bottom: 10px; }
.pick input { position: absolute; width: 1px; height: 1px; opacity: 0; min-height: 0; }
.pick:focus-within { outline: 3px solid var(--focus); }

/* ── แผ่น dialog ── */
dialog.sheet { width: min(100%, 520px); max-width: 100%; max-height: 92dvh; margin: auto auto 0; padding: 0; border: 0; border-radius: 18px 18px 0 0; color: inherit; overflow: auto; }
dialog.sheet.wide { width: min(100%, 760px); }
dialog.sheet::backdrop { background: rgba(10, 20, 30, .55); }
@media (min-width: 620px) { dialog.sheet { margin: auto; border-radius: 18px; } }
.sheet-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; background: #fff; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; } .sheet-body { padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); }
.x { width: 44px; height: 44px; border: 0; background: none; font-size: 1.2rem; cursor: pointer; border-radius: 50%; }
.menu { display: grid; gap: 8px; } .menu-item { display: flex; align-items: center; min-height: 52px; padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; text-align: left; cursor: pointer; }
.menu-item.danger { color: var(--bad); }
.sticker-preview { display: block; max-width: 100%; margin: 0 auto 12px; border: 1px solid var(--line); image-rendering: pixelated; }

/* ── ตั้งค่า / ผู้ใช้ ── */
.frow { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.frow:first-of-type { border-top: 0; } .frow .grow { flex: 1; min-width: 0; } .frow.off .grow { color: var(--mute); text-decoration: line-through; }
.type { font-size: .78rem; color: var(--mute); display: block; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; } .seg label { margin: 0; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: 48px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; font-weight: 600; cursor: pointer; }
.seg input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 60; max-width: 480px; margin: 0 auto; padding: 12px 16px; border-radius: var(--radius); background: #14202b; color: #fff; font-weight: 600; text-align: center; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.toast.bad { background: var(--bad); }
@media (prefers-reduced-motion: no-preference) { .bar span { transition: width .4s ease; } }

/* ── ล็อกอินทับหน้าปัจจุบัน + ช่องรหัสลับ ── */
dialog.login-overlay { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 16px; border: 0; background: var(--bg); color: inherit; }
dialog.login-overlay::backdrop { background: var(--bg); }
input.masked { -webkit-text-security: disc; font-family: ui-monospace, Consolas, monospace; }
