.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 30 !important;
}

.leaflet-div-icon {
  border: none;
  background-color: transparent;
}

.leaflet-container {
  overflow: hidden;
  z-index: 30 !important;
}

.leaflet-bottom {
  z-index: 30 !important;
}

#map {
  z-index: 0 !important;
}

/* Esri satellite: keep imagery below labels; markers stay at z-index 30 above both.
   Use .leaflet-pane.leaflet-esri-* so we beat the global .leaflet-pane { z-index: 30 }. */
.leaflet-pane.leaflet-esri-imagery-pane {
  z-index: 28 !important;
}

.leaflet-pane.leaflet-esri-reference-pane {
  z-index: 29 !important;
}

.leaflet-popup-pane,
.leaflet-control {
  z-index: 30 !important;
}

.leaflet-draw-section{
  position: relative;
  margin-right: 42px;
}

.leaflet-draw-toolbar a {
  background-image: linear-gradient(transparent, transparent),
                    url("/images/spritesheet.png") !important;
}


/* ============================================================================
   USER LIVE-POSITION MARKER (dot + heading beam)
   ============================================================================ */

.user-direction-icon {
  background: transparent;
  border: none;
}

.user-direction-marker {
  position: relative;
  width: 44px;
  height: 44px;
  pointer-events: none;
}

/* Directional cone ("shadow"), Google-Maps style: the apex (narrow point) is
   pinned to the icon center and the cone fans OUTWARD toward the heading. Both
   the element's bottom-center and its transform-origin land on the icon center
   (left:50% + bottom:50% + centered width), so rotating sweeps the cone around
   the worker with the point never leaving the center. Sits behind the icon
   (z-index) and fades out at the far edge for a soft beam, not a hard arrow. */
.user-direction-marker .udm-beam {
  position: absolute;
  left: 50%;
  bottom: 50%;
  width: 40px;
  height: 44px;
  margin-left: -20px;
  background: linear-gradient(to top, rgba(0, 150, 199, 0.55), rgba(0, 150, 199, 0));
  /* point at bottom-center (icon center), wide base at top (outward) */
  clip-path: polygon(50% 100%, 0% 0%, 100% 0%);
  transform-origin: bottom center;
  transition: transform 0.3s ease-out;
  z-index: 0;
}

/* ── Current user: Google-Maps navigation ("driving") arrow ───────────────
   A blue chevron that rotates to the direction of travel. The rotating element
   reuses .udm-beam (setBeamHeading applies rotate()), but here it's a solid
   chevron centered on the marker instead of the fan-out cone. A soft pulsing
   halo sits behind it. Overrides the base cone styles from .udm-beam above. */
.current-user-marker .udm-beam.nav-arrow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 30px;
  height: 34px;
  margin: -17px 0 0 -15px;
  /* Chevron: apex at top (north), notched tail at bottom. */
  clip-path: polygon(50% 0%, 100% 100%, 50% 74%, 0% 100%);
  background: #fff; /* white outline layer */
  transform-origin: center center;
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
  z-index: 2;
}

/* Inner blue chevron sits on top of the white one, slightly smaller, giving a
   crisp white outline. Gradient + top highlight for depth. */
.current-user-marker .udm-beam.nav-arrow::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 3px;
  width: 22px;
  height: 26px;
  margin-left: -11px;
  clip-path: polygon(50% 0%, 100% 100%, 50% 74%, 0% 100%);
  background: linear-gradient(160deg, #4a90ff 0%, #1a73e8 55%, #1257c9 100%);
}

/* Small grounding dot at the arrow's pivot — anchors it to the exact position. */
.current-user-marker .cum-accuracy {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  background: rgba(26, 115, 232, 0.9);
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.25);
  z-index: 1;
}

/* Expanding presence pulse, drawn behind everything via ::before. */
.current-user-marker .cum-accuracy::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  background: rgba(26, 115, 232, 0.35);
  border-radius: 50%;
  animation: cum-pulse 2.4s ease-out infinite;
}

@keyframes cum-pulse {
  0%   { transform: scale(1);   opacity: 0.55; }
  100% { transform: scale(4);   opacity: 0; }
}

/* The worker icon stays upright at the marker center, above the cone. */
.user-direction-marker .udm-icon {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.4));
  pointer-events: auto;
  z-index: 1;
}


/* ============================================================================
   MARKER ANIMATIONS
   ============================================================================ */

   .custom-trajectory-marker {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.15));
}

.custom-trajectory-marker:hover {
  transform: scale(1.15);
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.25));
  z-index: 1000;
}

/* Colorized hover glows per marker type */
.trajectory-marker-end:hover {
  filter: drop-shadow(0 8px 16px rgba(59, 130, 246, 0.4));
}

.trajectory-marker-start:hover {
  filter: drop-shadow(0 8px 16px rgba(31, 41, 55, 0.4));
}

.trajectory-marker-entity_scan:hover {
  filter: drop-shadow(0 8px 16px rgba(16, 185, 129, 0.4));
}

.trajectory-marker-intermediate:hover {
  filter: drop-shadow(0 8px 16px rgba(139, 92, 246, 0.4));
}


/* ============================================================================
   TRAJECTORY LINE ANIMATION
   ============================================================================ */

/* The stroke-dasharray + duration + offset should be applied inline in JS */
.trajectory-line {
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

@keyframes flowingTrajectory {
  0% {
    stroke-dashoffset: var(--trajectory-total-offset);
  }
  100% {
    stroke-dashoffset: 0;
  }
}


/* ============================================================================
   POPUP BASE STYLE (Glassmorphism)
   ============================================================================ */

.enhanced-trajectory-popup .leaflet-popup-content-wrapper {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.95) 0%,
    rgba(248, 250, 252, 0.95) 100%
  );
  border-radius: 16px;
  padding: 0;
  min-width: 250px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow:
    0 20px 25px -5px rgba(0, 0, 0, 0.1),
    0 10px 10px -5px rgba(0, 0, 0, 0.04);
  backdrop-filter: blur(10px);
}

