/* ============================================================
 * Axismundi — table surfaces.
 *
 * Handles WordPress core/table internals only. Raw HTML table semantics live in
 * the theme's global style.css. theme.json owns the editable source for
 * core/table, but WordPress core ships strong cell borders and thead/tfoot
 * separators; those need explicit selector-level reset here to get a single
 * Material grid.
 * ============================================================ */

.wp-block-table .has-fixed-layout {
	inline-size: 100%;
	table-layout: fixed;
}

/* Force border-collapse: separate so the table's structured border-radius
 * actually rounds the frame. Core ships `.wp-block-table table { border-collapse:
 * collapse }` at class specificity (0,2,0), which the theme.json css :where()
 * slot (0,1,0) cannot beat — and a collapsed-border table ignores border-radius
 * entirely (the frame paints square and even escapes an ancestor's rounded clip).
 * With separate + border-spacing 0 the cells stay flush (single-sided cell
 * borders already avoid doubling) and the table border rounds. */
.wp-block-table table {
	border-collapse: separate;
	border-spacing: 0;
}

/* Core/table reset.
 *
 * Core ships:
 *   .wp-block-table td, .wp-block-table th { border: 1px solid; }
 *   .wp-block-table thead { border-bottom: 3px solid; }
 *   .wp-block-table tfoot { border-top: 3px solid; }
 * Reset those so the table element owns the frame and cells draw only the M3
 * internal grid. */
.wp-block-table table :is(th, td) {
	box-sizing: border-box;
	background-clip: padding-box;
	text-align: start;
	vertical-align: top;
	padding-block: var(--wp--preset--spacing--150);
	padding-inline: var(--wp--preset--spacing--200);
	border: 0;
	border-block-end: 1px solid var(--wp--preset--color--outline-variant);
	border-inline-end: 1px solid var(--wp--preset--color--outline-variant);
}

.wp-block-table.is-style-stripes table :is(th, td) {
	background-clip: border-box;
}

.wp-block-table table tr > :is(th, td):last-child {
	border-inline-end: 0;
}

.wp-block-table table tbody tr:last-child > :is(th, td) {
	border-block-end: 0;
}

.wp-block-table table thead :is(th, td) {
	border-block-end: 1px solid var(--wp--preset--color--outline);
}

.wp-block-table table thead tr:first-child > :is(th, td):first-child {
	border-start-start-radius: 7px;
}

.wp-block-table table thead tr:first-child > :is(th, td):last-child {
	border-start-end-radius: 7px;
}

/* Round the bottom corners of the last visual row (tfoot if present, else the
 * last tbody row) to match the frame's 8px radius — so a coloured last row
 * (e.g. stripes) fills cleanly into the rounded corner instead of poking a
 * square edge past it. */
.wp-block-table table > :last-child tr:last-child > :is(th, td):first-child {
	border-end-start-radius: 7px;
}

.wp-block-table table > :last-child tr:last-child > :is(th, td):last-child {
	border-end-end-radius: 7px;
}

.wp-block-table table tfoot tr:first-child > :is(th, td) {
	border-block-start: 1px solid var(--wp--preset--color--outline);
}

.wp-block-table table tfoot tr:last-child > :is(th, td) {
	border-block-end: 0;
}

.wp-block-table thead {
	border-block-end: 0;
}

.wp-block-table tfoot {
	border-block-start: 0;
}

/* WordPress core intentionally propagates table border controls to rows and
 * cells via `table[style*=border-*]` selectors. Keep the user's selected table
 * frame editable, but preserve Axismundi's 1px internal M3 grid. */
.wp-block-table table[style*="border-width"] tr > :is(th, td),
.wp-block-table table[style*="border-style"] tr > :is(th, td),
.wp-block-table table[style*="border-color"] tr > :is(th, td) {
	border-block-start: 0;
	border-inline-start: 0;
	border-block-end: 1px solid var(--wp--preset--color--outline-variant);
	border-inline-end: 1px solid var(--wp--preset--color--outline-variant);
}

