/**
 * Enhanced Leaflet Map CSS
 * Provides styles for search box, legend, 'found' markers, and popup buttons
 * Updated to match screenshots for improved UI
 * Includes fix for preventing "Mark as Found" and "Share" buttons from wrapping
 * Consolidated to remove duplicates and combine .leaflet-popup-content and .marker-popup
 */

.leaflet-control {
  clear: both;
}

/* Control bar margins */
.leaflet-top.leaflet-right .leaflet-bar,
.leaflet-top.leaflet-left .leaflet-bar {
  margin: 0 !important;
}

/* Legend styles */
.leaflet-legend {
  background-color: white;
  border-radius: 4px;
  box-shadow: 0 1px 5px rgba(0,0,0,0.4);
  min-width: 200px;
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
  margin: 0;
  padding: 0;
  transition: transform 0.3s ease, width 0.3s ease;
}

/* Collapsed panel state */
.leaflet-legend.panel-collapsed {
  transform: translateX(calc(100% - 10px));
  min-width: 20px;
  width: 20px;
  overflow: visible;
  z-index: 800;
  border: none;
  box-shadow: none;
  background: transparent;
}

/* Collapsed state: expand button (▶) */
.leaflet-legend.panel-collapsed .legend-filter-icon {
  position: absolute;
  left: -20px;
  top: 7px;
  background: white;
  border: 1px solid #ccc;
  border-radius: 3px;
  box-shadow: 1px 1px 3px rgba(0,0,0,0.2);
  visibility: visible;
  width: 20px;
  height: 20px;
  line-height: 18px;
  text-align: center;
  z-index: 802;
}

/* Ensure no pseudo-elements interfere */
.leaflet-legend.panel-collapsed .leaflet-legend-header:before {
  content: none;
}

/* Hide content in collapsed state */
.leaflet-legend.panel-collapsed .legend-content,
.leaflet-legend.panel-collapsed .legend-bottom-controls,
.leaflet-legend.panel-collapsed .legend-title,
.leaflet-legend.panel-collapsed .legend-collapse-icon {
  display: none;
}

/* Legend header in collapsed state */
.leaflet-legend.panel-collapsed .leaflet-legend-header {
  background: transparent;
  border: none;
  padding: 0;
}

/* Legend header */
.leaflet-legend-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  background-color: #f0f0f0;
  border-bottom: 1px solid #ccc;
  cursor: pointer;
  position: relative;
}

/* Legend filter icon */
.legend-filter-icon {
  font-size: 14px;
  color: #2a2a2a;
  cursor: pointer;
  display: inline-block;
  width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  position: relative;
  z-index: 802;
}

/* Expanded state: collapse button (◀) */
.leaflet-legend:not(.panel-collapsed) .legend-filter-icon {
  background: transparent;
}

/* Legend title and collapse icon */
.legend-title {
  flex-grow: 1;
  font-weight: bold;
  font-size: 14px;
  color: #222;
  margin: 0 8px;
}

.legend-collapse-icon {
  font-size: 14px;
  color: #2a2a2a;
  cursor: pointer;
}

/* Legend content */
.legend-content {
  padding: 8px;
  max-height: 350px;
  overflow-y: auto;
  transition: max-height 0.3s ease;
}

.legend-content.collapsed {
  max-height: 0;
  padding: 0 8px;
  overflow: hidden;
}

/* Bottom control buttons */
.legend-bottom-buttons {
  padding: 4px;
  border-top: 1px solid #ddd;
  background-color: #f4f4f4;
}

/* Button rows */
.button-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 2px;
  gap: 3px;
}

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

/* Legend buttons */
.legend-enable-all,
.legend-disable-all,
.legend-collapse-all,
.legend-expand-all {
  flex: 1;
  background-color: #f0f0f0;
  border: 1px solid #ccc;
  border-radius: 2px;
  padding: 2px 4px;
  font-size: 10px;
  cursor: pointer;
  transition: background-color 0.3s;
  white-space: nowrap;
  line-height: 1.2;
  height: auto;
  min-height: 20px;
  color: #333 !important;
}

.legend-enable-all:hover,
.legend-disable-all:hover,
.legend-collapse-all:hover,
.legend-expand-all:hover {
  background-color: #e0e0e0;
}

