:root {
  --bg: #eef2f5; --card: #fff; --ink: #1d2733; --muted: #66727f; --line: #d5dce3;
  --brand: #1f5f8b; --brand-ink: #fff; --accent: #e8f1f8; --ok: #1e7f45; --warn: #b45f06; --bad: #b42318;
  --fill: rgba(31, 95, 139, .10); --fill-hot: rgba(255, 196, 0, .28); --val: #0b3d91;
  font-family: 'Sarabun', 'Leelawadee UI', 'Tahoma', sans-serif;
}
[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-size: 16px; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.bar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px; padding: 10px 12px calc(10px) 12px; padding-top: calc(10px + env(safe-area-inset-top)); background: var(--brand); color: var(--brand-ink); }
.bar h1 { font-size: 18px; margin: 0; flex: 1; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar button { background: rgba(255,255,255,.16); border: 0; color: inherit; border-radius: 8px; padding: 8px 12px; min-height: 40px; }
.wrap { max-width: 900px; margin: 0 auto; padding: 12px 12px 96px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.parcel { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.parcel .code { font-weight: 700; font-size: 18px; }
.parcel .sub { color: var(--muted); font-size: 14px; grid-column: 1 / -1; }
.pill { font-size: 13px; border-radius: 999px; padding: 2px 10px; background: #fff4e5; color: var(--warn); border: 1px solid #f2d4a9; white-space: nowrap; }
.pill.ok { background: #e8f6ee; color: var(--ok); border-color: #b9e2c8; }
.muted { color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 14px; min-height: 44px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 36px; padding: 6px 10px; font-size: 14px; }
.fab { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 15; border: 0; border-radius: 999px; background: var(--brand); color: #fff; font-weight: 700; padding: 14px 20px; box-shadow: 0 6px 18px rgba(0,0,0,.25); }

/* กระดาษสำรวจ — พิกัดอ้างอิงภาพ 1347x952 (ภาพพื้นหลังจริง 2x) */
.paper-scroll { overflow: auto; -webkit-overflow-scrolling: touch; background: #9aa6b2; border-radius: 10px; padding: 8px; }
.paper { position: relative; width: 1347px; height: 952px; background: #fff url(form-bg.png) 0 0 / 1347px 952px no-repeat; transform-origin: 0 0; box-shadow: 0 2px 10px rgba(0,0,0,.25); }
.paper-holder { position: relative; }
.zone { position: absolute; background: var(--fill); border: 1px dashed rgba(31,95,139,.35); border-radius: 3px; padding: 0; cursor: pointer; }
.zone:active, .zone.hot { background: var(--fill-hot); }
.zone.filled { background: transparent; border-color: transparent; }
.v { position: absolute; color: var(--val); font-weight: 600; white-space: nowrap; overflow: hidden; line-height: 1.15; pointer-events: none; display: flex; align-items: center; }
.v.c { justify-content: center; text-align: center; }
.v.wrapok { white-space: normal; align-items: flex-start; font-size: 11px; }
.pagenav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 8px 0; }
.zoombar { display: flex; gap: 6px; }

.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.thumb { position: relative; width: 84px; height: 84px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: #f3f5f7; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button { position: absolute; top: 2px; right: 2px; border: 0; border-radius: 999px; width: 26px; height: 26px; background: rgba(0,0,0,.6); color: #fff; font-size: 14px; line-height: 26px; padding: 0; }
.addphoto { width: 84px; height: 84px; border-radius: 8px; border: 2px dashed var(--brand); background: var(--accent); color: var(--brand); font-size: 13px; font-weight: 600; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.addphoto input { display: none; }
.addphoto span.big { font-size: 26px; line-height: 1; }

/* แผ่นกรอกข้อมูล (bottom sheet) */
#sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; }
#sheet { position: fixed; inset: 0; z-index: 41; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; background: var(--card); padding: 0 16px calc(24px + env(safe-area-inset-bottom)); }
#sheet > form { max-width: 760px; margin: 0 auto; }
body.sheet-open { overflow: hidden; }
html, body { overscroll-behavior-y: none; }
.sheet-head { position: sticky; top: 0; padding-top: calc(12px + env(safe-area-inset-top)) !important; background: var(--card); display: flex; align-items: center; gap: 8px; padding: 12px 0 10px; border-bottom: 1px solid var(--line); margin-bottom: 10px; z-index: 2; }
.sheet-head h2 { flex: 1; font-size: 18px; margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px 12px; }
.grid .wide { grid-column: 1 / -1; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
label.f input, label.f select, label.f textarea { font-size: 16px; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 10px; min-height: 44px; background: #fff; width: 100%; }
label.f textarea { min-height: 70px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 12px; margin: 10px 0; }
legend { font-weight: 600; padding: 0 6px; }
.sub-row { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; background: #fafbfc; }
.sub-row .row { justify-content: space-between; margin-bottom: 6px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 10px 14px; min-height: 44px; }
.seg button.on { background: var(--brand); color: #fff; font-weight: 600; }
#toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #22313f; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 60; max-width: 90vw; }
h3 { font-size: 16px; margin: 14px 0 6px; }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }

.areainfo { margin: 8px 0; padding: 10px 12px; border-radius: 10px; background: var(--accent); font-size: 14px; line-height: 1.6; }
.areainfo.full { background: #e8f6ee; }
.areainfo.over { background: #fdecea; color: var(--bad); border: 1px solid #f5c2bd; }
.areainfo .btn { margin-top: 4px; }
fieldset.locked { border: 1px dashed var(--line); background: #f3f5f7; margin-top: 6px; }
fieldset.locked input, fieldset.locked select { background: #eef1f4 !important; color: var(--ink); opacity: 1; -webkit-text-fill-color: var(--ink); }
