/**
 * Auth.css - Стили системы аутентификации
 * Современный адаптивный дизайн с поддержкой PWA и мобильных устройств
 * 
 * Основные особенности:
 * - CSS Grid и Flexbox
 * - CSS Custom Properties (переменные)
 * - Dark theme support
 * - Mobile-first подход
 * - Accessibility (a11y)
 * - High DPI оптимизация
 */

/* ===== CSS VARIABLES ===== */
:root {
    /* Цветовая палитра */
    --primary: #7c3aed;
    --primary-light: #8b5cf6;
    --primary-dark: #6d28d9;
    --secondary: #f59e0b;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    
    /* Текст */
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-light: #9ca3af;
    
    /* Фоны */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-dark: #111827;
    
    /* Границы */
    --border-light: #e5e7eb;
    --border-medium: #d1d5db;
    
    /* Тени */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    
    /* Радиусы */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    
    /* Анимации */
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== DARK THEME ===== */
[data-theme="dark"] {
    --text-primary: #f9fafb;
    --text-secondary: #e5e7eb;
    --text-light: #9ca3af;
    
    --bg-primary: #1f2937;
    --bg-secondary: #111827;
    --bg-dark: #030712;
    
    --border-light: #374151;
    --border-medium: #4b5563;
}

/* ===== BASE STYLES ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', 'SF Pro Display', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    line-height: 1.6;
    color: var(--text-primary);
}

/* ===== AUTH CONTAINER ===== */
.auth-container {
    width: 100%;
    max-width: 440px;
    perspective: 1000px;
}

.auth-card {
    background: var(--bg-primary);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    padding: 3rem 2.5rem;
    position: relative;
    overflow: hidden;
    transform-style: preserve-3d;
    transition: var(--transition-slow);
}

/* Акцентная полоса сверху */
.auth-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
}

/* Эффект при наведении */
.auth-card:hover {
    transform: translateY(-4px) rotateX(2deg);
    box-shadow: var(--shadow-xl), 0 25px 50px -12px rgb(0 0 0 / 0.25);
}

/* ===== HEADER STYLES ===== */
.auth-header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.logo {
    width: 80px;
    height: 80px;
    margin: 0 auto 1.5rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 50%;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 2rem;
    box-shadow: var(--shadow-lg);
}

.auth-title {
    font-size: 1.875rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.role-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1.25rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    border-radius: 2rem;
    font-weight: 600;
    font-size: 0.875rem;
    box-shadow: var(--shadow-md);
}

/* ===== FORM STYLES ===== */
.auth-form {
    space-y: 1.5rem;
}

.form-group {
    margin-bottom: 1.5rem;
    position: relative;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.input-group {
    position: relative;
    display: flex;
    align-items: center;
}

.form-control {
    width: 100%;
    padding: 1rem 1rem 1rem 3rem;
    border: 2px solid var(--border-light);
    border-radius: var(--radius-lg);
    background: var(--bg-secondary);
    font-size: 1rem;
    transition: var(--transition);
    font-family: inherit;
}

/* Состояния поля ввода */
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--bg-primary);
    box-shadow: 0 0 0 3px rgb(124 58 237 / 0.1);
    transform: translateY(-1px);
}

.form-control:invalid {
    border-color: var(--error);
}

.input-icon {
    position: absolute;
    left: 1rem;
    color: var(--text-light);
    transition: var(--transition);
    z-index: 2;
}

.form-control:focus + .input-icon {
    color: var(--primary);
}

.password-toggle {
    position: absolute;
    right: 1rem;
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    transition: var(--transition);
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.password-toggle:hover {
    color: var(--primary);
    background: var(--bg-secondary);
}

/* ===== BUTTON STYLES ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem 2rem;
    border: none;
    border-radius: var(--radius-lg);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    position: relative;
    overflow: hidden;
    min-height: 44px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    width: 100%;
    box-shadow: var(--shadow-md);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-loading {
    pointer-events: none;
    opacity: 0.8;
}

.btn-loading::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid transparent;
    border-top: 2px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* ===== ALERT STYLES ===== */
.alert {
    padding: 1rem 1.25rem;
    border-radius: var(--radius-lg);
    margin-bottom: 1.5rem;
    border-left: 4px solid;
    animation: slideIn 0.3s ease-out;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: var(--transition);
}

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--error);
    color: var(--error);
}

