/* GRRI Map styles — v2.2 */
/* ========================================================
   GRRI Interactive Map — Stylesheet (scoped under #ag-map-container)
   Henley & Partners × AlphaGeo

   Notes for integrators:
   - All rules are scoped to #ag-map-container so they cannot affect
     the rest of the host site.
   - No external font imports — fonts inherit from the parent site
     by default. Specific elements opt into Garamond serif or
     Roboto sans-serif as documented inline.
   ======================================================== */

/* ----- Tokens (scoped to the container) ------------------ */
#ag-map-container {
  --ag-slate-darkest: #385060;
  --ag-slate-mid:     #788890;

  --ag-ink:           #1f2937;
  --ag-ink-soft:      #334155;
  --ag-muted:         #64748b;
  --ag-rule:          #e4e7ec;
  --ag-rule-lt:       #f0f2f5;
  --ag-na:            #f5f6f7;
  --ag-red:           #c44a3f;

  /* Font stacks — Garamond for serif, Roboto for UI */
  --ag-serif: 'ClassGarmnd BT', Garamond, serif;
  --ag-sans:  Roboto, Helvetica, sans-serif;

  /* Inherit font from the parent page by default; specific
     elements below explicitly opt into the serif or sans stacks. */
  color: var(--ag-ink);
  line-height: 1.5;

  /* Layout shell */
  max-width: 1400px;
  margin: 0 auto;
  padding: 40px 40px 48px;
  box-sizing: border-box;
}

/* Reset only descendants of the scoped container — never global */
#ag-map-container,
#ag-map-container *,
#ag-map-container *::before,
#ag-map-container *::after {
  box-sizing: border-box;
}

/* ----- Layout: sidebar + map ----------------------------- */
#ag-map-container .ag-main {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 22px;
  align-items: flex-start;
}

/* ----- Sidebar ------------------------------------------- */
#ag-map-container .ag-sidebar-label {
  font-family: var(--ag-sans);
  font-weight: 400;
  font-size: 13px;
  color: var(--ag-muted);
  margin-bottom: 12px;
  padding-left: 2px;
}

#ag-map-container .ag-filter-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1.5px solid var(--ag-rule);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  margin: 0 0 10px 0;
  text-align: left;
  transition: all 0.15s;
  font-family: var(--ag-sans);
  color: var(--ag-ink-soft);
}
#ag-map-container .ag-filter-btn:hover { border-color: var(--ag-slate-mid); }
#ag-map-container .ag-filter-btn.ag-is-active {
  background: var(--ag-slate-darkest);
  border-color: var(--ag-slate-darkest);
  color: #ffffff;
}

#ag-map-container .ag-filter-icon {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid transparent;
  border-radius: 3px;
}
#ag-map-container .ag-filter-icon svg {
  width: 18px;
  height: 18px;
  stroke-width: 1.4;
  fill: none;
  stroke: var(--ag-slate-darkest);
}
#ag-map-container .ag-filter-btn.ag-is-active .ag-filter-icon svg { stroke: #ffffff; }

#ag-map-container .ag-filter-btn.ag-v-change .ag-filter-icon       { border-color: var(--ag-slate-darkest); }
#ag-map-container .ag-filter-btn.ag-v-change .ag-filter-icon svg   { stroke: var(--ag-slate-darkest); }
#ag-map-container .ag-filter-btn.ag-v-change.ag-is-active .ag-filter-icon       { border-color: #ffffff; }
#ag-map-container .ag-filter-btn.ag-v-change.ag-is-active .ag-filter-icon svg   { stroke: #ffffff; }

#ag-map-container .ag-filter-label {
  font-family: var(--ag-sans);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: -0.005em;
}

/* ----- Map ----------------------------------------------- */
#ag-map-container .ag-map-panel {
  position: relative;
  border: 1px solid var(--ag-rule);
  border-radius: 4px;
  padding: 20px 18px 18px;
  background: #ffffff;
}

#ag-map-container .ag-map-wrapper {
  position: relative;
  width: 100%;
  padding-bottom: 48%;
  /* Allow native pinch-zoom but let D3 handle pan/wheel */
  touch-action: manipulation;
}
#ag-map-container .ag-map-wrapper > svg {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  cursor: grab;
}
#ag-map-container .ag-map-wrapper > svg:active { cursor: grabbing; }

#ag-map-container .ag-country {
  stroke: #ffffff;
  stroke-width: 0.6;
  cursor: pointer;
  pointer-events: all;
  paint-order: fill stroke;
  transition: filter 0.1s;
}
#ag-map-container .ag-country:hover {
  stroke: var(--ag-slate-darkest);
  stroke-width: 1.5;
  filter: brightness(1.08);
}
#ag-map-container .ag-country.ag-is-focused {
  stroke: var(--ag-slate-darkest);
  stroke-width: 1.6;
  filter: brightness(1.05);
}

/* ----- Tooltip ------------------------------------------- */
#ag-map-container .ag-tooltip {
  position: absolute;
  pointer-events: none;
  background: #ffffff;
  color: var(--ag-ink);
  padding: 10px 14px;
  border-radius: 3px;
  font-family: var(--ag-sans);
  font-size: 12px;
  min-width: 220px;
  max-width: 280px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  z-index: 15;
  opacity: 0;
  transition: opacity 0.1s;
  border: 1px solid var(--ag-rule);
}
#ag-map-container .ag-tooltip.ag-is-visible { opacity: 1; }

