/**
 * Table Components
 * Professional data tables with proper responsive handling
 */

/* =============================================================================
   BASE TABLE
   ============================================================================= */

.table {
    width: 100%;
    margin-bottom: var(--space-4);
    color: var(--color-text);
    vertical-align: top;
    border-color: var(--color-border);
}

.table > :not(caption) > * > * {
    padding: var(--space-3) var(--space-4);
    background-color: var(--color-surface);
    border-bottom-width: var(--border-width-1);
    box-shadow: inset 0 0 0 9999px transparent;
}

/* =============================================================================
   TABLE HEADER
   ============================================================================= */

.table > thead {
    vertical-align: bottom;
}

.table > thead > tr > th {
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
    background-color: var(--color-gray-50);
    border-bottom: var(--border-width-2) solid var(--color-border);
}

[data-theme="dark"] .table > thead > tr > th {
    background-color: var(--color-gray-200);
}

/* =============================================================================
   TABLE BODY
   ============================================================================= */

.table > tbody {
    vertical-align: inherit;
}

.table > tbody > tr > td {
    border-bottom: var(--border-width-1) solid var(--color-border);
}

/* =============================================================================
   TABLE FOOTER
   ============================================================================= */

.table > tfoot {
    vertical-align: top;
}

.table > tfoot > tr > td {
    font-weight: var(--font-weight-medium);
    border-top: var(--border-width-2) solid var(--color-border);
}

/* =============================================================================
   TABLE VARIANTS
   ============================================================================= */

/* Striped Rows */
.table-striped > tbody > tr:nth-of-type(odd) > * {
    background-color: var(--color-gray-50);
}

[data-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > * {
    background-color: var(--color-gray-200);
}

/* Hover Effect */
.table-hover > tbody > tr {
    transition: var(--transition-colors);
}

.table-hover > tbody > tr:hover > * {
    background-color: var(--color-primary-subtle);
    cursor: pointer;
}

[data-theme="dark"] .table-hover > tbody > tr:hover > * {
    background-color: var(--color-gray-300);
}

/* Bordered Table */
.table-bordered {
    border: var(--border-width-1) solid var(--color-border);
}

.table-bordered > :not(caption) > * {
    border-width: var(--border-width-1) 0;
}

.table-bordered > :not(caption) > * > * {
    border-width: 0 var(--border-width-1);
}

/* Borderless Table */
.table-borderless > :not(caption) > * > * {
    border-bottom-width: 0;
}

/* Small Table */
.table-sm > :not(caption) > * > * {
    padding: var(--space-2) var(--space-3);
}

/* =============================================================================
   TABLE ROW STATES
   ============================================================================= */

.table-active {
    background-color: var(--color-primary-subtle) !important;
}

.table-primary {
    background-color: var(--color-primary-subtle);
}

.table-success {
    background-color: var(--color-success-subtle);
}

.table-info {
    background-color: var(--color-info-subtle);
}

.table-warning {
    background-color: var(--color-warning-subtle);
}

.table-danger {
    background-color: var(--color-danger-subtle);
}

/* =============================================================================
   RESPONSIVE TABLE WRAPPER
   ============================================================================= */

.table-responsive {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
}

/* CRITICAL: Allow dropdowns to overflow */
.table-responsive.allow-dropdown {
    overflow: visible !important;
}

/* =============================================================================
   TABLE WITH DROPDOWNS (FIX FOR DROPDOWN POSITIONING)
   ============================================================================= */

.table .dropdown {
    position: relative;
}

/* Ensure dropdowns don't get cut off */
.table-container {
    position: relative;
    overflow: visible;
}

/* =============================================================================
   STICKY TABLE HEADERS
   ============================================================================= */

.table-sticky-header thead th {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    background-color: var(--color-surface);
    box-shadow: 0 2px 2px -1px var(--color-border);
}

/* =============================================================================
   TABLE ACTIONS
   ============================================================================= */

.table-actions {
    display: flex;
    gap: var(--space-2);
    align-items: center;
    justify-content: flex-end;
}

.table-actions .btn {
    padding: var(--space-1) var(--space-2);
}

/* =============================================================================
   TABLE PAGINATION
   ============================================================================= */

.table-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-4) 0;
}

.table-pagination-info {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.table-pagination-controls {
    display: flex;
    gap: var(--space-2);
}

/* =============================================================================
   TABLE SORT
   ============================================================================= */

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

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

[data-theme="dark"] .table-sortable thead th:hover {
    background-color: var(--color-gray-300);
}

.table-sortable thead th::after {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: var(--space-2);
    vertical-align: middle;
    opacity: 0.5;
}

.table-sortable thead th.sort-asc::after {
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 4px solid currentColor;
}

.table-sortable thead th.sort-desc::after {
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 4px solid currentColor;
}

/* =============================================================================
   TABLE LOADING STATE
   ============================================================================= */

.table-loading {
    position: relative;
}

.table-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

[data-theme="dark"] .table-loading::after {
    background-color: rgba(15, 23, 42, 0.8);
}

/* =============================================================================
   TABLE EMPTY STATE
   ============================================================================= */

.table-empty {
    text-align: center;
    padding: var(--space-12) var(--space-6);
    color: var(--color-text-muted);
}

.table-empty-icon {
    font-size: var(--font-size-5xl);
    margin-bottom: var(--space-4);
    opacity: 0.5;
}

.table-empty-message {
    font-size: var(--font-size-lg);
    margin-bottom: var(--space-2);
}

/* =============================================================================
   RESPONSIVE DESIGN
   ============================================================================= */

@media (max-width: 768px) {
    .table {
        font-size: var(--font-size-sm);
    }
    
    .table > :not(caption) > * > * {
        padding: var(--space-2) var(--space-3);
    }
    
    /* Stack table on mobile */
    .table-responsive-stack {
        display: block;
    }
    
    .table-responsive-stack thead {
        display: none;
    }
    
    .table-responsive-stack tbody,
    .table-responsive-stack tr,
    .table-responsive-stack td {
        display: block;
        width: 100%;
    }
    
    .table-responsive-stack tr {
        margin-bottom: var(--space-4);
        border: var(--border-width-1) solid var(--color-border);
        border-radius: var(--radius-md);
    }
    
    .table-responsive-stack td {
        text-align: right;
        padding-left: 50%;
        position: relative;
    }
    
    .table-responsive-stack td::before {
        content: attr(data-label);
        position: absolute;
        left: var(--space-3);
        width: calc(50% - var(--space-6));
        padding-right: var(--space-3);
        text-align: left;
        font-weight: var(--font-weight-semibold);
    }
}

/* =============================================================================
   CUSTOM SCROLLBAR FOR RESPONSIVE TABLES
   ============================================================================= */

.table-responsive::-webkit-scrollbar {
    height: 8px;
}

.table-responsive::-webkit-scrollbar-track {
    background: var(--color-gray-100);
    border-radius: var(--radius-sm);
}

.table-responsive::-webkit-scrollbar-thumb {
    background: var(--color-gray-400);
    border-radius: var(--radius-sm);
}

.table-responsive::-webkit-scrollbar-thumb:hover {
    background: var(--color-gray-500);
}

