/* Map component styles */

/* Fix for Leaflet marker shadows in dark mode */
.leaflet-shadow-pane {
  display: none;
}

/* Ensure popups are readable in dark mode */
.leaflet-popup-content-wrapper {
  background-color: #f8f9fa;
  color: #212529;
}

.leaflet-popup-tip {
  background-color: #f8f9fa;
}

/* Make the map container responsive */
.leaflet-container {
  width: 100%;
  height: 100%;
  min-height: 300px;
  border-radius: 0.375rem;
}

/* Ensure controls are visible on dark backgrounds */
.leaflet-control-zoom a {
  background-color: var(--color-background-card) !important;
  color: var(--color-foreground) !important;
  border-color: var(--color-border) !important;
  font-weight: bold !important;
  font-size: 18px !important;
  font-family: 'Lucida Console', Monaco, monospace !important;
  text-indent: 1px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 30px !important;
  height: 30px !important;
}

/* Ensure attribution is readable */
.leaflet-control-attribution {
  background-color: rgba(255, 255, 255, 0.8) !important;
  color: #212529 !important;
  font-size: 10px !important;
}

/* Fix for map container in dark mode */
[data-map-target="container"] {
  background-color: #1f2937;
  border-radius: 0.375rem;
  overflow: hidden;
}

/* Device marker styles */
.device-marker {
  z-index: 850 !important; /* Above map tiles but below controls */
  background: transparent !important;
  border: none !important;
}

/* Fix for device icon container */
.device-icon-container {
  position: relative;
  width: 32px !important;
  height: 32px !important;
  display: block !important;
}

