/**
 * Custom WordPress Gallery Styles
 * Designed for AVIF/JPEG galleries with lightbox support
 *
 * Usage: Add to your theme's CSS or enqueue as separate stylesheet
 */

/* ========================================
   Gallery Container Styles
   ======================================== */

/* Override WordPress default gallery styles (scoped) */
.aa-gallery .gallery, .gallery.aa-gallery {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 2em 0;
    padding: 10px;
    background: #1a1a1a;
    justify-content: center;
}

/* Gallery columns don't affect flexbox layout but maintain compatibility */
.gallery-columns-1,
.gallery-columns-2,
.gallery-columns-3,
.gallery-columns-4,
.gallery-columns-5,
.gallery-columns-6 {
    /* Columns handled by flexbox with fixed widths */
}

/* Tablet responsive - flexbox handles automatically */
@media (max-width: 768px) {
    .gallery {
        justify-content: center;
    }
}

/* Mobile responsive - flexbox handles automatically */
@media (max-width: 480px) {
    .aa-gallery .gallery, .gallery.aa-gallery {
        justify-content: center;
        gap: 8px;
    }

    .aa-gallery .gallery .gallery-item, .gallery.aa-gallery .gallery-item {
        width: 140px;
        height: 105px;
        max-width: 140px;
        max-height: 105px;
        min-width: 140px;
        min-height: 105px;
        flex: 0 0 140px;
        border: 2px solid #F9A643;
        border-radius: 5px;
        box-sizing: border-box;
    }

    .aa-gallery .gallery .gallery-item:hover, .gallery.aa-gallery .gallery-item:hover {
        border: 2px solid #00A1C6;
        border-color: #00A1C6;
        background: #00A1C6;
    }
}

/* ========================================
   Gallery Item Styles
   ======================================== */

.aa-gallery .gallery .gallery-item, .gallery.aa-gallery .gallery-item {
    position: relative;
    overflow: hidden;
    margin: 0;
    padding: 0;
    background: #F9A643;
    border: 2px solid #F9A643;
    border-radius: 5px;
    outline: none;
    box-shadow: none;
    transition: transform 0.3s ease;
    width: 200px;
    height: 150px;
    max-width: 200px;
    max-height: 150px;
    min-width: 200px;
    min-height: 150px;
    flex: 0 0 200px;
    box-sizing: border-box;
}

.aa-gallery .gallery-item:hover, .gallery.aa-gallery .gallery-item:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 30px rgba(0, 161, 198, 0.4);
    border-color: #00A1C6;
    background: #00A1C6;
    z-index: 10;
}

.aa-gallery .gallery .gallery-icon, .gallery.aa-gallery .gallery-icon {
    display: block;
    position: relative;
    width: 100%;
    height: 100%; /* Fill the entire gallery item */
    padding: 0;
    padding-bottom: 0;
    overflow: hidden;
    background: #000;
    border-radius: 5px;
}

/* Desktop: Fixed 200x150 boxes */
@media (min-width: 769px) {
    .aa-gallery .gallery .gallery-item, .gallery.aa-gallery .gallery-item {
        width: 200px;
        height: 150px;
        max-width: 200px;
        max-height: 150px;
        min-width: 200px;
        min-height: 150px;
        border: 2px solid #F9A643;
        box-sizing: border-box;
    }

    .aa-gallery .gallery .gallery-item:hover, .gallery.aa-gallery .gallery-item:hover {
        border: 2px solid #00A1C6;
        border-color: #00A1C6;
        background: #00A1C6;
    }

    .aa-gallery .gallery .gallery-icon img, .gallery.aa-gallery .gallery-icon img {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        object-fit: cover;
    }
}

