/*
 * Features — Accordion + Preview
 * Port of 21st.dev "accordion-feature-section".
 */

.cw-acc {
	max-width: 100%;
	--cw-fg: #18181b;
	--cw-muted: #71717a;
	--cw-border: rgba(0, 0, 0, 0.1);

	--cw-list-width: 50%;
	--cw-columns-gap: 3rem;
	--cw-row-padding: 1.25rem;
	--cw-fade: 350ms;

	position: relative;
	width: 100%;
	color: var(--cw-fg);
}

.cw-acc[data-cw-theme='dark'] {
	--cw-fg: #fafafa;
	--cw-muted: #a1a1aa;
	--cw-border: rgba(255, 255, 255, 0.12);
}

/* --------------------------------------------------------------------- Title block */

.cw-acc__header {
	margin-bottom: 3rem;
}

.cw-acc__eyebrow {
	display: block;
	margin-bottom: 0.75rem;
	font-size: 0.875rem;
	font-weight: 700;
	line-height: 1.3;
	letter-spacing: 0.08em;
	color: #2f5fbf;
}

.cw-acc__heading {
	display: block;
}

.cw-acc__title {
	display: block;
	font-size: clamp(1.75rem, 1.2rem + 2vw, 2.75rem);
	font-weight: 600;
	line-height: 1.15;
	letter-spacing: -0.02em;
	color: var(--cw-fg);
	text-wrap: balance;
}

.cw-w .cw-acc__description {
	/* inline-block so a max-width box follows the header's text-align
	   instead of staying pinned to the left. */
	display: inline-block;
	margin-top: 0.875rem;
	font-size: 1.0625rem;
	line-height: 1.65;
	color: var(--cw-muted);
	text-wrap: pretty;
}

/* ------------------------------------------------------------------------ Columns */

/*
 * Mobile first, deliberately. The two columns only exist from 768px up, and every rule
 * that narrows the accordion lives inside that media query.
 *
 * The bug this replaces: align-items: flex-start was set unconditionally. In a row that
 * aligns children vertically and is harmless, but the mobile layout switches to
 * flex-direction: column, which flips the cross axis to horizontal — so flex-start
 * stopped the column stretching and shrank it to its content. The column rendered at
 * roughly half the screen and the titles had nowhere to wrap.
 */
.cw-acc__inner {
	display: flex;
	flex-direction: column;
	gap: var(--cw-columns-gap);
}

.cw-acc__list {
	width: 100%;
	min-width: 0;
	/* Explicit, so a stray align-items on the container cannot shrink it. */
	align-self: stretch;
}

@media (min-width: 768px) {
	.cw-acc__inner {
		flex-direction: row;
		/* Read from a variable so the alignment control cannot reach mobile, where it
		   would shrink the column instead of aligning it. */
		align-items: var(--cw-col-align, flex-start);
	}

	.cw-acc__list {
		flex: 1 1 auto;
		align-self: auto;
	}

	.cw-acc--has-preview .cw-acc__list {
		flex: 0 0 var(--cw-list-width);
		width: var(--cw-list-width);
		max-width: var(--cw-list-width);
	}

	.cw-acc--preview-left .cw-acc__inner {
		flex-direction: row-reverse;
	}
}

/* -------------------------------------------------------------------------- Items */

.cw-acc--dividers .cw-acc__item {
	border-bottom-width: 1px;
	border-bottom-color: var(--cw-border);
}

.cw-acc__item {
	min-width: 0;
}

/* Block, not flex: one less layer that can be widened by its own content. */
.cw-acc__item-heading {
	display: block;
	min-width: 0;
}

/*
 * Grid with an explicit minmax(0, 1fr) track, rather than flex. A flex item's
 * min-width:auto has to be cancelled at every level in the chain, and a <button> brings
 * its own intrinsic sizing on top of that — miss one and a long title still stretches
 * the row. A 0-minimum grid track cannot exceed its share of the row whatever it holds,
 * so the text has no choice but to wrap.
 */
