/* ---------------------------------------------------------------------------
   ChunkTrace docs (/docs), on top of styles.css and its tokens.

   Three columns under the site header: the page list on the left and "On this
   page" on the right stay put while the article scrolls. Below 1280px the
   right column goes; below 1024px the page list moves into the header's menu.
   The pages themselves are built by scripts/build-docs.mjs.
   --------------------------------------------------------------------------- */

.docs {
  --doc-header: 3.75rem;
}

/* An anchor's target stops below the sticky header, not under it. */
html:has(.docs) {
  scroll-padding-top: calc(3.75rem + 1.5rem);
}

.docs .mk-frame {
  max-width: 1360px;
}

.docs .mk-header {
  border-bottom-color: rgb(var(--line));
  background: rgb(var(--bg) / 0.84);
}

.docs .mk-nav-link[aria-current] {
  color: rgb(var(--fg));
}

/* ---------------------------------------------------------------------------
   Layout
   --------------------------------------------------------------------------- */
.doc-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  column-gap: 3rem;
  min-height: calc(100vh - var(--doc-header));
}

.doc-sidebar,
.doc-toc {
  position: sticky;
  top: var(--doc-header);
  display: none;
  max-height: calc(100vh - var(--doc-header));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-block: 2.25rem 3rem;
  scrollbar-width: thin;
  scrollbar-color: rgb(var(--line-strong)) transparent;
}

.doc-sidebar {
  align-self: stretch;
  padding-right: 1.5rem;
  border-right: 1px solid rgb(var(--line));
}

.doc-main {
  min-width: 0;
  padding-block: 2.25rem 5rem;
}

@media (min-width: 1024px) {
  .doc-layout {
    grid-template-columns: 14.5rem minmax(0, 1fr);
  }

  .doc-sidebar {
    display: block;
  }

  .doc-main {
    padding-block: 3rem 6rem;
  }
}

@media (min-width: 1280px) {
  .doc-layout {
    grid-template-columns: 14.5rem minmax(0, 1fr) 12.5rem;
  }

  .doc-toc {
    display: block;
    padding-top: 3.25rem;
  }
}

/* ---------------------------------------------------------------------------
   Page list (sidebar, and the same list inside the mobile menu)
   --------------------------------------------------------------------------- */
.doc-nav ul,
.doc-toc ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.doc-nav-group + .doc-nav-group {
  margin-top: 1.6rem;
}

