/*
 * Look of the "switch" output format, based on example-css/switch.css from StyleSwitch.
 * Scoped to the widget container and without theme variables, colors follow the text color.
 * Themes may set --style-switch-color, --style-switch-color-on, --style-switch-hover and --style-switch-radius.
 */
style-switch label.style-switch-toggle {
	display: block;
	padding: 4px 4px 6px 6px;
	border: 0 solid var(--style-switch-color, currentColor);
	border-radius: var(--style-switch-radius, 5px);
	width: min-content;
	white-space: nowrap;
	cursor: pointer;
	user-select: none;

	& > :first-child {
		display: inline-block;
		padding-right: 1em;
	}

	&:hover,
	&:has([role=switch]:focus-visible) {
		padding: 2px 2px 4px 4px;
		border-width: 2px;
		background-color: var(--style-switch-hover, color-mix(in srgb, currentColor 10%, transparent));
	}

	.visual {
		position: relative;
		top: 2px;
		display: inline-block;
		border: 2px solid var(--style-switch-color, currentColor);
		width: 2.5em;
		height: 1.25em;
		border-radius: 2em;
		vertical-align: sub;

		&::before {
			content: "";
			position: absolute;
			top: 1px;
			left: 2px;
			display: inline-block;
			border: 2px solid var(--style-switch-color, currentColor);
			border-radius: 1em;
			width: 0.88em;
			height: 0.88em;
			background: var(--style-switch-color, currentColor);
			opacity: 0.6;
			transition: left 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
		}
	}

	.state {
		display: inline-grid;
		grid-template-areas: "overlay";
		padding-left: 0.5em;

		& > .boolean {
			grid-area: overlay;
		}
	}
}

style-switch [role=switch] {
	opacity: 0;
	position: absolute;

	&:not(:checked) ~ .state .on {
		opacity: 0;
	}

	&:checked ~ .state .off {
		opacity: 0;
	}

	&:checked ~ .visual::before {
		left: 1.25em;
		border-color: var(--style-switch-color-on, currentColor);
		background: var(--style-switch-color-on, currentColor);
		opacity: 1;
	}
}

@media (prefers-reduced-motion: reduce) {
	style-switch label.style-switch-toggle .visual::before {
		transition: none;
	}
}
