/* =============================================================================
   OrganicSystem — ERP Scroll System
   One vertical scrollbar for the whole app. Nested vertical scroll is forbidden.

   Layout:
     Header / Topbar     → fixed (flex, outside scroll pane)
     Page chrome         → fixed
     Filter toolbar      → fixed
     Content Area (main) → ONLY vertical scroll owner
     Footer              → fixed
     Grid                → horizontal scroll only
   ============================================================================= */

html:has(body.os-app-shell),
html:has(body.os-module-shell),
html:has(body.os-report-layout) {
  height: 100% !important;
  max-height: 100% !important;
  overflow: hidden !important;
}

/* ---------- Module shell ---------- */
body.os-module-shell,
body.os-module-shell.os-app-shell {
  height: 100dvh !important;
  max-height: 100dvh !important;
  min-height: 100dvh !important;
  overflow: hidden !important;
}

body.os-module-shell .app-main,
body.os-module-shell.os-table-fill-page .app-main,
body.os-module-shell.os-dedicated-export-page .app-main,
body.os-module-shell:has(.ags-export-invoice-index-page) .app-main,
body.os-module-shell:has(.ags-export-invoices-products-page) .app-main,
body.os-module-shell:has([data-os-dedicated-page-chrome="true"]) .app-main {
  display: flex !important;
  flex-direction: column !important;
  height: 100% !important;
  max-height: 100% !important;
  min-height: 0 !important;
  overflow: hidden !important; /* NOT a scroll container */
}

/* Shell chrome — in document flow outside the content scroll pane */
body.os-module-shell .app-main > .app-topbar,
body.os-module-shell .app-main > .os-erp-breadcrumb,
body.os-module-shell .app-main > #os-app-page-chrome-host,
body.os-module-shell .app-main > .os-module-toolbar,
body.os-module-shell .app-main > .os-subscription-warning,
body.os-module-shell .app-main > .os-global-report-links {
  position: relative !important;
  top: auto !important;
  left: auto !important;
  right: auto !important;
  bottom: auto !important;
  flex: 0 0 auto !important;
  margin-top: 0 !important;
  transform: none !important;
  z-index: 30;
}

body.os-module-shell .app-main > .app-topbar {
  z-index: 32;
}

body.os-module-shell .app-main > #os-app-page-chrome-host:not([hidden]) {
  z-index: 31;
}

body.os-module-shell .app-main > .os-module-toolbar {
  z-index: 30;
}

/* Content Area — sole vertical scrollbar */
body.os-module-shell .app-main > main.os-app-main.app-content,
body.os-module-shell .app-main > main.os-app-main,
body.os-module-shell.os-table-fill-page .app-main > main.os-app-main.app-content,
body.os-module-shell.os-table-fill-page .app-main > main.os-app-main,
body.os-module-shell.os-dedicated-export-page .app-main > main.os-app-main,
body.os-module-shell:has(.ags-export-invoice-index-page) .app-main > main.os-app-main,
body.os-module-shell:has(.ags-export-invoices-products-page) .app-main > main.os-app-main,
body.os-module-shell:has([data-os-dedicated-page-chrome="true"]) .app-main > main.os-app-main {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  height: auto !important;
  max-height: none !important;
  overflow-x: clip !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  display: block !important;
}

/* Footer is a body-level row spanning under the sidebar */
body.os-module-shell > .os-app-footer,
body.os-module-shell > footer.os-app-footer,
body.os-module-shell .app-main > .os-app-footer,
body.os-module-shell .app-main > footer.os-app-footer {
  position: relative !important;
  flex: 0 0 auto !important;
  margin-top: 0 !important;
  width: 100% !important;
  z-index: 20;
}

/* ---------- Classic shell (Admin / non-module) ---------- */
body.os-app-shell:not(.login-shell):not(.os-module-shell):not(.os-report-layout) {
  height: 100dvh !important;
  max-height: 100dvh !important;
  min-height: 100dvh !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
}

body.os-app-shell:not(.login-shell):not(.os-module-shell):not(.os-report-layout) > header.os-app-header,
body.os-app-shell:not(.login-shell):not(.os-module-shell):not(.os-report-layout) > .os-subscription-warning,
body.os-app-shell:not(.login-shell):not(.os-module-shell):not(.os-report-layout) > .alert.os-subscription-warning {
  flex: 0 0 auto !important;
  position: relative !important;
  z-index: 30;
}

body.os-app-shell:not(.login-shell):not(.os-module-shell):not(.os-report-layout) > .container-fluid {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
}

