/* --- Checkout Popup System --- */
.ostore-checkout-popup-wrapper,
.ostore-checkout-popup-wrapper *,
.ostore-checkout-popup-wrapper *::before,
.ostore-checkout-popup-wrapper *::after {
    box-sizing: border-box !important;
}

.ostore-checkout-popup-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999999999 !important; /* Above cart drawer and everything else */
    display: none;
    /* The wrapper itself is the single scroll region: the popup panel renders at
       its full natural height (no internal sub-scroll), and if it's taller than
       the viewport, this scrolls the whole thing — panel, list, form, button, all together. */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 40px 16px;
}

.ostore-checkout-popup-wrapper.active {
    display: flex;
    align-items: flex-start; /* not center: centering a taller-than-viewport flex child can clip its top out of scroll reach */
    justify-content: center;
    min-height: 100%;
}

/* Locks the background page while the popup is open so touch drags can't scroll it
   underneath the popup (which read as scrolling "from outside" on mobile).
   overflow:hidden alone doesn't stop touch-drag scrolling on iOS Safari — body
   must also be pinned with position:fixed (scroll offset saved/restored in popup.js). */
html.ostore-popup-open,
body.ostore-popup-open {
    overflow: hidden;
    height: 100%;
}
body.ostore-popup-open {
    position: fixed;
    width: 100%;
}

.ostore-checkout-popup-wrapper .ostore-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: -1;
}

.ostore-checkout-popup-wrapper .ostore-popup-container {
    position: relative;
    background: #fff;
    width: 100%;
    max-width: 500px;
    border-radius: 12px;
    border: 2px solid var(--ostore-brand, #355872); /* 2px Brand Border */
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    animation: ostore-popup-slide 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1;
}

@keyframes ostore-popup-slide {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.ostore-checkout-popup-wrapper .ostore-popup-close {
    position: absolute;
    top: 8px; /* Adjusted */
    right: 15px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #333; /* Dark color for white background */
    z-index: 10;
    transition: opacity 0.2s;
}

.ostore-checkout-popup-wrapper .ostore-popup-close:hover {
    opacity: 0.7;
}

.ostore-checkout-popup-wrapper .ostore-popup-content {
    padding: 24px;
    padding-top: 34px; /* clears the close button, which sits above this content now that the top bar is gone */
}

.ostore-checkout-popup-wrapper .ostore-checkout-actions {
    margin: 12px -24px -24px;
    padding: 12px 24px 24px;
    background: #fff;
    border-top: 1px solid #f0f0f0;
    /* This box's negative margins bleed it out to the container's own edges;
       since the container no longer clips via overflow:hidden (that broke
       internal scrolling), it needs its own matching radius on the bottom
       corners it now touches directly. */
    border-radius: 0 0 10px 10px;
}

/* Product Summary in Popup — flows inside .ostore-popup-content, which is the
   single scroll container for the whole popup (products + total + form together). */
.ostore-checkout-popup-wrapper .ostore-popup-product-summary {
    background: transparent;
    padding: 0;
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
}

.ostore-checkout-popup-wrapper .ostore-summary-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid #f0f0f0;
}

.ostore-checkout-popup-wrapper .ostore-summary-item:last-child {
    border-bottom: none;
}

.ostore-checkout-popup-wrapper .ostore-item-image {
    width: 45px;
    height: 45px;
    border-radius: 6px;
    position: relative;
    border: 1px solid #f0f0f0;
    flex-shrink: 0;
}

.ostore-checkout-popup-wrapper .ostore-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 6px;
}

.ostore-checkout-popup-wrapper .ostore-item-qty-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 16px;
    height: 16px;
    background: var(--ostore-brand, #355872);
    color: #fff;
    font-size: 9px;
    font-weight: 800;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid #fff;
}

.ostore-checkout-popup-wrapper .ostore-item-info {
    flex: 1;
}

.ostore-checkout-popup-wrapper .ostore-item-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: #111827;
    margin: 0 0 2px 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ostore-checkout-popup-wrapper .ostore-item-variation {
    font-size: 0.6875rem;
    font-weight: 500;
    color: #9ca3af;
    margin: 0 0 2px 0;
}

.ostore-checkout-popup-wrapper .ostore-item-price {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--ostore-brand, #355872);
}

.ostore-checkout-popup-wrapper .ostore-remove-summary-item {
    background: transparent;
    border: none;
    color: #d1d5db;
    cursor: pointer;
    padding: 5px;
    font-size: 16px;
}

.ostore-checkout-popup-wrapper .ostore-remove-summary-item:hover {
    color: #111827;
}

.ostore-checkout-popup-wrapper .ostore-popup-total-bar {
    display: none;
}

/* Form Styles Override */
.ostore-checkout-popup-wrapper .ostore-popup-form-container .ostore-modular-checkout-wrapper {
    border: none;
    padding: 0;
    background: transparent;
    margin-top: 0;
}

/* Same title, same look as the product-page checkout form — just without the
   top border/spacing that separates it from content above, since here it's
   the first thing in the popup. */
.ostore-checkout-popup-wrapper .ostore-popup-form-container .ostore-checkout-header {
    padding-top: 0;
    border-top: none;
    margin-bottom: 16px;
}

@media (max-width: 500px) {
    .ostore-checkout-popup-wrapper {
        padding: 24px 12px; /* 12px gap on sides, breathing room top/bottom when the panel scrolls */
        display: none; /* Keep hidden by default */
    }
    .ostore-checkout-popup-wrapper.active {
        display: flex; /* Show + center only when active */
        align-items: flex-start; /* not center: centering a taller-than-viewport panel can clip its top out of scroll reach */
        justify-content: center;
        min-height: 100%;
    }
    .ostore-checkout-popup-wrapper .ostore-popup-container {
        min-height: auto; /* Not full height */
        border-radius: 12px;
        border: 2px solid var(--ostore-brand, #355872);
    }
    .ostore-checkout-popup-wrapper .ostore-popup-content {
        padding: 16px 12px; /* Reduce horizontal padding to make input fields wider and more responsive */
        padding-top: 34px; /* clears the close button */
    }
    .ostore-checkout-popup-wrapper .ostore-checkout-actions {
        margin: 12px -12px -16px;
        padding: 12px 12px 16px;
    }
}

/* --- Checkout Popup Loader --- */
.ostore-popup-loader {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.85);
    z-index: 99;
    display: flex;
    align-items: center;
    justify-content: center;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.ostore-checkout-popup-wrapper.loading .ostore-popup-loader {
    visibility: visible;
    opacity: 1;
}

.ostore-popup-loader .spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--ostore-brand, #355872);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    animation: ostore-popup-spin 0.8s linear infinite;
}

@keyframes ostore-popup-spin {
    to { transform: rotate(360deg); }
}
