/* ==========================================================================
   GLOBAL TABLE STYLES
   Applied to all tables rendered from WYSIWYG/TinyMCE content site-wide
   (RichTextBlock, AccordionItemBlock, CardBlock, etc.)
   ========================================================================== */

/* Responsive wrapper — horizontal scroll on mobile */
table {
    width: 100% !important;
    border-collapse: collapse !important;
    border-spacing: 0;
    margin-bottom: var(--space-6);
    font-size: var(--font-size-sm);
    line-height: 1.5;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (min-width: 768px) {
    table {
        display: table;
        overflow-x: visible;
    }
}

/* Strip all borders — TinyMCE adds border="1" attribute and inline styles */
table,
th,
td {
    border: none !important;
}

/* Override TinyMCE colgroup/col inline widths — let content determine column sizing */
col {
    width: auto !important;
}

/* Header row — TinyMCE uses tbody/td (no thead/th), so the first row is the header */
tbody tr:first-child td {
    background-color: var(--color-bg-light-blue, #EBFAFE) !important;
    color: var(--color-text-primary, #182230) !important;
    font-weight: var(--font-weight-semibold, 600);
    padding: 12px 16px;
    text-align: center;
}

/* Data cells — centered with bottom separator */
tbody tr:not(:first-child) td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-gray-200, #e5e7eb) !important;
    vertical-align: top;
    text-align: center;
}

/* Row label column (first cell in each data row) — bold, left-aligned */
tbody tr:not(:first-child) td:first-child {
    font-weight: var(--font-weight-semibold, 600);
    color: var(--color-text-primary, #182230);
    text-align: left;
}

/* Subtle alternating row backgrounds (skip header row) */
tbody tr:nth-child(even) {
    background-color: var(--color-gray-50, #f9fafb);
}

/* Hover state (skip header row) */
tbody tr:not(:first-child):hover {
    background-color: var(--color-gray-100, #f3f4f6);
}

/* Dark background context — invert the table */
[class*="bg-dark"] tbody tr:first-child td,
[class*="bg-black"] tbody tr:first-child td {
    background-color: rgba(255, 255, 255, 0.1) !important;
    color: var(--color-white) !important;
}

[class*="bg-dark"] tbody tr:not(:first-child) td,
[class*="bg-black"] tbody tr:not(:first-child) td {
    border-bottom-color: rgba(255, 255, 255, 0.12) !important;
    color: rgba(255, 255, 255, 0.9);
}

[class*="bg-dark"] tbody tr:not(:first-child) td:first-child,
[class*="bg-black"] tbody tr:not(:first-child) td:first-child {
    color: var(--color-white);
}

[class*="bg-dark"] tbody tr:nth-child(even),
[class*="bg-black"] tbody tr:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.04);
}

[class*="bg-dark"] tbody tr:not(:first-child):hover,
[class*="bg-black"] tbody tr:not(:first-child):hover {
    background-color: rgba(255, 255, 255, 0.08);
}

/* ==========================================================================
   Table Carousel — Mobile comparison table navigation
   JS wraps tables with 3+ columns in .table-carousel and adds a nav bar.
   On mobile: header row hidden, nav bar shows column title with prev/next.
   Label column stays visible, one data column shown at a time.
   ========================================================================== */

/* Nav bar — hidden by default, visible only when carousel is active */
.table-carousel-nav {
    display: none;
}

.table-carousel--active .table-carousel-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background-color: var(--color-bg-light-blue, #EBFAFE);
    border-radius: var(--radius-md, 8px) var(--radius-md, 8px) 0 0;
}

.table-carousel-nav__title {
    font-weight: var(--font-weight-semibold, 600);
    font-size: var(--font-size-base, 1rem);
    color: var(--color-text-primary, #182230);
    flex: 1;
    text-align: center;
}

.table-carousel-nav__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background-color: var(--color-dark-blue, #003B97);
    color: var(--color-white, #fff);
    cursor: pointer;
    transition: opacity 0.2s ease;
    padding: 0;
    flex-shrink: 0;
}

.table-carousel-nav__btn:disabled {
    opacity: 0.25;
    cursor: not-allowed;
}

/* Hide the header row when carousel is active — nav bar replaces it */
.table-carousel--active table tbody tr:first-child {
    display: none;
}

/* Force table display (override the display:block mobile rule) */
.table-carousel--active table {
    display: table !important;
    overflow-x: visible;
    border-radius: 0 0 var(--radius-md, 8px) var(--radius-md, 8px);
}

/* Left-align data cells on mobile for readability with single column */
.table-carousel--active tbody tr:not(:first-child) td {
    text-align: left;
}

/* Dark background context — invert nav bar */
[class*="bg-dark"] .table-carousel-nav,
[class*="bg-black"] .table-carousel-nav {
    background-color: rgba(255, 255, 255, 0.1);
}

[class*="bg-dark"] .table-carousel-nav__title,
[class*="bg-black"] .table-carousel-nav__title {
    color: var(--color-white);
}

[class*="bg-dark"] .table-carousel-nav__btn,
[class*="bg-black"] .table-carousel-nav__btn {
    background-color: var(--color-white);
    color: var(--color-dark-blue, #003B97);
}