#ag-map-container .ag-tt-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
#ag-map-container .ag-tt-flag {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
}
#ag-map-container .ag-tt-name {
  font-family: var(--ag-serif);
  font-size: 18px;
  font-weight: 400;
  line-height: 1.15;
  color: var(--ag-ink);
}
#ag-map-container .ag-tt-ranks {
  display: grid;
  grid-template-columns: 1fr auto 1fr 1fr;
  gap: 10px;
  align-items: end;
  padding-top: 10px;
  border-top: 1px solid var(--ag-rule);
}
#ag-map-container .ag-tt-rank-cell,
#ag-map-container .ag-tt-change-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
}
#ag-map-container .ag-tt-col-label {
  font-family: var(--ag-sans);
  font-size: 9px;
  color: var(--ag-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 400;
  margin-bottom: 6px;
}
#ag-map-container .ag-tt-col-value {
  font-family: var(--ag-serif);
  font-size: 22px;
  font-weight: 400;
  line-height: 1;
  color: var(--ag-ink);
}
#ag-map-container .ag-tt-ord {
  font-family: var(--ag-serif);
  font-size: 0.55em;
  font-weight: 400;
  vertical-align: super;
  line-height: 0;
  margin-left: 1px;
}
#ag-map-container .ag-tt-arrow {
  width: 22px;
  height: 12px;
  align-self: end;
  margin-bottom: 5px;
  margin-left: -18px;
}
/* All ranks (1, 2, or 3 digit) follow the same layout: the "GIRRI" label
   sits left-aligned with the start of the rank digits, just like France.
   For 3-digit countries, nudge the rank value slightly left so the digits
   visually align under the GIRRI label. */
#ag-map-container .ag-tt-ranks-wide > .ag-tt-rank-cell:first-child > .ag-tt-col-value {
  margin-left: -2px;
}
#ag-map-container .ag-tt-change {
  font-family: var(--ag-serif);
  font-size: 22px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0;
  color: var(--ag-ink);
}
#ag-map-container .ag-tt-change.ag-pos  { color: var(--ag-ink); }
#ag-map-container .ag-tt-change.ag-neg  { color: var(--ag-ink); }
#ag-map-container .ag-tt-change.ag-zero { color: var(--ag-muted); }
#ag-map-container .ag-tt-na {
  font-family: var(--ag-sans);
  font-size: 11px;
  color: var(--ag-muted);
  font-style: normal;
  text-align: left;
  margin: 4px 0 0 0;
}

/* ----- Legend -------------------------------------------- */
#ag-map-container .ag-legend {
  margin-top: 18px;
  padding: 0 4px;
}
#ag-map-container .ag-legend-title {
  font-family: var(--ag-sans);
  font-size: 13px;
  color: var(--ag-ink-soft);
  font-weight: 400;
  margin-bottom: 4px;
}
#ag-map-container .ag-legend-sub {
  font-family: var(--ag-sans);
  font-size: 11px;
  color: var(--ag-muted);
  margin-bottom: 14px;
}
#ag-map-container .ag-legend-gradient {
  position: relative;
  height: 10px;
  border-radius: 1px;
  margin-bottom: 6px;
}
#ag-map-container .ag-legend-labels {
  display: flex;
  justify-content: space-between;
  font-family: var(--ag-sans);
  font-size: 11px;
  color: var(--ag-muted);
  font-weight: 400;
}

/* ----- Zoom controls (bottom-left of map) ---------------- */
#ag-map-container .ag-zoom-controls {
  position: absolute !important;
  left: 18px !important;
  bottom: 20px !important;
  top: auto !important;
  right: auto !important;
  display: flex !important;
  flex-direction: column !important;
  width: auto !important;
  height: auto !important;
  background: #ffffff;
  border: 1px solid var(--ag-rule);
  border-radius: 3px;
  overflow: hidden;
  z-index: 5;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}
#ag-map-container .ag-zoom-btn {
  width: 38px !important;
  height: 38px !important;
  min-width: 38px !important;
  min-height: 38px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  background: #ffffff !important;
  border: none;
  border-bottom: 1px solid var(--ag-rule);
  cursor: pointer;
  color: var(--ag-ink-soft);
  transition: background 0.12s, color 0.12s;
  padding: 0 !important;
  margin: 0 !important;
  font-family: var(--ag-sans);
  box-sizing: border-box !important;
}
#ag-map-container .ag-zoom-btn:last-child { border-bottom: none; }
#ag-map-container .ag-zoom-btn:hover {
  background: var(--ag-rule-lt);
  color: var(--ag-slate-darkest);
}
#ag-map-container .ag-zoom-btn:active { background: var(--ag-rule); }
#ag-map-container .ag-zoom-btn > svg {
  width: 18px !important;
  height: 18px !important;
  position: static !important;
  top: auto !important;
  left: auto !important;
  stroke: currentColor !important;
  fill: none !important;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}


/* ----- "Not in GIRRI dataset" indicator (top-left of map) - */
#ag-map-container .ag-na-indicator {
  position: absolute;
  top: 12px;
  left: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 4;
  pointer-events: none;
}
#ag-map-container .ag-na-indicator > svg {
  width: 20px;
  height: 14px;
  position: static;
  flex-shrink: 0;
}
#ag-map-container .ag-na-label {
  font-family: var(--ag-sans);
  font-size: 11px;
  font-weight: 400;
  color: var(--ag-muted);
  white-space: nowrap;
}

/* ----- Responsive ---------------------------------------- */
@media (max-width: 860px) {
  #ag-map-container .ag-main { grid-template-columns: 1fr; }
  #ag-map-container { padding: 24px 16px; }
  /* On mobile, give the map a taller aspect ratio so countries are bigger */
  #ag-map-container .ag-map-wrapper { padding-bottom: 70%; }
  /* Tooltip narrower on mobile */
  #ag-map-container .ag-tooltip {
    min-width: 200px;
    max-width: 240px;
    font-size: 11px;
  }
}
