/* Reset styles and base settings */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background: #f8f9fa;
}

.container {
    max-width: 750px;
    margin: 0 auto;
    padding: 20px 20px;
    min-height: 100vh; /* Fallback для старых браузеров */
    min-height: 100dvh; /* Динамическая высота viewport */
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 24px;
}

header h1 {
    font-size: 2rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: #2c3e50;
}

header p {
    font-size: 1rem;
    color: #6c757d;
}

/* Main content */
main {
    flex: 1;
}

/* Upload area */
.upload-area {
    border: 2px dashed #dee2e6;
    border-radius: 8px;
    padding: 48px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: white;
}

.upload-area:hover {
    border-color: #007bff;
    background: #f8f9ff;
}

.upload-area.dragover {
    border-color: #007bff;
    background: #f8f9ff;
}

.upload-content {
    pointer-events: none;
}

.upload-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 16px;
    color: #6c757d;
}

.upload-area h2 {
    font-size: 1.25rem;
    margin-bottom: 8px;
    color: #495057;
    font-weight: 500;
}

.upload-area p {
    color: #6c757d;
    margin-bottom: 8px;
}

.browse-link {
    color: #007bff;
    text-decoration: none;
    font-weight: 500;
}

.browse-link:hover {
    text-decoration: underline;
}

.upload-area small {
    color: #adb5bd;
    font-size: 0.875rem;
}

/* Preview section */
.preview-section {
    margin-top: 16px;
    text-align: center;
}

.image-preview {
    margin-bottom: 16px;
    position: relative;
    display: inline-block; /* подстраивается под ширину содержимого: превью или галерея */
    max-width: 100%; /* не шире контейнера на мобильных */
}

/* В batch-режиме контейнер должен занимать доступную ширину,
   иначе shrink-to-fit сжимает сетку до одной колонки на мобилках */
.preview-section.is-batch .image-preview {
    display: block;
    width: 100%;
}

.image-preview img {
    max-width: 100%;
    max-height: 50dvh; /* Не выше половины экрана в обычном режиме */
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    display: block;
    margin: 0 auto 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    object-fit: contain;
}

/* В batch-режиме скрываем только основное превью */
.preview-section.is-batch #originalImage {
    display: none;
}
/* В batch-режиме показываем строку с именем выбранного файла */

.image-preview img:hover {
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.15);
}

.image-info {
    text-align: center;
    padding: 4px;
    font-size: 0.875rem;
    color: #6c757d;
    margin-bottom: 16px;
    font-weight: normal;
}

/* Thumbnails: single-row horizontal scroller */
.thumbnails {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    width: 100%;
    margin: 8px auto 0;
}

.thumbnails.dragover {
    outline: 2px dashed #007bff;
    outline-offset: 2px;
    background: #f8f9ff;
}

/* Галерея в batch-режиме: сетка, вертикальная прокрутка */
.preview-section.is-batch .thumbnails {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 8px;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 50dvh; /* максимум половина экрана по высоте */
    max-width: 100%; /* fallback, не шире экрана */
    max-width: min(75dvh, 100%);  /* максимум 75% высоты экрана, но не шире экрана */
    background: #e8eaec; /* мягкий серый фон */
    border-radius: 8px;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.3);
    padding: 8px;
    width: 100%; /* занимает доступную ширину контейнера */
    margin-bottom: 12px; /* промежуток над строкой имени, как у одиночного превью */
}

.thumbnail-item {
    position: relative;
    width: 72px;
    height: 72px;
    flex: 0 0 auto;
    border-radius: 8px;
    overflow: hidden;
    background: #f1f3f5;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.preview-section.is-batch .thumbnail-item {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1; /* квадратные карточки в сетке */
    flex: initial;
}

.thumbnail-item img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumbnail-item.is-first {
    outline: 2px solid #007bff;
}

/* Кнопка скачивания миниатюры */
.thumb-download-btn {
    position: absolute;
    right: 6px;
    bottom: 6px;
    width: clamp(0px, 28%, 36px);
    height: clamp(0px, 28%, 36px);
    border: none;
    border-radius: 25%;
    background: rgba(255,255,255,0.7);
    color: #007bff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.thumb-download-btn svg {
    width: 70%;
    height: 70%;
}

