/**
 * @file
 * Map readout popup (biopama_libraries/map-readout, js/maps/mapReadout*.js):
 * the dark popup that follows the pointer over a scored grid and pins on a
 * click, its value columns and its collapsible groups. NOTES-map-readout.md.
 *
 * Mapbox owns .mapboxgl-popup-content and the tip, so the skin needs rules;
 * the content itself uses Bootstrap utilities for layout and type, and the
 * classes below for colour. Colours come from the --biopama-readout-* tokens
 * (Conservation Tracking's grey by default): a tool re-skins its popups with
 * one rule on `.biopama-readout-popup` (and, for the group chevrons,
 * Bootstrap's --bs-accordion-btn-icon / --bs-accordion-btn-active-icon on
 * `.biopama-readout-popup .accordion-button::after`). No rule depends on the
 * page skin. The height cap (--biopama-readout-max-height) is written on the
 * map container by the controller. Selectors out-rank Bootstrap and the
 * theme instead of using !important (theme CSS, Bootstrap included, loads
 * after module CSS).
 */

.biopama-readout-popup {
  --biopama-readout-bg: var(--bs-dark);
  --biopama-readout-color: #fff;
  --biopama-readout-muted: rgba(255, 255, 255, 0.65);
  --biopama-readout-value-color: var(--bs-warning);
  --biopama-readout-points-color: #fff;
  --biopama-readout-active-bg: #2f3438;
  --biopama-readout-border: rgba(255, 255, 255, 0.15);
  --biopama-readout-number: 4rem;
  --biopama-readout-gap: 0.75rem;
  --biopama-readout-chevron: 0.875rem;
}

/* 0,2,0: also beats the CT skin's page-wide .mapboxgl-popup-content rule
   (biopama_conservation_tracking/css/ct_map.css: max-height 400px, black
   text). A hover popup must not catch the pointer, or sliding onto it fires
   the map's mouseout and it flickers at its edge. The height cap is written
   on the map container by the controller (half the map, so the popup fits
   above or below its point; a measured value, so a custom property). */
.biopama-readout-popup .mapboxgl-popup-content {
  pointer-events: none;
  background-color: var(--biopama-readout-bg);
  color: var(--biopama-readout-color);
  padding: 0.25rem 0;
  max-height: min(60vh, var(--biopama-readout-max-height, 60vh));
  overflow-y: auto;
}

/* Pinned by a click: the close button and the groups become clickable. */
.biopama-readout-popup.biopama-readout-pinned .mapboxgl-popup-content {
  pointer-events: auto;
}

.biopama-readout-popup.mapboxgl-popup-anchor-bottom .mapboxgl-popup-tip,
.biopama-readout-popup.mapboxgl-popup-anchor-bottom-left .mapboxgl-popup-tip,
.biopama-readout-popup.mapboxgl-popup-anchor-bottom-right .mapboxgl-popup-tip {
  border-top-color: var(--biopama-readout-bg);
}

.biopama-readout-popup.mapboxgl-popup-anchor-top .mapboxgl-popup-tip,
.biopama-readout-popup.mapboxgl-popup-anchor-top-left .mapboxgl-popup-tip,
.biopama-readout-popup.mapboxgl-popup-anchor-top-right .mapboxgl-popup-tip {
  border-bottom-color: var(--biopama-readout-bg);
}

.biopama-readout-popup.mapboxgl-popup-anchor-left .mapboxgl-popup-tip {
  border-right-color: var(--biopama-readout-bg);
}

.biopama-readout-popup.mapboxgl-popup-anchor-right .mapboxgl-popup-tip {
  border-left-color: var(--biopama-readout-bg);
}

/* The pointer over a result (create()'s `cursor` option). 0,3,0 beats
   Mapbox's grab cursor; Mapbox's grabbing cursor still wins while dragging. */
.mapboxgl-canvas-container.mapboxgl-interactive.biopama-readout-hover {
  cursor: pointer;
}

/* --- Colour ------------------------------------------------------------- */

.biopama-readout-popup .biopama-readout-muted {
  color: var(--biopama-readout-muted);
}

.biopama-readout-popup .biopama-readout-value {
  color: var(--biopama-readout-value-color);
}

.biopama-readout-popup .biopama-readout-points {
  color: var(--biopama-readout-points-color);
}

/* --- Value columns ------------------------------------------------------- */

/* A label column, then one fixed-width column per value (any number), so
   the numbers of separate rows - the column titles, a group header, its
   items - line up. */
.biopama-readout-popup .biopama-readout-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  grid-auto-columns: var(--biopama-readout-number);
  column-gap: var(--biopama-readout-gap);
  align-items: baseline;
}

/* Rows outside a group header: room for the header's chevron, so their
   numbers sit under the header's numbers. */
.biopama-readout-popup .biopama-readout-row {
  padding-right: calc(var(--biopama-readout-chevron) + var(--biopama-readout-gap));
}

/* --- Collapsible groups (Bootstrap's accordion, toggled by the controller) */

/* 0,3,0: beats the skin's .akp-skin-ct .accordion tokens (0,2,0). */
.biopama-readout-popup .accordion.biopama-readout-groups {
  --bs-accordion-bg: transparent;
  --bs-accordion-color: var(--biopama-readout-color);
  --bs-accordion-border-color: var(--biopama-readout-border);
  --bs-accordion-btn-bg: transparent;
  --bs-accordion-btn-color: var(--biopama-readout-color);
  --bs-accordion-active-bg: var(--biopama-readout-active-bg);
  --bs-accordion-active-color: var(--biopama-readout-value-color);
  --bs-accordion-btn-icon-width: var(--biopama-readout-chevron);
  --bs-accordion-btn-focus-box-shadow: 0 0 0 0.2rem var(--biopama-readout-border);
}

/* The chevrons, on ::after as Bootstrap and the skin declare them
   (0,2,1 / 0,3,1): white closed, yellow open, as the sidebar accordions. */
.biopama-readout-popup .accordion.biopama-readout-groups .accordion-button::after {
  --bs-accordion-btn-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23ffffff'%3e%3cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3e%3c/svg%3e");
  --bs-accordion-btn-active-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23ffc107'%3e%3cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3e%3c/svg%3e");
  margin-left: var(--biopama-readout-gap);
}

/* Bootstrap fixes the header text at 1rem; the popup's is `small`. */
.biopama-readout-popup .biopama-readout-groups .accordion-button {
  font-size: inherit;
}
