/* Smart NCD full-height data tables v2.43.4
   Scope: primary registries / patient lists only.
   Dashboard and analytical summary tables are intentionally excluded. */

@media (min-width:769px) {
  /* Views with a primary scrollable registry should not scroll the whole page. */
  .main:has(> #registry.active),
  .main:has(> .view.active:is(#followup-overview,#service-history,#area-treatment,#reports-disease,#reports-village)),
  .main:has(> .view.active:is(#lab-registry,#lab-egfr,#lab-hba1c):has(.lab-tab-panel[data-lab-panel="results"]:not([hidden]))),
  .main:has(> #critical-lab.active:has(.critical-lab-panel[data-critical-lab-panel="queue"]:not([hidden]))),
  .main:has(> #critical-lab.active:has(.critical-lab-panel[data-critical-lab-panel="mapping"]:not([hidden]))),
  .main:has(> #ncd-screening.active:has(#screeningListPanel:not([hidden]))),
  .main:has(> #ncd-screening.active:has(#screeningHistoryPanel:not([hidden]))),
  .main:has(> #ncd-remission.active:has(.remission-panel.active .registry-table-card-v2)) {
    overflow-y:hidden!important;
  }

  #registry.active,
  .view.active:is(#followup-overview,#service-history,#area-treatment,#reports-disease,#reports-village),
  .view.active:is(#lab-registry,#lab-egfr,#lab-hba1c):has(.lab-tab-panel[data-lab-panel="results"]:not([hidden])),
  #critical-lab.active:has(.critical-lab-panel[data-critical-lab-panel="queue"]:not([hidden])),
  #critical-lab.active:has(.critical-lab-panel[data-critical-lab-panel="mapping"]:not([hidden])),
  #ncd-screening.active:has(#screeningListPanel:not([hidden])),
  #ncd-screening.active:has(#screeningHistoryPanel:not([hidden])),
  #ncd-remission.active:has(.remission-panel.active .registry-table-card-v2) {
    height:calc(100dvh - var(--fixed-header-height) - var(--fixed-footer-height) - 16px)!important;
    min-height:0!important;
    overflow:hidden!important;
  }

  /* Generic module-style list pages */
  .view.active:is(#followup-overview,#service-history,#area-treatment,#reports-disease,#reports-village) > .module-view {
    height:100%!important;
    min-height:0!important;
    display:flex!important;
    flex-direction:column!important;
  }
  .view.active:is(#followup-overview,#service-history,#area-treatment,#reports-disease,#reports-village) > .module-view > :not(.table-wrap) {
    flex:0 0 auto!important;
  }
  .view.active:is(#followup-overview,#service-history,#area-treatment,#reports-disease,#reports-village) > .module-view > .table-wrap {
    flex:1 1 0!important;
    min-height:0!important;
    max-height:none!important;
    overflow:auto!important;
  }

  /* Registry landing + disease registry */
  #registry.active > .registry-landing:not([hidden]),
  #registry.active > .registry-detail:not([hidden]) {
    height:100%!important;
    min-height:0!important;
    display:flex!important;
    flex-direction:column!important;
  }
  #registry.active .registry-table-card-v2 {
    flex:1 1 0!important;
    min-height:0!important;
    height:auto!important;
    display:flex!important;
    flex-direction:column!important;
    overflow:hidden!important;
  }
  #registry.active .registry-table-card-v2 > .registry-table-wrap-v2,
  #registry.active > .registry-detail:not([hidden]) > .registry-table-wrap {
    flex:1 1 0!important;
    min-height:0!important;
    max-height:none!important;
    overflow:auto!important;
  }
  #registry.active > .registry-detail:not([hidden]) > :not(.registry-table-wrap) {
    flex:0 0 auto!important;
  }

  /* Lab registry result tabs */
  .view.active:is(#lab-registry,#lab-egfr,#lab-hba1c):has(.lab-tab-panel[data-lab-panel="results"]:not([hidden])) > .module-view {
    height:100%!important;
    min-height:0!important;
    display:flex!important;
    flex-direction:column!important;
  }
  .view.active:is(#lab-registry,#lab-egfr,#lab-hba1c) .lab-head-filter-row,
  .view.active:is(#lab-registry,#lab-egfr,#lab-hba1c) .lab-header-tabs {
    flex:0 0 auto!important;
  }
  .view.active:is(#lab-registry,#lab-egfr,#lab-hba1c) .lab-tab-panel[data-lab-panel="results"]:not([hidden]) {
    flex:1 1 0!important;
    min-height:0!important;
    display:flex!important;
    flex-direction:column!important;
  }
  .view.active:is(#lab-registry,#lab-egfr,#lab-hba1c) .lab-tab-panel[data-lab-panel="results"]:not([hidden]) > .module-result {
    flex:0 0 auto!important;
  }
  .view.active:is(#lab-registry,#lab-egfr,#lab-hba1c) .lab-tab-panel[data-lab-panel="results"]:not([hidden]) > .table-wrap {
    flex:1 1 0!important;
    min-height:0!important;
    max-height:none!important;
    overflow:auto!important;
  }

  /* Critical Lab queue and mapping */
  #critical-lab.active > .critical-lab-page {
    height:100%!important;
    min-height:0!important;
    display:flex!important;
    flex-direction:column!important;
  }
  #critical-lab.active .critical-lab-head-filter-row,
  #critical-lab.active .critical-lab-tabs {
    flex:0 0 auto!important;
  }
  #critical-lab.active .critical-lab-panel[data-critical-lab-panel="queue"]:not([hidden]),
  #critical-lab.active .critical-lab-panel[data-critical-lab-panel="mapping"]:not([hidden]) {
    flex:1 1 0!important;
    min-height:0!important;
    display:flex!important;
    flex-direction:column!important;
  }
  #critical-lab.active .critical-lab-panel[data-critical-lab-panel="queue"]:not([hidden]) > :not(.critical-lab-table-wrap),
  #critical-lab.active .critical-lab-panel[data-critical-lab-panel="mapping"]:not([hidden]) > :not(.table-wrap) {
    flex:0 0 auto!important;
  }
  #critical-lab.active .critical-lab-panel[data-critical-lab-panel="queue"]:not([hidden]) > .critical-lab-table-wrap,
  #critical-lab.active .critical-lab-panel[data-critical-lab-panel="mapping"]:not([hidden]) > .table-wrap {
    flex:1 1 0!important;
    min-height:0!important;
    max-height:none!important;
    overflow:auto!important;
  }

  /* NCD Screening main list + history */
  #ncd-screening.active:has(#screeningListPanel:not([hidden])) > .screening-page,
  #ncd-screening.active:has(#screeningHistoryPanel:not([hidden])) > .screening-page {
    height:100%!important;
    min-height:0!important;
    display:flex!important;
    flex-direction:column!important;
  }
  #ncd-screening.active .screening-head-filter-row,
  #ncd-screening.active .screening-tabs {
    flex:0 0 auto!important;
  }
  #ncd-screening.active #screeningListPanel:not([hidden]),
  #ncd-screening.active #screeningHistoryPanel:not([hidden]) {
    flex:1 1 0!important;
    min-height:0!important;
    display:flex!important;
    flex-direction:column!important;
  }
  #ncd-screening.active #screeningListPanel:not([hidden]) > :not(.table-wrap),
  #ncd-screening.active #screeningHistoryPanel:not([hidden]) > :not(.table-wrap) {
    flex:0 0 auto!important;
  }
  #ncd-screening.active #screeningListPanel:not([hidden]) > .table-wrap,
  #ncd-screening.active #screeningHistoryPanel:not([hidden]) > .table-wrap {
    flex:1 1 0!important;
    min-height:0!important;
    max-height:none!important;
    overflow:auto!important;
  }

  /* DM confirmation drill-down: keep internal scrolling even though it is nested in a report page. */
  #dmConfirmationListPanel:not([hidden]) {
    min-height:360px!important;
    max-height:calc(100dvh - var(--fixed-header-height) - var(--fixed-footer-height) - 190px)!important;
    display:flex!important;
    flex-direction:column!important;
    overflow:hidden!important;
  }
  #dmConfirmationListPanel:not([hidden]) > :not(.dm-confirmation-table-wrap) {
    flex:0 0 auto!important;
  }
  #dmConfirmationListPanel:not([hidden]) > .dm-confirmation-table-wrap {
    flex:1 1 0!important;
    min-height:0!important;
    max-height:none!important;
    overflow:auto!important;
  }

  /* Remission list/registry tabs */
  #ncd-remission.active:has(.remission-panel.active .registry-table-card-v2) {
    display:flex!important;
    flex-direction:column!important;
  }
  #ncd-remission.active:has(.remission-panel.active .registry-table-card-v2) > .remission-tabs {
    flex:0 0 auto!important;
  }
  #ncd-remission.active .remission-panel.active:has(.registry-table-card-v2) {
    flex:1 1 0!important;
    min-height:0!important;
    overflow:hidden!important;
  }
  #ncd-remission.active .remission-panel.active > .remission-list-v2,
  #ncd-remission.active .remission-panel.active > .remission-registry-v2 {
    height:100%!important;
    min-height:0!important;
    display:flex!important;
    flex-direction:column!important;
  }
  #ncd-remission.active .remission-panel.active .registry-table-card-v2 {
    flex:1 1 0!important;
    min-height:0!important;
    height:auto!important;
    display:flex!important;
    flex-direction:column!important;
    overflow:hidden!important;
  }
  #ncd-remission.active .remission-panel.active .registry-table-wrap-v2 {
    flex:1 1 0!important;
    min-height:0!important;
    max-height:none!important;
    overflow:auto!important;
  }

  /* Sticky headers for every primary data-table scroller in scope. */
  #registry.active .registry-table-wrap-v2 thead th,
  #registry.active > .registry-detail:not([hidden]) > .registry-table-wrap thead th,
  .view.active:is(#followup-overview,#service-history,#area-treatment,#reports-disease,#reports-village) > .module-view > .table-wrap thead th,
  .view.active:is(#lab-registry,#lab-egfr,#lab-hba1c) .lab-tab-panel[data-lab-panel="results"]:not([hidden]) > .table-wrap thead th,
  #critical-lab.active .critical-lab-panel[data-critical-lab-panel="queue"]:not([hidden]) > .critical-lab-table-wrap thead th,
  #critical-lab.active .critical-lab-panel[data-critical-lab-panel="mapping"]:not([hidden]) > .table-wrap thead th,
  #ncd-screening.active #screeningListPanel:not([hidden]) > .table-wrap thead th,
  #ncd-screening.active #screeningHistoryPanel:not([hidden]) > .table-wrap thead th,
  #dmConfirmationListPanel:not([hidden]) > .dm-confirmation-table-wrap thead th,
  #ncd-remission.active .remission-panel.active .registry-table-wrap-v2 thead th {
    position:sticky!important;
    top:0!important;
    z-index:8!important;
    background:var(--surface-soft,#f5f9ff)!important;
    box-shadow:0 1px 0 var(--line,#d8e3ef)!important;
  }
}

/* Mobile/tablet: retain natural document scrolling. */
@media (max-width:768px) {
  .main { overflow-y:auto!important; }
}


/* Sticky THEAD hardening v2.43.6
   Chrome-safe: pin the whole header group to the actual vertical scroller. */
@media (min-width:769px) {
  #registry.active .registry-table-wrap-v2,
  #registry.active > .registry-detail:not([hidden]) > .registry-table-wrap,
  .view.active:is(#followup-overview,#service-history,#area-treatment,#reports-disease,#reports-village) > .module-view > .table-wrap,
  .view.active:is(#lab-registry,#lab-egfr,#lab-hba1c) .lab-tab-panel[data-lab-panel="results"]:not([hidden]) > .table-wrap,
  #critical-lab.active .critical-lab-panel[data-critical-lab-panel="queue"]:not([hidden]) > .critical-lab-table-wrap,
  #critical-lab.active .critical-lab-panel[data-critical-lab-panel="mapping"]:not([hidden]) > .table-wrap,
  #ncd-screening.active #screeningListPanel:not([hidden]) > .table-wrap,
  #ncd-screening.active #screeningHistoryPanel:not([hidden]) > .table-wrap,
  #dmConfirmationListPanel:not([hidden]) > .dm-confirmation-table-wrap,
  #ncd-remission.active .remission-panel.active .registry-table-wrap-v2 {
    position:relative!important;
    isolation:isolate!important;
    overscroll-behavior:contain!important;
  }

  #registry.active .registry-table-wrap-v2 table,
  #registry.active > .registry-detail:not([hidden]) > .registry-table-wrap table,
  .view.active:is(#followup-overview,#service-history,#area-treatment,#reports-disease,#reports-village) > .module-view > .table-wrap table,
  .view.active:is(#lab-registry,#lab-egfr,#lab-hba1c) .lab-tab-panel[data-lab-panel="results"]:not([hidden]) > .table-wrap table,
  #critical-lab.active .critical-lab-panel[data-critical-lab-panel="queue"]:not([hidden]) > .critical-lab-table-wrap table,
  #critical-lab.active .critical-lab-panel[data-critical-lab-panel="mapping"]:not([hidden]) > .table-wrap table,
  #ncd-screening.active #screeningListPanel:not([hidden]) > .table-wrap table,
  #ncd-screening.active #screeningHistoryPanel:not([hidden]) > .table-wrap table,
  #dmConfirmationListPanel:not([hidden]) > .dm-confirmation-table-wrap table,
  #ncd-remission.active .remission-panel.active .registry-table-wrap-v2 table {
    border-collapse:separate!important;
    border-spacing:0!important;
  }

  #registry.active .registry-table-wrap-v2 table > thead,
  #registry.active > .registry-detail:not([hidden]) > .registry-table-wrap table > thead,
  .view.active:is(#followup-overview,#service-history,#area-treatment,#reports-disease,#reports-village) > .module-view > .table-wrap table > thead,
  .view.active:is(#lab-registry,#lab-egfr,#lab-hba1c) .lab-tab-panel[data-lab-panel="results"]:not([hidden]) > .table-wrap table > thead,
  #critical-lab.active .critical-lab-panel[data-critical-lab-panel="queue"]:not([hidden]) > .critical-lab-table-wrap table > thead,
  #critical-lab.active .critical-lab-panel[data-critical-lab-panel="mapping"]:not([hidden]) > .table-wrap table > thead,
  #ncd-screening.active #screeningListPanel:not([hidden]) > .table-wrap table > thead,
  #ncd-screening.active #screeningHistoryPanel:not([hidden]) > .table-wrap table > thead,
  #dmConfirmationListPanel:not([hidden]) > .dm-confirmation-table-wrap table > thead,
  #ncd-remission.active .remission-panel.active .registry-table-wrap-v2 table > thead {
    position:sticky!important;
    top:0!important;
    inset-block-start:0!important;
    z-index:30!important;
    background:var(--surface-soft,#f1f5f9)!important;
  }

  #registry.active .registry-table-wrap-v2 table > thead > tr > th,
  #registry.active > .registry-detail:not([hidden]) > .registry-table-wrap table > thead > tr > th,
  .view.active:is(#followup-overview,#service-history,#area-treatment,#reports-disease,#reports-village) > .module-view > .table-wrap table > thead > tr > th,
  .view.active:is(#lab-registry,#lab-egfr,#lab-hba1c) .lab-tab-panel[data-lab-panel="results"]:not([hidden]) > .table-wrap table > thead > tr > th,
  #critical-lab.active .critical-lab-panel[data-critical-lab-panel="queue"]:not([hidden]) > .critical-lab-table-wrap table > thead > tr > th,
  #critical-lab.active .critical-lab-panel[data-critical-lab-panel="mapping"]:not([hidden]) > .table-wrap table > thead > tr > th,
  #ncd-screening.active #screeningListPanel:not([hidden]) > .table-wrap table > thead > tr > th,
  #ncd-screening.active #screeningHistoryPanel:not([hidden]) > .table-wrap table > thead > tr > th,
  #dmConfirmationListPanel:not([hidden]) > .dm-confirmation-table-wrap table > thead > tr > th,
  #ncd-remission.active .remission-panel.active .registry-table-wrap-v2 table > thead > tr > th {
    position:static!important;
    background:var(--surface-soft,#f1f5f9)!important;
    box-shadow:inset 0 -1px 0 var(--line,#d8e3ef)!important;
  }

  body:not(.dark) #registry.active .registry-table-wrap-v2 table > thead,
  body:not(.dark) #registry.active .registry-table-wrap-v2 table > thead > tr > th {
    background:#eaf4ff!important;
    color:#123366!important;
  }
  body.dark #registry.active .registry-table-wrap-v2 table > thead,
  body.dark #registry.active .registry-table-wrap-v2 table > thead > tr > th {
    background:#0f2c49!important;
    color:#eaf4ff!important;
  }
}


/* HT confirmation drill-down — same full-height/sticky behavior as DM */
@media (min-width:769px) {
  #htConfirmationListPanel:not([hidden]) {
    min-height:360px!important;
    max-height:calc(100dvh - var(--fixed-header-height) - var(--fixed-footer-height) - 190px)!important;
    display:flex!important;
    flex-direction:column!important;
    overflow:hidden!important;
  }
  #htConfirmationListPanel:not([hidden]) > :not(.dm-confirmation-table-wrap) {
    flex:0 0 auto!important;
  }
  #htConfirmationListPanel:not([hidden]) > .dm-confirmation-table-wrap {
    flex:1 1 0!important;
    min-height:0!important;
    max-height:none!important;
    overflow:auto!important;
    position:relative!important;
    isolation:isolate!important;
    overscroll-behavior:contain!important;
  }
  #htConfirmationListPanel:not([hidden]) > .dm-confirmation-table-wrap table {
    border-collapse:separate!important;
    border-spacing:0!important;
  }
  #htConfirmationListPanel:not([hidden]) > .dm-confirmation-table-wrap table > thead {
    position:sticky!important;
    top:0!important;
    inset-block-start:0!important;
    z-index:30!important;
    background:var(--surface-soft,#f1f5f9)!important;
  }
  #htConfirmationListPanel:not([hidden]) > .dm-confirmation-table-wrap table > thead > tr > th {
    position:static!important;
    background:var(--surface-soft,#f1f5f9)!important;
    box-shadow:inset 0 -1px 0 var(--line,#d8e3ef)!important;
  }
}
