/* ==========================================================================
   Broken Wings Initiative (BWI) - Charity: Water Style Interactive Map
   Features:
   - Dark-themed command-center map container (#0b1329 / #152238)
   - Zero-jitter absolute positioned circular pulse pins with short metric badges (e.g. 4k, 13k, 18k)
   - SVG vector geography with pointer-events: none (zero polygon hover twitching)
   - Dedicated side-panel info card updated smoothly with zero layout reflow
   ========================================================================== */

/* ==========================================================================
   FLUID CORE
   styles.css already applies a global `*` border-box reset, but this file
   repeats it so the map/infocard subtree stays self-contained. Padding can
   therefore never push a track past the viewport edge.
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

.map-wrapper {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Map Header & Controls Strip */
.map-controls {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.map-controls-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.map-live-beacon {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8da2c0;
}

.live-beacon-dot {
  width: 9px;
  height: 9px;
  background: #e63946;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(230, 57, 70, 0.35);
  animation: liveBeaconPulse 2s infinite;
}

@keyframes liveBeaconPulse {
  0% { transform: scale(0.9); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 1; box-shadow: 0 0 0 5px rgba(230, 57, 70, 0.15); }
  100% { transform: scale(0.9); opacity: 0.8; }
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1.2rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #64748b;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
}

.legend-dot.critical {
  background: #e63946;
  box-shadow: 0 0 0 2px rgba(230, 57, 70, 0.3);
}

.legend-dot.high {
  background: #f4a261;
}

/* Dark Zone Selector Pills */
.map-zone-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.zone-pill {
  padding: 0.45rem 0.95rem;
  border-radius: var(--radius-full);
  border: 1px solid #e2e8f0;
  background: #ffffff;
  color: #334155;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  transition: all 0.2s ease;
  user-select: none;
}

.zone-pill:hover {
  border-color: #e63946;
  color: #e63946;
  background: #fff5f5;
}

.zone-pill.active {
  background: #e63946;
  color: #ffffff;
  border-color: #e63946;
  box-shadow: 0 4px 12px rgba(230, 57, 70, 0.35);
}

.zone-pill.active i {
  color: #ffccd5;
}

.zone-pill-count {
  background: rgba(0, 0, 0, 0.15);
  padding: 0.1rem 0.45rem;
  border-radius: 9999px;
  font-size: 0.72rem;
  font-weight: 800;
}

.zone-pill.active .zone-pill-count {
  background: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

/* ==========================================================================
   CHARITY: WATER STYLE DARK MAP CONTAINER
   ========================================================================== */

.cw-map-container {
  position: relative;
  background: radial-gradient(circle at 62% 42%, #142239 0%, #0b1329 100%);
  border-radius: var(--radius-lg);
  border: 1px solid #1e293b;
  box-shadow: 0 16px 40px rgba(11, 19, 41, 0.22);
  min-height: 520px;
  height: 540px;
  overflow: hidden;
  user-select: none;
}

/* Coordinate Grid Lines Background */
.cw-map-grid-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: 
    linear-gradient(to right, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 50px 50px;
  pointer-events: none;
}

/* Geographic SVG Canvas (Strictly pointer-events: none to prevent any hover jitter) */
.cw-svg-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none !important;
  display: block;
}

/* Vector Geography Styles */
.cw-geo-bg {
  fill: rgba(22, 38, 63, 0.45);
  stroke: #1e3a5f;
  stroke-width: 1.2;
}

.cw-prov-shape {
  fill: rgba(30, 48, 77, 0.6);
  stroke: #2a476f;
  stroke-width: 1.5;
  stroke-linejoin: round;
}

.cw-prov-metro {
  fill: rgba(230, 57, 70, 0.15);
  stroke: rgba(230, 57, 70, 0.5);
  stroke-width: 1.5;
}

.cw-river {
  stroke: #38bdf8;
  stroke-width: 1.6;
  fill: none;
  stroke-linecap: round;
  stroke-dasharray: 4, 4;
  opacity: 0.35;
}

.cw-water-text {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  fill: #64748b;
  opacity: 0.7;
}

.cw-geo-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  fill: #475569;
}

/* Map Meta Watermark */
.cw-map-meta {
  position: absolute;
  bottom: 1rem;
  left: 1.25rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: #475569;
  letter-spacing: 0.05em;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.cw-map-meta span {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

/* ==========================================================================
   STABLE CIRCULAR PULSE PINS (ABSOLUTE POSITIONED - ZERO JITTER)
   ========================================================================== */

.cw-pins-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* Only children pins receive events */
}

.cw-map-pin {
  position: absolute;
  transform: translate(-50%, -50%);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  pointer-events: all !important;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), z-index 0.2s ease;
  user-select: none;
  outline: none;
}

/* Expanding Radar Pulse Ring */
.cw-pin-pulse {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  margin-top: -22px;
  margin-left: -22px;
  border-radius: 50%;
  border: 2px solid rgba(230, 57, 70, 0.75);
  background: rgba(230, 57, 70, 0.12);
  pointer-events: none !important;
  animation: cwRadarPulse 2.5s infinite cubic-bezier(0.2, 0.6, 0.3, 1);
}

@keyframes cwRadarPulse {
  0% { transform: scale(0.85); opacity: 0.95; }
  65% { transform: scale(2.2); opacity: 0.2; }
  100% { transform: scale(2.6); opacity: 0; }
}

/* Core Circular Metric Badge (Charity: Water signature style) */
.cw-pin-badge {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #e63946;
  border: 2.5px solid #ffffff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5), 0 0 12px rgba(230, 57, 70, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-weight: 800;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.88rem;
  letter-spacing: -0.02em;
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none; /* parent gets click */
}

/* Pin Label Tag */
.cw-pin-label {
  margin-top: 6px;
  background: rgba(11, 19, 41, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #f1f5f9;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 0.22rem 0.55rem;
  border-radius: 9999px;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  transition: all 0.2s ease;
}

/* Hover State - gated to hover-capable pointers so touch devices don't get
   a sticky "stuck hovered" pin after a tap */
@media (hover: hover) and (pointer: fine) {
  .cw-map-pin:hover {
    z-index: 25;
  }

  .cw-map-pin:hover .cw-pin-badge {
    transform: scale(1.12);
    background: #d90429;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.6), 0 0 16px rgba(230, 57, 70, 0.8);
  }

  .cw-map-pin:hover .cw-pin-label {
    border-color: rgba(255, 255, 255, 0.4);
    color: #ffffff;
  }
}

/* Active / Selected State */
.cw-map-pin.active {
  z-index: 30;
}

.cw-map-pin.active .cw-pin-badge {
  background: #c1121f;
  transform: scale(1.22);
  border-color: #ffd166;
  box-shadow: 0 0 24px rgba(230, 57, 70, 0.95), 0 0 0 4px rgba(255, 209, 102, 0.45);
}

.cw-map-pin.active .cw-pin-pulse {
  border-color: rgba(255, 209, 102, 0.85);
  animation-duration: 1.6s;
}

.cw-map-pin.active .cw-pin-label {
  background: #e63946;
  color: #ffffff;
  border-color: #ffffff;
  font-weight: 800;
  box-shadow: 0 4px 14px rgba(230, 57, 70, 0.5);
  transform: translateY(2px) scale(1.05);
}

/* Map Bottom Instruction Strip */
.cw-map-instruction {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}

/* ==========================================================================
   LOCKED TWO-COLUMN TRACKING - MAP SIDE | INFO SIDE
   Percentage tracks (instead of 1.3fr / 0.9fr) stop a long zone title from
   pushing the info column wider and squeezing the map column narrower. The
   map geometry and the zone-pill rows therefore stay identical across zones.
   min-width: 0 on the children stops their content from forcing the tracks
   to overflow (grid items default to min-width: auto, which is the actual
   cause of the "long title widens the column" behaviour).
   ========================================================================== */

.impact-layout-grid {
  display: grid !important;
  /* Map side is locked to exactly 45% of the container. The gap is subtracted
     from the second track so the two columns can never sum past 100% and
     overflow the grid. */
  grid-template-columns: 45% calc(55% - 2.5rem) !important;
  width: 100%;
  gap: 2.5rem;
  align-items: start;
  box-sizing: border-box;
}

.impact-layout-grid > .map-card-container,
.impact-layout-grid > .infocard-container {
  min-width: 0;
  max-width: 100%;
}

/* Title text must never be able to widen the info column */
.zone-title {
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
  overflow: hidden;
}

/* ==========================================================================
   DEDICATED REGIONAL CRISIS SIDE-PANEL INFO CARD
   ========================================================================== */

.infocard-box {
  background: #ffffff;
  border-radius: var(--radius-lg);
  padding: 2rem;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 100px;
  min-height: 590px;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.infocard-content-wrap {
  animation: cwFadeIn 0.25s ease-out;
}

@keyframes cwFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.infocard-header {
  margin-bottom: 1.3rem;
}

.crisis-severity-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 800;
  color: #c1121f;
  background: #ffe3e3;
  border: 1px solid #ffccd5;
  padding: 0.3rem 0.8rem;
  border-radius: var(--radius-full);
  margin-bottom: 0.55rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.crisis-severity-badge.high {
  color: #b45309;
  background: #fef3c7;
  border-color: #fde68a;
}

.zone-title {
  font-size: 1.55rem;
  margin-bottom: 0.25rem;
  color: var(--dark-slate);
  line-height: 1.22;
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
  overflow: hidden;
}

.zone-province {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Metrics 2x2 Grid
   align-items: stretch makes every card in a row auto-match the tallest
   card in that row, so boxes stay visually identical without a hard height.
   The auto-fit track list lets the grid reflow from 2 columns to 1 on its
   own when the viewport can no longer fit a 140px column. */
.infocard-metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  align-items: stretch;
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

/* Fluid metric box: no static height anywhere, padding scales with viewport */
.metric-box {
  border-radius: var(--radius-sm);
  padding: clamp(10px, 3vw, 16px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  border: 1px solid transparent;
  height: auto;
  min-height: 120px;
  overflow: hidden;
  box-sizing: border-box;
}

.metric-data {
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex: 1;
  min-height: 0;
}

.metric-box.alert-box {
  background: #fff5f5;
  border-color: #ffe3e3;
}

.metric-box.warning-box {
  background: #fffdf5;
  border-color: #fef3c7;
}

.metric-icon {
  font-size: 1.25rem;
  padding-top: 0.2rem;
}

.alert-box .metric-icon {
  color: var(--primary-red);
}

.warning-box .metric-icon {
  color: #d97706;
}

/* Uniform typographic rhythm inside the metric cards.
   Fixed line-heights + reserved min-heights mean a value that wraps onto a
   second line grows the card by exactly one predictable increment instead of
   an arbitrary amount, so the 2x2 grid stays visually even. */
.metric-label {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-muted);
  line-height: 1.25;
  min-height: 2.5em; /* Always reserves two lines for the label */
}

/* The large numeric headline inside each metric card.
   The font size and line-height are rigid and locked with !important so a
   long value ("16,800+ children") renders identically across every region
   and cannot be overridden by inherited or responsive font scaling.
   min-height reserves exactly two lines, so the .metric-sub caption below
   always begins on the same vertical baseline whether the value wraps to
   one line or two. */
.metric-val {
  font-size: clamp(1.2rem, 4vw, 1.6rem);
  line-height: 1.2;
  font-weight: 800;
  font-family: 'Outfit', sans-serif;
  margin: 0.15rem 0;
  min-height: 2.4em; /* 2 lines x 1.2 line-height = fixed anchor for .metric-sub */
  display: flex;
  align-items: flex-start;
  overflow-wrap: anywhere;
  word-break: normal;
}

.metric-sub {
  font-size: 0.72rem;
  color: var(--text-gray);
  line-height: 1.2;
  min-height: 1.2em;
  overflow-wrap: anywhere;
}

/* Human Reality Narrative */
.infocard-details {
  border-top: 1px solid var(--border-color);
  padding-top: 1.2rem;
  margin-bottom: 1.5rem;
  flex: 1;
}

.infocard-details h4 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--dark-slate);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.zone-description {
  font-size: 0.88rem;
  color: var(--text-gray);
  line-height: 1.55;
  margin-bottom: 0.9rem;
}

.root-causes-wrap {
  background: #f8fafc;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--primary-red);
  font-size: 0.82rem;
  margin-bottom: 1rem;
}

.root-causes-wrap strong {
  color: var(--dark-slate);
  display: block;
  margin-bottom: 0.2rem;
}

.causes-text {
  color: var(--text-gray);
  line-height: 1.45;
  margin: 0;
}

.active-projects-list .proj-title {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--dark-slate);
  margin-bottom: 0.5rem;
}

.proj-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.proj-tag.emergency {
  background: rgba(230, 57, 70, 0.08);
  color: #c1121f;
  border: 1px solid rgba(230, 57, 70, 0.2);
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.infocard-actions {
  margin-top: auto;
}

/* ==========================================================================
   RESPONSIVE ADJUSTMENTS
   Breakpoints are declared largest-first and in descending width order
   (1024 -> 768 -> 640 -> 420). Later blocks win on equal specificity, so
   each narrower breakpoint reliably layers on top of the previous one and
   tiny screens always land on the clean single-column layout.
   ========================================================================== */

/* Tablet / small laptop: stack the two-column impact layout.
   Tracks must be reset with matching !important to beat the locked 45/55
   desktop rule above. */
@media (max-width: 1024px) {
  .impact-layout-grid {
    grid-template-columns: 1fr !important;
  }

  .cw-map-container {
    height: 480px;
    min-height: 480px;
  }

  .infocard-box {
    position: static;
    min-height: auto;
  }
}

/* Phone / tablet portrait: fluid single-column layout */
@media (max-width: 768px) {
  /* Hard container constraints so nothing can spill off the right edge.
     100% + max-width is used rather than 100vw, because 100vw includes the
     scrollbar gutter and would itself introduce horizontal overflow. */
  body,
  .container,
  .section,
  .impact-layout-grid,
  .map-card-container,
  .infocard-container,
  .infocard-box,
  .map-wrapper,
  .infocard-details,
  .infocard-actions {
    width: 100% !important;
    max-width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
  }

  /* Vertical stack. The grid tracks are neutralised too, since a flex
     container ignores grid-template-columns. */
  .impact-layout-grid {
    display: flex !important;
    flex-direction: column !important;
    grid-template-columns: none !important;
    gap: 10px;
  }

  .map-card-container,
  .infocard-container,
  .infocard-box {
    min-height: 0;
    margin: 10px 0;
  }

  /* Keep the map visible: the desktop min-height: 600px on the card would
     otherwise reserve a huge empty box above a short map. */
  .map-card-container {
    min-height: 0 !important;
    padding: clamp(10px, 3vw, 16px);
  }

  /* Map scales with the device height ratio, clamped at both ends so it
     never clips on a short landscape phone nor balloons on a tablet. */
  .cw-map-container {
    width: 100% !important;
    height: 45vh !important;
    min-height: 280px;
    max-height: 400px;
    display: block !important;
    overflow: hidden;
  }

  .cw-svg-canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
  }

  .cw-pins-layer {
    width: 100% !important;
    height: 100% !important;
  }

  .infocard-box {
    padding: clamp(10px, 3vw, 16px);
  }

  /* Fluid wrapping: 2 columns when >=140px each fits, 1 column below that.
     No hard column count, so no breakpoint can strand the layout. */
  .infocard-metrics-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important;
    align-items: stretch;
    gap: 12px !important;
    width: 100% !important;
  }

  .metric-box {
    height: auto !important;
    padding: clamp(10px, 3vw, 16px) !important;
    min-width: 0;
    max-width: 100%;
  }

  .metric-label {
    min-height: 2.5em;
  }

  /* Value scales with viewport width so long figures stay on one line */
  .metric-val {
    font-size: clamp(1.2rem, 4vw, 1.6rem) !important;
    line-height: 1.2 !important;
  }

  /* Buttons, forms and subscribe inputs stay inside their card slots */
  .btn,
  .btn-block,
  .zone-pill,
  input,
  select,
  textarea,
  .form-group,
  .newsletter-form-row {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  .newsletter-form-row {
    flex-wrap: wrap;
    gap: 10px;
  }

  .zone-pill {
    padding: 0.5rem 0.8rem;
    font-size: 0.78rem;
  }
}

/* Small phones: smaller pins, no pin label clutter.
   The metric grid stays fluid via auto-fit, and .metric-val keeps scaling
   through its clamp, so no per-breakpoint font override is needed here. */
@media (max-width: 640px) {
  .cw-pin-badge {
    width: 36px;
    height: 36px;
    font-size: 0.8rem;
  }

  .cw-pin-pulse {
    width: 38px;
    height: 38px;
    margin-top: -19px;
    margin-left: -19px;
  }

  .cw-pin-label {
    display: none; /* Hide pin labels on small mobile to prevent clutter */
  }

  .metric-box {
    min-height: 104px;
  }
}

/* Very narrow phones: final tightening pass */
@media (max-width: 420px) {
  .infocard-metrics-grid {
    /* Below ~140px of track the auto-fit columns would be unusably narrow,
       so drop the minimum and let each box own the full row. */
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }

  .zone-title {
    font-size: 1.3rem;
  }
}
