/* ─────────────── SHARED MAP MARKER STYLES ───────────────
   One source of truth for the MapLibre marker DOM that map-core.js builds on
   every surface: /live/ (live.css) and the home map card (home.css). Linked
   by both live/index.html and index.html — keep page-specific styling out of
   this file.

   Theme contract — the embedding page supplies these custom properties (on
   :root for /live/, pinned to civic values on .home-map for the home page):
     --transition-fast, --transition-standard
     --text-main, --bg-lifted, --bg-deep, --border
     --font-display, --font-mono (optional; falls back to JetBrains Mono)
   map-core.js sets --accent-color and --bg-color inline per marker. */

/* MapLibre positions marker roots itself (absolute + transform). Site rules
   on marker classes (e.g. .community-pin's position: relative) must never
   pull them back into document flow — markers would stack by static layout
   position and drift off their coordinates, worst when zoomed out. */
.maplibregl-marker { position: absolute !important; }

/* wrapper positioned by MapLibre */
.maplibre-marker-wrapper {
  --marker-hit-size: 40px;
  width: var(--marker-hit-size);
  height: var(--marker-hit-size);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  pointer-events: auto;
  cursor: pointer;
  touch-action: manipulation;
}

.maplibre-marker-wrapper:focus-visible {
  outline: 2px solid var(--text-main);
  outline-offset: 3px;
  border-radius: 50%;
}

/* Base custom marker style container */
.maplibre-marker-wrapper > div {
  pointer-events: none;
  transition: transform var(--transition-fast);
}

/* --- Quiet Background Quakes --- */
.background-quake-marker {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 10px;
  height: 10px;
}

.background-quake-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--accent-color);
  opacity: 0.72;
  border: 1px solid #FFFFFF;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.background-quake-marker:hover .background-quake-dot {
  opacity: 1;
  transform: scale(1.2);
}

/* --- Epicentre Earthquakes --- */
.quake-marker.severity-weak { --dot-size: 8px; }
.quake-marker.severity-light { --dot-size: 10px; }
.quake-marker.severity-moderate { --dot-size: 12px; }
.quake-marker.severity-strong { --dot-size: 14px; }
.quake-marker.severity-severe { --dot-size: 17px; }
.quake-marker.severity-extreme { --dot-size: 20px; }

.quake-marker {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--dot-size);
  height: var(--dot-size);
}

/* Halo behind the dot */
.quake-halo {
  position: absolute;
  width: 180%;
  height: 180%;
  border-radius: 50%;
  background-color: var(--accent-color);
  opacity: 0.15;
  transition: width var(--transition-standard), height var(--transition-standard), opacity var(--transition-standard);
  pointer-events: none;
}

.quake-marker.selected .quake-halo {
  width: 230%;
  height: 230%;
  opacity: 0.28;
}

/* Solid Inner Dot */
.quake-dot {
  width: var(--dot-size);
  height: var(--dot-size);
  border-radius: 50%;
  background-color: var(--accent-color);
  border: 1px solid rgba(255, 255, 255, 0.65);
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  z-index: 2;
  transition: transform var(--transition-fast);
}

.quake-marker.selected .quake-dot {
  transform: scale(1.2);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

/* Concentric expanding P-wave rings */
.quake-ring {
  position: absolute;
  width: var(--dot-size);
  height: var(--dot-size);
  border-radius: 50%;
  border: 1.5px solid var(--accent-color);
  pointer-events: none;
  opacity: 0;
  box-sizing: border-box;
}

/* Wave expansion keyframe trigger */
.quake-marker.pulse-animate .quake-ring.ring-1 {
  animation: wavePulse 2.4s cubic-bezier(0.215, 0.610, 0.355, 1) infinite;
}
.quake-marker.pulse-animate .quake-ring.ring-2 {
  animation: wavePulse 2.4s cubic-bezier(0.215, 0.610, 0.355, 1) infinite;
  animation-delay: 1.2s;
}

@keyframes wavePulse {
  0% {
    transform: scale(1);
    opacity: 0.65;
  }
  100% {
    transform: scale(4);
    opacity: 0;
  }
}

/* Age decay: older quakes recede without losing their intensity colour. */
.quake-marker[data-age="aging"] {
  opacity: 0.78;
}
.quake-marker[data-age="stale"] {
  opacity: 0.58;
  filter: saturate(0.55);
}
.quake-marker.selected[data-age] {
  opacity: 1;
  filter: none;
}

/* Magnitude badge below epicentre */
.quake-mag-badge {
  position: absolute;
  bottom: -22px;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--bg-lifted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 6px;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  z-index: 3;
}

.quake-mag-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--accent-color);
  display: inline-block;
}

