html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: sans-serif;
    background-color: #2f1e25;
    color: white;
}

#app {
    position: relative;
    width: 100%;
    height: 100vh;
}

#map-container {
    position: relative;
    width: 100%;
    height: 100%;
}

#map {
    width: 100%;
    height: 100vh;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

/* ========================================= */
/* TÍTULO Y LOGO */
/* ========================================= */
#tituloMapa {
    background-color: rgba(0, 0, 0, 0.342);
    color: white;
    text-align: center;
    font-size: 25px; 
    font-weight: bold;
    padding: 15px 70px; /* Padding lateral para que no tape logo ni fecha */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 9990;
    text-transform: uppercase;
    margin: 0;
    box-sizing: border-box;
}

#logoFPA {
    position: fixed;
    top: 5px;
    left: 10px;
    width: 50px;
    height: auto;
    z-index: 9999; /* Siempre por encima */
    opacity: 1 !important;
}

/* ========================================= */
/* BARRA DE HERRAMIENTAS - DESKTOP */
/* ========================================= */
#barraHerramientas {
    position: fixed;
    top: 57px; /* Pegada al título para eliminar franja gris */
    left: 0;
    width: 100%;
    height: auto;
    display: flex;
    justify-content: center;
    gap: 15px;
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.95);
    z-index: 9980;
    box-sizing: border-box;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* ========================================= */
/* MENÚ DE CAPAS (SIDEBAR) - DESKTOP */
/* ========================================= */
#menu {
    position: fixed;
    top: 107px; /* Ajustado para la nueva posición de la barra */
    right: 0;
    width: 250px;
    height: calc(100vh - 107px);
    background-color: rgba(51, 51, 63, 0.95);
    color: white;
    padding: 15px;
    overflow-y: auto;
    z-index: 9998;
    border-radius: 8px 0 0 8px;
    box-shadow: -2px 0 5px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    transition: transform 0.3s ease;
}

.logout-button {
    background-color: #dc3545;
    color: white;
    padding: 8px 12px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    margin-top: 20px;
    width: 100%;
    transition: background-color 0.3s ease;
    font-size: 0.9em;
    text-transform: uppercase;
}

.logout-button:hover {
    background-color: #c82333;
}

.grupo-capas {
    margin-bottom: 15px;
    border: 1px solid #444;
    border-radius: 5px;
    overflow: hidden;
}

.grupo-capas h3.titulo-desplegable {
    background-color: #2a2a33;
    color: white;
    padding: 10px;
    cursor: pointer;
    font-size: 1.1em;
    font-weight: bold;
    border-bottom: 1px solid #444;
    transition: background-color 0.2s ease;
    text-transform: uppercase;
}

.grupo-capas h3.titulo-desplegable:hover {
    background-color: #3a3a45;
}

.contenedor-botones {
    padding: 5px 10px;
    background-color: #33333f;
}

#botonesCapas button {
    display: block;
    margin: 8px 0;
    width: 100%;
    background: #ffffff;
    color: rgb(10, 10, 10);
    border: none;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    text-align: left;
    font-size: 14px;
    font-weight: normal;
    transition: background-color 0.2s ease, color 0.2s ease;
    text-transform: uppercase;
}

#botonesCapas button:hover:not(:disabled) {
    background-color: #e0e0e0;
}

#botonesCapas button:disabled {
    background-color: #f0f0f0;
    color: #aaa;
    cursor: not-allowed;
    opacity: 0.7;
}

.sub-grupo-capas {
    margin-top: 10px;
    margin-bottom: 5px;
    border: 1px solid #555;
    border-radius: 4px;
    overflow: hidden;
    background-color: #44444c;
}

.titulo-desplegable-anio {
    background-color: #f0f0f0;
    color: #333;
    padding: 6px 10px;
    margin: 0;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s ease, color 0.2s ease;
    text-align: left;
    font-size: 14px;
    font-weight: normal;
    text-transform: uppercase;
}

.titulo-desplegable-anio:hover {
    background-color: #e0e0e0;
}

.sub-contenedor-botones {
    padding: 5px 10px;
    background-color: #44444c;
}

/* ========================================= */
/* CONTROLES DE LEAFLET */
/* ========================================= */
.leaflet-control-container .leaflet-top.leaflet-left {
    top: 165px; /* Ajustado para la nueva posición */
    left: 10px;
    pointer-events: auto;
}

.leaflet-control-container .leaflet-top.leaflet-right {
    top: 117px; /* Ajustado */
    right: 270px;
}

.leaflet-control-layers {
    bottom: 10px !important;
    top: auto !important;
    right: auto !important;
    left: 10px !important;
    position: absolute !important;
    background-color: rgba(255, 255, 255, 0.8);
    padding: 5px;
    border-radius: 5px;
}

.leaflet-draw-toolbar {
    z-index: 1010;
}

