/* ============================================================================
   TABLES
   Clean rows, compact head, hover affordance, and DataTables theming.
   ============================================================================ */

.table,
table.dataTable {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 0;
    color: var(--text-dark);
    background: transparent;
}

/* ── Head ──────────────────────────────────────────────────────────────────
   Quiet, compact column labels — uppercase micro-caps on a faint fill with a
   single hairline divider. No heavy banding; the data is the focus. */
.table thead th,
table.dataTable thead th,
table thead th {
    background: var(--surface-2) !important;
    color: var(--text-subtle) !important;
    font-weight: var(--font-weight-semibold) !important;
    font-size: 0.7rem !important;
    text-transform: uppercase !important;
    letter-spacing: 0.06em !important;
    padding: 0.55rem var(--spacing-md) !important;
    border-bottom: 1px solid var(--border-color) !important;
    border-top: 0 !important;
    text-align: left !important;
    white-space: nowrap;
    vertical-align: middle;
}
.table thead th.text-end,
table thead th.text-end { text-align: right !important; }
.table thead th.text-center,
table thead th.text-center { text-align: center !important; }

/* ── Body ──────────────────────────────────────────────────────────────────
   Compact 13px rows with a comfortable 40px rhythm and hairline dividers. */
.table td,
table.dataTable td,
table td {
    padding: 0.6rem var(--spacing-md) !important;
    border-top: 1px solid var(--border-light);
    vertical-align: middle;
    font-size: var(--font-size-sm);
    line-height: 1.4;
    color: var(--text-default);
}

.table tbody tr:first-child td,
table.dataTable tbody tr:first-child td { border-top: 0; }

.table tbody tr,
table.dataTable tbody tr {
    transition: background-color 0.15s var(--ease-out), box-shadow 0.15s var(--ease-out);
}

.table-hover tbody tr:hover,
table.dataTable.table-hover tbody tr:hover,
table.table-hover tbody tr:hover {
    background: var(--surface-2);
    cursor: default;
}

/* Row "selected" / focus accent — soft indigo with a left marker */
.table tbody tr.is-selected td {
    background: var(--secondary-soft);
    box-shadow: inset 3px 0 0 var(--secondary-color);
}

/* Edge breathing room so the first/last columns clear the card border. */
.table th:first-child,
.table td:first-child,
table.dataTable th:first-child,
table.dataTable td:first-child { padding-left: var(--spacing-lg) !important; }

.table th:last-child,
.table td:last-child,
table.dataTable th:last-child,
table.dataTable td:last-child { padding-right: var(--spacing-lg) !important; }

/* Right-aligned cells are almost always figures — line them up with tabular,
   monospaced-friendly digits. */
.table td.text-end,
.table th.text-end { font-variant-numeric: tabular-nums; }

/* Make code in cells look intentional */
.table td code { font-size: 0.85em; }

/* Density variants */
.table-comfortable td { padding: 0.85rem var(--spacing-md) !important; }
.table-compact td,
.table-compact th { padding: 0.4rem 0.75rem !important; }

/* ── Standalone table surface ───────────────────────────────────────────────
   A self-contained table panel — its own surface, border, radius and shadow —
   so a list can stand on its own WITHOUT an <x-card> wrapper. Use either:
     <x-data-table surface>…</x-data-table>
   or, for a hand-written table:
     <div class="table-panel"><table class="table">…</table></div>
   The rounded corners are clipped via overflow:hidden, so the header and the
   first/last rows follow the panel's radius cleanly. */
.table-panel {
    background: var(--surface-1);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-soft);
    overflow: hidden;
}
.table-panel > .table-responsive,
.table-panel > [class^="table-responsive"] { border-radius: inherit; }
.table-panel .table { margin: 0; }

/* Optional header — title / subtitle on the left, actions on the right. Mirrors
   the <x-card> header so a titled list reads the same without the card. */
