/* ==========================================================================
   Arcanum Geosciences: Africa operational footprint map
   Lightweight SVG component. No framework dependencies.

   Colour tokens: each --afmap-* token reads the site's design token from
   css/style.css (left-hand var) and falls back to the component's original
   navy / orange palette if that token is ever missing.
   ========================================================================== */

.afmap {
  --afmap-accent:        var(--c-copper-500, #e8772e);    /* operational countries */
  --afmap-accent-strong: var(--c-copper-600, #f5903f);
  --afmap-ink:           var(--c-navy-950, #13243a);      /* labels, headings */
  --afmap-land:          var(--c-stone-200, #c9d2dc);/* non-operational countries */
  --afmap-border:        var(--c-white, #ffffff);   /* country borders */
  --afmap-muted:         var(--c-text-muted, #52627a);
  --afmap-rule:          var(--c-border, #d9e0e8);

  display: grid;
  grid-template-columns: minmax(0, 2.4fr) minmax(13rem, 1fr);
  gap: clamp(1.5rem, 4vw, 3.5rem);
  align-items: center;
  margin-block-start: clamp(1.5rem, 3vw, 2.5rem);
  font-family: inherit;
  color: var(--afmap-ink);
}

/* Dark section variant: class="afmap afmap--on-dark" */
.afmap--on-dark {
  --afmap-ink:    var(--c-stone-100, #eef2f7);
  --afmap-land:   var(--c-navy-700, #2a3f58);
  --afmap-border: var(--c-navy-950, #0f1d2e);
  --afmap-muted:  var(--c-stone-300, #a9b6c7);
  --afmap-rule:   rgba(255, 255, 255, 0.14);
}

/* ---------- map ---------- */
.afmap__figure {
  position: relative;
  margin: 0;
  container-type: inline-size;
  container-name: afmap;
}

.afmap__svg {
  display: block;
  width: 100%;
  height: auto;          /* viewBox keeps the continent in proportion */
  overflow: visible;
}

.afmap__country {
  fill: var(--afmap-land);
  stroke: var(--afmap-border);
  stroke-width: 1.1;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.afmap__country--op {
  fill: var(--afmap-accent);
  cursor: pointer;
  transition: fill 160ms ease, fill-opacity 160ms ease;
}

.afmap__country--op:hover,
.afmap__country--op.is-active { fill: var(--afmap-accent-strong); }

/* While one country is active, the other operational ones recede slightly */
.afmap.has-active .afmap__country--op:not(.is-active) { fill-opacity: 0.82; }

/* ---------- labels (SVG units, scale with the map) ---------- */
.afmap__label {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.01em;
  fill: var(--afmap-ink);
  paint-order: stroke;
  stroke: var(--afmap-accent);
  stroke-width: 3px;
  stroke-linejoin: round;
  pointer-events: none;
  transition: opacity 160ms ease;
}
.afmap--on-dark .afmap__label:not(.afmap__label--out) { fill: var(--afmap-on-accent, #13243a); }
.afmap__label--out {            /* labels placed over sea or neutral land */
  stroke: var(--afmap-border);
  stroke-width: 4px;
}
.afmap__leader {
  stroke: var(--afmap-ink);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  opacity: 0.6;
}
.afmap__dot { fill: var(--afmap-ink); }

.afmap.has-active .afmap__label:not(.is-active),
.afmap.has-active .afmap__leader:not(.is-active),
.afmap.has-active .afmap__dot:not(.is-active) { opacity: 0.6; }

/* Small maps: labels become unreadable, so the legend list takes over */
@container afmap (max-width: 520px) {
  .afmap__labels { display: none; }
}

/* ---------- tooltip ---------- */
.afmap__tooltip {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  padding: 0.35rem 0.65rem;
  border-radius: 4px;
  background: var(--afmap-ink);
  color: var(--afmap-border);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 10px));
  opacity: 0;
  transition: opacity 120ms ease;
}
.afmap--on-dark .afmap__tooltip { background: #ffffff; color: #13243a; }
.afmap__tooltip.is-visible { opacity: 1; }

/* ---------- legend (compact key; the map is the primary element) ---------- */
.afmap__legend { min-width: 0; align-self: end; padding-block-end: 4%; }

.afmap__key {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  margin: 0 0 0.9rem;
  font-size: 0.8125rem;
  color: var(--afmap-muted);
}
.afmap__key-item { display: inline-flex; align-items: center; gap: 0.45rem; }
.afmap__swatch {
  flex: none;
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 2px;
  background: var(--afmap-accent);
}
.afmap__swatch--land { background: var(--afmap-land); box-shadow: inset 0 0 0 1px var(--afmap-rule); }

.afmap__list {
  list-style: none;
  margin: 0;
  padding: 0.9rem 0 0;
  border-top: 1px solid var(--afmap-rule);
  display: flex;
  flex-wrap: wrap;
  gap: 0 1rem;
}

.afmap__item {
  all: unset;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2rem;            /* ≥ 24px target (WCAG 2.5.8) */
  font-size: 0.875rem;
  line-height: 1.2;
  color: var(--afmap-ink);
  cursor: pointer;
}
.afmap__item::before {
  content: "";
  flex: none;
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--afmap-accent);
  transition: transform 160ms ease;
}
.afmap__item:hover { color: var(--afmap-accent-strong); }
.afmap__item:hover::before,
.afmap__item.is-active::before { transform: scale(1.6); }
.afmap__item.is-active { font-weight: 600; }
.afmap__item:focus-visible {
  outline: 2px solid var(--afmap-accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .afmap { grid-template-columns: 1fr; gap: 1.25rem; }
  .afmap__figure { width: 100%; max-width: 640px; margin-inline: auto; }
  .afmap__legend { width: 100%; max-width: 640px; margin-inline: auto; padding: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .afmap__country--op, .afmap__label, .afmap__tooltip, .afmap__item::before { transition: none; }
  .afmap__item.is-active::before, .afmap__item:hover::before { transform: none; }
}

@media (forced-colors: active) {
  .afmap__country { fill: Canvas; stroke: CanvasText; }
  .afmap__country--op { fill: Highlight; }
  .afmap__label { fill: CanvasText; stroke: none; }
}

/* Screen-reader-only helper, scoped to the component */
.afmap__sr {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}
