/* @svelte-lean/styles — button-group (Tier 0, buttons in role="group").
 * Markup: <div role="group" aria-label="…" data-slean="button-group"> <button type="button"
 * data-slean="button" data-variant="outlined">…</button> … </div>. The children are the buttons
 * (button.css or toggle.css draw them; load this file after those). Every child after the first
 * overlaps the previous border by 1px and the corners that meet are square; contained buttons get
 * a divider in their own text color. A split button's menu popover goes after the group, so the
 * trigger stays the last child. Option: data-slean-orientation="vertical". */
@layer slean.reset, slean.tokens, slean.base, slean.components, slean.compositions, slean.utilities;
@import './button.css';

@layer slean.compositions {
	:where([data-slean='button-group']) {
		display: inline-flex;
		align-items: stretch;
		vertical-align: middle;
	}

	:where([data-slean='button-group'][data-slean-orientation='vertical']) {
		flex-direction: column;
	}

	/* A hovered or focused button is raised above its neighbours, so its border and focus ring are
	 * not covered by the button that overlaps it. */
	:where([data-slean='button-group'] > *) {
		position: relative;
	}

	:where([data-slean='button-group'] > :focus-visible) {
		z-index: 2;
	}

	@media (hover: hover) {
		:where([data-slean='button-group'] > :hover) {
			z-index: 1;
		}
	}

	/* Horizontal: shared inline borders, square corners where two buttons meet. */
	:where(
		[data-slean='button-group']:not([data-slean-orientation='vertical']) > :not(:first-child)
	) {
		margin-inline-start: -1px;
		border-start-start-radius: 0;
		border-end-start-radius: 0;
	}

	:where([data-slean='button-group']:not([data-slean-orientation='vertical']) > :not(:last-child)) {
		border-start-end-radius: 0;
		border-end-end-radius: 0;
	}

	/* Vertical: shared block borders, square corners where two buttons meet. */
	:where([data-slean='button-group'][data-slean-orientation='vertical'] > :not(:first-child)) {
		margin-block-start: -1px;
		border-start-start-radius: 0;
		border-start-end-radius: 0;
	}

	:where([data-slean='button-group'][data-slean-orientation='vertical'] > :not(:last-child)) {
		border-end-start-radius: 0;
		border-end-end-radius: 0;
	}

	/* Contained buttons (the default variant) have transparent borders, so two of them would merge
	 * into one block: the shared border becomes a divider in the button's own text color. */
	:where(
		[data-slean='button-group']:not([data-slean-orientation='vertical'])
			> [data-slean='button']:not([data-variant]):not(:first-child)
	),
	:where(
		[data-slean='button-group']:not([data-slean-orientation='vertical'])
			> [data-slean='button'][data-variant='contained']:not(:first-child)
	) {
		border-inline-start-color: color-mix(in oklch, currentColor 35%, transparent);
	}

	:where(
		[data-slean='button-group'][data-slean-orientation='vertical']
			> [data-slean='button']:not([data-variant]):not(:first-child)
	),
	:where(
		[data-slean='button-group'][data-slean-orientation='vertical']
			> [data-slean='button'][data-variant='contained']:not(:first-child)
	) {
		border-block-start-color: color-mix(in oklch, currentColor 35%, transparent);
	}

	/* Forced colors draw every button border in ButtonText (button.css), so the shared borders
	 * read as single lines; the dividers of contained buttons take the same system color. */
	@media (forced-colors: active) {
		:where(
			[data-slean='button-group']
				> [data-slean='button']:not(:first-child, :disabled, [aria-disabled='true'])
		) {
			border-color: ButtonText;
		}
	}
}
