/*
 * Tables Component Styles
 * Responsive table layouts with horizontal scroll and column hiding
 * Breakpoints: mobile (default), sm (640px), md (768px), lg (1024px)
 */

/* Table wrapper for horizontal scroll */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Show scrollbar hint on mobile */
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

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

.table-responsive::-webkit-scrollbar-track {
    background: transparent;
}

.table-responsive::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
    background-color: rgba(0, 0, 0, 0.3);
}

/* Base table styles */
.table {
    width: 100%;
    min-width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

/* Allow tables to expand beyond container when needed */
.table-auto {
    width: auto;
    min-width: 100%;
}

/* Table headers */
.table thead {
    background-color: var(--table-header-bg, #f9fafb);
    border-bottom: 2px solid var(--border-color, #e5e7eb);
}

.table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--text-secondary, #6b7280);
    text-transform: uppercase;
    letter-spacing: 0.025em;
    white-space: nowrap;
}

/* Table body */
.table tbody tr {
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    transition: background-color 0.15s ease;
}

.table tbody tr:hover {
    background-color: var(--table-row-hover, #f9fafb);
}

.table td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
}

/* Flexible column widths - no fixed widths */
.table .col-icon {
    width: 1%;
    white-space: nowrap;
}

.table .col-checkbox {
    width: 1%;
    padding-right: 0.5rem;
}

.table .col-actions {
    width: 1%;
    white-space: nowrap;
    text-align: right;
}

.table .col-status {
    width: 1%;
    white-space: nowrap;
}

.table .col-date {
    width: 1%;
    white-space: nowrap;
}

.table .col-number {
    width: 1%;
    white-space: nowrap;
    text-align: right;
}

/* Responsive column hiding - hide less important columns on mobile */
@media (max-width: 639px) {
    .table .col-hide-mobile {
        display: none;
    }
}

@media (max-width: 767px) {
    .table .col-hide-sm {
        display: none;
    }
}

@media (max-width: 1023px) {
    .table .col-hide-md {
        display: none;
    }
}

/* Show columns at specific breakpoints */
@media (min-width: 640px) {
    .table .col-show-sm {
        display: table-cell;
    }
}

@media (min-width: 768px) {
    .table .col-show-md {
        display: table-cell;
    }
}

@media (min-width: 1024px) {
    .table .col-show-lg {
        display: table-cell;
    }
}

/* Compact table for dense data */
.table-compact th {
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
}

.table-compact td {
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
}

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

.table-striped tbody tr:hover {
    background-color: var(--table-row-hover, #f3f4f6);
}

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

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

/* Expandable rows */
.table tr.expandable-row {
    cursor: pointer;
}

.table tr.expandable-row:hover {
    background-color: var(--table-row-hover, #f9fafb);
}

.table tr.expanded-content {
    background-color: var(--table-expanded-bg, #ffffff);
}

.table tr.expanded-content td {
    padding: 1.5rem 1rem;
    border-top: none;
}

.table tr.expanded-content .expanded-inner {
    padding: 1rem;
    background-color: var(--table-expanded-inner, #f9fafb);
    border-radius: 0.375rem;
}

/* Empty state */
.table-empty {
    padding: 3rem 1.5rem;
    text-align: center;
    color: var(--text-secondary, #6b7280);
}

.table-empty-icon {
    font-size: 3rem;
    color: var(--text-muted, #d1d5db);
    margin-bottom: 1rem;
}

.table-empty-text {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.table-empty-subtext {
    font-size: 0.875rem;
    color: var(--text-muted, #9ca3af);
}

/* 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;
}

/* Sticky header for long tables */
.table-sticky-header thead {
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* Cell alignment utilities */
.table .text-center {
    text-align: center;
}

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

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

/* Truncate long text in cells */
.table .truncate {
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (min-width: 768px) {
    .table .truncate {
        max-width: 300px;
    }
}

/* Nested table support */
.table .nested-table {
    margin: 1rem 0;
    font-size: 0.8125rem;
}

.table .nested-table th {
    background-color: var(--table-nested-header, #f3f4f6);
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
}

.table .nested-table td {
    padding: 0.5rem 0.75rem;
}

/* Mobile: Stack table as cards */
@media (max-width: 639px) {
    .table-stack-mobile {
        display: block;
    }

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

    .table-stack-mobile tbody {
        display: block;
    }

    .table-stack-mobile tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid var(--border-color, #e5e7eb);
        border-radius: 0.375rem;
        padding: 1rem;
    }

    .table-stack-mobile td {
        display: block;
        padding: 0.5rem 0;
        border: none;
        text-align: left;
    }

    .table-stack-mobile td::before {
        content: attr(data-label);
        display: block;
        font-weight: 600;
        font-size: 0.75rem;
        color: var(--text-secondary, #6b7280);
        margin-bottom: 0.25rem;
        text-transform: uppercase;
    }

    .table-stack-mobile .col-actions {
        display: flex;
        gap: 0.5rem;
        padding-top: 1rem;
        border-top: 1px solid var(--border-color, #e5e7eb);
    }
}

/* Responsive padding adjustments */
@media (max-width: 767px) {
    .table th,
    .table td {
        padding: 0.625rem 0.75rem;
    }
}

@media (max-width: 639px) {
    .table th,
    .table td {
        padding: 0.5rem 0.5rem;
    }
}
