/**
 * The news map.
 *
 * Every colour and size reads a theme token with a hardcoded fallback. The
 * fallbacks are what make this module survive a theme swap: with arabi-intel
 * active the map is in brand, and with Jannah alone - or any future theme - it
 * still renders legibly instead of collapsing into unstyled Leaflet.
 */

/* -------------------------------------------------------------------
 *  Block
 * ------------------------------------------------------------------- */
.mea-map-block {
  /* Shared kind colours: pins, swatches, chips, and list dots all read these. */
  --mea-kind-news: #005cff;
  --mea-kind-monitoring: #0b6e6a;
  --mea-kind-report: #886329;
  --mea-kind-investigation: #c0272a;
  --mea-kind-article: #0b6e4f;
  --mea-kind-video: #5b2d8e;
  margin: var(--ai-space-6, 2rem) 0;
  position: relative;
  /* Contain the block's own stack. The filters sit at z-index 1000 and the
   * Leaflet panes at 400+; without a stacking context here they escape and
   * paint over the sticky header's flyout menus (the header is z-index 999).
   * Isolating keeps every inner layer below the header where it belongs. */
  isolation: isolate;
}

/* Flag pills (عاجل / حصري) — shared by popup, atlas cards, and the fallback list. */
.mea-flag {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.05em 0.45em;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: var(--ai-fw-semibold, 600);
  line-height: 1.45;
  white-space: nowrap;
}

