/**
 * Smart Table of Contents — frontend styles.
 *
 * Design matches the reference: white rounded card, soft shadow, bold title,
 * nested decimal numbering with hanging indents.
 *
 * All rules are scoped under .stoc to survive Elementor / theme CSS.
 * Colors, radius and sticky offset arrive as CSS variables injected from
 * plugin settings (see Smart_TOC_Shortcode::enqueue_assets()).
 */

.stoc {
	/* Fallbacks in case inline vars fail to print. */
	--stoc-accent: #4338ca;
	--stoc-accent-soft: rgba(67, 56, 202, 0.08);
	--stoc-text: #1f2430;
	--stoc-muted: #6b7280;
	--stoc-bg: #ffffff;
	--stoc-radius: 14px;
	--stoc-sticky-top: 90px;
	--stoc-border-color: #c99e8c;
	--stoc-bw: 0 3px 0 0;            /* top right bottom left */
	--stoc-pad: 26px 26px 22px 26px; /* top right bottom left */

	box-sizing: border-box;
	width: 100%;
	max-width: 420px;
	font-family: inherit;
	line-height: 1.5;
	z-index: 5;
}

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

/* ---- Sticky (laptop / desktop only) --------------------------------- */
@media (min-width: 1025px) {
	.stoc--sticky {
		position: -webkit-sticky;
		position: sticky;
		top: var(--stoc-sticky-top);
		align-self: flex-start; /* Required inside flex columns (Elementor). */
	}
}

/* ---- Card ------------------------------------------------------------ */
.stoc__card {
	background: var(--stoc-bg);
	border-style: solid;
	border-color: var(--stoc-border-color);
	border-width: var(--stoc-bw);   /* Per-side widths from settings. */
	border-radius: var(--stoc-radius);
	padding: var(--stoc-pad);       /* Per-side padding from settings. */
	overflow: hidden;
}

.stoc--shadow .stoc__card {
	box-shadow:
		0 1px 2px rgba(17, 24, 39, 0.04),
		0 12px 32px -12px rgba(17, 24, 39, 0.18);
}

/* ---- Header ----------------------------------------------------------- */
.stoc__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
}

.stoc__title {
	margin: 0 !important;
	padding: 0;
	font-size: 22px;
	font-weight: 700;
	letter-spacing: -0.01em;
	color: var(--stoc-text);
	line-height: 1.25;
}

/* Toggle button — hidden on desktop, shown on mobile when collapsible. */
.stoc__toggle {
	display: none;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	padding: 0;
	border: 1px solid rgba(17, 24, 39, 0.1);
	border-radius: 50%;
	background: transparent;
	color: var(--stoc-text);
	cursor: pointer;
	transition: background-color 0.2s ease, transform 0.2s ease;
}

.stoc__toggle:hover {
	background: var(--stoc-accent-soft);
}

.stoc__toggle:focus-visible {
	outline: 2px solid var(--stoc-accent);
	outline-offset: 2px;
}

.stoc__chevron {
	transition: transform 0.25s ease;
}

.stoc__toggle[aria-expanded="false"] .stoc__chevron {
	transform: rotate(-90deg);
}

.stoc__sr,
.stoc .screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

/* ---- Body / collapse -------------------------------------------------- */
.stoc__body {
	margin-top: 14px;
}

/* ---- Lists ------------------------------------------------------------ */
.stoc__list {
	list-style: none !important;
	margin: 0 !important;
	padding: 0 !important;
}

.stoc__list--sub {
	margin: 2px 0 4px 18px !important;
}

.stoc__item {
	margin: 0 !important;
	padding: 0 !important;
}

.stoc__link {
	display: flex;
	align-items: baseline;
	gap: 8px;
	padding: 7px 10px;
	margin: 1px -10px;
	border-radius: 8px;
	color: var(--stoc-text);
	font-size: 17px;
	font-weight: 500;
	text-decoration: none !important;
	box-shadow: none !important; /* Kill theme link underlines. */
	transition: color 0.15s ease, background-color 0.15s ease;
}

