/*
 * FAQ (cis/faq + cis/faq-item). Loaded with the blocks, front end and editor canvas.
 *
 * Moved here from the Etch styles of the FAQ Card component and the list wrapper:
 * .bw-work-details__grid, .bw-faq__grid, .bw-work-details__card, .bw-faq-card, __trigger, __details,
 * .bw-faq-card__icon, __icon-toggle, __icon-plus, __icon-minus, .bw-faq-card__content.
 * Etch still prints those styles for any page that has the class names in its markup, so every rule
 * here is written with two classes (.bw-faq__grid first) to win on its own and to match the old
 * look exactly. Plain stylesheet, not compiled by Etch, so:
 *   - lengths are in rem (to-rem(1.5px) = 0.09375rem, 10px = 0.625rem, 48px = 3rem, 54px = 3.375rem,
 *     27px = 1.6875rem, 26px = 1.625rem, 5px = 0.3125rem) and ACSS variables are used as is;
 *   - the Etch @custom-media tokens do not exist here, so their conditions are written out:
 *       --container-query-large / --block-query-large = inline-size >= 800px  (50rem)
 *   - the FAQ look is the one the old cards had inside .bw-faq__grid: white card, accent when open,
 *     and extra room at the bottom for the toggle.
 *
 * The question (cis/heading) and the answer (cis/paragraph) carry their own Etch classes
 * (.bw-work-details__card-heading, .bw-work-details__excerpt), printed by the heading and paragraph blocks.
 * The answer is hidden until the card is open: the open rule below shows it again.
 *
 * The container queries need an ancestor with container-type: inline-size. On the page that is the
 * Etch container (or, later, the section block); in the editor it is the block wrapper, set below.
 *
 * Mobile first: one column, then three from 50rem of container width.
 */

.bw-work-details__grid.bw-faq__grid {
	display: grid;
	grid-template-columns: var(--grid-1);
	gap: 0.625rem;
	align-items: start;
	inline-size: 100%;

	@container (inline-size >= 50rem) {
		grid-template-columns: var(--grid-3);
	}
}

.bw-faq__grid .bw-work-details__card {
	--faq-radius: var(--radius-l);

	position: relative;
	border: 0.09375rem solid var(--accent);
	border-radius: var(--faq-radius);
	background-color: var(--white);
	transition: background-color 0.2s ease;
	min-inline-size: 0;

	/* Room at the bottom for the toggle: 54px icon plus --space-xl. */
	padding-block-end: calc(3.375rem + var(--space-xl));

	/* Only the round icon opens and closes the card, so text and links in the card stay usable. */
	> summary {
		pointer-events: none;
	}

	> summary :is(a, button, .bw-work-details__icon-toggle) {
		pointer-events: auto;
		cursor: pointer;
	}

	.bw-faq-card__icon {
		z-index: 1;
	}

	&[open] {
		background-color: var(--accent);

		.bw-work-details__icon-plus {
			display: none !important;
		}

		.bw-work-details__icon-minus {
			display: block !important;
		}

		.bw-work-details__excerpt {
			display: block;
		}
	}

	/* Keyboard focus ring on the icon, the part that opens the card. */
	> summary:focus-visible .bw-work-details__icon-toggle {
		outline: var(--focus-width) solid var(--focus-color);
		outline-offset: var(--focus-offset);
	}

	> summary:focus-visible {
		outline: none;
	}

	@media (prefers-reduced-motion: reduce) {
		transition: none;
	}
}

.bw-faq__grid .bw-work-details__trigger {
	display: flex;
	flex-direction: column;
	list-style: none;
	cursor: pointer;

	&::-webkit-details-marker {
		display: none;
	}

	&:focus-visible {
		border-radius: var(--faq-radius);
	}
}

.bw-faq__grid .bw-work-details__details {
	display: flex;
	flex-direction: column;
	gap: var(--space-xl);
	padding: var(--space-s);
	inline-size: 100%;
}

.bw-faq__grid .bw-faq-card__icon {
	position: absolute;
	inset-block-end: var(--space-s);
	inset-inline-end: var(--space-s);
	display: flex;
}

.bw-faq__grid .bw-work-details__icon-toggle {
	position: relative;
	align-self: flex-end;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	inline-size: 3rem;
	block-size: 3rem;
	border-radius: 50%;
	background-color: var(--primary);
	flex-shrink: 0;
	margin-inline-start: auto;

	@container (inline-size >= 50rem) {
		inline-size: 3.375rem;
		block-size: 3.375rem;
	}
}

.bw-faq__grid .bw-work-details__icon-plus {
	inline-size: 1.6875rem;
}

.bw-faq__grid .bw-work-details__icon-minus {
	position: absolute;
	inset: 0;
	margin: auto;
	inline-size: 1.625rem;
	block-size: 0.3125rem;
	display: none;
}

.bw-faq__grid .bw-faq-card__content {
	/* The question block ends with a --space-s pad; pull up so the gap under it is --space-xxs. */
	margin-block-start: calc(var(--space-xxs) - var(--space-s));
	padding-inline: var(--space-s);
	padding-block-end: var(--space-s);
}

/* ---- Editor canvas only ---------------------------------------------------------------------------
 * The canvas shows each question open on its answer (a <div>, not <details>), so the client can type
 * in both. The wrapper is the container for the queries above. */
/* Full width, so the size container cannot collapse inside a shrink-to-fit parent (same fix as the logo row). */
.bw-faq-editor {
	container-type: inline-size;
	inline-size: 100%;
}

.bw-faq-item-editor {
	min-inline-size: 0;

	.bw-work-details__excerpt {
		display: block;
	}

	.bw-work-details__details {
		gap: var(--space-s);
	}

	/* The block wrapper adds its own margins; the grid gap does the spacing. */
	&.wp-block {
		margin: 0;
	}
}