.quake-mag-badge span {
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  font-size: 10px;
  font-weight: 700;
  color: var(--text-main);
}

/* --- Alert Icon Markers (Weather & NEMA) --- */
.alert-icon-marker {
  position: relative;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background-color: var(--bg-lifted);
  border: 2px solid var(--accent-color);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 8px rgba(0,0,0,0.3);
  transition: transform var(--transition-fast), border-width var(--transition-fast), width var(--transition-fast), height var(--transition-fast), background-color var(--transition-standard), border-color var(--transition-standard);
  z-index: 5;
}

.alert-icon-marker::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  background-color: var(--bg-color);
  z-index: 0;
  opacity: 0.8;
}

.alert-marker-icon-container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.alert-icon-marker svg {
  width: 14px;
  height: 14px;
  color: var(--accent-color);
  stroke: currentColor;
  fill: none;
  transition: width var(--transition-fast), height var(--transition-fast);
}

/* Selected state scaling */
.alert-icon-marker.selected {
  width: 34px;
  height: 34px;
  border-width: 3px;
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  z-index: 999;
}

.alert-icon-marker.selected svg {
  width: 18px;
  height: 18px;
}

/* ─── Feed-card hover → map-marker "locator" animation ───
   When a feed card is hovered, its marker animates so the eye can find it on
   the map: area alerts wiggle, quakes (circular, so rotation reads as nothing)
   pulse/ping instead. The animated element is always the INNER marker, never
   the wrapper — the wrapper carries MapLibre's positioning transform. */
.maplibre-marker-wrapper.marker-hover-active {
  z-index: 1000;
}

.marker-hover-active .alert-icon-marker {
  transform-origin: center center;
  animation: marker-wiggle 0.55s ease-in-out infinite;
}

@keyframes marker-wiggle {
  0%, 100% { transform: scale(1.18) rotate(0deg); }
  25%      { transform: scale(1.18) rotate(-8deg); }
  50%      { transform: scale(1.18) rotate(7deg); }
  75%      { transform: scale(1.18) rotate(-4deg); }
}

/* Epicentre quakes: bounce the dot and force the P-wave rings on so a burst
   radiates out — far more findable than a rotation on a tiny circle. */
.marker-hover-active .quake-marker {
  animation: marker-quake-bounce 0.7s ease-in-out infinite;
}
.marker-hover-active .quake-halo {
  opacity: 0.4;
}
.marker-hover-active .quake-ring.ring-1 {
  animation: wavePulse 1.1s cubic-bezier(0.215, 0.610, 0.355, 1) infinite;
}
.marker-hover-active .quake-ring.ring-2 {
  animation: wavePulse 1.1s cubic-bezier(0.215, 0.610, 0.355, 1) infinite;
  animation-delay: 0.55s;
}

@keyframes marker-quake-bounce {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.5); }
}

/* Tiny background quakes have no rings — give the dot a radar-style ping. */
.marker-hover-active .background-quake-dot {
  opacity: 1;
  animation: bg-quake-ping 1s ease-out infinite;
}

@keyframes bg-quake-ping {
  0%   { transform: scale(1);   box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-color) 65%, transparent); }
  70%  { transform: scale(1.7); box-shadow: 0 0 0 9px color-mix(in srgb, var(--accent-color) 0%, transparent); }
  100% { transform: scale(1);   box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-color) 0%, transparent); }
}

/* Transient ping shown when a hovered card's quake is too small to be drawn at
   the current zoom (so the card still points to a spot on the map). */
.hover-locator {
  position: relative;
  width: 0;
  height: 0;
  pointer-events: none;
  z-index: 1000;
}

.hover-locator-dot,
.hover-locator-ping {
  position: absolute;
  left: -7px;
  top: -7px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
}

.hover-locator-dot {
  background-color: var(--accent-color);
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.25);
}

.hover-locator-ping {
  border: 2px solid var(--accent-color);
  animation: locator-ping 1s ease-out infinite;
}

