/**
 * TocBox — Public Frontend Styles
 *
 * Original compact Amber/Blue styles preserved exactly.
 * Full typography control via CSS custom properties.
 * Progress bar with percentage badge.
 * Reading time & heading count badges.
 * Active indicator variants (background / left-border / underline).
 *
 * @since 1.1
 */

/* ============================================
   CSS CUSTOM PROPERTIES
   Set from PHP wp_add_inline_style; these are fallback defaults.
   ============================================ */
.tocbox-container {
	--tocbox-primary: #3B82F6;
	--tocbox-bg: #FFFFFF;
	--tocbox-border: #E2E8F0;
	--tocbox-text: #374151;
	--tocbox-radius: 12px;
	--tocbox-max-height: 500px;
	--tocbox-mobile-width: 90%;
	--tocbox-font-family: inherit;
	--tocbox-font-size: 14px;
	--tocbox-font-weight: 500;
	--tocbox-title-font-size: 15px;
	--tocbox-title-font-weight: 600;
	--tocbox-line-height: 1.6;
	--tocbox-letter-spacing: 0px;
	--tocbox-text-transform: none;
}

/* ============================================
   BASE STYLES (compact, unchanged from original)
   ============================================ */
#tocbox-wrapper { position: relative; }
.tocbox-container { width: 100%; margin-bottom: 2rem; }
.tocbox-is-fixed { position: fixed !important; z-index: 999 !important; margin-bottom: 0 !important; }
.tocbox-is-absolute-bottom { position: absolute !important; bottom: 0 !important; top: auto !important; margin-bottom: 0 !important; }

/* ============================================
   PROGRESS BAR (sits between toggle and list)
   ============================================ */
.tocbox-progress-bar {
	height: 3px;
	background: rgba(0, 0, 0, 0.06);
	overflow: hidden;
}

.tocbox-style-dark .tocbox-progress-bar {
	background: rgba(255, 255, 255, 0.08);
}

.tocbox-progress-fill {
	height: 100%;
	width: 0%;
	border-radius: inherit;
	transition: width 0.12s ease-out;
}

