/* ========================================
   Maps page — right-side detail panel

   Hidden by default. Shows when content lands in
   #incidents-col-detail-body or #alerts-col-detail-body via existing
   incident.edit_form / alert.edit_form SSE OOB pushes, OR when a
   new-create button creates an entity. Close button (X) clears the
   slots and the :has() selector hides the panel again. No JS state —
   DOM presence IS the state.

   When the panel is visible the map shrinks to leave room, the legend
   collapses to chevron-only, and the .map-controls cluster shifts
   left so its buttons stay clickable.

   Plan: docs/plans/maps-detail-panel-and-quick-create.md (Phase B).
   ======================================== */

:root {
  --maps-detail-panel-width: 420px;
}

.maps-col-detail {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--maps-detail-panel-width);
  max-width: 90vw;
  background: rgba(8, 13, 26, 0.92);
  border-left: 1px solid var(--color-border-light);
  color: var(--color-text);
  z-index: calc(var(--z-overlay) + 1);
  display: none;
  flex-direction: column;
  backdrop-filter: blur(4px);
}

/* Panel shows when any slot has content. */
.map-container:has(#incidents-col-detail-body:not(:empty)) .maps-col-detail,
.map-container:has(#alerts-col-detail-body:not(:empty)) .maps-col-detail,
.map-container:has(#geofences-col-detail-body:not(:empty)) .maps-col-detail {
  display: flex;
}

/* Map shrinks to leave the right column for the panel. */
.map-container:has(#incidents-col-detail-body:not(:empty)) #map,
.map-container:has(#alerts-col-detail-body:not(:empty)) #map,
.map-container:has(#geofences-col-detail-body:not(:empty)) #map {
  right: var(--maps-detail-panel-width);
}

/* .map-controls cluster shifts left so it stays clickable. */
.map-container:has(#incidents-col-detail-body:not(:empty)) .map-controls,
.map-container:has(#alerts-col-detail-body:not(:empty)) .map-controls,
.map-container:has(#geofences-col-detail-body:not(:empty)) .map-controls {
  right: calc(var(--maps-detail-panel-width) + var(--spacing-4));
}

/* Legend stays togglable regardless of detail-panel state — operators need
   to flip layers on/off while reviewing an alert/incident in the panel.
   Earlier this block force-collapsed the legend body when the panel was
   open; that locked out the layer checkboxes. */

.maps-col-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-3);
}

/* ========================================
   Maps canvas slot — full-bleed minimap

   When the operator clicks the Area+Geofence widget on an incident
   form in the detail panel, the server pushes the search canvas
   (templates/incidents/search_canvas.hbs) into #maps-canvas-slot via
   SSE OOB. The slot's :not(:empty) state hides the main #map and
   shows the canvas full-bleed (minus the right-side detail panel
   if it's open). Close-X inside the canvas (id inc-canvas-close-maps)
   clears the slot and map.js recentres on the incident.
   ======================================== */

.maps-canvas-slot {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  background: var(--color-bg, #0a0e1a);
  overflow: auto;
}

.map-container:has(#maps-canvas-slot:not(:empty)) .maps-canvas-slot {
  display: block;
}

/* Hide main #map and map-controls when the canvas slot is active —
   they're not interactable and the canvas covers them anyway. */
.map-container:has(#maps-canvas-slot:not(:empty)) #map,
.map-container:has(#maps-canvas-slot:not(:empty)) .map-controls,
.map-container:has(#maps-canvas-slot:not(:empty)) .map-legend-panel {
  display: none;
}

/* When detail panel is also open, canvas leaves room for it. */
.map-container:has(#maps-canvas-slot:not(:empty)):has(#incidents-col-detail-body:not(:empty)) .maps-canvas-slot,
.map-container:has(#maps-canvas-slot:not(:empty)):has(#alerts-col-detail-body:not(:empty)) .maps-canvas-slot,
.map-container:has(#maps-canvas-slot:not(:empty)):has(#geofences-col-detail-body:not(:empty)) .maps-canvas-slot {
  right: var(--maps-detail-panel-width);
}

/* Close-X button at the top right of the canvas — paired with the
   server-rendered #inc-canvas-close-maps button in the canvas
   toolbar. Toolbar already lays out as flex row; the button positions
   inline with the breadcrumb. */
.inc-canvas-close-maps {
  margin-left: auto;
}

/* ========================================
   Quick-create popovers (Phase C)

   .map-create-trigger buttons sit inside .map-controls. When clicked,
   map.js toggles aria-expanded and the matching popover's [hidden].
   Popovers position themselves to the LEFT of the .map-controls
   cluster so they don't get clipped by the right-side detail panel.
   ======================================== */

.map-create-popover {
  position: absolute;
  top: calc(var(--spacing-4) + 36px * 9);
  right: calc(var(--maps-detail-panel-width) + var(--spacing-4) + 44px);
  min-width: 180px;
  max-height: 60vh;
  overflow-y: auto;
  background: rgba(8, 13, 26, 0.94);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  padding: var(--spacing-1);
  z-index: calc(var(--z-overlay) + 2);
  display: flex;
  flex-direction: column;
  gap: 2px;
  backdrop-filter: blur(4px);
}

/* [hidden] attribute must beat display:flex above — author CSS wins
   over the UA stylesheet's [hidden]{display:none}, so restate it. */
.map-create-popover[hidden] {
  display: none;
}

/* When the detail panel is CLOSED, no need to leave room for it. */
.map-container:not(:has(#incidents-col-detail-body:not(:empty))):not(:has(#alerts-col-detail-body:not(:empty))):not(:has(#geofences-col-detail-body:not(:empty))) .map-create-popover {
  right: calc(var(--spacing-4) + 44px);
}

/* Anchor each popover roughly under its trigger. */
#map-new-incident-popover { top: calc(var(--spacing-4) + 36px * 9 + var(--spacing-1) * 9); }
#map-new-alert-popover { top: calc(var(--spacing-4) + 36px * 10 + var(--spacing-1) * 10); }

.map-create-heading {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--spacing-2) var(--spacing-2) var(--spacing-1);
}

.map-create-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--spacing-1) var(--spacing-2);
  background: none;
  border: none;
  color: var(--color-text);
  font-size: var(--font-size-sm);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.map-create-item:hover {
  background: var(--color-bg-overlay);
}

/* ========================================
   Geofence associations picker
   (templates/geofences/associations_list.hbs)

   Lands in #geofences-col-detail-body when an operator clicks a polygon
   that has 2+ alerts/incidents/dispatches. Styled to mirror the
   incident/dispatch detail panels: a panel header (geofence name + count
   meta) over labelled sections of selectable rows. Each row carries the
   level badge + name + status pill — the same chip vocabulary the detail
   forms use (alert-levels.css / incident-statuses.css).
   ======================================== */

.geofence-associations {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-4);
}

/* Panel header — geofence name + "1 alert · 2 dispatches" meta. */
.geofence-associations .form-section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--spacing-3);
  padding-bottom: var(--spacing-3);
  border-bottom: 1px solid var(--color-border);
}

.geofence-associations .form-section-title {
  margin: 0;
  font-size: var(--font-size-md, 1rem);
  font-weight: 600;
  color: var(--color-text);
}

.geofence-associations .form-section-meta {
  flex: none;
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* One labelled section per type (Alerts / Incidents / Dispatches). */
.geofence-associations .form-section-label {
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: var(--spacing-2);
}

.geofence-associations .assoc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-1);
}

/* Selectable row — full-width button, level badge + name + status pill. */
.geofence-associations .assoc-row {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
  width: 100%;
  text-align: left;
  padding: var(--spacing-2) var(--spacing-3);
  background: var(--color-surface, rgba(255, 255, 255, 0.03));
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.geofence-associations .assoc-row:hover {
  background: var(--color-surface-hover, rgba(255, 255, 255, 0.07));
  border-color: var(--color-border-light);
}

.geofence-associations .assoc-row-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--font-size-sm);
}

/* Badges/pills keep their own colour from alert-levels.css /
   incident-statuses.css; just stop them from being squeezed. */
.geofence-associations .assoc-row .alert-level-badge,
.geofence-associations .assoc-row .status-badge {
  flex: none;
}
