/* Importar fuente Inter de Google Fonts para una tipografía moderna */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* Reglas básicas para todo el documento */
html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: #f0f2f5;
    color: #333;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Aplicar box-sizing para un manejo de layout más intuitivo */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* Layout principal de la aplicación */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background-color: #f0f2f5;
    box-shadow: none;
    border-radius: 0;
    overflow: hidden;
    margin: 0;
    position: relative;
}

/* Contenedor del mapa */
#map-container {
    flex-grow: 1;
    height: 100%;
    min-height: 400px;
    position: relative;
    overflow: hidden;
    border-radius: 0;
    width: 100%;
}

#map {
    width: 100%;
    height: 100%;
    min-height: inherit;
    margin: 0;
    padding: 0;
    touch-action: pan-x pan-y;
}

/* --- Sidebar --- */
/* Estilos de la barra lateral como menú desplegable */
.sidebar-dropdown {
    position: absolute;
    top: 0;
    left: -300px;
    width: 280px;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.95);
    padding: 20px;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.5);
    transition: left 0.3s ease;
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

    /* Clase para mostrar el menú, se activa con JavaScript */
    .sidebar-dropdown.open {
        left: 0;
    }

/* Contenedor para alinear el título y el botón de cerrar */
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

/* Estilos de los elementos internos del sidebar */
.sidebar-dropdown h1 {
    font-size: 2.2rem;
    font-weight: 700;
    color: #4a4a4a;
    margin: 0;
}

    .sidebar-dropdown h1 span {
        color: #2c7be5;
    }

.sidebar-dropdown label {
    font-weight: 600;
    color: #555;
    margin-bottom: 0.6rem;
    display: block;
    font-size: 1.1rem;
}

/* Estilos de los botones para abrir y cerrar */
.open-btn {
    position: absolute;
    top: 80px;
    left: 20px;
    /* Estilos nuevos para mejorar la visibilidad */
    background-color: rgba(255, 255, 255, 0.95); /* Fondo blanco semi-transparente */
    border: 1px solid #dcdcdc; /* Borde suave */
    border-radius: 10px; /* Bordes redondeados */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); /* Sombra para que se destaque */
    padding: 0.8rem 1.2rem; /* Espacio interno para que no sea solo un símbolo */
    width: 50px; /* Tamaño fijo */
    height: 50px; /* Tamaño fijo */
    display: flex; /* Para centrar el símbolo */
    justify-content: center;
    align-items: center;
    /* Fin de estilos nuevos */
    font-size: 2.2rem;
    cursor: pointer;
    z-index: 1001;
    color: #3867d6; /* El color del símbolo */
    transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
}

    .open-btn:hover {
        background-color: #f0f2f5;
        transform: translateY(-3px);
        box-shadow: 0 6px 15px rgba(0, 0, 0, 0.2);
    }

.close-btn {
    font-size: 2.2rem;
    background-color: transparent;
    border: none;
    cursor: pointer;
    z-index: 1001;
    color: #3867d6;
    margin: 0;
}

/* Estilos para los botones dentro de la barra lateral */
#sidebar button {
    padding: 0.9rem 1.5rem;
    background-color: #2c7be5;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 8px rgba(44, 123, 229, 0.2);
    transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
    margin-top: 15px;
}

    #sidebar button:hover {
        background-color: #1a6ac9;
        transform: translateY(-2px);
        box-shadow: 0 6px 12px rgba(44, 123, 229, 0.3);
    }

    #sidebar button:active {
        background-color: #114b9c;
        transform: translateY(0);
        box-shadow: 0 2px 4px rgba(44, 123, 229, 0.2);
    }

    #sidebar button:disabled {
        background-color: #cccccc;
        color: #888;
        cursor: not-allowed;
        box-shadow: none;
        transform: none;
    }

/* Ajustes específicos para los inputs y selects */
.filtro {
    margin-bottom: 15px;
}

    .filtro select {
        width: 100%;
        padding: 0.9rem 1.2rem;
        border: 1px solid #dcdcdc;
        border-radius: 8px;
        background-color: #fff;
        font-size: 1.1rem;
        color: #333;
        appearance: none;
        background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23333%22%20d%3D%22M287%2C146.2L146.2%2C287L5.4%2C146.2l140.8%2C140.8Z%22%2F%3E%3C%2Fsvg%3E');
        background-repeat: no-repeat;
        background-position: right 0.7em top 50%, 0 0;
        background-size: 0.65em auto, 100%;
        transition: border-color 0.3s ease, box-shadow 0.3s ease;
    }

        .filtro select:focus {
            border-color: #2c7be5;
            outline: none;
            box-shadow: 0 0 0 3px rgba(44, 123, 229, 0.25);
        }


        /* Estilo para hacer el panel de leyenda flotante, pequeño y posicionado */
