/* Базовые переменные для светлой темы */
:root {
    /* Цветовая система */
    --color-bg: #ffffff;
    --color-surface: #f8f9fa;
    --color-surface-alt: #e9ecef;
    --color-text: #212529;
    --color-text-secondary: #6c757d;
    --color-border: #dee2e6;
    --color-primary: #0d6efd;
    --color-primary-hover: #0b5ed7;
    --color-success: #198754;
    --color-processing: #0dcaf0;
    --color-error: #dc3545;
    --color-warning: #ffc107;
    --color-preview-bg: #ffffff;
    --color-control-bg: #f1f3f5;
    --color-thumb-bg: #f8f9fa;
    --color-thumb-border: #dee2e6;
    --color-thumb-active: #e3f2fd;
    --color-thumb-active-border: #0d6efd;
    --color-sidebar-bg: #f8f9fa;
    --color-header-bg: #f8f9fa;
    
    /* Тени */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --shadow-inset: inset 0 2px 4px rgba(0,0,0,0.05);
    
    /* Анимации */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 350ms ease;
    
    /* Размеры */
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
}

/* Тёмная тема */
.dark-theme {
    --color-bg: #121212;
    --color-surface: #1e1e1e;
    --color-surface-alt: #2d2d2d;
    --color-text: #f8f9fa;
    --color-text-secondary: #adb5bd;
    --color-border: #404040;
    --color-primary: #90caf9;
    --color-primary-hover: #64b5f6;
    --color-success: #4caf50;
    --color-processing: #4fc3f7;
    --color-error: #f44336;
    --color-warning: #ffb300;
    --color-preview-bg: #2a2a2a;
    --color-control-bg: #363636;
    --color-thumb-bg: #2d2d2d;
    --color-thumb-border: #404040;
    --color-thumb-active: #1e3a5f;
    --color-thumb-active-border: #90caf9;
    --color-sidebar-bg: #1e1e1e;
    --color-header-bg: #1e1e1e;
    
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.25);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.35);
    --shadow-inset: inset 0 2px 4px rgba(0,0,0,0.2);
}

/* Сброс и базовые стили */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    transition: background-color var(--transition-base), color var(--transition-base);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* Контейнер */
.container {
    width: 100%;
    max-width: 800px;
    position: relative;
}

/* Переключатель темы (общий для всех состояний) */
.theme-toggle {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--color-text-secondary);
    transition: all var(--transition-fast);
    z-index: 10;
}

.theme-toggle:hover {
    background: var(--color-surface-alt);
    color: var(--color-primary);
    transform: rotate(15deg);
}

/* Основная карточка */
.converter-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 2px dashed var(--color-border);
    transition: all var(--transition-base);
    height: 600px;
    width: 100%;
    max-width: 800px;
    display: flex;
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
    margin: 0 auto;
}

.converter-card:hover:not(.processing):not(.result) {
    background: var(--color-surface-alt);
    box-shadow: var(--shadow-md);
}

.converter-card.dragover {
    background: var(--color-surface-alt);
    box-shadow: var(--shadow-lg);
}

/* Рамка ВСЕГДА остается пунктирной */
.converter-card.processing,
.converter-card.result {
    border: 2px dashed var(--color-border);
}

/* Общие стили состояний */
.state {
    width: 100%;
    padding: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 24px;
    box-sizing: border-box;
    height: 100%;
    overflow: hidden;
}

.state-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
    transition: transform var(--transition-base);
}

.state-initial .state-icon {
    background: linear-gradient(135deg, var(--color-primary) 0%, rgba(13, 110, 253, 0.1) 100%);
    color: white;
    font-size: 32px;
}

.state-processing .state-icon {
    background: linear-gradient(135deg, var(--color-processing) 0%, rgba(13, 202, 240, 0.1) 100%);
    color: white;
    font-size: 32px;
}

.state-result {
    padding: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
}

/* Верхняя панель навигации между файлами (только в состоянии результата) */
.file-navigation-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 145px;
    background: var(--color-header-bg);
    border-bottom: 1px solid var(--color-border);
    width: 100%;
    min-height: 70px;
    box-sizing: border-box;
}

