@charset "UTF-8";

/**
 * sidebar.css 1.4.0
 * Author: hybrid.
 * Type: core
 * Load: optional
 *
 * Core layout — aside, sidebar.
 * Project overrides live in styles-layout.css (load sidebar.css before it).
 * All selectors are wrapped in :where() — specificity stays at 0 for the element part.
 *
 * Position
 * The aside follows the DOM order, like .columns.
 * Stacked below 1000px (layout.css): the aside stays where it is in the DOM.
 * From 1000px: .reversed swaps the side compared to the DOM order (row-reverse on the section):
 * a second aside is shown first, a first aside is shown last.
 *
 * Modifiers
 * .reversed  — swaps the aside side compared to the DOM order, desktop only (section: row-reverse)
 * .short     — reduced flex-grow (1/3 instead of 1/2)
 * .sticky    — sticks under the header
 *
 * Tokens
 * Declared on :root and on section, so they follow section.full / .min / .large:
 * override them on the section, not on the aside.
 * --aside-size        flex-grow of aside/.sidebar in a flex section (default: 1/2, .short: 1/3)
 * --aside-min-width   min-width of aside/.sidebar, falls back to --columns-min-width
 * --aside-max-width   max-width of aside/.sidebar, falls back to --content-max-width
 * --aside-width       width of aside/.sidebar, falls back to --section-width
 * --aside-gap-x       horizontal margin of aside/.sidebar (--section-gap-x)
 * --aside-gap-y       vertical margin of aside/.sidebar (--section-gap-y)
 * --aside-sticky-top  sticky offset of .sticky (--header-height)
 *
 * Dependencies
 * --gutter-gap        structural spacing between section-content and aside — defined in layout.css
 * --section-gap-x     horizontal section margin — defined in layout.css
 * --section-gap-y     vertical section margin — defined in layout.css
 * --content-max-width max-width of content areas — defined in layout.css
 * --section-width     default section width — defined in layout.css
 * --header-height     sticky offset — defined in layout.css
 * --columns-min-width defined in columns.css (optional — fallback provided)
 */



/* ================================================================================================== */
/* ============================================= CONFIG ============================================= */
/* ================================================================================================== */

/* ============================== DEFAULT ============================== */

/* declared on section too: resolved against section.full / .min / .large, not frozen on :root */

:root,
section {
	--aside-size: calc(1 / 2);
	--aside-min-width: var(--columns-min-width, 15rem);
	--aside-max-width: var(--content-max-width, 100%);
	--aside-width: var(--section-width, 100%);
	--aside-gap-x: var(--section-gap-x);
	--aside-gap-y: var(--section-gap-y);
	--aside-sticky-top: var(--header-height, 0px);
}



/* =================================================================================================== */
/* ============================================= SIDEBAR ============================================= */
/* =================================================================================================== */

/* aside and .sidebar are not always the same element — both handled in parallel */

/* ============================== DEFAULT ============================== */

:where(aside, .sidebar) {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	width: var(--aside-width);
	min-width: var(--aside-min-width);
	max-width: var(--aside-max-width);
	margin-inline: var(--aside-gap-x);
	margin-block: var(--aside-gap-y);
}


/* ============================== MODIFIERS ============================== */

/* .short — token override, scoped to the section that holds the aside */

section:has(> :where(aside, .sidebar).short) { --aside-size: calc(1 / 3); }

:where(aside, .sidebar).sticky {
	position: sticky;
	z-index: 200;
	top: var(--aside-sticky-top);
}

/* .reversed — see @MEDIA (desktop only) */


/* ============================== IN SECTION ============================== */

/* direct children only — an aside nested in content must not change the section */

section:has(> :where(aside, .sidebar)) { flex-wrap: wrap; }

section:has(> :where(aside, .sidebar)) > .section-content {
	flex-grow: 1;
	min-width: var(--aside-min-width);
}

section > :where(aside, .sidebar) {
	position: relative;
	z-index: 10;
	flex-grow: var(--aside-size);
	flex-basis: 0;
}


/* ============================== @MEDIA ============================== */

/* stacked: an aside first in the DOM has no bottom margin, the content carries the spacing */

@media (width < 1000px) {
	section > :where(aside, .sidebar):first-child { margin-bottom: 0; }
}

/*
 * Row layout
 * The vertical spacing is carried by .section-content only.
 * Facing sides share the inner gap (gutter-gap / 2), outer sides keep the section gap.
 * "First" = first in the DOM without .reversed, or second in the DOM with .reversed (row-reverse).
 */

@media (min-width: 1000px) {

	/* =============== REVERSED =============== */

	section:has(> :where(aside, .sidebar).reversed) { flex-direction: row-reverse; }


	/* =============== COMMON =============== */

	section:has(> :where(aside, .sidebar)) > .section-content {
		flex-grow: calc(1 - var(--aside-size));
		flex-basis: 0;
	}
	section > .section-content:not(:only-child) {
		max-width: calc(var(--content-max-width) * (1 - var(--aside-size)) - var(--aside-gap-x) / 2);
	}
	section > .section-content ~ :where(aside, .sidebar),
	section > :where(aside, .sidebar):has(~ .section-content) {
		max-width: calc(var(--content-max-width) * var(--aside-size) - var(--aside-gap-x) / 2);
	}


	/* =============== ASIDE LAST (default) =============== */

	section:has(> :where(aside, .sidebar)) > .section-content { margin-right: calc(var(--gutter-gap) / 2); }
	section > :where(aside, .sidebar) { margin-left: calc(var(--gutter-gap) / 2); }


	/* =============== ASIDE FIRST =============== */

	section:has(> :where(aside, .sidebar):is(:first-child:not(.reversed), .reversed:not(:first-child))) > .section-content {
		margin-left: calc(var(--gutter-gap) / 2);
		margin-right: var(--section-gap-x);
	}
	section > :where(aside, .sidebar):is(:first-child:not(.reversed), .reversed:not(:first-child)) {
		margin-left: var(--aside-gap-x);
		margin-right: calc(var(--gutter-gap) / 2);
	}
}