/* ============================================
   UMBC Photo Gallery Block Styles
   ============================================ */

.umbc-photo-gallery {
    width: 100%;
    margin: 2rem auto;
}

.gallery-container {
    display: grid; /* Default for grid layouts */
    width: 100%;
}

/* Masonry layouts override grid display with column layout */
.umbc-photo-gallery.layout-masonry-2 .gallery-container,
.umbc-photo-gallery.layout-masonry-3 .gallery-container,
.umbc-photo-gallery.layout-masonry-4 .gallery-container,
.umbc-photo-gallery.layout-masonry-5 .gallery-container {
    display: block; /* Override grid display for masonry */
}

/* ============================================
   Gap Sizes
   ============================================ */
.umbc-photo-gallery.gap-none .gallery-container {
    gap: 0;
}

.umbc-photo-gallery.gap-small .gallery-container {
    gap: 8px;
}

.umbc-photo-gallery.gap-medium .gallery-container {
    gap: 16px;
}

.umbc-photo-gallery.gap-large .gallery-container {
    gap: 24px;
}

.umbc-photo-gallery.gap-xlarge .gallery-container {
    gap: 32px;
}

/* ============================================
   Grid Layouts
   ============================================ */
.umbc-photo-gallery.layout-grid-2 .gallery-container {
    grid-template-columns: repeat(2, 1fr);
}

.umbc-photo-gallery.layout-grid-3 .gallery-container {
    grid-template-columns: repeat(3, 1fr);
}

.umbc-photo-gallery.layout-grid-4 .gallery-container {
    grid-template-columns: repeat(4, 1fr);
}

.umbc-photo-gallery.layout-grid-5 .gallery-container {
    grid-template-columns: repeat(5, 1fr);
}