#legendPanel {
    position: absolute; /* CLAVE: Permite que flote sobre el mapa */
    bottom: 20px; /* Distancia desde el borde inferior del mapa */
    right: 20px; /* Distancia desde el borde derecho del mapa */
    z-index: 1000; /* Asegura que siempre esté por encima del mapa */
    /* Propiedades para hacerlo compacto */
    max-width: 200px; /* Ancho máximo reducido */
    max-height: 35vh; /* Altura limitada para dejar espacio en la pantalla */
    overflow-y: auto; /* Habilita la barra de desplazamiento si hay muchas leyendas */
    /* Estilo visual */
    background-color: #ffffff;
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); /* Sombra suave para destacarlo */
    /* Inicialmente oculto o visible (debes definir el estado inicial en el JS o aquí) */
    display: block; /* Mantenemos visible para añadir el botón de ocultar */
}

            /* Opcional: Estilos para el contenido interno para hacerlo aún más pequeño */
    #legendPanel h3 {
        font-size: 1rem;
        margin-bottom: 5px;
    }

    #legendPanel label, #legendPanel .legend-item {
        font-size: 0.85rem;
    }




/* Añadir al final de styles.txt */

#btnToggleLeyenda {
    position: absolute;
    bottom: 20px;
    right: 230px; /* Posicionarlo a la izquierda del panel (200px del ancho del panel + 10px de margen) */
    width: 35px;
    height: 35px;
    border-radius: 50%; /* Botón redondo */
    background-color: #007bff; /* Color azul primario */
    color: white;
    font-size: 1rem;
    font-weight: bold;
    border: none;
    cursor: pointer;
    z-index: 1001; /* Asegura que esté por encima del panel */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
    transition: background-color 0.2s;
}

    #btnToggleLeyenda:hover {
        background-color: #0056b3;
    }




/* Oculta el botón de abrir cuando la barra lateral está visible */
body.sidebar-open .open-btn {
    display: none;
}

/* Toolbar flotante */
#toolbar {
    position: absolute;
    top: 15px;
    right: 15px;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    z-index: 900;
    background-color: rgba(255, 255, 255, 0.95);
    padding: 12px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(5px);
}

    #toolbar button {
        width: 50px;
        height: 50px;
        font-size: 1.6rem;
        border: 1px solid #dcdcdc;
        background-color: #fff;
        border-radius: 10px;
        cursor: pointer;
        display: flex;
        justify-content: center;
        align-items: center;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.08);
        transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
        color: #555;
    }

        #toolbar button:hover {
            background-color: #f0f2f5;
            transform: translateY(-3px);
            box-shadow: 0 6px 15px rgba(0, 0, 0, 0.2);
        }

        #toolbar button:active {
            background-color: #e0e2e5;
            transform: translateY(0);
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        }

/* Botón de capas */
#btnCapas {
    position: absolute;
    top: 160px;
    left: 15px;
    z-index: 900;
    padding: 0.8rem 1.2rem;
    background-color: rgba(255, 255, 255, 0.95);
    border: 1px solid #dcdcdc;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
}

    #btnCapas:hover {
        background-color: #f0f2f5;
        transform: translateY(-3px);
        box-shadow: 0 6px 15px rgba(0, 0, 0, 0.2);
    }

    #btnCapas:disabled {
        background-color: #e0e0e0;
        color: #888;
        cursor: not-allowed;
        box-shadow: none;
        transform: none;
    }

    #btnCapas .icono {
        font-size: 1.4em;
    }

/* Panel de capas */
#panelCapas {
    position: absolute;
    top: 230px; /* Se queda igual, pero ahora el botón de capas está a 100px */
    left: 15px;
    z-index: 850; /* Cambiado a 850, menor que el botón de capas (z-index: 900) */
    background-color: rgba(255, 255, 255, 0.98);
    border: 1px solid #dcdcdc;
    padding: 20px;
    border-radius: 12px;
    display: none;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(8px);
    flex-direction: column;
    gap: 1rem;
    min-width: 250px;
}

    #panelCapas label {
        display: flex;
        align-items: center;
        gap: 0.8rem;
        margin-bottom: 0;
        cursor: pointer;
        font-size: 1.1rem;
        color: #4a4a4a;
        transition: color 0.2s ease;
    }

        #panelCapas label:hover {
            color: #2c7be5;
        }

    #panelCapas input[type="checkbox"] {
        transform: scale(1.5);
        cursor: pointer;
        accent-color: #2c7be5;
        min-width: 20px;
        min-height: 20px;
    }
