:root {
    --popup-primary: #154390;
    --popup-white: #fff;
    --popup-text: #333;
    --popup-overlay: rgba(0, 0, 0, 0.2);
    --popup-shadow: 0 10px 30px rgba(0,0,0,0.2);
    --popup-radius: 8px;
    --trans-speed: 0.4s;
}

/* --- Base container --- */
.custom-popup {
    position: fixed;
    z-index: 99999;
    opacity: 0;
    visibility: hidden;
    transition: all var(--trans-speed) ease;
}

/* Ripristino dello stato minimizzato al caricamento della pagina (vedi main.js): va impostato senza
   animazione. Il transform di partenza e' translateX(0), cioe' la posizione aperta, quindi lasciando
   correre la transizione il pannello si vede comparire aperto e richiudersi a ogni cambio pagina.
   Vale un solo frame: il toggle dell'utente resta animato. */
.custom-popup.is-restoring,
.custom-popup.is-restoring * {
    transition: none !important;
}

.custom-popup * {
    box-sizing: border-box;
}

.custom-popup__overlay {
    position: absolute;
    inset: 0;
    background: var(--popup-overlay);
    backdrop-filter: blur(2px);
    transition: .3s;
}

.custom-popup .icon {
    aspect-ratio: 1;
}

/* Visibility trigger */
.custom-popup.is-visible {
    opacity: 1;
    visibility: visible;
}

/* --- Standard Mode (Overlay + Center) --- */
.custom-popup[data-mode="standard"] {
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--popup-overlay);
    padding: 16px;
}

.custom-popup[data-mode="standard"] .custom-popup__content {
    position: relative;
    background: var(--popup-white);
    width: 100%;
    max-width: 500px;
    padding: 30px;
    border-radius: var(--popup-radius);
    box-shadow: var(--popup-shadow);
    transform: translateY(20px);
    transition: transform var(--trans-speed);
}

.custom-popup[data-mode="standard"].is-visible .custom-popup__content {
    transform: translateY(0);
}

.custom-popup[data-mode="standard"] .custom-popup__close {
    position: absolute;
    top: 8px;
    right: 8px;
    border: none;
    cursor: pointer;
    color: var(--popup-text);
    line-height: 1;
    width: 36px;
    height: 36px;
    background: var(--popup-white);
    border-radius: 0 0 0 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Slide-in Mode (Bottom Left + Tab) --- */
.custom-popup[data-mode="slidein"] {
    top: auto;
    right: auto;
    bottom: 0;
    left: 0;
    width: auto;
    max-width: 400px;
    transform: translateX(0);
    transition: transform var(--trans-speed) cubic-bezier(0.25, 0.8, 0.25, 1), opacity var(--trans-speed);
    pointer-events: none;
}

.custom-popup[data-mode="slidein"] .custom-popup__content {
    background: var(--popup-white);
    border-radius: 0 var(--popup-radius) var(--popup-radius) 0;
    box-shadow: var(--popup-shadow);
    padding: 12px;
    pointer-events: auto;
    transform: translateY(100px);
    transition: transform var(--trans-speed);
    max-width: 320px !important;
}

.custom-popup[data-mode="slidein"].is-visible .custom-popup__content {
    transform: translateY(0);
}

/* Hides the popup box on the left */
.custom-popup[data-mode="slidein"].is-minimized {
    transform: translateX(calc(-100% - 20px));
}

.custom-popup[data-mode="slidein"] .custom-popup__toggle {
    pointer-events: auto;
    cursor: pointer;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--trans-speed);
    z-index: 10;
}

/* Toggle state: OPEN (X button inside) */
.custom-popup[data-mode="slidein"]:not(.is-minimized) .custom-popup__toggle {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 36px;
    height: 36px;
    background: var(--popup-white);
    border-radius: 0 0 0 8px;
}

/* Toggle state: MINIMIZED (Side tab) */
.custom-popup[data-mode="slidein"].is-minimized .custom-popup__toggle {
    position: absolute;
    left: calc(100% + 20px);
    bottom: 24px;
    background: var(--popup-primary);
    color: white;
    padding: 8px;
    border-radius: 0 8px 8px 0;
    flex-direction: column-reverse;
    gap: 10px;
}

/* Vertical text for the tab */
.custom-popup__label {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg) translateX(1px);
    white-space: nowrap;
    font-size: .875em;
    font-weight: 500;
    text-transform: uppercase;
}

