/* The homepage owns the space between widgets; each widget keeps its internal layout. */
body:is(.home, .blog) {
    --xz-home-widget-gap: 16px;
    --xz-home-header-fallback: 68px;
}

/* Use the widget gap below the navigation as well. The overlay slider and
   WordPress toolbar have their own offsets in the parent theme. */
body:is(.home, .blog):not(.nav-fixed) > header.header:not(.show-slide) {
    margin-bottom: var(--xz-home-widget-gap);
}

body:is(.home, .blog).nav-fixed:not(.admin-bar):has(> header.header:not(.show-slide)) {
    padding-top: calc(var(--xz-home-header-height, var(--xz-home-header-fallback)) + var(--xz-home-widget-gap));
}

body:is(.home, .blog) :is(.fluid-widget-wrap, main.container) .zib-widget-wrap {
    margin-top: 0;
    margin-bottom: var(--xz-home-widget-gap);
}

/* Remove only the known callback/container trailing margins, never nested cards or rows.
   CSF's explicitly configured padding and background variables are left intact. */
body:is(.home, .blog) :is(.fluid-widget-wrap, main.container) .zib-widget-wrap > .widget-container > :is(.mb20, .theme-box, .zib-widget),
body:is(.home, .blog) :is(.fluid-widget-wrap, main.container) .zib-widget-wrap > .widget-container > div > .widget-content > :last-child:is(.mb20, .theme-box, .zib-widget, .xz-scrolling-notice) {
    margin-bottom: 0;
}

/* The native new-slider callback adds a wrapper around its own mb20 element. */
body:is(.home, .blog) :is(.fluid-widget-wrap, main.container) .zib-widget-wrap > .widget-container > div > .widget-content > .zib-slider:last-child > .slide-widget.mb20 {
    margin-bottom: 0;
}

/* Older widgets and the native homepage article tabs do not use the CSF wrapper. */
body:is(.home, .blog) :is(.fluid-widget-wrap, .content-layout, .sidebar) > :is(.zib-widget, .theme-box, .home-tab-content),
body:is(.home, .blog) .fluid-widget-wrap > .widget-container > :is(.zib-widget, .theme-box) {
    margin-top: 0;
    margin-bottom: var(--xz-home-widget-gap);
}

@media (max-width: 767px) {
    body:is(.home, .blog) {
        --xz-home-widget-gap: 12px;
    }
}

@media (max-width: 640px) {
    body:is(.home, .blog) {
        --xz-home-header-fallback: 52px;
    }
}