/* Кнопка удаления миниатюры */
.thumb-delete-btn {
    position: absolute;
    left: 6px;
    bottom: 6px;
    width: clamp(0px, 28%, 36px);
    height: clamp(0px, 28%, 36px);
    border: none;
    border-radius: 25%;
    background: rgba(255,255,255,0.7);
    color: #dc3545; /* красный акцент */
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.thumb-delete-btn:hover {
    background: rgba(255,255,255,0.9);
}

.thumb-delete-btn:active {
    transform: translateY(0);
}

.thumb-delete-btn:disabled {
    opacity: 0.6;
    cursor: default;
}

.thumb-delete-btn svg {
    width: 70%;
    height: 70%;
}

.thumb-download-btn:hover {
    background: #ffffff;
    transform: translateY(-1px);
}

.thumb-download-btn:active {
    transform: translateY(0);
}

.thumb-download-btn:disabled {
    opacity: 0.6;
    cursor: default;
}

/* New file button (refresh icon) */
.new-file-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
    z-index: 10;
}

/* Чуть ниже в batch-режиме, чтобы не налезала на галерею */
.preview-section.is-batch .new-file-btn {
    top: 12px;
}

/* Более выражённая тень для кнопки в batch-режиме */
.preview-section.is-batch .new-file-btn {
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
    background: rgba(255, 255, 255, 0.95);
}

.preview-section.is-batch .new-file-btn:hover {
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.34);
}

.new-file-btn:hover {
    background: rgba(255, 255, 255, 1);
    transform: scale(1.1);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
}

.new-file-btn:active {
    transform: scale(0.95);
}

.new-file-btn svg {
    width: 20px;
    height: 20px;
    color: #6c757d;
    transition: transform 0.2s ease;
}

.new-file-btn:hover svg {
    color: #007bff;
    transform: rotate(180deg);
}

/* Conversion controls */
.convert-controls {
    text-align: center;
    margin-bottom: 16px;
}

/* Main convert button */
.convert-btn {
    background: #007bff;
    color: white;
    border: none;
    padding: 14px 36px;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-block;
    min-width: 220px;
    box-shadow: 0 2px 10px rgba(0, 123, 255, 0.2);
    text-decoration: none;
}

.convert-btn:hover {
    background: #0056b3;
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(0, 123, 255, 0.3);
    text-decoration: none;
}

.convert-btn:active {
    transform: translateY(1px);
}

.convert-btn:disabled {
    background: #6c757d;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Footer */
footer {
    text-align: center;
    margin-top: 16px;
    color: #6c757d;
    font-size: 0.875rem;
}

/* Responsive design */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    header {
        margin-bottom: 12px;
    }
    
    header h1 {
        font-size: 1.75rem;
    }
    
    .upload-area {
        padding: 32px 15px;
    }
    
    .upload-icon {
        width: 40px;
        height: 40px;
    }
    
    .upload-area h2 {
        font-size: 1.125rem;
    }
    
    .preview-section {
        margin-top: 8px;
    }
    
    .image-preview {
        margin-bottom: 12px;
    }
    
    .image-preview img {
        max-height: 45dvh;
        width: 100%;
    }
    
    .image-info {
        margin-bottom: 12px;
    }

    .thumbnails {
        gap: 6px;
        max-width: 100%;
    }

    .preview-section.is-batch .thumbnails {
        grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
        max-width: 100%;
        width: 100%;
    }

    /* На мобиле: без подсветки и без имени файла в batch-режиме */
    .preview-section.is-batch .thumbnail-item.is-first {
        outline: none;
    }
    .preview-section.is-batch .image-info {
        display: none;
    }

    .thumbnail-item {
        width: 60px;
        height: 60px;
    }
    
    .convert-controls {
        margin-bottom: 12px;
    }
    
    .convert-btn {
        padding: 12px 24px;
        font-size: 0.95rem;
        min-width: 180px;
        width: 100%;
        max-width: 280px;
    }
    
    .new-file-btn {
        width: 44px;
        height: 44px;
        top: 6px;
        right: 12px;
    }
    
    .new-file-btn svg {
        width: 22px;
        height: 22px;
    }
    
    footer {
        margin-top: 12px;
    }
}

