/* Gift Map block (js/gift-map.js). Colours come from the page theme's CSS
   variables, so the map follows each organization's branding. */

/* The data colours. --gift-map-color is the block's Map color setting; unset,
   areas shade in the theme's primary and city dots use its accent. Set, it
   colours everything, with dots a little darker to stand out on shaded areas. */
.gift-map {
  --gift-map-fill: var(--gift-map-color, var(--color-primary, #2563eb));
  --gift-map-dot: var(--color-accent, var(--color-secondary, #f59e0b));
}

.gift-map--single-color {
  --gift-map-dot: color-mix(in srgb, var(--gift-map-color) 78%, #000);
}

.gift-map__canvas {
  position: relative;
  aspect-ratio: 8 / 5;
}

.gift-map__svg {
  display: block;
  width: 100%;
  height: 100%;
}

.gift-map__zoom.is-animated {
  transition: transform 600ms cubic-bezier(0.22, 1, 0.36, 1);
}

.gift-map__shape {
  stroke: var(--color-surface, #fff);
  stroke-width: 0.75;
  vector-effect: non-scaling-stroke;
  transition: fill 700ms ease, opacity 200ms ease;
  outline: none;
}

.gift-map__shape[role="button"] {
  cursor: pointer;
}

.gift-map__shape[role="button"]:hover,
.gift-map__shape:focus-visible {
  opacity: 0.82;
  stroke: var(--color-text-primary, #111827);
  stroke-width: 1.25;
}

.gift-map__shape.is-selected {
  stroke: var(--color-text-primary, #111827);
  stroke-width: 2;
}

.gift-map__dot {
  fill: var(--gift-map-dot);
  fill-opacity: 0.78;
  stroke: var(--color-surface, #fff);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  outline: none;
}

.gift-map__dot[role="button"] {
  cursor: pointer;
}

.gift-map__dot:hover,
.gift-map__dot:focus-visible {
  fill-opacity: 1;
  stroke: var(--color-text-primary, #111827);
  stroke-width: 1.5;
}

/* A new gift in a city: one ring that grows and fades */
.gift-map__pulse {
  fill: none;
  stroke: var(--gift-map-dot);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  transform-box: fill-box;
  transform-origin: center;
  animation: gift-map-pulse 1.6s ease-out forwards;
  pointer-events: none;
}

@keyframes gift-map-pulse {
  from {
    transform: scale(1);
    opacity: 0.9;
  }
  to {
    transform: scale(4);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gift-map__zoom.is-animated,
  .gift-map__shape {
    transition: none;
  }
  .gift-map__pulse {
    display: none;
  }
}

.gift-map__tooltip {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  padding: 0.4rem 0.6rem;
  border-radius: 0.5rem;
  background: var(--color-text-primary, #111827);
  color: var(--color-surface, #fff);
  font-size: 0.8125rem;
  line-height: 1.3;
  white-space: nowrap;
  box-shadow: var(--shadow-lg, 0 10px 15px -3px rgb(0 0 0 / 0.15));
}

.gift-map__view {
  color: var(--color-text-secondary, #6b7280);
  white-space: nowrap;
}

.gift-map__view.is-active {
  background: var(--color-primary, #2563eb);
  color: #fff;
}

.gift-map__swatch {
  display: inline-block;
  width: 1.5rem;
  height: 0.6rem;
}

.gift-map__swatch:first-of-type {
  border-radius: 9999px 0 0 9999px;
}

.gift-map__swatch:last-of-type {
  border-radius: 0 9999px 9999px 0;
}

.gift-map__legend-dot {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  margin-left: 0.75rem;
  border-radius: 9999px;
  background: var(--gift-map-dot);
}

.gift-map__top {
  display: block;
  padding: 0.25rem 0.375rem;
  border-radius: 0.375rem;
}

.gift-map__top:not(:disabled):hover {
  background: var(--color-surface-hover, rgb(0 0 0 / 0.04));
}

.gift-map__bar {
  display: block;
  height: 0.375rem;
  margin-top: 0.25rem;
  border-radius: 9999px;
  background: color-mix(in srgb, var(--color-border, #e5e7eb) 60%, transparent);
  overflow: hidden;
}

.gift-map__bar > span {
  display: block;
  height: 100%;
  border-radius: 9999px;
  background: var(--gift-map-fill);
  transition: width 700ms ease;
}

.gift-map__cities,
.gift-map__donors {
  max-height: 18rem;
  overflow-y: auto;
}

.gift-map__city {
  display: flex;
  width: 100%;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.25rem 0.375rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  color: var(--color-text-primary, #111827);
}

.gift-map__city:hover {
  background: var(--color-surface-hover, rgb(0 0 0 / 0.04));
}

.gift-map__donors li {
  padding: 0.3rem 0;
  border-bottom: 1px solid color-mix(in srgb, var(--color-border, #e5e7eb) 70%, transparent);
  font-size: 0.875rem;
  color: var(--color-text-primary, #111827);
}

.gift-map__subhead {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-text-secondary, #6b7280);
}

/* Live updates: a state, province or country that just gained a gift, and its
   row in "Most gifts from", light up briefly */
.gift-map__shape.is-updated {
  animation: gift-map-flash 1.4s ease-out;
}

@keyframes gift-map-flash {
  0%,
  35% {
    stroke: var(--gift-map-dot);
    stroke-width: 2.5;
  }
  100% {
    stroke: var(--color-surface, #fff);
    stroke-width: 0.75;
  }
}

.gift-map__top.is-updated {
  animation: gift-map-row 1.6s ease-out;
}

@keyframes gift-map-row {
  0%,
  30% {
    background: color-mix(in srgb, var(--gift-map-fill) 16%, transparent);
  }
  100% {
    background: transparent;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gift-map__shape.is-updated,
  .gift-map__top.is-updated {
    animation: none;
  }
}

/* The smallest phones: keep the three views on one line */
@media (max-width: 359px) {
  .gift-map__view {
    padding-inline: 0.45rem;
    font-size: 0.75rem;
  }
}

/* The GeoNames credit (CC BY 4.0), at the end of the legend row */
.gift-map__credit {
  font-size: 0.6875rem;
  color: var(--color-text-secondary, #6b7280);
  opacity: 0.8;
  text-decoration: none;
}

.gift-map__credit:hover,
.gift-map__credit:focus-visible {
  opacity: 1;
  text-decoration: underline;
}

/* Legend labels stay on one line; the legend wraps rather than overflow, and
   narrower swatches make room on phones */
.gift-map__legend {
  flex-wrap: wrap;
  row-gap: 0.25rem;
  max-width: 100%;
}

.gift-map__legend > span {
  white-space: nowrap;
}

@media (max-width: 479px) {
  .gift-map__swatch {
    width: 1rem;
  }
}

/* "All places", on the map's top-left corner while zoomed into a place */
.gift-map__back {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 5;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 9999px;
  background: color-mix(in srgb, var(--color-surface, #fff) 92%, transparent);
  color: var(--gift-map-fill);
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: var(--shadow-sm, 0 1px 2px rgb(0 0 0 / 0.08));
  backdrop-filter: blur(4px);
}

.gift-map__back[hidden] {
  display: none;
}

.gift-map__back:hover,
.gift-map__back:focus-visible {
  background: var(--color-surface, #fff);
  text-decoration: underline;
}

/* Drill-down rows: the name on the left, its numbers inline on the right */
.gift-map__donors li {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  column-gap: 0.75rem;
}

.gift-map__row-name {
  /* Keeps its width; the numbers wrap below it when long labels need the room */
  flex-shrink: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gift-map__row-numbers {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-secondary, #6b7280);
  text-align: right;
}

.gift-map__city {
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 0.75rem;
}
