/* ============================================
   ESTILIZACIÓN DEL MAPA IMAGO
   ============================================
   Este archivo controla cómo se ve el mapa visualmente.
   Está organizado en secciones:
   - Variables raíz: Variables CSS usadas en todo el archivo
   - Integración con WordPress: Lo hace funcionar en WordPress
   - Diseño general: Cómo se posicionan el mapa y la UI
   - Controles del mapa: Botones y elementos interactivos
   - Pop-ups: Las cajas de información que aparecen
   - Leyenda: La clave que muestra qué significan los símbolos
   - Responsive móvil: Cómo se ve en pantallas pequeñas
   
   Conceptos clave:
   - Variables CSS (--navbar-height) nos permiten cambiar valores en un lugar
   - @media queries hacen el diseño responsive (amigable con móviles)
   - z-index controla qué está encima (número mayor = arriba)
============================================ */

/* Variable CSS Raíz para altura de barra de navegación */
:root {
    --navbar-height: 150px;
}

/* Contexto del Plugin de WordPress */
.imago-map-wrapper {
    display: flex !important;
    flex-direction: column !important;
    height: 100vh !important;
    width: 100vw !important;
    max-width: 100% !important;
    position: fixed !important;
    top: var(--navbar-height, 150px) !important;
    left: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-sizing: border-box !important;
    z-index: 1 !important;
    height: calc(100vh - var(--navbar-height, 150px)) !important;
}

/* Asegurar que los controles de Leaflet sean visibles sobre el wrapper del mapa */
.leaflet-control {
    z-index: 1000 !important;
}

.leaflet-top {
    top: 10px !important;
}

.leaflet-bottom {
    bottom: 10px !important;
}

.leaflet-control-zoom {
    box-shadow: 0 2px 6px rgba(0,0,0,0.2) !important;
    border-radius: 6px !important;
}

/* Ajustar para pantallas más pequeñas sin barra de admin */
@media (max-width: 980px) {
    :root {
        --navbar-height: 130px;
    }
    
    .imago-map-wrapper {
        top: var(--navbar-height, 130px) !important;
        height: calc(100vh - var(--navbar-height, 130px)) !important;
    }
    
    .leaflet-top {
        top: 10px !important;
    }
}

/* Ajustar para móvil */
@media (max-width: 767px) {
    :root {
        --navbar-height: 110px;
    }
    
    .imago-map-wrapper {
        top: var(--navbar-height, 110px) !important;
        height: calc(100vh - var(--navbar-height, 110px)) !important;
    }
    
    .leaflet-top {
        top: 10px !important;
    }
}

.imago-map-wrapper #map {
    flex: 1 !important;
    height: 100% !important;
    width: 100% !important;
    position: relative !important;
}

/* Contexto HTML Independiente */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
}

#map {
    height: 100%;
    width: 100%;
    position: relative;
}

.leaflet-container {
    background: linear-gradient(135deg, #abcbe9 0%, #abcbe9 100%);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
}

.legend {
    background: #f5ede0;
    padding: 12px 14px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border: 1px solid #e0e0e0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    width: 300px;
    max-width: 85vw;
    margin-bottom: 40px;
}

.legend-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    background: #f5ede0;
    padding: 0;
    margin: 0;
}

.legend-title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: #3e3e3e;
    letter-spacing: 0.3px;
}

.legend-toggle {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid #e0e0e0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
    color: #666;
    background: #f8f9fa;
    transition: all 0.2s ease;
}

.legend-header:hover .legend-toggle {
    background: #e3f2fd;
    border-color: #1976d2;
}

.legend-body {
    margin-top: 10px;
    padding-top: 10px;
    padding-right: 6px;
    border-top: 1px solid #e8dcc8;
    background: #f5ede0;
    color: #4a3d2a;
    max-height: 40vh;
    overflow-y: auto;
    overflow-x: hidden;
    overflow-wrap: break-word;
}

.legend-body > p {
    break-inside: avoid;
    -webkit-column-break-inside: avoid;
    margin: 6px 0;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    white-space: normal;
    line-height: 1.4;
}

.legend-body > p svg {
    flex-shrink: 0;
    min-width: 28px;
    width: 28px;
    height: 28px;
}

