/* Reset y variables */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --color-primary: #2E7D32;
    --color-secondary: #66BB6A;
    --color-accent: #FFA726;
    --color-text: #333;
    --color-text-light: #666;
    --color-border: #e0e0e0;
    --color-bg: #f5f5f5;
    --color-white: #ffffff;
    --header-height: 70px;
    --sidebar-width: 380px;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.2);
}

body {
    font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--color-text);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Header PASOS */
#main-header {
    background: var(--color-white);
    box-shadow: var(--shadow-md);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    z-index: 1000;
}

#main-header .container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
}

.logo_container {
    display: flex;
    align-items: center;
}

.logo_container a {
    display: flex;
    align-items: center;
}

#logo {
    height: 50px;
    width: auto;
}

#top-menu-nav {
    flex: 1;
    display: flex;
    justify-content: flex-end;
}

#top-menu {
    display: flex;
    list-style: none;
    gap: 30px;
    align-items: center;
}

.menu-item {
    position: relative;
}

.menu-item>a {
    color: var(--color-text);
    text-decoration: none;
    font-weight: 500;
    font-size: 15px;
    padding: 8px 0;
    transition: color 0.3s;
}

.menu-item>a:hover {
    color: var(--color-primary);
}

.current-menu-item>a {
    color: var(--color-primary);
    font-weight: 600;
}

.sub-menu {
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--color-white);
    box-shadow: var(--shadow-md);
    list-style: none;
    padding: 10px 0;
    min-width: 200px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s;
    border-radius: 8px;
    margin-top: 10px;
}

.menu-item-has-children:hover .sub-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.sub-menu li {
    padding: 0;
}

.sub-menu a {
    display: block;
    padding: 10px 20px;
    color: var(--color-text);
    text-decoration: none;
    transition: background 0.3s;
}

.sub-menu a:hover {
    background: var(--color-bg);
    color: var(--color-primary);
}

#mobile-menu-toggle {
    display: none;
    flex-direction: column;
    gap: 5px;
    cursor: pointer;
}

#mobile-menu-toggle span {
    display: block;
    width: 25px;
    height: 3px;
    background: var(--color-text);
    transition: all 0.3s;
}

/* Contenido principal */
#main-content {
    margin-top: var(--header-height);
    display: flex;
    height: calc(100vh - var(--header-height));
}

/* Mapa */
#map-container {
    flex: 1;
    position: relative;
    background: #e8f4f1;
}

#map {
    width: 100%;
    height: 100%;
}

#loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--color-white);
    padding: 20px 40px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    font-weight: 600;
    color: var(--color-primary);
    z-index: 500;
    display: flex;
    align-items: center;
    gap: 12px;
}

#loading::before {
    content: '';
    width: 20px;
    height: 20px;
    border: 3px solid var(--color-primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Sidebar */
#sidebar {
    width: var(--sidebar-width);
    background: var(--color-white);
    box-shadow: var(--shadow-md);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 30px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    color: var(--color-white);
    text-align: center;
}

.sidebar-header h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.subtitle {
    font-size: 14px;
    opacity: 0.95;
    font-weight: 400;
}

/* Secciones del sidebar */
.filters-section,
.stats-section,
.legend-section {
    padding: 25px;
    border-bottom: 1px solid var(--color-border);
}

.filters-section h3,
.stats-section h3,
.legend-section h3 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 15px;
    color: var(--color-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Filtros */
.filter-group {
    margin-bottom: 15px;
}

.filter-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 6px;
}

.filter-group label svg {
    color: var(--color-primary);
}

.filter-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: var(--color-white);
    cursor: pointer;
    transition: all 0.3s;
}

.filter-group select:hover {
    border-color: var(--color-primary);
}

.filter-group select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.1);
}

/* Estadísticas */
.stats-grid-vertical {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 400px;
    overflow-y: auto;
}

