/* ==========================================
   СЧЁТЧИК ФОТО НА КАРТОЧКЕ
========================================== */

.gallery-photos-count {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.75);
    color: #ffffff;
    padding: 6px 12px;
    border-radius: 50px;
    font-size: 14px;
    font-weight: 600;
    backdrop-filter: blur(8px);
    z-index: 3;
    pointer-events: none;
}

.gallery-photos-count svg {
    width: 16px;
    height: 16px;
    opacity: 0.9;
}

.gallery-image {
    position: relative;
}

/* ==========================================
   МОДАЛЬНОЕ ОКНО ГАЛЕРЕИ
========================================== */

.gallery-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.96);
    z-index: 10000;
    padding: 20px;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    overflow: hidden;
    /* Отключаем все жесты браузера на модалке */
    touch-action: none;
    -ms-touch-action: none;
}

.gallery-modal.open {
    display: block;
}

/* Дополнительная защита для всех элементов внутри */
.gallery-modal * {
    touch-action: none;
    -ms-touch-action: none;
}

/* ==========================================
   ПРОСМОТРЩИК (ОБЛАСТЬ ДЛЯ КАРТИНКИ)
========================================== */

.gallery-viewer {
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 130px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    cursor: grab;
    touch-action: none;
    -ms-touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.gallery-viewer:active {
    cursor: grabbing;
}

.gallery-viewer img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    transform-origin: center center;
    transition: transform 0.15s ease;
    will-change: transform;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
}

/* Во время перетаскивания отключаем плавность */
.gallery-viewer.dragging img {
    transition: none;
}

/* ==========================================
   КНОПКА ЗАКРЫТИЯ
========================================== */

.gallery-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #ffffff;
    font-size: 32px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    transition: 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    padding: 0;
    line-height: 1;
}

.gallery-close:hover {
    background: var(--accent);
    color: var(--accent-text);
    transform: rotate(90deg);
}

/* ==========================================
   КНОПКИ-СТРЕЛКИ
========================================== */

.gallery-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #ffffff;
    font-size: 28px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    cursor: pointer;
    transition: 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 15;
    padding: 0;
    line-height: 1;
}

.gallery-nav:hover {
    background: var(--accent);
    color: var(--accent-text);
    border-color: var(--accent);
}

.gallery-prev {
    left: 20px;
}

.gallery-next {
    right: 20px;
}

.gallery-nav.hidden {
    display: none;
}

/* ==========================================
   ТУЛБАР (ЗУМ + СЧЁТЧИК)
========================================== */

.gallery-toolbar {
    position: absolute;
    bottom: 75px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(0, 0, 0, 0.7);
    padding: 10px 16px;
    border-radius: 50px;
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 15;
    touch-action: manipulation;
}

.gallery-tool {
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: #ffffff;
    font-size: 20px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    transition: 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}

.gallery-tool:hover {
    background: var(--accent);
    color: var(--accent-text);
}

.gallery-counter {
    color: #ffffff;
    font-size: 15px;
    font-weight: 600;
    min-width: 60px;
    text-align: center;
}

/* ==========================================
   МИНИАТЮРЫ
========================================== */

.gallery-thumbs {
    position: absolute;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    max-width: 90%;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 6px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
    z-index: 15;
    /* Разрешаем горизонтальный скролл миниатюр */
    touch-action: pan-x;
    -ms-touch-action: pan-x;
}

.gallery-thumbs::-webkit-scrollbar {
    height: 4px;
}

.gallery-thumbs::-webkit-scrollbar-track {
    background: transparent;
}

.gallery-thumbs::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
}

.gallery-thumb {
    flex-shrink: 0;
    width: 70px;
    height: 50px;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: 0.2s;
    opacity: 0.5;
    background: #000;
    touch-action: manipulation;
}

.gallery-thumb:hover {
    opacity: 0.8;
}

.gallery-thumb.active {
    border-color: var(--accent);
    opacity: 1;
}

.gallery-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
}

/* ==========================================
   ПОДПИСЬ
========================================== */

.gallery-caption {
    position: absolute;
    bottom: 130px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.85);
    font-size: 15px;
    text-align: center;
    max-width: 80%;
    padding: 0 20px;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
    z-index: 5;
    pointer-events: none;
}

/* ==========================================
   МОБИЛЬНАЯ ВЕРСИЯ
========================================== */

@media (max-width: 768px) {
    .gallery-modal {
        padding: 10px;
    }

    .gallery-viewer {
        top: 55px;
        bottom: 120px;
    }

    .gallery-close {
        top: 10px;
        right: 10px;
        width: 44px;
        height: 44px;
        font-size: 26px;
    }

    .gallery-nav {
        width: 44px;
        height: 44px;
        font-size: 20px;
    }

    .gallery-prev {
        left: 10px;
    }

    .gallery-next {
        right: 10px;
    }

    .gallery-toolbar {
        bottom: 70px;
        padding: 8px 12px;
        gap: 8px;
    }

    .gallery-tool {
        width: 32px;
        height: 32px;
        font-size: 18px;
    }

    .gallery-counter {
        font-size: 13px;
        min-width: 50px;
    }

    .gallery-thumb {
        width: 55px;
        height: 40px;
    }

    .gallery-thumbs {
        bottom: 12px;
        padding: 5px;
    }

    .gallery-caption {
        bottom: 115px;
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .gallery-nav {
        display: none;
    }

    .gallery-viewer {
        top: 55px;
        bottom: 110px;
    }

    .gallery-thumbs {
        bottom: 10px;
        padding: 5px;
    }

    .gallery-thumb {
        width: 48px;
        height: 36px;
    }

    .gallery-toolbar {
        bottom: 65px;
        padding: 6px 10px;
    }

    .gallery-caption {
        bottom: 105px;
        font-size: 12px;
    }
}