/* ============================================================
   FUENTE E IMPORTACIONES
============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ============================================================
   ESTILOS GENERALES Y RESET
============================================================ */
*, *::before, *::after {
    box-sizing: border-box;
}

body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    font-family: 'Inter', sans-serif;
    overflow: hidden;
}

/* ============================================================
   LAYOUT PRINCIPAL (MAPA Y SIDEBAR)
============================================================ */
#map {
    position: absolute;
    top: 0;
    left: 280px;
    height: 100%;
    width: calc(100% - 280px);
    z-index: 1;
}

#sidebar {
    position: absolute;
    top: 0;
    left: 0;
    width: 280px;
    height: 100%;
    background: linear-gradient(180deg, #00352a 0%, #004d40 40%, #00382e 100%);
    color: white;
    z-index: 1000;
    padding: 0;
    box-shadow: 3px 0 15px rgba(0,0,0,0.4);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

/* ============================================================
   ENCABEZADO DEL SIDEBAR
============================================================ */
.sidebar-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 24px 20px 18px;
    background: rgba(0,0,0,0.25);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    position: relative;
}

.sidebar-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20px;
    right: 20px;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(39,174,96,0.6), transparent);
}

.sidebar-logo-wrap {
    background: white;
    padding: 10px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.35);
    margin-bottom: 14px;
    display: inline-block;
}

.sidebar-logo-wrap img {
    width: 120px;
    height: auto;
    display: block;
}

.sidebar-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.sidebar-brand-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: 0.3px;
    line-height: 1.2;
}

.sidebar-brand-sub {
    font-size: 0.78rem;
    font-weight: 400;
    color: #80cbc4;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.sidebar-version-badge {
    margin-top: 8px;
    display: inline-block;
    background: rgba(39,174,96,0.2);
    border: 1px solid rgba(39,174,96,0.4);
    color: #69d097;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 2px 9px;
    border-radius: 20px;
    letter-spacing: 0.4px;
}

/* ============================================================
   MENÚ DE NAVEGACIÓN
============================================================ */
#sidebar .menu-items {
    list-style: none;
    padding: 10px 0;
    margin: 0;
    flex-grow: 1;
    overflow-y: auto;
}

#sidebar .menu-items::-webkit-scrollbar {
    width: 4px;
}
#sidebar .menu-items::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 2px;
}

#sidebar .menu-items li a {
    display: flex;
    align-items: center;
    padding: 11px 20px;
    color: #b2dfdb;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    letter-spacing: 0.1px;
}

#sidebar .menu-items li a:hover {
    background: rgba(255,255,255,0.07);
    color: #ffffff;
    border-left-color: #27ae60;
    padding-left: 24px;
}

#sidebar .menu-items li a i {
    margin-right: 12px;
    width: 18px;
    text-align: center;
    font-size: 0.9rem;
    opacity: 0.85;
}

/* ============================================================
   SEPARADOR DE SECCIÓN EN MENÚ
============================================================ */
.menu-section-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.3);
    padding: 14px 20px 4px;
}

/* ============================================================
   FORMULARIOS DESPLEGABLES (ACORDEÓN)
============================================================ */
.search-form-container,
.upload-form-container {
    padding: 12px 20px;
    background: rgba(0,0,0,0.2);
    border-top: 1px solid rgba(255,255,255,0.06);
    border-bottom: 1px solid rgba(255,255,255,0.06);
    display: none;
}

.menu-item-expandable.active .search-form-container,
.menu-item-expandable.active .upload-form-container {
    display: block;
    animation: fadeIn 0.25s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.search-form-container label,
.upload-form-container label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 10px;
    margin-bottom: 5px;
    display: block;
    color: #80cbc4;
}

.search-form-container input,
.search-form-container select,
.upload-form-container input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 6px;
    background: rgba(255,255,255,0.1);
    color: #fff;
    font-size: 0.85rem;
    font-family: 'Inter', sans-serif;
    transition: border-color 0.2s;
    outline: none;
}

.search-form-container input::placeholder {
    color: rgba(255,255,255,0.35);
}

.search-form-container input:focus,
.search-form-container select:focus {
    border-color: #27ae60;
    background: rgba(255,255,255,0.13);
}

.search-form-container select option {
    background: #004d40;
    color: #fff;
}

#search-coords-button {
    width: 100%;
    padding: 9px;
    margin-top: 12px;
    background: #27ae60;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    font-family: 'Inter', sans-serif;
    letter-spacing: 0.3px;
    transition: background 0.2s, transform 0.1s;
}

#search-coords-button:hover {
    background: #219150;
    transform: translateY(-1px);
}

