/* ==========================================================================
   TN TOC — table of contents
   Selectors start with nav.tn-toc so they win over a theme's article styles
   (.prose ul, .prose a…) without !important.
   Colours are CSS custom properties: themes set them, a site can override
   them, "custom" gets them from the plugin settings.
   ========================================================================== */

.tn-toc,
.tn-toc-sticky {
  --tn-toc-bg: #f9f9f9;
  --tn-toc-border: #aaaaaa;
  --tn-toc-title: #222222;
  --tn-toc-link: #444444;
  --tn-toc-link-hover: #000000;
  --tn-toc-counter: currentColor;
  --tn-toc-active-bg: color-mix(in srgb, var(--tn-toc-link) 12%, transparent);
  --tn-toc-active-color: var(--tn-toc-link-hover);
  --tn-toc-radius: 8px;
}

/* Themes ------------------------------------------------------------------ */
.tn-toc--light-blue { --tn-toc-bg: #edf6ff; --tn-toc-border: #c5ddf5; --tn-toc-title: #1b3a57; --tn-toc-link: #1b5fa8; --tn-toc-link-hover: #0d3d73; }
.tn-toc--white      { --tn-toc-bg: #ffffff; --tn-toc-border: #dddddd; --tn-toc-title: #222222; --tn-toc-link: #2f6fb7; --tn-toc-link-hover: #1d4a80; }
.tn-toc--black      { --tn-toc-bg: #111111; --tn-toc-border: #333333; --tn-toc-title: #ffffff; --tn-toc-link: #dddddd; --tn-toc-link-hover: #ffffff; }
.tn-toc--transparent { --tn-toc-bg: transparent; --tn-toc-border: color-mix(in srgb, currentColor 18%, transparent); --tn-toc-title: inherit; --tn-toc-link: inherit; --tn-toc-link-hover: inherit; --tn-toc-active-bg: color-mix(in srgb, currentColor 10%, transparent); --tn-toc-active-color: inherit; }
/* "auto" follows the page: its own text colour, tinted box. Works on light and dark sites. */
.tn-toc--auto       { --tn-toc-bg: color-mix(in srgb, currentColor 5%, transparent); --tn-toc-border: color-mix(in srgb, currentColor 16%, transparent); --tn-toc-title: inherit; --tn-toc-link: inherit; --tn-toc-link-hover: inherit; --tn-toc-active-bg: color-mix(in srgb, currentColor 11%, transparent); --tn-toc-active-color: inherit; }

/* The light presets on a page that is in dark mode. */
:root[data-theme="dark"] .tn-toc--grey, .dark .tn-toc--grey,
:root[data-theme="dark"] .tn-toc--white, .dark .tn-toc--white { --tn-toc-bg: #1c1c20; --tn-toc-border: #34343a; --tn-toc-title: #f5f5f7; --tn-toc-link: #d2d2d7; --tn-toc-link-hover: #ffffff; }
:root[data-theme="dark"] .tn-toc--light-blue, .dark .tn-toc--light-blue { --tn-toc-bg: #14202e; --tn-toc-border: #24384f; --tn-toc-title: #e6f0fa; --tn-toc-link: #9cc4ee; --tn-toc-link-hover: #cfe4fa; }

/* Box ---------------------------------------------------------------------- */
nav.tn-toc {
  display: block; box-sizing: border-box; width: auto; max-width: 100%; margin: 1.5em 0; padding: 14px 18px;
  border: 1px solid var(--tn-toc-border); border-radius: var(--tn-toc-radius); background: var(--tn-toc-bg);
  font-size: 0.95em; line-height: 1.5; clear: both;
}
nav.tn-toc--fit { width: max-content; }
nav.tn-toc--full, nav.tn-toc--w-100 { width: 100%; }
nav.tn-toc--w-25 { width: 25%; } nav.tn-toc--w-50 { width: 50%; } nav.tn-toc--w-75 { width: 75%; }
nav.tn-toc--px-200 { width: 200px; } nav.tn-toc--px-250 { width: 250px; } nav.tn-toc--px-300 { width: 300px; }
nav.tn-toc--px-350 { width: 350px; } nav.tn-toc--px-400 { width: 400px; }
nav.tn-toc--align-left { float: left; margin: 0.4em 1.5em 1em 0; clear: none; }
nav.tn-toc--align-right { float: right; margin: 0.4em 0 1em 1.5em; clear: none; }
nav.tn-toc--align-center { margin-inline: auto; }

/* Head */
nav.tn-toc .tn-toc__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0; }
nav.tn-toc .tn-toc__head--bare:empty { display: none; }
nav.tn-toc .tn-toc__title { margin: 0; padding: 0; font-size: 1.1em; font-weight: 600; line-height: 1.3; color: var(--tn-toc-title); }
nav.tn-toc.tn-toc--title-toggles .tn-toc__title { cursor: pointer; }
nav.tn-toc .tn-toc__toggle {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; width: 30px; height: 30px; margin: 0 0 0 auto; padding: 0;
  border: 1px solid var(--tn-toc-border); border-radius: 6px; background: transparent; color: var(--tn-toc-title); cursor: pointer; font: inherit;
}
nav.tn-toc .tn-toc__toggle:hover { background: var(--tn-toc-active-bg); }
nav.tn-toc .tn-toc__toggle::before {
  content: ""; width: 8px; height: 8px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: translateY(-2px) rotate(45deg); transition: transform .15s;
}
nav.tn-toc.is-collapsed .tn-toc__toggle::before { transform: translateX(-2px) rotate(-45deg); }
nav.tn-toc .tn-toc__meta { margin: 6px 0 0; font-size: 0.85em; opacity: 0.75; }
nav.tn-toc .tn-toc__body { margin-top: 10px; }
nav.tn-toc .tn-toc__head--bare + .tn-toc__body { margin-top: 0; }
nav.tn-toc.is-collapsed .tn-toc__body, nav.tn-toc.is-collapsed .tn-toc__meta, nav.tn-toc.is-collapsed .tn-toc__more { display: none; }

/* List --------------------------------------------------------------------- */
.tn-toc ul.tn-toc__list { margin: 0; padding: 0; list-style: none; counter-reset: tn-toc; }
.tn-toc ul.tn-toc__list--sub { margin: 2px 0 2px 1.25em; }
.tn-toc li.tn-toc__item { margin: 0; padding: 0; list-style: none; counter-increment: tn-toc; break-inside: avoid; }
.tn-toc li.tn-toc__item::before, .tn-toc li.tn-toc__item::marker { content: none; }
.tn-toc a.tn-toc__link {
  display: inline-block; padding: 3px 6px; margin-left: -6px; border-radius: 5px; color: var(--tn-toc-link);
  text-decoration: none; font-weight: 500; box-shadow: none; background-image: none;
}
.tn-toc a.tn-toc__link:hover { color: var(--tn-toc-link-hover); text-decoration: underline; }
.tn-toc ul.tn-toc__list--sub a.tn-toc__link { font-size: 0.95em; font-weight: 400; }

/* Counters (CSS only — nothing is numbered in the HTML) */
.tn-toc a.tn-toc__link::before { color: var(--tn-toc-counter); margin-right: 0.45em; font-variant-numeric: tabular-nums; }
.tn-toc--counter-decimal.tn-toc--nested a.tn-toc__link::before { content: counters(tn-toc, ".") "."; }
.tn-toc--counter-decimal.tn-toc--flat a.tn-toc__link::before,
.tn-toc--counter-numeric a.tn-toc__link::before { content: counter(tn-toc) "."; }
.tn-toc--counter-roman a.tn-toc__link::before { content: counter(tn-toc, upper-roman) "."; }
.tn-toc--counter-roman ul.tn-toc__list--sub a.tn-toc__link::before { content: counter(tn-toc, lower-roman) "."; }
.tn-toc--counter-alpha a.tn-toc__link::before { content: counter(tn-toc, upper-alpha) "."; }
.tn-toc--counter-alpha ul.tn-toc__list--sub a.tn-toc__link::before { content: counter(tn-toc, lower-alpha) "."; }
.tn-toc--counter-disc a.tn-toc__link::before { content: "•"; }
.tn-toc--counter-disc ul.tn-toc__list--sub a.tn-toc__link::before { content: "◦"; }
.tn-toc--counter-none a.tn-toc__link::before { content: none; }

/* Columns */
nav.tn-toc--cols-2 .tn-toc__list--root { columns: 2; column-gap: 28px; }
nav.tn-toc--cols-3 .tn-toc__list--root { columns: 3; column-gap: 24px; }
nav.tn-toc--cols-4 .tn-toc__list--root { columns: 4; column-gap: 20px; }

/* Highlight (scroll spy) ---------------------------------------------------- */
.tn-toc li.tn-toc__item.is-active > a.tn-toc__link { background: var(--tn-toc-active-bg); color: var(--tn-toc-active-color); font-weight: 600; }

/* View more ------------------------------------------------------------------ */
.tn-toc li.tn-toc__item.is-extra { display: none; }
.tn-toc.is-expanded li.tn-toc__item.is-extra { display: list-item; }
nav.tn-toc .tn-toc__more {
  display: inline-block; margin: 10px 0 0; padding: 5px 14px; border: 1px solid var(--tn-toc-border); border-radius: 999px;
  background: transparent; color: var(--tn-toc-link); font: inherit; font-size: 0.9em; cursor: pointer;
}
nav.tn-toc .tn-toc__more:hover { background: var(--tn-toc-active-bg); }

/* Collapsible sub-headings ---------------------------------------------------- */
.tn-toc .tn-toc__sub-toggle {
  display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; margin-left: 4px; padding: 0; vertical-align: middle;
  border: 0; border-radius: 4px; background: transparent; color: var(--tn-toc-link); cursor: pointer;
}
.tn-toc .tn-toc__sub-toggle:hover { background: var(--tn-toc-active-bg); }
.tn-toc .tn-toc__sub-toggle::before {
  content: ""; width: 6px; height: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform .15s;
}
.tn-toc li.is-sub-open > .tn-toc__sub-toggle::before { transform: translateY(-2px) rotate(45deg); }
.tn-toc--collapse-sub.is-enhanced li.tn-toc__item:not(.is-sub-open) > ul.tn-toc__list--sub { display: none; }

/* Widget variant */
nav.tn-toc--widget { margin: 0; padding: 0; border: 0; }

/* Devices -------------------------------------------------------------------- */
@media (min-width: 769px) { .tn-toc--only-mobile { display: none !important; } }
@media (max-width: 768px) {
  .tn-toc--only-desktop { display: none !important; }
  nav.tn-toc[class*="tn-toc--cols-"] .tn-toc__list--root { columns: 1; }
  nav.tn-toc[class*="tn-toc--align-"], nav.tn-toc[class*="tn-toc--px-"], nav.tn-toc[class*="tn-toc--w-"] { float: none; width: 100%; margin: 1.5em 0; }
}

/* Smooth scrolling, when the setting is on (it sets --tn-toc-scroll).
   The space before the colon is deliberate: Core's asset registry refuses inline
   CSS that contains the legacy IE token "behavior" followed by a colon, and
   this file is printed inline when "inline assets" is on. */
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior : var(--tn-toc-scroll, auto); }
}

/* Anchors: leave room for a sticky site header ------------------------------ */
h1[id^="cms-content-"], h2[id^="cms-content-"], h3[id^="cms-content-"],
h4[id^="cms-content-"], h5[id^="cms-content-"], h6[id^="cms-content-"] { scroll-margin-top: var(--tn-toc-offset, 30px); }
@media (max-width: 768px) {
  h1[id^="cms-content-"], h2[id^="cms-content-"], h3[id^="cms-content-"],
  h4[id^="cms-content-"], h5[id^="cms-content-"], h6[id^="cms-content-"] { scroll-margin-top: var(--tn-toc-offset-mobile, 0px); }
}

/* ==========================================================================
   Sticky drawer
   A tab on the edge of the screen + a panel that slides out. Both stay hidden
   until the script decides they are useful: the tab appears once the reader
   has scrolled past the table of contents in the article.
   ========================================================================== */
.tn-toc-sticky {
  --tn-toc-accent: var(--primary, #0b6bcb);
  --tn-toc-surface: #ffffff;
  --tn-toc-ink: #1d1d1f;
  --tn-toc-muted: #6e6e73;
  --tn-toc-line: rgba(0, 0, 0, .1);
  --tn-toc-hover: rgba(0, 0, 0, .05);
  --tn-toc-current: color-mix(in srgb, var(--tn-toc-accent) 10%, transparent);
  position: fixed; z-index: 90; inset: 0; pointer-events: none; font-family: inherit;
}
:root[data-theme="dark"] .tn-toc-sticky, .dark .tn-toc-sticky, .tn-toc-sticky.tn-toc--black {
  --tn-toc-surface: #18181b; --tn-toc-ink: #f5f5f7; --tn-toc-muted: #98989d;
  --tn-toc-line: rgba(255, 255, 255, .12); --tn-toc-hover: rgba(255, 255, 255, .07);
  --tn-toc-current: color-mix(in srgb, var(--tn-toc-accent) 22%, transparent);
}
/* Custom colours from the settings also drive the drawer. */
.tn-toc-sticky.tn-toc--custom { --tn-toc-surface: var(--tn-toc-bg); --tn-toc-ink: var(--tn-toc-link); --tn-toc-line: var(--tn-toc-border); --tn-toc-accent: var(--tn-toc-link-hover); }

/* Tab ----------------------------------------------------------------------- */
.tn-toc-sticky__open {
  pointer-events: none; position: absolute; display: inline-flex; align-items: center; gap: 8px; margin: 0; padding: 14px 9px;
  border: 1px solid var(--tn-toc-line); background: var(--tn-toc-surface); color: var(--tn-toc-ink);
  font: inherit; font-size: 13px; font-weight: 600; letter-spacing: .02em; line-height: 1; cursor: pointer;
  writing-mode: vertical-rl; box-shadow: 0 4px 18px rgba(0, 0, 0, .14);
  opacity: 0; transition: opacity .2s ease, transform .2s ease, background-color .15s;
}
.tn-toc-sticky--left .tn-toc-sticky__open { left: 0; border-left: 0; border-radius: 0 10px 10px 0; transform: translateX(-100%); }
.tn-toc-sticky--right .tn-toc-sticky__open { right: 0; border-right: 0; border-radius: 10px 0 0 10px; transform: translateX(100%); }
.tn-toc-sticky--top .tn-toc-sticky__open { top: 22vh; }
.tn-toc-sticky--middle .tn-toc-sticky__open { top: 50%; margin-top: -60px; }
.tn-toc-sticky--bottom .tn-toc-sticky__open { bottom: 16vh; }
.tn-toc-sticky.is-visible:not(.is-open) .tn-toc-sticky__open { pointer-events: auto; opacity: 1; transform: none; }
.tn-toc-sticky__open:hover { background: color-mix(in srgb, var(--tn-toc-accent) 8%, var(--tn-toc-surface)); color: var(--tn-toc-accent); }
.tn-toc-sticky__open:focus-visible, .tn-toc-sticky__close:focus-visible { outline: 2px solid var(--tn-toc-accent); outline-offset: 2px; }
.tn-toc-sticky__open-icon {
  width: 14px; height: 12px; flex-shrink: 0;
  background: linear-gradient(currentColor, currentColor) 0 0 / 100% 2px no-repeat,
              linear-gradient(currentColor, currentColor) 0 5px / 70% 2px no-repeat,
              linear-gradient(currentColor, currentColor) 0 10px / 100% 2px no-repeat;
}

/* Backdrop (phones: the drawer covers most of the screen) */
.tn-toc-sticky__backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .35); opacity: 0; transition: opacity .2s ease; }
@media (max-width: 768px) { .tn-toc-sticky.is-open .tn-toc-sticky__backdrop { opacity: 1; pointer-events: auto; } }

/* Panel --------------------------------------------------------------------- */
.tn-toc-sticky__drawer {
  position: absolute; top: 0; bottom: 0; width: min(340px, 88vw); display: flex; flex-direction: column;
  background: var(--tn-toc-surface); color: var(--tn-toc-ink); border: 0 solid var(--tn-toc-line);
  box-shadow: 0 0 40px rgba(0, 0, 0, .18); visibility: hidden; pointer-events: none;
  transition: transform .24s cubic-bezier(.2, .7, .2, 1), visibility 0s linear .24s;
}
.tn-toc-sticky--left .tn-toc-sticky__drawer { left: 0; border-right-width: 1px; transform: translateX(-102%); }
.tn-toc-sticky--right .tn-toc-sticky__drawer { right: 0; border-left-width: 1px; transform: translateX(102%); }
.tn-toc-sticky.is-open .tn-toc-sticky__drawer { transform: none; visibility: visible; pointer-events: auto; transition-delay: 0s; }
@media (prefers-reduced-motion: reduce) { .tn-toc-sticky__drawer, .tn-toc-sticky__open { transition: none; } }

.tn-toc-sticky__head { display: flex; align-items: center; gap: 10px; padding: 16px 14px 14px 20px; }
.tn-toc-sticky__head .tn-toc__title { flex: 1; margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--tn-toc-muted); }
.tn-toc-sticky__count { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--tn-toc-muted); }
.tn-toc-sticky__close {
  display: grid; place-items: center; width: 30px; height: 30px; margin: 0; padding: 0; border: 0; border-radius: 8px;
  background: transparent; color: var(--tn-toc-muted); font: inherit; font-size: 22px; line-height: 1; cursor: pointer;
}
.tn-toc-sticky__close:hover { background: var(--tn-toc-hover); color: var(--tn-toc-ink); }
.tn-toc-sticky__progress { height: 2px; background: var(--tn-toc-line); }
.tn-toc-sticky__progress span { display: block; width: 0; height: 100%; background: var(--tn-toc-accent); transition: width .12s linear; }

