/**
 * Mapa de Recursos - Estilos
 */

/* Smooth scroll para toda la página */
html {
  scroll-behavior: smooth;
}

/* Ancla con offset para que no vaya tan arriba */
#maparecursos {
  position: absolute;
  top: -100px;
  visibility: hidden;
}

/* Bloque principal */
.rn-mapa-recursos-block {
  position: relative;
  width: 100%;
  max-width: 100%;
  padding: 0;
}

/* Solo padding en móvil para evitar scroll horizontal */
@media (max-width: 767px) {
  .rn-mapa-recursos-block {
    padding: 0 1rem;
  }
}

/* Layout: Desktop con sidebar */
.rn-mapa-layout {
  display: block;
  width: 100%;
}

@media (min-width: 1024px) {
  .rn-mapa-layout {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 2.5rem;
    align-items: start;
  }
  
  .rn-map-controls {
    grid-column: 1;
  }
  
  .rn-map-wrapper {
    grid-column: 2;
  }
}

/* Panel de controles */
.rn-map-controls {
  background: #fff;
  border: 1px solid #e6e9e2;
  border-radius: 12px;
  padding: 1rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  margin-bottom: 1rem;
  position: relative;
  z-index: 100;
  width: 100%;
  max-width: 100%;
}

/* Toggle filtros móvil */
.rn-filters-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.75rem 1rem;
  background: #2f6237;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.9375rem;
  font-weight: 700;
  cursor: pointer;
  margin-bottom: 0.5rem;
  transition: background 0.2s;
}

.rn-filters-toggle:hover {
  background: #1f3d29;
}

.rn-toggle-icon {
  transition: transform 0.3s ease;
  font-size: 0.75rem;
}

.rn-filters-toggle.is-open .rn-toggle-icon {
  transform: rotate(180deg);
}

.rn-filters-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}

.rn-filters-content.is-open {
  max-height: 2000px;
  transition: max-height 0.4s ease-in;
}

@media (min-width: 1024px) {
  .rn-filters-toggle {
    display: none;
  }
  
  .rn-filters-content {
    max-height: none !important;
    overflow: visible !important;
  }
  
  .rn-map-controls {
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1.25rem;
    margin-bottom: 0;
  }
  
  /* Ocultar scrollbar pero mantener funcionalidad */
  .rn-map-controls::-webkit-scrollbar {
    width: 6px;
  }
  
  .rn-map-controls::-webkit-scrollbar-track {
    background: transparent;
  }
  
  .rn-map-controls::-webkit-scrollbar-thumb {
    background: #e6e9e2;
    border-radius: 3px;
  }
  
  .rn-map-controls::-webkit-scrollbar-thumb:hover {
    background: #d0d3cd;
  }
}

.rn-controls-column {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  overflow: visible;
}

.rn-control-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.rn-services-group {
  flex: 1;
  min-width: 300px;
}

.rn-stats-group {
  margin-left: auto;
  align-items: flex-end;
}

.rn-form-label {
  font-weight: 600;
  font-size: 0.875rem;
  color: #1f3d29;
  margin: 0;
}

.rn-form-select {
  padding: 0.625rem 1rem;
  border: 2px solid #e6e9e2;
  border-radius: 8px;
  font-size: 0.9375rem;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.2s;
  min-width: 180px;
}

.rn-form-select:hover,
.rn-form-select:focus {
  border-color: #2f6237;
  outline: none;
}

/* Filtros de chips */
.rn-service-filters-chips {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: flex-start;
}

.rn-filter-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  width: 100%;
  margin-bottom: 0.5rem;
}

@media (min-width: 1024px) {
  .rn-filter-group {
    width: auto;
  }
}

/* Chips base */
.rn-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.875rem;
  border-radius: 20px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
  border: 2px solid transparent;
}

.rn-chip input[type="checkbox"] {
  width: 14px;
  height: 14px;
  margin: 0;
  cursor: pointer;
}

