/* CP529: the browser document owns page scrolling, including the side margins.
 * A layer makes these important layout resets outrank the legacy, unlayered
 * fixed-frame rules without duplicating selectors or changing authored content.
 * Inner dialogs, menus, tables and form surfaces keep their own overflow rules.
 */
@layer unisonges-document-scroll {
  @media screen {
    html:has(#unisonges-scrollframe) {
      height: auto !important;
      min-height: 100% !important;
      overflow-x: clip !important;
      overflow-y: auto !important;
      scrollbar-gutter: stable;
      scrollbar-width: thin;
      scrollbar-color: rgb(69 96 79 / 48%) transparent;
    }
    html:has(#unisonges-scrollframe)::-webkit-scrollbar { width: 8px; height: 8px; }
    html:has(#unisonges-scrollframe)::-webkit-scrollbar-track { background: transparent; }
    html:has(#unisonges-scrollframe)::-webkit-scrollbar-thumb {
      background: rgb(69 96 79 / 48%);
      border: 2px solid transparent;
      border-radius: 8px;
      background-clip: padding-box;
    }
    html:has(#unisonges-scrollframe)::-webkit-scrollbar-thumb:hover { background-color: rgb(69 96 79 / 72%); }
    body:has(#unisonges-scrollframe) {
      --us-document-gap: 18px;
      --us-document-header: var(--header-h, 76px);
      --us-document-start: calc(var(--us-admin-top, 0px) + var(--us-document-header) + var(--us-document-gap) + var(--us-event-preview-height, 0px));
      height: auto !important;
      min-height: 100svh !important;
      box-sizing: border-box !important;
      overflow-x: clip !important;
      overflow-y: visible !important;
      padding-top: var(--us-document-start) !important;
      padding-right: var(--us-admin-right, 0px) !important;
      padding-bottom: var(--us-document-gap) !important;
      padding-left: var(--us-admin-left, 0px) !important;
    }
    body:has(#unisonges-scrollframe):has(.home-page--portal) {
      --us-document-gap: 0px;
      --us-document-header: 144px;
    }
    #unisonges-scrollframe.scrollframe {
      position: relative !important;
      inset: auto !important;
      transform: none !important;
      height: auto !important;
      min-height: 0 !important;
      max-height: none !important;
      margin: 0 auto !important;
      overflow: visible !important;
      overscroll-behavior: auto !important;
    }
    #unisonges-scrollframe > .scrollframe__inner {
      overflow: visible !important;
    }
    body:has(#unisonges-scrollframe) #main-content,
    body:has(#unisonges-scrollframe) #main-content :where([id], :focus) {
      scroll-margin-top: calc(var(--us-document-start) + 12px);
      scroll-margin-bottom: 16px;
    }
    /* These surfaces already isolate their focus. Keep the page behind them
     * still while preserving the surfaces' own vertical scrolling. */
    html:has(#unisonges-scrollframe):has(body.modal-open),
    html:has(#unisonges-scrollframe):has(.mobile-drawer:not([hidden]):not([inert])),
    html:has(#unisonges-scrollframe):has(body > .ui-widget-overlay),
    html:has(#unisonges-scrollframe):has(#unisonges-navigation-guard[open]) {
      overflow-y: hidden !important;
    }
  }
  @media screen and (forced-colors: active) {
    html:has(#unisonges-scrollframe) { scrollbar-color: auto; }
  }
  @media screen and (max-width: 640px) {
    body:has(#unisonges-scrollframe) { --us-document-gap: 8px; }
  }
  @media screen and (max-width: 760px) {
    body:has(#unisonges-scrollframe):has(.home-page--portal) {
      --us-document-gap: 0px;
      --us-document-header: 128px;
    }
  }
}

/* CP529 home-only follow-up: keep the transparent header separate from the
 * scrolling cards. The native scroll viewport covers the side margins too;
 * the authored home and its footer keep their existing centred reading width.
 * Load after document-scroll529.css. No wheel interception or content change.
 */
@layer unisonges-document-scroll {
  @media screen {
    html:has(#unisonges-scrollframe .home-page--portal) {
      height: 100% !important;
      overflow: hidden !important;
      scrollbar-gutter: auto !important;
    }
    body:has(#unisonges-scrollframe .home-page--portal) {
      --us-home-scroll-gutters: 80px;
      height: 100% !important;
      min-height: 0 !important;
      padding: 0 !important;
      overflow: hidden !important;
    }
    #unisonges-scrollframe.scrollframe.unisonges-refined:has(.home-page--portal) {
      position: fixed !important;
      top: var(--us-document-start) !important;
      right: var(--us-admin-right, 0px) !important;
      bottom: 0 !important;
      left: var(--us-admin-left, 0px) !important;
      width: auto !important;
      max-width: none !important;
      height: auto !important;
      min-height: 0 !important;
      max-height: none !important;
      margin: 0 !important;
      transform: none !important;
      background: transparent !important;
      border: 0 !important;
      border-radius: 0 !important;
      box-shadow: none !important;
      overflow-x: hidden !important;
      overflow-y: auto !important;
      overscroll-behavior: contain !important;
      scrollbar-gutter: stable both-edges !important;
      scrollbar-width: thin !important;
      scrollbar-color: rgb(69 96 79 / 48%) transparent !important;
    }
    #unisonges-scrollframe.scrollframe.unisonges-refined:has(.home-page--portal) > .scrollframe__inner {
      width: min(1360px, calc(100vw - var(--us-admin-left, 0px) - var(--us-admin-right, 0px) - var(--us-admin-frame-gutters, var(--us-home-scroll-gutters)))) !important;
      max-width: 100% !important;
      box-sizing: border-box !important;
      margin-inline: auto !important;
      padding: 0 !important;
      overflow: visible !important;
    }
    #unisonges-scrollframe:has(.home-page--portal)::-webkit-scrollbar { width: 8px !important; height: 8px !important; }
    #unisonges-scrollframe:has(.home-page--portal)::-webkit-scrollbar-track { background: transparent !important; }
    #unisonges-scrollframe:has(.home-page--portal)::-webkit-scrollbar-thumb {
      background: rgb(69 96 79 / 48%) !important;
      border: 2px solid transparent !important;
      border-radius: 8px !important;
      background-clip: padding-box !important;
    }
    #unisonges-scrollframe:has(.home-page--portal)::-webkit-scrollbar-thumb:hover { background-color: rgb(69 96 79 / 72%) !important; }
    /* This scrollport already starts below the header/admin/preview strip. */
    body:has(#unisonges-scrollframe .home-page--portal) #main-content,
    body:has(#unisonges-scrollframe .home-page--portal) #main-content :where([id], :focus) {
      scroll-margin-top: 12px !important;
    }
    /* A document lock alone cannot lock this home scrollport. Keep the native
     * modal/drawer contents scrollable while their background remains still. */
    body.modal-open #unisonges-scrollframe.scrollframe.unisonges-refined:has(.home-page--portal),
    body:has(.mobile-drawer:not([hidden]):not([inert])) #unisonges-scrollframe.scrollframe.unisonges-refined:has(.home-page--portal),
    body:has(> .ui-widget-overlay) #unisonges-scrollframe.scrollframe.unisonges-refined:has(.home-page--portal),
    body:has(#unisonges-navigation-guard[open]) #unisonges-scrollframe.scrollframe.unisonges-refined:has(.home-page--portal) {
      overflow-y: hidden !important;
    }
  }
  @media screen and (max-width: 1100px) {
    body:has(#unisonges-scrollframe .home-page--portal) { --us-home-scroll-gutters: 48px; }
  }
  @media screen and (max-width: 760px) {
    body:has(#unisonges-scrollframe .home-page--portal) { --us-home-scroll-gutters: 32px; }
  }
  @media screen and (forced-colors: active) {
    #unisonges-scrollframe.scrollframe.unisonges-refined:has(.home-page--portal) {
      background: Canvas !important;
      scrollbar-color: auto !important;
    }
  }
}
