:root {
  --bg: #0a0a0c;
  --panel: #15151a;
  --panel-border: #2a2a32;
  --text: #e5e5ea;
  --text-dim: #8e8e93;
  --accent: #22c55e;
  --danger: #ef4444;
  --warn: #eab308;
  --shelter-low: #7c3aed;
  --shelter-mid: #a855f7;
  --shelter-high: #d946ef;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  height: 100dvh;
}

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

.maplibregl-canvas {
  filter: saturate(0.85);
}

#panel {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 320px;
  max-height: calc(100dvh - 32px);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 20px;
  overflow-y: auto;
  z-index: 10;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  -webkit-overflow-scrolling: touch;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

#panel.hidden {
  transform: translateX(calc(-100% - 32px));
  opacity: 0;
  pointer-events: none;
}

#panel-close {
  display: none;
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
}

#panel-close:hover { color: var(--text); }

#panel-toggle {
  display: none;
  position: absolute;
  top: max(env(safe-area-inset-top), 16px);
  left: 16px;
  z-index: 11;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px 14px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  backdrop-filter: blur(8px);
  min-height: 44px;
}

#panel-toggle .hamburger { font-size: 16px; }

#panel header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

#panel .subtitle {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-dim);
}

#panel h2 {
  margin: 24px 0 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.layers label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  font-size: 13px;
  cursor: pointer;
  min-height: 32px;
  user-select: none;
}

.layers input[type="checkbox"] {
  appearance: none;
  width: 20px;
  height: 20px;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  background: var(--bg);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}

.layers input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.layers input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 2px;
  width: 5px;
  height: 11px;
  border: solid var(--bg);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 4px 0;
  color: var(--text-dim);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

footer {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--panel-border);
}

.meta {
  font-size: 11px;
  color: var(--text-dim);
  margin: 0;
  line-height: 1.5;
}

.popup {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 360px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 20px;
  z-index: 20;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
}

.popup.hidden {
  display: none;
}

.popup .close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  line-height: 1;
}

.popup .close:hover {
  color: var(--text);
}

.popup .header-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.popup h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  flex: 1;
}

.popup .badge {
  display: inline-block;
  padding: 3px 8px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: 6px;
  white-space: nowrap;
}

.popup .badge.recommended { background: rgba(34, 197, 94, 0.18); color: #86efac; border: 1px solid rgba(34, 197, 94, 0.35); }
.popup .badge.mixed { background: rgba(234, 179, 8, 0.18); color: #fde68a; border: 1px solid rgba(234, 179, 8, 0.35); }
.popup .badge.avoid { background: rgba(239, 68, 68, 0.18); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.35); }
.popup .badge.good-to-tour { background: rgba(59, 130, 246, 0.18); color: #93c5fd; border: 1px solid rgba(59, 130, 246, 0.35); }
.popup .badge.aspirational { background: rgba(168, 85, 247, 0.18); color: #d8b4fe; border: 1px solid rgba(168, 85, 247, 0.35); }
.popup .badge.high { background: rgba(217, 70, 239, 0.18); color: #f0abfc; border: 1px solid rgba(217, 70, 239, 0.35); }
.popup .badge.medium { background: rgba(168, 85, 247, 0.18); color: #d8b4fe; border: 1px solid rgba(168, 85, 247, 0.35); }
.popup .badge.low { background: rgba(124, 58, 237, 0.18); color: #c4b5fd; border: 1px solid rgba(124, 58, 237, 0.35); }
.popup .badge.starred { background: rgba(251, 191, 36, 0.18); color: #fde68a; border: 1px solid rgba(251, 191, 36, 0.35); }

.popup .address {
  font-size: 12px;
  color: var(--text-dim);
  margin: 0 0 4px;
}

.popup .meta-line {
  font-size: 11px;
  color: var(--text-dim);
  margin: 0 0 14px;
  letter-spacing: 0.02em;
}

.popup .price-block {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  margin-bottom: 12px;
}

.popup .price {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.popup .ppsf {
  font-size: 11px;
  color: var(--text-dim);
}

.popup dl {
  margin: 0 0 12px;
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 7px 12px;
  font-size: 12px;
}

.popup dt {
  color: var(--text-dim);
  font-weight: 500;
}

.popup dd {
  margin: 0;
  color: var(--text);
  line-height: 1.4;
}

.popup .watch-out {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
  background: rgba(239, 68, 68, 0.06);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.2);
  margin-bottom: 12px;
}

.popup .verdict-note {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
  background: rgba(255,255,255,0.04);
  color: var(--text);
  border: 1px solid var(--panel-border);
  margin-bottom: 14px;
  font-style: italic;
}

.popup .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.popup .action-btn {
  flex: 1;
  min-width: 120px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(34, 197, 94, 0.12);
  color: #86efac;
  border: 1px solid rgba(34, 197, 94, 0.3);
  text-align: center;
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
  transition: background 0.15s;
}

.popup .action-btn:hover {
  background: rgba(34, 197, 94, 0.22);
}

.popup .action-btn.secondary {
  background: rgba(255,255,255,0.06);
  color: var(--text);
  border-color: var(--panel-border);
}

.popup .action-btn.secondary:hover {
  background: rgba(255,255,255,0.12);
}

.popup .availability {
  margin-top: 12px;
  padding: 8px 12px;
  background: rgba(59, 130, 246, 0.06);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: 8px;
  font-size: 11px;
  text-align: center;
}

@media (max-width: 700px) {
  #panel-toggle { display: inline-flex; }
  #panel-close { display: block; }

  #panel {
    width: calc(100vw - 24px);
    max-width: 360px;
    left: 12px;
    top: max(env(safe-area-inset-top), 12px);
    max-height: calc(100dvh - max(env(safe-area-inset-top), 12px) - max(env(safe-area-inset-bottom), 12px) - 12px);
    padding: 56px 18px 18px;
    border-radius: 14px;
  }

  #panel header h1 { font-size: 17px; }

  .popup {
    width: auto;
    right: 12px;
    left: 12px;
    top: auto;
    bottom: max(env(safe-area-inset-bottom), 12px);
    max-height: 70dvh;
    overflow-y: auto;
    padding: 18px;
    -webkit-overflow-scrolling: touch;
  }

  .popup .actions { flex-direction: column; }
  .popup .action-btn { min-width: 0; padding: 12px; font-size: 13px; }

  .maplibregl-ctrl-bottom-left,
  .maplibregl-ctrl-bottom-right {
    bottom: max(env(safe-area-inset-bottom), 8px);
  }
}

@media (max-width: 700px) and (orientation: landscape) {
  #panel { max-height: calc(100dvh - 24px); }
}