/* Responsive grid adjustments */
@media (max-width: 1200px) {
    .umbc-photo-gallery.layout-grid-5 .gallery-container {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 1024px) {
    .umbc-photo-gallery.layout-grid-4 .gallery-container,
    .umbc-photo-gallery.layout-grid-5 .gallery-container {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .umbc-photo-gallery.layout-grid-3 .gallery-container,
    .umbc-photo-gallery.layout-grid-4 .gallery-container,
    .umbc-photo-gallery.layout-grid-5 .gallery-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .umbc-photo-gallery.layout-grid-2 .gallery-container,
    .umbc-photo-gallery.layout-grid-3 .gallery-container,
    .umbc-photo-gallery.layout-grid-4 .gallery-container,
    .umbc-photo-gallery.layout-grid-5 .gallery-container {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   Masonry Layouts (Pinterest-style, preserves natural heights)
   ============================================ */
.umbc-photo-gallery.layout-masonry-2 .gallery-container {
    column-count: 2;
    column-gap: 16px;
}

.umbc-photo-gallery.layout-masonry-3 .gallery-container {
    column-count: 3;
    column-gap: 16px;
}

.umbc-photo-gallery.layout-masonry-4 .gallery-container {
    column-count: 4;
    column-gap: 16px;
}

.umbc-photo-gallery.layout-masonry-5 .gallery-container {
    column-count: 5;
    column-gap: 16px;
}

.umbc-photo-gallery.layout-masonry-2.gap-small .gallery-container,
.umbc-photo-gallery.layout-masonry-3.gap-small .gallery-container,
.umbc-photo-gallery.layout-masonry-4.gap-small .gallery-container,
.umbc-photo-gallery.layout-masonry-5.gap-small .gallery-container {
    column-gap: 8px;
}

.umbc-photo-gallery.layout-masonry-2.gap-medium .gallery-container,
.umbc-photo-gallery.layout-masonry-3.gap-medium .gallery-container,
.umbc-photo-gallery.layout-masonry-4.gap-medium .gallery-container,
.umbc-photo-gallery.layout-masonry-5.gap-medium .gallery-container {
    column-gap: 16px;
}

.umbc-photo-gallery.layout-masonry-2.gap-large .gallery-container,
.umbc-photo-gallery.layout-masonry-3.gap-large .gallery-container,
.umbc-photo-gallery.layout-masonry-4.gap-large .gallery-container,
.umbc-photo-gallery.layout-masonry-5.gap-large .gallery-container {
    column-gap: 24px;
}

.umbc-photo-gallery.layout-masonry-2.gap-xlarge .gallery-container,
.umbc-photo-gallery.layout-masonry-3.gap-xlarge .gallery-container,
.umbc-photo-gallery.layout-masonry-4.gap-xlarge .gallery-container,
.umbc-photo-gallery.layout-masonry-5.gap-xlarge .gallery-container {
    column-gap: 32px;
}

.umbc-photo-gallery.layout-masonry-2 .gallery-item,
.umbc-photo-gallery.layout-masonry-3 .gallery-item,
.umbc-photo-gallery.layout-masonry-4 .gallery-item,
.umbc-photo-gallery.layout-masonry-5 .gallery-item {
    display: inline-block;
    width: 100%;
    margin-bottom: 16px;
    break-inside: avoid;
}

.umbc-photo-gallery.layout-masonry-2.gap-small .gallery-item,
.umbc-photo-gallery.layout-masonry-3.gap-small .gallery-item,
.umbc-photo-gallery.layout-masonry-4.gap-small .gallery-item,
.umbc-photo-gallery.layout-masonry-5.gap-small .gallery-item {
    margin-bottom: 8px;
}

.umbc-photo-gallery.layout-masonry-2.gap-large .gallery-item,
.umbc-photo-gallery.layout-masonry-3.gap-large .gallery-item,
.umbc-photo-gallery.layout-masonry-4.gap-large .gallery-item,
.umbc-photo-gallery.layout-masonry-5.gap-large .gallery-item {
    margin-bottom: 24px;
}

.umbc-photo-gallery.layout-masonry-2.gap-xlarge .gallery-item,
.umbc-photo-gallery.layout-masonry-3.gap-xlarge .gallery-item,
.umbc-photo-gallery.layout-masonry-4.gap-xlarge .gallery-item,
.umbc-photo-gallery.layout-masonry-5.gap-xlarge .gallery-item {
    margin-bottom: 32px;
}

/* Masonry responsive */
@media (max-width: 1200px) {
    .umbc-photo-gallery.layout-masonry-5 .gallery-container {
        column-count: 4;
    }
}

@media (max-width: 1024px) {
    .umbc-photo-gallery.layout-masonry-4 .gallery-container,
    .umbc-photo-gallery.layout-masonry-5 .gallery-container {
        column-count: 3;
    }
}

@media (max-width: 768px) {
    .umbc-photo-gallery.layout-masonry-3 .gallery-container,
    .umbc-photo-gallery.layout-masonry-4 .gallery-container,
    .umbc-photo-gallery.layout-masonry-5 .gallery-container {
        column-count: 2;
    }
}

@media (max-width: 480px) {
    .umbc-photo-gallery.layout-masonry-2 .gallery-container,
    .umbc-photo-gallery.layout-masonry-3 .gallery-container,
    .umbc-photo-gallery.layout-masonry-4 .gallery-container,
    .umbc-photo-gallery.layout-masonry-5 .gallery-container {
        column-count: 1;
    }
}

/* ============================================
   Carousel Layout
   ============================================ */
.umbc-photo-gallery.layout-carousel .gallery-container {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #999 #f0f0f0;
}

.umbc-photo-gallery.layout-carousel .gallery-container::-webkit-scrollbar {
    height: 8px;
}

.umbc-photo-gallery.layout-carousel .gallery-container::-webkit-scrollbar-track {
    background: #f0f0f0;
}

.umbc-photo-gallery.layout-carousel .gallery-container::-webkit-scrollbar-thumb {
    background: #999;
    border-radius: var(--umbc-radius-sm, 4px);
}

.umbc-photo-gallery.layout-carousel .gallery-item {
    flex: 0 0 auto;
    width: 80%;
    max-width: 600px;
    scroll-snap-align: start;
}

@media (max-width: 768px) {
    .umbc-photo-gallery.layout-carousel .gallery-item {
        width: 90%;
    }
}

@media (max-width: 480px) {
    .umbc-photo-gallery.layout-carousel .gallery-item {
        width: 95%;
    }
}

/* ============================================
   Justified Row Layout
   ============================================ */
.umbc-photo-gallery.layout-justified .gallery-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
}

.umbc-photo-gallery.layout-justified .gallery-item {
    flex-grow: 1;
    height: 250px;
    position: relative;
}

.umbc-photo-gallery.layout-justified .gallery-image-wrapper {
    height: 100%;
}

.umbc-photo-gallery.layout-justified .gallery-image {
    height: 100%;
    width: 100%;
    object-fit: cover;
}

/* ============================================
   Gallery Item
   ============================================ */
.gallery-item {
    position: relative;
    overflow: hidden;
    background: #f0f0f0;
}

.gallery-image-wrapper {
    position: relative;
    width: 100%;
    overflow: hidden;
    background: #f0f0f0;
}

/* Aspect Ratios for Grid Layouts only (not masonry or justified) */
.umbc-photo-gallery.aspect-square:not(.layout-masonry-2):not(.layout-masonry-3):not(.layout-masonry-4):not(.layout-masonry-5):not(.layout-justified) .gallery-image-wrapper {
    aspect-ratio: 1 / 1;
}

.umbc-photo-gallery.aspect-landscape:not(.layout-masonry-2):not(.layout-masonry-3):not(.layout-masonry-4):not(.layout-masonry-5):not(.layout-justified) .gallery-image-wrapper {
    aspect-ratio: 4 / 3;
}

.umbc-photo-gallery.aspect-wide:not(.layout-masonry-2):not(.layout-masonry-3):not(.layout-masonry-4):not(.layout-masonry-5):not(.layout-justified) .gallery-image-wrapper {
    aspect-ratio: 16 / 9;
}

.umbc-photo-gallery.aspect-portrait:not(.layout-masonry-2):not(.layout-masonry-3):not(.layout-masonry-4):not(.layout-masonry-5):not(.layout-justified) .gallery-image-wrapper {
    aspect-ratio: 3 / 4;
}

.gallery-image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

/* Don't crop masonry images - preserve natural height */
.umbc-photo-gallery.layout-masonry-2 .gallery-image,
.umbc-photo-gallery.layout-masonry-3 .gallery-image,
.umbc-photo-gallery.layout-masonry-4 .gallery-image,
.umbc-photo-gallery.layout-masonry-5 .gallery-image {
    height: auto;
    object-fit: contain;
}

/* Natural aspect ratio */
.umbc-photo-gallery.aspect-natural .gallery-image {
    object-fit: contain;
    height: auto;
}

/* ============================================
   Hover Effects (Lightbox Only)
   ============================================ */
.umbc-photo-gallery.has-lightbox .gallery-link {
    display: block;
    position: relative;
    text-decoration: none;
    cursor: zoom-in;
}

.umbc-photo-gallery.has-lightbox .gallery-link:hover .gallery-image {
    transform: scale(1.05);
}

.gallery-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.umbc-photo-gallery.has-lightbox .gallery-link:hover .gallery-overlay {
    opacity: 1;
}

.gallery-icon {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

/* ============================================
   Captions
   ============================================ */
.gallery-caption {
    padding: 8px 12px;
    font-size: 0.875rem;
    color: #666;
    background: #f9f9f9;
    text-align: center;
}

/* ============================================
   Lightbox Styles
   ============================================ */
.gallery-lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 10000;
    animation: fadeIn 0.3s ease;
}

.gallery-lightbox.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

.lightbox-image {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    animation: scaleIn 0.3s ease;
}

@keyframes scaleIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.lightbox-caption {
    margin-top: 1rem;
    color: white;
    font-size: 1rem;
    text-align: center;
    max-width: 600px;
    padding: 0 1rem;
}

.lightbox-counter {
    margin-top: 0.5rem;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.875rem;
}

/* Lightbox Controls - High specificity to override theme styles */
.umbc-photo-gallery .gallery-lightbox .lightbox-close,
.umbc-photo-gallery .gallery-lightbox .lightbox-prev,
.umbc-photo-gallery .gallery-lightbox .lightbox-next {
    position: absolute !important;
    background: rgba(255, 255, 255, 0.1) !important;
    border: none !important;
    color: white !important;
    width: 50px !important;
    height: 50px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    transition: background 0.2s ease !important;
    border-radius: var(--umbc-radius-sm, 4px) !important;
    z-index: 10001 !important;
    padding: 0 !important;
    margin: 0 !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.umbc-photo-gallery .gallery-lightbox .lightbox-close:hover,
.umbc-photo-gallery .gallery-lightbox .lightbox-prev:hover,
.umbc-photo-gallery .gallery-lightbox .lightbox-next:hover {
    background: rgba(255, 255, 255, 0.2) !important;
}

.umbc-photo-gallery .gallery-lightbox .lightbox-close:focus,
.umbc-photo-gallery .gallery-lightbox .lightbox-prev:focus,
.umbc-photo-gallery .gallery-lightbox .lightbox-next:focus {
    outline: 2px solid white !important;
    outline-offset: 2px !important;
}

.umbc-photo-gallery .gallery-lightbox .lightbox-close {
    top: 20px !important;
    right: 20px !important;
}

.umbc-photo-gallery .gallery-lightbox .lightbox-prev {
    left: 20px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
}

.umbc-photo-gallery .gallery-lightbox .lightbox-next {
    right: 20px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
}

.umbc-photo-gallery .gallery-lightbox .lightbox-prev:disabled,
.umbc-photo-gallery .gallery-lightbox .lightbox-next:disabled {
    opacity: 0.3 !important;
    cursor: not-allowed !important;
}

/* Ensure SVG icons inside buttons are visible */
.umbc-photo-gallery .gallery-lightbox button svg {
    display: block !important;
    width: 24px !important;
    height: 24px !important;
    fill: none !important;
    stroke: currentColor !important;
    pointer-events: none !important;
}

@media (max-width: 768px) {
    .umbc-photo-gallery .gallery-lightbox .lightbox-close {
        top: 10px !important;
        right: 10px !important;
        width: 40px !important;
        height: 40px !important;
    }

    .umbc-photo-gallery .gallery-lightbox .lightbox-prev,
    .umbc-photo-gallery .gallery-lightbox .lightbox-next {
        width: 40px !important;
        height: 40px !important;
    }

    .umbc-photo-gallery .gallery-lightbox .lightbox-prev {
        left: 10px !important;
    }

    .umbc-photo-gallery .gallery-lightbox .lightbox-next {
        right: 10px !important;
    }

    .umbc-photo-gallery .gallery-lightbox .lightbox-image {
        max-height: 70vh !important;
    }
}

/* ============================================
   Block Editor Styles
   ============================================ */
.block-editor-block-list__block[data-type="umbc/photo-gallery-block"] {
    margin: 2rem 0;
}

/* =============================================================
   Dark Mode — Photo Gallery Block
   ============================================================= */

/* Image placeholder bg (shows while images load) */
[data-theme="dark"] .gallery-item,
[data-theme="dark"] .gallery-image-wrapper {
    background: var(--umbc-surface-card-alt, #232323);
}

/* Caption strip */
[data-theme="dark"] .gallery-caption {
    background: #1a1a1a;
    color: #b0b0b0;
}

/* Carousel scrollbar */
[data-theme="dark"] .umbc-photo-gallery.layout-carousel .gallery-container {
    scrollbar-color: #555 #1a1a1a;
}

[data-theme="dark"] .umbc-photo-gallery.layout-carousel .gallery-container::-webkit-scrollbar-track {
    background: #1a1a1a;
}

[data-theme="dark"] .umbc-photo-gallery.layout-carousel .gallery-container::-webkit-scrollbar-thumb {
    background: #555;
}

/* Lightbox is already rgba(0,0,0,0.95) — no changes needed */