.leaflet-draw-toolbar a {
    display: block !important;
    margin-bottom: 5px !important;
    border: 1px solid #ccc !important;
    border-radius: 4px !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3) !important;
}

.leaflet-draw-actions {
    z-index: 1020;
    background: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.leaflet-draw-actions a {
    z-index: 1021 !important;
    pointer-events: auto !important;
    background: white !important;
    color: #333 !important;
    border-bottom: 1px solid #ddd !important;
    padding: 12px 16px !important;
    display: block !important;
    text-decoration: none !important;
    font-size: 14px !important;
    font-weight: bold !important;
    min-width: 80px !important;
    text-align: center !important;
}

.leaflet-draw-actions a:hover {
    background: #f0f0f0 !important;
    color: #000 !important;
}

.leaflet-draw-actions a:last-child {
    border-bottom: none !important;
}

.polygon-info {
    position: absolute;
    top: 160px;
    left: 250px;
    z-index: 1000;
    background: white;
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    color: #333;
    display: none;
    max-width: 280px;
    font-size: 13px;
}

/* ========================================= */
/* POPUPS */
/* ========================================= */
.popup-box {
    background: #ffffff;
    color: #333333;
    font-size: 14px;
    line-height: 1.5;
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.popup-container-flex {
    display: flex;
}

.popup-list-column {
    flex: 1;
    min-width: 200px;
}

.popup-detail-column {
    flex: 1;
    padding-left: 20px;
    border-left: 1px solid #ccc;
    min-width: 250px;
}

.popup-field {
    margin-bottom: 5px;
}

.popup-relato {
    max-height: 150px;
    overflow-y: auto;
    border: 1px solid #eee;
    padding: 5px;
    background-color: #f9f9f9;
    border-radius: 4px;
}

.popup-box .popup-scrollable-list {
    max-height: 250px;
    overflow-y: auto;
    padding: 5px;
    border: 1px solid #ccc;
    border-radius: 4px;
    margin-top: 10px;
}

.popup-box .list-item-link {
    display: block;
    padding: 8px 10px;
    margin-bottom: 5px;
    background-color: #f8f9fa;
    border-radius: 4px;
    text-decoration: none;
    color: #333;
    transition: background-color 0.2s ease;
    font-size: 14px;
    border-left: 5px solid #007bff;
}

.popup-box .list-item-link.selected {
    background-color: #e2e6ea;
    border-left-color: #0056b3;
    font-weight: bold;
}

.popup-box .list-item-link:hover {
    background-color: #e2e6ea;
    cursor: pointer;
}

.popup-box h4 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 16px;
    color: #333;
}

.select-message {
    font-style: italic;
    color: #888;
}

/* ========================================= */
/* PANTALLA DE LOGIN */
/* ========================================= */
#pantallaInicio {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10002;
}

.fondo-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: -1;
}

.login-box {
    background: rgba(0, 0, 0, 0.747);
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
    text-align: center;
    display: flex;
    flex-direction: column;
    width: 320px;
    align-items: center;
    position: relative;
    box-sizing: border-box;
}

.login-box img {
    width: 150%;
    max-width: 300px;
    margin-bottom: 20px;
    margin-top: 10px;
    display: block;
}

.input-group {
    position: relative;
    width: 100%;
    margin: 0.75rem 0;
}

.input-group input {
    width: calc(100% - 35px - 0.75rem);
    padding: 0.75rem 0.75rem 0.75rem 35px;
    border: none;
    border-radius: 5px;
    background-color: #f2f2f2;
    color: #333;
    font-size: 1rem;
    box-sizing: border-box;
}

.input-group .icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #888;
    font-size: 1.2rem;
    z-index: 2;
}

.login-box button {
    background: #4caf50;
    color: white;
    border: none;
    padding: 0.8rem 1.2rem;
    border-radius: 5px;
    cursor: pointer;
    width: 100%;
    margin-top: 1.5rem;
    transition: background-color 0.3s ease;
}

.login-box button:hover {
    background-color: #45a049;
}

.login-box .error {
    color: #ff4f4f;
    margin-top: 10px;
    font-size: 0.9rem;
}

/* ========================================= */
/* BOTONES HAMBURGUESA Y OVERLAYS */
/* ========================================= */

/* Botón menú de capas (derecha) */
.btn-toggle {
    display: none;
    position: fixed;
    top: 70px;
    right: 10px;
    z-index: 10002;
    background: #2c5aa0;
    color: white;
    border: none;
    border-radius: 8px;
    width: 50px;
    height: 50px;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    transition: all 0.3s ease;
    align-items: center;
    justify-content: center;
}

.btn-toggle:hover {
    background: #1e3a70;
    transform: scale(1.05);
}

.btn-toggle:active {
    transform: scale(0.95);
}

