/* ========================================
   CONFIGURACION GENERAL
======================================== */

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
}

body {
    display: flex;
    flex-direction: column;
    font-family: Arial, Helvetica, sans-serif;
    background: #ffffff;
}


/* ========================================
   CABECERA
======================================== */

#cabecera {
    flex: 0 0 auto;
    padding: 8px 14px;
    background: #ffffff;
    border-bottom: 1px solid #dddddd;
    z-index: 1000;
}

h1 {
    margin: 0 0 8px;
    text-align: center;
    font-size: 26px;
}

#acciones {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-bottom: 7px;
}

#adminPassword {
    width: 250px;
    padding: 8px 10px;
    border: 1px solid #aaaaaa;
    border-radius: 5px;
    font-family: Arial, Helvetica, sans-serif;
}

button {
    padding: 8px 15px;
    cursor: pointer;
    border: 1px solid #aaaaaa;
    border-radius: 5px;
    background: #ffffff;
    font-family: Arial, Helvetica, sans-serif;
}

button:hover {
    background: #eeeeee;
}

#botonGuardar {
    color: #ffffff;
    background: #1769aa;
    border-color: #1769aa;
    font-weight: bold;
}

#botonGuardar:hover {
    background: #125486;
}

#botonGuardar:disabled {
    background: #999999;
    border-color: #999999;
    cursor: wait;
}

#estadoGuardado {
    min-width: 180px;
    font-size: 14px;
    color: #555555;
}

.estado-guardando {
    color: #555555;
}

.estado-correcto {
    color: #17813a;
    font-weight: bold;
}

.estado-error {
    color: #b42318;
    font-weight: bold;
}

#contador {
    text-align: center;
    font-size: 17px;
    font-weight: bold;
}


/* ========================================
   CONTENEDOR PRINCIPAL
======================================== */

#contenedor {
    display: flex;
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    overflow: hidden;
}

#sidebar {
    flex: 0 0 350px;
    width: 350px;
    height: 100%;
    overflow-y: auto;
    padding: 12px;
    background: #fafafa;
    border-right: 1px solid #cccccc;
}

#sidebar h2 {
    margin: 0 0 12px;
    font-size: 22px;
}

#map {
    flex: 1 1 auto;
    width: auto;
    height: 100%;
    min-width: 0;
    background: #e8e8e8;
}


/* ========================================
   COMARCAS
======================================== */

details {
    margin-bottom: 5px;
}

summary {
    padding: 5px;
    cursor: pointer;
    border-radius: 4px;
    font-weight: bold;
}

summary:hover {
    background: #e5e5e5;
}

.porcentaje-comarca {
    font-weight: normal;
}


/* ========================================
   COMARCA COMPLETADA
======================================== */

.comarca-completada > summary {
    padding-left: 8px;
    color: #147a35;
    background: #e8f7ed;
    border-left: 4px solid #2ecc71;
}

.comarca-completada > summary:hover {
    background: #d9f2e2;
}

.comarca-completada[open] > summary {
    color: #11652d;
    background: #d9f2e2;
}

.tick-comarca {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    margin-left: 7px;
    color: #ffffff;
    background: #219653;
    border-radius: 50%;
    font-size: 13px;
    font-weight: bold;
    vertical-align: middle;
}


/* ========================================
   MUNICIPIOS
======================================== */

.municipio-admin {
    margin-bottom: 4px;
    border-radius: 5px;
}

.municipio-cabecera {
    display: flex;
    align-items: center;
    gap: 4px;
}

.municipio-item {
    padding: 4px 5px 4px 22px;
    cursor: pointer;
    border-radius: 3px;
    font-size: 14px;
}

.municipio-item:hover {
    background: #e6eff7;
}

.municipio-cabecera .municipio-item {
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: space-between;
    min-width: 0;
}

.indicador-rutas {
    flex: 0 0 auto;
    margin-left: 8px;
    padding: 2px 6px;
    color: #1769aa;
    background: #e7f1fa;
    border-radius: 10px;
    font-size: 11px;
    font-weight: bold;
}


/* ========================================
   BOTON DESPLEGABLE DE RUTAS
======================================== */

.boton-rutas {
    flex: 0 0 32px;
    width: 32px;
    height: 30px;
    padding: 0;
    color: #555555;
    background: transparent;
    border: none;
    border-radius: 4px;
    font-size: 18px;
    line-height: 1;
}

.boton-rutas:hover {
    color: #1769aa;
    background: #e6eff7;
}