/* Tablet and mobile: Smaller fixed boxes */
@media (max-width: 768px) {
    .aa-gallery .gallery .gallery-item, .gallery.aa-gallery .gallery-item {
        width: 150px;
        height: 112px; /* Maintain 4:3 aspect ratio */
        max-width: 150px;
        max-height: 112px;
        min-width: 150px;
        min-height: 112px;
        flex: 0 0 150px;
        border: 2px solid #F9A643;
        border-radius: 5px;
        box-sizing: border-box;
    }

    .aa-gallery .gallery .gallery-item:hover, .gallery.aa-gallery .gallery-item:hover {
        border: 2px solid #00A1C6;
        border-color: #00A1C6;
        background: #00A1C6;
    }

    .aa-gallery .gallery .gallery-icon img, .gallery.aa-gallery .gallery-icon img {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        object-fit: cover;
    }
}

/* Base img styles - overridden by media queries above */
.aa-gallery .gallery .gallery-icon img, .gallery.aa-gallery .gallery-icon img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease, opacity 0.3s ease;
    cursor: pointer;
}

.aa-gallery .gallery-item:hover .gallery-icon img, .gallery.aa-gallery .gallery-item:hover .gallery-icon img {
    transform: scale(1.08);
    filter: brightness(1.1);
}

/* Loading state for images */
.gallery-icon img.loading {
    opacity: 0;
}

.gallery-icon img.loaded {
    animation: fadeIn 0.5s ease;
    opacity: 1;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* Gallery captions - bottom with spacing */
.gallery-caption {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.3;
    text-align: center;
    border-radius: 3px;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 3;
    max-width: 85%;
    word-wrap: break-word;
}

.gallery-item:hover .gallery-caption {
    opacity: 1;
}

/* ========================================
   Lightbox Trigger Overlay
   ======================================== */

.gallery-icon::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to bottom, transparent 0%, rgba(0,0,0,0.3) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

/* Remove crosshair icon - no ::before content */

.gallery-item:hover .gallery-icon::after {
    opacity: 1;
}

/* ========================================
   Square Grid Option
   ======================================== */

.aa-gallery .gallery.gallery-square .gallery-item, .gallery.aa-gallery.gallery-square .gallery-item {
    width: 200px;
    height: 200px;
    max-width: 200px;
    max-height: 200px;
    min-width: 200px;
    min-height: 200px;
    border: 2px solid #F9A643;
    border-radius: 5px;
    box-sizing: border-box;
}

/* ========================================
   Masonry Layout Option
   ======================================== */

.aa-gallery .gallery.gallery-masonry, .gallery.aa-gallery.gallery-masonry {
    display: block;
    column-count: 3;
    column-gap: 15px;
}

.aa-gallery .gallery.gallery-masonry .gallery-item, .gallery.aa-gallery.gallery-masonry .gallery-item {
    display: inline-block;
    width: 100%;
    margin-bottom: 15px;
}

.aa-gallery .gallery.gallery-masonry .gallery-icon, .gallery.aa-gallery.gallery-masonry .gallery-icon {
    height: auto;
}

.aa-gallery .gallery.gallery-masonry .gallery-icon img, .gallery.aa-gallery.gallery-masonry .gallery-icon img {
    position: relative;
    width: 100%;
    height: auto;
    object-fit: contain;
}

@media (max-width: 768px) {
    .aa-gallery .gallery.gallery-masonry, .gallery.aa-gallery.gallery-masonry {
        column-count: 2;
    }
}

@media (max-width: 480px) {
    .aa-gallery .gallery.gallery-masonry, .gallery.aa-gallery.gallery-masonry {
        column-count: 1;
    }
}

/* ========================================
   Loading Spinner
   ======================================== */

.gallery-loading {
    position: relative;
    min-height: 200px;
}

.gallery-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ========================================
   AVIF Format Support Indicator
   ======================================== */

.gallery-item[data-format="avif"] .gallery-icon::after {
    content: 'AVIF';
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 2px 8px;
    background: rgba(102, 126, 234, 0.9);
    color: white;
    font-size: 11px;
    font-weight: bold;
    border-radius: 3px;
    transform: none;
    width: auto;
    height: auto;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.gallery-item[data-format="avif"]:hover .gallery-icon::after {
    opacity: 1;
    transform: none;
}

/* ========================================
   Accessibility
   ======================================== */

.gallery-item:focus-within {
    outline: 3px solid #667eea;
    outline-offset: 2px;
}

.gallery-icon img:focus {
    outline: none;
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
