/**
 * Leaflet Fix CSS
 * Forces proper display of Leaflet maps and tiles
 */

/* Base Map Container Styles */
[data-controller="browse-map"], [data-controller="single-map"] {
  display: block !important;
  position: relative !important;
  overflow: hidden !important;
  visibility: visible !important;
  min-height: 400px !important;
  background-color: #f5f5f5 !important; /* Visible background as fallback */
  z-index: 1 !important;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

/* Map Container - Core Dimensions and Visibility */
.leaflet-container {
  min-height: 400px !important;
  height: 400px !important;
  width: 100% !important;
  visibility: visible !important;
  display: block !important;
  position: relative !important;
  overflow: visible !important;
  opacity: 1 !important;
  background-color: #f2f2f2 !important; /* Light background to show map area */
  outline: 1px solid rgba(0,0,0,0.1) !important; /* Subtle border to define map edges */
  border-radius: 8px !important;
}

/* Responsive map heights */
@media (max-width: 991.98px) {
  .leaflet-container {
    min-height: 350px !important;
    height: 350px !important;
  }
}

@media (max-width: 767.98px) {
  .leaflet-container {
    min-height: 300px !important;
    height: 300px !important;
  }
  
  [data-controller="browse-map"], [data-controller="single-map"] {
    min-height: 300px !important;
  }
}

@media (max-width: 575.98px) {
  .leaflet-container {
    min-height: 250px !important;
    height: 250px !important;
  }
  
  [data-controller="browse-map"], [data-controller="single-map"] {
    min-height: 250px !important;
  }
}

/* Individual Pane Ordering */
.leaflet-map-pane {
  z-index: 100 !important;
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
}

/* IMPORTANT: Tile pane must be at bottom but visible */
.leaflet-tile-pane {
  z-index: 100 !important;
  visibility: visible !important;
  display: block !important;
  position: absolute !important;
  width: 100% !important;
  height: 100% !important;
}

/* All other panes */
.leaflet-overlay-pane {
  z-index: 300 !important;
}

.leaflet-shadow-pane {
  z-index: 400 !important;
}

.leaflet-marker-pane {
  z-index: 500 !important;
}

.leaflet-tooltip-pane {
  z-index: 600 !important;
}

.leaflet-popup-pane {
  z-index: 700 !important;
}

/* Force Tile Layers to Display */
.leaflet-layer {
  z-index: 100 !important;
  visibility: visible !important;
  position: absolute !important;
  width: 100% !important;
  height: 100% !important;
  display: block !important;
}

.leaflet-tile-container {
  visibility: visible !important;
  opacity: 1 !important;
  position: absolute !important;
  left: 0 !important;
  top: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  z-index: 100 !important;
  pointer-events: auto !important;
  overflow: visible !important;
}

.leaflet-tile {
  visibility: visible !important;
  display: block !important;
  position: absolute !important;
  opacity: 1 !important;
  border: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  pointer-events: auto !important;
  image-rendering: auto !important;
}

/* Fix OpenStreetMap Tiles Specifically */
.osm-tile, 
.leaflet-tile-pane img {
  visibility: visible !important;
  display: block !important;
  opacity: 1 !important;
}

/* Make sure controls are visible and touch-friendly */
.leaflet-control-container {
  visibility: visible !important;
  z-index: 800 !important;
}

/* Make controls touch-friendly */
.leaflet-control-zoom a {
  width: 30px !important;
  height: 30px !important;
  line-height: 30px !important;
  text-align: center !important;
  font-weight: bold !important;
}

/* Larger controls for mobile */
@media (max-width: 767.98px) {
  .leaflet-control-zoom a {
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 18px !important;
  }
  
  .leaflet-control-zoom {
    margin-right: 10px !important;
    margin-bottom: 10px !important;
    box-shadow: 0 1px 5px rgba(0,0,0,0.2) !important;
  }
  
  .leaflet-control-attribution {
    font-size: 10px !important;
    padding: 2px 6px !important;
  }
}

/* Marker Clusters */
.marker-cluster {
  background-color: rgba(181, 226, 140, 0.6) !important;
  z-index: 500 !important;
  border-radius: 50% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.marker-cluster div {
  background-color: rgba(110, 204, 57, 0.6) !important;
  color: #000 !important;
  border-radius: 50% !important;
  font-weight: bold !important;
  text-align: center !important;
}

/* Mobile-friendly marker clusters */
@media (max-width: 767.98px) {
  .marker-cluster {
    width: 40px !important;
    height: 40px !important;
    margin-left: -20px !important;
    margin-top: -20px !important;
  }
  
  .marker-cluster div {
    width: 30px !important;
    height: 30px !important;
    line-height: 30px !important;
    font-size: 14px !important;
  }
}

/* Map popups */
.map-popup {
  padding: 8px;
  max-width: 280px;
  font-size: 14px;
}

.map-popup strong {
  display: block;
  font-size: 15px;
  margin-bottom: 5px;
  line-height: 1.3;
}

.map-popup p {
  margin: 4px 0;
  line-height: 1.3;
}

.map-popup a.btn {
  margin-top: 8px;
  display: block;
  width: 100%;
  text-align: center;
  padding: 6px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 4px;
}

/* Mobile-specific popup styling */
@media (max-width: 767.98px) {
  .map-popup {
    padding: 10px;
    max-width: 240px;
  }
  
  .leaflet-popup-content {
    margin: 10px !important;
  }
  
  .map-popup a.btn {
    padding: 8px;
    font-size: 14px;
  }
}

/* Make sure controls are visible */
.leaflet-control-container {
  visibility: visible !important;
}

/* Make marker clusters visible */
.marker-cluster {
  background-color: rgba(181, 226, 140, 0.6) !important;
}

.marker-cluster div {
  background-color: rgba(110, 204, 57, 0.6) !important;
  color: #000 !important;
}

/* Map popup styling */
.map-popup {
  padding: 5px;
}

.map-popup strong {
  display: block;
  font-size: 14px;
  margin-bottom: 5px;
}

.map-popup p {
  margin: 3px 0;
}

.map-popup a.btn {
  margin-top: 5px;
}
