/* Wetland and Riparian map: search, legend rows and popup title. Uses Mark's tokens from whetstone-map.css. */
.wr-search { margin: 0 0 0.75rem; }
.wr-search-label { display: block; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--forest-800, #1f3a2e); margin: 0 0 0.35rem; }
.wr-search-row { display: flex; gap: 0.35rem; }
.wr-search input[type="search"] { flex: 1 1 auto; min-width: 0; min-height: 2.25rem; padding: 0.35rem 0.55rem; font: inherit; font-size: 0.82rem; border: 1px solid var(--stone-300, #c9c4b8); border-radius: 6px; background: #fff; color: var(--forest-900, #141c18); }
.wr-search input[type="search"]:focus-visible { outline: 2px solid var(--ochre-500, #c08a2b); outline-offset: 1px; }
.wr-clear { flex: 0 0 auto; min-height: 2.25rem; padding: 0 0.6rem; font: inherit; font-size: 0.75rem; font-weight: 600; border: 1px solid var(--stone-300, #c9c4b8); border-radius: 6px; background: var(--stone-50, #faf9f6); color: var(--forest-800, #1f3a2e); cursor: pointer; }
.wr-results { list-style: none; margin: 0.35rem 0 0; padding: 0; max-height: 15rem; overflow: auto; border: 1px solid var(--stone-200, #e3dfd5); border-radius: 6px; background: #fff; }
.wr-results li + li { border-top: 1px solid var(--stone-100, #f1efe8); }
.wr-result { display: flex; align-items: flex-start; gap: 0.45rem; width: 100%; min-height: 2.75rem; padding: 0.4rem 0.55rem; font: inherit; text-align: left; background: none; border: 0; cursor: pointer; color: var(--forest-900, #141c18); }
.wr-result:hover, .wr-result:focus-visible { background: var(--stone-100, #f1efe8); outline: none; }
.wr-result-text { display: flex; flex-direction: column; min-width: 0; }
.wr-result-title { font-size: 0.8rem; font-weight: 600; }
.wr-result-sub { font-size: 0.7rem; color: var(--stone-600, #6b665c); }
.wr-noresult { padding: 0.5rem 0.55rem; font-size: 0.74rem; color: var(--stone-600, #6b665c); }
.wr-found { margin: 0.35rem 0 0; font-size: 0.72rem; color: var(--forest-800, #1f3a2e); }
.wr-swatch { display: inline-block; flex: 0 0 auto; width: 14px; height: 14px; margin-top: 0.15rem; border: 1px solid #B3B3B3; border-radius: 3px; }
.wr-popup-title { display: flex; align-items: center; gap: 0.45rem; }
.wr-popup-title .wr-swatch { margin-top: 0; }
.wr-count { margin-left: auto; padding-left: 0.4rem; font-size: 0.68rem; font-variant-numeric: tabular-nums; color: var(--stone-600, #6b665c); }
.wr-group { margin-top: 0.45rem; }
.wr-group-label .wg-legend-group-name { margin: 0; }
.wr-legend-layer { display: flex; align-items: center; justify-content: space-between; gap: 0.4rem; flex-wrap: wrap; }
.wr-legend-layer .wg-legend-group-name { margin: 0; }
.wg-legend-sublist .wg-legend-class .wg-class-label { width: 100%; }
@media (max-width: 640px) {
  .wr-search input[type="search"], .wr-clear { min-height: 44px; font-size: 16px; }
  .wr-result { min-height: 44px; }
  .wg-legend-sublist .wg-legend-class .wg-class-label, .wr-group-label { min-height: 44px; }
  .wr-bulk button { min-height: 44px; }
}
body.wg-export .wr-search, body.wg-export .wr-bulk, body.wg-export .wr-toggle { display: none !important; }
@media (max-width: 640px) {
  /* Keep part of the map tappable while the legend is open; the legend scrolls inside. */
  .wg-map-legends { max-height: min(62dvh, calc(100dvh - 9rem)) !important; }
  .wr-legend-layer { margin-bottom: 0.1rem; }
}
.wr-group-label { margin-bottom: 0.25rem; }

/* ---------- Style pass (Mark, Nov 28, 2026) ---------- */
.wg-map {
  --wg-title-max: 20.5rem;
  --wg-legend-max: 17.25rem;
}
.wg-map-subtitle { text-wrap: pretty; }

/* Popups: tight label/value grid on desktop, stacked rows on phones. */
.wr-popup .popup-row {
  display: grid;
  grid-template-columns: minmax(7.4rem, 0.42fr) minmax(0, 1fr);
  gap: 0.12rem 0.7rem;
  align-items: start;
  margin: 0 0 0.32rem;
  justify-content: stretch;
}
.wr-popup .popup-label {
  line-height: 1.3;
  overflow-wrap: break-word;
  text-wrap: pretty;
}
.wr-popup .popup-value {
  text-align: right;
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: break-word;
  word-break: normal;
  hyphens: manual;
  min-width: 0;
}
.wr-popup .popup-credits .popup-row {
  display: block;
}
.wr-popup .popup-credits .popup-label {
  display: block;
  margin-bottom: 0.12rem;
}
.wr-popup .popup-credits .popup-value {
  display: block;
  text-align: left;
  font-weight: 500;
}

/* Legend class rows: count stays right, long official names wrap on a word. */
.wg-legend-sublist .wg-legend-class {
  flex-wrap: nowrap;
}
.wg-legend-sublist .wg-legend-class .wg-class-label {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  align-items: start;
  column-gap: 0.4rem;
  width: 100%;
}
.wg-legend-sublist .wg-legend-item:not(.wg-legend-class) {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  column-gap: 0.4rem;
}
.wg-legend-sublist .wg-legend-label {
  min-width: 0;
  line-height: 1.3;
}
.wr-count { align-self: start; padding-top: 0.05rem; }

@media (max-width: 640px) {
  /* Template caps the open legend at 15.5rem, which wraps "Riparian Scrub Shrub" mid phrase.
     Only widen the open panel; the collapsed Legend chip stays auto width. */
  .wg-map-legends:has(.wg-map-legend-collapse:checked),
  .wg-map-legend:has(.wg-map-legend-collapse:checked) {
    width: min(17.25rem, calc(100% - 2 * var(--wg-overlay-inset, 0.6rem)));
    max-width: min(17.25rem, calc(100% - 2 * var(--wg-overlay-inset, 0.6rem)));
  }
  .wr-popup .popup-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.08rem;
    margin: 0 0 0.42rem;
  }
  .wr-popup .popup-label { font-size: 0.7rem; }
  .wr-popup .popup-value { text-align: left; }
  .wr-search input[type="search"] { text-overflow: ellipsis; }
  /* Leave room for zoom and attribution under a tall popup. */
  .leaflet-popup-content-wrapper {
    max-height: min(52dvh, calc(100dvh - 9.5rem));
  }
  .leaflet-popup-content {
    max-height: min(48dvh, calc(100dvh - 11rem));
    overflow-wrap: break-word;
    word-break: normal;
  }
}

/* Export still: keep the full credit line in frame, and show the data footer. */
body.wg-export {
  --wg-title-max: 22rem;
  --wg-legend-max: 18rem;
}
body.wg-export .leaflet-bottom {
  bottom: calc(var(--wg-info-footer-height, 0px) + 0.55rem);
}
body.wg-export .leaflet-control-attribution {
  max-width: calc(100vw - 2rem);
  line-height: 1.35;
  padding: 0.18rem 0.5rem;
}
body.wg-export .wg-map-footer,
body.wg-export .wg-map-footer.wr-export-footer {
  display: block !important;
  text-align: center;
}
body.wg-export .wg-map-footer .wg-footer-toggle,
body.wg-export .wg-map-footer .wg-info-footer { display: none !important; }
body.wg-export .wg-data-footer {
  display: block !important;
  font-size: 0.78rem;
  padding: 0.35rem 0.8rem 0.45rem;
}

/* Export still: room for the widest legend count (Tech, Nov 28, 2026). */
body.wg-export .wg-map { --wg-legend-max: 19.25rem; }
