﻿/**
 * Saga Payments - Checkout Styles
 * Clean, modern fintech design with light theme
 */

/* ========================================
   Container & Base Styles
   ======================================== */

.saga-payments-container {
    padding: 20px 0;
    font-family: inherit;
}

/* ========================================
   Apple Pay & Google Pay Button Styles
   ======================================== */

/* ============================================
   WALLET BUTTON CONTAINER (Place Order area)
   ============================================ */

#saga-wallet-button-container {
    width: 100% !important;
    min-height: 48px !important;
}

#saga-wallet-button-container #saga-applepay-widget,
#saga-wallet-button-container #saga-googlepay-widget {
    display: block !important;
    width: 100% !important;
    min-height: 48px !important;
}

/* ============================================
   APPLE PAY BUTTON
   Reference: #sdk-applepay-button from integration guide
   ============================================ */

#saga-applepay-widget {
    width: 100%;
    height: 48px;
    overflow: hidden;
    position: relative;
    border-radius: 8px;
    contain: paint;
    isolation: isolate;
}

/* Force all SDK-generated children to fill the container */
#saga-applepay-widget > *,
#saga-applepay-widget > * > * {
    width: 100% !important;
    max-width: 100% !important;
    height: 48px !important;
    max-height: 48px !important;
    overflow: hidden !important;
    border-radius: 8px !important;
}

/* Apple Pay Web Component CSS properties */
apple-pay-button,
#saga-applepay-widget apple-pay-button {
    --apple-pay-button-width: 100%;
    --apple-pay-button-height: 48px;
    --apple-pay-button-border-radius: 8px;
    display: block !important;
    width: 100% !important;
    height: 48px !important;
    min-height: 48px !important;
    cursor: pointer !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Apple Pay iframe inside button */
#saga-applepay-widget iframe {
    width: 100% !important;
    height: 48px !important;
    border: none !important;
}

/* ============================================
   GOOGLE PAY BUTTON
   Reference: #sdk-googlepay-button from integration guide
   ============================================ */

#saga-googlepay-widget {
    width: 100%;
    height: 48px;
    overflow: hidden;
    position: relative;
    border-radius: 8px;
    contain: paint;
    isolation: isolate;
}

/* Force all SDK-generated children to fill the container */
#saga-googlepay-widget > *,
#saga-googlepay-widget > * > * {
    width: 100% !important;
    max-width: 100% !important;
    height: 48px !important;
    max-height: 48px !important;
    overflow: hidden !important;
    border-radius: 8px !important;
}

#saga-googlepay-widget button,
#saga-googlepay-widget .gpay-button {
    width: 100% !important;
    min-height: 48px !important;
    border-radius: 8px !important;
}

/* Google Pay popup/overlay */
body > div[id*="gpay"],
body > div[class*="gpay"],
body > iframe[src*="pay.google.com"] {
    z-index: 999999 !important;
}

/* Error Container */
#saga-error-container {
    display: none;
}

.saga-error {
    background: #fef2f2 !important;
    border: 1px solid #fecaca !important;
    border-left-width: 4px !important;
    border-left-color: #ef4444 !important;
    color: #991b1b !important;
    padding: 12px 16px;
    margin-bottom: 16px;
    border-radius: 8px;
    font-size: 14px;
}

/* ========================================
   Loading State
   ======================================== */

.saga-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 20px;
    color: #6b7280;
    font-size: 14px;
}

.saga-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: saga-spin 0.8s linear infinite;
}

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

/* ========================================
   Payment Method Options - Matching React Design
   ======================================== */

.saga-payment-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.saga-payment-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border: 2px solid #e5e7eb !important;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #ffffff !important;
    color: #1f2937 !important;
}

.saga-payment-option:hover {
    border-color: #d1d5db !important;
}

.saga-payment-option.active {
    border-color: #a855f7 !important;
    background: #faf5ff !important;
}

.saga-payment-option input[type="radio"] {
    margin: 0;
    margin-right: 12px;
    width: 20px;
    height: 20px;
    accent-color: #a855f7;
    cursor: pointer;
    flex-shrink: 0;
}

.saga-option-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 1;
    min-width: 0;
}

.saga-option-label {
    font-weight: 500;
    font-size: 14px;
    color: #1f2937 !important;
}

.saga-option-logos {
    display: flex;
    gap: 4px;
    align-items: center;
}