.rn-chip:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Chip padre (categoría principal) - Estilo RuralNAV */
.rn-chip-parent {
  background: #2f6237;
  color: white;
  font-weight: 700;
  border-color: #2f6237;
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  border-radius: 12px;
  white-space: nowrap;
}

.rn-chip-parent:hover {
  background: #1f3d29;
  border-color: #1f3d29;
}

@media (min-width: 1024px) {
  .rn-chip-parent {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
  }
}


/* Chip hijo (subcategoría) - Estilo RuralNAV */
.rn-chip-child {
  background: #f6f7f4;
  color: #1f3d29;
  border: 1px solid #e6e9e2;
  padding: 0.25rem 0.5rem;
  font-size: 0.7rem;
  border-radius: 12px;
  gap: 0.25rem;
  transition: all 0.2s;
  white-space: nowrap;
}

@media (min-width: 1024px) {
  .rn-chip-child {
    font-size: 0.75rem;
  }
}

.rn-chip-child:hover {
  background: #fff;
  border-color: #4f8a3c;
}

.rn-chip-child input[type="checkbox"] {
  accent-color: #2f6237;
}

.rn-chip-child input[type="checkbox"]:checked {
  accent-color: #2f6237;
}

/* Estado checked en hijos */
.rn-chip-child input[type="checkbox"]:checked ~ span {
  color: #2f6237;
  font-weight: 700;
}

/* Stats badge - Estilo RuralNAV */
.rn-stats-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.75rem;
  background: #1f3d29;
  color: white;
  border-radius: 16px;
  font-size: 0.8125rem;
  font-weight: 600;
}

.rn-stats-badge strong {
  color: #d2a63a;
  font-weight: 700;
}

/* Stats y toggle vista */
.rn-stats-and-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Header actions */
.rn-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Grupo de botones toggle vista */
.rn-view-toggle-group {
  display: inline-flex;
  background: #f6f7f4;
  border: 1px solid #e6e9e2;
  border-radius: 6px;
  padding: 2px;
}

.rn-view-toggle-btn {
  padding: 0.375rem 0.75rem;
  background: transparent;
  color: #5b5e5a;
  border: none;
  border-radius: 4px;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.rn-view-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.5);
  color: #121312;
}

.rn-view-toggle-btn.active {
  background: #fff;
  color: #1f3d29;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Botón descargar PDF */
.rn-pdf-download-btn {
  padding: 0.5rem 1rem;
  background: #2f6237;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.8125rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.rn-pdf-download-btn:hover {
  background: #1f3d29;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.rn-pdf-download-btn:active {
  transform: translateY(0);
}

.rn-pdf-download-btn:disabled {
  background: #8a8f88;
  cursor: not-allowed;
  transform: none;
}

/* GPS Status */
.rn-gps-status {
  margin-top: 1rem;
  padding: 0.5rem 1rem;
  background: #f6f7f4;
  border-radius: 6px;
  font-size: 0.875rem;
  text-align: center;
}

/* Contenedor del mapa */
.rn-map-wrapper {
  position: relative;
  z-index: 1;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  isolation: isolate;
  width: 100%;
  min-height: 900px;
  display: flex;
  flex-direction: column;
}

@media (max-width: 1023px) {
  .rn-map-wrapper {
    min-height: 600px;
  }
}

@media (min-width: 1024px) {
  .rn-map-wrapper {
    min-height: 1050px;
  }
}

/* Toggle vista arriba del mapa */
.rn-map-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  background: #fff;
  border-bottom: 1px solid #e6e9e2;
  gap: 1rem;
  flex-wrap: wrap;
  z-index: 10;
}

.rn-map-content {
  flex: 1;
  position: relative;
  min-height: 600px;
}

.rn-leaflet-map {
  width: 100%;
  height: 100%;
  min-height: 750px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  position: relative;
  z-index: 0;
}

@media (max-width: 1023px) {
  .rn-leaflet-map {
    min-height: 600px;
  }
}

/* Asegurar que Leaflet no se monte sobre otros elementos */
.rn-leaflet-map .leaflet-pane,
.rn-leaflet-map .leaflet-tile-pane {
  z-index: 1 !important;
}

