/* ===== БАЗОВЫЕ СТИЛИ ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Скрываем scrollbar */
::-webkit-scrollbar {
    width: 0px;
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: transparent;
}

* {
    scrollbar-width: none;
}

:root {
    /* Цвета */
    --primary: #4f46e5;
    --primary-dark: #3730a3;
    --success: #059669;
    --warning: #d97706;
    --error: #dc2626;
    --text-primary: #111827;
    --text-secondary: #374151;
    --text-muted: #6b7280;
    --border: #d1d5db;
    --background: #ffffff;
    --surface: #ffffff;
    --surface-hover: #f9fafb;
    
    /* Тени */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    
    /* Переходы */
    --transition: 150ms ease-in-out;
    
    /* Радиусы */
    --radius: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    
    /* Шрифты */
    /* Inter с кириллицей как основной шрифт; SF Pro Display как дополнение на системах Apple */
    --font-family: 'Inter', 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, Arial, sans-serif;
    /* Адаптивные размеры шрифта */
    --fs-xs: clamp(12px, 0.25vw + 11px, 13px);
    --fs-sm: clamp(13px, 0.35vw + 12px, 14px);
    --fs-md: clamp(14px, 0.45vw + 13px, 16px);
    --fs-lg: clamp(16px, 0.70vw + 14px, 20px);
    --fs-xl: clamp(18px, 1.00vw + 15px, 24px);
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    font-size: var(--fs-md);
    font-weight: 400;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--background);
/* Шрифт и типографика для элементов формы */
input, button, textarea, select { font-family: inherit; font-size: inherit; }
label, small, .error-message, .success { font-size: var(--fs-sm); }
.app-header h1 { font-size: var(--fs-lg); }
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    margin: 0;
    padding: 0;
    height: 100vh;
    overflow: hidden;
}

.app-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--background);
}

/* ===== УВЕДОМЛЕНИЯ И ПРЕЛОАДЕР ===== */
.notifications-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.notification {
    padding: 10px 12px;
    border-radius: 10px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.08);
    color: #111827;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    font-weight: 500;
    min-width: 220px;
}

/* Better text wrapping for long messages */
.notification span { flex: 1; word-break: break-word; }

.notification.success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }

.notification.error { background: #fef2f2; color: #7f1d1d; border-color: #fecaca; }

.notification.warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }

/* Ensure info notifications are visible */
.notification.info { background: #eef2ff; color: #3730a3; border-color: #c7d2fe; }

.preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.preloader-spinner {
    font-size: 2rem;
    color: var(--primary);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ===== ЗАГОЛОВОК ===== */
.app-header {
    background: var(--primary);
    color: white;
    padding: clamp(12px, 2vw, 20px) clamp(16px, 3vw, 32px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-md);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-brand i { font-size: clamp(18px, 1.6vw, 24px); }

.header-brand h1 { font-size: var(--fs-lg); font-weight: 600; margin: 0; }

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.1);
    padding: 8px 16px;
    border-radius: var(--radius-lg);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.user-email { font-weight: 500; font-size: var(--fs-sm); }

.logout-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 6px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
}

.logout-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* ===== ФОРМА ВХОДА ===== */
.login-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(16px, 4vw, 40px);
    background: var(--background);
    z-index: 1000;
}

.login-card {
    background: var(--surface);
    border-radius: 20px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    padding: clamp(16px, 3.2vw, 28px);
    width: 100%;
    max-width: clamp(340px, 92vw, 560px);
    margin: 0;
    position: relative;
    transform: translateY(-5vh); /* Слегка смещаем вверх для лучшего визуального центрирования */
}

.login-header {
    text-align: center;
    margin-bottom: 1.75rem;
}

.login-header i {
    font-size: 3rem;
    color: var(--primary);
    margin-bottom: 1rem;
    display: block;
}

.login-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.login-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.input-group {
    margin-bottom: clamp(12px, 2.4vw, 18px);
}

.input-group:last-of-type {
    margin-bottom: 1.5rem;
}

