/* ==== Sidebar TOC for Pandoc (no extra classes needed) ==== */
/* Styles <nav id="TOC"> as a sticky left sidebar with responsive fallback */

/* Fallback variables in case theme.css isn't loaded */
:root{
  --toc-width: 320px;
  --gap: 2rem;

  --toc-bg: #f8f9fb;
  --toc-border: #e6e8ec;
  --toc-text: #0f172a;
  --toc-muted: #6b7280;
  --toc-link: #1f6feb;
  --toc-link-hover: #0b66e3;

  --radius: 12px;
  --shadow: 0 10px 30px rgba(0,0,0,.08);
}

/* Two-column layout: TOC + content */
body{
  margin: 0;
  display: grid;
  grid-template-columns: var(--toc-width) minmax(0,1fr);
  gap: var(--gap);
  align-items: start;
}

/* Put everything except the TOC into the content column */
body > :not(#TOC){ grid-column: 2; }

/* TOC card */
#TOC{
  grid-column: 1;
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow: auto;

  color: var(--toc-text);
  background: var(--toc-bg);
  border: 1px solid var(--toc-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1rem .75rem;
  margin: 1rem 0;
}

/* Pandoc emits a heading inside #TOC */
#TOC > h1, #TOC > h2, #TOC > h3{
  margin: .25rem 0 .6rem;
  font-size: .95rem;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--toc-muted);
}

/* TOC list + links */
#TOC ul{ list-style: none; margin: 0; padding-left: 0; }
#TOC li{ margin: .15rem 0; }

#TOC a{
  display: inline-block;
  text-decoration: none;
  color: var(--toc-link);
  font-size: .95rem;
  line-height: 1.45;
  padding: .12rem .25rem;
  border-radius: 6px;
}
#TOC a:hover{
  color: var(--toc-link-hover);
  text-decoration: underline;
  text-underline-offset: 2px;
}
#TOC a:focus{
  outline: 2px solid #94c0ff;
  outline-offset: 2px;
}

/* Nested levels: subtle indent + guide */
#TOC ul ul{
  margin-left: .5rem;
  padding-left: .75rem;
  border-left: 1px dashed var(--toc-border);
}

/* Highlight the destination heading area when jumped to */
:target{
  scroll-margin-top: 72px; /* adjust if you have a fixed header */
  outline: 0px solid #e5e7eb;
  outline-offset: .25rem;
}

/* Content width for comfortable reading */
body > :not(#TOC){ max-width: 75ch; }

/* Small screens: stack TOC on top */
@media (max-width: 900px){
  body{ display: block; }
  #TOC{
    position: static;
    max-height: none;
    margin: 0 1rem 1.25rem;
  }
  body > :not(#TOC){
    margin: 0 1rem;
    max-width: 100%;
  }
}

/* Dark mode */
@media (prefers-color-scheme: dark){
  :root{
    --toc-bg: #0b1220;
    --toc-border: #1e293b;
    --toc-text: #e2e8f0;
    --toc-muted: #94a3b8;
    --toc-link: #76a9ff;
    --toc-link-hover: #a4c2ff;
    --shadow: none;
  }
  :target{ outline-color: #334155; }
}

/* Print: inline, simple TOC */
@media print{
  body{ display: block; }
  #TOC{
    position: static;
    max-height: none;
    background: none;
    border: none;
    box-shadow: none;
    padding: 0 0 .5rem 0;
    margin: 0 0 1rem 0;
  }
}