.file-info-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex: 1;
    text-align: center;
    margin: 0 60px;
}

.file-counter-header {
    font-size: 18px;
    font-weight: 600;
    color: var(--color-primary);
}

.file-name-header {
    font-size: 14px;
    color: var(--color-text-secondary);
    max-width: 400px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Стрелки навигации между файлами */
.nav-arrow-top {
    background: transparent;
    border: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    opacity: 0.8;
    z-index: 10;
    display: none;
    width: 40px;
    height: 40px;
    position: relative;
}

.nav-arrow-top:hover {
    opacity: 1;
    color: var(--color-primary);
    transform: scale(1.1);
}

.nav-arrow-top i {
    font-size: 24px;
}

.state-title {
    font-size: 28px;
    font-weight: 600;
    color: var(--color-text);
    line-height: 1.2;
}

.state-subtitle {
    font-size: 18px;
    font-weight: 500;
    color: var(--color-text);
}

.state-hint {
    font-size: 14px;
    color: var(--color-text-secondary);
    margin-top: -16px;
}

/* Состояние 1: Начальное */
.quality-section {
    width: 100%;
    margin: 16px 0;
}

.quality-control {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.quality-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 15px;
    color: var(--color-text);
    margin-bottom: 8px;
}

.quality-value {
    font-weight: 600;
    color: var(--color-primary);
    min-width: 20px;
}

#qualityRange {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    background: linear-gradient(to right, 
        var(--color-border), 
        var(--color-primary));
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

#qualityRange::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--color-primary);
    cursor: pointer;
    border: 3px solid var(--color-surface);
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    transition: all var(--transition-fast);
}

#qualityRange::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 3px 8px rgba(0,0,0,0.3);
}

#qualityRange::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--color-primary);
    cursor: pointer;
    border: 3px solid var(--color-surface);
}

.quality-scale {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--color-text-secondary);
    padding: 0 2px;
}

/* Кнопка загрузки */
.btn-upload {
    background: var(--color-primary);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    border: none;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all var(--transition-fast);
    margin-top: 20px;
}

.btn-upload:hover {
    background: var(--color-primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.file-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--color-text-secondary);
    margin-top: 8px;
    padding: 8px 16px;
    background: var(--color-surface-alt);
    border-radius: var(--radius-sm);
}

.file-info i {
    color: var(--color-success);
}

/* Состояние 2: Обработка */
.file-meta {
    width: 100%;
    background: var(--color-surface-alt);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.meta-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.meta-label {
    font-size: 14px;
    color: var(--color-text-secondary);
}

.meta-value {
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text);
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.progress-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
}

#progressText {
    color: var(--color-text);
    font-weight: 500;
}

#progressPercent {
    color: var(--color-primary);
    font-weight: 600;
    font-family: 'SF Mono', monospace;
}

.progress-bar {
    height: 8px;
    background: var(--color-surface-alt);
    border-radius: 4px;
    overflow: hidden;
    margin: 4px 0;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-processing), var(--color-primary));
    border-radius: 4px;
    width: 0%;
    transition: width var(--transition-fast);
    position: relative;
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, 
        transparent, 
        rgba(255, 255, 255, 0.4), 
        transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.progress-details {
    font-size: 13px;
    color: var(--color-text-secondary);
    display: flex;
    justify-content: space-between;
}

/* Состояние 3: Результат - Новая структура */
.result-layout {
    display: flex;
    height: calc(100% - 70px);
    width: 100%;
}

/* Боковая панель с миниатюрами */
.sidebar {
    width: 140px;
    background: var(--color-sidebar-bg);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: relative;
}

/* Контейнер миниатюр */
.thumbnails-container {
    flex: 1;
    overflow-y: auto;
    position: relative;
    padding: 10px;
}

.thumbnails-wrapper {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 5px;
}

/* Миниатюра страницы */
.thumbnail {
    width: 100%;
    background: var(--color-thumb-bg);
    border: 2px solid var(--color-thumb-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    aspect-ratio: 0.7;
}

.thumbnail:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
    border-color: var(--color-primary);
}

