/* ── Shared data table (revamp I6, I5; DESIGN.md §4) ────────────────────────
   Markup from static/lib/table.js (class "dt"). Version D: the table is the
   one primary element on a list page; compact 40px rows by default and
   56px with Comfortable (html[data-table-density="comfortable"]); hairline
   row separators, no zebra and no vertical gridlines; sticky header inside
   the scroll box and a sticky identity column; text left, numbers right in
   tabular figures; a muted "None" for a missing value. */

.dt-wrap {
    position: relative;
    overflow: auto;
    max-height: min(70vh, 720px);
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--border);
}
.dt-wrap.is-flat { max-height: none; }

table.dt {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--fs-13);
}
.dt thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    height: 34px;
    padding: 0 10px;
    text-align: left;
    vertical-align: middle;
    font-family: var(--sans);
    font-size: var(--fs-label);
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
    color: var(--text-3);
    white-space: nowrap;
    cursor: default;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.dt thead th:first-child { padding-left: 14px; }
.dt thead th:last-child { padding-right: 14px; }
.dt thead th:hover { color: var(--text-3); }

/* Sortable headers are buttons (aria-sort sits on the <th>). */
.dt-sort {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 100%;
    margin: 0 -4px;
    padding: 2px 4px;
    border: 0;
    border-radius: var(--radius-xs);
    background: transparent;
    font: inherit;
    color: inherit;
    white-space: nowrap;
    cursor: pointer;
}
.dt-sort:hover { color: var(--text); }
.dt-sort svg.i { opacity: 0; color: var(--text-3); }
.dt-sort:hover svg.i, .dt-sort:focus-visible svg.i { opacity: 0.7; }
.dt-sort.is-asc, .dt-sort.is-desc { color: var(--text); }
.dt-sort.is-asc svg.i, .dt-sort.is-desc svg.i { opacity: 1; color: var(--accent-text); }
.dt-sort:focus-visible { outline-offset: 0; }
.dt th.dt-num .dt-sort { flex-direction: row-reverse; }

.dt tbody td {
    height: var(--row-h);
    padding: 0 10px;
    font-family: var(--sans);
    font-size: var(--fs-13);
    font-weight: 400;
    color: var(--text-2);
    white-space: nowrap;
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-sub);
    background: var(--surface);
}
.dt tbody td:first-child { padding-left: 14px; }
.dt tbody td:last-child { padding-right: 14px; }
.dt tbody tr:last-child td { border-bottom: 0; }
.dt tbody tr { background: transparent; border: 0; }
.dt tbody tr:nth-child(even) { background: transparent; }
.dt tbody tr[data-row-idx], .dt tbody tr.is-clickable { cursor: pointer; }
.dt tbody tr:hover td { background: var(--hover); }
.dt tbody tr:hover { background: transparent !important; }
.dt tbody tr.is-selected td { background: var(--accent-dim); }
.dt tbody tr.is-selected td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.dt tbody tr:focus-visible { outline-offset: -2px; }

html[data-table-density="comfortable"] .dt tbody td { height: var(--row-h-comfortable); font-size: var(--fs-14); }
html[data-table-density="comfortable"] .dt thead th { height: 40px; }

/* Cell kinds. */
.dt td.dt-id { font-family: var(--mono); font-weight: var(--mono-font-weight); font-size: var(--fs-12); color: var(--text); letter-spacing: -0.01em; }
.dt td.dt-mono { font-family: var(--mono); font-weight: var(--mono-font-weight); font-size: var(--fs-12); color: var(--text); }
.dt .dt-num, .dt .dt-date, .dt .dt-bar { font-variant-numeric: tabular-nums; }
.dt th.dt-num, .dt td.dt-num, .dt th.dt-action, .dt td.dt-action { text-align: right; }
.dt td.dt-action { overflow: visible; }
.dt td.dt-wrap-text { white-space: normal; line-height: 1.4; padding-top: 6px; padding-bottom: 6px; }
.dt .dt-strong { color: var(--text); font-weight: 500; }

/* Identity column: sticky when the table scrolls sideways. */
.dt .dt-ident { position: sticky; left: 0; z-index: 1; }
.dt thead th.dt-ident { z-index: 3; }
.dt-wrap.is-scrolled-x .dt .dt-ident { box-shadow: inset -1px 0 0 var(--border); }

/* DESIGN.md §4: a missing value is an explicit, muted marker. */
.none-mark { color: var(--text-3); font-style: normal; font-weight: 400; font-family: var(--sans); font-size: var(--fs-12); }

/* Empty state inside a table body. */
.dt tbody tr.dt-empty-row td { height: auto; padding: 0; white-space: normal; max-width: none; text-align: center; cursor: default; }
.dt tbody tr.dt-empty-row:hover td { background: var(--surface); }

/* Table heads above a table: title, count and actions on one row. */
.dt-head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--sp-2) var(--sp-3);
    margin: 0 0 var(--sp-2);
    min-height: 34px;
}
.dt-head .section-title { margin: 0; }
.dt-head .dt-count { color: var(--text-3); font-size: var(--fs-13); font-variant-numeric: tabular-nums; }
.dt-head .dt-desc { order: 10; flex: 1 1 100%; min-width: 0; margin: -4px 0 0; color: var(--text-3); font-size: var(--fs-13); }
.dt-head .dt-actions { display: flex; align-items: center; gap: var(--sp-2); margin-left: auto; flex-wrap: wrap; }
.dt-head .dt-actions .list-search, .dt-head .dt-actions .stock-search { width: 240px; max-width: 100%; }

/* Density toggle sits in the table head actions. */
.dt-density { align-self: center; }

@media (max-width: 640px) {
    .dt-wrap { max-height: none; }
    .dt-head .dt-actions { margin-left: 0; width: 100%; }
    .dt-head .dt-actions .list-search, .dt-head .dt-actions .stock-search { flex: 1 1 160px; width: auto; }
}

@media print {
    .dt-wrap { max-height: none !important; overflow: visible !important; box-shadow: none; }
    .dt .dt-ident, .dt thead th { position: static !important; }
}

/* A table head that only holds a list search still hidden (short lists)
   takes no room. */
.dt-head:has(> .dt-actions:only-child > [hidden]:only-child) { display: none; }
