/* ==========================================================================
   CLUNKY DESIGN SYSTEM
   Table of Contents
   File: /assets/css/components/toc.css

   Sprint 1 canonical version.

   RESPONSIBILITY
   - Article table of contents
   - Sticky desktop TOC
   - Mobile TOC
   - Active section state
   - Accessible navigation

   IMPORTANT
   The TOC must remain inside the normal document flow.
   Do NOT use position: absolute or position: fixed for the TOC itself.
========================================================================== */


/* ==========================================================================
   1. TOC WRAPPER
========================================================================== */

.article-toc {
  width: 100%;

  color: var(
    --color-text-muted,
    #64748b
  );
}


/* ==========================================================================
   2. TOC INNER PANEL
========================================================================== */

.article-toc-inner {
  width: 100%;

  padding: 1rem;

  border: 1px solid var(
    --color-border,
    #e5e7eb
  );

  border-radius: 0.75rem;

  background: var(
    --color-surface,
    #ffffff
  );
}


/* ==========================================================================
   3. TOC TITLE
========================================================================== */

.article-toc-title {
  margin: 0 0 0.75rem;

  color: var(
    --color-heading,
    #111827
  );

  font-size: 0.8125rem;
  font-weight: 800;

  line-height: 1.4;

  letter-spacing: 0.04em;

  text-transform: uppercase;
}


/* ==========================================================================
   4. TOC LIST
========================================================================== */

.article-toc-list {
  display: flex;
  flex-direction: column;

  gap: 0.125rem;

  margin: 0;
  padding: 0;

  list-style: none;
}


/* ==========================================================================
   5. TOC LINK
========================================================================== */

.article-toc-link {
  display: block;

  padding: 0.4rem 0.625rem;

  border-radius: 0.375rem;

  color: var(
    --color-text-muted,
    #64748b
  );

  font-size: 0.875rem;

  line-height: 1.45;

  text-decoration: none;

  transition:
    color 160ms ease,
    background-color 160ms ease;
}


.article-toc-link:hover {
  color: var(
    --color-heading,
    #111827
  );

  background: var(
    --color-surface-subtle,
    #f8fafc
  );
}


.article-toc-link:focus-visible {
  outline: 3px solid var(
    --color-focus,
    #2563eb
  );

  outline-offset: 2px;
}


/* ==========================================================================
   6. ACTIVE TOC LINK
========================================================================== */

.article-toc-link[aria-current="true"] {
  color: var(
    --color-heading,
    #111827
  );

  background: var(
    --color-surface-subtle,
    #f8fafc
  );

  font-weight: 700;
}


/* ==========================================================================
   7. NESTED ITEMS
========================================================================== */

.article-toc-list .toc-level-3 {
  padding-left: 0.75rem;
}


/* ==========================================================================
   8. DESKTOP STICKY BEHAVIOUR
========================================================================== */

/*
   The sidebar provides the full-height containing area.

   The TOC itself becomes sticky.

   This is intentionally NOT position: fixed.
*/

@media (min-width: 1200px) {

    .article-toc {

        position: sticky;

        top: 6rem;

        max-height: calc(
            100vh - 7rem
        );

        overflow-y: auto;

    }

}
/* ==========================================================================
   9. ARTICLE CONTENT ANCHOR OFFSET
==========================================================================

   Prevents headings from hiding behind a future sticky header when the user
   clicks a TOC link.
========================================================================== */

.article-content h2,
.article-content h3 {
  scroll-margin-top: 6rem;
}


/* ==========================================================================
   10. MOBILE TOC
========================================================================== */

@media (max-width: 1199px) {

  .article-toc {
    position: relative;

    top: auto;

    max-height: none;

    overflow: visible;

    margin-bottom: 2rem;
  }


  .article-toc-inner {
    max-height: none;

    overflow: visible;
  }

}


/* ==========================================================================
   11. SMALL MOBILE
========================================================================== */

@media (max-width: 600px) {

  .article-toc {
    margin-bottom: 1.5rem;
  }


  .article-toc-inner {
    padding: 0.875rem;
  }


  .article-toc-link {
    padding: 0.5rem;

    font-size: 0.875rem;
  }

}


/* ==========================================================================
   12. DARK MODE
========================================================================== */

@media (prefers-color-scheme: dark) {

  .article-toc-inner {
    border-color: var(
      --color-border-dark,
      #273449
    );

    background: var(
      --color-surface-dark,
      #0f172a
    );
  }


  .article-toc-title {
    color: var(
      --color-heading-dark,
      #f8fafc
    );
  }


  .article-toc-link {
    color: var(
      --color-text-muted-dark,
      #94a3b8
    );
  }


  .article-toc-link:hover,
  .article-toc-link[aria-current="true"] {
    color: var(
      --color-heading-dark,
      #f8fafc
    );

    background: var(
      --color-surface-subtle-dark,
      #172033
    );
  }

}


/* ==========================================================================
   13. REDUCED MOTION
========================================================================== */

@media (prefers-reduced-motion: reduce) {

  .article-toc-link {
    transition: none;
  }

}