/* =============================================================================
   OrganicSystem — Portrait page scroll (FINAL, loads last)
   One vertical scrollbar for the shell content pane: main.os-app-main.

   Portrait / square / narrow → main owns Y on EVERY page (forms + grids + fill).
   Landscape / desktop → this file does nothing (media query gated).
   ============================================================================= */

@media (orientation: portrait), (max-aspect-ratio: 1/1), (max-width: 991.98px) {
  /* Document / shell stay locked — do not open a second page scrollbar */
  html:has(body.os-app-shell:not(.login-shell)),
  html:has(body.os-module-shell),
  html:has(body.os-report-layout),
  html.os-portrait-root:has(body.os-app-shell:not(.login-shell)),
  html.os-portrait-root:has(body.os-module-shell),
  body.os-app-shell:not(.login-shell),
  body.os-module-shell,
  body.os-report-layout {
    overflow-x: hidden !important;
    overflow-y: hidden !important;
  }

  /* Parents of the content pane are never scroll containers */
  body.os-module-shell .app-main,
  body.os-module-shell.has-sidebar .app-main,
  body.os-portrait-layout.os-module-shell .app-main,
  html.os-portrait-root body.os-module-shell .app-main,
  body.os-app-shell:not(.login-shell):not(.os-module-shell):not(.os-report-layout) > .container-fluid,
  body.os-report-layout > .container-fluid {
    min-height: 0 !important;
    overflow-x: hidden !important;
    overflow-y: hidden !important;
  }

  /*
    Global Portrait scroll owner = main.os-app-main on ALL pages.
    Beats os-scroll-engine / os-responsive-fix grid-internal locks.
  */
  body.os-module-shell .app-main > main.os-app-main,
  body.os-module-shell .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-table-fill-page .app-main > main.os-app-main.app-content,
  body.os-portrait-layout.os-module-shell main.os-app-main,
  body.os-portrait-layout.os-module-shell main.os-app-main.app-content,
  html.os-portrait-root body.os-module-shell main.os-app-main,
  html[data-os-scroll-engine="on"] body.os-module-shell main.os-app-main,
  html[data-os-scroll-engine="on"] body.os-app-shell main.os-app-main,
  html[data-os-portrait-scroll="page"] 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.app-content,
  html[data-os-portrait-scroll="page"] body.os-app-shell main.os-app-main,
  html[data-os-grid-scroll="internal"] 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.app-content,
  html[data-os-grid-scroll="internal"] body.os-app-shell main.os-app-main,
  body.os-module-shell .app-main > main.os-app-main:has(.os-dx-grid--fill),
  body.os-module-shell .app-main > main.os-app-main.app-content:has(.os-dx-grid--fill),
  body.os-module-shell .app-main > main.os-app-main:has([data-os-grid-internal-scroll="1"]),
  body.os-module-shell .app-main > main.os-app-main.app-content:has([data-os-grid-internal-scroll="1"]),
  body.os-module-shell .app-main > main.os-app-main:has(.os-grid-container),
  body.os-module-shell .app-main > main.os-app-main.app-content:has(.os-grid-container),
  body.os-module-shell .app-main > main.os-app-main:has(.os-page-grid-view),
  body.os-module-shell .app-main > main.os-app-main.app-content:has(.os-page-grid-view),
  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) > .container-fluid > main.os-app-main,
  body.os-report-layout > .container-fluid > .os-app-main,
  body.os-report-layout > .container-fluid > main.os-app-main,
  main.os-app-main.os-scroll-owner {
    display: block !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  /* Nested page wrappers must not create a second Y scrollbar or page X-scroll.
     Data-table hosts keep their own overflow-x/y: auto + max-height. */
  body.os-app-shell .os-page-scroll,
  body.os-module-shell .os-page-scroll,
  body.os-app-shell .os-app-main > [class*="-edit-page"],
  body.os-module-shell .os-app-main > [class*="-edit-page"],
  body.os-app-shell .os-app-main > [class*="-index-page"],
  body.os-module-shell .os-app-main > [class*="-index-page"],
  body.os-app-shell .os-page-sticky-chrome,
  body.os-module-shell .os-page-sticky-chrome,
  body.os-app-shell .os-erp-page-shell,
  body.os-module-shell .os-erp-page-shell,
  body.os-app-shell .os-erp-panel,
  body.os-module-shell .os-erp-panel,
  body.os-app-shell .prs-content-panel,
  body.os-module-shell .prs-content-panel {
    min-width: 0 !important;
    min-height: 0 !important;
    max-width: 100% !important;
    max-height: none !important;
    height: auto !important;
    overflow-x: hidden !important;
    overflow-y: visible !important;
  }

  body.os-app-shell main .os-erp-data-table-host,
  body.os-module-shell main .os-erp-data-table-host,
  body.os-app-shell main .os-native-table-scroll,
  body.os-module-shell main .os-native-table-scroll,
  body.os-app-shell main .table-responsive:not(:has(.dx-datagrid)):not(:has(.os-dx-grid)):not(:has(.os-desktop-form-table)),
  body.os-module-shell main .table-responsive:not(:has(.dx-datagrid)):not(:has(.os-dx-grid)):not(:has(.os-desktop-form-table)) {
    overflow-x: auto !important;
    overflow-y: auto !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  /*
    All grids (including fill hosts) grow with content in portrait so the page
    scrollbar can reach every row. Horizontal overflow stays on the grid host.
  */
  body.os-app-shell main.os-app-main .os-dx-grid,
  body.os-module-shell main.os-app-main .os-dx-grid,
  body.os-app-shell main.os-app-main .os-page-grid-view,
  body.os-module-shell main.os-app-main .os-page-grid-view,
  body.os-app-shell main.os-app-main .os-grid-container,
  body.os-module-shell main.os-app-main .os-grid-container,
  body.os-app-shell main.os-app-main .os-dx-grid--fill,
  body.os-module-shell main.os-app-main .os-dx-grid--fill,
  body.os-app-shell main.os-app-main [data-os-grid-internal-scroll="1"],
  body.os-module-shell main.os-app-main [data-os-grid-internal-scroll="1"],
  body.os-table-fill-page main.os-app-main .os-dx-grid,
  html[data-os-portrait-scroll="page"] main.os-app-main .os-dx-grid,
  html[data-os-portrait-scroll="page"] main.os-app-main .os-dx-grid--fill,
  html[data-os-portrait-scroll="page"] main.os-app-main [data-os-grid-internal-scroll="1"] {
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    flex: none !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
  }

  html[data-os-portrait-scroll="page"] main.os-app-main .dx-datagrid,
  html[data-os-portrait-scroll="page"] main.os-app-main .dx-datagrid-rowsview,
  html[data-os-portrait-scroll="page"] main.os-app-main .dx-scrollable-container {
    height: auto !important;
    max-height: none !important;
    overflow-y: visible !important;
  }

  /*
    Export Invoice Edit (module + classic shell):
    Always page-scroll in Portrait. Nested products/list panels must not trap Y.
  */
  body.os-module-shell .app-main > main.os-app-main:has(.ags-export-invoice-edit-page),
  body.os-module-shell main.os-app-main:has(.ags-export-invoice-edit-page),
  body.os-app-shell main.os-app-main:has(.ags-export-invoice-edit-page),
  main.os-app-main.os-export-invoice-portrait-scroll-main,
  html[data-os-scroll-engine="on"] main.os-app-main:has(.ags-export-invoice-edit-page),
  html[data-os-grid-scroll="internal"] main.os-app-main:has(.ags-export-invoice-edit-page) {
    display: block !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .ags-export-invoice-edit-page,
  .ags-export-invoice-edit-page.os-export-invoice-portrait-scroll-page,
  .ags-export-invoice-edit-page .ags-export-invoice-form,
  .ags-export-invoice-edit-page .ags-export-invoice-layout,
  .ags-export-invoice-edit-page .ags-export-invoice-layout.row,
  .ags-export-invoice-edit-page .ags-export-invoice-products-section,
  .ags-export-invoice-edit-page .ags-export-invoice-details-panel {
    display: block !important;
    flex: none !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  .ags-export-invoice-edit-page .ags-export-invoice-layout,
  .ags-export-invoice-edit-page .ags-export-invoice-layout.row {
    display: flex !important;
    flex-direction: column !important;
  }

  .ags-export-invoice-edit-page .ags-export-invoice-list-panel,
  .ags-export-invoice-edit-page .ags-export-invoice-details-panel .os-dx-grid,
  .ags-export-invoice-edit-page .ags-export-invoice-details-panel .dx-datagrid {
    height: auto !important;
    max-height: none !important;
    flex: none !important;
  }
}

/* Local Invoice Edit: main owns page Y; tables keep overflow: auto. */
html[data-os-scroll-engine="on"] main.os-app-main:has(.prs-local-invoice-edit),
html[data-os-grid-scroll="internal"] main.os-app-main:has(.prs-local-invoice-edit),
html[data-os-scroll-engine="on"][data-os-grid-scroll="internal"] body.os-module-shell:has(.prs-local-invoice-edit) .app-main > main.os-app-main,
html[data-os-scroll-engine="on"][data-os-grid-scroll="internal"] body.os-module-shell:has(.prs-local-invoice-edit) .app-main > main.os-app-main.app-content,
html[data-os-grid-scroll="internal"] body.os-module-shell:has(.prs-local-invoice-edit) .app-main > main.os-app-main,
html[data-os-grid-scroll="internal"] body.os-module-shell:has(.prs-local-invoice-edit) .app-main > main.os-app-main.app-content,
html[data-os-scroll-engine="on"] body.os-module-shell:has(.prs-local-invoice-edit) .app-main > main.os-app-main,
html[data-os-scroll-engine="on"] body.os-module-shell:has(.prs-local-invoice-edit) .app-main > main.os-app-main.app-content {
  display: block !important;
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
}

html[data-os-grid-scroll="internal"] .os-app-main > .prs-local-invoice-edit,
html[data-os-scroll-engine="on"] .prs-local-invoice-edit {
  display: flex !important;
  flex-direction: column !important;
  flex: 0 0 auto !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow: visible !important;
}

html[data-os-grid-scroll="internal"] .prs-local-invoice-edit .prs-content-panel,
html[data-os-grid-scroll="internal"] .prs-local-invoice-edit .prs-content-panel:has(.os-dx-grid, .dx-datagrid),
html[data-os-scroll-engine="on"] .prs-local-invoice-edit .prs-content-panel {
  display: block !important;
  flex: 0 0 auto !important;
  min-height: 0 !important;
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
}

html[data-os-scroll-engine="on"] .prs-local-invoice-edit .prs-li-invoices-grid .dx-scrollable-container,
html[data-os-scroll-engine="on"] .prs-local-invoice-edit .prs-li-balance-grid .dx-scrollable-container,
html[data-os-grid-scroll="internal"] .prs-local-invoice-edit .prs-li-invoices-grid .dx-scrollable-container,
html[data-os-grid-scroll="internal"] .prs-local-invoice-edit .prs-li-balance-grid .dx-scrollable-container,
html[data-os-scroll-engine="on"] .prs-local-invoice-edit .prs-li-invoices-grid .dx-datagrid-rowsview.dx-scrollable-simulated .dx-scrollable-container,
html[data-os-scroll-engine="on"] .prs-local-invoice-edit .prs-li-balance-grid .dx-datagrid-rowsview.dx-scrollable-simulated .dx-scrollable-container {
  overflow-x: auto !important;
  overflow-y: auto !important;
}

html[data-os-scroll-engine="on"] .prs-local-invoice-edit .prs-li-invoices-grid .dx-scrollbar-horizontal,
html[data-os-scroll-engine="on"] .prs-local-invoice-edit .prs-li-balance-grid .dx-scrollbar-horizontal,
html[data-os-scroll-engine="on"] .prs-local-invoice-edit .prs-li-invoices-grid .dx-scrollbar-horizontal.dx-state-invisible,
html[data-os-scroll-engine="on"] .prs-local-invoice-edit .prs-li-balance-grid .dx-scrollbar-horizontal.dx-state-invisible {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  height: 12px !important;
  pointer-events: auto !important;
}

html[data-os-scroll-engine="on"] .prs-local-invoice-edit .prs-li-products-scroll {
  overflow-x: auto !important;
  overflow-y: auto !important;
  max-height: var(--os-table-scroll-max-height);
  scrollbar-gutter: auto;
}


