:root {
  --bg: rgba(15, 23, 42, 0.92);
  --bg-solid: #0f172a;
  --card: rgba(30, 41, 59, 0.92);
  --border: rgba(148, 163, 184, 0.25);
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --red: #ef4444;
  --green: #22c55e;
  --amber: #f59e0b;
  --blue: #3b82f6;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #0b1120;
  color: var(--text);
  user-select: none;
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Top HUD: GPS Distance + Network/Offline Controls */
.top-hud {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  z-index: 20;
}

.hud-card {
  pointer-events: auto;
  background: var(--bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.distance-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 52px;
}

.distance-metric {
  display: flex;
  flex-direction: column;
}

.distance-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.distance-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}

.hud-actions {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.touch-btn {
  min-height: 48px;
  min-width: 48px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  backdrop-filter: blur(12px);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.touch-btn:active {
  transform: scale(0.97);
}

.touch-btn.primary {
  background: #0284c7;
  border-color: #38bdf8;
}

.touch-btn.success {
  background: #15803d;
  border-color: #22c55e;
}

/* Right Panel: 30 Most Recent Freedom Calls */
.calls-panel {
  position: absolute;
  top: calc(max(12px, env(safe-area-inset-top)) + 64px);
  right: 12px;
  width: min(370px, calc(100vw - 24px));
  max-height: calc(100dvh - 90px);
  display: flex;
  flex-direction: column;
  z-index: 15;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.panel-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.calls-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.call-item {
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.call-item.selected {
  border-color: var(--accent);
  background: rgba(2, 132, 199, 0.25);
}

.call-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.call-nature {
  font-weight: 700;
  font-size: 15px;
}

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
}

.badge.active { background: rgba(239, 68, 68, 0.25); color: #fca5a5; border: 1px solid #ef4444; }
.badge.closed { background: rgba(148, 163, 184, 0.2); color: #cbd5e1; }
.badge.resp { background: rgba(34, 197, 94, 0.25); color: #86efac; border: 1px solid #22c55e; }
.badge.enrt { background: rgba(59, 130, 246, 0.25); color: #93c5fd; border: 1px solid #3b82f6; }
.badge.arrv { background: rgba(245, 158, 11, 0.25); color: #fcd34d; border: 1px solid #f59e0b; }

.call-meta {
  font-size: 13px;
  color: #cbd5e1;
  line-height: 1.35;
}

/* Bottom-Right: Active911 Responder Status Box */
.responders-box {
  position: absolute;
  bottom: max(14px, env(safe-area-inset-bottom));
  right: 12px;
  width: min(340px, calc(100vw - 24px));
  max-height: 260px;
  display: flex;
  flex-direction: column;
  z-index: 15;
}

.responders-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  -webkit-overflow-scrolling: touch;
}

.responder-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}

.responder-name {
  font-weight: 600;
  font-size: 14px;
}

.responder-sub {
  font-size: 11px;
  color: var(--muted);
}

/* Right Slide-Over Drawer: GIS Layer Toggles */
.layers-drawer {
  position: absolute;
  top: calc(max(12px, env(safe-area-inset-top)) + 64px);
  right: 12px;
  width: min(300px, calc(100vw - 24px));
  z-index: 25;
  display: none;
  flex-direction: column;
  gap: 8px;
}

.layers-drawer.open,
.settings-drawer.open {
  display: flex;
}

.settings-drawer {
  position: absolute;
  top: calc(max(12px, env(safe-area-inset-top)) + 64px);
  right: 12px;
  width: min(360px, calc(100vw - 24px));
  max-height: calc(100dvh - 100px);
  z-index: 26;
  display: none;
  flex-direction: column;
  gap: 8px;
}

.settings-scroll {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
  -webkit-overflow-scrolling: touch;
}

.settings-section {
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-heading {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 40px;
  font-size: 14px;
}

.setting-select {
  background: #1e293b;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  min-height: 40px;
}

.legend-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  font-size: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #cbd5e1;
}

.search-panel {
  position: absolute;
  top: calc(max(12px, env(safe-area-inset-top)) + 64px);
  right: 12px;
  width: min(380px, calc(100vw - 24px));
  max-height: 60dvh;
  display: none;
  flex-direction: column;
  gap: 8px;
  z-index: 28;
}

.search-panel.open {
  display: flex;
}

.search-input-row {
  display: flex;
  gap: 8px;
}

.search-input {
  flex: 1;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0f172a;
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.search-results {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 44dvh;
  -webkit-overflow-scrolling: touch;
}

.search-item {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
}

.call-responders {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.resp-chip {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 8px;
  background: rgba(34, 197, 94, 0.18);
  border: 1px solid #22c55e;
  color: #bbf7d0;
}

.resp-chip.unvl {
  background: rgba(148, 163, 184, 0.18);
  border-color: #64748b;
  color: #cbd5e1;
}

.notes-modal {
  position: absolute;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: min(440px, calc(100vw - 24px));
  display: none;
  flex-direction: column;
  z-index: 30;
}

.notes-modal.open {
  display: flex;
}

.calls-panel.hidden {
  display: none;
}

.call-notes-inline {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.85);
  border: 1px solid rgba(56, 189, 248, 0.35);
  font-size: 13.5px;
  line-height: 1.5;
  color: #f1f5f9;
  max-height: 250px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.call-notes-summary {
  background: rgba(30, 41, 59, 0.9);
  border-left: 3px solid #38bdf8;
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 8px;
  color: #f8fafc;
}

.layer-toggle {
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.8);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.layer-toggle.on {
  border-color: var(--accent);
  background: rgba(2, 132, 199, 0.25);
}

.layer-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 10px;
}

.collapsed .calls-list,
.collapsed .responders-list {
  display: none;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  background: var(--green);
}

.status-dot.offline {
  background: var(--amber);
}
