/**
 * Universal Payment Bridge (UPB) Styles
 *
 * Encapsulated styles for the payment form components.
 * Uses CSS custom properties for theme integration.
 */

/* ============================================
   CSS CUSTOM PROPERTIES (DEFAULTS)
   ============================================ */
:root {
    --upb-font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --upb-font-size: 16px;
    --upb-line-height: 1.5;

    /* Colors - Light Mode */
    --upb-text-primary: #1e293b;
    --upb-text-secondary: #64748b;
    --upb-text-muted: #94a3b8;
    --upb-bg: #ffffff;
    --upb-bg-input: #ffffff;
    --upb-border: #e2e8f0;
    --upb-border-focus: #3b82f6;
    --upb-border-error: #ef4444;
    --upb-error: #ef4444;
    --upb-success: #22c55e;
    --upb-radius: 8px;
    --upb-shadow-focus: 0 0 0 3px rgba(59, 130, 246, 0.15);
    --upb-shadow-error: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

/* Dark Mode */
.upb-dark,
[data-theme="dark"] .upb-container,
.dark .upb-container {
    --upb-text-primary: #f1f5f9;
    --upb-text-secondary: #94a3b8;
    --upb-text-muted: #64748b;
    --upb-bg: #1e293b;
    --upb-bg-input: #0f172a;
    --upb-border: #334155;
    --upb-border-focus: #60a5fa;
    --upb-shadow-focus: 0 0 0 3px rgba(96, 165, 250, 0.2);
}

/* ============================================
   CONTAINER
   ============================================ */
.upb-container {
    font-family: var(--upb-font-family);
    font-size: var(--upb-font-size);
    line-height: var(--upb-line-height);
    color: var(--upb-text-primary);
    box-sizing: border-box;
}

.upb-container *,
.upb-container *::before,
.upb-container *::after {
    box-sizing: inherit;
}

/* ============================================
   ERROR DISPLAY
   ============================================ */
.upb-error {
    display: none;
    color: var(--upb-error);
    font-size: 14px;
    margin-top: 8px;
    padding: 0;
    line-height: 1.4;
}

.upb-error:not(:empty) {
    display: block;
}

/* ============================================
   STRIPE ELEMENT OVERRIDES
   ============================================ */
.StripeElement {
    padding: 12px 14px;
    background: var(--upb-bg-input);
    border: 1px solid var(--upb-border);
    border-radius: var(--upb-radius);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.StripeElement--focus {
    border-color: var(--upb-border-focus);
    box-shadow: var(--upb-shadow-focus);
    outline: none;
}

.StripeElement--invalid {
    border-color: var(--upb-border-error);
    box-shadow: var(--upb-shadow-error);
}

.StripeElement--webkit-autofill {
    background-color: var(--upb-bg-input) !important;
}

/* ============================================
   SQUARE CARD OVERRIDES
   ============================================ */
[data-sq-form] {
    min-height: 50px;
}

/* Collapse Square's error message placeholder until it has content */
.sq-card-message:empty {
    display: none;
}

/* ============================================
   PAYPAL BUTTON CONTAINER
   ============================================ */
.upb-paypal-container {
    min-height: 45px;
}

/* PayPal buttons get their own styling, minimal overrides */
.upb-paypal-container .paypal-buttons {
    width: 100%;
}

/* ============================================
   AUTHORIZE.NET CUSTOM FORM
   ============================================ */
.upb-authnet-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.upb-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.upb-field-row {
    display: flex;
    gap: 16px;
}

.upb-field-half {
    flex: 1;
}

.upb-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--upb-text-secondary);
}

.upb-input {
    width: 100%;
    padding: 12px 14px;
    font-family: var(--upb-font-family);
    font-size: var(--upb-font-size);
    color: var(--upb-text-primary);
    background: var(--upb-bg-input);
    border: 1px solid var(--upb-border);
    border-radius: var(--upb-radius);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.upb-input::placeholder {
    color: var(--upb-text-muted);
}

.upb-input:focus {
    border-color: var(--upb-border-focus);
    box-shadow: var(--upb-shadow-focus);
}

.upb-input.upb-input-error,
.upb-input:invalid {
    border-color: var(--upb-border-error);
    box-shadow: var(--upb-shadow-error);
}

/* ============================================
   LOADING STATE
   ============================================ */
.upb-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

.upb-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 2px solid var(--upb-border);
    border-top-color: var(--upb-border-focus);
    border-radius: 50%;
    animation: upb-spin 0.8s linear infinite;
}

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

/* ============================================
   GATEWAY TABS (OPTIONAL UI COMPONENT)
   ============================================ */
.upb-gateway-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.upb-gateway-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    font-family: var(--upb-font-family);
    font-size: 14px;
    font-weight: 500;
    color: var(--upb-text-secondary);
    background: var(--upb-bg);
    border: 1px solid var(--upb-border);
    border-radius: var(--upb-radius);
    cursor: pointer;
    transition: all 0.15s ease;
}

.upb-gateway-tab:hover {
    border-color: var(--upb-text-muted);
    color: var(--upb-text-primary);
}

.upb-gateway-tab.active {
    border-color: var(--upb-border-focus);
    background: rgba(59, 130, 246, 0.05);
    color: var(--upb-border-focus);
}

.upb-gateway-tab img,
.upb-gateway-tab svg {
    width: 24px;
    height: 16px;
    object-fit: contain;
}

/* ============================================
   GATEWAY ICONS (SVG PATHS)
   ============================================ */
.upb-icon-stripe {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 28 12'%3E%3Cpath fill='%23635BFF' d='M13.3 2.5c0-.9.7-1.2 1.8-1.2 1.6 0 3.7.5 5.3 1.4V.4C18.7.1 17 0 15.1 0 12 0 10 1.6 10 4.3c0 4.2 5.8 3.5 5.8 5.3 0 1-.9 1.4-2.1 1.4-1.8 0-4.2-.7-6-1.8v2.4c2 .9 4.1 1.3 6 1.3 3.2 0 5.5-1.6 5.5-4.3 0-4.5-5.9-3.7-5.9-5.5v-.6zM5.5 5.8l-.4 2 2.9-.1-.2.9-2.9.2-.6 2.6H2L3.6 3h5.2l-.4 1.9H5.5l-.4 1.9h2.8z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

.upb-icon-square {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M21 7H3c-1.1 0-2 .9-2 2v6c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2V9c0-1.1-.9-2-2-2zm0 8H3V9h18v6z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 480px) {
    .upb-field-row {
        flex-direction: column;
        gap: 16px;
    }

    .upb-gateway-tabs {
        flex-direction: column;
    }

    .upb-gateway-tab {
        width: 100%;
        justify-content: center;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
.upb-input:focus-visible,
.upb-gateway-tab:focus-visible {
    outline: 2px solid var(--upb-border-focus);
    outline-offset: 2px;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .upb-loading::after {
        animation: none;
    }

    .upb-input,
    .upb-gateway-tab,
    .StripeElement {
        transition: none;
    }
}
