/**
 * Mediagrid - Адаптивная умная сетка медиафайлов (VK Post Grid)
 */

.mediagrid-wrapper {
    display: block;
    width: 100%;
    margin: 14px 0;
    clear: both;
    box-sizing: border-box;
    border-radius: var(--mg-radius, 12px);
    overflow: hidden;
    position: relative;
    background: transparent;
}

.mediagrid-container {
    display: flex;
    flex-wrap: wrap;
    gap: var(--mg-gap, 2px);
    width: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    background: transparent;
}

.mg-item {
    position: relative;
    overflow: hidden;
    cursor: pointer;
    user-select: none;
    background: #18191f;
    box-sizing: border-box;
    display: block;
    margin: 0;
    padding: 0;
    border: none;
    outline: none;
    flex-shrink: 0;
}

.mg-item-inner {
    position: relative;
    width: 100%;
    height: 100%;
    display: block;
    overflow: hidden;
}

.mg-image {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    object-fit: cover;
    display: block;
    transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.mg-item:hover .mg-image {
    transform: scale(1.035);
}

/* Отключение анимации зума */
.mg-no-zoom .mg-item:hover .mg-image,
.mg-no-zoom .mg-item:hover .mg-play-icon {
    transform: none !important;
}

/* Пользовательская фиксированная высота сетки (десктоп, планшет, мобильные) */
.mediagrid-wrapper.mg-has-custom-height .mediagrid-container {
    height: var(--mg-h-desk, auto);
    min-height: var(--mg-h-desk, auto);
}

.mediagrid-wrapper.mg-has-custom-height .mg-item {
    height: 100% !important;
    min-height: 0 !important;
}

.mediagrid-wrapper.mg-has-custom-height .mg-item-inner {
    height: 100% !important;
    min-height: 0 !important;
}

.mediagrid-wrapper.mg-has-custom-height.mg-smart-1 .mg-image {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
}

@media (max-width: 768px) {
    .mediagrid-wrapper.mg-has-custom-height .mediagrid-container {
        height: var(--mg-h-tab, var(--mg-h-desk, auto));
        min-height: var(--mg-h-tab, var(--mg-h-desk, auto));
    }
}

@media (max-width: 480px) {
    .mediagrid-wrapper.mg-has-custom-height .mediagrid-container {
        height: var(--mg-h-mob, var(--mg-h-tab, var(--mg-h-desk, auto)));
        min-height: var(--mg-h-mob, var(--mg-h-tab, var(--mg-h-desk, auto)));
    }
}

.mg-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.25);
    background: #23242c;
}

/* ==========================================================================
   Умные раскладки по количеству элементов (1, 2, 3, 4, 5, 6)
   Адаптируются под естественные пропорции (вертикальные и горизонтальные)
   ========================================================================== */

/* 1 элемент: естественная высота без обрезки */
.mg-smart-1 .mg-item {
    width: 100%;
}
.mg-smart-1 .mg-item-inner {
    width: 100%;
    height: auto !important;
}
.mg-smart-1 .mg-image {
    position: relative !important;
    inset: auto !important;
    width: 100% !important;
    height: auto !important;
    max-height: 850px;
    object-fit: contain;
    display: block;
}

/* 2 элемента: 2 равные колонки (50% каждая) */
.mg-smart-2 .mg-item {
    width: calc((100% - var(--mg-gap, 2px)) / 2);
}
.mg-smart-2 .mg-item-inner {
    min-height: 220px;
}

/* 3 элемента: 3 равные колонки */
.mg-smart-3 .mg-item {
    width: calc((100% - var(--mg-gap, 2px) * 2) / 3);
}
.mg-smart-3 .mg-item-inner {
    min-height: 180px;
}

/* 4 элемента: 2 строки по 2 колонки (50% каждая) */
.mg-smart-4 .mg-item {
    width: calc((100% - var(--mg-gap, 2px)) / 2);
}
.mg-smart-4 .mg-item-inner {
    min-height: 220px;
}

/* 5 элементов: 3 сверху + 2 снизу */
.mg-smart-5 .mg-item:nth-child(1),
.mg-smart-5 .mg-item:nth-child(2),
.mg-smart-5 .mg-item:nth-child(3) {
    width: calc((100% - var(--mg-gap, 2px) * 2) / 3);
}
.mg-smart-5 .mg-item:nth-child(4),
.mg-smart-5 .mg-item:nth-child(5) {
    width: calc((100% - var(--mg-gap, 2px)) / 2);
}
.mg-smart-5 .mg-item-inner {
    min-height: 180px;
}

/* 6 элементов: 3 сверху + 3 снизу */
.mg-smart-6 .mg-item {
    width: calc((100% - var(--mg-gap, 2px) * 2) / 3);
}
.mg-smart-6 .mg-item-inner {
    min-height: 180px;
}

/* ==========================================================================
   Видео: затемнение и кнопка Play
   ========================================================================== */

.mg-video-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.45) 0%, rgba(0, 0, 0, 0.1) 60%, rgba(0, 0, 0, 0.25) 100%);
    pointer-events: none;
    transition: background 0.25s ease;
}

.mg-item:hover .mg-video-overlay {
    background: linear-gradient(to top, rgba(0, 0, 0, 0.55) 0%, rgba(0, 0, 0, 0.18) 60%, rgba(0, 0, 0, 0.35) 100%);
}

.mg-play-icon {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    border: none;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    transition: all 0.2s ease;
}

.mg-play-icon svg {
    margin-left: 3px;
}

.mg-item:hover .mg-play-icon {
    transform: scale(1.12);
    background: rgba(0, 0, 0, 0.8);
    border: none;
    box-shadow: none;
    color: #ffffff;
}

.mg-provider-badge {
    display: none !important;
}

/* ==========================================================================
   Оверлей «+N ещё медиа» на последней плитке
   ========================================================================== */

.mg-more-overlay {
    position: absolute;
    inset: 0;
    background: rgba(10, 11, 15, 0.65);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    transition: background 0.25s ease;
    pointer-events: none;
}

.mg-item:hover .mg-more-overlay {
    background: rgba(10, 11, 15, 0.75);
}

.mg-more-plus {
    font-size: 34px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.5px;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    user-select: none;
}

.mg-more-label {
    display: none !important;
}

/* ==========================================================================
   Адаптивность для мобильных экранов (до 576px)
   ========================================================================== */

@media (max-width: 576px) {
    .mg-smart-1 .mg-image {
        max-height: 520px;
    }
    .mg-smart-2 .mg-item-inner,
    .mg-smart-4 .mg-item-inner {
        min-height: 160px;
    }
    .mg-smart-3 .mg-item-inner,
    .mg-smart-5 .mg-item-inner,
    .mg-smart-6 .mg-item-inner {
        min-height: 120px;
    }
    .mg-play-icon {
        width: 44px;
        height: 44px;
    }
    .mg-play-icon svg {
        width: 22px;
        height: 22px;
    }
    .mg-more-plus {
        font-size: 26px;
    }
}