.saga-logo {
    height: 20px;
    width: auto;
    max-width: 36px;
    object-fit: contain;
}

/* ========================================
   Widget Containers - Matching React Design
   ======================================== */

.saga-widget-container {
    margin-top: 12px;
    border-radius: 8px;
    overflow: hidden !important;
    background: #ffffff !important;
    border: 1px solid #e5e7eb !important;
    padding: 16px;
    box-sizing: border-box !important;
    width: 100% !important;
}

#saga-card-widget-container {
    width: 100%;
    box-sizing: border-box;
    padding: 16px 20px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-top: none;
    border-radius: 0 0 12px 12px;
    margin-top: -9px;
    margin-bottom: 8px;
    transition: max-height 0.3s ease, opacity 0.2s ease, padding 0.3s ease;
    overflow: hidden;
    contain: paint;
    position: relative;
}

#saga-card-widget-container.saga-card-visible {
    display: block;
    max-height: 600px;
    opacity: 1;
}

#saga-card-widget-container.saga-card-hidden {
    display: none;
    max-height: 0;
    opacity: 0;
    padding: 0;
}

#saga-card-widget {
    overflow: hidden;
    contain: paint;
    position: relative;
}

#saga-card-widget iframe {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    transform: none !important;
    max-width: 100% !important;
    z-index: auto !important;
}

/* WooCommerce payment box */
.payment_method_saga_payments .payment_box {
    width: 100% !important;
    box-sizing: border-box !important;
    padding: 16px !important;
}

#payment .payment_methods .payment_method_saga_payments {
    width: 100% !important;
}

/* Wallet widget containers - SDK renders buttons inside these */
#saga-applepay-widget,
#saga-googlepay-widget {
    min-height: 48px;
    width: 100%;
    contain: paint;
    overflow: hidden;
    position: relative;
    isolation: isolate;
}

/* Wallet widget buttons - contain SDK-generated iframes */
#saga-applepay-widget iframe,
#saga-googlepay-widget iframe {
    position: relative !important;
    max-width: 100% !important;
    border: none !important;
}

/* ========================================
   Payment Method Info Boxes - Matching React Design
   ======================================== */

#saga-redirect-info {
    display: none;
    padding: 16px;
    background: #f0fdf4 !important;
    border: 1px solid #bbf7d0 !important;
    border-radius: 8px;
    margin-top: 12px;
    text-align: left;
}

#saga-redirect-info p {
    margin: 0;
    color: #166534 !important;
    font-size: 14px;
}

/* Payment method info boxes */
#saga-pay-info {
    display: none;
    padding: 16px;
    border-radius: 8px;
    margin-top: 16px;
    text-align: center;
}

#saga-pay-info p {
    margin: 0;
    font-size: 14px;
}

/* Apple Pay info */
#saga-pay-info.applepay-info,
.saga-pay-info-applepay {
    background: #f9fafb !important;
    border: 1px solid #e5e7eb !important;
    color: #374151 !important;
}

/* Google Pay info */
#saga-pay-info.googlepay-info,
.saga-pay-info-googlepay {
    background: #f9fafb !important;
    border: 1px solid #e5e7eb !important;
    color: #374151 !important;
}

/* Klarna info */
#saga-pay-info.klarna-info,
.saga-pay-info-klarna {
    background: #fdf2f8 !important;
    border: 1px solid #fbcfe8 !important;
    color: #9d174d !important;
}

/* Vipps info */
#saga-pay-info.vipps-info,
.saga-pay-info-vipps {
    background: #fff7ed !important;
    border: 1px solid #fed7aa !important;
    color: #9a3412 !important;
}

/* Secure badge - matching React design */
.saga-secure-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    font-size: 12px;
    color: #6b7280 !important;
}

.saga-secure-badge svg {
    color: #22c55e;
    flex-shrink: 0;
}

.saga-secure-badge strong {
    color: #374151;
}

/* ========================================
   Processing State
   ======================================== */

.saga-processing {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

.saga-processing::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 3px solid #e5e7eb;
    border-top-color: #a855f7;
    border-radius: 50%;
    animation: saga-spin 0.8s linear infinite;
}

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

#saga_payment_method { display: none; }

.saga-test-mode-notice {
    background: #fef3c7 !important;
    border: 1px solid #fcd34d !important;
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 16px;
    font-size: 13px;
    color: #92400e !important;
    font-weight: 500;
}

