/* ระบบตรวจเวรยาม รปภ. — ธีมน้ำเงิน โลโก้กระทรวงสาธารณสุข, ใช้บนมือถือเป็นหลัก */
:root {
  --bg: #eef3fb;
  --card: #ffffff;
  --ink: #0b1b3a;
  --muted: #51607a;
  --line: #dde5f2;
  --brand: #1d4ed8;
  --brand-2: #2563eb;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --warn-bg: #fef3c7;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(15, 30, 70, .06), 0 10px 28px -14px rgba(15, 30, 70, .28);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; color: var(--ink);
  font-family: Anuphan, "Sarabun", "Leelawadee UI", system-ui, sans-serif; font-size: 16px; line-height: 1.55;
  background: linear-gradient(170deg, #f4f7fd 0%, var(--bg) 40%, #dfe8f8 100%) fixed;
  padding-bottom: 96px;
}
body.no-scroll { overflow: hidden; }
a { color: var(--brand); }
h1 { font-size: 1.45rem; margin: 0 0 .4rem; line-height: 1.3; }
h2 { font-size: 1.12rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small, small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.req { color: var(--bad); }
.grow { flex: 1; min-width: 0; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px;
  padding: 10px 16px; background: rgba(255, 255, 255, .9); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand b { display: block; font-size: 1rem; line-height: 1.2; }
.brand small { display: block; color: var(--muted); font-size: .75rem; }
.shield { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(160deg, #60a5fa, var(--brand)); box-shadow: 0 6px 14px -6px rgba(37, 99, 235, .6); }
.shield svg { width: 22px; height: 22px; }
.menu { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.menu a { padding: 6px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 500; white-space: nowrap; }
.menu a.on, .menu a:hover { background: var(--ok-bg); color: var(--brand); }
.who { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.who form { margin: 0; }
@media (max-width: 720px) {
  .menu { order: 3; flex-basis: 100%; }
  .who { margin-left: auto; }
}

/* ---------- layout ---------- */
.wrap { width: min(1100px, 100%); margin: 0 auto; padding: 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card.narrow { width: min(440px, 100%); margin: 24px auto 0; }
.card.narrow-wide { width: min(720px, 100%); margin: 0 auto; }
.head-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.head-row h1, .head-row h2 { margin: 0; }

/* ---------- forms ---------- */
label { display: grid; gap: 4px; font-weight: 500; margin-bottom: 12px; }
input, select, textarea {
  font: inherit; color: inherit; width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fbfcff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(37, 99, 235, .35); border-color: var(--brand-2); }
label.check { display: flex; align-items: center; gap: 8px; }
label.check input { width: 20px; height: 20px; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid-form .span2, .grid-form h2 { grid-column: 1 / -1; }
.grid-form h2 { margin-top: 10px; }
@media (max-width: 640px) { .grid-form { grid-template-columns: 1fr; } }
.with-btn { display: flex; gap: 8px; }
.with-btn .btn { flex: none; }
@media (max-width: 480px) { .with-btn { flex-direction: column; } }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
form.inline { display: inline; margin: 0; }
form.inline select { width: auto; padding: 4px 8px; }
.filters { display: flex; flex-wrap: wrap; gap: 0 10px; align-items: end; }
.filters label { flex: 1 1 150px; margin-bottom: 10px; }
.filters .btn { margin-bottom: 10px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  white-space: nowrap; flex-shrink: 0; word-break: normal; overflow-wrap: normal;
}
.btn:hover { background: #f1f5fd; }
.btn.primary { background: linear-gradient(135deg, #3b82f6 0%, #2563eb 55%, #1d4ed8 100%); border-color: transparent; color: #fff; box-shadow: 0 8px 18px -8px rgba(37, 99, 235, .7), inset 0 1px 0 rgba(255, 255, 255, .25); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.primary:disabled { opacity: .6; cursor: wait; }
.btn.block { display: flex; width: 100%; margin-top: 8px; }
.btn.big { padding: 14px 20px; font-size: 1.08rem; }
.btn.small { padding: 4px 10px; font-size: .82rem; border-radius: 8px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.danger { color: #fff; background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%); border-color: transparent; box-shadow: 0 6px 16px -6px rgba(220, 38, 38, .6); }
.btn.danger:hover { filter: brightness(1.06); }
button.link { border: 0; background: none; color: var(--bad); font: inherit; cursor: pointer; padding: 0; }

/* ---------- flash / chips ---------- */
.flash { padding: 10px 14px; border-radius: 12px; background: var(--ok-bg); color: #14532d; border: 1px solid #bbf7d0; margin: 0; }
.flash.error { background: var(--bad-bg); color: #7f1d1d; border-color: #fecaca; }
.flash.big { font-size: 1.05rem; font-weight: 600; }
.chip { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: #eef2f8; color: var(--muted); white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.warn { background: #fef3c7; color: #92400e; }
.chip.big { font-size: 1rem; padding: 6px 14px; }
.badge-num { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; font-size: .72rem; font-weight: 800; border-radius: 999px; background: #ef4444; color: #fff; line-height: 1; vertical-align: middle; margin-left: 2px; }
.hero-btns { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.sos-alert-card { border: 2px solid #f87171; background: #fff5f5; }
.category-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; margin-top: 6px; }
.cat-opt { margin: 0; cursor: pointer; }
.cat-opt input { position: absolute; opacity: 0; pointer-events: none; }
.cat-opt span { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 2px solid var(--line); border-radius: 12px; background: #fff; font-weight: 600; font-size: .92rem; transition: border-color .15s, background .15s; }
.cat-opt input:checked + span { border-color: var(--bad); background: #fef2f2; color: #991b1b; }
.cat-opt .cat-icon { font-size: 1.35rem; }
.cat-badge { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; }
.tabs-nav { display: flex; flex-wrap: wrap; gap: 6px; }
.tabs-nav .chip { text-decoration: none; padding: 6px 14px; font-size: .85rem; }
.tabs-nav .chip.active { outline: 2px solid currentColor; font-weight: 700; }

/* ---------- home ---------- */
.hero { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between; }
.hero > div { flex: 1 1 260px; }
.hero .num { color: var(--brand-2); }
.hero-top-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.view-switch { display: flex; gap: 4px; background: rgba(0, 0, 0, .2); padding: 3px; border-radius: 999px; }
.view-switch a.chip { text-decoration: none; color: rgba(255, 255, 255, .85); background: transparent; padding: 3px 10px; font-size: .75rem; border-radius: 999px; }
.view-switch a.chip.active { background: #fff; color: #1d4ed8; font-weight: 700; box-shadow: 0 2px 6px rgba(0, 0, 0, .2); }
.period-badge { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; font-weight: 600; background: rgba(255, 255, 255, .2); padding: 4px 10px; border-radius: 8px; margin-bottom: 6px; }
.progress { height: 10px; border-radius: 999px; background: #e3eaf7; overflow: hidden; margin-top: 8px; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, #60a5fa, var(--brand)); border-radius: inherit; }
.points, .list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.points li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.points li small { display: block; }
.points .right { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; text-align: right; }
.points .dot { width: 12px; height: 12px; border-radius: 50%; background: #cbd3e0; flex: none; }
.points li.done .dot { background: var(--brand-2); box-shadow: 0 0 0 4px var(--ok-bg); }
.points li.alert { border-color: #fecaca; background: #fff7f7; }
.points li.alert .dot { background: var(--bad); box-shadow: 0 0 0 4px var(--bad-bg); }
.list a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: inherit; }
.list .time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--brand); }

/* floating scan button */
.fab {
  position: fixed; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 30; display: flex; align-items: center; gap: 8px;
  padding: 14px 20px; border-radius: 999px; background: linear-gradient(180deg, #3b82f6, var(--brand)); color: #fff; text-decoration: none; font-weight: 700;
  box-shadow: 0 14px 30px -10px rgba(37, 99, 235, .75);
}
.fab svg { width: 24px; height: 24px; }

/* ---------- scanner ---------- */
.scanner-card { width: min(520px, 100%); margin: 0 auto; text-align: center; }
.viewfinder { position: relative; aspect-ratio: 1; border-radius: 18px; overflow: hidden; background: #0b1530; margin: 12px 0; }
.viewfinder video { width: 100%; height: 100%; object-fit: cover; display: block; }
.viewfinder .frame { position: absolute; inset: 18%; border: 3px solid rgba(255, 255, 255, .9); border-radius: 18px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .35); }
.status { font-weight: 600; }
.torch-btn { margin: 10px 0; background: #f8fafc; color: #1e293b; border: 2px solid #cbd5e1; font-weight: 700; padding: 12px; border-radius: 12px; font-size: 1rem; }
.torch-btn.active { background: #fef08a; color: #854d0e; border-color: #eab308; }

/* ---------- report form ---------- */
.report { width: min(640px, 100%); margin: 0 auto; }
.gps-box { padding: 10px 14px; border-radius: 12px; background: #eef2f8; color: var(--muted); font-weight: 600; margin: 10px 0 16px; }
.gps-box.ok { background: var(--ok-bg); color: var(--ok); }
.gps-box.bad { background: var(--bad-bg); color: var(--bad); }
.status-pick { border: 0; padding: 0; margin: 0 0 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.status-pick legend { font-weight: 600; margin-bottom: 8px; }
.status-pick .opt { margin: 0; cursor: pointer; }
.status-pick .opt input { position: absolute; opacity: 0; pointer-events: none; }
.status-pick .opt span { display: block; text-align: center; padding: 16px 10px; border: 2px solid var(--line); border-radius: 14px; font-size: 1.1rem; font-weight: 700; background: #fff; }
.status-pick .opt.ok input:checked + span { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); }
.status-pick .opt.bad input:checked + span { border-color: var(--bad); background: var(--bad-bg); color: var(--bad); }
.status-pick .opt input:focus-visible + span { outline: 3px solid rgba(37, 99, 235, .4); }
.photos .label { font-weight: 600; margin: 0 0 8px; }
.photo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.photo-grid.big img { width: 100%; border-radius: 12px; display: block; }
.photo-slot { position: relative; aspect-ratio: 3 / 4; border: 2px dashed #a8bde8; border-radius: 14px; background: #f5f8ff; padding: 0; cursor: pointer; overflow: hidden; font: inherit; color: var(--muted); }
.photo-slot .ph { display: grid; place-items: center; gap: 6px; height: 100%; padding: 10px; font-weight: 600; }
.photo-slot .cam { font-size: 2rem; }
.photo-slot.has { border: 2px solid var(--ok); }
.photo-slot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-slot .retake { position: absolute; left: 8px; bottom: 8px; padding: 3px 10px; border-radius: 999px; background: rgba(0, 0, 0, .6); color: #fff; font-size: .8rem; }

/* fullscreen camera */
.camera { position: fixed; inset: 0; z-index: 100; background: #000; display: flex; flex-direction: column; }
.camera[hidden] { display: none; }
.camera video { flex: 1; width: 100%; min-height: 0; object-fit: cover; }
.cam-info { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px; right: 12px; padding: 6px 12px; border-radius: 10px; background: rgba(0, 0, 0, .5); color: #fff; font-size: .9rem; text-align: center; }
.cam-bar { display: flex; align-items: center; justify-content: space-around; padding: 18px 12px max(18px, env(safe-area-inset-bottom)); background: #000; }
.cam-btn { background: none; border: 0; color: #fff; font: inherit; font-weight: 600; min-width: 54px; padding: 10px; cursor: pointer; }
.shutter { width: 74px; height: 74px; border-radius: 50%; border: 5px solid #fff; background: #fff; box-shadow: inset 0 0 0 4px #000; cursor: pointer; }
.shutter:disabled { opacity: .4; }
.shutter:active { transform: scale(.94); }

/* ---------- reports ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stats div { padding: 12px; border-radius: 12px; background: #f1f5fd; border: 1px solid var(--line); color: var(--muted); font-size: .85rem; }
.stats span { display: block; font-size: 1.6rem; font-weight: 700; color: var(--ink); line-height: 1.2; }
.stats .bad span { color: var(--bad); }
@media (max-width: 560px) { .stats { grid-template-columns: 1fr 1fr; } }
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr.alert td { background: #fff7f7; }
tr.miss td { background: #fffbeb; }
tr.off td { opacity: .55; }
table.rows tbody tr { cursor: pointer; }
table.rows tbody tr:hover td { background: #f1f5fd; }
.thumbs { white-space: nowrap; }
.thumbs img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; margin-right: 4px; }
.qr-thumb { width: 64px; height: 64px; display: block; }
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 12px; }
dl.info { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 16px; }
dl.info dt { color: var(--muted); }
dl.info dd { margin: 0; }
dl.info dd.strong { font-weight: 600; color: var(--bad); }
@media (max-width: 480px) { dl.info { grid-template-columns: 1fr; gap: 0; } dl.info dd { margin-bottom: 8px; } }

/* ---------- login (โครงเดียวกับ CarsRefer, ธีมน้ำเงิน) ---------- */
body.login-page { padding-bottom: 0; }
.login-overlay {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 2rem 1rem max(2rem, env(safe-area-inset-bottom));
  background: radial-gradient(ellipse at 20% 10%, #dbe6ff 0, transparent 60%), radial-gradient(ellipse at 85% 90%, #e3ecff 0, transparent 55%), #eef3fb;
}
.login-card {
  width: 100%; max-width: 440px; padding: 2rem 1.6rem; border-radius: 26px;
  background: linear-gradient(160deg, #ffffff 0%, #fbfcff 60%, #f2f6fe 100%);
  border: 1px solid #d6e0f2; box-shadow: inset 0 2px 0 #fff, 0 5px 0 #dae3f4, 0 24px 60px rgba(15, 30, 70, .18);
}
.login-header { text-align: center; margin-bottom: 1.25rem; }
.login-logo { width: 92px; height: 92px; margin: 0 auto .75rem; border-radius: 50%; padding: 4px; background: #fff;
  box-shadow: 0 4px 0 #dae3f4, 0 8px 22px rgba(37, 99, 235, .16); }
.login-logo img { width: 100%; height: 100%; object-fit: contain; border-radius: 50%; display: block; }
.login-header h2 { font-size: 1.35rem; font-weight: 800; color: #0b1b3a; margin: 0 0 3px; letter-spacing: .3px; }
.login-en { font-size: .85rem; font-weight: 600; color: #1d4ed8; margin-bottom: 3px; }
.login-header p { font-size: .82rem; color: var(--muted); margin: 0; }
.login-notice { display: flex; align-items: center; gap: .65rem; padding: .65rem .85rem; margin-bottom: 1.25rem; border-radius: 10px;
  background: #eef4ff; border: 1px solid #c8d6f3; font-size: .78rem; line-height: 1.4; color: #475569; }
.login-notice > span { font-size: 1.5rem; }
.login-notice strong { display: block; color: #1e40af; }
.login-mode-tabs { display: flex; gap: 4px; padding: 4px; margin-bottom: 1.25rem; border-radius: 12px;
  background: #e6ecf7; border: 1px solid #d3ddef; box-shadow: inset 0 2px 5px rgba(15, 30, 70, .12), 0 1px 0 #fff; }
.login-tab-btn { flex: 1; display: flex; align-items: center; justify-content: center; gap: .35rem; min-height: 44px; padding: .55rem .4rem;
  border: 0; border-radius: 9px; background: none; color: #475569; font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer; }
.login-tab-btn:hover { background: rgba(255, 255, 255, .8); color: #1e40af; }
.login-tab-btn.active { background: linear-gradient(155deg, #60a5fa 0%, #2563eb 50%, #1e40af 100%); color: #fff;
  box-shadow: 0 6px 14px -6px rgba(37, 99, 235, .65), inset 0 1px 0 rgba(255, 255, 255, .3); }
.login-form label > span { font-size: .9rem; }
.login-help { display: block; font-size: .78rem; color: var(--muted); font-weight: 400; }
.login-error { padding: .6rem .85rem; margin-bottom: 1rem; border-radius: 10px; background: var(--bad-bg); color: #7f1d1d; border: 1px solid #fecaca; font-size: .88rem; font-weight: 600; }
.login-foot { text-align: center; margin-top: 1.25rem; padding-top: .85rem; border-top: 1px solid #e1e8f4; font-size: .75rem; color: var(--muted); }
.login-install-wrap { margin-bottom: 10px; }
.login-install-link {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 999px;
  background: #eef4ff; border: 1px solid #c8d6f3;
  color: #1d4ed8; font-size: .92rem; font-weight: 700;
  text-decoration: none; transition: background .15s, transform .1s;
}
.login-install-link:hover { background: #dbeafe; color: #1e40af; }
.login-install-link:active { transform: scale(.97); }
.login-install-link svg { width: 20px; height: 20px; flex: none; }
.login-foot-note { margin: 6px 0 0; }
@media (max-width: 420px) { .login-card { padding: 1.4rem 1rem; } .login-tab-btn { font-size: .8rem; } }
.login-pane[hidden] { display: none; }
.center-label { text-align: center; }
.login-help.center { text-align: center; }
.pin-display { text-align: center; margin: .5rem 0 1.1rem; }
.pin-label { font-size: .88rem; color: var(--muted); margin-bottom: .6rem; }
.pin-dots { display: flex; justify-content: center; gap: 16px; }
.pin-dots span { width: 18px; height: 18px; border-radius: 50%; background: #e6ecf7; border: 2px solid #bccbea; transition: transform .12s, background .12s; }
.pin-dots span.on { background: #2563eb; border-color: #1e40af; transform: scale(1.1); }
.pin-hint { min-height: 1.3em; margin-top: .5rem; font-size: .85rem; font-weight: 600; color: var(--muted); }
.pin-keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 300px; margin: 0 auto; }
.pin-btn { height: 60px; border-radius: 16px; border: 1px solid #d6e0f2; background: linear-gradient(180deg, #fff, #f2f6fe); color: #0b1b3a;
  font: inherit; font-size: 1.5rem; font-weight: 700; cursor: pointer; box-shadow: inset 0 2px 0 #fff, 0 3px 0 #d6e0f2; touch-action: manipulation; }
.pin-btn:active { transform: translateY(2px); box-shadow: inset 0 2px 0 #fff, 0 1px 0 #d6e0f2; background: #e6eefc; }
.pin-btn.pin-clear, .pin-btn.pin-back { font-size: 1.1rem; color: var(--muted); }
.login-ok { padding: .6rem .85rem; margin-bottom: 1rem; border-radius: 10px; background: var(--ok-bg); color: #14532d; border: 1px solid #bbf7d0; font-size: .88rem; font-weight: 700; }
.login-error { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@media (prefers-reduced-motion: reduce) { .login-error { animation: none; } }

/* =====================================================================
   มือถือ: แถบเมนูล่าง, ตารางเป็นการ์ด, ปุ่มใหญ่กดง่าย
   ===================================================================== */
.bottom-nav, .sheet { display: none; }
@media (min-width: 761px) {
  .bottom-nav { display: none !important; }
}
@media (max-width: 760px) {
  body { font-size: 16px; }
  body.has-nav { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
  .desk-only, .menu { display: none !important; }
  .top { padding: 8px 14px; padding-top: max(8px, env(safe-area-inset-top)); gap: 8px; }
  .brand small { display: none; }
  .who { font-size: .85rem; max-width: 45%; }
  .who a { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-decoration: none; }
  .wrap { padding: 12px; gap: 12px; }
  .card { padding: 14px; border-radius: 14px; }
  h1 { font-size: 1.3rem; }

  /* แถบเมนูด้านล่าง */
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, .96); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--line); box-shadow: 0 -6px 20px rgba(15, 30, 70, .08);
  }
  .bottom-nav a, .bottom-nav button {
    display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 52px; justify-content: flex-end;
    padding: 4px 2px; border: 0; background: none; font: inherit; font-size: .72rem; font-weight: 600; color: #5b6b86;
    text-decoration: none; cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  .bottom-nav svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
  .bottom-nav .on { color: var(--brand-2); }
  .bottom-nav .on svg { stroke-width: 2.3; }
  .bottom-nav .scan-btn {
    display: grid; place-items: center; width: 58px; height: 58px; margin-top: -26px; border-radius: 50%; color: #fff;
    background: linear-gradient(160deg, #60a5fa, var(--brand)); border: 4px solid #fff;
    box-shadow: 0 10px 22px -8px rgba(37, 99, 235, .8);
  }
  .bottom-nav .scan-btn svg { width: 28px; height: 28px; stroke-width: 2.4; }
  .bottom-nav .scan { color: var(--brand); }
  .bottom-nav a:active .scan-btn { transform: scale(.94); }

  /* แผ่นเมนูเพิ่มเติม (เลื่อนขึ้นจากล่าง) */
  .sheet[open] { display: block; }
  .sheet { margin: auto 0 0; width: 100%; max-width: 100%; max-height: 85vh; padding: 0; border: 0; border-radius: 20px 20px 0 0; background: #fff; color: var(--ink); }
  .sheet::backdrop { background: rgba(10, 20, 50, .45); }
  .sheet-body { display: grid; gap: 4px; padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); }
  .sheet-handle { width: 42px; height: 5px; border-radius: 3px; background: #d6e0f2; margin: 0 auto 8px; }
  .sheet-who { margin: 0 0 8px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
  .sheet a { display: block; padding: 14px 12px; border-radius: 12px; text-decoration: none; color: var(--ink); font-weight: 600; background: #f3f6fc; }
  .sheet form { margin: 6px 0 0; }
  .sheet-logout { width: 100%; padding: 14px; border-radius: 12px; border: 1px solid #fecaca; background: #fff5f5; color: var(--bad); font: inherit; font-weight: 700; }

  /* ปุ่มและช่องกรอกให้กดง่าย (อย่างน้อย 44px) */
  .btn { min-height: 46px; }
  .btn.small { min-height: 40px; padding: 8px 12px; font-size: .88rem; }
  input, select, textarea { min-height: 46px; font-size: 16px; }  /* 16px กัน iPhone ซูมเข้าเอง */
  textarea { min-height: 84px; }
  td.nowrap { white-space: normal; }
  td.nowrap .btn, td.nowrap form.inline { margin: 2px 4px 2px 0; }
  form.inline { display: inline-block; }

  /* หน้าแรก */
  .hero .btn.big { width: 100%; }
  .points li { padding: 12px; align-items: flex-start; }
  .points .right { min-width: 96px; }

  /* ตัวกรองรายงาน 2 คอลัมน์ */
  .filters { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
  .filters .btn { grid-column: 1 / -1; width: 100%; }
  .head-row .btn { width: 100%; }

  /* ตาราง → การ์ด */
  .table-wrap:not(.matrix-scroll) { margin: 0; padding: 0; overflow: visible; }
  .table-wrap.matrix-scroll { margin: 0; padding: 0; overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tfoot, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { margin-bottom: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
  table.stack td { display: flex; gap: 10px; padding: 5px 0; border: 0; text-align: right; justify-content: space-between; align-items: flex-start; }
  table.stack td::before { content: attr(data-label); flex: none; max-width: 44%; color: var(--muted); font-size: .8rem; font-weight: 600; text-align: left; }
  table.stack td:empty, table.stack td[data-label=""]::before { display: none; }
  table.stack td:last-child { justify-content: flex-end; flex-wrap: wrap; text-align: right; }
  table.stack td:last-child::before { flex-basis: auto; max-width: 44%; }
  tr.alert td, tr.miss td, table.rows tbody tr:hover td { background: transparent; }
  table.stack tr.alert { border-color: #fecaca; background: #fff7f7; }
  table.stack tr.miss { border-color: #fde68a; background: #fffbeb; }
  .thumbs img { width: 64px; height: 64px; }

  /* แบบฟอร์มรายงาน: ซ่อนแถบเมนูล่างเมื่อเปิดฟอร์มเพื่อไม่ให้ปุ่มสแกน QR มาอยู่ใกล้ปุ่มบันทึก */
  body.has-report .bottom-nav,
  body:has(#report-form) .bottom-nav {
    display: none !important;
  }
  body.has-report,
  body:has(#report-form) {
    padding-bottom: max(24px, env(safe-area-inset-bottom)) !important;
  }
  .report #submit-btn {
    position: relative;
    bottom: auto;
    z-index: 2;
    margin-top: 20px;
    min-height: 52px;
    font-size: 1.15rem;
    font-weight: 700;
    box-shadow: 0 10px 24px -8px rgba(37, 99, 235, .7);
  }
  .status-pick .opt span { padding: 18px 8px; }
  .photo-slot .ph { font-size: .9rem; }

  .stats span { font-size: 1.4rem; }
  dl.info { font-size: .95rem; }
}

/* หน้าสแกนบนมือถือ: ช่องกล้องเต็มความกว้าง */
@media (max-width: 760px) {
  .scanner-card { padding: 12px; }
  .viewfinder { margin: 10px 0; }
}
/* เปิดจากไอคอนบนหน้าจอ (standalone) ไม่มีแถบเบราว์เซอร์: เว้นที่ด้านบน */
@media (display-mode: standalone) {
  .top { padding-top: max(10px, env(safe-area-inset-top)); }
}
.perm-help { margin-top: 12px; text-align: left; font-size: .88rem; border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; background: #f7f9fe; }
.perm-help summary { cursor: pointer; font-weight: 600; color: var(--brand); padding: 4px 0; }
.perm-help p { margin: 8px 0; }

/* ---------- กันหน้าเลื่อนซ้าย-ขวาบนมือถือ ---------- */
html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  touch-action: pan-y;
  position: relative;
}
img, video, svg, canvas, iframe { max-width: 100%; }
input, select, textarea, button { max-width: 100%; }
*, *::before, *::after { box-sizing: border-box; }
h1, h2, h3, h4, p, .card, .flash, dd, .sheet a {
  overflow-wrap: break-word;
  word-break: normal;
}
.wrap { width: 100%; max-width: 1100px; overflow-x: hidden; }
.top { width: 100%; max-width: 100%; box-sizing: border-box; }
.brand { min-width: 0; }
.brand > span:last-child { min-width: 0; }
.brand b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 760px) {
  .hero-top-row { flex-wrap: wrap; }
  .hero-top-row > * { min-width: 0; }
  .hero-btns { flex-direction: column; width: 100%; }
  .hero-btns .btn { width: 100%; }
  .points .right { min-width: 0; flex: none; max-width: 45%; }
  .points .chip { white-space: normal; }
  table.stack td { min-width: 0; }
  table.stack td > * { min-width: 0; }
  .thumbs { white-space: normal; }
  .with-btn input { min-width: 0; }
  dl.info dd { min-width: 0; }
}
/* iPhone: ช่องวันที่มีความกว้างขั้นต่ำของตัวเอง ทำให้ล้นจอ */
input[type="date"] { min-width: 0; -webkit-appearance: none; appearance: none; display: block; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
.filters label { min-width: 0; }

/* ---------- หน้าบันทึกการตรวจ: กันล้นจอ ---------- */
fieldset { min-width: 0; }
.status-pick { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.photo-slot, .photo-grid > a { min-width: 0; width: 100%; }
.photo-slot img, .photo-grid img { max-width: 100%; }
.report { overflow-x: hidden; max-width: 100%; }
.report label, .report textarea, .gps-box { min-width: 0; max-width: 100%; }
.camera { width: 100%; max-width: 100%; overflow: hidden; }
.cam-info { overflow-wrap: anywhere; }
#report-view, #scan-view { min-width: 0; max-width: 100%; }

/* ---------- หน้าต่างยืนยันบันทึกสำเร็จ (Success Modal) ---------- */
.save-modal-overlay {
  position: fixed; inset: 0; z-index: 250;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(10, 20, 50, .68);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  animation: modalFadeIn .2s ease-out;
}
.save-modal-overlay[hidden] { display: none !important; }
.save-modal-card {
  width: 100%; max-width: 380px; padding: 24px 20px;
  background: #ffffff; border-radius: 22px;
  box-shadow: 0 20px 50px rgba(15, 30, 70, .28);
  text-align: center; color: var(--ink);
  animation: modalPopIn .25s cubic-bezier(.175, .885, .32, 1.275);
}
.save-modal-icon {
  width: 64px; height: 64px; margin: 0 auto 12px;
  border-radius: 50%; background: linear-gradient(135deg, #22c55e, #15803d);
  color: #fff; font-size: 2.2rem; font-weight: 700;
  display: grid; place-items: center;
  box-shadow: 0 10px 24px -6px rgba(34, 197, 94, .55);
}
.save-modal-card h2 {
  font-size: 1.28rem; font-weight: 700; color: #0b1b3a; margin: 0 0 12px;
}
.save-modal-details {
  background: #f4f7fd; border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; margin: 14px 0; text-align: left;
  display: grid; gap: 8px; font-size: .92rem;
}
.save-modal-row {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
}
.save-modal-row b { text-align: right; overflow-wrap: anywhere; word-break: break-word; }
.save-modal-actions { display: grid; gap: 8px; margin-top: 14px; }
.save-modal-timer { margin: 10px 0 0; font-size: .82rem; }
@keyframes modalFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalPopIn { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* กล่องแจ้งเตือนบันทึกเรียบร้อยที่หน้าแรก */
.flash-saved {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  border-radius: 14px; border: 1px solid #86efac; background: #ecfdf5;
  box-shadow: 0 6px 18px -6px rgba(22, 163, 74, .25);
}
.flash-saved-icon { font-size: 1.4rem; flex: none; }
.flash-close-btn {
  background: none; border: 0; color: var(--muted); font-size: 1.2rem;
  font-weight: 700; cursor: pointer; padding: 4px 8px; border-radius: 8px;
}
.flash-close-btn:hover { background: rgba(0, 0, 0, .08); }

/* ---------- ดูรูปเต็มจอ ---------- */
.lightbox { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, .92); touch-action: pinch-zoom; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100vw; max-height: 100vh; max-height: 100dvh; object-fit: contain; transition: transform .15s; user-select: none; -webkit-user-drag: none; }
.lb-close { position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; width: 48px; height: 48px; border-radius: 50%; border: 0;
  background: rgba(255, 255, 255, .92); color: #111; font-size: 1.4rem; font-weight: 700; cursor: pointer; box-shadow: 0 4px 14px rgba(0, 0, 0, .4); }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 64px; border: 0; border-radius: 12px;
  background: rgba(255, 255, 255, .18); color: #fff; font-size: 2.2rem; line-height: 1; cursor: pointer; }
.lb-nav[hidden] { display: none; }
.lb-prev { left: 8px; }
.lb-next { right: 8px; }
.lb-count { position: absolute; bottom: max(16px, env(safe-area-inset-bottom)); left: 0; right: 0; text-align: center; color: #fff; font-weight: 600; }
.thumbs a { display: inline-block; }


/* =====================================================================
   ธีมน้ำเงินแบบโมเดิร์น: พื้นไล่สีอ่อน, การ์ดขาวเงานุ่ม, หัวกระจกฝ้า, โลโก้ สธ.
   ===================================================================== */
:root { --radius: 18px; --shadow: 0 1px 2px rgba(15, 30, 70, .05), 0 12px 32px -16px rgba(15, 30, 70, .22); }
body {
  background:
    radial-gradient(900px 500px at 100% -10%, rgba(96, 165, 250, .25), transparent 60%),
    radial-gradient(700px 420px at -10% 10%, rgba(37, 99, 235, .14), transparent 60%),
    linear-gradient(180deg, #f6f9ff 0%, #eef3fb 55%, #e7eefa 100%) fixed;
}
.top { background: rgba(255, 255, 255, .78); border-bottom: 1px solid rgba(221, 229, 242, .9); box-shadow: 0 6px 20px -16px rgba(15, 30, 70, .35); }
.brand-logo { width: 40px; height: 40px; flex: none; border-radius: 50%; background: #fff; padding: 2px; box-shadow: 0 0 0 2px #dbe6ff, 0 4px 10px -4px rgba(37, 99, 235, .45); }
.brand b { color: #0b1b3a; letter-spacing: -.01em; }
.brand small { color: #2563eb; font-weight: 600; }
.menu a { border-radius: 10px; }
.menu a.on { background: #2563eb; color: #fff; box-shadow: 0 6px 14px -8px rgba(37, 99, 235, .8); }
.menu a:not(.on):hover { background: #eef4ff; color: #1d4ed8; }
.card { border-color: rgba(221, 229, 242, .9); }
h1 { letter-spacing: -.015em; }
.btn { border-radius: 12px; transition: transform .08s, box-shadow .2s, background .2s; }
.btn:active { transform: scale(.98); }
.btn:not(.primary):hover { border-color: #c8d6f3; background: #f5f8ff; }
.hero { background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 45%, #3b82f6 100%); color: #fff; border: 0; position: relative; overflow: hidden; }
.hero::after { content: ""; position: absolute; right: -60px; top: -60px; width: 220px; height: 220px; border-radius: 50%; background: rgba(255, 255, 255, .1); pointer-events: none; }
.hero .muted { color: rgba(255, 255, 255, .8); }
.hero .num { color: #fff; }
.hero .progress { background: rgba(255, 255, 255, .25); }
.hero .progress span { background: linear-gradient(90deg, #bfdbfe, #fff); }
.hero .btn.primary { background: #fff; color: #1d4ed8; box-shadow: 0 10px 20px -10px rgba(10, 20, 60, .6); position: relative; z-index: 1; }
.points li.done .dot { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-bg); }
.stats div { background: linear-gradient(180deg, #fff, #f5f8ff); border-color: #dde5f2; }
.stats span { color: #1d4ed8; }
.stats .bad span { color: var(--bad); }
th { background: #f5f8ff; }
.gps-box { background: #eef2f8; }
.fab { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }
.bottom-nav .on { color: #2563eb; }
.login-logo { width: 104px; height: 104px; padding: 6px; box-shadow: 0 0 0 4px #e3ecff, 0 14px 30px -12px rgba(37, 99, 235, .55); }
.login-card { border-radius: 24px; }
.login-header h2 { letter-spacing: -.01em; }
.login-en { letter-spacing: .08em; }
.pin-btn { border-radius: 18px; }

/* ---------- หน้าแนะนำการติดตั้งแอป (Install PWA) ---------- */
.install-card {
  max-width: 560px; margin: 12px auto; padding: 24px 20px;
}
.install-header {
  text-align: center; margin-bottom: 20px;
}
.install-icon-wrap {
  width: 88px; height: 88px; margin: 0 auto 12px;
  border-radius: 22px; padding: 6px; background: #fff;
  box-shadow: 0 4px 14px rgba(37, 99, 235, .18), 0 0 0 2px #dbe6ff;
}
.install-icon-wrap img { width: 100%; height: 100%; border-radius: 16px; object-fit: contain; }
.install-header h1 { font-size: 1.45rem; margin-bottom: 6px; }
.install-header p { font-size: .92rem; margin: 0; line-height: 1.5; }
.install-guide { display: grid; gap: 14px; margin: 20px 0; }
.guide-box {
  background: #f8fafc; border: 1px solid var(--line); border-radius: 16px;
  padding: 16px; position: relative;
}
.guide-box.ios { border-color: #cbd5e1; background: #fbfcfe; }
.guide-box.android { border-color: #bbf7d0; background: #f0fdf4; }
.guide-badge {
  font-weight: 700; font-size: .95rem; margin-bottom: 10px;
  display: flex; align-items: center; gap: 6px; color: #0f172a;
}
.guide-steps {
  margin: 0; padding-left: 20px; font-size: .9rem; line-height: 1.7; color: #334155;
}
.guide-steps li { margin-bottom: 6px; }
.ios-share-icon {
  display: inline-block; padding: 0 4px; font-size: 1rem;
}
.guide-tip {
  margin-top: 12px; padding: 10px 12px; border-radius: 12px;
  background: #eff6ff; border: 1px solid #bfdbfe; font-size: .85rem; color: #1e40af; line-height: 1.5;
}
.guide-tip p { margin: 4px 0 0; }
.install-actions { margin-top: 20px; }

/* ---------- หน้ารายงาน: แผนที่จุดสแกนและสถิติ ---------- */
.reports-map-card { position: relative; }
.map-ctrls {
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: space-between; margin-bottom: 12px;
}
.map-ctrls-left { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.map-ctrls-right { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.reports-map {
  width: 100%; height: 440px; border-radius: 16px; border: 1px solid var(--line);
  box-shadow: inset 0 1px 3px rgba(15, 30, 70, .08); z-index: 1;
}
@media (max-width: 640px) {
  .reports-map { height: 350px; border-radius: 12px; }
  .map-ctrls { flex-direction: column; align-items: stretch; }
  .map-ctrls-left, .map-ctrls-right { width: 100%; justify-content: space-between; }
}
.map-legend {
  display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; margin-top: 10px; font-size: .84rem; color: var(--muted);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.guard-dot {
  width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none;
  box-shadow: 0 0 0 2px #fff, 0 1px 3px rgba(0, 0, 0, .2);
}

/* Custom Marker Pins */
.scan-map-pin { background: transparent; border: 0; }
.scan-pin-marker {
  position: relative; width: 32px; height: 32px; border-radius: 50%;
  background: var(--pin-color, #2563eb); color: #fff; font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  border: 2.5px solid #fff; box-shadow: 0 4px 10px rgba(0, 0, 0, .35);
  cursor: pointer; transition: transform .15s;
}
.scan-pin-marker:hover { transform: scale(1.15); z-index: 50; }
.scan-pin-marker.abnormal {
  background: #dc2626; animation: pinPulse 1.6s infinite;
}
.scan-pin-badge {
  position: absolute; right: -4px; top: -4px; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid #fff;
}
.scan-pin-badge.ok { background: #22c55e; }
.scan-pin-badge.bad { background: #ef4444; }

.cp-map-pin { background: transparent; border: 0; }
.cp-pin-marker {
  width: 30px; height: 30px; border-radius: 8px; background: #0f172a; color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 14px;
  border: 2px solid #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, .3);
}

/* Popup Content */
.map-popup-card {
  padding: 4px; min-width: 220px; max-width: 280px; font-family: inherit; font-size: .88rem; line-height: 1.45; color: var(--ink);
}
.map-popup-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 6px;
  padding-bottom: 6px; border-bottom: 1px solid #e2e8f0; font-size: .95rem; font-weight: 700;
}
.map-popup-meta { display: grid; gap: 3px; font-size: .84rem; color: #334155; margin-bottom: 8px; }
.map-popup-thumbs {
  display: flex; gap: 6px; margin-bottom: 8px;
}
.map-popup-thumbs img {
  width: 54px; height: 54px; border-radius: 8px; object-fit: cover; border: 1px solid #cbd5e1;
}
.map-popup-link {
  display: inline-block; font-weight: 700; font-size: .84rem; color: var(--brand); text-decoration: none;
}
@keyframes pinPulse {
  0% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .7); }
  70% { box-shadow: 0 0 0 10px rgba(220, 38, 38, 0); }
  100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}