.legend-body > p span {
    flex-shrink: 1;
    min-width: 0;
}

.legend.legend-collapsed .legend-body {
    display: none;
}

.reset-button {
    position: fixed !important;
    top: calc(var(--navbar-height, 150px) + 55px) !important;
    right: 15px !important;
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #FF671F 0%, #FF671F 100%);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    z-index: 999999 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(25, 118, 210, 0.3);
    pointer-events: auto !important;
}

.reset-button:hover {
    background: linear-gradient(135deg, #FF671F 0%, #FF671F 100%);
    transform: rotate(90deg) scale(1.08);
    box-shadow: 0 6px 16px rgba(25, 118, 210, 0.4);
}

.reset-button:active {
    transform: rotate(90deg) scale(0.95);
}

/* Ajustar botón de reinicio para pantallas más pequeñas sin barra de admin */
@media (max-width: 980px) {
    .reset-button {
        top: calc(var(--navbar-height, 130px) + 50px) !important;
        width: 48px;
        height: 48px;
        font-size: 18px;
    }
}

/* Ajustar botón de reinicio para móvil */
@media (max-width: 767px) {
    .reset-button {
        top: calc(var(--navbar-height, 110px) + 45px) !important;
        width: 44px;
        height: 44px;
        font-size: 16px;
    }
}

.language-selector {
    position: absolute;
    bottom: 15px;
    left: 15px;
    z-index: 1001 !important;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.96);
    border: none;
    border-radius: 20px;
    font-size: 12px;
    color: #1a1a1a;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    backdrop-filter: blur(10px);
}

.language-selector label {
    font-weight: 600;
    letter-spacing: 0.2px;
    color: #424242;
}

.language-selector select {
    border: 1.5px solid #e0e0e0;
    border-radius: 8px;
    padding: 4px 8px;
    font-size: 12px;
    background: #f8f9fa;
    color: #1a1a1a;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.language-selector select:hover {
    background: #fff;
    border-color: #1976d2;
}

.language-selector select:focus {
    outline: none;
    background: #fff;
    border-color: #1976d2;
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.1);
}

.leaflet-popup-content-wrapper {
    border-radius: 16px;
    padding: 0;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    border: 2px solid #c9b89e;
    overflow: hidden;
    background: #ffffff;
    max-height: 80vh;
    max-width: 90vw;
}

.leaflet-popup {
    z-index: 9999 !important;
}

.leaflet-pane.leaflet-popup-pane {
    z-index: 9999 !important;
}

.leaflet-popup-content {
    margin: 0 auto;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 70vh;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    width: min(760px, calc(92vw - 28px));
    max-width: none;
    box-sizing: border-box;
}

.popup-card {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin: 0 auto;
    box-sizing: border-box;
    word-break: break-word;
    word-wrap: break-word;
    white-space: normal;
    overflow: hidden;
}

.popup-long {
    max-height: none;
    overflow: visible;
    padding-right: 0;
}

.popup-img {
    width: 100%;
    max-width: 240px;
    height: auto;
    display: block !important;
    border-radius: 12px;
    margin: 2px auto 14px auto;
    object-fit: contain;
    box-shadow: 0 6px 16px rgba(0,0,0,0.12);
    visibility: visible !important;
    opacity: 1 !important;
}

.popup-card img {
    max-width: 100%;
    height: auto;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    border-radius: 12px;
}

