/**
 * OTP Form Frontend Styles - Material Design
 */

/* CSS Variables */
.aio-wc-otp-page {
    --otp-primary: #009688;
    --otp-primary-hover: #00796b;
    --otp-text: #333333;
    --otp-text-light: #666666;
    --otp-border: #e0e0e0;
    --otp-border-width: 1px;
    --otp-bg: #ffffff;
    --otp-error: #f44336;
    --otp-success: #4caf50;
    --otp-btn-radius: 4px;
    --otp-shadow: 0 2px 20px rgba(0, 0, 0, 0.08);
}

/* Page Wrapper */
.aio-wc-otp-page {
    min-height: 100px;
    padding-left: 20px;
    padding-right: 20px;
    background-color: #f5f5f5;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    box-sizing: border-box;
}



/* Form Wrapper */
.aio-wc-otp-form-wrapper {
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
    padding: 40px;
    background: var(--otp-bg);
    border-radius: 8px;
    box-shadow: var(--otp-shadow);
    box-sizing: border-box;
}



/* Header (Logo + Title) */
.aio-wc-otp-header {
    text-align: center;
    margin-bottom: 30px;
    box-sizing: border-box;
    position: relative;
}

/* Back Button - Rounded square style like Digikala */
.aio-wc-otp-back-btn {
    position: absolute;
    top: 0;
    right: 0;
    width: 40px;
    height: 40px;
    background: #f5f5f5;
    border: 1px solid var(--otp-border);
    border-radius: 10px;
    padding: 0;
    cursor: pointer;
    color: var(--otp-primary);
    transition: all 0.2s ease;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.aio-wc-otp-back-btn:hover {
    background: #eee;
    border-color: var(--otp-primary);
}

.aio-wc-otp-back-btn svg {
    display: block;
    width: 20px;
    height: 20px;
}

/* Logo */
.aio-wc-otp-logo {
    text-align: center;
    margin-bottom: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.aio-wc-otp-logo img {
    max-width: 180px;
    max-height: 80px;
    height: auto;
    object-fit: contain;
    display: block;
    margin: 0 auto;
}

/* Title */
.aio-wc-otp-title {
    text-align: center;
    font-size: 20px;
    font-weight: 600;
    color: var(--otp-text);
    margin: 0;
    padding: 0;
}

/* When logo exists, reduce title margin */
.aio-wc-otp-logo + .aio-wc-otp-title {
    margin-top: 0;
}

/* Form */
.aio-wc-otp-form {
    direction: rtl;
    text-align: right;
    width: 100%;
    box-sizing: border-box;
}

/* Field Container - for transitions */
.aio-wc-otp-field-container {
    width: 100%;
    margin-bottom: 20px;
    box-sizing: border-box;
}

/* Floating Label Field */
.aio-wc-otp-floating-field {
    position: relative;
    width: 100%;
}

.aio-wc-otp-floating-input {
    width: 100%;
    height: 56px;
    padding: 14px 16px 14px 16px;
    border: var(--otp-border-width) solid var(--otp-border);
    border-radius: var(--otp-btn-radius);
    font-size: 16px;
    color: var(--otp-text);
    background: var(--otp-bg);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
    outline: none;
    direction: ltr !important;
    text-align: left !important;
}

.aio-wc-otp-floating-input:focus {
    border-color: var(--otp-primary);
    box-shadow: 0 0 0 3px rgba(0, 150, 136, 0.1);
}

.aio-wc-otp-floating-label {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 15px;
    color: #888;
    pointer-events: none;
    transition: all 0.2s ease;
    background: transparent;
    padding: 0 4px;
    direction: rtl;
}

/* Floating label - active state (focused or has value) */
.aio-wc-otp-floating-input:focus + .aio-wc-otp-floating-label,
.aio-wc-otp-floating-input:not(:placeholder-shown) + .aio-wc-otp-floating-label {
    top: 0;
    transform: translateY(-50%) scale(0.85);
    font-size: 13px;
    color: var(--otp-primary);
    background: var(--otp-bg);
    font-weight: 500;
}

/* Code Section */
.aio-wc-otp-code-section {
    margin-bottom: 0;
}

/* Code Info - shows label and phone number on single line */
.aio-wc-otp-code-info {
    text-align: center;
    margin-bottom: 20px;
    font-size: 14px;
    color: var(--otp-text-light);
    line-height: 1.6;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.aio-wc-otp-code-info-text {
    white-space: nowrap;
}

.aio-wc-otp-code-info .aio-wc-otp-phone-number {
    font-weight: 600;
    font-size: 15px;
    color: var(--otp-primary);
    white-space: nowrap;
}

/* New User Notice */
.aio-wc-otp-new-user-notice {
    text-align: center !important;
    margin-bottom: 16px !important;
    padding: 12px 14px !important;
    font-size: 12px !important;
    line-height: 1.7 !important;
    color: #5d4037 !important;
    background-color: #fff8e1 !important;
    border: 1px solid #ffe082 !important;
    border-radius: var(--otp-btn-radius) !important;
}

/* Password Container */
.aio-wc-otp-password-container {
    animation: fadeSlideIn 0.3s ease;
}

/* Forgot Password Link */
.aio-wc-otp-forgot-password {
    text-align: center;
    margin-top: 12px;
}

.aio-wc-otp-forgot-link {
    color: var(--otp-primary);
    font-size: 13px;
    text-decoration: none;
    cursor: pointer;
}

.aio-wc-otp-forgot-link:hover {
    text-decoration: underline;
}

/* Use Password Link */
.aio-wc-otp-use-password {
    text-align: center;
    margin-top: 16px;
}

.aio-wc-otp-use-password-link {
    color: var(--otp-primary);
    font-size: 13px;
    text-decoration: none;
    cursor: pointer;
}

.aio-wc-otp-use-password-link:hover {
    text-decoration: underline;
}

/* Set Password Container */
.aio-wc-otp-set-password-container {
    animation: fadeSlideIn 0.3s ease;
}

.aio-wc-otp-set-password-header {
    text-align: center;
    margin-bottom: 24px;
}

.aio-wc-otp-set-password-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--otp-text);
    margin: 0 0 8px 0;
    padding: 0;
}

.aio-wc-otp-set-password-desc {
    font-size: 14px;
    color: var(--otp-text-light);
    margin: 0;
    line-height: 1.5;
}

.aio-wc-otp-set-password-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
}