/* ============================================================
   RESULTADOS DE BÚSQUEDA
============================================================ */
.search-results-list {
    list-style: none;
    padding: 0;
    margin: 8px 0 0 0;
    max-height: 260px;
    overflow-y: auto;
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    display: none;
}

.search-results-list.visible {
    display: block;
}

.search-result-item {
    padding: 9px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    cursor: pointer;
    transition: all 0.15s;
    font-size: 0.82em;
    color: #ccc;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: rgba(39,174,96,0.15);
    color: white;
    padding-left: 16px;
}

.search-result-item strong {
    color: #4db6ac;
    display: block;
    margin-bottom: 2px;
    font-size: 0.9em;
}

.search-result-item span {
    display: block;
    font-size: 0.88em;
    opacity: 0.85;
}

.search-results-list::-webkit-scrollbar { width: 4px; }
.search-results-list::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 2px;
}

/* ============================================================
   SECCIÓN DE APOYO AL PROYECTO
============================================================ */
.support-section {
    margin: 10px 14px;
    padding: 14px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
}

.support-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: rgba(255,255,255,0.4);
    text-align: center;
    margin-bottom: 10px;
}

.support-qr-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.support-qr-wrap img {
    width: 62px;
    height: 62px;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.2);
    flex-shrink: 0;
}

.support-qr-info {
    flex: 1;
}

.support-qr-label {
    font-size: 0.68rem;
    color: rgba(255,255,255,0.4);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.support-qr-sub {
    font-size: 0.75rem;
    color: #b2dfdb;
    font-weight: 500;
    line-height: 1.3;
}

.btn-paypal {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 7px 12px;
    background: #0070ba;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    text-decoration: none;
    transition: background 0.2s, transform 0.1s;
    letter-spacing: 0.2px;
}

.btn-paypal:hover {
    background: #005ea0;
    transform: translateY(-1px);
    color: white;
}

/* ============================================================
   PIE DEL SIDEBAR
============================================================ */
.sidebar-footer {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.3);
    text-align: center;
    padding: 12px 20px;
    border-top: 1px solid rgba(255,255,255,0.07);
    line-height: 1.6;
}

.sidebar-footer a {
    color: rgba(255,255,255,0.4);
    text-decoration: none;
}

.sidebar-footer a:hover {
    color: #80cbc4;
}

.sidebar-footer .dev-name {
    color: rgba(255,255,255,0.55);
    font-weight: 600;
    font-size: 0.74rem;
}

/* ============================================================
   HERRAMIENTAS DEL MAPA (FLOTANTES)
============================================================ */
.map-tools {
    position: absolute;
    top: 120px;
    right: 16px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.map-tools button {
    width: 38px;
    height: 38px;
    font-size: 16px;
    background: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    color: #444;
    transition: all 0.2s;
}

.map-tools button:hover {
    background: #f0f0f0;
    box-shadow: 0 3px 12px rgba(0,0,0,0.3);
    transform: translateY(-1px);
    color: #004d40;
}

/* ============================================================
   POPUP DE CAPAS
============================================================ */
.popup-content {
    max-height: 200px;
    overflow-y: auto;
    font-size: 0.9em;
    font-family: 'Inter', sans-serif;
}

/* ============================================================
   LEYENDA ACORDEÓN
============================================================ */
.legend-accordion {
    font-family: 'Inter', sans-serif;
    background: rgba(255,255,255,0.98);
    box-shadow: 0 3px 12px rgba(0,0,0,0.22);
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,0.1);
    min-width: 195px;
    max-width: 260px;
    overflow: hidden;
    transition: box-shadow 0.2s;
}

.legend-accordion:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.28);
}

/* ---- Cabecera principal (siempre visible) ---- */
.legend-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    cursor: pointer;
    background: #004d40;
    color: white;
    font-weight: 700;
    font-size: 0.8rem;
    letter-spacing: 0.4px;
    user-select: none;
    transition: background 0.2s;
    gap: 8px;
}

.legend-header:hover {
    background: #00695c;
}

.legend-title {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-icon {
    font-size: 0.9rem;
    line-height: 1;
}

.legend-arrow {
    font-size: 0.65rem;
    transition: transform 0.25s ease;
    flex-shrink: 0;
    color: rgba(255,255,255,0.85);
}

/* ---- Cuerpo de la leyenda (colapsable) ---- */
.legend-body {
    padding: 4px 0;
    max-height: 320px;
    overflow-y: auto;
    transition: max-height 0.3s ease;
}

.legend-body::-webkit-scrollbar {
    width: 4px;
}
.legend-body::-webkit-scrollbar-thumb {
    background: rgba(0,77,64,0.2);
    border-radius: 2px;
}

/* ---- Encabezado de categoría (acordeón interno) ---- */
.legend-category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 0.73rem;
    font-weight: 600;
    color: #004d40;
    background: rgba(0,77,64,0.06);
    border-bottom: 1px solid rgba(0,0,0,0.06);
    user-select: none;
    transition: background 0.15s, padding-left 0.15s;
}