/* Desktop adjustments */
@media (min-width: 769px) {
    .preview-section.is-batch .new-file-btn {
        right: 30px; /* и в батч-режиме тоже */
    }
}

/* Loading animations */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #007bff;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
} 

/* Content sections (cards) */
.content-sections {
    margin-top: 76px;
}

.content-card {
    background: #ffffff;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 16px 16px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.04);
}

.content-card + .content-card {
    margin-top: 12px;
}

.content-card h2 {
    font-size: 1.125rem;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 8px;
}

.content-card p {
    color: #6c757d;
}

.content-card ol {
    padding-left: 18px;
    color: #495057;
}

/* FAQ */
.faq-card details {
    border-top: 1px solid #f1f3f5;
    padding: 10px 0;
}

.faq-card details:first-of-type {
    border-top: none;
}

.faq-card summary {
    cursor: pointer;
    list-style: none;
    color: #2c3e50;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.faq-card summary::-webkit-details-marker {
    display: none;
}

.faq-card details p {
    margin-top: 6px;
    color: #6c757d;
}

/* Click affordance for FAQ: chevron, hover and focus styles */
.faq-card summary::before {
    content: '▸';
    color: hsl(210, 11%, 71%);
    font-size: 1.5rem; /* slightly larger chevron */
    line-height: 1;
    width: 1.5rem;
    min-width: 1.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 1.5rem;
    transform-origin: 50% 50%;
    transition: transform 0.2s ease, color 0.2s ease;
}

.faq-card details[open] > summary::before {
    transform: rotate(90deg);
    color: #6c757d;
}

.faq-card summary:hover {
    color: #007bff;
}

.faq-card summary:focus-visible {
    outline: 2px solid #cfe2ff;
    outline-offset: 2px;
    border-radius: 6px;
}

/* Preserve hover color inside muted variant */
.content-sections.is-muted .faq-card summary:hover {
    color: #007bff;
}

@media (max-width: 768px) {
    .content-card {
        padding: 14px 14px;
    }
    .content-card h2 {
        font-size: 1.0625rem;
        margin-bottom: 6px;
    }

    /* Mobile styling for muted variant: bring back subtle cards */
    .content-sections.is-muted {
        display: block;
    }
    .content-sections.is-muted .content-card {
        background: #ffffff;
        border: 1px solid #e9ecef;
        border-radius: 8px;
        box-shadow: 0 2px 16px rgba(0,0,0,0.04);
        padding: 14px 14px;
    }
    .content-sections.is-muted .content-card + .content-card {
        margin-top: 12px;
    }
    .content-sections.is-muted .faq-card details {
        border-top: 1px solid #f1f3f5;
        padding: 10px 0;
    }
}

/* Muted variant: make content sections less prominent */
.content-sections.is-muted {
    display: grid;
    gap: 8px;
    align-items: start;
    align-content: start;
    justify-items: stretch;
}

.content-sections.is-muted .content-card {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 8px 0;
    align-self: start;
}

/* Remove adjacent top margins when in muted grid layout */
.content-sections.is-muted .content-card + .content-card {
    margin-top: 0;
}

.content-sections.is-muted .content-card h2 {
    font-size: 1rem;
    font-weight: 500;
    color: #6c757d;
    margin-bottom: 4px;
}

.content-sections.is-muted .content-card p,
.content-sections.is-muted .content-card ol {
    color: #6c757d;
}

.content-sections.is-muted .faq-card details {
    border-top: none;
    padding: 6px 0;
}

.content-sections.is-muted .faq-card summary {
    color: #495057;
    font-weight: 500;
}

@media (min-width: 992px) {
    .content-sections.is-muted {
        grid-template-columns: 1fr 1fr;
        grid-auto-rows: minmax(min-content, auto);
        align-items: start;
    }
    .content-sections.is-muted .faq-card {
        grid-column: 1 / -1;
    }
}