/* ==========================================================================
   ONBOARDING INTERACTIVO — tour guiado (FAB + spotlight + popover)
   Sin dependencias. Consume los tokens del sistema de diseño, por lo que
   funciona en tema claro/oscuro y en ambas escuelas sin reglas extra.
   Estructura:
     .tour-guia            contenedor (display: contents, no crea contexto)
     .tour-fab             botón flotante de disparo
     .tour-menu            mini-menú rápido del FAB
     .tour-capa            capa que captura la interacción
     .tour-foco            agujero del spotlight (box-shadow gigante)
     .tour-tarjeta         tarjeta flotante del paso
   ========================================================================== */

.tour-guia {
    /* `contents` evita que el contenedor cree contexto de apilamiento o
       containing block: los hijos `position: fixed` se miden contra el
       viewport aunque el layout padre tenga transform/filter. */
    display: contents;
}

.tour-guia[hidden] {
    display: none !important;
}

/* --- Botón flotante de disparo (FAB) ------------------------------------- */

.tour-fab {
    position: fixed;
    right: max(24px, env(safe-area-inset-right, 0px));
    bottom: max(24px, env(safe-area-inset-bottom, 0px));
    z-index: 1250;
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    padding: 0;
    border: 0;
    border-radius: var(--radio-pill);
    background: var(--boton-primario);
    color: var(--boton-primario-contraste);
    box-shadow: 0 12px 26px -12px var(--boton-primario-sombra), 0 2px 6px rgba(0, 0, 0, 0.18);
    cursor: pointer;
    transition: transform var(--transicion), background var(--transicion), box-shadow var(--transicion);
}

.tour-fab:hover {
    transform: translateY(-2px) scale(1.05);
    background: var(--boton-primario-hover);
    box-shadow: 0 16px 30px -12px var(--boton-primario-sombra), 0 3px 8px rgba(0, 0, 0, 0.2);
}

.tour-fab:active {
    transform: scale(0.96);
}

.tour-fab:focus-visible {
    outline: 3px solid var(--acento);
    outline-offset: 3px;
}

.tour-fab__icono {
    font-size: 1.15rem;
    font-weight: 800;
    line-height: 1;
    /* El icono es texto para que se vea nítido sin cargar un SVG extra. */
    font-family: var(--fuente-base);
}

/* Pulso suave sólo la primera vez (clase que pone el JS al no haber tour hecho). */
.tour-fab[data-novedad="true"]::after {
    content: "";
    position: absolute;
    inset: -4px;
    border-radius: inherit;
    border: 2px solid var(--boton-primario);
    opacity: 0;
    animation: tour-pulso 2.4s ease-out 1.2s 2;
    pointer-events: none;
}

@keyframes tour-pulso {
    0% { transform: scale(0.9); opacity: 0.55; }
    70% { transform: scale(1.35); opacity: 0; }
    100% { transform: scale(1.35); opacity: 0; }
}

/* Tooltip accesible: visible en hover y en focus de teclado. */
.tour-fab__tooltip {
    position: absolute;
    right: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%) translateX(6px);
    padding: 0.35rem 0.6rem;
    border-radius: var(--radio-sm);
    background: var(--texto);
    color: var(--fondo);
    font-size: var(--texto-xs);
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transicion), transform var(--transicion);
}

