/* Separate independently titled content. Controls and results within the same
   view keep their existing compact spacing. */
@layer site-reading {
  :root { --reading-map-gap: 32px; }

  body:has(> .shared-site-header) #main.about-main > .about-section,
  body:has(> .shared-site-header) #main.editorial-main > :is(.editorial-section,.editorial-grid,.report-invitation),
  body:has(> .shared-site-header)[data-workspace="company"] #main.company-detail-page > .company-location-context,
  body:has(> .shared-site-header) #main.public-contact > :is(#contact-step,section.form-card) {
    margin-block-start: var(--reading-section-gap) !important;
    margin-block-end: 0 !important;
  }

  body:has(> .shared-site-header)[data-workspace="company"] #main.company-detail-page :is(.company-reading-grid,.company-reading) {
    row-gap: var(--reading-section-gap) !important;
  }
  body:has(> .shared-site-header)[data-workspace="company"] #main.company-detail-page .company-reading-grid > .company-reading {
    margin-block-start: 0 !important;
  }
  body:has(> .shared-site-header)[data-workspace="company"] #main.company-detail-page .company-location-context > :is(.company-location-map,.company-related-category),
  body:has(> .shared-site-header) #main.editorial-main :is(.editorial-section,.editorial-card,.editorial-notice,.report-invitation),
  body:has(> .shared-site-header) #main.public-contact > :is(#contact-step,section.form-card) {
    padding: var(--reading-panel-padding) !important;
  }
  body:has(> .shared-site-header) #main.editorial-main > :is(.editorial-section,.editorial-grid,.report-invitation):last-child {
    margin-block-end: 0 !important;
  }

  body[data-map-page="japan"]:has(> .shared-site-header[data-compact-header]) {
    --home-section-gap: 24px;
  }
  body[data-map-page="japan"]:has(> .shared-site-header[data-compact-header]) #panel-regions .map-details #metrics,
  body[data-map-page="japan"]:has(> .shared-site-header[data-compact-header]) #panel-public-reports :is(.home-map-counts,.japan-reference-counts) {
    margin-block-start: var(--home-section-gap) !important;
  }
  body[data-map-page="japan"]:has(> .shared-site-header[data-compact-header]) #panel-public-reports :is(#japan-records-breakdown,.japan-records-count-details) {
    margin-block: var(--home-section-gap) !important;
  }
  body[data-home-dashboard] #panel-regions .explorer-grid > .dashboard-side {
    row-gap: var(--home-section-gap) !important;
  }
  body[data-home-dashboard] #panel-regions .dashboard-side > section + section {
    margin-block-start: 0 !important;
  }
  @media (min-width: 1001px) {
    body[data-home-dashboard] .home-dashboard-actions {
      row-gap: var(--home-section-gap) !important;
    }
  }
  @media (max-width: 1000px) {
    body[data-home-dashboard] .home-dashboard-actions > .lookup-hero {
      margin-block-start: var(--home-section-gap) !important;
    }
  }
  @media (max-width: 700px) {
    /* The existing 8px layout gap remains around the map entry controls. */
    body[data-home-dashboard] #panel-regions .explorer-grid > :is(.dashboard-side,.explorer-picker) {
      margin-block-start: calc(var(--home-section-gap) - 8px) !important;
    }
  }

  body.world-page:not([data-world-search-embed]) #main #panel-world-map:not([hidden]) ~ :is(#world-initial-snapshot,.world-source-counts) {
    margin-block-start: var(--reading-section-gap) !important;
  }
  body.world-page:not([data-world-search-embed]) #main #panel-world-map:not([hidden]) ~ #world-initial-snapshot:not([hidden]) ~ .world-source-counts {
    margin-block-start: 12px !important;
  }

  body[data-map-page="japan"]:not([data-home-map-embed],[data-dashboard-embed]) #main #panel-regions .japan-map-quick-filters {
    margin-block-end: 0 !important;
  }
  body[data-map-page="japan"]:not([data-home-map-embed],[data-dashboard-embed]) #main #panel-regions .map-stage,
  body.world-page:not([data-world-search-embed]):has(> .shared-site-header) #main #panel-world-map .world-map-stage {
    margin-block: var(--reading-map-gap) !important;
  }
  @media (min-width: 1001px) {
    /* Reserve room for the added map margin in the whole-world first view. */
    body.world-page:not([data-world-search-embed]):has(> .shared-site-header) #main #panel-world-map .world-map-stage[data-world-focus="world"] {
      max-block-size: max(300px, calc(100svh - 490px)) !important;
    }
  }
  @media (min-width: 1500px) {
    /* The overview controls are positioned relative to the same grid row as
       the mainland map. Keep both below the empty space following filters. */
    body[data-map-page="japan"]:not([data-home-map-embed],[data-dashboard-embed]) #main #panel-regions .map-canvas[data-mainlands-overview] .japan-map-views {
      row-gap: var(--reading-map-gap) !important;
    }
    body[data-map-page="japan"]:not([data-home-map-embed],[data-dashboard-embed]) #main #panel-regions .map-canvas[data-mainlands-overview] .map-stage {
      margin-block-start: 0 !important;
    }
  }
}