.input-group label {
    display: block;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-wrapper i {
    position: absolute;
    left: 1rem;
    color: var(--text-muted);
    z-index: 1;
}

.input-wrapper input {
    width: 100%;
    padding: clamp(14px, 2.2vw, 18px) clamp(14px, 2.4vw, 20px);
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: var(--fs-md);
    background: #f6f7f9;
    transition: all var(--transition);
}

.input-wrapper input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.toggle-password {
    position: absolute;
    right: 1rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: var(--radius);
    transition: all var(--transition);
    z-index: 2;
}

.toggle-password:hover {
    color: var(--primary);
}

.fa-eye:before {
    display: none;
}

.error-message {
    display: block;
    color: var(--error);
    font-size: 0.875rem;
    margin-top: 0.5rem;
    min-height: 1rem;
}

.login-btn {
    width: 100%;
    background: #1d4ed8;
    color: #fff;
    border: none;
    padding: clamp(14px, 2.6vw, 18px);
    border-radius: 12px;
    font-size: var(--fs-md);
    font-weight: 700;
    cursor: pointer;
    transition: background var(--transition), transform var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: clamp(8px, 1.6vw, 12px);
}

.login-btn:hover { background: #1e40af; }

.login-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
/* === AUTH redesigned === */
.auth-card { border-radius: 16px; }
.auth-form { display: flex; flex-direction: column; gap: clamp(12px, 2.2vw, 18px); }
.auth-head { margin-bottom: clamp(6px, 1.2vw, 10px); }
.auth-title { font-size: var(--fs-xl); font-weight: 700; margin: 0 0 4px; }
.auth-subtitle { color: var(--text-secondary); font-size: var(--fs-sm); }
.auth-input-group { margin-bottom: 0; }
.auth-input-wrapper input::placeholder { color: #9aa3af; }
.auth-btn { background: #2563eb; }
.auth-btn:hover { background: #1d4ed8; }

/* Доступность: скрываем визуально, но оставляем для screen-reader */
.visually-hidden {
    position: absolute !important;
    height: 1px; width: 1px;
    overflow: hidden;
    clip: rect(1px, 1px, 1px, 1px);
    white-space: nowrap;
}

/* Сообщение об ошибке формы логина */
.form-alert {
    border: 1px solid #fecaca;
    background: #fef2f2;
    color: #7f1d1d;
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 6px;
    font-size: var(--fs-sm);
}


/* ===== ИНТЕРФЕЙС ПОЧТЫ ===== */
.mail-interface {
    display: flex;
    flex: 1;
    height: calc(100vh - 72px);
}

/* ===== САЙДБАР ===== */
.mail-sidebar {
    width: clamp(220px, 28vw, 300px);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: clamp(12px, 2vw, 24px);
    gap: clamp(8px, 1.6vw, 16px);
}

.compose-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: clamp(10px, 1.6vw, 14px) clamp(12px, 2vw, 16px);
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.compose-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.compose-btn:active {
    transform: translateY(0);
}

/* Пульсирующая анимация для кнопки "Написать" при первом входе */
.compose-btn.pulse {
    animation: composePulse 2s ease-in-out infinite;
}

@keyframes composePulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(79, 70, 229, 0);
    }
}

.folders {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.folder {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: clamp(10px, 1.6vw, 14px) clamp(12px, 2vw, 16px);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text-secondary);
}

.folder:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.folder.active {
    background: var(--primary);
    color: white;
}

.folder i {
    width: 16px;
    text-align: center;
}

.unread-count {
    margin-left: auto;
    background: var(--error);
    color: white;
    font-size: var(--fs-xs);
    font-weight: 600;
    padding: 0.125rem 0.375rem;
    border-radius: 50px;
    min-width: 16px;
    text-align: center;
    line-height: 1.2;
}

.folder.active .unread-count {
    background: rgba(255, 255, 255, 0.3);
}

.refresh-btn {
    margin-top: auto;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 0.75rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.refresh-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* ===== КОНТЕНТ ПОЧТЫ ===== */
.mail-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* ===== СПИСОК ПИСЕМ ===== */
.mail-list {
    flex: 1;
    overflow-y: auto;
    background: var(--surface);
    padding: clamp(10px, 2vw, 16px);
}

/* Видимые скроллбары в списке писем */
.mail-list { scrollbar-width: auto; }
.mail-list::-webkit-scrollbar { width: 8px; height: 8px; }
.mail-list::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; }
.mail-list::-webkit-scrollbar-track { background: transparent; }

.email-item {
    display: flex;
    align-items: center;
    padding: clamp(10px, 2vw, 16px);
    border-radius: var(--radius);
    border: 1px solid transparent;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--surface);
    position: relative;
}

.email-item:hover {
    background: var(--surface-hover);
    border-color: var(--border);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.email-item:active {
    transform: translateY(0);
    transition: transform 0.1s ease;
}

.email-item.unread {
    background: rgba(79, 70, 229, 0.05);
    border-color: rgba(79, 70, 229, 0.1);
    font-weight: 600;
}

.email-item.unread::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--primary);
    border-radius: 0 3px 3px 0;
}

/* Подсветка новых писем (появившихся при автообновлении) */
.email-item.new-email {
    animation: flashNew 1.6s ease-out 1;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.0);
    position: relative;
}

