/* Sticky TOC for long documents. Paired with assets/doc-toc.js. */

/* By default, give the main article a left margin to make room for the TOC.
   The TOC itself is fixed to the viewport. */
@media (min-width: 1100px) {
  main.doc {
    margin-left: 300px;
    transition: margin-left .2s ease;
  }
  .doc-toc-collapsed main.doc {
    margin-left: 60px;
  }
}

/* Default (mobile / narrow): inline collapsible disclosure at top of the article.
   Below 1100px the fixed left-rail doesn't fit, so the TOC reflows here.
   The header acts as a tap target; the doc-toc-mobile-open class on the toc
   toggles the list visible. */
.doc-toc {
  display: block;
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 12px 0 28px;
  border: 1px solid var(--rule-soft);
  background: var(--paper);
}
.doc-toc .doc-toc-head {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 0;
  margin-bottom: 0;
}
.doc-toc .doc-toc-head::after {
  content: "\25BE";   /* down chevron */
  margin-left: auto;
  color: var(--ink-3);
  font-size: 14px;
  line-height: 1;
  transition: transform .15s;
}
.doc-toc.doc-toc-mobile-open .doc-toc-head::after {
  transform: rotate(180deg);
}
.doc-toc .doc-toc-list {
  display: none;
  max-height: 60vh;
  overflow-y: auto;
  padding: 0 14px 14px;
  border-top: 1px dotted var(--rule-soft);
}
.doc-toc.doc-toc-mobile-open .doc-toc-list {
  display: block;
}
.doc-toc .doc-toc-collapse {
  display: none;        /* mobile uses the head as the toggle */
}

@media (min-width: 1100px) {
  .doc-toc {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 76px;            /* just below the topbar */
    bottom: 24px;
    width: 280px;         /* was 220px — too narrow for lvl-4 italic items at 30px indent */
    padding: 0 16px 0 28px;
    margin: 0;
    border-right: 1px solid var(--rule-soft);
    border-top: 0;
    border-bottom: 0;
    border-left: 0;
    background: var(--paper);
    z-index: 30;
  }
  /* Desktop: collapse button shows again, head no longer acts as tap target */
  .doc-toc .doc-toc-head { cursor: default; padding: 12px 0 8px; border-bottom: 1px dotted var(--rule-soft); margin-bottom: 8px; }
  .doc-toc .doc-toc-head::after { content: none; }
  .doc-toc .doc-toc-collapse { display: flex; }
  .doc-toc .doc-toc-list { display: block; max-height: none; overflow-y: auto; padding-right: 6px; border-top: 0; }
}

.doc-toc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 8px;
  border-bottom: 1px dotted var(--rule-soft);
  margin-bottom: 8px;
  flex: 0 0 auto;
}
.doc-toc-head h6 {
  margin: 0;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 600;
}
.doc-toc-collapse {
  background: none;
  border: 1px solid var(--rule-soft);
  width: 22px;
  height: 22px;
  border-radius: 3px;
  color: var(--ink-3);
  font: inherit;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, border-color .12s, color .12s;
}
.doc-toc-collapse:hover {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.doc-toc-collapsed .doc-toc-collapse::before {
  content: "\203A";
}
.doc-toc-collapsed .doc-toc-collapse {
  font-size: 0;
}
.doc-toc-collapsed .doc-toc-collapse::before {
  font-size: 14px;
}

.doc-toc-list {
  overflow-y: auto;
  flex: 1 1 auto;
  scrollbar-width: thin;
  padding-right: 6px;
}
.doc-toc-list::-webkit-scrollbar {
  width: 4px;
}
.doc-toc-list::-webkit-scrollbar-thumb {
  background: var(--rule-soft);
}

.doc-toc-item {
  display: block;
  padding: 5px 8px 5px 8px;
  font-family: var(--serif);
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--ink-3);
  text-decoration: none;
  border-left: 2px solid transparent;
  text-wrap: pretty;
}
.doc-toc-item:hover {
  color: var(--ink);
  background: var(--paper-2);
}
.doc-toc-item.cur {
  color: var(--ink);
  border-left-color: var(--red);
  background: var(--paper-2);
}
/* Hierarchy — top-level items take the visual weight so you can scan the spine of
   the document just by reading the bold lines in the sidebar. */
.doc-toc-item.lvl-2 {
  font-weight: 600;
  color: var(--ink);
  font-size: 12.5px;
  margin-top: 10px;
}
.doc-toc-item.lvl-2:first-child { margin-top: 0; }
.doc-toc-item.lvl-3 {
  padding-left: 18px;
  font-size: 12px;
  color: var(--ink-2);
  font-weight: 400;
}
.doc-toc-item.lvl-4 {
  padding-left: 28px;
  font-size: 11.5px;
  color: var(--ink-3);
  font-weight: 400;
  font-style: italic;
}
/* When the current item is a leaf, keep the parent visible by promoting weight slightly. */
.doc-toc-item.cur.lvl-3 { font-weight: 500; color: var(--ink); }
.doc-toc-item.cur.lvl-4 { font-weight: 500; color: var(--ink); font-style: italic; }

/* Collapsed mode: shrink to a stub */
.doc-toc-collapsed .doc-toc {
  width: 36px;
  padding: 0 4px 0 8px;
}
.doc-toc-collapsed .doc-toc-list,
.doc-toc-collapsed .doc-toc-head h6 {
  display: none;
}
.doc-toc-collapsed .doc-toc-head {
  border-bottom: 0;
  margin: 0;
  padding-top: 12px;
}

/* Print: hide the TOC */
@media print {
  .doc-toc { display: none; }
  main.doc { margin-left: 0 !important; }
}