.custom-popup__toggle-state { display: none; }

.custom-popup[data-mode="slidein"]:not(.is-minimized) .custom-popup__toggle-state--close {
    display: flex;
}

.custom-popup[data-mode="slidein"].is-minimized .custom-popup__toggle-state--open {
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: 4px;
}

.custom-popup__toggle .icon { font-size: 24px; }

.custom-popup__toggle-state--open .icon {
    width: 24px;
    height: 24px;
}

/* Names the icon-only toggle for assistive technology. It lives in this stylesheet rather than
   reusing the theme's `.sr-only` because the theme CSS is loaded asynchronously by WP Rocket:
   until it applies, the text would be visible inside the button. This file has no such window —
   it is also what hides the popup in the first place (`.custom-popup { visibility: hidden }`),
   so if it has not loaded there is nothing to keep hidden.
   Absolute positioning keeps it out of the flex flow, so the toggle's layout is unchanged. */
.custom-popup__sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* --- Content Resets & Image Handling --- */
.custom-popup__body img {
    max-width: 100%;
    height: auto;
    display: block;
}

.custom-popup .wp-block-image:last-child {
    margin-bottom: 0;
}

/* --- Codice coupon di campagna --- */

/* Il codice del coupon dentro il popup e' un link vero (`?coupon=CODICE`, gestito da
   inc/hooks/woocommerce/coupon-from-url.php): cliccandolo il coupon si mette in carrello da solo,
   quindi deve sembrare cliccabile. Senza questa regola non lo sembra, perche' il tema toglie la
   sottolineatura agli anchor, e qui il colore non aiuta nemmeno per differenza: lo stile di gruppo
   di Gutenberg dipinge i link del popup dello stesso bianco del testo (e il colore da solo non
   basterebbe comunque, WCAG 1.4.1).
   Stessa resa della bacheca (`.welcome-banner__coupon-link`, in
   assets/src/sass/frontend/woocommerce/_account.scss): semibold - dallo `<strong>` che sta nel
   contenuto del popup - piu' una sottolineatura che sparisce su hover/focus.
   Colpisce il solo link del coupon, non ogni anchor che un redattore puo' mettere in un popup.
   ⚠️ Il `.custom-popup` iniziale non e' ridondante, serve a vincere per specificita': la regola del
   tema compilata e' `a:not(.btn--underline):not(.product-spec-link__cta)`, che vale gia' (0,2,1),
   e questo foglio e' accodato **prima** di main.min.css - per giunta WP Rocket rimanda entrambi,
   quindi l'ordine di applicazione non e' nemmeno garantito. Senza quella classe si pareggia e si
   perde, e senza alcun errore: la prima stesura di questa regola, piu' corta, non sottolineava
   niente. */
.custom-popup .custom-popup__body a[href*="coupon="] {
    text-decoration: underline;
}

.custom-popup .custom-popup__body a[href*="coupon="]:hover,
.custom-popup .custom-popup__body a[href*="coupon="]:focus {
    text-decoration: none;
}

/* Disable standard elements in slide-in mode */
.custom-popup[data-mode="slidein"] .custom-popup__overlay,
.custom-popup[data-mode="slidein"] .custom-popup__close {
    display: none;
}

/* --- Responsive Adjustments --- */
@media (max-width: 768px) {
    .custom-popup[data-mode="standard"] .custom-popup__content {
        width: 95%;
        max-height: 90vh;
        overflow-y: auto;
    }

    .custom-popup[data-mode="slidein"] .custom-popup__content {
        max-width: 280px !important;
    }
}

/* --- Linguetta del primo ordine (WELCOME20): solo sotto 1024 px --- */

/* Da 1024 px compare la barra di navigazione desktop, con la voce «Primo ordine -20%» che porta al
   percorso del primo ordine: da lì in su la linguetta laterale col coupon WELCOME20 non esce.
   Sotto i 1024 px resta com'è. Il popup si riconosce dal link del coupon nel contenuto, che vale
   per i tre post (uno per lingua); un popup slide-in con un altro codice non è toccato. La regola
   è in questo foglio, lo stesso che rende visibile il popup, quindi si applica nello stesso
   momento. Senza supporto per `:has()` non si applica e la linguetta resta visibile. */
@media (min-width: 1024px) {
    .custom-popup[data-mode="slidein"]:has(a[href*="coupon=WELCOME20" i]) {
        display: none;
    }
}
