/**
 * Table of Contents module – styles
 * Override any variable from Customizer > Additional CSS, e.g.
 *   .ctoc { --ctoc-accent: #e4572e; --ctoc-radius: 4px; }
 */

.ctoc {
	--ctoc-accent:#036643;
	--ctoc-text: #2b2f36;
	--ctoc-muted: #6b7280;
	--ctoc-bg: #ffffff;
	--ctoc-border: #e5e7eb;
	--ctoc-hover-bg: rgba(0, 137, 247, 0.08);
	--ctoc-radius: 10px;
	--ctoc-offset: 100px;

	box-sizing: border-box;
	width: 100%;
	margin: 0 0 30px;
	background: var(--ctoc-bg);
	border: 1px solid var(--ctoc-border);
	border-radius: var(--ctoc-radius);
	box-shadow: 0 2px 10px rgba(17, 24, 39, 0.04);
	color: var(--ctoc-text);
	font-size: 15px;
	line-height: 1.5;
}

.ctoc *,
.ctoc *::before,
.ctoc *::after {
	box-sizing: border-box;
}

.ctoc[hidden] {
	display: none !important;
}

/* ---------- Header ---------- */

.ctoc .ctoc__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	width: 100%;
	margin: 0;
	padding: 14px 18px;
	background: none;
	border: 0;
	border-radius: var(--ctoc-radius);
	box-shadow: none;
	color: inherit;
	font: inherit;
	letter-spacing: normal;
	text-align: start;
	text-transform: none;
}

.ctoc button.ctoc__header {
	cursor: pointer;
}

.ctoc .ctoc__title {
	color: var(--ctoc-text);
	font-size: 1.1em;
	font-weight: 700;
	line-height: 1.3;
}

.ctoc .ctoc__header:focus-visible,
.ctoc .ctoc__link:focus-visible {
	outline: 2px solid var(--ctoc-accent);
	outline-offset: 2px;
}

.ctoc .ctoc__icon {
	flex: none;
	width: 9px;
	height: 9px;
	margin-inline-end: 4px;
	border-inline-end: 2px solid var(--ctoc-muted);
	border-bottom: 2px solid var(--ctoc-muted);
	transform: rotate(45deg) translateY(-2px);
	transition: transform 0.25s ease;
}

.ctoc.is-collapsed .ctoc__icon {
	transform: rotate(-45deg);
}

[dir="rtl"] .ctoc.is-collapsed .ctoc__icon {
	transform: rotate(135deg);
}

/* ---------- Body (animated collapse) ---------- */

.ctoc .ctoc__body {
	display: grid;
	grid-template-rows: 1fr;
	transition: grid-template-rows 0.28s ease;
}

.ctoc.is-collapsed .ctoc__body {
	grid-template-rows: 0fr;
}

.ctoc .ctoc__inner {
	min-height: 0;
	overflow-x: hidden;
	overflow-y: auto;
	position: relative;
	padding: 0 12px 12px;
	transition: visibility 0.28s;
}

.ctoc.is-collapsed .ctoc__inner {
	visibility: hidden;
}

/* ---------- List ---------- */

.ctoc .ctoc__list,
.ctoc .ctoc__list ol {
	margin: 0;
	padding: 0;
	list-style: none;
}

.ctoc .ctoc__item {
	margin: 0;
	padding: 0;
	list-style: none;
}

.ctoc .ctoc__item::before,
.ctoc .ctoc__item::marker {
	content: none;
}

.ctoc .ctoc__list .ctoc__list {
	margin-inline-start: 14px;
	padding-inline-start: 8px;
	border-inline-start: 1px solid var(--ctoc-border);
	font-size: 0.95em;
}

.ctoc .ctoc__link {
	display: flex;
	align-items: baseline;
	gap: 0.55em;
	margin: 1px 0;
	padding: 6px 10px;
	border-inline-start: 2px solid transparent;
	border-radius: 6px;
	box-shadow: none;
	color: var(--ctoc-text);
	text-decoration: none;
	transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
	word-break: break-word;
}

.ctoc .ctoc__link:hover {
	background: var(--ctoc-hover-bg);
	color: var(--ctoc-accent);
	text-decoration: none;
}

.ctoc .ctoc__link.is-active {
	background: var(--ctoc-hover-bg);
	border-inline-start-color: var(--ctoc-accent);
	color: var(--ctoc-accent);
	font-weight: 600;
}

/* Numbering: 1.  1.1  1.2  2.  … */
.ctoc--numbered .ctoc__list {
	counter-reset: ctoc;
}

.ctoc--numbered .ctoc__item {
	counter-increment: ctoc;
}

.ctoc--numbered .ctoc__link::before {
	content: counters(ctoc, ".") ".";
	flex: none;
	min-width: 1.7em;
	color: var(--ctoc-muted);
	font-variant-numeric: tabular-nums;
	font-weight: 500;
}

.ctoc--numbered .ctoc__link.is-active::before {
	color: inherit;
}

/* ---------- Sticky ---------- */

.ctoc--sticky {
	position: sticky;
	top: var(--ctoc-offset);
	z-index: 5;
}

.ctoc--sticky .ctoc__inner {
	max-height: calc(100vh - var(--ctoc-offset) - 90px);
}

/* ---------- Styles ---------- */

.ctoc--minimal {
	--ctoc-bg: transparent;
	border: 0;
	border-inline-start: 3px solid var(--ctoc-accent);
	border-radius: 0;
	box-shadow: none;
}

.ctoc--minimal .ctoc__header {
	border-radius: 0;
}

.ctoc--dark {
	--ctoc-accent: #5eb8ff;
	--ctoc-text: #e5e7eb;
	--ctoc-muted: #9ca3af;
	--ctoc-bg: #111827;
	--ctoc-border: #2f3a4d;
	--ctoc-hover-bg: rgba(255, 255, 255, 0.07);
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}

/* ---------- Smooth scrolling (only when a TOC is on the page) ---------- */

@media (prefers-reduced-motion: no-preference) {
	html.ctoc-smooth {
		scroll-behavior: smooth;
	}
}

@media (prefers-reduced-motion: reduce) {
	.ctoc .ctoc__body,
	.ctoc .ctoc__icon,
	.ctoc .ctoc__link {
		transition: none;
	}
}

/* ---------- Small screens ---------- */

@media (max-width: 767px) {
	.ctoc {
		font-size: 14px;
	}

	/* Sticky behaves badly inside stacked mobile columns. */
	.ctoc--sticky {
		position: static;
	}

	.ctoc--sticky .ctoc__inner {
		max-height: 60vh;
	}
}

/* ---------- Print ---------- */

@media print {
	.ctoc {
		box-shadow: none;
		break-inside: avoid;
	}

	.ctoc .ctoc__icon {
		display: none;
	}

	.ctoc.is-collapsed .ctoc__body {
		grid-template-rows: 1fr;
	}

	.ctoc.is-collapsed .ctoc__inner {
		visibility: visible;
	}
}