/* Fix for inner black circle */
.device-icon-container > div:nth-child(2) {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

/* Fix for SVG in device markers */
.device-marker svg {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 16px !important;
  height: 16px !important;
}

/* Zone map labels (all Leaflet zone polygons) */
/* Above device markers (z-index 850) so names stay readable; clicks pass through. */
.zone-map-label {
  z-index: 860 !important;
  background: transparent !important;
  border: none !important;
  pointer-events: none;
}

/* Centered on the zone centroid: the marker sits at the point, the strip
   translates itself so its middle lands there. */
.zone-map-label__text {
  display: inline-block;
  transform: translate(-50%, -50%);
  padding: 0.1875rem 0.5rem;
  border-radius: 0.125rem;
  background: var(--color-zone-map-label-bg);
  color: var(--color-zone-map-label-text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  line-height: 1.2;
  text-transform: uppercase;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.zone-map-label__text--retired {
  color: var(--color-foreground-muted);
}

.leaflet-tooltip.zone-map-label-tooltip {
  background: var(--color-zone-map-label-bg);
  border: none;
  border-radius: 0.125rem;
  color: var(--color-zone-map-label-text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  line-height: 1.2;
  padding: 0.1875rem 0.5rem;
  text-transform: uppercase;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

/* Map legend swatch mirroring the zone polygon (stroke over dark shadow, faint fill). */
.zone-map-legend-swatch {
  height: 0.75rem;
  width: 2rem;
  flex-shrink: 0;
  border: 1.5px solid var(--color-zone-map-stroke);
  background: color-mix(in srgb, var(--color-zone-map-fill) 22%, transparent);
  box-shadow: 0 0 0 1px var(--color-zone-map-shadow);
}

/* Zone editor vertex handles (Leaflet.draw), only shown while drawing/editing. */
[data-controller="zone-polygon-drawer"] .leaflet-editing-icon {
  border-radius: 0;
  background: var(--color-zone-map-handle-fill);
  border: 1.5px solid var(--color-zone-map-handle-border);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35), 0 1px 3px rgba(0, 0, 0, 0.5);
}

.leaflet-tooltip.zone-map-label-tooltip::before {
  display: none;
}

/* Remove default Leaflet icon styles for our custom markers */
/* Device location picker pin (divIcon: no image assets) */
.device-location-marker-icon {
  background: transparent;
  border: none;
}

/* Device location + direction overlays sit on satellite imagery in both
   themes, so they use a fixed high-contrast palette instead of theme tokens. */
.device-location-marker-icon,
.device-heading-cone-icon,
.device-heading-aim-handle-icon {
  --map-aim-accent: #e1f224;
  --map-aim-ink: #1c1e14;
  background: transparent;
  border: none;
}

.device-location-marker-dot {
  display: block;
  width: 22px;
  height: 22px;
  margin: 3px;
  border-radius: 9999px;
  background: var(--map-aim-ink);
  border: 3px solid var(--map-aim-accent);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}

.device-heading-cone-icon {
  pointer-events: none;
}

.device-heading-cone-icon svg {
  display: block;
  overflow: visible;
  transform-origin: 50% 50%;
}

.device-heading-cone-path {
  fill: var(--map-aim-accent);
  fill-opacity: 0.18;
  stroke: var(--map-aim-accent);
  stroke-width: 1.5;
  stroke-linejoin: round;
}

.device-heading-aim-line {
  stroke: var(--map-aim-accent, #e1f224);
  stroke-opacity: 0.9;
}

.device-heading-aim-handle-icon {
  cursor: grab;
}

.device-heading-aim-handle-icon:active {
  cursor: grabbing;
}

.device-heading-aim-handle {
  display: block;
  width: 24px;
  height: 24px;
  margin: 2px;
  border-radius: 9999px;
  background: var(--map-aim-accent);
  border: 3px solid var(--map-aim-ink);
  box-shadow: 0 0 0 2px rgba(225, 242, 36, 0.35), 0 2px 6px rgba(0, 0, 0, 0.45);
}

.device-heading-aim-label {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, calc(-50% - 34px));
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(28, 30, 20, 0.88);
  border: 1px solid rgba(225, 242, 36, 0.5);
  color: #f4f6e8;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
}

.device-marker.leaflet-marker-icon {
  background: transparent !important;
  border: none !important;
  width: 32px !important;
  height: 32px !important;
  margin-left: -16px !important;
  margin-top: -16px !important;
}

/* Leaflet.draw toolbar: match app map controls (zone polygon editor) */
[data-controller="zone-polygon-drawer"] .leaflet-top.leaflet-right {
  margin-top: 10px !important;
  margin-right: 10px !important;
}

[data-controller="zone-polygon-drawer"] .leaflet-top.leaflet-left {
  margin-top: 10px !important;
  margin-left: 10px !important;
}

.leaflet-draw-toolbar {
  margin-top: 0 !important;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06) !important;
}

.leaflet-draw-toolbar a {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 30px !important;
  height: 30px !important;
  background-color: var(--color-background-card) !important;
  background-image: none !important;
  border: 1px solid var(--color-border) !important;
  color: var(--color-foreground) !important;
}

.leaflet-draw-toolbar a:hover {
  background-color: var(--color-background-muted) !important;
}

.leaflet-draw-toolbar a.leaflet-draw-edit-remove {
  margin-top: 6px !important;
}

.leaflet-draw-toolbar a svg {
  width: 18px !important;
  height: 18px !important;
  stroke: currentColor !important;
}

.leaflet-draw-toolbar .leaflet-disabled {
  opacity: 0.45 !important;
  cursor: not-allowed !important;
}

/* Edit-mode Save/Cancel: horizontal bar beside toolbar (default Leaflet layout) */
.leaflet-draw-actions {
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06) !important;
}

.leaflet-draw-actions a {
  background-color: var(--color-background-card) !important;
  border: 1px solid var(--color-border) !important;
  color: var(--color-foreground) !important;
  font: 500 12px/30px system-ui, sans-serif !important;
  height: 30px !important;
  line-height: 30px !important;
  padding: 0 12px !important;
  text-decoration: none !important;
}

.leaflet-draw-actions a:hover {
  background-color: var(--color-background-muted) !important;
}

/* Save: primary action */
.leaflet-draw-actions li:first-child a {
  background-color: var(--color-brand-secondary) !important;
  border-color: var(--color-brand-secondary) !important;
  color: var(--color-brand-secondary-fg, #fafbfc) !important;
}

.leaflet-draw-actions li:first-child a:hover {
  background-color: var(--color-brand-secondary-800, var(--color-brand-secondary)) !important;
}

/* Mobile: larger touch targets; stack Save/Cancel above edit tools */
@media (max-width: 767px) {
  [data-controller="zone-polygon-drawer"] .leaflet-draw-toolbar a {
    width: 44px !important;
    height: 44px !important;
  }

  [data-controller="zone-polygon-drawer"] .leaflet-draw-toolbar a svg {
    width: 20px !important;
    height: 20px !important;
  }

  [data-controller="zone-polygon-drawer"] .leaflet-draw-toolbar a.leaflet-draw-edit-remove {
    margin-top: 8px !important;
  }

  [data-controller="zone-polygon-drawer"] .leaflet-right .leaflet-draw-actions {
    right: 0 !important;
    left: auto !important;
    top: auto !important;
    bottom: calc(100% + 6px) !important;
    white-space: normal !important;
  }

  [data-controller="zone-polygon-drawer"] .leaflet-right .leaflet-draw-actions li {
    display: block !important;
  }

  [data-controller="zone-polygon-drawer"] .leaflet-right .leaflet-draw-actions li + li {
    margin-top: 4px !important;
  }

  [data-controller="zone-polygon-drawer"] .leaflet-draw-actions a {
    min-width: 6.5rem !important;
    height: 44px !important;
    line-height: 44px !important;
    padding: 0 16px !important;
    border-radius: 4px !important;
    text-align: center !important;
  }
}

/* Draw tooltips */
.leaflet-draw-tooltip {
  background: color-mix(in srgb, var(--color-background-card) 92%, transparent) !important;
  border: 1px solid var(--color-border) !important;
  color: var(--color-foreground) !important;
  font-size: 12px !important;
}

.leaflet-draw-tooltip::before {
  border-right-color: var(--color-border) !important;
}

.leaflet-error-draw-tooltip {
  background-color: color-mix(in srgb, var(--color-error) 15%, var(--color-background-card)) !important;
  border-color: var(--color-error) !important;
  color: var(--color-error) !important;
}

.leaflet-error-draw-tooltip::before {
  border-right-color: var(--color-error) !important;
}

/* Console map shell overlays share the zone palette: pale lime accent on dark
   ink, fixed in both themes because they sit on satellite imagery. */
.console-edge-unit,
.console-observation-pill,
.console-map-legend,
.console-map-chip {
  --console-map-accent: var(--color-zone-map-stroke);
  --console-map-ink: #1c1e14;
  --console-map-panel: var(--color-zone-map-label-bg);
  --console-map-text: #f4f6e8;
}

.console-edge-unit {
  background: transparent;
  border: none;
}

.console-edge-unit__dot {
  position: relative;
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 9999px;
  background: var(--console-map-ink);
  border: 2.5px solid var(--console-map-accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  transition: transform 120ms ease-out, box-shadow 120ms ease-out;
}

.console-edge-unit__dot::after {
  content: "";
  position: absolute;
  top: -4px;
  right: -4px;
  display: none;
  width: 8px;
  height: 8px;
  border-radius: 9999px;
  border: 1.5px solid var(--console-map-ink);
}

.console-edge-unit__dot[data-connectivity="warn"]::after {
  display: block;
  background: #f59e0b;
}

.console-edge-unit__dot[data-connectivity="down"]::after {
  display: block;
  background: #ef4444;
}

.console-edge-unit__dot[data-connectivity="idle"] {
  border-color: color-mix(in srgb, var(--console-map-accent) 45%, transparent);
}

/* Active situation on the device: the ring takes the worst situation's
   severity; critical and high pulse a halo in the same color. */
.console-edge-unit__dot[data-situation] {
  --console-situation-color: #3b82f6;
  border-width: 3px;
  border-color: var(--console-situation-color);
}

.console-edge-unit__dot[data-situation="medium"] { --console-situation-color: #eab308; }
.console-edge-unit__dot[data-situation="high"] { --console-situation-color: #f97316; }
.console-edge-unit__dot[data-situation="critical"] { --console-situation-color: #ef4444; }

.console-edge-unit__dot[data-situation="high"]::before,
.console-edge-unit__dot[data-situation="critical"]::before {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 9999px;
  border: 2px solid var(--console-situation-color);
  pointer-events: none;
  animation: console-situation-pulse 1.8s ease-out infinite;
}

@keyframes console-situation-pulse {
  from { transform: scale(1); opacity: 0.85; }
  to { transform: scale(2.1); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .console-edge-unit__dot[data-situation]::before { animation: none; opacity: 0.5; transform: scale(1.5); }
}

.console-map-hide-situation-rings .console-edge-unit__dot[data-situation] {
  border-width: 2.5px;
  border-color: var(--console-map-accent);
}

.console-map-hide-situation-rings .console-edge-unit__dot[data-situation]::before {
  display: none;
}

/* Facing direction when zoomed out too far for the 40 m detection sector:
   rotates around the dot, with the arrowhead just outside the ring. */
.console-edge-unit__arrow {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
  transform-origin: 50% 50%;
}

.console-edge-unit__arrow::before {
  content: "";
  position: absolute;
  top: -8px;
  left: 50%;
  margin-left: -4.5px;
  border-left: 4.5px solid transparent;
  border-right: 4.5px solid transparent;
  border-bottom: 7px solid var(--console-map-accent);
  filter: drop-shadow(0 0 1px var(--console-map-ink));
}

.console-map-compact-devices .console-edge-unit__arrow {
  display: block;
}

/* Hovered or selected device. Leaflet positions the marker element with
   transform, so emphasis scales the inner dot instead. */
.console-map-marker-emphasized .console-edge-unit__dot {
  transform: scale(1.25);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--console-map-accent) 40%, transparent), 0 1px 4px rgba(0, 0, 0, 0.5);
}

/* Observation count for a camera, pinned to the lower right of its dot. */
.console-observation-pill {
  background: transparent;
  border: none;
}

.console-observation-pill__count,
.console-map-legend-observation {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 16px;
  padding: 0 4px;
  border-radius: 9999px;
  /* History, not live: muted next to the situation rings. */
  background: #cfccc0;
  color: #44473a;
  border: 1.5px solid #5d6050;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
}

.console-observation-pill__count {
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  transition: transform 120ms ease-out, box-shadow 120ms ease-out;
}

.console-map-marker-emphasized .console-observation-pill__count {
  transform: scale(1.15);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--console-map-accent) 45%, transparent), 0 1px 4px rgba(0, 0, 0, 0.5);
}

.console-map-window-caption {
  opacity: 0.75;
}

.console-map-legend-observation::before {
  content: "3";
}

.console-map-legend {
  background: var(--console-map-panel);
  color: var(--console-map-text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.console-map-legend .zone-map-legend-swatch {
  width: 0.875rem;
  height: 0.75rem;
}

.console-map-legend .console-edge-unit__dot {
  width: 0.875rem;
  height: 0.875rem;
  border-width: 2px;
}

.console-map-legend-cone {
  width: 0.875rem;
  height: 0.75rem;
  background: color-mix(in srgb, var(--console-map-accent) 60%, transparent);
  clip-path: polygon(50% 100%, 0 0, 100% 0);
}

.console-map-legend-arrow {
  width: 0;
  height: 0;
  margin: 0 2.5px;
  border-left: 4.5px solid transparent;
  border-right: 4.5px solid transparent;
  border-bottom: 7px solid var(--console-map-accent);
}

.console-map-legend .console-map-legend-situation {
  border-color: #f97316;
}

/* Layer toggles drawn on the map, styled like the legend. */
.console-map-chip {
  background: var(--console-map-panel);
  color: color-mix(in srgb, var(--console-map-text) 65%, transparent);
  border: 1px solid transparent;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.console-map-chip:hover {
  color: var(--console-map-text);
}

.console-map-chip:has(:checked) {
  color: var(--console-map-accent);
  border-color: color-mix(in srgb, var(--console-map-accent) 55%, transparent);
}

.console-map-chip:has(:focus-visible) {
  outline: 2px solid var(--console-map-accent);
  outline-offset: 2px;
}

.console-map-chip input {
  accent-color: var(--console-map-accent);
}

/* Observation time range: one segmented chip, pressed segment in accent. */
.console-map-window {
  color: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
}

.console-map-window:hover {
  color: var(--console-map-text);
}

.console-map-window[aria-pressed="true"] {
  background: color-mix(in srgb, var(--console-map-accent) 18%, transparent);
  color: var(--console-map-accent);
}

.console-map-window:focus-visible {
  outline: none;
}
