/* @svelte-lean/styles — pagination (Tier 0, <nav> + a list of links + aria-current="page").
 * Markup: <nav aria-label="Pagination" data-slean="pagination"> <ul> <li><a href="?page=4"
 * rel="prev" data-slean-part="previous">Previous</a></li> <li><a href="?page=1">1</a></li>
 * <li data-slean-part="ellipsis" aria-hidden="true">…</li> … <li><a href="?page=5"
 * aria-current="page">5</a></li> … <li><a href="?page=6" rel="next"
 * data-slean-part="next">Next</a></li> </ul> </nav>. The current page is aria-current="page".
 * At an end, previous or next is an <a> without href: not a link, not focusable, muted here.
 * The chevrons and the ellipsis are icons masked on pseudo-elements (the ellipsis text stays for
 * copy and paste but is not drawn); the chevrons are mirrored under :dir(rtl). Color: data-color
 * on the root or an ancestor tints the current page (primary by default). Sizes (data-size):
 * small, medium (default), large. */
@layer slean.reset, slean.tokens, slean.base, slean.components, slean.compositions, slean.utilities;

@layer slean.components {
	:where([data-slean='pagination']) {
		color: var(--slean-fg);
		font-size: var(--slean-text-sm);
		line-height: 1.25;
	}

	:where([data-slean='pagination'] ul) {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		gap: var(--slean-space-1);
		margin: 0;
		padding: 0;
		list-style: none;
	}

	:where([data-slean='pagination'] a) {
		box-sizing: border-box;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		gap: var(--slean-space-2);
		min-inline-size: var(--slean-control-height-md);
		min-block-size: var(--slean-control-height-md);
		padding-inline: var(--slean-space-3);
		border: 1px solid transparent;
		border-radius: var(--slean-radius-md);
		color: inherit;
		font-weight: var(--slean-font-weight-medium);
		font-variant-numeric: tabular-nums;
		text-decoration: none;
		white-space: nowrap;
		-webkit-tap-highlight-color: transparent;
		transition:
			background-color var(--slean-duration-fast) var(--slean-ease),
			color var(--slean-duration-fast) var(--slean-ease);
	}

	:where([data-slean='pagination'] a:focus-visible) {
		outline: var(--slean-focus-ring);
		outline-offset: var(--slean-focus-ring-offset);
	}

	@media (hover: hover) {
		:where([data-slean='pagination'] a[href]:not([aria-current='page']):hover) {
			background: var(--slean-muted);
		}
	}

	:where([data-slean='pagination'] a[aria-current='page']) {
		border-color: color-mix(in oklch, var(--slean-color-main) 30%, transparent);
		background: var(--slean-color-soft);
		color: var(--slean-color-soft-text);
		font-weight: var(--slean-font-weight-semibold);
	}

	/* Previous or next at an end: rendered without href, so it is text. The muted text color keeps
	 * it readable (contrast checkers see text, not a disabled control); the chevron is dimmed. */
	:where([data-slean='pagination'] a:not([href])) {
		color: var(--slean-fg-muted);
		font-weight: inherit;
		cursor: default;
	}

	:where([data-slean='pagination'] a:not([href]))::before,
	:where([data-slean='pagination'] a:not([href]))::after {
		opacity: 0.6;
	}

	:where([data-slean='pagination'] [data-slean-part='ellipsis']) {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		min-inline-size: var(--slean-control-height-md);
		min-block-size: var(--slean-control-height-md);
		color: var(--slean-fg-muted);
		font-size: 0;
		user-select: none;
	}

	/* Icons: previous points to the inline start, next to the inline end. */
	:where([data-slean='pagination'] [data-slean-part='previous'])::before,
	:where([data-slean='pagination'] [data-slean-part='ellipsis'])::before,
	:where([data-slean='pagination'] [data-slean-part='next'])::after {
		content: '';
		flex: none;
		inline-size: 1rem;
		block-size: 1rem;
		background: currentColor;
		mask: var(--slean-icon-chevron-left) center / contain no-repeat;
	}

	:where([data-slean='pagination'] [data-slean-part='previous'])::before {
		margin-inline-start: calc(-1 * var(--slean-space-1));
	}

	:where([data-slean='pagination'] [data-slean-part='next'])::after {
		margin-inline-end: calc(-1 * var(--slean-space-1));
		mask-image: var(--slean-icon-chevron-right);
	}

	:where([data-slean='pagination'] [data-slean-part='ellipsis'])::before {
		mask-image: var(--slean-icon-more);
	}

	/* Sizes. */
	:where([data-slean='pagination'][data-size='small'] a),
	:where([data-slean='pagination'][data-size='small'] [data-slean-part='ellipsis']) {
		min-inline-size: var(--slean-control-height-sm);
		min-block-size: var(--slean-control-height-sm);
	}

	:where([data-slean='pagination'][data-size='small'] a) {
		padding-inline: var(--slean-space-2);
		font-size: var(--slean-text-xs);
	}

	:where([data-slean='pagination'][data-size='large'] a),
	:where([data-slean='pagination'][data-size='large'] [data-slean-part='ellipsis']) {
		min-inline-size: var(--slean-control-height-lg);
		min-block-size: var(--slean-control-height-lg);
	}

	:where([data-slean='pagination'][data-size='large'] a) {
		font-size: var(--slean-text-md);
	}

	:where([data-slean='pagination']:dir(rtl) [data-slean-part='previous'])::before,
	:where([data-slean='pagination']:dir(rtl) [data-slean-part='next'])::after {
		scale: -1 1;
	}

	/* Forced colors turn transparent borders into visible ones; keep only the current page's. */
	@media (forced-colors: active) {
		:where([data-slean='pagination'] a) {
			border-color: Canvas;
		}

		:where([data-slean='pagination'] a[aria-current='page']) {
			border-color: Highlight;
			color: Highlight;
		}

		:where([data-slean='pagination'] a:not([href])) {
			color: GrayText;
		}

		:where([data-slean='pagination'] [data-slean-part='previous'])::before,
		:where([data-slean='pagination'] [data-slean-part='ellipsis'])::before,
		:where([data-slean='pagination'] [data-slean-part='next'])::after {
			forced-color-adjust: none;
			background: currentColor;
		}
	}
}
