/* Phase 39 — hard-fixed ERP sidebar geometry
   Phase 38 separated menu scrolling, but position:sticky still allowed the sidebar shell to be
   influenced by document/ancestor scroll geometry in some browsers/pages. Desktop now uses a
   real viewport-fixed sidebar. The main page keeps normal window scrolling, so forms/modals and
   route scroll restoration do not need to be rewritten. */

:root{--erp-shell-top:60px}
body.ui-v2{--erp-sidebar-w:272px}
body[data-theme="clarity-pro"]{--erp-sidebar-w:242px}
body.ui-v2.sidebar-compact{--erp-sidebar-w:78px}

@media (min-width:881px){
  body.ui-v2 .layout{
    display:grid!important;
    grid-template-columns:var(--erp-sidebar-w) minmax(0,1fr)!important;
    align-items:start!important;
    min-height:calc(100vh - var(--erp-shell-top))!important;
    min-height:calc(100dvh - var(--erp-shell-top))!important;
    position:relative;
  }
  body.ui-v2 .sidebar{
    position:fixed!important;
    top:var(--erp-shell-top)!important;
    right:auto!important;
    bottom:0!important;
    left:0!important;
    width:var(--erp-sidebar-w)!important;
    height:auto!important;
    min-height:0!important;
    max-height:none!important;
    overflow:hidden!important;
    overscroll-behavior:none;
    align-self:auto!important;
    z-index:60;
    box-sizing:border-box;
    margin:0!important;
  }
  body.ui-v2 .main{
    grid-column:2!important;
    min-width:0!important;
    width:100%!important;
    box-sizing:border-box;
  }
  body.ui-v2 .sidebar-scroll{
    min-height:0!important;
    max-height:none!important;
    overflow-y:auto!important;
    overflow-x:hidden!important;
    overscroll-behavior-y:contain;
    scrollbar-gutter:stable;
  }
  body.ui-v2 .sidebar-collapse-control,
  body.ui-v2 .sidebar-search,
  body.ui-v2 .sidebar-footer{flex-shrink:0!important}
}

/* Mobile stays an off-canvas fixed panel, but uses the measured topbar height as well. */
@media (max-width:880px){
  body.ui-v2 .layout{display:block!important;min-height:calc(100dvh - var(--erp-shell-top))!important}
  body.ui-v2 .sidebar{
    position:fixed!important;
    top:var(--erp-shell-top)!important;
    bottom:0!important;
    height:auto!important;
    min-height:0!important;
    max-height:none!important;
    overflow:hidden!important;
    overscroll-behavior:none;
    margin:0!important;
  }
  body.ui-v2 .sidebar-scroll{
    min-height:0!important;
    overflow-y:auto!important;
    overflow-x:hidden!important;
    overscroll-behavior-y:contain;
    -webkit-overflow-scrolling:touch;
  }
}

/* Do not let legacy sticky declarations or transforms create a new sidebar containing block. */
body.ui-v2 .sidebar,
body.ui-v2 .sidebar-scroll{transform:none!important}
