/*
 * PFAS heatmap styles.
 * Scoped to the #map-section container and the floating tooltip / bottom
 * sheet elements. Does NOT override the host page's body/html/header —
 * that is the site's responsibility (this runs inside the Astro layout).
 */

:root {
  --pfm-bg: #0d1117;
  --pfm-surface: #1c1c2e;
  --pfm-surface-hover: #252540;
  --pfm-border: rgba(255,255,255,0.08);
  --pfm-border-light: rgba(255,255,255,0.15);
  --pfm-text: #e6edf3;
  --pfm-text-muted: #8b949e;
  --pfm-accent: #f4a259;
  --pfm-accent-hover: #f5b576;
}

/* ── Map container (background already set by Astro page) ─────── */
#map {
  width: 100%;
  height: 100%;
}

/* Leaflet overrides — use high specificity so they win against Leaflet's own CSS */
.pfas-map-section .leaflet-container {
  background: var(--pfm-bg) !important;
  font-family: 'IBM Plex Sans', system-ui, -apple-system, sans-serif !important;
  color: var(--pfm-text);
}

.pfas-map-section .leaflet-control-attribution {
  background: rgba(13, 17, 23, 0.85) !important;
  color: var(--pfm-text-muted) !important;
  font-size: 10px !important;
  padding: 2px 6px !important;
}

.pfas-map-section .leaflet-control-attribution a {
  color: var(--pfm-text-muted) !important;
}

.pfas-map-section .leaflet-control-zoom {
  border: 1px solid var(--pfm-border-light) !important;
  border-radius: 6px !important;
  overflow: hidden;
}

.pfas-map-section .leaflet-control-zoom a {
  background: var(--pfm-surface) !important;
  color: var(--pfm-text) !important;
  border-color: var(--pfm-border) !important;
  width: 32px !important;
  height: 32px !important;
  line-height: 32px !important;
  font-size: 16px !important;
}

.pfas-map-section .leaflet-control-zoom a:hover {
  background: var(--pfm-surface-hover) !important;
}

/* ── Legend ───────────────────────────────────────────────────── */
.legend-control {
  background: rgba(13, 17, 23, 0.92);
  border: 1px solid var(--pfm-border-light);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 11px;
  color: var(--pfm-text-muted);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  min-width: 150px;
}

.legend-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--pfm-text);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
}

.legend-swatch {
  width: 16px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.06);
}

.legend-label {
  font-size: 11px;
  color: var(--pfm-text-muted);
}

/* ── Tooltip (desktop floating) ──────────────────────────────── */
.tooltip {
  position: fixed;
  z-index: 2000;
  background: var(--pfm-surface);
  border: 2px solid var(--pfm-border-light);
  border-radius: 10px;
  padding: 14px 16px;
  min-width: 240px;
  max-width: 300px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  pointer-events: auto;
  transition: border-color 0.15s, box-shadow 0.15s, opacity 0.15s;
  color: var(--pfm-text);
  font-family: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
}

.tooltip.hidden { display: none; }

.tooltip.pinned {
  border-color: var(--pfm-accent);
  box-shadow:
    0 8px 32px rgba(0,0,0,0.6),
    0 0 0 3px rgba(244, 162, 89, 0.35),
    0 0 24px rgba(244, 162, 89, 0.25);
}

.tooltip-close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: none;
  border: none;
  color: var(--pfm-text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  display: none;
}
.tooltip-close:hover { color: var(--pfm-text); }

.tooltip-hint {
  font-size: 10px;
  color: var(--pfm-text-muted);
  text-align: center;
  margin-top: 8px;
  display: none;
}

.tooltip-header {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--pfm-border);
}

.tooltip-county {
  font-size: 14px;
  font-weight: 600;
  color: var(--pfm-text);
}

.tooltip-state {
  font-size: 12px;
  font-weight: 500;
  color: var(--pfm-text-muted);
}

.tooltip-zips {
  font-size: 11px;
  font-weight: 500;
  color: var(--pfm-text-muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.tooltip-zips:not(:empty)::before {
  content: 'ZIPs ';
  color: var(--pfm-border-light);
  font-size: 10px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 2px;
}

.tooltip-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.tooltip-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.tooltip-label {
  font-size: 12px;
  color: var(--pfm-text-muted);
}

.tooltip-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--pfm-text);
  font-variant-numeric: tabular-nums;
}

.tooltip-cta {
  display: block;
  text-align: center;
  background: var(--pfm-accent);
  color: #1a1a2e;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 6px;
  transition: background 0.15s;
}

.tooltip-cta:hover {
  background: var(--pfm-accent-hover);
}

/* ── Bottom Sheet (mobile) ───────────────────────────────────── */
.bottom-sheet {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 2000;
  background: var(--pfm-surface);
  border-top: 1px solid var(--pfm-border-light);
  border-radius: 16px 16px 0 0;
  padding: 8px 20px 24px;
  box-shadow: 0 -8px 32px rgba(0,0,0,0.5);
  max-height: 50vh;
  overflow-y: auto;
  transition: transform 0.25s ease;
  color: var(--pfm-text);
  font-family: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
}

.bottom-sheet.hidden { display: none; }
.bottom-sheet.visible { display: block; }

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--pfm-border-light);
  border-radius: 2px;
  margin: 0 auto 12px;
}

/* ── Loading overlay (absolute within map section) ───────────── */
.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 9999;
  background: var(--pfm-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  transition: opacity 0.4s;
}

.loading-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--pfm-border-light);
  border-top-color: var(--pfm-accent);
  border-radius: 50%;
  animation: pfmSpin 0.8s linear infinite;
}

@keyframes pfmSpin { to { transform: rotate(360deg); } }

.loading-overlay p {
  font-size: 14px;
  color: var(--pfm-text-muted);
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Desktop tooltip hidden on mobile */
  .tooltip { display: none !important; }

  .legend-control {
    font-size: 10px;
    padding: 8px 10px;
    min-width: 120px;
  }
}

@media (min-width: 769px) {
  .bottom-sheet { display: none !important; }
}
