/* =================================================================
   Modern TOC — Base Plugin Stylesheet (mtoc.css)
   v6.0.0
   Structural + accordion mechanics. Themeable via CSS custom properties.
   ================================================================= */

/* --- Custom Properties (defaults) --------------------------------- */
:root {
	--mtoc-bg:          #ffffff;
	--mtoc-link:        #333333;
	--mtoc-width:       auto;
	--mtoc-max-height:  none;
	--mtoc-radius:      8px;
	--mtoc-border:      #e5e7eb;
	--mtoc-header-bg:   transparent;
}


/* --- 1. WRAPPER --------------------------------------------------- */

.mtoc-wrapper {
	width: var(--mtoc-width);
}


/* --- 2. CONTAINER (nav) ------------------------------------------- */

.mtoc-container {
	background: transparent;
	/*border: 1px solid var(--mtoc-border);
	border-radius: var(--mtoc-radius);*/
	overflow: hidden;
	display: flex;
	flex-direction: column;
}


/* --- 3. HEADER ---------------------------------------------------- */

.mtoc-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0.85rem 1rem;
	border-bottom: 1px solid var(--mtoc-border);
	background: var(--mtoc-header-bg);
	flex-shrink: 0;
}

.mtoc-title {
	font-size: 0.75rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--mtoc-link);
	opacity: 0.5;
	margin: 0;
	padding: 0;
	line-height: 1;
}

/* Global toggle (collapse entire TOC) */
.mtoc-toggle {
	background: none;
	border: none;
	padding: 4px;
	margin: 0;
	cursor: pointer;
	color: var(--mtoc-link);
	opacity: 0.45;
	border-radius: 4px;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: opacity 0.2s ease, background 0.2s ease;
}
.mtoc-toggle:hover {
	opacity: 0.8;
	background: rgba(0, 0, 0, 0.04);
}
.mtoc-toggle svg {
	width: 18px;
	height: 18px;
	transition: transform 0.25s ease;
}
/* Collapsed state — JS toggles .mtoc-body--collapsed */
.mtoc-container.is-collapsed .mtoc-toggle svg {
	transform: rotate(180deg);
}
.mtoc-container.is-collapsed .mtoc-body {
	display: none;
}


/* --- 4. BODY — scrollable, invisible scrollbar -------------------- */

.mtoc-body {
	overflow-y: auto;
	overflow-x: hidden;
	flex: 1 1 auto;
	min-height: 0;
	padding: 0.35rem 0;
	overscroll-behavior: contain;

	/* Hide scrollbar — all engines */
	scrollbar-width: none;               /* Firefox  */
	-ms-overflow-style: none;            /* IE/Edge  */
}
.mtoc-body::-webkit-scrollbar {
	display: none;                       /* Chrome / Safari / Opera */
}

/* When max-height is set by the plugin (inline style or CSS var) */
.mtoc-body--scrollable {
	max-height: var(--mtoc-max-height, none);
}


/* --- 5. LIST RESET ------------------------------------------------ */

.mtoc-list,
.mtoc-children {
	list-style: none;
	margin: 0;
	padding: 0;
}


/* --- 6. TOP-LEVEL ITEMS (e.g. H2) -------------------------------- */

.mtoc-item {
	margin: 0;
	padding: 0;
}

/* Direct link (items without children) */
.mtoc-item > a.mtoc-link {
	display: block;
	padding: 0.5rem 1rem;
	text-decoration: none;
	line-height: 1.45;
	transition: color 0.15s ease, background 0.15s ease;
}

/* Row container for items WITH children: link + toggle side by side */
.mtoc-row {
	display: flex;
	gap: 0rem;
}

.mtoc-row > .mtoc-link {
	flex: 1 1 auto;
	min-width: 0;         /* allow text truncation / wrapping */
	display: block;
	padding: 0.5rem 0 0.5rem 1rem;
	text-decoration: none;
	line-height: 1.45;
	transition: color 0.15s ease, background 0.15s ease;
	padding-right: 1.5rem;
}