@keyframes flashNew {
    0% {
        background: #ecfdf5; /* светло-зеленый фон */
        border-color: #a7f3d0;
    }
    40% {
        background: #ffffff;
        border-color: #d1fae5;
    }
    60% {
        background: #f0fdf4;
        border-color: #bbf7d0;
    }
    100% {
        background: var(--surface);
        border-color: transparent;
    }
}

.email-from {
    width: clamp(140px, 22vw, 240px);
    font-weight: 600;
    color: var(--text-primary);
    margin-right: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-subject {
    flex: 1;
    margin-right: 1rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-item.unread .email-subject {
    color: var(--text-primary);
}

.email-date { width: 120px; color: var(--text-muted); font-size: var(--fs-sm); text-align: right; }

/* ===== АНИМАЦИЯ ЗАГРУЗКИ ПИСЕМ ===== */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: var(--text-muted);
    position: relative;
    min-height: 200px;
}

/* Современная анимация загрузки с пульсирующими точками */
.loading-emails {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: var(--text-secondary);
    position: relative;
    min-height: 200px;
}

.loading-icon {
    position: relative;
    margin-bottom: 2rem;
}

.loading-envelope {
    font-size: 2.5rem;
    color: var(--primary);
    animation: floatEnvelope 2s ease-in-out infinite;
    position: relative;
    z-index: 2;
}

.loading-dots {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.loading-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    animation: loadingDots 1.5s ease-in-out infinite;
}

.loading-dot:nth-child(1) { animation-delay: 0s; }
.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }

.loading-text {
    font-size: var(--fs-md);
    font-weight: 500;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.4;
    opacity: 0.8;
}

.loading-progress {
    width: 200px;
    height: 3px;
    background: rgba(79, 70, 229, 0.1);
    border-radius: 3px;
    margin-top: 1rem;
    overflow: hidden;
    position: relative;
}

.loading-progress::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, 
        transparent, 
        var(--primary), 
        transparent
    );
    animation: loadingProgress 1.8s ease-in-out infinite;
}

/* Анимации */
@keyframes floatEnvelope {
    0%, 100% {
        transform: translateY(0px) scale(1);
        opacity: 1;
    }
    50% {
        transform: translateY(-10px) scale(1.05);
        opacity: 0.9;
    }
}

@keyframes loadingDots {
    0%, 20%, 80%, 100% {
        transform: scale(1);
        opacity: 0.5;
    }
    50% {
        transform: scale(1.2);
        opacity: 1;
    }
}

@keyframes loadingProgress {
    0% {
        left: -100%;
    }
    50% {
        left: 0%;
    }
    100% {
        left: 100%;
    }
}

/* Скелетон анимация для списка писем */
.loading-skeleton {
    padding: 1rem;
}

.skeleton-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    margin-bottom: 0.5rem;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}

