/**
 * aFFirmFirst Gallery — Frontend Styles
 * Templates: grid, masonry, slider, justified
 * Includes: lightbox, hover effects, captions, responsive
 */

/* =========================================================================
   Base Gallery
   ========================================================================= */

.affirm-gallery {
    position: relative;
    width: 100%;
    margin: 1.5em 0;
}

.affirm-gallery__item {
    position: relative;
    overflow: hidden;
    border-radius: var(--af-radius, 8px);
    background: #f8fafc;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.affirm-gallery__image {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.affirm-gallery__image > * {
    width: 100%;
    height: 100%;
    display: block;
}

.affirm-gallery__image img,
.affirm-gallery__image iframe,
.affirm-gallery__image canvas,
.affirm-gallery__image .affirmfirst-protected-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* =========================================================================
   Template: Grid
   ========================================================================= */

.affirm-gallery--grid {
    display: grid;
    grid-template-columns: repeat(var(--af-columns, 3), 1fr);
    gap: var(--af-gap, 8px);
}

.affirm-gallery--grid .affirm-gallery__item {
    aspect-ratio: 1;
}

/* =========================================================================
   Template: Masonry (CSS columns)
   ========================================================================= */

.affirm-gallery--masonry {
    column-count: var(--af-columns, 3);
    column-gap: var(--af-gap, 8px);
}

.affirm-gallery--masonry .affirm-gallery__item {
    break-inside: avoid;
    margin-bottom: var(--af-gap, 8px);
    display: inline-block;
    width: 100%;
}

.affirm-gallery--masonry .affirm-gallery__image {
    height: auto;
}

.affirm-gallery--masonry .affirm-gallery__image > * {
    height: auto;
    object-fit: contain;
}

/* =========================================================================
   Template: Slider (horizontal carousel)
   ========================================================================= */

/* Outer wrapper — relative positioned for nav/dots */
.affirm-gallery--slider {
    position: relative;
    padding-bottom: 44px; /* space for dots below */
}

/* Inner scrollable track */
.affirm-gallery__track {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    gap: var(--af-gap, 8px);
    align-items: center;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 4px 0;
}

.affirm-gallery__track::-webkit-scrollbar {
    display: none;
}

.affirm-gallery--slider .affirm-gallery__item {
    flex: 0 0 32%;
    min-width: 220px;
    scroll-snap-align: center;
    aspect-ratio: 4/3;
}

/* Slider column overrides */
.affirm-gallery--slider[data-columns="1"] .affirm-gallery__item { flex: 0 0 100%; }
.affirm-gallery--slider[data-columns="2"] .affirm-gallery__item { flex: 0 0 calc(50% - var(--af-gap, 8px) / 2); }
.affirm-gallery--slider[data-columns="3"] .affirm-gallery__item { flex: 0 0 calc(33.333% - var(--af-gap, 8px) * 2 / 3); }
.affirm-gallery--slider[data-columns="4"] .affirm-gallery__item { flex: 0 0 calc(25% - var(--af-gap, 8px) * 3 / 4); }
.affirm-gallery--slider[data-columns="5"] .affirm-gallery__item { flex: 0 0 calc(20% - var(--af-gap, 8px) * 4 / 5); }
.affirm-gallery--slider[data-columns="6"] .affirm-gallery__item { flex: 0 0 calc(16.666% - var(--af-gap, 8px) * 5 / 6); }

/* Slider navigation arrows — positioned on outer wrapper */
.affirm-gallery__nav {
    position: absolute;
    top: calc(50% - 22px - 20px); /* half of track minus dots space */
    z-index: 5;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #e2e8f0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #1e293b;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.2s;
    padding: 0;
}

.affirm-gallery__nav:hover {
    background: #fff;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    transform: scale(1.08);
}

.affirm-gallery__nav--prev { left: -8px; }
.affirm-gallery__nav--next { right: -8px; }

/* Slider dots — below the track */
.affirm-gallery__dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding-top: 14px;
}

.affirm-gallery__dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #cbd5e1;
    border: none;
    cursor: pointer;
    padding: 0;
    transition: all 0.25s;
}

.affirm-gallery__dot:hover {
    background: #94a3b8;
}

.affirm-gallery__dot--active {
    background: #10b981;
    transform: scale(1.3);
}

/* =========================================================================
   Template: Justified (row-based, full-width)
   ========================================================================= */

.affirm-gallery--justified {
    display: flex;
    flex-wrap: wrap;
    gap: var(--af-gap, 8px);
}

.affirm-gallery--justified .affirm-gallery__item {
    flex-grow: 1;
    height: 240px;
    min-width: 180px;
}

/* Force last row items to not stretch too wide when there are few orphans */
.affirm-gallery--justified::after {
    content: '';
    flex-grow: 999;
}