.thumbnail.active {
    border-color: var(--color-thumb-active-border);
    background: var(--color-thumb-active);
    box-shadow: var(--shadow-md);
}

.thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: white;
    display: block;
}

.thumbnail-number {
    position: absolute;
    top: 5px;
    left: 5px;
    background: rgb(0 0 0 / 29%);
    color: white;
    font-size: 10px;
    font-weight: 500;
    padding: 1px 5px;
    border-radius: 3px;
    backdrop-filter: blur(4px);
}

.thumbnail.active .thumbnail-number {
    background: #484848;
}

/* Индикатор поворота */
.thumbnail-rotation {
    position: absolute;
    top: 5px;
    right: 5px;
    color: #ffffff;
    background: #a8a8a8;
    font-size: 8px;
    font-weight: 500;
    padding: 1px 4px;
    border-radius: 3px;
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    gap: 2px;
}

.thumbnail.active .thumbnail-rotation {
    background: #484848;
    color: var(--color-warning);
}

/* Контролы для каждой миниатюры */
.thumbnail-controls {
    position: absolute;
    bottom: 5px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 5px;
    padding: 5px;
    opacity: 0;
    transition: opacity var(--transition-fast);
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.thumbnail:hover .thumbnail-controls {
    opacity: 1;
}

.thumbnail-control-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #676767b3;
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    font-size: 12px;
}

.thumbnail-control-btn:hover {
    transform: scale(1.1);
}

.thumbnail-control-btn.rotate-btn {
    background: #5a67d8b3;
}

.thumbnail-control-btn.rotate-btn:hover {
    background: var(--color-processing);
}

.thumbnail-control-btn.download-btn {
    background: #48bb78b3;
}

.thumbnail-control-btn.download-btn:hover {
    background: var(--color-success);
}

.thumbnail-control-btn.delete-btn {
    background: #f56565b3;
}

.thumbnail-control-btn.delete-btn:hover {
    background: var(--color-error);
}

/* Основная область предпросмотра */
.main-preview {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
}

.preview-image-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-preview-bg);
    position: relative;
    overflow: hidden;
    padding: 20px;
}

.preview-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: transform var(--transition-base);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
}

/* Глобальные действия на месте preview-controls */
.main-actions {
    position: absolute;
    bottom: 35px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.95);
    padding: 6px 10px;
    border-radius: 50px;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(10px);
    z-index: 2;
}

.dark-theme .main-actions {
    background: rgba(30, 30, 30, 0.95);
}

.main-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    position: relative;
}

.main-btn i {
    font-size: 24px;
}

.main-btn.download-current {
    background: var(--color-primary);
    color: white;
}

.main-btn.download-current:hover {
    background: var(--color-primary-hover);
    transform: translateY(-2px) scale(1.1);
    box-shadow: 0 8px 20px rgba(13, 110, 253, 0.3);
}

.main-btn.download-all-jpg {
    background: var(--color-success);
    color: white;
}

.main-btn.download-all-jpg:hover {
    background: #198754;
    transform: translateY(-2px) scale(1.1);
    box-shadow: 0 8px 20px rgba(25, 135, 84, 0.3);
}

.main-btn.download-all-pdf {
    background: var(--color-error);
    color: white;
}

.main-btn.download-all-pdf:hover {
    background: #d32f2f;
    transform: translateY(-2px) scale(1.1);
    box-shadow: 0 8px 20px rgba(220, 53, 69, 0.3);
}

