/* ==========================================================================
   Auth Module - Modern Design System
   ========================================================================== */

/* ---- CSS Variables for Auth ---- */
:root {
    --auth-primary: #0068c8;
    --auth-primary-hover: #0052a3;
    --auth-primary-light: rgba(0, 104, 200, 0.1);
    --auth-secondary: #41c1c6;
    --auth-accent: #ff6b35;
    --auth-success: #189d0e;
    --auth-error: #dc3545;
    --auth-warning: #ffc107;

    --auth-bg: #f4f5f9;
    --auth-card-bg: #ffffff;
    --auth-border: #e8ebef;

    --auth-text-primary: #1a1d21;
    --auth-text-secondary: #4b5563;
    --auth-text-muted: #9ca3af;
    --auth-placeholder: #d1d5db;

    --auth-radius-sm: 8px;
    --auth-radius-md: 12px;
    --auth-radius-lg: 16px;
    --auth-radius-xl: 24px;
    --auth-radius-pill: 50px;

    --auth-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --auth-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --auth-shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.1);
    --auth-shadow-xl: 0 20px 48px rgba(0, 0, 0, 0.12);

    --auth-transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --auth-transition-fast: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);

    --auth-font: 'yekan-bakh', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ---- RTL Support ---- */
[dir="rtl"] {
    font-family: var(--auth-font);
}

/* ---- Layout ---- */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--auth-bg);
    padding: 24px 16px;
    position: relative;
    overflow: hidden;
}

.auth-page::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, var(--auth-primary-light) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
    z-index: 0;
}

.auth-page::after {
    content: '';
    position: absolute;
    bottom: -30%;
    left: -15%;
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(65, 193, 198, 0.15) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
    z-index: 0;
}

.auth-container {
    width: 100%;
    max-width: 420px;
    position: relative;
    z-index: 1;
}

