:root{
  --table-sticky-offset:var(--app-header-height,55px);
  --table-sticky-body-z:12;
  --table-sticky-intersection-z:31;
  --table-sticky-header-bg:var(--surface,var(--card,#fff));
}

/*
 * Canonical financial-table contract:
 * - the document owns vertical scrolling;
 * - the table wrapper owns horizontal scrolling only;
 * - dropdowns, dialogs, drawers and virtualized lists remain explicit exceptions.
 */
:is(
  .page-scroll-table,
  main>.content .table-wrap,
  .analytics-table-wrap,
  .branch-report-table-wrap,
  .reports-preview-table-wrap,
  .review-table-wrap,
  .expense-matrix-wrap,
  .ranking-table-wrap,
  .sales-explorer-table-wrap,
  .cheques-new-table-wrap,
  .cheques-new-outstanding-table-wrap,
  .targets-table-wrap,
  .data-operations-table-wrap,
  .gate3-history-table,
  .g3b-table,
  .import-center-table-wrap,
  .settings-table-wrap,
  .operating-table-scroll,
  .inventory-table-wrap
){
  width:100%;
  max-width:100%;
  height:auto!important;
  max-height:none!important;
  overflow-x:auto!important;
  overflow-y:visible!important;
  overscroll-behavior-inline:contain;
  scrollbar-width:thin;
  -webkit-overflow-scrolling:touch;
}

/* Intentional nested-scroll regions opt in explicitly and are not table defaults. */
.intentional-internal-scroll{
  max-height:var(--internal-scroll-max,70vh)!important;
  overflow:auto!important;
}

/* Keep the primary business identifier visible while scrolling wide tables. */
.expense-matrix .category-column,
.expense-matrix .category-cell{
  right:auto;
  left:auto;
  inset-inline-start:0;
}

.cheques-new-table :is(thead th,tbody td):first-child,
.cheques-new-outstanding-table :is(thead th,tbody th,tfoot th):first-child,
.targets-table :is(thead th,tbody th,tbody td):first-child,
.data-operations-table-wrap table :is(thead th,tbody th,tbody td):first-child,
.branch-report-table :is(thead th,tbody th,tbody td):first-child,
.reports-preview-table :is(thead th,tbody th,tbody td):first-child,
.settings-table :is(thead th,tbody th,tbody td):first-child,
.period-center-table table :is(thead th,tbody th,tbody td):first-child,
.review-table :is(thead th,tbody th,tbody td):first-child{
  position:sticky;
  inset-inline-start:0;
  z-index:var(--table-sticky-body-z);
  background:var(--surface,#fff);
  box-shadow:1px 0 0 var(--table-border);
}

[dir="rtl"] :is(
  .cheques-new-table,
  .cheques-new-outstanding-table,
  .targets-table,
  .data-operations-table-wrap table,
  .branch-report-table,
  .reports-preview-table,
  .settings-table,
  .period-center-table table,
  .review-table
) :is(thead th,tbody th,tbody td):first-child{
  box-shadow:-1px 0 0 var(--table-border);
}

:is(
  .cheques-new-table,
  .cheques-new-outstanding-table,
  .targets-table,
  .data-operations-table-wrap table,
  .branch-report-table,
  .reports-preview-table,
  .settings-table,
  .period-center-table table,
  .review-table
) thead th:first-child{
  z-index:calc(var(--table-sticky-body-z) + 1);
}

@media(max-width:480px){
  :root{--table-sticky-offset:52px}
}

.page-scroll-sticky-header{
  position:fixed;
  display:none;
  overflow:hidden;
  clip-path:inset(0);
  contain:layout paint style;
  isolation:isolate;
  pointer-events:none;
  z-index:29;
  border-radius:0;
  box-shadow:var(--shadow-card);
  background:var(--table-sticky-header-bg);
}

.page-scroll-sticky-header.is-visible{display:block}
.page-scroll-sticky-header.is-invalid{display:none!important}
.page-scroll-sticky-header>table{
  position:absolute!important;
  inset-block-start:0;
  margin:0!important;
  table-layout:fixed!important;
  background:var(--table-sticky-header-bg)!important;
}
.page-scroll-sticky-header>table>thead{display:table-header-group!important;background:var(--table-sticky-header-bg)!important}
.page-scroll-sticky-header>table>thead>tr{display:table-row!important}
.page-scroll-sticky-header>table>thead>tr>th{display:table-cell!important}
.page-scroll-sticky-primary-table{
  inset-inline-start:0!important;
  z-index:var(--table-sticky-intersection-z)!important;
}

.page-scroll-floating-rail{
  position:fixed;
  inset-block-end:max(7px,env(safe-area-inset-bottom));
  display:none;
  height:18px;
  overflow-x:auto;
  overflow-y:hidden;
  z-index:28;
  border:1px solid var(--border-strong);
  border-radius:7px;
  background:var(--surface-subtle);
  box-shadow:var(--shadow-card);
  scrollbar-width:auto;
  overscroll-behavior-inline:contain;
}
.page-scroll-floating-rail.is-visible{display:block}
.page-scroll-floating-rail:focus-visible{outline:3px solid var(--focus-ring);outline-offset:2px}
.page-scroll-floating-spacer{height:1px;pointer-events:none}

@media(max-width:600px){
  .page-scroll-floating-rail{display:none!important}
}

@media print{
  :root{--table-sticky-offset:0px}
  .page-scroll-sticky-header,.page-scroll-floating-rail{display:none!important}
  :is(.page-scroll-table,main>.content .table-wrap,.expense-matrix-wrap,.ranking-table-wrap){overflow:visible!important}
}