.main-btn.reset-converter {
    background: var(--color-surface-alt);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.main-btn.reset-converter:hover {
    background: var(--color-surface);
    transform: translateY(-2px) scale(1.1);
    box-shadow: var(--shadow-md);
}

/* Тултипы для кнопок - ИЗМЕНЕНО: выпадают вверх */
.main-btn {
    position: relative;
}

.main-btn::after {
    content: attr(title);
    position: absolute;
    top: -45px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
    pointer-events: none;
    z-index: 1000;
}

.dark-theme .main-btn::after {
    background: rgba(255, 255, 255, 0.95);
    color: #121212;
}

.main-btn:hover::after {
    opacity: 1;
    visibility: visible;
    top: -40px;
}

/* Убираем повторное всплывание при долгом удержании */
.main-btn:hover::after {
    animation: none;
}

/* Адаптивность */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .theme-toggle {
        top: 10px;
        right: 10px;
        width: 35px;
        height: 35px;
    }
    
    .converter-card {
        height: 450px;
        flex-direction: column;
    }
    
    .state {
        padding: 30px 20px;
        gap: 20px;
    }
    
    .state-icon {
        width: 64px;
        height: 64px;
        font-size: 24px;
    }
    
    .state-title {
        font-size: 24px;
    }
    
    .state-subtitle {
        font-size: 16px;
    }
    
    .state-result {
        padding: 0;
    }
    
    .file-navigation-header {
        min-height: 60px;
        padding: 10px 15px;
    }
    
    .file-info-center {
        margin: 0 50px;
    }
    
    .file-counter-header {
        font-size: 16px;
    }
    
    .file-name-header {
        font-size: 12px;
        max-width: 300px;
    }
    
    .nav-arrow-top {
        width: 35px;
        height: 35px;
    }
    
    .nav-arrow-top i {
        font-size: 20px;
    }
    
    .result-layout {
        flex-direction: column;
        height: calc(100% - 60px);
    }
    
    .sidebar {
        width: 100%;
        height: 130px;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
    }
    
    .thumbnails-container {
        margin-top: 0;
        margin-bottom: 0;
        padding: 8px;
    }
    
    .thumbnails-wrapper {
        flex-direction: row;
        gap: 8px;
        overflow-x: auto;
        padding: 5px;
    }
    
    .thumbnail {
        width: 70px;
        height: 90px;
        flex-shrink: 0;
        aspect-ratio: unset;
    }
    
    .thumbnail-controls {
        opacity: 1;
        padding: 3px;
        gap: 3px;
    }
    
    .thumbnail-control-btn {
        width: 22px;
        height: 22px;
        font-size: 10px;
    }
    
    .main-actions {
        bottom: 10px;
        padding: 12px 20px;
        gap: 15px;
    }
    
    .main-btn {
        width: 50px;
        height: 50px;
    }
    
    .main-btn i {
        font-size: 20px;
    }
    
    .main-btn::after {
        top: -40px;
        font-size: 11px;
        padding: 6px 10px;
    }
    
    .main-btn:hover::after {
        top: -35px;
    }
    
    .meta-value {
        max-width: 180px;
    }
}

@media (max-width: 480px) {
    .converter-card {
        height: 400px;
    }
    
    .file-navigation-header {
        min-height: 50px;
        padding: 8px 10px;
    }
    
    .file-info-center {
        margin: 0 40px;
    }
    
    .file-name-header {
        max-width: 200px;
    }
    
    .sidebar {
        height: 100px;
    }
    
    .thumbnail {
        width: 60px;
        height: 80px;
    }
    
    .main-actions {
        gap: 8px;
        padding: 10px 16px;
    }
    
    .main-btn {
        width: 45px;
        height: 45px;
    }
    
    .main-btn i {
        font-size: 18px;
    }
    
    .main-btn::after {
        font-size: 10px;
        padding: 4px 8px;
        top: -35px;
    }
    
    .main-btn:hover::after {
        top: -30px;
    }
}

/* Скрытие полосы прокрутки для миниатюр */
.thumbnails-container::-webkit-scrollbar {
    width: 4px;
}

.thumbnails-container::-webkit-scrollbar-track {
    background: transparent;
}

.thumbnails-container::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 2px;
}

.thumbnails-container::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-secondary);
}

/* Анимации для уведомлений */
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translate(-50%, -20px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

@keyframes slideUp {
    from {
        opacity: 1;
        transform: translate(-50%, 0);
    }
    to {
        opacity: 0;
        transform: translate(-50%, -20px);
    }
}

/* Уведомление об ошибке */
.error-notification {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-error);
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 1000;
    box-shadow: var(--shadow-md);
    animation: slideDown 0.3s ease;
}

.error-notification i {
    font-size: 18px;
}