/* Shared distance from the final content block to the footer. */
:root { --bsv-footer-content-gap: 56px; }
#middle { padding-bottom: var(--bsv-footer-content-gap); }

/* Page components previously supplied their own terminal spacing. */
#middle #about-us-block.company-seo,
#middle .news-page,
#middle .articles-page,
#middle .bsv-publication,
#middle .about-company,
#middle .brands-page,
#middle .vacancies-page,
#middle .service-center-page,
#middle .bsv-cms-article,
#middle .bsv-buyers-page,
#middle .bsv-cart-page { margin-bottom: 0; }
#middle .about-company,
#middle .bsv-contacts,
#middle .product-page,
#middle .favorites-page { padding-bottom: 0; }
body.bsv-cart-page-body #middle { padding-bottom: var(--bsv-footer-content-gap); }

/* Terminal margins inside components must not extend the footer gap. */
#middle .favorites-page > :is(.favorites-page__loading, .favorites-page__error, .favorites-page__empty) {
    margin-bottom: 0;
}
#middle .favorites-page > .favorites-grid:empty { display: none; }
#middle .bsv-contacts > .bsv-contacts__section:last-child { margin-bottom: 0; }
#middle .product-page > .product-content-sections:last-child { margin-bottom: 0; }
#middle :is(.news-page__pagination, .articles-page__pagination):last-child { margin-bottom: 0; }
#middle :is(.news-page__pagination, .articles-page__pagination) #goods_loader_btns_container {
    margin-bottom: 20px;
}
#middle .bsv-cms-article > :last-child > :last-child > :last-child,
#middle .bsv-cms-article > :last-child > :last-child > :last-child > :last-child,
#middle .bsv-cms-article > :last-child > :last-child > :last-child > :last-child > :last-child {
    margin-bottom: 0 !important;
}
#middle #content404 { height: auto; min-height: 0; }

/* Remove spacing generated below the final row of product cards. */
#middle #collections { padding-bottom: 0; row-gap: 20px; }
#middle #collections::before,
#middle #collections::after { content: none; display: none; }
#middle #collections .catalog-card-column { margin-bottom: 0; }
#middle #opisanie_bot > div { padding-bottom: 0; }
#middle #opisanie_bot > div > :last-child { margin-bottom: 0; }

/* Category tiles keep their row rhythm without a trailing margin. */
#middle .block_razdels #razdels > .row {
    display: flex;
    flex-wrap: wrap;
    row-gap: 20px;
}
#middle .block_razdels #razdels > .row::before,
#middle .block_razdels #razdels > .row::after { content: none; display: none; }
#middle .block_razdels #razdels > .row > * > .image-container { margin-bottom: 0; }
body.catalog-inner-page #middle .block_razdels #razdels > .row { row-gap: 8px; }

/* Legacy forms and download rows must not add a second bottom gap. */
#middle #form-registration { margin-bottom: 0; padding-bottom: 0; }
#middle #form-registration > fieldset:last-child { padding-bottom: 0; }
#middle .list_content > .row:last-child :is(.save_price_pdf, .save_price_xls):last-child {
    margin-bottom: 0;
}

/* The left column may be taller than the main content. */
#middle #content > [class*="col-"] > .catalog-filter:last-child { padding-bottom: 0; }
#middle #content > [class*="col-"] > .b-categories:last-child > ul { margin-bottom: 0; }
#middle #content > [class*="col-"] > .b-categories:last-child > ul > li:last-child { margin-bottom: 0; }

/* The old gallery keeps spacing between rows, but not after the last row. */
#middle #gallery_list { display: flex; flex-wrap: wrap; row-gap: 12px; }
#middle #gallery_list .gallery_list_item { margin-bottom: 0; }
#middle #gallery_list_not_available { padding-bottom: 0; }

/* Generic CMS content can end with a paragraph, heading or list. */
#middle #content > [class*="col-"] > :last-child { margin-bottom: 0; }
#middle #content404 > :last-child { margin-bottom: 0; }
#middle .bsv-cms-article > :last-child,
#middle .bsv-cms-article > :last-child > :last-child,
#middle .bsv-buyers-page > :last-child { margin-bottom: 0 !important; }

@media (min-width: 768px) {
    #middle #collections.catalog-view--list { row-gap: 15px; }
}
@media (max-width: 767px) {
    :root { --bsv-footer-content-gap: 32px; }
}
