/*
 * Custom Gallery — mosaic-gallery.css  v5.0
 * Классы: .cgal-gallery / .cgal-item / .cgal-inner / .cgal-img
 */

/* ── Сетка ──────────────────────────────────────── */
.cgal-gallery {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    max-width: 970px;
    margin: 0 auto;
    padding: 0;
}

/* ── Ячейка ─────────────────────────────────────── */
.cgal-item {
    height: 180px;
    border-radius: 6px;
    overflow: hidden;
    background: #f0f0f0;
    box-shadow: 0 2px 6px rgba(0,0,0,.08);
    transition: transform .25s ease, box-shadow .25s ease;
}

.cgal-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0,0,0,.16);
}

/* ── Ссылка ─────────────────────────────────────── */
.cgal-link {
    display: block;
    width: 100%;
    height: 100%;
    text-decoration: none;
}

/* ── Внутренний контейнер ───────────────────────── */
.cgal-inner {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* ── Псевдоэлемент blur-фона ────────────────────── */
/*   Срабатывает для вертикальных (.is-v)
     и широких горизонтальных (.is-wide)             */
.cgal-inner.blur-bg::before {
    content: '';
    position: absolute;
    inset: -15px;                       /* выходим за края, чтобы размытие не давало белых полос */
    background-image: var(--cgal-bg);
    background-size: cover;
    background-position: center;
    filter: blur(18px);
    transform: scale(1.05);
    opacity: .85;
    z-index: 0;
}

/* ── Картинка ───────────────────────────────────── */
.cgal-img {
    position: relative;
    z-index: 1;
    display: block;
    transition: transform .3s ease;
}

/* Обычное горизонтальное фото — заполняем весь квадрат */
.cgal-inner.is-h .cgal-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

/* Вертикальное — видна вся фотография, blur заполняет боковые полосы */
.cgal-inner.is-v .cgal-img {
    width: auto;
    height: 100%;
    max-width: 100%;
    object-fit: contain;
}

/* Широкое горизонтальное (панорама/узкое) — вся фотография видна,
   blur заполняет верхние/нижние полосы */
.cgal-inner.is-wide .cgal-img {
    width: 100%;
    height: auto;
    max-height: 100%;
    object-fit: contain;
}

.cgal-item:hover .cgal-img {
    transform: scale(1.04);
}

/* ── Анимация появления ─────────────────────────── */
.cgal-item {
    animation: cgal-fade .45s ease both;
}
.cgal-item:nth-child(1)  { animation-delay: .04s }
.cgal-item:nth-child(2)  { animation-delay: .08s }
.cgal-item:nth-child(3)  { animation-delay: .12s }
.cgal-item:nth-child(4)  { animation-delay: .16s }
.cgal-item:nth-child(5)  { animation-delay: .20s }
.cgal-item:nth-child(6)  { animation-delay: .24s }
.cgal-item:nth-child(7)  { animation-delay: .28s }
.cgal-item:nth-child(8)  { animation-delay: .32s }
.cgal-item:nth-child(n+9){ animation-delay: .36s }

@keyframes cgal-fade {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Адаптив ────────────────────────────────────── */

/* Планшет — 3 колонки */
@media (max-width: 991px) {
    .cgal-gallery { grid-template-columns: repeat(3, 1fr); }
    .cgal-item    { height: 160px; }
}

/* Телефон — 2 колонки */
@media (max-width: 767px) {
    .cgal-gallery {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    .cgal-item {
        height: 140px;
        border-radius: 4px;
    }
    /* На телефоне убираем hover-подъём */
    .cgal-item:hover { transform: none; box-shadow: 0 2px 6px rgba(0,0,0,.08); }
}

/* Маленький телефон */
@media (max-width: 480px) {
    .cgal-item { height: 120px; }
}

/* ── Lazy-loading shimmer ───────────────────────── */
.cgal-img:not([src]) ,
.cgal-img[src=""] {
    background: linear-gradient(90deg,#ececec 25%,#e0e0e0 50%,#ececec 75%);
    background-size: 200% 100%;
    animation: cgal-shimmer 1.4s infinite;
}
@keyframes cgal-shimmer {
    0%   { background-position: -200% 0 }
    100% { background-position:  200% 0 }
}

/* ── Фокус (доступность) ────────────────────────── */
.cgal-link:focus-visible {
    outline: 2px solid #0078d4;
    outline-offset: 2px;
}

/* ── Reduced motion ─────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .cgal-item, .cgal-img { animation: none; transition: none; }
    .cgal-item:hover      { transform: none; }
}


/* ═══════════════════════════════════════════════════
   ЛАЙТБОКС — BLUR-ФОН
   .cgal-lb-blur вставляется внутрь .fancybox__container
═══════════════════════════════════════════════════ */

.cgal-lb-blur {
    position: fixed;
    inset: 0;
    z-index: 0;                        /* под всем содержимым FancyBox */
    background-size: cover;
    background-position: center;
    filter: blur(40px);
    transform: scale(1.15);            /* убираем белые края от blur */
    opacity: 0;
    transition: opacity .4s ease, background-image .3s ease;
    pointer-events: none;
}

/* FancyBox backdrop делаем полупрозрачным, чтобы был виден blur */
.fancybox__container .fancybox__backdrop {
    background: rgba(0, 0, 0, 0.55) !important;
}

/* ═══════════════════════════════════════════════════
   ЛАЙТБОКС — TIKTOK РЕЖИМ
═══════════════════════════════════════════════════ */

/* Индикатор режима (всплывает снизу) */
.cgal-mode-hint {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    padding: 8px 22px;
    border-radius: 24px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 99999;
    opacity: 0;
    transition: opacity .25s ease, transform .25s ease;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.cgal-mode-hint.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* В вертикальном режиме — темнее фон */
.fancybox__container[data-cgal-mode="vertical"] .fancybox__backdrop {
    background: rgba(0, 0, 0, 0.72) !important;
}

/* Индикатор вертикального режима в углу */
.fancybox__container[data-cgal-mode="vertical"]::after {
    content: '↕';
    position: fixed;
    top: 16px;
    left: 16px;
    width: 34px;
    height: 34px;
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: #fff;
    font-size: 18px;
    line-height: 34px;
    text-align: center;
    border-radius: 50%;
    z-index: 99999;
    pointer-events: none;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* Индикатор горизонтального режима в углу */
.fancybox__container[data-cgal-mode="horizontal"]::after {
    content: '↔';
    position: fixed;
    top: 16px;
    left: 16px;
    width: 34px;
    height: 34px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: rgba(255,255,255,0.6);
    font-size: 18px;
    line-height: 34px;
    text-align: center;
    border-radius: 50%;
    z-index: 99999;
    pointer-events: none;
}

/* ═══════════════════════════════════════════════════
   REDUCED MOTION — отключаем анимации
═══════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
    .cgal-lb-blur         { transition: none; }
    .cgal-mode-hint       { transition: none; }
}