/* =========================================================
   ФОТОГАЛЕРЕЯ: слайдер на карусели Bootstrap 5.3.
   Свой JS — только автопрокрутка (с учётом prefers-reduced-motion),
   ленивая подгрузка кадров и счётчик «N / M».
   Оформление — в единых токенах страницы (camp-tokens.css).
   ========================================================= */

/* Вырываем слайдер за пределы ограничений .container */
.gallery-wrapper {
    width: 100vw;
    margin-left: calc(50% - 50vw);
    border-radius: 0;
    box-shadow: none;
    background: #0d0d17; /* Чуть темнее, чтобы переход к размытому фону был мягче */
    transition: box-shadow var(--camp-transition);
}

/* Единая высота кадра. 16/9 — универсальная пропорция:
   и широкие, и квадратные фото смотрятся органично. */
.gallery-slide {
    aspect-ratio: 16 / 9;
    max-height: 80vh;
    background: #212529;      /* запасной цвет, пока не загрузилось фото */
    position: relative;
    overflow: hidden;         /* обрезаем размытый фон по границам слайда */
}

/* Размытый фон — та же фотография, но blur + darken.
   Путь к картинке подставляет JS через CSS-переменную --slide-bg. */
.gallery-slide::before {
    content: '';
    position: absolute;
    inset: -10%;              /* с запасом, чтобы края blur не были видны */
    background-image: var(--slide-bg, none);
    background-size: cover;
    background-position: center;
    background-color: #212529; /* если фото ещё нет — тёмный плейсхолдер */
    filter: blur(40px) brightness(0.8) saturate(1.2);
    transform: scale(1.1);    /* компенсируем inset и скрываем артефакты blur */
    z-index: 0;
    transition: background-image .4s ease;
}

/* Сама фотография — поверх размытого фона, целиком, без обрезки */
.gallery-slide-img {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    object-fit: contain;      /* ключевое изменение: показываем фото целиком */
}

/* Плавное появление кадра после догрузки */
.gallery-slide-img[data-src] {
    opacity: 0;
}

.gallery-slide-img.is-loaded {
    animation: galleryFadeIn .5s ease forwards;
}

@keyframes galleryFadeIn {
    from { opacity: 0; transform: scale(1.02); }
    to   { opacity: 1; transform: scale(1); }
}

/* ---- Счётчик поверх фото ---- */
.gallery-counter {
    z-index: 4;
    background: rgba(0, 0, 0, .55);
    backdrop-filter: blur(6px);
    font-size: .8rem;
    letter-spacing: .04em;
}

/* ---- Стрелки в фирменном стиле ---- */
.gallery-wrapper .carousel-control-prev,
.gallery-wrapper .carousel-control-next {
    width: 80px;
    opacity: 0;
    transition: opacity var(--camp-transition);
}

.gallery-wrapper:hover .carousel-control-prev,
.gallery-wrapper:hover .carousel-control-next {
    opacity: 1;
}

/* Сама кнопка-круг */
.gallery-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .15);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 2px solid rgba(255, 255, 255, .30);
    color: #fff;
    font-size: 1.3rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .30);
    transition: all .3s var(--camp-ease);
}

.gallery-arrow:hover {
    background: rgba(255, 255, 255, .25);
    border-color: rgba(255, 255, 255, .50);
    transform: scale(1.1);
    box-shadow: 0 12px 32px rgba(0, 0, 0, .40);
}

.gallery-arrow:active {
    transform: scale(0.95);
}

/* Иконка внутри */
.gallery-arrow i {
    transition: transform .2s ease;
}

.gallery-arrow--prev:hover i {
    transform: translateX(-2px);
}

.gallery-arrow--next:hover i {
    transform: translateX(2px);
}

/* Позиционирование стрелок */
.gallery-wrapper .carousel-control-prev {
    left: 20px;
}

.gallery-wrapper .carousel-control-next {
    right: 20px;
}

/* ---- Точки-индикаторы ---- */
.gallery-wrapper .carousel-indicators {
    margin-bottom: .75rem;
    gap: .4rem;
}

.gallery-wrapper .carousel-indicators [data-bs-target] {
    width: 10px;
    height: 10px;
    border: 0;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, .55);
    opacity: 1;
    transition: transform .2s ease, background-color .2s ease;
}

.gallery-wrapper .carousel-indicators .active {
    background: linear-gradient(135deg, var(--camp-orange) 0%, var(--camp-gold) 100%);
    transform: scale(1.3);
}

/* ---- Плейсхолдер: папка существует, но фото ещё не загрузили ---- */
.gallery-empty {
    aspect-ratio: 16 / 9;
    max-height: 70vh;
    border: 2px dashed #ced4da;
    border-radius: var(--camp-radius-card);
    background: #f8f9fa;
    color: var(--camp-muted);
}
/* =========================================================
   АДАПТИВ (Финальная версия для мобильных)
   ========================================================= */
@media (max-width: 767.98px) {
    /* 1. Убираем гигантские замыленные поля по высоте.
       Квадрат 1/1 — идеальный баланс, чтобы не было полос размытия
       ни у горизонтальных, ни у вертикальных фото. */
    .gallery-slide {
        aspect-ratio: 1 / 1;
        max-height: 65vh;
    }

    /* 2. Фикс свайпа: разрешаем браузеру корректно обрабатывать
       горизонтальные жесты внутри слайда, не перехватывая их как скролл. */
    .gallery-slide,
    .gallery-slide-img {
        touch-action: pan-y;
    }

    /* 3. Зоны нажатия стрелок: сбрасываем растягивание на всю высоту */
    .gallery-wrapper .carousel-control-prev,
    .gallery-wrapper .carousel-control-next {
        width: 20%;
        height: auto;          /* Сбрасываем top:0 / bottom:0 от Bootstrap */
        top: 50%;
        transform: translateY(-50%); /* Центрируем строго по вертикали */
        opacity: 1;
        padding: 0;
    }

    /* 4. Фикс огромных/растянутых кнопок: жестко задаем размеры кружка */
    .gallery-arrow {
        width: 40px !important;
        height: 40px !important;
        flex-shrink: 0;        /* Запрещаем flex-контейнеру растягивать кнопку */
        font-size: 1rem;
        border-width: 1px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, .30);
    }

    /* 5. Точки-индикаторы */
    .gallery-wrapper .carousel-indicators {
        gap: .3rem;
        margin-bottom: 1rem;
    }

    .gallery-wrapper .carousel-indicators [data-bs-target] {
        width: 10px;
        height: 10px;
    }
}
