/* ===== 3-in-1 Combined Theme System (PEA Luxury + Smart Grid Dark + Clean Enterprise) ===== */
:root,
html[data-theme="pea"] {
  --pri: #4c1d95;
  --pri2: #6d28d9;
  --pri3: #7c3aed;
  --gold: #f59e0b;
  --gold-light: #fef3c7;
  --accent: #0ea5e9;
  --bg: #f3f0ff;
  --bg-grad: radial-gradient(1100px 550px at 8% -5%, rgba(124, 58, 237, 0.16), transparent 60%),
             radial-gradient(900px 500px at 95% 5%, rgba(245, 158, 11, 0.14), transparent 55%),
             linear-gradient(180deg, #f5f3ff 0%, #eef2ff 50%, #f8fafc 100%);
  --topbar-bg: linear-gradient(125deg, #2e1065 0%, #4c1d95 48%, #1e1b4b 100%);
  --hero-bg: linear-gradient(130deg, #240747 0%, #4c1d95 50%, #1e1b4b 100%);
  --card: rgba(255, 255, 255, 0.9);
  --card-solid: #ffffff;
  --surface: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --line: rgba(148, 163, 184, 0.25);
  --red: #ef4444;
  --green: #10b981;
  --amber: #f59e0b;
  --shadow: 0 12px 32px -8px rgba(46, 16, 101, 0.11), 0 4px 12px -2px rgba(15, 23, 42, 0.05);
  --radius: 20px;
  --navh: 68px;
}

html[data-theme="dark"] {
  --pri: #6366f1;
  --pri2: #8b5cf6;
  --pri3: #a855f7;
  --gold: #fbbf24;
  --gold-light: rgba(251, 191, 36, 0.16);
  --accent: #38bdf8;
  --bg: #090d16;
  --bg-grad: radial-gradient(1000px 500px at 10% 0%, rgba(139, 92, 246, 0.22), transparent 60%),
             radial-gradient(900px 500px at 90% 10%, rgba(14, 165, 233, 0.16), transparent 55%),
             linear-gradient(180deg, #090d16 0%, #0f172a 100%);
  --topbar-bg: linear-gradient(125deg, #090d16 0%, #1e1b4b 55%, #0f172a 100%);
  --hero-bg: linear-gradient(130deg, #161336 0%, #2e1065 52%, #0f172a 100%);
  --card: rgba(17, 24, 39, 0.88);
  --card-solid: #111827;
  --surface: #1e293b;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --line: rgba(148, 163, 184, 0.2);
  --shadow: 0 14px 34px -8px rgba(0, 0, 0, 0.55);
}

html[data-theme="clean"] {
  --pri: #0f3d75;
  --pri2: #1d4ed8;
  --pri3: #2563eb;
  --gold: #d97706;
  --gold-light: #fef3c7;
  --accent: #0284c7;
  --bg: #f1f5f9;
  --bg-grad: linear-gradient(180deg, #f1f5f9 0%, #e2e8f0 100%);
  --topbar-bg: linear-gradient(120deg, #0f172a 0%, #1e3a8a 60%, #1d4ed8 100%);
  --hero-bg: linear-gradient(125deg, #0f2942 0%, #1e3a8a 60%, #0369a1 100%);
  --card: rgba(255, 255, 255, 0.96);
  --card-solid: #ffffff;
  --surface: #f8fafc;
  --text: #0f172a;
  --muted: #475569;
  --line: #e2e8f0;
  --shadow: 0 8px 24px -4px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: 'Sarabun', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  padding-bottom: calc(var(--navh) + env(safe-area-inset-bottom) + 12px);
  position: relative;
  overflow-x: hidden;
}
body.noscroll { overflow: hidden; }
[hidden] { display: none !important; }

h1, h2, h3, .brand b, .seg-btn b {
  font-family: 'Prompt', 'Sarabun', sans-serif;
  letter-spacing: -0.01em;
}
h1 { font-size: clamp(1.3rem, 2.5vw, 1.75rem); margin: 0 0 6px; }
h2 { font-size: 1.12rem; margin: 0 0 6px; font-weight: 600; }
h3 { font-size: 1.05rem; margin: 0; font-weight: 600; }
p { margin: 0; }
a { color: var(--pri3); }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.green-t { color: var(--green); font-weight: 600; }
.warn-t { color: #d97706; font-weight: 600; }
.reject { color: #b45309; background: #fef3c7; padding: 3px 10px; border-radius: 8px; margin-top: 5px; display: inline-block; font-weight: 600; }

/* Decorative ambient orbs */
.bg-orb {
  position: fixed; border-radius: 50%; filter: blur(85px);
  pointer-events: none; z-index: 0; opacity: 0.42;
}
.orb-1 { width: 380px; height: 380px; background: #a855f7; top: -120px; left: -100px; }
.orb-2 { width: 340px; height: 340px; background: #f59e0b; bottom: -100px; right: -80px; }

#app { position: relative; z-index: 1; display: flex; flex-direction: column; min-height: 100vh; }

/* ---------- Topbar & Navigation ---------- */
.topbar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 18px;
  background: var(--topbar-bg);
  color: #fff;
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.28);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo-wrap { width: 46px; height: 46px; flex: none; display: grid; place-items: center; }
.logo {
  font-size: 1.55rem; width: 44px; height: 44px; border-radius: 14px;
  background: linear-gradient(135deg, #fbbf24, #d97706);
  color: #1e1b4b; display: grid; place-items: center;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.45);
}
.brand-kicker { font-size: .68rem; font-weight: 700; letter-spacing: .12em; color: #fcd34d; text-transform: uppercase; line-height: 1.1; }
.brand b { display: block; font-size: 1.06rem; line-height: 1.2; color: #fff; }
.brand small { color: rgba(255, 255, 255, 0.78); font-size: .78rem; display: block; }

.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, 0.14); color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.22);
  padding: 6px 12px; border-radius: 999px;
  font: inherit; font-size: .8rem; font-weight: 600;
  cursor: pointer; backdrop-filter: blur(8px); transition: all .2s;
}
.chip-btn:hover { background: rgba(255, 255, 255, 0.24); transform: translateY(-1px); }
.chip-btn.test-on {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.95), rgba(217, 119, 6, 0.95));
  color: #fff; border-color: #fde68a;
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.45);
}
.role-chip.role-admin {
  background: linear-gradient(135deg, #10b981, #059669);
  border-color: #a7f3d0;
}
.role-chip.role-contractor {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  border-color: #bfdbfe;
}
.pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; }
.chip-btn.test-on .pulse-dot {
  background: #fef08a;
  box-shadow: 0 0 0 3px rgba(254, 240, 138, 0.35);
  animation: pulse 1.2s infinite;
}

.badge { font-size: .75rem; font-weight: 600; padding: 5px 11px; border-radius: 999px; background: rgba(255,255,255,.15); white-space: nowrap; }
.badge.local { background: rgba(251, 191, 36, 0.22); color: #fde68a; border: 1px solid rgba(251, 191, 36, 0.45); }
.badge.firebase { background: rgba(34, 197, 94, 0.25); color: #bbf7d0; border: 1px solid rgba(34, 197, 94, 0.5); }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  display: flex; background: var(--card-solid); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -4px 20px rgba(0,0,0,.1);
}
.nav a {
  flex: 1; height: var(--navh); display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-decoration: none; color: var(--muted); font-size: .78rem; font-weight: 500; gap: 3px; transition: all .2s;
}
.nav a i { font-style: normal; font-size: 1.32rem; filter: grayscale(.85); opacity: .75; transition: transform .2s; }
.nav a.on { color: var(--pri2); font-weight: 700; }
.nav a.on i { filter: none; opacity: 1; transform: translateY(-2px); }

@media (min-width: 960px) {
  body { padding-bottom: 0; }
  .nav {
    position: static; background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 999px; box-shadow: none; gap: 4px; padding: 4px;
  }
  .nav a {
    flex: none; flex-direction: row; height: 38px; padding: 0 15px;
    border-radius: 999px; color: rgba(255,255,255,.85); font-size: .9rem; gap: 6px;
  }
  .nav a i { font-size: 1rem; filter: none; opacity: 1; transform: none !important; }
  .nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
  .nav a.on {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: #1e1b4b;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.35);
  }
}

main { max-width: 1240px; width: 100%; margin: 0 auto; padding: 20px 14px; flex: 1; }
.page { display: flex; flex-direction: column; gap: 18px; animation: fadeIn .22s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Minimal-Luxury Executive Hero (Dashboard) ---------- */
.luxury-hero {
  background: var(--hero-bg);
  color: #fff;
  border-radius: 24px;
  padding: 28px 32px;
  display: flex; align-items: center; justify-content: space-between; gap: 28px; flex-wrap: wrap;
  box-shadow: 0 20px 44px -12px rgba(46, 16, 101, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.16);
  position: relative; overflow: hidden;
}
.luxury-hero::before {
  content: ""; position: absolute; right: -80px; top: -80px;
  width: 320px; height: 320px; border-radius: 50%;
  background: radial-gradient(circle, rgba(251, 191, 36, 0.25), transparent 70%);
  pointer-events: none;
}
.lh-left { flex: 1; min-width: 280px; }
.lh-kicker {
  display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .14em;
  padding: 4px 14px; border-radius: 999px;
  background: rgba(251, 191, 36, 0.18); color: #fde047;
  border: 1px solid rgba(251, 191, 36, 0.38); margin-bottom: 10px;
}
.lh-sub { color: rgba(255, 255, 255, 0.78); font-size: .95rem; margin-bottom: 20px; }
.lh-metrics {
  display: inline-flex; align-items: center; gap: 24px; flex-wrap: wrap;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(12px);
  padding: 14px 24px; border-radius: 18px;
}
.lh-m-label { display: block; font-size: .78rem; color: rgba(255, 255, 255, 0.75); margin-bottom: 2px; }
.lh-m-val { font-family: 'Prompt', sans-serif; font-size: 1.85rem; font-weight: 700; line-height: 1.1; color: #fde047; }
.lh-m-val small { font-size: .9rem; font-weight: 500; color: rgba(255, 255, 255, 0.8); }
.lh-m-val.green { color: #34d399; }
.lh-m-val.red { color: #f87171; }
.lh-divider { width: 1px; height: 42px; background: rgba(255, 255, 255, 0.18); }

.lh-right { display: flex; align-items: center; justify-content: center; }
.ring-wrap {
  position: relative; width: 152px; height: 152px;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 50%;
  box-shadow: 0 0 32px rgba(251, 191, 36, 0.18);
}
.ring-svg { width: 152px; height: 152px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(255, 255, 255, 0.14); stroke-width: 10; }
.ring-fg { fill: none; stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset .6s ease; }
.ring-center { position: absolute; text-align: center; }
.ring-center b { display: block; font-family: 'Prompt', sans-serif; font-size: 2rem; font-weight: 700; color: #fde047; line-height: 1; }
.ring-center small { font-size: .75rem; color: rgba(255, 255, 255, 0.82); }

/* ---------- Luxury Contract Cards (3 สัญญา) ---------- */
.grid3 { display: grid; gap: 18px; }
@media (min-width: 920px) { .grid3 { grid-template-columns: repeat(3, 1fr); } }
.lux-contract {
  border-top: 5px solid var(--c);
  display: flex; flex-direction: column;
  padding: 22px;
  transition: transform .2s, box-shadow .2s;
}
.lux-contract:hover { transform: translateY(-3px); }
.lc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
.lc-tag { display: inline-block; font-size: .75rem; font-weight: 700; color: var(--muted); letter-spacing: .03em; margin-bottom: 2px; }
.lc-top h3 { font-size: 1.25rem; color: var(--text); }
.lc-pct {
  font-family: 'Prompt', sans-serif; font-size: 2.1rem; font-weight: 700; line-height: 1;
  color: var(--c);
}
.lc-pct small { font-size: 1rem; font-weight: 600; margin-left: 1px; }
.lc-progress-row { display: flex; justify-content: space-between; align-items: center; font-size: .88rem; margin-bottom: 8px; }
.lc-status-dots { font-size: .8rem; font-weight: 600; color: var(--muted); }
.lux-bar { height: 10px; background: var(--surface); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); margin-bottom: 16px; }
.lux-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--c), #10b981); border-radius: 99px; transition: width .5s ease; }

.lc-routes { flex: 1; display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.lc-route-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line);
  padding: 10px 12px; border-radius: 12px; font-size: .88rem;
}
.lc-route-item b { display: block; font-size: .9rem; }
.lc-route-item small { color: var(--muted); font-size: .78rem; }
.lc-r-num {
  font-family: 'Prompt', sans-serif; font-size: .82rem; font-weight: 700;
  color: var(--c); background: var(--card-solid); border: 1px solid var(--line);
  padding: 3px 10px; border-radius: 99px; white-space: nowrap;
}
.cc-actions { display: flex; gap: 8px; }
.cc-actions .btn { flex: 1; }

/* ---------- Glass Cards ---------- */
.card {
  background: var(--card);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-h h2 { margin: 0; }
.empty { text-align: center; color: var(--muted); padding: 32px 14px; border: 2px dashed var(--line); border-radius: 14px; }

.map-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: .84rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; font-weight: 500; }
.legend .ln { width: 18px; height: 4px; border-radius: 2px; display: inline-block; }
.legend .pt { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 2px solid #fff; box-shadow: 0 0 0 1px #94a3b8; }

/* ---------- Map ---------- */
.map { height: 400px; border-radius: 14px; overflow: hidden; z-index: 0; border: 1px solid var(--line); box-shadow: inset 0 2px 6px rgba(0,0,0,.06); }
.map-lg { height: 480px; }
@media (max-width: 600px) { .map { height: 340px; } .map-lg { height: 400px; } }
.pp { font-family: 'Sarabun', sans-serif; font-size: 13px; color: #0f172a; }
.pp-img { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 6px; }
.pp-img figure { margin: 0; text-align: center; }
.pp-img img { width: 100%; height: 92px; object-fit: cover; border-radius: 6px; cursor: zoom-in; }
.pp-img figcaption { font-size: 11px; color: #475569; font-weight: 600; }
.leaflet-container { font-family: 'Sarabun', sans-serif; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card-solid); color: var(--text);
  padding: 9px 15px; border-radius: 12px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  transition: all .16s ease; box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,.08); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .6; pointer-events: none; }
.btn.sm { padding: 6px 11px; font-size: .84rem; border-radius: 10px; }
.btn.lg { padding: 13px 22px; font-size: 1.02rem; border-radius: 14px; }
.btn.primary {
  background: linear-gradient(135deg, var(--pri2), var(--pri));
  color: #fff; border-color: transparent;
  box-shadow: 0 4px 14px rgba(109, 40, 217, 0.32);
}
.btn.gold {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff; border-color: transparent;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}
.btn.accent {
  background: linear-gradient(135deg, #0ea5e9, #0284c7);
  color: #fff; border-color: transparent;
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
}
.btn.ok {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff; border-color: transparent;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}
.btn.warn {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff; border-color: transparent;
}
.btn.ghost { background: var(--surface); }
.btn.danger { color: var(--red); border-color: rgba(239, 68, 68, 0.35); background: rgba(239, 68, 68, 0.06); }
.btn.danger:hover { background: var(--red); color: #fff; }
.link { background: none; border: 0; color: var(--pri3); text-decoration: underline; cursor: pointer; font: inherit; font-weight: 600; padding: 0 4px; }
.row { display: flex; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.center { justify-content: center; }

/* ---------- Contract Segmented Selector ---------- */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.seg-btn {
  border: 2px solid var(--line); background: var(--surface); border-radius: 14px; padding: 12px 10px; cursor: pointer; font: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--text); transition: all .18s;
}
.seg-btn:hover { border-color: var(--c); transform: translateY(-1px); }
.seg-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
.seg-btn b { font-size: 1.02rem; }
.seg-badge { font-size: .74rem; font-weight: 700; padding: 2px 9px; border-radius: 99px; background: rgba(0,0,0,.07); }
.seg-btn small { color: var(--muted); font-size: .78rem; }
.seg-btn.on {
  border-color: var(--c);
  background: linear-gradient(135deg, var(--c), var(--pri));
  color: #fff;
  box-shadow: 0 8px 20px -4px rgba(109, 40, 217, 0.4);
}
.seg-btn.on small { color: rgba(255,255,255,.9); }
.seg-btn.on .seg-badge { background: rgba(255,255,255,.24); color: #fff; }

.route-list { display: grid; gap: 10px; margin-top: 12px; }
@media (min-width: 720px) { .route-list { grid-template-columns: repeat(2, 1fr); } }
.route-chip {
  border: 1px solid var(--line); border-left: 5px solid var(--c);
  background: var(--surface); border-radius: 12px; padding: 10px 14px; font-size: .9rem;
}
.rc-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 3px; }
.rc-badge { font-size: .75rem; font-weight: 700; background: var(--card-solid); border: 1px solid var(--line); padding: 2px 9px; border-radius: 99px; color: var(--c); }

/* ---------- GPS & Test Mode Bar ---------- */
.gpsbar, .gps-inline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; font-size: .92rem; }
.gpsbar-main { flex: 1; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.gpsbar-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.gps-inline { background: var(--surface); border: 1px solid var(--line); padding: 10px 12px; border-radius: 12px; margin-bottom: 6px; }
.gps-inline-txt { flex: 1; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.src-badge {
  font-size: .74rem; font-weight: 700; padding: 2px 9px; border-radius: 99px;
  display: inline-flex; align-items: center; gap: 4px;
}
.src-badge.sim { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.src-badge.real { background: #e0f2fe; color: #075985; border: 1px solid #7dd3fc; }

.test-banner {
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.14), rgba(124, 58, 237, 0.1));
  border: 1px solid rgba(245, 158, 11, 0.45);
  color: var(--text); padding: 9px 13px; border-radius: 12px; font-size: .86rem; margin-bottom: 10px;
}

.dot { width: 11px; height: 11px; border-radius: 50%; background: #94a3b8; display: inline-block; flex: none; }
.dot.ok { background: var(--green); box-shadow: 0 0 0 4px rgba(16, 185, 129, .22); }
.dot.warn { background: var(--amber); }
.dot.wait { background: #0ea5e9; animation: pulse 1s infinite; }
.dot.err { background: var(--red); }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- Record List ---------- */
.count-pill { font-size: .84rem; font-weight: 700; padding: 3px 12px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line); }
.rec-list { display: flex; flex-direction: column; gap: 10px; }
.rec-item {
  display: flex; gap: 12px; align-items: center; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  transition: transform .15s;
}
.rec-item:hover { transform: translateX(2px); }
.thumb { width: 66px; height: 66px; border-radius: 10px; background: var(--card-solid); border: 1px solid var(--line); display: grid; place-items: center; overflow: hidden; flex: none; }
.thumb img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.rec-body { flex: 1; min-width: 0; }
.rec-top { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.rec-act { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { color: #fff; font-size: .73rem; padding: 2px 9px; border-radius: 99px; font-weight: 700; white-space: nowrap; }
.tag { font-size: .73rem; padding: 2px 8px; border-radius: 6px; border: 1.5px solid var(--c); color: var(--c); font-weight: 700; }

.fab {
  position: fixed; right: 20px; bottom: calc(var(--navh) + 20px + env(safe-area-inset-bottom)); z-index: 900;
  height: 58px; padding: 0 22px; border-radius: 999px; border: 2px solid rgba(255,255,255,.35);
  background: linear-gradient(135deg, #ef4444, #dc2626); color: #fff;
  display: inline-flex; align-items: center; gap: 8px;
  font-family: 'Prompt', sans-serif; font-size: 1rem; font-weight: 600;
  cursor: pointer; box-shadow: 0 10px 26px rgba(220, 38, 38, .48);
  transition: transform .18s, box-shadow .18s;
}
.fab span { font-size: 1.5rem; line-height: 1; }
.fab:hover { transform: translateY(-3px) scale(1.02); box-shadow: 0 14px 30px rgba(220, 38, 38, .6); }
@media (min-width: 960px) { .fab { bottom: 28px; right: 28px; } }

/* ---------- GPS Page ---------- */
.gps-card { text-align: center; }
.gps-status { display: inline-block; padding: 6px 16px; border-radius: 99px; background: var(--surface); font-weight: 600; font-size: .92rem; margin-bottom: 12px; }
.gps-status.ok { background: #dcfce7; color: #166534; }
.gps-status.warn { background: #fef3c7; color: #92400e; }
.gps-status.err { background: #fee2e2; color: #991b1b; }
.gps-status.wait { background: #e0f2fe; color: #075985; }
.gps-big { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 10px; }
.coord-box { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 8px; }
.coord-box label { display: block; color: var(--muted); font-size: .84rem; font-weight: 600; }
.coord-box b { font-size: clamp(1.25rem, 4.5vw, 2.05rem); font-variant-numeric: tabular-nums; color: var(--pri2); }
.gps-meta { color: var(--muted); margin-bottom: 14px; font-size: .9rem; display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; }
.gps-nearest { margin-top: 14px; font-size: .92rem; background: var(--surface); padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); }

/* ---------- Verify Page ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.filters button {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 99px; padding: 7px 14px; font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer;
  transition: all .15s;
}
.filters button::after { content: attr(data-n); margin-left: 6px; background: var(--card-solid); border-radius: 99px; padding: 1px 8px; font-size: .78rem; }
.filters button.on { background: linear-gradient(135deg, var(--pri2), var(--pri)); color: #fff; border-color: transparent; }
.filters button.on::after { background: rgba(255,255,255,.24); color: #fff; }

.report-box {
  display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap;
  background: linear-gradient(130deg, rgba(109, 40, 217, 0.08), rgba(245, 158, 11, 0.08));
  border: 1.5px solid rgba(109, 40, 217, 0.28);
}
.report-badge {
  display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .08em;
  color: var(--pri2); background: rgba(109, 40, 217, 0.12);
  padding: 3px 10px; border-radius: 99px; margin-bottom: 4px;
}
.report-box p { margin: 8px 0 0; font-size: .86rem; line-height: 1.5; }
.chk { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; margin-top: 4px; font-size: .92rem; }
.chk input { width: 18px; height: 18px; accent-color: var(--pri2); }

.ver-list { display: grid; gap: 16px; }
@media (min-width: 900px) { .ver-list { grid-template-columns: repeat(2, 1fr); } }
.ver-card { border-left: 6px solid var(--red); }
.ver-card.st-approved { border-left-color: var(--green); }
.ver-card.st-rejected { border-left-color: var(--amber); }
.vc-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 1rem; margin-bottom: 2px; }
.vc-photos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.vc-photos figure { margin: 0; text-align: center; }
.vc-photos figcaption { font-size: .84rem; font-weight: 700; color: var(--muted); margin-top: 4px; }
.img-box { aspect-ratio: 4/3; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; display: grid; place-items: center; overflow: hidden; color: var(--muted); font-size: .85rem; }
.img-box img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; transition: transform .2s; }
.img-box img:hover { transform: scale(1.03); }
.vc-act { display: flex; gap: 8px; flex-wrap: wrap; }
.vc-act .btn { flex: 1; }

/* ---------- Footer เครดิตผู้จัดทำ ---------- */
.app-footer {
  margin-top: 28px;
  padding: 24px 16px calc(28px + env(safe-area-inset-bottom));
  text-align: center;
}
.footer-inner {
  max-width: 680px; margin: 0 auto;
  background: var(--card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px 24px;
  box-shadow: var(--shadow);
}
.footer-line {
  width: 64px; height: 4px; border-radius: 99px;
  background: linear-gradient(90deg, var(--pri2), var(--gold));
  margin: 0 auto 10px;
}
.footer-badge { font-size: .78rem; font-weight: 700; color: var(--pri2); letter-spacing: .04em; margin-bottom: 4px; }
.footer-author { font-family: 'Prompt', sans-serif; font-size: 1.02rem; font-weight: 700; color: var(--text); }
.footer-author span { font-weight: 500; color: var(--muted); font-size: .92rem; display: inline-block; margin-left: 6px; }
.footer-role {
  display: inline-block; margin-top: 4px;
  font-size: .78rem; font-weight: 700;
  color: #92400e; background: #fef3c7; border: 1px solid #fde68a;
  padding: 2px 12px; border-radius: 999px;
}

/* ---------- Modal เพิ่มข้อมูล & Auth Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 2000; background: rgba(15, 23, 42, .65); backdrop-filter: blur(5px); display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 700px) { .modal { align-items: center; padding: 16px; } }
.modal-box {
  background: var(--card-solid); color: var(--text);
  width: 100%; max-width: 660px; max-height: 94vh;
  display: flex; flex-direction: column;
  border-radius: 22px 22px 0 0;
  border: 1px solid var(--line);
  box-shadow: 0 24px 48px rgba(0,0,0,.35);
  animation: up .22s ease-out;
}
.auth-box { max-width: 420px; border-radius: 22px; margin: 16px; }
@media (min-width: 700px) { .modal-box { border-radius: 22px; } }
@keyframes up { from { transform: translateY(36px); opacity: 0; } }
.modal-h {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  background: linear-gradient(120deg, rgba(109, 40, 217, 0.08), transparent);
}
.modal-kicker { font-size: .72rem; font-weight: 700; color: var(--pri2); text-transform: uppercase; letter-spacing: .06em; }
.modal-b { padding: 14px 20px; overflow-y: auto; }
.modal-f { display: flex; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
.modal-f .btn:last-child { flex: 2; }
.modal-f .btn:first-child { flex: 1; }
.x { border: 1px solid var(--line); background: var(--surface); color: var(--text); width: 36px; height: 36px; border-radius: 50%; font-size: 1.35rem; cursor: pointer; }

.pass-input {
  text-align: center; font-size: 1.5rem !important; letter-spacing: .25em; font-weight: 700;
  padding: 12px !important;
}
.auth-err {
  color: var(--red); background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 10px; padding: 8px 12px; margin-top: 10px;
  font-size: .86rem; font-weight: 600; text-align: center;
}

.modal-test-bar {
  background: linear-gradient(120deg, rgba(245, 158, 11, 0.15), rgba(14, 165, 233, 0.12));
  border: 1.5px dashed #f59e0b; border-radius: 14px; padding: 10px 12px; margin-bottom: 10px;
}
.mtb-head { font-size: .85rem; margin-bottom: 8px; }
.mtb-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.mtb-btns .btn { flex: 1; min-width: 200px; }

.near-hint { font-size: .85rem; margin-top: 4px; }
.ok-hint { display: inline-block; background: rgba(16, 185, 129, 0.12); color: var(--green); border: 1px solid rgba(16, 185, 129, 0.35); padding: 4px 10px; border-radius: 8px; }

.lbl { display: block; font-weight: 700; font-size: .9rem; margin: 12px 0 5px; }
select, input:not([type=checkbox]), textarea {
  width: 100%; font: inherit; color: var(--text);
  padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--surface);
}
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--pri2); box-shadow: 0 0 0 3px rgba(109, 40, 217, 0.15); }

.form-row2 { display: grid; gap: 10px; }
@media (min-width: 560px) { .form-row2 { grid-template-columns: 1fr 1fr; } }
.contractor-fixed {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 14px; border: 1.5px solid rgba(109, 40, 217, 0.35);
  border-radius: 12px; background: rgba(109, 40, 217, 0.08);
  color: var(--text); font-size: .95rem;
}

.photo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 6px; }
.photo-slot { border: 2px dashed var(--line); background: var(--surface); border-radius: 14px; padding: 10px; text-align: center; transition: border-color .2s; }
.photo-slot:hover { border-color: var(--pri2); }
.ph-title { font-weight: 700; margin-bottom: 6px; font-size: .92rem; }
.photo-slot[data-slot=before] .ph-title { color: #d97706; }
.photo-slot[data-slot=after] .ph-title { color: var(--green); }
.ph-prev {
  position: relative; aspect-ratio: 4/3; background: var(--card-solid);
  border: 1px solid var(--line); border-radius: 10px;
  display: grid; place-items: center; overflow: hidden;
  color: var(--muted); font-size: .84rem; cursor: pointer;
}
.ph-placeholder { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px; pointer-events: none; }
.ph-placeholder i { font-style: normal; font-size: 1.8rem; opacity: .75; }
.ph-prev img { width: 100%; height: 100%; object-fit: cover; }
.ph-prev .rm { position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(15,23,42,.75); color: #fff; font-size: 1.1rem; cursor: pointer; }
.ph-btns { display: flex; gap: 6px; margin-top: 8px; }
.ph-btns .btn { flex: 1; padding: 8px 4px; }

.lightbox { position: fixed; inset: 0; z-index: 3000; background: rgba(0,0,0,.92); display: grid; place-items: center; cursor: zoom-out; }
.lightbox img { max-width: 96vw; max-height: 92vh; border-radius: 8px; }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--navh) + 22px); z-index: 4000; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: 92%; max-width: 520px; }
.toast { background: #1e293b; color: #fff; padding: 11px 18px; border-radius: 12px; font-weight: 600; box-shadow: 0 10px 28px rgba(0,0,0,.3); transition: opacity .4s; text-align: center; }
.toast.ok { background: #059669; }
.toast.err { background: #dc2626; }
.toast.out { opacity: 0; }

/* ---------- Report (A4 Print Only - ห้ามรูปต่อหน้าเด็ดขาด) ---------- */
#report { display: none; }
@page { size: A4 portrait; margin: 12mm 12mm 14mm; }
@media print {
  html, body { background: #fff !important; background-image: none !important; color: #000 !important; padding: 0 !important; font-size: 11pt; }
  .bg-orb, #app, .modal, .lightbox, #toast, .fab { display: none !important; }
  #report { display: block !important; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.rp { color: #000; font-family: 'Sarabun', sans-serif; }
.rp-head { text-align: center; margin-bottom: 8px; }
.rp-head h1 { font-size: 16pt; margin: 0; color: #000; }
.rp-head h2 { font-size: 13.5pt; margin: 2px 0; color: #000; }
.rp-head div { font-size: 10pt; }
.rp-sum { width: 100%; border-collapse: collapse; font-size: 9pt; margin: 8px 0 12px; }
.rp-sum th, .rp-sum td { border: 1px solid #000; padding: 3px 4px; vertical-align: top; }
.rp-sum th { background: #e5e7eb; }
.rp-sum .tot td { font-weight: 700; background: #f3f4f6; }
.rp-sum .c { text-align: center; } .rp-sum .r { text-align: right; }

.rp-th, .rp-row { display: flex; border: 1px solid #000; border-top: 0; }
.rp-th { border-top: 1px solid #000; background: #e5e7eb; font-weight: 700; text-align: center; font-size: 10pt; break-after: avoid; page-break-after: avoid; }
.rp-th > div, .rp-row > div { padding: 4px; border-left: 1px solid #000; }
.rp-th > div:first-child, .rp-row > div:first-child { border-left: 0; }
.rp-row { break-inside: avoid; page-break-inside: avoid; font-size: 9pt; line-height: 1.35; }
.rp-no { width: 11mm; flex: none; text-align: center; }
.rp-info { flex: 1; min-width: 0; word-break: break-word; }
.rp-img { width: 64mm; flex: none; text-align: center; }
.rp-row .rp-img { height: 50mm; display: flex; align-items: center; justify-content: center; }
.rp-row .rp-img img { max-width: 100%; max-height: 100%; max-fit: contain; object-fit: contain; display: block; }
.rp-st { font-weight: 700; margin-top: 2px; }
.rp-sign { display: flex; justify-content: space-between; gap: 6mm; margin-top: 14mm; break-inside: avoid; page-break-inside: avoid; text-align: center; font-size: 10.5pt; }
.rp-sign .sg { flex: 1; }
.sg-line { margin-bottom: 4px; white-space: nowrap; }
.sg-date { margin-top: 6px; }