.aio-wc-otp-set-password-buttons .aio-wc-otp-btn--link {
    background: transparent;
    color: var(--otp-text-light);
    font-weight: 500;
}

.aio-wc-otp-set-password-buttons .aio-wc-otp-btn--link:hover {
    color: var(--otp-primary);
}

/* Both Options Container (for pre-existing users) */
.aio-wc-otp-both-options-container {
    animation: fadeSlideIn 0.3s ease;
}

.aio-wc-otp-both-options-header {
    text-align: center;
    margin-bottom: 20px;
    font-size: 14px;
    color: var(--otp-text-light);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.aio-wc-otp-both-options-title {
    font-size: 15px;
    color: var(--otp-text);
}

.aio-wc-otp-both-options-header .aio-wc-otp-phone-number {
    font-weight: 600;
    font-size: 15px;
    color: var(--otp-primary);
}

.aio-wc-otp-both-options-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Secondary Button Style */
.aio-wc-otp-btn--secondary {
    background-color: transparent !important;
    color: var(--otp-primary) !important;
    border: 2px solid var(--otp-primary) !important;
}

.aio-wc-otp-btn--secondary:hover {
    background-color: rgba(0, 150, 136, 0.08) !important;
}

/* Password Input RTL fix */
.aio-wc-otp-password-input {
    direction: ltr !important;
    text-align: left !important;
}

.aio-wc-otp-code-label {
    display: block;
    margin-bottom: 12px;
    font-weight: 500;
    color: var(--otp-text);
    font-size: 14px;
    text-align: right;
}

/* Transition animations for container switching */
.aio-wc-otp-phone-container {
    animation: fadeSlideIn 0.3s ease;
}

.aio-wc-otp-code-container {
    animation: fadeSlideIn 0.3s ease;
}

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Steps - kept for backward compatibility */
.aio-wc-otp-step {
    display: none;
    width: 100%;
    box-sizing: border-box;
}

.aio-wc-otp-step.active {
    display: block;
}

/* Form Group */
.aio-wc-otp-form-group {
    margin-bottom: 24px;
    width: 100%;
    box-sizing: border-box;
}

/* Labels */
.aio-wc-otp-label {
    display: block;
    margin-bottom: 10px;
    font-weight: 500;
    color: var(--otp-text);
    font-size: 14px;
}

/* Inputs - Flat Material Design */
.aio-wc-otp-input {
    width: 100%;
    height: 48px;
    padding: 0 16px;
    border: var(--otp-border-width) solid var(--otp-border);
    border-radius: var(--otp-btn-radius);
    font-size: 15px;
    color: var(--otp-text);
    background: var(--otp-bg);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
    outline: none;
}

/* Phone input - always LTR for numbers */
.aio-wc-otp-input[type="tel"] {
    direction: ltr !important;
    text-align: left !important;
}

.aio-wc-otp-input::placeholder {
    color: #999;
    letter-spacing: normal;
    font-weight: normal;
    font-size: 14px;
}

.aio-wc-otp-input:focus {
    border-color: var(--otp-primary);
    box-shadow: 0 0 0 3px rgba(0, 150, 136, 0.1);
}

/* OTP Digit Boxes Container - Using CSS Grid for automatic sizing */
.aio-wc-otp-code-boxes {
    display: grid !important;
    grid-template-columns: repeat(5, 1fr) !important;
    gap: 8px !important;
    direction: ltr !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
}

/* Grid columns based on data-length attribute */
.aio-wc-otp-code-boxes[data-length="4"] {
    grid-template-columns: repeat(4, 1fr) !important;
}

.aio-wc-otp-code-boxes[data-length="5"] {
    grid-template-columns: repeat(5, 1fr) !important;
}

.aio-wc-otp-code-boxes[data-length="6"] {
    grid-template-columns: repeat(6, 1fr) !important;
}

/* Individual Digit Box - Square 1:1 aspect ratio */
.aio-wc-otp-digit-box {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: auto !important;
    aspect-ratio: 1 / 1 !important;
    padding: 0 !important;
    margin: 0 !important;
    border: var(--otp-border-width) solid var(--otp-border);
    border-radius: var(--otp-btn-radius);
    font-size: clamp(16px, 4vw, 22px);
    font-weight: 600;
    text-align: center;
    line-height: 1;
    color: var(--otp-text);
    background: var(--otp-bg);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box !important;
    outline: none;
    caret-color: var(--otp-primary);
    -webkit-appearance: none;
    -moz-appearance: textfield;
    appearance: none;
}

/* Hide number input spinners */
.aio-wc-otp-digit-box::-webkit-outer-spin-button,
.aio-wc-otp-digit-box::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Focus state */
.aio-wc-otp-digit-box:focus {
    border-color: var(--otp-primary);
    box-shadow: 0 0 0 3px rgba(0, 150, 136, 0.15);
}

/* Filled state */
.aio-wc-otp-digit-box.filled {
    border-color: var(--otp-primary);
    background-color: rgba(0, 150, 136, 0.05);
}

/* Error state */
.aio-wc-otp-digit-box.error {
    border-color: var(--otp-error);
    animation: shake 0.4s ease;
}

/* Success state */
.aio-wc-otp-digit-box.success {
    border-color: var(--otp-success);
    background-color: rgba(76, 175, 80, 0.1);
}

/* Shake animation for error */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-5px); }
    40%, 80% { transform: translateX(5px); }
}

