/* Variables CSS */
:root {
  --primary-color: #2c3e50;
  --secondary-color: #34495e;
  --accent-color: #3498db;
  --success-color: #27ae60;
  --warning-color: #f39c12;
  --error-color: #e74c3c;
  --text-light: #ecf0f1;
  --text-muted: #bdc3c7;
  --text-dark: #2c3e50;
  --border-color: #4a5f7a;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.2);
  --border-radius: 8px;
  --transition: all 0.3s ease;
  --sidebar-width: 380px;
}

/* Reset y base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  height: 100vh;
  overflow: hidden;
  background: #f8f9fa;
}

/* Contenedor principal */
.app-container {
  display: flex;
  height: 100vh;
  position: relative;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--primary-color);
  color: var(--text-light);
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
}

.sidebar.collapsed {
  margin-left: calc(-1 * var(--sidebar-width));
}

.sidebar-header {
  padding: 24px 20px;
  background: var(--secondary-color);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.logo i {
  font-size: 32px;
  color: var(--accent-color);
}

.logo h1 {
  font-size: 28px;
  font-weight: 300;
  color: var(--text-light);
}

.sidebar-header p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.4;
}

.sidebar-content {
  flex: 1;
  padding: 0;
}

/* Secciones de categorías */
.category-section {
  border-bottom: 1px solid var(--secondary-color);
}

.category-header {
  padding: 16px 20px;
  background: var(--primary-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: var(--transition);
  border-left: 4px solid transparent;
}

.category-header:hover {
  background: var(--secondary-color);
  border-left-color: var(--accent-color);
}

.category-header.collapsed {
  background: var(--secondary-color);
}

.category-icon {
  font-size: 12px;
  transition: transform 0.3s ease;
  color: var(--accent-color);
  width: 16px;
}

.category-header.collapsed .category-icon {
  transform: rotate(-90deg);
}

.category-title {
  font-weight: 600;
  font-size: 16px;
  flex: 1;
}

.category-count {
  font-size: 12px;
  color: var(--text-muted);
  background: rgba(52, 73, 94, 0.8);
  padding: 4px 8px;
  border-radius: 12px;
  font-weight: 500;
}

.category-content {
  max-height: 1000px;
  overflow: hidden;
  transition: max-height 0.3s ease;
  background: var(--secondary-color);
}

.category-content.collapsed {
  max-height: 0;
}

/* Items de capas */
.layer-item {
  margin: 8px 16px;
  padding: 16px;
  background: var(--primary-color);
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: var(--transition);
  border-left: 4px solid transparent;
  position: relative;
}

.layer-item:hover {
  background: #4a5f7a;
  transform: translateX(5px);
  box-shadow: var(--shadow);
}

.layer-item.active {
  background: #2980b9;
  border-left-color: var(--accent-color);
  box-shadow: 0 4px 12px rgba(41, 128, 185, 0.3);
}

.layer-item.active:hover {
  background: var(--accent-color);
}

.layer-item.loading {
  opacity: 0.6;
  pointer-events: none;
}

.layer-item.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 16px;
  width: 16px;
  height: 16px;
  border: 2px solid var(--accent-color);
  border-top: 2px solid transparent;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  transform: translateY(-50%);
}

@keyframes spin {
  0% {
    transform: translateY(-50%) rotate(0deg);
  }
  100% {
    transform: translateY(-50%) rotate(360deg);
  }
}

.layer-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
  color: var(--text-light);
  display: flex;
  align-items: center;
  gap: 8px;
}

.layer-description {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 8px;
}

.layer-depth {
  font-size: 11px;
  color: #95a5a6;
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Controles de opacidad */
.opacity-control {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.opacity-label {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.opacity-slider {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.2);
  outline: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.opacity-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-color);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: var(--shadow);
}

.opacity-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-color);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: var(--shadow);
}

/* Contenedor del mapa */
.map-container {
  flex: 1;
  position: relative;
  height: 100vh;
}

#map {
  width: 100%;
  height: 100%;
}

