/*
 * Casillas para códigos de verificación (Clave Dinámica, dispositivo nuevo, correo, teléfono).
 * Comportamiento: assets/evolution/js/colpay-otp.js. Se activa solo en los <input data-otp>.
 * Marcado que genera el script (el input original queda oculto y conserva su name y su valor):
 *   <div class="cp-otp"> .cp-otp__boxes > .cp-otp__group > input.cp-otp__box ...
 *                         .cp-otp__tools > button.cp-otp__paste     .cp-otp__status </div>
 * Botones con esquinas redondeadas (no en pastilla), igual que el resto del sitio.
 */

.cp-otp {
    --cp-otp-navy: var(--cpui-navy, #21214f);
    --cp-otp-cyan: var(--cpui-cyan, #00ade1);
    --cp-otp-border: #cfd3e1;
    --cp-otp-bg: #fff;
    --cp-otp-text: var(--cp-otp-navy);
    --cp-otp-danger: #dc3545;
    --cp-otp-danger-bg: #fff5f5;
    --cp-otp-box-w: 3.1rem;
    --cp-otp-box-h: 3.7rem;
    --cp-otp-font: 1.75rem;
    --cp-otp-gap: .5rem;
    margin: .25rem 0 .5rem;
}

/* Hasta que el script lo reemplaza (o si no carga) el input original se ve como siempre; ya reemplazado queda fuera de la vista. */
.cp-otp-source {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    opacity: 0 !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    pointer-events: none !important;
}

.cp-otp__boxes {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: .6rem .9rem;
}
.cp-otp__group {
    display: flex;
    justify-content: center;
    gap: var(--cp-otp-gap);
    flex: 0 1 auto;
    min-width: 0;
    max-width: 100%;
}

.cp-otp__box {
    box-sizing: border-box;
    /* Ancho ideal de la casilla, pero se encoge si el contenedor es angosto (p. ej. la tarjeta del ingreso en un celular pequeño). */
    flex: 0 1 var(--cp-otp-box-w);
    width: auto;
    min-width: 0;
    max-width: var(--cp-otp-box-w);
    height: var(--cp-otp-box-h);
    margin: 0;
    padding: 0;
    border: 1.5px solid var(--cp-otp-border);
    border-radius: 10px;
    background: var(--cp-otp-bg);
    color: var(--cp-otp-text);
    caret-color: var(--cp-otp-cyan);
    font-family: inherit;
    font-size: var(--cp-otp-font);
    font-weight: 800;
    line-height: 1;
    text-align: center;
    text-transform: uppercase;
    box-shadow: 0 1px 2px rgba(33, 33, 79, .06);
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
    -webkit-appearance: none;
    appearance: none;
}
.cp-otp__box:focus {
    border-color: var(--cp-otp-cyan);
    box-shadow: 0 0 0 3px rgba(0, 173, 225, .2);
}
/* Código completo: todas las casillas con el borde de acento (como en el diseño). */
.cp-otp.is-complete .cp-otp__box {
    border-color: var(--cp-otp-cyan);
}
.cp-otp.is-busy .cp-otp__box {
    cursor: progress;
}
.cp-otp.is-invalid .cp-otp__box,
.cp-otp.is-invalid .cp-otp__box:focus {
    border-color: var(--cp-otp-danger);
    background: var(--cp-otp-danger-bg);
    box-shadow: 0 0 0 3px rgba(220, 53, 69, .14);
}
.cp-otp.is-shaking .cp-otp__boxes {
    animation: cp-otp-shake .38s ease-in-out;
}
@keyframes cp-otp-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-7px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(3px); }
}

/* Códigos largos (10 caracteres del correo): dos bloques de 5, que pasan a dos filas cuando no caben. */
.cp-otp--long {
    --cp-otp-box-w: 2.55rem;
    --cp-otp-box-h: 3.1rem;
    --cp-otp-font: 1.4rem;
    --cp-otp-gap: .35rem;
}
.cp-otp--long .cp-otp__group {
    flex: 1 1 13.5rem;
    max-width: 100%;
}
.cp-otp--long .cp-otp__box {
    flex: 0 1 var(--cp-otp-box-w);
    max-width: var(--cp-otp-box-w);
}

/* ------------------------------------------------------------------ acciones y estado */
.cp-otp__tools {
    display: flex;
    justify-content: center;
    margin-top: .6rem;
}
.cp-otp__paste {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .3rem .6rem;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--cp-otp-navy);
    font: inherit;
    font-size: .95rem;
    font-weight: 700;
    cursor: pointer;
}
.cp-otp__paste:hover,
.cp-otp__paste:focus-visible {
    background: rgba(0, 173, 225, .1);
    outline: none;
}
.cp-otp__paste svg {
    width: 1.1rem;
    height: 1.1rem;
    flex: 0 0 auto;
}
.cp-otp__paste[hidden] {
    display: none;
}

.cp-otp__status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .55rem;
    margin-top: .65rem;
    padding: .55rem .8rem;
    border-radius: 10px;
    background: #e8f9fd;
    color: #0b6b80;
    font-size: .85rem;
    line-height: 1.3;
    text-align: left;
}
.cp-otp__status[hidden] {
    display: none;
}
.cp-otp__status svg {
    width: 1.05rem;
    height: 1.05rem;
    flex: 0 0 auto;
    color: var(--cp-otp-cyan);
}
.cp-otp__status strong {
    display: block;
    color: var(--cp-otp-navy);
    font-size: .98rem;
}
.cp-otp__status small {
    display: block;
    color: #5b6280;
    font-size: .82rem;
}
.cp-otp.is-busy .cp-otp__status {
    background: transparent;
    padding-left: 0;
    padding-right: 0;
    justify-content: center;
}
.cp-otp__spinner {
    flex: 0 0 auto;
    width: 1.5rem;
    height: 1.5rem;
    border: 3px solid rgba(0, 173, 225, .25);
    border-top-color: var(--cp-otp-cyan);
    border-radius: 50%;
    animation: cp-otp-spin .8s linear infinite;
}
@keyframes cp-otp-spin {
    to { transform: rotate(360deg); }
}

/* En los formularios que se envían solos, el botón de enviar sobra (queda en el HTML por si el script no carga). */
.cp-otp-auto [data-otp-submit] {
    display: none !important;
}

@media (max-width: 400px) {
    .cp-otp {
        --cp-otp-box-w: 2.7rem;
        --cp-otp-box-h: 3.3rem;
        --cp-otp-font: 1.55rem;
        --cp-otp-gap: .4rem;
    }
    .cp-otp--long {
        --cp-otp-box-w: 2.4rem;
        --cp-otp-box-h: 3rem;
        --cp-otp-font: 1.3rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cp-otp__box { transition: none; }
    .cp-otp.is-shaking .cp-otp__boxes { animation: none; }
    .cp-otp__spinner { animation-duration: 2s; }
}
