/* ══════════════════════════════════════════════════════════════
   Map View — Leaflet + custom controls
   ══════════════════════════════════════════════════════════════ */

/* ── Container ─────────────────────────────────────────────── */
.map-view {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  animation: rise-in 0.4s var(--ease-out) both;
}

.map-container {
  width: 100%;
  height: 65vh;
  min-height: 400px;
  max-height: 800px;
  border-radius: var(--radius-lg);
}

/* ── Custom cluster icons ──────────────────────────────────── */
.map-cluster-icon {
  background: none !important;
  border: none !important;
}

.map-cluster {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-family: "Sora", system-ui, sans-serif;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
  box-shadow: var(--shadow);
  border: 2px solid rgba(255, 255, 255, 0.8);
}

.map-cluster--small {
  width: 32px;
  height: 32px;
  font-size: 0.72rem;
  background: var(--brand);
}

.map-cluster--medium {
  width: 38px;
  height: 38px;
  font-size: 0.78rem;
  background: var(--brand-strong);
}

.map-cluster--large {
  width: 44px;
  height: 44px;
  font-size: 0.85rem;
  background: #043830;
}

/* ── Floating controls panel ──────────────────────────────── */
.map-controls {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 1000;
  width: 220px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 0.82rem;
  overflow: hidden;
  transition: width var(--duration) ease;
}

.map-controls-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.85rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--ink);
  background: var(--surface-dim);
  border-bottom: 1px solid var(--line-soft);
  user-select: none;
}

.map-controls-head:hover {
  background: var(--bg);
}

.map-controls .panel-toggle-icon {
  font-size: 0.65rem;
  transition: transform var(--duration) ease;
}

.map-controls.collapsed .panel-toggle-icon {
  transform: rotate(-90deg);
}

.map-controls.collapsed .map-controls-body {
  display: none;
}

.map-controls-body {
  padding: 0.75rem 0.85rem;
  display: grid;
  gap: 0.65rem;
}

/* ── Control groups ────────────────────────────────────────── */
.map-control-group {
  border: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.3rem;
}

.map-control-group legend {
  font-weight: 600;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.25rem;
}

.map-control-group label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.82rem;
  color: var(--ink-secondary);
  cursor: pointer;
}

.map-control-group input[type="radio"],
.map-control-group input[type="checkbox"] {
  accent-color: var(--brand);
  margin: 0;
  width: 0.95rem;
  height: 0.95rem;
}

.map-control-group select {
  width: 100%;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.78rem;
  background: var(--surface);
  color: var(--ink);
}

.map-sub-control {
  padding-left: 1.4rem;
  margin-top: 0.15rem;
}

/* ── Legend ─────────────────────────────────────────────────── */
.map-legend {
  display: grid;
  gap: 0.25rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--line-soft);
}

.map-legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--ink-secondary);
}

.map-legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.map-legend-gradient {
  height: 12px;
  border-radius: 3px;
  background: linear-gradient(to right, hsl(0, 70%, 45%), hsl(60, 70%, 45%), hsl(120, 70%, 45%));
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.map-legend-gradient-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: var(--faint);
}

.map-status-line {
  font-size: 0.72rem;
  color: var(--faint);
  padding-top: 0.35rem;
  border-top: 1px solid var(--line-soft);
  text-align: center;
}

/* ── Popup styling ─────────────────────────────────────────── */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-lg) !important;
  font-family: "Sora", system-ui, sans-serif !important;
  padding: 0 !important;
}

.leaflet-popup-content {
  margin: 0 !important;
  padding: 0.85rem 1rem !important;
  min-width: 200px;
  max-width: 280px;
  line-height: 1.45;
}

.leaflet-popup-tip {
  box-shadow: none !important;
}

.map-popup-title {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--ink);
  margin: 0 0 0.35rem;
  line-height: 1.3;
}

.map-popup-meta {
  display: grid;
  gap: 0.15rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.map-popup-meta strong {
  color: var(--ink-secondary);
}

.map-popup-stats {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--line-soft);
}

.map-popup-stat {
  text-align: center;
  flex: 1;
}

.map-popup-stat-value {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--brand);
  font-variant-numeric: tabular-nums;
}

.map-popup-stat-label {
  font-size: 0.65rem;
  color: var(--faint);
}

.map-popup-btn {
  display: block;
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.4rem;
  border: 1px solid var(--brand-muted, #8cc5b5);
  border-radius: 6px;
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-weight: 600;
  font-size: 0.78rem;
  cursor: pointer;
  text-align: center;
  transition: background var(--duration-fast) ease;
}

.map-popup-btn:hover {
  background: #d0ede4;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 860px) {
  .map-container {
    height: 50vh;
    min-height: 300px;
    max-height: 500px;
  }

  .map-controls {
    width: 180px;
    font-size: 0.78rem;
  }

  .map-controls-body {
    padding: 0.6rem 0.7rem;
  }
}

@media (max-width: 480px) {
  .map-controls {
    top: auto;
    bottom: 0.5rem;
    right: 0.5rem;
    left: 0.5rem;
    width: auto;
    border-radius: var(--radius);
  }

  .map-controls.collapsed {
    left: auto;
    width: auto;
  }
}