.tn-toc-sticky__nav { position: relative; flex: 1; overflow-y: auto; overscroll-behavior : contain; padding: 12px 12px 28px; font-size: 14px; line-height: 1.45; }

/* List: one step of indentation per heading level, with a guide line. */
.tn-toc-sticky ul.tn-toc__list { margin: 0; padding: 0; list-style: none; counter-reset: tn-toc; }
.tn-toc-sticky ul.tn-toc__list--sub { margin: 2px 0 4px 16px; padding-left: 8px; border-left: 1px solid var(--tn-toc-line); }
.tn-toc-sticky li.tn-toc__item { margin: 0; padding: 0; list-style: none; counter-increment: tn-toc; }
.tn-toc-sticky li.tn-toc__item::before, .tn-toc-sticky li.tn-toc__item::marker { content: none; }
.tn-toc-sticky a.tn-toc__link {
  position: relative; display: flex; align-items: baseline; gap: 8px; margin: 1px 0; padding: 7px 10px 7px 12px; border-radius: 8px;
  color: var(--tn-toc-ink); text-decoration: none; font-weight: 500; box-shadow: none; background-image: none;
  transition: background-color .12s, color .12s;
}
.tn-toc-sticky ul.tn-toc__list--sub a.tn-toc__link { padding-block: 5px; font-size: 13.5px; font-weight: 400; color: color-mix(in srgb, var(--tn-toc-ink) 82%, transparent); }
.tn-toc-sticky ul.tn-toc__list--sub ul.tn-toc__list--sub a.tn-toc__link { font-size: 13px; }
.tn-toc-sticky a.tn-toc__link:hover { background: var(--tn-toc-hover); color: var(--tn-toc-ink); text-decoration: none; }
.tn-toc-sticky a.tn-toc__link::before { flex-shrink: 0; min-width: 1.4em; margin: 0; font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--tn-toc-muted); }

