/* ═══════════════════════════════════════════════════════════════
   SHIELD AI — Map Panel Styles
   Leaflet overrides, map toolbar, layer toggles
   ═══════════════════════════════════════════════════════════════ */

/* ── S-039 / S-205: Map panel — amber top accent + line-draw boot ── */
/* S-099: Map vignette — surveillance lens effect */
.map-panel {
  display: flex;
  flex-direction: column;
  position: relative;
}

.map-panel > summary {
  cursor: pointer;
}
.map-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
  z-index: 1001;
  transform-origin: left;
  animation: line-draw 500ms ease-out 600ms both;
}

.map-panel::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 998;
  pointer-events: none;
  border-radius: var(--radius-sm);
  background: radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(15, 23, 42, 0.07) 100%);
}

/* S-185: Drawn polygon center label */
.drawn-label {
  background: rgba(255, 255, 255, 0.88) !important;
  color: #0f172a !important;
  border: 1px solid var(--accent-dim) !important;
  border-radius: var(--radius-pill) !important;
  font: 500 10px/1 var(--font-mono) !important;
  padding: 3px 8px !important;
  box-shadow: none !important;
  letter-spacing: 0.04em !important;
  pointer-events: none !important;
}

/* S-187: Zoom level indicator */
.zoom-indicator {
  font: 500 10px/1 var(--font-mono);
  color: var(--text-tertiary);
  background: rgba(255, 255, 255, 0.9);
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  pointer-events: none;
  margin-top: 4px !important;
  margin-left: 10px !important;
  letter-spacing: 0.06em;
}

/* S-102: Live cursor coordinates */
.map-coords {
  position: absolute;
  bottom: 6px;
  left: 6px;
  z-index: 1000;
  font: 400 10px/1 var(--font-mono);
  color: var(--text-tertiary);
  background: rgba(255, 255, 255, 0.92);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: opacity 150ms ease;
  pointer-events: none;
  letter-spacing: 0.04em;
}

/* S-147: Tile failure fallback for air-gapped networks */
.tile-fallback {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  font: 400 var(--text-sm)/1.3 var(--font-body);
  color: var(--text-tertiary);
  background: rgba(255, 255, 255, 0.92);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  white-space: nowrap;
  pointer-events: none;
}

/* S-145: Map desaturation when disconnected */
.map-panel.is-disconnected #map {
  filter: saturate(0.7) brightness(0.95);
  transition: filter 1s ease;
}

/* S-072: Map border amber pulse while analyzing */
@keyframes map-scanning {
  0%, 100% { border-color: var(--line); }
  50% { border-color: var(--accent-dim); }
}

#map.is-analyzing {
  animation: map-scanning 3s ease-in-out infinite;
}

/* S-078: Radar sweep during analysis */
.map-panel.is-analyzing {
  position: relative;
}

.map-panel.is-analyzing::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 999;
  pointer-events: none;
  border-radius: var(--radius-sm);
  background: conic-gradient(
    from 0deg at 50% 50%,
    transparent 0deg,
    transparent 345deg,
    rgba(212, 160, 25, 0.04) 355deg,
    rgba(212, 160, 25, 0.08) 358deg,
    rgba(212, 160, 25, 0.03) 360deg
  );
  animation: radar-sweep 4s linear infinite;
}

@keyframes radar-sweep {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* S-061: Map + progress bar as one surface */
#map {
  flex: 1;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 420px;
  height: auto;
  max-height: 68vh;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--line);
}

.map-toolbar {
  margin-bottom: var(--space-2);
}

/* S-092: Map hint collapses on draw, returns on clear */
.map-hint {
  font: 400 var(--text-sm)/1.4 var(--font-body);
  color: var(--accent);
  margin-bottom: var(--space-2);
  padding: var(--space-1) 0;
  opacity: 0.8;
  transition: opacity 400ms ease, max-height 400ms ease, margin 400ms ease, padding 400ms ease;
  max-height: 40px;
}

.map-hint.hidden {
  opacity: 0;
  max-height: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.layer-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: var(--bg-2);
  font: 500 var(--text-xs)/1 var(--font-display);
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color var(--transition-fast);
}

/* S-060: Layer toggle active state */
.layer-toggle {
  transition: border-color 200ms ease, background 200ms ease, color 200ms ease;
}

