/*
 * Shared payment popup: product page direct pay, homepage quick buy and cart.
 * Surfaces (modal/field/border) stay local to the overlay; brand accents follow
 * the site theme via --tw-brand* from twelve-ui / national-day CSS.
 */

.tw-pp-pay-overlay {
    --tw-bg-field: #151517;
    --tw-bg-inset: #151517;
    --tw-bg-modal: #1a1a1e;
    --tw-border: #26262b;
    --tw-grad: linear-gradient(110deg, var(--tw-brand), var(--tw-brand-2));
    --tw-muted: #8b8b93;
    --tw-muted-2: #a9a9b2;
    --tw-ok: #4ade80;
    --tw-ok-border: rgba(74, 222, 128, .35);
    --tw-ok-soft: rgba(74, 222, 128, .1);
    --tw-on-primary: #fff;
    --tw-overlay: rgba(10, 10, 12, .72);
    --tw-primary: var(--tw-brand);
    --tw-primary-soft: rgba(var(--tw-brand-rgb), .1);
    --tw-shadow-md: rgba(0, 0, 0, .35);
    --tw-shadow-xl: rgba(0, 0, 0, .6);
    --tw-text: #fff;
}

body.lightMode .tw-pp-pay-overlay {
    --tw-bg-field: #ffffff;
    --tw-bg-inset: #f3f3f6;
    --tw-bg-modal: #ffffff;
    --tw-border: #e5e5ec;
    --tw-muted: #70707a;
    --tw-muted-2: #52525b;
    --tw-ok: #16a34a;
    --tw-ok-border: rgba(22, 163, 74, .3);
    --tw-ok-soft: rgba(22, 163, 74, .09);
    --tw-overlay: rgba(24, 24, 30, .48);
    --tw-shadow-md: rgba(24, 24, 40, .12);
    --tw-shadow-xl: rgba(24, 24, 40, .24);
    --tw-text: #16161a;
}

