/* Переменные для удобной настройки стилей */
:root {
    --preview-bg-color: rgba(0, 0, 0, 0.95); /* Еще темнее фон */
    --image-border-radius: 8px;
    --image-box-shadow: 0 4px 30px rgba(0, 0, 0, 0.8);
    --title-color: #fff;
    
    --main-font-family: 'Rubik', sans-serif;
    
    /* Навигация */
    --nav-zone-width: 8%; 
    --nav-arrow-color: #fbd38d; 
    --nav-hover-bg: rgba(255, 255, 255, 0.08); 
    
    --thumb-border-color: #fbd38d;
    --thumb-inactive-opacity: 0.5;
}

/* Общие стили для контейнера превью */
.image-preview-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--preview-bg-color);
    backdrop-filter: blur(5px);
    display: flex;
    flex-direction: column;
    justify-content: flex-start; /* Контент сверху вниз */
    align-items: center; /* Центрирование по горизонтали */
    z-index: 99999;
    cursor: zoom-out; 
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
    user-select: none;
    padding-top: 0; /* Убрали отступ сверху, будем регулировать маржинами */
}

.image-preview-container.is-active {
    opacity: 1;
    visibility: visible;
}

/* === ЗАГОЛОВОК === */
.preview-title {
    color: var(--title-color);
    text-align: center;
    margin: 15px 0 10px 0; /* Отступ сверху и снизу */
    font-size: 1.5em;
    font-family: var(--main-font-family);
    font-weight: 400;
    letter-spacing: 1px;
    text-transform: uppercase;
    flex-shrink: 0;
    transform: translateY(-20px);
    opacity: 0;
    transition: transform 0.3s ease-out, opacity 0.3s ease-out;
    z-index: 30;
    max-width: 90%;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}

.image-preview-container.is-active .preview-title {
    transform: translateY(0);
    opacity: 1;
}

/* === ИЗОБРАЖЕНИЕ И ВИДЕО === */
.image-preview-img,
.image-preview-video {
    /* (!!) ГЛАВНЫЕ ИЗМЕНЕНИЯ ДЛЯ МАСШТАБА */
    flex: 1; /* Занимать все свободное место по высоте */
    min-height: 0; /* Важно для Flexbox, чтобы элемент мог сжиматься */
    
    /* Размеры для ПК */
    width: auto;
    height: auto;
    max-width: 100%; /* Было 85%, стало 100% для полного использования ширины */
    max-height: 85vh; /* Ограничение по высоте, чтобы влезли тамбнейлы */
    
    object-fit: contain; /* Сохранять пропорции, не обрезать */
    
    border-radius: var(--image-border-radius);
    box-shadow: var(--image-box-shadow);
    
    flex-shrink: 1;
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), opacity 0.15s ease;
    
    z-index: 10;
    cursor: default;
}

.image-preview-img {
    cursor: zoom-out;
}

/* Скрываем неактивный элемент */
.media-hidden {
    display: none !important;
}

.image-preview-container.is-active .image-preview-img,
.image-preview-container.is-active .image-preview-video {
    transform: scale(1);
}

/* === Прогресс-бар === */
.preview-video-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0%; 
    height: 3px; /* Чуть толще для мобильных */
    background-color: #fbd38d; 
    z-index: 50;
    transition: width 0.1s linear; 
    pointer-events: none; 
    box-shadow: 0 -1px 5px rgba(251, 211, 141, 0.5); /* Свечение */
}

/* === НАВИГАЦИЯ (Стрелки и Зоны) === */
.preview-nav-zone {
    position: absolute;
    top: 0;
    bottom: 0;
    width: var(--nav-zone-width);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 20;
    transition: background 0.3s ease;
}

.preview-nav-left { left: 0; }
.preview-nav-left:hover { background: linear-gradient(to right, var(--nav-hover-bg), transparent); }

.preview-nav-right { right: 0; }
.preview-nav-right:hover { background: linear-gradient(to left, var(--nav-hover-bg), transparent); }

.preview-nav-zone.hidden { display: none !important; }

.nav-arrow {
    width: 50px;
    height: 50px;
    opacity: 0.6; 
    transition: opacity 0.2s, transform 0.2s;
    fill: none;
    stroke: var(--nav-arrow-color);
    stroke-width: 2;
    stroke-linecap: round; 
    stroke-linejoin: round;
    filter: drop-shadow(0 0 3px rgba(0,0,0,0.8));
}