/* Group lists */
.marker-group-list {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

.marker-group-list li {
  margin-bottom: 5px;
}

.marker-group-category {
  font-weight: bold;
  margin: 10px 0 5px;
  padding-bottom: 2px;
  border-bottom: 1px solid #eee;
  color: #000;
}

/* Category styles */
.filter-category-header {
  display: flex;
  align-items: center;
  padding: 3px 0;
  font-weight: bold;
  cursor: pointer;
  color: #000;
}

.filter-category-header:hover {
  background-color: #f5f5f5;
}

.category-checkbox {
  margin-right: 5px;
}

.filter-category-icon {
  margin-right: 5px;
  color: #666;
  font-size: 12px;
}

.filter-category-items {
  max-height: 1000px;
  overflow-y: auto;
  transition: max-height 0.2s ease;
}

.filter-category:not(.filter-category-expanded) .filter-category-items {
  max-height: 0;
}

/* Group items */
.marker-group-item {
  padding-left: 20px;
  margin: 4px 0;
  color: #000;
  font-weight: 500;
}

.marker-group-list label {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 2px 0;
  color: #000;
  font-weight: 500;
}

.marker-group-list input[type="checkbox"] {
  margin-right: 5px;
}

.marker-group-list img {
  width: 16px;
  height: 16px;
  margin-right: 8px;
  vertical-align: middle;
}

/* Show found markers toggle */
.show-found-toggle {
  border-top: 1px solid #eee;
  padding: 8px 0;
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.show-found-toggle label {
  color: #333 !important;
  font-weight: 500;
  font-size: 12px;
  text-shadow: none !important;
}

.show-found-toggle input {
  margin-right: 8px;
}

/* Search styles */
.leaflet-search {
  z-index: 1000;
}

/* Search button */
.leaflet-control-search-button {
  display: block;
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
  text-align: center;
  background-color: white;
  border-radius: 4px;
  box-shadow: 0 1px 5px rgba(0,0,0,0.4);
  cursor: pointer;
  text-decoration: none;
  color: #333;
}

.search-icon {
  font-size: 18px;
}

/* Search panel */
.leaflet-search-panel {
  position: absolute;
  top: 0;
  left: 36px;
  background: white;
  border-radius: 0 4px 4px 0;
  box-shadow: 0 1px 5px rgba(0,0,0,0.4);
  padding: 0;
  height: 36px;
  display: flex;
  align-items: center;
  z-index: 1000;
  overflow: hidden;
  transition: width 0.3s ease-in-out;
  width: 0;
}

.leaflet-search-panel.visible {
  width: 220px;
  display: flex;
}

.search-close-button {
  display: none;
}

.search-input {
  flex: 1;
  height: 36px;
  padding: 0 10px;
  border: none;
  font-size: 14px;
  outline: none;
  color: #000;
  font-weight: normal;
  background: white;
}

.search-submit {
  height: 36px;
  width: 36px;
  background: #1e90ff;
  color: white;
  border: none;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-input:focus {
  border-color: #4d90fe;
  box-shadow: 0 0 3px rgba(77, 144, 254, 0.5);
}

.search-results {
  position: absolute;
  top: 36px;
  left: 0;
  width: 250px;
  max-height: 400px;
  overflow-y: auto;
  border-top: 1px solid #eee;
  list-style-type: none;
  margin: 0;
  padding: 0;
  background: white;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
  z-index: 1000;
  border-radius: 0 0 4px 4px;
}

.search-results li {
  padding: 8px 10px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  font-size: 13px;
  color: #000 !important;
  font-weight: 500 !important;
  background: white !important;
  white-space: normal;
  line-height: 1.4;
  word-break: break-word;
}

.search-results li:hover {
  background-color: #f5f5f5;
}

.search-results li:last-child {
  border-bottom: none;
}

/* Custom Zoom Controls */
.custom-zoom-control {
  display: flex;
  flex-direction: column;
  margin-top: 10px !important;
}

.custom-zoom-control a {
  display: block;
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
  text-align: center;
  background-color: white;
  font-size: 18px;
  font-weight: bold;
  text-decoration: none;
  color: #333;
  margin-bottom: 1px !important;
}

.custom-zoom-control a:first-child {
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
}

.custom-zoom-control a:last-child {
  border-bottom-left-radius: 4px;
  border-bottom-right-radius: 4px;
  margin-bottom: 0 !important;
}

/* Fullscreen and Pop Out controls */
.leaflet-control-fullscreen,
.leaflet-control-popout {
  display: block;
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
  text-align: center;
  background-color: white;
  border-radius: 4px;
  box-shadow: 0 1px 5px rgba(0,0,0,0.4);
  margin-bottom: 10px !important;
  cursor: pointer;
  text-decoration: none;
  color: #333;
}

/* Control alignment */
.leaflet-top.leaflet-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.fullscreen-icon {
  font-size: 18px;
}

.home-icon {
  font-size: 16px;
}

/* Found markers and paths */
.leaflet-marker-icon.marker-found,
.leaflet-interactive.path-found {
  opacity: 0.4 !important;
  filter: grayscale(100%) !important;
  transition: opacity 0.3s ease, filter 0.3s ease;
}

.leaflet-marker-icon.marker-found:hover,
.leaflet-interactive.path-found:hover {
  opacity: 0.7 !important;
}

/* Coordinates display */
.leaflet-coord-display {
  background-color: rgba(255, 255, 255, 0.7);
  padding: 5px 8px;
  font-size: 12px;
  border-radius: 4px;
  font-family: monospace;
}

/* Geojson popups */
.geojson-popup h3 {
  margin: 0 0 8px;
  font-size: 14px;
  border-bottom: 1px solid #eee;
  padding-bottom: 4px;
}

.geojson-popup table {
  border-collapse: collapse;
  width: 100%;
  font-size: 12px;
}

.geojson-popup td {
  padding: 3px 5px;
  border-bottom: 1px solid #f5f5f5;
}

/* Share tooltip */
.leaflet-react-map-popup-share-tooltip {
  display: none;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 8px;
  box-shadow: 0 0 5px rgba(0,0,0,0.2);
  z-index: 1000;
  width: 100%;
  margin-top: 8px;
  box-sizing: border-box;
}

.leaflet-react-map-popup-share-tooltip.visible {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 5px;
}

.leaflet-react-map-popup-share-input {
  flex: 1;
  padding: 5px 8px;
  border: 1px solid #ccc;
  border-radius: 3px;
  font-size: 12px;
  height: 28px;
  min-width: 0;
  color: #333 !important;
  background-color: white !important;
}

.leaflet-react-map-popup-share-button {
  background: #f0f0f0;
  border: 1px solid #ccc;
  border-radius: 3px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  height: 28px;
  color: #333 !important;
  font-weight: bold;
}

.leaflet-react-map-popup-share-button:hover {
  background: #e0e0e0;
}

.leaflet-tooltip.hover-tooltip {
  background: #fff;
  border: 1px solid #ccc;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  font-size: 12px;
  padding: 6px 10px; /* Increased padding for more space */
  max-width: 300px; /* Increased to allow more words per line */
  white-space: normal; /* Allow text wrapping */
  overflow-wrap: break-word; /* Break long words */
  overflow: hidden; /* Hide any overflow */
  text-overflow: ellipsis; /* Optional: ellipsis for clipped text */
  line-height: 1.5; /* Slightly increased for better readability */
}

/* Popup actions container */
.leaflet-react-map-popup-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  justify-content: center;
}

/* Found and Share buttons */
.leaflet-react-map-popup-found-toggle,
.leaflet-react-map-popup-share {
  display: inline-flex;
  align-items: center;
  justify-content: center; /* Center content horizontally */
  padding: 5px 8px; /* Slightly reduce padding to fit longer text */
  font-size: 12px;
  border: 1px solid #ccc;
  border-radius: 3px;
  background-color: #f0f0f0;
  cursor: pointer;
  white-space: nowrap;
  width: 120px; /* Fixed width for consistency */
  height: 30px; /* Fixed height for uniformity */
  box-sizing: border-box; /* Ensure padding doesn't affect width */
  overflow: hidden; /* Prevent text overflow */
  text-overflow: ellipsis; /* Truncate text if too long */
  color: #333 !important;
}

.leaflet-react-map-popup-found-toggle:hover,
.leaflet-react-map-popup-share:hover {
  background-color: #e0e0e0;
}

/* Icon spacing */
.found-icon,
.leaflet-react-map-popup-share-icon {
  margin-right: 5px;
  flex-shrink: 0; /* Prevent icon from shrinking */
}

/* Popup content */
.leaflet-popup-content,
.marker-popup {
  margin: 10px;
  max-width: 100%;
  box-sizing: border-box;
}

/* Popup minimum width */
.leaflet-popup-content-wrapper {
  min-width: 250px !important;
}

/* Mobile adjustments */
@media (max-width: 600px) {
  .leaflet-react-map-popup-found-toggle,
  .leaflet-react-map-popup-share {
    width: 100px; /* Slightly smaller fixed width for mobile */
    font-size: 11px;
    padding: 4px 6px;
    height: 28px;
  }
}

.leaflet-line, .leaflet-polygon  {
    display: none;
}


/* Ensure the maximized map covers the entire viewport */
.leaflet-map-container.maximized {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 10000 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important; /* Prevent internal scrolling */
    flex: none !important;
    grid-area: none !important;
}

/* Ensure the internal map div also resizes fully */
.leaflet-map-container.maximized .leaflet-react-map {
    width: 100% !important;
    height: 100% !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
}

/* Hide all other page content when map is maximized */
.leaflet-map-container.maximized ~ * {
    display: none !important;
}

/* Prevent parent containers from clipping or constraining */
.leaflet-map-container.maximized,
.leaflet-map-container.maximized * {
    max-height: none !important;
    max-width: none !important;
    overflow: visible !important;
}

/* Ensure body and html don’t allow scrolling */
body:has(.leaflet-map-container.maximized),
html:has(.leaflet-map-container.maximized) {
    overflow: hidden !important;
    height: 100vh !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Hide search panel and results by default in maximized state */
.leaflet-map-container.maximized .leaflet-search-panel,
.leaflet-map-container.maximized .search-results {
    display: none;
    visibility: hidden;
}

/* Ensure search panel shows when toggled */
.leaflet-map-container.maximized .leaflet-search-panel.visible {
    display: flex !important;
    visibility: visible !important;
    width: 220px !important;
    left: 36px !important;
    transition: none;
}

/* Re-enable transition after initial render */
.leaflet-map-container.maximized .leaflet-search-panel:not(.initializing) {
    transition: width 0.3s ease-in-out !important;
}

/* Ensure search results show when active in maximized mode */
.leaflet-map-container.maximized .leaflet-search .search-results {
    display: none !important; /* Default to hidden */
    visibility: hidden !important;
}


/* Show search results when active in maximized state */
.leaflet-map-container.maximized .leaflet-control.leaflet-search .search-results.active {
    display: block !important;
    visibility: visible !important;
    top: 36px !important;
    left: 36px !important;
    width: 250px !important;
    z-index: 1002 !important;
    position: absolute !important;
    background: white !important;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2) !important;
}

/* Ensure search control is accessible */
.leaflet-map-container.maximized .leaflet-search {
    z-index: 1001 !important;
}

/* Prevent parent constraints */
.leaflet-map-container.maximized .leaflet-search-panel,
.leaflet-map-container.maximized .leaflet-search .search-results {
    position: absolute !important;
    box-sizing: border-box !important;
}

/* Override common WordPress theme conflicts */
.leaflet-map-container.maximized .leaflet-control * {
    max-height: none !important;
    overflow: visible !important;
}


/* Ensure legend remains interactive in maximized mode */
.leaflet-map-container.maximized .leaflet-legend {
    z-index: 10001 !important; /* Higher than map container */
    overflow: visible !important; /* Allow content to display */
    position: relative !important; /* Ensure proper stacking */
}

/* Ensure filter category items are not constrained in maximized mode */
.leaflet-map-container.maximized .filter-category-items {
    max-height: 1000px !important; /* Explicit max-height when expanded */
    overflow-y: auto !important; /* Allow scrolling */
    transition: max-height 0.2s ease !important; /* Maintain transition */
}

.leaflet-map-container.maximized .filter-category:not(.filter-category-expanded) .filter-category-items {
    max-height: 0 !important;
    overflow: hidden !important;
}

/* Ensure legend buttons remain clickable */
.leaflet-map-container.maximized .legend-bottom-buttons,
.leaflet-map-container.maximized .legend-bottom-buttons button {
    z-index: 10002 !important; /* Ensure buttons are clickable */
    position: relative !important;
    pointer-events: auto !important; /* Allow clicks */
}

/* Text Label Styles */
.leaflet-text-label {
    background: transparent; /* No background for clean text */
    color: #fff; /* White text for better visibility */
    font-size: 12px; /* Smaller base size for zoomed-out views */
    font-weight: bold; /* Bold for emphasis */
    text-shadow: 1px 1px 2px #000; /* Black shadow for contrast */
    white-space: nowrap; /* Prevent wrapping */
}

/* Tooltip Styles */
.leaflet-label-tooltip {
    background: rgba(255, 255, 255, 0.8); /* Semi-transparent for hover tooltips */
    color: #fff; /* White text for consistency */
    border: 1px solid #000; /* Black border for contrast */
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 10px; /* Smaller size for tooltips */
    text-shadow: 1px 1px 2px #000; /* Black shadow for readability */
}