/**
 * Table Component Styles
 * Compact, responsive table styling with density variants
 */

/* Responsive table wrapper */
.table-responsive {
    border: 1px solid var(--ds-color-border-primary, #e5e7eb);
    border-radius: var(--ds-radius-lg, 12px);
    overflow: hidden;
    background: var(--ds-color-surface, #ffffff);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.table-responsive .table {
    margin-bottom: 0;
    border-radius: 0;
    box-shadow: none;
}

/* Base table styles */
.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--ds-font-size-sm, 14px);
    color: var(--ds-color-text-primary, #1f2937);
    background-color: var(--ds-color-surface, #ffffff);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
    border-radius: var(--ds-radius-lg, 12px);
    overflow: hidden;
}

/* Table wrapper for bordered tables */
.table-wrapper {
    border: 1px solid var(--ds-color-border-primary, #e5e7eb);
    border-radius: var(--ds-radius-lg, 12px);
    overflow: hidden;
    background: var(--ds-color-surface, #ffffff);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.table-wrapper .table {
    margin-bottom: 0;
    box-shadow: none;
}

/* Table head */
.table thead {
    background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
    border-bottom: 3px solid #60a5fa;
}

.table thead th {
    padding: var(--ds-space-lg, 18px) var(--ds-space-lg, 20px);
    text-align: left;
    font-weight: var(--ds-font-weight-semibold, 600);
    font-size: var(--ds-font-size-base, 15px);
    color: #ffffff;
    border-bottom: none;
    white-space: nowrap;
    letter-spacing: 0.015em;
}

/* Sticky header for scrollable tables */
.table--sticky-header thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: var(--ds-color-neutral-50, #f9fafb);
}

/* Table body */
.table tbody td {
    padding: var(--ds-space-sm, 14px) var(--ds-space-lg, 20px);
    border-bottom: 1px solid var(--ds-color-border-subtle, #e5e7eb);
    vertical-align: middle;
    font-size: var(--ds-font-size-sm, 14px);
    background-color: #ffffff;
}

.table tbody tr {
    background-color: #ffffff;
}

.table tbody tr:nth-child(even) {
    background-color: #f8fafc;
}

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

/* Hoverable rows */
.table--hoverable tbody tr {
    transition: all var(--ds-duration-fast, 150ms) var(--ds-ease-out, ease-out);
    cursor: pointer;
}

.table--hoverable tbody tr:hover {
    background-color: #dbeafe;
    transform: translateX(2px);
    box-shadow: -4px 0 0 0 #3b82f6;
}

/* Striped rows */
.table--striped tbody tr:nth-child(even) {
    background-color: var(--ds-color-surface-alt, #f8fafc);
}

.table--striped.table--hoverable tbody tr:nth-child(even):hover {
    background-color: var(--ds-color-primary-50, #eff6ff);
}

/* Bordered table */
.table--bordered {
    border: 1px solid var(--ds-color-border-primary, #d1d5db);
}

.table--bordered thead th,
.table--bordered tbody td {
    border-right: 1px solid var(--ds-color-border-subtle, #e5e7eb);
}

.table--bordered thead th:last-child,
.table--bordered tbody td:last-child {
    border-right: none;
}

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

/* Table Density Variants */

/* Compact: Tightest spacing for maximum density */
.table--compact {
    --table-cell-padding-y: var(--ds-space-2xs, 4px);
    --table-cell-padding-x: var(--ds-space-xs, 8px);
    font-size: var(--ds-font-size-xs, 12px);
}

.table--compact thead th {
    padding: var(--ds-space-2xs, 4px) var(--ds-space-xs, 8px);
    font-size: 11px;
}

/* Dense: Balanced density (default) */
.table--dense {
    --table-cell-padding-y: var(--ds-space-xs, 8px);
    --table-cell-padding-x: var(--ds-space-sm, 12px);
}

/* Comfortable: More breathing room */
.table--comfortable {
    --table-cell-padding-y: var(--ds-space-sm, 12px);
    --table-cell-padding-x: var(--ds-space-md, 16px);
    font-size: var(--ds-font-size-base, 14px);
}

.table--comfortable thead th {
    padding: var(--ds-space-sm, 12px) var(--ds-space-md, 16px);
    font-size: var(--ds-font-size-sm, 14px);
}

/* Column alignment utilities */
.table th.text-right,
.table td.text-right {
    text-align: right;
}

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

/* Column width utilities */
.table .col-auto {
    width: 1%;
    white-space: nowrap;
}

.table .col-expand {
    width: 100%;
}

/* Cell content utilities */
.table td.nowrap {
    white-space: nowrap;
}

.table td.truncate {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Table actions column (for buttons/icons) */
.table__actions {
    display: flex;
    gap: var(--ds-space-xs, 8px);
    align-items: center;
    justify-content: flex-end;
}

/* Table empty state */
.table__empty {
    padding: var(--ds-space-2xl, 48px) var(--ds-space-lg, 20px);
    text-align: center;
    color: var(--ds-color-text-tertiary, #9ca3af);
    font-size: var(--ds-font-size-sm, 14px);
}

/* Table loading state */
.table__loading {
    position: relative;
    min-height: 200px;
}

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

/* Row selection */
.table tbody tr.selected {
    background-color: var(--ds-color-primary-100, #dbeafe);
}

.table tbody tr.selected:hover {
    background-color: var(--ds-color-primary-200, #bfdbfe);
}

/* Row status indicators */
.table tbody tr.status-success {
    border-left: 3px solid var(--ds-color-success-500, #22c55e);
}

.table tbody tr.status-warning {
    border-left: 3px solid var(--ds-color-warning-500, #f59e0b);
}

.table tbody tr.status-error {
    border-left: 3px solid var(--ds-color-danger-500, #ef4444);
}

.table tbody tr.status-info {
    border-left: 3px solid var(--ds-color-info-500, #06b6d4);
}

/* Responsive table - horizontal scroll on small screens */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Responsive table - stack on mobile */
.table--stack {
    display: table;
}

@media (max-width: 768px) {
    .table--stack,
    .table--stack thead,
    .table--stack tbody,
    .table--stack th,
    .table--stack td,
    .table--stack tr {
        display: block;
    }

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

    .table--stack tbody tr {
        margin-bottom: var(--ds-space-md, 16px);
        border: 1px solid var(--ds-color-border-primary, #d1d5db);
        border-radius: var(--ds-radius-md, 6px);
        padding: var(--ds-space-sm, 12px);
    }

    .table--stack tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: var(--ds-space-xs, 8px) 0;
        border: none;
        text-align: right;
    }

    .table--stack tbody td::before {
        content: attr(data-label);
        font-weight: var(--ds-font-weight-semibold, 600);
        color: var(--ds-color-text-secondary, #6b7280);
        text-align: left;
        margin-right: var(--ds-space-md, 16px);
    }

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

/* Scrollable table container with shadow indicators */
.table-scroll-container {
    position: relative;
    overflow: auto;
    max-height: 600px;
}

.table-scroll-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.table-scroll-container::-webkit-scrollbar-track {
    background: var(--ds-color-neutral-100, #f3f4f6);
    border-radius: 4px;
}

.table-scroll-container::-webkit-scrollbar-thumb {
    background: var(--ds-color-neutral-400, #9ca3af);
    border-radius: 4px;
}

.table-scroll-container::-webkit-scrollbar-thumb:hover {
    background: var(--ds-color-neutral-500, #6b7280);
}

/* Table sorting indicators */
.table thead th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: calc(var(--table-cell-padding-x, var(--ds-space-sm, 12px)) + 16px);
}

.table thead th.sortable:hover {
    background-color: var(--ds-color-neutral-100, #f3f4f6);
}

.table thead th.sortable::after {
    content: '⇅';
    position: absolute;
    right: var(--ds-space-xs, 8px);
    opacity: 0.4;
    font-size: 12px;
}

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

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

/* High contrast mode support */
@media (prefers-contrast: high) {
    .table {
        border: 2px solid var(--ds-color-border-primary);
    }

    .table thead th {
        border-bottom-width: 3px;
    }

    .table tbody td {
        border-bottom-width: 2px;
    }
}

/* Print styles */
@media print {
    .table {
        border-collapse: collapse;
    }

    .table thead th,
    .table tbody td {
        border: 1px solid #000;
    }

    .table--hoverable tbody tr:hover {
        background-color: transparent;
    }

    .table__actions {
        display: none;
    }
}