/* Modal genérico */
#modalFondo {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: none;
    z-index: 9999;
    backdrop-filter: blur(5px);
}

.modal {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

    .modal.hidden {
        display: none;
    }

.modal-content {
    background-color: #fff;
    padding: 30px 40px;
    border-radius: 15px;
    width: 90%;
    max-width: 550px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    position: relative;
    animation: fadeIn 0.3s ease-out;
}

    .modal-content h2 {
        font-size: 1.8rem;
        color: #333;
        margin-bottom: 1.8rem;
    }

    .modal-content input {
        width: calc(100% - 20px);
        padding: 14px 12px;
        margin: 12px 0 25px;
        border: 1px solid #dcdcdc;
        border-radius: 10px;
        font-size: 1.1rem;
        color: #333;
        transition: border-color 0.3s ease, box-shadow 0.3s ease;
    }

        .modal-content input:focus {
            border-color: #2c7be5;
            outline: none;
            box-shadow: 0 0 0 4px rgba(44, 123, 229, 0.3);
        }

    .modal-content button {
        padding: 12px 25px;
        background-color: #2c7be5;
        color: white;
        border: none;
        border-radius: 10px;
        cursor: pointer;
        font-size: 1.15rem;
        font-weight: 600;
        box-shadow: 0 4px 10px rgba(44, 123, 229, 0.25);
        transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
    }

        .modal-content button:hover {
            background-color: #1a6ac9;
            transform: translateY(-2px);
            box-shadow: 0 6px 15px rgba(44, 123, 229, 0.35);
        }

        .modal-content button:active {
            background-color: #114b9c;
            transform: translateY(0);
            box-shadow: 0 2px 5px rgba(44, 123, 229, 0.25);
        }

.close {
    position: absolute;
    top: 18px;
    right: 22px;
    font-size: 30px;
    font-weight: bold;
    color: #aaa;
    cursor: pointer;
    transition: color 0.3s ease;
}

    .close:hover {
        color: #555;
    }

/* Animación de entrada para el modal */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, -70%);
    }

    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

/* Popups de OpenLayers */
.ol-popup,
.terreno-popup {
    position: absolute;
    background-color: white;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
    padding: 18px 25px;
    border-radius: 12px;
    border: 1px solid #dcdcdc;
    min-width: 280px;
    max-width: 400px;
    z-index: 1001;
    font-size: 1rem;
    line-height: 1.6;
    animation: fadeIn 0.3s ease-out;
}

    /* Flecha del popup */
    .ol-popup:after,
    .ol-popup:before,
    .terreno-popup:after,
    .terreno-popup:before {
        content: " ";
        position: absolute;
        pointer-events: none;
        top: 100%;
        border: solid transparent;
        height: 0;
        width: 0;
    }

    .ol-popup:after {
        border-top-color: white;
        border-width: 14px;
        left: 50%;
        margin-left: -14px;
    }

    .ol-popup:before {
        border-top-color: #dcdcdc;
        border-width: 15px;
        left: 50%;
        margin-left: -15px;
    }

/* Cerrar botón del popup */
.ol-popup-closer,
.terreno-popup-closer {
    text-decoration: none;
    position: absolute;
    top: 10px;
    right: 12px;
    font-size: 24px;
    color: #888;
    cursor: pointer;
    transition: color 0.3s ease;
}

    .ol-popup-closer:hover {
        color: #333;
    }

.terreno-popup-closer {
    top: 8px;
    font-size: 26px;
    color: #000;
}

/* Utilidades */
.hidden {
    display: none !important;
}

/* Indicadores de carga */
#map-loading-indicator,
#search-loading-indicator {
    background-color: rgba(255, 255, 255, 0.9);
    padding: 25px;
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    color: #333;
    font-size: 1.2em;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
}

#map-loading-indicator {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#search-loading-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.spinner {
    border: 5px solid rgba(0, 0, 0, 0.1);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border-left-color: #2c7be5;
    animation: spin 1s linear infinite;
    margin-right: 12px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Estilos para el mensaje temporal (toast/snackbar) */
#temporary-message-container {
    position: fixed;
    top: 25px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 11000;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
    width: 100%;
}

.temporary-message {
    background-color: rgba(44, 123, 229, 0.95);
    color: white;
    padding: 15px 25px;
    border-radius: 10px;
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.25);
    margin-bottom: 12px;
    opacity: 0;
    transform: translateY(-25px);
    transition: opacity 0.3s ease-out, transform 0.3s ease-out;
    max-width: 450px;
    text-align: center;
    font-size: 1rem;
    font-weight: 500;
    pointer-events: auto;
}

    .temporary-message.show {
        opacity: 1;
        transform: translateY(0);
    }

    .temporary-message.hide {
        opacity: 0;
        transform: translateY(-25px);
    }

