/* One design for all website grids, including plain tables and lazy/modal content.
   The existing admin body class also supports layouts compiled before this update. */
body:is(.ip-grid-system, .ip-admin-body) {
    --ip-grid-border: #d3d9e1;
    --ip-grid-header: #f2f6fc;
    --ip-grid-stripe: #e9ecef;
    --ip-grid-surface: #fff;
    --ip-grid-hover: #eaf2ff;
    --ip-grid-text: #334e73;
    --ip-grid-font-size: 0.925rem;
    --ip-grid-padding: 0.35rem 0.5rem;
}

body:is(.ip-grid-system, .ip-admin-body) :is(table, table.table, table.display, table.dataTable):not(:where(.bootstrap-timepicker-widget *, .daterangepicker *, .ui-datepicker *, .fc *, [role="presentation"])) {
    width: 100%;
    border-collapse: collapse !important;
    border-spacing: 0 !important;
    border-radius: 0 !important;
    border: 1px solid var(--ip-grid-border) !important;
    background: var(--ip-grid-surface);
    font-size: var(--ip-grid-font-size);
    color: var(--ip-grid-text);
    font-variant-numeric: tabular-nums lining-nums;
}

/* Direct cells only: responsive detail lists and form controls keep their geometry. */
body:is(.ip-grid-system, .ip-admin-body) :is(table, table.table, table.display, table.dataTable):not(:where(.bootstrap-timepicker-widget *, .daterangepicker *, .ui-datepicker *, .fc *, [role="presentation"])) > :is(thead, tbody, tfoot) > tr > :is(th, td) {
    border: 1px solid var(--ip-grid-border) !important;
    padding: var(--ip-grid-padding) !important;
    font-size: var(--ip-grid-font-size) !important;
    line-height: 1.5;
    vertical-align: middle;
    /* Bootstrap 5 paints stripes/hover with a cell-sized inset shadow. Reset
       that layer so both website themes show the same actual row colours. */
    box-shadow: none;
}

body:is(.ip-grid-system, .ip-admin-body) :is(table, table.table, table.display, table.dataTable):not(:where(.bootstrap-timepicker-widget *, .daterangepicker *, .ui-datepicker *, .fc *, [role="presentation"])) > tbody > tr > :is(th, td) {
    background-color: inherit;
}

body:is(.ip-grid-system, .ip-admin-body) :is(table, table.table, table.display, table.dataTable):not(:where(.bootstrap-timepicker-widget *, .daterangepicker *, .ui-datepicker *, .fc *, [role="presentation"])) > thead > tr > :is(th, td) {
    background: var(--ip-grid-header) !important;
    color: var(--ip-grid-text) !important;
    font-weight: 600 !important;
    text-transform: none !important;
    letter-spacing: normal !important;
    /* The navbar offset used by legacy sticky headers covered the first row
       inside cards/tabs. DataTables manages its own scrolling header. */
    position: static !important;
    top: auto !important;
    z-index: auto;
}

/* All grids use the reference's grey/white stripes, even without table-striped.
   Row backgrounds let existing warning/error/dirty cell colours survive. */
body:is(.ip-grid-system, .ip-admin-body) :is(table, table.table, table.display, table.dataTable):not(:where(.bootstrap-timepicker-widget *, .daterangepicker *, .ui-datepicker *, .fc *, [role="presentation"])) > tbody > tr:nth-child(n) {
    background-color: var(--ip-grid-surface);
}

body:is(.ip-grid-system, .ip-admin-body) :is(table, table.table, table.display, table.dataTable):not(:where(.bootstrap-timepicker-widget *, .daterangepicker *, .ui-datepicker *, .fc *, [role="presentation"])) > tbody > tr:nth-child(odd) {
    background-color: var(--ip-grid-stripe);
}

body:is(.ip-grid-system, .ip-admin-body) :is(table, table.table, table.display, table.dataTable):not(:where(.bootstrap-timepicker-widget *, .daterangepicker *, .ui-datepicker *, .fc *, [role="presentation"])) > tbody > tr:is(:hover, :focus-within) {
    background-color: var(--ip-grid-hover) !important;
}

/* Sorted columns and sticky action cells follow the row's opaque background. */
body:is(.ip-grid-system, .ip-admin-body) table.dataTable > tbody > tr > :is(.sorting_1, .sorting_2, .sorting_3),
body:is(.ip-grid-system, .ip-admin-body) table > tbody > tr > .vq-actions {
    background: inherit !important;
}

body:is(.ip-grid-system, .ip-admin-body) :is(table, table.table, table.display, table.dataTable):not(:where(.bootstrap-timepicker-widget *, .daterangepicker *, .ui-datepicker *, .fc *, [role="presentation"])) > tfoot > tr > :is(th, td) {
    background: var(--ip-grid-header) !important;
    font-weight: 600;
}

/* Reserve the sorting and responsive-expand control gutters. */
body:is(.ip-grid-system, .ip-admin-body) table.dataTable > thead > tr > :is(.sorting, .sorting_asc, .sorting_desc, .sorting_asc_disabled, .sorting_desc_disabled) {
    padding-inline-end: 1.8rem !important;
}

body:is(.ip-grid-system, .ip-admin-body) table.dataTable > tbody > tr > :is(.dtr-control, .control),
body:is(.ip-grid-system, .ip-admin-body) table.dataTable.dtr-inline.collapsed > tbody > tr > :is(th, td):first-child {
    padding-inline-start: 30px !important;
}

/* Hidden sizing headers must stay zero-height in DataTables scroll bodies. */
body:is(.ip-grid-system, .ip-admin-body) .dataTables_scrollBody > table.dataTable > :is(thead, tfoot) > tr > :is(th, td) {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    border-top-width: 0 !important;
    border-bottom-width: 0 !important;
}

/* Explicit business states remain visible regardless of zebra position. */
body:is(.ip-grid-system, .ip-admin-body) table > tbody > tr:is(.selected, .table-active) {
    background-color: #dceaff !important;
}

body:is(.ip-grid-system, .ip-admin-body) table > tbody > tr.duplicate {
    background-color: #ea7878 !important;
}

body:is(.ip-grid-system, .ip-admin-body) table > tbody > tr.row-bg-red {
    background-color: #ffc9c9 !important;
}

/* Horizontal action-column pinning and the activity log's own scroll region. */
body:is(.ip-grid-system, .ip-admin-body) table > thead > tr > .vq-actions {
    position: sticky !important;
    right: 0;
    z-index: 4;
}

body:is(.ip-grid-system, .ip-admin-body) .activity-notes-card table > thead > tr > th {
    position: sticky !important;
    top: 0 !important;
    z-index: 2;
}
