/*
 * Villas More — Accordion block (Task 006 proof of concept).
 *
 * Consumes the theme's existing design tokens (theme.json) rather than
 * hard-coding new colours/spacing. Loaded as this block's `style`
 * asset, so it applies in both the editor and the front end; rows
 * carrying the `vm-accordion-item--editor` class use the always-open
 * editor layout instead of the `<details>` disclosure behaviour.
 *
 * Animation technique: `.vm-accordion-item__content` is a CSS grid
 * whose single row track is transitioned between `0fr` and `1fr`
 * ("grid-rows" open/close trick). `display: grid` is set unconditionally
 * (not only when `[open]`) so it overrides the browser's default
 * `details > :not(summary) { display: none }` rule — this is what lets
 * a *closed* row still be transitioned instead of snapping instantly.
 * `overflow: hidden` on both the row and its inner wrapper clips the
 * content, and its border, while collapsed. The `[open]` rule below is
 * the no-JavaScript fallback: without `view.js`, opening/closing is the
 * browser's normal instant `<details>` toggle, not the animated one.
 */

.vm-accordion {
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
}

.vm-accordion-item {
	border: 1px solid var(--wp--preset--color--border);
	border-radius: 2px;
	background-color: var(--wp--preset--color--base);
	overflow: hidden;
}

.vm-accordion-item__summary {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	padding: 1rem 1.25rem;
	cursor: pointer;
	list-style: none;
	font-family: var(--wp--preset--font-family--heading);
	font-weight: 500;
	color: var(--wp--preset--color--contrast);
}

.vm-accordion-item__summary::-webkit-details-marker {
	display: none;
}

.vm-accordion-item__summary::marker {
	content: "";
}

.vm-accordion-item__summary:hover {
	color: var(--wp--preset--color--primary);
}

.vm-accordion-item__summary:focus-visible {
	outline: 2px solid var(--wp--preset--color--primary);
	outline-offset: -2px;
}

.vm-accordion-item__summary-text {
	flex: 1 1 auto;
}

/* Plus/minus indicator: two CSS-drawn bars, no icon font/SVG dependency. */
.vm-accordion-item__icon {
	position: relative;
	flex: 0 0 auto;
	width: 1rem;
	height: 1rem;
}

.vm-accordion-item__icon::before,
.vm-accordion-item__icon::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	background-color: currentColor;
	transform: translate(-50%, -50%);
	transition: opacity 0.2s ease, transform 0.2s ease;
}

.vm-accordion-item__icon::before {
	width: 100%;
	height: 2px;
}

.vm-accordion-item__icon::after {
	width: 2px;
	height: 100%;
}

details[open] > .vm-accordion-item__summary .vm-accordion-item__icon::after {
	opacity: 0;
	transform: translate(-50%, -50%) rotate(90deg);
}

/* Expandable content: closed by default, animated via view.js; see note above. */
.vm-accordion-item__content {
	display: grid;
	grid-template-rows: 0fr;
	overflow: hidden;
	transition: grid-template-rows 0.3s ease;
}

details[open] > .vm-accordion-item__content {
	grid-template-rows: 1fr;
}

.vm-accordion-item__content-inner {
	overflow: hidden;
	min-height: 0;
	border-top: 1px solid var(--wp--preset--color--border);
	padding: 1rem 1.25rem 1.25rem;
	color: var(--wp--preset--color--muted);
}

.vm-accordion-item__content-inner > *:last-child {
	margin-bottom: 0;
}

/* -- Editor-only layout: always expanded for editing, no disclosure. -- */

.vm-accordion-item__summary--editor {
	cursor: text;
}

.vm-accordion-item__content--editor {
	display: block;
	border-top: 1px solid var(--wp--preset--color--border);
	padding: 1rem 1.25rem 1.25rem;
	color: var(--wp--preset--color--muted);
}

/*
 * Width (Task 006-5): `default` intentionally sets no rule at all here — the
 * Accordion inherits whatever contains it (today's actual, unstyled
 * behaviour), which is what makes it compose correctly inside a future
 * split/column layout without a special case. `narrow`/`wide` use plain
 * class selectors (not WordPress's native `alignwide` mechanism, which only
 * behaves correctly as a direct child of a `layout:"constrained"` section).
 *
 * `!important` confirmed necessary by live-testing in the editor (Task
 * 006-5): a parent Group that sets its own explicit `layout.contentSize`
 * (rather than just inheriting the theme default — e.g. `patterns/faq-
 * accordion.php`'s `vm-container` wrapper) makes WordPress generate a
 * *non*-`:where()` per-instance override rule with several chained `:not()`
 * clauses, which outranks a plain class selector on specificity alone
 * regardless of source order. Without `!important` here, "Wide"/"Narrow"
 * would silently do nothing in exactly that (common) composition. This is
 * the same reasoning WordPress's own per-instance override rules rely on —
 * an explicit width choice must win over whatever contains it.
 */
.vm-accordion--width-narrow {
	max-width: var(--wp--custom--layout--narrow-size, 42rem) !important;
	margin-inline: auto !important;
}

.vm-accordion--width-wide {
	max-width: var(--wp--style--global--wide-size, 1320px) !important;
	margin-inline: auto !important;
}

/* Respect reduced-motion preferences: skip the animated transition. */
@media (prefers-reduced-motion: reduce) {
	.vm-accordion-item__content,
	.vm-accordion-item__icon::before,
	.vm-accordion-item__icon::after {
		transition: none;
	}
}
