/*
 * RKB Native Distribution map + species identity header.
 *
 * Consumes the "Quiet Reference" design tokens from site.css (colours,
 * spacing, type). Flat, square-cornered, shadowless — matching the system's
 * --radius/--shadow of 0/none. Theme-aware automatically because every colour
 * is a token that site.css already redefines for dark mode. Nothing here is
 * conveyed by colour alone: the country list and summary duplicate the map.
 */

/* ---- Shared: visually-hidden (screen-reader only) ---- */
.nd-visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Species identity header ---- */
.species-identity {
  border: 1px solid var(--line);
  padding: var(--space-4, 1.5rem);
  margin-bottom: var(--space-5, 2rem);
  background: var(--surface);
}
.species-identity__head {
  border-bottom: 1px solid var(--line);
  padding-bottom: var(--space-3, 1rem);
  margin-bottom: var(--space-3, 1rem);
}
.species-identity__common {
  font-family: var(--serif, Georgia, serif);
  font-size: var(--font-size-xl, 2rem);
  line-height: var(--line-height-tight, 1.2);
  margin: 0;
}
.species-identity__scientific {
  font-family: var(--serif, Georgia, serif);
  color: var(--ink-2);
  margin: 0.25rem 0 0;
}
.species-identity__authority {
  color: var(--ink-3);
  font-style: normal;
  font-size: var(--font-size-sm, 0.8125rem);
}
.species-identity__status {
  display: inline-block;
  margin-top: 0.5rem;
}
.species-identity__grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: var(--space-4, 1.5rem);
}
.species-identity__subtitle {
  font-family: var(--sans, system-ui, sans-serif);
  font-size: var(--font-size-xs, 0.6875rem);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  margin: 0 0 0.5rem;
}
.species-identity__conservation {
  margin: 0 0 var(--space-3, 1rem);
}
.species-identity__fact {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--line);
}
.species-identity__fact dt {
  color: var(--ink-3);
  font-size: var(--font-size-sm, 0.8125rem);
}
.species-identity__fact dd {
  margin: 0;
  text-align: right;
}
@media (max-width: 720px) {
  .species-identity__grid {
    grid-template-columns: 1fr;
  }
}