.legend-category-header:hover {
    background: rgba(0,77,64,0.12);
    padding-left: 14px;
}

.cat-arrow {
    font-size: 0.55rem;
    transition: transform 0.2s;
    color: #999;
    flex-shrink: 0;
}

/* ---- Cuerpo de categoría (colapsable) ---- */
.legend-category-body {
    padding: 4px 12px 6px;
    border-bottom: 1px solid rgba(0,0,0,0.04);
}

/* ---- Ítem individual de la leyenda ---- */
.legend-item {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.75rem;
    line-height: 22px;
    color: #444;
    padding: 1px 0;
    transition: color 0.1s;
}

.legend-item:hover {
    color: #004d40;
}

.legend-item i {
    width: 11px;
    height: 11px;
    border-radius: 3px;
    border: 1px solid rgba(0,0,0,0.15);
    flex-shrink: 0;
    display: inline-block;
}

/* ---- Responsivo: más compacto en móvil ---- */
@media (max-width: 768px) {
    .legend-accordion {
        min-width: 170px;
        max-width: 200px;
        font-size: 0.72rem;
    }

    .legend-header {
        padding: 6px 10px;
        font-size: 0.75rem;
    }

    .legend-body {
        max-height: 240px;
    }

    .legend-category-header {
        padding: 5px 10px;
        font-size: 0.7rem;
    }

    .legend-category-body {
        padding: 3px 10px 5px;
    }

    .legend-item {
        font-size: 0.7rem;
        line-height: 20px;
    }

    .legend-item i {
        width: 10px;
        height: 10px;
    }
}

/* ============================================================
   HERRAMIENTA: CAPTURA DE COORDENADAS UTM
============================================================ */
.btn-utm-coords {
    background-color: white;
    border: 2px solid rgba(0,0,0,0.2);
    border-radius: 4px;
    width: 30px;
    height: 30px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    box-shadow: 0 1px 5px rgba(0,0,0,0.25);
    transition: background-color 0.2s, border-color 0.2s;
}

.btn-utm-coords:hover {
    background-color: #f4f4f4;
    border-color: rgba(0,0,0,0.4);
}

.btn-utm-coords.activo {
    background-color: #e8f5e9;
    border-color: #2e7d32;
    color: #2e7d32;
}

.mapa-modo-utm {
    cursor: crosshair !important;
}

.popup-utm {
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    min-width: 220px;
}

.popup-utm .utm-titulo {
    background: #1a237e;
    color: white;
    padding: 7px 10px;
    border-radius: 4px 4px 0 0;
    font-weight: 700;
    font-size: 11px;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 6px;
}

.popup-utm .utm-cuerpo {
    padding: 10px;
    border: 1px solid #1a237e;
    border-top: none;
    border-radius: 0 0 4px 4px;
    background: #f8f9ff;
}

.popup-utm .utm-fila {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px dashed #ddd;
}

.popup-utm .utm-fila:last-of-type {
    border-bottom: none;
    margin-bottom: 8px;
}

.popup-utm .utm-label {
    color: #555;
    font-weight: 600;
    font-size: 11px;
}

.popup-utm .utm-valor {
    color: #1a237e;
    font-weight: 700;
    font-family: 'Courier New', monospace;
}

.btn-copiar-utm {
    width: 100%;
    margin-top: 6px;
    padding: 6px;
    background: #1a237e;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: background 0.2s;
}

.btn-copiar-utm:hover { background: #283593; }
.btn-copiar-utm.copiado { background: #2e7d32; }

/* ============================================================
   FLECHA DEL NORTE — elemento DOM, solo visible al imprimir
============================================================ */
#north-arrow-map {
    display: none; /* oculto en pantalla */
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1000;
    background: rgba(255,255,255,0.93);
    border-radius: 7px;
    padding: 7px 9px 5px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    border: 1px solid rgba(0,0,0,0.12);
    text-align: center;
    pointer-events: none;
}

/* ============================================================
   CUADRÍCULA UTM — ETIQUETAS
============================================================ */
#utm-grid-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 450;
    overflow: hidden;
}

.utm-gl {
    position: absolute;
    font-family: 'Inter', sans-serif;
    font-size: 9px;
    font-weight: 600;
    color: #333;
    background: rgba(255,255,255,0.75);
    padding: 1px 3px;
    border-radius: 2px;
    white-space: nowrap;
    line-height: 1.4;
}

.utm-gl-e {
    bottom: 6px;
    transform: translateX(-50%);
}

