/**
 * Flavor Lightbox + Carousel — Enterprise CSS
 * Zero external dependencies. CSS vars for theming.
 * @layer flb for proper cascade ordering (2026).
 */

@layer flb {

/* ===========================================
   Lightbox Overlay
   =========================================== */
#flavorLightbox {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.flb-backdrop {
    position: absolute;
    inset: 0;
    z-index: 0;
    background: rgba(0, 0, 0, calc(var(--flb-overlay-opacity, 92) / 100));
}

/* ===========================================
   Content Container
   =========================================== */
.flb-content {
    position: relative;
    z-index: 1;
    max-width: 94vw;
    max-height: 90vh;
    transform: scale(0.92);
    opacity: 0;
    transition:
        transform var(--flb-anim-ms, 300ms) cubic-bezier(0.4, 0, 0.2, 1),
        opacity var(--flb-anim-ms, 300ms) cubic-bezier(0.4, 0, 0.2, 1);
}

#flavorLightbox.flb-open .flb-content {
    transform: scale(1);
    opacity: 1;
}

/* Animation variants */
#flavorLightbox.flb-anim-fade .flb-content { transform: scale(1); }
#flavorLightbox.flb-anim-slide .flb-content { transform: translateY(30px); }
#flavorLightbox.flb-anim-slide.flb-open .flb-content { transform: translateY(0); }
#flavorLightbox.flb-anim-none .flb-content { transition: none; transform: scale(1); }

/* Swipe-to-close visual feedback */
#flavorLightbox.flb-swiping .flb-content {
    transition: none;
}

/* Image / Video */
.flb-content img,
.flb-content video {
    max-width: 94vw;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 8px;
    display: block;
    margin: 0 auto;
    user-select: none;
    -webkit-user-drag: none;
    touch-action: none;
}

.flb-content img.flb-zoomed {
    max-width: none;
    max-height: none;
    cursor: grab;
    transform-origin: center center;
}

/* ===========================================
   Controls (position: fixed to viewport)
   =========================================== */
.flb-btn {
    position: fixed;
    z-index: 999999;
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
}

.flb-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.08);
}

.flb-btn:active { transform: scale(0.95); }
.flb-btn:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.6);
    outline-offset: 2px;
}

.flb-close    { top: 16px; right: 16px; }
.flb-prev     { left: 12px; top: 50%; margin-top: -24px; }
.flb-next     { right: 12px; top: 50%; margin-top: -24px; }
.flb-zoom-btn { top: 16px; right: 76px; }

/* Bottom stack: thumbnails above the caption. One fixed container, so a caption
   of any height pushes the strip up instead of sliding under it. */
.flb-bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 999999;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom);
    pointer-events: none;
}

/* Caption bar */
.flb-bar {
    align-self: stretch;
    padding: 12px 20px;
    text-align: center;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
    pointer-events: none;
}

/* Counter */
.flb-counter {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 999999;
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* Spinner */
.flb-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    margin: -20px 0 0 -20px;
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: white;
    border-radius: 50%;
    animation: flb-spin 0.7s linear infinite;
}

@keyframes flb-spin { to { transform: rotate(360deg); } }

/* Thumbnail strip */
.flb-thumbs {
    display: flex;
    pointer-events: auto;
    gap: 6px;
    max-width: 90vw;
    overflow-x: auto;
    padding: 6px;
    scrollbar-width: none;
}

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

.flb-thumb {
    width: 56px;
    height: 40px;
    min-height: 40px;
    max-height: 40px;
    border-radius: 6px;
    object-fit: cover;
    cursor: pointer;
    opacity: 0.5;
    border: 2px solid transparent;
    flex-shrink: 0;
    aspect-ratio: auto;
    transition: opacity 0.2s, border-color 0.2s;
}

.flb-thumb:hover { opacity: 0.8; }
.flb-thumb.flb-thumb-active { opacity: 1; border-color: white; }

/* Trigger */
/* Zoom cursor only while the viewer is on: the viewer marks <body> when it starts */
.flb-viewer-on [data-lightbox] { cursor: zoom-in; }

/* ===========================================
   Touch action — JS handles all gestures inside lightbox
   =========================================== */
#flavorLightbox {
    touch-action: manipulation;
}

/* ===========================================
   Reduced motion — accessibility
   =========================================== */
@media (prefers-reduced-motion: reduce) {
    .flb-content { transition: none; }
    .flb-btn { transition: none; }
    .flb-spinner { animation: none; }
    .flb-carousel-slide { transition: none; }
    .flb-c-arrow { transition: none; }
    .flb-c-dot { transition: none; }
    .flb-thumb { transition: none; }
}

/* ===========================================
   Responsive — Mobile
   =========================================== */
@media (max-width: 640px) {
    .flb-content {
        max-width: 100vw;
        padding: 0 clamp(12px, 3vw, 24px);
        box-sizing: border-box;
    }

    .flb-content img,
    .flb-content video {
        max-width: 100%;
        max-height: 75vh;
        border-radius: 4px;
    }

    .flb-btn { width: 44px; height: 44px; }
    .flb-prev { left: 4px; margin-top: -22px; }
    .flb-next { right: 4px; margin-top: -22px; }
    .flb-close { top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); }
    .flb-zoom-btn { top: max(8px, env(safe-area-inset-top)); right: calc(max(8px, env(safe-area-inset-right)) + 52px); }
    .flb-counter { top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); font-size: 13px; }
    .flb-thumbs {
        max-width: 85vw;
        scroll-snap-type: x mandatory;
    }
    .flb-thumb {
        width: 48px; height: 36px; min-height: 36px; max-height: 36px;
        scroll-snap-align: center;
    }
}

