/* ===== GALLERY GRID - 4 Columns Desktop, 1 Column Mobile ===== */
.ag-gallery {
    width: 100%;
    margin: 20px 0;
    padding: 0;
}

.ag-gallery-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr); /* 4 columns on desktop */
    gap: 15px;
    width: 100%;
}

/* Gallery Items */
.ag-gallery-item {
    position: relative;
    overflow: hidden;
    border-radius: 10px;
    cursor: pointer;
    background: #f5f5f5;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.ag-gallery-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

/* Image Wrapper - maintains aspect ratio */
.ag-image-wrapper {
    position: relative;
    overflow: hidden;
    padding-bottom: 100%; /* 1:1 Square ratio - change to 75% for 4:3 or 56.25% for 16:9 */
    background: #f0f0f0;
}

/* Images - High Quality */
.ag-image-wrapper img.ag-gallery-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    image-rendering: auto;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Better image quality */
.ag-image-wrapper img.ag-gallery-image {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    -ms-interpolation-mode: bicubic;
}

/* Hover Zoom Effect */
.ag-gallery-item:hover .ag-image-wrapper img.ag-gallery-image {
    transform: scale(1.12);
}

/* Image Overlay */
.ag-image-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    opacity: 0;
    transition: opacity 0.4s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ag-gallery-item:hover .ag-image-overlay {
    opacity: 1;
}

/* Zoom Icon */
.ag-zoom-icon {
    font-size: 44px;
    color: #fff;
    transform: scale(0) rotate(-30deg);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.ag-gallery-item:hover .ag-zoom-icon {
    transform: scale(1) rotate(0deg);
}

/* ===== LIGHTBOX ===== */
.ag-lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 999999;
    animation: agFadeIn 0.3s ease;
}

@keyframes agFadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.ag-lightbox-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 92%;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* High quality lightbox image */
.ag-lightbox-content img {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    transition: transform 0.3s ease;
    border-radius: 6px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.6);
    image-rendering: auto;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Close Button */
.ag-lightbox-close {
    position: absolute;
    top: 25px;
    right: 35px;
    color: #fff;
    font-size: 42px;
    font-weight: 300;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 10;
    width: 55px;
    height: 55px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.1);
    border-radius: 50%;
    backdrop-filter: blur(10px);
}

.ag-lightbox-close:hover {
    transform: rotate(90deg) scale(1.1);
    background: rgba(255,0,0,0.3);
}

/* Zoom Controls */
.ag-zoom-controls {
    position: absolute;
    bottom: 35px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 12px;
    background: rgba(0, 0, 0, 0.7);
    padding: 12px 20px;
    border-radius: 50px;
    backdrop-filter: blur(15px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.ag-zoom-controls button {
    background: rgba(255,255,255,0.15);
    border: 2px solid rgba(255,255,255,0.3);
    color: #fff;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 22px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.ag-zoom-controls button:hover {
    background: #fff;
    color: #000;
    transform: scale(1.1);
    border-color: #fff;
}

.ag-zoom-controls button:active {
    transform: scale(0.95);
}

/* ===== MOBILE RESPONSIVE ===== */

/* Tablet - 2 columns */
@media (max-width: 1024px) and (min-width: 769px) {
    .ag-gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
}

/* Mobile - 1 column */
@media (max-width: 768px) {
    .ag-gallery-grid {
        grid-template-columns: 1fr !important; /* Force 1 column */
        gap: 15px;
    }
    
    .ag-gallery-item .ag-image-wrapper {
        padding-bottom: 75%; /* 4:3 ratio on mobile for better view */
    }
    
    .ag-image-wrapper img.ag-gallery-image {
        object-fit: cover;
    }
    
    .ag-lightbox-content {
        max-width: 95%;
        max-height: 92vh;
    }
    
    .ag-lightbox-content img {
        max-height: 75vh;
    }
    
    .ag-lightbox-close {
        top: 15px;
        right: 15px;
        font-size: 30px;
        width: 45px;
        height: 45px;
    }
    
    .ag-zoom-controls {
        bottom: 25px;
        padding: 8px 15px;
        gap: 8px;
    }
    
    .ag-zoom-controls button {
        width: 38px;
        height: 38px;
        font-size: 18px;
    }
    
    .ag-zoom-icon {
        font-size: 30px;
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    .ag-gallery-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }
    
    .ag-gallery-item .ag-image-wrapper {
        padding-bottom: 75%;
    }
    
    .ag-lightbox-content img {
        max-height: 70vh;
    }
    
    .ag-zoom-controls {
        bottom: 20px;
        padding: 6px 12px;
        gap: 6px;
    }
    
    .ag-zoom-controls button {
        width: 34px;
        height: 34px;
        font-size: 16px;
    }
}

/* ===== SHORTCODE COLUMN OVERRIDES ===== */

/* If someone wants custom columns via shortcode */
.ag-gallery[data-columns="2"] .ag-gallery-grid {
    grid-template-columns: repeat(2, 1fr);
}

.ag-gallery[data-columns="3"] .ag-gallery-grid {
    grid-template-columns: repeat(3, 1fr);
}

.ag-gallery[data-columns="4"] .ag-gallery-grid {
    grid-template-columns: repeat(4, 1fr);
}

.ag-gallery[data-columns="5"] .ag-gallery-grid {
    grid-template-columns: repeat(5, 1fr);
}

/* Mobile overrides for custom columns */
@media (max-width: 768px) {
    .ag-gallery[data-columns="2"] .ag-gallery-grid,
    .ag-gallery[data-columns="3"] .ag-gallery-grid,
    .ag-gallery[data-columns="4"] .ag-gallery-grid,
    .ag-gallery[data-columns="5"] .ag-gallery-grid {
        grid-template-columns: 1fr !important;
    }
}

/* Empty gallery message */
.ag-gallery-empty {
    padding: 30px;
    background: #f9f9f9;
    border-radius: 10px;
    border: 2px dashed #ddd;
    margin: 20px 0;
    text-align: center;
}

.ag-gallery-empty p {
    margin: 0;
    color: #999;
    font-size: 16px;
}