/**
 * Comparison Table Block Styles
 *
 * Feature-comparison matrix with an optional highlighted column.
 *
 * @package TMW_Core_Child
 * @since 1.0.0
 */

@import url("../../assets/css/src/components/comparison-icons.css");

/* Block -------------------------------------------------------------------- */

.comparison-table {
	width: 100%;
}

.comparison-table__inner {
	display: flex;
	flex-direction: column;
}

/* The parent theme's .section-subtitle is built for centered section headers:
   margin-left/right: auto plus a max-width narrower than the container. In
   this left-aligned block that both centers the intro copy and wraps it short
   of the table's width. */
.comparison-table .comparison-table__subtitle {
	max-width: none;
	margin-top: var(--space-sm);
	margin-left: 0;
	margin-right: 0;
}

/* Scroll container --------------------------------------------------------- */

/* The table has a min-width, so on narrow viewports it scrolls horizontally
   inside this container rather than forcing the page body to scroll. */
.comparison-table__scroll {
	margin-top: var(--space-xl);
	overflow-x: auto;

	/* Momentum scrolling on iOS. */
	-webkit-overflow-scrolling: touch;
}

/* The container is focusable so keyboard users can scroll it; that focus must
   be visible. Uses the design system's focus shadow rather than suppressing
   the ring, which would be an accessibility regression. */
.comparison-table__scroll:focus-visible {
	outline: 2px solid var(--color-primary);
	outline-offset: 2px;
}

/* Table -------------------------------------------------------------------- */

.comparison-table__table {
	width: 100%;
	min-width: 640px; /* Below this the columns become unreadable; scroll instead. */
	border-collapse: collapse;
	background-color: transparent;
}

/* Header cells ------------------------------------------------------------- */

.comparison-table__feature-head,
.comparison-table__col-head,
.comparison-table__col-head th {
	padding: var(--space-xs) var(--space-md);
	text-transform: uppercase;
	color: var(--color-text-primary);
	vertical-align: bottom;
	border-bottom: 2px solid var(--color-primary);
}

.comparison-table__feature-head {
	font-family: var(--font-family-heading);
	font-weight: var(--font-weight-normal);
	text-align: left;
}

.comparison-table__col-head {
	text-align: center;
}

.comparison-table__table thead tr {
	border-bottom: 2px solid var(--color-border-light);
}

/* The column label is the product name — reads as a name, not a shouted
   label, so it opts out of the uppercase treatment above. */
.comparison-table__col-label {
	display: block;
	margin-bottom: var(--space-3xs);
	font-family: var(--font-family-heading);
	font-weight: var(--font-weight-semibold);
	text-transform: none;
	letter-spacing: 0;
	line-height: var(--line-height-body);
	color: var(--color-primary);
}

.comparison-table__col-sublabel {
	display: block;
	font-size: var(--font-size-small);
	font-weight: var(--font-weight-normal);
	text-transform: none;
	letter-spacing: 0;
	line-height: var(--line-height-body);
	color: var(--color-text-primary);
}

/* Highlighted column ------------------------------------------------------- */

/* The "ours" column is tinted the full height of the table so the eye can
   track it down the rows. */
.comparison-table__col-head.is-highlighted {
	background-color: var(--color-accent);
	border-top: 3px solid var(--color-primary);
	border-radius: var(--radius-sm) var(--radius-sm) 0 0;
	min-width: 125px;
}

.comparison-table__cell.is-highlighted {
	background-color: var(--color-accent);
}

/* Body cells --------------------------------------------------------------- */

.comparison-table__table tbody tr {
	border-bottom: 1px solid var(--color-border);
}

.comparison-table__row-head {
	padding: var(--space-sm) var(--space-md);
	font-family: var(--font-family-heading);
	font-weight: var(--font-weight-heading);
	color: var(--color-tertiary);
	text-align: left;
	vertical-align: middle;
	border-bottom: 1px solid var(--color-border);
}

.comparison-table__cell {
	padding: var(--space-xs) var(--space-md);
	text-align: center;
	vertical-align: middle;
	border-bottom: 1px solid var(--color-border-light);
}

