/**
 * CW Smart TOC — Native UIkit 3 / YOOtheme Pro Styles
 * Override custom properties in your child theme if needed.
 */

:root {
	--cw-toc-bg: #f8f9fb;
	--cw-toc-border: rgba(15, 23, 42, 0.1);
	--cw-toc-radius: 8px;
	--cw-toc-accent: var(--uk-color-primary, #1e87f0);
	--cw-toc-text: inherit;
	--cw-toc-muted: #64748b;
	--cw-toc-hover-bg: rgba(30, 135, 240, 0.06);
	--cw-toc-active-bg: rgba(30, 135, 240, 0.1);
	--cw-toc-z: 970;
}

/* Inline & Sidebar Containers */
.cw-toc--inline,
.cw-toc--sidebar {
	background: var(--cw-toc-bg);
	border: 1px solid var(--cw-toc-border);
	border-radius: var(--cw-toc-radius);
	padding: 18px 22px;
	box-shadow: none;
}

.cw-toc--inline {
	margin: 24px 0 32px;
}

.cw-toc--sidebar {
	margin: 0 0 24px;
	padding: 16px 18px;
}

.cw-toc--sidebar .cw-toc__list {
	margin-top: 12px;
	padding-top: 10px;
	border-top: 1px solid var(--cw-toc-border);
	max-height: calc(100vh - 200px);
	overflow-y: auto;
}

.cw-toc__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
}

.cw-toc__title-wrap {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: 6px 14px;
}

.cw-toc__title {
	margin: 0;
	font-size: 1.05rem;
	font-weight: 700;
	line-height: 1.3;
	color: var(--cw-toc-text);
}

.cw-toc__reading-time {
	font-size: 0.82rem;
	font-weight: 500;
	color: var(--cw-toc-muted);
	white-space: nowrap;
}

.cw-toc__toggle {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	padding: 0;
	border: 1px solid var(--cw-toc-border);
	border-radius: 6px;
	background: transparent;
	color: var(--cw-toc-text);
	cursor: pointer;
	flex-shrink: 0;
	transition: background-color 0.2s ease, border-color 0.2s ease;
}

.cw-toc__toggle:hover,
.cw-toc__toggle:focus-visible {
	background: var(--cw-toc-hover-bg);
	border-color: var(--cw-toc-accent);
	outline: none;
}

.cw-toc__chevron {
	transition: transform 0.22s ease;
}

.cw-toc__toggle[aria-expanded="false"] .cw-toc__chevron {
	transform: rotate(-90deg);
}

/* Hierarchical Counter List */
.cw-toc__list,
.cw-toc__sublist {
	list-style: none;
	margin: 0;
	padding: 0;
	counter-reset: cw-toc-counter;
}

.cw-toc--inline .cw-toc__list {
	margin-top: 14px;
	padding-top: 12px;
	border-top: 1px solid var(--cw-toc-border);
}

.cw-toc__list[hidden] {
	display: none;
}

.cw-toc__sublist {
	margin-left: 16px;
	padding-left: 10px;
	border-left: 1px solid var(--cw-toc-border);
}

.cw-toc__item {
	counter-increment: cw-toc-counter;
	margin: 2px 0;
}

.cw-toc__link {
	display: flex;
	align-items: baseline;
	gap: 8px;
	padding: 5px 10px;
	border-left: 2px solid transparent;
	border-radius: 0 5px 5px 0;
	color: var(--cw-toc-text);
	text-decoration: none;
	font-size: 0.94rem;
	line-height: 1.45;
	transition: color 0.18s ease, background-color 0.18s ease, border-color 0.18s ease;
}

.cw-toc__link::before {
	content: counters(cw-toc-counter, ".") ".";
	font-size: 0.82em;
	font-weight: 600;
	color: var(--cw-toc-muted);
	flex-shrink: 0;
}

.cw-toc__link:hover,
.cw-toc__link:focus-visible {
	color: var(--cw-toc-accent);
	background: var(--cw-toc-hover-bg);
	text-decoration: none;
	outline: none;
}

.cw-toc__link.is-active {
	color: var(--cw-toc-accent);
	background: var(--cw-toc-active-bg);
	border-left-color: var(--cw-toc-accent);
	font-weight: 600;
}

.cw-toc__link.is-active::before {
	color: var(--cw-toc-accent);
}

.cw-toc__item--level-3 > .cw-toc__link,
.cw-toc__item--level-4 > .cw-toc__link,
.cw-toc__item--level-5 > .cw-toc__link,
.cw-toc__item--level-6 > .cw-toc__link {
	font-size: 0.88rem;
}

/* Sticky Floating Widget */
.cw-toc-sticky {
	position: fixed;
	right: 24px;
	bottom: 24px;
	z-index: var(--cw-toc-z);
	opacity: 0;
	visibility: hidden;
	transform: translateY(12px);
	transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
}

.cw-toc-sticky.is-visible {
	opacity: 1;
	visibility: visible;
	transform: translateY(0);
}

.cw-toc-sticky__progress {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 3px;
	background: transparent;
	pointer-events: none;
	z-index: calc(var(--cw-toc-z) + 5);
}

.cw-toc-sticky__progress-bar {
	display: block;
	height: 100%;
	width: 0%;
	background: var(--cw-toc-accent);
	transition: width 0.1s linear;
}

.cw-toc-sticky__fab {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 10px 16px;
	border: 1px solid var(--cw-toc-border);
	border-radius: 999px;
	background: #ffffff;
	color: #1e293b;
	font-size: 0.88rem;
	font-weight: 600;
	box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
	cursor: pointer;
	transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.cw-toc-sticky__fab:hover,
.cw-toc-sticky__fab:focus-visible {
	border-color: var(--cw-toc-accent);
	color: var(--cw-toc-accent);
	transform: translateY(-2px);
	box-shadow: 0 12px 28px rgba(15, 23, 42, 0.18);
	outline: none;
}

.cw-toc-sticky__panel {
	position: absolute;
	right: 0;
	bottom: calc(100% + 12px);
	width: min(340px, calc(100vw - 32px));
	max-height: min(62vh, 460px);
	display: flex;
	flex-direction: column;
	background: #ffffff;
	border: 1px solid var(--cw-toc-border);
	border-radius: 10px;
	overflow: hidden;
}

.cw-toc-sticky__panel[hidden] {
	display: none;
}

.cw-toc-sticky__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px 16px;
	border-bottom: 1px solid var(--cw-toc-border);
	background: var(--cw-toc-bg);
}

.cw-toc-sticky__close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
	border: none;
	border-radius: 6px;
	background: transparent;
	color: var(--cw-toc-muted);
	font-size: 1.35rem;
	line-height: 1;
	cursor: pointer;
}

.cw-toc-sticky__close:hover,
.cw-toc-sticky__close:focus-visible {
	background: var(--cw-toc-hover-bg);
	color: var(--cw-toc-text);
	outline: none;
}

.cw-toc-sticky__body {
	padding: 10px 12px 14px;
	overflow-y: auto;
	overscroll-behavior: contain;
}

@media (max-width: 640px) {
	.cw-toc--inline {
		padding: 14px 16px;
	}

	.cw-toc-sticky {
		right: 16px;
		bottom: 16px;
	}

	.cw-toc-sticky__panel {
		width: calc(100vw - 32px);
		max-height: 55vh;
	}
}

@media (prefers-reduced-motion: reduce) {
	.cw-toc__chevron,
	.cw-toc__link,
	.cw-toc-sticky,
	.cw-toc-sticky__fab,
	.cw-toc-sticky__progress-bar {
		transition: none;
	}
}