/* Flat lists carry no nesting, so the level is shown from the item's own class. */
.tn-toc-sticky.tn-toc--flat li.tn-toc__item--h3 > a.tn-toc__link { margin-left: 16px; font-weight: 400; }
.tn-toc-sticky.tn-toc--flat li.tn-toc__item--h4 > a.tn-toc__link { margin-left: 32px; font-weight: 400; font-size: 13.5px; }
.tn-toc-sticky.tn-toc--flat li.tn-toc__item--h5 > a.tn-toc__link,
.tn-toc-sticky.tn-toc--flat li.tn-toc__item--h6 > a.tn-toc__link { margin-left: 48px; font-weight: 400; font-size: 13px; }

/* The section being read, and the branch it belongs to. */
.tn-toc-sticky li.tn-toc__item.is-trail > a.tn-toc__link { color: var(--tn-toc-ink); font-weight: 600; }
.tn-toc-sticky li.tn-toc__item.is-active > a.tn-toc__link { background: var(--tn-toc-current); color: var(--tn-toc-accent); font-weight: 600; }
.tn-toc-sticky li.tn-toc__item.is-active > a.tn-toc__link::after {
  content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px; border-radius: 3px; background: var(--tn-toc-accent);
}
.tn-toc-sticky li.tn-toc__item.is-active > a.tn-toc__link::before { color: var(--tn-toc-accent); }

@media print { .tn-toc-sticky { display: none; } }