body.os-app-shell:not(.login-shell):not(.os-module-shell):not(.os-report-layout) > .container-fluid > .os-app-main,
body.os-app-shell:not(.login-shell):not(.os-module-shell):not(.os-report-layout).os-table-fill-page > .container-fluid > .os-app-main {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow-x: clip !important;
  overflow-y: auto !important; /* sole classic-shell vertical scroll */
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

body.os-app-shell:not(.login-shell):not(.os-module-shell):not(.os-report-layout) > footer.os-app-footer,
body.os-app-shell:not(.login-shell):not(.os-module-shell):not(.os-report-layout) > footer.footer {
  flex: 0 0 auto !important;
  margin-top: 0 !important;
  width: 100%;
}

/* ---------- Report layout ---------- */
body.os-report-layout {
  height: 100dvh !important;
  max-height: 100dvh !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
  padding-top: 0 !important;
}

body.os-report-layout > header.os-app-header {
  position: relative !important;
  top: auto !important;
  flex: 0 0 auto !important;
}

body.os-report-layout > .container-fluid {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
}

body.os-report-layout > .container-fluid > .os-app-main {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow-x: clip !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

body.os-report-layout > footer.os-app-footer {
  flex: 0 0 auto !important;
}

/* ---------- Kill nested vertical scroll panes ---------- */
body.os-app-shell .os-page-scroll,
body.os-module-shell .os-page-scroll,
body.os-app-shell .os-page-sticky-chrome,
body.os-module-shell .os-page-sticky-chrome,
body.os-app-shell .os-page-grid-view:not(.os-grid-container),
body.os-module-shell .os-page-grid-view:not(.os-grid-container),
body.os-app-shell .os-dx-grid:not(.os-grid-container),
body.os-module-shell .os-dx-grid:not(.os-grid-container),
body.os-app-shell .os-page-table-view:not(.os-grid-container),
body.os-module-shell .os-page-table-view:not(.os-grid-container),
body.os-table-fill-page .os-page-grid-view:not(.os-grid-container),
body.os-table-fill-page .os-dx-grid:not(.os-grid-container),
body.os-app-shell .plan-grids-row,
body.os-module-shell .plan-grids-row,
body.os-app-shell .plan-grid-panel,
body.os-module-shell .plan-grid-panel {
  overflow-y: visible !important;
}

body.os-app-shell .os-page-scroll,
body.os-module-shell .os-page-scroll {
  display: block !important;
  flex: none !important;
  height: auto !important;
  max-height: none !important;
  min-height: 0 !important;
  overflow-x: clip !important;
}

/* Unmanaged grid hosts grow with content; Grid Containers / internal-scroll use flex fill */
html:not([data-os-grid-scroll="internal"]) body.os-app-shell .os-page-grid-view:not(.os-grid-container):not(.os-dx-grid--fill):not([data-os-grid-internal-scroll="1"]),
html:not([data-os-grid-scroll="internal"]) body.os-module-shell .os-page-grid-view:not(.os-grid-container):not(.os-dx-grid--fill):not([data-os-grid-internal-scroll="1"]),
html:not([data-os-grid-scroll="internal"]) body.os-app-shell .os-dx-grid:not(.os-grid-container):not(.os-dx-grid--fill):not([data-os-grid-internal-scroll="1"]),
html:not([data-os-grid-scroll="internal"]) body.os-module-shell .os-dx-grid:not(.os-grid-container):not(.os-dx-grid--fill):not([data-os-grid-internal-scroll="1"]),
html:not([data-os-grid-scroll="internal"]) body.os-table-fill-page .os-page-grid-view:not(.os-grid-container):not(.os-dx-grid--fill):not([data-os-grid-internal-scroll="1"]),
html:not([data-os-grid-scroll="internal"]) body.os-table-fill-page .os-dx-grid:not(.os-grid-container):not(.os-dx-grid--fill):not([data-os-grid-internal-scroll="1"]) {
  height: auto !important;
  min-height: var(--os-grid-host-min-height, 240px) !important;
  max-height: none !important;
  flex: none !important;
  overflow-x: clip !important;
  overflow-y: visible !important;
}

/* Split View owns pane sizing — empty season grids must not reserve 240px */
body.os-app-shell .os-split-view .os-dx-grid,
body.os-module-shell .os-split-view .os-dx-grid,
body.os-app-shell .os-split-view .os-page-grid-view,
body.os-module-shell .os-split-view .os-page-grid-view,
body.os-app-shell .plan-grid-panel > [id$="-grid"],
body.os-module-shell .plan-grid-panel > [id$="-grid"] {
  min-height: 0 !important;
}

html:not([data-os-grid-scroll="internal"]) body.os-app-shell .os-page-grid-view:not(.os-grid-container):not(.os-dx-grid--fill) .dx-datagrid,
html:not([data-os-grid-scroll="internal"]) body.os-module-shell .os-page-grid-view:not(.os-grid-container):not(.os-dx-grid--fill) .dx-datagrid,
html:not([data-os-grid-scroll="internal"]) body.os-app-shell .os-dx-grid:not(.os-grid-container):not(.os-dx-grid--fill) .dx-datagrid,
html:not([data-os-grid-scroll="internal"]) body.os-module-shell .os-dx-grid:not(.os-grid-container):not(.os-dx-grid--fill) .dx-datagrid,
html:not([data-os-grid-scroll="internal"]) body.os-app-shell .os-page-grid-view:not(.os-grid-container):not(.os-dx-grid--fill).dx-datagrid,
html:not([data-os-grid-scroll="internal"]) body.os-module-shell .os-page-grid-view:not(.os-grid-container):not(.os-dx-grid--fill).dx-datagrid,
html:not([data-os-grid-scroll="internal"]) body.os-table-fill-page :not(.os-grid-container):not(.os-dx-grid--fill) > .dx-datagrid {
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow: visible !important;
}

/* Grid Container: flex width; GRID owns Y (rows scroll inside) */
body.os-app-shell .os-grid-container,
body.os-module-shell .os-grid-container,
body.os-table-fill-page .os-grid-container,
body.os-app-shell .os-dx-grid,
body.os-module-shell .os-dx-grid,
body.os-app-shell .os-page-grid-view,
body.os-module-shell .os-page-grid-view {
  flex: 1 1 auto !important;
  width: auto !important;
  max-width: 100% !important;
  min-width: 0 !important;
  min-height: 0 !important;
  height: var(--os-gc-height, 100%) !important;
  max-height: var(--os-gc-height, 100%) !important;
  overflow: hidden !important;
}

/* Grid body: rowsview clips; scrollable-container is the sole Y owner */
body.os-app-shell .os-dx-grid .dx-datagrid-rowsview,
body.os-module-shell .os-dx-grid .dx-datagrid-rowsview,
body.os-table-fill-page .os-dx-grid .dx-datagrid-rowsview,
body.os-app-shell .os-grid-container .dx-datagrid-rowsview,
body.os-module-shell .os-grid-container .dx-datagrid-rowsview,
body.os-app-shell .os-page-grid-view .dx-datagrid-rowsview,
body.os-module-shell .os-page-grid-view .dx-datagrid-rowsview {
  overflow-x: hidden !important;
  overflow-y: hidden !important;
  height: 100% !important;
  max-height: 100% !important;
  min-height: 0 !important;
}

body.os-app-shell .os-dx-grid .dx-datagrid-rowsview.dx-scrollable-native .dx-scrollable-container,
body.os-module-shell .os-dx-grid .dx-datagrid-rowsview.dx-scrollable-native .dx-scrollable-container,
body.os-table-fill-page .os-dx-grid .dx-datagrid-rowsview.dx-scrollable-native .dx-scrollable-container,
body.os-app-shell .os-grid-container .dx-datagrid-rowsview.dx-scrollable-native .dx-scrollable-container,
body.os-module-shell .os-grid-container .dx-datagrid-rowsview.dx-scrollable-native .dx-scrollable-container,
body.os-app-shell .os-page-grid-view .dx-datagrid-rowsview.dx-scrollable-native .dx-scrollable-container,
body.os-module-shell .os-page-grid-view .dx-datagrid-rowsview.dx-scrollable-native .dx-scrollable-container {
  overflow-x: auto !important;
  overflow-y: auto !important;
  height: 100% !important;
  max-height: 100% !important;
  min-height: 0 !important;
}

body.os-app-shell .os-dx-grid .dx-datagrid-rowsview.dx-scrollable-simulated .dx-scrollable-container,
body.os-module-shell .os-dx-grid .dx-datagrid-rowsview.dx-scrollable-simulated .dx-scrollable-container,
body.os-table-fill-page .os-dx-grid .dx-datagrid-rowsview.dx-scrollable-simulated .dx-scrollable-container,
body.os-app-shell .os-grid-container .dx-datagrid-rowsview.dx-scrollable-simulated .dx-scrollable-container,
body.os-module-shell .os-grid-container .dx-datagrid-rowsview.dx-scrollable-simulated .dx-scrollable-container,
body.os-app-shell .os-page-grid-view .dx-datagrid-rowsview.dx-scrollable-simulated .dx-scrollable-container,
body.os-module-shell .os-page-grid-view .dx-datagrid-rowsview.dx-scrollable-simulated .dx-scrollable-container {
  overflow: hidden !important;
  height: 100% !important;
  max-height: 100% !important;
  min-height: 0 !important;
}

/* Export Invoice sidebar list: fixed-height host — scrollable-container owns Y. */
body.os-app-shell .ags-export-invoice-edit-page .ags-export-invoice-list-panel .dx-datagrid-rowsview,
body.os-module-shell .ags-export-invoice-edit-page .ags-export-invoice-list-panel .dx-datagrid-rowsview {
  overflow-x: hidden !important;
  overflow-y: hidden !important;
  height: 100% !important;
  max-height: none !important;
}

body.os-app-shell .ags-export-invoice-edit-page .ags-export-invoice-list-panel .dx-datagrid-rowsview.dx-scrollable-native .dx-scrollable-container,
body.os-module-shell .ags-export-invoice-edit-page .ags-export-invoice-list-panel .dx-datagrid-rowsview.dx-scrollable-native .dx-scrollable-container {
  overflow-x: auto !important;
  overflow-y: auto !important;
  height: 100% !important;
  max-height: none !important;
}

body.os-app-shell .ags-export-invoice-edit-page .ags-export-invoice-list-panel .dx-datagrid-rowsview.dx-scrollable-simulated .dx-scrollable-container,
body.os-module-shell .ags-export-invoice-edit-page .ags-export-invoice-list-panel .dx-datagrid-rowsview.dx-scrollable-simulated .dx-scrollable-container {
  overflow: hidden !important;
  height: 100% !important;
  max-height: none !important;
}

body.os-app-shell .os-page-table-view.os-grid-container,
body.os-module-shell .os-page-table-view.os-grid-container,
body.os-app-shell .os-page-table-view[data-os-grid-internal-scroll="1"],
body.os-module-shell .os-page-table-view[data-os-grid-internal-scroll="1"] {
  height: var(--os-gc-height, 100%) !important;
  max-height: var(--os-gc-height, 100%) !important;
  min-height: 0 !important;
  overflow-x: auto !important;
  overflow-y: auto !important;
}

/* Page fragments must not introduce a second vertical bar */
body.os-app-shell [class*="-index-page"],
body.os-module-shell [class*="-index-page"],
body.os-app-shell [class*="-edit-page"],
body.os-module-shell [class*="-edit-page"],
body.os-module-shell .module-main-page,
body.os-module-shell .ags-plan-page,
body.os-module-shell .rotation-page {
  overflow-x: clip !important;
  overflow-y: visible !important;
  max-height: none !important;
  height: auto !important;
}

/* Sidebar keeps its own scroll (nav only — not page content nesting) */
body.os-module-shell .app-sidebar__scroll {
  overflow-y: auto;
  overflow-x: hidden;
}

/* Dialogs / overlays may scroll internally — unless a DataGrid owns Y */
.modal-body:not(:has(.dx-datagrid)),
.modal-dialog-scrollable .modal-body:not(:has(.dx-datagrid)),
.offcanvas-body:not(:has(.dx-datagrid)),
.dx-popup-content:not(:has(.dx-datagrid)) {
  overflow-y: auto;
}

.modal-body:has(.dx-datagrid),
.offcanvas-body:has(.dx-datagrid),
.dx-popup-content:has(.dx-datagrid) {
  overflow: hidden !important;
}

/* Portrait / narrow: every page uses main as the vertical scroll owner */
@media (orientation: portrait), (max-aspect-ratio: 1/1), (max-width: 991.98px) {
  body.os-module-shell .app-main {
    overflow: hidden !important;
  }

  body.os-module-shell .app-main > main.os-app-main,
  html[data-os-portrait-scroll="page"] body.os-module-shell .app-main > main.os-app-main,
  html[data-os-grid-scroll="internal"] body.os-module-shell .app-main > main.os-app-main {
    overflow-x: clip !important;
    overflow-y: auto !important;
  }

  body.os-app-shell:not(.login-shell):not(.os-module-shell) > .container-fluid > .os-app-main,
  html[data-os-portrait-scroll="page"] body.os-app-shell:not(.login-shell):not(.os-module-shell) > .container-fluid > .os-app-main,
  html[data-os-grid-scroll="internal"] body.os-app-shell:not(.login-shell):not(.os-module-shell) > .container-fluid > .os-app-main {
    overflow-x: clip !important;
    overflow-y: auto !important;
  }
}