.skeleton-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, 
        transparent, 
        rgba(255, 255, 255, 0.6), 
        transparent
    );
    animation: skeletonShimmer 1.5s ease-in-out infinite;
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #e5e7eb;
    margin-right: 1rem;
    flex-shrink: 0;
}

.skeleton-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.skeleton-line {
    height: 12px;
    background: #e5e7eb;
    border-radius: 6px;
}

.skeleton-line.short {
    width: 60%;
}

.skeleton-line.medium {
    width: 80%;
}

.skeleton-line.long {
    width: 100%;
}

.skeleton-date {
    width: 80px;
    height: 12px;
    background: #e5e7eb;
    border-radius: 6px;
    margin-left: auto;
}

@keyframes skeletonShimmer {
    0% {
        left: -100%;
    }
    50% {
        left: 0%;
    }
    100% {
        left: 100%;
    }
}

/* Анимация появления писем */
.email-item.fade-in {
    animation: fadeInEmail 0.5s ease-out forwards;
    opacity: 0;
    transform: translateY(20px);
}

.email-item.fade-in:nth-child(1) { animation-delay: 0.1s; }
.email-item.fade-in:nth-child(2) { animation-delay: 0.2s; }
.email-item.fade-in:nth-child(3) { animation-delay: 0.3s; }
.email-item.fade-in:nth-child(4) { animation-delay: 0.4s; }
.email-item.fade-in:nth-child(5) { animation-delay: 0.5s; }

@keyframes fadeInEmail {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== СВАЙП ДЛЯ УДАЛЕНИЯ ===== */
.email-item {
    position: relative;
    overflow: hidden;
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.email-item.swiping {
    transition: none !important;
    z-index: 10;
}

.email-item.swipe-complete {
    transition: transform 0.3s ease-out, opacity 0.3s ease-out !important;
}

/* Фон для индикатора удаления */
.email-item::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 80px;
    height: 100%;
    background: linear-gradient(90deg, transparent, var(--error));
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    z-index: 1;
}

.email-item.swipe-active::after {
    opacity: 1;
}

/* Фон для индикатора восстановления (свайп вправо) */
.email-item.swipe-restore::after {
    left: 0;
    right: auto;
    background: linear-gradient(90deg, var(--success), transparent);
}

.email-item.swipe-restore.swipe-active::after {
    opacity: 1;
}

/* Иконка корзины для свайпа удаления */
.email-item.swipe-active::before {
    content: '\f2ed'; /* FontAwesome trash icon */
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    top: 50%;
    right: 25px;
    transform: translateY(-50%);
    color: white;
    font-size: 1.2rem;
    opacity: 0;
    animation: swipeTrashIcon 0.3s ease-out forwards;
    z-index: 2;
    pointer-events: none;
}

/* Иконка восстановления для свайпа вправо */
.email-item.swipe-restore.swipe-active::before {
    content: '\f0e2'; /* FontAwesome undo icon */
    left: 25px;
    right: auto;
    animation: swipeRestoreIcon 0.3s ease-out forwards;
}

@keyframes swipeTrashIcon {
    0% {
        opacity: 0;
        transform: translateY(-50%) scale(0.5);
    }
    100% {
        opacity: 1;
        transform: translateY(-50%) scale(1);
    }
}

@keyframes swipeRestoreIcon {
    0% {
        opacity: 0;
        transform: translateY(-50%) scale(0.5);
    }
    100% {
        opacity: 1;
        transform: translateY(-50%) scale(1);
    }
}

/* Анимация удаления после свайпа */
.email-item.deleting {
    animation: swipeDelete 0.4s ease-out forwards;
}

/* Анимация восстановления после свайпа */
.email-item.restoring {
    animation: swipeRestore 0.4s ease-out forwards;
}

@keyframes swipeDelete {
    0% {
        transform: translateX(0);
        opacity: 1;
        max-height: 100px;
    }
    50% {
        transform: translateX(-100%);
        opacity: 0.3;
        max-height: 100px;
    }
    100% {
        transform: translateX(-100%);
        opacity: 0;
        max-height: 0;
        margin-bottom: 0;
        padding-top: 0;
        padding-bottom: 0;
    }
}

@keyframes swipeRestore {
    0% {
        transform: translateX(0);
        opacity: 1;
        max-height: 100px;
    }
    50% {
        transform: translateX(100%);
        opacity: 0.3;
        max-height: 100px;
    }
    100% {
        transform: translateX(100%);
        opacity: 0;
        max-height: 0;
        margin-bottom: 0;
        padding-top: 0;
        padding-bottom: 0;
    }
}

/* Feedback для успешного свайпа */
.swipe-feedback {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--error);
    color: white;
    padding: 12px 24px;
    border-radius: 25px;
    font-weight: 500;
    font-size: var(--fs-sm);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    opacity: 0;
    animation: swipeFeedback 2s ease-out forwards;
    pointer-events: none;
}

