/**
 * Custom Leaflet Styles
 * Global styles for Leaflet map components
 */

/* Default Leaflet popup styling - theme-aware */
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: none !important;
  color: #333 !important;
  box-shadow: none !important;
}

/* Dark theme overrides */
body.dark-theme .leaflet-popup-content-wrapper,
body.dark-theme .leaflet-popup-tip {
  background: none !important;
  color: var(--text-light) !important;
  box-shadow: none !important;
}

/* Popup styling - overridden for reliefweb and weather alert popups */
.leaflet-popup-content-wrapper {
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  width: auto !important;
  min-width: 180px;
}

/* Specific styling for reliefweb and weather alert popups */
.reliefweb-popup .leaflet-popup-content-wrapper,
.my-tooltip .leaflet-popup-content-wrapper {
  background: transparent !important;
  box-shadow: none !important;
  border: none !important;
  border-radius: 0 !important;
  padding: 0 !important;
}

.leaflet-popup-content {
  margin: 0;
  padding: 0;
  font-size: 0.8rem;
  line-height: 1.3;
}

/* Arrow-like popup tip - theme-aware */
.leaflet-popup-tip {
  width: 14px;
  height: 14px;
  transform: rotate(45deg);
  margin-top: -7px;
  z-index: 1;
}

/* Light theme adjustments */
body.light-theme .leaflet-popup-tip {
  background: white !important;
  box-shadow: 0 3px 14px rgba(0,0,0,0.4) !important;
}

/* Specific styling for reliefweb and weather alert popup tips */
.reliefweb-popup .leaflet-popup-tip,
.my-tooltip .leaflet-popup-tip {
  background: #1a2740 !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15) !important;
}

body.light-theme .reliefweb-popup .leaflet-popup-tip,
body.light-theme .my-tooltip .leaflet-popup-tip {
  background: var(--light-panel) !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15) !important;
}

/* Popup close button */
.leaflet-popup-close-button {
  color: var(--text-light);
  font-size: 14px;
  font-weight: bold;
  padding: 4px;
  transition: all var(--transition-speed) ease;
}

.leaflet-popup-close-button:hover {
  color: var(--primary-color);
  transform: scale(1.1);
}

body.light-theme .leaflet-popup-close-button {
  color: var(--text-dark);
}

/* Popup container */
.leaflet-popup {
    max-width: 35vw;
    min-width: 220px;
    font-size: calc(0.75rem + 0.15vw);
    line-height: 1.4;
}

/* Ensure popup content is properly styled */
.leaflet-popup-content-wrapper {
  padding: 0;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  width: auto !important;
  min-width: 180px;
}

/* Ensure popup content has proper padding */
.leaflet-popup-content > div {
  padding: 8px;
}

/* Popup text elements */
.leaflet-popup-content h1,
.leaflet-popup-content h2,
.leaflet-popup-content h3,
.leaflet-popup-content h4,
.leaflet-popup-content h5,
.leaflet-popup-content h6 {
  margin: 0 0 6px 0;
  font-size: 1rem;
  line-height: 1.2;
}

.leaflet-popup-content p {
  margin: 0 0 6px 0;
  font-size: 0.85rem;
  line-height: 1.3;
}

/* Progressive responsive scaling - matching carousel pattern */
@media (max-width: 768px) {
  .leaflet-popup {
    max-width: min(90vw, 45vw);
    min-width: 180px;
    font-size: 0.8rem;
    
    /* Mobile touch optimizations */
    touch-action: manipulation;
    -webkit-touch-callout: none;
  }

  .leaflet-popup-content-wrapper {
    min-width: 160px;
    /* Prevent popup from capturing touch events meant for map */
    pointer-events: auto;
    touch-action: pan-y pinch-zoom;
  }
  
  .leaflet-popup-content {
    font-size: 0.75rem;
    /* Allow scrolling within popup content */
    touch-action: pan-y;
  }
  
  .leaflet-popup-content > div {
    padding: 6px;
  }
  
  .leaflet-popup-content h1,
  .leaflet-popup-content h2,
  .leaflet-popup-content h3,
  .leaflet-popup-content h4,
  .leaflet-popup-content h5,
  .leaflet-popup-content h6 {
    font-size: 0.9rem;
    margin: 0 0 5px 0;
  }

  .leaflet-popup-content p {
    font-size: 0.8rem;
    margin: 0 0 5px 0;
  }
  
  /* Enhanced close button for mobile */
  .leaflet-popup-close-button {
    width: 32px;
    height: 32px;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    transition: all 0.2s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(52, 152, 219, 0.3);
  }
  
  .leaflet-popup-close-button:hover,
  .leaflet-popup-close-button:active {
    background: rgba(0, 0, 0, 0.2);
    transform: scale(1.1);
  }
}

