/**
 * Tables Module CSS
 * Material Design 3 table styles with responsive support
 */

/* Base Table */
.md-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--md-sys-color-surface-container);
    border-radius: var(--md-sys-shape-corner-medium);
    overflow: hidden;
    box-shadow: var(--elevation-1);
}

/* Table Header */
.md-table thead {
    background: var(--md-sys-color-surface-container-high);
}

.md-table th {
    padding: var(--spacing-md);
    text-align: left;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    white-space: nowrap;
}

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

.md-table th.sortable:hover {
    background: var(--hover-overlay);
}

.md-table th.sorted-asc::after,
.md-table th.sorted-desc::after {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: 8px;
    vertical-align: middle;
}

.md-table th.sorted-asc::after {
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 5px solid var(--md-sys-color-on-surface);
}

.md-table th.sorted-desc::after {
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid var(--md-sys-color-on-surface);
}

/* Table Body */
.md-table tbody tr {
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    transition: background-color var(--transition-fast);
}

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

.md-table tbody tr:hover {
    background: var(--hover-overlay);
}

.md-table tbody tr.selected {
    background: var(--active-tint);
}

.md-table td {
    padding: var(--spacing-md);
    color: var(--md-sys-color-on-surface);
    vertical-align: middle;
}

/* Cell Alignments */
.md-table .text-center {
    text-align: center;
}

.md-table .text-right {
    text-align: right;
}

/* Cell Types */
.md-table .cell-numeric {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.md-table .cell-actions {
    text-align: right;
    white-space: nowrap;
}

.md-table .cell-actions md-icon-button {
    --md-icon-button-icon-size: 20px;
}

.md-table .cell-status {
    text-align: center;
}

/* Status Badges in Tables */
.md-table .status-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: 4px 12px;
    border-radius: var(--md-sys-shape-corner-extra-large);
    font-size: 12px;
    font-weight: 500;
}

.md-table .status-badge.success {
    background: var(--md-sys-color-success-container);
    color: var(--md-sys-color-success);
}

.md-table .status-badge.warning {
    background: var(--md-sys-color-warning-container);
    color: var(--md-sys-color-warning);
}

.md-table .status-badge.error {
    background: var(--md-sys-color-error-container);
    color: var(--md-sys-color-error);
}

.md-table .status-badge.info {
    background: var(--md-sys-color-info-container);
    color: var(--md-sys-color-info);
}

.md-table .status-badge.neutral {
    background: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
}

/* Clickable Rows */
.md-table tbody tr.clickable {
    cursor: pointer;
}

.md-table tbody tr.clickable:hover {
    background: var(--active-tint);
}

/* Compact Table */
.md-table.compact th,
.md-table.compact td {
    padding: var(--spacing-sm) var(--spacing-md);
}

/* Striped Table */
.md-table.striped tbody tr:nth-child(odd) {
    background: var(--md-sys-color-surface-container-low);
}

.md-table.striped tbody tr:nth-child(even) {
    background: var(--md-sys-color-surface-container);
}

/* Borderless Table */
.md-table.borderless {
    box-shadow: none;
}

.md-table.borderless th,
.md-table.borderless td {
    border: none;
}

/* Table Container (for horizontal scroll) */
.table-container {
    width: 100%;
    overflow-x: auto;
    border-radius: var(--md-sys-shape-corner-medium);
    box-shadow: var(--elevation-1);
}

.table-container .md-table {
    box-shadow: none;
    border-radius: 0;
}

/* Table Empty State */
.table-empty {
    text-align: center;
    padding: var(--spacing-xl);
    color: var(--md-sys-color-on-surface-variant);
}

.table-empty md-icon {
    font-size: 48px;
    margin-bottom: var(--spacing-md);
    opacity: 0.5;
}

/* Table Loading State */
.table-loading {
    position: relative;
}

.table-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--md-sys-color-surface-container);
    opacity: 0.7;
}

/* Table Pagination */
.table-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md);
    background: var(--md-sys-color-surface-container);
    border-top: 1px solid var(--md-sys-color-outline-variant);
}

.table-pagination-info {
    color: var(--md-sys-color-on-surface-variant);
    font-size: 14px;
}

.table-pagination-controls {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

/* Responsive Table */
@media (max-width: 768px) {
    .md-table {
        display: block;
    }
    
    .md-table thead {
        display: none;
    }
    
    .md-table tbody {
        display: block;
    }
    
    .md-table tbody tr {
        display: block;
        padding: var(--spacing-md);
        margin-bottom: var(--spacing-sm);
        border-radius: var(--md-sys-shape-corner-small);
        border: 1px solid var(--md-sys-color-outline-variant);
    }
    
    .md-table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: var(--spacing-sm) 0;
        border: none;
        border-bottom: 1px solid var(--md-sys-color-outline-variant);
    }
    
    .md-table tbody td:last-child {
        border-bottom: none;
    }
    
    .md-table tbody td::before {
        content: attr(data-label);
        font-weight: 500;
        color: var(--md-sys-color-on-surface-variant);
        margin-right: var(--spacing-md);
    }
    
    .md-table .cell-actions {
        justify-content: flex-end;
    }
}

/* Data Grid (alternative layout) */
.data-grid {
    display: grid;
    gap: var(--spacing-md);
}

.data-grid-header {
    display: grid;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    background: var(--md-sys-color-surface-container-high);
    border-radius: var(--md-sys-shape-corner-small);
    font-weight: 500;
}

.data-grid-row {
    display: grid;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    background: var(--md-sys-color-surface-container);
    border-radius: var(--md-sys-shape-corner-small);
    transition: background-color var(--transition-fast);
}

.data-grid-row:hover {
    background: var(--hover-overlay);
}