.auth-card {
    background: var(--auth-card-bg);
    border-radius: var(--auth-radius-xl);
    box-shadow: var(--auth-shadow-lg);
    border: 1px solid var(--auth-border);
    padding: 40px 32px;
    animation: authFadeInUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes authFadeInUp {
    from {
        opacity: 0;
        transform: translateY(24px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ---- Logo ---- */
.auth-logo {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo a {
    display: inline-block;
    transition: transform var(--auth-transition);
}

.auth-logo a:hover {
    transform: scale(1.02);
}

.auth-logo img {
    width: 160px;
    height: auto;
    filter: drop-shadow(0 4px 16px rgba(0, 104, 200, 0.15));
}

/* ---- Header / Title ---- */
.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.auth-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--auth-text-primary);
    margin: 0 0 8px;
    letter-spacing: -0.5px;
}

.auth-subtitle {
    font-size: 15px;
    color: var(--auth-text-secondary);
    margin: 0;
    line-height: 1.6;
    font-weight: 400;
}

/* ---- Form ---- */
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.auth-form .form-group {
    margin: 0;
}

/* ---- Input Groups ---- */
.auth-input-group {
    position: relative;
}

.auth-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--auth-card-bg);
    border: 2px solid var(--auth-border);
    border-radius: var(--auth-radius-md);
    transition: var(--auth-transition);
    overflow: hidden;
}

.auth-input-wrapper:focus-within {
    border-color: var(--auth-primary);
    box-shadow: 0 0 0 4px var(--auth-primary-light);
}

.auth-input-wrapper.has-error {
    border-color: var(--auth-error);
    box-shadow: 0 0 0 4px rgba(220, 53, 69, 0.1);
}

.auth-input-wrapper.has-success {
    border-color: var(--auth-success);
}

.auth-input-prefix {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    background: var(--auth-bg);
    color: var(--auth-text-muted);
    font-size: 20px;
    border-left: 2px solid var(--auth-border);
    flex-shrink: 0;
}

.auth-input-wrapper:focus-within .auth-input-prefix {
    color: var(--auth-primary);
    background: var(--auth-primary-light);
}

.auth-input {
    flex: 1;
    height: 56px;
    border: none;
    outline: none;
    background: transparent;
    font-family: var(--auth-font);
    font-size: 17px;
    font-weight: 500;
    color: var(--auth-text-primary);
    padding: 0 20px;
    letter-spacing: 1px;
    text-align: right;
    direction: ltr;
}

.auth-input::placeholder {
    color: var(--auth-placeholder);
    font-weight: 400;
    letter-spacing: 2px;
}

.auth-input::-webkit-inner-spin-button,
.auth-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.auth-input[type=number] {
    -moz-appearance: textfield;
}

/* Input validation icons */
.auth-input-wrapper .auth-input-suffix {
    position: absolute;
    left: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    pointer-events: none;
    opacity: 0;
    transform: scale(0.8);
    transition: var(--auth-transition-fast);
}

.auth-input-wrapper.has-success .auth-input-suffix.success {
    opacity: 1;
    transform: scale(1);
    color: var(--auth-success);
}

.auth-input-wrapper.has-error .auth-input-suffix.error {
    opacity: 1;
    transform: scale(1);
    color: var(--auth-error);
}

/* Error message */
.auth-error {
    display: none;
    align-items: center;
    gap: 6px;
    color: var(--auth-error);
    font-size: 13px;
    font-weight: 500;
    margin-top: 8px;
    padding: 0 4px;
    animation: authSlideDown 0.2s ease-out;
}

.auth-error.visible {
    display: flex;
}

@keyframes authSlideDown {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.auth-error i {
    font-size: 12px;
    flex-shrink: 0;
}

/* ---- OTP Input ---- */
/* Override main.css #otp-input styles with higher specificity */
#otp-input,
div#otp-input.otp-input-container {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    white-space: nowrap !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 8px !important;
    margin: 8px 0 4px !important;
    direction: ltr !important;
    min-width: 0 !important;
}

/* Override main.css #otp-input input styles */
#otp-input input.otp-input,
.otp-input {
    width: 52px !important;
    height: 58px !important;
    min-width: 52px !important;
    flex: 0 0 52px !important;
    border: 2px solid var(--auth-border) !important;
    border-radius: var(--auth-radius-md) !important;
    background: var(--auth-card-bg) !important;
    font-family: var(--auth-font) !important;
    font-size: 26px !important;
    font-weight: 600 !important;
    color: var(--auth-text-primary) !important;
    text-align: center !important;
    outline: none !important;
    transition: var(--auth-transition) !important;
    -moz-appearance: textfield !important;
    padding: 0 !important;
}

.otp-input::-webkit-inner-spin-button,
.otp-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.otp-input:focus {
    border-color: var(--auth-primary);
    box-shadow: 0 0 0 4px var(--auth-primary-light);
}

.otp-input.filled {
    border-color: var(--auth-primary);
    background: var(--auth-primary-light);
}

.otp-input.error {
    border-color: var(--auth-error);
    animation: authShake 0.4s ease-out;
}

@keyframes authShake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

/* OTP Input RTL/LTR fix for mobile */
.otp-input-container[dir="ltr"] .otp-input {
    direction: ltr;
}

/* ---- Buttons ---- */
.auth-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    height: 56px;
    padding: 0 24px;
    border: none;
    border-radius: var(--auth-radius-md);
    font-family: var(--auth-font);
    font-size: 16px;
    font-weight: 600;
    color: #ffffff !important;
    background: linear-gradient(135deg, var(--auth-primary) 0%, var(--auth-primary-hover) 100%);
    cursor: pointer;
    transition: var(--auth-transition);
    position: relative;
    overflow: hidden;
    z-index: 0;
}

.auth-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--auth-primary-hover) 0%, var(--auth-primary) 100%);
    opacity: 0;
    transition: var(--auth-transition);
    z-index: -1;
}

.auth-btn:hover:not(:disabled)::before {
    opacity: 1;
}

.auth-btn:active:not(:disabled) {
    transform: scale(0.98);
}

.auth-btn:focus-visible {
    outline: 3px solid var(--auth-primary-light);
    outline-offset: 2px;
}

.auth-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.auth-btn .btn-text,
.auth-btn .btn-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: var(--auth-transition-fast);
    position: relative;
    z-index: 1;
    color: #ffffff !important;
}

.auth-btn .btn-loading {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.auth-btn.loading .btn-text {
    opacity: 0;
    transform: translateY(-10px);
}

.auth-btn.loading .btn-loading {
    opacity: 1;
    transform: translateY(0);
}

.auth-btn .spinner-border {
    width: 20px;
    height: 20px;
    border-width: 2.5px;
    animation-duration: 0.8s;
}

.auth-btn-secondary {
    background: transparent;
    color: var(--auth-primary) !important;
    border: 2px solid var(--auth-primary);
}

.auth-btn-secondary::before {
    background: var(--auth-primary-light);
}

.auth-btn-secondary:hover:not(:disabled) {
    background: var(--auth-primary);
    color: #ffffff !important;
}

/* Link buttons */
.auth-link-btn {
    background: none;
    border: none;
    padding: 8px 4px;
    font: inherit;
    color: var(--auth-primary);
    font-weight: 600;
    cursor: pointer;
    transition: var(--auth-transition-fast);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    position: relative;
}

.auth-link-btn::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: currentColor;
    transform: scaleX(0);
    transform-origin: right;
    transition: transform var(--auth-transition-fast);
}

