/* ==========================================
   True Gallery — Styles v1.1.0
   ========================================== */

/* ==========================================
   Filters
   ========================================== */
.tg-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-bottom: 20px;
}

.tg-filter-btn {
    cursor: pointer;
    border: none;
    outline: none;
    padding: 8px 20px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    transition: all 0.3s ease;
    background-color: #f0f0f0;
    color: #333;
    border-radius: 6px;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}

.tg-filter-btn:hover {
    background-color: #555;
    color: #fff;
}

.tg-filter-btn.active {
    background-color: #333;
    color: #fff;
}

/* ==========================================
   Grid
   ========================================== */
.tg-gallery-grid {
    display: grid;
    grid-template-columns: repeat( var(--tg-cols, 3), 1fr );
    gap: 10px;
}

.tg-gallery-grid .tg-gallery-item {
    height: 280px;
}

/* ==========================================
   Masonry — оригинальные пропорции через <img>
   ========================================== */
.tg-gallery-masonry {
    column-count: var(--tg-cols, 3);
    column-gap: 10px;
    column-fill: balance;
}

.tg-gallery-masonry .tg-gallery-item {
    break-inside: avoid;
    -webkit-column-break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: 10px;
    height: auto;
    display: block;
    width: 100%;
    overflow: hidden;
}

.tg-gallery-masonry .tg-gallery-item img {
    display: block;
    width: 100%;
    height: auto;
    object-fit: cover;
    border-radius: inherit;
}

/* ==========================================
   Justified
   ========================================== */
.tg-gallery-justified {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.tg-gallery-justified .tg-gallery-item {
    flex-grow: 1;
    height: 250px;
    min-width: 160px;
}

/* ==========================================
   Carousel
   ========================================== */
.tg-gallery-carousel {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
}

.tg-carousel-track {
    display: flex;
    gap: inherit;
    overflow: hidden;
    width: 100%;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.tg-carousel-track .tg-gallery-item {
    min-width: calc( (100% - (var(--tg-carousel-cols, 3) - 1) * 10px ) / var(--tg-carousel-cols, 3) );
    flex-shrink: 0;
    height: 280px;
}

.tg-carousel-arrow {
    position: relative;
    z-index: 5;
    cursor: pointer;
    border: none;
    outline: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: rgba(0,0,0,0.5);
    flex-shrink: 0;
    transition: background 0.3s;
    -webkit-tap-highlight-color: transparent;
}

.tg-carousel-arrow:hover {
    background-color: rgba(0,0,0,0.8);
}

.tg-carousel-arrow svg {
    fill: #fff;
}

/* ==========================================
   Gallery Item — Base
   ========================================== */
.tg-gallery-item {
    position: relative;
    overflow: hidden;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    cursor: pointer;
    border-radius: 8px;
    transition: transform 0.4s ease, opacity 0.4s ease;
    -webkit-tap-highlight-color: transparent;
}

/* Overlay */
.tg-gallery-item .tg-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background-color: rgba(0,0,0,0.35);
    opacity: 0;
    transition: opacity 0.35s ease;
    padding: 12px;
    pointer-events: none;
}

.tg-gallery-item:hover .tg-overlay {
    opacity: 1;
}

/* ==========================================
   Hover Effects
   ========================================== */

/* Zoom */
.tg-hover-zoom {
    overflow: hidden;
}

.tg-hover-zoom::before {
    content: '';
    position: absolute;
    inset: 0;
    background: inherit;
    background-size: cover;
    background-position: center;
    transition: transform 0.5s ease;
    z-index: 0;
}

.tg-hover-zoom:hover::before {
    transform: scale(1.1);
}

.tg-hover-zoom .tg-overlay {
    z-index: 1;
}

/* Masonry zoom — img-based, not background */
.tg-gallery-masonry .tg-hover-zoom::before {
    display: none;
}

.tg-gallery-masonry .tg-hover-zoom img {
    transition: transform 0.5s ease;
}

.tg-gallery-masonry .tg-hover-zoom:hover img {
    transform: scale(1.1);
}

/* Fade */
.tg-hover-fade {
    transition: opacity 0.4s;
}

.tg-hover-fade:hover {
    opacity: 0.8;
}

/* Slide up */
.tg-hover-slide .tg-overlay {
    transform: translateY(100%);
    opacity: 1;
    transition: transform 0.4s ease;
}

.tg-hover-slide:hover .tg-overlay {
    transform: translateY(0);
}

/* ==========================================
   Filter Animation States
   ========================================== */
.tg-gallery-item.tg-hidden-fade,
.tg-gallery-item.tg-hidden-scale,
.tg-gallery-item.tg-hidden-none {
    opacity: 0;
    position: absolute !important;
    pointer-events: none;
    visibility: hidden;
    width: 0 !important;
    height: 0 !important;
    overflow: hidden;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
}

/* Masonry: must use display:none to fully remove from column flow */
.tg-gallery-masonry .tg-gallery-item.tg-hidden-fade,
.tg-gallery-masonry .tg-gallery-item.tg-hidden-scale,
.tg-gallery-masonry .tg-gallery-item.tg-hidden-none {
    display: none !important;
}

.tg-gallery-item.tg-visible-fade {
    opacity: 1;
    position: relative !important;
    visibility: visible;
    pointer-events: auto;
}

.tg-gallery-item.tg-visible-scale {
    transform: scale(1);
    position: relative !important;
    visibility: visible;
    pointer-events: auto;
}

.tg-gallery-item.tg-visible-none {
    position: relative !important;
    visibility: visible;
    pointer-events: auto;
}

/* Masonry: restore display:block when visible */
.tg-gallery-masonry .tg-gallery-item.tg-visible-fade,
.tg-gallery-masonry .tg-gallery-item.tg-visible-scale,
.tg-gallery-masonry .tg-gallery-item.tg-visible-none {
    display: block !important;
}

/* ==========================================
   Lightbox
   ========================================== */
.tg-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: rgba(0,0,0,0.92);
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.tg-lightbox.active {
    display: flex;
}

.tg-lb-image {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 4px;
    animation: tg-lb-in 0.3s ease;
    user-select: none;
    -webkit-user-drag: none;
}

@keyframes tg-lb-in {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
}

.tg-lb-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    color: #fff;
    font-size: 36px;
    cursor: pointer;
    line-height: 1;
    z-index: 10;
    transition: transform 0.2s;
    padding: 8px;
    -webkit-tap-highlight-color: transparent;
}

