/**
 * Cray OTP Login - Frontend Styles
 *
 * WCAG 2.1 AA compliant styles for the OTP login form.
 * Compatible with default WordPress and WooCommerce themes.
 *
 * Color contrast ratios:
 * - Text #1a1a2e on white: ~15:1
 * - Error #c0392b on white: ~5.6:1
 * - Success #1e7e34 on white: ~5.3:1
 * - Links #2271b1 on white: ~5.5:1 (WordPress standard)
 * - Borders #8c8f94 on white: ~3.5:1 (WordPress standard)
 * - Disabled text #6c7781 on #f0f0f1: ~4.6:1
 */

/* ==========================================================================
   Tabs Navigation
   ========================================================================== */

.cray-otp-tab-wrapper {
    text-align: center;
    margin: 0 auto 0;
    max-width: 320px;
}

.cray-otp-tab-title {
    margin: 0 0 0.75rem;
    font-size: 0.875rem;
    font-weight: 700;
    color: #50575e;
    text-align: center;
}

.cray-otp-tabs {
    display: flex;
    margin: 0;
    padding: 0;
    border-bottom: 2px solid #dcdcde;
    gap: 0;
}

.cray-otp-tab-btn {
    flex: 1;
    padding: 0.75rem 1rem;
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.4;
    text-align: center;
    cursor: pointer;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    color: #50575e;
    transition: color 0.15s ease, border-color 0.15s ease;
    min-height: 44px;
}

.cray-otp-tab-btn:hover {
    color: #1a1a2e;
}

.cray-otp-tab-btn--active {
    color: #2271b1;
    border-bottom-color: #2271b1;
}

.cray-otp-tab-btn:focus-visible {
    outline: 2px solid #2271b1;
    outline-offset: -2px;
    border-radius: 2px 2px 0 0;
}

/* Tab content panels */
.cray-otp-tab-content {
    padding: 0;
}

/* Hide the marker div the PHP outputs */
.cray-otp-tab-end {
    display: none;
}

/* Keep "Lost your password?" styled normally inside the password tab */
#cray-otp-tab-password #nav {
    display: block;
    margin: 0.75rem 0 0;
    padding: 0;
    text-align: left;
}

/* Force the submit row to have Remember Me left, Log In button right */
#cray-otp-tab-password .submit {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0;
}

#cray-otp-tab-password .forgetmenot {
    margin: 0;
}

#cray-otp-tab-password .submit #wp-submit {
    margin-left: auto;
}

/* ==========================================================================
   Separator (kept for WooCommerce)
   ========================================================================== */

.cray-otp-separator {
    display: flex;
    align-items: center;
    margin: 1.5rem 0;
    text-align: center;
}

.cray-otp-separator::before,
.cray-otp-separator::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid #8c8f94;
}

.cray-otp-separator span {
    padding: 0 0.75rem;
    font-size: 14px;
    color: #50575e;
    white-space: nowrap;
}

/* ==========================================================================
   Form Container
   ========================================================================== */

.cray-otp-login-form {
    margin: 0;
    padding: 0;
}

.cray-otp-step {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* ==========================================================================
   Labels
   ========================================================================== */

.cray-otp-login-form label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: #1a1a2e;
    margin-bottom: 0.25rem;
}

/* ==========================================================================
   Input Fields
   ========================================================================== */

.cray-otp-login-form .input,
.cray-otp-login-form .input-text {
    width: 100%;
    min-height: 44px;
    padding: 0.5rem 0.75rem;
    font-size: 14px;
    line-height: 1.5;
    color: #1a1a2e;
    background-color: #fff;
    border: 1px solid #8c8f94;
    border-radius: 4px;
    box-sizing: border-box;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.cray-otp-login-form .input:focus,
.cray-otp-login-form .input-text:focus {
    border-color: #2271b1;
    box-shadow: 0 0 0 1px #2271b1;
    outline: 2px solid #2271b1;
    outline-offset: 0;
}

.cray-otp-login-form .input::placeholder,
.cray-otp-login-form .input-text::placeholder {
    color: #6c7781;
    opacity: 1;
    font-size: 14px;
}

/* ==========================================================================
   Buttons - Primary (Send Code, Verify Code)
   ========================================================================== */

.cray-otp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 44px;
    padding: 0.625rem 1rem;
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.5;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    border-radius: 4px;
    border: 1px solid transparent;
    box-sizing: border-box;
    transition: background-color 0.15s ease-in-out,
                border-color 0.15s ease-in-out,
                box-shadow 0.15s ease-in-out;
}

.cray-otp-btn:focus-visible {
    outline: 2px solid #2271b1;
    outline-offset: 2px;
}

.cray-otp-login-form .button-primary.cray-otp-btn,
.cray-otp-login-form .woocommerce-button.cray-otp-btn:not(.cray-otp-resend-btn) {
    background-color: #2271b1;
    border-color: #2271b1;
    color: #fff;
}

.cray-otp-login-form .button-primary.cray-otp-btn:hover,
.cray-otp-login-form .woocommerce-button.cray-otp-btn:not(.cray-otp-resend-btn):hover {
    background-color: #135e96;
    border-color: #135e96;
    color: #fff;
}