/* Botón herramientas (izquierda) */
.btn-toggle-tools {
    display: none;
    position: fixed;
    top: 130px;
    right: 10px;
    z-index: 10002;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    width: 50px;
    height: 50px;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    transition: all 0.3s ease;
    align-items: center;
    justify-content: center;
}

.btn-toggle-tools:hover {
    background: #5578d9;
    transform: scale(1.05);
}

.btn-toggle-tools:active {
    transform: scale(0.95);
}

/* Overlays */
.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 9998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.overlay.activo {
    display: block;
    opacity: 1;
}

.overlay-tools {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9997;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.overlay-tools.activo {
    display: block;
    opacity: 1;
}

/* ========================================= */
/* OFICINA Y FECHA */
/* ========================================= */
.oficina-box {
    background-color: #800020;
    color: white;
    padding: 5px 15px;
    text-align: center;
    font-size: 11px;
    font-weight: bold;
    position: fixed;
    bottom: 0;
    left: 0;
    width: auto;
    min-width: 80px;
    z-index: 10001;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-radius: 0 5px 0 0;
    box-shadow: 2px -2px 5px rgba(0,0,0,0.3);
}

.fecha-actualizacion {
    position: fixed !important;
    top: 8px !important; /* Subida para evitar superposición */
    right: 10px !important;
    background-color: rgba(255, 255, 255, 0.9) !important;
    color: black !important;
    padding: 3px 10px !important;
    font-size: 11px !important;
    font-weight: bold !important;
    border-radius: 4px;
    z-index: 9999 !important; /* Por encima del título */
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* ========================================= */
/* RESPONSIVE: PANTALLAS MEDIANAS (769px - 1200px) */
/* ========================================= */
@media (min-width: 769px) and (max-width: 1200px) {

    #tituloMapa {
        font-size: 18px; /* Título más pequeño */
        padding: 12px 70px; /* Mantener espacio para logo y fecha */
    }

    #logoFPA {
        width: 40px; /* Logo más pequeño */
        top: 6px;
        left: 10px;
    }

    .fecha-actualizacion {
        top: 8px !important;
        right: 10px !important;
        font-size: 9px !important;
        padding: 2px 8px !important;
    }

    #barraHerramientas {
        top: 50px; /* Ajustado para título más pequeño */
        padding: 6px 15px;
        gap: 10px;
    }

    #menu {
        top: 92px; /* Ajustado */
        height: calc(100vh - 92px);
        width: 220px; /* Menú más estrecho */
        padding: 12px;
    }

    .leaflet-control-container .leaflet-top.leaflet-left {
        top: 145px;
    }

    .leaflet-control-container .leaflet-top.leaflet-right {
        top: 102px;
        right: 240px;
    }

    #menu h2 {
        font-size: 0.9rem;
    }

    .grupo-capas h3.titulo-desplegable {
        font-size: 0.9rem;
        padding: 8px;
    }

    #botonesCapas button {
        font-size: 0.8rem;
        padding: 5px 8px;
    }

    .titulo-desplegable-anio {
        font-size: 0.8rem;
        padding: 5px 8px;
    }

    .logout-button {
        font-size: 0.85rem;
        padding: 7px;
    }
}