/* Per-section expand/collapse button — sits on the RIGHT */
.mtoc-expand {
	flex: 0 0 auto;
	background: none;
	border: none;
	padding: 0.5rem 0.75rem;
	margin: 0;
	cursor: pointer;
	color: var(--mtoc-link);
	opacity: 0.3;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: opacity 0.2s ease, background 0.2s ease;
}
.mtoc-expand:hover {
	opacity: 0.7;
	background: rgba(0, 0, 0, 0.03);
}

.mtoc-expand__icon {
	width: 14px;
	height: 14px;
	transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
	transform: rotate(0deg);
	color: white;
}

/* Expanded state — JS toggles .is-expanded on the <li> */
.mtoc-has-children.is-expanded > .mtoc-row > .mtoc-expand .mtoc-expand__icon {
	transform: rotate(90deg);
}
.mtoc-has-children.is-expanded > .mtoc-row > .mtoc-expand {
	opacity: 0.55;
}


/* --- 7. CHILDREN LIST — collapsible ------------------------------- */

.mtoc-children {
	overflow: hidden;
	max-height: 0;
	opacity: 0;
	transition:
		max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
		opacity    0.25s ease;
}

.mtoc-has-children.is-expanded > .mtoc-children {
	max-height: 800px;   /* large enough for any reasonable sub-list */
	opacity: 1;
}


/* --- 8. HIERARCHY — level-based styling via CSS vars -------------- */

/*
 * The plugin injects --mtoc-link-hN, --mtoc-weight-hN, --mtoc-size-hN
 * via wp_add_inline_style.  Fallbacks below ensure graceful defaults.
 */

/* Top-level items (H2 by default) */
.mtoc-item-2 > a.mtoc-link,
.mtoc-item-2 > .mtoc-row > .mtoc-link {
	color: var(--mtoc-link-h2, var(--mtoc-link));
	font-weight: var(--mtoc-weight-h2, 600);
	font-size: var(--mtoc-size-h2, 0.875rem);
}

/* Second level (H3) — indented */
.mtoc-item-3 > a.mtoc-link,
.mtoc-item-3 > .mtoc-row > .mtoc-link {
	padding-left: 1.75rem;
	color: var(--mtoc-link-h3, var(--mtoc-link));
	font-weight: var(--mtoc-weight-h3, 400);
	font-size: var(--mtoc-size-h3, 0.825rem);
}

/* Third level (H4) — deeper indent */
.mtoc-item-4 > a.mtoc-link,
.mtoc-item-4 > .mtoc-row > .mtoc-link {
	padding-left: 2.5rem;
	color: var(--mtoc-link-h4, var(--mtoc-link));
	font-weight: var(--mtoc-weight-h4, 400);
	font-size: var(--mtoc-size-h4, 0.8rem);
}

/* Fourth level (H5) */
.mtoc-item-5 > a.mtoc-link,
.mtoc-item-5 > .mtoc-row > .mtoc-link {
	padding-left: 3.25rem;
	color: var(--mtoc-link-h5, var(--mtoc-link));
	font-weight: var(--mtoc-weight-h5, 400);
	font-size: var(--mtoc-size-h5, 0.775rem);
}

/* Fifth level (H6) */
.mtoc-item-6 > a.mtoc-link,
.mtoc-item-6 > .mtoc-row > .mtoc-link {
	padding-left: 4rem;
	color: var(--mtoc-link-h6, var(--mtoc-link));
	font-weight: var(--mtoc-weight-h6, 400);
	font-size: var(--mtoc-size-h6, 0.75rem);
}


/* --- 9. ACTIVE STATE ---------------------------------------------- */

.mtoc-link.is-active {
	color: var(--mtoc-link) !important;
	font-weight: 600 !important;
}


/* --- 10. HOVER ---------------------------------------------------- */

.mtoc-link:hover {
	color: var(--mtoc-link);
	opacity: 0.75;
}


/* --- 11. REDUCED MOTION ------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	.mtoc-children {
		transition: none;
	}
	.mtoc-expand__icon {
		transition: none;
	}
	.mtoc-toggle svg {
		transition: none;
	}
}