/* Mapping page — full-viewport height layout with layer tree sidebar */

/* ── Layout ── */
.map-fullpage {
  display: flex;
  flex-direction: row;
  border: 1px solid var(--bs-border-color, #dee2e6);
  border-radius: var(--varial-radius, 0.5rem);
  overflow: hidden;
  /* height set by JS to fill viewport from this element's top edge */
}

.map-canvas-wrap {
  flex: 0 0 50%;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

#nem-map {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  position: relative;
}

/* ── Map legend ── */
.map-legend {
  position: absolute;
  left: 0.75rem;
  bottom: 0.75rem;
  /* Sit above map tiles/markers but below Leaflet popups (700) and controls,
     so the legend no longer dominates the whole map stack. */
  z-index: 650;
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-start;
}

#nem-map.leaflet-container {
  background: #b7d4e5;
}

[data-bs-theme="dark"] #nem-map.leaflet-container {
  background: #0F172A;
}

.map-legend-trigger {
  border: 1px solid var(--bs-border-color, #dee2e6);
  background: var(--bs-body-bg, #fff);
  color: var(--bs-body-color, #212529);
  border-radius: 0.375rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.map-legend-panel {
  /* Absolutely anchored above the trigger button (out of normal flow) so the
     hidden panel doesn't enlarge the legend's hover target — the panel now
     only opens when the cursor is on the "Legend" button (or the panel
     itself), not anywhere over the panel's would-be footprint. Flush to the
     button top (no dead gap) keeps the hover bridge continuous. */
  position: absolute;
  left: 0;
  bottom: 100%;
  width: 16.5rem;
  max-height: 22rem;
  overflow-y: auto;
  border: 1px solid var(--bs-border-color, #dee2e6);
  border-radius: 0.5rem;
  background: var(--bs-body-bg, #fff);
  box-shadow: var(--varial-shadow-2, 0 0.4rem 1rem rgba(0, 0, 0, 0.16));
  padding: 0.5rem 0.625rem;
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition: opacity 0.14s ease, transform 0.14s ease;
}

.map-legend:hover .map-legend-panel,
.map-legend:focus-within .map-legend-panel {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.map-legend-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--bs-secondary-color, #6c757d);
  margin-bottom: 0.4rem;
}

.map-legend-group + .map-legend-group {
  margin-top: 0.5rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--bs-border-color, #dee2e6);
}

.map-legend-subtitle {
  font-size: 0.67rem;
  font-weight: 700;
  color: var(--bs-body-color, #212529);
  margin-bottom: 0.3rem;
}

.map-legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.66rem;
  color: var(--bs-secondary-color, #6c757d);
  margin-bottom: 0.18rem;
}

.map-legend-swatch,
.map-legend-dot,
.map-legend-circle {
  display: inline-block;
  flex-shrink: 0;
}

.map-legend-swatch {
  width: 0.82rem;
  height: 0.55rem;
  border-radius: 0.14rem;
  border: 1px solid var(--bs-border-color, #dee2e6);
}

.map-legend-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 999px;
}

.map-legend-circle {
  border-radius: 999px;
  border: 1px solid var(--bs-body-color, #212529);
  background: color-mix(in srgb, var(--bs-body-color, #212529) 15%, transparent);
}

/* ── Toolbar ── */
.map-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.375rem;
  padding: 0.4375rem 0.75rem;
  background: var(--bs-body-bg, #fff);
  border-bottom: 1px solid var(--bs-border-color, #dee2e6);
  flex-shrink: 0;
  z-index: 1000;
}

.map-toolbar-layers {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem;
  flex: 1 1 0;
  min-width: 0;
}

.map-toolbar-sep {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--bs-secondary-color, #6c757d);
  margin-right: 0.125rem;
  white-space: nowrap;
}

.map-toolbar-actions {
  display: flex;
  gap: 0.375rem;
  flex-shrink: 0;
}

/* Layer pill toggles */
.map-pill-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  padding: 0.1875rem 0.625rem;
  border-radius: 999px;
  border: 1px solid var(--bs-border-color, #dee2e6);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--bs-secondary-color, #6c757d);
  background: transparent;
  user-select: none;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  white-space: nowrap;
}

.map-pill-toggle input {
  display: none;
}

.map-pill-toggle:has(input:checked) {
  background: var(--varial-primary, #1B3AA0);
  color: var(--varial-white, #fff);
  border-color: var(--varial-primary, #1B3AA0);
}

/* Toolbar action buttons (Satellite / Reset zoom). Bootstrap's `btn-light` is a
   fixed white that clashes with the dark basemap + dark theme, so remap it onto
   theme tokens — like the layer pills, it now follows light/dark. The compound
   selector outscores Bootstrap's `.btn`/`.btn-light` rules without `!important`. */
.map-toolbar-actions .btn-light {
  background: var(--bs-tertiary-bg, #f8f9fa);
  border-color: var(--bs-border-color, #dee2e6);
  color: var(--bs-body-color, #212529);
}

.map-toolbar-actions .btn-light:hover,
.map-toolbar-actions .btn-light:focus-visible {
  background: var(--bs-secondary-bg, #e9ecef);
  border-color: var(--bs-border-color, #dee2e6);
  color: var(--bs-body-color, #212529);
}

/* Active = Satellite basemap engaged (JS toggles `.active`). */
.map-toolbar-actions .btn-light.active {
  background: var(--varial-primary, #1B3AA0);
  border-color: var(--varial-primary, #1B3AA0);
  color: var(--varial-white, #fff);
}

/* ── Tree sidebar ── */
.map-tree-sidebar {
  width: auto;
  flex: 0 0 50%;
  min-width: 360px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  border-left: 1px solid var(--bs-border-color, #dee2e6);
  background: var(--bs-body-bg, #fff);
}

.tree-sidebar-hd {
  padding: 0.5rem 0.875rem;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--bs-secondary-color, #6c757d);
  border-bottom: 1px solid var(--bs-border-color, #dee2e6);
  flex-shrink: 0;
  background: var(--bs-tertiary-bg, #f8f9fa);
}

.tree-section {
  border-bottom: 1px solid var(--bs-border-color, #dee2e6);
}

.tree-section-hd {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.4375rem 0.75rem;
}

.tree-section-hd .form-check-input {
  margin-top: 0;
  flex-shrink: 0;
}

.tree-caret {
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 0;
  color: var(--bs-secondary-color, #6c757d);
  cursor: pointer;
  width: 1.125rem;
  height: 1.125rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  transition: background 0.1s;
}

.tree-caret:hover {
  background: var(--bs-tertiary-bg, #f0f0f0);
}

.tree-caret .fa-chevron-right {
  transition: transform 0.15s;
  font-size: 0.5625rem;
}

.tree-caret:not(.collapsed) .fa-chevron-right {
  transform: rotate(90deg);
}

/* ── Year picker (inside collapsed generator section) ── */
.tree-year-picker {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem 0.25rem;
  border-bottom: 1px solid var(--bs-border-color, #dee2e6);
}
.tyb-range { flex: 1; min-width: 0; }
.tyb-label {
  font-size: 0.75rem;
  font-weight: 600;
  min-width: 2.5rem;
  text-align: center;
}
.tyb-btn {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--bs-border-color, #dee2e6);
  border-radius: 3px;
  padding: 0 0.3rem;
  font-size: 0.875rem;
  line-height: 1.4;
  cursor: pointer;
  color: var(--bs-body-color);
}
.tyb-btn:disabled { opacity: 0.4; cursor: default; }

.tree-section-name {
  flex: 1 1 0;
  min-width: 0;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-count-badge {
  flex-shrink: 0;
  font-size: 0.625rem;
  color: var(--bs-secondary-color, #6c757d);
  background: var(--bs-tertiary-bg, #f0f0f0);
  padding: 0.0625rem 0.375rem;
  border-radius: 999px;
  min-width: 1.5rem;
  text-align: center;
  white-space: nowrap;
}

.tree-items-wrap {
  overflow-y: auto;
  max-height: 42vh;
  background: var(--bs-tertiary-bg, #f8f9fa);
}

.tree-group-hd {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.1875rem 0.75rem;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--bs-secondary-color, #6c757d);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--bs-tertiary-bg, #f0f0f0) 90%, #000 10%);
  z-index: 1;
}

.tree-item {
  display: flex;
  align-items: flex-start;
  gap: 0.375rem;
  padding: 0.3125rem 0.875rem;
  font-size: 0.75rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
  cursor: pointer;
}

.tree-item:last-child {
  border-bottom: none;
}

.tree-item-code {
  font-family: monospace;
  font-size: 0.625rem;
  color: var(--bs-secondary-color, #6c757d);
  flex-shrink: 0;
  min-width: 3.5rem;
}

.tree-item-name {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-item-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1 1 0;
}

.tree-item-main {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  min-width: 0;
}

.tree-item-main.wrap {
  flex-wrap: wrap;
}

.tree-item-detail {
  font-size: 0.6875rem;
  color: var(--bs-secondary-color, #6c757d);
  white-space: normal;
  line-height: 1.25;
  margin-top: 0.125rem;
}

/* Columnar grid detail — hidden by default, revealed on row hover/focus */
.tree-item-detail.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.175rem 0.75rem;
  margin-top: 0;
  /* Collapsed */
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.18s ease, opacity 0.18s ease, margin-top 0.18s ease;
}

.tree-item:hover .tree-item-detail.grid,
.tree-item:focus-within .tree-item-detail.grid,
.tree-item.focused .tree-item-detail.grid {
  max-height: 10rem;
  opacity: 1;
  margin-top: 0.25rem;
}

.tree-item-field {
  font-size: 0.6625rem;
  color: var(--bs-secondary-color, #6c757d);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-item-field b {
  color: var(--bs-body-color, #2f2f2f);
  font-weight: 600;
}

.tree-fuel-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  display: inline-block;
  flex-shrink: 0;
}

.tree-fuel-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border-radius: 999px;
  padding: 0.06rem 0.4rem;
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  border: 1px solid var(--bs-border-color, #dee2e6);
  background: var(--bs-body-bg, #fff);
  color: var(--bs-body-color, #2f2f2f);
}

.tree-unit-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  width: 100%;
}

.tree-item-capacity {
  margin-left: auto;
  font-weight: 600;
  color: var(--bs-body-color, #2f2f2f);
  white-space: nowrap;
}

.tree-station {
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.tree-station:last-child {
  border-bottom: none;
}

.tree-station-summary {
  list-style: none;
  cursor: pointer;
  padding: 0.375rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.tree-item:hover,
.tree-station-summary:hover {
  background: color-mix(in srgb, var(--varial-primary, #1B3AA0) 6%, var(--varial-white, #fff) 94%);
}

.tree-item-focus {
  background: color-mix(in srgb, var(--varial-primary, #1B3AA0) 14%, var(--varial-white, #fff) 86%);
}

.tree-item--active {
  background: color-mix(in srgb, var(--varial-primary, #1B3AA0) 18%, var(--varial-white, #fff) 82%);
  outline: 2px solid color-mix(in srgb, var(--varial-primary, #1B3AA0) 40%, transparent);
  outline-offset: -1px;
  transition: background 0.8s ease-out, outline 0.8s ease-out;
}

.gen-table tbody tr.tree-item--active td {
  background: color-mix(in srgb, var(--varial-primary, #1B3AA0) 18%, var(--varial-white, #fff) 82%);
  outline: none;
  transition: background 0.8s ease-out;
}

.tree-station-summary::-webkit-details-marker {
  display: none;
}

.tree-units {
  padding-bottom: 0.1875rem;
}

.tree-item-unit {
  padding-left: 1.25rem;
}

@media (max-width: 1199.98px) {
  .map-canvas-wrap {
    flex-basis: 52%;
  }

  .map-tree-sidebar {
    flex-basis: 48%;
    min-width: 300px;
  }
}

@media (max-width: 991.98px) {
  .map-fullpage {
    flex-direction: column;
  }

  .map-canvas-wrap,
  .map-tree-sidebar {
    flex-basis: auto;
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .map-tree-sidebar {
    border-left: 0;
    border-top: 1px solid var(--bs-border-color, #dee2e6);
    max-height: 42vh;
  }
}

.tree-item-meta {
  flex-shrink: 0;
  font-size: 0.6875rem;
  color: var(--bs-secondary-color, #6c757d);
  white-space: nowrap;
}

.tree-empty,
.tree-loading {
  display: block;
  padding: 0.5rem 0.875rem;
  font-size: 0.75rem;
  color: var(--bs-secondary-color, #6c757d);
  font-style: italic;
}

/* ── Map labels ── */
.vrl-region-label span,
.varial-region-label span {
  background: rgba(0, 0, 0, 0.5);
  color: var(--varial-white, #fff);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.vrl-ic-label span,
.varial-ic-label span {
  background: rgba(220, 38, 38, 0.75);
  color: var(--varial-white, #fff);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}

.varial-rez-label span {
  background: rgba(5, 150, 105, 0.85);
  color: var(--varial-white, #fff);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}

.vrl-tx-excluded {
  opacity: 0.55;
  font-style: italic;
  color: var(--varial-muted, #6c757d);
}

/* ── Skeleton utilities ── */
.vrl-skeleton-chart-h260 {
  height: 260px;
}

.rez-chart-scenario-select {
  min-width: 220px;
}

.infra-summary-select {
  min-width: 140px;
}

@media (max-width: 767.98px) {
  .map-pill-toggle {
    font-size: 0.6875rem;
    padding: 0.125rem 0.4375rem;
  }

  .map-toolbar-sep {
    display: none;
  }

  .map-legend {
    display: none;
  }
}
