/* ==========================================================================
   SOLUTION 3: Universal Sticky Header & Viewport-Bounded Scroll on All Grids
   MadrassaTech Production & All Demo Instances
   ========================================================================== */

/* 1. All table container wrappers: Viewport-bounded height with both X and Y scrollbars always visible on screen */
.table-scroll-container,
.table-responsive,
.data-table-container,
.overflow-x-auto:has(table),
div[style*="overflowX"]:has(table),
div[style*="overflow-x"]:has(table),
div:has(> table),
div:has(> .data-table) {
  max-height: calc(100vh - 270px) !important;
  overflow: auto !important;
  position: relative !important;
  -webkit-overflow-scrolling: touch;
  border-radius: 12px;
}

/* Modals & Dialogs: Contained within modal viewport */
[role="dialog"] div:has(> table),
[role="dialog"] .table-scroll-container,
[role="dialog"] .table-responsive,
.modal div:has(> table),
div[style*="zIndex: 99"] div:has(> table),
div[style*="z-index: 99"] div:has(> table),
div[style*="position: fixed"] div:has(> table) {
  max-height: min(55vh, 460px) !important;
}

/* 2. Sticky Table Headers: Locked at the top during vertical scroll */
table thead,
.data-table thead {
  position: sticky !important;
  top: 0 !important;
  z-index: 25 !important;
}

table thead th,
table thead tr th,
.data-table thead th,
.data-table thead tr th {
  position: sticky !important;
  top: 0 !important;
  z-index: 25 !important;
  background-color: #0f172a; /* Sleek dark slate default matching MadrassaTech header theme */
  color: #f8fafc;
  box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.2);
}

/* Emerald headers override for finance/canteen tables */
table thead tr[style*="059669"] th,
table thead tr[style*="#059669"] th,
table thead tr[style*="emerald"] th,
.data-table thead th,
.data-table thead tr th {
  background-color: #059669 !important;
  color: #ffffff !important;
}

/* Light headers override if table specifies light theme */
table.table-light thead th,
table.light-header thead th,
table[data-theme="light"] thead th {
  background-color: #f8fafc !important;
  color: #0f172a !important;
  box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.08);
}

/* 3. Table styling for seamless sticky rendering */
table:has(thead th),
.data-table {
  border-collapse: separate !important;
  border-spacing: 0 !important;
  min-width: 100%;
}

/* 4. Sleek modern scrollbars: High visibility, rounded, fast grab */
.table-scroll-container::-webkit-scrollbar,
.table-responsive::-webkit-scrollbar,
.data-table-container::-webkit-scrollbar,
div[style*="overflowX"]:has(table)::-webkit-scrollbar,
div[style*="overflow-x"]:has(table)::-webkit-scrollbar,
div:has(> table)::-webkit-scrollbar {
  width: 9px !important;
  height: 9px !important;
}

.table-scroll-container::-webkit-scrollbar-track,
.table-responsive::-webkit-scrollbar-track,
.data-table-container::-webkit-scrollbar-track,
div[style*="overflowX"]:has(table)::-webkit-scrollbar-track,
div[style*="overflow-x"]:has(table)::-webkit-scrollbar-track,
div:has(> table)::-webkit-scrollbar-track {
  background: #f1f5f9 !important;
  border-radius: 8px !important;
}

.table-scroll-container::-webkit-scrollbar-thumb,
.table-responsive::-webkit-scrollbar-thumb,
.data-table-container::-webkit-scrollbar-thumb,
div[style*="overflowX"]:has(table)::-webkit-scrollbar-thumb,
div[style*="overflow-x"]:has(table)::-webkit-scrollbar-thumb,
div:has(> table)::-webkit-scrollbar-thumb {
  background: #94a3b8 !important;
  border-radius: 8px !important;
  border: 2px solid #f1f5f9 !important;
}

.table-scroll-container::-webkit-scrollbar-thumb:hover,
.table-responsive::-webkit-scrollbar-thumb:hover,
.data-table-container::-webkit-scrollbar-thumb:hover,
div[style*="overflowX"]:has(table)::-webkit-scrollbar-thumb:hover,
div[style*="overflow-x"]:has(table)::-webkit-scrollbar-thumb:hover,
div:has(> table)::-webkit-scrollbar-thumb:hover {
  background: #64748b !important;
}

/* Firefox scrollbars */
.table-scroll-container,
.table-responsive,
.data-table-container,
div[style*="overflowX"]:has(table),
div[style*="overflow-x"]:has(table),
div:has(> table) {
  scrollbar-width: thin;
  scrollbar-color: #94a3b8 #f1f5f9;
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .table-scroll-container,
  .table-responsive,
  .data-table-container,
  div[style*="overflowX"]:has(table),
  div[style*="overflow-x"]:has(table),
  div:has(> table) {
    max-height: calc(100vh - 220px) !important;
    border-radius: 8px;
  }
}
