/* =========================================================================
   EV Inspect — Apple / iOS-inspired UI
   ========================================================================= */
:root {
  /* ไอคอนแว่นขยาย (ใช้กับ mask ในช่องค้นหา) — เส้นสไตล์เดียวกับไอคอน SVG ตัวอื่นในแอป */
  --ic-search: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg>');
  --bg: #f2f2f7;              /* iOS grouped background */
  --bg-elev: #ffffff;
  --card: #ffffff;
  --field: #ffffff;
  --field-alt: #f2f2f7;
  --text: #1c1c1e;
  --text-2: #3c3c43;
  --muted: #8e8e93;
  --sep: rgba(60, 60, 67, .13);
  --sep-strong: rgba(60, 60, 67, .29);
  --accent: #d0202e;         /* corporate red */
  --accent-press: #a3161f;
  --accent-tint: rgba(208, 32, 46, .10);
  --brand-grad: linear-gradient(135deg, #e23140, #b3121f);
  --blue: #d0202e;           /* ปุ่มลิงก์เป็นแดงให้เข้าธีม */
  --danger: #ff3b30;
  --amber: #ff9f0a;
  --pass: #16a34a; --pass-tint: #e6f6ec;   /* เสร็จ/ผ่าน = เขียว */
  --pend: #e08a00; --pend-tint: #fdf0da;    /* ค้าง = เหลือง */
  --radius-card: 18px;
  --radius-field: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 6px 20px rgba(0,0,0,.05);
  --blur: saturate(180%) blur(20px);
  --seg-on: #ffffff;
}

/* โทเคนธีมมืด (ใช้ร่วมกันทั้ง "ตามระบบ" และ "เลือกมืดเอง") */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --bg-elev: #1c1c1e;
    --card: #1c1c1e;
    --field: #1c1c1e;
    --field-alt: #2c2c2e;
    --text: #ffffff;
    --text-2: #ebebf5;
    --muted: #8e8e93;
    --sep: rgba(84, 84, 88, .40);
    --sep-strong: rgba(84, 84, 88, .65);
    --accent: #ff4d5a;
    --accent-press: #e23140;
    --accent-tint: rgba(255, 77, 90, .18);
    --brand-grad: linear-gradient(135deg, #e23140, #8f0f1a);
    --blue: #ff6b74;
    --pass: #33c17a; --pass-tint: rgba(51,193,122,.16);
    --pend: #e0a63a; --pend-tint: rgba(224,166,58,.16);
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.5);
    --seg-on: #636366;
  }
}
/* เลือก "มืด" เอง -> ชนะ แม้ระบบจะสว่าง */
:root[data-theme="dark"] {
  --bg: #000000;
  --bg-elev: #1c1c1e;
  --card: #1c1c1e;
  --field: #1c1c1e;
  --field-alt: #2c2c2e;
  --text: #ffffff;
  --text-2: #ebebf5;
  --muted: #8e8e93;
  --sep: rgba(84, 84, 88, .40);
  --sep-strong: rgba(84, 84, 88, .65);
  --accent: #ff4d5a;
  --accent-press: #e23140;
  --accent-tint: rgba(255, 77, 90, .18);
  --brand-grad: linear-gradient(135deg, #e23140, #8f0f1a);
  --blue: #ff6b74;
  --pass: #33c17a; --pass-tint: rgba(51,193,122,.16);
  --pend: #e0a63a; --pend-tint: rgba(224,166,58,.16);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.5);
  --seg-on: #636366;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Prompt", "Sarabun", "Noto Sans Thai", -apple-system, BlinkMacSystemFont,
    "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: contain;
}
/* ---------- แถบเลื่อน (scrollbar) ให้เข้าธีมแอพ ----------
   ของเดิมเป็นแถบขาวหนา + ปุ่มลูกศรหัวท้ายแบบ Windows ดูหลุดธีมมาก
   ตรงนี้ทำให้เป็นแท่งบางโค้งมน สีตามธีม (สว่าง/มืดปรับเอง) และไม่มีปุ่มลูกศร */
* { scrollbar-width: thin; scrollbar-color: var(--sep-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--sep-strong);
  border-radius: 999px;
  border: 3px solid transparent;   /* เว้นขอบใส -> แท่งดูบางลอย ไม่ชนขอบ */
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }
::-webkit-scrollbar-thumb:active { background: var(--accent); background-clip: content-box; }
::-webkit-scrollbar-button { display: none; width: 0; height: 0; }   /* ตัดปุ่มลูกศรหัว-ท้ายออก */
::-webkit-scrollbar-corner { background: transparent; }

/* ฟอนต์ Mono เฉพาะ Serial/ตัวเลข ให้เรียงตรง อ่าน/เทียบง่าย */
.mono, .serial, .id-v, .v.mono, .kv .v, .cv { font-family: "IBM Plex Mono", "SF Mono", ui-monospace, monospace !important; }
img { max-width: 100%; display: block; }
button, input, textarea, select { font: inherit; color: inherit; }
button { letter-spacing: -0.01em; }

/* ---------- App shell ---------- */
.app { max-width: 640px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; padding-top: max(14px, env(safe-area-inset-top));
  background: var(--brand-grad);
  color: #fff;
  box-shadow: 0 4px 16px rgba(179,18,31,.25);
}
.topbar .logo { width: 34px; height: 34px; border-radius: 10px; background: rgba(255,255,255,.16); padding: 2px; }
.topbar h1 { font-size: 19px; margin: 0; font-weight: 800; letter-spacing: -0.02em; flex: 1; color: #fff; }
.topbar .sub { font-size: 11.5px; color: rgba(255,255,255,.85); font-weight: 400; display: block; margin-top: 1px; }
/* ปุ่มไอคอน (เริ่มต้น: พื้นอ่อน ข้อความเข้ม — ใช้ในหน้าแก้ไข) */
.icon-btn {
  background: var(--field-alt); border: none; color: var(--accent);
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  font-size: 20px; cursor: pointer; transition: transform .12s, background .12s;
}
.icon-btn:active { transform: scale(.9); background: var(--sep); }
/* บนแถบสีแดง: ให้เป็นสีขาว */
.topbar .icon-btn { background: rgba(255,255,255,.18); color: #fff; }
.topbar .icon-btn:active { background: rgba(255,255,255,.3); }

.content { flex: 1; padding: 18px; padding-bottom: 108px; }

/* ---------- Dashboard (หน้าหลัก) ---------- */
.hero {
  background: var(--brand-grad); color: #fff; border-radius: 24px;
  padding: 22px 22px 52px; margin-bottom: 0; box-shadow: 0 14px 30px -14px rgba(179,18,31,.5);
  position: relative; overflow: hidden; min-height: 158px;
}
.hero::after { content: ""; position: absolute; right: -40px; top: -50px; width: 170px; height: 170px; border-radius: 50%; background: rgba(255,255,255,.08); }
.hero .hero-fig { position: absolute; right: 16px; top: 20px; width: 78px; height: 92px; fill: none; stroke: rgba(255,255,255,.85); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; z-index: 1; }
.hero .h-txt { position: relative; z-index: 2; max-width: 64%; }
.hero .h-txt .s { font-size: 14px; font-weight: 500; opacity: .92; }
.hero .h-txt .t { font-size: 26px; font-weight: 700; line-height: 1.18; letter-spacing: 0; margin-top: 6px; }

.net-status {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  background: #fff4e5; color: #b45309; border: 1px solid #fde3c0;
  border-radius: 12px; padding: 9px 12px; font-size: 13px; font-weight: 600;
  margin-bottom: 16px; cursor: pointer;
}
@media (prefers-color-scheme: dark) { .net-status { background: #3a2a12; color: #ffb057; border-color: #5a3f18; } }

.action-grid {
  display: flex; justify-content: center; gap: 0;
  margin: -42px 6px 18px; background: var(--card); border-radius: 20px; padding: 14px 6px;
  box-shadow: 0 12px 28px -14px rgba(20,24,40,.45); position: relative; z-index: 5;
}
.action-item {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer;
  background: none; border: none; color: var(--text); font-family: inherit;
  flex: 0 0 30%; max-width: 150px;
}
.action-item + .action-item::before { content: ""; position: absolute; left: 0; top: 7px; bottom: 7px; width: 1px; background: var(--sep-strong); }
/* โหมดผู้ชม: ซ่อน "ตรวจใหม่" (child 1) เลยไม่ต้องมีเส้นคั่นหน้าปุ่มถัดไป (child 2) */
.action-grid.no-new .action-item:nth-child(2)::before { display: none; }
.action-item .ico {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center;
  font-size: 21px; color: var(--accent); background: var(--accent-tint); box-shadow: none;
  transition: transform .12s;
}
.action-item .ico svg { width: 21px; height: 21px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.action-item:active .ico { transform: scale(.9); }
.action-item .lbl { font-size: 12px; font-weight: 600; color: var(--text-2); text-align: center; line-height: 1.2; }
.action-item.alt .ico { background: var(--accent-tint); color: var(--accent); }

.section-title { font-size: 15px; font-weight: 700; margin: 0 0 10px 2px; letter-spacing: -.02em; }

/* ---- Home sections: ตรวจล่าสุด (การ์ดแนวนอน) + ค้างตรวจ ---- */
.sec-head { display: flex; align-items: center; justify-content: space-between; margin: 6px 2px 11px; }
.sec-head .sh-t { font-size: 16.5px; font-weight: 700; }
.sec-head .sh-c { color: var(--muted); font-weight: 500; font-size: 13px; }
.sec-head .sh-more { background: none; border: none; color: var(--muted); font-weight: 600; font-size: 12.5px; cursor: pointer; font-family: inherit; }
.hscroll { display: flex; gap: 12px; overflow-x: auto; padding: 2px 2px 16px; margin: 0 -2px; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity; }
.hscroll::-webkit-scrollbar { display: none; }
.rcardh { flex: 0 0 152px; scroll-snap-align: start; background: var(--card); border: none; border-radius: 16px; padding: 8px; box-shadow: var(--shadow); text-align: left; cursor: pointer; font-family: inherit; color: var(--text); transition: transform .1s; }
.rcardh:active { transform: scale(.98); }
.rcardh-img { height: 96px; border-radius: 12px; overflow: hidden; position: relative; background: var(--field-alt); display: grid; place-items: center; }
.rcardh-img img { width: 100%; height: 100%; object-fit: cover; }
.rcardh-img img.rcardh-logo { width: 46%; height: 46%; object-fit: contain; opacity: .9; }
.rcardh-ph { font-size: 30px; opacity: .5; }
.brc { position: absolute; left: 7px; top: 7px; font-size: 10px; font-weight: 700; color: #fff; padding: 3px 8px; border-radius: 999px; }
.brc.ok { background: var(--pass); } .brc.wait { background: var(--pend); }
.rcardh-tl { font-family: "IBM Plex Mono", monospace; font-weight: 600; font-size: 12px; margin-top: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rcardh-st { font-size: 12.5px; color: var(--text-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rcardh-ft { font-size: 11px; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty-sm { color: var(--muted); font-size: 14px; text-align: center; padding: 22px; background: var(--card); border-radius: 16px; box-shadow: var(--shadow); }

/* ---- หน้ารายการเครื่อง (แยก) ---- */
.lhead { background: var(--brand-grad); color: #fff; margin: -18px -18px 16px; padding: 16px 20px 18px; border-radius: 0 0 24px 24px; box-shadow: 0 14px 30px -16px rgba(179,18,31,.45); }
.lhead-t { font-size: 21px; font-weight: 700; }
.lhead-sub { font-size: 12.5px; opacity: .9; margin-top: 3px; }
.lsearch { display: flex; align-items: center; gap: 8px; margin-top: 14px; background: rgba(255,255,255,.16); border-radius: 12px; padding: 0 12px; }
.lsearch-ic { opacity: .85; font-size: 14px; }
.lsearch input { flex: 1; background: none; border: none; outline: none; color: #fff; font-size: 16px; padding: 11px 0; font-family: inherit; }
.lsearch input::placeholder { color: rgba(255,255,255,.72); }
.fpills { display: flex; gap: 8px; margin-bottom: 12px; }
.fpill { font-size: 13px; font-weight: 600; padding: 7px 15px; border-radius: 999px; border: 1px solid var(--sep-strong); color: var(--text-2); background: var(--card); cursor: pointer; font-family: inherit; transition: all .12s; }
.fpill.on { background: var(--accent); color: #fff; border-color: var(--accent); }
/* รายงาน: กรองตามพื้นที่ */
.area-chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin: 0 -2px 4px; -webkit-overflow-scrolling: touch; }
.area-chips::-webkit-scrollbar { display: none; }
.area-chips .fpill { flex: none; white-space: nowrap; }
.sel-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 2px 12px; }
/* ปุ่มกลม สแกน QR หาเครื่อง (มุมซ้ายล่าง หน้ารายการ) */
.fab-qr { position: fixed; right: max(16px, calc(50% - 304px)); bottom: calc(80px + env(safe-area-inset-bottom)); width: 58px; height: 58px; border-radius: 50%; background: var(--brand-grad); color: #fff; border: none; display: grid; place-items: center; box-shadow: 0 8px 22px -6px rgba(179,18,31,.55); z-index: 45; cursor: pointer; transition: transform .1s; }
.fab-qr svg { width: 28px; height: 28px; stroke: #fff; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.fab-qr:active { transform: scale(.92); }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); z-index: 40;
  width: 100%; max-width: 640px;
  display: flex; justify-content: space-around; align-items: center;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border-top: 0.5px solid var(--sep);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: none; cursor: pointer; color: var(--muted); font-family: inherit; padding: 4px;
}
.nav-item .nico { font-size: 21px; line-height: 1; display: grid; place-items: center; }
.nav-item .nico svg { width: 23px; height: 23px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav-item .nlbl { font-size: 10.5px; font-weight: 600; }
.nav-item.on { color: var(--accent); }
.nav-item.primary .nico {
  width: 48px; height: 48px; border-radius: 16px; background: var(--brand-grad); color: #fff;
  display: grid; place-items: center; margin-top: -22px; box-shadow: 0 8px 18px rgba(179,18,31,.45); border: 3px solid var(--bg);
}
.nav-item.primary .nico svg { width: 24px; height: 24px; stroke: #fff; stroke-width: 2.4; }
.nav-item.primary .nlbl { margin-top: 1px; }

/* ---------- List ---------- */
.list-actions { display: flex; gap: 8px; margin-bottom: 16px; align-items: center; }
.search { flex: 1; position: relative; }
.search input {
  width: 100%; background: var(--card); border: 1px solid var(--sep-strong);
  border-radius: 11px; padding: 11px 12px 11px 36px; outline: none; font-size: 16px;
  color: var(--text); transition: box-shadow .15s; box-shadow: var(--shadow);
}
.search input::placeholder { color: var(--muted); }
.search input:focus { box-shadow: 0 0 0 3px var(--accent-tint); }
/* ไอคอนแว่นขยายในช่องค้นหา — ใช้ SVG (เส้นเดียวกับไอคอนอื่นในแอป) ไม่ใช้อิโมจิ */
.search::before {
  content: ""; position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; opacity: .5; background: currentColor;
  -webkit-mask: var(--ic-search) center/contain no-repeat;
          mask: var(--ic-search) center/contain no-repeat;
}

.record {
  display: flex; gap: 14px; align-items: center;
  background: var(--card); border: none;
  border-radius: var(--radius-card); padding: 12px 14px; margin-bottom: 12px;
  cursor: pointer; box-shadow: var(--shadow);
  transition: transform .12s ease, background .12s;
}
.record:active { transform: scale(.985); background: color-mix(in srgb, var(--card) 92%, var(--muted)); }
.record .thumb {
  width: 58px; height: 58px; border-radius: 13px; object-fit: cover;
  background: var(--field-alt); flex: none; display: grid; place-items: center; color: var(--muted); font-size: 24px;
}
/* ไม่มีรูป -> โชว์โลโก้แอปแทน (ไม่ใช่อิโมจิ) */
.record .thumb.logo { background: var(--accent-tint); }
.record .thumb.logo img { width: 60%; height: 60%; object-fit: contain; opacity: .9; }
.record .meta { flex: 1; min-width: 0; }
.record .meta .model { font-weight: 600; font-size: 16px; letter-spacing: -0.02em; display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.record .meta .serial { font-family: "SF Mono", ui-monospace, "Cascadia Mono", monospace; color: var(--text-2); font-size: 13px; word-break: break-all; margin-top: 1px; }
.record .meta .date { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.record .chev { color: var(--sep-strong); font-size: 20px; flex: none; font-weight: 600; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--pend-tint); color: var(--pend); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.done { color: var(--pass); background: var(--pass-tint); }
.badge.dup { color: #b45309; background: #fff4e5; border: 1px solid #fde3c0; }
@media (prefers-color-scheme: dark) { .badge.dup { color: #ffb057; background: #3a2a12; border-color: #5a3f18; } }
.badge.multi { color: #0a63b8; background: #e8f2fd; border: 1px solid #cfe4fb; }
.badge.multi::before, .badge.dup::before { display: none; }
@media (prefers-color-scheme: dark) { .badge.multi { color: #6db4f5; background: #10263c; border-color: #1d3f5e; } }
/* ไอคอน SVG ที่แทรกในบรรทัดข้อความเล็ก (วันที่/ชิป/ป้าย) — ให้ขนาดพอดีกับตัวอักษร ไม่ล้นบรรทัด */
.date .ei, .rcardh-ft .ei, .ss-chip .ei, .fpill .ei, .badge .ei,
.vlbl .ei, .lbl .ei, .gps-link .ei, .dh-eye .ei, .hint .ei { width: 1.05em; height: 1.05em; stroke-width: 1.9; }
.badge .ei { width: 13px; height: 13px; margin-right: -1px; }
.lsearch-ic .ei { width: 17px; height: 17px; color: var(--muted); }
.empty .big .ei, .lb-btn .ei { width: 1em; height: 1em; }
.empty .big .ei { width: 46px; height: 46px; stroke-width: 1.4; }
/* ป้ายสถานะซิงค์รายรายการ — ช่างดูปราดเดียวรู้ว่างานขึ้นเซิร์ฟเวอร์แล้วหรือยัง */
.badge.sync-ok, .badge.sync-wait, .badge.sync-off { border: 1px solid transparent; }
.badge.sync-ok::before, .badge.sync-wait::before, .badge.sync-off::before { display: none; }
.badge.sync-ok { color: var(--muted); background: transparent; border-color: var(--line); font-weight: 500; }
.badge.sync-wait { color: #b45309; background: #fff4e5; border-color: #fde3c0; }
.badge.sync-off { color: #9a3412; background: #ffece5; border-color: #ffd4c2; }
@media (prefers-color-scheme: dark) {
  .badge.sync-wait { color: #ffb057; background: #3a2a12; border-color: #5a3f18; }
  .badge.sync-off { color: #ff9c72; background: #3d1f14; border-color: #64301f; }
}
[data-theme="dark"] .badge.sync-wait { color: #ffb057; background: #3a2a12; border-color: #5a3f18; }
[data-theme="dark"] .badge.sync-off { color: #ff9c72; background: #3d1f14; border-color: #64301f; }

.record.sel { box-shadow: 0 0 0 2px var(--accent), var(--shadow); }
.record .check {
  width: 58px; height: 58px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-size: 22px; font-weight: 700; color: #fff; background: var(--field-alt); border: 2px solid var(--sep-strong);
}
.record .check.on { background: var(--accent); border-color: var(--accent); }

.gps-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.gps-box { flex: 1; min-width: 140px; font-size: 13.5px; }
.gps-link { color: var(--accent); text-decoration: none; font-weight: 600; }
.gps-empty { color: var(--muted); font-size: 13px; }

.empty { text-align: center; color: var(--muted); padding: 72px 20px; }
.empty .big { font-size: 52px; margin-bottom: 10px; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--accent); color: #fff; border: none; border-radius: 999px;
  padding: 15px 26px; font-size: 16px; font-weight: 600; letter-spacing: -0.01em;
  box-shadow: 0 6px 20px rgba(208,32,46,.4);
  display: flex; gap: 8px; align-items: center; cursor: pointer; transition: transform .12s;
}
.fab:active { transform: translateX(-50%) scale(.96); }
.fab[disabled] { opacity: .45; pointer-events: none; }
/* แถวปุ่มลอย 2 ปุ่ม (สร้างรายงาน + Excel) — วางเรียงกันแทนที่จะซ้อนกลางจอ */
.fab-row {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 30;
  display: flex; gap: 10px; align-items: center;
  width: max-content; max-width: calc(100vw - 24px);
}
.fab-row .fab { position: static; transform: none; bottom: auto; left: auto; padding: 14px 20px; font-size: 15px; }
.fab-row .fab:active { transform: scale(.96); }
.fab.alt { background: var(--card); color: var(--ink); box-shadow: 0 6px 20px rgba(0,0,0,.18); border: 1px solid var(--line); }
.fab.alt .ei { color: #1a7f4b; }
@media (max-width: 380px) { .fab-row .fab { padding: 13px 15px; font-size: 14px; } }

/* ---------- Fields & cards ---------- */
.field { margin-bottom: 18px; }
.field > label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 7px 2px; font-weight: 500; }
.field .req { color: var(--accent); }
.input, textarea.input {
  width: 100%; background: var(--field); border: 0.5px solid var(--sep-strong);
  border-radius: var(--radius-field); padding: 13px 14px; outline: none; font-size: 16px;
  color: var(--text); transition: box-shadow .15s, border-color .15s;
}
.input:focus, textarea.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3.5px var(--accent-tint); }
.input.mono { font-family: "SF Mono", ui-monospace, "Cascadia Mono", monospace; letter-spacing: 0.02em; font-size: 17px; font-weight: 500; }
textarea.input { resize: vertical; min-height: 96px; line-height: 1.5; }
select.input { -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238e8e93' d='M6 8 0 2 1.4.6 6 5.2 10.6.6 12 2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }

/* iOS segmented control */
.segment { display: flex; background: var(--field-alt); border-radius: 11px; padding: 3px; gap: 3px; }
.seg-opt {
  flex: 1; border: none; background: transparent; color: var(--text); padding: 10px 8px;
  border-radius: 8px; font-weight: 600; font-size: 15px; cursor: pointer; transition: all .18s ease;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
.seg-opt .ei { width: 17px; height: 17px; }
.seg-opt.on { background: var(--seg-on); box-shadow: 0 1px 3px rgba(0,0,0,.14); }
.seg-opt.done.on { color: var(--pass); }

.card {
  background: var(--card); border: none;
  border-radius: var(--radius-card); padding: 16px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 14px; font-size: 16px; font-weight: 600; letter-spacing: -0.02em; display: flex; align-items: center; gap: 9px; }
.card h3 .n { width: 24px; height: 24px; border-radius: 7px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 700; flex: none; }

/* photo capture */
.photo-slot { border-radius: 14px; overflow: hidden; background: var(--field-alt); position: relative; }
.photo-slot .ph {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 34px 12px; color: var(--muted); cursor: pointer; text-align: center;
  border: 1.5px dashed var(--sep-strong); border-radius: 14px;
}
.photo-slot .ph .ic { font-size: 34px; line-height: 0; }
.photo-slot .ph .ic .ei { width: 34px; height: 34px; stroke-width: 1.6; }
.photo-slot img.preview { width: 100%; max-height: 300px; object-fit: contain; background: #000; }
.photo-slot .bar { display: flex; gap: 8px; padding: 10px; border-top: 0.5px solid var(--sep); background: var(--card); }

.btn {
  background: var(--field-alt); border: none; color: var(--blue);
  border-radius: 11px; padding: 12px 14px; font-weight: 600; cursor: pointer; font-size: 15px;
  display: inline-flex; align-items: center; gap: 6px; justify-content: center; transition: transform .1s, filter .12s;
}
.btn:active { transform: scale(.97); filter: brightness(.95); }
.btn.brand { background: var(--accent); color: #fff; }
.btn.ghost { background: var(--field-alt); }
.btn.danger { color: var(--danger); background: var(--field-alt); }
.btn.sm { padding: 9px 12px; font-size: 14px; }
.btn.block { width: 100%; }

/* ---- หน้าแผนที่ (จอคอม) ---- */
.mapv-top { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.mapv-top h1 { font-size: 22px; font-weight: 700; margin: 0; }
.mapv-cnt { margin-left: auto; font-size: 13px; color: var(--muted); }
.mapv-cnt b { color: var(--text); }
.mapv-body { display: grid; grid-template-columns: 1fr 300px; gap: 16px; }
.mapv-canvas { height: 600px; border-radius: 16px; overflow: hidden; border: 1px solid var(--sep); background: var(--field-alt); isolation: isolate; z-index: 0; }
.mapv-list { max-height: 600px; overflow-y: auto; background: var(--card); border: 1px solid var(--sep); border-radius: 16px; }
.mapv-search { position: sticky; top: 0; z-index: 2; background: var(--card); padding: 10px 12px; border-bottom: 1px solid var(--sep); }
.mapv-search input { width: 100%; background: var(--field-alt); border: 1px solid var(--sep-strong); border-radius: 9px; padding: 9px 11px; color: var(--text); font-family: inherit; font-size: 14px; outline: none; }
.mapv-search input::placeholder { color: var(--muted); }
.mrow2 { display: flex; align-items: center; gap: 11px; width: 100%; text-align: left; background: none; border: none; border-bottom: 1px solid var(--sep); padding: 11px 14px; cursor: pointer; color: var(--text); font-family: inherit; }
.mrow2:hover { background: var(--field-alt); }
.pin-dot { width: 14px; height: 14px; border-radius: 50%; flex: none; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--sep-strong); }
.pin-dot.done { background: #16a34a; } .pin-dot.pend { background: #e08a00; }
.mrow2 .sr { font-family: "IBM Plex Mono", monospace; font-size: 13px; font-weight: 600; }
.mrow2 .st { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.nogps2 { padding: 12px 14px; font-size: 12px; color: var(--muted); line-height: 1.6; }
.nogps2 b { color: var(--pend); }
.lf-pin-wrap svg { filter: drop-shadow(0 3px 4px rgba(0,0,0,.4)); }
/* วงกลมรวมกลุ่มหมุด (cluster) */
.lf-cluster-wrap { background: none !important; border: none !important; }
.lf-cluster { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-family: "IBM Plex Mono", monospace; font-weight: 700; border: 3px solid rgba(255,255,255,.92); box-shadow: 0 3px 8px rgba(0,0,0,.35); position: relative; }
.lf-cluster::after { content: ""; position: absolute; inset: -8px; border-radius: 50%; background: currentColor; opacity: .2; }
.lf-cluster span { position: relative; font-size: 15px; }
.lf-cluster.lo { background: #2ea56b; color: #2ea56b; } .lf-cluster.lo span { color: #fff; }
.lf-cluster.mid { background: #e0a020; color: #e0a020; } .lf-cluster.mid span { color: #fff; }
.lf-cluster.hi { background: #d0202e; color: #d0202e; } .lf-cluster.hi span { color: #fff; }
/* ป้ายชื่อเครื่อง (ขึ้นเองเมื่อซูมใกล้) */
.mapv .leaflet-tooltip.lf-lbl { background: var(--card); color: var(--text); border: 1px solid var(--sep-strong); border-radius: 7px; font-family: "IBM Plex Mono", monospace; font-size: 11px; font-weight: 600; padding: 2px 7px; box-shadow: 0 2px 6px rgba(0,0,0,.25); }
.mapv .leaflet-tooltip.lf-lbl::before { display: none; }
/* ป๊อปอัปแผนที่ = การ์ดสวย (รองรับธีมมืด/สว่าง) */
.mapv .leaflet-popup-content-wrapper { background: var(--card); color: var(--text); border-radius: 14px; box-shadow: 0 10px 30px -8px rgba(0,0,0,.45); }
.mapv .leaflet-popup-content { margin: 13px 15px; width: 214px !important; font-family: "Prompt", "Noto Sans Thai", sans-serif; }
.mapv .leaflet-popup-tip { background: var(--card); }
.mapv .leaflet-popup-close-button { color: var(--muted) !important; padding: 6px 7px 0 0 !important; }
.lf-pop .lf-pic { width: 100%; height: 100px; object-fit: cover; border-radius: 9px; margin-bottom: 9px; background: var(--field-alt); display: block; }
.lf-pop .lf-sr { font-family: "IBM Plex Mono", monospace; font-weight: 600; font-size: 14.5px; color: var(--text); }
.lf-pop .lf-md { font-size: 12px; color: var(--muted); margin-top: 2px; }
.lf-pop .lf-row { display: flex; align-items: center; gap: 8px; margin-top: 9px; }
.lf-pop .lf-tag { font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 99px; }
.lf-pop .lf-tag.done { background: var(--pass-tint); color: var(--pass); }
.lf-pop .lf-tag.pend { background: var(--pend-tint); color: var(--pend); }
.lf-pop .lf-co { font-family: "IBM Plex Mono", monospace; font-size: 11.5px; color: var(--muted); }
.lf-pop .lf-act { display: flex; gap: 8px; margin-top: 11px; }
.lf-pop .lf-act a { flex: 1; text-align: center; font-size: 12.5px; font-weight: 600; text-decoration: none; padding: 8px 6px; border-radius: 9px; }
.lf-pop .lf-act .lf-go { background: var(--brand-grad); color: #fff; }
.lf-pop .lf-act .lf-mp { background: var(--field-alt); color: var(--text-2); border: 1px solid var(--sep-strong); }
.mapv-seg { display: none; }   /* ปุ่มสลับ = เฉพาะมือถือ */
@media (max-width: 900px){
  .mapv-body { grid-template-columns: 1fr; }
  .mapv-seg { display: inline-flex; gap: 4px; background: var(--field-alt); border-radius: 99px; padding: 4px; width: max-content; }
  .mapv-seg button { border: none; background: none; color: var(--text-2); font-family: inherit; font-size: 13px; font-weight: 600; padding: 7px 20px; border-radius: 99px; cursor: pointer; }
  .mapv-seg button.on { background: var(--accent); color: #fff; }
  .mapv.view-map .mapv-list { display: none; }
  .mapv.view-list .mapv-canvas { display: none; }
  .mapv.view-map .mapv-canvas { height: calc(100vh - 190px); }
  .mapv.view-list .mapv-list { max-height: calc(100vh - 190px); }
}
/* จอคอม: ให้แผนที่ยืดเต็มความสูงจอ (ไม่เหลือที่ว่างด้านล่าง) */
@media (min-width: 1024px){
  body.authed .content:has(.mapv) { padding-bottom: 16px; }
  .mapv { display: flex; flex-direction: column; height: calc(100vh - 42px); }
  .mapv-body { flex: 1; min-height: 0; }
  .mapv-canvas { height: 100%; }
  .mapv-list { max-height: 100%; }
}
.btn:disabled { opacity: .45; pointer-events: none; }

/* ไอคอนเส้นในปุ่ม/ป้าย (แทนอิโมจิ) */
.ei { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.2em; }
.dh-lb .ei { vertical-align: -.15em; margin-right: 2px; }

.ocr-status {
  display: none; align-items: center; gap: 12px; margin-top: 12px;
  background: var(--field-alt); border-radius: 12px; padding: 12px 14px; font-size: 14px;
}
.ocr-status.on { display: flex; }
.spinner { width: 20px; height: 20px; border: 2.5px solid var(--sep); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress { flex: 1; height: 6px; background: var(--sep); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .2s; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip {
  background: var(--accent-tint); border: none; border-radius: 999px; color: var(--accent-press);
  padding: 8px 14px; font-size: 14px; cursor: pointer; font-family: "SF Mono", ui-monospace, monospace; font-weight: 600;
  transition: transform .1s;
}
.chip:active { transform: scale(.95); }
.chips-label { font-size: 13px; color: var(--muted); margin-top: 14px; }

details.raw { margin-top: 12px; }
details.raw summary { cursor: pointer; color: var(--blue); font-size: 14px; font-weight: 500; }
details.raw pre { white-space: pre-wrap; word-break: break-word; background: var(--field-alt); border-radius: 10px; padding: 12px; font-size: 12.5px; max-height: 170px; overflow: auto; margin-top: 8px; }

/* photo grids (รูปตัวเครื่อง + รูปงาน) */
.wp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.wp-item { background: var(--field-alt); border-radius: 13px; overflow: hidden; box-shadow: var(--shadow); }
.wp-item img { width: 100%; height: 120px; object-fit: cover; background: #000; }
.wp-item input { width: 100%; border: none; border-top: 0.5px solid var(--sep); background: transparent; padding: 9px 10px; font-size: 14px; outline: none; color: var(--text); }
.wp-add {
  border: 1.5px dashed var(--sep-strong); border-radius: 13px; min-height: 150px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  color: var(--muted); cursor: pointer; transition: background .12s;
}
.wp-add:active { background: var(--field-alt); }
.wp-cell { position: relative; }
.wp-cell .del {
  position: absolute; top: 7px; right: 7px; width: 28px; height: 28px; border-radius: 50%;
  background: rgba(0,0,0,.55); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  border: none; color: #fff; cursor: pointer; font-size: 14px; z-index: 2; display: grid; place-items: center;
}

.editor-actions {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 25;
  display: flex; gap: 10px; padding: 12px 18px; padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border-top: 0.5px solid var(--sep);
  max-width: 640px; margin: 0 auto;
}
.editor-actions .btn { flex: 1; padding: 15px; font-size: 16px; }

.hint { font-size: 12.5px; color: var(--muted); margin-top: 8px; line-height: 1.5; }

/* Checklist */
.ck-badge { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--field-alt); padding: 3px 10px; border-radius: 999px; }
.ck-quick { margin-bottom: 10px; }
.ck-sec { font-size: 12px; font-weight: 700; color: var(--accent); margin: 14px 0 6px; }
.ck-item { padding: 8px 0; border-bottom: 1px solid var(--sep); }
.ck-item:last-child { border-bottom: none; }
.ck-top { margin-bottom: 7px; }
.ck-label { font-size: 14px; }
.ck-unit { color: var(--muted); font-size: 12px; }
.ck-controls { display: flex; align-items: center; gap: 8px; }
.ck-val { width: 78px; flex: none; background: var(--field); border: 0.5px solid var(--sep-strong); border-radius: 9px; padding: 8px 10px; font-size: 15px; outline: none; color: var(--text); font-family: "SF Mono", ui-monospace, monospace; }
.ck-val:focus { border-color: var(--accent); }
.ck-btns { display: flex; gap: 6px; flex: 1; }
.ck-b { flex: 1; border: 1px solid var(--sep-strong); background: var(--field); color: var(--muted); border-radius: 9px; padding: 8px 4px; font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit; transition: all .12s; }
.ck-b:active { transform: scale(.96); }
.ck-b.pass.on { background: #e7f8ec; border-color: #34c759; color: #1a8a3d; }
.ck-b.fail.on { background: #ffecec; border-color: var(--danger); color: #d02a20; }
.ck-b.na.on { background: var(--field-alt); border-color: var(--sep-strong); color: var(--text); }
@media (prefers-color-scheme: dark) {
  .ck-b.pass.on { background: rgba(52,199,89,.22); color: #5be584; }
  .ck-b.fail.on { background: rgba(255,59,48,.22); color: #ff8a82; }
}
.ck-note { display: block; width: 100%; margin-top: 8px; background: var(--field); border: 0.5px solid var(--danger); border-radius: 9px; padding: 9px 11px; font-size: 14px; outline: none; color: var(--text); }
.ck-note.hidden { display: none; }

/* ---- จัดการ Checklist (แก้ไข/เพิ่ม/ลบ) ---- */
.ckm-sechead { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.ckm-secname { flex: 1; font-weight: 700; }
.ckm-item { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.ckm-item .input { flex: 1; min-width: 0; }
.ckm-item .ckm-unit { width: 66px; flex: none; padding-right: 26px; }
.ckm-item .btn.sm.danger { flex: none; padding: 9px 11px; }

/* รูปที่โหลดไม่สำเร็จ (เน็ตหลุด) — แสดงเป็นปุ่มแตะเพื่อโหลดใหม่ แทนกล่องดำ */
img.img-failed {
  background: var(--field-alt) !important;
  border: 1px dashed var(--sep-strong);
  min-height: 90px;
  cursor: pointer;
  position: relative;
}

/* ครอปภาพจากป้าย เหนือช่อง Model/Serial */
.ocr-crop { margin-bottom: 10px; border-radius: 12px; overflow: hidden; background: #fff; box-shadow: var(--shadow); }
.ocr-crop .tag { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: #fff; background: var(--accent); padding: 6px 10px; font-weight: 600; }
.ocr-crop .tag .ei { width: 15px; height: 15px; vertical-align: 0; }
.ocr-crop img { width: 100%; max-height: 96px; object-fit: contain; background: #fff; padding: 6px; }
.fix-note { font-size: 12.5px; color: var(--text-2); background: var(--accent-tint); border-radius: 10px; padding: 8px 10px; margin-top: 8px; line-height: 1.5; }

/* เสนอสถานที่ติดตั้งล่าสุด (แตะเพื่อเติม) */
.site-suggest { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-top: 9px; }
.site-suggest .ss-lbl { font-size: 12px; color: var(--muted); width: 100%; margin-bottom: 1px; }
.ss-chip { border: 1px solid var(--accent); background: var(--accent-tint); color: var(--accent); border-radius: 999px; padding: 7px 13px; font-size: 13.5px; font-weight: 600; cursor: pointer; font-family: inherit; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; transition: transform .1s; }
.ss-chip:active { transform: scale(.95); }

/* ประวัติการตรวจเครื่องเดียวกัน */
.hist-list { display: flex; flex-direction: column; gap: 9px; }
.hist-item { display: block; width: 100%; text-align: left; background: var(--field-alt); border: 0.5px solid var(--sep); border-radius: 12px; padding: 11px 13px; cursor: pointer; font-family: inherit; color: var(--text); transition: transform .1s; }
.hist-item:active { transform: scale(.985); }
.hist-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hist-num { font-size: 12px; font-weight: 700; color: var(--text-2); background: var(--sep-strong); padding: 2px 9px; border-radius: 999px; }
.hist-latest { font-size: 11px; font-weight: 700; color: var(--accent); background: var(--accent-tint); padding: 2px 9px; border-radius: 999px; }
.hist-date { font-size: 13.5px; font-weight: 700; }
.hist-prob { margin-left: auto; font-size: 12px; font-weight: 700; color: var(--danger); background: rgba(255,59,48,.12); padding: 2px 9px; border-radius: 999px; }
.hist-ok { margin-left: auto; font-size: 12px; font-weight: 600; color: #1a8a3d; }
.hist-site { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.hist-log { font-size: 13px; color: var(--text-2); margin-top: 5px; line-height: 1.45; }

/* ไอคอน "กำลังโหลด" หมุน ๆ */
.spin-load { display: inline-block; animation: spinLoad 1.6s linear infinite; }
@keyframes spinLoad { to { transform: rotate(360deg); } }

/* แถบ progress ตอนอัปโหลดรูปทีละใบ */
.up-prog { position: fixed; inset: 0; z-index: 9000; display: grid; place-items: center; background: rgba(0,0,0,.45); backdrop-filter: blur(2px); }
.up-card { width: min(78%, 300px); background: var(--card, #fff); border-radius: 16px; padding: 20px 20px 22px; box-shadow: 0 12px 40px rgba(0,0,0,.28); text-align: center; }
.up-msg { font-size: 15px; font-weight: 700; color: var(--text); margin-bottom: 14px; }
.up-bar { height: 10px; border-radius: 999px; background: var(--field-alt); overflow: hidden; }
.up-bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .25s ease; }
.dup-warn { font-size: 12.5px; font-weight: 600; color: #0a63b8; background: #e8f2fd; border: 1px solid #cfe4fb; border-radius: 10px; padding: 9px 11px; margin-top: 8px; cursor: pointer; line-height: 1.5; }
@media (prefers-color-scheme: dark) { .dup-warn { background: #10263c; color: #6db4f5; border-color: #1d3f5e; } }

/* toast */
.toast {
  position: fixed; bottom: calc(100px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%) translateY(20px);
  background: rgba(30,30,32,.92); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  color: #fff; padding: 13px 20px; border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.3); z-index: 120;
  opacity: 0; pointer-events: none; transition: all .28s cubic-bezier(.2,.9,.3,1.2); font-size: 14.5px; font-weight: 500; max-width: 90%;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: rgba(255,59,48,.94); }

/* Login */
.login-wrap { min-height: 68vh; display: grid; place-items: center; padding: 10px; }
.login-card { background: var(--card); border-radius: 20px; box-shadow: var(--shadow); padding: 30px 24px; width: 100%; max-width: 340px; text-align: center; }
.login-logo { width: 64px; height: 64px; border-radius: 16px; margin: 0 auto 14px; box-shadow: var(--shadow); }
.login-title { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.login-sub { font-size: 13px; color: var(--muted); margin: 4px 0 20px; }
.login-card .input { margin-bottom: 12px; text-align: left; }
.pw-wrap { position: relative; margin-bottom: 12px; }
.login-card .pw-wrap .input { margin-bottom: 0; padding-right: 46px; }
.pw-eye { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; border: none; background: none; color: var(--muted); display: grid; place-items: center; cursor: pointer; border-radius: 8px; }
.pw-eye:hover { color: var(--text-2); background: var(--field-alt); }
.pw-eye .ei { width: 20px; height: 20px; }
.login-err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 16px; font-weight: 600; }

.ro-banner { background: #fff4e5; color: #b45309; border: 1px solid #fde3c0; border-radius: 12px; padding: 10px 12px; font-size: 13px; font-weight: 600; text-align: center; margin-bottom: 14px; }
@media (prefers-color-scheme: dark) { .ro-banner { background: #3a2a12; color: #ffb057; border-color: #5a3f18; } }

/* Viewer detail — red hero */
.dhero { background: var(--brand-grad); color: #fff; margin: -18px -18px 0; padding: 14px 20px 42px; border-radius: 0 0 26px 26px; box-shadow: 0 14px 30px -16px rgba(179,18,31,.45); position: relative; overflow: hidden; }
.dhero::after { content: ""; position: absolute; right: -40px; top: -50px; width: 170px; height: 170px; border-radius: 50%; background: rgba(255,255,255,.08); }
.dh-top { display: flex; align-items: center; gap: 10px; position: relative; z-index: 1; }
.dh-bk { width: 34px; height: 34px; border-radius: 11px; background: rgba(255,255,255,.16); border: none; color: #fff; font-size: 22px; line-height: 1; cursor: pointer; display: grid; place-items: center; font-family: inherit; }
.dh-tt { font-weight: 600; font-size: 16px; flex: 1; }
.dh-eye { font-size: 11px; font-weight: 600; background: rgba(255,255,255,.16); padding: 5px 10px; border-radius: 999px; }
.dh-lb { font-size: 11px; opacity: .85; font-weight: 600; letter-spacing: .05em; margin-top: 16px; position: relative; z-index: 1; }
.dh-sr { font-size: 22px; font-weight: 600; letter-spacing: .04em; margin-top: 5px; word-break: break-all; position: relative; z-index: 1; }
.dh-md { font-size: 13.5px; opacity: .92; margin-top: 2px; position: relative; z-index: 1; }
.dh-pill { display: inline-flex; align-items: center; gap: 5px; margin-top: 13px; background: rgba(255,255,255,.18); padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; position: relative; z-index: 1; }
.vbody { padding-top: 16px; }
.vbody .card { margin-bottom: 14px; }
.ed-hero { margin: -18px -18px 16px; }

/* Checklist summary banner (แดง) */
.ck-summary { display: flex; align-items: center; gap: 14px; background: var(--brand-grad); color: #fff; border-radius: 14px; padding: 13px 15px; margin-bottom: 12px; box-shadow: 0 10px 22px -14px rgba(179,18,31,.5); }
.ck-summary.has-fail { background: linear-gradient(135deg, #e2a33a, #c17e12); box-shadow: 0 10px 22px -14px rgba(193,126,18,.5); }
.ck-sum-n { font-weight: 700; font-size: 19px; background: rgba(255,255,255,.22); border-radius: 12px; padding: 8px 12px; flex: none; font-variant-numeric: tabular-nums; }
.ck-sum-txt .a { font-weight: 600; font-size: 15px; }
.ck-sum-txt .b { font-size: 12px; opacity: .93; margin-top: 3px; }

/* Viewer summary */
.vfield { display: flex; flex-direction: column; gap: 3px; padding: 9px 0; border-bottom: 1px solid var(--sep); }
.vlbl { font-size: 11.5px; color: var(--muted); }
.vval { font-size: 15px; font-weight: 500; }
.note-view { white-space: pre-wrap; background: var(--field-alt); border-left: 3px solid var(--accent); border-radius: 8px; padding: 12px 14px; font-size: 14px; min-height: 20px; }
.vck-item { display: flex; gap: 9px; align-items: flex-start; padding: 6px 0; font-size: 13.5px; border-bottom: 1px solid var(--sep); }
.vck-ic { width: 20px; text-align: center; font-weight: 800; flex: none; }
.vck-pass .vck-ic { color: #1a8a3d; }
.vck-fail { color: var(--danger); }
.vck-fail .vck-ic { color: var(--danger); }
.vck-na .vck-ic { color: var(--muted); }

/* Bottom sheet menu */
.sheet-wrap { position: fixed; inset: 0; z-index: 1200; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.42); opacity: 0; transition: opacity .25s; }
.sheet-wrap.show .sheet-backdrop { opacity: 1; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 640px; margin: 0 auto;
  background: var(--bg-elev); border-radius: 22px 22px 0 0;
  padding: 6px 16px calc(16px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .3s cubic-bezier(.2,.9,.3,1);
  box-shadow: 0 -10px 34px rgba(0,0,0,.22);
  /* เมนูยาวเกินจอ -> ให้เลื่อนในตัวเมนูเอง (เดิมไม่มี ส่วนบนเลยทะลุออกนอกจอ เลื่อนกลับขึ้นไม่ได้) */
  max-height: 86vh;
  max-height: 86dvh;            /* มือถือ: กันแถบ URL บังด้านล่าง */
  overflow-y: auto;
  overscroll-behavior: contain;  /* เลื่อนสุดแล้วไม่ไปลากหน้าเว็บข้างหลัง */
  -webkit-overflow-scrolling: touch;
}
.sheet-wrap.show .sheet { transform: translateY(0); }
/* ที่จับ + หัวเรื่อง ปักไว้ด้านบน — เลื่อนลงไปไกลแค่ไหนก็ยังเห็นและกดกลับขึ้นได้ */
.sheet-handle {
  width: 40px; height: 5px; border-radius: 999px; background: var(--sep-strong);
  margin: 0 auto 10px; position: sticky; top: 0; z-index: 3;
  box-shadow: 0 0 0 8px var(--bg-elev), 0 8px 0 8px var(--bg-elev);
  cursor: pointer;
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 4px; padding: 6px 4px 8px;
  position: sticky; top: 13px; z-index: 2; background: var(--bg-elev);
}
.sheet-title { font-size: 19px; font-weight: 800; letter-spacing: -.02em; }
.sheet-user { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; color: var(--accent); background: var(--accent-tint); padding: 5px 12px; border-radius: 999px; }
.sheet-user .ru-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.sheet-user.view { color: var(--muted); background: var(--field-alt); }
.sheet-user.view .ru-dot { background: var(--muted); }

.mi-sec { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 15px 6px 7px; }
.mi-group { background: var(--field-alt); border-radius: 16px; overflow: hidden; }
/* หมวด "ขั้นสูง" — ย่อไว้ กดกางเมื่อต้องใช้ */
.mi-adv { margin-top: 2px; }
.mi-adv > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px; }
.mi-adv > summary::-webkit-details-marker { display: none; }
.mi-adv .mi-adv-chev { display: inline-flex; transition: transform .2s; }
.mi-adv .mi-adv-chev svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; transform: rotate(90deg); }
.mi-adv[open] .mi-adv-chev { transform: rotate(180deg); }
.mi-adv > summary:active { opacity: .6; }
.mi-row {
  display: flex; align-items: center; gap: 13px; width: 100%; text-align: left;
  background: none; border: none; color: var(--text); font-family: inherit; cursor: pointer;
  padding: 13px 14px; position: relative; transition: filter .12s;
}
.mi-row + .mi-row::before { content: ""; position: absolute; left: 60px; right: 0; top: 0; height: 1px; background: var(--sep-strong); }
.mi-row:active { filter: brightness(.94); }
.mi-tile { width: 38px; height: 38px; flex: none; border-radius: 11px; display: grid; place-items: center; background: rgba(120,120,128,.16); color: var(--text-2); }
.mi-row.brand .mi-tile, .mi-row.danger .mi-tile { background: var(--accent-tint); color: var(--accent); }
.mi-tile svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.mi-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.mi-lbl { font-size: 15px; font-weight: 600; line-height: 1.25; }
.mi-row.danger .mi-lbl { color: var(--accent); }
.mi-sub { font-size: 11px; color: var(--muted); }
.mi-chev { color: var(--muted); flex: none; display: grid; }
.mi-chev svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sheet-cancel {
  width: 100%; margin-top: 12px; padding: 15px; border: none; border-radius: 13px;
  background: var(--field-alt); color: var(--text); font-size: 15px; font-weight: 700; cursor: pointer; font-family: inherit;
}
.sheet-cancel:active { filter: brightness(.95); }
.sheet-ver { text-align: center; font-size: 11px; color: var(--muted); margin-top: 10px; letter-spacing: .02em; }
/* ตัวเลือกธีมในเมนู */
.theme-seg { display: flex; gap: 4px; background: var(--field-alt); border-radius: 14px; padding: 4px; }
.theme-seg button {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; background: none; color: var(--text-2); font-family: inherit; font-size: 13px; font-weight: 600;
  padding: 9px 6px; border-radius: 10px; cursor: pointer;
}
.theme-seg button .ei { width: 16px; height: 16px; }
.theme-seg button.on { background: var(--seg-on); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.18); }

/* ================= เวอร์ชันจอคอม (Desktop ≥1024px) ================= */
.dsk-side { display: none; }   /* มือถือ: ซ่อน */

@media (min-width: 1024px) {
  body.authed .dsk-side {
    display: flex; flex-direction: column; gap: 4px;
    position: fixed; left: 0; top: 0; bottom: 0; width: 248px; z-index: 30;
    background: var(--card); border-right: 1px solid var(--sep); padding: 18px 14px;
  }
  .dsk-brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 16px; }
  .dsk-mk { width: 38px; height: 38px; border-radius: 11px; background: var(--brand-grad); display: grid; place-items: center; flex: none; }
  .dsk-mk img { width: 24px; height: 24px; }
  .dsk-brand b { font-size: 16px; font-weight: 700; display: block; line-height: 1.1; color: var(--text); }
  .dsk-brand span { font-size: 11px; color: var(--muted); }
  .dsk-nav { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
  .dsk-a { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 11px; color: var(--text-2); background: none; border: none; font-family: inherit; font-size: 14.5px; font-weight: 500; cursor: pointer; text-align: left; }
  .dsk-a .ei { width: 20px; height: 20px; }
  .dsk-a:hover { background: var(--field-alt); color: var(--text); }
  .dsk-a.on { background: var(--accent-tint); color: var(--accent); font-weight: 600; }
  .dsk-sp { flex: 1; }
  .dsk-user { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 12px; background: var(--field-alt); }
  .dsk-av { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-grad); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 14px; flex: none; }
  .dsk-nm { font-size: 13.5px; font-weight: 600; line-height: 1.2; color: var(--text); }
  .dsk-rl { font-size: 11px; color: var(--muted); }

  .topbar { display: none; }
  .fab-qr { display: none; }   /* จอคอม: ไม่ต้องมีปุ่ม QR ลอย */
  body.authed .app { max-width: none; margin: 0; padding-left: 248px; }
  body.authed .bottom-nav { display: none; }
  body.authed .content { padding: 26px 34px 40px; }
  /* จัดกึ่งกลางที่ตัวเนื้อหา (content เป็น flex item จึงห้าม margin:auto ที่ตัวมัน) */
  body.authed .dsh { max-width: 1300px; margin: 0 auto; }
  /* หน้าแก้ไข/ดู: คอลัมน์แคบลง จัดกึ่งกลาง (ไม่กองซ้าย) */
  body.authed .editor { max-width: 900px; margin: 0 auto; }
  body.authed .ed-hero { margin: 0 0 16px; }
  /* แถบปุ่มบันทึก: การ์ดลอยมุมมน จัดกึ่งกลางให้ตรงกับฟอร์ม */
  body.authed .editor-actions {
    left: 248px; right: 0; max-width: 900px; margin: 0 auto;
    bottom: 18px; border-radius: 16px; border: 1px solid var(--sep);
    box-shadow: 0 10px 30px -10px rgba(0,0,0,.35);
  }
  /* หน้าดูรายละเอียด (viewer) จัดกึ่งกลางเช่นกัน */
  body.authed .dhero:not(.ed-hero), body.authed .vbody { max-width: 900px; margin-left: auto; margin-right: auto; }

  /* ---- แดชบอร์ด + ตาราง ---- */
  .dsh-top { display: flex; align-items: center; gap: 16px; margin-bottom: 22px; }
  .dsh-h1 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin: 0; }
  .dsh-rt { margin-left: auto; display: flex; align-items: center; gap: 10px; }
  .dsh-search { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--sep); border-radius: 11px; padding: 9px 13px; width: 280px; }
  .dsh-search .ei { width: 17px; height: 17px; color: var(--muted); flex: none; }
  .dsh-search input { border: none; background: none; outline: none; color: var(--text); font-family: inherit; font-size: 14px; width: 100%; }
  .dsh-new { display: inline-flex; align-items: center; gap: 8px; background: var(--brand-grad); color: #fff; border: none; border-radius: 11px; padding: 11px 16px; font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
  .dsh-new .ei { width: 18px; height: 18px; }

  .dsh-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
  .dsh-stat { background: var(--card); border: 1px solid var(--sep); border-radius: 16px; padding: 16px 18px; box-shadow: var(--shadow); }
  .dsh-sl { font-size: 12.5px; color: var(--muted); font-weight: 500; }
  .dsh-sn { font-size: 30px; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
  .dsh-sn.ok { color: var(--pass); }
  .dsh-sn.wait { color: var(--pend); }

  .dsh-bar { margin-bottom: 14px; }

  .dsh-tablewrap { background: var(--card); border: 1px solid var(--sep); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); }
  .dsh-table { width: 100%; border-collapse: collapse; }
  .dsh-table thead th { text-align: left; font-size: 11.5px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 13px 16px; border-bottom: 1px solid var(--sep); background: var(--field-alt); }
  .dsh-table tbody td { padding: 11px 16px; border-bottom: 1px solid var(--sep); font-size: 14px; vertical-align: middle; }
  .dsh-table tbody tr:last-child td { border-bottom: none; }
  .dsh-table tbody tr { cursor: pointer; }
  .dsh-table tbody tr:hover { background: var(--field-alt); }
  .dsh-mc { display: flex; align-items: center; gap: 12px; }
  .dsh-mc .thumb { width: 46px; height: 46px; border-radius: 10px; background: var(--field-alt); object-fit: cover; display: grid; place-items: center; overflow: hidden; flex: none; }
  .dsh-mc .thumb.logo { background: var(--accent-tint); }
  .dsh-mc .thumb.logo img { width: 55%; height: 55%; object-fit: contain; opacity: .9; }
  .dsh-sr { font-family: "IBM Plex Mono", monospace; font-size: 13.5px; font-weight: 600; }
  .dsh-md { font-size: 12px; color: var(--muted); margin-top: 2px; }
  .dsh-num { font-variant-numeric: tabular-nums; color: var(--text-2); }
  .dsh-dim { color: var(--muted); }
  .dsh-r { text-align: right; }
  .dsh-go { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--sep); color: var(--muted); }
  .dsh-go .ei { width: 16px; height: 16px; }
  .dsh-table tbody tr:hover .dsh-go { color: var(--accent); border-color: var(--accent); }
  .dsh-empty { text-align: center; color: var(--muted); padding: 40px 0; }
}

.hidden { display: none !important; }
.file-input { display: none; }

img.zoomable { cursor: zoom-in; }

/* Lightbox */
#lightbox { position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,.94); display: none; flex-direction: column; }
#lightbox.show { display: flex; }
.lb-bar { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding: 14px; padding-top: max(14px, env(safe-area-inset-top)); }
.lb-btn {
  background: rgba(255,255,255,.16); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border: none; color: #fff; padding: 11px 15px; border-radius: 11px; font-size: 14.5px; font-weight: 600; cursor: pointer;
}
.lb-btn:active { transform: scale(.96); }
.lb-stage { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; padding: 10px; }
.lb-stage img { max-width: 100%; max-height: 100%; object-fit: contain; transition: transform .15s; cursor: zoom-in; }
.lb-stage img.zoom { max-width: none; max-height: none; width: 270%; height: auto; cursor: zoom-out; }

/* QR scanner */
.qr-scan { position: fixed; inset: 0; z-index: 210; background: #000; display: flex; flex-direction: column; }
.qr-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px; padding-top: max(14px, env(safe-area-inset-top)); color: #fff; font-size: 14px; }
.qr-stage { flex: 1; position: relative; overflow: hidden; display: grid; place-items: center; }
.qr-stage video { width: 100%; height: 100%; object-fit: cover; }
.qr-frame { position: absolute; width: 64vw; max-width: 300px; aspect-ratio: 1; border: 3px solid var(--accent); border-radius: 20px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); }
.qr-hint { position: absolute; bottom: 12%; color: #fff; background: rgba(0,0,0,.5); padding: 8px 16px; border-radius: 999px; font-size: 13px; }

/* ---------- เลือกตำแหน่งเองบนแผนที่ (หน้าแก้ไข -> "เลือกบนแผนที่") ---------- */
.gpspick {
  position: fixed; inset: 0; z-index: 1400;
  background: var(--bg); display: flex; flex-direction: column;
  isolation: isolate;   /* กัน z-index ภายในของ Leaflet ทะลุออกไปทับอย่างอื่น */
}
.gpspick-bar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: var(--bg-elev); border-bottom: 1px solid var(--sep); flex: none;
}
.gpspick-t { flex: 1; text-align: center; font-size: 13.5px; font-weight: 600; color: var(--muted); }
.gpspick-stage { position: relative; flex: 1; min-height: 0; }
.gpspick-map { position: absolute; inset: 0; background: var(--field-alt); }
/* หมุดปักนิ่งกลางจอ — ผู้ใช้ลากแผนที่ข้างใต้แทน (แม่นกว่าและถนัดกว่าบนมือถือ) */
.gpspick-cross {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -100%);
  pointer-events: none; z-index: 500;
  filter: drop-shadow(0 3px 5px rgba(0,0,0,.35));
}
.gpspick-dot {
  position: absolute; left: 50%; bottom: -4px; transform: translateX(-50%);
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 2px #fff;
}
.gpspick-foot {
  flex: none; padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
  background: var(--bg-elev); border-top: 1px solid var(--sep);
  display: flex; flex-direction: column; gap: 10px;
}
.gpspick-co { text-align: center; font-size: 14px; font-weight: 600; letter-spacing: .3px; }

/* ---------- แถวปุ่มเหนือแผนที่ + ปุ่มเปิด/ปิดป้ายชื่อ Serial ---------- */
.mapv-segrow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.mapv-lbltog {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--sep-strong); background: var(--card); color: var(--text-2);
  font-family: inherit; font-size: 13px; font-weight: 600;
  padding: 7px 14px; border-radius: 99px; cursor: pointer; transition: all .15s;
}
.mapv-lbltog .ei { width: 15px; height: 15px; }
.mapv-lbltog.on { background: var(--accent); color: #fff; border-color: transparent; }
.mapv-lbltog:active { transform: scale(.96); }

/* ---------- ปุ่มถ่ายรูป / เลือกจากคลัง ---------- */
/* ในช่องรูปป้ายที่ยังว่าง — ปุ่มคู่ใต้ไอคอนกล้อง */
.ph-btns { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; justify-content: center; }
.ph-btns .btn { pointer-events: auto; }
/* กล่องเพิ่มรูป (ตัวเครื่อง/งาน) — แบ่งเป็น 2 ปุ่ม ถ่าย/คลัง */
.wp-add { gap: 8px; padding: 8px; }
.wpadd-b {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  width: 100%; flex: 1; min-height: 0;
  border: none; background: var(--field-alt); color: var(--text-2);
  font-family: inherit; font-size: 12.5px; font-weight: 600;
  border-radius: 9px; padding: 10px 6px; cursor: pointer; transition: background .12s;
}
.wpadd-b:active { background: var(--sep); }
.wpadd-b .ei { width: 22px; height: 22px; }
.wpadd-b:first-child { color: var(--accent); }

/* ป้ายสถานะซิงค์แบบไอคอนล้วน (ไม่มีข้อความ) — ทำให้เป็นวงกลมพอดีไอคอน */
.badge.ic-only { padding: 4px; gap: 0; border-radius: 50%; line-height: 0; }
.badge.ic-only .ei { width: 15px; height: 15px; margin: 0; }

/* ---------- กล่องแสดงพื้นที่เก็บข้อมูล (เมนูขั้นสูง) ---------- */
.stor-box { background: var(--field-alt); border-radius: 14px; padding: 14px; margin-bottom: 10px; }
.stor-load { color: var(--muted); font-size: 13px; text-align: center; padding: 6px; }
.stor-h { display: flex; align-items: center; gap: 7px; font-size: 13.5px; font-weight: 700; margin-bottom: 10px; }
.stor-h .ei { width: 16px; height: 16px; }
.stor-bar { height: 10px; border-radius: 99px; background: var(--sep); overflow: hidden; }
.stor-fill { height: 100%; border-radius: 99px; transition: width .4s; }
.stor-fill.ok { background: var(--pass); }
.stor-fill.warn { background: var(--amber); }
.stor-fill.full { background: var(--danger); }
.stor-line { display: flex; justify-content: space-between; font-size: 13px; margin-top: 7px; }
.stor-line b { font-weight: 700; }
.stor-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.stor-rows { margin-top: 10px; border-top: 1px solid var(--sep); padding-top: 8px; display: flex; flex-direction: column; gap: 5px; }
.stor-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-2); }
.stor-row b { color: var(--text); font-weight: 700; }
.stor-warn { margin-top: 10px; font-size: 12.5px; font-weight: 600; color: var(--danger); background: var(--danger-tint, rgba(220,50,50,.1)); border-radius: 8px; padding: 8px 10px; }
