/* ──────────────────────────────────────────────────────────────────────────
   Table block — optional heading + intro + striped table. Tokens only.

   Two paths share this file:
   - legacy: .uw-tbl__head + .uw-tbl__scroll > table.uw-tbl__table
   - inline: .uw-tbl__flow > h2 + p + figure.wp-block-table.uw-tbl__table
   Inline's <figure> plays .uw-tbl__scroll's role. .wp-block-table is listed
   alongside .uw-tbl__table so a re-inserted table (lost className) still
   looks right.
   ────────────────────────────────────────────────────────────────────────── */

.uw-tbl {
	background: var(--wp--preset--color--white);
	color: var(--wp--preset--color--deep-navy);
}
.uw-tbl--bg-porcelain {
	background: var(--wp--preset--color--porcelain);
}
.uw-tbl__inner {
	position: relative;
	padding-top: clamp(48px, 6vw, 100px);
	padding-bottom: clamp(48px, 6vw, 100px);
	display: flex;
	flex-direction: column;
	gap: clamp(2rem, 3vw, 48px);
}
/* Optional top border, matching the content width only — excludes the left/right padding. */
.uw-tbl--top-border .uw-tbl__inner::before {
	content: '';
	position: absolute;
	top: 0;
	left: clamp(24px, 4.94vw, 80px);
	right: clamp(24px, 4.94vw, 80px);
	height: 1px;
	background: color-mix(in srgb, var(--wp--preset--color--deep-navy) 10%, transparent);
}
.uw-tbl__head {
	display: flex;
	justify-content: space-between;
	gap: clamp(2rem, 6vw, 15%);
	flex-wrap: wrap;
	align-items: stretch;
}
.uw-tbl__heading {
	flex: 0 1 50%;
	margin: 0;
	font-family: var(--wp--preset--font-family--marr-sans-cond);
	font-weight: 600;
	font-size: clamp(40px, 5vw, var(--wp--preset--font-size--heading-3));
	line-height: 1;
	letter-spacing: -0.01em;
}
.uw-tbl__body {
	flex: 0 1 35%;
	margin: 0;
	font-family: var(--wp--preset--font-family--pp-mori);
	font-weight: 400;
	font-size: var(--wp--preset--font-size--heading-7);
	line-height: 1.3;
}

/* ── Inline layout ──────────────────────────────────────────────────────────
   Replaces .uw-tbl__head + .uw-tbl__scroll. Grid, not flex: the heading
   spans both paragraph rows (grid-row: 1 / 3) so its height doesn't force
   row 1 to match it — flex can't do this, an item lives on one line only.
   Descendant combinators, never `>`: the editor wraps inner blocks in extra
   divs that `>` would break on. */
.uw-tbl__flow {
	display: grid;
	grid-template-columns: 50% 42%;
	justify-content: space-between;
	column-gap: clamp(2rem, 6vw, 15%);
	row-gap: 0;
	align-items: start;
}
.uw-tbl__flow .uw-tbl__heading {
	grid-column: 1;
	grid-row: 1 / 3;
}
.uw-tbl__flow .uw-tbl__body {
	grid-column: 2;
	grid-row: 1;
}
/* Any paragraph typed into the intro, not just the seeded .uw-tbl__body one. */
.uw-tbl__inner p {
	grid-column: 2;
}
/* A 2nd/3rd paragraph stacks below the first at a smaller size. grid-row:
   auto (not a fixed number) so each extra one gets its own row. */
.uw-tbl__inner p ~ p,
.uw-tbl__flow .uw-tbl__body ~ .uw-tbl__body {
	grid-row: auto;
	margin-top: 0;
	font-size: var(--wp--preset--font-size--extra-small);
}
/* No heading: swap track order so the intro sits flush left instead of
   floating in column 2. contenteditable keeps an empty canvas placeholder
   counting as "a heading" so layout doesn't jump while typing. */