/* Legacy single input (kept for backward compatibility) */
.aio-wc-otp-input--code {
    text-align: left;
    letter-spacing: 10px;
    font-size: 18px;
    font-weight: 600;
    height: 56px;
    line-height: 56px;
    direction: ltr;
    caret-color: var(--otp-primary);
}

.aio-wc-otp-input--code::placeholder {
    letter-spacing: 0 !important;
    font-size: 14px !important;
    font-weight: 400 !important;
    text-align: right !important;
    direction: rtl !important;
}

.aio-wc-otp-input--code::-webkit-input-placeholder {
    text-align: right !important;
    direction: rtl !important;
}

.aio-wc-otp-input--code::-moz-placeholder {
    text-align: right !important;
    direction: rtl !important;
}

/* Buttons - Flat Material Design */
.aio-wc-otp-btn {
    display: block;
    width: 100%;
    padding: 14px 28px;
    border: none;
    border-radius: var(--otp-btn-radius);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    text-align: center;
    outline: none;
    box-sizing: border-box;
}

.aio-wc-otp-btn--primary {
    background-color: var(--otp-primary);
    color: #fff;
}

.aio-wc-otp-btn--primary:hover {
    background-color: var(--otp-primary-hover);
}

.aio-wc-otp-btn--primary:active {
    transform: translateY(1px);
}