.stat-item {
    background: linear-gradient(135deg, #f8fdf9, #e8f5e9);
    padding: 15px;
    border-radius: 10px;
    border: 1px solid rgba(46, 125, 50, 0.1);
    cursor: pointer;
    transition: all 0.3s;
}

.stat-item:hover {
    transform: translateX(4px);
    box-shadow: var(--shadow-sm);
    border-color: var(--color-primary);
}

.stat-item.selected {
    background: linear-gradient(135deg, #66BB6A, #4CAF50);
    border-color: var(--color-primary);
    box-shadow: var(--shadow-md);
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.stat-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text);
}

.stat-item.selected .stat-name {
    color: var(--color-white);
}

.stat-count {
    font-size: 18px;
    font-weight: 700;
    color: var(--color-primary);
}

.stat-item.selected .stat-count {
    color: var(--color-white);
}

.stat-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--color-text-light);
}

.stat-item.selected .stat-footer {
    color: rgba(255, 255, 255, 0.9);
}

.stat-area {
    font-weight: 600;
}

.loading-stats {
    text-align: center;
    padding: 20px;
    color: var(--color-text-light);
}

/* Leyenda */
.leyenda-items {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.leyenda-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 6px;
    font-size: 13px;
    transition: background 0.3s;
}

.leyenda-item:hover {
    background: var(--color-bg);
}

.leyenda-color {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.leyenda-label {
    font-weight: 500;
    color: var(--color-text);
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--color-text-light);
    font-size: 14px;
}

/* Footer */
#main-footer {
    background: #2c3e50;
    color: var(--color-white);
    padding: 20px 0;
    text-align: center;
}

#main-footer .container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 30px;
}

#main-footer p {
    font-size: 14px;
    opacity: 0.9;
}

/* Estilos del mapa */
.leaflet-popup-content-wrapper {
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
}

.leaflet-popup-content {
    margin: 15px;
    font-size: 14px;
}

.leaflet-popup-content h4 {
    color: var(--color-primary);
    margin-bottom: 10px;
    font-size: 16px;
}

/* Scrollbar personalizado */
#sidebar::-webkit-scrollbar,
.stats-grid-vertical::-webkit-scrollbar {
    width: 6px;
}

#sidebar::-webkit-scrollbar-track,
.stats-grid-vertical::-webkit-scrollbar-track {
    background: var(--color-bg);
}

#sidebar::-webkit-scrollbar-thumb,
.stats-grid-vertical::-webkit-scrollbar-thumb {
    background: var(--color-primary);
    border-radius: 3px;
}

/* Responsive */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 320px;
    }
}

@media (max-width: 768px) {
    #top-menu-nav {
        display: none;
    }

    #mobile-menu-toggle {
        display: flex;
    }

    #main-content {
        flex-direction: column;
    }

    #sidebar {
        width: 100%;
        height: 50vh;
        order: 2;
    }

    #map-container {
        height: 50vh;
        order: 1;
    }

    .sidebar-header {
        padding: 20px;
    }

    .sidebar-header h2 {
        font-size: 20px;
    }

    .filters-section,
    .stats-section,
    .legend-section {
        padding: 20px;
    }
}

/* Modal Infografía */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s;
}

.modal.show {
    opacity: 1;
}

.modal-content {
    background-color: var(--color-white);
    margin: auto;
    padding: 20px;
    border-radius: 12px;
    width: 90%;
    max-width: 1000px;
    height: 85vh;
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.close-modal {
    color: #666;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    transition: color 0.3s;
    display: flex;
    align-items: center;
}

.close-modal:hover,
.close-modal:focus {
    color: var(--color-primary);
    text-decoration: none;
}

/* Modal Header & Actions */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--color-border);
}

.modalTitle {
    margin: 0;
    font-size: 18px;
    color: var(--color-primary);
}

.modal-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.download-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background-color: var(--color-primary);
    color: var(--color-white);
    padding: 8px 16px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.3s, transform 0.2s;
}

.download-btn:hover {
    background-color: var(--color-secondary);
    transform: translateY(-2px);
}

.download-btn svg {
    width: 16px;
    height: 16px;
}

.iframe-container {
    flex: 1;
    width: 100%;
    margin-top: 0;
    /* Remove top margin as header handles spacing */
    background: #f5f5f5;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.iframe-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}