.alert-success {
    background: rgba(16, 185, 129, 0.1);
    border-color: var(--success);
    color: var(--success);
}

/* ===== ERROR STYLES ===== */
.form-error {
    color: var(--error);
    font-size: 0.875rem;
    margin-top: 0.5rem;
    display: none;
    animation: slideIn 0.2s ease-out;
}

/* ===== FOOTER STYLES ===== */
.auth-footer {
    text-align: center;
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-light);
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-lg);
    min-height: 44px;
}

.back-link:hover {
    color: var(--primary);
    background: var(--bg-secondary);
    transform: translateX(-4px);
}

/* ===== ANIMATIONS ===== */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.loading {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* ===== ENHANCED MOBILE OPTIMIZATIONS ===== */

/* Small mobile devices */
@media (max-width: 480px) {
    .auth-container {
        padding: 0.5rem;
    }
    
    .auth-card {
        padding: 2rem 1.25rem;
        border-radius: 1.5rem;
        margin: 0.5rem;
    }
    
    .auth-title {
        font-size: 1.75rem;
    }
    
    .logo {
        width: 70px;
        height: 70px;
        font-size: 1.75rem;
    }
    
    .form-control {
        padding: 1.125rem 1rem 1.125rem 3rem;
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    .btn {
        padding: 1.125rem 2rem;
        font-size: 1.125rem;
    }
}

/* iPhone Notch Support */
@supports (padding: max(0px)) {
    .auth-container {
        padding-left: max(0.5rem, env(safe-area-inset-left));
        padding-right: max(0.5rem, env(safe-area-inset-right));
        padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
    }
}

/* Mobile-specific interactions */
@media (hover: none) and (pointer: coarse) {
    .btn-primary:hover {
        transform: none;
    }
    
    .auth-card:hover {
        transform: none;
    }
    
    .form-control:focus {
        transform: none;
    }
    
    /* Better feedback for touch */
    .btn-primary:active {
        transform: scale(0.98);
    }
    
    .back-link:active {
        background: var(--bg-secondary);
        transform: scale(0.95);
    }
}

/* Orientation specific styles */
@media (max-width: 768px) and (orientation: landscape) {
    .auth-container {
        padding: 0.25rem;
    }
    
    .auth-card {
        padding: 1.5rem 1.25rem;
        max-height: 90vh;
        overflow-y: auto;
    }
    
    .auth-header {
        margin-bottom: 1.5rem;
    }
    
    .logo {
        width: 50px;
        height: 50px;
        font-size: 1.5rem;
        margin-bottom: 1rem;
    }
}

/* High DPI mobile screens */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .logo {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* Reduced motion for mobile */
@media (prefers-reduced-motion: reduce) and (max-width: 768px) {
    .auth-card {
        transition: none;
    }
    
    .btn-primary {
        transition: none;
    }
    
    .form-control {
        transition: none;
    }
}

/* Mobile form improvements */
@media (max-width: 768px) {
    .input-group {
        position: relative;
    }
    
    .form-control {
        -webkit-appearance: none;
        border-radius: 12px;
    }
    
    /* Fix for iOS form styling */
    input[type="text"],
    input[type="password"] {
        border-radius: 12px;
        appearance: none;
    }
    
    /* Improve password manager integration */
    .form-control:-webkit-autofill {
        -webkit-box-shadow: 0 0 0px 1000px var(--bg-secondary) inset;
        -webkit-text-fill-color: var(--text-primary);
        border: 2px solid var(--primary);
    }
}

/* Very small screens */
@media (max-width: 360px) {
    .auth-card {
        padding: 1.5rem 1rem;
    }
    
    .auth-title {
        font-size: 1.5rem;
    }
    
    .role-badge {
        font-size: 0.75rem;
        padding: 0.375rem 1rem;
    }
    
    .btn {
        padding: 1rem 1.5rem;
    }
}

/* Foldable devices support */
@media (max-width: 320px) {
    .auth-container {
        min-height: 100vh;
        align-items: flex-start;
        padding-top: 1rem;
    }
}

/* ===== ACCESSIBILITY ENHANCEMENTS ===== */

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border-light: #000000;
        --text-primary: #000000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible for accessibility */
.form-control:focus-visible,
.btn:focus-visible,
.back-link:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}