/*
 * Tabula: table styles.
 *
 * Kept small on purpose so the theme's own table styles still apply. Adjust
 * the look with these custom properties, for example in your theme's CSS:
 *
 *   .tabula {
 *     --tabula-border-color: #e3ebf0;
 *     --tabula-border-width: 2px;
 *     --tabula-sticky-bg: #f5f5f5;
 *   }
 */

.tabula-wrap {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: var(--tabula-gap, 2em);
}

.tabula-wrap[style*="max-height"] {
    overflow-y: auto;
}

.tabula-wrap:focus-visible {
    outline: 2px solid var(--tabula-focus-color, currentColor);
    outline-offset: 2px;
}

.tabula {
    --tabula-border: var(--tabula-border-width, 1px) solid var(--tabula-border-color, rgba(128, 128, 128, 0.3));
    border-collapse: collapse;
    width: 100%;
    margin: 0;
}

.tabula caption {
    caption-side: top;
    text-align: start;
    font-weight: 600;
    padding-bottom: 0.5em;
}

.tabula th,
.tabula td {
    vertical-align: top;
}

.tabula--nowrap th,
.tabula--nowrap td {
    white-space: nowrap;
}

/* Cell padding set on a single table (padding="…"); the site-wide setting adds
   the same rule inline. Without either, the theme's padding applies. */
.tabula-wrap--padding .tabula :is(th, td) {
    padding: var(--tabula-padding);
}

/* Numbers right-aligned, with digits of equal width so decimals line up. */
.tabula .tabula-num {
    text-align: end;
    font-variant-numeric: tabular-nums;
}

/* ─── Borders ────────────────────────────────────────────────────────────── */

.tabula--border-all,
.tabula--border-all th,
.tabula--border-all td,
.tabula--border-outer {
    border: var(--tabula-border);
}

/* Lines between rows. A cell spanning several rows is not crossed. */
.tabula--border-inner tr + tr > *,
.tabula--border-horizontal tr + tr > *,
.tabula--border-inner :is(thead, tbody) + :is(tbody, tfoot) > tr:first-child > *,
.tabula--border-horizontal :is(thead, tbody) + :is(tbody, tfoot) > tr:first-child > * {
    border-top: var(--tabula-border);
}

/* Lines between columns. First-column cells are marked with a class, because
   under a rowspan the first cell of a row belongs to the second column. */
.tabula--border-inner :is(th, td):not(.tabula-first),
.tabula--border-vertical :is(th, td):not(.tabula-first) {
    border-inline-start: var(--tabula-border);
}

.tabula--border-header thead {
    border-bottom: calc(var(--tabula-border-width, 1px) * 2) solid var(--tabula-border-color, rgba(128, 128, 128, 0.3));
}

/* ─── Sticky header row and first column ─────────────────────────────────── */

.tabula--sticky-header thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background-color: var(--tabula-sticky-bg, #f5f5f5);
    background-image: none;
}

.tabula--sticky-col .tabula-first {
    position: sticky;
    inset-inline-start: 0;
    z-index: 1;
    background-color: var(--tabula-sticky-bg, #f5f5f5);
    background-image: none;
}

.tabula--sticky-header.tabula--sticky-col thead .tabula-first {
    z-index: 3;
}

/* ─── Stacked layout on small screens ────────────────────────────────────── */

@media (max-width: 40em) {
    .tabula--stack,
    .tabula--stack tbody,
    .tabula--stack tfoot,
    .tabula--stack tr,
    .tabula--stack th,
    .tabula--stack td {
        display: block;
        width: auto;
    }

    .tabula--stack thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .tabula--stack tr {
        border: var(--tabula-border);
        margin-bottom: 1em;
    }

    .tabula--stack :is(th, td) {
        border: 0;
        position: static;
        white-space: normal;
        text-align: start;
    }

    .tabula--stack :is(th, td)[data-label]::before {
        content: attr(data-label);
        display: block;
        font-weight: 600;
        font-size: 0.85em;
        opacity: 0.75;
    }

    .tabula--stack .tabula-num {
        text-align: start;
    }
}

/* ─── Other plugins that wrap every table ────────────────────────────────── */

/* Simple Responsive Tables puts two scrolling divs around each table. Inside
   Tabula the outer .tabula-wrap already scrolls; a second scroll container
   would break the sticky header and first column. */
.tabula-wrap .simple-responsive-table,
.tabula-wrap .simple-responsive-table > div {
    position: static;
    overflow: visible;
}

.tabula-wrap .simple-responsive-table::before,
.tabula-wrap .simple-responsive-table::after {
    display: none;
}

/* ─── Errors (shown instead of the table) ────────────────────────────────── */

.tabula-error {
    border-inline-start: 4px solid #c0392b;
    padding: 0.5em 1em;
    margin-bottom: 1em;
}
