/* ==========================================================================
   Map Canvas, Custom Trailhead Markers & Floating Top Controls
   ========================================================================== */
#map {
  flex: 1;
  height: 100%;
  width: 100%;
  z-index: 1;
  background: #1e293b;
}

/* Floating Top Controls (Layers + POIs + Region) */
.top-map-bar {
  position: absolute;
  top: 14px;
  right: 60px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
}

.map-layer-dropdown-wrapper {
  position: relative;
}

.map-layer-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: rgba(255, 255, 255, 0.98);
  border: 1.5px solid rgba(0, 0, 0, 0.1);
  border-radius: 14px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.18);
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 2px;
  min-width: 210px;
  z-index: 1100;
  backdrop-filter: blur(12px);
  animation: fadeInMenu 0.15s ease-out;
}

.map-layer-menu.open {
  display: flex;
}

@keyframes fadeInMenu {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.layer-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  border: none;
  background: transparent;
  font-size: 0.78rem;
  font-weight: 600;
  color: #334155;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
  width: 100%;
}

.layer-menu-item:hover {
  background: #f1f5f9;
  color: var(--primary);
}

.layer-menu-item.active {
  background: #fff7ed;
  color: var(--primary);
  font-weight: 800;
}

.layer-menu-divider {
  height: 1px;
  background: #e2e8f0;
  margin: 4px 0;
}

.layer-menu-item.pin-action {
  color: #2563eb;
  font-weight: 700;
}

.layer-menu-item.pin-action:hover {
  background: #eff6ff;
}

.floating-btn {
  background: rgba(255, 255, 255, 0.95);
  color: #0f172a;
  border: 1.5px solid rgba(0, 0, 0, 0.1);
  border-radius: 30px;
  padding: 7px 14px;
  font-size: 0.78rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(10px);
  white-space: nowrap;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.floating-btn:hover {
  transform: translateY(-2px);
  color: var(--primary);
  border-color: var(--primary);
  background: white;
  box-shadow: var(--shadow-lg);
}

.floating-btn.active {
  background: #f0fdf4;
  border-color: #22c55e;
  color: #15803d;
}

/* Trail Number Pin Markers */
.custom-trail-marker {
  background-color: var(--primary);
  border: 2px solid #ffffff;
  border-radius: 50%;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 12px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.custom-trail-marker:hover {
  transform: scale(1.25);
  background-color: var(--primary-hover);
}

.custom-start-marker {
  background-color: var(--transit-dark);
  border: 2px solid #ffffff;
  border-radius: 50%;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(67, 56, 202, 0.5);
  cursor: grab;
  transition: transform 0.2s ease;
}

.custom-start-marker:active {
  cursor: grabbing;
  transform: scale(1.25);
}

.trail-tracker-marker {
  position: relative;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border: 3px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(2, 132, 199, 0.8), 0 2px 5px rgba(0,0,0,0.35);
  pointer-events: none;
}

.trail-tracker-marker::after {
  content: '';
  position: absolute;
  top: -7px;
  left: -7px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: trackerPulse 1.4s infinite ease-out;
}

@keyframes trackerPulse {
  0% { transform: scale(0.6); opacity: 1; }
  100% { transform: scale(1.8); opacity: 0; }
}

.tracker-map-tooltip {
  background: #0f172a !important;
  color: #ffffff !important;
  border: none !important;
  font-weight: 600 !important;
  font-size: 0.75rem !important;
  padding: 3px 7px !important;
  border-radius: 4px !important;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.2) !important;
}

/* Floating POI Category Filter Bar on Map */
.floating-poi-bar {
  position: absolute;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  gap: 6px;
  background: rgba(15, 23, 42, 0.85);
  padding: 5px 8px;
  border-radius: 30px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(12px);
  max-width: 92vw;
  overflow-x: auto;
}

.poi-filter-btn {
  background: transparent;
  border: 1px solid transparent;
  color: #cbd5e1;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.poi-filter-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: white;
}

.poi-filter-btn.active {
  background: rgba(2, 132, 199, 0.3);
  border-color: #38bdf8;
  color: #38bdf8;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.3);
}

.poi-filter-btn.inactive {
  opacity: 0.45;
  background: transparent !important;
  border-color: transparent !important;
  color: #64748b !important;
}

/* POI Marker Badge Styles */
.poi-marker {
  border-radius: 50%;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  border: 2px solid #ffffff;
}

.poi-marker:hover {
  transform: scale(1.35);
  z-index: 1000 !important;
}

.poi-marker.peak {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  border-color: #fecaca;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.6);
}

.poi-marker.nature {
  background: linear-gradient(135deg, #10b981, #047857);
  border-color: #a7f3d0;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.6);
}

.poi-marker.refuge {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  border-color: #fde68a;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.6);
}

.poi-marker.viewpoint {
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  border-color: #ddd6fe;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.6);
}

.poi-marker.cultural {
  background: linear-gradient(135deg, #64748b, #334155);
  border-color: #e2e8f0;
  box-shadow: 0 4px 12px rgba(100, 116, 139, 0.6);
}

/* POI Popup Card */
.poi-popup-card {
  font-family: inherit;
  padding: 4px;
}

.poi-popup-cat {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  color: #0284c7;
  letter-spacing: 0.04em;
}

.poi-popup-title {
  display: block;
  font-size: 0.95rem;
  color: #0f172a;
  margin: 2px 0 4px 0;
  line-height: 1.25;
}

.poi-popup-desc {
  font-size: 0.76rem;
  color: #475569;
  line-height: 1.4;
  margin: 6px 0 8px 0;
}

.poi-popup-link {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  color: #0284c7;
  text-decoration: none;
}

.poi-popup-link:hover {
  text-decoration: underline;
}

/* User-Defined Custom Pin Styling */
.btn-add-user-pin {
  background: #0284c7 !important;
  color: white !important;
  border-color: #38bdf8 !important;
}

.btn-add-user-pin:hover {
  background: #0369a1 !important;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.5);
}

.btn-add-user-pin.active-drop-mode {
  background: #ea580c !important;
  border-color: #fdba74 !important;
  color: white !important;
  animation: pulseDropBtn 1.2s infinite;
}

@keyframes pulseDropBtn {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); box-shadow: 0 0 14px rgba(234, 88, 12, 0.7); }
  100% { transform: scale(1); }
}

.map-crosshair-mode {
  cursor: crosshair !important;
}

.pin-cat-btn {
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 6px 4px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition: all 0.15s;
}

.pin-cat-btn:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
}

