/**
 * Auth UX Enhancements - World-Class Authentication Experience
 * Inspired by: Stripe, Vercel, Linear, Notion
 *
 * Features:
 * - Smooth animations and transitions
 * - Enhanced focus states
 * - Loading states
 * - Error handling UX
 * - Accessibility improvements
 * - Micro-interactions
 */

/* ====================
   SMOOTH TRANSITIONS
   ==================== */

* {
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

.form-input,
.submit-btn,
.error-message,
.toggle-password {
    transition: all 0.2s ease-in-out;
}

/* ====================
   ENHANCED FOCUS STATES
   ==================== */

.form-input:focus {
    outline: none;
    border-color: var(--primary-color, #3b82f6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    transform: translateY(-1px);
}

.form-input:focus-visible {
    outline: 2px solid var(--primary-color, #3b82f6);
    outline-offset: 2px;
}

/* ====================
   INPUT STATES
   ==================== */

.form-input:hover:not(:focus):not(:disabled) {
    border-color: rgba(59, 130, 246, 0.4);
}

.form-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background-color: rgba(0, 0, 0, 0.05);
}

.form-input.error {
    border-color: #ef4444;
    background-color: rgba(239, 68, 68, 0.05);
}

.form-input.success {
    border-color: #10b981;
    background-color: rgba(16, 185, 129, 0.05);
}

/* ====================
   BUTTON LOADING STATE
   ==================== */

.submit-btn.loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.submit-btn.loading .btn-text {
    opacity: 0;
}

.submit-btn.loading .spinner {
    display: block;
}

.spinner {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ====================
   BUTTON HOVER EFFECTS
   ==================== */

.submit-btn:hover:not(:disabled):not(.loading) {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(59, 130, 246, 0.3);
}

.submit-btn:active:not(:disabled):not(.loading) {
    transform: translateY(0);
}

/* ====================
   ERROR MESSAGE ANIMATIONS
   ==================== */

.error-message {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    margin-bottom: 0;
    transition: max-height 0.3s ease-out, opacity 0.2s ease-out, margin-bottom 0.3s ease-out;
}

.error-message.show {
    max-height: 200px;
    opacity: 1;
    margin-bottom: 1rem;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ====================
   ERROR CONTENT STYLING
   ==================== */

.error-content {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem;
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1) 0%, rgba(239, 68, 68, 0.05) 100%);
    border-left: 3px solid #ef4444;
    border-radius: 8px;
}

.error-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.error-details {
    flex: 1;
}

.error-title {
    font-weight: 600;
    color: #dc2626;
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
}

.error-message-text {
    color: #991b1b;
    font-size: 0.875rem;
    line-height: 1.5;
}

/* ====================
   TOGGLE PASSWORD BUTTON
   ==================== */

.toggle-password {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.25rem;
    padding: 0.5rem;
    opacity: 0.6;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 10;
}

.toggle-password:hover {
    opacity: 1;
    transform: translateY(-50%) scale(1.1);
}

.toggle-password:active {
    transform: translateY(-50%) scale(0.95);
}

.input-wrapper {
    position: relative;
}

.input-wrapper .form-input {
    padding-right: 3rem;
}

/* ====================
   FORM VALIDATION HINTS
   ==================== */

.field-hint {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 0.25rem;
    transition: color 0.2s ease;
}

.form-input:focus + .field-hint {
    color: rgba(255, 255, 255, 0.7);
}

.form-input.error + .field-hint {
    color: #ef4444;
}

.form-input.success + .field-hint {
    color: #10b981;
}

/* ====================
   CHECKBOX & REMEMBER ME
   ==================== */

.remember-me {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

.remember-me input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color, #3b82f6);
}

.remember-me:hover span {
    color: rgba(255, 255, 255, 0.9);
}

/* ====================
   LINKS
   ==================== */

.forgot-link,
.signup-link a {
    position: relative;
    color: var(--primary-color, #3b82f6);
    text-decoration: none;
    transition: color 0.2s ease;
}

.forgot-link::after,
.signup-link a::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 2px;
    background-color: var(--primary-color, #3b82f6);
    transition: width 0.3s ease;
}

.forgot-link:hover::after,
.signup-link a:hover::after {
    width: 100%;
}

.forgot-link:hover,
.signup-link a:hover {
    color: #2563eb;
}

/* ====================
   AUTO-FILL STYLING
   ==================== */

.form-input:-webkit-autofill,
.form-input:-webkit-autofill:hover,
.form-input:-webkit-autofill:focus {
    -webkit-text-fill-color: rgba(255, 255, 255, 0.9);
    -webkit-box-shadow: 0 0 0 30px rgba(255, 255, 255, 0.1) inset;
    transition: background-color 5000s ease-in-out 0s;
}

/* ====================
   SUCCESS STATES
   ==================== */

.success-message {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, rgba(16, 185, 129, 0.05) 100%);
    border-left: 3px solid #10b981;
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    animation: slideDown 0.3s ease-out;
}

.success-message .success-icon {
    font-size: 1.25rem;
    color: #10b981;
}

.success-message .success-text {
    color: #059669;
    font-size: 0.875rem;
    line-height: 1.5;
}

/* ====================
   ACCESSIBILITY
   ==================== */

.skip-link:focus {
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 9999;
    padding: 0.75rem 1.5rem;
    background-color: var(--primary-color, #3b82f6);
    color: white;
    border-radius: 8px;
    text-decoration: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ====================
   SHAKE ANIMATION FOR ERRORS
   ==================== */

@keyframes shake-element {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-10px); }
    20%, 40%, 60%, 80% { transform: translateX(10px); }
}

.shake {
    animation: shake-element 0.5s ease-in-out;
}

/* ====================
   FORM ROW LAYOUT
   ==================== */

.form-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 1rem 0;
    gap: 1rem;
}

/* ====================
   RESPONSIVE DESIGN
   ==================== */

@media (max-width: 640px) {
    .form-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .forgot-link {
        order: -1;
        margin-bottom: 0.5rem;
    }
}

/* ====================
   DARK MODE SUPPORT
   ==================== */

@media (prefers-color-scheme: dark) {
    .form-input:disabled {
        background-color: rgba(255, 255, 255, 0.05);
    }

    .form-input:-webkit-autofill,
    .form-input:-webkit-autofill:hover,
    .form-input:-webkit-autofill:focus {
        -webkit-box-shadow: 0 0 0 30px rgba(0, 0, 0, 0.3) inset;
    }
}

/* ====================
   TOOLTIPS (OPTIONAL)
   ==================== */

[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    padding: 0.5rem 0.75rem;
    background-color: rgba(0, 0, 0, 0.9);
    color: white;
    font-size: 0.75rem;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

[data-tooltip]:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(-12px);
}