.mea-flag--breaking {
  background: color-mix(in srgb, var(--ai-urgent, #c0272a) 14%, transparent);
  color: var(--ai-urgent, #c0272a);
}

.mea-flag--exclusive {
  background: color-mix(in srgb, var(--ai-gold, #886329) 16%, transparent);
  color: var(--ai-gold, #886329);
}

.mea-kind-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.05em 0.5em;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: var(--ai-fw-semibold, 600);
  line-height: 1.45;
  color: #fff;
  background: var(--mea-kind-news, #005cff);
}

.mea-kind-chip--news { background: var(--mea-kind-news, #005cff); }
.mea-kind-chip--monitoring { background: var(--mea-kind-monitoring, #0b6e6a); }
.mea-kind-chip--report { background: var(--mea-kind-report, #886329); }
.mea-kind-chip--investigation { background: var(--mea-kind-investigation, #c0272a); }
.mea-kind-chip--article { background: var(--mea-kind-article, #0b6e4f); }
.mea-kind-chip--video { background: var(--mea-kind-video, #5b2d8e); }

.mea-map-block__title {
  font-family: var(--ai-font, sans-serif);
  font-size: var(--ai-fs-2xl, 1.625rem);
  font-weight: var(--ai-fw-bold, 700);
  line-height: var(--ai-lh-heading, 1.4);
  color: var(--ai-text, #0d0e18);
  margin: 0 0 var(--ai-space-4, 1rem);
}

.mea-map-block__canvas {
  height: var(--mea-map-height, 520px);
  min-height: 240px;
  background: var(--ai-bg-sunken, #f0f0ee);
  border: 1px solid var(--ai-border, #e2e3eb);
  border-radius: var(--ai-radius, 2px);
  /* Clip popups to the map frame. Leaflet panes sit at z-index 400+; the
   * stacking context also stops a map from punching through a sticky header. */
  overflow: hidden;
  isolation: isolate;
}

.mea-map-block__noscript {
  padding: var(--ai-space-4, 1rem);
  font-family: var(--ai-font, sans-serif);
  font-size: var(--ai-fs-sm, 0.9375rem);
  color: var(--ai-text-body, #484a5e);
}

.mea-map-block.is-loading .mea-map-block__canvas {
  opacity: 0.65;
  transition: opacity var(--ai-transition, 0.25s ease);
}

.mea-map-block.has-error .mea-map-block__canvas {
  border-color: var(--ai-urgent, #c0272a);
}

.mea-map-block__count,
.mea-map-block__empty {
  font-family: var(--ai-font, sans-serif);
  font-size: var(--ai-fs-xs, 0.875rem);
  color: var(--ai-text-muted, #68697a);
  margin: var(--ai-space-2, 0.5rem) 0 0;
}

/* Fullscreen: the browser paints the backdrop black by default, which looks
 * like a video player rather than a newsroom tool. */
.mea-map-block.is-fullscreen {
  background: var(--ai-bg, #fff);
  padding: var(--ai-space-4, 1rem);
  overflow-y: auto;
}

.mea-map-block.is-fullscreen .mea-map-block__canvas {
  height: calc(100vh - 11rem);
}

/* -------------------------------------------------------------------
 *  Filters
 * ------------------------------------------------------------------- */
.mea-map-block__filters {
  position: relative;
  z-index: 1000;
  display: flex;
  flex-wrap: wrap;
  gap: var(--ai-space-3, 0.75rem);
  align-items: flex-end;
  margin-bottom: var(--ai-space-3, 0.75rem);
  padding: var(--ai-space-3, 0.75rem);
  background: var(--ai-bg-raised, #f8f8f6);
  border: 1px solid var(--ai-border-soft, #edeef4);
  border-radius: var(--ai-radius, 2px);
}

/* -------------------------------------------------------------------
 *  Collapsible filter shell
 *
 *  The filter grid is tall and leads the page before the map itself. Tuck it
 *  behind a small "تصفية" button - the same move the section archives make - so
 *  the map leads and the controls stay one click away. Native <details> keeps
 *  it keyboard-accessible and working with no JavaScript; it opens on its own
 *  when a filter is already applied so the reader sees the active scope.
 * ------------------------------------------------------------------- */
.mea-map-block__filter-bar {
  position: relative;
  z-index: 1000;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--ai-space-3, 0.75rem);
  margin-bottom: var(--ai-space-3, 0.75rem);
}

.mea-map-block__filter-shell {
  flex: 0 0 auto;
}

.mea-map-block__filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2.25rem;
  padding: 0 0.85rem;
  border: 1px solid var(--ai-border, #e2e3eb);
  border-radius: var(--ai-radius, 2px);
  background: var(--ai-bg, #fff);
  color: var(--ai-text, #0d0e18);
  font-family: var(--ai-font, sans-serif);
  font-size: var(--ai-fs-sm, 0.9375rem);
  font-weight: var(--ai-fw-bold, 700);
  line-height: 1;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.mea-map-block__filter-toggle::-webkit-details-marker {
  display: none;
}

.mea-map-block__filter-toggle-text {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.mea-map-block__filter-toggle-text::after {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  border-inline-end: 1.5px solid currentColor;
  border-block-end: 1.5px solid currentColor;
  transform: translateY(-15%) rotate(45deg);
  transition: transform 160ms ease;
}

.mea-map-block__filter-shell[open] .mea-map-block__filter-toggle {
  border-color: var(--ai-brand, #005cff);
  color: var(--ai-brand, #005cff);
}

.mea-map-block__filter-shell[open] .mea-map-block__filter-toggle-text::after {
  transform: translateY(15%) rotate(-135deg);
}

/* Clear link sits beside the toggle in the bar (not inside the <summary>, where
 * the summary would swallow the click). It stays visible while the panel is
 * collapsed and resets every map_* parameter by pointing at the bare page URL.
 * Secondary weight so it reads as the quieter of the two actions. */
.mea-map-block__filter-clear {
  display: inline-flex;
  align-items: center;
  font-family: var(--ai-font, sans-serif);
  font-size: var(--ai-fs-sm, 0.9375rem);
  color: var(--ai-text-muted, #5c6478);
  font-weight: var(--ai-fw-normal, 400);
  text-decoration: none;
}

.mea-map-block__filter-clear:hover,
.mea-map-block__filter-clear:focus-visible {
  color: var(--ai-urgent, #c0272a);
  text-decoration: underline;
}

/* The clear link and the count badge are always in the DOM so map.js can show
 * them the moment a filter is applied interactively; [hidden] must win over the
 * element's own display rule. */
.mea-map-block__filter-clear[hidden],
.mea-map-block__filter-count[hidden] {
  display: none;
}

/* When the panel is open an inline clear (next to تطبيق) takes over, so the
 * bar clear beside the toggle would be redundant — hide it. */
.mea-map-block__filter-shell[open] + .mea-map-block__filter-clear:not([hidden]) {
  display: none;
}

/* تطبيق and مسح التصفية sit together at the end of the open filter panel. */
.mea-map-block__actions {
  display: inline-flex;
  align-items: center;
  gap: var(--ai-space-3, 0.75rem);
}

.mea-map-block__filter-toggle:focus-visible {
  outline: 2px solid transparent;
  box-shadow: var(--ai-focus-ring, 0 0 0 2px #fff, 0 0 0 4px #005cff);
}

.mea-map-block__filter-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.3em;
  padding: 0 0.3em;
  border-radius: 999px;
  background: var(--ai-brand, #005cff);
  color: #fff;
  font-size: 0.72rem;
  line-height: 1.4;
}

/* The form is a sibling of the toggle bar, shown only while the <details> is
 * open. :has() lets native <details> drive it with no JavaScript. It is gated on
 * @supports so a browser without :has() keeps the form visible (the toggle just
 * becomes decorative) instead of hiding the filters with no way to reach them. */
@supports selector(:has(*)) {
  .mea-map-block__filters {
    display: none;
  }

  .mea-map-block:has(.mea-map-block__filter-shell[open]) .mea-map-block__filters {
    display: flex;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mea-map-block__filter-toggle-text::after {
    transition: none;
  }
}

.mea-map-block__filter {
  display: flex;
  flex-direction: column;
  gap: var(--ai-space-1, 0.25rem);
  font-family: var(--ai-font, sans-serif);
  font-size: var(--ai-fs-xs, 0.875rem);
  color: var(--ai-text-body, #484a5e);
}

.mea-map-pick {
  position: relative;
  min-width: 11rem;
}

.mea-map-pick__label {
  display: block;
}

.mea-map-pick__trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  min-height: 2.75rem;
  padding: 0 var(--ai-space-2, 0.5rem);
  font-family: inherit;
  font-size: var(--ai-fs-sm, 0.9375rem);
  color: var(--ai-text, #0d0e18);
  text-align: start;
  background: var(--ai-bg, #fff);
  border: 1px solid var(--ai-border, #e2e3eb);
  border-radius: var(--ai-radius, 2px);
  cursor: pointer;
}

.mea-map-pick__trigger::after {
  content: '';
  width: 0.45rem;
  height: 0.45rem;
  border-inline-end: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  opacity: 0.55;
  flex-shrink: 0;
}

.mea-map-pick.is-open .mea-map-pick__trigger::after {
  transform: rotate(-135deg);
  margin-top: 0.25rem;
}

.mea-map-pick__panel {
  position: absolute;
  z-index: 2;
  inset-inline-start: 0;
  top: calc(100% + 0.2rem);
  width: min(18rem, 85vw);
  max-height: 18rem;
  display: flex;
  flex-direction: column;
  background: var(--ai-bg, #fff);
  border: 1px solid var(--ai-border, #e2e3eb);
  border-radius: var(--ai-radius, 2px);
  box-shadow: 0 8px 24px rgba(13, 14, 24, 0.12);
}

.mea-map-pick__panel[hidden] {
  display: none;
}

.mea-map-pick__search {
  flex: 0 0 auto;
  width: 100%;
  min-height: 2.5rem;
  margin: 0;
  padding: 0 0.75rem;
  font: inherit;
  border: 0;
  border-bottom: 1px solid var(--ai-border-soft, #edeef4);
  border-radius: 0;
  background: transparent;
}

.mea-map-pick__options {
  overflow: auto;
  max-height: 14rem;
  padding: 0.25rem 0;
}

.mea-map-pick__group {
  padding: 0.45rem 0.75rem 0.2rem;
  font-size: var(--ai-fs-xs, 0.875rem);
  font-weight: var(--ai-fw-semibold, 600);
  color: var(--ai-text-muted, #646970);
}

.mea-map-block__filters .mea-map-pick__option {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  box-sizing: border-box;
  min-height: 2.75rem;
  margin: 0;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  pointer-events: auto;
  user-select: none;
}

.mea-map-pick__option[hidden] {
  display: none;
}

.mea-map-pick__option:hover,
.mea-map-pick__option:focus-within {
  background: var(--ai-bg-sunken, #f4f5f8);
}

.mea-map-block__filters .mea-map-pick__option span,
.mea-map-block__filters .mea-map-pick__option input {
  pointer-events: none;
}

.mea-map-block__filters .mea-map-pick__option span {
  flex: 1 1 auto;
}

.mea-map-block__filters .mea-map-pick__option input {
  width: 1rem;
  height: 1rem;
  min-width: 1rem;
  min-height: 1rem;
  margin: 0;
  padding: 0;
  flex: 0 0 1rem;
}

.mea-map-pick__option:focus-visible {
  outline: 2px solid var(--ai-brand, #005cff);
  outline-offset: -2px;
}

.mea-map-pick__native {
  display: block;
  min-width: 11rem;
  min-height: 2.75rem;
}

.mea-map-pick__trigger,
.mea-map-pick__panel {
  display: none;
}

.mea-map-block.is-ready .mea-map-pick__trigger {
  display: flex;
}

.mea-map-block.is-ready .mea-map-pick.is-open .mea-map-pick__panel {
  display: flex;
}

.mea-map-block.is-ready .mea-map-pick__native {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  border: 0;
}

.mea-map-suggest {
  position: relative;
}

.mea-map-suggest__input,
.mea-map-suggest__list {
  display: none;
}

.mea-map-block.is-ready .mea-map-suggest__native {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  border: 0;
}

.mea-map-block.is-ready .mea-map-suggest__input {
  display: block;
  width: 16rem;
  max-width: 100%;
}

.mea-map-block.is-ready .mea-map-suggest__list:not([hidden]) {
  display: block;
  position: absolute;
  z-index: 6;
  inset-inline-start: 0;
  top: calc(100% - 0.15rem);
  width: 16rem;
  max-width: 70vw;
  max-height: 16rem;
  margin: 0;
  padding: 0.25rem 0;
  overflow: auto;
  list-style: none;
  background: var(--ai-bg, #fff);
  border: 1px solid var(--ai-border, #e2e3eb);
  border-radius: var(--ai-radius, 2px);
  box-shadow: 0 8px 24px rgba(13, 14, 24, 0.12);
}

.mea-map-suggest__option {
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  min-height: 2.75rem;
}

.mea-map-suggest__option[aria-selected='true'],
.mea-map-suggest__option:hover {
  background: var(--ai-bg-sunken, #f4f5f8);
}

.mea-map-suggest__empty {
  padding: 0.6rem 0.75rem;
  color: var(--ai-text-muted, #646970);
}

.mea-map-block__dates {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ai-space-3, 0.75rem);
}

.mea-map-block__dates .mea-map-block__filter {
  flex: 1 1 18rem;
}

.mea-map-block__dates[hidden] {
  display: none;
}

.mea-map-block__filter select,
.mea-map-block__filter input {
  font-family: inherit;
  font-size: var(--ai-fs-sm, 0.9375rem);
  /* 44px hit target: these controls are used on a phone more than a desktop. */
  min-height: 2.75rem;
  padding: 0 var(--ai-space-2, 0.5rem);
  color: var(--ai-text, #0d0e18);
  background: var(--ai-bg, #fff);
  border: 1px solid var(--ai-border, #e2e3eb);
  border-radius: var(--ai-radius, 2px);
}

.mea-map-block__apply {
  font-family: var(--ai-font, sans-serif);
  font-size: var(--ai-fs-sm, 0.9375rem);
  font-weight: var(--ai-fw-semibold, 600);
  min-height: 2.75rem;
  padding: 0 var(--ai-space-4, 1rem);
  color: var(--ai-on-brand, #fff);
  background: var(--ai-brand, #005cff);
  border: 0;
  border-radius: var(--ai-radius, 2px);
  cursor: pointer;
}

.mea-map-block__apply:hover {
  background: var(--ai-brand-hover, #0049cc);
}

.mea-map-block__filter :focus-visible,
.mea-map-block__apply:focus-visible,
.mea-map-controls__btn:focus-visible,
.mea-map-timeline__range:focus-visible {
  outline: 2px solid transparent;
  box-shadow: var(--ai-focus-ring, 0 0 0 2px #fff, 0 0 0 4px #005cff);
}

/* -------------------------------------------------------------------
 *  Pins
 *
 *  Shape and fill both carry meaning, never colour alone (WCAG 1.4.1):
 *  an approximate location is a hollow dashed ring, an exact one is filled.
 *
 *  Never put transform/transition:transform on .mea-pin itself: Leaflet and
 *  MarkerCluster position icons with transform, and our animation was wiping
 *  that out — spiderfy stacked every pin on the same spot.
 * ------------------------------------------------------------------- */
.mea-pin__dot {
  display: block;
  box-sizing: border-box;
  width: 14px;
  height: 14px;
  margin: 2px;
  border-radius: 50%;
  /* Always a light ring on the map tiles — --ai-bg goes dark in night mode
   * and made pins look cropped against the daylight basemap. */
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(13, 14, 24, 0.45);
  transition: box-shadow 0.18s ease, width 0.18s ease, height 0.18s ease, margin 0.18s ease;
  animation: mea-pin-fade 0.28s ease-out both;
}

.mea-pin--news .mea-pin__dot,
.mea-swatch--news { background: var(--mea-kind-news); }

.mea-pin--monitoring .mea-pin__dot,
.mea-swatch--monitoring { background: var(--mea-kind-monitoring); }

.mea-pin--report .mea-pin__dot,
.mea-swatch--report { background: var(--mea-kind-report); }

.mea-pin--investigation .mea-pin__dot,
.mea-swatch--investigation { background: var(--mea-kind-investigation); }

.mea-pin--article .mea-pin__dot,
.mea-swatch--article { background: var(--mea-kind-article); }

.mea-pin--video .mea-pin__dot,
.mea-swatch--video { background: var(--mea-kind-video); }

.mea-pin--approx .mea-pin__dot {
  background: transparent;
  border-width: 2.5px;
  border-style: dashed;
  box-shadow: none;
}

.mea-pin--approx.mea-pin--news .mea-pin__dot { border-color: var(--mea-kind-news); }
.mea-pin--approx.mea-pin--monitoring .mea-pin__dot { border-color: var(--mea-kind-monitoring); }
.mea-pin--approx.mea-pin--report .mea-pin__dot { border-color: var(--mea-kind-report); }
.mea-pin--approx.mea-pin--investigation .mea-pin__dot { border-color: var(--mea-kind-investigation); }
.mea-pin--approx.mea-pin--article .mea-pin__dot { border-color: var(--mea-kind-article); }
.mea-pin--approx.mea-pin--video .mea-pin__dot { border-color: var(--mea-kind-video); }

/* Exclusive: thin gold halo. Breaking: soft urgent pulse. */
.mea-pin--exclusive .mea-pin__dot {
  box-shadow:
    0 1px 3px rgba(13, 14, 24, 0.45),
    0 0 0 2px color-mix(in srgb, var(--ai-gold, #886329) 70%, transparent);
}

.mea-pin--breaking .mea-pin__dot {
  animation: mea-pin-pulse 1.6s ease-out infinite;
}

/* Scale the inner dot only — never the Leaflet icon shell. */
.leaflet-marker-icon.mea-pin:hover .mea-pin__dot,
.leaflet-marker-icon.mea-pin:focus-visible .mea-pin__dot {
  width: 16px;
  height: 16px;
  margin: 1px;
  box-shadow: 0 2px 6px rgba(13, 14, 24, 0.5);
}

.leaflet-marker-icon.mea-pin:focus-visible .mea-pin__dot {
  box-shadow: 0 0 0 3px var(--ai-focus, #005cff);
}

@keyframes mea-pin-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes mea-pin-pulse {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--ai-urgent, #c0272a) 45%, transparent);
  }

  70% {
    box-shadow: 0 0 0 8px transparent;
  }

  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}

/* -------------------------------------------------------------------
 *  Clusters
 *
 *  Same rule as pins: no transform on the Leaflet icon. Keep the painted
 *  circle inside iconSize so overflow:hidden on the canvas does not crop
 *  the ring or the count.
 * ------------------------------------------------------------------- */
.mea-cluster {
  background: transparent;
  border: 0;
}

.mea-cluster span {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  font-family: var(--ai-font-num, monospace);
  font-size: var(--ai-fs-xs, 0.875rem);
  font-weight: var(--ai-fw-bold, 700);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: #fff;
  /* Fixed white ring: dark-mode --ai-bg made clusters look amputated on the map. */
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(13, 14, 24, 0.35);
  transition: box-shadow 0.18s ease, filter 0.18s ease;
}

.mea-cluster:hover span {
  box-shadow: 0 2px 8px rgba(13, 14, 24, 0.45);
  filter: brightness(1.06);
}

.mea-cluster--sm {
  width: 30px;
  height: 30px;
  font-size: var(--ai-fs-2xs, 0.8125rem);
}

.mea-cluster--md {
  width: 38px;
  height: 38px;
}

.mea-cluster--lg {
  width: 46px;
  height: 46px;
}

.mea-map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  margin: 0.75rem 0 0;
  padding: 0;
  list-style: none;
}

.mea-map-legend li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.mea-swatch {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
}

.mea-country h3,
.mea-country ul,
.mea-country p {
  margin: 0;
}

.mea-country ul {
  padding: 0;
}

.mea-country {
  padding: 0.4rem 0.5rem 0.35rem;
  direction: inherit;
  text-align: start;
}

html[dir='rtl'] .mea-country,
html[dir='rtl'] .mea-popup {
  /* Leave room for the close button, which sits on the left in RTL. */
  padding-inline-end: 1.15rem;
}

.mea-country__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.4rem;
  margin: 0 0 0.3rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--ai-border-soft, #edeef4);
}

.mea-country__name {
  margin: 0;
  font-size: 0.875rem;
  font-weight: var(--ai-fw-bold, 700);
  line-height: 1.25;
  color: var(--ai-text, #0d0e18);
}

.mea-country__count {
  margin: 0;
  flex-shrink: 0;
  font-size: 0.6875rem;
  font-variant-numeric: tabular-nums;
  color: var(--ai-text-muted, #68697a);
}

.mea-country__empty {
  margin: 0 0 0.25rem;
  font-size: 0.75rem;
  color: var(--ai-text-body, #484a5e);
}

.mea-country__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.mea-country__item {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0.28rem 0;
  border-bottom: 1px solid var(--ai-border-soft, #edeef4);
}

.mea-country__item:last-child {
  border-bottom: 0;
}

.mea-country__kind {
  font-size: 0.6875rem;
  font-weight: var(--ai-fw-semibold, 600);
  line-height: 1.2;
  color: var(--ai-brand-text, #005cff);
}

.mea-country__link {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: 0.75rem;
  font-weight: var(--ai-fw-semibold, 600);
  line-height: 1.3;
  color: var(--ai-text, #0d0e18);
  text-decoration: none;
}

.mea-country__link:hover {
  color: var(--ai-brand-text, #005cff);
  text-decoration: underline;
}

.mea-country__date {
  font-size: 0.6875rem;
  line-height: 1.2;
  color: var(--ai-text-muted, #68697a);
}

.mea-country__foot {
  margin: 0.25rem 0 0;
  padding-top: 0.25rem;
  border-top: 1px solid var(--ai-border-soft, #edeef4);
}

.mea-country__page {
  font-size: 0.75rem;
  font-weight: var(--ai-fw-semibold, 600);
  color: var(--ai-brand-text, #005cff);
  text-decoration: none;
}

.mea-country__page:hover {
  text-decoration: underline;
}

.mea-country__loading {
  margin: 0;
  padding: var(--ai-space-3, 0.75rem);
  font-size: var(--ai-fs-sm, 0.9375rem);
  color: var(--ai-text-body, #484a5e);
}

/* -------------------------------------------------------------------
 *  Controls
 *
 *  Sit on daylight map tiles. Keep a fixed light face and dark icons —
 *  theme tokens like --ai-bg go dark at night and wash the strokes out.
 * ------------------------------------------------------------------- */
.mea-map-controls {
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.14);
  border-radius: var(--ai-radius, 2px);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.18);
  overflow: hidden;
}

.mea-map-controls__btn {
  display: block;
  width: 34px;
  height: 34px;
  padding: 0;
  background: #fff center / 18px 18px no-repeat;
  border: 0;
  border-bottom: 1px solid #e2e3eb;
  color: #2a2c3e;
  cursor: pointer;
}

.mea-map-controls__btn:last-child {
  border-bottom: 0;
}

.mea-map-controls__btn:hover {
  background-color: #f0f0ee;
}

.mea-map-controls__btn[aria-pressed='true'] {
  background-color: var(--ai-brand, #005cff);
}

.mea-map-block .leaflet-bar {
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.14);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.18);
}

.mea-map-block .leaflet-bar a {
  background-color: #fff;
  color: #2a2c3e;
  border-bottom-color: #e2e3eb;
}

.mea-map-block .leaflet-bar a:hover,
.mea-map-block .leaflet-bar a:focus {
  background-color: #f0f0ee;
  color: #111827;
}

/* Icons are inline SVG data URIs rather than an icon font: a font would be a
 * second blocking download, and a missing glyph renders as a tofu box. */
.mea-map-controls__btn--heat {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232a2c3e' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Ccircle cx='12' cy='12' r='7' opacity='.55'/%3E%3Ccircle cx='12' cy='12' r='10.5' opacity='.3'/%3E%3C/svg%3E");
}

.mea-map-controls__btn--borders {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232a2c3e' stroke-width='2'%3E%3Cpath d='M4 6l4-2 4 2 4-2 4 2v12l-4 2-4-2-4 2-4-2V6z'/%3E%3Cpath d='M8 4v12M12 6v12M16 4v12' opacity='.55'/%3E%3C/svg%3E");
}

.mea-map-controls__btn--reset {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232a2c3e' stroke-width='2'%3E%3Cpath d='M3 12a9 9 0 1 0 3-6.7'/%3E%3Cpath d='M3 4v5h5'/%3E%3C/svg%3E");
}

.mea-map-controls__btn--full {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232a2c3e' stroke-width='2'%3E%3Cpath d='M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5'/%3E%3C/svg%3E");
}

.mea-map-controls__btn--satellite {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232a2c3e' stroke-width='2'%3E%3Cpath d='M7.5 7.5l-3-3 3-3 3 3zM19.5 19.5l-3-3 3-3 3 3z'/%3E%3Cpath d='M9 9l6 6M13.5 6.5l4 4'/%3E%3Ccircle cx='9' cy='15' r='1.2'/%3E%3Cpath d='M5 15a4 4 0 0 0 4 4M2 15a7 7 0 0 0 7 7' opacity='.55'/%3E%3C/svg%3E");
}

.mea-map-controls__btn[aria-pressed='true'].mea-map-controls__btn--satellite {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2'%3E%3Cpath d='M7.5 7.5l-3-3 3-3 3 3zM19.5 19.5l-3-3 3-3 3 3z'/%3E%3Cpath d='M9 9l6 6M13.5 6.5l4 4'/%3E%3Ccircle cx='9' cy='15' r='1.2'/%3E%3Cpath d='M5 15a4 4 0 0 0 4 4M2 15a7 7 0 0 0 7 7' opacity='.55'/%3E%3C/svg%3E");
}

.mea-map-controls__btn[aria-pressed='true'].mea-map-controls__btn--heat {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Ccircle cx='12' cy='12' r='7' opacity='.55'/%3E%3Ccircle cx='12' cy='12' r='10.5' opacity='.3'/%3E%3C/svg%3E");
}

.mea-map-controls__btn[aria-pressed='true'].mea-map-controls__btn--borders {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2'%3E%3Cpath d='M4 6l4-2 4 2 4-2 4 2v12l-4 2-4-2-4 2-4-2V6z'/%3E%3Cpath d='M8 4v12M12 6v12M16 4v12' opacity='.55'/%3E%3C/svg%3E");
}

/* -------------------------------------------------------------------
 *  Timeline
 * ------------------------------------------------------------------- */
.mea-map-timeline {
  display: flex;
  align-items: center;
  gap: var(--ai-space-3, 0.75rem);
  margin-top: var(--ai-space-3, 0.75rem);
  font-family: var(--ai-font, sans-serif);
  font-size: var(--ai-fs-xs, 0.875rem);
  color: var(--ai-text-body, #484a5e);
}

.mea-map-timeline__range {
  flex: 1 1 auto;
  /* The track is a time axis; in RTL it must run right to left like the text. */
  direction: inherit;
  accent-color: var(--ai-brand, #005cff);
  min-height: 2.75rem;
}

.mea-map-timeline__value {
  font-family: var(--ai-font-num, monospace);
  font-variant-numeric: tabular-nums;
  min-width: 6ch;
  color: var(--ai-text-strong, #2a2c3e);
}

/* -------------------------------------------------------------------
 *  Popups
 * ------------------------------------------------------------------- */
.leaflet-popup-content-wrapper {
  border-radius: var(--ai-radius, 8px);
  background: var(--ai-card, #fff);
  color: var(--ai-text, #0d0e18);
  box-shadow: var(--ai-shadow-lg, 0 8px 28px rgba(13, 14, 24, 0.12));
}

.leaflet-popup-tip {
  background: var(--ai-card, #fff);
}

.leaflet-popup-content {
  margin: 0;
  font-family: var(--ai-font, sans-serif);
}

.mea-country-popup {
  /* Stay inside the map frame even when the country sits on the edge. */
  max-width: 220px;
}

.mea-country-popup .leaflet-popup-content-wrapper,
.mea-country-popup .leaflet-popup-content {
  direction: rtl;
  text-align: start;
}

.mea-country-popup .leaflet-popup-content-wrapper {
  max-height: min(16rem, calc(var(--mea-map-height, 520px) - 5rem));
  overflow: auto;
}

html[dir='rtl'] .leaflet-container a.leaflet-popup-close-button {
  right: auto;
  left: 0;
  padding: 4px 0 0 4px;
}

.mea-country-popup .leaflet-popup-content {
  width: 200px;
  min-width: 0;
  margin: 0;
}

/* Leaflet popup chrome — match site cards rather than the default white slab. */
.mea-map-block .leaflet-popup-content-wrapper {
  padding: 0;
  border: 1px solid var(--ai-border, #e2e3eb);
  border-radius: var(--ai-radius-lg, 10px);
  background: var(--ai-card, #fff);
  box-shadow: var(--ai-lift-md, 0 10px 28px rgba(13, 14, 24, 0.14));
  overflow: hidden;
  animation: mea-popup-open 0.22s ease-out both;
}

.mea-map-block .leaflet-popup-content {
  margin: 0;
  min-width: 220px;
}

.mea-map-block .leaflet-popup-tip {
  background: var(--ai-card, #fff);
  border: 1px solid var(--ai-border, #e2e3eb);
  box-shadow: none;
}

.mea-popup {
  padding: var(--ai-space-3, 0.75rem);
}

.mea-popup__image-wrap {
  display: block;
  width: calc(100% + 1.5rem);
  margin: -0.75rem -0.75rem var(--ai-space-2, 0.5rem);
  max-width: none;
  height: 7.5rem;
  overflow: hidden;
}

.mea-popup__image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.35s ease;
}

.mea-popup:hover .mea-popup__image {
  transform: scale(1.04);
}

.mea-popup__kind {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin: 0 0 var(--ai-space-1, 0.25rem);
  font-size: var(--ai-fs-2xs, 0.8125rem);
  font-weight: var(--ai-fw-semibold, 600);
  letter-spacing: 0.02em;
  color: var(--ai-brand-text, #005cff);
}

.mea-popup__title {
  margin: 0 0 var(--ai-space-2, 0.5rem);
  font-size: var(--ai-fs-md, 1rem);
  font-weight: var(--ai-fw-bold, 700);
  line-height: var(--ai-lh-heading, 1.4);
}

.mea-popup__title a {
  color: var(--ai-text, #0d0e18);
  text-decoration: none;
}

.mea-popup__title a:hover {
  color: var(--ai-brand-text, #005cff);
  text-decoration: underline;
}

.mea-popup__place {
  margin: 0 0 var(--ai-space-2, 0.5rem);
  font-size: var(--ai-fs-xs, 0.875rem);
  color: var(--ai-text-body, #484a5e);
}

.mea-popup__precision {
  color: var(--ai-text-muted, #68697a);
}

.mea-popup__excerpt {
  margin: 0 0 var(--ai-space-2, 0.5rem);
  font-size: var(--ai-fs-xs, 0.875rem);
  line-height: var(--ai-lh-body, 1.85);
  color: var(--ai-text-body, #484a5e);
}

.mea-popup__footer {
  display: flex;
  justify-content: space-between;
  gap: var(--ai-space-2, 0.5rem);
  margin: 0;
  font-size: var(--ai-fs-2xs, 0.8125rem);
  color: var(--ai-text-muted, #68697a);
}

.mea-popup__more {
  font-weight: var(--ai-fw-semibold, 600);
  color: var(--ai-brand-text, #005cff);
}

@keyframes mea-popup-open {
  from {
    opacity: 0;
    transform: translateY(4px) scale(0.97);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* -------------------------------------------------------------------
 *  Fallback list
 *
 *  Not hidden when JavaScript runs. A reader who prefers a list, a reader
 *  using a screen reader, and a crawler all get the same content, and the
 *  map stops being the only way to reach it.
 * ------------------------------------------------------------------- */
.mea-map-block__list {
  margin-top: var(--ai-space-5, 1.5rem);
  font-family: var(--ai-font, sans-serif);
}

.mea-map-block__list-title {
  font-size: var(--ai-fs-lg, 1.1875rem);
  font-weight: var(--ai-fw-bold, 700);
  color: var(--ai-text, #0d0e18);
  margin: 0 0 var(--ai-space-3, 0.75rem);
}

.mea-map-block__items {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--ai-border-soft, #edeef4);
}

.mea-map-block__item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--ai-space-2, 0.5rem);
  padding: var(--ai-space-3, 0.75rem) var(--ai-space-2, 0.5rem);
  margin-inline: calc(-1 * var(--ai-space-2, 0.5rem));
  border-bottom: 1px solid var(--ai-border-soft, #edeef4);
  border-radius: var(--ai-radius, 2px);
  transition: background 0.15s ease;
}

.mea-map-block__item:hover {
  background: color-mix(in srgb, var(--mea-kind-news) 6%, transparent);
}

.mea-map-block__item[data-kind='monitoring']:hover { background: color-mix(in srgb, var(--mea-kind-monitoring) 8%, transparent); }
.mea-map-block__item[data-kind='report']:hover { background: color-mix(in srgb, var(--mea-kind-report) 8%, transparent); }
.mea-map-block__item[data-kind='investigation']:hover { background: color-mix(in srgb, var(--mea-kind-investigation) 8%, transparent); }
.mea-map-block__item[data-kind='article']:hover { background: color-mix(in srgb, var(--mea-kind-article) 8%, transparent); }
.mea-map-block__item[data-kind='video']:hover { background: color-mix(in srgb, var(--mea-kind-video) 8%, transparent); }

.mea-map-block__item-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  flex: 1 1 12rem;
}

.mea-map-block__item-swatch {
  flex: 0 0 auto;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--mea-kind-news);
  box-shadow: 0 0 0 1px rgba(13, 14, 24, 0.08);
}

.mea-map-block__item[data-kind='monitoring'] .mea-map-block__item-swatch { background: var(--mea-kind-monitoring); }
.mea-map-block__item[data-kind='report'] .mea-map-block__item-swatch { background: var(--mea-kind-report); }
.mea-map-block__item[data-kind='investigation'] .mea-map-block__item-swatch { background: var(--mea-kind-investigation); }
.mea-map-block__item[data-kind='article'] .mea-map-block__item-swatch { background: var(--mea-kind-article); }
.mea-map-block__item[data-kind='video'] .mea-map-block__item-swatch { background: var(--mea-kind-video); }

.mea-map-block__item-link {
  font-size: var(--ai-fs-base, 1.0625rem);
  font-weight: var(--ai-fw-medium, 500);
  line-height: var(--ai-lh-heading, 1.4);
  color: var(--ai-text, #0d0e18);
  text-decoration: none;
}

.mea-map-block__item-link:hover {
  color: var(--ai-brand-text, #005cff);
  text-decoration: underline;
}

.mea-map-block__item-flags {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.mea-map-block__item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ai-space-2, 0.5rem);
  font-size: var(--ai-fs-xs, 0.875rem);
  color: var(--ai-text-muted, #68697a);
}

.mea-map-block__item-place {
  color: var(--ai-gold, #886329);
}

.mea-map-block__more,
.mea-map-block__truncated {
  margin: var(--ai-space-3, 0.75rem) 0 0;
  font-size: var(--ai-fs-xs, 0.875rem);
  color: var(--ai-text-muted, #68697a);
}

/* -------------------------------------------------------------------
 *  Dark mode
 *
 *  Tiles are daylight imagery. Dimming them slightly keeps a dark page from
 *  being dominated by a glowing rectangle, without the full hue-rotate trick
 *  that turns deserts purple and makes the map harder to read.
 * ------------------------------------------------------------------- */
[data-theme='dark'] .leaflet-tile-pane {
  filter: brightness(0.82) saturate(0.85);
}

[data-theme='dark'] .mea-map-controls,
[data-theme='dark'] .mea-map-block .leaflet-bar {
  border-color: rgba(255, 255, 255, 0.55);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .leaflet-tile-pane {
    filter: brightness(0.82) saturate(0.85);
  }

  :root:not([data-theme='light']) .mea-map-controls,
  :root:not([data-theme='light']) .mea-map-block .leaflet-bar {
    border-color: rgba(255, 255, 255, 0.55);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  }
}

/* -------------------------------------------------------------------
 *  Small screens
 * ------------------------------------------------------------------- */
@media (max-width: 600px) {
  .mea-map-block__canvas {
    height: min(var(--mea-map-height, 520px), 68vh);
  }

  .mea-map-block__filters {
    flex-direction: column;
    align-items: stretch;
  }

  .mea-map-block.is-fullscreen .mea-map-block__canvas {
    height: calc(100vh - 8rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .leaflet-fade-anim .leaflet-tile,
  .leaflet-zoom-anim .leaflet-zoom-animated {
    transition: none !important;
  }

  .mea-pin__dot,
  .mea-pin--breaking .mea-pin__dot,
  .mea-map-block .leaflet-popup-content-wrapper {
    animation: none;
  }

  .mea-pin__dot,
  .mea-cluster span,
  .mea-popup__image,
  .mea-map-block__item {
    transition: none;
  }

  .leaflet-marker-icon.mea-pin:hover .mea-pin__dot,
  .leaflet-marker-icon.mea-pin:focus-visible .mea-pin__dot {
    width: 14px;
    height: 14px;
    margin: 2px;
  }

  .mea-popup:hover .mea-popup__image {
    transform: none;
  }
}
