/* Popup Styles LAYER FIX V2 - Mobile Structure Hack */

/* Overlay - General */
.apl-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999990;
    display: flex;
    pointer-events: none !important;
}

/* Container */
.apl-popup-container {
    position: relative;
    background: white;
    box-shadow: 0 15px 50px -10px rgba(0, 0, 0, 0.25);
    border-radius: 16px;
    pointer-events: auto !important;
    overflow: visible;
    z-index: 999999;

    /* Desktop */
    margin: 20px !important;
    width: auto;
    height: auto;
    max-width: 500px;
}

/* Close Link */
.apl-popup-close {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 34px;
    height: 34px;
    background: white;
    border-radius: 50%;
    border: 1px solid #ddd;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    z-index: 2147483647 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #333;
    pointer-events: auto !important;
}

/* Desktop Styles */
@media (min-width: 769px) {
    .apl-position-center {
        align-items: center;
        justify-content: center;
    }

    .apl-position-bottom-right {
        align-items: flex-end;
        justify-content: flex-end;
    }

    .apl-position-bottom-left {
        align-items: flex-end;
        justify-content: flex-start;
    }

    /* Force LTR for predictable positioning (Right is Right) */
    .apl-popup-overlay {
        direction: ltr !important;
    }

    /* Top Positions - FIX for "Huge White Space" */
    .apl-position-top-right {
        align-items: flex-start !important;
        justify-content: flex-end !important;
    }

    .apl-position-top-center {
        align-items: flex-start !important;
        justify-content: center !important;
    }

    .apl-position-top-left {
        align-items: flex-start !important;
        justify-content: flex-start !important;
    }

    .apl-popup-container {
        /* SAFETY NET: Never stretch taller than content */
        height: fit-content !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
    }

    .apl-popup-content {
        padding: 30px;
    }

    .apl-popup-title {
        font-size: 22px;
        margin-bottom: 15px;
    }

    .apl-popup-close:hover {
        transform: scale(1.1);
        color: #000;
        border-color: #999;
    }
}

/* --- MOBILE MAGIC (The unblocker) --- */
@media (max-width: 768px) {

    /* 1. Kill the overlay surface area */
    .apl-popup-overlay {
        top: auto !important;
        /* Don't start at top */
        bottom: 0 !important;
        /* Sit at bottom */
        height: 0 !important;
        /* Take ZERO vertical space */
        width: 100% !important;
        background: transparent !important;
        overflow: visible !important;
        /* Let popup overflow upwards */
        display: block !important;
    }

    /* 2. Position the container relative to the zero-height overlay */
    .apl-popup-container {
        position: absolute !important;
        /* Not fixed, but absolute within the fixed overlay */
        bottom: 10px !important;
        /* Push up from bottom */

        width: auto !important;
        max-width: 47vw !important;
        height: auto !important;
        min-height: 140px !important;

        border-radius: 10px !important;
        direction: ltr !important;
        box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3) !important;
        margin: 0 !important;
    }

    .apl-popup-content {
        direction: rtl !important;
        text-align: center !important;
        padding: 10px !important;
    }

    .apl-popup-content img {
        max-width: 100% !important;
        margin: 0 auto 6px auto !important;
        border-radius: 6px;
    }

    .apl-popup-title {
        font-size: 14px !important;
        margin-bottom: 4px !important;
        line-height: 1.2;
    }

    .apl-popup-body {
        font-size: 11px !important;
        line-height: 1.3;
    }

    .apl-popup-button {
        padding: 6px 0 !important;
        font-size: 11px !important;
        width: 100%;
        margin-top: 4px !important;
    }

    /* 3. REFINED CLICKABLE CLOSE BUTTON (V3 - Visual vs Touch separation) */
    .apl-popup-close {
        /* Positioning */
        top: -8px !important;
        right: -8px !important;

        /* VISUAL SIZE (Small Circle) */
        width: 24px !important;
        height: 24px !important;
        padding: 0 !important;
        /* No padding inside the visual circle */
        margin: 0 !important;

        background: rgba(255, 255, 255, 0.95) !important;
        border: 1px solid rgba(0, 0, 0, 0.1) !important;
        color: #555 !important;
        border-radius: 50% !important;

        display: flex !important;
        align-items: center;
        justify-content: center;
        font-size: 14px !important;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15) !important;
        opacity: 0.9 !important;

        /* Ensure specific sizing logic */
        box-sizing: border-box !important;
    }

    /* Shrink the icon inside to fit nicely */
    .apl-popup-close svg {
        width: 14px !important;
        height: 14px !important;
    }

    /* THE MAGIC TOUCH AREA (Invisible Expansion) */
    .apl-popup-close::after {
        content: '';
        position: absolute;
        top: -15px;
        left: -15px;
        right: -15px;
        bottom: -15px;
        /* Huge invisible hit box */
        border-radius: 50%;
        background: transparent;
        z-index: 10;
        cursor: pointer;
    }

    /* POSITIONS */
    /* Since container is absolute inside overlay, we use left/right/bottom easily */
    .apl-position-bottom-right .apl-popup-container,
    .apl-container-bottom-right {
        right: 5px !important;
        left: auto !important;
    }

    .apl-position-bottom-left .apl-popup-container,
    .apl-container-bottom-left {
        left: 5px !important;
        right: auto !important;
    }
}

.apl-animation-fade {
    animation: aplFadeIn 0.4s ease;
    transform-origin: bottom center;
}

@keyframes aplFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}