/* ============================================================
   CARTE DES MOULINS D'ANJOU — Styles
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
}

#moulins-carte-wrapper {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  max-width: auto;
  margin: 0 auto;
  overflow: hidden;
  position: relative;
}

/* ------- Barre de filtres ------- */

#filtres-bar {
  background: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 8px 8px 0 0;
  padding: 12px 16px;
  overflow: hidden;
}

#filtres-toggle {
  display: none;
  width: 100%;
  background: #2c6e49;
  color: #fff;
  border: none;
  padding: 10px;
  font-size: 15px;
  cursor: pointer;
  border-radius: 6px;
  margin-bottom: 8px;
}

#filtres-content {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-start;
}

.filtre-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filtre-group label.group-title {
  font-weight: 600;
  font-size: 13px;
  color: #495057;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.filtre-group .checkboxes,
.filtre-group .radios {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filtre-group .checkboxes label,
.filtre-group .radios label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: #333;
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 4px;
  background: #fff;
  border: 1px solid #ced4da;
  transition: background 0.15s;
  white-space: nowrap;
}

.filtre-group .checkboxes label:hover,
.filtre-group .radios label:hover {
  background: #e9ecef;
}

.filtre-group select {
  font-size: 13px;
  padding: 4px 8px;
  border: 1px solid #ced4da;
  border-radius: 4px;
  background: #fff;
}

.color-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.2);
  flex-shrink: 0;
}

/* ------- Carte ------- */

#map {
  width: 100%;
  height: 70vh;
  min-height: 400px;
  border: 1px solid #dee2e6;
  border-top: none;
  border-radius: 0 0 8px 8px;
}

/* ------- Popups (conservés pour circuits) ------- */

.leaflet-popup-content {
  max-width: 340px;
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* ------- Panneau détail (desktop = côté, mobile = overlay) ------- */

.detail-panel {
  position: absolute;
  top: 0;
  right: -400px;
  width: 380px;
  height: 100%;
  background: #fff;
  box-shadow: -2px 0 12px rgba(0,0,0,.15);
  z-index: 1000;
  transition: right 0.3s ease;
  overflow-y: auto;
  border-left: 1px solid #dee2e6;
}

.detail-panel.open {
  right: 0;
}

.detail-panel-close {
  position: sticky;
  top: 0;
  float: right;
  background: #fff;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: #666;
  padding: 8px 14px;
  line-height: 1;
  z-index: 1001;
}

.detail-panel-close:hover {
  color: #000;
}

.detail-panel-content {
  padding: 16px;
  padding-top: 8px;
}

.detail-panel-content .popup-moulin,
.detail-panel-content .popup-circuit {
  max-width: 100%;
}

.popup-moulin h2 {
  font-size: 16px;
  margin: 0 0 8px;
  color: #2c6e49;
}

.popup-moulin img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  margin: 6px 0;
  display: block;
}

.popup-moulin .badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 6px 0;
}

.popup-moulin .badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
}

.badge-fonctionnement { background: #2e7d32; }
.badge-visitable { background: #1565c0; }
.badge-restauration { background: #e65100; }

.popup-moulin .desc-text {
  margin: 6px 0;
}

.popup-moulin .desc-text p {
  margin: 4px 0;
}

.popup-moulin a.savoir-plus {
  display: inline-block;
  margin-top: 6px;
  color: #1565c0;
  font-weight: 600;
  text-decoration: none;
}

.popup-moulin a.savoir-plus:hover {
  text-decoration: underline;
}

.popup-circuit h3 {
  font-size: 15px;
  margin: 0 0 6px;
  color: #2c6e49;
}

.popup-circuit .circuit-info {
  font-size: 13px;
  color: #555;
}

/* ------- Légende ------- */

.legend-control {
  background: rgba(255,255,255,.92);
  padding: 10px 14px;
  border-radius: 6px;
  box-shadow: 0 1px 5px rgba(0,0,0,.2);
  font-size: 12px;
  line-height: 1.8;
  transition: all 0.3s ease;
  max-width: 180px;
}

.legend-control.legend-collapsed {
  padding: 0;
  overflow: hidden;
  width: 0;
  height: 0;
  opacity: 0;
}

.legend-control h4 {
  margin: 0 0 4px;
  font-size: 13px;
  color: #333;
}

.legend-control .legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.legend-control .legend-line {
  width: 22px;
  height: 3px;
  display: inline-block;
  flex-shrink: 0;
}

.legend-control hr {
  border: none;
  border-top: 1px solid #ccc;
  margin: 5px 0;
}

/* ------- Bouton toggle légende ------- */

.legend-toggle-btn {
  background: #fff;
  border: 2px solid rgba(0,0,0,.2);
  border-radius: 4px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 5px rgba(0,0,0,.2);
}

.legend-toggle-btn:hover {
  background: #f4f4f4;
}

/* ------- Bouton plein écran ------- */

.fullscreen-btn {
  background: #fff;
  border: 2px solid rgba(0,0,0,.2);
  border-radius: 4px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 5px rgba(0,0,0,.2);
}

.fullscreen-btn:hover {
  background: #f4f4f4;
}

/* ------- Mode plein écran (API native — desktop) ------- */

#moulins-carte-wrapper:fullscreen {
  display: flex;
  flex-direction: column;
  background: #fff;
}

#moulins-carte-wrapper:fullscreen #filtres-bar {
  border-radius: 0;
  flex-shrink: 0;
}

#moulins-carte-wrapper:fullscreen #map {
  flex: 1;
  height: auto !important;
  min-height: 0 !important;
  border-radius: 0;
}

