/* ═══════════════════════════════════════════════════
   FENITEL — Shared Map Component
   Realistic Spain outline with click-to-popup UX
   Mobile-first bottom-sheet pattern
   ═══════════════════════════════════════════════════ */

/* ── Map container ── */
.feni-map { position: relative; }
.feni-map-svg {
  width: 100%; height: auto; display: block;
  filter: none;
  overflow: visible;
}

/* The dots group must sit above everything and receive events */
.feni-map-svg .map-dot-layer,
.feni-map-svg #fmDots { pointer-events: auto; }
/* Avoid isolate/stacking tricks: iOS WebKit can fail to paint SVG circles
   inside isolated compositing groups. */
.feni-map-svg .map-dot-layer-inset {
  pointer-events: none;
}

/* ── Region paths — decorative, must not intercept pin events ── */
.feni-map-svg .region {
  fill: #EEF2FF; stroke: #C7D2FE; stroke-width: 1;
  stroke-linejoin: round; transition: fill .2s;
  pointer-events: none;
}
.feni-map-svg .region:hover { fill: #DBEAFE; }
.feni-map-svg .region.has-assoc { fill: #E0E7FF; }
.feni-map-svg .region.has-assoc:hover { fill: #C7D2FE; }

/* ── Override: Galicia and La Rioja are intentionally NOT plotted on the
      presence map. Force them to the non-associated visual treatment even
      if the SVG still carries the `has-assoc` class from the source file. */
.feni-map-svg .region[data-id="ESGA"],
.feni-map-svg .region[data-id="ESRI"] { fill: #EEF2FF !important; }
.feni-map-svg .region[data-id="ESGA"]:hover,
.feni-map-svg .region[data-id="ESRI"]:hover { fill: #DBEAFE !important; }

/* ── Shared marker sizing ── */
.feni-map-svg {
  --map-dot-association-r: 6.8;
  --map-dot-association-hover-r: 7.4;
  --map-dot-association-active-r: 7.7;
  --map-dot-regional-r: 7.2;
  --map-dot-regional-hover-r: 7.7;
  --map-dot-presence-r: 6;
  --map-dot-presence-inset-r: 10.8;
}

/* ── Castilla y León — regional federation, given restrained visual weight */
.feni-map-svg .region[data-id="ESCL"] { fill: #D7DEFB; stroke: #A5B4FC; stroke-width: 1.25; }
.feni-map-svg .region[data-id="ESCL"]:hover { fill: #C7D2FE; }
.feni-map-svg .map-pin.cyl-hub,
.feni-map-svg .map-dot--regional { r: var(--map-dot-regional-r); fill: #2563EB; }
.feni-map-svg .map-pin.cyl-hub:hover,
.feni-map-svg .map-pin.cyl-hub:focus,
.feni-map-svg .map-dot--regional:hover,
.feni-map-svg .map-dot--regional:focus { r: var(--map-dot-regional-hover-r); }
@keyframes feniCylPulse {
  0%   { r: 8;  opacity: .55; }
  100% { r: 18; opacity: 0;   }
}
.feni-map-svg .cyl-pulse {
  display: none;
  fill: none; stroke: #2563EB; stroke-width: 1.5;
  pointer-events: none;
  transform-origin: center;
  animation: feniCylPulse 2.4s ease-out infinite;
}

/* All non-interactive SVG children must not intercept events */
.feni-map-svg text,
.feni-map-svg rect,
.feni-map-svg defs,
.feni-map-svg linearGradient,
.feni-map-svg filter { pointer-events: none; }

/* ── Shared dot model: SVG circles controlled by radius, not layout sizing ── */
.feni-map-svg .map-dot,
.feni-map-svg .map-pin,
.feni-map-svg .map-presence-dot {
  transform: none;
  transform-box: fill-box;
  transform-origin: center;
  shape-rendering: geometricPrecision;
  vector-effect: non-scaling-stroke;
  filter: none;
}

/* ── Decorative associate-presence dots ── */
.feni-map-svg .map-presence-dot,
.feni-map-svg .map-dot--presence {
  r: var(--map-dot-presence-r);
  fill: #93C5FD;
  stroke: rgba(255,255,255,.9);
  stroke-width: .75;
  opacity: 1;
  pointer-events: none;
}
.feni-map-svg .map-dot--inset {
  r: var(--map-dot-presence-inset-r);
  stroke-width: .85;
}

/* ── Clickable dots ── */
.feni-map-svg .map-pin,
.feni-map-svg .map-dot--association {
  r: var(--map-dot-association-r);
  fill: #2563EB;
  stroke: rgba(255,255,255,.98);
  stroke-width: 1.15;
  cursor: pointer; pointer-events: all;
  transition: r .15s ease, fill .15s ease;
}
.feni-map-svg .map-pin:hover,
.feni-map-svg .map-pin:focus,
.feni-map-svg .map-dot--association:hover,
.feni-map-svg .map-dot--association:focus { r: var(--map-dot-association-hover-r); fill: #1D4ED8; outline: none; }
.feni-map-svg .map-pin.active,
.feni-map-svg .map-dot--association.active { r: var(--map-dot-association-active-r); fill: #1E40AF; }

/* Invisible expanded hit area for touch — rendered by JS on mobile */
.feni-map-svg .map-pin-hit {
  fill: transparent; cursor: pointer;
  pointer-events: all; stroke: none;
}

/* Active ring on selected pin */
@keyframes feniActiveRing {
  0%   { r: 7; opacity: .28; }
  50%  { r: 10; opacity: .1; }
  100% { r: 7; opacity: .28; }
}
.feni-map-svg .map-pin-active-ring {
  fill: none; stroke: #2563EB; stroke-width: 1.25;
  pointer-events: none; opacity: 0;
}
.feni-map-svg .map-pin-active-ring.visible {
  opacity: 1;
  animation: feniActiveRing 2s ease-in-out infinite;
}

/* Ripple ring for emphasis dots */
@keyframes feniRipple {
  0%   { r: 5; opacity: .7; }
  70%  { r: 14; opacity: 0; }
  100% { r: 5; opacity: 0; }
}
.feni-map-svg .map-ripple {
  display: none;
  fill: none; stroke: #2563EB; stroke-width: 1.5;
  animation: feniRipple 2.8s ease-out infinite;
  pointer-events: none;
}

/* ── HTML dot overlay ──
   Real iPhone Safari/WebKit has proved unreliable at painting SVG circles in
   this map. JS wraps the SVG in a frame and renders these plain HTML dots
   positioned via percentages computed from the SVG viewBox — timing-safe and
   resize-safe (no getBoundingClientRect dependency). */
.feni-map-svg-frame {
  position: relative;
  display: block;
  line-height: 0;
}
.feni-map-svg-frame > .feni-map-svg {
  display: block;
  width: 100%;
  height: auto;
}
.feni-map-html-dots {
  position: absolute;
  inset: 0;
  z-index: 35;
  pointer-events: none;
  display: block;
}
.feni-map-html-dot {
  position: absolute;
  left: 0;
  top: 0;
  box-sizing: border-box;
  border-radius: 999px;
  transform: translate(-50%, -50%);
  filter: none;
  -webkit-transform: translate(-50%, -50%);
}
.feni-map-html-dot--presence {
  width: 9px;
  height: 9px;
  background: #93C5FD;
  border: 1px solid rgba(255,255,255,.95);
  pointer-events: none;
}
.feni-map-html-dot--inset {
  width: 9px;
  height: 9px;
}
.feni-map-html-dot--association {
  width: 15px;
  height: 15px;
  padding: 0;
  border: 1.5px solid rgba(255,255,255,.98);
  background: #2563EB;
  box-shadow: 0 1px 4px rgba(15,23,42,.18);
  cursor: pointer;
  pointer-events: auto;
  appearance: none;
  -webkit-appearance: none;
}
.feni-map-html-dot--regional {
  width: 16px;
  height: 16px;
}
.feni-map-html-dot--association.active {
  background: #1E40AF;
}

/* SVG dots remain only as geometry/data anchors. Visible dots are HTML. */
.feni-map-svg .map-dot,
.feni-map-svg .map-pin,
.feni-map-svg .map-presence-dot,
.feni-map-svg .map-pin-hit,
.feni-map-svg .map-pin-active-ring {
  opacity: 0 !important;
  pointer-events: none !important;
}

/* Mobile: enlarge HTML dots for tappability and visibility on small screens */
@media (max-width: 768px) {
  .feni-map-html-dot--presence {
    width: 8.25px;
    height: 8.25px;
  }
  .feni-map-html-dot--inset {
    width: 8.25px;
    height: 8.25px;
  }
  .feni-map-html-dot--association {
    width: 18px;
    height: 18px;
    border-width: 1.75px;
  }
  .feni-map-html-dot--regional {
    width: 20px;
    height: 20px;
  }
}

/* ── Popup card (desktop contextual popover) ── */
@keyframes feniPopIn {
  from { opacity: 0; transform: translateY(8px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.feni-map-popup {
  display: none; position: absolute; z-index: 60;
  width: 92%; max-width: 340px;
  background: white; border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,.16), 0 2px 8px rgba(0,0,0,.06);
  padding: 24px 22px; animation: feniPopIn .2s ease-out;
  pointer-events: auto;
}
.feni-map-popup.open { display: block; }

.feni-map-popup-close {
  position: absolute; top: 10px; right: 10px;
  width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid #E2E8F0; background: white;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: #94A3B8; transition: background .15s, color .15s;
}
.feni-map-popup-close:hover { background: #F1F5F9; color: #475569; }
.feni-map-popup-close:focus-visible { outline: 2px solid #2563EB; outline-offset: 2px; }

.feni-map-popup-region {
  display: inline-block; font-size: 11px; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  color: #2563EB; background: rgba(37,99,235,.06);
  padding: 3px 10px; border-radius: 6px; margin-bottom: 10px;
}
.feni-map-popup-name {
  font-size: 18px; font-weight: 700; color: #0F172A;
  margin-bottom: 4px; line-height: 1.3;
}
.feni-map-popup-full {
  font-size: 12px; color: #64748B; margin-bottom: 10px;
}
.feni-map-popup-desc {
  font-size: 13px; line-height: 1.6; color: #64748B; margin-bottom: 18px;
}
.feni-map-popup-link {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 700; color: white;
  background: #2563EB; padding: 10px 20px; border-radius: 10px;
  text-decoration: none; transition: background .15s;
  width: 100%; justify-content: center;
}
.feni-map-popup-link:hover { background: #1D4ED8; }

/* ── Overlay backdrop ── */
.feni-map-overlay {
  display: none; position: absolute; inset: 0; z-index: 55;
  background: rgba(255,255,255,.82); backdrop-filter: blur(3px);
  border-radius: inherit;
}
.feni-map-overlay.open { display: block; }

/* ── Map wrapper for layout ── */
.feni-map-wrap {
  background: white; border: 1px solid var(--border, #E2E8F0);
  border-radius: 20px; padding: 32px; position: relative;
  box-shadow: 0 4px 24px rgba(0,0,0,.06);
  overflow: hidden;
}
.feni-map-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px; flex-wrap: wrap; gap: 8px;
}
.feni-map-header h4 { font-size: 15px; font-weight: 700; margin: 0; }
.feni-map-hint {
  text-align: center; font-size: 12px; color: #94A3B8; margin-top: 12px;
}
.feni-map-legend {
  display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px;
}
.feni-map-legend-item {
  font-size: 11px; color: #64748B; display: flex; align-items: center; gap: 6px;
}
.feni-map-legend-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #2563EB; flex-shrink: 0;
}

/* ── Full-page map mode (mapa-asociados) ── */
.feni-map-full { max-width: 700px; margin: 0 auto; }
.feni-map-full .feni-map-wrap { padding: 24px; }

/* ── Popover connector caret (desktop only) ── */
.feni-map-popup::before {
  content: ''; position: absolute;
  width: 14px; height: 14px; background: white;
  border-radius: 2px; transform: rotate(45deg);
  box-shadow: -2px -2px 4px rgba(0,0,0,.04);
  z-index: -1;
}
.feni-map-popup.anchor-left::before  { left: -6px;  top: 24px; }
.feni-map-popup.anchor-right::before { right: -6px; top: 24px; }
.feni-map-popup.anchor-above::before { bottom: -6px; left: 50%; margin-left: -7px; box-shadow: 2px 2px 4px rgba(0,0,0,.04); }
.feni-map-popup.anchor-below::before { top: -6px;    left: 50%; margin-left: -7px; }

/* Hide drag handle by default (mobile media query overrides below) */
.feni-map-popup-drag { display: none; }


/* ═══════════════════════════════════════════════════
   MOBILE BOTTOM SHEET — replaces centered popup
   ═══════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .feni-map-wrap { padding: 20px 16px; border-radius: 16px; }
  .feni-map-full .feni-map-wrap { padding: 16px 12px; }

  /* iOS/Chrome is more reliable when dots are painted without an SVG filter
     compositing layer or CSS-only SVG geometry. JS also writes attributes. */
  .feni-map-svg,
  .feni-map-svg.map-mobile-safe {
    filter: none !important;
  }
  .feni-map-svg #fmDots {
    display: block;
    opacity: 1;
  }
  .feni-map-svg .map-dot,
  .feni-map-svg .map-pin,
  .feni-map-svg .map-presence-dot {
    visibility: visible !important;
    opacity: 0 !important;
    filter: none !important;
    transform: none !important;
    vector-effect: non-scaling-stroke;
    shape-rendering: geometricPrecision;
    pointer-events: none !important;
  }
  .feni-map-svg .map-pin-hit,
  .feni-map-svg .map-pin-active-ring {
    opacity: 0 !important;
    pointer-events: none !important;
  }
  .feni-map-svg .map-pin,
  .feni-map-svg .map-dot--association {
    r: var(--map-dot-association-r);
    fill: #2563EB !important;
    stroke: rgba(255,255,255,.98) !important;
    stroke-width: 1.15 !important;
  }
  .feni-map-svg .map-pin.cyl-hub,
  .feni-map-svg .map-dot--regional {
    r: var(--map-dot-regional-r);
    fill: #2563EB !important;
  }
  .feni-map-svg .map-presence-dot,
  .feni-map-svg .map-dot--presence {
    r: var(--map-dot-presence-r);
    fill: #93C5FD !important;
    stroke: rgba(255,255,255,.9) !important;
    stroke-width: .75 !important;
    opacity: 0 !important;
  }
  .feni-map-svg .map-dot--inset {
    r: var(--map-dot-presence-inset-r);
    stroke-width: .85 !important;
  }

  /* Keep map visible — no blurry overlay on mobile */
  .feni-map-overlay {
    background: rgba(0,0,0,.12);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  /* ── Bottom sheet popup ── */
  .feni-map-popup {
    position: fixed !important;
    left: 0 !important; right: 0 !important;
    bottom: 0 !important; top: auto !important;
    width: 100% !important; max-width: 100% !important;
    border-radius: 20px 20px 0 0;
    padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -8px 40px rgba(0,0,0,.18), 0 -2px 12px rgba(0,0,0,.08);
    transform: none;
    animation: feniSheetUp .28s cubic-bezier(.32,.72,.32,1);
    z-index: 1000;
    max-height: 55vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .feni-map-popup::before { display: none; }

  @keyframes feniSheetUp {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
  }

  .feni-map-popup.closing {
    animation: feniSheetDown .22s cubic-bezier(.32,.72,.32,1) forwards;
  }
  @keyframes feniSheetDown {
    from { transform: translateY(0); opacity: 1; }
    to   { transform: translateY(100%); opacity: 0; }
  }

  /* Drag handle */
  .feni-map-popup-drag {
    display: block;
    width: 36px; height: 4px;
    background: #D1D5DB; border-radius: 2px;
    margin: 0 auto 16px;
    flex-shrink: 0;
  }

  /* Close button — larger on mobile */
  .feni-map-popup-close {
    width: 36px; height: 36px;
    top: 12px; right: 12px;
    font-size: 18px;
  }

  /* Card content adjustments */
  .feni-map-popup-region { font-size: 10px; padding: 3px 8px; margin-bottom: 8px; }
  .feni-map-popup-name { font-size: 17px; margin-bottom: 4px; padding-right: 40px; }
  .feni-map-popup-full { font-size: 12px; margin-bottom: 8px; }
  .feni-map-popup-desc { font-size: 13px; margin-bottom: 16px; }
  .feni-map-popup-link { padding: 12px 20px; font-size: 14px; border-radius: 12px; }

  /* Overlay: fixed on mobile to match fixed popup */
  .feni-map-overlay.open {
    position: fixed;
    inset: 0;
    z-index: 999;
    border-radius: 0;
  }

  /* Map hint adjustments */
  .feni-map-hint { font-size: 11px; margin-top: 8px; }

  /* Header adjustments */
  .feni-map-header h4 { font-size: 14px; }
}

/* ── Responsive grid stacking for homepage map section ── */
@media (max-width: 900px) {
  .about-map-grid {
    grid-template-columns: 1fr !important;
    gap: 32px !important;
  }
}
