/*
 * Acutis TOC Frontend Styles — v1.2.3
 * Thuật toán layout và class structure dựa theo Fixed TOC plugin.
 * Namespace: acutis-toc-* (tránh xung đột với bất kỳ plugin nào khác).
 */

/* ════════════════════════════════════════════════════════════
 * 1. RESET TOÀN BỘ BÊN TRONG CONTAINER (theo cách Fixed TOC làm)
 * ════════════════════════════════════════════════════════════ */
.acutis-toc-container,
.acutis-toc-container *,
.acutis-toc-container *::before,
.acutis-toc-container *::after {
	box-sizing: border-box;
}

.acutis-toc-container button,
.acutis-toc-container button:hover,
.acutis-toc-container button:focus,
.acutis-toc-container ol,
.acutis-toc-container ul,
.acutis-toc-container li,
.acutis-toc-container a,
.acutis-toc-container a:link,
.acutis-toc-container a:visited,
.acutis-toc-container a:hover,
.acutis-toc-container a:active,
.acutis-toc-container span {
	margin: 0;
	padding: 0;
	line-height: inherit;
	font: inherit;
	color: inherit;
	background: transparent;
	box-shadow: none;
	text-shadow: none;
	text-decoration: none;
	text-align: inherit;
	border: none;
	outline: none;
	border-radius: 0;
	clear: none;
}

.acutis-toc-container li {
	list-style: none;
}

.acutis-toc-container li::before,
.acutis-toc-container li::after {
	display: none;
}

/* ════════════════════════════════════════════════════════════
 * 2. CONTAINER CHÍNH
 * ════════════════════════════════════════════════════════════ */
.acutis-toc-container {
	position: relative;
	display: inline-block;
	width: 100%;
	max-width: 480px;
	margin: 0 0 1.6em;
	font-size: 14px;
	font-family: inherit;
	line-height: 1.5;
	border: 1px solid #c9d8e8;
	border-radius: 8px;
	background: #f7f9fc;
	box-shadow: 0 2px 12px rgba(23, 54, 93, 0.08);
	overflow: hidden;
	transition: box-shadow 0.25s ease;
}

.acutis-toc-container:hover {
	box-shadow: 0 4px 18px rgba(23, 54, 93, 0.13);
}

/* ════════════════════════════════════════════════════════════
 * 3. HEADER (thanh tiêu đề)
 * ════════════════════════════════════════════════════════════ */
.acutis-toc-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 10px 14px;
	background: linear-gradient(135deg, #17365d 0%, #1e4480 100%);
	color: #fff;
	cursor: pointer;
	user-select: none;
	-webkit-user-select: none;
}

.acutis-toc-title {
	font-weight: 700;
	font-size: 13px;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	opacity: 0.95;
}

/* Nút thu gọn / mở rộng toàn bộ TOC */
.acutis-toc-toggle {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 24px;
	height: 24px;
	padding: 0;
	border: 1px solid rgba(255,255,255,0.35);
	border-radius: 50%;
	background: transparent;
	color: #fff;
	font-size: 14px;
	line-height: 1;
	cursor: pointer;
	opacity: 0.75;
	transition: opacity 0.2s, transform 0.25s ease;
	flex-shrink: 0;
}

.acutis-toc-toggle:hover {
	opacity: 1;
}

.acutis-toc-toggle[aria-expanded="false"] {
	transform: rotate(-90deg);
}

/* ════════════════════════════════════════════════════════════
 * 4. BODY — NAV chứa danh sách
 * ════════════════════════════════════════════════════════════ */
.acutis-toc-body {
	overflow: hidden;
	transition: max-height 0.3s ease, opacity 0.25s ease;
	max-height: 9999px;
	opacity: 1;
}

/* Trạng thái đã thu gọn (JS thêm class .acutis-toc-collapsed) */
.acutis-toc-container.acutis-toc-collapsed .acutis-toc-body {
	max-height: 0;
	opacity: 0;
}

/* ════════════════════════════════════════════════════════════
 * 5. DANH SÁCH CHÍNH — OL#acutis-toc-list
 * Sử dụng đánh số thứ tự (decimal) và thụt lề con theo cấp (Fixed TOC style)
 * ════════════════════════════════════════════════════════════ */
#acutis-toc-list,
#acutis-toc-floating-list {
	counter-reset: acutis-toc-counter;
	margin: 0;
	padding: 10px 0;
	background: transparent;
}

/* ── Item ── */
.acutis-toc-item {
	counter-increment: acutis-toc-counter;
	position: relative;
	overflow: visible;
	text-indent: 0;
}

