/* The outer ad region owns the gap. Empty SDK slots reserve no space. */
body[data-page] {
  --ad-flow-gap: 5px;
}

body[data-page] :is(.home-container,.home-intro,.task-container,.result-container,.merchant-container,.stores-container) > .ad-region,
body[data-page] .ad-band {
  margin-top: 0;
  margin-bottom: 0;
}

/* Only rendered media earns disclosure/spacing; SDK wrappers alone do not. */
body[data-page] :is(.home-container,.home-intro,.task-container,.result-container,.merchant-container,.stores-container) > .ad-region:has(> .ad-slot-inline[data-ad-filled="true"],> .temporary-unit-inline),
body[data-page] .ad-band:has(> .ad-slot-top[data-ad-filled="true"],> .temporary-unit-top) {
  margin-top: var(--ad-flow-gap);
  margin-bottom: var(--ad-flow-gap);
}

body[data-page] .ad-region > .ad-slot-inline[data-ad-filled="true"] {
  margin-top: 0;
  margin-bottom: 0;
}

/* The disclosure is content, not an extra margin around the creative. */
body[data-page="articles"] .ad-band:has(> .ad-slot-top[data-ad-filled="true"],> .temporary-unit-top) {
  margin-bottom: 0;
}

body[data-page] .ad-region > .ad-slot-inline[data-ad-filled="true"]::before {
  line-height: 14px;
  margin: 0;
}

/* Avoid adding adjacent component margins to the shared ad gap. */
body[data-page] :is(.home-container,.home-intro,.task-container,.result-container,.merchant-container,.stores-container) > :has(+ .ad-region) {
  margin-bottom: 0;
}
body[data-page] :is(.home-container,.home-intro,.task-container,.result-container,.merchant-container,.stores-container) > .ad-region + * {
  margin-top: 0;
}
body[data-page] .merchant-intro > .merchant-country,
body[data-page] .merchant-intro > .merchant-heading:last-child,
body[data-page] .stores-intro > .stores-tools {
  margin-bottom: 0;
}
body[data-page] .merchant-body > .merchant-grid,
body[data-page] .stores-body > .stores-grid,
body[data-page] :is(.merchant-body,.stores-body) > .sf-feedback:not(.is-quiet) {
  margin-top: 0;
}
body[data-page] .task-heading:has(+ .ad-region) {
  padding-bottom: 0;
}

/* The reference list's middle banner stays full-width and collapses when empty. */
body[data-page] .reference-coupons > .ad-region,
body[data-page] .reference-deal-page .merchant-body > .ad-region {
  margin: 0;
}
body[data-page] .reference-coupons > .ad-region:has(> .ad-slot-inline[data-ad-filled="true"],> .temporary-unit-inline),
body[data-page] .reference-deal-page .merchant-body > .ad-region:has(> .ad-slot-inline[data-ad-filled="true"],> .temporary-unit-inline) {
  margin-top: var(--ad-flow-gap);
  margin-bottom: var(--ad-flow-gap);
}
body[data-page] .reference-coupons > .ad-region:has(> .ad-slot-inline[data-ad-filled="true"],> .temporary-unit-inline) + .reference-coupon-card {
  margin-top: 0;
}
body[data-page] .reference-deal-page .merchant-body > .ad-region:has(> .ad-slot-inline[data-ad-filled="true"],> .temporary-unit-inline) + .reference-related > .reference-related-title {
  margin-top: 0;
}