.auth-link-btn:hover {
    color: var(--auth-primary-hover);
    text-decoration: none;
}

.auth-link-btn:hover::after {
    transform: scaleX(1);
    transform-origin: left;
}

.auth-link-btn:focus-visible {
    outline: 3px solid var(--auth-primary-light);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ---- Resend / Timer ---- */
.auth-resend {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 8px 0 4px;
}

.auth-resend-text {
    color: var(--auth-text-secondary);
    font-size: 14px;
}

.auth-resend-timer {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 60px;
    height: 28px;
    padding: 0 10px;
    background: var(--auth-primary-light);
    color: var(--auth-primary);
    border-radius: var(--auth-radius-pill);
    font-family: var(--auth-font);
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.5px;
}

.auth-resend-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: transparent;
    border: 1px solid var(--auth-border);
    border-radius: var(--auth-radius-sm);
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    color: var(--auth-text-secondary);
    cursor: pointer;
    transition: var(--auth-transition-fast);
}

.auth-resend-btn:hover:not(:disabled) {
    background: var(--auth-bg);
    border-color: var(--auth-primary);
    color: var(--auth-primary);
}

.auth-resend-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.auth-resend-btn .spinner-border {
    width: 16px;
    height: 16px;
    border-width: 2px;
}

/* ---- Terms / Footer ---- */
.auth-terms {
    text-align: center;
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--auth-border);
}

.auth-terms p {
    margin: 0;
    font-size: 13px;
    color: var(--auth-text-muted);
    line-height: 1.7;
}

.auth-terms a {
    color: var(--auth-primary);
    font-weight: 600;
    text-decoration: none;
    transition: var(--auth-transition-fast);
    position: relative;
}

.auth-terms a::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 2px;
    background: currentColor;
    transition: width var(--auth-transition-fast);
}

.auth-terms a:hover {
    color: var(--auth-primary-hover);
    text-decoration: none;
}

.auth-terms a:hover::after {
    width: 100%;
}

.auth-terms a:focus-visible {
    outline: 3px solid var(--auth-primary-light);
    outline-offset: 2px;
    border-radius: 2px;
}

/* ---- Alert / Toast ---- */
.auth-alert {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    border-radius: var(--auth-radius-md);
    font-size: 14px;
    line-height: 1.6;
    animation: authSlideDown 0.3s ease-out;
}

.auth-alert.success {
    background: rgba(24, 157, 14, 0.1);
    border: 1px solid rgba(24, 157, 14, 0.2);
    color: #146c0a;
}

.auth-alert.error {
    background: rgba(220, 53, 69, 0.1);
    border: 1px solid rgba(220, 53, 69, 0.2);
    color: #b02a37;
}

.auth-alert i {
    flex-shrink: 0;
    margin-top: 2px;
    font-size: 18px;
}

/* ---- Countdown Bar ---- */
/* Override main.css .countdown-bar styles */
.countdown-bar,
div.countdown-bar {
    height: 4px !important;
    background: var(--auth-border) !important;
    border-radius: var(--auth-radius-pill) !important;
    overflow: hidden !important;
    margin: 16px 0 !important;
    width: 100% !important;
}

.countdown-bar .progress {
    height: 100% !important;
    background: linear-gradient(90deg, var(--auth-primary), var(--auth-secondary)) !important;
    border-radius: var(--auth-radius-pill) !important;
    transform-origin: left !important;
    transform: scaleX(0);
    transition: transform 1s linear;
}

/* ---- Success State ---- */
.auth-success {
    text-align: center;
    padding: 24px 0;
}

.auth-success-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    background: linear-gradient(135deg, var(--auth-success), #2ebf1c);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: authScaleIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes authScaleIn {
    from {
        transform: scale(0);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.auth-success-icon i {
    font-size: 36px;
    color: #ffffff;
}

.auth-success-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--auth-text-primary);
    margin: 0 0 8px;
}