/* ── Anchor ── */
.acutis-toc-anchor {
	display: flex;
	align-items: flex-start;
	gap: 0;
	padding: 5px 14px 5px 14px;
	color: #17365d;
	text-decoration: none;
	position: relative;
	z-index: 10;
	transition: color 0.2s, background 0.15s;
	line-height: 1.4;
	overflow: hidden;
}

.acutis-toc-anchor:hover {
	color: #1d4ed8;
	background: rgba(29,78,216,0.06);
}

/* Số thứ tự trước anchor (giống Fixed TOC decimal style) */
.acutis-toc-anchor::before {
	content: counters(acutis-toc-counter, ".") ".";
	flex-shrink: 0;
	margin-right: 8px;
	font-size: 12px;
	line-height: 1.5;
	color: #64748b;
	min-width: 26px;
	font-variant-numeric: tabular-nums;
}

/* ── Text span ── */
.acutis-toc-text {
	display: block;
	overflow: hidden;
}

/* ── Link active (heading đang trong viewport) ── */
.acutis-toc-anchor.acutis-toc-active {
	color: #1d4ed8;
	font-weight: 600;
}

.acutis-toc-anchor.acutis-toc-active::after {
	content: '';
	position: absolute;
	left: 0;
	top: 0;
	bottom: 0;
	width: 3px;
	background: #1d4ed8;
	border-radius: 0 2px 2px 0;
}

/* Scroll-spy đánh dấu item tương ứng trong cả TOC inline và TOC nổi. */
.acutis-active-item > a {
	background-color: #d32f2f !important;
	color: #fff !important;
}

.acutis-active-item > a::before {
	color: #fff !important;
}

/* ════════════════════════════════════════════════════════════
 * 6. DANH SÁCH CON (nested — theo Fixed TOC ftwp-sub style)
 * ════════════════════════════════════════════════════════════ */
.acutis-toc-sub {
	counter-reset: acutis-toc-counter;
	margin: 0;
	padding: 0;
	overflow: hidden;
	transition: max-height 0.25s ease, opacity 0.2s ease;
	max-height: 9999px;
	opacity: 1;
}

/* Thụt lề cấp 1 con (cấp con của cấp gốc) */
.acutis-toc-item .acutis-toc-sub .acutis-toc-anchor {
	padding-left: 28px;
	font-size: 0.925em;
	color: #334155;
}

.acutis-toc-item .acutis-toc-sub .acutis-toc-anchor::before {
	min-width: 32px;
}

/* Thụt lề cấp 2 con */
.acutis-toc-item .acutis-toc-sub .acutis-toc-sub .acutis-toc-anchor {
	padding-left: 44px;
	font-size: 0.875em;
	color: #475569;
}

/* Thụt lề cấp 3 con */
.acutis-toc-item .acutis-toc-sub .acutis-toc-sub .acutis-toc-sub .acutis-toc-anchor {
	padding-left: 60px;
	font-size: 0.85em;
	color: #64748b;
}

/* Thụt lề cấp 4 con */
.acutis-toc-item .acutis-toc-sub .acutis-toc-sub .acutis-toc-sub .acutis-toc-sub .acutis-toc-anchor {
	padding-left: 76px;
}

/* ════════════════════════════════════════════════════════════
 * 7. NÚT THU GỌN/MỞ RỘNG NHÁNH CON (collapse/expand icon)
 * Giống Fixed TOC ftwp-icon-collapse / ftwp-icon-expand
 * ════════════════════════════════════════════════════════════ */
.acutis-toc-has-sub {
	position: relative;
}

.acutis-toc-colexp-icon {
	position: absolute;
	right: 10px;
	top: 4px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 22px;
	height: 22px;
	border: none;
	border-radius: 50%;
	background: transparent;
	color: #64748b;
	font-size: 11px;
	cursor: pointer;
	opacity: 0.6;
	transition: opacity 0.2s, transform 0.22s ease, background 0.15s;
	z-index: 20;
	line-height: 1;
	padding: 0;
}

.acutis-toc-colexp-icon::after {
	content: '▾';
	display: inline-block;
	transition: transform 0.22s ease;
}

.acutis-toc-colexp-icon:hover {
	opacity: 1;
	background: rgba(29,78,216,0.08);
}

/* Khi thu gọn: xoay icon 90° */
.acutis-toc-has-sub.acutis-toc-collapse > .acutis-toc-colexp-icon::after {
	transform: rotate(-90deg);
}

