/* Main-site inner pages: the page rule belongs below its title block.
   Home section rules, admin panels and independent/embedded portals are excluded. */
body[data-site-design]:not([data-review-area="admin"]):not([data-design-portal]):not(:has(.review-home-reference)) #main-content :is(
  .page-masthead, .registration-page-head, .certificate-page-head,
  .topic-page-head, .ar-list-head, .certificate-query-heading,
  .account-header-v2, .oa-page-head, .calendar-page-head,
  .course-learning-head, .calendar-page-heading, .rg-page-heading,
  .sf-page-heading
) {
  border-top: 0;
  border-bottom: 2px solid var(--sm-primary);
}

body[data-site-design]:not([data-review-area="admin"]):not([data-design-portal]):not(:has(.review-home-reference)) #main-content .sf-page-heading {
  margin-bottom: 24px;
}

body[data-site-design]:not([data-review-area="admin"]):not([data-design-portal]):not(:has(.review-home-reference)) #main-content .rg-service-tabs {
  padding-top: 22px;
}

/* Reading and detail shells must not draw a second rule above their heading. */
body[data-site-design]:not([data-review-area="admin"]):not([data-design-portal]):not(:has(.review-home-reference)) #main-content :is(.article, .course-detail, .certificate-query-card)::before {
  content: none;
  display: none;
}

body[data-site-design]:not([data-review-area="admin"]):not([data-design-portal]):not(:has(.review-home-reference)) #main-content :is(
  .article, .article-page, .ar-reading-panel, .registration-detail-info,
  .school-workspace-content, .auth-card, .school-access-card,
  .sc-native .certificate-query-card
) {
  border-top: 0;
}

/* The desktop reading sidebar becomes a full-width block after the article. */
@media (max-width: 1000px) {
  body[data-site-design]:not([data-review-area="admin"]):not([data-design-portal]) #main-content .ro-page.ar-detail-page .ar-detail-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  body[data-site-design]:not([data-review-area="admin"]):not([data-design-portal]) #main-content .ro-page.ar-detail-page :is(.ar-reading-panel, .ar-reading-aside) {
    grid-column: 1;
    grid-row: auto;
  }
}

body[data-site-design]:not([data-review-area="admin"]):not([data-design-portal]):not(:has(.review-home-reference)) #main-content .ar-detail-heading {
  border-top: 0;
  border-bottom: 2px solid var(--sm-primary);
}

body[data-site-design]:not([data-review-area="admin"]):not([data-design-portal]):not(:has(.review-home-reference)) #main-content .course-a-hero {
  border-top: 0;
  border-bottom: 2px solid var(--sm-primary);
  padding-bottom: 24px;
}

body[data-site-design]:not([data-review-area="admin"]):not([data-design-portal]):not(:has(.review-home-reference)) #main-content :is(
  .article > h1 + .meta,
  .registration-detail-info > h1 + .meta,
  .sc-native .certificate-query-intro,
  .compliance-page > h1,
  .auth-card > .auth-brand,
  .auth-card > .auth-title,
  .school-access-card > div > h2
) {
  padding-bottom: 20px;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--sm-primary);
}

/* Keep only the heading's rule when the following panel directly adjoins it. */
body[data-site-design]:not([data-review-area="admin"]):not([data-design-portal]):not(:has(.review-home-reference)) #main-content :is(
  .topic-page-head + .topic-competition-section,
  .oa-page-head + .oa-panel,
  .page-masthead + .oa-panel
) {
  border-top: 0;
}
