/**
 * DH Suite — shared tables.
 *
 * Split out of components.css, which had grown to 1,073 lines
 * across eleven unrelated families. Same layer, same order: these are
 * linked in the sequence they were concatenated, because within a layer
 * later source wins.
 */

@layer components {

/* ==========================================================================
   Tables
   ========================================================================== */

/* --- Wrapper for horizontal scroll -------------------------------------- */

.table-wrapper {
    /* Wide tables stay reachable rather than being cut off — the app shell
       clips overflow-x.

       This used to be an alias pair, `.table-wrapper, .table-container`, for
       one thing under two names. Arbitrated to `.table-wrapper` on 2026-08-24:
       it is the wrapper, not a container of tables, and it
       had 43 usages against 12. */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background-color: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

/* --- Data table --------------------------------------------------------- */

.data-table {
    width: 100%;
    border-collapse: collapse;
    background-color: white;
}

.data-table th,
.data-table td {
    padding: var(--spacing-3) var(--spacing-4);
    text-align: left;
    border-bottom: 1px solid var(--color-gray-200);
}

.data-table th {
    background-color: var(--color-gray-50);
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-sm);
    color: var(--color-gray-600);
    white-space: nowrap;
}

.data-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.data-table th.sortable:hover {
    background-color: var(--color-gray-100);
}

.data-table th.sortable:focus-visible {
    outline: var(--focus-ring);
    outline-offset: calc(-1 * var(--focus-ring-offset, 2px));
}

.data-table tbody tr:hover {
    background-color: var(--color-gray-50);
}

.data-table tbody tr.clickable {
    cursor: pointer;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* --- Mobile: opt-in stacked "card" layout for data tables ---------------- */
/* Add class `stacked` to a .data-table and `data-label="Column"` to each <td>.
   Below the mobile breakpoint, each row becomes a card and each cell a
   label:value pair — far more usable than a wide horizontal scroll on phones. */
@media (max-width: 640px) {
    .data-table.stacked thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
    }
    .data-table.stacked,
    .data-table.stacked tbody,
    .data-table.stacked tr,
    .data-table.stacked td {
        display: block;
        width: 100%;
    }
    .data-table.stacked tr {
        margin-bottom: var(--spacing-3);
        border: 1px solid var(--color-gray-200);
        border-radius: var(--radius-lg);
        overflow: hidden;
    }
    .data-table.stacked td {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: var(--spacing-4);
        text-align: right;
        border-bottom: 1px solid var(--color-gray-100);
    }
    .data-table.stacked tr:last-child td:last-child,
    .data-table.stacked td:last-child {
        border-bottom: none;
    }
    .data-table.stacked td::before {
        content: attr(data-label);
        font-weight: var(--font-weight-semibold);
        color: var(--color-gray-600);
        text-align: left;
        white-space: nowrap;
        flex-shrink: 0;
    }
    /* let long single-word values wrap instead of hugging the card edge */
    .data-table.stacked td {
        min-width: 0;
        overflow-wrap: anywhere;
    }
}

/* --- Legacy .table class (Reach compatibility) -------------------------- */

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--font-size-sm);
    margin-bottom: var(--spacing-4);
}

.table thead th {
    background: var(--color-gray-50);
    color: var(--color-gray-600);
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    font-size: var(--font-size-xs);
    letter-spacing: 0.05em;
    padding: var(--spacing-3) var(--spacing-4);
    text-align: left;
    border-bottom: 2px solid var(--color-gray-200);
    white-space: nowrap;
}

.table tbody td {
    padding: var(--spacing-3) var(--spacing-4);
    border-bottom: 1px solid var(--color-gray-100);
    vertical-align: top;
    color: var(--color-gray-700);
}

.table tbody tr {
    background: white;
    transition: background-color var(--transition-fast);
}

.table tbody tr:hover {
    background: var(--color-gray-50);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

/* --- Compact density ---------------------------------------------------- */

/* Legacy .table-compact variant (Reach compatibility) */
.table-compact thead th {
    padding: var(--spacing-2) var(--spacing-3);
}

.table-compact tbody td {
    padding: var(--spacing-2) var(--spacing-3);
}

/* .data-table compact variant */
.compact-view .data-table th,
.compact-view .data-table td {
    padding: var(--spacing-2) var(--spacing-3);
    font-size: var(--font-size-sm);
}

.compact-view .data-table th {
    font-size: var(--font-size-xs);
}

.compact-view .badge {
    padding: 0.125rem 0.375rem;
    font-size: 0.6875rem;
}

.compact-view .btn-icon {
    width: 28px;
    height: 28px;
    padding: var(--spacing-1);
}

.compact-view .btn-icon svg {
    width: 14px;
    height: 14px;
}

/* --- Action buttons in table rows --------------------------------------- */

.action-buttons {
    display: flex;
    gap: var(--spacing-1);
}

.compact-view .action-buttons {
    gap: 2px;
}

/* --- Column visibility -------------------------------------------------- */

.col-hidden {
    display: none !important;
}

}