.utm-gl-n {
    left: 3px;
    writing-mode: vertical-rl;
    transform: rotate(180deg) translateY(50%);
}

/* ============================================================
   CABECERA Y PIE — IMPRESIÓN (ocultos en pantalla)
============================================================ */
#print-header,
#print-footer {
    display: none;
}

/* ============================================================
   @MEDIA PRINT — DISEÑO CARTOGRÁFICO PROFESIONAL
============================================================ */
@media print {
    @page {
        size: A4 landscape;
        margin: 6mm;
    }

    /* Reset del body para imprimir */
    html, body {
        height: auto !important;
        overflow: visible !important;
        width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        font-family: 'Inter', sans-serif !important;
    }

    /* Ocultar elementos de UI */
    #sidebar,
    .map-tools,
    #menu-mobile-btn,
    #legal-modal,
    #stats-modal,
    .leaflet-top,
    .leaflet-pm-toolbar,
    .btn-utm-coords,
    .leaflet-control-attribution {
        display: none !important;
    }

    /* Mostrar cabecera de impresión */
    #print-header {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        padding: 3mm 4mm;
        background: #004d40;
        color: white;
        height: 16mm;
        flex-shrink: 0;
        page-break-inside: avoid;
    }

    /* Mapa ocupa el espacio central */
    #map {
        position: relative !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        height: 157mm !important;
        border: 1.5px solid #222 !important;
        flex-shrink: 0;
        display: block !important;
    }

    /* Mostrar pie de impresión */
    #print-footer {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        padding: 2mm 4mm;
        background: #f0f0f0;
        border-top: 1px solid #999;
        font-size: 7pt;
        color: #444;
        height: 10mm;
        flex-shrink: 0;
    }

    /* Mantener visibles controles del mapa inferiores */
    .leaflet-bottom {
        display: block !important;
    }

    /* Leyenda acordeón visible en impresión — tamaño reducido y compacto */
    .legend-accordion {
        display: block !important;
        font-size: 7pt !important;
        min-width: 140px !important;
    }

    .legend-accordion .legend-header {
        padding: 5px 8px !important;
        font-size: 7pt !important;
    }

    .legend-accordion .legend-body {
        max-height: none !important;
        overflow: visible !important;
    }

    .legend-accordion .legend-category-header {
        padding: 4px 8px !important;
        font-size: 6.5pt !important;
    }

    .legend-accordion .legend-item {
        font-size: 6.5pt !important;
        line-height: 16px !important;
    }

    .legend-accordion .legend-item i {
        width: 10px !important;
        height: 10px !important;
    }

    /* Escala gráfica visible */
    .leaflet-control-scale {
        display: block !important;
    }

    /* Flecha Norte visible en esquina superior derecha */
    #north-arrow-map {
        display: block !important;
    }

    /* Cuadrícula UTM visible */
    #utm-grid-overlay {
        display: block !important;
    }

    /* Etiquetas de cuadrícula */
    .utm-gl {
        font-size: 7pt !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* ============================================================
   ESTILOS INTERNOS DEL PRINT-HEADER
============================================================ */
.ph-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ph-logo {
    height: 36px;
    width: auto;
    background: white;
    border-radius: 6px;
    padding: 2px 4px;
}

.ph-text {
    display: flex;
    flex-direction: column;
}

.ph-title {
    font-size: 12pt;
    font-weight: 700;
    color: white;
    line-height: 1.2;
}

.ph-subtitle {
    font-size: 8pt;
    color: #b2dfdb;
    margin-top: 1px;
}

.ph-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.ph-info-row {
    font-size: 8pt;
    color: #e0e0e0;
    display: flex;
    gap: 5px;
}

.ph-lbl {
    font-weight: 700;
    color: #80cbc4;
}

/* ============================================================
   ESTILOS RESPONSIVOS PARA MÓVILES
============================================================ */
#menu-mobile-btn {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 10001;
    width: 40px;
    height: 40px;
    font-size: 18px;
    background: #004d40;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.35);
    display: none;
}

@media (max-width: 768px) {
    #menu-mobile-btn { display: block; }

    #sidebar {
        width: 85%;
        left: -100%;
        position: fixed;
        transition: left 0.3s ease-in-out;
        z-index: 10000;
    }

    #sidebar.visible { left: 0; }

    #map {
        left: 0;
        width: 100%;
    }

    .map-tools {
        top: 16px;
        right: 65px;
        flex-direction: row;
        background: rgba(255,255,255,0.9);
        padding: 5px;
        border-radius: 6px;
        gap: 6px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    }

    .map-tools button {
        width: 34px;
        height: 34px;
        font-size: 15px;
    }

}