@keyframes swipeFeedback {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    15% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    85% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
}

/* Старая анимация для совместимости */
.loading i {
    font-size: 2rem;
    margin-bottom: 1rem;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ===== EMPTY STATE ===== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    text-align: center;
    color: var(--text-primary);
    background: var(--surface);
    border-radius: var(--radius);
    margin: 2rem;
}

.empty-state i {
    font-size: 3rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.empty-state h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.empty-state p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    max-width: 300px;
    line-height: 1.5;
}

/* ===== ПРОСМОТР ПИСЬМА ===== */
.mail-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--surface);
}

.mail-view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: clamp(10px, 2vw, 16px);
    border-bottom: 1px solid var(--border);
}

.back-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: clamp(6px, 1.2vw, 10px) clamp(10px, 2vw, 16px);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
}

.back-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.mail-view-actions {
    display: flex;
    gap: 0.5rem;
}

.action-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 0.5rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    width: clamp(34px, 4.5vw, 40px);
    height: clamp(34px, 4.5vw, 40px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.delete-btn:hover {
    border-color: var(--error);
    color: var(--error);
}

.restore-btn:hover {
    border-color: var(--success);
    color: var(--success);
}

.reply-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* ===== ДЕТАЛИ ПИСЬМА ===== */
.mail-details {
    flex: 1;
    overflow-y: auto;
    padding: clamp(16px, 3vw, 32px);
}

/* Видимые скроллбары в области просмотра письма */
.mail-details { scrollbar-width: auto; }
.mail-details::-webkit-scrollbar { width: 8px; height: 8px; }
.mail-details::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; }
.mail-details::-webkit-scrollbar-track { background: transparent; }