.aio-wc-otp-btn--primary:disabled {
    background-color: #bdbdbd;
    cursor: not-allowed;
    transform: none;
}

/* Countdown state on primary button */
.aio-wc-otp-btn--primary.aio-wc-otp-btn--countdown {
    background-color: #78909c !important;
    cursor: not-allowed;
}

/* Countdown timer text inside button */
.aio-wc-otp-btn--countdown .aio-wc-countdown-time {
    font-variant-numeric: tabular-nums !important;
    font-size: inherit !important;
    display: inline-block !important;
    min-width: 55px !important;
    text-align: center !important;
}

/* Messages */
.aio-wc-otp-message {
    padding: 14px 16px;
    border-radius: var(--otp-btn-radius);
    margin-top: 20px;
    font-size: 14px;
    text-align: center;
}

.aio-wc-otp-message--success {
    background-color: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #c8e6c9;
}

.aio-wc-otp-message--error {
    background-color: #ffebee;
    color: #c62828;
    border: 1px solid #ffcdd2;
}

/* Logged In Message */
.aio-wc-otp-logged-in {
    text-align: center;
    padding: 40px;
    background: #fafafa;
    border-radius: 8px;
    max-width: 400px;
    margin: 0 auto;
}

.aio-wc-otp-logged-in a {
    color: var(--otp-primary);
    text-decoration: none;
    font-weight: 500;
}

.aio-wc-otp-logged-in a:hover {
    text-decoration: underline;
}

/* RTL Support */
[dir="rtl"] .aio-wc-otp-form,
.rtl .aio-wc-otp-form,
body.rtl .aio-wc-otp-form {
    direction: rtl;
    text-align: right;
}

[dir="ltr"] .aio-wc-otp-form {
    direction: ltr;
    text-align: left;
}

/* Responsive */
@media (max-width: 480px) {
    .aio-wc-otp-page {
        padding-left: 15px;
        padding-right: 15px;
    }
    
    .aio-wc-otp-form-wrapper {
        padding: 30px 24px;
    }

    .aio-wc-otp-input--code {
        letter-spacing: 6px;
        font-size: 20px;
    }
    
    .aio-wc-otp-logo img {
        max-width: 140px;
    }
    
    /* Smaller gap on mobile */
    .aio-wc-otp-code-boxes {
        gap: 6px !important;
    }
}

/* Extra small screens */
@media (max-width: 360px) {
    .aio-wc-otp-code-boxes {
        gap: 4px !important;
    }
    
    .aio-wc-otp-digit-box {
        font-size: 16px !important;
    }
}

/* Loading State */
.aio-wc-otp-btn--loading {
    position: relative;
    pointer-events: none;
    padding-right: 44px !important;
}

.aio-wc-otp-btn--loading .aio-wc-btn-text {
    opacity: 0.7;
}

.aio-wc-otp-btn--loading::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    top: 50%;
    right: 14px;
    margin-top: -9px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: aio-wc-otp-spin 0.7s linear infinite;
}

