/* ============================================
   REFERENZEN.HTML — Filter Grid + Lightbox
   ============================================ */

.ref-section {
    padding-top: clamp(2rem, 4vw, 4rem);
}

/* ========== FILTER BAR ========== */
.ref-filter-bar {
    position: sticky;
    top: var(--nav-height);
    z-index: 40;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.55rem;
    margin: 0 auto 3rem;
    max-width: 1000px;
    padding: 0.75rem 0;
    background: rgba(20, 18, 17, 0.95);
    backdrop-filter: blur(20px) saturate(1.4);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    will-change: transform;
}

.ref-filter-chip {
    padding: 0.65rem 1.35rem;
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.04em;
    color: var(--text-body);
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    background: linear-gradient(to bottom,
                    rgba(240, 232, 217, 0.04),
                    rgba(240, 232, 217, 0.01));
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: inset 0 1px 0 rgba(240, 232, 217, 0.06),
                0 2px 6px var(--shadow-sm);
    cursor: pointer;
    transition: all 0.3s var(--ease);
}

.ref-filter-chip:hover {
    border-color: var(--accent-40);
    color: var(--text);
}

.ref-filter-chip.active {
    background: linear-gradient(to bottom, var(--accent-light), var(--accent-hover));
    border-color: var(--accent-60);
    color: #fff;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2),
                0 3px 10px var(--accent-25);
}

/* ========== GRID ========== */
.ref-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    /* Eigene Transition-Gruppe damit Grid-Höhe smooth gemorpht wird
       (sonst snappt die Höhe beim Filter-Klick). */
    view-transition-name: ref-grid;
}

/* Längeres + weicheres Timing für alle Tile-Morphs beim Filter-Klick
   (Browser-Default ist 250ms ease, hier 350ms ease-out). */
::view-transition-group(*) {
    animation-duration: 350ms;
    animation-timing-function: ease-out;
}

@media (min-width: 560px) {
    .ref-grid { grid-template-columns: 1fr 1fr; gap: 1.1rem; }
}

@media (min-width: 900px) {
    .ref-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1200px) {
    .ref-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Wrapper — Entry-Animation via animation-timeline */
.ref-tile-wrap {
    opacity: 0;
    transform: translateY(32px);
    /* Kein filter:blur auf dem Grid — bei 27 Tiles gleichzeitig scroll-animiert
       wird's zum Rendering-Killer. opacity + translateY reicht visuell. */
}

@keyframes ref-tile-enter {
    from { opacity: 0; transform: translateY(32px); }
    to   { opacity: 1; transform: translateY(0); }
}

@supports (animation-timeline: view()) {
    .ref-tile-wrap {
        animation: ref-tile-enter linear both;
        animation-timeline: view();
        animation-range: entry 0% cover 30%;
    }
}

@supports not (animation-timeline: view()) {
    .ref-tile-wrap {
        opacity: 1;
        transform: none;
    }
}

/* Ref-Tile Wrapper sits inside grid — inherits grid-column from tile's modifier */
.ref-tile-wrap--wide {
    grid-column: span 1;
}

@media (min-width: 900px) {
    .ref-tile-wrap--wide { grid-column: span 2; }
}

/* Tile: no entry state, only hover interaction */
.ref-tile {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--radius-md);
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    isolation: isolate;
    box-shadow: var(--depth-rest);
    border: 1px solid var(--border);
    background: var(--bg-surface);
    display: block;
    cursor: pointer;
    transition:
        transform 0.5s var(--ease),
        border-color 0.4s var(--ease),
        box-shadow 0.4s var(--ease);
}

.ref-tile::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--glass-highlight);
    pointer-events: none;
    z-index: 2;
}

/* Wide modifier — wrapper gets grid-span, tile gets aspect */
@media (min-width: 900px) {
    .ref-tile-wrap--wide .ref-tile { aspect-ratio: 2/1; }
}

.ref-tile-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
}

.ref-tile-bg img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: brightness(0.85) contrast(1.05) saturate(0.95);
    transition: transform 1.2s var(--ease), filter 0.7s var(--ease);
}

.ref-tile-overlay {
    position: absolute;
    inset: 0;
    z-index: 1;
    background: linear-gradient(to top,
        rgba(20, 18, 17, 0.85) 0%,
        rgba(20, 18, 17, 0.4) 35%,
        rgba(20, 18, 17, 0.1) 70%,
        transparent 100%);
    opacity: 0.7;
    transition: opacity 0.5s var(--ease);
}

.ref-tile-tag {
    position: absolute;
    left: 1rem;
    bottom: 1rem;
    z-index: 3;
    padding: 0.35rem 0.85rem;
    border-radius: var(--radius-pill);
    background: rgba(20, 18, 17, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-light);
}

@media (hover: hover) and (min-width: 1025px) {
    .ref-tile:is(:hover, .sticky-hover) {
        transform: scale(1.015);
        border-color: var(--accent-25);
        box-shadow: var(--depth-hover), var(--depth-glow);
    }
    .ref-tile:is(:hover, .sticky-hover) .ref-tile-bg img {
        transform: scale(1.05);
    }
    .ref-tile:is(:hover, .sticky-hover) .ref-tile-overlay {
        opacity: 1;
    }
}

