/* ==========================================================================
   HOMEPAGE LAYOUT - Структура главной страницы по макету
   ========================================================================== */

/* 1. Большой пост на всю ширину */
.main-post-section {
    padding: 70px 0;
}

/* 3. Блок с постами и баннером */
.posts-section {
    padding: 20px 0;
    overflow: visible !important; /* Важно для работы sticky баннеров */
    position: relative;
    z-index: 1;
    background: #f5f5f5;
}

section.posts-section.posts-section--first {
    padding-top: 10px;
    padding-bottom: 5px;
}

.posts-section__container {
    display: flex;
    justify-content: space-between;
    gap: 50px;
    /* Расстояние между контентом и баннером справа */
    position: relative;
    overflow: visible; /* Важно для работы sticky */
}

/* Отступы между блоками ленты */
.posts-section:not(:first-of-type) {
    margin-top: 20px;
    margin-bottom: 20px;
}

/* Баннер между чанками */
.chunk-banner {
    width: 100%;
    margin: 0 auto;
    position: relative;
    z-index: 1;
    background: #fff;
}

.chunk-banner__placeholder {
    width: 100%;
    height: 250px;
    background-color: #f5f5f5;
    border: 1px solid #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background-color 0.3s ease;
}

.chunk-banner__placeholder:hover {
    background-color: #e8e8e8;
}

.chunk-banner__placeholder span {
    color: #666;
    font-size: 16px;
    font-weight: 500;
    text-align: center;
    line-height: 1.4;
}

.posts-section__content {
    min-width: 0;
    max-width: 715px;
    /* Максимальная ширина блока с постами */
    display: flex;
    flex-direction: column;
    gap: 0 40px;
    /* Расстояние между постами внутри */
    position: relative;
    z-index: 1; /* z-index ниже хедера (z-index: 9999), но выше брендированного фона (z-index: 0) */
}

/* Два больших поста друг за другом */
.posts-section__large-post {
    margin-bottom: 60px;
}

.posts-section__large-post:last-child {
    margin-bottom: 0;
}

/* Строка с двумя средними постами */
.posts-section__medium-row {
    display: flex;
    gap: 50px;
    justify-content: space-between;
    /* margin-bottom: 20px; */
}

.posts-section__medium-post {
    width: 100%;
    max-width: 330px;
}

/* Строка с тремя средними постами */
.posts-section__medium-row--three {
    display: flex;
    gap: 55px;
    margin-top: 60px;
    justify-content: flex-start;
}

.posts-section__medium-row--three .posts-section__medium-post {
    width: 100%;
    max-width: 330px;
}

/* Правый сайдбар с баннером */
.posts-section__sidebar {
    width: 330px;
    flex-shrink: 0;
    position: relative;
    min-height: 650px;
}

.posts-section__banner {
    position: sticky;
    top: 70px;
    width: 330px;
    height: 660px;
    margin-bottom: 60px;
    /* Sidebar banner aspect-ratio (330x660) — резервируем место до загрузки */
    aspect-ratio: 330 / 660;
}

/* Десктоп баннер */
.banner-article-left--desktop {
    display: block;
    width: 100%;
    height: 100%;
    aspect-ratio: 330 / 660;
}

/* Изображения внутри баннера */
.banner-article-left--desktop img {
    width: 100%;
    height: auto;
    object-fit: contain;
    max-height: 660px;
}

/* Мобильный баннер */
.banner-middle-flat--mobile {
    display: none;
}

.posts-section__banner-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f9f9f9;
    border-radius: 8px;
    transition: background-color 0.3s ease;
}

.posts-section__banner-placeholder:hover {
    background-color: #e8e8e8;
}

.posts-section__banner-placeholder span {
    color: #666;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    line-height: 1.4;
}

/* Планшет: первая карточка на всю ширину, остальные по 2 в ряд (главная, категории, архивы, теги, AJAX) */
@media (min-width: 769px) and (max-width: 1150px) {
    .posts-section__container {
        display: flex;
        flex-direction: column;
    }

    .posts-section__sidebar {
        display: none;
    }

    .posts-section__content {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 40px 50px;
        max-width: 100%;
    }

    /* Все посты по 2 в ряд, кроме самого последнего в чанке — он на всю ширину */
    .posts-section__content > .posts-section__large-post {
        grid-column: span 1;
    }

    .posts-section__medium-row {
        grid-column: 1 / -1;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 50px;
    }

    .posts-section__medium-post {
        max-width: 100%;
    }

    .posts-section__medium-row--three {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 50px;
        margin-top: 60px;
    }

    .posts-section__medium-row--three .posts-section__medium-post {
        max-width: 100%;
    }

    /* Последний пост в чанке (7-й) — на всю ширину */
    .posts-section__medium-row--three .posts-section__medium-post:last-child {
        grid-column: 1 / -1;
    }
}

/* До 768px контейнер без сайдбара, контент в одну колонку */
@media (max-width: 768px) {
    .posts-section__container {
        display: flex;
        flex-direction: column;
    }

    .posts-section__sidebar {
        display: none;
    }

    .posts-section__medium-row {
        display: flex;
        flex-direction: column;
        max-width: 715px;
    }

    .posts-section__medium-post {
        max-width: 100%;
    }

    .posts-section__medium-row--three .posts-section__medium-post {
        max-width: 100%;
    }
}

@media (max-width: 768px) {
    .main-post-section {
        padding: 40px 0;
    }

    .posts-section {
        padding: 20px 0;
    }

    .posts-section.posts-section--first {
        padding: 5px 0 20px;
    }


    .posts-section__medium-row {
        flex-direction: column;
        gap: 40px;
        margin-bottom: 0px;
    }

    .posts-section__medium-row--three {
        flex-direction: column;
        gap: 40px;
        margin-top: 40px;
    }

    .posts-section__content {
        gap: 0 30px;
        /* Меньше расстояние на мобильных */
        max-width: 100%;
    }

    .posts-section__sidebar {
        max-width: 100%;
    }

    .posts-section__banner {
        width: 100%;
        max-width: 330px;
        height: auto;
        /* Та же пропорция, что на десктопе: 1:2 (330/660) */
        aspect-ratio: 1 / 2;
    }

    /* На мобилках показываем мобильный баннер */
    .banner-article-left--desktop {
        display: none;
    }

    .banner-middle-flat--mobile {
        display: flex;
        width: 100%;
        height: 100%;
        justify-content: center;
        align-items: center;
    }

    .chunk-banner {
        margin: 30px auto;
    }

    .chunk-banner__placeholder {
        height: 200px;
    }
    .posts-section__large-post{
        margin-bottom: 40px;
    }
}

@media (max-width: 480px) {
    /* Отступы между блоками ленты */
.posts-section:not(:first-of-type) {
    margin-top: 10px;
    margin-bottom: 10px;
}


    .posts-section__banner {
        height: auto;
        aspect-ratio: 1 / 2;
    }

    /* На очень маленьких экранах тоже мобильный баннер */
    .banner-article-left--desktop {
        display: none;
    }

    .banner-middle-flat--mobile {
        display: flex;
        width: 100%;
        height: 100%;
        justify-content: center;
        align-items: center;
    }

    .chunk-banner {
        margin: 20px auto;
    }

    .chunk-banner__placeholder {
        height: 150px;
    }
}