/* ========================================
   Card Widget Wrapper — expand/collapse for Blocks
   ======================================== */

.saga-card-widget-wrapper {
    overflow: hidden;
    contain: paint;
    position: relative;
    width: 100% !important;
    transition: max-height 0.3s ease, opacity 0.2s ease;
}

.saga-card-widget-wrapper.expanded {
    max-height: 500px !important;
    opacity: 1 !important;
    padding: 0 !important;
}

.saga-card-widget-wrapper.collapsed {
    max-height: 0 !important;
    opacity: 0 !important;
    padding: 0 !important;
    pointer-events: none !important;
}

.saga-card-widget-wrapper.collapsed #saga-card-widget {
    visibility: hidden !important;
}

/* ========================================
   WooCommerce Blocks Styles
   ======================================== */

.saga-block-container {
    padding: 0;
}

.saga-block-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.saga-block-option {
    display: flex;
    flex-direction: column !important;
    padding: 0 !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #ffffff !important;
    color: #1f2937 !important;
    overflow: hidden;
}

.saga-block-option:hover {
    border-color: #c7d2e0 !important;
}

.saga-block-option.active {
    border-color: #a855f7 !important;
    background: #ffffff !important;
}

.saga-block-option input[type="radio"] {
    margin: 0;
    margin-right: 12px;
    width: 20px;
    height: 20px;
    accent-color: #a855f7;
    flex-shrink: 0;
}

.saga-block-option-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 1;
    min-width: 0;
}

.saga-block-option-label {
    font-weight: 500;
    font-size: 14px;
    color: #1f2937 !important;
}

.saga-block-logos {
    display: flex;
    gap: 4px;
    align-items: center;
}

.saga-block-logo {
    height: 20px;
    width: auto;
    max-width: 36px;
    object-fit: contain;
}

/* Removed - not used */

.saga-block-secure-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    font-size: 12px;
    color: #6b7280 !important;
}

.saga-block-secure-badge svg {
    color: #22c55e;
}

/* Payment method info boxes for Blocks - matching React */
.saga-block-pay-info {
    margin-top: 12px;
    padding: 16px;
    border-radius: 8px;
    font-size: 14px;
}

.saga-block-pay-info.applepay-info,
.saga-block-pay-info.googlepay-info {
    background: #f9fafb !important;
    border: 1px solid #e5e7eb !important;
    color: #374151 !important;
}

.saga-block-pay-info.klarna-info {
    background: #fdf2f8 !important;
    border: 1px solid #fbcfe8 !important;
    color: #9d174d !important;
}

.saga-block-pay-info.vipps-info {
    background: #fff7ed !important;
    border: 1px solid #fed7aa !important;
    color: #9a3412 !important;
}

.saga-block-processing {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255, 255, 255, 0.95) !important;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 100;
    border-radius: 8px;
}

.saga-block-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #e5e7eb;
    border-top-color: #a855f7;
    border-radius: 50%;
    animation: saga-spin 0.8s linear infinite;
}

/* Blocks card widget */
.saga-card-widget,
#saga-card-widget {
    overflow: hidden;
    contain: paint;
    position: relative;
}

.saga-card-widget iframe,
#saga-card-widget iframe {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    transform: none !important;
    max-width: 100% !important;
    z-index: auto !important;
}

/* Processing overlay for blocks - z-index BELOW 3DS overlays */
.saga-processing-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95) !important;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 9998; /* Below 3DS popups (9999999) */
}

/* 3DS, Vipps, Klarna and other payment popups/iframes must appear ABOVE overlay */
/* Reference: Section 7 from integration guide */
[id*="3ds"], [id*="3DS"],
[class*="3ds"], [class*="3DS"],
iframe[src*="3ds"],
iframe[src*="3DS"],
iframe[src*="acs"],
iframe[src*="ACS"],
iframe[src*="secure"],
iframe[src*="authenticate"],
iframe[src*="authentication"],
iframe[src*="threedsecure"],
iframe[src*="visa"],
iframe[src*="mastercard"],
iframe[src*="surfboard"],
iframe[src*="surfgw"],
iframe[src*="thorium"],
div[data-surfboard-3ds],
.surfboard-3ds-frame,
.surfboard-3ds-overlay,
.surfboard-3ds-container,
.surfboard-modal,
.saga-3ds-container,
[id*="Cardinal"], [class*="Cardinal"],
iframe[name*="3ds"],
iframe[id*="challenge"] {
    z-index: 9999999 !important;
    position: fixed !important;
}

