:root {
  --bg: #0f1419;
  --panel: #1a212b;
  --panel-2: #222c39;
  --line: #2c3947;
  --text: #e6edf3;
  --muted: #9bb0c3;
  --accent: #2dd4a0;
  --green: #22c55e;
  --amber: #eab308;
  --red: #ef4444;
  --gray: #64748b;
  --danger: #ef4444;
  --sheet-h: 62vh;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); overflow: hidden;
  overscroll-behavior: none;
}
#map { position: absolute; inset: 0; background: var(--bg); z-index: 0; }

button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---- Top bar ---- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 1000;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px 8px;
}
.iconbtn {
  width: 44px; height: 44px; flex: 0 0 44px;
  border-radius: 12px; border: 1px solid var(--line);
  background: rgba(26,33,43,0.92); color: var(--text);
  font-size: 20px; line-height: 1; display: grid; place-items: center;
  backdrop-filter: blur(6px); box-shadow: 0 2px 8px rgba(0,0,0,.35);
}
.iconbtn:active { background: var(--panel-2); }
.pill {
  flex: 1 1 auto; min-width: 0; height: 44px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 12px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(26,33,43,0.92); color: var(--muted);
  font-size: 13px; font-weight: 600; backdrop-filter: blur(6px);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pill.tracking { color: var(--accent); border-color: var(--accent); }

/* ---- FABs ---- */
.fab {
  position: absolute; right: 14px; bottom: calc(env(safe-area-inset-bottom,0px) + 18px);
  z-index: 1000; height: 52px; padding: 0 20px; border-radius: 26px;
  border: none; background: var(--accent); color: #06231b;
  font-size: 16px; font-weight: 800; box-shadow: 0 4px 16px rgba(0,0,0,.45);
}
.fab.active { background: var(--danger); color: #fff; }
.needspin-fab {
  position: absolute; left: 14px; bottom: calc(env(safe-area-inset-bottom,0px) + 18px);
  z-index: 1000; height: 44px; padding: 0 14px; border-radius: 22px;
  border: 1px solid var(--line); background: rgba(26,33,43,0.95); color: var(--text);
  font-size: 14px; font-weight: 700; box-shadow: 0 2px 10px rgba(0,0,0,.4);
}
.needspin-fab.empty { display: none; }

/* ---- Alert banner ---- */
.alert-banner {
  position: absolute; left: 10px; right: 10px;
  top: calc(env(safe-area-inset-top,0px) + 60px); z-index: 1500;
  display: flex; align-items: center; gap: 10px;
  padding: 14px 14px; border-radius: 14px;
  background: linear-gradient(135deg, #133a2e, #1c5240);
  border: 1px solid var(--accent); color: #fff;
  box-shadow: 0 8px 28px rgba(0,0,0,.55);
  animation: slidein .25s ease;
}
@keyframes slidein { from { transform: translateY(-12px); opacity: 0; } to { transform: none; opacity: 1; } }
.alert-banner .alert-name { font-size: 18px; font-weight: 800; }
.alert-banner .alert-meta { font-size: 13px; color: #c9f5e6; margin-top: 3px; }
.alert-main { flex: 1 1 auto; min-width: 0; }
.alert-dismiss { background: transparent; border: none; color: #fff; font-size: 20px; width: 36px; height: 36px; }

/* ---- Bottom sheet ---- */
.scrim { position: absolute; inset: 0; background: rgba(0,0,0,.45); z-index: 1900; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2000;
  max-height: var(--sheet-h); overflow-y: auto;
  background: var(--panel); border-radius: 18px 18px 0 0;
  border-top: 1px solid var(--line);
  padding: 8px 16px calc(env(safe-area-inset-bottom,0px) + 20px);
  box-shadow: 0 -8px 30px rgba(0,0,0,.5);
  animation: sheetup .22s ease;
}
@keyframes sheetup { from { transform: translateY(100%); } to { transform: none; } }
.sheet .grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 6px auto 12px; }

.det-head { display: flex; align-items: flex-start; gap: 10px; }
.det-title { font-size: 20px; font-weight: 800; line-height: 1.2; flex: 1; }
.det-dot { width: 14px; height: 14px; border-radius: 50%; margin-top: 5px; flex: 0 0 14px; }
.det-sub { color: var(--muted); font-size: 14px; margin: 2px 0 12px; }
.det-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat { background: var(--panel-2); border-radius: 12px; padding: 10px 12px; }
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-size: 17px; font-weight: 800; margin-top: 3px; }
.stat .v.pos { color: var(--green); } .stat .v.neg { color: var(--red); }

.rating-row { display: flex; gap: 8px; margin: 4px 0 14px; }
.rating-row button {
  flex: 1; height: 42px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--muted); font-weight: 700; font-size: 13px;
}
.rating-row button.sel-hot { background: var(--green); color: #042b14; border-color: var(--green); }
.rating-row button.sel-neutral { background: var(--gray); color: #fff; border-color: var(--gray); }
.rating-row button.sel-cold { background: #2563eb; color: #fff; border-color: #2563eb; }
.rating-row button.sel-blacklisted { background: var(--red); color: #fff; border-color: var(--red); }

.notes-box {
  width: 100%; min-height: 60px; resize: vertical; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 10px; font: inherit; font-size: 14px; margin-bottom: 12px;
}
.btn-row { display: flex; gap: 8px; }
.btn {
  flex: 1; height: 46px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-weight: 700; font-size: 15px;
}
.btn.primary { background: var(--accent); color: #06231b; border-color: var(--accent); }
.btn.warn { color: var(--amber); }
.det-closed-tag { display: inline-block; font-size: 11px; font-weight: 700; color: var(--red);
  border: 1px solid var(--red); border-radius: 6px; padding: 1px 6px; margin-left: 6px; vertical-align: middle; }

/* ---- Panels (filters/settings/needs-pin) ---- */
.panel {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 2100;
  width: min(420px, 100%); overflow-y: auto;
  background: var(--panel); border-left: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top,0px) + 14px) 16px calc(env(safe-area-inset-bottom,0px) + 24px);
  box-shadow: -8px 0 30px rgba(0,0,0,.5);
  animation: panelin .22s ease;
}
@keyframes panelin { from { transform: translateX(100%); } to { transform: none; } }
.panel h2 { margin: 0 0 4px; font-size: 20px; display: flex; align-items: center; }
.panel .close { margin-left: auto; background: transparent; border: none; color: var(--muted); font-size: 24px; }
.panel .sub { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.field input[type=number], .field input[type=text], .field select {
  width: 100%; height: 44px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); padding: 0 12px; font: inherit; font-size: 15px;
}
.field .row2 { display: flex; gap: 10px; }
.field .row2 input { flex: 1; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.chiprow { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 12px; border-radius: 18px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--muted); font-size: 13px; font-weight: 600;
}
.chip.on { background: var(--accent); color: #06231b; border-color: var(--accent); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); }
.toggle-row .lbl { font-size: 15px; }
.toggle-row .lbl small { display: block; color: var(--muted); font-size: 12px; }
.switch { position: relative; width: 50px; height: 30px; flex: 0 0 50px; }
.switch input { display: none; }
.switch .slider { position: absolute; inset: 0; background: var(--line); border-radius: 30px; transition: .2s; }
.switch .slider::before { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(20px); }

.np-item { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.np-item .np-info { flex: 1; min-width: 0; }
.np-item .np-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-item .np-addr { font-size: 12px; color: var(--muted); }
.np-item .np-handle { font-size: 12px; color: var(--accent); font-weight: 700; }
.np-item button { height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--accent); background: transparent; color: var(--accent); font-weight: 700; }
.np-pinning { outline: 2px dashed var(--accent); }

.legend { position: absolute; left: 10px; top: calc(env(safe-area-inset-top,0px) + 60px); z-index: 900;
  background: rgba(26,33,43,0.9); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 12px; }
.legend div { display: flex; align-items: center; gap: 6px; margin: 2px 0; color: var(--muted); }
.legend .d { width: 10px; height: 10px; border-radius: 50%; }

.banner-info { position: absolute; left: 10px; right: 10px; bottom: calc(env(safe-area-inset-bottom,0px) + 80px);
  z-index: 1400; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 13px; color: var(--muted); text-align: center; }

/* Custom marker dots (divIcon) */
.vgt-marker { border-radius: 50%; border: 2px solid rgba(0,0,0,.35); box-shadow: 0 0 4px rgba(0,0,0,.5); }
.vgt-marker.visited-recent { opacity: 0.4; }
.vgt-marker.manual { border-style: dashed; border-color: #fff; }

.toast { position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom,0px) + 84px); z-index: 2500;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 22px; font-size: 14px; font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,.5); animation: slidein .2s ease; }
