/**
 * VenDoor Sticky Table of Contents — front-end styles.
 *
 * The panel is intentionally box-less: instead of a border and a shadow, a vertical rail
 * runs alongside the items and the active section's segment is painted in the accent colour.
 *
 * @package VendoorStickyTableOfContents
 */

#stoc-btn {
	position: fixed;
	top: 50%;
	left: 18px;
	transform: translateY( -50% );
	z-index: 9990;
	width: 46px;
	height: 46px;
	border-radius: 50%;
	background: #fff;
	border: 1px solid #e4e8f0;
	box-shadow: 0 6px 18px rgba( 20, 34, 51, 0.16 );
	color: #1b5fd9;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	opacity: 1;
	visibility: visible;
	transition: opacity 0.2s ease, visibility 0s, box-shadow 0.15s ease;
}

#stoc-btn:hover {
	box-shadow: 0 9px 24px rgba( 20, 34, 51, 0.26 );
}

#stoc-btn:focus-visible {
	outline: 2px solid #1b5fd9;
	outline-offset: 2px;
}

#stoc-btn svg {
	width: 22px;
	height: 22px;
}

/*
 * `visibility` — not just opacity — so the hidden launcher leaves the tab order and the
 * accessibility tree. `pointer-events` alone stops the mouse but not the keyboard, which
 * would strand focus on an invisible control that does nothing when activated.
 */
#stoc-btn.stoc-off {
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition: opacity 0.2s ease, visibility 0s linear 0.2s, box-shadow 0.15s ease;
}

#stoc-panel {
	position: fixed;
	top: 50%;
	left: 18px;
	transform: translateY( -50% );
	z-index: 9991;
	width: 284px;
	max-height: 78vh;
	overflow-y: auto;
	overflow-x: hidden;
	background: #fff;
	border: 0;
	border-radius: 0;
	box-shadow: none;
	padding: 2px 6px 6px 6px;
	display: none;
	font-family: inherit;
}

#stoc-panel.stoc-open {
	display: block;
}

#stoc-panel * {
	box-sizing: border-box;
}

#stoc-panel .stoc__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	border-left: 2px solid #e4e8f0;
	padding: 2px 2px 8px 14px;
	margin: 0;
	font-size: 11.5px;
	font-weight: 700;
	letter-spacing: 0.05em;
	text-transform: uppercase;
	color: #94a0b3;
}

#stoc-panel .stoc__x {
	border: 0;
	background: none;
	font-size: 20px;
	line-height: 1;
	color: #68758c; /* 4.65:1 on white — #b5becc only reached 1.87:1. */
	cursor: pointer;
	padding: 0 2px;
}

#stoc-panel .stoc__x:hover {
	color: #25324a;
}

#stoc-panel .stoc-item {
	margin: 0;
}

#stoc-panel .stoc-row {
	display: flex;
	align-items: stretch;
	border-left: 2px solid #e4e8f0;
}

#stoc-panel .stoc-row.stoc-on {
	border-left-color: #1b5fd9;
}

#stoc-panel .stoc-cv {
	flex: 0 0 22px;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #68758c; /* 4.65:1 on white — #9aa6b8 was 2.6:1, under the 3:1 WCAG asks of a control. */
}

#stoc-panel .stoc-cv.stoc-has {
	cursor: pointer;
}

#stoc-panel .stoc-cv svg {
	width: 11px;
	height: 11px;
	transition: transform 0.15s ease;
}

#stoc-panel .stoc-item.stoc-exp .stoc-cv svg {
	transform: rotate( 90deg );
}

/*
 * Items are <button>, never <a href="#...">, so no crawlable fragment URL is ever created.
 * These resets neutralise the button styling most themes apply.
 */
#stoc-panel button {
	margin: 0;
	padding: 0;
	width: auto;
	height: auto;
	min-height: 0;
	background: none;
	background-color: transparent;
	border: 0;
	border-radius: 0;
	box-shadow: none;
	font-family: inherit;
	text-transform: none;
	letter-spacing: normal;
	-webkit-appearance: none;
	appearance: none;
}

#stoc-panel button:hover,
#stoc-panel button:focus,
#stoc-panel button:active {
	background: none;
	background-color: transparent;
	box-shadow: none;
	transform: none;
}

#stoc-panel button:focus-visible {
	outline: 2px solid #1b5fd9;
	outline-offset: -2px;
}

#stoc-panel button.stoc-h2 {
	flex: 1 1 auto;
	display: block;
	width: 100%;
	text-align: left;
	padding: 8px 8px 8px 2px;
	color: #33415c;
	font-size: 14.5px;
	line-height: 1.32;
	font-weight: 500;
	cursor: pointer;
}

#stoc-panel .stoc-row:hover {
	background: #f7f9fc;
}

#stoc-panel .stoc-row.stoc-on button.stoc-h2 {
	color: #1b5fd9;
	font-weight: 600;
}

#stoc-panel .stoc-sub {
	display: none;
	margin: 0;
}

#stoc-panel .stoc-item.stoc-exp .stoc-sub {
	display: block;
}