/* Trạng thái thu gọn nhánh con */
.acutis-toc-has-sub.acutis-toc-collapse > .acutis-toc-sub {
	max-height: 0;
	opacity: 0;
	pointer-events: none;
}

/* ════════════════════════════════════════════════════════════
 * 8. ĐƯỜNG KẺ NGĂN CÁCH giữa các mục gốc
 * ════════════════════════════════════════════════════════════ */
#acutis-toc-list > .acutis-toc-item + .acutis-toc-item > .acutis-toc-anchor,
#acutis-toc-floating-list > .acutis-toc-item + .acutis-toc-item > .acutis-toc-anchor {
	border-top: 1px solid rgba(23, 54, 93, 0.07);
}

/* ════════════════════════════════════════════════════════════
 * 9. CLASS ftwp-heading ĐƯỢC PHP GÁN VÀO THẺ H THỰC
 * (tương thích với cách Fixed TOC modify heading trong content)
 * ════════════════════════════════════════════════════════════ */
.acutis-heading {
	scroll-margin-top: 80px; /* offset khi scroll tới, tránh bị header che */
}

/* ════════════════════════════════════════════════════════════
 * 10. MỤC LỤC NỔI — cách ly hoàn toàn khỏi TOC inline
 * ════════════════════════════════════════════════════════════ */
#acutis-toc-trigger {
	position: fixed;
	right: 0;
	top: 50%;
	opacity: 0;
	visibility: hidden;
	z-index: 9998;
	transition: all 0.3s;
	transform: translateY(-50%);
	width: 44px;
	height: 48px;
	padding: 0;
	border: 0;
	border-radius: 8px 0 0 8px;
	background: #17365d;
	color: #fff;
	font-size: 24px;
	line-height: 1;
	cursor: pointer;
	box-shadow: 0 3px 12px rgba(0, 0, 0, 0.22);
}

#acutis-toc-trigger.acutis-toc-trigger-visible {
	opacity: 1;
	visibility: visible;
}

#acutis-toc-floating-wrapper {
	position: fixed;
	top: 0;
	right: 0;
	width: 300px;
	height: 100vh;
	height: 100dvh;
	transform: translateX(100%);
	z-index: 9999;
	transition: transform 0.3s ease;
	background: #f7f9fc;
	box-shadow: -5px 0 22px rgba(0, 0, 0, 0.2);
	overflow: hidden;
}

body.acutis-toc-floating-enabled {
	transition: padding-right 0.3s ease;
}

body.acutis-toc-floating-open {
	padding-right: 300px;
}

body.acutis-toc-floating-open #acutis-toc-floating-wrapper {
	transform: translateX(0);
}

#acutis-toc-floating-close {
	position: absolute;
	top: 10px;
	right: 45px;
	z-index: 3;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 26px;
	height: 26px;
	padding: 0;
	border: 1px solid rgba(255, 255, 255, 0.4);
	border-radius: 50%;
	background: transparent;
	color: #fff;
	font-size: 20px;
	line-height: 1;
	cursor: pointer;
}

#acutis-toc-floating-wrapper .acutis-toc-floating-container {
	display: flex;
	flex-direction: column;
	width: 100%;
	max-width: none;
	height: 100%;
	margin: 0;
	border: 0;
	border-radius: 0;
	box-shadow: none;
}

#acutis-toc-floating-wrapper .acutis-toc-body {
	flex: 1 1 auto;
	min-height: 0;
	overflow-x: hidden;
	overflow-y: auto;
}

#acutis-toc-floating-wrapper .acutis-toc-container.acutis-toc-collapsed .acutis-toc-body {
	flex: 0 0 auto;
}

/* ════════════════════════════════════════════════════════════
 * 11. RESPONSIVE
 * ════════════════════════════════════════════════════════════ */
@media screen and (max-width: 640px) {
	.acutis-toc-container {
		max-width: 100%;
		font-size: 13px;
	}

	.acutis-toc-anchor {
		padding: 6px 12px;
	}

	.acutis-toc-item .acutis-toc-sub .acutis-toc-anchor {
		padding-left: 20px;
	}

	.acutis-toc-item .acutis-toc-sub .acutis-toc-sub .acutis-toc-anchor {
		padding-left: 34px;
	}
}

@media screen and (max-width: 782px) {
	body.acutis-toc-floating-open {
		padding-right: 0;
	}

	#acutis-toc-floating-wrapper {
		width: min(300px, 100vw);
	}
}

@media (prefers-reduced-motion: reduce) {
	#acutis-toc-trigger,
	#acutis-toc-floating-wrapper,
	body.acutis-toc-floating-enabled {
		transition: none;
	}
}
