/* SchoolCMS – Content tables
   Base styling for WYSIWYG content (js/utilities/table.js wraps bare
   tables in Bootstrap's .table-responsive), plus the one table the
   editor's Formats dropdown offers (inc/wysiwyg.php +
   js/admin/wysiwyg-table-styles.js).

   The table is the design's drawn table – Text (Table), 8001:2884 – and
   it is the only one: a navy header band (Rectangle 53, 1296 × 51) with
   white titles in the h4 style, body cells in the body style and grey,
   every second body row on a cream band (Frame 262), no rules, no
   borders, no corners, no shadow. The columns start 23 in from the
   table's edge and stand 28 apart; a row is 46 deep (10 + 26 + 10 – the
   rows' pitch, 171.3 → 217.4 → 263.3); the first row sits 23 clear of
   the header band (its copy 33 under it).

   DEPARTURE – the header titles sit in the middle of their band. The
   file draws them 10.3 from the top of the 51px band and 6.7 from its
   foot; the theme keeps the band's depth and gives the titles 8.5 above
   and below (house rule: typography.md §Table, Charlie 2026-10-29).
   DEPARTURE – the cream band is drawn 43 deep with 10 above its copy and
   7 below, 3 short of the rows' own 46 pitch; a stripe here is its whole
   row, 46.

   The header's colour is --table-accent and its titles'
   --table-accent-text, both set on the table; the scroll bar under a
   wide table takes the header's colour too (table.js). */

/* No frame round the table. The editor's Table button writes border="1"
   on every table it makes, and the browser draws that attribute as a 1px
   frame the design does not have – so a client-made table came out boxed
   where a hand-written one did not (found on Burlington, 2026-10-14).
   Bootstrap's reboot already cancels the cells' half of the attribute;
   `border: 0` here cancels the table's, so every table reads the same
   however it was made. The lines a wysiwyg adds to show the columns are
   css/admin/editor-canvas.css. */
table {
    --table-accent:      var(--color-navy);
    --table-accent-text: var(--color-white);

    width:           100%;
    /* the heading over a table already stands 32 clear of it */
    margin:          0 0 var(--space-lg);
    border:          0;
    border-collapse: collapse;

    th,
    td {
        padding:        10px 14px;
        font:           var(--text-16or);
        color:          var(--color-grey);
        text-align:     left;
        /* Rows are as tall as their longest cell; centring leaves the
           short cells floating against wrapped neighbours, so every cell
           starts at the top. */
        vertical-align: top;

        /* the columns' 23px inset from the table's edges */
        &:first-child {
            padding-left: 23px;
        }

        &:last-child {
            padding-right: 23px;
        }
    }

    /* The header row. TinyMCE's Table button builds every row out of
       <td>, so a table the client made by hand has no <th> at all; where
       there is no header cell anywhere, the first row stands in for one.
       And only the table's own first row, not the opening row of every
       section: a plain `tr:first-child` also matches the first row inside
       <tbody>, so a table split into <thead> + <tbody> would come out
       with two header rows – use the thead when there is one, the first
       tbody otherwise. (Both lessons inherited from the Cathedral build.) */
    th,
    &:not(:has(th)) > thead:first-of-type > tr:first-child > td,
    &:not(:has(th)):not(:has(thead)) > tbody:first-of-type > tr:first-child > td {
        padding-top:    8.5px;
        padding-bottom: 8.5px;
        font:           var(--text-24or);
        color:          var(--table-accent-text);
        background:     var(--table-accent);
        /* a title that wraps stays centred beside one that does not */
        vertical-align: middle;
    }

    /* The first row under the header stands 23 clear of the band – its
       copy 33 below it (Frame 259 at 171.3 under a band ending at 138).
       Which row that is depends on what the header is: a thead's row, so
       the tbody's first; or the table's own first row, so its second. */
    &:has(thead) > tbody:first-of-type > tr:first-child > td,
    &:not(:has(thead)) > tbody:first-of-type > tr:nth-child(2) > td {
        padding-top: 33px;
    }

    /* Alternate body rows on the cream band, the first row under the
       header plain: the tbody's even rows under a thead, or the table's
       3rd, 5th, 7th… where its own first row is the header. */
    &:has(thead) > tbody > tr:nth-child(even) > td,
    &:not(:has(thead)) > tbody:first-of-type > tr:nth-child(2n+3) > td {
        background: var(--color-cream);
    }
}

