/* Table tools (assets/js/table_tools.js) */
.tt-bar .tt-search { width: 240px; max-width: 100%; }
table.tt-table .tt-hide { display: none; }
table.tt-table th.tt-sortable { cursor: pointer; user-select: none; white-space: nowrap; }
table.tt-table .tt-sort-icon { margin-left: 4px; opacity: .45; font-size: .85em; }
table.tt-table th.tt-sortable:hover .tt-sort-icon { opacity: .9; }
table.tt-table th { position: relative; }
table.tt-table.tt-fixed { table-layout: fixed; max-width: none; }
table.tt-table.tt-fixed th,
table.tt-table.tt-fixed td { overflow: hidden; text-overflow: ellipsis; overflow-wrap: anywhere; }
table.tt-table .tt-resizer {
    position: absolute; top: 0; right: 0; width: 6px; height: 100%;
    cursor: col-resize; user-select: none; z-index: 2;
}
table.tt-table .tt-resizer:hover,
body.tt-resizing table.tt-table .tt-resizer { background: rgba(var(--bs-primary-rgb, 13, 110, 253), .35); }
body.tt-resizing { cursor: col-resize; user-select: none; }
table.tt-table .tt-filter-row th { padding: 4px; font-weight: 400; }
table.tt-table .tt-filter-row input { min-width: 0; width: 100%; }

