/* ==========================================================================
   D2K layer panel
   Sits inside the map container, top-left. No build step, no framework.

   THEMING
   -------
   Everything below is driven by the custom properties in this first block.
   They default to Bootstrap 5.3 theme variables, so the panel inherits the
   site palette automatically and follows [data-bs-theme] without extra work.
   If the map chrome uses colours that are not the page body colours, pin
   them here and nowhere else.
   ========================================================================== */

.lp,
.lp-handle {
  --lp-bg:            var(--bs-body-bg, #fff);
  --lp-bg-raised:     var(--bs-tertiary-bg, rgba(0, 0, 0, .04));
  --lp-fg:            var(--bs-body-color, #212529);
  --lp-fg-muted:      var(--bs-secondary-color, rgba(33, 37, 41, .65));
  --lp-border:        var(--bs-border-color, #dee2e6);
  --lp-accent:        var(--bs-primary, #0d6efd);
  --lp-accent-soft:   color-mix(in srgb, var(--lp-accent) 14%, transparent);
  --lp-radius:        var(--bs-border-radius, .375rem);
  --lp-width:         21rem;
  --lp-map-radius:    .75rem;   /* matches #map's border-radius in map.html */
  --lp-row-height:    2rem;
}

/* --------------------------------------------------------------- shell -- */

.lp {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 1000;                 /* above Leaflet panes, below Bootstrap modals */
  width: var(--lp-width);
  max-width: 85%;
  display: flex;
  flex-direction: column;
  background: var(--lp-bg);
  color: var(--lp-fg);
  border-right: 1px solid var(--lp-border);
  /* #map is rounded at .75rem; match its left corners so the panel sits
     flush inside it rather than squaring them off. */
  border-radius: var(--lp-map-radius) 0 0 var(--lp-map-radius);
  box-shadow: .25rem 0 1rem rgba(0, 0, 0, .16);
  font-size: .875rem;
  overflow: hidden;
  transform: translateX(0);
  transition: transform .2s ease;
}

/* Collapsed: the whole drawer slides out through the left edge of the map.
   The handle is a sibling so it is not clipped away with it. */
.lp[data-collapsed="true"] {
  transform: translateX(-100%);
  box-shadow: none;
}

/* Leaflet sets cursor/handlers on everything inside the map container. */
.lp,
.lp * {
  cursor: default;
}

/* -------------------------------------------------------------- handle -- */

.lp-handle {
  position: absolute;
  top: 50%;
  left: var(--lp-width);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.375rem;
  height: 4rem;
  padding: 0;
  transform: translateY(-50%);
  border: 1px solid var(--lp-border);
  border-left: 0;
  border-radius: 0 var(--lp-radius) var(--lp-radius) 0;
  background: var(--lp-bg);
  color: var(--lp-fg-muted);
  box-shadow: .125rem 0 .5rem rgba(0, 0, 0, .14);
  transition: left .2s ease;
}

.lp-handle:hover { color: var(--lp-fg); }

.lp-handle:focus-visible {
  outline: 2px solid var(--lp-accent);
  outline-offset: 2px;
}

.lp-handle .lp-chevron {
  width: .75rem;
  height: .75rem;
  transform: rotate(90deg);
}

.lp[data-collapsed="true"] ~ .lp-handle {
  left: 0;
}

.lp[data-collapsed="true"] ~ .lp-handle .lp-chevron {
  transform: rotate(-90deg);
}

.lp__head {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .625rem .75rem;
  border-bottom: 1px solid var(--lp-border);
  background: var(--lp-bg-raised);
  flex: 0 0 auto;
}

.lp__title {
  font-size: .8125rem;
  font-weight: 600;
  letter-spacing: .01em;
  margin: 0;
}

.lp__count {
  margin-left: auto;
  min-width: 1.5rem;
  padding: 0 .375rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: .75rem;
  line-height: 1.25rem;
  border-radius: 999px;
  background: var(--lp-accent-soft);
  color: var(--lp-accent);
}

.lp__count[data-empty="true"] {
  background: transparent;
  color: var(--lp-fg-muted);
}

/* -------------------------------------------------------------- search -- */

.lp__search {
  flex: 0 0 auto;
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--lp-border);
}

.lp__search input {
  width: 100%;
  padding: .3125rem .5rem;
  font-size: .8125rem;
  color: var(--lp-fg);
  background: var(--lp-bg-raised);
  border: 1px solid var(--lp-border);
  border-radius: var(--lp-radius);
}

.lp__search input::placeholder { color: var(--lp-fg-muted); }

.lp__search input:focus-visible {
  outline: 2px solid var(--lp-accent);
  outline-offset: 1px;
  border-color: transparent;
}

/* ---------------------------------------------------------------- body -- */

.lp__body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: .25rem 0 .375rem;
}

/* ------------------------------------------------------------- groups -- */

.lp-group { border-bottom: 1px solid transparent; }

.lp-group__head {
  display: flex;
  align-items: center;
  gap: .375rem;
  width: 100%;
  min-height: var(--lp-row-height);
  padding: .25rem .625rem .25rem .375rem;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  font-size: .8125rem;
  font-weight: 600;
}

.lp-group__head:hover { background: var(--lp-bg-raised); }

.lp-group__head:focus-visible {
  outline: 2px solid var(--lp-accent);
  outline-offset: -2px;
}

/* The one deliberate flourish: a rail down the left of a group, lit while
   anything inside it is drawn on the map. With eight collapsed groups this
   is the only way to see at a glance what is contributing to the view. */
.lp-group__rail {
  flex: 0 0 3px;
  align-self: stretch;
  border-radius: 3px;
  background: transparent;
  margin-right: .125rem;
}

.lp-group[data-active="true"] > .lp-group__head .lp-group__rail {
  background: var(--lp-accent);
}

.lp-group__label { flex: 1 1 auto; }

.lp-group__tally {
  font-size: .6875rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--lp-fg-muted);
}

.lp-group__body { padding: .125rem 0 .375rem 1.25rem; }

.lp-group[data-open="false"] > .lp-group__body { display: none; }

.lp-group[data-open="false"] > .lp-group__head .lp-chevron { transform: rotate(-90deg); }

/* --------------------------------------------------------------- rows -- */

.lp-layer {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-height: var(--lp-row-height);
  padding: .1875rem .625rem .1875rem .375rem;
  border-radius: var(--lp-radius);
}

.lp-layer:hover { background: var(--lp-bg-raised); }

.lp-layer__box {
  flex: 0 0 auto;
  width: .9375rem;
  height: .9375rem;
  margin: 0;
  accent-color: var(--lp-accent);
}

.lp-layer__box:focus-visible {
  outline: 2px solid var(--lp-accent);
  outline-offset: 2px;
}

.lp-layer__label {
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Swatch for layers that have a fixed symbology. */
.lp-layer__swatch {
  flex: 0 0 auto;
  width: .75rem;
  height: .75rem;
  border-radius: 2px;
  border: 1px solid var(--lp-border);
}

.lp-layer__meta {
  flex: 0 0 auto;
  display: inline-flex;
  width: 1rem;
  height: 1rem;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid var(--lp-border);
  color: var(--lp-fg-muted);
  font-size: .625rem;
  font-weight: 700;
}

.lp-layer__meta:hover { color: var(--lp-fg); border-color: currentColor; }

/* ------------------------------------------------------------ opacity -- */
/* One slider per group, shown only while something in the group is drawn.
   Replaces geology_layer.js's floating OpacityControl, which did the same
   thing from the top-right corner. */

.lp-group__opacity {
  display: none;
  align-items: center;
  gap: .5rem;
  padding: .1875rem .625rem .3125rem .375rem;
}

.lp-group[data-active="true"] > .lp-group__body > .lp-group__opacity {
  display: flex;
}

.lp-group__opacity input {
  flex: 1 1 auto;
  height: 1rem;
  accent-color: var(--lp-accent);
}

.lp-group__opacity span {
  flex: 0 0 auto;
  font-size: .6875rem;
  color: var(--lp-fg-muted);
}

.lp-group__opacity output {
  flex: 0 0 2.25rem;
  text-align: right;
  font-size: .6875rem;
  font-variant-numeric: tabular-nums;
  color: var(--lp-fg-muted);
}

/* ------------------------------------------------------------- locked -- */

.lp-group[data-locked="true"] .lp-layer-item { opacity: .5; }

.lp-group[data-locked="true"] .lp-layer__box { pointer-events: none; }

.lp-lock {
  display: block;
  margin: .125rem .625rem .375rem 0;
  padding: .3125rem .5rem;
  font-size: .75rem;
  border-radius: var(--lp-radius);
  border: 1px dashed var(--lp-border);
  color: var(--lp-accent);
  background: var(--lp-accent-soft);
  text-decoration: none;
}

.lp-lock:hover { text-decoration: underline; }

/* -------------------------------------------------------------- empty -- */

.lp__empty {
  display: none;
  padding: 1rem .75rem;
  color: var(--lp-fg-muted);
  font-size: .8125rem;
}

.lp[data-no-results="true"] .lp__empty { display: block; }

/* --------------------------------------------------------------- foot -- */

.lp__foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .5rem .75rem;
  border-top: 1px solid var(--lp-border);
  background: var(--lp-bg-raised);
}

.lp__foot button {
  border: 0;
  background: transparent;
  padding: 0;
  font-size: .75rem;
  color: var(--lp-fg-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.lp__foot button:hover { color: var(--lp-fg); }

.lp__foot button:disabled { opacity: .45; text-decoration: none; }

/* ------------------------------------------------------------ chevron -- */

.lp-chevron {
  flex: 0 0 auto;
  width: .625rem;
  height: .625rem;
  transition: transform .12s ease;
}

/* -------------------------------------------------- filtering + hidden -- */

.lp-group[hidden],
.lp-layer-item[hidden] { display: none !important; }

@media (max-width: 575.98px) {
  .lp { --lp-width: 17rem; }
}

@media (prefers-reduced-motion: reduce) {
  .lp,
  .lp-handle,
  .lp-chevron { transition: none; }
}
