/*
 * bh_stripe — estilos del checkout (paso 4 /pedido).
 *
 * Diseño:
 *   - Desktop: payment-options compactos, botones wallet limitados a 360px.
 *   - Mobile: cada payment-option se convierte en una TARJETA clickeable
 *     ancha con padding generoso para fácil tap con el dedo. Logos
 *     anclados a la derecha con flex-shrink:0 para que NO se caigan a
 *     otra línea.
 *   - El mount del wallet button está oculto hasta que Stripe confirma
 *     soporte (ready event) — así no se ve un rectángulo blanco vacío
 *     mientras carga ni cuando el wallet no está disponible.
 */

/* ============================================================
   Variables de diseño
   ============================================================ */

:root {
    --bh-stripe-btn-max-width: 360px;
    --bh-stripe-btn-height: 48px;
    --bh-stripe-btn-radius: 8px;
    --bh-stripe-msg-max-width: 480px;
    --bh-stripe-card-border: #e5e5e5;
    --bh-stripe-card-active-border: #635bff;
    --bh-stripe-card-active-bg: #f5f4ff;
}

/* ============================================================
   Logos al lado del label de cada payment-option
   ============================================================ */

.payment-option label img[src*="modules/bh_stripe"],
.payment-options img[src*="modules/bh_stripe"] {
    max-height: 26px;
    width: auto;
    max-width: 90px;
    object-fit: contain;
    vertical-align: middle;
    margin-left: 10px;
    background: transparent;
    image-rendering: -webkit-optimize-contrast;
}

/* Logos inyectados por JS para métodos nativos PS9 (cheque, transferencia
   bancaria) — mismo tamaño que el resto para coherencia visual. */
.bh-stripe-injected-logo {
    flex-shrink: 0;
    margin-left: auto !important;
    max-height: 28px;
    max-width: 90px;
    object-fit: contain;
    background: transparent;
    image-rendering: -webkit-optimize-contrast;
}

/* ============================================================
   Textos informativos y banners
   ============================================================ */

.bh-stripe-info {
    margin: 8px 0 0;
    padding: 8px 12px;
    background: #f5f4ff;
    border-left: 3px solid #635bff;
    color: #555;
    font-size: 0.95em;
    border-radius: 2px;
    max-width: var(--bh-stripe-msg-max-width);
}

.bh-stripe-info.bh-stripe-method-apple_pay,
.bh-stripe-info.bh-stripe-method-google_pay,
.bh-stripe-info.bh-stripe-method-mb_way {
    display: none !important;
}

.additional-information:has(> .bh-stripe-method-apple_pay),
.additional-information:has(> .bh-stripe-method-google_pay),
.additional-information:has(> .bh-stripe-method-mb_way) {
    display: none !important;
}

/* Banner "pago no completado" en /pedido y /carrito */
.bh-stripe-cart-recovered {
    background: #fff8e1;
    border: 1px solid #ffd54f;
    border-left: 4px solid #f9a825;
    color: #5d4037;
    padding: 12px 16px;
    border-radius: 4px;
    margin-bottom: 20px;
}

.bh-stripe-cart-recovered strong {
    color: #e65100;
    margin-right: 6px;
}

/* Página de procesando */
.bh-stripe-processing .page-header h1 {
    color: #635bff;
    margin-bottom: 0;
}

/* ============================================================
   Mount del Express Checkout (Apple/Google Pay) + status
   ============================================================ */

.bh-stripe-wallet-mount {
    margin: 12px 0 8px;
    padding: 0;
    background: none;
    border: 0;
}

/* Contenedor del iframe de Stripe. Necesita `position: relative` para que
   el spinner del estado loading se posicione absoluto dentro de él. */
.bh-stripe-wallet-button {
    position: relative;
    max-width: var(--bh-stripe-btn-max-width);
    min-height: var(--bh-stripe-btn-height);
    border-radius: var(--bh-stripe-btn-radius);
    overflow: hidden;
}

/* ----- Estado LOADING: skeleton shimmer + spinner centrado -----
   Mientras Stripe inicializa el iframe del Express Checkout Element,
   mostramos un placeholder visual:
     - Fondo gris con animación shimmer (sutil onda de luz)
     - Spinner circular violeta en el centro
   Cuando llega el ready event y se aplica .bh-stripe-ready, el iframe
   real toma el espacio y este placeholder desaparece (background y
   ::before se anulan).
   Igualmente, si .bh-stripe-unsupported, el botón entero se oculta
   más abajo. */
