/**
 * XPayr Gateway - Checkout Page Styles
 * Modern, minimal design inspired by Stripe/BitPay
 * Dark/Light theme support with CSS variables
 */

/* =================================================================
   CSS VARIABLES - THEMING
   ================================================================= */
:root {
    /* Light Theme (Default) */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-card: rgba(255, 255, 255, 0.95);
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: rgba(0, 0, 0, 0.08);
    --accent-primary: #029bfd;
    --merchant-brand-color: #029bfd;
    --accent-hover: #0287db;
    --accent-glow: rgba(2, 155, 253, 0.3);
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.12);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --transition: all 0.2s ease;
}

[data-theme="dark"] {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: rgba(18, 18, 26, 0.95);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: rgba(255, 255, 255, 0.08);
    --accent-primary: #029bfd;
    --merchant-brand-color: #029bfd;
    --accent-hover: #17a7ff;
    --accent-glow: rgba(2, 155, 253, 0.45);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.4);
}

/* =================================================================
   BASE STYLES
   ================================================================= */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body.checkout-page {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    transition: var(--transition);
}

body.checkout-page.checkout-embed {
    min-height: auto;
    padding: 0;
    justify-content: flex-start;
    background: transparent;
}

/* =================================================================
   CHECKOUT CONTAINER
   ================================================================= */
.checkout-container {
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
}

body.checkout-page.checkout-embed .checkout-container {
    max-width: 100%;
}

body.checkout-page.checkout-embed .checkout-card {
    border-radius: 12px;
    box-shadow: none;
    border: 1px solid var(--border-color);
}

/* =================================================================
   THEME TOGGLE
   ================================================================= */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--text-primary);
    transition: var(--transition);
    z-index: 100;
}

.theme-toggle:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-md);
}

.theme-toggle .icon-sun {
    display: none;
}

.theme-toggle .icon-moon {
    display: block;
}

[data-theme="dark"] .theme-toggle .icon-sun {
    display: block;
}

[data-theme="dark"] .theme-toggle .icon-moon {
    display: none;
}

/* =================================================================
   CHECKOUT CARD
   ================================================================= */
.checkout-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    backdrop-filter: blur(10px);
}

/* Header */
.checkout-header {
    padding: 24px 24px 20px;
    border-bottom: 1px solid var(--border-color);
    text-align: center;
}

.checkout-merchant-brand-card {
    display: block;
    margin-bottom: 14px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 10px 12px;
    background: color-mix(in oklab, var(--merchant-brand-color) 8%, var(--bg-primary));
}

.checkout-merchant-brand-logo-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    margin-bottom: 8px;
}

.checkout-merchant-brand-logo {
    width: auto;
    height: 30px;
    max-width: 180px;
    object-fit: contain;
    display: block;
}

.checkout-merchant-brand-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
    width: 100%;
}

.checkout-merchant-brand-name {
    font-size: 14px;
    line-height: 1.15;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.01em;
    text-align: left;
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.checkout-merchant-brand-support {
    display: inline-block;
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 58%;
    margin-left: auto;
    padding: 0;
    text-align: right;
}

.merchant-logo {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    margin-bottom: 12px;
}

.merchant-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.checkout-amount {
    font-size: 36px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.checkout-currency {
    font-size: 20px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-left: 6px;
}

/* Network Badge */
.network-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    padding: 6px 12px;
    background: var(--bg-primary);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.network-badge svg {
    width: 16px;
    height: 16px;
}

.network-badge.testnet {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
}

.sandbox-label {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background: var(--warning);
    color: #000;
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    padding: 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Body */
.checkout-body {
    padding: 24px;
}

/* Session Info */
.session-info {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.session-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
}

.session-label {
    color: var(--text-muted);
}

.session-value {
    color: var(--text-primary);
    font-weight: 500;
}

/* Expiry Timer */
.expiry-timer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.expiry-timer i {
    color: var(--warning);
}

.expiry-timer.expired {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
}

/* Status Feedback */
.status-feedback {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 14px;
    text-align: center;
    margin-bottom: 20px;
    transition: var(--transition);
}

.status-feedback.info {
    background: rgba(99, 102, 241, 0.1);
    color: var(--accent-primary);
}

.status-feedback.success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.status-feedback.error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
}

.status-feedback.hidden {
    display: none;
}

/* Pay Button */
.pay-button {
    width: 100%;
    padding: 16px 24px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--merchant-brand-color);
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.pay-button:hover:not(:disabled) {
    background: color-mix(in oklab, var(--merchant-brand-color) 88%, #000000);
    box-shadow: 0 0 20px var(--accent-glow);
    transform: translateY(-1px);
}

.pay-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pay-button .spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Footer */
.checkout-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.powered-by {
    font-size: 12px;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.powered-by-logo-link {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}

.powered-by-logo {
    height: 20px;
    width: auto;
    display: block;
}

.powered-by-logo-dark {
    display: none;
}

[data-theme="dark"] .powered-by-logo-light {
    display: none;
}

[data-theme="dark"] .powered-by-logo-dark {
    display: block;
}

/* Legal Links */
.legal-links {
    margin-top: 20px;
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
}

.legal-links a {
    color: var(--text-secondary);
    text-decoration: none;
    margin: 0 8px;
}

.legal-links a:hover {
    color: var(--merchant-brand-color);
}

/* =================================================================
   WALLET SELECTOR MODAL
   ================================================================= */
.wallet-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.wallet-modal-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.wallet-modal {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 360px;
    max-height: 80vh;
    overflow: hidden;
    transform: scale(0.95);
    transition: var(--transition);
}

.wallet-modal-overlay.visible .wallet-modal {
    transform: scale(1);
}

.wallet-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.wallet-modal-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.wallet-modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.wallet-modal-close:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.wallet-list {
    padding: 12px;
    max-height: 320px;
    overflow-y: auto;
}

.wallet-button {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 8px;
}

.wallet-button:hover {
    border-color: var(--accent-primary);
    background: rgba(2, 155, 253, 0.08);
}

.checkout-complete-card {
    margin-top: 12px;
    padding: 18px 16px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(16, 185, 129, 0.35);
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.14), rgba(2, 155, 253, 0.10));
    text-align: center;
}

.checkout-complete-head {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-weight: 700;
    color: var(--success);
    margin-bottom: 8px;
}

.checkout-complete-text {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.checkout-complete-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

.checkout-complete-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    background: var(--bg-secondary);
    font-size: 12px;
    text-decoration: none;
}

.checkout-complete-link:hover {
    border-color: var(--accent-primary);
}

.wallet-button img {
    width: 32px;
    height: 32px;
    border-radius: 8px;
}

.wallet-button .wallet-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

/* =================================================================
   ERROR STATES
   ================================================================= */
.error-container {
    text-align: center;
    padding: 40px 24px;
}

.error-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.error-icon.expired {
    color: var(--warning);
}

.error-icon.not-found {
    color: var(--error);
}

.error-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.error-message {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.error-cta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    transition: var(--transition);
}

.error-cta:hover {
    background: var(--bg-primary);
    border-color: var(--accent-primary);
}

/* =================================================================
   RESPONSIVE
   ================================================================= */
@media (max-width: 480px) {
    body.checkout-page {
        padding: 10px;
    }

    .checkout-container {
        max-width: 100%;
    }

    .checkout-amount {
        font-size: 32px;
    }

    .checkout-merchant-brand-meta {
        flex-wrap: wrap;
    }

    .checkout-merchant-brand-support {
        max-width: 100%;
        margin-left: 0;
    }

    .theme-toggle {
        top: 10px;
        right: 10px;
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
}
