/**
 * Table Components
 * Table layouts and responsive designs
 */

/* Base table styles */
.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--white);
    border-radius: var(--border-radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    margin: var(--spacing-lg) 0;
}

.table th,
.table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid rgb(0 0 0 / 5%);
    vertical-align: top;
}

.table th {
    background: linear-gradient(135deg, var(--qk-accent-blue) 0%, var(--blue-dark) 100%);
    color: var(--white);
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    font-size: var(--font-size-sm);
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.table tbody tr {
    transition: background-color var(--transition-normal);
}

.table tbody tr:hover {
    background-color: var(--light-gray);
}

/* Table variants (placed before structural last-child reset for specificity) */
.table-striped tbody tr:nth-child(even) {
    background-color: rgb(0 0 0 / 2%);
}

.table-striped tbody tr:nth-child(even):hover {
    background-color: var(--light-gray);
}

.table-bordered {
    border: 1px solid var(--medium-gray);
}

.table-bordered th,
.table-bordered td {
    border-right: 1px solid rgb(0 0 0 / 5%);
}

.table-sm th,
.table-sm td {
    padding: 8px 12px;
    font-size: var(--font-size-sm);
}

.table-lg th,
.table-lg td {
    padding: 16px 20px;
    font-size: var(--font-size-lg);
}

/* Structural row/cell tail adjustments after variants */

/* Column border reset placed before row tail reset to avoid specificity conflicts */
.table-bordered th:last-child,
.table-bordered td:last-child {
    border-right: none;
}

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

/* Table cell content alignment */
.table .text-center {
    text-align: center;
}

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

.table .text-nowrap {
    white-space: nowrap;
}

/* Status badges in tables */
.table .badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    border-radius: var(--border-radius-sm);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

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

.table .badge-warning {
    background: var(--warning);
    color: var(--dark-gray);
}

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

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

.table .badge-secondary {
    background: var(--medium-gray);
    color: var(--dark-gray);
}

/* Action buttons in tables */
.table .table-actions {
    display: flex;
    gap: var(--spacing-sm);
    justify-content: flex-end;
}

.table .table-actions .btn {
    padding: 6px 12px;
    font-size: var(--font-size-sm);
}

/* Sortable table headers */
.table .sortable {
    cursor: pointer;
    -webkit-user-select: none; /* Safari/iOS support */ /* stylelint-disable-line property-no-vendor-prefix */
    user-select: none;
    position: relative;
    padding-right: 24px;
}

.table .sortable::after {
    content: '↕';
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.5;
    font-size: var(--font-size-sm);
}

.table .sortable:hover::after {
    opacity: 1;
}

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

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

/* Responsive table wrapper */
.table-responsive {
    overflow-x: auto;
    border-radius: var(--border-radius-lg);
}

.table-responsive .table {
    margin: 0;
    border-radius: 0;
}

/* Mobile-first responsive table */
@media (width <= 768px) {
    .table-mobile-stack {
        border: none;
        box-shadow: none;
    }
    
    .table-mobile-stack thead {
        display: none;
    }
    
    .table-mobile-stack,
    .table-mobile-stack tbody,
    .table-mobile-stack tr,
    .table-mobile-stack td {
        display: block;
        width: 100%;
    }
    
    .table-mobile-stack tr {
        background: var(--white);
        border-radius: var(--border-radius-md);
        box-shadow: var(--shadow-sm);
        margin-bottom: var(--spacing-md);
        padding: var(--spacing-lg);
        border: 1px solid var(--medium-gray);
    }
    
    .table-mobile-stack td {
        border: none;
        padding: var(--spacing-sm) 0;
        position: relative;
        padding-left: 50% !important;
        text-align: left;
    }
    
    .table-mobile-stack td::before {
        content: attr(data-label) ': ';
        position: absolute;
        left: 0;
        width: 45%;
        font-weight: var(--font-weight-semibold);
        color: var(--qk-accent-blue);
        text-transform: uppercase;
        font-size: var(--font-size-sm);
        letter-spacing: 0.5px;
    }
    
    .table-mobile-stack .table-actions {
        justify-content: flex-start;
        margin-top: var(--spacing-md);
        padding-top: var(--spacing-md);
        border-top: 1px solid var(--medium-gray);
    }
}

/* Table loading state */
.table-loading {
    position: relative;
    overflow: hidden;
}

.table-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgb(255 255 255 / 40%),
        transparent
    );
    animation: table-loading 1.5s infinite;
}

@keyframes table-loading {
    0% {
      left: -100%;
    }

    100% {
      left: 100%;
    }
}

/* Empty state */
.table-empty {
    text-align: center;
    padding: var(--spacing-3xl);
    color: var(--medium-gray);
}

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

.table-empty-message {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-medium);
    margin-bottom: var(--spacing-sm);
}

.table-empty-description {
    font-size: var(--font-size-base);
    color: var(--dark-gray);
}
