/* Map view */

#view-map {
  max-width: 1300px;
  margin: 0 auto;
}

.map-host {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  margin-top: 8px;
  min-height: 360px;
  position: relative;
  overflow: hidden;
}

.map-loading,
.map-error {
  padding: 60px 12px;
  text-align: center;
  color: var(--text-secondary);
}
.map-error { color: #b94a48; }

.map-svg {
  width: 100%;
  height: auto;
  display: block;
  --map-empty: var(--bg-surface-alt);
  cursor: grab;
  /* Stop the browser from scrolling the page while the user drags or
     pinches inside the map — let d3.zoom handle the gesture exclusively. */
  touch-action: none;
  /* Stops the iOS magnifier loupe + text selection on long-press. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.map-svg:active { cursor: grabbing; }

.map-controls {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin: 6px 4px 0;
}
.map-zoom-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 18px;
  line-height: 1;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.map-zoom-btn:hover { background: var(--bg-hover-soft); border-color: var(--accent); }

/* Touch targets: bump zoom buttons + give the map a taller aspect on
   small viewports so individual countries are tappable. The taller box
   shows blank top/bottom under NaturalEarth's natural 2:1 ratio, but
   that's a fair tradeoff for usable hit-zones. */
@media (max-width: 680px) {
  .map-zoom-btn {
    width: 44px;
    height: 44px;
    font-size: 22px;
  }
  .map-host {
    min-height: 320px;
  }
  .map-tip {
    /* On touch this only appears briefly after a tap — keep it small. */
    font-size: 12px;
    padding: 6px 8px;
  }
  .map-modal-card {
    width: 96vw;
    max-height: 92vh;
  }
}

.map-region {
  stroke: var(--border-color);
  stroke-width: 0.4px;
  transition: filter 0.12s, stroke 0.12s, stroke-width 0.12s;
}
.map-region-active {
  cursor: pointer;
}
.map-region-active:hover {
  stroke: var(--accent);
  stroke-width: 1.4px;
  filter: brightness(1.05);
}

/* US states drawn over the (transparent) USA polygon — make their borders
   a touch sharper so individual states read at world scale. */
.map-states .map-region {
  stroke: var(--border-color);
  stroke-width: 0.5px;
}

.map-legend rect {
  stroke-width: 0.5px;
}
.map-legend-label {
  font-size: 10px;
  fill: var(--text-secondary);
}
.map-legend-title {
  font-size: 11px;
  fill: var(--text-muted);
}

#map-summary {
  color: var(--text-secondary);
}

/* ---- Tooltip ---- */

.map-tip {
  position: fixed;
  z-index: 250;
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.35;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  max-width: 260px;
}
.map-tip-muted { color: var(--text-muted); font-style: italic; }

/* ---- Click modal ---- */

.map-modal {
  position: fixed;
  inset: 0;
  z-index: 220;
  display: flex;
  align-items: center;
  justify-content: center;
}
.map-modal.hidden { display: none; }

.map-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
}
.map-modal-card {
  position: relative;
  background: var(--bg-surface);
  color: var(--text-primary);
  border-radius: 10px;
  width: min(560px, 92vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 14px 40px rgba(0,0,0,0.35);
  overflow: hidden;
}
.map-modal-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
}
.map-modal-header h3 {
  margin: 0;
  font-size: 17px;
  flex: 1;
}
.map-modal-close {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: 6px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 14px;
}
.map-modal-close:hover { background: var(--bg-hover-soft); }
.map-modal-body {
  padding: 14px 16px 18px;
  overflow-y: auto;
}
.map-modal-count {
  margin: 0 0 10px;
  color: var(--text-muted);
  font-size: 13px;
}
.map-modal-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.map-modal-chip {
  background: var(--accent-soft, var(--bg-surface-alt));
  color: var(--text-primary);
  border: 1px solid var(--accent-border, var(--border-color));
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
}
.map-modal-chip strong { color: var(--accent); margin-left: 4px; }
.map-modal-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.map-modal-list li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border-color);
}
.map-modal-list li:last-child { border-bottom: 0; }
.map-modal-person {
  background: transparent;
  border: 0;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-align: left;
}
.map-modal-person:hover { text-decoration: underline; }
.map-modal-meta {
  color: var(--text-muted);
  font-size: 12px;
}
.map-modal-empty {
  color: var(--text-muted);
  text-align: center;
  margin: 30px 0;
}