.comparison-table__table tbody tr:last-child,
.comparison-table__table tbody tr:last-child .comparison-table__cell,
.comparison-table__table tbody tr:last-child .comparison-table__row-head {
	border-bottom: 0;
}

/* Status emphasis for text values. Sourced from the design system rather than
   the one-off oranges/reds the original inline markup used. */

/* Class name kept as --warning because it mirrors the stored field value;
   renaming it would orphan the emphasis on any already-saved table. */
.comparison-table__value--warning {
	color: var(--comparison-icon-qualified);
}

.comparison-table__value--negative {
	color: var(--comparison-icon-negative);
}

/* Footnote ----------------------------------------------------------------- */

.comparison-table__footnote {
	padding-top: var(--space-md);
	border-top: 1px solid var(--color-border-light);
	font-size: var(--font-size-small);
	font-style: italic;
	color: var(--color-text-primary);
}

.comparison-table__footnote > :last-child {
	margin-bottom: 0;
}

.comparison-table__footnote-text {
	margin: 0;
}

/* The per-cell column label only exists for the stacked mobile layout, where
   the header row is gone. On desktop the <thead> supplies it. */
.comparison-table__cell-label {
	display: none;
}

/* Icon key ----------------------------------------------------------------- */

/* Renders above the footnote text. Sits inline on one line where there is room
   and wraps to separate lines when there is not, rather than forcing a
   two-line list on wide screens. */
.comparison-table__key {
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-xs) var(--space-md);
	list-style: none;
	margin: 0;
	padding: 0;
}

/* Only spaces the two apart when both are present, so a key with no footnote
   text (or vice versa) does not leave a dangling gap. */
.comparison-table__key + .comparison-table__footnote-text {
	margin-top: var(--space-xs);
}

.comparison-table__key-item {
	display: flex;
	align-items: center;
	gap: var(--space-2xs);
	margin: 0;
}

/* The key is not italic even though the surrounding footnote is — it is a
   definition list rather than an aside, and italics hurt legibility at this
   size. */
.comparison-table__key-text {
	font-style: normal;
}

/* Dark section support ----------------------------------------------------- */

/* When the section background is dark, the tinted highlight column and the
   light hairline borders both stop working. Re-derive them from the current
   text color so the table stays legible instead of washing out. */
.comparison-table[data-section-dark-bg='true'] .comparison-table__col-label,
.comparison-table[data-section-dark-bg='true'] .comparison-table__col-sublabel,
.comparison-table[data-section-dark-bg='true'] .comparison-table__row-head,
.comparison-table[data-section-dark-bg='true'] .comparison-table__feature-head,
.comparison-table[data-section-dark-bg='true'] .comparison-table__col-head,
.comparison-table[data-section-dark-bg='true'] .comparison-table__footnote {
	color: var(--color-text-light);
}

.comparison-table[data-section-dark-bg='true'] .comparison-table__table thead tr,
.comparison-table[data-section-dark-bg='true'] .comparison-table__table tbody tr,
.comparison-table[data-section-dark-bg='true'] .comparison-table__footnote {
	border-color: color-mix(in srgb, var(--color-text-light) 30%, transparent);
}

.comparison-table[data-section-dark-bg='true'] .comparison-table__col-head.is-highlighted,
.comparison-table[data-section-dark-bg='true'] .comparison-table__cell.is-highlighted {
	background-color: color-mix(in srgb, var(--color-text-light) 12%, transparent);
}

.comparison-table[data-section-dark-bg='true'] .comparison-table__col-head.is-highlighted .comparison-table__col-label {
	color: var(--color-text-light);
}

/* Responsive: stacked cards ------------------------------------------------- */

/* Below 768px the matrix reflows to one card per feature rather than staying a
   640px-wide horizontal scroller.

   A 4-column clinical table in a horizontal scroll is poor on a phone: the
   feature name scrolls out of view, so a bare checkmark in the far-right
   column has nothing identifying either the row or the column it belongs to.
   Stacking keeps every value paired with both its feature (the card heading)
   and its column (the per-cell label).

   The table keeps its semantics — this only changes `display`, so the
   header/row associations remain intact for assistive tech. */
