/**
 * Accordion FAQ — frontend styles.
 * Theme-aware via CSS custom properties; no !important.
 */

.afaq {
	--afaq-accent: var(--wp--preset--color--primary, #2563eb);
	--afaq-text: inherit;
	--afaq-border: rgba(0, 0, 0, 0.12);
	--afaq-bg: transparent;
	--afaq-surface: #fff; /* Opaque surface for popovers (autocomplete). */
	--afaq-header-bg: transparent;
	--afaq-header-bg-hover: rgba(0, 0, 0, 0.03);
	--afaq-radius: 6px;
	--afaq-gap: 0.5rem;
	--afaq-pad: 1rem;
	--afaq-muted: #64748b;

	color: var(--afaq-text);
	max-width: 100%;
}

@media (prefers-color-scheme: dark) {
	.afaq {
		--afaq-border: rgba(255, 255, 255, 0.18);
		--afaq-surface: #1f2430;
		--afaq-header-bg-hover: rgba(255, 255, 255, 0.06);
	}
}

/* --- Controls ------------------------------------------------------------ */
.afaq__controls {
	position: relative;
	z-index: 2; /* Keep the search + its autocomplete above the filter row. */
	display: flex;
	flex-wrap: wrap;
	gap: var(--afaq-gap);
	align-items: flex-end; /* Bottom-align the expand-all button with the input. */
	justify-content: space-between;
	margin-block-end: 1rem;
}

.afaq__search {
	position: relative;
	flex: 1 1 240px;
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
}

.afaq__search-label {
	font-size: 0.85em;
	font-weight: 600;
}

.afaq__search-input {
	width: 100%;
	padding: 0.5rem 0.75rem;
	border: 1px solid var(--afaq-border);
	border-radius: var(--afaq-radius);
	background: var(--afaq-bg);
	color: inherit;
	font: inherit;
}

/* --- Autocomplete suggestions ------------------------------------------- */
.afaq__suggest {
	position: absolute;
	z-index: 60;
	inset-inline: 0;
	top: 100%;
	margin: 0.25rem 0 0;
	padding: 0.25rem;
	list-style: none;
	max-height: 320px;
	overflow-y: auto;
	/* A popover needs a genuinely opaque surface — the list uses a transparent
	   --afaq-bg on purpose, so use a dedicated surface color here. */
	background: var(--afaq-surface, #fff);
	border: 1px solid var(--afaq-border, #d1d5db);
	border-radius: var(--afaq-radius);
	box-shadow: 0 12px 32px rgba( 0, 0, 0, 0.14 );
}

@media ( prefers-color-scheme: dark ) {
	.afaq__suggest {
		background: var(--afaq-surface, #1f2430);
	}
}

.afaq__suggest[hidden] {
	display: none;
}

.afaq__suggest-item {
	padding: 0.5rem 0.6rem;
	border-radius: calc( var(--afaq-radius) - 2px );
	cursor: pointer;
	line-height: 1.35;
}

.afaq__suggest-item.is-active,
.afaq__suggest-item:hover {
	background: var(--afaq-header-bg);
}

.afaq__suggest-q {
	display: block;
	font-weight: 600;
}

/* --- Search match highlight --------------------------------------------- */
.afaq__hl {
	background: rgba( 255, 214, 0, 0.4 );
	color: inherit;
	padding: 0 0.05em;
	border-radius: 2px;
}

/* --- Filtering & pagination --------------------------------------------- */
/* A filtered-out item is always hidden. */
.afaq__item.is-filtered {
	display: none !important;
}

/* Paged-out items are hidden until "Load more" (or a search/filter) reveals
   them. During an active search/filter, every match is shown regardless of page. */
.afaq__item.is-paged {
	display: none;
}

.afaq--search-active .afaq__item.is-paged {
	display: block;
}

.afaq__more-wrap {
	display: flex;
	justify-content: center;
	margin-block-start: 1rem;
}

.afaq__more {
	padding: 0.55rem 1.4rem;
	border: 1px solid var(--afaq-border);
	border-radius: var(--afaq-radius);
	background: var(--afaq-header-bg);
	color: inherit;
	cursor: pointer;
	font: inherit;
	font-weight: 600;
}

.afaq__more[hidden] {
	display: none;
}

/* --- Table of contents (sticky sidebar + scroll spy) -------------------- */
.afaq--has-toc .afaq__layout {
	display: grid;
	grid-template-columns: minmax(180px, 240px) 1fr;
	gap: clamp( 1rem, 4vw, 2.5rem );
	align-items: start;
}

.afaq__toc {
	position: sticky;
	top: 1.5rem;
	align-self: start;
	max-height: calc( 100vh - 3rem );
	overflow-y: auto;
}

.afaq__toc-title {
	margin: 0 0 0.5rem;
	font-size: 0.75em;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--afaq-muted, #6b7280);
}

.afaq__toc-list {
	margin: 0;
	padding: 0;
	list-style: none;
	display: flex;
	flex-direction: column;
	gap: 0.1rem;
}

.afaq__toc-link {
	display: block;
	padding: 0.35rem 0.6rem;
	border-inline-start: 2px solid transparent;
	border-radius: 0 var(--afaq-radius) var(--afaq-radius) 0;
	color: inherit;
	text-decoration: none;
	font-size: 0.9em;
	line-height: 1.35;
	opacity: 0.75;
}

.afaq__toc-link:hover {
	opacity: 1;
	background: var(--afaq-header-bg);
}

.afaq__toc-link.is-active {
	opacity: 1;
	font-weight: 600;
	border-inline-start-color: var(--afaq-accent);
	color: var(--afaq-accent);
	background: var(--afaq-header-bg);
}

@media ( max-width: 700px ) {
	.afaq--has-toc .afaq__layout {
		grid-template-columns: 1fr;
	}
	.afaq__toc {
		position: static;
		max-height: none;
	}
}

.afaq__expand-all {
	padding: 0.5rem 0.9rem;
	border: 1px solid var(--afaq-border);
	border-radius: var(--afaq-radius);
	background: var(--afaq-header-bg);
	color: inherit;
	cursor: pointer;
	font: inherit;
}

.afaq__filters {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4rem;
	margin-block-end: 1rem;
}

.afaq__filter {
	padding: 0.35rem 0.8rem;
	border: 1px solid var(--afaq-border);
	border-radius: 999px;
	background: transparent;
	color: inherit;
	cursor: pointer;
	font: inherit;
	line-height: 1.2;
}

.afaq__filter.is-active {
	background: var(--afaq-accent);
	border-color: var(--afaq-accent);
	color: #fff;
}

/* --- Items --------------------------------------------------------------- */
.afaq__list {
	display: flex;
	flex-direction: column;
	gap: var(--afaq-gap);
}

.afaq__item {
	background: var(--afaq-bg);
}

.afaq__item[hidden] {
	display: none;
}

.afaq__header {
	margin: 0;
	font-size: inherit;
	line-height: inherit;
}

.afaq__trigger {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	width: 100%;
	margin: 0;
	padding: var(--afaq-pad);
	border: 0;
	background: var(--afaq-header-bg);
	color: inherit;
	font: inherit;
	font-weight: 600;
	text-align: start;
	cursor: pointer;
	list-style: none; /* hide default <summary> marker */
}

.afaq__trigger::-webkit-details-marker {
	display: none;
}

.afaq__trigger:hover {
	background: var(--afaq-header-bg-hover);
}

.afaq__trigger:focus-visible {
	outline: 2px solid var(--afaq-accent);
	outline-offset: -2px;
}

.afaq--icon-left .afaq__trigger {
	flex-direction: row-reverse;
	justify-content: flex-end;
}

.afaq__question {
	margin: 0;
	font: inherit;
	font-weight: 600;
}

/* Chevron icon */
.afaq__icon {
	flex: 0 0 auto;
	width: 0.6em;
	height: 0.6em;
	border-right: 2px solid currentColor;
	border-bottom: 2px solid currentColor;
	transform: rotate(45deg);
	transition: transform 0.2s ease;
	margin-inline-start: auto;
}

.afaq--icon-left .afaq__icon {
	margin-inline-start: 0;
	margin-inline-end: 0;
}

/* Open state icon rotation */
.afaq__trigger[aria-expanded="true"] .afaq__icon,
.afaq__item--details[open] .afaq__icon {
	transform: rotate(-135deg);
}

/* Panel */
.afaq__panel {
	overflow: hidden;
}

.afaq__answer {
	padding: 0 var(--afaq-pad) var(--afaq-pad);
}

.afaq__answer > :first-child {
	margin-top: 0;
}

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

/* --- Style variants ------------------------------------------------------ */
.afaq--style-bordered .afaq__item,
.afaq--style-filled .afaq__item,
.afaq--style-separated .afaq__item {
	border: 1px solid var(--afaq-border);
	border-radius: var(--afaq-radius);
	overflow: hidden;
}

.afaq--style-filled .afaq__trigger {
	--afaq-header-bg: rgba(0, 0, 0, 0.04);
}

.afaq--style-minimal .afaq__item {
	border-bottom: 1px solid var(--afaq-border);
}

.afaq--style-separated .afaq__list {
	gap: 0.75rem;
}

/* --- Entrance animation (respects reduced motion) ------------------------ */
@media (prefers-reduced-motion: no-preference) {
	.afaq__panel:not([hidden]) {
		animation: afaq-reveal 0.2s ease;
	}

	.afaq__item--details[open] .afaq__panel {
		animation: afaq-reveal 0.2s ease;
	}
}

@keyframes afaq-reveal {
	from {
		opacity: 0;
		transform: translateY(-4px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

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

/* --- Utilities ----------------------------------------------------------- */
.afaq .screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.afaq__empty {
	padding: var(--afaq-pad);
	opacity: 0.75;
}

/* --- Premium skins ------------------------------------------------------- */
.afaq--style-modern .afaq__list {
	gap: 0.6rem;
}

.afaq--style-modern .afaq__item {
	border: 1px solid var(--afaq-border);
	border-radius: 10px;
	overflow: hidden;
	background: var(--afaq-bg);
}

.afaq--style-modern .afaq__trigger {
	padding: 1rem 1.15rem;
}

.afaq--style-card .afaq__list {
	gap: 0.8rem;
}

.afaq--style-card .afaq__item {
	border: 1px solid var(--afaq-border);
	border-radius: 14px;
	overflow: hidden;
	background: var(--afaq-bg);
	box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 10px 24px -16px rgba(15, 23, 42, 0.3);
}

.afaq--style-card .afaq__trigger {
	padding: 1.05rem 1.25rem;
}

/* --- Icon styles --------------------------------------------------------- */
.afaq--iconstyle-plus .afaq__icon {
	width: 14px;
	height: 14px;
	border: 0;
	transform: none;
	position: relative;
}

.afaq--iconstyle-plus .afaq__icon::before,
.afaq--iconstyle-plus .afaq__icon::after {
	content: "";
	position: absolute;
	inset-inline-start: 50%;
	top: 50%;
	background: currentColor;
	transition: transform 0.2s ease;
}

.afaq--iconstyle-plus .afaq__icon::before {
	width: 2px;
	height: 14px;
	transform: translate(-50%, -50%);
}

.afaq--iconstyle-plus .afaq__icon::after {
	width: 14px;
	height: 2px;
	transform: translate(-50%, -50%);
}

.afaq--iconstyle-plus .afaq__trigger[aria-expanded="true"] .afaq__icon,
.afaq--iconstyle-plus .afaq__item--details[open] .afaq__icon {
	transform: none;
}

.afaq--iconstyle-plus .afaq__trigger[aria-expanded="true"] .afaq__icon::before,
.afaq--iconstyle-plus .afaq__item--details[open] .afaq__icon::before {
	transform: translate(-50%, -50%) scaleY(0);
}

.afaq--iconstyle-arrow .afaq__trigger[aria-expanded="true"] .afaq__icon,
.afaq--iconstyle-arrow .afaq__item--details[open] .afaq__icon {
	transform: rotate(225deg);
}

/* --- Views + voting ------------------------------------------------------ */
.afaq__meta {
	display: flex;
	align-items: center;
	gap: 1rem;
	flex-wrap: wrap;
	padding: 0 var(--afaq-pad) var(--afaq-pad);
	font-size: 0.9em;
	color: var(--afaq-muted);
}

.afaq__vote {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	margin-inline-start: auto;
}

.afaq__vote-btn {
	display: inline-flex;
	align-items: center;
	gap: 0.3rem;
	border: 1px solid var(--afaq-border);
	background: transparent;
	color: inherit;
	border-radius: 999px;
	padding: 0.25rem 0.65rem;
	cursor: pointer;
	font: inherit;
	font-size: 0.9em;
	line-height: 1.2;
}

.afaq__vote-btn:hover:not(:disabled) {
	border-color: var(--afaq-accent);
	color: var(--afaq-accent);
}

.afaq__vote-btn:focus-visible {
	outline: 2px solid var(--afaq-accent);
	outline-offset: 2px;
}

.afaq__vote-btn:disabled {
	opacity: 0.55;
	cursor: default;
}

.afaq__vote-thanks {
	color: var(--afaq-accent);
	font-weight: 600;
}

/* --- Submission form ----------------------------------------------------- */
.afaq-submit {
	--afaq-accent: var(--wp--preset--color--primary, #2563eb);
	--afaq-border: rgba(0, 0, 0, 0.15);
	--afaq-bg: transparent;
	max-width: 560px;
	display: flex;
	flex-direction: column;
	gap: 0.85rem;
}

.afaq-submit__title {
	margin: 0 0 0.25rem;
}

.afaq-submit__row {
	display: flex;
	flex-direction: column;
	gap: 0.3rem;
}

.afaq-submit__label {
	font-weight: 600;
	font-size: 0.9em;
}

.afaq-submit__input {
	width: 100%;
	padding: 0.6rem 0.75rem;
	border: 1px solid var(--afaq-border);
	border-radius: 8px;
	font: inherit;
	background: var(--afaq-bg);
	color: inherit;
}

.afaq-submit__input:focus-visible {
	outline: 2px solid var(--afaq-accent);
	outline-offset: 1px;
}

.afaq-submit__btn {
	align-self: flex-start;
	background: var(--afaq-accent);
	color: #fff;
	border: 0;
	border-radius: 8px;
	padding: 0.6rem 1.2rem;
	font: inherit;
	font-weight: 600;
	cursor: pointer;
}

.afaq-submit__hp {
	position: absolute;
	left: -9999px;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

.afaq-submit__msg {
	margin: 0.25rem 0 0;
	font-weight: 600;
	color: var(--afaq-accent);
}
