/* ==========================================================================
   Data tables in content (results, statistics, season archives, squads).

   - The figure scrolls horizontally on small screens instead of squashing
     columns; a soft shadow at the edge shows that more columns follow.
   - Tabular, lining numerals so scores and counts line up.
   - Subtle zebra rows plus a strong hover row for scanning across.
   ========================================================================== */

.wm-theme .entry-content :is(.wp-block-table, figure.wp-block-table) {
    position: relative;
    max-width: 100%;
    margin-inline: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    border: 1px solid var(--wm-line);
    border-radius: var(--wm-radius-sm);
    background:
        linear-gradient(90deg, var(--wm-surface) 30%, transparent) left / 2.5rem 100% no-repeat local,
        linear-gradient(270deg, var(--wm-surface) 30%, transparent) right / 2.5rem 100% no-repeat local,
        radial-gradient(farthest-side at 0 50%, rgb(0 0 0 / 18%), transparent) left / .9rem 100% no-repeat scroll,
        radial-gradient(farthest-side at 100% 50%, rgb(0 0 0 / 18%), transparent) right / .9rem 100% no-repeat scroll,
        var(--wm-surface);
    scrollbar-width: thin;
    scrollbar-color: var(--wm-line-strong) transparent;
}

/* Bare tables (classic editor, imported content) */
.wm-theme .entry-content > table,
.wm-theme .entry-content :not(.wp-block-table) > table:not(.wm-table-plain) {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    border: 1px solid var(--wm-line);
    border-radius: var(--wm-radius-sm);
}

.wm-theme .entry-content table {
    width: 100%;
    margin: 0;
    font-size: clamp(.9rem, .85rem + .2vw, 1rem);
    line-height: 1.4;
    font-variant-numeric: tabular-nums lining-nums;
    border-collapse: separate;
    border-spacing: 0;
    background: transparent;
}
/* The table sits flush inside its framed figure (the generic content rule would add a bottom margin) */
.wm-theme .entry-content .wp-block-table > table { margin: 0; }
.wm-theme .entry-content .wp-block-table table { min-width: max-content; }
@media (min-width: 48em) {
    .wm-theme .entry-content .wp-block-table table { min-width: 100%; }
}

.wm-theme .entry-content :is(th, td) {
    padding: .65rem .9rem;
    text-align: left;
    vertical-align: top;
    border: 0;
    border-bottom: 1px solid var(--wm-line);
}
.wm-theme .entry-content tr:last-child > :is(td, th) { border-bottom: 0; }
.wm-theme .entry-content :is(th, td):first-child { padding-left: 1.1rem; }
.wm-theme .entry-content :is(th, td):last-child { padding-right: 1.1rem; }

/* Header: dark band with a red rule */
.wm-theme .entry-content thead th,
.wm-theme .entry-content thead td {
    font-family: var(--wm-font-display);
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
    white-space: nowrap;
    color: #fff;
    background: light-dark(#2a2427, #0b090b);
    border-bottom: 3px solid var(--wm-red);
}
/* Tables without <thead> often use a first row of <th> */
.wm-theme .entry-content tbody tr:first-child:has(> th:nth-child(2)) > th {
    font-family: var(--wm-font-display);
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: #fff;
    background: light-dark(#2a2427, #0b090b);
    border-bottom: 3px solid var(--wm-red);
}
/* Row headers (key/value tables like player profiles) */
.wm-theme .entry-content tbody th:first-child:not(:nth-last-child(n+3)) {
    font-weight: 700;
    color: var(--wm-text-muted);
    background: var(--wm-surface-2);
}

/* Zebra + hover */
.wm-theme .entry-content tbody tr:nth-child(even) > td,
.wm-theme .entry-content .is-style-stripes tbody tr:nth-child(odd) > td { background: light-dark(#faf7f5, #1e1a1f); }
.wm-theme .entry-content .is-style-stripes tbody tr:nth-child(even) > td { background: transparent; }
.wm-theme .entry-content .is-style-stripes { border-bottom: 1px solid var(--wm-line); }
.wm-theme .entry-content tbody tr { transition: background-color .15s; }
.wm-theme .entry-content tbody tr:hover > td { background: light-dark(#fdecee, #3a1a20) !important; }
.wm-theme .entry-content tbody tr:hover > td:first-child { box-shadow: inset 3px 0 0 var(--wm-red); }

/* Numbers and alignment helpers set in the editor */
.wm-theme .entry-content :is(th, td).has-text-align-right,
.wm-theme .entry-content :is(th, td)[data-align="right"] { text-align: right; }
.wm-theme .entry-content :is(th, td).has-text-align-center,
.wm-theme .entry-content :is(th, td)[data-align="center"] { text-align: center; }
.wm-theme .entry-content td a { font-weight: 700; }

/* Totals row */
.wm-theme .entry-content tfoot :is(td, th) {
    font-weight: 800;
    background: var(--wm-surface-2);
    border-top: 2px solid var(--wm-line-strong);
    border-bottom: 0;
}

/* Legacy totals row: Twig templates stored in ~50 pages (season statistics) render "Gesamt" as the last
   <tbody> row with an inline border-top and one cell fewer than the header. Style it like <tfoot>: the dividing
   line sits on the full row above, and the last cell's background is extended to the right with a spread shadow
   clipped to that side (shadows are ink overflow, so the scrolling figure gets no extra scroll width). */
.wm-theme .entry-content tbody > tr:has(+ tr[style*="border-top"]) > :is(td, th) { border-bottom: 2px solid var(--wm-line-strong); }
.wm-theme .entry-content tbody > tr[style*="border-top"] > :is(td, th) {
    font-weight: 800;
    background: var(--wm-surface-2) !important;
    border: 0;
}
.wm-theme .entry-content tbody > tr[style*="border-top"] > :is(td, th):last-child {
    box-shadow: 0 0 0 100vw var(--wm-surface-2) !important;
    clip-path: inset(0 -100vw 0 0);
}

.wm-theme .entry-content .wp-block-table figcaption,
.wm-theme .entry-content table caption {
    margin: 0;
    padding: .6rem 1rem;
    font-size: var(--wm-step--1);
    text-align: left;
    color: var(--wm-text-muted);
    background: var(--wm-surface-2);
    border-top: 1px solid var(--wm-line);
}
.wm-theme .entry-content table caption { caption-side: bottom; }

/* Fixed-layout tables from the editor keep their column widths */
.wm-theme .entry-content .wp-block-table .has-fixed-layout { table-layout: fixed; min-width: 100%; }
.wm-theme .entry-content .wp-block-table .has-fixed-layout :is(td, th) { overflow-wrap: anywhere; }

/* Older tables use inline borders/colors; neutralise them so they read in both schemes */
.wm-theme .entry-content table[border] :is(td, th) { border-color: var(--wm-line); }
.wm-theme .entry-content :is(td, th)[style*="background"] { background-color: transparent !important; }
.wm-theme .entry-content :is(td, th)[bgcolor] { background-color: transparent; }

/* Dense tables (many columns): tighter cells on phones */
@media (max-width: 47.99em) {
    .wm-theme .entry-content :is(th, td) { padding: .5rem .65rem; }
    .wm-theme .entry-content :is(th, td):first-child { padding-left: .8rem; }
}
