/* ============================================
   HOMEPAGE FEATURE 1 — Guest Photo Gallery
   Modular CSS for the dynamically-injected gallery section.
   Mobile-first responsive grid with lightbox viewer.

   ARCHITECTURE:
   - Uses design tokens (CSS custom properties) from homepage.css
   - Mobile-first: 2 cols → 3 cols (640px) → 4 cols (1024px)
   - Lightbox: full-screen with nav arrows + swipe on mobile
   - Skeleton shimmer loaders during API fetch
   - prefers-reduced-motion respected

   DEPENDENCIES:
   - CSS custom properties from homepage.css (:root variables)
   - Font Awesome (icons via homepage.html)

   AI-OPTIMIZED:
   - Flat selectors, no nesting beyond 2 levels
   - Shared design token usage — zero hardcoded values
   - Clear section comments for each component
   ============================================ */

/* ----------------------------------------
   Gallery Section
   ---------------------------------------- */
.section-gallery {
    background: var(--color-bg-primary);
    overflow: hidden;
}

/* ----------------------------------------
   Gallery Grid — Responsive Columns
   Mobile: 2 cols → Tablet: 3 cols → Desktop: 4 cols
   ---------------------------------------- */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-sm);
}

.gallery-grid:empty {
    display: none;
}

@media (min-width: 640px) {
    .gallery-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: var(--spacing-md);
    }
}

@media (min-width: 1024px) {
    .gallery-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: var(--spacing-md);
    }
}

/* ----------------------------------------
   Gallery Item — Square Image Tile
   ---------------------------------------- */
.gallery-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    background: var(--color-bg-elevated);
    transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.gallery-item:hover {
    transform: scale(1.03);
    box-shadow: var(--shadow-lg);
}

.gallery-item:active {
    transform: scale(0.98);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity var(--transition-slow);
}

.gallery-item img.loaded {
    opacity: 1;
}

/* Guest name overlay — appears on hover/focus */
.gallery-item-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: var(--spacing-sm) var(--spacing-md);
    background: linear-gradient(transparent, rgba(26, 18, 16, 0.7));
    opacity: 0;
    transition: opacity var(--transition-fast);
    pointer-events: none;
}

.gallery-item:hover .gallery-item-overlay,
.gallery-item:focus-within .gallery-item-overlay {
    opacity: 1;
}

.gallery-item-guest {
    font-size: var(--font-size-xs);
    color: var(--color-text-inverse);
    font-weight: var(--fw-medium);
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.gallery-item-guest i {
    font-size: 0.625rem;
    opacity: 0.7;
}

/* ----------------------------------------
   Empty State — Warm Placeholder
   Shown when no guest photos have been uploaded yet.
   Encourages guests to be the first to share photos.
   ---------------------------------------- */
.gallery-empty {
    text-align: center;
    padding: var(--spacing-3xl) var(--spacing-xl);
    background: var(--color-bg-surface);
    border: 2px dashed var(--color-border-gold);
    border-radius: var(--radius-lg);
}

.gallery-empty[hidden] {
    display: none;
}

.gallery-empty-inner {
    max-width: 420px;
    margin: 0 auto;
}

.gallery-empty-icon {
    font-size: var(--font-size-4xl);
    color: var(--color-gold);
    margin-bottom: var(--spacing-lg);
    opacity: 0.6;
}

.gallery-empty-title {
    font-family: var(--font-heading);
    font-size: var(--font-size-xl);
    font-weight: var(--fw-medium);
    color: var(--color-text-primary);
    margin-bottom: var(--spacing-sm);
}

.gallery-empty-subtitle {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    line-height: 1.7;
    margin-bottom: var(--spacing-xl);
}

.gallery-empty-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) var(--spacing-xl);
    font-family: var(--font-body);
    font-size: var(--font-size-sm);
    font-weight: var(--fw-semibold);
    color: var(--color-bg-dark);
    background: var(--color-gold);
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background var(--transition-fast), transform var(--transition-fast);
}

.gallery-empty-btn:hover {
    background: var(--color-gold-hover);
    transform: scale(1.03);
}

.gallery-empty-btn:active {
    transform: scale(0.97);
}

/* ----------------------------------------
   Skeleton Loading — Shimmer Placeholders
   Shown while the API fetches gallery data.
   ---------------------------------------- */