/* ---- Native Distribution section ---- */
.nd-section {
  margin: var(--space-5, 2rem) 0;
}
.nd-section__title {
  font-family: var(--serif, Georgia, serif);
}
.nd-empty,
.nd-nogeometry {
  color: var(--ink-2);
  border: 1px solid var(--line);
  padding: var(--space-3, 1rem);
  background: var(--bg-alt);
}
.nd-preview-banner {
  border: 1px solid var(--warning, #c99a1e);
  background: var(--warning-tint, #f7efd4);
  color: var(--ink);
  padding: 0.5rem 0.75rem;
  font-size: var(--font-size-sm, 0.8125rem);
  margin-bottom: 0.75rem;
}

/* ---- The map figure ---- */
.nd-map {
  position: relative;
  margin: 0 0 var(--space-3, 1rem);
  border: 1px solid var(--line);
  background: var(--bg-alt);
}
.nd-map__figure {
  width: 100%;
}
.nd-map__svg {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
}
.nd-map--interactive .nd-map__svg {
  cursor: grab;
}
.nd-map--dragging .nd-map__svg {
  cursor: grabbing;
}
.nd-map__svg:focus-visible {
  outline: 2px solid var(--link, #146b45);
  outline-offset: -2px;
}

/* Country polygons: context = neutral land, native = accent. Stroke keeps
 * countries distinguishable without relying on fill colour alone. */
.nd-map__land {
  fill: var(--surface);
  stroke: var(--line);
  stroke-width: 0.5;
}
.nd-map__native {
  fill: var(--official, #1e8f5e);
  stroke: var(--official-ink, #146b45);
  stroke-width: 0.6;
  transition: fill 120ms ease;
}
.nd-map--reduced-motion .nd-map__native {
  transition: none;
}
.nd-map__native.is-active,
.nd-map__native:hover {
  fill: var(--official-ink, #146b45);
}

/* Controls — flat square buttons, top-right. */
.nd-map__controls {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nd-map__btn {
  min-width: 2rem;
  min-height: 2rem;
  padding: 0 0.5rem;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--sans, system-ui, sans-serif);
  font-size: var(--font-size-base, 0.875rem);
  cursor: pointer;
  line-height: 1;
}
.nd-map__btn:hover {
  background: var(--bg-alt);
}
.nd-map__btn:focus-visible {
  outline: 2px solid var(--link, #146b45);
  outline-offset: 1px;
}
.nd-map__hint {
  position: absolute;
  bottom: 0.5rem;
  left: 0.5rem;
  margin: 0;
  font-size: var(--font-size-xs, 0.6875rem);
  color: var(--ink-3);
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  padding: 0.15rem 0.4rem;
  pointer-events: none;
}

/* ---- Summary + country list ---- */
.nd-summary {
  font-size: var(--font-size-md, 1.125rem);
  line-height: var(--line-height-relaxed, 1.8);
  margin: 0 0 var(--space-3, 1rem);
}
.nd-country-list {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--space-2, 0.5rem);
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.nd-country-list__label {
  font-size: var(--font-size-sm, 0.8125rem);
  color: var(--ink-3);
  margin: 0.5rem 0 0.25rem;
}
.nd-country {
  display: inline-block;
  font: inherit;
  font-size: var(--font-size-sm, 0.8125rem);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 0.2rem 0.55rem;
  cursor: pointer;
}
li.nd-country--region {
  cursor: default;
  color: var(--ink-2);
  font-style: italic;
}
.nd-country.is-active {
  border-color: var(--official-ink, #146b45);
  background: var(--official-tint, #dff5e9);
  color: var(--official-ink, #146b45);
}
.nd-country:focus-visible {
  outline: 2px solid var(--link, #146b45);
  outline-offset: 1px;
}

/* ---- Source / review metadata ---- */
.nd-meta {
  margin: var(--space-3, 1rem) 0 0.5rem;
  border-top: 1px solid var(--line);
}
.nd-meta__row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--line);
  font-size: var(--font-size-sm, 0.8125rem);
}
.nd-meta__row dt {
  color: var(--ink-3);
}
.nd-meta__row dd {
  margin: 0;
  text-align: right;
}
.nd-attribution {
  font-size: var(--font-size-xs, 0.6875rem);
  color: var(--ink-3);
  margin: 0.5rem 0 0;
}

/* ---- Report a correction ---- */
.nd-report {
  margin-top: var(--space-3, 1rem);
  border: 1px solid var(--line);
  padding: 0.5rem 0.75rem;
}
.nd-report summary {
  cursor: pointer;
  font-size: var(--font-size-sm, 0.8125rem);
  color: var(--link, #146b45);
}
.nd-report__form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.nd-report__form textarea {
  width: 100%;
  font: inherit;
  border: 1px solid var(--line);
  padding: 0.5rem;
  background: var(--surface);
  color: var(--ink);
}
.nd-report__form button {
  align-self: flex-start;
}
.nd-report__status {
  font-size: var(--font-size-sm, 0.8125rem);
  color: var(--ink-2);
  margin: 0;
}

/* ---- Legend (print + inline) ---- */
.nd-legend {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: var(--font-size-sm, 0.8125rem);
  color: var(--ink-2);
  margin: 0.4rem 0 0;
}
.nd-legend__swatch {
  display: inline-block;
  width: 0.9rem;
  height: 0.9rem;
  background: var(--official, #1e8f5e);
  border: 1px solid var(--official-ink, #146b45);
}

/* ---- Print / PDF ---- */
@media print {
  .nd-map__controls,
  .nd-map__hint,
  .nd-report {
    display: none !important;
  }
  .nd-map,
  .species-identity {
    border-color: #999;
    break-inside: avoid;
  }
  .nd-map__native {
    fill: #4a4a4a !important; /* legible in monochrome print */
    stroke: #000 !important;
  }
  .nd-map__land {
    fill: #fff !important;
    stroke: #bbb !important;
  }
  .nd-section {
    break-inside: avoid;
  }
  .nd-print-url {
    font-family: monospace;
    word-break: break-all;
  }
}

/* ---- Interactive web legend (two swatches: native vs context) ---- */
.nd-legend {
  flex-wrap: wrap;
  gap: 0.4rem 1.1rem;
}
.nd-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.nd-legend__swatch--native {
  background: var(--official, #1e8f5e);
  border-color: var(--official-ink, #146b45);
}
.nd-legend__swatch--context {
  background: var(--surface);
  border-color: var(--line);
}

/* ---- Hover tooltip (country name), positioned within the figure ---- */
.nd-map__tooltip {
  position: absolute;
  transform: translate(-50%, calc(-100% - 10px));
  pointer-events: none;
  z-index: 3;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--ink, #1a1a1a);
  color: #fff;
  font: 600 var(--font-size-xs, 0.75rem) / 1.3 var(--sans);
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* ---- Distribution Explorer page ---- */
.dist-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin: 18px 0;
}
.dist-summary {
  font: 400 var(--font-size-md, 1rem) / 1.5 var(--sans);
  color: var(--ink-2);
  margin: 0 0 8px;
}
.dist-continent {
  padding: 14px 0;
  border-top: 1px solid var(--line);
}
.dist-continent:first-of-type {
  border-top: 0;
}
.dist-continent__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
}
.dist-continent__name {
  margin: 0;
  font: 300 var(--font-size-lg, 1.25rem) / 1.2 var(--serif);
}
.dist-country-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin: 10px 0 0;
  padding: 0;
}
.dist-country {
  display: inline-block;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font: 400 var(--font-size-sm, 0.8125rem) / 1.3 var(--sans);
  color: var(--ink-2);
}
.dist-country--mapped {
  border-color: var(--official-ink, #146b45);
  color: var(--official-ink, #146b45);
}
.dist-country--region {
  font-style: italic;
  color: var(--ink-3);
}

.dist-related-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.dist-related {
  padding: 14px 0;
  border-top: 1px solid var(--line);
}
.dist-related:first-child {
  border-top: 0;
}
.dist-related__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
}
.dist-related__name {
  font: 500 var(--font-size-md, 1rem) / 1.3 var(--serif);
  color: var(--ink);
  text-decoration: none;
}
.dist-related__name:hover {
  color: var(--official-ink, #146b45);
}
.dist-related__sci {
  color: var(--ink-2);
  font: 400 var(--font-size-sm, 0.8125rem) / 1.3 var(--sans);
}
.dist-related__shared {
  margin-left: auto;
}
.dist-related__links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.nd-explore-link {
  margin: 12px 0 0;
}
