/* ═══════════════════════════════════════════════════════════════════════════
   Edad Digital — Mapa Interactivo de Cursos
   Cádiz · CSS puro · Sin framework
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --ed-bg:          #f4f6f9;
  --ed-surface:     #ffffff;
  --ed-border:      #dde3ec;
  --ed-text:        #1a2332;
  --ed-text-light:  #5a6a7e;
  --ed-primary:     #1b4f8a;
  --ed-primary-h:   #1560ab;

  --ed-muni-fill:       #c8d8f0;
  --ed-muni-stroke:     #ffffff;
  --ed-muni-hover:      #3a7bd5;
  --ed-muni-focus:      #1b4f8a;

  --ed-low:   #d0e8f7;
  --ed-mid:   #5ba3e0;
  --ed-high:  #1b4f8a;
  --ed-elas:  #f4a72e;

  --ed-tooltip-bg:      rgba(15, 25, 50, 0.95);
  --ed-tooltip-radius:  8px;

  --ed-transition: 220ms ease;
  --ed-zoom-dur:   400ms cubic-bezier(0.4, 0, 0.2, 1);

  --ed-radius:  12px;
  --ed-shadow:  0 4px 24px rgba(0, 0, 0, 0.10);
}

/* ── Root container ────────────────────────────────────────────────────────── */
#ed-map {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--ed-bg);
  border-radius: var(--ed-radius);
  padding: 24px;
  max-width: 900px;
  margin: 0 auto;
  box-shadow: var(--ed-shadow);
}

/* ── Header ────────────────────────────────────────────────────────────────── */
.ed-map__header {
  text-align: center;
}

.ed-map__title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--ed-text);
  margin: 0 0 4px;
}

.ed-map__subtitle {
  font-size: 0.875rem;
  color: var(--ed-text-light);
  margin: 0;
}

/* ── Back button ───────────────────────────────────────────────────────────── */
.ed-map__back {
  display: none;
  align-self: flex-start;
  padding: 8px 16px;
  background: var(--ed-surface);
  border: 1.5px solid var(--ed-border);
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ed-primary);
  cursor: pointer;
  transition: background var(--ed-transition), border-color var(--ed-transition);
}

.ed-map__back.is-visible {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.ed-map__back:hover {
  background: var(--ed-primary);
  color: #fff;
  border-color: var(--ed-primary);
}

.ed-map__back:focus-visible {
  outline: 2px solid var(--ed-primary);
  outline-offset: 2px;
}

/* ── Viewport ──────────────────────────────────────────────────────────────── */
.ed-map__viewport {
  position: relative;
  background: var(--ed-surface);
  border: 1px solid var(--ed-border);
  border-radius: var(--ed-radius);
  overflow: hidden;
  min-height: 500px;
  display: flex;
  align-items: stretch;
}

.ed-map__loading {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ed-text-light);
  font-size: 0.9rem;
  width: 100%;
  min-height: 500px;
}

/* ── SVG ───────────────────────────────────────────────────────────────────── */
.ed-map__viewport svg {
  width: 100%;
  height: auto;
  display: block;
  transform-origin: 0 0;
  transition: transform var(--ed-zoom-dur);
  will-change: transform;
}

/* Municipality paths — base */
.ed-map__viewport path,
.ed-map__viewport rect,
.ed-map__viewport circle {
  stroke: var(--ed-muni-stroke);
  stroke-width: 1px;
  stroke-linejoin: round;
  cursor: pointer;
  transition:
    fill var(--ed-transition),
    stroke var(--ed-transition),
    filter var(--ed-transition);
  vector-effect: non-scaling-stroke;
  outline: none;
}

/* ELA group containers */
.ed-map__viewport g[data-slug] {
  cursor: pointer;
}

/* Density fills */
path.density-low,   rect.density-low,   circle.density-low   { fill: var(--ed-low); }
path.density-mid,   rect.density-mid,   circle.density-mid   { fill: var(--ed-mid); }
path.density-high,  rect.density-high,  circle.density-high  { fill: var(--ed-high); }

/* ELAs accent stroke */
path.has-elas { stroke: var(--ed-elas); stroke-width: 2px; }

/* ELA type paths */
path.is-ela, rect.is-ela, circle.is-ela {
  fill: var(--ed-low);
  stroke: var(--ed-primary);
  stroke-width: 1.5px;
}

/* Hover state */
path.is-hovered,
rect.is-hovered,
circle.is-hovered,
g.is-hovered circle {
  fill: var(--ed-muni-hover) !important;
  stroke: var(--ed-primary) !important;
  stroke-width: 2px;
  filter: drop-shadow(0 2px 8px rgba(27, 79, 138, 0.3));
}

/* Focus-visible (keyboard) */
path:focus-visible,
rect:focus-visible,
circle:focus-visible,
g[role="button"]:focus-visible circle {
  outline: 3px solid var(--ed-primary);
  outline-offset: 2px;
  fill: var(--ed-muni-focus) !important;
}

/* Schematic ELA map labels */
.ed-schematic text {
  fill: var(--ed-text);
  font-family: inherit;
  pointer-events: none;
}

.ed-schematic .ela-label {
  font-size: 13px;
  font-weight: 600;
}

.ed-schematic .ela-count {
  font-size: 11px;
  fill: var(--ed-text-light);
}

/* ── Tooltip ───────────────────────────────────────────────────────────────── */
.ed-tooltip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 9999;
  pointer-events: none;
  background: var(--ed-tooltip-bg);
  color: #fff;
  border-radius: var(--ed-tooltip-radius);
  padding: 10px 14px;
  min-width: 180px;
  max-width: 240px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transform: translate(-9999px, -9999px);
  transition: opacity 150ms ease;
  will-change: transform, opacity;
}

.ed-tooltip.is-visible {
  opacity: 1;
}

.ed-tooltip__header {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 6px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
  padding-bottom: 6px;
}

.ed-tooltip__body {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ed-tooltip__stat {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.85);
}

.ed-tooltip__elas {
  font-size: 0.78rem;
  color: var(--ed-elas);
  font-weight: 600;
  margin-top: 4px;
}

/* ── Legend ────────────────────────────────────────────────────────────────── */
.ed-map__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  justify-content: center;
}

.ed-map__legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--ed-text-light);
}

.ed-map__legend-item::before {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.1);
}

.ed-map__legend-item--low::before  { background: var(--ed-low); }
.ed-map__legend-item--mid::before  { background: var(--ed-mid); }
.ed-map__legend-item--high::before { background: var(--ed-high); }
.ed-map__legend-item--elas::before { background: var(--ed-elas); }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  #ed-map {
    padding: 14px;
    border-radius: 8px;
  }

  .ed-map__title {
    font-size: 1.1rem;
  }

  .ed-map__viewport {
    min-height: 350px;
  }

  .ed-tooltip {
    min-width: 150px;
    font-size: 0.8rem;
  }
}

/* Touch devices: disable hover effects that don't translate to tap */
@media (hover: none) {
  path.is-hovered,
  rect.is-hovered {
    filter: none;
  }
}

/* High contrast mode */
@media (forced-colors: active) {
  path, rect { stroke: ButtonText; }
  path.is-hovered, rect.is-hovered { fill: Highlight !important; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  :root {
    --ed-transition: 0ms;
    --ed-zoom-dur:   0ms;
  }
  .ed-tooltip { transition: none; }
}
