:root {
    --popup-primary: #00a3b0; /* FFL brand teal */
    /* Darker teal for small white text: #00a3b0 on white text is ~3:1, this is ~5:1 (WCAG AA). */
    --popup-primary-dark: #007a84;
    --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;
}

/* The BuddyBoss theme styles every <button> (white text, 10px 20px padding): reset ours, otherwise
   the close icon is white on white and the button grows over the content. */
.custom-popup .custom-popup__close,
.custom-popup .custom-popup__toggle,
.custom-popup .custom-popup__close:hover,
.custom-popup .custom-popup__toggle:hover,
.custom-popup .custom-popup__close:focus,
.custom-popup .custom-popup__toggle:focus {
    padding: 0;
    min-height: 0;
    color: var(--popup-text);
    background: var(--popup-white);
    box-shadow: none;
}

/* --- 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);
    /* Room on the right for the close toggle, which sits over the top-right corner. */
    padding: 12px 48px 12px 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,
.custom-popup[data-mode="slidein"].is-minimized .custom-popup__toggle:hover,
.custom-popup[data-mode="slidein"].is-minimized .custom-popup__toggle:focus {
    position: absolute;
    left: calc(100% + 20px);
    bottom: 24px;
    background: var(--popup-primary-dark);
    color: var(--popup-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` so the plugin does not depend on theme CSS or on the order
   in which WP Rocket applies deferred stylesheets. 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;
}

/* 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;
    }
}

/* The dialog container receives focus on open (tabindex="-1") only to move the reading position:
   it is not an interactive control, so no focus ring. */
.custom-popup__content:focus {
    outline: none;
}

/* --- Countdown --- */
.custom-popup__countdown {
    text-align: center;
    margin: 0 0 16px;
}

.custom-popup__body + .custom-popup__countdown {
    margin: 16px 0 0;
}

.custom-popup__countdown-label,
.custom-popup__countdown-expired {
    margin: 0 0 8px;
    font-weight: 600;
    color: var(--popup-text);
}

.custom-popup__countdown-expired {
    margin: 0;
}

.custom-popup__countdown-timer {
    display: flex;
    justify-content: center;
    gap: 8px;
}

.custom-popup__countdown-unit {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 56px;
    padding: 8px 4px;
    border-radius: var(--popup-radius);
    background: var(--popup-primary-dark);
    color: var(--popup-white);
    line-height: 1.1;
}

.custom-popup__countdown-value {
    font-size: 1.5em;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.custom-popup__countdown-unit-label {
    font-size: .75em;
    text-transform: uppercase;
}

@media (max-width: 768px) {
    .custom-popup__countdown-unit {
        min-width: 48px;
    }

    .custom-popup__countdown-value {
        font-size: 1.25em;
    }
}