/* ========================================
   PANEL DE RUTAS DEL MUNICIPIO
======================================== */

.panel-rutas {
    margin: 3px 5px 8px 22px;
    padding: 8px;
    background: #f2f5f7;
    border-left: 3px solid #3498db;
    border-radius: 4px;
}

.panel-rutas.oculto {
    display: none;
}

.titulo-rutas {
    margin: 0 0 7px;
    color: #444444;
    font-size: 13px;
    font-weight: bold;
}

.sin-rutas {
    margin: 4px 0 8px;
    color: #777777;
    font-size: 13px;
}

.ruta-item {
    margin-bottom: 6px;
    padding: 7px;
    background: #ffffff;
    border: 1px solid #dddddd;
    border-radius: 5px;
}

.ruta-nombre {
    display: block;
    color: #1769aa;
    font-size: 14px;
    font-weight: bold;
    text-decoration: none;
    word-break: break-word;
}

.ruta-nombre:hover {
    text-decoration: underline;
}


/* ========================================
   BOTONES DE GESTION DE RUTAS
======================================== */

.ruta-acciones {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 7px;
}

.ruta-acciones button,
.boton-anadir-ruta {
    padding: 5px 9px;
    font-size: 12px;
}

.boton-editar-ruta {
    color: #1769aa;
    border-color: #9bbbd5;
}

.boton-editar-ruta:hover {
    color: #125486;
    background: #e7f1fa;
}

.boton-eliminar-ruta {
    color: #a61b1b;
    border-color: #d5a4a4;
}

.boton-eliminar-ruta:hover {
    color: #7f1111;
    background: #fdecec;
}

.boton-anadir-ruta {
    margin-top: 5px;
    color: #ffffff;
    background: #1769aa;
    border-color: #1769aa;
}

.boton-anadir-ruta:hover {
    background: #125486;
}


/* ========================================
   MODAL PARA ANADIR O MODIFICAR RUTAS
======================================== */

.modal-ruta {
    position: fixed;
    inset: 0;
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.45);
}

/*
El formulario permanece oculto al cargar la pagina.
Se muestra solamente al pulsar "+ Anadir ruta"
o "Modificar".
*/
.modal-ruta.oculto {
    display: none !important;
}

.modal-ruta-contenido {
    width: 100%;
    max-width: 480px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    padding: 22px;
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}

.modal-ruta-contenido h2 {
    margin: 0 0 8px;
}

#municipioRuta {
    margin: 0 0 16px;
    color: #666666;
    font-weight: bold;
}

.modal-ruta-contenido label {
    display: block;
    margin: 12px 0 5px;
    font-weight: bold;
}

.modal-ruta-contenido input {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid #aaaaaa;
    border-radius: 5px;
    font-family: Arial, Helvetica, sans-serif;
}

.acciones-modal {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 18px;
}

#botonGuardarRuta {
    color: #ffffff;
    background: #1769aa;
    border-color: #1769aa;
}

#botonGuardarRuta:hover {
    background: #125486;
}

#errorRuta {
    min-height: 20px;
    margin-top: 10px;
    color: #b42318;
    font-size: 14px;
}


/* ========================================
   SELECCION DE TEXTO Y LEAFLET
======================================== */

#sidebar,
#map,
.leaflet-container,
.leaflet-pane,
.leaflet-interactive {
    user-select: none;
    -webkit-user-select: none;
}

input,
button,
a {
    user-select: auto;
    -webkit-user-select: auto;
}

.leaflet-container {
    outline: none;
}


/* ========================================
   VERSION MOVIL
======================================== */

@media (max-width: 750px) {

    html,
    body {
        overflow: auto;
    }

    #cabecera {
        padding: 7px;
    }

    h1 {
        font-size: 20px;
    }

    #acciones {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }

    #adminPassword {
        grid-column: 1 / -1;
        width: 100%;
    }

    #estadoGuardado {
        grid-column: 1 / -1;
        text-align: center;
    }

    #contenedor {
        flex-direction: column;
        overflow: visible;
    }

    #sidebar {
        width: 100%;
        flex: 0 0 auto;
        max-height: 300px;
        border-right: none;
        border-bottom: 1px solid #cccccc;
    }

    #map {
        width: 100%;
        min-height: 550px;
    }

    .modal-ruta {
        align-items: flex-start;
        padding: 30px 12px;
    }

    .modal-ruta-contenido {
        max-width: none;
        max-height: calc(100vh - 60px);
    }

    .municipio-cabecera {
        align-items: stretch;
    }
}