.mail-meta {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.mail-subject { font-size: var(--fs-xl); font-weight: 700; color: var(--text-primary); margin-bottom: 1rem; line-height: 1.3; }

.mail-info {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.mail-from,
.mail-date {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
}

.mail-from i,
.mail-date i {
    color: var(--text-muted);
}

.mail-body { color: var(--text-primary); line-height: 1.6; font-size: var(--fs-md); word-wrap: break-word; }
.mail-body-frame { width: 100%; border: none; min-height: 400px; background: #fff; display: block; }

/* Поддержка HTML в письмах */
.mail-body * {
    max-width: 100%;
    word-wrap: break-word;
}

.mail-body img {
    max-width: 100%;
    height: auto;
}

.mail-body table {
    width: 100%;
    border-collapse: collapse;
}

.mail-body td,
.mail-body th {
    padding: 0.5rem;
    border: 1px solid var(--border);
}

/* ===== ФОРМА СОЗДАНИЯ ПИСЬМА ===== */
.compose-form {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    z-index: 10;
}

.compose-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.compose-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.compose-title i {
    color: var(--primary);
}

.compose-title h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.close-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.5rem;
    border-radius: var(--radius);
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    border-color: var(--error);
    color: var(--error);
}

.compose-body {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.compose-fields {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
}

.field-group {
    margin-bottom: 1rem;
}

.field-group label {
    display: block;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.field-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    background: var(--surface);
}

.field-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    background: var(--surface);
    resize: vertical;
    min-height: 200px;
}

.field-group input:focus,
.field-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.message-group {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.message-group textarea {
    flex: 1;
}

.compose-footer {
    padding: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.5rem;
}

.send-btn {
    background: var(--success);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.send-btn:hover {
    background: #047857;
    transform: translateY(-1px);
}

.send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.cancel-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.cancel-btn:hover {
    border-color: var(--error);
    color: var(--error);
}

/* ===== АДАПТИВНОСТЬ ===== */
@media (max-width: 768px) {
    body {
        overflow: auto;
    }
    
    .mail-interface {
        flex-direction: column;
        height: auto;
    }
    
    .mail-sidebar {
        width: 100%;
        height: auto;
        padding: 1rem;
        order: 2;
        border-right: none;
        border-top: 1px solid var(--border);
    }
    
    /* Адаптация анимации загрузки для мобильных */
    .loading-emails {
        padding: 2rem 1rem;
        min-height: 150px;
    }
    
    .loading-envelope {
        font-size: 2rem;
    }
    
    .loading-progress {
        width: 150px;
    }
    
    .skeleton-item {
        padding: 0.75rem;
    }
    
    .skeleton-avatar {
        width: 32px;
        height: 32px;
    }
    
    .folders {
        flex-direction: row;
        overflow-x: auto;
        gap: 0.5rem;
    }
    
    .folder {
        flex-shrink: 0;
        white-space: nowrap;
    }
    
    .compose-btn,
    .refresh-btn {
        display: none;
    }
    
    .mail-content {
        order: 1;
        min-height: 60vh;
    }
    
    .email-item {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    
    .email-from,
    .email-subject,
    .email-date {
        width: 100%;
    }
    
    .email-date {
        text-align: left;
        font-size: 0.8rem;
    }
    
    .mail-info {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .back-btn span {
        display: none;
    }
    
    .compose-footer {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .app-header {
        padding: 0.75rem 1rem;
    }
    
    .user-email {
        display: none;
    }
    
    .login-card { 
        padding: 20px; 
        margin: 0; 
        transform: translateY(-3vh); /* Меньшее смещение на мобильных */
        max-width: calc(100vw - 32px); /* Учитываем отступы контейнера */
    }
    
    .mail-details {
        padding: 1rem;
    }
}

/* ===== ТОНКАЯ НАСТРОЙКА ДЛЯ ОЧЕНЬ БОЛЬШИХ/МАЛЕНЬКИХ ЭКРАНОВ ===== */
@media (min-width: 1600px) {
    :root {
        --fs-sm: 15px;
        --fs-md: 17px;
        --fs-lg: 22px;
        --fs-xl: 26px;
    }
    .login-card { max-width: 640px; padding: 32px; }
    .input-wrapper input { padding: 18px 22px; }
    .login-btn { padding: 18px; }
}

@media (max-width: 360px) {
    :root {
        --fs-xs: 11.5px;
        --fs-sm: 12px;
        --fs-md: 13.5px;
        --fs-lg: 16px;
    }
    .login-container { padding: 12px; }
    .login-card { 
        border-radius: 14px; 
        padding: 16px; 
        transform: translateY(-2vh); /* Минимальное смещение на очень маленьких экранах */
        max-width: calc(100vw - 24px);
    }
    .input-wrapper input { padding: 12px 14px; border-radius: 10px; }
    .login-btn { padding: 12px; border-radius: 10px; }
    .notifications-container { top: 10px; right: 10px; gap: 6px; }
    .notification { min-width: 180px; padding: 8px 10px; }
}

/* ===== ОШИБКИ И УВЕДОМЛЕНИЯ ===== */
.error {
    color: var(--error);
    background: rgba(220, 38, 38, 0.1);
    border: 1px solid rgba(220, 38, 38, 0.2);
    padding: 0.75rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    text-align: center;
}

.success {
    color: var(--success);
    background: rgba(5, 150, 105, 0.1);
    border: 1px solid rgba(5, 150, 105, 0.2);
    padding: 0.75rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    text-align: center;
}