.popup-text img {
    max-width: 100%;
    height: auto;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.popup-text {
    padding: 18px 20px 20px 20px;
    font-size: 15px;
    line-height: 1.65;
    color: #3e3e3e;
    word-wrap: break-word;
    word-break: break-word;
    white-space: normal;
    overflow-wrap: break-word;
    max-width: 100%;
    box-sizing: border-box;
}

.popup-text p, 
.popup-text div,
.popup-text span,
.popup-text a,
.popup-text li {
    max-width: 100%;
    box-sizing: border-box;
    word-break: break-word;
    overflow-wrap: anywhere;
}

@media (min-width: 992px) {
    .popup-card:not(.popup-long) {
        display: grid;
        grid-template-columns: minmax(170px, 210px) 1fr;
        column-gap: 20px;
        align-items: start;
    }

    .popup-card:not(.popup-long) .popup-img {
        width: min(190px, 100%);
        max-width: 190px;
        margin: 16px auto 12px auto;
    }

    .popup-card:not(.popup-long) .popup-text {
        padding: 18px 20px 20px 0;
    }

    .popup-text p,
    .popup-text li {
        max-width: 76ch;
    }
}

.popup-acis .popup-img,
.popup-andromeda .popup-img {
    width: min(145px, 100%);
    max-width: 145px;
    margin: 8px auto 14px auto;
}

.popup-title {
    font-size: 18px;
    margin: 0 0 14px 0;
    letter-spacing: 0.3px;
    font-weight: 700;
    color: #4a3d2a;
}

.popup-menu {
    margin: 10px 0 4px 0;
    border: 1.5px solid #f0f0f0;
    border-radius: 10px;
    background: linear-gradient(135deg, #fafafa 0%, #ffffff 100%);
    padding: 8px 12px 6px 12px;
    transition: all 0.2s ease;
}

.popup-menu:hover {
    background: linear-gradient(135deg, #f5f5f5 0%, #ffffff 100%);
    border-color: #e0e0e0;
}

.popup-menu > summary {
    cursor: pointer;
    font-weight: 700;
    font-size: 14px;
    color: #1565c0;
    list-style: none;
}

.popup-menu > summary::-webkit-details-marker {
    display: none;
}

.popup-menu > summary::after {
    content: "▸";
    float: right;
    color: #666;
}

.popup-menu[open] > summary::after {
    content: "▾";
}

.popup-text h3 {
    margin: 14px 0 8px 0;
    font-size: 15px;
    font-weight: 700;
    color: #1a1a1a;
}

.popup-text h4 {
    margin: 12px 0 8px 0;
    font-size: 14px;
    font-weight: 700;
    color: #424242;
}

.popup-text ul {
    margin: 8px 0 12px 20px;
    padding: 0;
}

.popup-text li {
    margin-bottom: 8px;
    line-height: 1.5;
}

.popup-text a {
    text-decoration: none;
    font-weight: 600;
    color: #1976d2;
    transition: color 0.2s ease;
    word-break: break-all;
}

.popup-text a:hover {
    color: #1565c0;
    text-decoration: underline;
}

.popup-text hr {
    border: none;
    border-top: 2px solid #f0f0f0;
    margin: 14px 0;
}

.popup-researcher {
    margin: 8px 0;
    border: 1.5px solid #f0f0f0;
    border-radius: 10px;
    background: linear-gradient(135deg, #fafafa 0%, #ffffff 100%);
    padding: 8px 12px 6px 12px;
    transition: all 0.2s ease;
}

.popup-researcher:hover {
    background: linear-gradient(135deg, #f5f5f5 0%, #ffffff 100%);
    border-color: #e0e0e0;
}

.popup-researcher > summary {
    cursor: pointer;
    font-weight: 700;
    font-size: 14px;
    color: #867610;
    list-style: none;
}

.popup-researcher > summary::-webkit-details-marker {
    display: none;
}

.popup-researcher > summary::after {
    content: "▸";
    float: right;
    color: #666;
}

.popup-researcher[open] > summary::after {
    content: "▾";
}

.popup-researcher-content {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid #ececec;
}

.popup-asteria .leaflet-popup-content-wrapper,
.popup-asteria .leaflet-popup-tip {
    background: #ffffff;
    color: #000000;
}

.popup-essex .leaflet-popup-content-wrapper,
.popup-mexico .leaflet-popup-content-wrapper,
.popup-essex .leaflet-popup-tip,
.popup-mexico .leaflet-popup-tip {
    background: #ffffff;
    color: #000000;
}

.popup-mitografias .leaflet-popup-content-wrapper,
.popup-grandesp .leaflet-popup-content-wrapper,
.popup-mitografias .leaflet-popup-tip,
.popup-grandesp .leaflet-popup-tip {
    background: #ffffff;
    color: #000000;
}

.popup-pachamama-brazil .leaflet-popup-content-wrapper,
.popup-pachamama-bayamon .leaflet-popup-content-wrapper,
.popup-pachamama-brazil .leaflet-popup-tip,
.popup-pachamama-bayamon .leaflet-popup-tip {
    background: #ffffff;
    color: #000000;
}

.country-hover-label {
    position: absolute;
    z-index: 1000;
    background: rgba(26, 35, 126, 0.92);
    color: #ffffff;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    pointer-events: none;
    max-width: 220px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.3px;
}


.popup-spain .leaflet-popup-content-wrapper,
.popup-uk .leaflet-popup-content-wrapper,
.popup-italy .leaflet-popup-content-wrapper,
.popup-slovenia .leaflet-popup-content-wrapper,
.popup-albania .leaflet-popup-content-wrapper,
.popup-philippines .leaflet-popup-content-wrapper,
.popup-brazil .leaflet-popup-content-wrapper,
.popup-nicaragua .leaflet-popup-content-wrapper,
.popup-kazakhstan .leaflet-popup-content-wrapper,
.popup-france .leaflet-popup-content-wrapper,
.popup-acis .leaflet-popup-content-wrapper,
.popup-andromeda .leaflet-popup-content-wrapper {
    background: #ffffff;
    color: #333333;
}

.popup-spain .leaflet-popup-tip,
.popup-uk .leaflet-popup-tip,
.popup-italy .leaflet-popup-tip,
.popup-slovenia .leaflet-popup-tip,
.popup-albania .leaflet-popup-tip,
.popup-philippines .leaflet-popup-tip,
.popup-brazil .leaflet-popup-tip,
.popup-nicaragua .leaflet-popup-tip,
.popup-kazakhstan .leaflet-popup-tip,
.popup-france .leaflet-popup-tip,
.popup-acis .leaflet-popup-tip,
.popup-andromeda .leaflet-popup-tip {
    background: #ffffff;
}

.popup-spain a,
.popup-uk a,
.popup-italy a,
.popup-slovenia a,
.popup-albania a,
.popup-philippines a,
.popup-brazil a,
.popup-nicaragua a,
.popup-kazakhstan a,
.popup-france a,
.popup-acis a,
.popup-andromeda a {
    color: #1976D2;
}

/* Estilos de barra de desplazamiento de la leyenda */
.legend-body::-webkit-scrollbar {
    width: 8px;
}

.legend-body::-webkit-scrollbar-track {
    background: #e8dcc8;
    border-radius: 10px;
}

.legend-body::-webkit-scrollbar-thumb {
    background: #c9b89e;
    border-radius: 10px;
}

.legend-body::-webkit-scrollbar-thumb:hover {
    background: #b5a285;
}

/* Firefox barra de desplazamiento */
.legend-body {
    scrollbar-color: #c9b89e #e8dcc8;
    scrollbar-width: thin;
}

/* Ajustes responsive de la leyenda para tabletas */
@media (max-width: 980px) {
    .legend {
        width: 280px;
    }
    
    .legend-body {
        max-height: 38vh;
    }
}

/* Ajustes responsive de la leyenda para móvil */
@media (max-width: 767px) {
    .leaflet-popup-content {
        width: calc(90vw - 24px);
    }

    .popup-card {
        min-width: 0;
    }

    .legend {
        width: 260px;
        max-width: 90vw;
        padding: 10px 12px;
    }
    
    .legend-body {
        max-height: 35vh;
    }
    
    .legend-title {
        font-size: 14px;
    }
    
    .legend-body > p {
        font-size: 11px;
        gap: 6px;
    }
    
    .legend-body > p svg {
        min-width: 24px;
        width: 24px;
        height: 24px;
    }
}

/* Accesibilidad: Contenido solo para lectores de pantalla */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Indicador de enfoque visual para navegación con teclado */
.leaflet-interactive:focus {
    outline: 3px solid #4A90E2;
    outline-offset: 2px;
}

/* Retroalimentación visual mejorada para la selección de países */
.country-selected {
    opacity: 1 !important;
    font-weight: bold;
}

/* Título de mapa */

.map-title-control {
    background: rgba(245, 237, 224, 0.95);
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 8px 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    margin-top: 0; /* increase if you want lower */
}

.map-title-text {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: #3e3e3e;
    letter-spacing: 0.2px;
}