/* Responsive Design */
@media (max-width: 1024px) {
    #app {
        flex-direction: column;
        margin: 10px;
        height: auto;
    }

    .sidebar-dropdown {
        width: 100%;
        height: auto;
        padding: 1.2rem;
        gap: 1rem;
        border-right: none;
        border-bottom: 1px solid #e0e0e0;
        border-radius: 12px 12px 0 0;
    }

    .sidebar-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .sidebar-dropdown h1 {
        font-size: 2.8rem;
        margin-bottom: 1rem;
    }

    .open-btn {
        top: 10px;
        left: 10px;
        font-size: 1.8rem;
    }

    .close-btn {
        margin-left: auto;
        position: absolute;
        top: 10px;
        right: 10px;
    }

    .filtro,
    #sidebar button {
        width: 100%;
        margin-top: 10px;
    }

    #toolbar {
        top: 10px;
        right: 10px;
        padding: 8px;
        gap: 0.4rem;
        border-radius: 8px;
    }

        #toolbar button {
            width: 42px;
            height: 42px;
            font-size: 1.6rem;
            border-radius: 6px;
        }

    #btnCapas {
        top: 100px;
        left: 10px;
        padding: 0.7rem 1rem;
        font-size: 1.2rem;
        border-radius: 8px;
    }

    #panelCapas {
        position: absolute;
        top: 150px;
        left: 10px;
        right: 10px;
        width: auto;
        padding: 15px;
        border-radius: 10px;
        gap: 0.8rem;
        min-width: unset;
        flex-direction: column;
    }

        #panelCapas label {
            font-size: 1.1rem;
            margin-bottom: 0.5rem;
            display: flex;
            align-items: center;
            gap: 0.8rem;
            cursor: pointer;
        }

        #panelCapas input[type="checkbox"] {
            transform: scale(1.6);
            margin: 0;
            -webkit-transform: scale(1.6);
            -moz-transform: scale(1.6);
            -ms-transform: scale(1.6);
            -o-transform: scale(1.6);
            min-width: 22px;
            min-height: 22px;
        }

    .modal-content {
        width: 95%;
        padding: 20px 25px;
    }

        .modal-content h2 {
            font-size: 1.3rem;
            margin-bottom: 1rem;
        }

        .modal-content input {
            padding: 10px;
            margin: 8px 0 15px;
        }

        .modal-content button {
            padding: 8px 16px;
            font-size: 1rem;
        }

    .close {
        font-size: 24px;
        top: 10px;
        right: 12px;
    }

    .ol-popup,
    .terreno-popup {
        min-width: 220px;
        max-width: 90vw;
        padding: 12px 15px;
    }

        .ol-popup:after,
        .ol-popup:before,
        .terreno-popup:after,
        .terreno-popup:before {
            border-width: 10px;
            margin-left: -10px;
        }

        .ol-popup:before,
        .terreno-popup:before {
            border-width: 11px;
            margin-left: -11px;
        }

    .terreno-popup-closer {
        font-size: 20px;
    }
}

@media (max-width: 768px) {
    #sidebar {
        flex-direction: column;
        align-items: stretch;
        padding: 1rem;
        gap: 1rem;
    }

        #sidebar h1 {
            font-size: 2.2rem;
        }

    .filtro {
        flex: 1 1 100%;
    }

        .filtro label {
            font-size: 1.1rem;
        }

        .filtro select {
            padding: 1rem;
            font-size: 1.2rem;
        }

    #sidebar button {
        flex: 1 1 100%;
    }

    #map-container {
        height: 50vh;
    }

    #toolbar,
    #btnCapas,
    #panelCapas {
        position: relative;
        margin: 10px auto;
        width: calc(100% - 20px);
        max-width: 300px;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.5rem;
    }

        #toolbar button {
            flex: 0 0 auto;
            margin: 0.25rem;
        }

    #btnCapas {
        justify-content: center;
    }

    #panelCapas {
        display: none;
        top: auto;
        left: auto;
        padding: 10px;
        border-radius: 8px;
        gap: 0.5rem;
        min-width: unset;
        flex-direction: column;
    }

    #temporary-message-container {
        top: 10px;
    }
}

@media (max-width: 480px) {
    #sidebar h1 {
        font-size: 1.8rem;
    }

    .filtro select,
    #sidebar button,
    .modal-content input,
    .modal-content button {
        padding: 0.8rem;
        font-size: 1rem;
    }

    .modal-content {
        padding: 15px 20px;
    }

        .modal-content h2 {
            font-size: 1.2rem;
        }
}
