/* ✅ Kiwa Beauty Popup Styles - Versione Ottimizzata */

/* ✅ MIGLIORAMENTO: Z-index più ragionevole per evitare conflitti */
.kiwa-popup-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background-color: rgba(0, 0, 0, 0.8) !important;
    z-index: 999999 !important; /* ✅ Ridotto da 2147483647 */
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease-in-out;
    pointer-events: none; /* ✅ Previene interazioni quando nascosto */
}

.kiwa-popup-overlay.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto; /* ✅ Ripristina interazioni quando visibile */
}

/* Regola rimossa - popup mostrato in tutte le pagine */

.kiwa-popup-container {
    position: relative !important;
    width: 90%;
    max-width: 600px;
    height: 80%;
    max-height: 500px;
    background-size: cover !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    transform: scale(0.7);
    transition: transform 0.3s ease-in-out;
    z-index: 1000000 !important; /* ✅ Ridotto ma sempre sopra overlay */
}

.kiwa-popup-overlay.show .kiwa-popup-container {
    transform: scale(1);
}

.kiwa-popup-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border: none;
    background-color: rgba(255, 255, 255, 0.9);
    color: #333;
    font-size: 24px;
    font-weight: bold;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 1000001 !important; /* ✅ Sopra tutto */
    
    /* ✅ MIGLIORAMENTO: Migliore accessibilità */
    outline: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.kiwa-popup-close:hover,
.kiwa-popup-close:focus {
    background-color: white;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* ✅ MIGLIORAMENTO: Stile per quando è premuto */
.kiwa-popup-close:active {
    transform: scale(0.95);
}

.kiwa-popup-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    width: 85%;
}

.kiwa-popup-logo {
    margin-bottom: 40px;
}

.kiwa-popup-logo img {
    max-height: 60px;
    max-width: 200px;
    height: auto;
    width: auto;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.kiwa-popup-message {
    background-color: rgba(255, 255, 255, 0.95);
    padding: 30px 25px;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.kiwa-popup-message h2 {
    font-size: 28px;
    font-weight: bold;
    color: #333;
    margin: 0 0 15px 0;
    letter-spacing: 2px;
    text-transform: uppercase;
    
    /* ✅ MIGLIORAMENTO: Reset degli stili che potrebbero interferire */
    line-height: 1.2;
    font-family: inherit;
}

.kiwa-popup-divider {
    width: 60px;
    height: 2px;
    background-color: #333;
    margin: 15px auto 25px auto;
}

.kiwa-popup-message p {
    font-size: 16px;
    color: #555;
    margin: 8px 0;
    line-height: 1.4;
    
    /* ✅ MIGLIORAMENTO: Reset degli stili */
    font-family: inherit;
    font-weight: normal;
}

.kiwa-popup-message p strong {
    color: #333;
    font-weight: bold;
}

/* ✅ MIGLIORAMENTO: Prevenzione conflitti con altri plugin */
.kiwa-popup-overlay * {
    box-sizing: border-box;
}

.kiwa-popup-overlay,
.kiwa-popup-overlay * {
    /* Reset che previene conflitti */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-style: normal;
    font-variant: normal;
    text-decoration: none;
    text-transform: none;
}

/* ✅ RESPONSIVE: Design migliorato per mobile */
@media (max-width: 768px) {
    .kiwa-popup-container {
        width: 95%;
        height: 85%;
        max-height: 600px;
    }
    
    .kiwa-popup-close {
        top: 15px;
        right: 15px;
        width: 35px;
        height: 35px;
        font-size: 20px;
    }
    
    .kiwa-popup-logo img {
        max-height: 50px;
    }
    
    .kiwa-popup-message {
        padding: 25px 20px;
    }
    
    .kiwa-popup-message h2 {
        font-size: 24px;
    }
    
    .kiwa-popup-message p {
        font-size: 15px;
    }
}

@media (max-width: 480px) {
    .kiwa-popup-container {
        width: 98%;
        height: 90%;
    }
    
    .kiwa-popup-content {
        width: 90%;
    }
    
    .kiwa-popup-logo {
        margin-bottom: 30px;
    }
    
    .kiwa-popup-logo img {
        max-height: 45px;
    }
    
    .kiwa-popup-message {
        padding: 20px 15px;
    }
    
    .kiwa-popup-message h2 {
        font-size: 20px;
        letter-spacing: 1px;
    }
    
    .kiwa-popup-message p {
        font-size: 14px;
    }
}

/* ✅ MIGLIORAMENTO: Animazioni più fluide */
@keyframes kiwaFadeInScale {
    from {
        opacity: 0;
        transform: scale(0.7);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes kiwaFadeOut {
    from {
        opacity: 1;
        visibility: visible;
    }
    to {
        opacity: 0;
        visibility: hidden;
    }
}

.kiwa-popup-overlay.show .kiwa-popup-container {
    animation: kiwaFadeInScale 0.3s ease-out forwards;
}

/* ✅ SICUREZZA: Stili per situazioni di emergenza */
.kiwa-emergency-hidden {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* ✅ MIGLIORAMENTO: Indicatore di caricamento per le immagini */
.kiwa-popup-container[style*="background-image"] {
    background-color: #f0f0f0; /* Colore di fallback */
}

.kiwa-popup-logo img {
    background-color: transparent;
    transition: opacity 0.3s ease;
}

/* ✅ ACCESSIBILITÀ: Focus per navigazione da tastiera */
.kiwa-popup-close:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

/* ✅ PERFORMANCE: Ottimizzazione per GPU */
.kiwa-popup-overlay,
.kiwa-popup-container {
    will-change: transform, opacity;
    backface-visibility: hidden;
    transform-style: preserve-3d;
}

/* ✅ COMPATIBILITÀ: Prevenzione conflitti con temi comuni */
.kiwa-popup-overlay {
    font-size: 16px; /* Reset base */
}

.kiwa-popup-overlay h1,
.kiwa-popup-overlay h2,
.kiwa-popup-overlay h3,
.kiwa-popup-overlay h4,
.kiwa-popup-overlay h5,
.kiwa-popup-overlay h6 {
    margin: 0;
    padding: 0;
    border: none;
    background: none;
}

.kiwa-popup-overlay p {
    margin: 8px 0;
    padding: 0;
    border: none;
    background: none;
}

.kiwa-popup-overlay img {
    border: none;
    box-shadow: none;
    max-width: 100%;
    height: auto;
}

/* ✅ FALLBACK: Se JavaScript è disabilitato */
.no-js .kiwa-popup-overlay {
    display: none !important;
}