/**
 * HeuriSight Table System
 * Based on: mockups/apple-redesign/06-student-completion.html, 07-dimension-drilldown.html
 * 
 * Usage:
 *   <table class="hs-table">
 *     <thead><tr><th>...</th></tr></thead>
 *     <tbody><tr><td>...</td></tr></tbody>
 *   </table>
 */

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

.hs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm, 13px);
}

.hs-table th,
.hs-table td {
    padding: var(--space-3, 12px) var(--space-4, 16px);
    text-align: left;
    border-bottom: 1px solid var(--border-light, rgba(0, 0, 0, 0.06));
}

.hs-table th {
    font-size: var(--text-xs, 11px);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-tertiary, #86868B);
    background: var(--bg-secondary, #F5F5F7);
}

.hs-table tbody tr {
    transition: background var(--duration-fast, 150ms);
}

.hs-table tbody tr:hover {
    background: var(--bg-secondary, #F5F5F7);
}

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

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

/* Compact table */
.hs-table--compact th,
.hs-table--compact td {
    padding: var(--space-2, 8px) var(--space-3, 12px);
}

/* Striped rows */
.hs-table--striped tbody tr:nth-child(even) {
    background: var(--bg-tertiary, #FAFAFA);
}

/* Borderless */
.hs-table--borderless th,
.hs-table--borderless td {
    border-bottom: none;
}

/* Clickable rows */
.hs-table--clickable tbody tr {
    cursor: pointer;
}

.hs-table--clickable tbody tr:hover {
    background: var(--accent-subtle, rgba(0, 113, 227, 0.08));
}

/* =============================================================================
   TABLE CELL ALIGNMENT
   ============================================================================= */

.hs-table th.text-center,
.hs-table td.text-center {
    text-align: center;
}

.hs-table th.text-right,
.hs-table td.text-right {
    text-align: right;
}

/* =============================================================================
   TABLE WITH FIXED HEADER
   ============================================================================= */

.hs-table-wrapper {
    position: relative;
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border-light, rgba(0, 0, 0, 0.06));
    border-radius: var(--radius-md, 12px);
}

.hs-table-wrapper .hs-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

.hs-table-wrapper .hs-table thead th {
    box-shadow: 0 1px 0 var(--border-light, rgba(0, 0, 0, 0.06));
}

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

.hs-table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 767px) {
    /* Stack cells on mobile */
    .hs-table--stack thead {
        display: none;
    }
    
    .hs-table--stack tbody tr {
        display: block;
        margin-bottom: var(--space-4, 16px);
        padding: var(--space-4, 16px);
        background: var(--bg-primary, #FFFFFF);
        border: 1px solid var(--border-light, rgba(0, 0, 0, 0.06));
        border-radius: var(--radius-md, 12px);
    }
    
    .hs-table--stack td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: var(--space-2, 8px) 0;
        border-bottom: 1px solid var(--border-light, rgba(0, 0, 0, 0.06));
    }
    
    .hs-table--stack td:last-child {
        border-bottom: none;
    }
    
    .hs-table--stack td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary, #6E6E73);
        font-size: var(--text-xs, 11px);
        text-transform: uppercase;
    }
}

/* =============================================================================
   TABLE SORTING INDICATORS
   ============================================================================= */

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

.hs-table th.sortable:hover {
    color: var(--text-primary, #1D1D1F);
}

.hs-table th.sortable::after {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: var(--space-1, 4px);
    vertical-align: middle;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    opacity: 0.3;
}

.hs-table th.sorted-asc::after {
    border-bottom: 4px solid currentColor;
    opacity: 1;
}

.hs-table th.sorted-desc::after {
    border-top: 4px solid currentColor;
    opacity: 1;
}

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

.hs-table-empty {
    padding: var(--space-12, 48px) var(--space-6, 24px);
    text-align: center;
    color: var(--text-tertiary, #86868B);
}

.hs-table-empty__icon {
    width: 48px;
    height: 48px;
    margin: 0 auto var(--space-4, 16px);
    color: var(--text-tertiary, #86868B);
}

.hs-table-empty__title {
    font-size: var(--text-lg, 17px);
    font-weight: 500;
    color: var(--text-secondary, #6E6E73);
    margin-bottom: var(--space-2, 8px);
}

.hs-table-empty__message {
    font-size: var(--text-sm, 13px);
    color: var(--text-tertiary, #86868B);
}

/* =============================================================================
   DARK THEME
   ============================================================================= */

[data-theme="dark"] .hs-table th {
    background: var(--bg-secondary, #2C2C2E);
}

[data-theme="dark"] .hs-table tbody tr:hover,
[data-theme="dark"] .hs-table--striped tbody tr:nth-child(even) {
    background: var(--bg-secondary, #2C2C2E);
}

[data-theme="dark"] .hs-table-wrapper {
    border-color: var(--border-light, rgba(255, 255, 255, 0.08));
}
