/**
 * "DB Archive FAQ" widget.
 *
 * The open/close animation is pure CSS: the answer is a grid whose single row
 * moves between `0fr` and `1fr`. That animates to the content's natural height
 * without JavaScript measuring anything, so it stays smooth however long the
 * answer is and however the viewport is resized mid-transition.
 */

.dba-faq {
	--dba-faq-item-gap: 0;

	width: 100%;
}

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

.dba-faq__title {
	margin: 0 0 0.5em;
	font-family: inherit;
	color: var( --dba-heading-color );
}

.dba-faq__description {
	margin: 0 0 var( --dba-gap-lg );
	font-family: inherit;
	color: var( --dba-text-color );
}

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

.dba-faq__list {
	display: flex;
	flex-direction: column;
	gap: var( --dba-faq-item-gap );
}

.dba-faq__item {
	border-bottom: 1px solid rgba( 128, 128, 128, 0.22 );
}

/* The closing rule would sit directly on top of whatever follows the widget,
   so the list ends without one. */
.dba-faq__list .dba-faq__item:last-child {
	border-bottom-color: transparent;
}

.dba-faq__heading {
	margin: 0;
	padding: 0;
	font: inherit;
	color: inherit;
}

/* --------------------------------------------------------------------------
 * Question
 * ----------------------------------------------------------------------- */

.dba-faq__question {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var( --dba-gap-md );
	width: 100%;
	margin: 0;
	padding: 1em 0;
	border: 0 !important;
	border-radius: inherit;
	background: none !important;
	color: #000 !important;
	font: inherit;
	text-align: inherit;
	line-height: inherit;
	cursor: pointer;
	appearance: none;
	-webkit-appearance: none;
	transition: color var( --dba-transition ), background-color var( --dba-transition );
	box-shadow: none !important;
	font-size: 20px;
}

.dba-faq__question-text {
	flex: 1 1 auto;
	min-width: 0;
	font: inherit;
	color: inherit;
	/* Long unbroken strings (part numbers, URLs) must not widen the layout. */
	overflow-wrap: break-word;
}

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

.dba-faq__icon {
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	line-height: 1;
	color: inherit;
	transition: color var( --dba-transition ), transform var( --dba-transition );
}

.dba-faq__icon svg {
	width: 1em;
	height: 1em;
	fill: currentColor;
}

/* Both icons ship in the markup and are swapped with CSS, so no icon font is
   re-resolved on toggle and there is never a flicker. */
.dba-faq__icon-open {
	display: none;
}

.dba-faq__item.is-open .dba-faq__icon-closed {
	display: none;
}

.dba-faq__item.is-open .dba-faq__icon-open {
	display: inline-flex;
}

/* Icon on the left: reverse the row and let the text take the free space. */
.dba-faq--icon-left .dba-faq__question {
	flex-direction: row-reverse;
	justify-content: flex-end;
}

.dba-faq--icon-none .dba-faq__icon {
	display: none;
}

/* --------------------------------------------------------------------------
 * Answer
 * ----------------------------------------------------------------------- */

.dba-faq__answer {
	display: grid;
	grid-template-rows: 0fr;
	/* visibility is what removes collapsed text from the accessibility tree;
	   it is delayed on close so the text does not vanish before it has slid up. */
	visibility: hidden;
	transition: grid-template-rows var( --dba-transition ), visibility 0s linear 0.3s;
}

.dba-faq__item.is-open .dba-faq__answer {
	grid-template-rows: 1fr;
	visibility: visible;
	transition: grid-template-rows var( --dba-transition ), visibility 0s;
}

.dba-faq__answer-inner {
	/* The grid row is what is animated; this element must clip to it. */
	overflow: hidden;
	min-height: 0;
	padding: 0 0 1.25em;
	font-family: inherit;
	color: var( --dba-text-color );
}

.dba-faq__answer-inner a {
	color: var( --dba-accent-color );
}

/* --------------------------------------------------------------------------
 * Responsive
 * ----------------------------------------------------------------------- */

@media ( max-width: 767px ) {
	.dba-faq__question {
		padding-top: 0.85em;
		padding-bottom: 0.85em;
		/* Keep the tap target comfortable on small screens. */
		min-height: 44px;
	}

	.dba-faq__answer-inner {
		padding-bottom: 1em;
	}
}