/* Sub-level items: smaller and slightly muted, like "6.1 Final Thoughts". */
.stoc__list--sub .stoc__link {
	font-size: 14.5px;
	font-weight: 500;
	padding-top: 5px;
	padding-bottom: 5px;
}

.stoc__link:hover {
	color: var(--stoc-accent);
	background: var(--stoc-accent-soft);
}

.stoc__link:focus-visible {
	outline: 2px solid var(--stoc-accent);
	outline-offset: 1px;
}

/* Active heading while scrolling. */
.stoc__link.is-active {
	color: var(--stoc-accent);
	background: var(--stoc-accent-soft);
	font-weight: 600;
}

/* ---- Nested decimal numbering (1., 2., 6.1) --------------------------- */
.stoc--numbered .stoc__list {
	counter-reset: stoc-l1;
}

.stoc--numbered .stoc__list > .stoc__item {
	counter-increment: stoc-l1;
}

.stoc--numbered .stoc__list > .stoc__item > .stoc__link::before {
	content: counter(stoc-l1) ".";
	flex: 0 0 auto;
	min-width: 20px;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	color: var(--stoc-text);
}

/* Level 2 */
.stoc--numbered .stoc__list--sub {
	counter-reset: stoc-l2;
}

.stoc--numbered .stoc__list--sub > .stoc__item {
	counter-increment: stoc-l2;
}

.stoc--numbered .stoc__list--sub > .stoc__item > .stoc__link::before {
	content: counter(stoc-l1) "." counter(stoc-l2);
	min-width: 28px;
}

/* Level 3 */
.stoc--numbered .stoc__list--sub .stoc__list--sub {
	counter-reset: stoc-l3;
}

.stoc--numbered .stoc__list--sub .stoc__list--sub > .stoc__item {
	counter-increment: stoc-l3;
}

.stoc--numbered .stoc__list--sub .stoc__list--sub > .stoc__item > .stoc__link::before {
	content: counter(stoc-l1) "." counter(stoc-l2) "." counter(stoc-l3);
	min-width: 36px;
}

/* Level 4+ (h5/h6 under deep nesting) — dot marker keeps it readable. */
.stoc--numbered .stoc__list--sub .stoc__list--sub .stoc__list--sub > .stoc__item > .stoc__link::before {
	content: "•";
	min-width: 16px;
}

/* Numbers inherit the accent color on hover/active. */
.stoc--numbered .stoc__link:hover::before,
.stoc--numbered .stoc__link.is-active::before {
	color: var(--stoc-accent);
}

/* ---- Scroll-margin fallback for anchor targets ------------------------ */
/* JS handles precise offsets; this covers no-JS / find-in-page jumps.     */
:target {
	scroll-margin-top: 110px;
}

/* ---- Responsive -------------------------------------------------------- */
@media (max-width: 1024px) {
	.stoc {
		max-width: 100%;
		position: static; /* Never sticky on tablet/mobile. */
	}
}

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

	.stoc__link {
		font-size: 16px;
		padding-top: 9px;    /* Larger touch targets. */
		padding-bottom: 9px;
	}

	/* Collapsible accordion. */
	.stoc--collapsible .stoc__toggle {
		display: inline-flex;
	}

	.stoc--collapsible .stoc__body {
		overflow: hidden;
		max-height: 1200px;
		transition: max-height 0.35s ease, opacity 0.25s ease, margin-top 0.25s ease;
	}

	.stoc--collapsible.is-collapsed .stoc__body {
		max-height: 0;
		opacity: 0;
		margin-top: 0;
	}
}

/* ---- Reduced motion ---------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
	.stoc__body,
	.stoc__chevron,
	.stoc__link,
	.stoc__toggle {
		transition: none !important;
	}
}

/* ---- Print ------------------------------------------------------------- */
@media print {
	.stoc {
		position: static !important;
	}

	.stoc--shadow .stoc__card {
		box-shadow: none;
	}

	.stoc__toggle {
		display: none !important;
	}
}