/* ------- Mode plein écran (fallback CSS — mobile/iOS) ------- */

#moulins-carte-wrapper.fullscreen-fallback {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  max-width: none !important;
  z-index: 999999 !important;
  margin: 0 !important;
  border-radius: 0 !important;
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
}

#moulins-carte-wrapper.fullscreen-fallback #filtres-bar {
  border-radius: 0;
  flex-shrink: 0;
}

#moulins-carte-wrapper.fullscreen-fallback #map {
  flex: 1;
  height: auto !important;
  min-height: 0 !important;
  border-radius: 0;
}

/* ------- Icônes moulins SVG ------- */

.mill-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 768px) {
  #moulins-carte-wrapper {
    max-width: 100%;
  }

  #filtres-toggle {
    display: block;
    padding: 8px;
    font-size: 14px;
    margin-bottom: 4px;
  }

  #filtres-content.collapsed {
    display: none;
  }

  #filtres-bar {
    padding: 8px;
    border-radius: 0;
  }

  #filtres-content {
    flex-direction: column;
    gap: 8px;
  }

  .filtre-group {
    gap: 2px;
  }

  .filtre-group label.group-title {
    font-size: 11px;
    margin-bottom: 0;
  }

  .filtre-group .checkboxes,
  .filtre-group .radios {
    gap: 4px;
  }

  .filtre-group .checkboxes label,
  .filtre-group .radios label {
    font-size: 12px;
    padding: 2px 6px;
    gap: 3px;
  }

  .filtre-group select {
    font-size: 12px;
    padding: 3px 6px;
  }

  #map {
    height: 70vh;
    min-height: 280px;
    border-radius: 0;
  }

  /* Panneau détail mobile : overlay centré par-dessus la carte */
  .detail-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    right: auto;
    bottom: auto;
    transform: translate(-50%, -50%) scale(0.9);
    width: 92vw;
    max-width: 400px;
    height: auto;
    max-height: 80vh;
    border-left: none;
    border: 1px solid #dee2e6;
    box-shadow: 0 4px 24px rgba(0,0,0,.3);
    border-radius: 12px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 100000;
  }

  .detail-panel.open {
    right: auto;
    bottom: auto;
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
  }

  .detail-panel-content {
    padding: 12px;
    padding-top: 4px;
  }

  .leaflet-popup-content {
    max-width: 250px;
    font-size: 13px;
  }

  .popup-moulin h2 {
    font-size: 14px;
  }

  .legend-control {
    font-size: 10px;
    padding: 6px 8px;
    max-width: 140px;
    line-height: 1.6;
  }

  .legend-control h4 {
    font-size: 11px;
  }

  .fullscreen-btn,
  .legend-toggle-btn {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }
}

@media (max-width: 480px) {
  #filtres-bar {
    padding: 6px;
  }

  #filtres-toggle {
    padding: 6px;
    font-size: 13px;
  }

  .filtre-group .checkboxes label,
  .filtre-group .radios label {
    font-size: 11px;
    padding: 1px 4px;
  }

  .filtre-group select {
    font-size: 11px;
    padding: 2px 4px;
  }

  #map {
    height: 75vh;
  }

  .leaflet-popup-content {
    max-width: 200px;
    font-size: 12px;
  }

  .popup-moulin h2 {
    font-size: 13px;
  }

  .popup-moulin .badge {
    font-size: 9px;
    padding: 1px 5px;
  }

  .legend-control {
    font-size: 9px;
    padding: 5px 6px;
    max-width: 120px;
  }
}
