/*!
 * ThinkTOC — stile front-end
 * Tutti i colori passano da variabili CSS: i temi le impostano, i widget Elementor le sovrascrivono.
 */

.thinktoc {
	--ttoc-bg: #f7f7f8;
	--ttoc-text: #1d1d1f;
	--ttoc-link: #1d4ed8;
	--ttoc-link-hover: #1e3a8a;
	--ttoc-active: #d9480f;
	--ttoc-border: #e3e3e8;
	--ttoc-radius: 10px;
	--ttoc-pad: 1rem 1.25rem;
	--ttoc-indent: 1.1em;
	--ttoc-gap: .35em;
	--ttoc-width: auto;
	--ttoc-font-size: 95%;
	/* --ttoc-sticky-top e --ttoc-max-height NON si dichiarano qui: arrivano dal body (kit Elementor). */

	box-sizing: border-box;
	display: block;
	margin: 1.5em 0;
	padding: var(--ttoc-pad);
	background: var(--ttoc-bg);
	color: var(--ttoc-text);
	border: 1px solid var(--ttoc-border);
	border-radius: var(--ttoc-radius);
	font-size: var(--ttoc-font-size);
	line-height: 1.45;
}
.thinktoc *,
.thinktoc *::before,
.thinktoc *::after { box-sizing: border-box; }

/* Nei widget Elementor i margini esterni li gestisce Elementor */
.thinktoc--ctx-elementor { margin: 0; }

/* Temi */
.thinktoc--theme-dark {
	--ttoc-bg: #17181c;
	--ttoc-text: #ececf1;
	--ttoc-link: #9ec5ff;
	--ttoc-link-hover: #ffffff;
	--ttoc-active: #ffb070;
	--ttoc-border: #2c2e35;
}
.thinktoc--theme-minimal {
	--ttoc-bg: transparent;
	--ttoc-border: transparent;
	--ttoc-pad: 0;
}
.thinktoc--theme-bordered {
	--ttoc-bg: transparent;
	--ttoc-radius: 0;
	--ttoc-pad: .25rem 0 .25rem 1.1rem;
	border-width: 0 0 0 3px;
}
.thinktoc--theme-inherit {
	--ttoc-bg: transparent;
	--ttoc-text: inherit;
	--ttoc-link: inherit;
	--ttoc-link-hover: inherit;
	--ttoc-active: currentColor;
	--ttoc-border: currentColor;
	border-color: rgba(127, 127, 127, .3);
}