.enhanced-trajectory-popup .leaflet-popup-tip {
  background: inherit;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.enhanced-trajectory-popup .leaflet-popup-content {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, sans-serif;
}

.enhanced-popup-content {
  padding: 0;
  overflow: hidden;
}


/* ============================================================================
   POPUP HEADER
   ============================================================================ */

.popup-header {
  display: flex;
  align-items: center;
  padding: 16px 20px 12px 20px;
  border-bottom: 1px solid rgba(229, 231, 235, 0.6);
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.8) 0%,
    rgba(249, 250, 251, 0.8) 100%
  );
}

/* Icon styles */
.popup-icon {
  margin-right: 12px;
  padding: 8px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

/* Icon color themes */
.entity-scan-header .popup-icon {
  background: linear-gradient(135deg, #10b981, #059669);
}

.segment-start-header .popup-icon {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
}

.segment-end-header .popup-icon {
  background: linear-gradient(135deg, #ef4444, #dc2626);
}

.location-header .popup-icon {
  background: linear-gradient(135deg, #8b5cf6, #7c3aed);
}

.start-point-header .popup-icon {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
}

.end-point-header .popup-icon {
  background: linear-gradient(135deg, #1f2937, #111827);
}

.popup-title {
  font-size: 16px;
  font-weight: 600;
  color: #1f2937;
  margin: 0;
  line-height: 1.25;
}


/* ============================================================================
   POPUP BODY
   ============================================================================ */

.popup-body {
  padding: 16px 20px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}

.info-row:last-child {
  margin-bottom: 0;
}

.info-label {
  font-weight: 500;
  color: #6b7280;
  font-size: 13px;
  white-space: nowrap;
}

.info-value {
  font-size: 13px;
  color: #374151;
  word-break: break-word;
}

/* Pole snap indicator: a glowing amber ring that pulses over the pole the
   drawn line will snap onto, so the user sees the valid snap target while
   drawing at any zoom. Rendered by map-controller's _highlightSnapTarget. */
.snap-halo {
  filter: drop-shadow(0 0 4px rgba(245, 158, 11, 0.9));
  animation: snap-halo-pulse 1s ease-in-out infinite;
}

/* Name label above the active snap target, so clustered poles are identified
   by name before clicking. Rendered by map-controller's _highlightSnapTarget. */
.snap-label.leaflet-tooltip {
  background: #1f2937;
  color: #ffffff;
  border: 1px solid #f59e0b;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  white-space: nowrap;
}

.snap-label.leaflet-tooltip-top::before {
  border-top-color: #f59e0b;
}

@keyframes snap-halo-pulse {
  0%,
  100% {
    opacity: 1;
    stroke-width: 3;
  }
  50% {
    opacity: 0.55;
    stroke-width: 5;
  }
}

/* Touch-only Confirm/Cancel bar shown after a line/polygon is drawn, so the
   user can verify the snapped endpoint before the entity picker opens. Mirrors
   the map stats panel: same frosted-white pill, anchored top-center, rounded
   bottom corners. Built in map-controller's _showDrawConfirmBar. */
.snap-confirm-bar {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(4px);
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 1rem;
  border-bottom-right-radius: 1rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  max-width: 95vw;
  overflow-x: auto;
}

.snap-confirm-label {
  color: #374151;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.snap-confirm-bar button {
  border: 1px solid transparent;
  border-radius: 0.75rem;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  min-height: 40px;
  white-space: nowrap;
  transition: background-color 0.15s ease;
}

.snap-confirm-ok {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #047857;
}

.snap-confirm-ok:hover {
  background: #d1fae5;
}

.snap-confirm-cancel {
  background: #f9fafb;
  border-color: #e5e7eb;
  color: #6b7280;
}

.snap-confirm-cancel:hover {
  background: #f3f4f6;
}

/* Per-template breakdown popover shown above a stats-panel chip. Mirrors the frosted
   stats pill. Fixed-positioned in map-controller's _openStatPopover to escape the
   panel's horizontal-scroll clipping. */
.stat-breakdown-popover {
  position: fixed;
  transform: translateX(-50%);
  z-index: 1100;
  min-width: 160px;
  max-width: min(260px, 90vw);
  max-height: 40vh;
  overflow-y: auto;
  padding: 6px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(4px);
  border: 1px solid #e5e7eb;
  border-radius: 0.75rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.12), 0 4px 6px -4px rgba(0, 0, 0, 0.12);
}

.stat-breakdown-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-breakdown-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 8px;
  border-radius: 0.5rem;
  font-size: 12px;
}

.stat-breakdown-list li:hover {
  background: #f3f4f6;
}

.stat-breakdown-clickable {
  cursor: pointer;
}

/* Row currently filtering the map — a leading check + tinted background + accent bar. */
.stat-breakdown-selected {
  background: #eef2ff;
  box-shadow: inset 2px 0 0 #4f46e5;
}

.stat-breakdown-selected:hover {
  background: #e0e7ff;
}

.stat-breakdown-selected .stat-breakdown-name::before {
  content: '✓ ';
  color: #4f46e5;
  font-weight: 800;
}

.stat-breakdown-selected .stat-breakdown-name,
.stat-breakdown-selected .stat-breakdown-count {
  color: #4338ca;
}

.stat-breakdown-name {
  color: #374151;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-breakdown-count {
  color: #111827;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.stat-breakdown-empty {
  padding: 6px 8px;
  font-size: 12px;
  color: #9ca3af;
  text-align: center;
}