/* ========================================= */
/* RESPONSIVE: MÓVIL (menos de 768px) */
/* ========================================= */
@media (max-width: 768px) {
    
    /* Título responsive - se ajusta al ancho */
    #tituloMapa {
        font-size: 14px; /* Más pequeño en móvil */
        padding: 10px 60px; /* Mantener espacio para logo y fecha */
    }
    
    /* Logo se mantiene fijo */
    #logoFPA {
        width: 35px;
        top: 5px;
        left: 5px;
    }
    
    /* Fecha se mantiene fija */
    .fecha-actualizacion {
        font-size: 8px !important;
        padding: 2px 5px !important;
        top: 8px !important;
        right: 5px !important;
    }
    
    /* Mostrar botones hamburguesa */
    .btn-toggle,
    .btn-toggle-tools {
        display: flex !important;
    }
    
    .btn-toggle {
        top: 55px;
    }
    
    .btn-toggle-tools {
        top: 110px;
    }
    
    /* Menú de capas lateral */
    #menu {
        right: auto !important;
        left: 0 !important;
        top: 0 !important;
        width: 85vw !important;
        max-width: 300px !important;
        height: 100vh !important;
        border-radius: 0 !important;
        padding-top: 20px !important;
        transform: translateX(-100%);
        z-index: 10000 !important;
    }
    
    #menu.activo {
        transform: translateX(0) !important;
    }
    
    /* Barra de herramientas lateral */
    #barraHerramientas {
        position: fixed;
        top: 0;
        left: 0;
        width: 85vw !important;
        max-width: 300px !important;
        height: 100vh !important;
        flex-direction: column;
        justify-content: flex-start;
        align-items: stretch;
        padding: 20px 15px;
        gap: 0;
        overflow-y: auto;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 10000 !important;
        box-shadow: 2px 0 8px rgba(0,0,0,0.3);
    }
    
    #barraHerramientas.activo {
        transform: translateX(0) !important;
    }
    
    #barraHerramientas > div {
        width: 100% !important;
        border: none !important;
        border-bottom: 1px solid rgba(0,0,0,0.1) !important;
        padding: 15px 0 !important;
        min-width: unset !important;
    }
    
    #barraHerramientas > div:last-child {
        border-bottom: none !important;
    }
    
    #barraHerramientas input,
    #barraHerramientas select {
        width: 100% !important;
        height: 40px !important;
        font-size: 14px !important;
        margin-bottom: 8px !important;
        box-sizing: border-box !important;
    }
    
    #barraHerramientas button {
        width: 100% !important;
        height: 40px !important;
        font-size: 14px !important;
        margin-bottom: 8px !important;
    }
    
    /* Ajustes del mapa */
    #map-container {
        width: 100% !important;
        left: 0 !important;
    }
    
    #map {
        width: 100% !important;
        height: 100vh !important;
    }
    
    /* Controles de Leaflet */
    .leaflet-control-zoom {
        bottom: 80px !important;
        right: 10px !important;
        top: auto !important;
        left: auto !important;
    }
    
    .leaflet-control-layers {
        bottom: 10px !important;
        left: 10px !important;
        top: auto !important;
        right: auto !important;
    }
    
    .leaflet-top.leaflet-left {
        top: 140px !important;
        left: 10px !important;
    }
    
    .leaflet-control-container .leaflet-top.leaflet-right {
        top: 70px !important;
        right: 70px !important;
    }
    
    /* Popups responsive */
    .leaflet-popup-content-wrapper {
        max-width: 85vw !important;
    }
    
    .popup-container-flex {
        flex-direction: column !important;
    }
    
    .popup-list-column,
    .popup-detail-column {
        width: 100% !important;
        max-width: 100% !important;
        min-width: auto !important;
        border-left: none !important;
        padding-left: 0 !important;
    }
    
    .popup-detail-column {
        border-top: 2px solid #ddd;
        padding-top: 15px;
        margin-top: 15px;
    }
    
    .popup-scrollable-list {
        max-height: 150px !important;
    }
    
    #polygonInfo {
        width: calc(100% - 20px) !important;
        max-width: 350px !important;
        left: 10px !important;
        top: auto !important;
        bottom: 80px !important;
    }
    
    /* Login responsive */
    .login-box {
        width: 90% !important;
        max-width: 400px !important;
        padding: 1.5rem !important;
    }
    
    /* Textos más pequeños en móvil */
    #menu h2 {
        font-size: 0.95rem !important;
    }
    
    .grupo-capas h3.titulo-desplegable {
        font-size: 0.85rem !important;
        padding: 8px !important;
    }
    
    #botonesCapas button {
        font-size: 0.8rem !important;
        padding: 6px 8px !important;
    }
    
    .titulo-desplegable-anio {
        font-size: 0.8rem !important;
        padding: 6px 8px !important;
    }
    
    .logout-button {
        font-size: 0.85rem !important;
        padding: 8px !important;
    }
    
    .oficina-box {
        font-size: 9px !important;
        padding: 3px 10px !important;
    }
}

/* ========================================= */
/* DESKTOP (más de 768px) */
/* ========================================= */
/* ========================================= */
/* DESKTOP GRANDE (más de 1200px) */
/* ========================================= */
@media (min-width: 1201px) {

    #tituloMapa {
        font-size: 25px;
        padding: 15px 70px;
    }

    #logoFPA {
        width: 50px;
        top: 5px;
        left: 10px;
    }

    .fecha-actualizacion {
        top: 8px !important;
        right: 10px !important;
        font-size: 11px !important;
        padding: 3px 10px !important;
    }

    #barraHerramientas {
        position: fixed;
        top: 57px;
        left: 0;
        width: 100%;
        height: auto;
        display: flex;
        justify-content: center;
        gap: 15px;
        padding: 10px 20px;
        background: rgba(255, 255, 255, 0.95);
        z-index: 9980;
        border-radius: 0;
        box-sizing: border-box;
    }

    #menu {
        height: calc(100vh - 107px);
        top: 107px;
        width: 250px;
    }

    .leaflet-control-container .leaflet-top.leaflet-left {
        top: 165px;
    }

    .leaflet-control-container .leaflet-top.leaflet-right {
        top: 117px;
        right: 270px;
    }

    /* Ocultamos botones en desktop */
    .btn-toggle,
    .btn-toggle-tools,
    .overlay,
    .overlay-tools {
        display: none !important;
    }
}