#stoc-panel button.stoc-h3 {
	display: block;
	width: 100%;
	text-align: left;
	border-left: 2px solid #e4e8f0;
	padding: 6px 8px 6px 32px;
	color: #68758c;
	font-size: 13.5px;
	line-height: 1.3;
	cursor: pointer;
}

#stoc-panel button.stoc-h3:hover {
	background: #f7f9fc;
}

#stoc-panel button.stoc-h3.stoc-on {
	border-left-color: #1b5fd9;
	color: #1b5fd9;
	font-weight: 600;
}

.stoc-mk {
	position: absolute;
	left: 0;
	top: 0;
	z-index: 9989;
	width: 19px;
	height: 19px;
	color: #1b5fd9;
	opacity: 0;
	pointer-events: none;
	filter: drop-shadow( 0 1px 2px rgba( 27, 95, 217, 0.35 ) );
	transition: top 0.32s cubic-bezier( 0.34, 1.2, 0.4, 1 ), opacity 0.22s ease;
}

.stoc-mk svg {
	display: block;
	width: 100%;
	height: 100%;
}

.stoc-mk.stoc-flip svg {
	transform: scaleX( -1 );
}

.stoc-body-open .stoc-mk.stoc-ready {
	opacity: 1;
}

#stoc-backdrop {
	position: fixed;
	inset: 0;
	background: rgba( 15, 23, 42, 0.5 );
	z-index: 9991;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.3s ease;
	display: none;
}

/*
 * Narrow layout: the panel becomes a bottom sheet.
 *
 * Driven by the `stoc-narrow` class the script puts on <html>, NOT by a media query. The
 * breakpoint is configurable through the `vendoor_toc_mobile_breakpoint` filter, and a hard-coded
 * `@media ( max-width: 1024px )` here would silently ignore it: at a filtered 768px, every width
 * between 769px and 1024px would paint the modal sheet while the script still believed it was on
 * desktop and never closed it. One source of truth, evaluated in JS.
 *
 * The hook is wrapped in `:where()` so it adds nothing to specificity. A bare `.stoc-narrow`
 * prefix would weigh more than the media query it replaces, and these rules would then outrank
 * the `@media print` and `prefers-reduced-motion` blocks below — which are also `!important`,
 * so specificity, not source order, decides between them. That is not theoretical: it printed
 * the open sheet on top of the article, on every page, because the panel is `position: fixed`.
 */
:where( .stoc-narrow ) .stoc-mk {
	display: none !important;
}

:where( .stoc-narrow ) #stoc-btn {
	left: auto !important;
	right: 16px !important;
	top: auto !important;
	bottom: 18px !important;
	transform: none !important;
	width: 56px !important;
	height: 56px !important;
}

:where( .stoc-narrow ) #stoc-btn svg {
	width: 24px !important;
	height: 24px !important;
}

/*
 * The bottom sheet is hidden by sliding it off-screen, and a transform hides nothing from
 * the keyboard or a screen reader. `visibility` is what actually takes the closed sheet out
 * of the tab order; it is delayed so the slide-out animation still plays.
 */
:where( .stoc-narrow ) #stoc-panel {
	display: block !important;
	visibility: hidden !important;
	left: 0 !important;
	right: 0 !important;
	top: auto !important;
	bottom: 0 !important;
	width: 100% !important;
	max-width: 100% !important;
	max-height: 74vh !important;
	transform: translateY( 106% ) !important;
	transition: transform 0.32s cubic-bezier( 0.4, 0, 0.2, 1 ), visibility 0s linear 0.32s !important;
	border-radius: 18px 18px 0 0 !important;
	box-shadow: 0 -12px 34px rgba( 20, 34, 51, 0.26 ) !important;
	padding: 14px 14px 20px !important;
	z-index: 9992 !important;
}

:where( .stoc-narrow ) #stoc-panel::before {
	content: "";
	position: sticky;
	top: 0;
	display: block;
	width: 40px;
	height: 4px;
	border-radius: 2px;
	background: #d7dce6;
	margin: -6px auto 8px;
}

:where( .stoc-narrow ) #stoc-panel.stoc-open {
	visibility: visible !important;
	transform: translateY( 0 ) !important;
	transition: transform 0.32s cubic-bezier( 0.4, 0, 0.2, 1 ), visibility 0s !important;
}

:where( .stoc-narrow ) #stoc-backdrop {
	display: block;
}

:where( .stoc-narrow ) .stoc-body-open #stoc-backdrop {
	opacity: 1;
	pointer-events: auto;
}

@media print {

	#stoc-btn,
	#stoc-panel,
	#stoc-backdrop {
		display: none !important;
	}
}

@media ( prefers-reduced-motion: reduce ) {

	/*
	 * `#stoc-panel.stoc-open` is listed explicitly: a plain `#stoc-panel` here loses to it on
	 * specificity, both being !important, so without this the bottom sheet still slid open for
	 * a reader who asked for no motion.
	 */
	#stoc-btn,
	#stoc-panel,
	#stoc-panel.stoc-open,
	.stoc-mk,
	#stoc-backdrop,
	#stoc-panel .stoc-cv svg {
		transition: none !important;
	}
}
