/* The docs pages (/docs/). Loaded after cf.css, which owns the tokens, the
   masthead, the footer, tables, .code and .eyebrow; everything here is
   composed from those tokens. Nothing on the rest of the site uses this file.
   The pages are rendered by tools/docs.js. */

/* ------------------------------------------------------------ the index */

.docs-hero { padding-top: 88px; padding-bottom: 56px; animation: cf-up .6s ease both; }
.docs-hero__note { margin-top: 18px; max-width: 720px; }
/* Rules drawn per link, so a wrapped row leaves ground, not a painted block. */
.docs-jump { display: flex; flex-wrap: wrap; margin-top: 32px; border-top: 1px solid var(--rule); border-left: 1px solid var(--rule); width: fit-content; max-width: 100%; }
.docs-jump a {
  font-family: var(--mono); font-size: 12px; letter-spacing: .04em;
  color: var(--body); padding: 10px 14px;
  border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
}
.docs-jump a:hover { color: var(--ink); background: var(--panel); text-decoration: none; }

.doc-group__blurb { font-size: 18px; line-height: 1.5; color: var(--ink); margin: 0 0 28px; max-width: 720px; }

/* Hairline grid of cards. Each card draws its own right and bottom rule, so a
   group that does not fill its last row leaves empty ground rather than the
   painted block a gap-based .grid-rule would show there. */