@keyframes locator-ping {
  0%   { transform: scale(1);   opacity: 0.8; }
  100% { transform: scale(4.5); opacity: 0; }
}

/* ─────────────── MAP COMMUNITY SIGNAL MARKERS ───────────────
   Point hazards (flooding, road blocked, fire …) render as glyph-first pins;
   area impressions (felt it, heavy rain) render as suburb label chips.
   data-age drives visual decay so the map self-cleans. */

.community-pin {
  position: relative;
  width: 34px;
  height: 42px;
  cursor: pointer;
  transition: opacity var(--transition-fast);
}

.community-pin-head {
  width: 34px;
  height: 34px;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  background-color: var(--accent-color);
  border: 2px solid color-mix(in srgb, #fff 82%, var(--accent-color));
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
  display: grid;
  place-items: center;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.community-pin-head svg {
  width: 16px;
  height: 16px;
  color: #fff;
  transform: rotate(45deg);
}

.community-pin:hover .community-pin-head,
.community-pin.selected .community-pin-head {
  transform: rotate(-45deg) scale(1.12);
  box-shadow: 0 0 16px var(--accent-color);
}

.community-pin-count {
  position: absolute;
  top: -5px;
  right: -7px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background-color: var(--bg-deep);
  border: 1.5px solid var(--accent-color);
  color: var(--text-main);
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 800;
  display: grid;
  place-items: center;
}

.community-pin-pulse {
  position: absolute;
  top: 0;
  left: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--accent-color);
  opacity: 0;
  animation: signal-pulse 2.2s cubic-bezier(0.24, 0, 0.38, 1) infinite;
  pointer-events: none;
}

@keyframes signal-pulse {
  0% { transform: scale(0.9); opacity: 0.65; }
  100% { transform: scale(1.3); opacity: 0; }
}

.community-area-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px 5px 7px;
  border-radius: 999px;
  background-color: color-mix(in srgb, var(--bg-deep) 88%, var(--accent-color));
  border: 1.5px solid color-mix(in srgb, var(--accent-color) 65%, transparent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  transition: opacity var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
  white-space: nowrap;
}

.community-area-chip:hover,
.community-area-chip.selected {
  transform: scale(1.06);
  box-shadow: 0 0 14px color-mix(in srgb, var(--accent-color) 55%, transparent);
}

.community-chip-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background-color: var(--accent-color);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.community-chip-icon svg {
  width: 11px;
  height: 11px;
}

.community-chip-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-main);
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.community-chip-count {
  font-family: var(--font-display);
  font-size: 11.5px;
  font-weight: 800;
  color: var(--accent-color);
}

/* Freshness decay + unconfirmed styling, shared by both marker families */
.community-pin[data-age="aging"],
.community-area-chip[data-age="aging"] { opacity: 0.85; }
.community-pin[data-age="stale"],
.community-area-chip[data-age="stale"] { opacity: 0.55; }
.community-pin.tentative .community-pin-head { border-style: dashed; }
.community-area-chip.tentative { border-style: dashed; opacity: 0.8; }

/* Disputed signals visually recede. */
.community-pin.contested,
.community-area-chip.contested { opacity: 0.45; }

/* NZ Police incidents (community layer) */
.community-pin.is-incident .community-pin-head {
  border-color: #1B4F9C; /* provenance ring: police blue, not the white of citizen pins */
}

/* Prefers Reduced Motion fallback */
@media (prefers-reduced-motion: reduce) {
  .quake-marker.pulse-animate .quake-ring {
    animation: none !important;
    opacity: 0.25;
    transform: scale(2.5);
  }
  /* Locator: swap motion for a static enlarge + halo so it's still findable. */
  .marker-hover-active .alert-icon-marker,
  .marker-hover-active .quake-marker,
  .marker-hover-active .quake-ring,
  .marker-hover-active .background-quake-dot,
  .hover-locator-ping {
    animation: none !important;
  }
  .marker-hover-active .alert-icon-marker { transform: scale(1.25); }
  .marker-hover-active .quake-marker { transform: scale(1.5); }
  .marker-hover-active .quake-halo { opacity: 0.5; }
  .marker-hover-active .background-quake-dot { transform: scale(1.9); opacity: 1; }
  .hover-locator-ping { transform: scale(2.2); opacity: 0.5; }
}