/* Payment provider modal overlays - ONLY target Saga/Surfboard ones.
 * NEVER hijack z-index on all divs - that breaks cookie popups,
 * chat widgets, mega menus, cart drawers, lightboxes etc. */
div[class*="surfboard"][style*="position: fixed"],
div[class*="saga"][style*="position: fixed"],
div[id*="surfboard"][style*="position: fixed"] {
    z-index: 9999999 !important;
}

/* 3DS challenge iframes that use position:fixed or position:absolute */
iframe[style*="position: fixed"],
iframe[style*="position:fixed"] {
    z-index: 9999999 !important;
}

/* Body-level z-index elements (Surfboard-generated) */
body > div[style*="z-index"]:not([class*="cookie"]):not([id*="cookie"]):not([class*="chat"]):not([id*="chat"]),
body > iframe[style*="z-index"] {
    z-index: 9999999 !important;
}

/* Surfboard popup/modal — center on screen */
.surfboard-popup,
.surfboard-modal,
[id*="surfboard"][id*="popup"],
[class*="surfboard"][class*="popup"] {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    min-width: 400px;
    min-height: 600px;
    z-index: 999999 !important;
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.saga-spinner-large {
    width: 48px;
    height: 48px;
    border: 4px solid #e5e7eb;
    border-top-color: #a855f7;
    border-radius: 50%;
    animation: saga-spin 0.8s linear infinite;
}

/* Spinner for loading state */
.saga-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #e5e7eb;
    border-top-color: #a855f7;
    border-radius: 50%;
    animation: saga-spin 0.8s linear infinite;
    display: inline-block;
}

/* Block loading state */
.saga-block-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 32px;
    color: #6b7280;
}

/* Block info messages */
.saga-block-info {
    margin-top: 16px;
    padding: 16px;
    border-radius: 8px;
    font-size: 14px;
    text-align: center;
}

.saga-block-info.applepay,
.saga-block-info.googlepay {
    background: #f9fafb !important;
    border: 1px solid #e5e7eb !important;
    color: #374151 !important;
}

.saga-block-info.klarna {
    background: #fdf2f8 !important;
    border: 1px solid #fbcfe8 !important;
    color: #9d174d !important;
}

.saga-block-info.vipps {
    background: #fff7ed !important;
    border: 1px solid #fed7aa !important;
    color: #9a3412 !important;
}

/* Secure badge for blocks */
.saga-secure-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    font-size: 12px;
    color: #6b7280 !important;
}

.saga-secure-badge svg {
    color: #22c55e;
    flex-shrink: 0;
}

.saga-secure-badge strong {
    color: #374151;
}

.saga-block-label { display: flex; align-items: center; gap: 12px; }
.saga-block-label-logos { display: flex; gap: 4px; align-items: center; }
.saga-block-label-logos img { height: 20px; width: auto; }

.saga-block-error {
    background: #fef2f2 !important;
    border: 1px solid #fecaca !important;
    color: #991b1b !important;
    padding: 12px 16px;
    margin-bottom: 12px;
    border-radius: 8px;
    font-size: 14px;
}

/* ========================================
   Force Light Theme Overrides
   ======================================== */

.woocommerce-checkout .saga-payments-container,
.woocommerce-checkout .saga-payment-option,
.wc-block-checkout .saga-block-container,
.wc-block-checkout .saga-block-option,
.wc-block-checkout .saga-block-widget-container {
    background-color: #ffffff !important;
    color: #1f2937 !important;
}

/* Card section uses #f9fafb, NOT white */
.woocommerce-checkout #saga-card-widget-container {
    background-color: #f9fafb !important;
    color: #1f2937 !important;
}

.saga-payments-container iframe,
.saga-block-container iframe {
    background-color: #ffffff !important;
}

/* Blocks wallet widget containment */
.saga-block-option #saga-applepay-widget,
.saga-block-option #saga-googlepay-widget {
    min-height: 48px;
    width: 100%;
    contain: paint;
    overflow: hidden;
    position: relative;
    isolation: isolate;
}

.saga-block-option #saga-applepay-widget iframe,
.saga-block-option #saga-googlepay-widget iframe {
    position: relative !important;
    max-width: 100% !important;
    border: none !important;
}

