/**
 * HTC Addons - Frequently Asked Questions block.
 *
 * Every rule is scoped to .htc-faq / .htc-faq-placeholder so nothing leaks into
 * the theme. Colours, spacing and motion are exposed as custom properties on
 * the block root, so a theme or child plugin can restyle the accordion by
 * overriding a handful of tokens instead of fighting specificity.
 *
 * Typography is deliberately inherited from the theme.
 */

.htc-faq {
	/* Colour tokens. */
	--htc-faq-accent: #005596;
	--htc-faq-accent-contrast: #ffffff;
	--htc-faq-text: inherit;
	--htc-faq-muted: rgba(0, 0, 0, 0.65);
	--htc-faq-border: rgba(0, 0, 0, 0.15);
	--htc-faq-surface: transparent;
	--htc-faq-surface-hover: rgba(0, 85, 150, 0.06);

	/* Spacing tokens. */
	--htc-faq-item-gap: 0.25rem;
	--htc-faq-trigger-padding-block: 1rem;
	--htc-faq-trigger-padding-inline: 0.25rem;
	--htc-faq-answer-padding-block-end: 1.25rem;
	--htc-faq-intro-margin-block-end: 1.5rem;

	/* Shape and motion tokens. */
	--htc-faq-radius: 4px;
	--htc-faq-border-width: 1px;
	--htc-faq-icon-size: 0.7em;
	--htc-faq-duration: 220ms;
	--htc-faq-easing: cubic-bezier(0.4, 0, 0.2, 1);
	--htc-faq-focus-width: 2px;
	--htc-faq-focus-offset: 2px;

	color: var(--htc-faq-text);
}

/*
 * Preferred tokens for browsers that support color-mix(): they blend with the
 * inherited text colour, which keeps the block legible on dark themes too.
 * Declared in @supports so unsupporting browsers keep the static fallbacks
 * above (custom properties would otherwise resolve to an invalid value).
 */
@supports (color: color-mix(in srgb, currentColor 50%, transparent)) {
	.htc-faq {
		--htc-faq-muted: color-mix(in srgb, currentColor 65%, transparent);
		--htc-faq-border: color-mix(in srgb, currentColor 18%, transparent);
		--htc-faq-surface-hover: color-mix(in srgb, var(--htc-faq-accent) 6%, transparent);
	}
}

/* Intro ------------------------------------------------------------------ */

.htc-faq__intro {
	margin-block-end: var(--htc-faq-intro-margin-block-end);
}

.htc-faq__title {
	margin-block: 0 0.5rem;
}

.htc-faq__intro-text > :first-child {
	margin-block-start: 0;
}

.htc-faq__intro-text > :last-child {
	margin-block-end: 0;
}

/* List ------------------------------------------------------------------- */

.htc-faq__list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: var(--htc-faq-item-gap);
}

.htc-faq__item {
	background: var(--htc-faq-surface);
	border-block-end: var(--htc-faq-border-width) solid var(--htc-faq-border);
	border-radius: var(--htc-faq-radius);
	margin: 0;
	padding: 0;
}

.htc-faq__item::marker,
.htc-faq__item::before {
	content: none;
}

.htc-faq__item:first-child {
	border-block-start: var(--htc-faq-border-width) solid var(--htc-faq-border);
}

/* Trigger ---------------------------------------------------------------- */

.htc-faq__question {
	margin: 0;
	padding: 0;
	font-size: inherit;
	line-height: inherit;
}

.htc-faq__trigger {
	/* Reset UA button styling without inheriting theme button skins. */
	appearance: none;
	-webkit-appearance: none;
	background: none;
	border: 0;
	border-radius: var(--htc-faq-radius);
	box-shadow: none;
	color: inherit;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	font: inherit;
	font-weight: 600;
	letter-spacing: inherit;
	text-align: start;
	text-transform: none;
	inline-size: 100%;
	padding: var(--htc-faq-trigger-padding-block) var(--htc-faq-trigger-padding-inline);
	transition: background-color var(--htc-faq-duration) var(--htc-faq-easing),
		color var(--htc-faq-duration) var(--htc-faq-easing);
}