@media (max-width: 480px) {
  .leaflet-popup {
    max-width: min(95vw, 60vw);
    min-width: 160px;
    font-size: 0.75rem;
  }

  .leaflet-popup-content-wrapper {
    min-width: 140px;
  }
  
  .leaflet-popup-content {
    font-size: 0.7rem;
  }
  
  .leaflet-popup-content > div {
    padding: 5px;
  }
  
  .leaflet-popup-content h1,
  .leaflet-popup-content h2,
  .leaflet-popup-content h3,
  .leaflet-popup-content h4,
  .leaflet-popup-content h5,
  .leaflet-popup-content h6 {
    font-size: 0.85rem;
    margin: 0 0 4px 0;
  }

  .leaflet-popup-content p {
    font-size: 0.75rem;
    margin: 0 0 4px 0;
  }
  
  /* Larger close button for small screens */
  .leaflet-popup-close-button {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }
}

@media (max-width: 360px) {
  .leaflet-popup {
    max-width: min(98vw, 75vw);
    min-width: 140px;
    font-size: 0.7rem;
  }

  .leaflet-popup-content-wrapper {
    min-width: 120px;
  }
  
  .leaflet-popup-content {
    font-size: 0.65rem;
  }
  
  .leaflet-popup-content > div {
    padding: 4px;
  }
  
  .leaflet-popup-content h1,
  .leaflet-popup-content h2,
  .leaflet-popup-content h3,
  .leaflet-popup-content h4,
  .leaflet-popup-content h5,
  .leaflet-popup-content h6 {
    font-size: 0.8rem;
    margin: 0 0 3px 0;
  }

  .leaflet-popup-content p {
    font-size: 0.7rem;
    margin: 0 0 3px 0;
  }
  
  /* Extra large close button for very small screens */
  .leaflet-popup-close-button {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }
}

/* Set max height for popups on small screens to avoid overflow */
@media (max-height: 600px) {
  .leaflet-popup-content {
    max-height: 70vh;
    overflow-y: auto;
  }
}

/* Leaflet Draw styles */
.leaflet-draw-draw-polygon {
  display: flex;
  width: var(--button-size);
  height: var(--button-size);
  justify-content: center;
  align-items: center;
  font-size: 1.4rem;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: var(--border-radius);
  transition: all var(--transition-speed) ease;
  box-shadow: var(--shadow);
}