.table-panel__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-md);
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-light);
}
.table-panel__heading { min-width: 0; }
.table-panel__title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--text-strong);
    margin: 0;
    line-height: var(--line-height-snug);
    letter-spacing: var(--letter-spacing-tight);
}
.table-panel__subtitle {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    margin: 2px 0 0;
}
.table-panel__actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
    flex-shrink: 0;
}

/* Optional search bar above the rows + pagination below, padded to the panel. */
.table-panel__bar {
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-light);
    margin-bottom: 0 !important;
}
.table-panel__foot {
    display: flex;
    justify-content: flex-end;
    padding: var(--spacing-sm) var(--spacing-lg);
    border-top: 1px solid var(--border-light);
    margin-top: 0 !important;
}
.table-panel__foot .pagination { margin: 0; }

/* ── Row-action dropdowns must escape the table's clipping containers ────────
   `.table-responsive` (overflow-x:auto also clips the y-axis) and `.table-panel`
   (overflow:hidden for rounded corners) would otherwise cut off an open
   row-actions menu. While a dropdown is actually open, relax the clipping so
   the menu shows in full. Scoped to the open state via :has(), so horizontal
   scrolling and corner-clipping are unaffected the rest of the time. */
[class*="table-responsive"]:has(.dropdown-menu.show),
.table-panel:has(.dropdown-menu.show) {
    overflow: visible;
}

/* ── Empty row ─────────────────────────────────────────────────────────── */
.table-empty td {
    padding: var(--spacing-2xl) var(--spacing-md) !important;
    text-align: center;
    color: var(--text-muted);
}

/* ── Action dropdown (shared with row actions) ─────────────────────────── */
.dropstart {
    display: inline-flex;
    align-items: center;
}

.dropdown-menu {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-medium);
    padding: 0.35rem 0;
    min-width: 11rem;
    font-size: var(--font-size-md);
    margin-top: 0.25rem !important;
    background: var(--surface-1);
}

.dropdown-divider {
    margin: 0.35rem 0;
    border-top: 1px solid var(--border-light);
}

.dropdown-item {
    padding: 0.45rem 0.85rem;
    font-size: var(--font-size-md);
    color: var(--text-default);
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}
.dropdown-item:hover,
.dropdown-item:focus {
    background: var(--surface-2);
    color: var(--primary-color);
}
.dropdown-item:active {
    background: var(--primary-soft);
    color: var(--primary-color);
}
.dropdown-item i { width: 1rem; color: var(--text-muted); }
.dropdown-item:hover i { color: var(--primary-color); }

.dropdown-item.text-danger:hover,
.dropdown-item.text-danger:focus {
    background: var(--danger-soft);
    color: var(--danger-color);
}
.dropdown-item.text-danger:hover i { color: var(--danger-color); }

/* Delete button used inside row dropdowns */
.btn-del {
    cursor: pointer;
    padding: 0.45rem 0.85rem;
    width: 100%;
    text-align: left;
    justify-content: flex-start;
    background: transparent;
    border: 0;
    color: var(--danger-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: var(--font-size-md);
}
.btn-del:hover {
    background: var(--danger-soft);
    color: var(--danger-color);
}

/* ── Zebra (opt-in) ────────────────────────────────────────────────────── */
.table-striped tbody tr:nth-child(even) td,
table.dataTable.table-striped tbody tr:nth-child(even) td {
    background: var(--surface-2);
}

/* ── Sticky head (use inside a scrolling card) ─────────────────────────── */
.table-sticky thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--surface-2) !important;
}

/* ── Responsive card-style fallback ────────────────────────────────────── */
/* Add .table-responsive-cards on the table to render rows as stacked cards
   below the md breakpoint. Requires each <td data-label="Column"> to expose
   the column label for the stacked layout. */
