/*
 * TPAL table styles.
 *
 * The default style should make ordinary Gutenberg tables look intentional.
 * Named block styles add stronger assumptions for ledgers, compact data, and
 * prose comparisons.
 */

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table {
	--tpal-table-blue: var(--wp--preset--color--brand-blue, #1133AF);
	--tpal-table-text: #111827;
	--tpal-table-muted: #4b5563;
	--tpal-table-border: rgba(17, 24, 39, 0.11);
	--tpal-table-blue-border: rgba(17, 51, 175, 0.18);
	--tpal-table-blue-wash: rgba(17, 51, 175, 0.06);
	--tpal-table-row-wash: rgba(17, 24, 39, 0.025);
	--tpal-table-shadow: 0 2px 8px rgba(12, 23, 67, 0.06);
	margin-block: 2rem;
	max-width: 100%;
	overflow-x: auto;
	position: relative;
	-webkit-overflow-scrolling: touch;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table:not(.is-style-tpa-comparison):not(.is-style-tpa-plain) {
	font-variant-numeric: tabular-nums;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table table {
	width: 100%;
	min-width: 100%;
	border-collapse: separate;
	border-spacing: 0;
	table-layout: auto;
	background: #ffffff;
	border: 1px solid var(--tpal-table-blue-border);
	border-radius: 8px;
	box-shadow: var(--tpal-table-shadow);
	color: var(--tpal-table-text);
	font-family: var(--wp--preset--font-family--source-serif-4, "Source Serif 4", Georgia, serif);
	font-size: 0.98rem;
	line-height: 1.45;
	overflow: hidden;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table table.has-fixed-layout {
	table-layout: auto;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table :is(th, td) {
	padding: 0.78rem 0.95rem;
	border: 0;
	border-bottom: 1px solid var(--tpal-table-border);
	vertical-align: top;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table :is(th, td) + :is(th, td) {
	border-left: 1px solid rgba(17, 24, 39, 0.055);
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table thead :is(th, td) {
	background: var(--tpal-table-blue-wash);
	color: var(--tpal-table-blue);
	font-family: var(--wp--preset--font-family--poppins, Poppins, sans-serif);
	font-size: 0.86rem;
	font-weight: 600;
	line-height: 1.35;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table:not(.tpal-table-no-sticky-header) thead :is(th, td) {
	position: sticky;
	top: 0;
	z-index: 3;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table:not(.tpal-table-no-sticky-first-column) tr > :is(th, td):first-child {
	position: sticky;
	left: 0;
	z-index: 2;
	background: #ffffff;
	box-shadow: 1px 0 0 rgba(17, 24, 39, 0.08);
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table:not(.tpal-table-no-sticky-first-column) tbody tr:nth-child(even) > :is(th, td):first-child {
	background: #fbfbfc;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table:not(.tpal-table-no-sticky-header):not(.tpal-table-no-sticky-first-column) thead tr > :is(th, td):first-child {
	z-index: 4;
	background: #f0f3ff;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table tbody tr:nth-child(even) :is(th, td) {
	background: var(--tpal-table-row-wash);
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table tbody tr:last-child :is(th, td) {
	border-bottom: 0;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table caption,
:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table figcaption {
	margin-top: 0.65rem;
	color: var(--tpal-table-muted);
	font-family: var(--wp--preset--font-family--poppins, Poppins, sans-serif);
	font-size: 0.86rem;
	line-height: 1.45;
	text-align: left;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table strong {
	font-weight: 700;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table:not(.is-style-tpa-comparison):not(.is-style-tpa-plain) thead :is(th, td) {
	border-bottom: 2px solid var(--tpal-table-blue);
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table:not(.is-style-tpa-comparison):not(.is-style-tpa-plain) :is(th, td):not(:first-child) {
	text-align: right;
	white-space: nowrap;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table:not(.is-style-tpa-comparison):not(.is-style-tpa-plain) :is(th, td):first-child {
	min-width: 12rem;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table:not(.is-style-tpa-comparison):not(.is-style-tpa-plain) tbody tr:last-child :is(th, td) {
	background: rgba(17, 51, 175, 0.09);
	color: #0b1f7a;
	font-family: var(--wp--preset--font-family--poppins, Poppins, sans-serif);
	font-weight: 600;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table:not(.is-style-tpa-comparison):not(.is-style-tpa-plain):not(.tpal-table-no-sticky-first-column) tbody tr:last-child > :is(th, td):first-child {
	background: #eef2ff;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table .tpa-chart-controls {
	position: sticky;
	top: 8px;
	right: 8px;
	display: flex;
	float: right;
	gap: 6px;
	width: max-content;
	margin-bottom: -32px;
	margin-left: auto;
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.15s ease, visibility 0.15s ease;
	z-index: 5;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table .tpa-chart-controls .tpa-chart-btn {
	width: 32px;
	height: 32px;
	border: 1px solid rgba(17, 51, 175, 0.25);
	border-radius: 8px;
	background: #ffffff;
	color: var(--tpal-color-primary, var(--tpal-table-blue));
	display: grid;
	place-items: center;
	cursor: pointer;
	padding: 0;
	outline: none;
	box-shadow: 0 8px 22px rgba(12, 23, 67, 0.15);
	transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table .tpa-chart-controls .tpa-chart-btn svg {
	width: 18px;
	height: 18px;
	stroke: currentColor;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table .tpa-chart-controls .tpa-chart-btn:hover,
:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table .tpa-chart-controls .tpa-chart-btn:focus-visible {
	background: var(--tpal-color-primary, var(--tpal-table-blue));
	color: #ffffff;
	border-color: transparent;
	box-shadow: 0 14px 30px rgba(12, 23, 67, 0.25);
	transform: translateY(-1px);
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table .tpa-chart-controls .tpa-chart-btn:focus-visible {
	outline: 3px solid rgba(17, 51, 175, 0.25);
	outline-offset: 2px;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table .tpa-chart-flash {
	position: absolute;
	top: 48px;
	right: 8px;
	background: #f5f7ff;
	color: var(--tpal-color-primary, var(--tpal-table-blue));
	border: 1px solid rgba(17, 51, 175, 0.2);
	border-radius: 8px;
	padding: 6px 10px;
	font-family: var(--wp--preset--font-family--poppins, Poppins, sans-serif);
	font-size: 12px;
	line-height: 1.3;
	box-shadow: 0 8px 22px rgba(12, 23, 67, 0.18);
	opacity: 0;
	transform: translateY(-4px);
	transition: opacity 0.2s ease, transform 0.2s ease;
	pointer-events: none;
	white-space: nowrap;
	z-index: 6;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table .tpal-table-search {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	margin: 0 0 0.75rem;
	font-family: var(--wp--preset--font-family--poppins, Poppins, sans-serif);
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table .tpal-table-search input[type="search"] {
	width: min(20rem, 100%);
	border: 1px solid rgba(17, 51, 175, 0.22);
	border-radius: 8px;
	background: #ffffff;
	color: var(--tpal-table-text);
	font: inherit;
	font-size: 0.9rem;
	line-height: 1.3;
	padding: 0.55rem 0.7rem;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table .tpal-table-search input[type="search"]:focus {
	border-color: var(--tpal-table-blue);
	box-shadow: 0 0 0 3px rgba(17, 51, 175, 0.14);
	outline: none;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table .tpal-table-search-status {
	color: var(--tpal-table-muted);
	font-size: 0.82rem;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table .tpal-table-sort-button {
	display: inline-flex;
	align-items: center;
	justify-content: inherit;
	gap: 0.35rem;
	width: 100%;
	border: 0;
	background: transparent;
	color: inherit;
	cursor: pointer;
	font: inherit;
	font-weight: inherit;
	line-height: inherit;
	padding: 0;
	text-align: inherit;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table .tpal-table-sort-button::after {
	content: "";
	width: 0;
	height: 0;
	border-left: 4px solid transparent;
	border-right: 4px solid transparent;
	border-top: 5px solid currentColor;
	opacity: 0.38;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table th[aria-sort="ascending"] .tpal-table-sort-button::after,
:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table td[aria-sort="ascending"] .tpal-table-sort-button::after {
	border-top: 0;
	border-bottom: 5px solid currentColor;
	opacity: 1;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table th[aria-sort="descending"] .tpal-table-sort-button::after,
:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table td[aria-sort="descending"] .tpal-table-sort-button::after {
	opacity: 1;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table .tpal-table-scroll-hint {
	display: none;
	position: sticky;
	right: 0.5rem;
	bottom: 0.5rem;
	float: right;
	margin-top: -2rem;
	background: rgba(17, 51, 175, 0.92);
	color: #ffffff;
	border-radius: 8px;
	box-shadow: 0 8px 22px rgba(12, 23, 67, 0.18);
	font-family: var(--wp--preset--font-family--poppins, Poppins, sans-serif);
	font-size: 0.78rem;
	line-height: 1.2;
	padding: 0.35rem 0.5rem;
	pointer-events: none;
	z-index: 7;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table .tpal-table-scroll-hint::after {
	content: " ->";
}

/* Financial/legal tables where the first column labels rows and the rest are figures. */
:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-ledger table {
	min-width: 42rem;
	font-variant-numeric: tabular-nums;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-ledger thead :is(th, td) {
	border-bottom: 2px solid var(--tpal-table-blue);
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-ledger :is(th, td):not(:first-child) {
	text-align: right;
	white-space: nowrap;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-ledger :is(th, td):first-child {
	min-width: 12rem;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-ledger tbody tr:last-child :is(th, td) {
	background: rgba(17, 51, 175, 0.09);
	color: #0b1f7a;
	font-family: var(--wp--preset--font-family--poppins, Poppins, sans-serif);
	font-weight: 600;
}

/* Dense supporting data. */
:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-compact {
	margin-block: 1.5rem;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-compact table {
	font-size: 0.88rem;
	line-height: 1.35;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-compact :is(th, td) {
	padding: 0.5rem 0.65rem;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-compact caption,
:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-compact figcaption {
	font-size: 0.8rem;
}

/* Prose-heavy side-by-side comparisons. */
:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-comparison table {
	min-width: 38rem;
	table-layout: fixed;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-comparison :is(th, td):not(:first-child) {
	text-align: left;
	white-space: normal;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-comparison :is(th, td):first-child {
	min-width: 0;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-comparison thead :is(th, td) {
	background: var(--tpal-table-blue);
	color: #ffffff;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-comparison tbody :is(th, td) {
	background: #ffffff;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-comparison tbody tr:nth-child(even) :is(th, td) {
	background: rgba(17, 51, 175, 0.035);
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-comparison:not(.tpal-table-no-sticky-first-column) tr > :is(th, td):first-child {
	background: #ffffff;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-comparison:not(.tpal-table-no-sticky-first-column) tbody tr:nth-child(even) > :is(th, td):first-child {
	background: #f6f8ff;
}

/* Quiet escape hatch for tables that should not draw much attention. */
:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-plain table {
	background: transparent;
	border-color: rgba(17, 24, 39, 0.14);
	border-radius: 0;
	box-shadow: none;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-plain thead :is(th, td) {
	background: transparent;
	color: var(--tpal-table-text);
	border-bottom: 2px solid rgba(17, 24, 39, 0.2);
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-plain tbody tr:nth-child(even) :is(th, td) {
	background: transparent;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-plain :is(th, td):not(:first-child) {
	text-align: left;
	white-space: normal;
}

:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.is-style-tpa-plain :is(th, td):first-child {
	min-width: 0;
}

@media (max-width: 640px) {
	:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table {
		margin-block: 1.5rem;
		margin-inline: -0.15rem;
		padding-bottom: 0.25rem;
	}

	:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table table {
		font-size: 0.9rem;
	}

	:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table :is(th, td) {
		padding: 0.65rem 0.75rem;
	}

	:where(.wp-block-post-content, .editor-styles-wrapper) .wp-block-table.tpal-table-is-scrollable:not(.tpal-table-has-scrolled) .tpal-table-scroll-hint {
		display: block;
	}
}

@media print {
	.wp-block-table {
		overflow: visible !important;
		break-inside: auto;
	}

	.wp-block-table .tpa-chart-controls,
	.wp-block-table .tpa-chart-flash,
	.wp-block-table .tpal-table-search,
	.wp-block-table .tpal-table-scroll-hint {
		display: none !important;
	}

	.wp-block-table table {
		box-shadow: none !important;
	}

	.wp-block-table thead {
		display: table-header-group;
	}

	.wp-block-table tr {
		break-inside: avoid;
	}
}
