

/* ── 1. DATATABLES' OWN CSS VARIABLES ────────────────────────
   DataTables exposes its color choices as CSS variables — most
   as raw "r, g, b" triples (no rgb() wrapper) since its own
   rules consume them via rgba(var(--dt-row-selected), alpha).
   Re-pointing these covers row selection, striping, hover and
   column-ordering tints with zero specificity fights.
   ────────────────────────────────────────────────────────── */
:root {
    /* var(--bsd-brand-500) #3b82f6 as an "r, g, b" triple */
    --dt-row-selected:        59, 130, 246;
    --dt-row-selected-text:   255, 255, 255;
    /* var(--bsd-brand-100) #dbeafe — links inside a selected row */
    --dt-row-selected-link:   219, 234, 254;
    /* var(--bsd-text) #0f172a — used as a low-alpha neutral tint
       for stripe/hover/order-column, same recipe DataTables uses
       by default, just tinted with BSD's ink instead of pure black */
    --dt-row-stripe:          15, 23, 42;
    --dt-row-hover:           15, 23, 42;
    --dt-column-ordering:     15, 23, 42;
    --dt-header-align-items:  center;
    --dt-header-vertical-align: middle;
    --dt-html-background:     var(--bsd-surface);
}

[data-bsd-theme="dark"],
html.dark {
    --dt-row-stripe:      255, 255, 255;
    --dt-row-hover:       255, 255, 255;
    --dt-column-ordering: 255, 255, 255;
    --dt-html-background: var(--bsd-surface);
}


/* ── 2. CONTAINER ─────────────────────────────────────────── */
div.dt-container {
    font-family: var(--bsd-font);
    font-size: var(--bsd-text-sm);
    color: var(--bsd-text);
    background: var(--bsd-surface);
    border: 1px solid var(--bsd-border);
    border-radius: var(--bsd-r-md);
    box-shadow: var(--bsd-shadow-xs);
    overflow: scroll;
}

/* Control rows (length/search up top, info/paging at the bottom)
   get padding and a tinted background; the row holding the
   actual <table> stays flush with the container's edges. */
div.dt-container div.dt-layout-row:not(.dt-layout-table) {
    margin: 0;
    padding: 12px var(--bsd-gap-lg);
}

div.dt-container div.dt-layout-row:not(.dt-layout-table):first-child {
    background: var(--bsd-surface-2);
    border-bottom: 1px solid var(--bsd-border);
}

div.dt-container div.dt-layout-row:not(.dt-layout-table):last-child {
    background: var(--bsd-surface-2);
    border-top: 1px solid var(--bsd-border);
    flex-wrap: wrap;
    gap: 8px;
}

div.dt-container div.dt-layout-row.dt-layout-table {
    margin: 0;
}

div.dt-container .dt-length,
div.dt-container .dt-search,
div.dt-container .dt-info,
div.dt-container .dt-processing,
div.dt-container .dt-paging {
    color: var(--bsd-text-2);
    font-size: var(--bsd-text-sm);
}

div.dt-container .dt-length label,
div.dt-container .dt-search label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--bsd-text-muted);
    font-size: var(--bsd-text-xs);
    font-weight: 500;
}

div.dt-container .dt-info {
    color: var(--bsd-text-muted);
    font-size: var(--bsd-text-xs);
}


/* ── 3. INPUTS: search box + length select ───────────────── */
div.dt-container .dt-input {
    border: 1px solid var(--bsd-border-2);
    border-radius: var(--bsd-r-md);
    padding: 7px 10px;
    background: var(--bsd-surface);
    color: var(--bsd-text);
    font-size: var(--bsd-text-sm);
    font-family: var(--bsd-font);
    box-shadow: var(--bsd-shadow-inset);
    transition: var(--bsd-t-fast);
    margin: 0;
}

div.dt-container .dt-input:focus {
    outline: none;
    border-color: var(--bsd-primary);
    box-shadow: var(--bsd-shadow-focus);

    background: var(--bsd-surface);
    color: var(--bsd-text);
}

div.dt-container .dt-search input.dt-input {
    min-width: 220px;

    border-radius: var(--bsd-r-md);
}

div.dt-container select.dt-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
    cursor: pointer;
}


/* ── 4. PAGINATION ────────────────────────────────────────── */
div.dt-container .dt-paging {
    display: flex;
}

div.dt-container .dt-paging .dt-paging-button {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    height: 30px;
    padding: 0 8px;
    margin-left: 4px;
    border-radius: var(--bsd-r-xs);
    border: 1px solid var(--bsd-border);
    background: var(--bsd-surface);
    color: var(--bsd-text-2) !important;
    font-size: var(--bsd-text-xs);
    font-weight: 500;
    text-decoration: none !important;
    cursor: pointer;
    transition: var(--bsd-t-fast);
}

div.dt-container .dt-paging .dt-paging-button:hover {
    background: var(--bsd-surface-3) !important;
    border-color: var(--bsd-border-2);
    color: var(--bsd-text) !important;
}

div.dt-container .dt-paging .dt-paging-button.current,
div.dt-container .dt-paging .dt-paging-button.current:hover {
    background: var(--bsd-primary) !important;
    border-color: var(--bsd-primary);
    color: #fff !important;
}

