/* โครงสี/ตัวอักษรเดียวกับระบบ meanamkok */
:root {
  --bg: #f8fafc; --panel: #fff; --border: #e2e8f0; --ink: #0f172a; --muted: #64748b;
  --accent: #0d9488; --danger: #dc2626; --warn: #d97706; --ok: #059669; --info: #2563eb;
  --sans: "IBM Plex Sans Thai", -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1120; --panel: #111827; --border: #1f2a3c; --ink: #f1f5f9; --muted: #94a3b8; --accent: #14b8a6; }
}
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--sans); background: var(--bg); color: var(--ink); font-size: 14px; }
a { color: var(--accent); }
.top { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { font-weight: 700; }
.brand span { font-size: 11px; background: var(--accent); color: #fff; border-radius: 99px; padding: 2px 8px; margin-left: 4px; }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; }
.top nav a { text-decoration: none; color: var(--ink); padding: 6px 12px; border-radius: 8px; }
.top nav a.on { background: var(--accent); color: #fff; }
.top nav a.muted { color: var(--muted); }
.wrap { max-width: 1400px; margin: 0 auto; padding: 16px; }
.wrap.narrow { max-width: 420px; }
h1 { font-size: 20px; margin: 4px 0 8px; }
h2 { font-size: 15px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 12px; white-space: nowrap; }
.r { text-align: right; }
.good { color: var(--ok); }
.bad { color: var(--danger); }
.error-text { color: var(--danger); font-weight: 600; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin: 14px 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid2 .card { margin: 0; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin: 12px 0; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 10px; padding: 10px 12px; }
.kpi b { display: block; font-size: 22px; }
.kpi span { font-size: 12px; color: var(--muted); }
.kpi.bad { border-left-color: var(--danger); } .kpi.bad b { color: var(--danger); }
.kpi.warn { border-left-color: var(--warn); } .kpi.good { border-left-color: var(--ok); }
.scroll { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 600; background: var(--bg); position: sticky; top: 0; }
.tbl th.r, .tbl td.r { text-align: right; }
.tbl.compact td, .tbl.compact th { padding: 4px 8px; }
tr.row-warn td { background: rgba(217, 119, 6, .08); }
.thumb { width: 64px; height: 48px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 99px; white-space: nowrap; }
.tag.warn { background: rgba(217, 119, 6, .14); color: var(--warn); }
.tag.info { background: rgba(37, 99, 235, .12); color: var(--info); }
.tag.ok { background: rgba(5, 150, 105, .12); color: var(--ok); }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg a { padding: 6px 12px; border: 1px solid var(--border); border-radius: 99px; text-decoration: none; color: var(--ink); font-size: 13px; }
.seg a.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; flex: 0 0 auto; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 4px; padding: 8px 14px; min-height: 40px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); color: var(--ink); text-decoration: none; font: inherit; cursor: pointer; }
.btn.small { padding: 5px 10px; min-height: 34px; font-size: 13px; }
.btn.big { min-height: 48px; font-size: 15px; font-weight: 600; width: 100%; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: .5; }
.btn.danger-link { color: var(--danger); border-color: transparent; background: none; }
.grow { flex: 1; }
input, select, textarea { font: inherit; font-size: 16px; padding: 9px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); color: var(--ink); width: 100%; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.form label.check > input[type=checkbox] { width: 22px; height: 22px; flex: 0 0 auto; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions.stack { flex-direction: column; margin-bottom: 8px; }

/* หน้าแผนที่ */
body.page-index { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
.map-layout { display: grid; grid-template-columns: 360px 1fr; flex: 1; min-height: 0; }
#map-viewport { position: relative; }
#map { height: 100%; }
.side { overflow-y: auto; border-right: 1px solid var(--border); background: var(--panel); padding: 10px; }
.small-kpis { grid-template-columns: repeat(3, 1fr); margin: 0 0 8px; gap: 6px; }
.small-kpis .kpi { padding: 6px 8px; } .small-kpis .kpi b { font-size: 18px; }
.box { border-top: 1px solid var(--border); padding: 8px 0; }
.box-title { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.search { margin: 6px 0; }
.grp { font-weight: 700; font-size: 12px; color: var(--muted); padding: 10px 4px 4px; border-bottom: 1px solid var(--border); }
.pitem { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 9px 4px; border: 0; border-bottom: 1px solid var(--border); background: none; color: var(--ink); font: inherit; cursor: pointer; }
.pitem:hover { background: var(--bg); }
.pname { flex: 1; font-size: 13px; line-height: 1.35; }
.pname small { display: block; color: var(--muted); font-size: 11.5px; }
.legend-note { margin-top: 10px; line-height: 1.7; }
.lg { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: -1px; border: 2px solid #64748b; }
.lg-todo { background: #fff; } .lg-done { background: var(--ok); } .lg-user { background: var(--warn); }

.pin { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font: 700 13px/1 var(--sans); border: 3px solid var(--ring); box-shadow: 0 1px 4px #0006; }
.pin.todo { background: #fff; color: #0f172a; }
.pin.done { background: var(--ok); color: #fff; }
.pin.user { background: var(--warn); color: #fff; }
.pin.user.done { background: var(--ok); }
.pin.approx { border-style: dashed; }
.pin.pending { outline: 2px dashed #f59e0b; outline-offset: 2px; }
.pin-label { position: absolute; left: 50%; top: 31px; transform: translateX(-50%); white-space: nowrap; font: 700 11px/1 var(--sans); color: #fff; text-shadow: 0 0 3px #000, 0 0 3px #000; pointer-events: none; }
.pop { font-family: var(--sans); font-size: 13px; line-height: 1.45; }
.pop-t { font-weight: 700; font-size: 14px; margin-bottom: 2px; }
.pop-sub { margin-top: 6px; font-weight: 700; }
.pop-ul { margin: 2px 0 0; padding-left: 18px; }
.pop-a { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.pop .muted { color: #64748b; }
.note { margin-top: 6px; font-size: 12px; padding: 4px 8px; border-radius: 6px; background: #f1f5f9; color: #334155; }
.note.warn { background: #fef3c7; color: #92400e; }
.note.bad { background: #fee2e2; color: #991b1b; }
.note.flood { background: #e0f2fe; color: #0c4a6e; }
details.box > summary { cursor: pointer; list-style: none; }
details.box > summary::-webkit-details-marker { display: none; }
details.box > summary::after { content: ' ▸'; color: var(--muted); }
details.box[open] > summary::after { content: ' ▾'; }
.fsub { font-size: 12px; font-weight: 600; color: var(--muted); margin: 8px 0 2px; }
.frow { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; cursor: pointer; }
.frow input { width: 20px; height: 20px; flex: 0 0 auto; }
.sw { width: 16px; height: 12px; border-radius: 3px; border: 1px solid #0003; flex: 0 0 auto; }
.zone-legend { display: flex; flex-wrap: wrap; gap: 3px 10px; font-size: 12px; margin: 2px 0 4px; }
.zone-legend > span { display: inline-flex; align-items: center; gap: 4px; }
.pond-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: #0284c7; border: 2px solid #fff; box-shadow: 0 0 0 1px #0284c7; flex: 0 0 auto; vertical-align: -1px; }
.pond-tip { font: 600 11px var(--sans); padding: 1px 5px; }
.pole-sm { display: inline-block; width: 22px; font-size: 9px; line-height: 13px; flex: 0 0 auto; }
.pole { background: #4c1d95; color: #fff; border: 1.5px solid #fff; border-radius: 10px; font: 700 11px/17px ui-monospace, monospace; text-align: center; box-shadow: 0 1px 3px #0006; }
.map-btns { position: absolute; right: 10px; bottom: 24px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.fab { width: 48px; height: 48px; border-radius: 50%; border: 0; background: #fff; color: #0f172a; font-size: 22px; box-shadow: 0 2px 8px #0005; cursor: pointer; }
#btnList, #btnAddFab { display: none; }
.fab.add { background: var(--accent); color: #fff; font-size: 26px; }
.side-close { display: none; }
#netStatus { position: absolute; left: 50%; transform: translateX(-50%); top: 10px; z-index: 1000; display: none; max-width: calc(100% - 120px); padding: 7px 12px; border-radius: 999px; font: 600 12.5px/1.3 var(--sans); color: #fff; box-shadow: 0 2px 8px #0003; cursor: pointer; text-align: center; }
.pick-banner { position: absolute; left: 10px; right: 10px; bottom: 90px; z-index: 1000; background: #0f172a; color: #fff; padding: 10px 12px; border-radius: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pick-banner[hidden] { display: none; }
.filter-note { position: absolute; left: 50%; transform: translateX(-50%); top: 50px; z-index: 1000; max-width: calc(100% - 120px); background: #fff; color: #0f172a; padding: 8px 12px; border-radius: 12px; box-shadow: 0 2px 10px #0004; display: flex; align-items: center; gap: 10px; font-size: 13px; }
.filter-note[hidden] { display: none; }
.filter-note .btn { background: var(--accent); color: #fff; border-color: var(--accent); white-space: nowrap; }

/* แผ่นฟอร์ม (dialog) */
dialog.sheet { width: min(560px, 100vw); max-height: 92dvh; border: 0; border-radius: 16px; padding: 16px; background: var(--panel); color: var(--ink); box-shadow: 0 10px 40px #0006; }
dialog.sheet::backdrop { background: #0f172a99; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.sheet-title { font-weight: 700; font-size: 17px; }
.x { border: 0; background: none; font-size: 22px; color: var(--muted); cursor: pointer; padding: 0 4px; }
.info-box { font-size: 13px; background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.info-box[hidden] { display: none; }
.kinds-list { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.kinds-list legend { font-size: 13px; font-weight: 600; padding: 0 4px; }
.sample { padding: 6px 0; border-bottom: 1px dashed var(--border); }
.sample span small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
#cOther { width: auto; flex: 1; font-size: 14px; padding: 6px 8px; }
.gps-box { display: flex; flex-direction: column; gap: 6px; background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.preview { max-width: 100%; max-height: 200px; border-radius: 10px; object-fit: contain; }
.help { padding-left: 20px; line-height: 1.6; margin: 0; }
.help li { margin-bottom: 6px; }

/* ---------- เลือกกรอบพิมพ์ (กรอบสัดส่วน A3 บนแผนที่ นอกกรอบมืดลง) ---------- */
.print-frame { position: absolute; z-index: 900; pointer-events: none; border: 2px dashed #fff; outline: 2px solid #0d9488; border-radius: 2px; }
.print-dim { position: absolute; z-index: 899; background: rgba(15, 23, 42, .65); pointer-events: none; }
.print-dim[hidden] { display: none; }
.print-frame[hidden], .print-bar[hidden] { display: none; }
.print-frame-label { position: absolute; left: 6px; top: 6px; background: #0d9488; color: #fff; font: 600 12px/1 var(--sans); padding: 5px 8px; border-radius: 6px; }
.print-bar { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 1001; background: #fff; color: #0f172a; border-radius: 14px; box-shadow: 0 4px 18px #0006; padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; max-width: calc(100% - 20px); }
.print-bar-hint { font-size: 12px; color: #475569; text-align: center; }
.print-bar-btns { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: center; }
.print-bar .seg a { color: #0f172a; border-color: #cbd5e1; }
.print-bar .seg a.on { color: #fff; }
.print-bar .btn:not(.primary) { background: #fff; color: #0f172a; border-color: #cbd5e1; }
body.kf-framing .map-btns, body.kf-framing #filterNote, body.kf-framing .leaflet-control-layers { display: none !important; }

/* ---------- พิมพ์ A3 (print.js ใส่ class kf-print และขนาดหน้าเป็น มม.) ---------- */
body.kf-print { display: block; height: auto; overflow: visible; background: #fff; color: #111; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
body.kf-print header.top, body.kf-print .side, body.kf-print .map-btns, body.kf-print #netStatus, body.kf-print .pick-banner,
body.kf-print .leaflet-control-zoom, body.kf-print .leaflet-control-layers, body.kf-print dialog { display: none !important; }
body.kf-print .map-layout { display: block; height: auto; }
body.kf-print #map-viewport { position: relative; border: 1px solid #111; overflow: hidden; }
body.kf-print #map { height: 100%; }
#printSheet .ph { display: flex; justify-content: space-between; align-items: flex-end; gap: 10mm; height: 15mm; margin-bottom: 2mm; border-bottom: 1.2mm solid #0d9488; padding-bottom: 1.5mm; color: #111; }
.ph-t { font-size: 20pt; font-weight: 700; line-height: 1.15; }
.ph-s { font-size: 10pt; color: #334155; }
.ph-r { font-size: 9pt; color: #334155; text-align: right; white-space: nowrap; }
.pf { font-size: 7.5pt; color: #475569; margin-top: 1.5mm; }
.plegend { position: absolute; top: 3mm; left: 3mm; z-index: 1000; max-width: 125mm; background: #ffffffee; color: #111; border: 1px solid #111; border-radius: 2mm; padding: 2.5mm 3mm; font-size: 8.5pt; line-height: 1.5; }
.pl-title { font-weight: 700; font-size: 10pt; margin-bottom: 1mm; }
.pl-row { display: block; }
.pl-row > i { margin-right: 3px; }
.psw { display: inline-block; width: 14px; height: 10px; border: 1px solid #1f2937; border-radius: 2px; vertical-align: -1px; }
.ppin { display: inline-grid; place-items: center; width: 14px; height: 14px; border-radius: 50%; border: 2.5px solid var(--ring); background: #fff; font: 700 8px/1 var(--sans); color: #fff; font-style: normal; }
.ppin.done { background: #059669; } .ppin.user { background: #d97706; }
.pnorth { position: absolute; top: 3mm; right: 3mm; z-index: 1000; background: #ffffffcc; border-radius: 2mm; padding: 1mm 2mm; }
.pscale { position: absolute; left: 4mm; bottom: 4mm; z-index: 1000; background: #ffffffee; color: #111; border: 1px solid #111; border-radius: 1.5mm; padding: 1.5mm 4mm 1mm 3mm; font-size: 8pt; }
.pscale-t { font-weight: 700; margin-bottom: 1mm; }
.pscale-bar { display: flex; height: 2.2mm; border: 0.4mm solid #111; }
.pscale-bar i { flex: 1; background: #fff; } .pscale-bar i.k { background: #111; }
.pscale-l { position: relative; height: 4mm; }
.pscale-l span { position: absolute; top: 0.5mm; transform: translateX(-50%); white-space: nowrap; }
.pscale-l span:first-child { transform: none; }
body.kf-print .leaflet-control-scale { display: none; }
.print-scale { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; }
.print-scale select { width: auto; font-size: 13px; padding: 4px 6px; background: #fff; color: #0f172a; border-color: #cbd5e1; }
.print-scale-now { color: #475569; font-size: 12px; min-width: 70px; }
body.kf-print .leaflet-control-scale-line { font-size: 9pt; border-color: #111; background: #ffffffdd; color: #111; }
@media print {
  body:not(.kf-print) .side, body:not(.kf-print) header.top { display: none; }
  .leaflet-control-attribution { font-size: 7pt; }
}

@media (max-width: 768px) {
  .top { padding: 8px 12px; gap: 8px; }
  .brand { font-size: 14px; }
  .map-layout { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; right: 0; bottom: 0; top: 30%; z-index: 1100; border-radius: 16px 16px 0 0; border: 0; box-shadow: 0 -6px 24px #0004; transform: translateY(105%); transition: transform .25s; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .side.open { transform: none; }
  #btnList, #btnAddFab { display: block; }
  .top nav a { padding: 4px 8px; }
  .side-close { display: flex; margin: 0 0 8px auto; }
  dialog.sheet { margin: auto auto 0; border-radius: 16px 16px 0 0; width: 100vw; max-width: 100vw; padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); }
  .grid-form { grid-template-columns: 1fr 1fr; }
}