.rn-leaflet-map .leaflet-overlay-pane {
  z-index: 2 !important;
}

.rn-leaflet-map .leaflet-shadow-pane {
  z-index: 3 !important;
}

.rn-leaflet-map .leaflet-marker-pane {
  z-index: 4 !important;
}

.rn-leaflet-map .leaflet-tooltip-pane {
  z-index: 5 !important;
}

.rn-leaflet-map .leaflet-popup-pane {
  z-index: 6 !important;
}

.rn-leaflet-map .leaflet-control {
  z-index: 7 !important;
}

/* Popups de Leaflet */
.rn-marker-popup {
  min-width: 200px;
}

.rn-marker-popup h4 {
  margin: 0 0 0.5rem;
  font-size: 1.125rem;
  color: #1f3d29;
}

.rn-marker-popup p {
  margin: 0.25rem 0;
  font-size: 0.9375rem;
  color: #5b5e5a;
}

.rn-popup-tipo {
  color: #2f6237 !important;
  font-weight: 600;
}

.rn-popup-link {
  display: inline-block;
  margin-top: 0.5rem;
  color: #2f6237;
  font-weight: 600;
  text-decoration: none;
  transition: color 0.2s;
}

.rn-popup-link:hover {
  color: #1f3d29;
  text-decoration: underline;
}

/* Vista de lista */
.rn-resources-list {
  padding: 1.5rem;
  background: #fff;
  border-radius: 12px;
  border: 1px solid #e6e9e2;
  min-height: 750px;
  max-height: 70vh;
  overflow-y: auto;
}

@media (max-width: 1023px) {
  .rn-resources-list {
    min-height: 600px;
    max-height: 60vh;
  }
}

.rn-resource-item {
  padding: 1.25rem;
  border: 1px solid #e6e9e2;
  border-radius: 12px;
  margin-bottom: 1rem;
  transition: all 0.2s;
  background: #fff;
}

.rn-resource-item:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border-color: #2f6237;
}

.rn-resource-item h4 {
  margin: 0 0 0.75rem;
  color: #1f3d29;
  font-size: 1.125rem;
  font-weight: 700;
}

.rn-resource-tipo {
  display: inline-block;
  background: #eef3ec;
  color: #2f6237;
  font-weight: 600;
  font-size: 0.8125rem;
  padding: 0.25rem 0.625rem;
  border-radius: 12px;
  margin: 0 0 0.75rem;
}

.rn-resource-item p {
  margin: 0.5rem 0;
  color: #5b5e5a;
}

.rn-resource-link {
  display: inline-block;
  margin-top: 0.5rem;
  color: #2f6237;
  font-weight: 600;
  text-decoration: none;
  transition: color 0.2s;
}

.rn-resource-link:hover {
  color: #1f3d29;
  text-decoration: underline;
}

/* Responsive */
@media (max-width: 768px) {
  .rn-controls-row {
    flex-direction: column;
    gap: 1rem;
  }
  
  .rn-control-group {
    width: 100%;
  }
  
  .rn-services-group {
    min-width: auto;
  }
  
  .rn-stats-group {
    margin-left: 0;
    align-items: stretch;
  }
  
  .rn-service-toggles {
    justify-content: center;
  }
  
  .rn-leaflet-map {
    height: 60vh;
    min-height: 600px;
  }
  
  .rn-btn-toggle-view {
    width: 100%;
    margin-top: 0;
  }
}

/* Leaflet overrides */
.leaflet-popup-content-wrapper {
  border-radius: 8px;
}

/* Marcadores personalizados */
.rn-custom-marker {
  display: flex;
  align-items: center;
  justify-content: center;
}

.rn-marker-svg {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
}

.rn-marker-svg svg {
  width: 24px;
  height: 24px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.rn-marker-emoji {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 14px;
  border: 2px solid white;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Compatibilidad con marcadores antiguos */
.rn-simple-marker {
  border-radius: 50%;
}

/* Animaciones */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.rn-resource-item {
  animation: fadeIn 0.3s ease;
}