@media (width <= 768px) {
	/* No longer a scroller, so drop the focusable-region affordances: an
	   element that cannot scroll should not be a tab stop. The template still
	   emits them, so they are neutralised rather than removed. */
	.comparison-table__scroll {
		overflow-x: visible;
	}

	.comparison-table__table {
		min-width: 0;
	}

	/* `td` is deliberately excluded — it becomes a flex row below. Including it
	   here would win on specificity (0,2,1 beats the 0,1,0 of the class
	   selector) and silently flatten the label/value layout. */
	.comparison-table__table,
	.comparison-table__table tbody,
	.comparison-table__table tbody tr,
	.comparison-table__table tbody th {
		display: block;
		width: auto;
	}

	.comparison-table__table tbody td {
		width: auto;
	}

	/* The header row is redundant once each cell carries its own label, and
	   visually hiding it (rather than display:none) keeps it available to
	   screen readers that surface table headers. */
	.comparison-table__table thead {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip-path: inset(50%);
		white-space: nowrap;
	}

	/* Each feature becomes a card: grey heading, white value rows. Set
	   explicitly rather than left to inherit, so the card keeps its own
	   surface when the section behind it is coloured or dark. */
	.comparison-table__table tbody tr {
		margin-bottom: var(--space-md);
		background-color: var(--color-white);
		border: 1px solid var(--color-border-light);
		border-radius: var(--radius-card);
		overflow: hidden;
	}

	.comparison-table__table tbody tr:last-child {
		margin-bottom: 0;
		border-bottom: 1px solid var(--color-border-light);
	}

	/* Feature name is the card heading. */
	.comparison-table__row-head {
		padding: var(--space-sm) var(--space-md);
		background-color: var(--color-bg);
		border-bottom: 1px solid var(--color-border);
	}

	/* Value rows: label left, value right. */
	.comparison-table__cell {
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: var(--space-md);
		padding: var(--space-xs) var(--space-md);
		text-align: left;
		border-bottom: 1px solid var(--color-border-light);
	}

	.comparison-table__cell:last-child {
		border-bottom: 0;
	}

	/* The highlighted option keeps its tint on mobile. Stacked, it is no longer
	   a column the eye tracks downward, but it still marks which of the
	   compared options is ours — one tinted row per card, against the white
	   ones around it. The tint comes from the base .is-highlighted rule; only
	   the label colour is reinforced below. */

	/* An empty cell would collapse to a labelless sliver; keep the label
	   visible so the reader still sees the column was considered. */
	.comparison-table__cell-label {
		display: block;
		font-size: var(--font-size-small);
		font-weight: var(--font-weight-semibold);
		color: var(--color-text-primary);
	}

	.comparison-table__cell-value {
		display: inline-flex;
		align-items: center;
		flex-shrink: 0;
	}

	/* The stacked cards are white surfaces even inside a dark section, so the
	   light-text and light-border treatment applied above would make them
	   unreadable. Restore the normal palette within the card.

	   These must come AFTER the base .comparison-table__cell-label rule above:
	   both are single-class on the same element inside this media block, so
	   source order decides — placed earlier, the override would be dead code. */
	.comparison-table[data-section-dark-bg='true'] .comparison-table__row-head {
		color: var(--color-tertiary);
	}

	.comparison-table[data-section-dark-bg='true'] .comparison-table__cell-label {
		color: var(--color-text-primary);
	}

	.comparison-table[data-section-dark-bg='true'] .comparison-table__table tbody tr,
	.comparison-table[data-section-dark-bg='true'] .comparison-table__row-head,
	.comparison-table[data-section-dark-bg='true'] .comparison-table__cell {
		border-color: var(--color-border-light);
	}

	/* On a dark section the desktop rule tints the highlighted cell with a
	   translucent white wash, which is designed to sit on the dark background.
	   The stacked card is white, so that wash is invisible — restore the normal
	   blue tint so the highlighted option still reads as highlighted. */
	.comparison-table[data-section-dark-bg='true'] .comparison-table__cell.is-highlighted {
		background-color: var(--color-accent);
	}

	/* The highlight tint reads as a full-width band on the stacked card, which
	   is the correct emphasis now that it is no longer a vertical column. */
	.comparison-table__cell.is-highlighted .comparison-table__cell-label {
		color: var(--color-primary);
	}
}
