/* ESTRUCTURA PRINCIPAL */
.legend.leaflet-control {
  background: white;
  padding: 12px 15px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  font-size: 14px;
  line-height: 1.5;
  width: 280px;
  max-width: 280px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

/* Media query específica para celulares (horizontal y vertical) */
@media (max-width: 600px), (max-height: 600px) and (orientation: landscape) {
  .legend.leaflet-control {
    overflow-y: auto; /* Scroll vertical */
    max-height: 60vh; /* Limitar altura a 60% de la pantalla */
    -webkit-overflow-scrolling: touch; /* Mejorar scroll en dispositivos táctiles */
  }

  /* Preservamos el diseño original cuando está colapsado */
  .legend.leaflet-control.collapsed {
    overflow: hidden; /* Sin scroll cuando está colapsado */
    max-height: none;
  }

  /* Ajuste interno para el contenido de la leyenda */
  #leyenda-contenido {
    max-height: calc(60vh - 50px); /* Restar espacio de header */
    overflow-y: auto;
  }
}

/* ESTILOS ORIGINALES PRESERVADOS */
.legend.leaflet-control.collapsed {
  width: 140px;
  padding: 15px 12px;
  min-height: 48px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* CABECERA */
.legend-header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 8px;
}

.legend-header-container h4 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  width: 100%;
}

.legend.leaflet-control.collapsed .legend-header-container {
  margin-bottom: 0;
}

.legend-header-container h4 span {
  padding-top: 2px;
}

.legend.leaflet-control.collapsed h4 {
  justify-content: center;
  padding-right: 0;
}

/* CONTENIDO */
#leyenda-contenido {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 500px;
  overflow-y: auto;
}

#leyenda-contenido.collapsed {
  max-height: 0;
  opacity: 0;
}

#leyenda-contenido::-webkit-scrollbar {
  width: 6px;
}

#leyenda-contenido::-webkit-scrollbar-thumb {
  background: #adb5bd;
  border-radius: 3px;
}

/* SECCIONES */
.legend-section {
  margin-top: 10px;
}

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

.legend-items {
  padding-left: 10px;
  overflow: hidden;
  transition: max-height 0.3s ease;
  max-height: 1000px;
}

.legend-subsection {
  margin: 8px 0;
}

.legend-subsection em {
  font-weight: normal;
  color: #555;
  display: block;
  margin-bottom: 2px;
}

.legend-content {
  overflow-y: auto;
  transition: max-height 0.3s ease;
  max-height: 300px;
}

.collapsed {
  max-height: 0 !important;
}

/* ELEMENTOS DE INTERFAZ */
.legend-header,
.legend-subheader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}

.legend-header-buttons {
  display: flex;
  gap: 4px;
  align-items: center;
}

.legend-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px;
}

.legend-content label {
  display: block;
  margin-bottom: 2px;
  cursor: pointer;
}

.legend-content input[type="checkbox"] {
  margin-right: 6px;
}

/* BOTONES */
.toggle-btn {
  background: none;
  border: none;
  font-weight: bold;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0 5px;
}

#toggle-leyenda-global {
  background: #e9ecef;
  border: none;
  border-radius: 6px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-left: 10px;
  color: #495057;
}

#toggle-leyenda-global:hover {
  background: #dee2e6;
}

.legend.leaflet-control.collapsed .toggle-btn {
  position: static;
  margin-left: 5px;
}

.info-btn {
  background-color: #eee;
  border: 1px solid #ccc;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 12px;
  font-weight: bold;
  line-height: 1;
  text-align: center;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.multimedia-btn {
  background-color: #e9d8fd;
  border: 1px solid #9f7aea;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: #553c9a;
}

.multimedia-btn:hover {
  background-color: #e0e0e0;
}