.affirm-gallery--justified .affirm-gallery__image {
    height: 100%;
}

.affirm-gallery--justified .affirm-gallery__image > * {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

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

/* Zoom */
.affirm-gallery--hover-zoom .affirm-gallery__image > * {
    transition: transform 0.4s ease;
}

.affirm-gallery--hover-zoom .affirm-gallery__item:hover .affirm-gallery__image > * {
    transform: scale(1.08);
}

/* Fade */
.affirm-gallery--hover-fade .affirm-gallery__item {
    transition: opacity 0.3s ease, transform 0.3s ease, box-shadow 0.3s ease;
}

.affirm-gallery--hover-fade .affirm-gallery__item:hover {
    opacity: 0.8;
}

/* Lift */
.affirm-gallery--hover-lift .affirm-gallery__item:hover {
    transform: translateY(-6px);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}

/* None */
.affirm-gallery--hover-none .affirm-gallery__item:hover {
    transform: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* =========================================================================
   Overlay (hover)
   ========================================================================= */

.affirm-gallery__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
    pointer-events: none;
    border-radius: var(--af-radius, 8px);
}

.affirm-gallery__item:hover .affirm-gallery__overlay {
    background: rgba(0, 0, 0, 0.2);
}

.affirm-gallery__zoom-icon {
    opacity: 0;
    transform: scale(0.7);
    transition: all 0.3s ease;
    color: #fff;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.affirm-gallery__item:hover .affirm-gallery__zoom-icon {
    opacity: 1;
    transform: scale(1);
}

/* =========================================================================
   Captions
   ========================================================================= */

.affirm-gallery__caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 12px;
    font-size: 13px;
    color: #fff;
    text-align: center;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
    border-radius: 0 0 var(--af-radius, 8px) var(--af-radius, 8px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* =========================================================================
   Lightbox
   ========================================================================= */

.affirm-lightbox-overlay {
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.affirm-lightbox-overlay.active {
    opacity: 1;
}

.affirm-lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.affirm-lightbox-image {
    max-width: 90vw;
    max-height: 80vh;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
}

.affirm-lightbox-image img,
.affirm-lightbox-image .affirmfirst-protected-image,
.affirm-lightbox-image iframe {
    max-width: 90vw;
    max-height: 80vh;
    object-fit: contain;
    display: block;
}

.affirm-lightbox-caption {
    margin-top: 12px;
    color: #e2e8f0;
    font-size: 14px;
    text-align: center;
    max-width: 600px;
}

.affirm-lightbox-counter {
    position: absolute;
    top: -36px;
    left: 0;
    color: #94a3b8;
    font-size: 13px;
}

.affirm-lightbox-close {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000000;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    padding: 0;
    line-height: 1;
}

.affirm-lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.affirm-lightbox-nav {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1000000;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    padding: 0;
}

.affirm-lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.25);
}

.affirm-lightbox-nav--prev { left: 20px; }
.affirm-lightbox-nav--next { right: 20px; }

/* Lightbox thumbnail strip */
.affirm-lightbox-thumbs {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000000;
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 12px;
    max-width: 80vw;
    overflow-x: auto;
    scrollbar-width: none;
}

.affirm-lightbox-thumbs::-webkit-scrollbar {
    display: none;
}

.affirm-lightbox-thumb {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    opacity: 0.5;
    transition: all 0.2s;
    flex-shrink: 0;
    padding: 0;
    background: #1e293b;
}

.affirm-lightbox-thumb:hover {
    opacity: 0.8;
}

.affirm-lightbox-thumb--active {
    border-color: #10b981;
    opacity: 1;
}

.affirm-lightbox-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* =========================================================================
   Responsive
   ========================================================================= */

@media (max-width: 768px) {
    .affirm-gallery--grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .affirm-gallery--masonry {
        column-count: 2;
    }

    .affirm-gallery--slider .affirm-gallery__item {
        flex: 0 0 75% !important;
        min-width: 0;
    }

    .affirm-gallery--justified .affirm-gallery__item {
        height: 180px;
        min-width: 140px;
    }

    .affirm-gallery__nav {
        width: 36px;
        height: 36px;
    }

    .affirm-gallery__nav--prev { left: 4px; }
    .affirm-gallery__nav--next { right: 4px; }

    .affirm-lightbox-nav { display: none; }
    .affirm-lightbox-thumbs { display: none; }
}

@media (max-width: 480px) {
    .affirm-gallery--grid {
        grid-template-columns: 1fr;
    }

    .affirm-gallery--masonry {
        column-count: 1;
    }

    .affirm-gallery--slider .affirm-gallery__item {
        flex: 0 0 90% !important;
    }

    .affirm-gallery--justified .affirm-gallery__item {
        height: 160px;
        min-width: 100%;
    }
}