.pin-cat-btn.active {
  background: #0284c7;
  color: white;
  border-color: #0369a1;
  box-shadow: 0 2px 6px rgba(2, 132, 199, 0.35);
}

.poi-marker.user-custom {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  border-color: #e0f2fe;
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.65), 0 0 0 2px rgba(255, 255, 255, 0.8);
  animation: userPinFloat 2.5s infinite ease-in-out;
}

@keyframes userPinFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.btn-delete-pin {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 6px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.btn-delete-pin:hover {
  background: #fee2e2;
  border-color: #f87171;
}

/* Specialized Marker Badges for Hotel, Start, Finish & Transit */
.poi-marker.hotel {
  background: linear-gradient(135deg, #4f46e5, #3730a3);
  border-color: #c7d2fe;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.6);
}

.poi-marker.trailhead_start {
  background: linear-gradient(135deg, #16a34a, #15803d);
  border-color: #bbf7d0;
  box-shadow: 0 4px 14px rgba(22, 163, 74, 0.7), 0 0 0 2px rgba(34, 197, 94, 0.5);
}

.poi-marker.trailhead_finish {
  background: linear-gradient(135deg, #dc2626, #991b1b);
  border-color: #fecaca;
  box-shadow: 0 4px 14px rgba(220, 38, 38, 0.7), 0 0 0 2px rgba(239, 68, 68, 0.5);
}

.poi-marker.transit {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  border-color: #bae6fd;
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.6);
}

.poi-marker.parking {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border-color: #bfdbfe;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.6);
}

.poi-marker.warning {
  background: linear-gradient(135deg, #ea580c, #c2410c);
  border-color: #fed7aa;
  box-shadow: 0 4px 12px rgba(234, 88, 12, 0.6);
}

.poi-marker.food {
  background: linear-gradient(135deg, #b45309, #92400e);
  border-color: #fde68a;
  box-shadow: 0 4px 12px rgba(180, 83, 9, 0.6);
}

/* Leaflet Professional Layer Control */
.leaflet-top.leaflet-right .leaflet-control-layers {
  margin-top: 14px;
  margin-right: 14px;
  border-radius: 12px;
  border: 1.5px solid rgba(0, 0, 0, 0.12);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.80rem;
  font-weight: 600;
  color: #1e293b;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
}

.leaflet-control-layers-toggle {
  width: 36px;
  height: 36px;
  background-size: 20px 20px;
}

.leaflet-control-layers-expanded {
  padding: 10px 14px;
  min-width: 220px;
  border-radius: 12px;
}

.leaflet-control-layers-base label,
.leaflet-control-layers-overlays label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  cursor: pointer;
}

.leaflet-control-layers-base label:last-child,
.leaflet-control-layers-overlays label:last-child {
  margin-bottom: 0;
}

.leaflet-control-layers-separator {
  margin: 8px 0;
  border-top: 1px solid #e2e8f0;
}

/* ==========================================================================
   Mobile Responsive Navigation & Map Menus
   ========================================================================== */
@media (max-width: 840px) {
  .top-map-bar {
    top: 8px;
    left: 8px;
    right: 50px;
    max-width: calc(100vw - 58px);
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding-bottom: 2px;
    gap: 6px;
  }

  .top-map-bar::-webkit-scrollbar {
    display: none;
  }

  .floating-btn {
    flex-shrink: 0;
    padding: 5px 9px;
    font-size: 0.72rem;
    gap: 4px;
  }

  .map-layer-dropdown-wrapper {
    flex-shrink: 0;
    position: static;
  }

  .map-layer-menu {
    position: fixed;
    top: 46px;
    left: 8px;
    right: auto;
    max-width: min(290px, 86vw);
    max-height: 65vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 10000;
  }

  .user-profile-badge-wrapper {
    flex-shrink: 0;
  }

  .user-profile-badge {
    padding: 4px 8px;
    font-size: 0.72rem;
    max-width: 130px;
  }

  .floating-poi-bar {
    top: 48px;
    left: 8px;
    right: 8px;
    transform: none;
    max-width: calc(100vw - 16px);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding: 4px 6px;
    gap: 4px;
    border-radius: 20px;
  }

  .floating-poi-bar::-webkit-scrollbar {
    display: none;
  }

  .poi-filter-btn {
    flex-shrink: 0;
    font-size: 0.68rem;
    padding: 3px 8px;
    gap: 3px;
  }

  .leaflet-top.leaflet-right .leaflet-control-layers {
    margin-top: 8px;
    margin-right: 8px;
  }

  .leaflet-control-layers-toggle {
    width: 32px;
    height: 32px;
  }

  .leaflet-control-layers-expanded {
    max-width: min(260px, 80vw);
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}