/* Colori globali di Elementor (Impostazioni del sito → Colori globali) */
.thinktoc--theme-elementor,
.thinktoc-dialog:where(.thinktoc--theme-elementor) {
	--ttoc-text: var(--e-global-color-text, #333);
	--ttoc-link: var(--e-global-color-primary, #1d4ed8);
	--ttoc-link-hover: var(--e-global-color-secondary, var(--e-global-color-primary, #1e3a8a));
	--ttoc-active: var(--e-global-color-accent, #d9480f);
	--ttoc-border: rgba(127, 127, 127, .25);
}
.thinktoc--theme-elementor { --ttoc-bg: rgba(127, 127, 127, .06); }
.thinktoc-dialog:where(.thinktoc--theme-elementor) { --ttoc-bg: #fff; }

/* Larghezza e allineamento */
.thinktoc--width-auto { display: table; max-width: 100%; }
.thinktoc--width-full { width: 100%; }
.thinktoc--width-custom { width: var(--ttoc-width); max-width: 100%; }
.thinktoc--align-left { float: left; margin: .25em 1.5em 1em 0; }
.thinktoc--align-right { float: right; margin: .25em 0 1em 1.5em; }
.thinktoc--align-center { margin-left: auto; margin-right: auto; }
@media (max-width: 600px) {
	.thinktoc--align-left,
	.thinktoc--align-right { float: none; margin: 1.5em 0; width: 100%; }
}

/* Intestazione */
.thinktoc__header {
	display: flex;
	align-items: center;
	gap: .5em 1em;
	flex-wrap: wrap;
	margin: 0;
	padding: 0;
	font-weight: 700;
	list-style: none;
}
.thinktoc__details > .thinktoc__header { cursor: pointer; user-select: none; }
.thinktoc__details > .thinktoc__header::-webkit-details-marker { display: none; }
.thinktoc__details > .thinktoc__header::marker { content: ""; }
.thinktoc__title { font-size: 1.05em; }
.thinktoc__reading-time { font-weight: 400; font-size: .85em; opacity: .75; }
.thinktoc__chevron {
	margin-left: auto;
	width: .6em;
	height: .6em;
	border-right: 2px solid currentColor;
	border-bottom: 2px solid currentColor;
	transform: rotate(45deg) translate(-2px, -2px);
	transition: transform .2s ease;
	flex: none;
}
.thinktoc__details:not([open]) .thinktoc__chevron { transform: rotate(-45deg); }
.thinktoc__details > .thinktoc__header:focus-visible { outline: 2px solid var(--ttoc-link); outline-offset: 3px; border-radius: 4px; }

.thinktoc__header + .thinktoc__body { margin-top: .75em; }

/* Elenco */
.thinktoc .thinktoc__list {
	list-style: none;
	margin: 0;
	padding: 0;
	counter-reset: ttoc;
}
.thinktoc .thinktoc__list .thinktoc__list {
	margin: var(--ttoc-gap) 0 0;
	padding-left: var(--ttoc-indent);
}
.thinktoc .thinktoc__item {
	position: relative;
	margin: 0 0 var(--ttoc-gap);
	padding: 0;
	counter-increment: ttoc;
}
.thinktoc .thinktoc__item:last-child { margin-bottom: 0; }
.thinktoc .thinktoc__item::before,
.thinktoc .thinktoc__item::marker { content: none; }

.thinktoc .thinktoc__link {
	color: var(--ttoc-link);
	text-decoration: none;
	transition: color .15s ease;
	box-shadow: none;
}
.thinktoc .thinktoc__link:hover,
.thinktoc .thinktoc__link:focus-visible { color: var(--ttoc-link-hover); text-decoration: underline; }
.thinktoc .thinktoc__link.is-active { color: var(--ttoc-active); font-weight: 600; }

/* Numerazione con contatori CSS: identica per indici lato server e lato client */
.thinktoc--num-decimal .thinktoc__link::before { content: counter(ttoc) ". "; }
.thinktoc--num-hierarchical .thinktoc__link::before { content: counters(ttoc, ".") " "; }
.thinktoc--num-decimal .thinktoc__link::before,
.thinktoc--num-hierarchical .thinktoc__link::before { font-variant-numeric: tabular-nums; opacity: .8; }

/* Mostra tutto */
.thinktoc--has-more:not(.thinktoc--expanded) .thinktoc__item--extra { display: none; }
.thinktoc .thinktoc__more {
	margin-top: .75em;
	padding: 0;
	border: 0;
	background: none;
	color: var(--ttoc-link);
	font: inherit;
	font-size: .9em;
	font-weight: 600;
	cursor: pointer;
	text-decoration: underline;
}

/* Sotto-voci richiudibili */
.thinktoc--sub-toggles .thinktoc__item--parent {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto;
	align-items: start;
}
.thinktoc--sub-toggles .thinktoc__item--parent > .thinktoc__list { grid-column: 1 / -1; }
.thinktoc .thinktoc__sub-toggle {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 1.5em;
	height: 1.5em;
	margin-left: .5em;
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	cursor: pointer;
	opacity: .65;
}
.thinktoc .thinktoc__sub-toggle::before {
	content: "";
	width: .45em;
	height: .45em;
	border-right: 2px solid currentColor;
	border-bottom: 2px solid currentColor;
	transform: rotate(45deg);
	transition: transform .2s ease;
}
.thinktoc .thinktoc__item--closed > .thinktoc__sub-toggle::before { transform: rotate(-45deg); }
.thinktoc .thinktoc__item--closed:not(.is-trail) > .thinktoc__list { display: none; }

/* Indice fisso */
.thinktoc--sticky {
	position: sticky;
	top: var(--ttoc-sticky-top, 24px);
	z-index: 5;
}
.thinktoc--sticky .thinktoc__body {
	max-height: var(--ttoc-max-height, none);
	overflow-y: auto;
	overscroll-behavior: contain;
}

/* Ancore: lo spazio sopra il titolo raggiunto */
.thinktoc-anchor { scroll-margin-top: var(--thinktoc-offset, 0px); }
.admin-bar .thinktoc-anchor { scroll-margin-top: calc(var(--thinktoc-offset, 0px) + 32px); }
@media (max-width: 782px) {
	.admin-bar .thinktoc-anchor { scroll-margin-top: calc(var(--thinktoc-offset, 0px) + 46px); }
}

/* Copia link */
.thinktoc-copy {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 1.6em;
	height: 1.6em;
	margin-left: .35em;
	padding: 0;
	border: 0;
	border-radius: 4px;
	background: none;
	color: inherit;
	font-size: .6em;
	line-height: 1;
	vertical-align: middle;
	cursor: pointer;
	opacity: 0;
	transition: opacity .15s ease;
}
.thinktoc-anchor:hover .thinktoc-copy,
.thinktoc-copy:focus-visible,
.thinktoc-copy.is-copied { opacity: .7; }
.thinktoc-copy:hover { opacity: 1; }
.thinktoc-copy svg { width: 1.6em; height: 1.6em; }
@media (hover: none) {
	.thinktoc-copy { opacity: .45; }
}
.thinktoc-copy.is-copied::after {
	content: attr(data-copied);
	position: absolute;
	left: 50%;
	bottom: calc(100% + 6px);
	transform: translateX(-50%);
	padding: .35em .6em;
	border-radius: 4px;
	background: #111;
	color: #fff;
	font-size: 12px;
	font-weight: 500;
	white-space: nowrap;
	pointer-events: none;
}

/* Pulsante flottante e pannello mobile */
.thinktoc-fab {
	position: fixed;
	bottom: var(--ttoc-fab-bottom, 20px);
	z-index: 9990;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: var(--ttoc-fab-size, 48px);
	height: var(--ttoc-fab-size, 48px);
	padding: 0;
	border: 0;
	border-radius: var(--ttoc-fab-radius, 50%);
	background: var(--ttoc-fab-bg, #1d1d1f);
	color: var(--ttoc-fab-color, #fff);
	box-shadow: 0 6px 18px rgba(0, 0, 0, .22);
	cursor: pointer;
}
.thinktoc-fab[hidden] { display: none; }
.thinktoc-fab--right { right: var(--ttoc-fab-side, 20px); }
.thinktoc-fab--left { left: var(--ttoc-fab-side, 20px); }
.thinktoc-fab:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

.thinktoc-dialog {
	--ttoc-bg: #ffffff;
	--ttoc-text: #1d1d1f;
	--ttoc-link: #1d4ed8;
	--ttoc-link-hover: #1e3a8a;
	--ttoc-active: #d9480f;
	--ttoc-border: #e3e3e8;
	--ttoc-indent: 1.1em;
	--ttoc-gap: .5em;

	box-sizing: border-box;
	width: min(92vw, 520px);
	max-height: 80vh;
	margin: auto auto 0;
	padding: 0;
	border: 0;
	border-radius: 16px 16px 0 0;
	background: var(--ttoc-bg);
	color: var(--ttoc-text);
	font-size: 16px;
	line-height: 1.45;
}
.thinktoc-dialog:where(.thinktoc--theme-dark) { --ttoc-bg: #17181c; --ttoc-text: #ececf1; --ttoc-link: #9ec5ff; --ttoc-link-hover: #fff; --ttoc-active: #ffb070; --ttoc-border: #2c2e35; }
.thinktoc-dialog::backdrop { background: rgba(0, 0, 0, .45); }
.thinktoc-dialog[open] { display: flex; flex-direction: column; animation: thinktoc-up .2s ease; }
@keyframes thinktoc-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .thinktoc-dialog[open] { animation: none; } }
.thinktoc-dialog__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 14px 18px;
	border-bottom: 1px solid var(--ttoc-border);
	font-weight: 700;
}
.thinktoc-dialog__close {
	width: 36px;
	height: 36px;
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	font-size: 26px;
	line-height: 1;
	cursor: pointer;
}
.thinktoc-dialog__body { padding: 14px 18px 22px; overflow-y: auto; }
.thinktoc-dialog .thinktoc__list { list-style: none; margin: 0; padding: 0; counter-reset: ttoc; }
.thinktoc-dialog .thinktoc__list .thinktoc__list { margin: var(--ttoc-gap) 0 0; padding-left: var(--ttoc-indent); }
.thinktoc-dialog .thinktoc__item { margin: 0 0 var(--ttoc-gap); counter-increment: ttoc; }
.thinktoc-dialog .thinktoc__item--extra { display: list-item; }
.thinktoc-dialog .thinktoc__link { color: var(--ttoc-link); text-decoration: none; }
.thinktoc-dialog .thinktoc__link.is-active { color: var(--ttoc-active); font-weight: 600; }
.thinktoc-dialog.thinktoc--num-decimal .thinktoc__link::before { content: counter(ttoc) ". "; }
.thinktoc-dialog.thinktoc--num-hierarchical .thinktoc__link::before { content: counters(ttoc, ".") " "; }

/* Barra di avanzamento */
.thinktoc-progress {
	position: fixed;
	left: 0;
	right: 0;
	z-index: 99999;
	height: var(--ttoc-progress-height, 3px);
	background: var(--ttoc-progress-track, transparent);
	pointer-events: none;
}
.thinktoc-progress--top { top: 0; }
.admin-bar .thinktoc-progress--top { top: 32px; }
@media (max-width: 782px) { .admin-bar .thinktoc-progress--top { top: 46px; } }
@media (max-width: 600px) { .admin-bar .thinktoc-progress--top { top: 0; } }
.thinktoc-progress--bottom { bottom: 0; }
.thinktoc-progress__fill {
	display: block;
	height: 100%;
	background: var(--ttoc-progress-color, #d9480f);
	transform: scaleX(0);
	transform-origin: 0 50%;
	will-change: transform;
}
.thinktoc-progress--inline { position: relative; left: auto; right: auto; top: auto; bottom: auto; }

/* Tempo di lettura stand-alone */
.thinktoc-reading-time { display: inline-flex; align-items: center; gap: .4em; }

/* Stampa */
@media print {
	.thinktoc-fab,
	.thinktoc-dialog,
	.thinktoc-progress,
	.thinktoc-copy { display: none !important; }
	.thinktoc__details:not([open]) > .thinktoc__body { display: block; }
}
