/*
   Site-wide grid styling for Scaleforms2.

   Strategy:
   - Apply borders + hover globally to .table so every page picks it up without per-page changes.
   - Hide DataTables wrappers until a "dt-ready" class is added by the global initComplete hook (see _Layout)
     to eliminate the search-controls-render-before-data flicker.
*/

/* Borders + hover on every .table (Bootstrap's defaults are border-less).
   Opt-out: add class="borderless" (legacy) or class="table-borderless" (Bootstrap 4) to skip styling. */
.table:not(.borderless):not(.table-borderless) {
    border-collapse: collapse;
}
.table:not(.borderless):not(.table-borderless) th,
.table:not(.borderless):not(.table-borderless) td {
    border: 1px solid #dee2e6;
}
.table:not(.borderless):not(.table-borderless) thead th {
    border-bottom: 2px solid #dee2e6;
    background-color: #A7D2FF;
    color: #343A40;
}
.table:not(.borderless):not(.table-borderless) tbody tr:hover {
    background-color: rgba(167, 210, 255, 0.18);
}
.table.borderless td,
.table.borderless th,
.table.table-borderless td,
.table.table-borderless th {
    border: none;
}

/* Flicker fix — opt-in via .sf2-grid class on the table.
   Both initial server paint AND DataTables-wrapped state stay hidden until init completes.

   How it works:
   - <table class="sf2-grid"> starts visibility:hidden at the very first paint (no flash of
     unsorted/un-paginated rows).
   - When DataTables wraps it in .dataTables_wrapper, the :has() selector hides the wrapper
     too (search controls + length picker do not appear before the table is ready).
   - initComplete adds .dt-ready -> reveal everything together, no flash.
   - 1.5s CSS animation safety net reveals the table no matter what, so we can never
     accidentally hide it forever (init error, JS race, no JS at all).

   :has() is supported in Chrome 105+ / Safari 15.4+ / Firefox 121+ (released 2023). */

.sf2-grid {
    visibility: hidden;
    width: 100%;
    animation: sf2-grid-reveal 0s 1.5s forwards;
}
.sf2-grid.dt-ready {
    visibility: visible;
    animation: none;
}
@keyframes sf2-grid-reveal { to { visibility: visible; } }

.dataTables_wrapper:has(.sf2-grid:not(.dt-ready)) {
    visibility: hidden;
    animation: sf2-grid-reveal 0s 1.5s forwards;
}
.dataTables_wrapper:has(.sf2-grid.dt-ready) {
    visibility: visible;
    animation: none;
}