@media (max-width: 768px) {
    .table-responsive-cards thead { display: none; }
    .table-responsive-cards,
    .table-responsive-cards tbody,
    .table-responsive-cards tr,
    .table-responsive-cards td { display: block; width: 100%; }

    .table-responsive-cards tr {
        background: var(--surface-1);
        border: 1px solid var(--border-color);
        border-radius: var(--border-radius);
        margin-bottom: var(--spacing-sm);
        padding: var(--spacing-xs) 0;
    }

    .table-responsive-cards td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: var(--spacing-md);
        padding: 0.55rem var(--spacing-md) !important;
        border: 0 !important;
        font-size: var(--font-size-sm);
    }
    .table-responsive-cards td::before {
        content: attr(data-label);
        font-size: var(--font-size-xs);
        text-transform: uppercase;
        letter-spacing: var(--letter-spacing-wide);
        color: var(--text-muted);
        font-weight: var(--font-weight-semibold);
        flex-shrink: 0;
    }
}

/* ── DataTables wrapper polish ─────────────────────────────────────────── */
.dataTables_wrapper {
    padding: var(--spacing-md) var(--spacing-lg);
}
.card-table .dataTables_wrapper,
.card .dataTables_wrapper { padding: var(--spacing-md) var(--spacing-lg); }

.dataTables_wrapper table.dataTable thead th { border-bottom: 1px solid var(--border-color); }
.dataTables_wrapper table.dataTable.no-footer { border-bottom: 0; }

.dataTables_wrapper .dt-search,
.dataTables_wrapper .dataTables_filter {
    margin-bottom: var(--spacing-md);
}
.dataTables_wrapper .dt-search input,
.dataTables_wrapper .dataTables_filter input {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 0.4rem 0.7rem;
    font-size: var(--font-size-md);
    width: 280px;
    background: var(--surface-1);
    transition: var(--transition-fast);
}
.dataTables_wrapper .dt-search input:focus,
.dataTables_wrapper .dataTables_filter input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: var(--focus-ring);
}

.dataTables_wrapper .dt-length select,
.dataTables_wrapper .dataTables_length select {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 0.3rem 0.5rem;
    font-size: var(--font-size-sm);
}

/* Pagination */
.dataTables_wrapper .dt-paging,
.dataTables_wrapper .dataTables_paginate {
    padding-top: var(--spacing-md);
}
.dataTables_wrapper .dt-paging .dt-paging-button,
.dataTables_wrapper .dataTables_paginate .paginate_button {
    border: 1px solid transparent !important;
    background: transparent !important;
    color: var(--text-muted) !important;
    padding: 0.35rem 0.65rem !important;
    margin: 0 0.1rem !important;
    border-radius: var(--border-radius-xs) !important;
    font-size: var(--font-size-sm) !important;
    transition: var(--transition-fast);
    min-width: 2rem;
}
.dataTables_wrapper .dt-paging .dt-paging-button:hover,
.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background: var(--surface-2) !important;
    color: var(--primary-color) !important;
    border-color: var(--border-color) !important;
}
.dataTables_wrapper .dt-paging .dt-paging-button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
    color: #fff !important;
}
.dataTables_wrapper .dt-paging .dt-paging-button.disabled,
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled {
    color: var(--text-subtle) !important;
    cursor: not-allowed;
}

.dataTables_wrapper .dt-info,
.dataTables_wrapper .dataTables_info {
    color: var(--text-muted);
    font-size: var(--font-size-sm);
    padding-top: var(--spacing-md);
}

/* DataTables export button toolbar */
.dataTables_wrapper .dt-buttons .btn,
.dataTables_wrapper .dt-buttons .dt-button {
    background: var(--surface-1);
    border: 1px solid var(--border-color);
    color: var(--text-default);
    border-radius: var(--border-radius-sm);
    padding: 0.4rem 0.75rem;
    font-size: var(--font-size-sm);
    margin-right: 0.25rem;
}
.dataTables_wrapper .dt-buttons .btn:hover,
.dataTables_wrapper .dt-buttons .dt-button:hover {
    background: var(--surface-2);
    border-color: var(--border-strong);
    color: var(--text-strong);
}
