/*
 * Toggle Button + Toggle List (cis/toggle-button, cis/toggle-list). Loaded with the blocks, front end and editor canvas.
 *
 * Plain stylesheet (not compiled by Etch): lengths in rem, ACSS variables used as they are. Mobile first.
 * The button look (colour, size, shape) is ACSS's btn--* classes plus cis/bw-button's stylesheet (loaded with this one);
 * this file only adds what a toggle needs: the text and icon that follow the open / closed state.
 */

/* ---- Toggle Button -------------------------------------------------------------------------------- */

.bw-toggle-button {
	gap: 0.5em;
	cursor: pointer;

	/* The ACSS button sets its own display, which would beat the hidden attribute (a button with no list is hidden by the script). */
	&[hidden] {
		display: none;
	}

	/*
	 * ACSS styles a button through [class*='btn--'] (one class), but its own reset "input, button, textarea, select { font: inherit }"
	 * comes later in the cascade and wins on a <button> (an <a> is not touched by it). So the text settings are restated here, from the
	 * same ACSS variables, to make this <button> look exactly like the cis/bw-button link.
	 */
	appearance: none;
	max-inline-size: 100%;
	font-family: var(--btn-font-family);
	font-size: var(--btn-font-size, var(--text-m));
	line-height: var(--btn-line-height);

	/* The padding of a bw-button that has its icon (the toggle always has one unless it is switched off). */
	&.bw-button.bw-button--sized {
		--btn-padding-block: 0.5rem;
		--btn-padding-inline: 1.75rem 1.28125rem;
	}

	/* Only the text that matches the state is shown. display:none also leaves the other out of the accessibility tree. */
	&.bw-toggle-button--swap .bw-toggle-button__label--open,
	.bw-toggle-button__icon .bw-toggle__minus {
		display: none;
	}

	&[aria-expanded='true'] {
		&.bw-toggle-button--swap .bw-toggle-button__label--closed {
			display: none;
		}

		&.bw-toggle-button--swap .bw-toggle-button__label--open {
			display: inline;
		}

		.bw-toggle-button__icon .bw-toggle__plus {
			display: none;
		}

		.bw-toggle-button__icon .bw-toggle__minus {
			display: block;
		}
	}
}

.bw-toggle-button__icon {
	display: inline-grid;
	place-items: center;
	flex: 0 0 auto;
	inline-size: 0.7em;
	block-size: 0.7em;

	svg {
		display: block;
		inline-size: 100%;
		block-size: auto;
		max-block-size: 100%;
		fill: currentcolor;

		path {
			fill: currentcolor;
		}
	}
}

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

.bw-toggle-list {
	inline-size: 100%;

	&[hidden] {
		display: none;
	}
}

.bw-toggle-list__items {
	display: flex;
	flex-direction: column;
	margin: 0;
	padding: 0;
	list-style: none;
}

.bw-toggle-list__item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--space-m);
	margin: 0;
	padding-block: var(--space-m);
	border-block-end: 0.0625rem solid var(--neutral-light);
}

.bw-toggle-list__text {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
	min-inline-size: 0;
}

.bw-toggle-list__title {
	margin: 0;
	font-family: var(--heading-font-family);
	font-size: var(--h3);
	font-weight: 400;
	line-height: 1.1;
	text-transform: uppercase;
	color: var(--primary);
	overflow-wrap: anywhere;
}

.bw-toggle-list__description {
	margin: 0;
	font-size: var(--text-m);
	line-height: 1.4;
}

/* The arrow: the brand arrow turned up and to the right, in the primary colour. The link is a 48px target. */
.bw-toggle-list__link {
	display: grid;
	place-items: center;
	flex: 0 0 auto;
	inline-size: 3rem;
	block-size: 3rem;
	color: var(--primary);
	text-decoration: none;

	svg {
		inline-size: 1.75rem;
		block-size: auto;
		fill: currentcolor;
		transform: rotate(-45deg);
		transition: transform 0.2s ease;

		path {
			fill: currentcolor;
		}
	}

	&:hover svg {
		transform: rotate(-30deg);
	}

	&:focus-visible {
		outline: 0.1875rem solid var(--primary);
		outline-offset: 0.125rem;
		border-radius: var(--radius-xs, 0.25rem);
	}

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

		&:hover svg {
			transform: rotate(-45deg);
		}
	}
}

/* ---- Without JavaScript: every list is shown and the buttons (which could do nothing) are hidden --------- */

@media (scripting: none) {
	.bw-toggle-list[hidden] {
		display: block;
	}

	.bw-toggle-button {
		display: none;
	}
}

/* ---- Editor canvas only ------------------------------------------------------------------------------ */

.bw-toggle-editor {
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
	align-items: flex-start;

	/* The canvas notes are the standard WordPress notice (blue info, yellow warning), like the sidebar notes of the other blocks. */
	.components-notice {
		margin: 0;
		inline-size: 100%;
	}

	.bw-toggle-list__tools {
		display: flex;
		flex-direction: column;
		align-items: flex-end;
		gap: 0.25rem;
		flex: 0 0 auto;
		inline-size: 16rem;
		max-inline-size: 40%;
	}

	.bw-toggle-list__tools-row {
		display: flex;
		gap: 0.125rem;
	}
}

.bw-toggle-list-editor {
	align-items: stretch;
}
