/* ═══════════════════════════════════════════════════════════════════
   TABLES — Complete Data Table Styles
   ═══════════════════════════════════════════════════════════════════
   Purpose: Consistent table styling including base tables,
   responsive wrappers, and mobile card view.
   No pure white (#FFFFFF), no pure black (#000000).
   ═══════════════════════════════════════════════════════════════════ */

/* ═══════════════════════════════════════════════════════════════════
   TABLE WRAPPER — For horizontal scroll
   ═══════════════════════════════════════════════════════════════════ */

.table-wrapper {
    overflow-x: auto;
    border-radius: var(--r-md, 10px);
    width: 100%;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

.table-wrapper .table-scroll-indicator {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 32px;
    background: linear-gradient(90deg, transparent, var(--bg-card, #fcfaf8));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

[data-theme="dark"] .table-wrapper .table-scroll-indicator {
    background: linear-gradient(90deg, transparent, rgba(26, 20, 16, 0.85));
}

.table-wrapper.has-scroll .table-scroll-indicator {
    opacity: 1;
}

/* ═══════════════════════════════════════════════════════════════════
   DATA TABLE
   ═══════════════════════════════════════════════════════════════════ */

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    border-radius: var(--r-md, 10px);
    overflow: hidden;
}

/* ── Table Header ─────────────────────────────────────────────────── */

.data-table thead tr {
    background: var(--bg-tertiary, #f0ebe6);
}

[data-theme="dark"] .data-table thead tr {
    background: rgba(240, 235, 230, 0.04);
}

.data-table th {
    padding: var(--sm, 8px) var(--md, 16px);
    text-align: left;
    font-weight: 700;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary, #6b5f56);
    border-bottom: 1px solid var(--border-light, #e8e0d8);
    white-space: nowrap;
    position: relative;
}

[data-theme="dark"] .data-table th {
    color: var(--text-secondary, #b8a89e);
    border-bottom-color: rgba(240, 235, 230, 0.06);
}

/* ── Table Header Sortable ────────────────────────────────────────── */

.data-table th.sortable {
    cursor: pointer;
    user-select: none;
    padding-right: 28px;
}

.data-table th.sortable::after {
    content: '↕';
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    opacity: 0.3;
    transition: opacity 0.2s ease;
}

.data-table th.sortable:hover::after {
    opacity: 0.7;
}

.data-table th.sortable.sorted-asc::after {
    content: '↑';
    opacity: 1;
}

.data-table th.sortable.sorted-desc::after {
    content: '↓';
    opacity: 1;
}

/* ── Table Body ───────────────────────────────────────────────────── */

.data-table td {
    padding: var(--sm, 8px) var(--md, 16px);
    border-bottom: 1px solid var(--border-light, #e8e0d8);
    vertical-align: middle;
    color: var(--text-body, #2c241e);
    transition: background 0.15s ease;
}

[data-theme="dark"] .data-table td {
    border-bottom-color: rgba(240, 235, 230, 0.06);
    color: var(--text-body, #d4ccc6);
}

/* ── Table Row Hover ──────────────────────────────────────────────── */

.data-table tbody tr:hover {
    background: var(--bg-hover, #f5f0eb);
}

[data-theme="dark"] .data-table tbody tr:hover {
    background: rgba(240, 235, 230, 0.04);
}

/* ── Table Row Alt (Striped) ─────────────────────────────────────── */

.data-table tbody tr.alt-row,
.data-table .alt-row {
    background: var(--bg-tertiary, #f0ebe6);
}

[data-theme="dark"] .data-table tbody tr.alt-row,
[data-theme="dark"] .data-table .alt-row {
    background: rgba(240, 235, 230, 0.02);
}

/* ── Table Row Last ───────────────────────────────────────────────── */

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

/* ── Table Footer ─────────────────────────────────────────────────── */

.data-table tfoot {
    background: var(--bg-tertiary, #f0ebe6);
    font-weight: 600;
}

[data-theme="dark"] .data-table tfoot {
    background: rgba(240, 235, 230, 0.04);
}

.data-table tfoot td {
    border-top: 2px solid var(--border-medium, #d4c8be);
    color: var(--text-dark, #1a1410);
}

[data-theme="dark"] .data-table tfoot td {
    border-top-color: rgba(240, 235, 230, 0.10);
    color: var(--text-dark, #f0ebe6);
}

/* ═══════════════════════════════════════════════════════════════════
   TABLE VARIANTS
   ═══════════════════════════════════════════════════════════════════ */

/* ── Compact Table ───────────────────────────────────────────────── */

.data-table-compact th,
.data-table-compact td {
    padding: var(--xs, 4px) var(--sm, 8px);
    font-size: 0.78rem;
}

/* ── Dense Table ──────────────────────────────────────────────────── */

.data-table-dense th,
.data-table-dense td {
    padding: 2px 6px;
    font-size: 0.72rem;
}

/* ── Bordered Table ───────────────────────────────────────────────── */

.data-table-bordered th,
.data-table-bordered td {
    border: 1px solid var(--border-light, #e8e0d8);
}

[data-theme="dark"] .data-table-bordered th,
[data-theme="dark"] .data-table-bordered td {
    border-color: rgba(240, 235, 230, 0.06);
}

/* ── Hoverable (Full row click) ──────────────────────────────────── */

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

/* ── Responsive Table (Stack on mobile) ──────────────────────────── */

.data-table-stack {
    width: 100%;
}

/* ═══════════════════════════════════════════════════════════════════
   TABLE ACTIONS
   ═══════════════════════════════════════════════════════════════════ */

.table-actions {
    display: flex;
    gap: var(--xs, 4px);
    flex-wrap: wrap;
    align-items: center;
}

.table-actions .btn {
    font-size: 0.75rem;
    padding: 3px 10px;
    min-height: 28px;
}

.table-actions .btn-icon {
    width: 28px;
    height: 28px;
    padding: 4px;
    font-size: 0.75rem;
}

/* ─── Action Bar ──────────────────────────────────────────────────── */

.table-action-bar {
    display: flex;
    align-items: center;
    gap: var(--sm, 8px);
    flex-wrap: wrap;
    margin-bottom: var(--sm, 8px);
    padding: var(--sm, 8px);
    background: var(--bg-tertiary, #f0ebe6);
    border-radius: var(--r-sm, 6px);
}

[data-theme="dark"] .table-action-bar {
    background: rgba(240, 235, 230, 0.04);
}

.table-action-bar .count {
    font-size: 0.78rem;
    color: var(--text-muted, #a8988e);
    margin-left: auto;
}

[data-theme="dark"] .table-action-bar .count {
    color: var(--text-muted, #6b5f56);
}

/* ═══════════════════════════════════════════════════════════════════
   STACKED TABLE — Mobile Card View
   ═══════════════════════════════════════════════════════════════════ */

.table-stack-mobile {
    display: block;
    width: 100%;
}

.table-stack-mobile thead {
    display: none;
}

.table-stack-mobile tbody,
.table-stack-mobile tr,
.table-stack-mobile td {
    display: block;
    width: 100%;
}

.table-stack-mobile tr {
    margin-bottom: var(--md, 16px);
    border: 1px solid var(--border-light, #e8e0d8);
    border-radius: var(--r-md, 10px);
    background: var(--bg-card, #fcfaf8);
    padding: var(--sm, 8px);
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(26, 20, 16, 0.05));
}

[data-theme="dark"] .table-stack-mobile tr {
    border-color: rgba(240, 235, 230, 0.06);
    background: rgba(26, 20, 16, 0.85);
}

.table-stack-mobile td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--sm, 8px) var(--md, 16px);
    border-bottom: 1px solid var(--border-light, #e8e0d8);
    text-align: right;
    font-size: 0.85rem;
}

[data-theme="dark"] .table-stack-mobile td {
    border-bottom-color: rgba(240, 235, 230, 0.06);
}

.table-stack-mobile td:last-child {
    border-bottom: none;
}

.table-stack-mobile td::before {
    content: attr(data-label);
    font-weight: 600;
    text-align: left;
    margin-right: var(--md, 16px);
    color: var(--text-muted, #a8988e);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

[data-theme="dark"] .table-stack-mobile td::before {
    color: var(--text-muted, #6b5f56);
}

/* ── Stacked Table with Actions ──────────────────────────────────── */

.table-stack-mobile .table-actions {
    justify-content: flex-end;
}

.table-stack-mobile .table-actions .btn {
    min-height: 32px;
}

/* ═══════════════════════════════════════════════════════════════════
   TABLE STATUS INDICATORS
   ═══════════════════════════════════════════════════════════════════ */

.table-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    border-radius: var(--r-full, 9999px);
    font-size: 0.7rem;
    font-weight: 600;
}

.table-status-success {
    background: var(--success-bg, #dce8e0);
    color: #2a5a3a;
}

[data-theme="dark"] .table-status-success {
    background: rgba(58, 122, 90, 0.15);
    color: #86efac;
}

.table-status-warning {
    background: var(--warning-bg, #f0e8d0);
    color: #7a5a1a;
}

[data-theme="dark"] .table-status-warning {
    background: rgba(184, 152, 58, 0.15);
    color: #fcd34d;
}

.table-status-danger {
    background: var(--danger-bg, #f0e0dc);
    color: #8a3a2a;
}

[data-theme="dark"] .table-status-danger {
    background: rgba(196, 90, 74, 0.15);
    color: #fca5a5;
}

.table-status-info {
    background: var(--info-bg, #dce8ec);
    color: #1a4a5a;
}

[data-theme="dark"] .table-status-info {
    background: rgba(74, 122, 138, 0.15);
    color: #93c5fd;
}

.table-status-neutral {
    background: var(--bg-tertiary, #f0ebe6);
    color: var(--text-soft, #6b5f56);
}

[data-theme="dark"] .table-status-neutral {
    background: rgba(240, 235, 230, 0.06);
    color: var(--text-soft, #9a8e86);
}

/* ═══════════════════════════════════════════════════════════════════
   TABLE SELECTION
   ═══════════════════════════════════════════════════════════════════ */

.data-table .row-select {
    width: 36px;
    text-align: center;
}

.data-table .row-select input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--role-primary, #2d1f3a);
    cursor: pointer;
}

[data-theme="dark"] .data-table .row-select input[type="checkbox"] {
    accent-color: var(--role-primary, #4d2f4a);
}

.data-table tbody tr.selected {
    background: var(--role-light, rgba(45, 31, 58, 0.06));
}

[data-theme="dark"] .data-table tbody tr.selected {
    background: rgba(77, 47, 74, 0.10);
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════════ */

@media (max-width: 1024px) {
    .data-table {
        font-size: 0.82rem;
    }

    .data-table th,
    .data-table td {
        padding: var(--xs, 4px) var(--sm, 8px);
    }
}

@media (max-width: 768px) {
    .data-table {
        font-size: 0.78rem;
        min-width: 500px;
    }

    .data-table th,
    .data-table td {
        padding: 6px 10px;
        white-space: nowrap;
    }

    .table-actions .btn {
        font-size: 0.7rem;
        padding: 2px 8px;
        min-height: 24px;
    }

    .table-actions .btn-icon {
        width: 24px;
        height: 24px;
        padding: 3px;
        font-size: 0.7rem;
    }

    /* ── Auto-stack on small screens ──────────────────────────────── */

    .data-table-auto-stack {
        min-width: unset;
    }

    .data-table-auto-stack thead {
        display: none;
    }

    .data-table-auto-stack tbody,
    .data-table-auto-stack tr,
    .data-table-auto-stack td {
        display: block;
        width: 100%;
    }

    .data-table-auto-stack tr {
        margin-bottom: var(--md, 16px);
        border: 1px solid var(--border-light, #e8e0d8);
        border-radius: var(--r-md, 10px);
        background: var(--bg-card, #fcfaf8);
        padding: var(--sm, 8px);
        box-shadow: var(--shadow-sm, 0 1px 2px rgba(26, 20, 16, 0.05));
    }

    [data-theme="dark"] .data-table-auto-stack tr {
        border-color: rgba(240, 235, 230, 0.06);
        background: rgba(26, 20, 16, 0.85);
    }

    .data-table-auto-stack td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: var(--sm, 8px) var(--md, 16px);
        border-bottom: 1px solid var(--border-light, #e8e0d8);
        text-align: right;
        font-size: 0.85rem;
        white-space: normal;
    }

    [data-theme="dark"] .data-table-auto-stack td {
        border-bottom-color: rgba(240, 235, 230, 0.06);
    }

    .data-table-auto-stack td:last-child {
        border-bottom: none;
    }

    .data-table-auto-stack td::before {
        content: attr(data-label);
        font-weight: 600;
        text-align: left;
        margin-right: var(--md, 16px);
        color: var(--text-muted, #a8988e);
        font-size: 0.7rem;
        text-transform: uppercase;
        letter-spacing: 0.3px;
    }

    [data-theme="dark"] .data-table-auto-stack td::before {
        color: var(--text-muted, #6b5f56);
    }
}

@media (max-width: 480px) {
    .data-table {
        font-size: 0.72rem;
        min-width: 600px;
    }

    .data-table th,
    .data-table td {
        padding: 4px 6px;
    }

    .table-action-bar {
        flex-direction: column;
        align-items: stretch;
        gap: var(--xs, 4px);
    }

    .table-action-bar .count {
        margin-left: 0;
        text-align: center;
    }

    .table-stack-mobile td {
        font-size: 0.78rem;
        padding: 4px 10px;
    }

    .table-stack-mobile td::before {
        font-size: 0.65rem;
    }

    .data-table-auto-stack td {
        font-size: 0.78rem;
        padding: 4px 10px;
    }

    .data-table-auto-stack td::before {
        font-size: 0.65rem;
    }
}