/* R372 — Front-end Drupal toolbar compatibility.
 * Load after site-finishing.css / page-editorial.css.
 * Every rule requires both the native toolbar and the public site header.
 * No anonymous, member-only, Claro, colour, plant or image changes.
 */
@media screen {
  body:has(#toolbar-administration):has(.site-header) {
    --us-admin-toolbar-fallback: 39px;
    --us-admin-top: max(var(--drupal-displace-offset-top, 0px), var(--us-admin-toolbar-fallback));
    --us-admin-left: var(--drupal-displace-offset-left, 0px);
    --us-admin-right: var(--drupal-displace-offset-right, 0px);
    --us-admin-frame-gap: 18px;
    --us-admin-frame-clearance: 36px;
    --us-admin-frame-max: 1180px;
    --us-admin-frame-gutters: 64px;
  }

  body.toolbar-horizontal.toolbar-tray-open:has(#toolbar-administration):has(.site-header) {
    --us-admin-toolbar-fallback: 79px;
  }

  /* Lift the root stacking context, not just its bar/tray children.
   * Public chrome is fixed at z-index:5000; the native toolbar uses 501/502.
   */
  body:has(#toolbar-administration):has(.site-header) #toolbar-administration {
    position: relative;
    z-index: 6000 !important;
  }

  body:has(#toolbar-administration):has(.site-header) .site-header {
    top: var(--us-admin-top) !important;
    left: var(--us-admin-left) !important;
    right: var(--us-admin-right) !important;
    width: auto !important;
  }

  /* --header-h is the measured header height, excluding its top offset.
   * Preserve the final site's 18px/36px spacing and 1180px width ceiling.
   * Center inside the available area when a native vertical tray is open.
   */
  body:has(#toolbar-administration):has(.site-header) #unisonges-scrollframe.scrollframe {
    top: calc(var(--us-admin-top) + var(--header-h, 72px) + var(--us-admin-frame-gap)) !important;
    height: calc(100dvh - var(--us-admin-top) - var(--header-h, 72px) - var(--us-admin-frame-clearance)) !important;
    left: calc((100vw + var(--us-admin-left) - var(--us-admin-right)) / 2) !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    width: min(var(--us-admin-frame-max), calc(100vw - var(--us-admin-left) - var(--us-admin-right) - var(--us-admin-frame-gutters))) !important;
    max-width: var(--us-admin-frame-max) !important;
  }

  /* These children are viewport-fixed, so they also need the offset.
   * All existing Tagetes, opacity, colour and width rules remain intact.
   */
  body:has(#toolbar-administration):has(.site-header) .site-header .mobile-backdrop {
    top: var(--us-admin-top) !important;
    left: var(--us-admin-left) !important;
    right: var(--us-admin-right) !important;
  }

  body:has(#toolbar-administration):has(.site-header) .site-header .mobile-drawer {
    top: var(--us-admin-top) !important;
    height: calc(100dvh - var(--us-admin-top)) !important;
    max-height: calc(100dvh - var(--us-admin-top)) !important;
    right: var(--us-admin-right) !important;
    max-width: calc(100vw - var(--us-admin-left) - var(--us-admin-right)) !important;
  }

  /* The home page has its own 144px header and flush content frame. */
  body:has(#toolbar-administration):has(.site-header):has(.home-page--portal) {
    --us-admin-frame-max: 1360px;
    --us-admin-frame-gutters: 80px;
  }

  body:has(#toolbar-administration):has(.home-page--portal) .site-header--refined .site-header__inner {
    width: min(var(--us-admin-frame-max), calc(100vw - var(--us-admin-left) - var(--us-admin-right) - var(--us-admin-frame-gutters))) !important;
    max-width: 100% !important;
    box-sizing: border-box;
  }

  body:has(#toolbar-administration):has(.site-header) #unisonges-scrollframe.scrollframe.unisonges-refined:has(.home-page--portal) {
    top: calc(var(--us-admin-top) + 144px) !important;
    height: calc(100dvh - var(--us-admin-top) - 144px) !important;
  }

  /* Account/auth pages retain their native width variable and auto height. */
  body.auth-account-page:has(#toolbar-administration):has(.site-header) #unisonges-scrollframe.scrollframe {
    width: min(var(--auth-account-width), calc(100vw - var(--us-admin-left) - var(--us-admin-right) - 2rem)) !important;
    max-width: var(--auth-account-width) !important;
    height: auto !important;
    max-height: calc(100dvh - var(--us-admin-top) - var(--header-h, 72px) - 1.5rem) !important;
    min-height: 0;
  }
}

@media screen and (max-width: 1100px) {
  body:has(#toolbar-administration):has(.site-header):has(.home-page--portal) {
    --us-admin-frame-gutters: 48px;
  }
}

@media screen and (max-width: 640px) {
  body:has(#toolbar-administration):has(.site-header) {
    --us-admin-frame-gap: 8px;
    --us-admin-frame-clearance: 16px;
    --us-admin-frame-gutters: 16px;
  }
}

@media screen and (max-width: 760px) {
  body:has(#toolbar-administration):has(.site-header):has(.home-page--portal) {
    --us-admin-frame-gutters: 32px;
  }

  body:has(#toolbar-administration):has(.site-header) #unisonges-scrollframe.scrollframe.unisonges-refined:has(.home-page--portal) {
    top: calc(var(--us-admin-top) + 128px) !important;
    height: calc(100dvh - var(--us-admin-top) - 128px) !important;
  }
}

@media screen and (max-width: 32rem) {
  body.auth-account-page:has(#toolbar-administration):has(.site-header) #unisonges-scrollframe.scrollframe {
    width: calc(100vw - var(--us-admin-left) - var(--us-admin-right) - 1rem) !important;
  }
}

@media screen and (max-width: 20rem) {
  body.auth-account-page:has(#toolbar-administration):has(.site-header) #unisonges-scrollframe.scrollframe {
    width: calc(100vw - var(--us-admin-left) - var(--us-admin-right) - .75rem) !important;
  }
}
