/* ==========================================================================
   IAAP TOC Menu
   Layout rules target the theme column (#side-menu); all visual rules are
   scoped to this plugin's root (#toc) so the side-menu plugin, which also
   lives in a #side-menu column, can never clash with it.
   ========================================================================== */

/* --- Page layout column ------------------------------------------------- */
#primary > .page-layout {
	display: flex;
	flex-direction: column;
	gap: 1rem;
}

#primary > .page-layout > #main {
	width: 100%;
}

#side-menu {
	width: 100%;
}

/* --- Design tokens ------------------------------------------------------ */
#toc {
	--iaap-blue: #0957c3;
	--iaap-blue-dark: #083f8f;
	--iaap-ink: #0b1f3a;
	--iaap-tint: #eaf2fd;
	--iaap-tint-strong: #dbe9fc;
	--iaap-border: #cfe0f9;
}

#toc .sticky-wrapper {
	width: 100%;
	margin: 0 0 1.5rem;
}

/* --- Card --------------------------------------------------------------- */
#toc .sidebar {
	width: 100%;
	overflow-wrap: anywhere;
	overflow: hidden;
	background: #fff;
	border: 1px solid var(--iaap-border);
	border-radius: 14px;
	box-shadow:
		0 1px 2px rgb(9 87 195 / 6%),
		0 10px 24px rgb(9 87 195 / 8%);
}

/* --- Header / toggle ---------------------------------------------------- */
#toc .menu-toggle {
	display: flex;
	width: 100%;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	border: 0;
	background: var(--iaap-tint);
	padding: 0.8rem 1rem;
	color: var(--iaap-ink);
	font: inherit;
	font-size: 1.1rem;
	font-weight: 800;
	text-align: left;
	cursor: pointer;
}

#toc .menu-toggle:hover {
	background: var(--iaap-tint-strong);
}

#toc .menu-toggle:focus-visible {
	outline: 3px solid var(--iaap-blue);
	outline-offset: -3px;
}

#toc .menu-toggle span:last-child {
	display: inline-grid;
	width: 1.9rem;
	height: 1.9rem;
	flex: 0 0 auto;
	place-items: center;
	border: 1px solid var(--iaap-border);
	border-radius: 8px;
	background: #fff;
	color: var(--iaap-blue);
	font-size: 1.35rem;
	font-weight: 400;
}

/* --- List --------------------------------------------------------------- */
#toc .menu-panel {
	padding: 0.5rem;
}

#toc .menu-root {
	margin: 0;
	padding: 0;
	list-style: none;
}

#toc .toc-item {
	list-style: none;
}

#toc .toc-item.level-2 {
	margin-left: 0.85rem;
}

#toc .menu-link {
	display: block;
	padding: 0.5rem 0.7rem;
	border-radius: 9px;
	color: var(--iaap-blue);
	font-size: 0.98rem;
	font-weight: 600;
	line-height: 1.35;
	text-decoration: none;
	transition: background-color 0.12s ease, color 0.12s ease;
}

#toc .menu-link:hover,
#toc .menu-link:focus-visible {
	background: var(--iaap-tint);
	color: var(--iaap-blue-dark);
	text-decoration: underline;
	text-decoration-thickness: 2px;
	text-underline-offset: 0.2em;
}

#toc .menu-link:focus-visible {
	outline: 3px solid var(--iaap-blue);
	outline-offset: 2px;
}

/* --- Active section (scroll-spy) ---------------------------------------- */
#toc .sidebar .menu-link.is-active {
	background: var(--iaap-tint);
	color: var(--iaap-blue-dark);
	font-weight: 800;
	box-shadow: inset 3px 0 0 var(--iaap-blue);
}

#toc .sidebar .menu-link.is-active:hover,
#toc .sidebar .menu-link.is-active:focus-visible {
	background: var(--iaap-tint-strong);
	color: var(--iaap-blue-dark);
}

/* --- Desktop: sticky sidebar column ------------------------------------ */
@media (min-width: 1024px) {
	/* align-items: stretch (the default) lets the #side-menu column grow to the
	   full height of the row. That gives the sticky TOC room to travel the whole
	   length of the article; with flex-start the column shrinks to the TOC's own
	   height and the sticky TOC scrolls away immediately. */
	#primary > .page-layout {
		flex-direction: row;
		align-items: stretch;
	}

	#primary > .page-layout > #main {
		min-width: 0;
		flex: 1 1 auto;
	}

	#side-menu {
		width: 17rem;
		flex: 0 0 17rem;
	}

	/* The shortcode div (#toc) is the sticky wrapper's containing block, so it
	   must fill the full (stretched) column height — otherwise the sticky menu
	   can only travel this div's own short height and scrolls away. padding-top
	   gives the same gap below the header bar at rest as the sticky `top` offset
	   gives once the menu pins, so the spacing stays consistent. */
	#toc {
		box-sizing: border-box;
		height: 100%;
		padding-top: 2rem;
	}

	#toc .sticky-wrapper {
		position: sticky;
		top: 2rem;
		margin-bottom: 0;
	}

	/* Logged-in users get a fixed 32px WordPress admin bar at the top of the
	   viewport; without this the pinned menu tucks under it and looks flush to
	   the top. Visitors (no admin bar) keep the plain 2rem offset above. */
	body.admin-bar #toc .sticky-wrapper {
		top: calc(2rem + 32px);
	}

	/* Cap the card to the viewport so a long TOC scrolls inside itself instead
	   of having its bottom items stuck off-screen. The card keeps its shadow
	   (an element's own box-shadow is not clipped by its own overflow), and the
	   0.5rem panel padding keeps focus outlines from being clipped. */
	#toc .sidebar {
		max-height: calc(100vh - 4rem);
		overflow-y: auto;
		overscroll-behavior: contain;
	}
}