.layer-toggle:hover {
  border-color: var(--line-active);
}

.layer-toggle:has(input:checked) {
  border-color: var(--accent-dim);
  background: var(--accent-glow);
}

.layer-toggle:has(input:checked):hover {
  border-color: var(--accent);
}

.layer-toggle input:checked + span {
  color: var(--accent);
}

/* ── Scene widgets (above/below map) ── */
.scene-widgets {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-1); /* S-017: tight gaps */
  margin-bottom: var(--space-2);
}

.scene-panels {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-1); /* S-017: tight gaps */
}

/* ── S-006: Card cascade animation on results ── */
@keyframes card-arrive {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.scene-widgets .widget-card,
.scene-panels .scene-panel-card {
  animation: card-arrive 250ms ease-out both;
}

.scene-widgets .widget-card:nth-child(1) { animation-delay: 0ms; }
.scene-widgets .widget-card:nth-child(2) { animation-delay: 60ms; }
.scene-widgets .widget-card:nth-child(3) { animation-delay: 120ms; }
.scene-widgets .widget-card:nth-child(4) { animation-delay: 180ms; }
.scene-panels .scene-panel-card:nth-child(1) { animation-delay: 200ms; }
.scene-panels .scene-panel-card:nth-child(2) { animation-delay: 260ms; }
.scene-panels .scene-panel-card:nth-child(3) { animation-delay: 320ms; }

/* S-067: Alternating panel depth */
.scene-panel-card:nth-child(even) {
  background: var(--bg-1);
}

/* ── S-008: Tactical crosshair cursor on map ── */
#map { cursor: crosshair; }
.leaflet-container { cursor: crosshair !important; }
.leaflet-grab { cursor: crosshair !important; }
.leaflet-dragging .leaflet-grab { cursor: grabbing !important; }

/* ── Leaflet dark overrides ── */
.leaflet-container {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  background: var(--bg-0);
}

/* Zoom controls */
.leaflet-control-zoom a {
  background: var(--bg-2) !important;
  color: var(--text-primary) !important;
  border-color: var(--line) !important;
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
  font-size: 18px !important;
}

/* S-108: Amber border on zoom hover */
.leaflet-control-zoom a:hover {
  background: var(--bg-3) !important;
  border-color: var(--accent-dim) !important;
}

.leaflet-bar {
  border: 1px solid var(--line) !important;
  box-shadow: none !important;
  border-radius: var(--radius-sm) !important;
}

/* Draw controls dark theme — bigger, more visible */
.leaflet-draw-toolbar a {
  background-color: var(--bg-2) !important;
  border-color: var(--line-strong) !important;
  color: var(--text-primary) !important;
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
}

.leaflet-draw-toolbar a:hover {
  background-color: var(--accent-glow) !important;
  border-color: var(--accent) !important;
}

/* Make the draw toolbar stand out from the map */
.leaflet-draw.leaflet-control {
  margin-top: 12px !important;
}

/* Brighter border on the draw toolbar bar itself */
.leaflet-draw-toolbar {
  border: 1px solid var(--line-strong) !important;
  border-radius: var(--radius-sm) !important;
}

.leaflet-draw-section {
  border-color: var(--line) !important;
}

/* Draw action buttons (Finish, Delete last point, Cancel) */
.leaflet-draw-actions {
  background: var(--bg-2) !important;
  border-color: var(--line) !important;
  padding: 0 !important;
  margin: 0 !important;
}

.leaflet-draw-actions li {
  background: none !important;
  border: none !important;
}

.leaflet-draw-actions li:first-child a,
.leaflet-draw-actions li a {
  background: var(--bg-2) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--line) !important;
  font: 500 11px/1 var(--font-display) !important;
  padding: 6px 12px !important;
  text-decoration: none !important;
  white-space: nowrap !important;
}

.leaflet-draw-actions li a:hover {
  background: var(--bg-3) !important;
  color: var(--accent) !important;
}

/* Draw tooltip (the distance/area info popup) */
/* S-159: Amber draw tooltip matches polygon color */
.leaflet-draw-tooltip {
  background: var(--bg-0) !important;
  color: var(--accent) !important;
  border: 1px solid var(--accent-dim) !important;
  opacity: 0.9 !important;
  border-radius: var(--radius-sm) !important;
  font-family: var(--font-mono) !important;
  font-size: var(--text-xs) !important;
  padding: 4px 8px !important;
  box-shadow: none !important;
}