.tg-lb-close:hover {
    transform: scale(1.2);
}

.tg-lb-prev,
.tg-lb-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255,0.15);
    border: none;
    cursor: pointer;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s;
    z-index: 10;
    -webkit-tap-highlight-color: transparent;
}

.tg-lb-prev { left: 12px; }
.tg-lb-next { right: 12px; }

.tg-lb-prev:hover,
.tg-lb-next:hover {
    background: rgba(255,255,255,0.3);
}

.tg-lb-counter {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255,255,255,0.7);
    font-size: 14px;
    font-family: inherit;
}

/* ==========================================
   RESPONSIVE — Tablet (max-width: 1024px)
   ========================================== */
@media (max-width: 1024px) {
    /* Grid */
    .tg-gallery-grid {
        grid-template-columns: repeat( var(--tg-cols-tablet, 2), 1fr );
    }

    /* Masonry */
    .tg-gallery-masonry {
        column-count: var(--tg-cols-tablet, 2);
    }

    /* Justified */
    .tg-gallery-justified .tg-gallery-item {
        min-width: 140px;
        height: 200px;
    }

    /* Carousel */
    .tg-carousel-track .tg-gallery-item {
        min-width: calc( (100% - (var(--tg-carousel-tablet, 2) - 1) * 10px ) / var(--tg-carousel-tablet, 2) );
    }

    /* Filters — keep wrap on tablet, still fits */
    .tg-filter-btn {
        white-space: nowrap;
    }
}

/* ==========================================
   RESPONSIVE — Mobile (max-width: 767px)
   ========================================== */
@media (max-width: 767px) {
    /* Grid */
    .tg-gallery-grid {
        grid-template-columns: repeat( var(--tg-cols-mobile, 1), 1fr );
    }

    .tg-gallery-grid .tg-gallery-item {
        height: 220px;
    }

    /* Masonry */
    .tg-gallery-masonry {
        column-count: var(--tg-cols-mobile, 1);
    }

    /* Justified */
    .tg-gallery-justified .tg-gallery-item {
        min-width: 100px;
        height: 160px;
    }

    /* Carousel — 1 slide, hide arrows, swipe only */
    .tg-carousel-track {
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
    }

    .tg-carousel-track .tg-gallery-item {
        min-width: calc(100% - 0px);
        scroll-snap-align: start;
        height: 240px;
    }

    .tg-carousel-arrow {
        display: none;
    }

    /* Filters — touch carousel */
    .tg-filters {
        flex-wrap: nowrap;
        overflow-x: scroll;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
        scrollbar-width: none;
        justify-content: flex-start;
        padding: 6px 0;
        margin-left: -4px;
        margin-right: -4px;
        position: relative;
        /* Fade edges via mask */
        -webkit-mask-image: linear-gradient(
            to right,
            transparent 0%,
            black 8%,
            black 92%,
            transparent 100%
        );
        mask-image: linear-gradient(
            to right,
            transparent 0%,
            black 8%,
            black 92%,
            transparent 100%
        );
    }

    .tg-filters::-webkit-scrollbar {
        display: none;
    }

    .tg-filter-btn {
        flex-shrink: 0;
        white-space: nowrap;
        scroll-snap-align: center;
        font-size: 13px;
        padding: 6px 14px;
        /* Prevent text selection while dragging */
        user-select: none;
        -webkit-user-select: none;
    }

    /* Active filter indicator line */
    .tg-filters::after {
        content: '';
        flex-shrink: 0;
        width: 20px;
    }

    .tg-filters::before {
        content: '';
        flex-shrink: 0;
        width: 20px;
    }

    /* Lightbox — fullscreen mobile */
    .tg-lightbox {
        padding: 10px;
    }

    .tg-lb-image {
        max-width: 96vw;
        max-height: 80vh;
    }

    .tg-lb-prev,
    .tg-lb-next {
        width: 36px;
        height: 36px;
    }

    .tg-lb-prev { left: 6px; }
    .tg-lb-next { right: 6px; }

    .tg-lb-close {
        top: 8px;
        right: 8px;
        font-size: 30px;
    }

    .tg-lb-counter {
        bottom: 10px;
        font-size: 12px;
    }
}

/* ==========================================
   RESPONSIVE — Small mobile (max-width: 480px)
   ========================================== */
@media (max-width: 480px) {
    .tg-gallery-grid .tg-gallery-item {
        height: 180px;
    }

    .tg-gallery-justified .tg-gallery-item {
        min-width: 80px;
        height: 130px;
    }

    .tg-carousel-track .tg-gallery-item {
        height: 200px;
    }

    .tg-filter-btn {
        font-size: 12px;
        padding: 5px 12px;
    }
}