.tour-fab:hover .tour-fab__tooltip,
.tour-fab:focus-visible .tour-fab__tooltip {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

/* Desplazamiento cuando el sitio ya tiene otro FAB en la misma esquina
   (menú burbuja del sitio público). Lo activa el JS detectando el otro botón. */
.tour-guia[data-desplazado="true"] .tour-fab {
    bottom: calc(max(24px, env(safe-area-inset-bottom, 0px)) + 68px);
}

/* --- Mini-menú rápido ---------------------------------------------------- */

.tour-menu {
    position: fixed;
    z-index: 1251;
    display: grid;
    gap: 2px;
    min-width: 236px;
    max-width: calc(100vw - 32px);
    padding: 0.35rem;
    border: 1px solid var(--borde);
    border-radius: var(--radio);
    background: var(--superficie);
    box-shadow: var(--sombra);
    animation: tour-aparecer 160ms ease-out;
}

.tour-menu[hidden] {
    display: none;
}

.tour-menu__opcion {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    width: 100%;
    padding: 0.6rem 0.7rem;
    border: 0;
    border-radius: var(--radio-sm);
    background: none;
    color: var(--texto);
    font-family: inherit;
    font-size: var(--texto-sm);
    font-weight: 600;
    text-align: start;
    text-decoration: none;
    cursor: pointer;
    transition: background var(--transicion), color var(--transicion);
}

.tour-menu__opcion:hover,
.tour-menu__opcion:focus-visible {
    background: var(--superficie-2);
    color: var(--acento-fuerte);
    outline: none;
}

.tour-menu__opcion[aria-disabled="true"] {
    color: var(--texto-tenue);
    cursor: not-allowed;
}

.tour-menu__opcion small {
    display: block;
    color: var(--texto-tenue);
    font-size: var(--texto-xs);
    font-weight: 500;
}

/* --- Spotlight ----------------------------------------------------------- */

.tour-capa {
    position: fixed;
    inset: 0;
    z-index: 1300;
    background: transparent;
    /* Bloquea la interacción con la página pero deja pasar el scroll y los
       eventos de teclado, que se manejan en el documento. */
    cursor: default;
}

.tour-foco {
    position: fixed;
    z-index: 1301;
    border-radius: 12px;
    pointer-events: none;
    /* El primer shadow con spread enorme oscurece todo MENOS el recuadro;
       el segundo dibuja un borde interior de 2px. */
    box-shadow:
        0 0 0 100vmax rgba(8, 10, 18, 0.66),
        inset 0 0 0 2px rgba(255, 255, 255, 0.35);
    transition:
        top 220ms cubic-bezier(0.2, 0.7, 0.3, 1),
        left 220ms cubic-bezier(0.2, 0.7, 0.3, 1),
        width 220ms cubic-bezier(0.2, 0.7, 0.3, 1),
        height 220ms cubic-bezier(0.2, 0.7, 0.3, 1);
}

.tour-foco[hidden],
.tour-capa[hidden] {
    display: none;
}

/* --- Tarjeta del paso ---------------------------------------------------- */

.tour-tarjeta {
    position: fixed;
    z-index: 1302;
    display: grid;
    gap: 0.5rem;
    width: min(360px, calc(100vw - 28px));
    padding: 1rem 1.05rem 1.1rem;
    border: 1px solid var(--borde);
    border-radius: var(--radio);
    background: var(--superficie);
    color: var(--texto);
    box-shadow: var(--sombra);
    animation: tour-aparecer 180ms ease-out;
}

.tour-tarjeta[hidden] {
    display: none;
}

.tour-tarjeta:focus-visible {
    outline: 2px solid var(--acento);
    outline-offset: 2px;
}

@keyframes tour-aparecer {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.tour-tarjeta__cabecera {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
}

.tour-tarjeta__titulo {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.3;
}

.tour-tarjeta__cerrar {
    flex: none;
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid var(--borde);
    border-radius: var(--radio-pill);
    background: var(--superficie);
    color: var(--texto-suave);
    font-size: 0.9rem;
    line-height: 1;
    cursor: pointer;
    transition: background var(--transicion), color var(--transicion), border-color var(--transicion);
}

.tour-tarjeta__cerrar:hover {
    background: var(--peligro-suave);
    border-color: var(--peligro);
    color: var(--peligro);
}

.tour-tarjeta__cerrar:focus-visible {
    outline: 2px solid var(--acento);
    outline-offset: 2px;
}

.tour-tarjeta__texto {
    margin: 0;
    color: var(--texto-suave);
    font-size: var(--texto-sm);
    line-height: 1.55;
    /* Evita que un mensaje con una palabra larga desborde en 320px. */
    overflow-wrap: anywhere;
}

.tour-progreso {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--texto-tenue);
    font-size: var(--texto-xs);
    font-weight: 600;
}

.tour-progreso__pista {
    flex: 1;
    height: 6px;
    border-radius: var(--radio-pill);
    background: var(--superficie-2);
    overflow: hidden;
}

.tour-progreso__relleno {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: var(--boton-primario);
    transition: width 220ms cubic-bezier(0.2, 0.7, 0.3, 1);
}

.tour-tarjeta__acciones {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    margin-top: 0.15rem;
}

.tour-tarjeta__acciones .boton {
    flex: 1 1 auto;
    min-width: 6.5rem;
    padding-inline: 0.9rem;
}

.tour-tarjeta__saltar {
    justify-self: start;
    padding: 0.15rem 0;
    border: 0;
    background: none;
    color: var(--texto-tenue);
    font-family: inherit;
    font-size: var(--texto-xs);
    text-decoration: underline;
    cursor: pointer;
    transition: color var(--transicion);
}

.tour-tarjeta__saltar:hover,
.tour-tarjeta__saltar:focus-visible {
    color: var(--peligro);
}

/* Elemento resaltado: por encima del spotlight para que se perciba nítido. */
[data-tour-resaltado="true"] {
    position: relative;
    z-index: 1301;
}

/* --- Adaptación móvil ---------------------------------------------------- */

@media (max-width: 480px) {
    .tour-fab {
        right: max(16px, env(safe-area-inset-right, 0px));
        width: 48px;
        height: 48px;
    }

    .tour-guia[data-desplazado="true"] .tour-fab {
        bottom: calc(max(16px, env(safe-area-inset-bottom, 0px)) + 62px);
    }

    .tour-fab__tooltip {
        /* El tooltip flotante puede salirse en pantallas estrechas: se oculta
           y la información sigue disponible por aria-label. */
        display: none;
    }

    .tour-tarjeta--hoja {
        /* Hoja inferior: nunca desborda horizontalmente ni tapa el objetivo. */
        top: auto !important;
        left: 12px !important;
        right: 12px;
        bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        width: auto;
        max-height: 62vh;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .tour-tarjeta__acciones .boton {
        min-width: 0;
    }

    .tour-menu {
        min-width: 0;
        left: 12px;
        right: 12px;
        width: auto;
    }
}

/* --- Accesibilidad: sin movimiento --------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    .tour-fab,
    .tour-foco,
    .tour-tarjeta,
    .tour-menu,
    .tour-progreso__relleno {
        transition: none !important;
        animation: none !important;
    }

    .tour-fab[data-novedad="true"]::after {
        animation: none !important;
    }
}

/* Impresión: el tour no debe aparecer en un PDF o captura del sitio. */
@media print {
    .tour-guia {
        display: none !important;
    }
}
