/* Table of contents (docs/widgets/toc.md), in the design language (spec §3.7). This is Soft, the
   default: a white card with a thin border and a soft shadow, the title above a thin line, links in
   the soft grey, and the current section a pale pill in the accent, in bold, so it isn't shown by
   colour alone. Fonts come from the theme. toc-outline.css and toc-solid.css change only the
   --hafe-toc-d-* tokens and the shared radius and shadow, on .hafe-toc itself, so a Style control's
   own property always wins. */
.hafe-toc {
	--hafe-toc-d-card: var(--hafe-surface);
	--hafe-toc-d-edge: var(--hafe-line);
	--hafe-toc-d-head: transparent;
	--hafe-toc-d-head-ink: var(--hafe-ink);
	--hafe-toc-d-head-line: var(--hafe-line);
	--hafe-toc-d-head-lw: 1px;
	--hafe-toc-d-now: var(--hafe-tint);
	--hafe-toc-d-now-ink: var(--hafe-accent-ink);
	--hafe-toc-d-now-line: transparent;
	--hafe-toc-d-link-radius: 0.5em;
	--hafe-toc-pad: 0.75em 1.25em;
	box-sizing: border-box;
	overflow: clip;
	border: var(--hafe-toc-border-width, 1px) solid var(--hafe-toc-border-color, var(--hafe-toc-d-edge));
	border-radius: var(--hafe-toc-radius, var(--hafe-radius));
	background: var(--hafe-toc-bg, var(--hafe-toc-d-card));
	box-shadow: var(--hafe-shadow);
	color: var(--hafe-ink);
}

.hafe-toc[hidden],
.hafe-toc__body[hidden] {
	display: none;
}

/* The title runs from edge to edge, so its line (or Solid's band) meets the card's border. */
.hafe-toc .hafe-toc__title {
	margin: 0 0 var(--hafe-toc-title-gap, 0);
	padding: var(--hafe-toc-pad);
	border-block-end: var(--hafe-toc-d-head-lw) solid var(--hafe-toc-d-head-line);
	background: var(--hafe-toc-d-head);
	color: var(--hafe-toc-title-color, var(--hafe-toc-d-head-ink));
	font-size: 1.05em;
	font-weight: 600;
}

/* Closed, the title is all there is: no line under it. */
.hafe-toc .hafe-toc__title:has(.hafe-toc__toggle[aria-expanded="false"]) {
	margin-bottom: 0;
	border-block-end-color: transparent;
}

.hafe-toc__body {
	padding: var(--hafe-toc-padding, 0.75em);
}

/* Long words (a URL, a product code) wrap rather than overflow the box on phones (found in a
   screenshot), and the toggle's chevron stays in view. */
.hafe-toc__title,
.hafe-toc__toggle > span,
.hafe-toc__link {
	min-width: 0;
	overflow-wrap: anywhere;
}

/* Specific enough to undo the button styles of themes and Elementor kits. */
.hafe-toc .hafe-toc__toggle.hafe-toc__toggle {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5em;
	width: 100%;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 0;
	background: none;
	box-shadow: none;
	color: inherit;
	font: inherit;
	letter-spacing: inherit;
	text-align: start;
	text-transform: inherit;
	cursor: pointer;
	appearance: none;
}

/* Stated here too: some packs take the outline off every focused button, site-wide. */
.hafe-toc .hafe-toc__toggle.hafe-toc__toggle:focus-visible {
	outline: 2px solid var(--hafe-accent);
	outline-offset: 2px;
}

.hafe-toc__chevron {
	flex: none;
	width: 1.1em;
	height: 1.1em;
	transition: transform 0.2s;
}

.hafe-toc__toggle[aria-expanded="false"] .hafe-toc__chevron {
	transform: rotate(-90deg);
}

.hafe-toc__toggle[aria-expanded="false"]:dir(rtl) .hafe-toc__chevron {
	transform: rotate(90deg);
}

.hafe-toc__list {
	margin: 0;
	padding: 0;
	list-style: none;
}