.preview-nav-zone:hover .nav-arrow {
    opacity: 1;
    transform: scale(1.2);
}

/* === МИНИАТЮРЫ (Снизу) === */
.preview-thumbnails-wrapper {
    /* Прибиваем к низу, но над прогресс-баром */
    position: relative; 
    margin-top: auto; /* Flexbox trick: отодвинуть в самый низ */
    margin-bottom: 10px;
    
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 10px;
    z-index: 20;
    padding: 5px 20px;
    box-sizing: border-box;
    overflow-x: auto;
    scrollbar-width: none; 
    -ms-overflow-style: none;
    min-height: 90px; /* Резервируем место */
}
.preview-thumbnails-wrapper::-webkit-scrollbar { display: none; }
.preview-thumbnails-wrapper.hidden { display: none !important; }

.preview-thumb {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 6px;
    cursor: pointer;
    opacity: var(--thumb-inactive-opacity);
    border: 2px solid transparent;
    transition: all 0.2s ease;
    flex-shrink: 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
}

.preview-thumb:hover { opacity: 0.9; transform: translateY(-2px); }
.preview-thumb.active { opacity: 1; border-color: var(--thumb-border-color); transform: scale(1.05); }

/* === СТИЛИ ДЛЯ ЛУПЫ === */
.magnifier-icon {
    opacity: 0;
    position: absolute;
    top: 20%;
    left: 15%;
    transform: translate(-50%, -50%);
    z-index: 10;
    cursor: pointer;
    width: clamp(25px, 15%, 50px);
    aspect-ratio: 1 / 1;
   /*  background-color: rgba(30, 30, 30, 0.8); */
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.2s ease-in-out;
}
.magnifier-icon:hover svg { transform: scale(1.8); transition: transform 0.2s ease; }
.fabric-item:hover .magnifier-icon, .bccgc-item:hover .magnifier-icon { opacity: 1 !important; }

/* === (!!) АДАПТАЦИЯ (Мобильные) === */
@media (max-width: 768px) {
    /* Логика для мобильных:
       1. Видео и фото растягиваем на 100% ширины.
       2. Высоту ставим auto, чтобы сохранить пропорции (aspect ratio).
       3. Max-height ограничиваем, чтобы оставалось место для меню снизу.
    */
    .image-preview-img, 
    .image-preview-video {
        width: 100%;      /* Растянуть на всю ширину */
        max-width: 100%;  /* Убрать ограничения */
        height: auto;     /* Высота подстроится под ширину */
        max-height: 70vh; /* Ограничим высоту, чтобы не перекрыть тамбнейлы */
        border-radius: 0; /* Уберем скругления для полного погружения */
        background: #000; /* Черный фон для видео 16:9 */
    }
    
    .preview-title { font-size: 1.1em; margin: 10px 0; }
    
    /* Зоны навигации чуть шире, но невидимы */
    .preview-nav-zone { width: 15%; }
    .preview-nav-zone:hover { background: none; }
    .nav-arrow { opacity: 0.8; width: 30px; height: 30px; }
    
    .preview-thumbnails-wrapper { 
        justify-content: flex-start; /* Скролл влево */
        padding-left: 15px; 
        margin-bottom: 20px;
    }

    /* (!!) FIX: Всегда показывать лупу на мобильных */
    .magnifier-icon {
        opacity: 1 !important;
        visibility: visible;
    }
}

/* Кнопка закрытия (крестик) */
.preview-close {
    position: absolute;
    top: 40px;
    right: 300px;
    width: 40px;
    height: 40px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 100;
    transition: background 0.2s ease, transform 0.2s ease;
    border: 1px solid rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(4px);
}

.preview-close:hover {
    background: rgba(0, 0, 0, 0.9);
    transform: scale(1.05);
}

.preview-close svg {
    width: 20px;
    height: 20px;
    stroke: #fff;
    stroke-width: 2;
}

/* На мобильных чуть меньше и выше, чтобы не мешать */
@media (max-width: 768px) {
    .preview-close {
        top: 60px;
        right: 20px;
        width: 36px;
        height: 36px;
    }
    .preview-close svg {
        width: 18px;
        height: 18px;
    }
}