/* Loader while a filter fetches every page of a server-paged table */
.tt-loading-host { position: relative; min-height: 90px; }
.tt-loader {
    position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center;
    background: rgba(var(--bs-body-bg-rgb, 255, 255, 255), .75);
}
.tt-loader-box {
    padding: 8px 16px; border-radius: 6px; font-size: .9rem;
    background: var(--bs-body-bg, #fff); border: 1px solid var(--bs-border-color, #dee2e6); box-shadow: 0 2px 8px rgba(0,0,0,.12);
}

/* Date columns: button in the filter row opens the filter popup */
table.tt-table .tt-date-btn { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; }
.tt-date-panel {
    position: fixed; z-index: 2000; width: 280px; padding: 12px 16px 14px;
    background: var(--bs-body-bg, #fff); color: var(--bs-body-color, #212529);
    border: 1px solid var(--bs-border-color, #dee2e6); border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.18);
}
.tt-date-panel .tt-date-title {
    margin: 0 0 10px; padding-bottom: 8px; font-size: .95rem; font-weight: 600;
    border-bottom: 1px solid var(--bs-border-color, #dee2e6);
}
.tt-date-panel .form-check { margin-bottom: 6px; }
.tt-date-panel .form-check-label i { margin-right: 4px; }
.tt-date-panel .tt-date-inputs { margin-top: 8px; }

/* The pages' old top filter bar (#filterContainer.d-none) leaves empty wrappers with padding/margin behind: collapse them */
.card-body:has(> .row > [class*="col-"] > #filterContainer.d-none:only-child),
.row:has(> [class*="col-"] > #filterContainer.d-none:only-child) { display: none; }

/* Bottom bar of server-paged tables (same layout as the NCR tables): Show [n] entries | Showing x to y of z | pager */
.tt-pager-row { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; padding: .5rem .75rem; margin-top: .25rem; }
.tt-pager-block { display: contents; }
.tt-pager-row .text-center { margin: 0 !important; }
.tt-pager-row .pagination { margin: 0; }
.tt-pager-row .form-select { padding-top: .2rem; padding-bottom: .2rem; }

/* Sticky header: column headers + the column filter row stay put while the table scrolls */
table.tt-table thead th {
    position: sticky; top: 0; z-index: 3;
    background-color: var(--bs-body-bg, #fff);
    box-shadow: inset 0 -1px 0 var(--bs-border-color, #dee2e6);
}
table.tt-table thead tr.tt-filter-row th { z-index: 2; } /* top is set by table_tools.js (height of the header row) */
/* Tables in a plain .table-responsive scroll the page, not the box: give the box a height so the header can stick in it */
.table-responsive:has(> table.tt-table) { max-height: 75vh; overflow-y: auto; }

/* No flash while the page loads: do the header re-arrangement in CSS first (table_tools.js moves the "Show entries"
   select to the bottom bar and finishes the job once it runs). Only on pages that have a server-paged tt-table. */
body:has(table[data-tt-server]) [class*="col-"]:has(#rowsPerPage):not(:has(table)):not(:has(h1, h2, h3, h4, h5, h6)) { display: none; }
body:has(table[data-tt-server]) .row > [class*="col-"]:has(.icon-btn):not(:has(table)) { margin-left: auto; }

/* No divider line between the "Select All" bar and the table tools */
body:has(table.tt-table) .card-body.border-bottom:has(#selectAllRecords) { border-bottom: 0 !important; }

/* Compact top: "Select All" + table tools share one line, tighter card header */
.tt-sa-merged { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; padding-top: .35rem !important; padding-bottom: .35rem !important; }
.tt-sa-merged > .row { flex: 0 0 auto; width: auto; margin: 0; }
.tt-sa-merged > .row > [class*="col-"] { width: auto; flex: 0 0 auto; }
.tt-sa-merged > .row > [class*="col-"]:last-child:not(:first-child) { display: none; } /* "Select multiple records..." hint */
.tt-sa-merged > .tt-bar { flex: 1 1 auto; margin: 0 !important; }
body:has(table[data-tt-server]) .card-header { padding-top: .6rem; padding-bottom: .4rem; }
body:has(table[data-tt-server]) .card-header h5 { margin-bottom: 0; }

/* ===== Standard look of every data table - rules set by the user (fix_logs 545) =====
   1. text 13px  2. row 32px, letter spacing -0.01em  3. no shadows, 1px row border at 8% (white in dark mode, black in light mode so it shows)
   4. long text = one line + ellipsis, tooltip with the whole text on hover (JS at the end of table_tools.js)  5. hover 80ms  6. all left aligned
   Applies to .table / .dataTable / .tt-table / .ncr-lobby-table (Harwin pages, NCR, Supplier Performance, Documentation data tables);
   not to report / print layouts (.ncr-8d, .ncr-an-table) or e-mail HTML. ===== */
:root { --tbl-line: rgba(0, 0, 0, .08); --tbl-row: 32px; --tbl-cell-max: 300px; }
body.dark { --tbl-line: rgba(255, 255, 255, .08); }

/* the tables this applies to */
:is(table.table:not(.ncr-an-table), table.dataTable, table.tt-table, table.ncr-lobby-table):not(.ncr-8d *) { box-shadow: none !important; border-collapse: collapse; }
:is(table.table:not(.ncr-an-table), table.dataTable, table.tt-table, table.ncr-lobby-table):not(.ncr-8d *) :is(thead, tbody, tfoot, tr) { box-shadow: none !important; }

/* 1 + 2 + 3 + 6: size, spacing, row height, row border, left alignment */
:is(table.table:not(.ncr-an-table), table.dataTable, table.tt-table, table.ncr-lobby-table):not(.ncr-8d *) :is(th, td) {
    font-size: 13px !important;
    letter-spacing: -0.01em !important;
    line-height: 1.35 !important;
    height: var(--tbl-row);
    padding-top: .2rem !important;
    padding-bottom: .2rem !important;
    vertical-align: middle;
    text-align: left !important;
    box-shadow: none !important;
    border: 0 !important;
    border-bottom: 1px solid var(--tbl-line) !important;
}
:is(table.table:not(.ncr-an-table), table.dataTable, table.tt-table, table.ncr-lobby-table):not(.ncr-8d *) :is(th, td) :is(.text-end, .text-center, .text-right, .text-start) { text-align: left !important; }
/* things written inside the cells follow the same size / spacing */
:is(table.table:not(.ncr-an-table), table.dataTable, table.tt-table, table.ncr-lobby-table):not(.ncr-8d *) :is(th, td) :is(a, span:not(.badge), label, small, p, div, input, select, textarea, .form-control, .form-select) { font-size: inherit; letter-spacing: inherit; }
:is(table.table:not(.ncr-an-table), table.dataTable, table.tt-table, table.ncr-lobby-table):not(.ncr-8d *) :is(.form-control, .form-select) { font-size: 13px !important; min-height: 26px; padding-top: .1rem; padding-bottom: .1rem; box-shadow: none; }
:is(table.table:not(.ncr-an-table), table.dataTable, table.tt-table, table.ncr-lobby-table):not(.ncr-8d *) td .btn.btn-sm { line-height: 1.2; box-shadow: none; }

/* 4: one line + ellipsis (cells that hold buttons / dropdowns / inputs are left alone so menus are not clipped) */
:is(table.table:not(.ncr-an-table), table.dataTable, table.tt-table, table.ncr-lobby-table):not(.ncr-8d *) th { white-space: nowrap; }
:is(table.table:not(.ncr-an-table), table.dataTable, table.tt-table, table.ncr-lobby-table):not(.ncr-8d *) td:not(.ncr-sel-col, .ncr-action-col, .text-wrap):not(:has(.dropdown, .dropdown-menu, input, select, textarea, .btn-group, .form-check)) {
    max-width: var(--tbl-cell-max);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
:is(table.table:not(.ncr-an-table), table.dataTable, table.tt-table, table.ncr-lobby-table):not(.ncr-8d *) td:not(.ncr-sel-col, .text-wrap) > :is(div, p, span:not(.badge), a):not(:has(.btn, input, select, textarea)) { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 5: hover = 80ms */
:is(table.table:not(.ncr-an-table), table.dataTable, table.tt-table, table.ncr-lobby-table):not(.ncr-8d *) :is(tbody tr, td, th, a, .btn, .btn i) { transition-duration: 80ms !important; transition-property: background-color, color, border-color, opacity, transform; transition-timing-function: ease-out; }

@media print { :is(table.table, table.dataTable, table.tt-table, table.ncr-lobby-table) :is(th, td) { height: auto; max-width: none; overflow: visible; white-space: normal; } }

/* the tooltip with the whole text (assets/js/table_tooltip.js) */
#tblTip { position: fixed; z-index: 2000; max-width: 380px; padding: .45rem .65rem; border-radius: 6px; background: #1f2433; color: #fff; font-size: 13px; line-height: 1.4; letter-spacing: -0.01em; text-align: left; white-space: normal; overflow-wrap: anywhere; box-shadow: none; pointer-events: none; opacity: 0; transition: opacity 80ms ease-out; }
#tblTip.on { opacity: 1; }

/* Row hover: the row under the pointer gets a soft theme tint so the user knows which row they are on (80ms, set above). Bootstrap's own hover
   uses an inset box-shadow, which the table standard removes - this replaces it. */
:is(table.table:not(.ncr-an-table), table.dataTable, table.tt-table, table.ncr-lobby-table):not(.ncr-8d *) tbody tr:hover > :is(td, th) {
    background-color: rgba(var(--primary, 91, 78, 230), .08) !important;
}

/* ---- hardening (fix_logs 545): content inside cells that used to break the standard on the _list pages ---- */
/* inner text elements (Bootstrap .small / .fs-* / page classes) get the standard size too; icons, badges and buttons keep their own */
:is(table.table:not(.ncr-an-table), table.dataTable, table.tt-table, table.ncr-lobby-table):not(.ncr-8d *) :is(th, td) :is(a, span, label, small, p, div, strong, b, em, code):not(.badge, .btn, .fa-solid, .fa-regular, .fa-brands, [class*="fa-"], .spinner-border) {
    font-size: 13px !important;
    letter-spacing: -0.01em !important;
    line-height: 1.35 !important;
    text-align: left !important;
}
/* buttons in cells are compact so a row stays 32px */
:is(table.table:not(.ncr-an-table), table.dataTable, table.tt-table, table.ncr-lobby-table):not(.ncr-8d *) td .btn:not(.ico-plain) {
    padding: .1rem .5rem !important; font-size: 12px !important; line-height: 1.2 !important; min-height: 0; letter-spacing: -0.01em;
}
:is(table.table:not(.ncr-an-table), table.dataTable, table.tt-table, table.ncr-lobby-table):not(.ncr-8d *) td .badge { font-size: 11px; line-height: 1.2; letter-spacing: -0.01em; }
:is(table.table:not(.ncr-an-table), table.dataTable, table.tt-table, table.ncr-lobby-table):not(.ncr-8d *) td .form-check { margin: 0; min-height: 0; padding-top: 0; padding-bottom: 0; }
:is(table.table:not(.ncr-an-table), table.dataTable, table.tt-table, table.ncr-lobby-table):not(.ncr-8d *) :is(th, td) :is(.form-check-input, input[type="checkbox"], input[type="radio"]) { margin-top: 0; }
/* a checkbox / radio alone in a cell must not switch the ellipsis off (only dropdowns, text inputs, selects and textareas do) */
:is(table.table:not(.ncr-an-table), table.dataTable, table.tt-table, table.ncr-lobby-table):not(.ncr-8d *) td:not(.ncr-sel-col, .ncr-action-col, .text-wrap):has(.form-check, input[type="checkbox"], input[type="radio"], .btn-group):not(:has(.dropdown, .dropdown-menu, select, textarea, input:not([type="checkbox"], [type="radio"]))) {
    max-width: var(--tbl-cell-max); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* theme icon buttons (.btn.icon-btn = 37x37px + m-1) and their <ul class="list-group-horizontal"> wrapper made rows ~53px (AVL List action cells etc.) */
:is(table.table:not(.ncr-an-table), table.dataTable, table.tt-table, table.ncr-lobby-table):not(.ncr-8d *) td .btn.icon-btn {
    width: auto !important; height: auto !important; min-width: 24px; min-height: 24px; margin: 0 .1rem !important; padding: .1rem .3rem !important; line-height: 1 !important;
}
:is(table.table:not(.ncr-an-table), table.dataTable, table.tt-table, table.ncr-lobby-table):not(.ncr-8d *) td :is(ul.list-group, ul.list-group-horizontal) {
    margin: 0 !important; padding: 0 !important; gap: 0; flex-wrap: nowrap; border-radius: 0; background: transparent;
}
:is(table.table:not(.ncr-an-table), table.dataTable, table.tt-table, table.ncr-lobby-table):not(.ncr-8d *) td :is(li.list-item, li.list-group-item, ul.list-group > li) {
    margin: 0 !important; padding: 0 !important; border: 0 !important; background: transparent; list-style: none; display: inline-flex; align-items: center;
}

/* ===== Column picker ('Table view settings') for the _list pages - same look as the NCR / Supplier Performance column arranger; built by assets/js/col_picker.js ===== */

/* "Table view settings" column arranger (table_kit.php ncr_tk_columns_modal(), fix_logs 108).
   The modal is moved under <body>, so it's scoped by .ncr-colpick, not .ncr-lobby. */
.ncr-colpick-grid { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto; gap: 0.75rem; align-items: center; }
.ncr-colpick-pane { min-width: 0; }
.ncr-colpick-btns { display: flex; flex-direction: column; gap: 0.35rem; }
.ncr-colpick-list { height: 22rem; overflow-y: auto; border: 1px solid var(--bs-border-color); border-radius: 0.375rem; margin-bottom: 0.25rem; }
.ncr-colpick-list .list-group-item { border-left: 0; border-right: 0; border-radius: 0; }
.ncr-colpick-list .list-group-item:first-child { border-top: 0; }
.ncr-colpick-item { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.35rem 0.6rem; font-size: 0.85rem; cursor: pointer; user-select: none; }
.ncr-colpick-item:hover { background: rgba(127, 127, 127, 0.08); }
.ncr-colpick-item:focus-visible { outline: 2px solid rgb(var(--primary)); outline-offset: -2px; }
.ncr-colpick-item.ncr-colpick-on { background: rgba(var(--primary), 0.14); }
.ncr-colpick-item.d-none { display: none !important; }
.ncr-colpick-icons { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--bs-secondary-color); flex-shrink: 0; }
.ncr-colpick-handle { cursor: grab; font-size: 1.05rem; }
.ncr-colpick-locked .ncr-colpick-text { font-weight: 600; }
.ncr-colpick-dragging { opacity: 0.45; }
.ncr-colpick-drop-before { box-shadow: inset 0 3px 0 rgb(var(--primary)); }
.ncr-colpick-drop-after { box-shadow: inset 0 -3px 0 rgb(var(--primary)); }
@media (max-width: 767.98px) {
    .ncr-colpick-grid { grid-template-columns: minmax(0, 1fr); }
    .ncr-colpick-btns { flex-direction: row; justify-content: center; }
    .ncr-colpick-list { height: 14rem; }
}

/* Coloured table headers (thead class table-dark / table-primary / ...): the sticky-header rule above paints header cells with the page background, which turned
   the white header text of these tables invisible in light mode. A header that carries a colour class keeps its own colour + text colour. */
table.tt-table :is(thead.table-dark, thead.table-primary, thead.table-secondary, thead.table-success, thead.table-danger, thead.table-warning, thead.table-info, thead.table-light) th {
    background-color: var(--bs-table-bg) !important; color: var(--bs-table-color, inherit) !important;
}
/* and a header whose cells are white-text by the theme but sit on a light background: never white-on-white */
table.tt-table thead:not([class*="table-"]) th:not([class*="bg-"]) { color: var(--bs-body-color, inherit); }

/* One header look for every table: a coloured header (thead.table-dark / -primary ...) is shown like the standard header (page background, body text),
   and sort links inside headers (class text-white) follow the header text colour - so this page style matches all the other tables. */
table.tt-table :is(thead.table-dark, thead.table-primary, thead.table-secondary, thead.table-success, thead.table-danger, thead.table-warning, thead.table-info, thead.table-light) th {
    background-color: var(--bs-body-bg, #fff) !important; color: var(--bs-body-color, inherit) !important;
}
table.tt-table thead th a, table.tt-table thead th a.text-white { color: inherit !important; font-weight: inherit; }

/* Sort icon: one look everywhere - faded double-arrow (fa-sort) when not sorted, solid caret up/down on the sorted column */
table.tt-table .tt-sort-icon { margin-left: 6px; font-size: .8em; opacity: .4; vertical-align: baseline; }
table.tt-table .tt-sort-icon.fa-caret-up, table.tt-table .tt-sort-icon.fa-caret-down { opacity: 1; color: var(--bs-primary, currentColor); }
table.tt-table th a:hover .tt-sort-icon, table.tt-table th.tt-sortable:hover .tt-sort-icon { opacity: .9; }

/* no flash of the page's own sort arrows: the header stays invisible until the toolkit has built it (sort icons are added in the same step) */
table.tt-table { transition: opacity .28s ease; }
/* header + rows appear together: the whole table waits (invisible, space reserved) until the toolkit has built it; failsafe reveals it after 2 s */
table.tt-table:not([data-tt-ready]):has(> thead > tr) { opacity: 0; animation: ttReveal 0s linear 2s forwards; }
@keyframes ttReveal { to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { table.tt-table { transition: none; } }