.doc-cards {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  border-top: 1px solid var(--rule); border-left: 1px solid var(--rule);
}
.doc-cards > li { display: flex; border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.doc-card {
  display: flex; flex-direction: column; gap: 10px; width: 100%;
  padding: 24px 22px; color: var(--body); transition: background .15s;
}
.doc-card:hover { background: var(--panel); text-decoration: none; color: var(--body); }
.doc-card__t { font-size: 19px; font-weight: 600; line-height: 1.25; letter-spacing: -.01em; color: var(--ink); }
.doc-card:hover .doc-card__t { color: var(--accent-hi); }
.doc-card__d { font-size: 14px; line-height: 1.55; flex: 1; }
.doc-card__m { font-family: var(--mono); font-size: 11px; color: var(--dim); overflow-wrap: anywhere; }

.doc-group__more { margin: 28px 0 0; font-size: 15px; }
.docs-mirror { max-width: 720px; }
.docs-mirror td.k { width: 140px; }
.docs-mirror__note { margin-top: 14px; }

/* ------------------------------------------------------- the page layout */

.docs {
  display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 64px;
  align-items: start; padding-top: 48px; padding-bottom: 72px;
}

/* The docs menu: groups in reading order, the current page's sections under it. */
.side {
  position: sticky; top: 84px;
  max-height: calc(100vh - 104px); overflow-y: auto; overscroll-behavior: contain;
  padding-right: 8px; scrollbar-width: thin; scrollbar-color: var(--edge) transparent;
}
.side__group {
  font-family: var(--mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted); margin: 26px 0 8px;
}
.side__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.side__list a {
  display: block; padding: 6px 10px; font-size: 14px; line-height: 1.35;
  color: var(--body); border-left: 1px solid var(--rule);
}
.side__list a:hover { color: var(--ink); border-left-color: var(--edge-hi); text-decoration: none; }
.side__list a[aria-current="page"] { color: var(--ink); border-left-color: var(--accent); background: var(--panel); }
.side__toc { list-style: none; margin: 4px 0 8px 10px; padding: 0; display: grid; gap: 1px; }
.side__toc a { font-size: 12.5px; color: var(--muted); padding: 4px 10px; }
.side__l3 a { padding-left: 22px; color: var(--dim); }
.side__more summary {
  cursor: pointer; padding: 6px 10px; font-family: var(--mono); font-size: 12px;
  color: var(--muted); border-left: 1px solid var(--rule); list-style: none;
}
.side__more summary::-webkit-details-marker { display: none; }
.side__more summary::before { content: "+ "; color: var(--accent); }
.side__more[open] summary::before { content: "\2212 "; }
.side__more summary:hover { color: var(--ink); }
.side__more .side__list { margin-left: 10px; }
.side__more .side__list a { font-size: 13px; }

.side-mobile { display: none; }

/* --------------------------------------------------------------- the doc */

/* Long-form: a measure, not the full shell width. */
.doc { min-width: 0; max-width: 80ch; }
.doc :where(p, ul, ol, blockquote, figure) { margin: 0; }
.doc > * + * { margin-top: 18px; }
.doc :is(h2, h3, h4, h5, h6) + * { margin-top: 12px; }
.doc__crumbs { margin-bottom: 18px; }
.doc__crumbs a { color: var(--accent); text-decoration: none; }
.doc__crumbs span[aria-hidden] { color: var(--dim); }

.doc h1 { font-size: clamp(32px, 4.2vw, 52px); line-height: 1.05; letter-spacing: -.03em; font-weight: 700; margin: 0 0 8px; }
.doc h2 {
  font-size: clamp(24px, 2.6vw, 30px); line-height: 1.15; letter-spacing: -.02em; font-weight: 600;
  margin: 56px 0 0; padding-top: 24px; border-top: 1px solid var(--rule);
}
.doc h3 { font-size: 20px; line-height: 1.3; letter-spacing: -.01em; font-weight: 600; margin: 36px 0 0; }
.doc h4, .doc h5, .doc h6 { font-size: 16px; font-weight: 600; margin: 28px 0 0; color: var(--ink); }
.doc :is(h1, h2, h3, h4, h5, h6) { position: relative; scroll-margin-top: 88px; overflow-wrap: anywhere; }

.anchor {
  position: absolute; left: -22px; top: auto;
  font-family: var(--mono); font-weight: 400; color: var(--dim); opacity: 0; transition: opacity .12s;
}
.anchor:hover { text-decoration: none; color: var(--accent); }
.doc :is(h2, h3, h4):hover .anchor, .anchor:focus { opacity: 1; }

.doc p, .doc li { font-size: 16px; line-height: 1.65; color: var(--body); text-wrap: pretty; }
.doc a { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; text-decoration-color: rgba(76, 111, 255, .45); }
.doc a:hover { text-decoration-color: currentColor; }
.doc h1 a, .doc h2 a, .doc h3 a, .doc h4 a, .doc .anchor { text-decoration: none; }
.doc p code, .doc li code, .doc td code, .doc th code, .doc blockquote code { overflow-wrap: anywhere; }

.doc ul, .doc ol { padding-left: 22px; display: grid; gap: 8px; }
.doc li::marker { color: var(--accent); font-family: var(--mono); font-size: 13px; }
.doc ul > li::marker { content: "\25A0  "; font-size: 9px; }

.doc blockquote {
  margin-left: 0; margin-right: 0; padding: 16px 20px;
  background: var(--panel); border: 1px solid var(--edge); border-left: 2px solid var(--accent);
}
.doc blockquote > * + * { margin-top: 12px; }
.doc blockquote p { color: var(--code); }

.doc hr { border: 0; border-top: 1px solid var(--rule); margin: 40px 0; }

.doc .code { margin-top: 20px; margin-bottom: 4px; }
.doc .code pre { white-space: pre; }
.doc .code code { font-size: inherit; color: inherit; }
.doc .code__path { text-transform: uppercase; }

.doc .table-wrap { margin-top: 20px; }
.doc table { font-size: 14px; }
.doc thead tr { color: var(--accent); }
.doc th { white-space: nowrap; text-align: left; }
.doc td { color: var(--body); }
.doc td code { white-space: nowrap; }

.diagram {
  margin: 24px 0 0; padding: 22px 18px;
  background: var(--panel); border: 1px solid var(--edge); overflow-x: auto;
}
/* docs.js strips the pixel width and keeps mermaid's max-width, so a diagram
   shrinks with the column and never grows past its drawn size. The labels
   keep the font the diagram was laid out in: another one would overflow. */
.diagram svg.mermaid { display: block; width: 100%; height: auto; margin: 0 auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.doc__source {
  margin-top: 56px !important; padding-top: 20px; border-top: 1px solid var(--rule);
  font-family: var(--mono); font-size: 12px !important; line-height: 1.6; color: var(--muted) !important;
}
.doc__source a { color: var(--muted); }

/* Previous / next, under each document. */
.pager {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin-top: 24px !important;
  background: var(--rule); border: 1px solid var(--rule);
}
.pager > * { background: var(--ground); }
.pager a { display: grid; gap: 4px; padding: 16px 18px; transition: background .15s; text-decoration: none !important; }
.pager a:hover { background: var(--panel); }
.pager__next { text-align: right; grid-column: 2; }
.pager__label { font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.pager__title { font-size: 16px; font-weight: 600; color: var(--ink); }

/* ------------------------------------------------------------------ narrow */

@media (max-width: 960px) {
  .docs { grid-template-columns: minmax(0, 1fr); gap: 24px; padding-top: 24px; }
  .side { display: none; }
  .side-mobile {
    display: block; position: sticky; top: 70px; z-index: 5;
    background: var(--ground); border: 1px solid var(--edge);
  }
  .side-mobile summary {
    list-style: none; cursor: pointer; padding: 12px 14px;
    display: flex; align-items: baseline; gap: 12px; min-width: 0;
  }
  .side-mobile summary::-webkit-details-marker { display: none; }
  .side-mobile summary::after { content: "+"; margin-left: auto; font-family: var(--mono); color: var(--accent); }
  .side-mobile[open] summary::after { content: "\2212"; }
  .side-mobile__label { font-family: var(--mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); flex: none; }
  .side-mobile__current { font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  .side-mobile nav { padding: 0 14px 14px; max-height: 65vh; overflow-y: auto; border-top: 1px solid var(--rule); }
  .side-mobile .side__group:first-child { margin-top: 14px; }
  .anchor { display: none; }
  .docs-hero { padding-top: 56px; padding-bottom: 40px; }
}

@media (max-width: 560px) {
  .pager { grid-template-columns: 1fr; }
  .pager__next { grid-column: 1; }
  .doc td code { white-space: normal; }
}

/* Mermaid draws its labels as HTML inside the SVG, laid out in the diagram's
   own font and size. The article's paragraph styles must not reach them, or a
   label grows past the box it was measured for and is clipped. */
.doc .diagram :is(p, span, div) {
  font-size: inherit; line-height: inherit; color: inherit;
  margin: 0; text-wrap: wrap;
}
