/* @svelte-lean/styles — steps (Tier 0, <ol> + aria-current="step").
 * Markup: <ol data-slean="steps" aria-label="Checkout"> <li><span data-slean-part="title">Cart
 * </span><span data-slean-part="complete">Completed</span></li> <li aria-current="step">
 * <span data-slean-part="title">Shipping</span><span data-slean-part="description">…</span></li>
 * <li>…</li> </ol>. A step is complete when it contains the complete part: text for assistive
 * technology, hidden here, and the marker the styles read through :has(). The indicator is
 * li::before with a CSS counter (generated content with empty alternative text, so the list
 * position is not read twice); a complete step is a filled disc with the check icon cut out of
 * it (two mask layers). The
 * connector to the next step is li::after. Option: data-slean-orientation="vertical". Color:
 * data-color on the root or an ancestor colors the current and complete steps (primary by
 * default); an error step keeps the error color. */
@layer slean.reset, slean.tokens, slean.base, slean.components, slean.compositions, slean.utilities;

@layer slean.components {
	:where([data-slean='steps']) {
		display: flex;
		margin: 0;
		padding: 0;
		list-style: none;
		counter-reset: slean-step;
		color: var(--slean-fg-muted);
		font-size: var(--slean-text-sm);
		line-height: 1.25rem;
	}

	:where([data-slean='steps'] > li) {
		position: relative;
		flex: 1 1 0;
		min-inline-size: 0;
		padding-block-start: calc(1.75rem + var(--slean-space-2));
		padding-inline-end: var(--slean-space-4);
		counter-increment: slean-step;
		overflow-wrap: anywhere;
	}

	/* Indicator: the step number in a ring. */
	:where([data-slean='steps'] > li)::before {
		content: counter(slean-step);
		content: counter(slean-step) / '';
		position: absolute;
		inset-block-start: 0;
		inset-inline-start: 0;
		display: grid;
		place-items: center;
		box-sizing: border-box;
		inline-size: 1.75rem;
		block-size: 1.75rem;
		border: 1.5px solid var(--slean-border-strong);
		border-radius: 50%;
		background-color: var(--slean-surface);
		color: var(--slean-fg-muted);
		font-size: var(--slean-text-xs);
		font-weight: var(--slean-font-weight-semibold);
		font-variant-numeric: tabular-nums;
		line-height: 1;
	}

	/* Connector: from the indicator to the end of the step. */
	:where([data-slean='steps'] > li:not(:last-child))::after {
		content: '';
		position: absolute;
		inset-block-start: calc(0.875rem - 0.75px);
		inset-inline-start: calc(1.75rem + var(--slean-space-2));
		inset-inline-end: var(--slean-space-2);
		block-size: 1.5px;
		border-radius: 1px;
		background: var(--slean-border);
	}

	:where([data-slean='steps'] [data-slean-part='title']) {
		display: block;
		font-weight: var(--slean-font-weight-medium);
	}

	:where([data-slean='steps'] [data-slean-part='description']) {
		display: block;
		margin-block-start: 0.125rem;
		color: var(--slean-fg-muted);
		font-size: var(--slean-text-xs);
		line-height: 1rem;
	}

	:where([data-slean='steps'] a) {
		color: inherit;
		text-underline-offset: 0.2em;
	}

	/* The completion and error texts, hidden visually and kept for assistive technology. */
	:where([data-slean='steps'] [data-slean-part='complete']),
	:where([data-slean='steps'] [data-slean-part='error']) {
		position: absolute;
		inline-size: 1px;
		block-size: 1px;
		margin: -1px;
		padding: 0;
		border: 0;
		overflow: hidden;
		clip-path: inset(50%);
		white-space: nowrap;
	}

	/* Current step. */
	:where([data-slean='steps'] > li[aria-current='step']) {
		color: var(--slean-fg);
	}

	:where([data-slean='steps'] > li[aria-current='step'] [data-slean-part='title']) {
		font-weight: var(--slean-font-weight-semibold);
	}

	:where([data-slean='steps'] > li[aria-current='step'])::before {
		border-color: var(--slean-color-main);
		background-color: var(--slean-color-main);
		color: var(--slean-color-contrast-text);
	}

	/* Complete step: a primary disc with the check icon cut out of it, the surface showing through. */
	:where([data-slean='steps'] > li:has([data-slean-part='complete'])) {
		color: var(--slean-fg);
	}

	:where([data-slean='steps'] > li:has([data-slean-part='complete']))::before {
		content: '';
		border-color: transparent;
		background-color: var(--slean-color-main);
		mask-image: var(--slean-icon-check), linear-gradient(currentColor 0 0);
		mask-position: center;
		mask-size:
			1rem,
			100% 100%;
		mask-repeat: no-repeat;
		mask-composite: exclude;
	}

	:where([data-slean='steps'] > li:has([data-slean-part='complete']):not(:last-child))::after {
		background: var(--slean-color-main);
	}

	/* A step with a problem: an error disc with the warning icon cut out of it, over any other state. */
	:where([data-slean='steps'] > li:has([data-slean-part='error'])) {
		color: var(--slean-fg);
	}

	:where([data-slean='steps'] > li:has([data-slean-part='error']))::before {
		content: '';
		border-color: transparent;
		background-color: var(--slean-error-main);
		mask-image: var(--slean-icon-warning), linear-gradient(currentColor 0 0);
		mask-position: center;
		mask-size:
			1rem,
			100% 100%;
		mask-repeat: no-repeat;
		mask-composite: exclude;
	}

	/* Vertical: the indicator on the inline start, the connector below it. */
	:where([data-slean='steps'][data-slean-orientation='vertical']) {
		flex-direction: column;
	}

	:where([data-slean='steps'][data-slean-orientation='vertical'] > li) {
		flex: none;
		min-block-size: 1.75rem;
		padding-block: 0.25rem var(--slean-space-5);
		padding-inline: calc(1.75rem + var(--slean-space-3)) 0;
	}

	:where([data-slean='steps'][data-slean-orientation='vertical'] > li:last-child) {
		padding-block-end: 0;
	}

	:where([data-slean='steps'][data-slean-orientation='vertical'] > li:not(:last-child))::after {
		inset-block: calc(1.75rem + var(--slean-space-1)) var(--slean-space-1);
		inset-inline: calc(0.875rem - 0.75px) auto;
		inline-size: 1.5px;
		block-size: auto;
	}

	@media (forced-colors: active) {
		:where([data-slean='steps'] > li)::before,
		:where([data-slean='steps'] > li:not(:last-child))::after {
			forced-color-adjust: none;
		}

		:where([data-slean='steps'] > li)::before {
			border-color: CanvasText;
			background-color: Canvas;
			color: CanvasText;
		}

		:where([data-slean='steps'] > li:not(:last-child))::after {
			background: CanvasText;
		}

		:where([data-slean='steps'] > li:has([data-slean-part='error']))::before {
			background-color: CanvasText;
		}

		:where([data-slean='steps'] > li[aria-current='step'])::before {
			border-color: Highlight;
			background-color: Highlight;
			color: HighlightText;
		}

		:where([data-slean='steps'] > li:has([data-slean-part='complete']))::before {
			border-color: transparent;
			background-color: CanvasText;
		}
	}
}