.wp-block-table table[style*="border-width"] tr > :is(th, td):last-child,
.wp-block-table table[style*="border-style"] tr > :is(th, td):last-child,
.wp-block-table table[style*="border-color"] tr > :is(th, td):last-child {
	border-inline-end: 0;
}

.wp-block-table table[style*="border-width"] tbody tr:last-child > :is(th, td),
.wp-block-table table[style*="border-style"] tbody tr:last-child > :is(th, td),
.wp-block-table table[style*="border-color"] tbody tr:last-child > :is(th, td) {
	border-block-end: 0;
}

.wp-block-table table[style*="border-width"] thead :is(th, td),
.wp-block-table table[style*="border-style"] thead :is(th, td),
.wp-block-table table[style*="border-color"] thead :is(th, td) {
	border-block-end: 1px solid var(--wp--preset--color--outline);
}

.wp-block-table table[style*="border-width"] tfoot tr:first-child > :is(th, td),
.wp-block-table table[style*="border-style"] tfoot tr:first-child > :is(th, td),
.wp-block-table table[style*="border-color"] tfoot tr:first-child > :is(th, td) {
	border-block-start: 1px solid var(--wp--preset--color--outline);
}

.wp-block-table table[style*="border-width"] tfoot tr:last-child > :is(th, td),
.wp-block-table table[style*="border-style"] tfoot tr:last-child > :is(th, td),
.wp-block-table table[style*="border-color"] tfoot tr:last-child > :is(th, td) {
	border-block-end: 0;
}

/* core/table's built-in stripes variation paints a literal #f0f0f0 bottom
 * border on the FIGURE. theme.json's core/table root maps to the inner table,
 * so only this parent reset stays in CSS; the row/cell stripe styling lives in
 * `styles.blocks.core/table.variations.stripes.css`.
 */
.wp-block-table.is-style-stripes {
	border-block-end: 0;
}

/* core/calendar — align the generated calendar table with the M3 table frame.
 *
 * core/calendar is not a .wp-block-table, so the contract above never reaches it.
 * theme.json owns its ink (styles.blocks.core/calendar.color.text -> on-surface,
 * via core's "table, th" selector) and the generic table baseline already gives
 * the OUTER frame an outline-variant border — but core paints a hardcoded,
 * non-scheme-aware #ddd on every th/td side, which reads as light gridlines on a
 * dark surface. core/calendar has no border support in theme.json, so the radius
 * and gridline model live here: separate borders for a real rounded frame, then
 * single-sided cell borders to avoid doubled internal gridlines. */
.wp-block-calendar table {
	border-collapse: separate;
	border-spacing: 0;
	overflow: hidden;
}

.wp-block-calendar.wp-block-calendar :where(table) :is(th, td) {
	border: 0;
	border-block-end: 1px solid var(--wp--preset--color--outline-variant);
	border-inline-end: 1px solid var(--wp--preset--color--outline-variant);
	padding-block: var(--wp--preset--spacing--100);
	padding-inline: var(--wp--preset--spacing--200);
}

.wp-block-calendar.wp-block-calendar :where(table) tr > :is(th, td):last-child {
	border-inline-end: 0;
}

.wp-block-calendar.wp-block-calendar :where(table) tbody tr:last-child > :is(th, td) {
	border-block-end: 0;
}

.wp-block-calendar.wp-block-calendar :where(table) thead :is(th, td) {
	border-block-end: 1px solid var(--wp--preset--color--outline);
}

.wp-block-calendar.wp-block-calendar :where(table) thead tr:first-child > :is(th, td):first-child {
	border-start-start-radius: 7px;
}

.wp-block-calendar.wp-block-calendar :where(table) thead tr:first-child > :is(th, td):last-child {
	border-start-end-radius: 7px;
}

.wp-block-calendar.wp-block-calendar :where(table) tbody tr:last-child > :is(th, td):first-child {
	border-end-start-radius: 7px;
}

.wp-block-calendar.wp-block-calendar :where(table) tbody tr:last-child > :is(th, td):last-child {
	border-end-end-radius: 7px;
}