.uw-tbl__flow:not(:has(.uw-tbl__heading:not(:empty), .uw-tbl__heading[contenteditable])) {
	grid-template-columns: 42% 50%;
}
.uw-tbl__flow:not(:has(.uw-tbl__heading:not(:empty), .uw-tbl__heading[contenteditable])) .uw-tbl__body,
.uw-tbl__flow:not(:has(.uw-tbl__heading:not(:empty), .uw-tbl__heading[contenteditable])) p {
	grid-column: 1;
}
/* Margin reproduces the old head-to-scroll gap; also clears the <figure>'s
   UA-sheet margin (1em 40px) since this theme skips wp-block-styles. */
.uw-tbl__flow :is(.uw-tbl__table, .wp-block-table) {
	grid-column: 1 / -1;
	grid-row: auto;
	margin: clamp(2rem, 3vw, 48px) 0 0;
	overflow-x: auto;
	border-radius: 12px;
}
/* Heading and intro both empty: no gap above the table either. */
.uw-tbl__flow:not(:has(.uw-tbl__heading:not(:empty), .uw-tbl__heading[contenteditable])):not(:has(.uw-tbl__body:not(:empty), .uw-tbl__body[contenteditable])) :is(.uw-tbl__table, .wp-block-table) {
	margin-top: 0;
}
/* Hide an empty heading/intro; contenteditable keeps it visible/clickable
   on the canvas even while empty. */
.uw-tbl__heading:empty:not([contenteditable]),
.uw-tbl__body:empty:not([contenteditable]) {
	display: none;
}
/* Canvas wraps inner blocks in extra divs; make them transparent to the grid. */
.uw-tbl__flow > .block-editor-inner-blocks,
.uw-tbl__flow > .block-editor-inner-blocks > .block-editor-block-list__layout {
	display: contents;
}

/* ── Table ──────────────────────────────────────────────────────────────────
   The scroll/clip box: the legacy wrapper div, and core/table's <figure>. */
.uw-tbl__scroll {
	overflow-x: auto;
	border-radius: 12px;
}
/* The table box itself: `.uw-tbl__table` on the legacy path, the <figure>'s
   child <table> on the inline path. */
table.uw-tbl__table,
.uw-tbl :is(.uw-tbl__table, .wp-block-table) > table {
	width: 100%;
	border-collapse: collapse;
	border-radius: 12px;
	overflow: hidden;
	font-family: var(--wp--preset--font-family--pp-mori);
	table-layout: fixed;
}

/* Neutralise core's block-library table CSS, which the legacy markup never met:
   `.wp-block-table td,.wp-block-table th{border:1px solid}` would draw a
   currentColor grid around every cell, and thead/tfoot would gain 3px rules.
   These sit before the per-cell rules so the border-right below still lands. */
.uw-tbl :is(.uw-tbl__table, .wp-block-table) :is(th, td) {
	border: 0;
}
.uw-tbl :is(.uw-tbl__table, .wp-block-table) thead {
	border-bottom: 0;
}
.uw-tbl :is(.uw-tbl__table, .wp-block-table) tfoot {
	border-top: 0;
}

/* Every rule below is prefixed with .uw-tbl to clear theme.json's
   styles.blocks["core/table"].css, which applies to this block for the first
   time. `text-transform` and `vertical-align` are declared here only because
   theme.json sets uppercase/middle and the legacy table used neither.
   `word-break: normal` is the initial value; it is stated so a table
   re-inserted with core's hasFixedLayout default does not start hyphenating. */
.uw-tbl :is(.uw-tbl__table, .wp-block-table) thead th {
	font-family: var(--wp--preset--font-family--marr-sans-cond);
	font-weight: 600;
	font-size: var(--wp--preset--font-size--body);
	letter-spacing: 0.02em;
	text-transform: none;
	word-break: normal;
	color: var(--wp--preset--color--white);
	padding: 16px 24px;
	border-right: 1px solid #fff;
}
.uw-tbl :is(.uw-tbl__table, .wp-block-table) thead th:last-child {
	border-right: 0;
}
.uw-tbl--blue :is(.uw-tbl__table, .wp-block-table) thead th {
	background: var(--wp--preset--color--cobalt-blue);
}
.uw-tbl--navy :is(.uw-tbl__table, .wp-block-table) thead th {
	background: var(--wp--preset--color--deep-navy);
}

