/* Ensure the main container doesn't get squished */
#mfg-gallery-container * {
    box-sizing: border-box;
}

#mfg-gallery-container {
    padding-bottom: 40px;
    /* Add extra space at the bottom */
}

/* Album Grid */
.mfg-album-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, 280px);
    /* Strict 280px columns */
    gap: 20px;
    justify-content: center;
    /* Center the grid if there's extra space */
}

.mfg-album-item {
    width: 280px;
    height: 280px;
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    text-decoration: none !important;
    /* Override theme styles */
    color: white;
    background-color: #222;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    /* Align meta to the bottom */
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s ease;
}

.mfg-album-item:hover {
    transform: translateY(-5px);
}

.mfg-album-cover {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* This is key for the image to fill the 280x280 box */
    z-index: 1;
    transition: opacity 0.3s ease;
}

.mfg-album-item:hover .mfg-album-cover {
    opacity: 0.8;
}

.mfg-album-meta {
    position: relative;
    z-index: 2;
    padding: 15px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0) 100%);
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8);
}

.mfg-album-name {
    font-size: 1.1em;
    font-weight: bold;
    display: block;
    line-height: 1.2;
    margin: 0;
    padding: 0;
}

.mfg-album-stats {
    font-size: 0.9em;
    display: block;
    opacity: 0.9;
    margin-top: 4px;
}

/* Photo Grid */
.mfg-photo-grid-container {
    padding-top: 20px;
}

.mfg-photo-grid {
    /* Default Grid Styles (applied when .mfg-layout-grid is present or no specific class) */
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 15px;
}

/* Remove padding class for full width galleries */
.mfg-no-padding {
    padding-left: 0 !important;
    padding-right: 0 !important;
}

/* Dynamic max photos per row (controlled via JavaScript based on data-max-photos attribute) */
.mfg-photo-grid[data-columns="1"] {
    grid-template-columns: repeat(1, 1fr);
}

.mfg-photo-grid[data-columns="2"] {
    grid-template-columns: repeat(2, 1fr);
}

.mfg-photo-grid[data-columns="3"] {
    grid-template-columns: repeat(3, 1fr);
}

.mfg-photo-grid[data-columns="4"] {
    grid-template-columns: repeat(4, 1fr);
}

.mfg-photo-grid[data-columns="5"] {
    grid-template-columns: repeat(5, 1fr);
}

.mfg-photo-grid[data-columns="6"] {
    grid-template-columns: repeat(6, 1fr);
}

.mfg-photo-grid[data-columns="7"] {
    grid-template-columns: repeat(7, 1fr);
}

.mfg-photo-grid[data-columns="8"] {
    grid-template-columns: repeat(8, 1fr);
}

.mfg-photo-grid[data-columns="9"] {
    grid-template-columns: repeat(9, 1fr);
}

.mfg-photo-grid[data-columns="10"] {
    grid-template-columns: repeat(10, 1fr);
}

/* Masonry Layout Styles */
.mfg-layout-masonry .mfg-photo-grid {
    display: block;
    /* Disable grid */
    column-count: 3;
    /* Default to 3 columns */
    column-gap: 15px;
}

/* Dynamic column count for Masonry based on max photos */
.mfg-layout-masonry .mfg-photo-grid[data-columns="1"] {
    column-count: 1;
}

.mfg-layout-masonry .mfg-photo-grid[data-columns="2"] {
    column-count: 2;
}

.mfg-layout-masonry .mfg-photo-grid[data-columns="3"] {
    column-count: 3;
}

.mfg-layout-masonry .mfg-photo-grid[data-columns="4"] {
    column-count: 4;
}

.mfg-layout-masonry .mfg-photo-grid[data-columns="5"] {
    column-count: 5;
}

.mfg-layout-masonry .mfg-photo-grid[data-columns="6"] {
    column-count: 6;
}

.mfg-layout-masonry .mfg-photo-grid[data-columns="7"] {
    column-count: 7;
}

.mfg-layout-masonry .mfg-photo-grid[data-columns="8"] {
    column-count: 8;
}

.mfg-layout-masonry .mfg-photo-grid[data-columns="9"] {
    column-count: 9;
}

.mfg-layout-masonry .mfg-photo-grid[data-columns="10"] {
    column-count: 10;
}

.mfg-layout-masonry .mfg-photo-item {
    break-inside: avoid;
    /* Prevent items from splitting across columns */
    margin-bottom: 15px;
    /* Space between items vertically */
    aspect-ratio: auto;
    /* Allow natural height */
}

/* Responsive columns for Masonry */
@media (max-width: 900px) {
    .mfg-layout-masonry .mfg-photo-grid {
        column-count: 2;
    }
}

@media (max-width: 600px) {
    .mfg-layout-masonry .mfg-photo-grid {
        column-count: 1;
    }
}

.mfg-photo-item {
    cursor: pointer;
    overflow: hidden;
    border-radius: 4px;
    aspect-ratio: 1 / 1;
    /* Make photos square */
}

.mfg-photo-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.mfg-photo-item:hover img {
    transform: scale(1.1);
}

/* Pagination & Other elements from before */
.mfg-pagination {
    text-align: center;
    margin: 30px 0 10px;
}