.bh-stripe-wallet-mount:not(.bh-stripe-ready):not(.bh-stripe-unsupported) .bh-stripe-wallet-button {
    background: linear-gradient(90deg, #f0f0f0 0%, #fafafa 50%, #f0f0f0 100%);
    background-size: 200% 100%;
    animation: bh-stripe-shimmer 1.4s ease-in-out infinite;
    border: 1px solid #e5e5e5;
}

.bh-stripe-wallet-mount:not(.bh-stripe-ready):not(.bh-stripe-unsupported) .bh-stripe-wallet-button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    margin-top: -11px;
    margin-left: -11px;
    width: 22px;
    height: 22px;
    border: 2.5px solid rgba(99, 91, 255, 0.2);
    border-top-color: var(--bh-stripe-card-active-border);
    border-radius: 50%;
    animation: bh-stripe-spin 0.7s linear infinite;
    z-index: 2;
}

@keyframes bh-stripe-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

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

/* Wallet ready y soportado → con sombra suave + borde redondo, fondo
   transparente (el iframe de Stripe se ve dentro). */
.bh-stripe-wallet-mount.bh-stripe-ready:not(.bh-stripe-unsupported) .bh-stripe-wallet-button {
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    background: transparent;
    border: 0;
}

/* Wallet no soportado → ocultar el cuadro vacío y dejar sólo el mensaje */
.bh-stripe-wallet-mount.bh-stripe-unsupported .bh-stripe-wallet-button {
    display: none;
}

.bh-stripe-wallet-status {
    margin: 8px 0;
    font-size: 0.92em;
    color: #555;
    line-height: 1.45;
    max-width: var(--bh-stripe-msg-max-width);
}

.bh-stripe-wallet-status:empty {
    display: none;
}

/* El texto "Cargando Apple Pay…" / "Cargando Google Pay…" del status es
   redundante con el spinner + shimmer del botón. Lo ocultamos cuando NO
   es un mensaje de error ni unsupported — el feedback visual ya está
   en el botón. */
.bh-stripe-wallet-status:not(.bh-stripe-error):not(.bh-stripe-unsupported) {
    display: none;
}

.bh-stripe-wallet-status.bh-stripe-unsupported {
    background: #fff8e1;
    border-left: 3px solid #f9a825;
    padding: 10px 14px;
    color: #5d4037;
    border-radius: 4px;
    margin: 12px 0 24px;
}

.bh-stripe-wallet-status.bh-stripe-error {
    background: #ffebee;
    border-left: 3px solid #d32f2f;
    padding: 10px 14px;
    color: #b71c1c;
    border-radius: 4px;
    margin: 12px 0 24px;
}

/* ============================================================
   Botón hosted (MB Way) — estilizado como un wallet más.
   ============================================================ */