@keyframes tw-dp-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes tw-dp-pop {
    0% { transform: scale(.6); opacity: 0; }
    70% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

body.tw-pp-modal-open {
    overflow: hidden;
}

/* Direct pay overlay.
   `display` must live here, not behind a [style*="display: block"] selector:
   jQuery's fadeIn() clears the inline `display:none` to "" and only writes a
   value back when the stylesheet still hides the element, so the style
   attribute ends up with no `display` at all. Declaring grid here lets the
   inline `display:none` win while closed and lets place-items centre the
   modal once fadeIn() clears it. */
.tw-pp-pay-overlay {
    position: fixed !important;
    inset: 0;
    display: grid;
    z-index: 1000000;
    background: var(--tw-overlay);
    backdrop-filter: blur(8px);
    place-items: center;
    padding: 30px;
    animation: tw-dp-in .25s ease-out;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.tw-pp-pay-overlay::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

.tw-pp-pay-modal {
    width: min(620px, 100%);
    max-height: calc(100vh - 60px);
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    background: var(--tw-bg-modal);
    border: 1px solid rgba(var(--tw-brand-rgb), .35);
    border-radius: 24px;
    padding: 22px 26px 26px;
    box-shadow: 0 40px 100px var(--tw-shadow-xl);
    animation: tw-dp-pop .35s ease-out;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.tw-pp-pay-modal::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

.tw-pp-pay-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: sticky;
    top: -22px;
    background: var(--tw-bg-modal);
    padding: 4px 0 10px;
    border-bottom: 1px solid var(--tw-border);
    z-index: 3;
}

.tw-pp-pay-head b {
    color: var(--tw-text);
    font-size: 17px;
}

.tw-pp-pay-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* Bootstrap's default .accordion-body padding (1rem 1.25rem) stacks on top of
   this modal's own 22px/26px padding, doubling the left/right gutter around
   the wallet toggle and reward boxes. The modal's own padding is enough. */
.tw-pp-pay-modal .accordion-body {
    padding: 0;
}

/* The embedded checkout paints itself from the site-wide theme variables.
   Re-point them at the panel palette so its surfaces separate from the modal
   instead of collapsing into it (--lighter-box #1c1c1c on a #1a1a1e modal). */
.tw-pp-pay-modal {
    --primary: var(--tw-primary);
    --background: var(--tw-bg-modal);
    --box: var(--tw-bg-inset);
    --lighter-box: var(--tw-bg-inset);
    --lighter-box-2: var(--tw-bg-inset);
    --mid-box: var(--tw-bg-inset);
    --border: var(--tw-border);
    --text-color: var(--tw-muted-2);
    --light-text-color: var(--tw-text);
    --light-text-color-2: var(--tw-muted);
    --shadow: var(--tw-shadow-md);
}

.tw-pp-pay-modal .inp {
    border: 1px solid var(--tw-border);
    cursor: pointer;
    transition: border-color .2s, background-color .2s;
}

.tw-pp-pay-modal .inp:hover {
    border-color: rgba(var(--tw-brand-rgb), .45);
}

/* Selection feedback: the shared checkout only tints the native radio, which
   reads as "nothing happened" when switching gateways. */
.tw-pp-pay-modal .inp.is-selected {
    border-color: var(--tw-primary);
    background-color: var(--tw-primary-soft);
}

.tw-pp-pay-modal .payment-toggle,
.tw-pp-pay-modal .pay {
    border-radius: 14px;
}

/* The shared .payment-toggle row (icon + balance text vs. the switch) has no
   shrink/nowrap control, so in this modal's narrower 620px width the balance
   text pushes the switch to the edge or forces a wrap. Keep it one row like
   cart: icon + text packed at the start, switch fixed at the end.

   Selectors must beat
   `.accordion .accordion-item .accordion-body .method .payment-toggle .image`
   (justify-content: center / mobile flex-direction: column) — a shorter
   `.tw-pp-pay-modal .payment-toggle .image` loses, and center + flex-grow
   leaves blank space before the icon and after the switch. */
.tw-pp-pay-modal .accordion .accordion-item .accordion-body .method .payment-toggle {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 12px;
}

.tw-pp-pay-modal .accordion .accordion-item .accordion-body .method .payment-toggle .image {
    flex: 1 1 auto;
    min-width: 0;
    flex-direction: row;
    justify-content: flex-start;
    text-align: start;
    gap: 8px;
}

.tw-pp-pay-modal .payment-toggle .wallet-balance-text {
    min-width: 0;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: baseline;
    text-align: start;
}

/* Popup only: Saudi (SAR, no local approx) → balance beside the label.
   Other countries keep the balance under the label. */
.tw-pp-pay-modal .payment-toggle .wallet-balance-text:not(:has(.wallet-balance-approx)) {
    flex-wrap: nowrap;
    gap: 0.35rem 0.5rem;
}

.tw-pp-pay-modal .payment-toggle .wallet-balance-text:has(.wallet-balance-approx) {
    flex-direction: column;
    align-items: flex-start;
}

.tw-pp-pay-modal .payment-toggle .wallet-balance-text__label,
.tw-pp-pay-modal .payment-toggle .wallet-balance-convertable {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tw-pp-pay-modal .payment-toggle .wallet-balance-text:not(:has(.wallet-balance-approx)) .wallet-balance-convertable {
    flex-shrink: 0;
}

.tw-pp-pay-modal .payment-toggle .form-switch {
    flex: 0 0 auto;
    margin-bottom: 0;
    /* Drop Bootstrap's .form-switch padding-left: 2.5em — it leaves empty
       space after the wallet toggle. Flex lays out input + label instead. */
    padding-left: 0;
    padding-inline-start: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tw-pp-pay-modal .payment-toggle .form-switch .form-check-input {
    float: none;
    margin-left: 0;
    margin-inline-start: 0;
}

.tw-pp-pay-modal .submit-btn {
    background: var(--tw-grad);
    color: var(--tw-on-primary);
    border: none;
    border-radius: 999px;
    font-weight: 800;
}

.tw-pp-modal-close {
    color: var(--tw-muted);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    background: none;
    border: none;
    font-family: inherit;
}

.tw-pp-modal-close:hover {
    color: var(--tw-primary);
}

/* Coupon field: product page summary and the quick-buy checkout. */
.tw-pp-coupon {
    display: flex;
    gap: 8px;
    position: relative;
}

.tw-pp-coupon-field {
    flex: 1;
    display: flex;
    align-items: center;
    background: var(--tw-bg-field);
    border: 1px solid var(--tw-border);
    border-radius: 11px;
    padding: 0 12px;
    transition: all .3s;
}

.tw-pp-coupon-field:focus-within {
    border-color: var(--tw-primary);
}

.tw-pp-coupon-field span {
    opacity: .5;
    font-size: 12px;
}

.tw-pp-coupon-field input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-family: inherit;
    font-size: 12px;
    color: var(--tw-text);
    padding: 9px 8px;
    min-width: 0;
}

/* Neutral like the design; the applied / invalid state shows in the note below. */
.tw-pp-coupon-btn {
    background: var(--tw-bg-card, #232326);
    color: var(--tw-text);
    font-weight: 800;
    border: 1px solid var(--tw-border-soft, #2c2c31);
    border-radius: 11px;
    padding: 0 16px;
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
    transition: border-color .3s, color .3s;
}

.tw-pp-coupon-btn:hover {
    border-color: var(--tw-primary);
    color: var(--tw-primary);
}

.tw-pp-coupon-note {
    display: flex;
    align-items: center;
    gap: 7px;
    background: var(--tw-ok-soft);
    border: 1px solid var(--tw-ok-border);
    border-radius: 10px;
    padding: 6px 11px;
    color: var(--tw-ok);
    font-size: 11px;
    font-weight: 700;
    animation: tw-dp-pop .35s ease-out;
    position: relative;
}

.tw-pp-coupon-note.d-none {
    display: none;
}

.tw-pp-coupon-note--error {
    background: var(--tw-primary-soft);
    border-color: rgba(var(--tw-brand-rgb), .35);
    color: var(--tw-primary);
}

.tw-pp-coupon-note-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.tw-pp-coupon-note-row.d-none {
    display: none;
}

.tw-pp-coupon-note-row .tw-pp-coupon-note {
    flex: 1;
    min-width: 0;
}

.tw-pp-coupon-remove {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    border: 1px solid var(--tw-border);
    background: var(--tw-bg-field);
    color: var(--tw-muted);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    transition: all .2s;
    font-family: inherit;
    padding: 0;
}

.tw-pp-coupon-remove:hover {
    border-color: var(--tw-primary);
    color: var(--tw-primary);
}

/* Order line shown above the checkout. */
.tw-pp-pay-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 14px;
    background: var(--tw-bg-inset);
    border: 1px solid var(--tw-border);
}

.tw-pp-pay-item img {
    width: 44px;
    height: 44px;
    flex: none;
    border-radius: 10px;
    object-fit: cover;
}

.tw-pp-pay-item__text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tw-pp-pay-item__name,
.tw-pp-pay-item__meta {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tw-pp-pay-item__name {
    color: var(--tw-text);
    font-size: 14px;
    font-weight: 700;
}

.tw-pp-pay-item__meta {
    color: var(--tw-muted);
    font-size: 12px;
}

.tw-pp-pay-item__price {
    flex: none;
    color: var(--tw-text);
    font-size: 15px;
    font-weight: 800;
}

/* Cart: #mainPayAndGift only flags the popup as open; it must not take a row in the cart grid. */
.settings-container #mainPayAndGift.active:has(> [data-tw-pay-modal]) {
    display: contents;
}

@media (max-width: 720px) {
    .tw-pp-pay-overlay {
        padding: 12px;
    }

    .tw-pp-pay-modal {
        padding: 18px 16px 20px;
        border-radius: 18px;
    }

    .tw-pp-pay-head {
        top: -18px;
    }
}