.tocbox-style-amber .tocbox-progress-fill { background: var(--tocbox-progress-color, linear-gradient(90deg, #F59E0B, #D97706)); }
.tocbox-style-blue .tocbox-progress-fill  { background: var(--tocbox-progress-color, linear-gradient(90deg, var(--tocbox-primary), #6366F1)); }
.tocbox-style-minimal .tocbox-progress-fill { background: var(--tocbox-progress-color, linear-gradient(90deg, #6B7280, #9CA3AF)); }
.tocbox-style-dark .tocbox-progress-fill  { background: var(--tocbox-progress-color, linear-gradient(90deg, #60A5FA, #A78BFA)); }

/* Percentage badge — fully customizable */
.tocbox-progress-pct {
	font-size: var(--tocbox-pct-font-size, 11px);
	font-weight: var(--tocbox-pct-font-weight, 700);
	letter-spacing: 0.3px;
	padding: 2px 7px;
	border-radius: 6px;
	flex-shrink: 0;
	min-width: 32px;
	text-align: center;
	line-height: 1.4;
	transition: background 0.2s, color 0.2s;
}

.tocbox-style-amber .tocbox-progress-pct {
	background: var(--tocbox-pct-bg, #FEF3C7);
	color: var(--tocbox-pct-color, #B45309);
}

.tocbox-style-blue .tocbox-progress-pct {
	background: var(--tocbox-pct-bg, #EFF6FF);
	color: var(--tocbox-pct-color, #2563EB);
}

.tocbox-style-minimal .tocbox-progress-pct {
	background: var(--tocbox-pct-bg, #F3F4F6);
	color: var(--tocbox-pct-color, #374151);
}

.tocbox-style-dark .tocbox-progress-pct {
	background: var(--tocbox-pct-bg, rgba(96, 165, 250, 0.15));
	color: var(--tocbox-pct-color, #60A5FA);
}

/* ============================================
   HEADER BADGES (reading time, heading count)
   ============================================ */
.tocbox-reading-time,
.tocbox-heading-count {
	font-size: 11px;
	font-weight: 600;
	padding: 2px 8px;
	border-radius: 6px;
	flex-shrink: 0;
	white-space: nowrap;
}

.tocbox-style-amber .tocbox-reading-time,
.tocbox-style-amber .tocbox-heading-count {
	background: #FEF3C7;
	color: #92400E;
}

.tocbox-style-blue .tocbox-reading-time,
.tocbox-style-blue .tocbox-heading-count {
	background: #EFF6FF;
	color: #1D4ED8;
}

.tocbox-style-minimal .tocbox-reading-time,
.tocbox-style-minimal .tocbox-heading-count {
	background: #F3F4F6;
	color: #6B7280;
}

.tocbox-style-dark .tocbox-reading-time,
.tocbox-style-dark .tocbox-heading-count {
	background: rgba(255, 255, 255, 0.08);
	color: #9CA3AF;
}

/* ============================================
   STYLE: AMBER (original preserved exactly)
   ============================================ */
.tocbox-style-amber {
	background-color: rgba(255, 255, 255, 0.9);
	backdrop-filter: blur(4px);
	border: 1px solid #fde68a;
	border-radius: 0.75rem;
	box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.tocbox-style-amber .tocbox-toggle {
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 0.75rem 1rem;
}

.tocbox-style-amber .tocbox-title {
	font-weight: var(--tocbox-title-font-weight);
	color: #1f2735;
	margin: 0;
	font-size: var(--tocbox-title-font-size);
	flex: 1;
}

.tocbox-style-amber .tocbox-header-icon {
	color: #D97706;
	flex-shrink: 0;
	opacity: 0.7;
}

.tocbox-style-amber .tocbox-chevron {
	width: 1.25rem;
	height: 1.25rem;
	transition: transform 0.2s;
	flex-shrink: 0;
}

.tocbox-style-amber .tocbox-list-container {
	display: none;
	padding: 0 1rem 1rem 1rem;
	border-top: 1px solid #fef3c7;
	max-height: var(--tocbox-max-height);
	overflow-y: auto;
}

.tocbox-style-amber .tocbox-list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.tocbox-style-amber .tocbox-list li a {
	display: flex;
	align-items: flex-start;
	padding: 0.4rem 0.35rem;
	color: var(--tocbox-text);
	text-decoration: none;
	border-radius: 4px;
	font-family: var(--tocbox-font-family);
	font-size: var(--tocbox-font-size);
	font-weight: var(--tocbox-font-weight);
	line-height: var(--tocbox-line-height);
	letter-spacing: var(--tocbox-letter-spacing);
	text-transform: var(--tocbox-text-transform);
	transition: all 0.15s ease;
}

.tocbox-style-amber .tocbox-list li a:hover {
	color: #D97706;
	background: rgba(254, 243, 199, 0.5);
}

/* ============================================
   STYLE: BLUE (original preserved exactly)
   ============================================ */
.tocbox-style-blue {
	background-color: #FFFFFF;
	border: 1px solid #E2E8F0;
	border-radius: 0.75rem;
	box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.tocbox-style-blue .tocbox-toggle {
	cursor: pointer;
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 0.6rem 1.15rem;
}

.tocbox-style-blue .tocbox-header-icon {
	color: #64748B;
	flex-shrink: 0;
	opacity: 0.6;
}

.tocbox-style-blue .tocbox-title {
	font-weight: var(--tocbox-title-font-weight);
	color: #1E293B;
	margin: 0;
	font-size: var(--tocbox-title-font-size);
	flex: 1;
}

.tocbox-style-blue .tocbox-chevron {
	width: 1.25rem;
	height: 1.25rem;
	transition: transform 0.2s;
	flex-shrink: 0;
}

.tocbox-style-blue .tocbox-list-container {
	display: none;
	padding: 0.5rem 0.75rem 0.75rem;
	border-top: 1px solid #F1F5F9;
	max-height: var(--tocbox-max-height);
	overflow-y: auto;
}

.tocbox-style-blue .tocbox-list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.tocbox-style-blue .tocbox-list li a {
	position: relative;
	display: flex;
	align-items: flex-start;
	padding: 0.3rem 0.5rem;
	color: #475569;
	text-decoration: none;
	border-radius: 0.35rem;
	font-family: var(--tocbox-font-family);
	font-size: var(--tocbox-font-size);
	font-weight: var(--tocbox-font-weight);
	line-height: var(--tocbox-line-height);
	letter-spacing: var(--tocbox-letter-spacing);
	text-transform: var(--tocbox-text-transform);
	transition: all 0.15s ease;
}

.tocbox-style-blue .tocbox-list li a:hover {
	color: #2563EB;
	background: #EFF6FF;
}

/* ============================================
   STYLE: MINIMAL (new)
   ============================================ */
.tocbox-style-minimal {
	background: transparent;
	border: none;
	border-left: 3px solid #E5E7EB;
	border-radius: 0;
	box-shadow: none;
}

.tocbox-style-minimal .tocbox-toggle {
	cursor: pointer;
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 0.5rem 0.75rem;
}

.tocbox-style-minimal .tocbox-title {
	font-size: 12px;
	color: #6B7280;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	font-weight: 700;
	margin: 0;
	flex: 1;
}

.tocbox-style-minimal .tocbox-header-icon { display: none; }

.tocbox-style-minimal .tocbox-chevron {
	width: 1.25rem;
	height: 1.25rem;
	transition: transform 0.2s;
	flex-shrink: 0;
}

.tocbox-style-minimal .tocbox-list-container {
	display: none;
	padding: 0 0.75rem 0.5rem;
	max-height: var(--tocbox-max-height);
	overflow-y: auto;
}

.tocbox-style-minimal .tocbox-list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.tocbox-style-minimal .tocbox-list li a {
	display: flex;
	align-items: flex-start;
	padding: 0.3rem 0.35rem;
	color: #6B7280;
	text-decoration: none;
	font-family: var(--tocbox-font-family);
	font-size: var(--tocbox-font-size);
	font-weight: var(--tocbox-font-weight);
	line-height: var(--tocbox-line-height);
	letter-spacing: var(--tocbox-letter-spacing);
	text-transform: var(--tocbox-text-transform);
	transition: all 0.15s ease;
}

.tocbox-style-minimal .tocbox-list li a:hover { color: #111827; }

/* ============================================
   STYLE: DARK (new)
   ============================================ */
.tocbox-style-dark {
	background: #1F2937;
	border: 1px solid #374151;
	border-radius: 0.75rem;
	box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
}

.tocbox-style-dark .tocbox-toggle {
	cursor: pointer;
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 0.7rem 1rem;
}

.tocbox-style-dark .tocbox-header-icon {
	color: #60A5FA;
	flex-shrink: 0;
	opacity: 0.7;
}

.tocbox-style-dark .tocbox-title {
	font-weight: var(--tocbox-title-font-weight);
	color: #F9FAFB;
	margin: 0;
	font-size: var(--tocbox-title-font-size);
	flex: 1;
}

.tocbox-style-dark .tocbox-chevron {
	width: 1.25rem;
	height: 1.25rem;
	transition: transform 0.2s;
	color: #9CA3AF;
	flex-shrink: 0;
}

.tocbox-style-dark .tocbox-list-container {
	display: none;
	padding: 0 0.75rem 0.75rem;
	border-top: 1px solid #374151;
	max-height: var(--tocbox-max-height);
	overflow-y: auto;
}

.tocbox-style-dark .tocbox-list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.tocbox-style-dark .tocbox-list li a {
	display: flex;
	align-items: flex-start;
	padding: 0.35rem 0.5rem;
	color: #9CA3AF;
	text-decoration: none;
	border-radius: 0.35rem;
	font-family: var(--tocbox-font-family);
	font-size: var(--tocbox-font-size);
	font-weight: var(--tocbox-font-weight);
	line-height: var(--tocbox-line-height);
	letter-spacing: var(--tocbox-letter-spacing);
	text-transform: var(--tocbox-text-transform);
	transition: all 0.15s ease;
}

.tocbox-style-dark .tocbox-list li a:hover {
	color: #E5E7EB;
	background: rgba(255, 255, 255, 0.05);
}

.tocbox-style-dark .tocbox-list-container::-webkit-scrollbar { width: 4px; }
.tocbox-style-dark .tocbox-list-container::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 4px; }

/* ============================================
   ACTIVE ITEM — "background" variant (default)
   ============================================ */
.tocbox-active-background .tocbox-list li a.tocbox-active {
	font-weight: 600;
}

.tocbox-active-background.tocbox-style-amber .tocbox-list li a.tocbox-active {
	background: var(--tocbox-active-bg, #FEF3C7);
	color: var(--tocbox-active-text, #B45309);
}

.tocbox-active-background.tocbox-style-blue .tocbox-list li a.tocbox-active {
	background: var(--tocbox-active-bg, #EFF6FF);
	color: var(--tocbox-active-text, #2563EB);
}

.tocbox-active-background.tocbox-style-minimal .tocbox-list li a.tocbox-active {
	color: var(--tocbox-active-text, #111827);
}

.tocbox-active-background.tocbox-style-dark .tocbox-list li a.tocbox-active {
	background: var(--tocbox-active-bg, rgba(96, 165, 250, 0.12));
	color: var(--tocbox-active-text, #60A5FA);
}

/* ============================================
   ACTIVE ITEM — "left-border" variant
   ============================================ */
.tocbox-active-left-border .tocbox-list li a.tocbox-active {
	border-left: 3px solid var(--tocbox-primary);
	padding-left: calc(0.35rem + 3px);
	font-weight: 600;
}

.tocbox-active-left-border.tocbox-style-amber .tocbox-list li a.tocbox-active {
	border-left-color: #D97706;
	color: var(--tocbox-active-text, #B45309);
}

.tocbox-active-left-border.tocbox-style-dark .tocbox-list li a.tocbox-active {
	border-left-color: #60A5FA;
	color: var(--tocbox-active-text, #60A5FA);
}

/* ============================================
   ACTIVE ITEM — "underline" variant
   ============================================ */
.tocbox-active-underline .tocbox-list li a.tocbox-active {
	text-decoration: underline;
	text-decoration-thickness: 2px;
	text-underline-offset: 3px;
	text-decoration-color: var(--tocbox-primary);
	font-weight: 600;
}

.tocbox-active-underline.tocbox-style-amber .tocbox-list li a.tocbox-active {
	text-decoration-color: #D97706;
	color: var(--tocbox-active-text, #B45309);
}

.tocbox-active-underline.tocbox-style-dark .tocbox-list li a.tocbox-active {
	text-decoration-color: #60A5FA;
	color: var(--tocbox-active-text, #60A5FA);
}

/* ============================================
   OPEN / CLOSED STATE (original)
   ============================================ */
.tocbox-state-open .tocbox-list-container { display: block; }
.tocbox-state-open .tocbox-chevron { transform: rotate(180deg); }
.tocbox-toggle.is-open .tocbox-chevron { transform: rotate(180deg); }

/* ============================================
   LIST NUMBERS (original)
   ============================================ */
.tocbox-numbers-on .tocbox-list { counter-reset: toc-counter; }
.tocbox-numbers-on .tocbox-list li { counter-increment: toc-counter; }

.tocbox-numbers-on .tocbox-list li a::before {
	content: counter(toc-counter) ".";
	font-weight: 600;
	min-width: 2em;
	padding-right: 0.5em;
	text-align: right;
	flex-shrink: 0;
}

.tocbox-numbers-on.tocbox-style-amber .tocbox-list li a::before { color: var(--tocbox-counter-color, #d97706); }
.tocbox-numbers-on.tocbox-style-blue .tocbox-list li a::before  { color: var(--tocbox-counter-color, #94A3B8); }
.tocbox-numbers-on.tocbox-style-minimal .tocbox-list li a::before { color: var(--tocbox-counter-color, #9CA3AF); }
.tocbox-numbers-on.tocbox-style-dark .tocbox-list li a::before  { color: var(--tocbox-counter-color, #4B5563); }

.tocbox-numbers-off .tocbox-list { list-style-type: none; padding-left: 0; margin-left: 12px; }

/* Multi-level heading indentation */
.tocbox-list li[data-level="3"] { padding-left: 1.25em; }
.tocbox-list li[data-level="4"] { padding-left: 2.5em; }

/* Collapsible sub-headings */
.tocbox-list li.tocbox-sub-collapsed { display: none; }

/* ============================================
   COPY LINK BUTTON (on headings)
   ============================================ */
.tocbox-copy-link {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 22px;
	height: 22px;
	margin-left: 4px;
	border: none;
	background: transparent;
	color: var(--tocbox-primary);
	cursor: pointer;
	border-radius: 4px;
	opacity: 0;
	transition: opacity 0.15s;
	vertical-align: middle;
}

h2:hover .tocbox-copy-link,
h3:hover .tocbox-copy-link,
h4:hover .tocbox-copy-link,
.tocbox-copy-link:focus { opacity: 0.6; }

.tocbox-copy-link:hover { opacity: 1 !important; background: rgba(59, 130, 246, 0.08); }
.tocbox-copy-link svg { width: 13px; height: 13px; }
.tocbox-style-dark .tocbox-copy-link { color: #60A5FA; }

.tocbox-copy-tooltip {
	position: absolute;
	bottom: 100%;
	left: 50%;
	transform: translateX(-50%);
	padding: 3px 7px;
	background: #1E293B;
	color: #FFFFFF;
	font-size: 10px;
	border-radius: 4px;
	white-space: nowrap;
	pointer-events: none;
	animation: tocboxTipIn 0.15s ease;
}

@keyframes tocboxTipIn {
	from { opacity: 0; transform: translateX(-50%) translateY(3px); }
	to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ============================================
   MOBILE (original logic)
   ============================================ */
@media (max-width: 768px) {
	body.tocbox-mobile-active { padding-bottom: 80px !important; }

	.tocbox-container.tocbox-mobile-on {
		position: fixed !important;
		bottom: 15px;
		left: 0;
		right: 0;
		z-index: 10000;
		margin-bottom: 0 !important;
		border-radius: 0.75rem !important;
		box-shadow: 0 -5px 15px rgba(0,0,0,0.1) !important;
		display: flex !important;
		flex-direction: column-reverse;
		width: 90%;
		margin: auto;
	}

	.tocbox-container.tocbox-mobile-on.tocbox-is-fixed,
	.tocbox-container.tocbox-mobile-on.tocbox-is-absolute-bottom {
		position: fixed !important;
		bottom: 15px;
		top: auto !important;
	}

	.tocbox-mobile-on .tocbox-toggle { cursor: pointer; }

	.tocbox-mobile-on .tocbox-list-container { display: none; max-height: 50vh; }

	.tocbox-mobile-on .tocbox-chevron { display: block !important; transform: rotate(0deg) !important; }
	.tocbox-mobile-on .tocbox-toggle.is-open .tocbox-chevron { transform: rotate(180deg) !important; }

	.tocbox-mobile-on .tocbox-toggle {
		border-bottom: none;
		border-top: 1px solid #F1F5F9;
	}

	.tocbox-style-blue.tocbox-mobile-on .tocbox-title { font-size: 1em; }

	.tocbox-mobile-on .tocbox-progress-bar {
		order: 10;
	}
}

@media (max-width: 768px) {
	.tocbox-mobile-off { display: none !important; }
}