/* ===========================================
   Responsive — Landscape mobile
   =========================================== */
@media (orientation: landscape) and (max-height: 500px) {
    .flb-content img,
    .flb-content video {
        max-height: 85vh;
    }
    .flb-thumbs { display: none; }
    .flb-bar { padding: 6px 20px; font-size: 12px; }
}

/* ===========================================
   Responsive — Tablet
   =========================================== */
@media (min-width: 641px) and (max-width: 1024px) {
    .flb-prev { left: 8px; }
    .flb-next { right: 8px; }
    .flb-c-arrow { opacity: 1; }
}

/* ===========================================
   Carousel — data-gallery="carousel"
   =========================================== */
.flb-carousel {
    position: relative;
    overflow: hidden;
}

.flb-carousel-track {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: var(--flb-c-gap, 16px);
    padding: 0 var(--flb-c-peek, 40px);
}

.flb-carousel-track::-webkit-scrollbar { display: none; }
/* WCAG 2.4.7 — the track is a tabindex=0 keyboard scroll stop; keep its focus
   ring visible. Inset offset so the carousel wrapper's overflow can't clip it. */
.flb-carousel-track:focus-visible {
    outline: 2px solid var(--fl-text-primary, #1e293b);
    outline-offset: -2px;
}

.flb-carousel-slide {
    flex: 0 0 var(--flb-c-card-w, 320px);
    scroll-snap-align: start;
    border-radius: 12px;
    overflow: hidden;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.flb-viewer-on .flb-carousel-slide { cursor: zoom-in; }

.flb-carousel-slide:hover {
    transform: translateY(-4px);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.15);
}

.flb-carousel-slide img {
    width: 100%;
    height: auto;
    display: block;
    aspect-ratio: 16/10;
    object-fit: cover;
}

/* Carousel arrows */
.flb-c-arrow {
    position: absolute;
    top: 50%;
    z-index: 5;
    width: 44px;
    height: 44px;
    margin-top: -22px;
    border: none;
    border-radius: 50%;
    background: var(--fl-paper, #fff);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    color: var(--fl-text-primary, #1e293b);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
    opacity: 0;
}

.flb-carousel:hover .flb-c-arrow { opacity: 1; }
.flb-c-arrow:hover { transform: scale(1.1); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2); }
.flb-c-arrow:active { transform: scale(0.95); }
.flb-c-arrow:disabled { opacity: 0.3; pointer-events: none; }
.flb-c-arrow:focus-visible {
    outline: 2px solid var(--fl-text-primary, #1e293b);
    outline-offset: 2px;
    opacity: 1;
}
.flb-c-dot:focus-visible {
    outline: 2px solid var(--fl-text-primary, #1e293b);
    outline-offset: 2px;
}
.flb-c-prev { left: 4px; }
.flb-c-next { right: 4px; }

/* Arrows / dots turned off in settings — also covers carousel markup without Alpine bindings */
.flb-carousel.flb-c-no-arrows .flb-c-arrow,
.flb-carousel.flb-c-no-dots .flb-c-dots { display: none; }

/* Carousel dots */
.flb-c-dots {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 16px;
}

.flb-c-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: none;
    background: var(--fl-border, #cbd5e1);
    cursor: pointer;
    padding: 0;
    transition: background 0.2s, transform 0.2s;
}

.flb-c-dot:hover { transform: scale(1.3); }

.flb-c-dot.flb-c-dot-active {
    background: var(--fl-text-primary, #1e293b);
    transform: scale(1.2);
}

/* Carousel responsive */
@media (max-width: 640px) {
    .flb-carousel-slide {
        flex: 0 0 calc(100vw - var(--flb-c-peek, 40px) * 2 - var(--flb-c-gap, 16px));
    }
    .flb-c-arrow { width: 40px; height: 40px; margin-top: -20px; opacity: 1; }
    .flb-c-prev { left: max(4px, env(safe-area-inset-left)); }
    .flb-c-next { right: max(4px, env(safe-area-inset-right)); }
    .flb-c-dots { margin-top: 12px; }
    .flb-c-dot { width: 10px; height: 10px; }
}

/* ===========================================
   Noscript fallback — show images normally
   =========================================== */
.flb-noscript-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    padding: 16px 0;
}

.flb-noscript-grid img {
    width: 100%;
    height: auto;
    border-radius: 8px;
    object-fit: cover;
    aspect-ratio: 16/10;
}

} /* end @layer flb */

/* ===========================================
   Unlayered overrides — beat global img resets
   (Tailwind/Hyvä set `img { height: auto }` unlayered,
    which wins over @layer flb. These must stay outside.)
   =========================================== */
#flavorLightbox .flb-thumb {
    height: 40px;
    min-height: 40px;
    max-height: 40px;
    aspect-ratio: auto;
}

@media (max-width: 640px) {
    #flavorLightbox .flb-thumb {
        height: 36px;
        min-height: 36px;
        max-height: 36px;
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    #flavorLightbox .flb-thumbs {
        display: none;
    }
}
