/* Public hubs and forms keep a comfortable content width. Their extra rail
   appears only on wide desktops; slot availability follows the content height. */
.bhm-editorial .bhm-public-ad-layout { display: block; width: 100%; min-width: 0; }
.bhm-editorial .bhm-public-ad-content { align-self: start; width: 100%; min-width: 0; }
.bhm-editorial .bhm-public-ad-rail { display: none; min-width: 0; margin: 0; padding: 0; }

@media screen and (min-width: 1280px) {
  .bhm-editorial .bhm-public-ad-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 160px;
    align-items: start;
    gap: 32px;
  }
  .bhm-editorial .bhm-public-ad-rail {
    display: grid;
    align-self: start;
    align-content: start;
    justify-items: start;
    gap: 32px;
    width: 160px;
  }
}

/* Loaded after each page family: remove only an empty advertising column.
   The controller sets this state after fitting, and clears it before measuring
   again. Related reading and supporter sidebars never receive this state. */
@media screen and (min-width: 960px) {
  .bhm-editorial .bhm-public-ad-layout:has(> .bhm-public-ad-rail[data-bhm-ad-rail-empty="true"]),
  .bhm-editorial .bhm-home .bhm-home-band--has-rail:has(> .bhm-home-band-rail[data-bhm-ad-rail-empty="true"]),
  .bhm-editorial .bhm-home .bhm-home-body--has-rail:has(> .bhm-home-body-rail[data-bhm-ad-rail-empty="true"]),
  .bhm-editorial .bhm-service-archive .bhm-service-shell:has(> .bhm-service-adrail[data-bhm-ad-rail-empty="true"]),
  .bhm-editorial .bhm-video-library .bhm-video-library-shell:has(> .bhm-video-library-adrail[data-bhm-ad-rail-empty="true"]),
  .bhm-editorial .bhm-subjects .bhm-subject-layout.has-ad:has(> .bhm-subject-ad[data-bhm-ad-rail-empty="true"]),
  .bhm-editorial .bhm-event-layout.bhm-event-layout--rail:has(> .bhm-event-ad-rail[data-bhm-ad-rail-empty="true"]),
  body.bhm-editorial:is(.archive, .search, .blog) .page-wrap > .container:has(> .banner-wrap[data-bhm-ad-rail][data-bhm-ad-rail-empty="true"]) {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Readers keep their text measure and related panels. Reset named areas as
     well as columns, avoiding an implicit vacant advertising column. */
  .bhm-editorial .bhm-article-layout.bhm-article-layout--rail:not(.bhm-article-layout--supporters):has(> .bhm-reader-ad-rail[data-bhm-ad-rail-empty="true"]) {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "reader";
    grid-template-rows: auto;
    column-gap: 0;
    max-width: 780px;
    margin-inline: auto;
  }
  .bhm-editorial .bhm-article-layout.bhm-article-layout--rail.bhm-article-layout--sidebar:not(.bhm-article-layout--supporters):has(> .bhm-reader-ad-rail[data-bhm-ad-rail-empty="true"]) {
    grid-template-areas: "reader" "sidebar";
    grid-template-rows: auto auto;
  }
  .bhm-editorial .bhm-article-layout.bhm-article-layout--rail.bhm-article-layout--news:not(.bhm-article-layout--supporters):has(> .bhm-reader-ad-rail[data-bhm-ad-rail-empty="true"]) {
    max-width: var(--bhm-news-reader-max, 1040px);
  }
}

@media screen and (min-width: 1280px) {
  /* The generic desktop reader has a separate 260px related-information
     sidebar. Preserve it in column two when only the third, ad column is empty.
     News readers keep their existing related cards beneath the article. */
  .bhm-editorial .bhm-article-layout.bhm-article-layout--rail.bhm-article-layout--sidebar:not(.bhm-article-layout--news):not(.bhm-article-layout--supporters):has(> .bhm-reader-ad-rail[data-bhm-ad-rail-empty="true"]) {
    grid-template-columns: minmax(0, 1fr) 260px;
    grid-template-areas: "reader sidebar";
    grid-template-rows: auto;
    column-gap: 32px;
    max-width: 1072px;
  }
}

@media print {
  .bhm-editorial .bhm-public-ad-layout { display: block; }
  .bhm-editorial .bhm-public-ad-rail { display: none !important; }
}
