.cpt-gallery-flex {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: space-between;
}

.cpt-gallery-item {
    flex: 1 1 calc(33.333% - 10px); /* Three items per row */
    max-width: calc(33.333% - 10px);
    max-height: 350px;
    overflow: hidden;
    box-sizing: border-box;
    position: relative;
}

.cpt-gallery-item img,
.cpt-gallery-item video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
    display: block;
}

.cpt-gallery-item video {
    background: #000; /* Background color for video thumbnails */
}

/* Two-column grid on mobile */
@media (max-width: 768px) {
    .cpt-gallery-item {
        flex: 1 1 calc(50% - 10px);
    }

    .popup-content {
        max-width: 90% !important;
    }

    .cpt-gallery-popup .prev {
        right: 0px !important;
    }

    .cpt-gallery-popup .next {
        left: 0px !important;
    }
}

.cpt-gallery-popup {
    display: none;
    position: fixed;
    z-index: 10000;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
}

.popup-content {
    position: relative;
    max-width: 70%;
    max-height: 100%;
    margin: auto;
    top: 50%;
    transform: translateY(-50%);
    padding: 20px;
    background: none;
    text-align: center;
}

.cpt-gallery-popup img,
.cpt-gallery-popup video {
    width: auto;
    max-height: 785px;
    object-fit: contain;
    display: block;
    margin: auto;
}

.cpt-gallery-popup video {
    background: #000; /* Background for videos */
}

.cpt-gallery-popup .close {
    position: absolute;
    top: -10px;
    right: -10px;
    color: #fff;
    cursor: pointer;
    font-size: 20px;
}

.cpt-gallery-popup .prev,
.cpt-gallery-popup .next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: #fff;
    cursor: pointer;
    font-size: 30px;
    width: 30px;
    height: 30px;
    background-size: contain;
    background-repeat: no-repeat;
    background-color: transparent;
}

.cpt-gallery-popup .prev {
    right: -25px;
}

.cpt-gallery-popup .next {
    left: -25px;
}
