/* Virtual Tour Styles */
.virtual-tour-wrapper {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%; /* 16:9 Aspect Ratio */
    background-color: #2c3e50; /* Colore di fallback più elegante del nero puro */
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

.virtual-tour-iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
    z-index: 1;
    /* Nascondiamo l'iframe di default per evitare il clutter dell'UI del tour in spazi piccoli */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

/* Mostriamo l'iframe quando è in fullscreen o quando la tour view è attiva */
.virtual-tour-wrapper.is-fullscreen .virtual-tour-iframe,
.virtual-tour-wrapper.show-tour .virtual-tour-iframe {
    opacity: 1;
    pointer-events: auto;
}

/* Nascondi l'overlay quando la tour view è attiva ma non in fullscreen */
.virtual-tour-wrapper.show-tour .virtual-tour-overlay {
    display: flex;
}

/* Overlay per interazione iniziale (previene scroll trap e invita al click) */
.virtual-tour-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.2);
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.3s ease;
}

.virtual-tour-overlay:hover {
    background: rgba(0,0,0,0.1);
}

/* Overlay di attivazione tour (mostrato sopra imageView quando si clicca sulla miniatura 360) */
.tour-activation-overlay {
    position: absolute !important;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    z-index: 999;
    cursor: pointer;
    pointer-events: auto;
    /* flex-direction, align-items, justify-content gestiti via JS */
}

.tour-activation-overlay:hover {
    background: rgba(0,0,0,0.8);
}

/* Assicuriamoci che i figli non blocchino i click */
.tour-activation-overlay > * {
    pointer-events: none;
}

@keyframes fadeInOverlay {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Icona e testo nell'overlay */
.virtual-tour-icon {
    font-size: 3rem;
    color: #fff;
    margin-bottom: 1rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
    transition: transform 0.3s ease;
}

.virtual-tour-overlay:hover .virtual-tour-icon {
    transform: scale(1.1);
}

.virtual-tour-text {
    color: #fff;
    font-family: 'Niramit', sans-serif;
    font-weight: 600;
    font-size: 1.2rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}

/* Pulsante Chiudi (visibile solo in fullscreen) */
.virtual-tour-close {
    position: absolute;
    top: 30px;
    left: 30px;
    right: auto;
    width: 50px;
    height: 50px;
    background-color: rgba(241, 126, 24, 0.95); /* Colore primario per visibilità */
    color: #fff;
    border: 3px solid #fff;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 100000; /* Superiore al wrapper fullscreen */
    transition: all 0.3s ease;
    font-size: 24px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.virtual-tour-close:hover {
    background: rgba(255,0,0,0.8);
    border-color: #fff;
    transform: rotate(90deg);
    animation: none; /* Ferma l'animazione quando l'utente passa il mouse */
}

/* Animazione automatica del pulsante di chiusura in fullscreen */
.virtual-tour-wrapper.is-fullscreen .virtual-tour-close {
    animation: pulseCloseButton 2s ease-in-out infinite;
}

@keyframes pulseCloseButton {
    0%, 100% {
        background-color: rgba(241, 126, 24, 0.95);
        transform: rotate(0deg);
    }
    50% {
        background-color: rgba(255, 0, 0, 0.8);
        transform: rotate(90deg);
    }
}

/* Fullscreen Mode State */
body.tour-fullscreen-active {
    overflow: hidden; /* Blocca scroll pagina */
}

.virtual-tour-wrapper.is-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    padding-bottom: 0;
    border-radius: 0;
    z-index: 99999; /* Superiore a navigation (10001) */
}

.virtual-tour-wrapper.is-fullscreen .virtual-tour-overlay {
    display: none; /* Nasconde overlay in fullscreen */
}

.virtual-tour-wrapper.is-fullscreen .virtual-tour-close {
    display: flex; /* Mostra bottone chiudi */
}

/* Fallback per errore caricamento */
.virtual-tour-error {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #2c3e50;
    color: #fff;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px;
    z-index: 3;
}

.virtual-tour-error.show {
    display: flex;
}

.virtual-tour-error i {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: var(--alife-primary);
}

.virtual-tour-error p {
    font-family: 'Niramit', sans-serif;
    font-size: 1rem;
    line-height: 1.6;
}

.virtual-tour-error button {
    margin-top: 1rem;
    padding: 10px 20px;
    background: var(--alife-primary);
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

/* Stato di caricamento del virtual tour */
.virtual-tour-wrapper.loading-tour {
    position: relative;
}

.virtual-tour-wrapper.loading-tour::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(44, 62, 80, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4;
    animation: fadeIn 0.3s ease;
}

.virtual-tour-wrapper.loading-tour::before {
    content: '\f110';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2.5rem;
    color: var(--alife-primary);
    z-index: 5;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Pulsante Torna al sito (visibile solo in fullscreen) */
.virtual-tour-back {
    position: absolute;
    bottom: 30px;
    right: 30px;
    top: auto;
    left: auto;
    height: 44px;
    padding: 0 20px;
    background-color: rgba(241, 126, 24, 0.95);
    color: #000;
    border: 3px solid #fff;
    border-radius: 6px;
    display: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    z-index: 100000;
    font-family: 'Oswald', sans-serif;
    font-size: 15px;
    font-style: italic;
    font-weight: 400;
    white-space: nowrap;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.virtual-tour-back:hover {
    background-color: rgba(255, 100, 0, 0.95);
    transform: translateY(-2px);
}

body.tour-fullscreen-active .virtual-tour-back {
    display: flex;
}

@media (max-width: 768px) {
    .virtual-tour-back {
        bottom: 80px;
        right: 16px;
        top: auto;
        left: auto;
        font-size: 13px;
        height: 36px;
        padding: 0 12px;
    }
}

/* Responsive adjustments */
@media (max-width: 991px) {
    .virtual-tour-wrapper {
        padding-bottom: 75%; /* 4:3 Aspect Ratio su tablet/mobile per maggiore visibilità verticale */
    }
}

@media (max-width: 768px) {
    .virtual-tour-icon {
        font-size: 2.5rem;
    }
    .virtual-tour-text {
        font-size: 1rem;
    }
    .virtual-tour-close {
        width: 56px; /* Touch target più grande per mobile */
        height: 56px;
        top: 30px;
        left: 30px;
        right: auto;
        font-size: 28px;
    }
    
    /* Aumentiamo leggermente il contrasto dell'overlay su mobile poiché sotto c'è l'immagine statica */
    .virtual-tour-overlay {
        background: rgba(0,0,0,0.3);
    }
}
