/* ============================================================================
   /mapa3d · Vista de detalle HD (MapLibre GL JS)
   ----------------------------------------------------------------------------
   Estilos del overlay de mapa plano que aparece cuando el usuario activa
   la vista HD desde el globo. Reutiliza la paleta del map3d.css principal.
   ============================================================================ */

.map3d-detail {
    position: fixed;
    inset: 0;
    z-index: 90;
    background: #1d1713;
    opacity: 0;
    pointer-events: none;
    transition: opacity 480ms cubic-bezier(0.22, 1, 0.36, 1);
}

.map3d-detail.is-active {
    opacity: 1;
    pointer-events: auto;
}

.map3d-detail__stage {
    position: absolute;
    inset: 0;
}

/* Filtro sepia/dorado sobre los tiles para coherencia con el atlas. */
.map3d-detail__stage .maplibregl-canvas {
    filter:
        sepia(0.42)
        hue-rotate(-15deg)
        contrast(1.12)
        brightness(1.0)
        saturate(0.82);
}

.map3d-detail__topbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 5;
    padding: 1.2rem clamp(1.2rem, 3vw, 2.4rem);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(180deg, rgba(28, 22, 18, 0.72), transparent);
    pointer-events: none;
}

.map3d-detail__back {
    background: var(--lat40-glass, rgba(28, 22, 18, 0.74));
    border: 1px solid rgba(201, 161, 107, 0.42);
    color: var(--lat40-ivory, #f4eadc);
    padding: 0.7rem 1.1rem;
    font-family: var(--map3d-sans, "Inter", system-ui, sans-serif);
    font-size: 0.72rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    cursor: pointer;
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    -webkit-backdrop-filter: blur(14px) saturate(115%);
    backdrop-filter: blur(14px) saturate(115%);
    transition: border-color 200ms ease, color 200ms ease, gap 220ms ease;
}

.map3d-detail__back em {
    font-style: normal;
    font-size: 0.95rem;
    color: var(--lat40-gold, #c9a16b);
}

.map3d-detail__back:hover,
.map3d-detail__back:focus-visible {
    border-color: var(--lat40-gold, #c9a16b);
    gap: 0.85rem;
    outline: none;
}

.map3d-detail__title {
    color: var(--lat40-ivory, #f4eadc);
    font-family: var(--map3d-serif, "Cormorant Garamond", serif);
    font-size: 1.1rem;
    letter-spacing: 0.04em;
    opacity: 0.75;
    pointer-events: none;
}

/* Botones de navegacion MapLibre · refinados estilo cobre. */
.map3d-detail .maplibregl-ctrl-group {
    background: var(--lat40-glass, rgba(28, 22, 18, 0.74));
    border: 1px solid rgba(201, 161, 107, 0.32);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
}

.map3d-detail .maplibregl-ctrl-group button {
    background: transparent;
    color: var(--lat40-ivory, #f4eadc);
}

.map3d-detail .maplibregl-ctrl-group button:hover {
    background: rgba(201, 161, 107, 0.18);
}

.map3d-detail .maplibregl-ctrl-attrib {
    background: rgba(28, 22, 18, 0.6);
    color: rgba(244, 234, 220, 0.6);
    font-size: 0.62rem;
}

.map3d-detail .maplibregl-ctrl-attrib a {
    color: var(--lat40-gold, #c9a16b);
}

/* Marker custom · pequeno punto dorado tipo joya. */
.lat40-hd-marker {
    display: block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: rgba(230, 190, 145, 0.92);
    border: 1px solid rgba(28, 22, 18, 0.65);
    box-shadow:
        0 0 0 3px rgba(201, 161, 107, 0.18),
        0 2px 6px rgba(0, 0, 0, 0.45);
    cursor: pointer;
    text-decoration: none;
    transition: transform 200ms ease, box-shadow 200ms ease;
}

.lat40-hd-marker:hover,
.lat40-hd-marker:focus-visible {
    transform: scale(1.4);
    box-shadow:
        0 0 0 5px rgba(201, 161, 107, 0.32),
        0 4px 12px rgba(0, 0, 0, 0.5);
    outline: none;
}

.lat40-hd-marker--dest {
    background: var(--lat40-ivory, #f4eadc);
    width: 14px;
    height: 14px;
}

/* Popup MapLibre · usa la misma ficha glass que el tooltip de Globe. */
.maplibregl-popup.lat40-hd-popup .maplibregl-popup-content {
    background: transparent;
    padding: 0;
    box-shadow: none;
    border: 0;
}

.maplibregl-popup.lat40-hd-popup .maplibregl-popup-tip {
    border-top-color: rgba(201, 161, 107, 0.6);
    border-bottom-color: rgba(201, 161, 107, 0.6);
    opacity: 0.6;
}

/* Boton "Vista HD" inyectado en la ficha lateral cuando hay API key. */
html:not(.map3d-hd-available) .map3d__sheet-hd { display: none; }

.map3d__sheet-hd {
    background: transparent;
    border: 1px solid var(--lat40-gold, #c9a16b);
    color: var(--lat40-gold, #c9a16b);
    padding: 0.7rem 1.1rem;
    font-family: var(--map3d-sans, "Inter", sans-serif);
    font-size: 0.7rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 200ms ease, color 200ms ease;
}

.map3d__sheet-hd:hover,
.map3d__sheet-hd:focus-visible {
    background: var(--lat40-gold, #c9a16b);
    color: var(--lat40-ink, #1d1713);
    outline: none;
}

/* prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
    .map3d-detail,
    .lat40-hd-marker,
    .map3d-detail__back {
        transition: none;
    }
}

/* Estado de carga · pen-stroke ambar mientras MapLibre se descarga. */
.map3d-detail.is-loading .map3d-detail__stage::after {
    content: "Cargando vista HD…";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--lat40-ivory, #f4eadc);
    font-family: var(--map3d-sans, "Inter", system-ui, sans-serif);
    font-size: 0.78rem;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    z-index: 4;
}
.map3d-detail.is-loading .map3d-detail__stage::before {
    content: "";
    position: absolute;
    top: calc(50% + 1.8rem);
    left: 50%;
    transform: translateX(-50%);
    width: 220px;
    height: 1px;
    background: var(--lat40-gold, #c9a16b);
    transform-origin: left center;
    animation: map3dDetailPen 1.4s cubic-bezier(0.65, 0, 0.35, 1) infinite;
    z-index: 4;
}

@keyframes map3dDetailPen {
    0%   { transform: translateX(-50%) scaleX(0); transform-origin: left; }
    50%  { transform: translateX(-50%) scaleX(1); transform-origin: left; }
    51%  { transform: translateX(-50%) scaleX(1); transform-origin: right; }
    100% { transform: translateX(-50%) scaleX(0); transform-origin: right; }
}

/* Error visible · si MapLibre o tiles fallan, mostramos un mensaje
   editorial con boton de vuelta al atlas. */
.map3d-detail__error {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: clamp(1.5rem, 4vw, 3rem);
    z-index: 6;
    background: rgba(28, 22, 18, 0.92);
}

.map3d-detail__error p {
    color: var(--lat40-ivory, #f4eadc);
    font-family: var(--map3d-sans, "Inter", system-ui, sans-serif);
    font-size: 0.92rem;
    line-height: 1.6;
    max-width: 38rem;
    margin: 0 0 1.6rem;
    white-space: pre-line;
}

.map3d-detail__error button {
    background: transparent;
    color: var(--lat40-gold, #c9a16b);
    border: 1px solid var(--lat40-gold, #c9a16b);
    padding: 0.75rem 1.4rem;
    font-family: var(--map3d-sans, "Inter", system-ui, sans-serif);
    font-size: 0.72rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 200ms ease, color 200ms ease;
}

.map3d-detail__error button:hover {
    background: var(--lat40-gold, #c9a16b);
    color: var(--lat40-ink, #1d1713);
}

/* Responsive */
@media (max-width: 900px) {
    .map3d-detail__title { display: none; }
    .map3d-detail__back  { font-size: 0.65rem; padding: 0.55rem 0.85rem; }
}