.leaflet-draw-tooltip-subtext {
  color: var(--text-secondary) !important;
}

/* Edit/delete toolbar */
.leaflet-draw-toolbar .leaflet-draw-edit-edit,
.leaflet-draw-toolbar .leaflet-draw-edit-remove {
  background-color: var(--bg-2) !important;
}

/* S-163: Country boundary tooltip */
.boundary-tooltip {
  background: var(--bg-0) !important;
  color: var(--accent) !important;
  border: 1px solid var(--accent-dim) !important;
  font: 500 var(--text-sm)/1 var(--font-mono) !important;
  padding: 4px 10px !important;
  border-radius: var(--radius-pill) !important;
  box-shadow: none !important;
}

.country-label {
  background: rgba(17, 35, 60, 0.66) !important;
  color: #eaf2ff !important;
  border: 1px solid rgba(130, 155, 188, 0.42) !important;
  border-radius: var(--radius-pill) !important;
  font: 600 9px/1 var(--font-mono) !important;
  letter-spacing: 0.04em !important;
  padding: 2px 6px !important;
  box-shadow: none !important;
  pointer-events: none !important;
}

.country-name-marker {
  background: transparent !important;
  border: none !important;
}

.country-name-inline {
  display: inline-block;
  transform: translate(-50%, -50%);
  background: rgba(17, 35, 60, 0.58);
  color: #eaf2ff;
  border: 1px solid rgba(130, 155, 188, 0.36);
  border-radius: 999px;
  font: 600 9px/1 var(--font-mono);
  letter-spacing: 0.03em;
  padding: 2px 5px;
  white-space: nowrap;
  pointer-events: none;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* S-074: Attribution fades on active map use */
.leaflet-control-attribution {
  background: rgba(10, 10, 11, 0.7) !important;
  color: var(--text-tertiary) !important;
  font-size: 9px !important;
  transition: opacity 300ms ease !important;
}

.leaflet-container:hover .leaflet-control-attribution {
  opacity: 0.3 !important;
}

.leaflet-interactive {
  transition: fill-opacity 160ms ease, stroke-opacity 160ms ease;
}

.leaflet-control-attribution a {
  color: var(--text-secondary) !important;
}

.leaflet-popup-content-wrapper {
  background: var(--bg-2) !important;
  color: var(--text-primary) !important;
  border-radius: var(--radius-sm) !important;
  box-shadow: none !important;
  border: 1px solid var(--line) !important;
}

.leaflet-popup-tip {
  background: var(--bg-2) !important;
}

/* S-064: Tooltip fade-up entrance */
.leaflet-tooltip {
  background: var(--bg-2) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--line) !important;
  border-radius: var(--radius-sm) !important;
  box-shadow: none !important;
  font-family: var(--font-mono) !important;
  font-size: var(--text-xs) !important;
  opacity: 0 !important;
  transform: translateY(4px) !important;
  transition: opacity 150ms ease, transform 150ms ease !important;
}

.leaflet-tooltip-pane .leaflet-tooltip {
  opacity: 1 !important;
  transform: translateY(0) !important;
}

.leaflet-tooltip-top::before { border-top-color: var(--bg-2) !important; }
.leaflet-tooltip-bottom::before { border-bottom-color: var(--bg-2) !important; }
.leaflet-tooltip-left::before { border-left-color: var(--bg-2) !important; }
.leaflet-tooltip-right::before { border-right-color: var(--bg-2) !important; }

/* ── Responsive ── */
@media (max-width: 1080px) {
  #map {
    aspect-ratio: 15 / 10;
    min-height: 360px;
    max-height: 62vh;
  }

  .scene-widgets,
  .scene-panels {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .scene-widgets,
  .scene-panels {
    grid-template-columns: 1fr;
  }
  #map {
    aspect-ratio: 4 / 3;
    min-height: 320px;
    max-height: 56vh;
  }
}

/* S-077: Tall monitors / portrait — map expands */
@media (min-height: 900px) and (max-width: 1400px) {
  #map { max-height: 80vh; }
}

@media (orientation: portrait) {
  #map { aspect-ratio: 4 / 3; min-height: 300px; max-height: 54vh; }
  .scene-widgets { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
