/* @svelte-lean/styles — splitter (Tier 2; the keyboard and the drag come from
 * @svelte-lean/primitives/splitter). Markup: <div data-slean="splitter"> with two
 * [data-slean-part="pane"] and, between them, a [data-slean-part="handle"] role="separator".
 * The first pane's size is --slean-split, a percentage of the root without the unit, written on
 * the root's inline style (50 until then). Options: data-slean-orientation="vertical" stacks the
 * panes. State: aria-valuenow, :focus-visible, data-slean-dragging during a drag, aria-disabled.
 * Color: data-color on the root or an ancestor colors the handle while it is hovered, focused or
 * dragged (primary by default). */
@layer slean.reset, slean.tokens, slean.base, slean.components, slean.compositions, slean.utilities;

@layer slean.components {
	:where([data-slean='splitter']) {
		display: grid;
		grid-template-columns:
			minmax(0, calc(var(--slean-split) * 1%))
			var(--slean-space-2)
			minmax(0, 1fr);
		min-block-size: 0;
		border: 1px solid var(--slean-border);
		border-radius: var(--slean-radius-md);
		background: var(--slean-surface);
		color: var(--slean-fg);
		overflow: hidden;
	}

	:where([data-slean='splitter'][data-slean-orientation='vertical']) {
		grid-template-columns: minmax(0, 1fr);
		grid-template-rows:
			minmax(0, calc(var(--slean-split) * 1%))
			var(--slean-space-2)
			minmax(0, 1fr);
	}

	:where([data-slean='splitter'] [data-slean-part='pane']) {
		min-inline-size: 0;
		min-block-size: 0;
		overflow: auto;
	}

	/* The handle is a strip as wide as the gap, with a line in its middle and a grip on focus. */
	:where([data-slean='splitter'] [data-slean-part='handle']) {
		position: relative;
		display: grid;
		place-items: center;
		background: transparent;
		cursor: col-resize;
		touch-action: none;
		user-select: none;
		-webkit-tap-highlight-color: transparent;
	}

	:where([data-slean='splitter'][data-slean-orientation='vertical'] [data-slean-part='handle']) {
		cursor: row-resize;
	}

	:where([data-slean='splitter'] [data-slean-part='handle'])::before {
		content: '';
		position: absolute;
		inset-block: 0;
		inset-inline-start: 50%;
		inline-size: 1px;
		background: var(--slean-border);
		transition: background-color var(--slean-duration-fast) var(--slean-ease);
	}

	:where(
		[data-slean='splitter'][data-slean-orientation='vertical'] [data-slean-part='handle']
	)::before {
		inset-block: 50% auto;
		inset-inline: 0;
		inline-size: auto;
		block-size: 1px;
	}

	:where([data-slean='splitter'] [data-slean-part='handle'])::after {
		content: '';
		inline-size: 0.25rem;
		block-size: 1.5rem;
		border-radius: var(--slean-radius-full);
		background: var(--slean-border-strong);
		opacity: 0;
		transition: opacity var(--slean-duration-fast) var(--slean-ease);
	}

	:where(
		[data-slean='splitter'][data-slean-orientation='vertical'] [data-slean-part='handle']
	)::after {
		inline-size: 1.5rem;
		block-size: 0.25rem;
	}

	@media (hover: hover) {
		:where(
			[data-slean='splitter'] [data-slean-part='handle']:not([aria-disabled='true']):hover
		)::before {
			background: var(--slean-color-main);
		}

		:where(
			[data-slean='splitter'] [data-slean-part='handle']:not([aria-disabled='true']):hover
		)::after {
			opacity: 1;
		}
	}

	:where([data-slean='splitter'] [data-slean-part='handle']:focus-visible) {
		outline: var(--slean-focus-ring);
		outline-offset: calc(-1 * var(--slean-focus-ring-width));
	}

	:where([data-slean='splitter'] [data-slean-part='handle']:focus-visible)::before,
	:where([data-slean='splitter'] [data-slean-part='handle'][data-slean-dragging])::before {
		background: var(--slean-color-main);
	}

	:where([data-slean='splitter'] [data-slean-part='handle']:focus-visible)::after,
	:where([data-slean='splitter'] [data-slean-part='handle'][data-slean-dragging])::after {
		opacity: 1;
	}

	:where([data-slean='splitter'] [data-slean-part='handle'][aria-disabled='true']) {
		cursor: default;
	}

	@media (pointer: coarse) {
		:where([data-slean='splitter']) {
			grid-template-columns:
				minmax(0, calc(var(--slean-split) * 1%))
				var(--slean-space-5)
				minmax(0, 1fr);
		}

		:where([data-slean='splitter'][data-slean-orientation='vertical']) {
			grid-template-columns: minmax(0, 1fr);
			grid-template-rows:
				minmax(0, calc(var(--slean-split) * 1%))
				var(--slean-space-5)
				minmax(0, 1fr);
		}
	}

	@media (forced-colors: active) {
		:where([data-slean='splitter'] [data-slean-part='handle'])::before {
			background: CanvasText;
		}

		:where([data-slean='splitter'] [data-slean-part='handle'])::after {
			background: CanvasText;
		}
	}
}