.cray-otp-login-form .button-primary.cray-otp-btn:focus-visible,
.cray-otp-login-form .woocommerce-button.cray-otp-btn:not(.cray-otp-resend-btn):focus-visible {
    background-color: #135e96;
    border-color: #135e96;
    outline: 2px solid #2271b1;
    outline-offset: 2px;
}

/* ==========================================================================
   Resend Button - Secondary Style
   ========================================================================== */

.cray-otp-resend-btn {
    background-color: #f0f0f1;
    border-color: #8c8f94;
    color: #1a1a2e;
    margin-top: 0.25rem;
}

.cray-otp-resend-btn:hover:not(:disabled) {
    background-color: #dcdcde;
    border-color: #50575e;
    color: #1a1a2e;
}

.cray-otp-resend-btn:focus-visible {
    outline: 2px solid #2271b1;
    outline-offset: 2px;
}

.cray-otp-resend-btn:disabled {
    background-color: #f0f0f1;
    border-color: #dcdcde;
    color: #6c7781;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Disabled state uses text to complement the visual change */
.cray-otp-resend-btn:disabled::after {
    content: '';
}

/* ==========================================================================
   OTP Remember Me
   ========================================================================== */

.cray-otp-remember {
    margin-top: 1rem;
}

.cray-otp-remember label {
    font-weight: normal;
    font-size: 0.875rem;
    color: #50575e;
}

/* ==========================================================================
   Back Link
   ========================================================================== */

.cray-otp-back-link {
    display: inline-block;
    margin-top: 0.75rem;
    font-size: 0.875rem;
    color: #2271b1;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
    padding: 0.25rem 0;
    min-height: 44px;
    line-height: 44px;
}

.cray-otp-back-link:hover {
    color: #135e96;
    text-decoration: underline;
}

.cray-otp-back-link:focus-visible {
    outline: 2px solid #2271b1;
    outline-offset: 2px;
    border-radius: 2px;
}

/* ==========================================================================
   Error Display
   ========================================================================== */

.cray-otp-error {
    margin-top: 0.75rem;
    padding: 0;
    font-size: 0.875rem;
    color: #c0392b;
    border-radius: 4px;
    line-height: 1.5;
}

.cray-otp-error:not(:empty) {
    padding: 0.625rem 0.75rem;
    border: 1px solid #c0392b;
    border-left-width: 4px;
    background-color: #fef2f1;
}

/* Error icon prefix via pseudo-element */
.cray-otp-error:not(:empty)::before {
    content: '\26A0\00a0';
    font-size: 1rem;
}

/* ==========================================================================
   Success Message
   ========================================================================== */

.cray-otp-success {
    margin-top: 0.75rem;
    padding: 0.625rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: #1e7e34;
    border: 1px solid #1e7e34;
    border-left-width: 4px;
    border-radius: 4px;
    background-color: #f0fdf4;
    line-height: 1.5;
}

/* Success icon prefix via pseudo-element */
.cray-otp-success::before {
    content: '\2713\00a0';
    font-size: 1rem;
}

/* ==========================================================================
   Countdown Timer
   ========================================================================== */

.cray-otp-countdown {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.8125rem;
    color: #50575e;
    line-height: 1.5;
}

.cray-otp-countdown:empty {
    display: none;
}

/* ==========================================================================
   Help Text
   ========================================================================== */

.cray-otp-help {
    margin: 0.125rem 0 0.5rem;
    font-size: 14px;
    color: #50575e;
    line-height: 1.4;
}

/* ==========================================================================
   Loading State
   ========================================================================== */

.cray-otp-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

.cray-otp-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 1.25rem;
    height: 1.25rem;
    margin: -0.625rem 0 0 -0.625rem;
    border: 2px solid #8c8f94;
    border-top-color: #2271b1;
    border-radius: 50%;
    animation: cray-otp-spin 0.6s linear infinite;
}

/* Loading on buttons - inline spinner */
.cray-otp-btn.cray-otp-loading {
    color: transparent;
}

.cray-otp-btn.cray-otp-loading::after {
    position: absolute;
    width: 1rem;
    height: 1rem;
    margin: -0.5rem 0 0 -0.5rem;
}

@keyframes cray-otp-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ==========================================================================
   Step Transitions
   ========================================================================== */

.cray-otp-step {
    transition: opacity 0.2s ease-in-out;
}

.cray-otp-step[style*="display: none"],
.cray-otp-step[style*="display:none"] {
    opacity: 0;
}

/* ==========================================================================
   WooCommerce Compatibility
   ========================================================================== */

.wc-cray-otp-login-form {
    margin-top: 1.5rem;
    padding-top: 0;
}

.wc-cray-otp-login-form .cray-otp-separator {
    margin: 1rem 0 1.5rem;
}

.wc-cray-otp-login-form .cray-otp-btn {
    width: 100%;
}

.wc-cray-otp-login-form .input-text {
    width: 100%;
    min-height: 44px;
}

/* ==========================================================================
   Focus Visible - Global for all interactive elements
   ========================================================================== */

.cray-otp-login-form *:focus-visible {
    outline: 2px solid #2271b1;
    outline-offset: 2px;
}

/* Remove default focus styles when focus-visible is supported */
.cray-otp-login-form *:focus:not(:focus-visible) {
    outline: none;
}

/* ==========================================================================
   Reduced Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .cray-otp-step {
        transition: none;
    }

    .cray-otp-loading::after {
        animation-duration: 1.5s;
    }
}
