/* Основные стили галереи */
.xcalendar-gallery-item {
    transition: transform 0.3s ease;
    position: relative;
    list-style: none;
    margin: 0;
    padding: 0;
}

.xcalendar-gallery-item:hover {
    transform: scale(1.02);
    z-index: 1;
}

.xcalendar-image-placeholder {
    position: relative;
    padding-bottom: 75%;
    background: #f5f5f5;
    overflow: hidden;
    border-radius: 4px;
}

.xcalendar-gallery-preview {
    transition: opacity 0.3s ease;
    opacity: 0.9;
    position: absolute;
    top: 0; /* Выравнивание по верхнему краю */
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover; /* Изменяем на cover для выравнивания по верху */
    object-position: top center; /* Выравнивание содержимого изображения по верху */
    cursor: pointer;
}

.xcalendar-gallery-preview:hover {
    opacity: 1;
}

.xcalendar-gallery-preview.loaded {
    animation: xcalendarFadeIn 0.5s ease;
}

@keyframes xcalendarFadeIn {
    from { opacity: 0; }
    to { opacity: 0.9; }
}

.xcalendar-gallery-caption {
    padding: 10px 5px;
    font-size: 14px;
    line-height: 1.4;
    text-align: center;
    background: #f9f9f9;
    border-top: 1px solid #eee;
    margin: 0;
}

.xcalendar-loading-indicator {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(245, 245, 245, 0.8);
}

.xcalendar-loading-indicator .loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* Стили для галереи WordPress */
.wp-block-gallery.columns-3.is-cropped {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -8px;
}

.wp-block-gallery.columns-3.is-cropped .blocks-gallery-item {
    flex: 0 0 calc(33.333% - 16px);
    margin: 8px;
    padding: 0;
}

.wp-block-gallery.columns-3.is-cropped .tiled-gallery__item {
    margin: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Обеспечиваем одинаковую высоту для всех элементов галереи */
.wp-block-gallery.columns-3.is-cropped .xcalendar-gallery-item {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.wp-block-gallery.columns-3.is-cropped .xcalendar-image-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Модальное окно */
.xcalendar-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 9999;
    cursor: pointer;
}

.xcalendar-modal-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    margin: 2% auto;
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    cursor: default;
}

.xcalendar-modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #8B0000;
    color: white;
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
}

.xcalendar-modal-close:hover {
    background: #a30000;
}

.xcalendar-modal-prev,
.xcalendar-modal-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(139, 0, 0, 0.7);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
}

.xcalendar-modal-prev:hover,
.xcalendar-modal-next:hover {
    background: rgba(139, 0, 0, 0.9);
}

.xcalendar-modal-prev {
    left: 10px;
}

.xcalendar-modal-next {
    right: 10px;
}

.xcalendar-modal-image-container {
    text-align: center;
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.xcalendar-modal-image {
    max-width: 100%;
    max-height: 70vh;
    display: block;
    margin: 0 auto;
    transition: opacity 0.3s ease;
    border-radius: 4px;
    object-fit: contain;
    object-position: top center; /* Выравнивание модального изображения по верху */
}

.xcalendar-modal-image.loading {
    opacity: 0.3;
}

.xcalendar-modal-loading {
    display: none;
    padding: 20px;
}

.xcalendar-modal-caption {
    text-align: center;
    margin-top: 15px;
    padding: 10px;
    font-style: italic;
    color: #333;
    font-size: 16px;
    line-height: 1.4;
}

/* Адаптивность */
@media (max-width: 768px) {
    .wp-block-gallery.columns-3.is-cropped .blocks-gallery-item {
        flex: 0 0 calc(50% - 16px);
    }
    
    .xcalendar-modal-content {
        max-width: 95%;
        max-height: 95%;
        margin: 1% auto;
        padding: 15px;
    }
    
    .xcalendar-modal-prev,
    .xcalendar-modal-next {
        width: 35px;
        height: 35px;
        font-size: 18px;
    }
    
    .xcalendar-modal-close {
        width: 25px;
        height: 25px;
        font-size: 18px;
    }
}

@media (max-width: 480px) {
    .wp-block-gallery.columns-3.is-cropped .blocks-gallery-item {
        flex: 0 0 calc(100% - 16px);
    }
    
    .xcalendar-gallery-caption {
        font-size: 12px;
        padding: 8px 3px;
    }
    
    .xcalendar-modal-content {
        padding: 10px;
    }
}

/* Специальный класс для выравнивания по верху */
.xcalendar-gallery-preview.top-aligned {
    object-position: top center;
}

/* Улучшенный контейнер для изображений */
.xcalendar-image-placeholder.top-aligned-container {
    display: flex;
    align-items: flex-start; /* Выравнивание по верху */
    justify-content: center;
}

/* Гарантированное выравнивание по верху с высотой */
.xcalendar-gallery-figure {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.xcalendar-image-placeholder {
    flex: 1;
    display: flex;
    align-items: flex-start; /* Ключевое изменение - выравнивание по верху */
}

/* Если используете Grid layout */
.xcalendar-grid-wrapper {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 15px;
    align-items: start; /* Выравнивание всех элементов по верху */
}

.xcalendar-grid-item {
    display: flex;
    flex-direction: column;
}

/* Для WordPress галереи */
.wp-block-gallery.columns-3.is-cropped .blocks-gallery-item {
    align-self: start; /* Выравнивание элементов галереи по верху */
}

.xcalendar-gallery-preview.top-aligned-no-crop {
    object-fit: contain; /* Не обрезать, сохранить пропорции */
    object-position: top center; /* Выравнивание по верху */
    background: white; /* Фон для пустых областей */
}

/* Или с flex контейнером */
.xcalendar-image-placeholder.flex-top {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background: white;
}

/* Вариант 1: Полное заполнение (обрезает) */
.xcalendar-gallery-preview.fill {
    object-fit: cover;
    object-position: center;
}

/* Вариант 2: Вся картинка видна (пропорционально) */
.xcalendar-gallery-preview.contain {
    object-fit: contain;
    object-position: center;
    background: white;
}

/* Вариант 3: Вся картинка + верхнее выравнивание */
.xcalendar-gallery-preview.contain-top {
    object-fit: contain;
    object-position: top center;
    background: white;
}