.cpt-gallery-flex {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.cpt-gallery-item {
    flex: 1 1 calc(25% - 10px);
    max-width: calc(25% - 10px);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    background: #fff;
    height: 300px;
    overflow: hidden;
}

.cpt-gallery-item a {
    height: 100%;
    width: 100%;
}

.cpt-gallery-item.with-caption a {
    height: 90%;
}



.cpt-gallery-item video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
    display: block;
}

.cpt-gallery-item img {
    width: 100%;
    height: 100% !important;
    object-fit: cover;
    display: block;
    border-radius: 4px;
}


.cpt-gallery-item video {
    background: #000; /* Background color for video thumbnails */
}

.cpt-gallery-title {
    margin: 20px 0 10px;
    text-align: center;
    font-weight: bold;
    font-family: 'Rubik';
}

/* Admin gallery image previews - smaller, square thumbnails */
.cpt-gallery-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}
.cpt-gallery-list li {
    list-style: none;
    position: relative;
    width: 100px;
    height: 100px;
    overflow: hidden;
    border: 1px solid #ccc;
    border-radius: 4px;
}
.cpt-gallery-list li img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.cpt-gallery-list li .remove {
    position: absolute;
    top: 2px;
    right: 5px;
    color: white;
    background: red;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    text-align: center;
    line-height: 18px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10;
}

.cpt-gallery-item figcaption {
    font-size: 14px;
    color: #555;
    padding: 6px 8px 10px;
    line-height: 1.3;
    font-style: italic;
}

/* 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;
}


/* Admin gallery image previews - smaller, square thumbnails */
.cpt-gallery-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}
.cpt-gallery-list li {
    list-style: none;
    position: relative;
    width: 100px;
    height: 100px;
    overflow: hidden;
    border: 1px solid #ccc;
    border-radius: 4px;
}
.cpt-gallery-list li img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.cpt-gallery-list li .remove {
    position: absolute;
    top: 2px;
    right: 5px;
    color: white;
    background: red;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    text-align: center;
    line-height: 18px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10;
}


/* Lightbox frontend */
.cpt-lightbox-overlay {
    position: fixed;
    display: none;
    align-items: center;
    justify-content: center;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 10000;
}
.cpt-lightbox-overlay.active {
    display: flex;
}
.cpt-lightbox-img {
    max-width: 90%;
    max-height: 90%;
    border-radius: 6px;
    box-shadow: 0 0 20px rgba(0,0,0,0.6);
}
.cpt-lightbox-close,
.cpt-lightbox-prev,
.cpt-lightbox-next {
    position: absolute;
    color: white;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    padding: 10px;
}
.cpt-lightbox-close {
    top: 10px;
    right: 20px;
}
.cpt-lightbox-prev {
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
}
.cpt-lightbox-next {
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
}