.htc-faq__trigger:hover,
.htc-faq__trigger:focus-visible {
	background-color: var(--htc-faq-surface-hover);
	color: var(--htc-faq-accent);
}

.htc-faq__trigger:focus-visible {
	outline: var(--htc-faq-focus-width) solid var(--htc-faq-accent);
	outline-offset: var(--htc-faq-focus-offset);
}

.htc-faq__trigger[aria-expanded="true"] {
	color: var(--htc-faq-accent);
}

/* Chevron drawn with borders so no image request is needed. */
.htc-faq__icon {
	flex: 0 0 auto;
	inline-size: var(--htc-faq-icon-size);
	block-size: var(--htc-faq-icon-size);
	border-inline-end: 2px solid currentColor;
	border-block-end: 2px solid currentColor;
	transform: rotate(45deg);
	transform-origin: center;
	translate: 0 -0.15em;
	transition: transform var(--htc-faq-duration) var(--htc-faq-easing);
}

.htc-faq__trigger[aria-expanded="true"] .htc-faq__icon {
	transform: rotate(225deg);
	translate: 0 0.1em;
}

/* Panel ------------------------------------------------------------------ */

.htc-faq__panel {
	display: grid;
	grid-template-rows: 1fr;
}

/*
 * The grid item must carry no padding of its own: a grid row sized 0fr still
 * reserves the item's padding, which would leave a sliver of every collapsed
 * answer on screen. Padding therefore lives on .htc-faq__answer inside it.
 */
.htc-faq__panel-inner {
	min-block-size: 0;
	overflow: hidden;
}

/* Give focus rings and shadows a little breathing room where supported. */
@supports (overflow: clip) {
	.htc-faq__panel-inner {
		overflow: clip;
		overflow-clip-margin: 4px;
	}
}

.htc-faq__answer {
	padding-inline: var(--htc-faq-trigger-padding-inline);
	padding-block-end: var(--htc-faq-answer-padding-block-end);
}

.htc-faq__answer > :first-child {
	margin-block-start: 0;
}

.htc-faq__answer > :last-child {
	margin-block-end: 0;
}

.htc-faq__answer a {
	color: var(--htc-faq-accent);
}

.htc-faq__answer img,
.htc-faq__answer iframe,
.htc-faq__answer video {
	max-inline-size: 100%;
	block-size: auto;
}

/*
 * Collapsed state. Only applied once JavaScript has enhanced the block, so a
 * failed or blocked script leaves every answer readable and in the a11y tree.
 */
.htc-faq[data-htc-faq-enhanced] .htc-faq__item:not([data-htc-faq-open]) .htc-faq__panel {
	grid-template-rows: 0fr;
	visibility: hidden;
}

.htc-faq[data-htc-faq-enhanced] .htc-faq__panel {
	transition: grid-template-rows var(--htc-faq-duration) var(--htc-faq-easing),
		visibility var(--htc-faq-duration) var(--htc-faq-easing);
}

/* Editor-only affordances ------------------------------------------------ */

.htc-faq__editor-notice,
.htc-faq-placeholder {
	border: 1px dashed var(--htc-faq-border, rgba(0, 0, 0, 0.25));
	border-radius: 4px;
	padding: 0.75rem 1rem;
	font-size: 0.8125rem;
	line-height: 1.5;
}

.htc-faq__editor-notice {
	margin-block: 0 1rem;
	background: rgba(0, 85, 150, 0.06);
	color: inherit;
}

.htc-faq-placeholder {
	background: rgba(0, 0, 0, 0.02);
}

.htc-faq-placeholder p {
	margin-block: 0.25rem;
}

/* Motion / print --------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	.htc-faq[data-htc-faq-enhanced] .htc-faq__panel,
	.htc-faq__icon,
	.htc-faq__trigger {
		transition-duration: 1ms;
	}
}

@media print {
	.htc-faq[data-htc-faq-enhanced] .htc-faq__item:not([data-htc-faq-open]) .htc-faq__panel {
		grid-template-rows: 1fr;
		visibility: visible;
	}

	.htc-faq__icon {
		display: none;
	}
}
