/* @svelte-lean/styles — listbox (Tier 1; keyboard behavior comes from @svelte-lean/primitives/listbox).
 * Markup: <ul role="listbox" aria-label="…" data-slean="listbox"> <li role="option"
 * aria-selected="true" tabindex="0" data-slean-value="…">…, or a root around a
 * [data-slean-part="list"][role="listbox"]. Selection is aria-selected; the roving tabindex is the
 * tab stop; disabled options carry aria-disabled. Options: data-slean-orientation="horizontal"
 * lays the options out in a row; data-slean-multiple draws a check mark on selected options
 * instead of filling the row. Options are focused directly, so the focus ring is drawn here (the
 * shared ring in base.css only covers [data-slean] and [data-slean-part] elements).
 * Looks: data-color picks the selected fill and the check mark (primary by default). */
@layer slean.reset, slean.tokens, slean.base, slean.components, slean.compositions, slean.utilities;

@layer slean.components {
	:where([data-slean='listbox'][role='listbox']),
	:where([data-slean='listbox'] [role='listbox']) {
		display: flex;
		flex-direction: column;
		gap: 1px;
		margin: 0;
		padding: var(--slean-space-1);
		border: 1px solid var(--slean-border);
		border-radius: var(--slean-radius-md);
		background: var(--slean-surface);
		color: var(--slean-fg);
		list-style: none;
		overflow: auto;
		overscroll-behavior: contain;
	}

	:where([data-slean='listbox'][data-slean-orientation='horizontal'][role='listbox']),
	:where([data-slean='listbox'][data-slean-orientation='horizontal'] [role='listbox']) {
		flex-direction: row;
		flex-wrap: wrap;
		gap: var(--slean-space-1);
	}

	:where([data-slean='listbox'] [role='option']) {
		position: relative;
		display: flex;
		align-items: center;
		gap: var(--slean-space-2);
		min-block-size: var(--slean-control-height-sm);
		padding-block: var(--slean-space-1);
		padding-inline: var(--slean-space-2);
		border-radius: var(--slean-radius-sm);
		color: var(--slean-fg);
		font-size: var(--slean-text-sm);
		font-variant-numeric: tabular-nums;
		text-align: start;
		cursor: default;
		user-select: none;
		-webkit-tap-highlight-color: transparent;
	}

	@media (hover: hover) {
		:where([data-slean='listbox'] [role='option']:hover:not([aria-disabled='true'])) {
			background: var(--slean-muted);
		}
	}

	/* Keyboard focus is the row's fill, as a hover; forced colors paint the transparent outline. */
	:where([data-slean='listbox'] [role='option']:focus-visible) {
		background: var(--slean-option-active);
		outline: var(--slean-focus-ring);
		outline-color: transparent;
		outline-offset: calc(-1 * var(--slean-focus-ring-width));
	}

	:where([data-slean='listbox'] [role='option'][aria-selected='true']) {
		background: var(--slean-color-soft);
		color: var(--slean-color-soft-text);
	}

	/* A chosen option that has keyboard focus: its fill stays, a thin inset line marks the focus. */
	:where([data-slean='listbox'] [role='option'][aria-selected='true']:focus-visible) {
		box-shadow: inset 0 0 0 1px var(--slean-color-soft-text);
	}

	:where([data-slean='listbox'] [role='option'][aria-disabled='true']) {
		opacity: 0.5;
		cursor: not-allowed;
	}

	/* Multi-select: rows stay neutral and selected options show the check icon at the start. */
	:where([data-slean='listbox'][data-slean-multiple] [role='option']) {
		padding-inline-start: calc(var(--slean-space-2) + 1.25rem);
	}

	:where([data-slean='listbox'][data-slean-multiple] [role='option'][aria-selected='true']) {
		background: transparent;
		color: var(--slean-fg);
	}

	:where([data-slean='listbox'][data-slean-multiple] [role='option'])::before {
		content: '';
		position: absolute;
		inset-block: 0;
		inset-inline-start: var(--slean-space-2);
		inline-size: 1rem;
		block-size: 1rem;
		margin-block: auto;
		background: var(--slean-color-main);
		mask: var(--slean-icon-check) center / contain no-repeat;
		opacity: 0;
	}

	:where(
		[data-slean='listbox'][data-slean-multiple] [role='option'][aria-selected='true']
	)::before {
		opacity: 1;
	}

	:where([data-slean='listbox'] [role='group']) {
		display: contents;
	}

	:where([data-slean='listbox'] [data-slean-part='group-label']) {
		padding-block: var(--slean-space-1);
		padding-inline: var(--slean-space-2);
		color: var(--slean-fg-muted);
		font-size: var(--slean-text-xs);
		font-weight: var(--slean-font-weight-medium);
	}

	@media (forced-colors: active) {
		:where([data-slean='listbox'] [role='option'][aria-selected='true']) {
			forced-color-adjust: none;
			background: Highlight;
			color: HighlightText;
		}

		/* The focus ring token is Highlight, the same color as the selected fill; on a selected
		 * option (every focused option in automatic mode) the inset ring takes the text color. */
		:where([data-slean='listbox'] [role='option'][aria-selected='true']:focus-visible) {
			outline-color: HighlightText;
		}

		:where([data-slean='listbox'][data-slean-multiple] [role='option'][aria-selected='true']) {
			background: Highlight;
			color: HighlightText;
		}

		:where([data-slean='listbox'][data-slean-multiple] [role='option'])::before {
			forced-color-adjust: none;
			background: currentColor;
		}

		:where([data-slean='listbox'] [role='option'][aria-disabled='true']) {
			color: GrayText;
			opacity: 1;
		}
	}
}