div.dt-container .dt-paging .dt-paging-button.disabled,
div.dt-container .dt-paging .dt-paging-button.disabled:hover,
div.dt-container .dt-paging .dt-paging-button.disabled:active {
    opacity: 0.45;
    cursor: not-allowed;
    background: var(--bsd-surface) !important;
    border-color: var(--bsd-border);
    color: var(--bsd-text-faint) !important;
}

div.dt-container .dt-paging .dt-paging-button:active {
    outline: none;
    box-shadow: none;
    background: var(--bsd-primary-hover) !important;
}

div.dt-container .dt-paging .ellipsis {
    color: var(--bsd-text-faint);
    padding: 0 4px;
}


/* ── 5. TABLE ─────────────────────────────────────────────── */
table.dataTable {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--bsd-text-sm);
    color: var(--bsd-text-2);
}

table.dataTable > thead > tr > th,
table.dataTable > thead > tr > td {
    padding: 11px 16px;
    background: var(--bsd-surface-2);
    border-bottom: 1px solid var(--bsd-border);
    font-family: var(--bsd-font-display);
    font-size: var(--bsd-text-xs);
    font-weight: 700;
    color: var(--bsd-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

table.dataTable > tfoot > tr > th,
table.dataTable > tfoot > tr > td {
    padding: 10px 16px;
    background: var(--bsd-surface-2);
    border-top: 1px solid var(--bsd-border);
    font-size: var(--bsd-text-xs);
    color: var(--bsd-text-muted);
}

table.dataTable > tbody > tr > th,
table.dataTable > tbody > tr > td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--bsd-border);
    vertical-align: middle;
}

table.dataTable > tbody > tr:last-child > * {
    border-bottom: none;
}

table.dataTable.row-border > tbody > tr > *,
table.dataTable.display > tbody > tr > * {
    border-top: none;
}

/* Selected row: solid primary fill with white text, same recipe
   DataTables uses natively — just driven by the --dt-row-* vars
   set above, so no override needed here beyond confirming it
   reads as a BSD-blue highlight rather than the library default. */
table.dataTable > tbody > tr.selected > * {
    font-weight: 500;
}

/* Sort indicator arrows */
table.dataTable thead > tr > th .dt-column-order:before,
table.dataTable thead > tr > th .dt-column-order:after {
    color: var(--bsd-text-faint);
}

table.dataTable thead > tr > th.dt-ordering-asc .dt-column-order:before,
table.dataTable thead > tr > th.dt-ordering-desc .dt-column-order:after {
    color: var(--bsd-primary);
    opacity: 1;
}

table.dataTable thead > tr > th.dt-orderable-asc:hover,
table.dataTable thead > tr > th.dt-orderable-desc:hover {
    outline: none;
    background: var(--bsd-surface-3);
}

/* Child-row expand/collapse control */
table.dataTable tbody td.dt-control {
    cursor: pointer;
}

table.dataTable tbody td.dt-control:before {
    border-left-color: var(--bsd-text-faint);
}

table.dataTable tbody tr.dt-hasChild td.dt-control:before {
    border-top-color: var(--bsd-primary);
}

/* Empty-state cell (no matching records) */
table.dataTable tbody td.dt-empty {
    padding: 48px 16px;
    color: var(--bsd-text-muted);
    font-size: var(--bsd-text-sm);
    text-align: center;
}


/* ── 6. SCROLLING TABLES (scrollX / scrollY) ─────────────── */
div.dt-scroll-head {
    background: var(--bsd-surface-2);
}

div.dt-scroll-body {
    scrollbar-width: thin;
    scrollbar-color: var(--bsd-border-2) transparent;
}

div.dt-scroll-body::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

div.dt-scroll-body::-webkit-scrollbar-thumb {
    background: var(--bsd-border-2);
    border-radius: var(--bsd-r-full);
}

div.dt-container.dt-empty-footer tbody > tr:last-child > * {
    border-bottom: none;
}

div.dt-container.dt-empty-footer .dt-scroll-body {
    border-bottom: 1px solid var(--bsd-border);
}


/* ── 7. PROCESSING INDICATOR ──────────────────────────────── */
div.dt-processing {
    background: var(--bsd-surface);
    color: var(--bsd-text-muted);
    font-size: var(--bsd-text-sm);
}

div.dt-processing > div:last-child > div {
    background: var(--bsd-primary) !important;
}


/* ── 8. COMPACT / NOWRAP MODIFIERS ────────────────────────── */
table.dataTable.compact > thead > tr > th,
table.dataTable.compact > thead > tr > td,
table.dataTable.compact > tbody > tr > th,
table.dataTable.compact > tbody > tr > td {
    padding: 7px 10px;
}


/* ── 9. RESPONSIVE ────────────────────────────────────────── */
@media screen and (max-width: 767px) {
    div.dt-container div.dt-layout-row:not(.dt-layout-table) {
        padding: 12px var(--bsd-gap);
    }
    div.dt-container .dt-search input.dt-input {
        min-width: 0;
        width: 100%;
    }
}


/* ── 10. DARK THEME ───────────────────────────────────────── */
[data-bsd-theme="dark"] div.dt-container,
html.dark div.dt-container {
    background: var(--bsd-surface);
    border-color: var(--bsd-border);
}

[data-bsd-theme="dark"] table.dataTable > thead > tr > th,
[data-bsd-theme="dark"] table.dataTable > tfoot > tr > th,
html.dark table.dataTable > thead > tr > th,
html.dark table.dataTable > tfoot > tr > th {
    background: var(--bsd-surface-2);
}