.uw-tbl :is(.uw-tbl__table, .wp-block-table) tbody td {
	padding: 24px;
	font-size: var(--wp--preset--font-size--extra-small);
	color: var(--wp--preset--color--deep-navy);
	vertical-align: inherit;
	word-break: normal;
	border-right: 1px solid #fff;
}
.uw-tbl :is(.uw-tbl__table, .wp-block-table) tbody td:first-child {
	font-weight: 600;
}
.uw-tbl :is(.uw-tbl__table, .wp-block-table) tbody td:last-child {
	border-right: 0;
}
.uw-tbl :is(.uw-tbl__table, .wp-block-table) tbody tr:nth-child(odd) {
	background: #F5F5F5;
}
.uw-tbl :is(.uw-tbl__table, .wp-block-table) tbody tr:nth-child(even) {
	background: #FBFBFB;
}

.uw-tbl--bg-porcelain :is(.uw-tbl__table, .wp-block-table) tbody tr:nth-child(odd) {
	background: #F1F0ED;
}
.uw-tbl--bg-porcelain :is(.uw-tbl__table, .wp-block-table) tbody tr:nth-child(even) {
	background: #E7E6E3;
}

/* Per-column alignment. The legacy render stamped a uw-tbl__th-- / uw-tbl__td--
   class on every cell from the headers repeater, defaulting to center;
   core/table stamps has-text-align-* from the same per-cell control. Both are
   honoured, and both must out-rank the center default just above them. */
.uw-tbl :is(.uw-tbl__table, .wp-block-table) :is(th, td) {
	text-align: center;
}
.uw-tbl :is(.uw-tbl__table, .wp-block-table) .uw-tbl__th--center,
.uw-tbl :is(.uw-tbl__table, .wp-block-table) .uw-tbl__td--center,
.uw-tbl :is(.uw-tbl__table, .wp-block-table) .has-text-align-center {
	text-align: center;
}
.uw-tbl :is(.uw-tbl__table, .wp-block-table) .uw-tbl__th--left,
.uw-tbl :is(.uw-tbl__table, .wp-block-table) .uw-tbl__td--left,
.uw-tbl :is(.uw-tbl__table, .wp-block-table) .has-text-align-left {
	text-align: left;
}
.uw-tbl :is(.uw-tbl__table, .wp-block-table) .has-text-align-right {
	text-align: right;
}

/* ── Mobile ── */
@media (max-width: 700px) {
	.uw-tbl :is(.uw-tbl__table, .wp-block-table) thead th,
	.uw-tbl :is(.uw-tbl__table, .wp-block-table) tbody td {
		padding: 12px 14px;
		font-size: 14px;
	}
	.uw-tbl__heading {
		font-size: clamp(32px, 9vw, 48px);
	}
	table.uw-tbl__table,
	.uw-tbl :is(.uw-tbl__table, .wp-block-table) > table {
		width: 800px;
	}
	.uw-tbl__head {
		flex-direction: column;
	}
	/* Single column below this width. */
	.uw-tbl__flow,
	.uw-tbl__flow:not(:has(.uw-tbl__heading:not(:empty), .uw-tbl__heading[contenteditable])) {
		grid-template-columns: minmax(0, 1fr);
	}
	.uw-tbl__flow .uw-tbl__heading,
	.uw-tbl__flow .uw-tbl__body,
	.uw-tbl__inner p {
		grid-column: 1;
		grid-row: auto;
	}
	.uw-tbl__flow .uw-tbl__body,
	.uw-tbl__inner p {
		margin-top: 2rem;
	}
	/* No heading: no gap above the first paragraph. :not(p ~ p) still lets a
	   2nd/3rd paragraph keep its own stacking gap. */
	.uw-tbl__flow:not(:has(.uw-tbl__heading:not(:empty), .uw-tbl__heading[contenteditable])) .uw-tbl__body,
	.uw-tbl__flow:not(:has(.uw-tbl__heading:not(:empty), .uw-tbl__heading[contenteditable])) p:not(p ~ p) {
		margin-top: 0;
	}
}
