/* Table Component System */

/* Base Table */
.table {
    width: 100%;
    max-width: 100%;
    margin-bottom: var(--spacing-5);
    border-collapse: collapse;
}

.table th,
.table td {
    padding: var(--spacing-2) var(--spacing-3);
    vertical-align: top;
    border-top: var(--border-width-1) solid var(--border-color);
}

.table thead th {
    vertical-align: bottom;
    border-bottom: calc(var(--border-width-1) * 2) solid var(--border-color);
    font-weight: var(--font-weight-bold);
}

.table tbody + tbody {
    border-top: calc(var(--border-width-1) * 2) solid var(--border-color);
}

/* Table Variants */
.table-striped tbody tr:nth-of-type(odd) {
    background-color: rgba(0, 0, 0, 0.025);
}

.table-hover tbody tr:hover {
    background-color: rgba(0, 0, 0, 0.075);
}

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

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

.table-bordered thead th,
.table-bordered thead td {
    border-bottom-width: calc(var(--border-width-1) * 2);
}

/* Table Sizes */
.table-sm th,
.table-sm td {
    padding: var(--spacing-1) var(--spacing-2);
}

.table-lg th,
.table-lg td {
    padding: var(--spacing-4) var(--spacing-5);
}

/* Responsive Table Container */
.table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-responsive > .table {
    margin-bottom: 0;
}

/* Post Content Tables - Specific styling for markdown tables */
.site-main-content .table-container,
.comment-body .table-container {
    container-type: inline-size;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: var(--spacing-4) 0;
    border: var(--border-width-1) solid var(--border-color);
    border-radius: var(--radius-base);
}

.site-main-content table,
.comment-body table {
    width: 100%;
    max-width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    margin: 0;
}

.site-main-content table th,
.site-main-content table td,
.comment-body table th,
.comment-body table td {
    padding: var(--spacing-2) var(--spacing-3);
    border: var(--border-width-1) solid var(--border-color);
    vertical-align: top;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.site-main-content table th,
.comment-body table th {
    background-color: var(--color-gray-100);
    font-weight: var(--font-weight-bold);
    text-align: left;
}

/* Table Content Overflow Handling */
.site-main-content table td,
.comment-body table td {
    max-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.site-main-content table td:hover,
.comment-body table td:hover {
    overflow: visible;
    white-space: normal;
    z-index: 1;
    position: relative;
    background-color: var(--color-white);
    box-shadow: var(--shadow-md);
}

/* Container Query for Responsive Tables */
@container (max-width: 600px) {
    .site-main-content .table-container table,
    .comment-body .table-container table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    .site-main-content .table-container table thead,
    .site-main-content .table-container table tbody,
    .site-main-content .table-container table th,
    .site-main-content .table-container table td,
    .site-main-content .table-container table tr,
    .comment-body .table-container table thead,
    .comment-body .table-container table tbody,
    .comment-body .table-container table th,
    .comment-body .table-container table td,
    .comment-body .table-container table tr {
        display: block;
    }

    .site-main-content .table-container table thead tr,
    .comment-body .table-container table thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    .site-main-content .table-container table tr,
    .comment-body .table-container table tr {
        border: var(--border-width-1) solid var(--border-color);
        margin-bottom: var(--spacing-2);
        padding: var(--spacing-2);
    }

    .site-main-content .table-container table td,
    .comment-body .table-container table td {
        border: none;
        position: relative;
        padding-left: 30%;
        padding-top: var(--spacing-2);
        padding-bottom: var(--spacing-2);
    }

    .site-main-content .table-container table td:before,
    .comment-body .table-container table td:before {
        content: attr(data-label) ": ";
        position: absolute;
        left: var(--spacing-2);
        width: 25%;
        padding-right: var(--spacing-2);
        white-space: nowrap;
        font-weight: var(--font-weight-bold);
    }
}

/* Browser-specific Table Fixes */
@supports (-webkit-appearance: none) {
    .site-main-content table,
    .comment-body table {
        table-layout: fixed;
    }

    .site-main-content table th,
    .site-main-content table td,
    .comment-body table th,
    .comment-body table td {
        word-break: break-word;
        -webkit-hyphens: auto;
        -moz-hyphens: auto;
        hyphens: auto;
    }
}

/* Table Caption */
.table caption {
    padding-top: var(--spacing-2);
    padding-bottom: var(--spacing-2);
    color: var(--color-muted);
    text-align: left;
    caption-side: bottom;
}

/* Table Color Variants */
.table-primary {
    background-color: rgba(0, 123, 255, 0.05);
}

.table-secondary {
    background-color: rgba(108, 117, 125, 0.05);
}

.table-success {
    background-color: rgba(40, 167, 69, 0.05);
}

.table-danger {
    background-color: rgba(220, 53, 69, 0.05);
}

.table-warning {
    background-color: rgba(255, 193, 7, 0.05);
}

.table-info {
    background-color: rgba(23, 162, 184, 0.05);
}

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

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

.table-dark th,
.table-dark td,
.table-dark thead th {
    border-color: rgba(255, 255, 255, 0.1);
}

/* Responsive Breakpoints for Tables */
@media (max-width: 768px) {
    .table-responsive-sm {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 992px) {
    .table-responsive-md {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 1200px) {
    .table-responsive-lg {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}