/* ── The Formats dropdown's table (Navy Table) ──
   The design draws one table, so the dropdown offers one: it restates
   what an unclassed table already renders, so a table always has its
   entry in the list. */
.table-navy {
    --table-accent:      var(--color-navy);
    --table-accent-text: var(--color-white);
}

/* The bar under a table wider than the page (js/utilities/table.js draws
   it). A phone and a Mac trackpad show the native scrollbar only while
   the table is being scrolled, so nothing said the table went on past the
   edge (Charlie, 2026-10-29, found on The Hall School). This one is in
   view whenever the table overflows: a 4px track in the table's ink at
   15%, the thumb – the visible share of the table – in the ink, 8 under
   the table (inside its margin). Drag the thumb or click the track.
   The ink is the table's own header colour, which table.js hands the
   bar and the wrapper as --table-scroll-ink, so a table in a colour
   variant gets a bar in that colour (Charlie, 2026-11-04, found on
   Burlington: four variants, one bar colour); a pale header gives its
   titles' colour instead, which stays visible. The black is the
   fallback for a bar the script has not reached.
   It takes no room: .tableScroll is an empty line after the wrapper and
   draws the track up into the space under the table, which table.js
   measures into --table-scroll-room – so nothing on the page moves when
   it appears, whatever margins the table has. The native bar is hidden
   only where the script has put this one in place, so without JS the
   table still scrolls with it. */
.table-responsive.has-scroll-bar {
    scrollbar-width: none;

    &::-webkit-scrollbar {
        display: none;
    }

    &:focus-visible {
        outline:        2px solid var(--table-scroll-ink, var(--color-navy));
        outline-offset: 2px;
    }
}

.tableScroll {
    position:     relative;
    height:       0;
    cursor:       pointer;
    touch-action: none;

    &[hidden] {
        display: none;
    }

    /* the track and the thumb on one line, 8 under the table */
    &::before,
    .tableScrollThumb {
        position:      absolute;
        top:           calc(8px - var(--table-scroll-room, 0px));
        height:        4px;
        border-radius: 2px;
    }

    &::before {
        content:    '';
        left:       0;
        right:      0;
        background: color-mix(in srgb, var(--table-scroll-ink, var(--color-navy)) 15%, transparent);
    }

    .tableScrollThumb {
        left:       0;
        background: var(--table-scroll-ink, var(--color-navy));
        cursor:     grab;

        &.is-dragging {
            cursor: grabbing;
        }
    }
}

/* Room for a table's shadow. Bootstrap's .table-responsive scrolls
   sideways, and a box that scrolls one way clips both, so a header band
   with a shadow is sliced along its top and at both ends (Brakenmoor's
   embossed header, 2026-11-05). A site whose table casts one sets the
   reach – offset + 1.5 × blur, the shadow's tail – as --table-room-y and,
   sideways, half the phone gutter (--table-room-x): the wrapper's box
   grows by that much and an equal negative margin puts the table back,
   so nothing on the page moves. The design's table casts none. */
.table-responsive:has(> table) {
    margin:  calc(-1 * var(--table-room-y, 0px)) calc(-1 * var(--table-room-x, 0px));
    padding: var(--table-room-y, 0px) var(--table-room-x, 0px);
}

/* The floor that makes the wrapper's sideways scroll actually happen:
   width: 100% alone lets a phone screen crush the columns to a word per
   line – the table never outgrows the wrapper, so overflow-x has nothing
   to do. Floors scale with the column count; a 2-column table fits any
   screen unaided. */
.table-responsive > table {
    &:has(tr > :nth-child(3)) {
        min-width: 640px;
    }

    &:has(tr > :nth-child(5)) {
        min-width: 900px;
    }
}
