:root {
  --bg: #0b1220;
  --panel: rgba(13, 20, 36, 0.92);
  --panel-solid: #111a2e;
  --line: rgba(255, 255, 255, 0.1);
  --text: #eef2f8;
  --muted: #9aa7bd;
  --accent: #4ea8ff;
  --land: #ff4d4f;
  --public: #14e0b0;
  --radius: 14px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: 'Sarabun', system-ui, sans-serif; font-size: 15px; overflow: hidden; overscroll-behavior: none; }
button, input, select { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

/* ---------- แผนที่ ---------- */
#mapView, #map { position: fixed; inset: 0; }
#map { background: #1b2433; }
.leaflet-container { font-family: inherit; }
.leaflet-control-attribution { font-size: 10px; background: rgba(0,0,0,.45) !important; color: #ccd !important; }
.leaflet-control-attribution a { color: #ccd !important; }
.leaflet-tooltip.plabel { background: rgba(10,16,28,.8); color: #fff; border: 0; box-shadow: none; font-size: 12px; padding: 1px 6px; border-radius: 6px; }
.leaflet-tooltip.plabel::before { display: none; }

.topbar { position: absolute; z-index: 1005; top: calc(10px + var(--safe-t)); left: 12px; right: 12px; max-width: 520px; margin: 0 auto; }
.search { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 0 14px; height: 46px; backdrop-filter: blur(10px); box-shadow: 0 6px 24px rgba(0,0,0,.35); }
.search svg { color: var(--muted); flex: none; }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; font-size: 16px; }
.search input::placeholder { color: var(--muted); }
.results { margin-top: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); max-height: 55vh; overflow: auto; backdrop-filter: blur(10px); }
.results button { display: flex; gap: 10px; align-items: flex-start; width: 100%; text-align: left; padding: 10px 14px; background: none; border: 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.results button:hover, .results button:focus-visible { background: rgba(255,255,255,.06); outline: 0; }
.results b { display: block; font-weight: 600; }
.results small { color: var(--muted); }
.results .empty { padding: 14px; color: var(--muted); }

.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; margin-top: 6px; }
.dot.land { background: var(--land); } .dot.public { background: var(--public); }

.fabs { position: absolute; z-index: 1000; right: 12px; top: calc(70px + var(--safe-t)); display: flex; flex-direction: column; gap: 10px; }
.fab { width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); display: grid; place-items: center; cursor: pointer; box-shadow: 0 4px 16px rgba(0,0,0,.35); }
.fab.active { color: var(--accent); }

.panel { position: absolute; z-index: 1001; right: 66px; top: calc(70px + var(--safe-t)); width: min(270px, calc(100vw - 90px)); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 14px 14px; backdrop-filter: blur(10px); }
.panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 10px 0 6px; font-weight: 600; }
.chk { display: flex; align-items: center; gap: 10px; padding: 6px 0; cursor: pointer; }
.chk input { display: none; }
.chk em { margin-left: auto; color: var(--muted); font-style: normal; font-size: 13px; }
.sw { width: 18px; height: 18px; border-radius: 5px; border: 2px solid; }
.sw.land { border-color: var(--land); } .sw.public { border-color: var(--public); }
.chk input:checked + .sw.land { background: var(--land); } .chk input:checked + .sw.public { background: var(--public); }
.seg { display: flex; background: rgba(255,255,255,.06); border-radius: 10px; padding: 3px; }
.seg label { flex: 1; } .seg input { display: none; }
.seg span { display: block; text-align: center; padding: 6px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.seg input:checked + span { background: var(--accent); color: #fff; }

.ar-cta { position: absolute; z-index: 1000; left: 50%; transform: translateX(-50%); bottom: calc(22px + var(--safe-b)); display: flex; align-items: center; gap: 10px; padding: 14px 26px; border-radius: 999px; border: 0; background: linear-gradient(135deg, #3d8bff, #6a5cff); color: #fff; font-weight: 700; font-size: 17px; box-shadow: 0 10px 30px rgba(61,139,255,.45); cursor: pointer; }
.ar-cta svg { width: 22px; height: 22px; }

.toast { position: absolute; z-index: 1002; left: 50%; transform: translateX(-50%); bottom: calc(90px + var(--safe-b)); max-width: calc(100vw - 32px); background: var(--panel); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; text-align: center; backdrop-filter: blur(10px); }

/* ---------- แผ่นรายละเอียด ---------- */
.sheet { position: fixed; z-index: 3000; left: 0; right: 0; bottom: 0; max-width: 560px; margin: 0 auto; max-height: 70vh; overflow: auto; background: var(--panel-solid); border: 1px solid var(--line); border-bottom: 0; border-radius: 20px 20px 0 0; padding: 8px 18px calc(18px + var(--safe-b)); box-shadow: 0 -10px 40px rgba(0,0,0,.5); animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.grip { width: 40px; height: 4px; border-radius: 4px; background: rgba(255,255,255,.2); margin: 0 auto 8px; }
.x { position: absolute; top: 10px; right: 12px; width: 34px; height: 34px; border-radius: 50%; border: 0; background: rgba(255,255,255,.08); cursor: pointer; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 2px 10px; border-radius: 999px; font-weight: 600; }
.badge.land { background: rgba(255,77,79,.15); color: #ff8a8b; } .badge.public { background: rgba(20,224,176,.14); color: var(--public); }
.sheet h2 { margin: 8px 40px 2px 0; font-size: 20px; line-height: 1.3; }
.sheet .sub { color: var(--muted); margin: 0 0 10px; }
.sheet .here { background: rgba(78,168,255,.14); color: #9ccbff; padding: 8px 12px; border-radius: 10px; margin-bottom: 10px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 600; word-break: break-word; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions a, .actions button { flex: 1 1 140px; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,.05); text-decoration: none; color: inherit; cursor: pointer; font-weight: 600; }
.actions .primary { background: var(--accent); border-color: transparent; color: #fff; }

/* ---------- AR ---------- */
#arView { position: fixed; inset: 0; z-index: 2000; background: #000; overflow: hidden; }
#arView.sim { background: linear-gradient(#16263f, #5b7ea3); }
#arVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#arCanvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
#arLabels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.ar-label { position: absolute; left: 0; top: 0; pointer-events: auto; display: flex; flex-direction: column; align-items: center; padding: 5px 11px 6px; border-radius: 12px; border: 0; background: rgba(8,14,26,.78); backdrop-filter: blur(6px); cursor: pointer; white-space: nowrap; max-width: 60vw; transform-origin: 50% 100%; will-change: transform; }
.ar-label::after { content: ''; position: absolute; bottom: -7px; left: 50%; margin-left: -7px; border: 7px solid transparent; border-bottom: 0; border-top-color: rgba(8,14,26,.78); }
.ar-label b { font-size: 14px; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.ar-label small { font-size: 12px; color: var(--muted); }
.ar-label.land { box-shadow: inset 0 0 0 1.5px var(--land); } .ar-label.public { box-shadow: inset 0 0 0 1.5px var(--public); }

.chip { background: rgba(8,14,26,.72); border: 1px solid var(--line); border-radius: 999px; padding: 7px 13px; backdrop-filter: blur(8px); font-size: 13px; }
.chip.btn { cursor: pointer; min-width: 38px; }
.chip.warn { color: #ffd166; }
.ar-top { position: absolute; top: calc(10px + var(--safe-t)); left: 12px; right: 12px; display: flex; gap: 8px; align-items: center; }
.ar-top .btn { width: 40px; height: 40px; padding: 0; font-size: 16px; }
.ar-banner { position: absolute; top: calc(60px + var(--safe-t)); left: 12px; right: 12px; max-width: 480px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: var(--radius); background: rgba(8,14,26,.8); border: 1px solid var(--line); backdrop-filter: blur(8px); cursor: pointer; }
.ar-banner b { display: block; font-size: 16px; line-height: 1.3; }
.ar-banner small { display: block; color: var(--muted); font-size: 12.5px; }
.ar-hint { position: absolute; left: 50%; bottom: calc(190px + var(--safe-b)); transform: translateX(-50%); max-width: 80vw; text-align: center; background: rgba(8,14,26,.85); padding: 12px 16px; border-radius: 12px; pointer-events: none; }
.ar-bottom { position: absolute; left: 12px; right: 12px; bottom: calc(14px + var(--safe-b)); display: flex; gap: 12px; align-items: flex-end; }
#arRadar { width: 120px; height: 120px; flex: none; border-radius: 50%; border: 1px solid var(--line); }
.ar-tools { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.calib { display: flex; gap: 6px; }
.calib .heading { min-width: 128px; text-align: center; cursor: pointer; }
.ar-row { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
select.chip { appearance: none; -webkit-appearance: none; padding-right: 13px; }
.tog { opacity: .5; } .tog.on { opacity: 1; }
.tog.land.on { border-color: var(--land); } .tog.public.on { border-color: var(--public); }

@media (max-width: 380px) {
  #arRadar { width: 100px; height: 100px; }
  .calib .heading { min-width: 100px; }
}