.mfg-pagination a {
    padding: 8px 12px;
    border: 1px solid #ddd;
    margin: 0 5px;
    text-decoration: none;
    color: #333;
    border-radius: 4px;
}

.mfg-pagination a:hover {
    background-color: #f5f5f5;
}

.mfg-lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mfg-lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
}

.mfg-lightbox-image {
    max-width: 100%;
    max-height: 80vh;
    display: block;
    border-radius: 4px;
}

.mfg-lightbox-info {
    color: white;
    text-align: center;
    padding: 10px;
}

.mfg-lightbox-close,
.mfg-lightbox-next,
.mfg-lightbox-prev {
    position: absolute;
    color: white;
    font-size: 30px;
    cursor: pointer;
    text-decoration: none;
    user-select: none;
}

.mfg-lightbox-close {
    top: 10px;
    right: 20px;
}

.mfg-lightbox-next {
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    padding: 10px;
}

.mfg-lightbox-prev {
    top: 50%;
    left: 10px;
    transform: translateY(-50%);
    padding: 10px;
}

.mfg-loading {
    border: 5px solid #f3f3f3;
    border-top: 5px solid #3498db;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: mfg-spin 1s linear infinite;
    margin: 50px auto;
}

@keyframes mfg-spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.mfg-lightbox-info h3 {
    color: #ffffff;
    /* Makes the photo title white */
    font-size: 19px;
    /* Sets the font size as requested */
    font-weight: normal;
    margin: 0 0 8px 0;
}

.mfg-lightbox-info p {
    margin: 0 0 15px 0;
    font-size: 14px;
    opacity: 0.8;
}

.mfg-lightbox-info a {
    color: #ffffff;
    /* Makes the download link white */
    text-decoration: underline;
}

.mfg-lightbox-info a:hover {
    color: #dddddd;
}

/* ADD THIS to the end of your CSS file */

.mfg-lightbox-next,
.mfg-lightbox-prev {
    z-index: 10;
    /* This brings the buttons in front of the image */
    background-color: rgba(0, 0, 0, 0.2);
    /* Adds a subtle background for visibility */
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
}

.mfg-lightbox-next:hover,
.mfg-lightbox-prev:hover {
    background-color: rgba(0, 0, 0, 0.5);
}

/* Specific adjustments for mobile screens */
@media (max-width: 768px) {
    .mfg-lightbox-next {
        right: 5px;
        /* Moves the button in from the far edge */
    }

    .mfg-lightbox-prev {
        left: 5px;
        /* Moves the button in from the far edge */
    }
}

/* Uniform Grid */
.mfg-layout-uniform .mfg-photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0;
    /* No gaps */
}

.mfg-layout-uniform .mfg-photo-item {
    border-radius: 0;
    /* No border radius */
    aspect-ratio: 1 / 1;
    /* Square */
    margin: 0;
}

/* Mosaic Layout */
.mfg-layout-mosaic .mfg-photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    grid-auto-rows: 150px;
    grid-auto-flow: dense;
    gap: 5px;
}

.mfg-layout-mosaic .mfg-photo-item {
    aspect-ratio: unset;
    /* Let grid handle it */
    height: 100%;
    width: 100%;
}

.mfg-layout-mosaic .mfg-photo-item:nth-child(5n) {
    grid-column: span 2;
    grid-row: span 2;
}

.mfg-layout-mosaic .mfg-photo-item:nth-child(8n) {
    grid-column: span 2;
}

/* Justified Layout */
.mfg-layout-justified .mfg-photo-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.mfg-layout-justified .mfg-photo-item {
    flex-grow: 1;
    height: 200px;
    width: auto;
    /* Let flex grow handle width */
    aspect-ratio: auto;
    margin: 0;
    border-radius: 0;
}

.mfg-layout-justified .mfg-photo-item img {
    width: auto;
    height: 100%;
    min-width: 100%;
    object-fit: cover;
}

/* Ensure last row doesn't stretch too much */
.mfg-layout-justified .mfg-photo-grid::after {
    content: '';
    flex-grow: 999999999;
}

/* Full Width Breakout */
.mfg-full-width {
    width: 100vw;
    position: relative;
    left: 50%;
    right: 50%;
    margin-left: -50vw;
    margin-right: -50vw;
    padding-left: 20px;
    padding-right: 20px;
    box-sizing: border-box;
}

/* Remove side padding for Uniform and Justified layouts in Full Width mode */
.mfg-full-width[data-layout="uniform"],
.mfg-full-width[data-layout="justified"] {
    padding-left: 0 !important;
    padding-right: 0 !important;
}

/* Mobile Optimizations */
@media (max-width: 600px) {

    /* Adjust Grid Layout for smaller screens */
    .mfg-photo-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }

    /* Adjust Uniform Grid for smaller screens */
    .mfg-layout-uniform .mfg-photo-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }

    /* Adjust Mosaic Layout for smaller screens */
    .mfg-layout-mosaic .mfg-photo-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        grid-auto-rows: 100px;
    }

    /* Adjust Justified Layout row height for smaller screens */
    .mfg-layout-justified .mfg-photo-item {
        height: 150px;
    }
}