.bh-stripe-hosted-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: var(--bh-stripe-btn-max-width);
    height: var(--bh-stripe-btn-height);
    padding: 0 16px;
    border: 0;
    border-radius: var(--bh-stripe-btn-radius);
    cursor: pointer;
    font-family: inherit;
    line-height: 1;
    transition: transform 0.08s ease, box-shadow 0.15s ease, filter 0.15s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.bh-stripe-hosted-btn:hover {
    filter: brightness(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
}

.bh-stripe-hosted-btn:active {
    transform: translateY(0);
    filter: brightness(0.95);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.bh-stripe-hosted-btn:focus-visible {
    outline: 2px solid rgba(99, 91, 255, 0.5);
    outline-offset: 2px;
}

.bh-stripe-hosted-btn-label {
    pointer-events: none;
    user-select: none;
    color: #fff;
    font-weight: 800;
    font-size: 15px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

.bh-stripe-hosted-btn-logo {
    pointer-events: none;
    user-select: none;
    max-height: 36px;
    width: auto;
    max-width: 140px;
    display: block;
    background: transparent;
    object-fit: contain;
}

/* MB Way — fondo blanco con borde fino. Hover suave con tinte rojo. */
.bh-stripe-hosted-btn-mb_way {
    background: #ffffff;
    border: 1px solid #e8e5e0;
}

.bh-stripe-hosted-btn-mb_way:hover {
    background: #fffafa;
    border-color: #f0c8c8;
    filter: none;
    box-shadow: 0 4px 12px rgba(230, 0, 57, 0.18);
}

.bh-stripe-hosted-btn-mb_way .bh-stripe-hosted-btn-logo {
    max-height: 38px;
    max-width: 180px;
}

/* ============================================================
   Animación shake para T&C
   ============================================================ */

@keyframes bh-stripe-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

.bh-stripe-shake {
    animation: bh-stripe-shake 0.35s ease-in-out 0s 3;
    background: #fff8e1;
    border-radius: 4px;
}

/* ============================================================
   ─── PAYMENT-OPTIONS COMO TARJETAS (todos los breakpoints) ───
   Cada .payment-option se renderiza como una tarjeta clickeable
   con padding generoso para fácil tap (móvil) o look limpio
   (desktop). En desktop/tablet limitamos el ancho a 600px para
   que no quede un banner gigante. En móvil llena el ancho.
   Texto siempre alineado a la IZQUIERDA, logos anclados a la
   derecha con flex-shrink:0 para que no se caigan de línea.
   ============================================================ */

.payment-options .payment-option {
    display: flex !important;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    margin: 10px 0;
    max-width: 600px;
    background: #fff;
    border: 1.5px solid var(--bh-stripe-card-border);
    border-radius: 12px;
    transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
    cursor: pointer;
    min-height: 64px;
}

.payment-options .payment-option:hover {
    border-color: #b3b3b3;
    background: #fafafa;
}

/* Estado seleccionado: borde violeta resaltado + fondo sutil + sombra */
.payment-options .payment-option:has(input[type="radio"]:checked) {
    border-color: var(--bh-stripe-card-active-border);
    background: var(--bh-stripe-card-active-bg);
    box-shadow: 0 2px 8px rgba(99, 91, 255, 0.15);
}

/* Radio button agrandado para fácil tap (22px en lugar del ~14px del
   default del browser). accent-color para que el círculo relleno
   coincida con el borde violeta de la tarjeta seleccionada. */
.payment-options .payment-option input[type="radio"] {
    width: 22px;
    height: 22px;
    min-width: 22px;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: var(--bh-stripe-card-active-border);
    margin: 0;
}

/* Label: flex container con texto a la IZQUIERDA + logos a la DERECHA.
   `justify-content: flex-start` y `text-align: left` forzados para
   evitar que el theme ceramica_brivahome (Codezeel) los centre. */
.payment-options .payment-option label {
    flex: 1;
    min-width: 0;
    margin: 0 !important;
    padding: 0;
    display: flex !important;
    align-items: center;
    justify-content: flex-start !important;
    text-align: left !important;
    gap: 10px;
    cursor: pointer;
    font-size: 15px;
    line-height: 1.35;
    font-weight: 500;
}

/* Logos dentro del label: anclados a la derecha (margin-left: auto)
   y NUNCA comprimidos / saltan de línea (flex-shrink: 0). */
.payment-options .payment-option label img {
    flex-shrink: 0;
    margin-left: auto !important;
    max-height: 28px;
    max-width: 90px;
}

/* El form wrapper con setForm content se renderiza como sibling de
   .payment-option. Cuando el radio está checked, PS9 lo despliega.
   Lo alineamos al mismo max-width que las tarjetas para visual
   consistency. */
.payment-options [id^="pay-with-"][id$="-form"] {
    max-width: 600px;
    padding: 0 16px;
    margin-top: -4px;
    margin-bottom: 12px;
}

/* additional-information (texto bajo cada radio) — lo ocultamos en
   TODOS los breakpoints para reducir ruido visual. El botón embedded
   identifica el método de sobra. */
.payment-options .additional-information {
    display: none !important;
}

/* ============================================================
   MÓVIL (≤575px): tarjetas llenan el ancho disponible, botones
   wallet/hosted full width, altura tap target mayor.
   ============================================================ */

@media (max-width: 575px) {
    .payment-options .payment-option,
    .payment-options [id^="pay-with-"][id$="-form"] {
        max-width: 100%;
    }

    .bh-stripe-wallet-button,
    .bh-stripe-hosted-btn {
        max-width: 100%;
    }

    .bh-stripe-wallet-status,
    .bh-stripe-info {
        max-width: 100%;
    }

    .bh-stripe-hosted-btn {
        height: 52px;
    }

    .bh-stripe-wallet-button {
        min-height: 52px;
    }
}