.doc-nav-title {
  margin: 0 0 0.5rem;
  padding-inline: 0.75rem;
  color: rgb(var(--fg));
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.doc-nav-link {
  display: flex;
  min-height: 2rem;
  align-items: center;
  padding: 0.3rem 0.75rem;
  border-radius: 7px;
  color: rgb(var(--muted));
  font-size: 0.875rem;
  line-height: 1.35;
  text-decoration: none;
  transition:
    background-color 150ms ease,
    color 150ms ease;
}

.doc-nav-link[aria-current="page"] {
  background: rgb(var(--accent) / 0.12);
  color: rgb(var(--accent-hover));
  font-weight: 500;
}

.doc-nav-link:focus-visible,
.doc-toc-link:focus-visible {
  outline: 2px solid rgb(var(--accent));
  outline-offset: 1px;
}

.doc-nav-mobile {
  max-height: calc(100vh - var(--doc-header));
  max-height: calc(100dvh - var(--doc-header));
  overflow-y: auto;
  padding-block: 1.1rem 1.75rem;
}

.doc-nav-mobile .doc-nav-link {
  min-height: 2.5rem;
  font-size: 0.95rem;
}

/* ---------------------------------------------------------------------------
   On this page
   --------------------------------------------------------------------------- */
.doc-toc .doc-nav-title {
  padding-inline: 0.85rem;
}

.doc-toc ul {
  border-left: 1px solid rgb(var(--line));
}

.doc-toc-link {
  display: block;
  margin-left: -1px;
  padding: 0.28rem 0.85rem;
  border-left: 1px solid transparent;
  color: rgb(var(--muted));
  font-size: 0.8rem;
  line-height: 1.4;
  text-decoration: none;
  transition:
    border-color 150ms ease,
    color 150ms ease;
}

.doc-toc-link.is-sub {
  padding-left: 1.6rem;
}

.doc-toc-link.is-active {
  border-left-color: rgb(var(--accent));
  color: rgb(var(--fg));
}

.doc-toc-link code {
  font-size: 0.92em;
}

@media (hover: hover) and (pointer: fine) {
  .doc-nav-link:not([aria-current="page"]):hover {
    background: rgb(var(--fg) / 0.05);
    color: rgb(var(--fg));
  }

  .doc-toc-link:hover {
    color: rgb(var(--fg));
  }
}

/* ---------------------------------------------------------------------------
   Article
   --------------------------------------------------------------------------- */
.doc-article {
  max-width: 46rem;
  color: rgb(var(--ink-soft));
  font-size: 0.97rem;
  line-height: 1.72;
}

.doc-crumb {
  margin: 0 0 0.6rem;
  color: rgb(var(--accent));
  font-size: 0.8rem;
  font-weight: 500;
}

.doc-article h1 {
  margin: 0;
  color: rgb(var(--fg));
  font-size: clamp(1.9rem, 4vw, 2.4rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.12;
  text-wrap: balance;
}

.doc-lede {
  margin: 0.9rem 0 0;
  color: rgb(var(--muted));
  font-size: 1.08rem;
  line-height: 1.6;
  text-wrap: pretty;
}

.doc-article h2 {
  margin: 3rem 0 0;
  padding-top: 2rem;
  border-top: 1px solid rgb(var(--line));
  color: rgb(var(--fg));
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.doc-lede + h2 {
  margin-top: 2.25rem;
}

.doc-article h3 {
  margin: 2.1rem 0 0;
  color: rgb(var(--fg));
  font-size: 1.06rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.35;
}

.doc-article h2 code,
.doc-article h3 code {
  font-size: 0.9em;
}

/* The "#" that links to a heading: shown on hover or focus, always reachable by keyboard. */
.doc-anchor {
  margin-left: 0.45rem;
  color: rgb(var(--muted));
  font-weight: 400;
  text-decoration: none;
  opacity: 0;
  transition: opacity 120ms ease;
}

.doc-article :is(h2, h3):hover .doc-anchor,
.doc-anchor:focus-visible {
  opacity: 1;
}

.doc-article p,
.doc-article ul,
.doc-article ol {
  margin: 1.05rem 0 0;
}

.doc-article ul,
.doc-article ol {
  padding-left: 1.3rem;
}

.doc-article li + li {
  margin-top: 0.4rem;
}

.doc-article li::marker {
  color: rgb(var(--muted));
}

.doc-article strong {
  color: rgb(var(--fg));
  font-weight: 600;
}

.doc-article a:not(.doc-anchor) {
  color: rgb(var(--accent-hover));
  text-decoration: underline;
  text-decoration-color: rgb(var(--accent) / 0.45);
  text-underline-offset: 0.2em;
}

.doc-article a:focus-visible {
  border-radius: 3px;
  outline: 2px solid rgb(var(--accent));
  outline-offset: 2px;
}

.doc-article :not(pre) > code {
  padding: 0.12em 0.38em;
  border-radius: 5px;
  background: rgb(var(--fg) / 0.07);
  color: rgb(var(--fg));
  font-size: 0.85em;
  overflow-wrap: anywhere;
}

/* ---------- code ---------- */
.doc-code {
  margin: 1.4rem 0 0;
  overflow: hidden;
  border: 1px solid rgb(var(--line-strong));
  border-radius: var(--radius);
  background: rgb(var(--surface));
}

.doc-code-bar {
  display: flex;
  height: 2.25rem;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0 0.5rem 0 1rem;
  border-bottom: 1px solid rgb(var(--line));
  background: rgb(var(--surface-2) / 0.6);
}

.doc-code-title {
  color: rgb(var(--muted));
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

.doc-copy {
  height: 1.6rem;
  padding-inline: 0.6rem;
  border: 1px solid rgb(var(--line-strong));
  border-radius: 6px;
  color: rgb(var(--muted));
  font-size: 0.72rem;
  font-weight: 500;
  transition:
    border-color 150ms ease,
    color 150ms ease;
}

.doc-copy:focus-visible,
.doc-code pre:focus-visible {
  outline: 2px solid rgb(var(--accent));
  outline-offset: -2px;
}

.doc-copy.is-copied {
  border-color: rgb(var(--ok) / 0.5);
  color: rgb(var(--ok));
}

.doc-code pre {
  margin: 0;
  padding: 1rem 1.1rem;
  color: rgb(var(--ink-soft));
  font-size: 0.8rem;
  line-height: 1.7;
  overflow-x: auto;
  tab-size: 2;
}

.doc-code .c {
  color: rgb(var(--accent));
}

.doc-code .s {
  color: rgb(var(--ok));
}

.doc-code .n {
  color: rgb(var(--warn));
}

.doc-code .cm {
  color: rgb(var(--muted));
}

.doc-code .k {
  color: rgb(var(--fg));
}

@media (hover: hover) and (pointer: fine) {
  .doc-copy:hover {
    border-color: rgb(var(--fg) / 0.3);
    color: rgb(var(--fg));
  }
}

/* ---------- notes, pictures, tables ---------- */
.doc-note {
  margin: 1.4rem 0 0;
  padding: 0.85rem 1.1rem;
  border: 1px solid rgb(var(--accent) / 0.25);
  border-left: 3px solid rgb(var(--accent));
  border-radius: var(--radius-sm);
  background: rgb(var(--accent) / 0.06);
  font-size: 0.93rem;
}

.doc-note > :first-child {
  margin-top: 0;
}

.doc-shot {
  margin: 1.6rem 0 0;
}

/* The pictures are cut out of the dashboard, edge to edge; the frame gives them its
   background (the dashboard's own dark one) as a margin. */
.doc-shot a {
  display: block;
  overflow: hidden;
  padding: clamp(0.75rem, 2.5vw, 1.25rem);
  border: 1px solid rgb(var(--line-strong));
  border-radius: var(--radius);
  background: rgb(11 13 19);
  box-shadow: var(--shadow-panel);
}

.doc-shot img {
  width: 100%;
  height: auto;
}

.doc-shot figcaption {
  margin-top: 0.6rem;
  color: rgb(var(--muted));
  font-size: 0.82rem;
  line-height: 1.5;
}

.doc-table {
  margin: 1.4rem 0 0;
  overflow-x: auto;
  border: 1px solid rgb(var(--line));
  border-radius: var(--radius);
}

/* Wide enough to read: on a phone the table scrolls sideways inside its frame. */
.doc-table table {
  width: 100%;
  min-width: 32rem;
  border-collapse: collapse;
  font-size: 0.875rem;
  line-height: 1.55;
}

.doc-table th,
.doc-table td {
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid rgb(var(--line));
  text-align: left;
  vertical-align: top;
}

.doc-table th {
  background: rgb(var(--surface));
  color: rgb(var(--fg));
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.doc-table tr:last-child td {
  border-bottom: 0;
}

.doc-table td:first-child code {
  white-space: nowrap;
  overflow-wrap: normal;
}

/* ---------- previous / next ---------- */
.doc-pager {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  max-width: 46rem;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid rgb(var(--line));
}

.doc-pager-link {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.8rem 1rem;
  border: 1px solid rgb(var(--line));
  border-radius: var(--radius);
  color: rgb(var(--fg));
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  transition:
    background-color 150ms ease,
    border-color 150ms ease;
}

.doc-pager-link span {
  color: rgb(var(--muted));
  font-size: 0.76rem;
  font-weight: 400;
}

.doc-pager-next {
  grid-column: 2;
  align-items: flex-end;
  text-align: right;
}

.doc-pager-link:focus-visible {
  outline: 2px solid rgb(var(--accent));
  outline-offset: 2px;
}

@media (hover: hover) and (pointer: fine) {
  .doc-pager-link:hover {
    border-color: rgb(var(--line-strong));
    background: rgb(var(--fg) / 0.04);
  }
}

@media (max-width: 480px) {
  .doc-pager {
    grid-template-columns: minmax(0, 1fr);
  }

  .doc-pager-next {
    grid-column: 1;
  }
}
