/* --- 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;
    overflow: hidden; /* only .ostore-popup-content scrolls; the wrapper itself must stay put */
}

.ostore-checkout-popup-wrapper.active {
    display: flex; /* centers the container; no outer scroll to fight with the inner one */
    align-items: center;
    justify-content: center;
}

/* 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). */
html.ostore-popup-open,
body.ostore-popup-open {
    overflow: hidden;
    height: 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;
    max-height: calc(100vh - 80px); /* bounds the panel so its own content scrolls, not the page */
    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;
    overflow: hidden;
}

@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 {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain; /* keeps momentum scroll from chaining to the page behind it */
    padding: 24px;
    padding-top: 34px; /* clears the close button, which sits above this content now that the top bar is gone */
}

/* Sticky action bar: confirm button + order total always stay reachable,
   regardless of how many products or form fields are above them. */
.ostore-checkout-popup-wrapper .ostore-checkout-actions {
    position: sticky;
    bottom: -24px; /* cancels .ostore-popup-content's own bottom padding */
    margin: 12px -24px -24px;
    padding: 12px 24px 24px;
    background: #fff;
    border-top: 1px solid #f0f0f0;
}

/* Product Summary in Popup */
.ostore-checkout-popup-wrapper .ostore-popup-product-summary {
    background: transparent;
    padding: 0;
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    max-height: 200px; /* Cap height to keep the form visible and accessible */
    overflow-y: auto;
    padding-right: 5px;
}

/* Custom thin scrollbar for product summary */
.ostore-checkout-popup-wrapper .ostore-popup-product-summary::-webkit-scrollbar {
    width: 4px;
}

.ostore-checkout-popup-wrapper .ostore-popup-product-summary::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}

.ostore-checkout-popup-wrapper .ostore-popup-product-summary::-webkit-scrollbar-track {
    background: transparent;
}

.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: 0 12px; /* 12px gap on sides for unified mobile spacing */
        display: none; /* Keep hidden by default */
    }
    .ostore-checkout-popup-wrapper.active {
        display: flex; /* Show + center only when active */
        align-items: center;
        justify-content: center;
    }
    .ostore-checkout-popup-wrapper .ostore-popup-container {
        min-height: auto; /* Not full height */
        max-height: calc(100vh - 40px); /* bounded so the panel scrolls internally and the action bar can stick */
        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;
        bottom: -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); }
}
