/* ── Smart TOC – stylesheet ───────────────────────────────────────────────── */

:root {
  --toc-width: 240px;
  --toc-font:  system-ui, sans-serif;
  --toc-bg:    #f8f8f6;
  --toc-border:#e2e2de;
  --toc-title: #1a1a18;
  --toc-link:  #4a4a47;
  --toc-hover: #111110;
  --toc-active:#2563eb;
  --toc-active-bg: #eff6ff;
  --toc-radius:10px;
  --toc-progress: #2563eb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --toc-bg:    #1e1e1c;
    --toc-border:#2e2e2b;
    --toc-title: #f0efeb;
    --toc-link:  #a8a89e;
    --toc-hover: #f0efeb;
    --toc-active:#60a5fa;
    --toc-active-bg: #1e2a3a;
  }
}

/* ── Progress bar ── */
#toc-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 0%;
  height: 3px;
  background: var(--toc-progress);
  z-index: 9999;
  transition: width 0.1s linear;
  border-radius: 0 2px 2px 0;
}

/* ── Base nav ── */
.smart-toc {
  font-family: var(--toc-font);
  font-size: 0.85rem;
  line-height: 1.5;
  margin: 1.5rem 0 2rem;
}

.smart-toc__inner {
  background: var(--toc-bg);
  border: 1px solid var(--toc-border);
  border-radius: var(--toc-radius);
  padding: 1rem 1.25rem;
  max-width: var(--toc-width);
}

.smart-toc__title {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--toc-title);
  margin-bottom: 0.65rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--toc-border);
}

/* ── Lists ── */
.smart-toc__list,
.smart-toc__sub {
  list-style: none;
  margin: 0;
  padding: 0;
}

.smart-toc__sub {
  padding-left: 0.85rem;
  margin-top: 0.2rem;
  border-left: 2px solid var(--toc-border);
  margin-left: 0.1rem;
}

.smart-toc__item {
  margin: 0.15rem 0;
}

/* ── Links ── */
.smart-toc__link {
  display: block;
  padding: 0.2rem 0.4rem;
  color: var(--toc-link);
  text-decoration: none;
  border-radius: 5px;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.smart-toc__link:hover {
  color: var(--toc-hover);
  background: var(--toc-border);
}

.smart-toc__link.is-active {
  color: var(--toc-active);
  background: var(--toc-active-bg);
  font-weight: 500;
}

/* ── Sticky ── */
.smart-toc--sticky {
  position: sticky;
  top: 1.5rem;
  max-height: calc(100vh - 3rem);
  overflow-y: auto;
  scrollbar-width: thin;
}

/* ── Inline (inside content) ── */
.page-content .smart-toc {
  float: none;
  max-width: 100%;
  margin: 1.5rem 0 2rem;
}

.page-content .smart-toc__inner {
  max-width: 320px;
}

/* ── Collapsed on mobile ── */
@media (max-width: 768px) {
  .smart-toc--sticky {
    position: static;
  }

  .smart-toc__inner {
    max-width: 100%;
  }

  .smart-toc__title {
    cursor: pointer;
    user-select: none;
  }

  .smart-toc__title::after {
    content: " ▾";
    font-size: 0.75em;
    opacity: 0.6;
  }

  .smart-toc.is-collapsed .smart-toc__title::after {
    content: " ▸";
  }

  .smart-toc.is-collapsed .smart-toc__list {
    display: none;
  }
}