.hafe-toc__list .hafe-toc__list {
	margin-top: var(--hafe-toc-item-gap, 0.15em);
	padding-inline-start: var(--hafe-toc-indent, 1em);
}

.hafe-toc__item {
	margin: 0;
}

/* Folded: sub-headings show under the current section, or while the keyboard is in its branch,
   so Tab reaches them from their heading. */
.hafe-toc--fold .hafe-toc__item:not(:has(.is-active), :focus-within) > .hafe-toc__list {
	display: none;
}

.hafe-toc__item + .hafe-toc__item {
	margin-top: var(--hafe-toc-item-gap, 0.15em);
}

/* Every link has its start line, see-through unless it's current in Outline, so switching design
   never moves the text. */
.hafe-toc .hafe-toc__link {
	display: block;
	padding: 0.3em 0.6em;
	border-inline-start: 2px solid transparent;
	border-radius: var(--hafe-toc-d-link-radius);
	color: var(--hafe-toc-link-color, var(--hafe-ink-soft));
	text-decoration: none;
}

.hafe-toc .hafe-toc__link:hover {
	color: var(--hafe-toc-link-hover-color, var(--hafe-ink));
	text-decoration: underline;
}

.hafe-toc .hafe-toc__link.is-active {
	border-inline-start-color: var(--hafe-toc-indicator-color, var(--hafe-toc-d-now-line));
	background: var(--hafe-toc-active-bg, var(--hafe-toc-d-now));
	color: var(--hafe-toc-active-color, var(--hafe-toc-d-now-ink));
	font-weight: 600;
}

.hafe-toc__number {
	color: var(--hafe-toc-number-color, inherit);
	font-variant-numeric: tabular-nums;
}

/* A mouse click on a link leaves no outline on the heading it moves focus to, outside the widget.
   Inside, design.css handles focus. */
.hafe-toc-target:focus:not(:focus-visible) {
	outline: none;
}

/* Logged-in users have the WordPress toolbar fixed at the top (wider than 600 px; narrower, it
   scrolls away), so sticky lists sit below it (found on a demo page). Scroll targets already
   do: WordPress sets the page's scroll-padding-top to the toolbar's height. */
.hafe-toc,
.elementor-element:has(> .hafe-toc--sticky) {
	--hafe-toc-bar: var(--wp-admin--admin-bar--height, 0px);
}

@media (max-width: 600px) {
	.hafe-toc,
	.elementor-element:has(> .hafe-toc--sticky) {
		--hafe-toc-bar: 0px;
	}
}

/* The offset setting, measured by the script in pixels whatever its unit. */
.hafe-toc__probe {
	position: absolute;
	width: 0;
	height: var(--hafe-toc-offset, 0px);
	visibility: hidden;
	pointer-events: none;
}

/* Sticky, through Elementor's wrapper. A list taller than the screen scrolls within. The card
   has its own background, so content scrolling under it never shows through. */
.hafe-toc--sticky,
.elementor-element:has(> .hafe-toc--sticky) {
	position: sticky;
	z-index: 1;
	top: calc(var(--hafe-toc-sticky-top, 1rem) + var(--hafe-toc-bar, 0px));
}

.hafe-toc--sticky {
	max-height: calc(100vh - var(--hafe-toc-sticky-top, 1rem) - var(--hafe-toc-bar, 0px) - 1rem);
	overflow-y: auto;
}

.hafe-empty {
	margin: 0;
	padding: 1em;
	border: 1px dashed currentColor;
	opacity: 0.7;
}

@media (prefers-reduced-motion: reduce) {
	.hafe-toc__chevron {
		transition: none;
	}
}

@media print {
	.hafe-toc--sticky,
	.elementor-element:has(> .hafe-toc--sticky) {
		position: static;
		max-height: none;
		overflow: visible;
	}

	.hafe-toc {
		box-shadow: none;
	}

	.hafe-toc__body[hidden],
	.hafe-toc--fold .hafe-toc__item > .hafe-toc__list {
		display: block;
	}

	.hafe-toc__chevron {
		display: none;
	}
}