/* ========================================
   Responsive Styles
   ======================================== */

@media (max-width: 600px) {
    .saga-payment-option { padding: 14px 12px; }
    .saga-option-label { font-size: 13px; }
    .saga-logo { height: 18px; max-width: 32px; }
    .saga-block-option { padding: 14px 12px; }
    .saga-block-option-label { font-size: 13px; }
    .saga-block-logo { height: 18px; max-width: 32px; }
}

/* Mobile wallet button sizing — Reference: Section 10 from integration guide */
@media (max-width: 480px) {
    #saga-applepay-widget,
    #saga-googlepay-widget {
        height: 44px;
    }

    #saga-applepay-widget > *,
    #saga-applepay-widget > * > *,
    #saga-googlepay-widget > *,
    #saga-googlepay-widget > * > * {
        height: 44px !important;
        max-height: 44px !important;
    }

    apple-pay-button,
    #saga-applepay-widget apple-pay-button {
        --apple-pay-button-height: 44px;
    }

    #saga-card-widget {
        padding: 12px;
        border-radius: 8px;
    }
}

/* Smooth transitions */
.saga-payment-option, .saga-block-option,
#saga-card-widget-container, .saga-block-widget-container {
    transition: all 0.2s ease;
}

/* WooCommerce Integration Fixes */
#payment .payment_method_saga_payments { background: transparent !important; }
#payment .payment_method_saga_payments label { color: #1f2937 !important; }
#payment .payment_method_saga_payments .payment_box {
    background: transparent !important;
    padding: 0;
}
.payment_method_saga_payments .saga-payment-option {
    background: #ffffff !important;
}
.payment_method_saga_payments #saga-card-widget-container {
    background: #f9fafb !important;
}

/* ========================================
   Vipps/Surfboard Popup Styling
   Note: SDK popups may use inline styles that override CSS.
   These are best-effort styles for popup windows.
   ======================================== */

/* Vipps popup iframe - center on screen
   NOTE: These iframes are Surfboard popup/redirect iframes, NOT the card form.
   Card form iframes inside #saga-card-widget are overridden by the higher-
   specificity containment rules (#saga-card-widget iframe). */
iframe[src*="vipps.no"],
body > iframe[src*="surfboard"],
body > iframe[src*="surfgw.com"],
body > iframe[src*="withsurfboard"] {
    width: 520px !important;
    min-width: 420px !important;
    min-height: 500px !important;
    max-width: 95vw !important;
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    z-index: 9999999 !important;
    border-radius: 12px !important;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.3) !important;
}

/* SDK-created Vipps/payment popup container — force center */
#saga-vipps-backdrop ~ div[style*="position: fixed"],
#saga-vipps-backdrop ~ div[style*="position:fixed"],
body > div[style*="z-index"][style*="position: fixed"]:not(#saga-processing-overlay):not(#saga-cancel-overlay):not(#saga-vipps-backdrop):not(.woocommerce-error):not([id^="wpadmin"]) {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* ========================================
   Order Pay Page - Minimal styling
   Let SDK handle its own form layout
   ======================================== */

/* Target order-pay page */
body.woocommerce-order-pay #payment,
body.woocommerce-order-pay #order_review {
    max-width: 100% !important;
    width: 100% !important;
}

body.woocommerce-order-pay .payment_method_saga_payments {
    width: 100% !important;
}

body.woocommerce-order-pay .payment_method_saga_payments .payment_box {
    width: 100% !important;
    padding: 20px !important;
    box-sizing: border-box !important;
}

body.woocommerce-order-pay #saga-card-widget-container {
    width: 100% !important;
    box-sizing: border-box !important;
}

body.woocommerce-order-pay #saga-card-widget {
    width: 100% !important;
    overflow: hidden;
    contain: paint;
    position: relative;
}

body.woocommerce-order-pay #saga-card-widget iframe {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    transform: none !important;
    max-width: 100% !important;
    z-index: auto !important;
}

body.woocommerce-order-pay .saga-payment-options {
    width: 100% !important;
}

body.woocommerce-order-pay .saga-payment-option {
    width: 100% !important;
    box-sizing: border-box !important;
}

body.woocommerce-order-pay .saga-widget-container {
    width: 100% !important;
    max-width: 100% !important;
    padding: 16px !important;
    box-sizing: border-box !important;
}