.auth-success-text {
    font-size: 15px;
    color: var(--auth-text-secondary);
    margin: 0;
}

/* ---- Divider ---- */
.auth-divider {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 24px 0 16px;
    color: var(--auth-text-muted);
    font-size: 13px;
    font-weight: 500;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--auth-border);
}

/* ---- Trust Indicators ---- */
.auth-trust {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px 20px;
    margin: 16px 0 24px;
    padding: 0 8px;
}

.trust-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--auth-text-secondary);
    font-weight: 500;
}

.trust-item i {
    font-size: 16px;
    color: var(--auth-primary);
    flex-shrink: 0;
}

/* ---- Alternative Actions ---- */
.auth-alternatives {
    margin-bottom: 24px;
}

.auth-alternatives .auth-link-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    font-size: 15px;
    font-weight: 600;
    color: var(--auth-primary);
    background: var(--auth-primary-light);
    border-radius: var(--auth-radius-md);
    transition: var(--auth-transition);
    text-decoration: none;
}

.auth-alternatives .auth-link-btn:hover {
    background: var(--auth-primary);
    color: #ffffff;
    text-decoration: none;
}

.auth-alternatives .auth-link-btn i {
    font-size: 18px;
}

/* ---- Terms / Footer ---- */
.auth-terms {
    text-align: center;
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--auth-border);
}

.auth-terms .terms-text {
    margin: 0 0 12px;
    font-size: 13px;
    line-height: 1.7;
}

.auth-terms .terms-support {
    margin: 0;
    font-size: 13px;
    line-height: 1.7;
}

/* Link buttons inside auth-terms (OTP pages) */
.auth-terms .auth-link-btn {
    color: #ffffff;
    font-weight: 600;
    font-size: 14px;
}

.auth-terms .auth-link-btn:hover {
    color: #ffffff;
    opacity: 0.8;
}

.auth-terms .auth-link-btn i {
    font-size: 16px;
    transition: transform var(--auth-transition-fast);
}

.auth-terms .auth-link-btn:hover i {
    transform: translateX(-4px);
}

/* Links inside auth-terms (auth page) */
.auth-terms a:not(.auth-link-btn) {
    font-weight: 600;
    text-decoration: none;
    transition: var(--auth-transition-fast);
    position: relative;
}

.auth-terms a:not(.auth-link-btn)::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 2px;
    background: currentColor;
    transition: width var(--auth-transition-fast);
}

.auth-terms a:not(.auth-link-btn):hover {
    opacity: 0.8;
    text-decoration: none;
}

.auth-terms a:not(.auth-link-btn):hover::after {
    width: 100%;
}

.auth-terms a:focus-visible {
    outline: 3px solid var(--auth-primary-light);
    outline-offset: 2px;
    border-radius: 2px;
}

/* ---- Responsive ---- */
@media (max-width: 480px) {
    .auth-card {
        padding: 32px 24px;
        border-radius: var(--auth-radius-lg);
    }

    .auth-title {
        font-size: 24px;
    }

    .auth-trust {
        gap: 10px 16px;
    }

    .trust-item {
        font-size: 11px;
        gap: 6px;
    }

    .trust-item i {
        font-size: 14px;
    }

    .auth-alternatives .auth-link-btn {
        padding: 10px 20px;
        font-size: 14px;
    }

    .auth-alternatives .auth-link-btn i {
        font-size: 16px;
    }

    .auth-terms .terms-text,
    .auth-terms .terms-support {
        font-size: 12px;
    }

    /* Override main.css responsive #otp-input input */
    #otp-input input.otp-input,
    .otp-input {
        width: 44px !important;
        min-width: 44px !important;
        flex: 0 0 44px !important;
        height: 52px !important;
        font-size: 22px !important;
    }

    #otp-input,
    .otp-input-container {
        gap: 6px !important;
    }

    .auth-input-wrapper,
    .auth-btn {
        height: 52px;
    }

    .auth-input {
        font-size: 16px;
    }
}

/* ---- Reduced Motion ---- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ---- Focus Visible Polyfill ---- */
:focus:not(:focus-visible) {
    outline: none;
}

:focus-visible {
    outline: 3px solid var(--auth-primary-light);
    outline-offset: 2px;
}

/* ---- High Contrast Mode ---- */
@media (prefers-contrast: high) {
    .auth-input-wrapper {
        border-width: 3px;
    }

    .auth-btn {
        border: 2px solid currentColor;
    }

    .otp-input {
        border-width: 3px;
    }
}