/* Controles del mapa */
.map-controls {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

/* Botón toggle sidebar */
.toggle-sidebar {
  position: absolute;
  top: 16px;
  left: calc(var(--sidebar-width) + 16px);
  z-index: 1001;
  background: var(--primary-color);
  color: white;
  border: none;
  padding: 12px;
  border-radius: var(--border-radius);
  cursor: pointer;
  font-size: 16px;
  transition: var(--transition);
  box-shadow: var(--shadow);
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toggle-sidebar:hover {
  background: var(--secondary-color);
  transform: scale(1.05);
}

.sidebar.collapsed + .toggle-sidebar {
  left: 16px;
}

/* Selector de mapas base */
.basemap-selector {
  background: rgba(44, 62, 80, 0.95);
  color: white;
  padding: 8px;
  border-radius: var(--border-radius);
  display: flex;
  gap: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.basemap-option {
  cursor: pointer;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  transition: var(--transition);
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.basemap-option:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.basemap-option.active {
  background: var(--accent-color);
  border-color: #2980b9;
  box-shadow: 0 2px 4px rgba(52, 152, 219, 0.3);
}

/* Display de coordenadas */
.coordinates-display {
  background: rgba(44, 62, 80, 0.95);
  color: white;
  padding: 10px 16px;
  border-radius: var(--border-radius);
  font-size: 12px;
  font-family: "Courier New", monospace;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Panel de información */
.info-panel {
  position: absolute;
  bottom: 16px;
  right: 16px;
  background: rgba(44, 62, 80, 0.95);
  color: white;
  padding: 16px;
  border-radius: var(--border-radius);
  font-size: 12px;
  max-width: 280px;
  z-index: 1000;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(10px);
}

.info-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 14px;
}

.info-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.info-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.info-item i {
  width: 16px;
  color: var(--accent-color);
}

/* Panel de leyendas */
.legend-panel {
  position: absolute;
  bottom: 16px;
  left: calc(var(--sidebar-width) + 16px);
  background: rgba(44, 62, 80, 0.98);
  color: white;
  padding: 0;
  border-radius: var(--border-radius);
  font-size: 12px;
  max-width: 350px;
  max-height: 450px;
  z-index: 1000;
  transition: var(--transition);
  display: none;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(10px);
  overflow: hidden;
}

.sidebar.collapsed ~ .map-container .legend-panel {
  left: 16px;
}

.legend-panel.show {
  display: block;
}

.legend-header {
  padding: 16px 20px;
  background: var(--secondary-color);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.legend-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-color);
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: var(--transition);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.legend-close:hover {
  color: white;
  background: var(--error-color);
}

.legend-content {
  padding: 16px;
  max-height: 380px;
  overflow-y: auto;
}

.no-legends {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
}

.no-legends i {
  font-size: 24px;
  margin-bottom: 8px;
  display: block;
}

.legend-item {
  margin-bottom: 16px;
  padding: 12px;
  background: rgba(52, 73, 94, 0.8);
  border-radius: 6px;
  border-left: 4px solid var(--accent-color);
}

.legend-item-title {
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text-light);
}

/* Leyendas personalizadas */
.custom-legend {
  margin-top: 8px;
  width: 100%;
  border-collapse: collapse;
}

.custom-legend td {
  padding: 4px 8px;
  font-size: 11px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.color-box {
  width: 20px;
  height: 16px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 3px;
}

.legend-unit {
  font-style: italic;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.legend-gradient {
  height: 20px;
  width: 100%;
  margin: 8px 0;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.legend-gradient-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Responsive */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 100%;
  }

  .sidebar {
    position: absolute;
    height: 100%;
    z-index: 1500;
  }

  .toggle-sidebar {
    left: 16px !important;
  }

  .map-controls {
    top: 80px;
    flex-direction: column;
    gap: 8px;
  }

  .basemap-selector {
    flex-direction: column;
    gap: 4px;
  }

  .legend-panel {
    left: 16px !important;
    max-width: calc(100% - 32px);
    bottom: 100px;
  }

  .info-panel {
    bottom: 16px;
    right: 16px;
    max-width: calc(100% - 32px);
    font-size: 11px;
  }

  .coordinates-display {
    font-size: 10px;
    padding: 8px 12px;
  }
}

/* Scrollbar personalizado */
.sidebar::-webkit-scrollbar,
.legend-content::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track,
.legend-content::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb,
.legend-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover,
.legend-content::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.5);
}

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

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

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