.cw-w .cw-acc__trigger {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto;
	align-items: center;
	gap: 1rem;
	width: 100%;
	max-width: 100%;
	min-width: 0;
	padding: var(--cw-row-padding) 0;
	text-align: left;
	cursor: pointer;
	background: transparent;
	transition: color 150ms ease;
}

.cw-acc__item-title {
	min-width: 0;
	/* `anywhere` rather than `break-word`: only `anywhere` reduces the element's
	   min-content width, which is what stops a long unbroken word from widening the
	   whole column. word-break covers older engines that ignore it. */
	overflow-wrap: anywhere;
	word-break: break-word;
	max-width: 100%;
	font-size: 1.25rem;
	font-weight: 600;
	line-height: 1.35;
	/* Closed items are dimmed; the open one lifts to full contrast. */
	color: var(--cw-muted);
	transition: color 150ms ease;
}

.cw-acc__item.is-open .cw-acc__item-title,
.cw-w .cw-acc__trigger:hover .cw-acc__item-title {
	color: var(--cw-fg);
}

.cw-acc__chevron {
	display: inline-flex;
	flex: 0 0 auto;
	flex: 0 0 auto;
	color: var(--cw-muted);
	transform: rotate(90deg);
	transition: transform 200ms ease;
}

.cw-acc__item.is-open .cw-acc__chevron {
	transform: rotate(-90deg);
}

.cw-acc__chevron .cw-icon {
	width: 16px;
	height: 16px;
}

/* Stated explicitly so a theme's button:hover cannot paint the row. */
.cw-w .cw-acc__trigger:hover,
.cw-w .cw-acc__trigger:focus {
	background: transparent;
	color: inherit;
}

.cw-w .cw-acc__trigger:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: -2px;
}

/* The 0fr/1fr grid trick animates to the panel's natural height without JS measuring
   it. Browsers without interpolation support still collapse and expand — just instantly. */
.cw-acc__panel {
	display: grid;
	grid-template-rows: 0fr;
	transition: grid-template-rows var(--cw-fade) ease;
}

.cw-acc__item.is-open .cw-acc__panel {
	grid-template-rows: 1fr;
}

.cw-acc__panel-inner {
	overflow: hidden;
	min-height: 0;
}

.cw-w .cw-acc__item-desc {
	overflow-wrap: anywhere;
	padding-bottom: var(--cw-desc-bottom, 1rem);
	font-size: 1rem;
	line-height: 1.65;
	color: var(--cw-muted);
	text-wrap: pretty;
}

.cw-acc__item-media {
	display: none;
	padding-bottom: var(--cw-desc-bottom, 1rem);
}

.cw-acc .cw-acc__item-media img {
	width: 100%;
	height: 20rem;
	max-height: 60vh;
	object-fit: cover;
	border-radius: 0.75rem;
}

/* ------------------------------------------------------------------------ Preview */

.cw-acc__preview {
	position: relative;
	display: block;
	flex: 1 1 auto;
	min-width: 0;
	overflow: hidden;
	aspect-ratio: 4 / 3;
	border-radius: 0.75rem;
	background-color: rgba(0, 0, 0, 0.04);
}

/* One image, src swapped by the script. width/height are also set inline in PHP so the
   panel is filled even if this stylesheet is stale or overridden. */
.cw-acc .cw-acc__preview-img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: opacity var(--cw-fade) ease;
}

.cw-acc .cw-acc__preview-img.is-swapping {
	opacity: 0;
}

/* ------------------------------------------------------------------------- Mobile */

@media (max-width: 767px) {
	/* With images shown inside each item, the side panel is redundant. */
	.cw-acc--inline-media .cw-acc__preview {
		display: none;
	}

	.cw-acc--inline-media .cw-acc__item-media {
		display: block;
	}

	.cw-acc__header {
		margin-bottom: 2rem;
	}
}

@media (prefers-reduced-motion: reduce) {
	.cw-acc__panel,
	.cw-acc__preview-img,
	.cw-acc__chevron {
		transition: none;
	}
}