/* Link button loading state */
.aio-wc-otp-btn--link.aio-wc-otp-btn--loading {
    padding-right: 28px !important;
}

.aio-wc-otp-btn--link.aio-wc-otp-btn--loading::after {
    width: 14px;
    height: 14px;
    right: 0;
    margin-top: -7px;
    border-color: rgba(0, 150, 136, 0.3);
    border-top-color: var(--otp-primary);
}

@keyframes aio-wc-otp-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Focus visible for accessibility */
.aio-wc-otp-btn:focus-visible,
.aio-wc-otp-input:focus-visible {
    outline: 2px solid var(--otp-primary);
    outline-offset: 2px;
}

/* Biometric Login Styles */
.aio-wc-otp-biometric-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.aio-wc-otp-biometric-btn svg {
    flex-shrink: 0;
}

/* Secondary button loading state (biometric button) */
.aio-wc-otp-btn--secondary.aio-wc-otp-btn--loading {
    position: relative;
    pointer-events: none;
}

.aio-wc-otp-btn--secondary.aio-wc-otp-btn--loading .aio-wc-btn-text {
    opacity: 0.7;
}

.aio-wc-otp-btn--secondary.aio-wc-otp-btn--loading .aio-wc-otp-biometric-icon {
    display: none;
}

.aio-wc-otp-btn--secondary.aio-wc-otp-btn--loading::before {
    content: '';
    width: 18px;
    height: 18px;
    border: 2px solid rgba(0, 150, 136, 0.3);
    border-radius: 50%;
    border-top-color: var(--otp-primary);
    animation: aio-wc-otp-spin 0.7s linear infinite;
    flex-shrink: 0;
}

.aio-wc-otp-biometric-separator {
    position: relative;
    text-align: center;
    margin: 16px 0;
}

.aio-wc-otp-biometric-separator::before,
.aio-wc-otp-biometric-separator::after {
    content: '';
    position: absolute;
    top: 50%;
    width: calc(50% - 60px);
    height: 1px;
    background: var(--otp-border);
}

.aio-wc-otp-biometric-separator::before {
    right: 0;
}

.aio-wc-otp-biometric-separator::after {
    left: 0;
}

.aio-wc-otp-biometric-separator span {
    background: var(--otp-bg, #fff);
    padding: 0 12px;
    font-size: 13px;
    color: var(--otp-text-light);
}

/* Biometric Prompt Container */
.aio-wc-otp-biometric-prompt-container {
    animation: fadeSlideIn 0.3s ease;
}

.aio-wc-otp-biometric-prompt-header {
    text-align: center;
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.aio-wc-otp-biometric-prompt-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--otp-text);
    margin: 0 0 8px 0;
}

.aio-wc-otp-biometric-prompt-desc {
    font-size: 14px;
    color: var(--otp-text-light);
    margin: 0;
    line-height: 1.5;
}

.aio-wc-otp-biometric-prompt-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.aio-wc-otp-biometric-prompt-buttons .aio-wc-otp-btn--link {
    background: transparent;
    color: var(--otp-text-light);
    font-weight: 500;
}

.aio-wc-otp-biometric-prompt-buttons .aio-wc-otp-btn--link:hover {
    color: var(--otp-primary);
}

/* Hide biometric elements when not supported */
body.webauthn-not-supported .aio-wc-otp-biometric-btn,
body.webauthn-not-supported .aio-wc-otp-biometric-separator,
body.webauthn-not-supported .aio-wc-otp-biometric-prompt-container,
body.webauthn-not-supported .aio-wc-otp-enable-biometric-btn {
    display: none !important;
}


/* Redirecting state - hide form content during redirect */
.aio-wc-otp-form--redirecting {
    opacity: 0.5;
    pointer-events: none;
}

.aio-wc-otp-form--redirecting::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 3px solid var(--otp-primary, #009688);
    border-top-color: transparent;
    border-radius: 50%;
    animation: aio-wc-spin 0.8s linear infinite;
}