.gallery-skeleton {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-sm);
}

.gallery-skeleton[hidden] {
    display: none;
}

@media (min-width: 640px) {
    .gallery-skeleton {
        grid-template-columns: repeat(3, 1fr);
        gap: var(--spacing-md);
    }
}

@media (min-width: 1024px) {
    .gallery-skeleton {
        grid-template-columns: repeat(4, 1fr);
        gap: var(--spacing-md);
    }
}

.gallery-skeleton-item {
    aspect-ratio: 1;
    border-radius: var(--radius-md);
    background: linear-gradient(
        110deg,
        var(--color-bg-elevated) 8%,
        var(--color-bg-surface) 18%,
        var(--color-bg-elevated) 33%
    );
    background-size: 200% 100%;
    animation: galleryShimmer 1.5s linear infinite;
}

@keyframes galleryShimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ----------------------------------------
   Lightbox — Full-Screen Photo Viewer
   Frosted glass backdrop with navigation.
   ---------------------------------------- */
.gallery-lightbox {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-lg);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base);
}

.gallery-lightbox.active {
    opacity: 1;
    pointer-events: auto;
}

.gallery-lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(26, 18, 16, 0.88);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
}

.gallery-lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 85vh;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    transform: scale(0.95);
    transition: transform var(--transition-base);
}

.gallery-lightbox.active .gallery-lightbox-content {
    transform: scale(1);
}

.gallery-lightbox-content img {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
    display: block;
}

/* Close Button */
.gallery-lightbox-close {
    position: absolute;
    top: var(--spacing-md);
    right: var(--spacing-md);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    font-size: var(--font-size-lg);
    border: none;
    cursor: pointer;
    z-index: 1;
    transition: background var(--transition-fast);
}

.gallery-lightbox-close:hover {
    background: rgba(0, 0, 0, 0.75);
}

/* Info Overlay — Guest name + date */
.gallery-lightbox-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: var(--spacing-lg) var(--spacing-xl);
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
    color: #fff;
    pointer-events: none;
}

.gallery-lightbox-guest {
    font-size: var(--font-size-sm);
    font-weight: var(--fw-medium);
}

.gallery-lightbox-date {
    font-size: var(--font-size-xs);
    opacity: 0.7;
    margin-top: 2px;
}

/* Navigation Arrows */
.gallery-lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.4);
    color: #fff;
    font-size: var(--font-size-base);
    border: none;
    cursor: pointer;
    transition: background var(--transition-fast);
    z-index: 1;
}

.gallery-lightbox-nav:hover {
    background: rgba(0, 0, 0, 0.65);
}

.gallery-lightbox-prev {
    left: var(--spacing-md);
}

.gallery-lightbox-next {
    right: var(--spacing-md);
}

/* ----------------------------------------
   Mobile Responsive
   ---------------------------------------- */
@media (max-width: 768px) {
    /* Show overlay permanently on touch (no hover) */
    .gallery-item-overlay {
        opacity: 1;
    }
}

@media (max-width: 639px) {
    /* Hide nav arrows on mobile — swipe instead */
    .gallery-lightbox-prev,
    .gallery-lightbox-next {
        display: none;
    }

    /* Full-width lightbox on small screens */
    .gallery-lightbox {
        padding: 0;
    }

    .gallery-lightbox-content {
        max-width: 100vw;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
    }

    .gallery-lightbox-content img {
        max-width: 100vw;
        max-height: 100vh;
        max-height: 100dvh;
    }
}

/* ----------------------------------------
   Touch Device Optimizations
   ---------------------------------------- */
@media (hover: none) and (pointer: coarse) {
    /* Always show overlay on touch devices */
    .gallery-item-overlay {
        opacity: 1;
    }

    /* Apple HIG 44px minimum touch targets */
    .gallery-lightbox-close,
    .gallery-lightbox-nav {
        width: 48px;
        height: 48px;
    }

    .gallery-empty-btn {
        min-height: 44px;
    }
}

/* ----------------------------------------
   Reduced Motion
   ---------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .gallery-item {
        transition: none;
    }

    .gallery-item img {
        opacity: 1;
        transition: none;
    }

    .gallery-lightbox,
    .gallery-lightbox-content {
        transition: none;
    }

    .gallery-skeleton-item {
        animation: none;
        background: var(--color-bg-elevated);
    }
}