.leaflet-draw-draw-polygon:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.leaflet-draw-draw-polygon:active {
  background: var(--primary-active);
  transform: translateY(1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.leaflet-draw-draw-polygon::before {
  content: "\f5ee";
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
}

.leaflet-draw-draw-polygon .sr-only {
  display: none;
}

/* Button icons */
#drawPolygonButton > i.fa-draw-polygon::before {
  content: "\f5ee";
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
}

.leaflet-draw-draw-rectangle {
  display: flex;
  width: var(--button-size);
  height: var(--button-size);
  justify-content: center;
  align-items: center;
  font-size: 1.4rem;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: var(--border-radius);
  transition: all var(--transition-speed) ease;
  box-shadow: var(--shadow);
}

.leaflet-draw-draw-rectangle:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.leaflet-draw-draw-rectangle:active {
  background: var(--primary-active);
  transform: translateY(1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.leaflet-draw-draw-rectangle::before {
  content: "\f5cb";
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
}

.leaflet-draw-draw-rectangle .sr-only {
  display: none;
}

#drawRectangleButton > i.fa-draw-rectangle::before {
  content: "\f5cb";
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
}

/* Hide default Leaflet controls */
.leaflet-control-container,
.leaflet-draw-toolbar,
.leaflet-draw-actions,
.leaflet-draw-toolbar-top,
.leaflet-draw-toolbar-bottom,
.leaflet-draw-tooltip {
  display: none !important;
}

/* Control Zoom Styles */
.leaflet-control-zoom-out {
  background-color: #3282B8;
  color: #333;
  font-size: 30px;
  width: 30px;
  height: 30px;
  line-height: 30px;
}

.leaflet-control-zoom-out:hover {
  background-color: #ddd;
}

.leaflet-control-zoom-out:active {
  background-color: #ccc;
}

/* Control Styling */
.leaflet-control .leaflet-bar {
  background-color: white;
  border-radius: 5px;
  box-shadow: 0 1px 5px rgba(0,0,0,0.4);
}

.leaflet-control label {
  display: block;
  margin: 5px 0;
  cursor: pointer;
}

.leaflet-control input[type="checkbox"] {
  margin-right: 5px;
}

.leaflet-control strong {
  display: block;
  margin-bottom: 5px;
  color: #333;
}

/* Heatmap Legend */
.leaflet-control .gradient-container {
  display: flex;
  align-items: center;
  margin: 5px 0;
}

.leaflet-control .gradient {
  width: 20px;
  height: 100px;
  margin-right: 10px;
}

.leaflet-control .labels {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100px;
}

.leaflet-control .labels div {
  font-size: 12px;
  color: #666;
}

/* Dark theme adjustments */
body.dark-theme .leaflet-control .leaflet-bar {
  background-color: var(--dark-panel);
}

body.dark-theme .leaflet-control label {
  color: var(--text-light);
}

body.dark-theme .leaflet-control strong {
  color: var(--text-light);
}

body.dark-theme .leaflet-control .labels div {
  color: var(--text-light);
}

/* Position adjustments for controls */
.leaflet-right .leaflet-control.accumulator-control {
  margin-right: 10px;
}

.leaflet-bottom .leaflet-control.accumulator-control {
  margin-bottom: 20px;
}

/* Ensure Leaflet map displays properly */
.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;
}

.leaflet-container {
  overflow: hidden;
  z-index: 1; /* Ensure it's above the background overlay */
}

.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}

.leaflet-tile-pane {
  z-index: 2; /* Ensure tiles are visible */
}

.leaflet-overlay-pane {
  z-index: 4;
}

.leaflet-marker-pane {
  z-index: 6;
}

.leaflet-tooltip-pane {
  z-index: 7;
}

.leaflet-popup-pane {
  z-index: 8;
}

/* Ensure proper styling for translated content */
.leaflet-popup-content .description-text p {
  background-color: transparent !important;
  padding: 0 !important;
  margin-bottom: 10px !important;
}

.leaflet-popup-content .description-text p b {
  margin-right: 8px;
  position: relative;
  color: var(--primary-color);
  min-width: auto;
}

.leaflet-popup-content .description-text p:last-child {
  margin-bottom: 0 !important;
} 

/* Mobile-optimized popup class */
.mobile-optimized-popup {
  /* Ensure popup stays within viewport */
  max-width: calc(100vw - 40px) !important;
  max-height: calc(100vh - 100px) !important;
}

.mobile-optimized-popup .leaflet-popup-content-wrapper {
  /* Responsive max-width based on screen size */
  overflow: hidden;
}

.mobile-optimized-popup .leaflet-popup-content {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Enhanced mobile popup sizing for portrait mode */
@media (max-width: 768px) and (orientation: portrait) {
  .mobile-optimized-popup {
    /* Account for navbar (~82px) + floating search wrapper (~80px) + carousel (~150px) + margins */
    max-height: calc(100vh - 320px) !important;
  }
  
  .mobile-optimized-popup .leaflet-popup-content {
    /* Reduce content height to fit within the smaller container */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* Even more constrained for very small screens */
@media (max-width: 480px) and (orientation: portrait) {
  .mobile-optimized-popup {
    /* More conservative sizing for smaller screens */
    max-height: calc(100vh - 280px) !important;
  }
  
  .mobile-optimized-popup .leaflet-popup-content {
  }
}

/* Enhanced mobile popup tip positioning */
@media (max-width: 768px) {
  .mobile-optimized-popup .leaflet-popup-tip {
    /* Ensure tip is visible and properly positioned */
    border: none !important;
    box-shadow: none !important;
  }
  
  /* Add subtle animation for mobile feedback */
  .mobile-optimized-popup .leaflet-popup-content-wrapper {
    animation: mobilePopupOpen 0.3s ease-out;
    transform-origin: center bottom;
  }
}

@keyframes mobilePopupOpen {
  0% {
    opacity: 0;
    transform: scale(0.8) translateY(20px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
} 