.ref-tile-wrap[hidden],
.ref-tile[hidden] { display: none !important; }

.ref-empty {
    text-align: center;
    padding: 4rem 0;
    color: var(--text-muted);
    font-size: 15px;
}

/* ========== LIGHTBOX — Spangler-Pattern (3-Slide-Carousel) ========== */
.lb-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(14, 12, 10, 0.97);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s var(--ease), visibility 0.4s;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.lb-backdrop.active {
    opacity: 1;
    visibility: visible;
}

/* Viewport: 3-Slide-Container mit scale-in beim Öffnen */
.lb-viewport {
    position: relative;
    width: 90vw;
    height: 85vh;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    touch-action: pan-y;
    cursor: default;
    transform: scale(0.94);
    transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

.lb-backdrop.active .lb-viewport {
    transform: scale(1);
}

/* Track: hält 3 Slides (prev, current, next), navigiert per translateX */
.lb-track {
    display: flex;
    width: 100%;
    height: 100%;
    transform: translateX(-100%);
    transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
    will-change: transform;
}

.lb-track.lb-no-transition {
    transition: none;
}

.lb-slide {
    flex: 0 0 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.5rem;
    overflow: hidden;
}

.lb-slide img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
    opacity: 0;
    transform-origin: center center;
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
    -webkit-user-drag: none;
}

.lb-slide img.lb-loaded {
    opacity: 1;
}

.lb-slide img.lb-zoomed {
    transform: scale(2);
    cursor: zoom-out;
}

/* Buttons */
.lb-close,
.lb-prev,
.lb-next {
    position: fixed;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(240, 230, 216, 0.75);
    background: rgba(20, 18, 17, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(240, 232, 217, 0.12);
    padding: 0;
    cursor: pointer;
    transition: color 0.3s var(--ease), background 0.3s var(--ease), border-color 0.3s var(--ease);
    z-index: 10001;
    -webkit-tap-highlight-color: transparent;
}

.lb-close:hover,
.lb-prev:hover,
.lb-next:hover {
    color: rgba(240, 230, 216, 1);
    background: rgba(20, 18, 17, 0.9);
    border-color: rgba(240, 232, 217, 0.28);
}

.lb-close {
    top: 1.5rem;
    right: 1.5rem;
    width: 48px;
    height: 48px;
    border-radius: 50%;
}

.lb-prev,
.lb-next {
    top: 50%;
    transform: translateY(-50%);
    width: 56px;
    height: 56px;
    border-radius: 50%;
}

.lb-prev { left: 1.5rem; }
.lb-next { right: 1.5rem; }

/* Counter */
.lb-counter {
    position: fixed;
    bottom: 3.5rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-family: var(--font-serif);
    font-size: 14px;
    letter-spacing: 0.08em;
    color: rgba(240, 230, 216, 0.6);
    z-index: 10001;
    pointer-events: none;
    font-variant-numeric: tabular-nums;
}

.lb-counter-num {
    line-height: 1;
}

.lb-counter-sep {
    display: inline-block;
    width: 22px;
    height: 1px;
    background: rgba(240, 230, 216, 0.35);
}

/* Thumbnail-Strip — nur bei 5+ Bildern (via JS .active/has-thumbs Klassen) */
.lb-thumbs {
    position: fixed;
    bottom: 1.25rem;
    left: 0;
    right: 0;
    display: none;
    gap: 6px;
    padding: 0 1rem;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    z-index: 10001;
    justify-content: flex-start;
    scroll-behavior: smooth;
}

.lb-thumbs::-webkit-scrollbar { display: none; }

.lb-thumbs.active {
    display: flex;
    justify-content: center;
}

.lb-thumbs.active::before,
.lb-thumbs.active::after {
    content: '';
    flex: 0 0 auto;
}

.lb-thumb {
    flex: 0 0 54px;
    height: 54px;
    border: 1px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    opacity: 0.38;
    background: transparent;
    padding: 0;
    transition: opacity 0.3s var(--ease), border-color 0.3s var(--ease);
}

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

.lb-thumb:hover { opacity: 0.75; }

.lb-thumb.active {
    opacity: 1;
    border-color: rgba(240, 230, 216, 0.7);
}

/* Counter höher wenn Thumbs sichtbar */
.lb-backdrop.has-thumbs .lb-counter {
    bottom: 5.25rem;
}

/* Mobile */
@media (max-width: 767px) {
    .lb-prev, .lb-next { display: none; }

    .lb-close {
        top: 0.75rem;
        right: 0.75rem;
        width: 40px;
        height: 40px;
    }

    .lb-viewport {
        width: 100vw;
        height: 78vh;
    }

    .lb-counter {
        bottom: 1.75rem;
        font-size: 12px;
    }

    .lb-backdrop.has-thumbs .lb-counter {
        bottom: 4.5rem;
    }
}
