.openai-gallery {
    column-count: 2; /* 2 столбца для мобильных устройств */
    column-gap: 10px;
    padding: 10px;
    margin-bottom: 40px; /* Отступ между галереями */
}

@media (min-width: 768px) {
    .openai-gallery {
        column-count: 3; /* 3 столбца на планшетах и ПК */
    }
}

.aigal-gallery-item {
    display: grid;
    width: -webkit-fill-available;
    position: relative;
    overflow: hidden;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    text-decoration: none;
}

.aigal-gallery-item:hover {
    transform: scale(1.02);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
}

.aigal-gallery-item img,
.aigal-gallery-item video {
    width: 100%;
    height: auto;
    object-fit: cover; /* Заполнение без искажения */
    display: block;
    transition: transform 0.5s ease, opacity 0.3s ease;
}

.aigal-gallery-item:hover img,
.aigal-gallery-item:hover video {
    transform: scale(1.05);
}

/* Прелоадер внутри галерейных элементов */
.aigal-gallery-item .thumbnail-preloader {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s ease;
    opacity: 1;
    pointer-events: none; /* Чтобы клики проходили через прелоадер */
}

.aigal-gallery-item.loaded .thumbnail-preloader {
    opacity: 0;
    visibility: hidden;
}

/* Горизонтальный прелоадер */
.horizontal-preloader {
    width: 80%;
    height: 4px;
    background: #ddd;
    overflow: hidden;
    position: relative;
}

.horizontal-preloader::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: #3498db;
    animation: preload 1.5s infinite;
}

@keyframes preload {
    0% {
        left: -100%;
    }
    50% {
        left: 50%;
    }
    100% {
        left: 100%;
    }
}

/* Подписи (captions) */
.caption {
    position: relative;
    top: 0;
    left: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.6);
    color: #c5c5c5;
    padding: 10px;
    box-sizing: border-box;
    font-size: 100%;
    text-align: center;
    opacity: 1;
    transition: opacity 0.3s ease;
    line-height: 22px;
}

.aigal-gallery-item:hover .caption {
    opacity: 1;
}

/* Попап */
.aigal-popup {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.aigal-popup-content {
    position: relative;
    width: auto; /* Изменено с 100% на auto */
    height: auto; /* Изменено с 100% на auto */
    max-width: 90%;
    max-height: 90%;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    animation: scaleIn 0.3s ease;
}

.aigal-popup img,
.aigal-popup video {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    border-radius: 10px;
    object-fit: contain; /* Сохранение пропорций */
}

.aigal-popup iframe {
    border-radius: 10px;
    object-fit: contain;
    min-width: 400px;
    min-height: 650px !important;
    background: #ffffff;
    border: 10px solid #fff;
}
@media (min-width: 768px) {
    .aigal-popup-content {
        max-width: 80%;
        max-height: 80%;
    }
    .caption {
        font-size: 75%;
        line-height: 21px;
        padding: 8px;
    }
}

.aigal-close {
    position: absolute;
    top: 20px;
    right: 30px;

    cursor: pointer;
    z-index: 1001;
    transition: color 0.3s ease;
        font-size: 200%;
        color: #ff6666;
        FONT-WEIGHT: 600;
	 
}

.aigal-close:hover {
    color: #ccc;
}

/* Предзагрузчик */
.preloader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1002;
    display: flex;
    justify-content: center;
    align-items: center;
}

.spinner {
    border: 8px solid rgba(255, 255, 255, 0.3);
    border-top: 8px solid #fff;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Блок подписи в попапе */
.popup-caption {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 10px 20px;
    border-radius: 5px;
    font-size: 16px;
    text-align: center;
    max-width: 90%;
    word-wrap: break-word;
}

/* Анимации */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleIn {
    from { transform: scale(0.8); }
    to { transform: scale(1); }
}



/* Адаптивность для мобильных */
@media (max-width: 767.98px) { /* Все устройства с шириной до 767.98px */

.aigal-popup iframe {
border-radius: 10px;
    object-fit: contain;
    height: calc(85vh - 20px);
    background: #ffffff;
    border: 10px solid #fff;
}

    .aigal-close {
        top: 10px;
        right: 20px;
        font-size: 30px;
    }

    .popup-caption {
        font-size: 14px;
        padding: 8px 16px;
    }

    .preloader .spinner {
        width: 40px;
        height: 40px;
        border-width: 6px;
    }

    .caption {
        font-size: 12px; /* Обновлённый размер шрифта */
        padding: 8px; /* Обновлённые отступы */
		line-height: 16px;
    }
}

@media (max-width: 500px) { 
    .caption {
        padding: 8px;
        line-height: 12px; /* Дополнительная настройка высоты строки */
    }
}