/* Revue's documentation pages (/docs, server/src/site/docs.rs), on top of
   style.css: its colours, radii and fonts come from style.css's custom
   properties, so a restyle there carries over here. */

.docs {
  --docs-side: 15.5rem;
  --docs-toc: 13.5rem;
  --docs-text: 72ch;
  --docs-sticky: calc(var(--header-h, 64px) + 16px);
  --docs-mono: var(--font-mono, ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", monospace);
  padding: 1.5rem 0 3rem;
}

.docs .wrap.docs-grid {
  max-width: 92rem;
  display: grid;
  gap: 2rem;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

@media (min-width: 60rem) {
  .docs .wrap.docs-grid {
    grid-template-columns: var(--docs-side) minmax(0, 1fr);
    gap: 2.5rem;
  }
}

@media (min-width: 90rem) {
  .docs .wrap.docs-grid.has-toc {
    grid-template-columns: var(--docs-side) minmax(0, 1fr) var(--docs-toc);
  }
}

/* The page list: a sticky sidebar on wide screens, a menu on narrow ones. */

.docs-side {
  display: none;
}

@media (min-width: 60rem) {
  .docs-side {
    display: block;
    position: sticky;
    top: var(--docs-sticky);
    max-height: calc(100vh - var(--docs-sticky) - 16px);
    overflow-y: auto;
    padding-right: 4px;
    scrollbar-width: thin;
  }

  .docs-menu {
    display: none;
  }
}

.docs-group + .docs-group {
  margin-top: 1.25rem;
}

.docs-group-name {
  margin: 0 0 0.35rem;
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.docs-group ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--line);
}

.docs-group a {
  display: block;
  margin-left: -1px;
  padding: 0.28rem 0.75rem;
  border-left: 2px solid transparent;
  color: var(--fg);
  text-decoration: none;
  font-size: 0.93rem;
  line-height: 1.4;
}

.docs-group a:hover {
  color: var(--accent);
}

.docs-group a[aria-current="page"] {
  color: var(--accent);
  font-weight: 600;
  border-left-color: var(--accent);
  background: linear-gradient(90deg, var(--accent-soft), transparent);
}

.docs-menu {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}

.docs-menu > summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 1rem;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}

.docs-menu > summary::-webkit-details-marker {
  display: none;
}

.docs-menu > summary::after {
  content: "";
  margin-left: auto;
  width: 0.55em;
  height: 0.55em;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  flex: none;
}

.docs-menu[open] > summary::after {
  transform: rotate(-135deg);
}

.docs-menu-here {
  font-weight: 400;
  color: var(--muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.docs-menu-here::before {
  content: "·";
  margin-right: 0.5rem;
}

.docs-menu > nav {
  padding: 0.25rem 1rem 1rem;
  border-top: 1px solid var(--line);
  padding-top: 1rem;
}

/* "On this page" */

.docs-toc {
  display: none;
}

@media (min-width: 90rem) {
  .docs-toc {
    display: block;
    position: sticky;
    top: var(--docs-sticky);
    max-height: calc(100vh - var(--docs-sticky) - 16px);
    overflow-y: auto;
    font-size: 0.87rem;
    scrollbar-width: thin;
  }
}

.docs-toc p {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.docs-toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.docs-toc li {
  margin: 0;
}

.docs-toc a {
  display: block;
  padding: 0.2rem 0;
  color: var(--muted);
  text-decoration: none;
  line-height: 1.35;
}

.docs-toc a:hover {
  color: var(--accent);
}

.docs-toc .toc-3 a {
  padding-left: 0.9rem;
  font-size: 0.84rem;
}

/* The article */

.doc {
  min-width: 0;
  max-width: 62rem;
}

/* Text at a comfortable width; tables, code and folded detail may use the
   whole column. */
.crumbs,
.doc-head,
.doc-foot,
.doc-body > :is(p, ul, ol, h2, h3, h4, blockquote, hr, .callout) {
  max-width: var(--docs-text);
}

.crumbs ol {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.5rem;
  margin: 0 0 1rem;
  padding: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.crumbs li + li::before {
  content: "/";
  margin-right: 0.5rem;
  opacity: 0.6;
}

.crumbs a {
  color: var(--muted);
  text-decoration: none;
}

.crumbs a:hover {
  color: var(--accent);
}

.crumbs [aria-current] {
  color: var(--fg);
}

.doc-head {
  padding-bottom: 1.25rem;
  margin-bottom: 1.75rem;
  border-bottom: 1px solid var(--line);
}

.doc-head h1 {
  font-size: clamp(1.9rem, 4vw, 2.6rem);
  margin-bottom: 0.4em;
}

.doc-summary {
  font-size: 1.12rem;
  color: var(--muted);
  margin: 0;
}

.doc-body {
  line-height: 1.7;
}

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

.doc-body h2,
.doc-body h3,
.doc-body h4 {
  position: relative;
  scroll-margin-top: var(--docs-sticky);
}

.doc-body h2 {
  font-size: 1.55rem;
  margin: 2.6rem 0 0.8rem;
  padding-top: 0.2rem;
}

.doc-body h3 {
  font-size: 1.17rem;
  margin: 1.9rem 0 0.6rem;
}

.doc-body h4 {
  font-size: 1rem;
  margin: 1.5rem 0 0.5rem;
}

.doc-body .anchor {
  margin-left: 0.4rem;
  color: var(--muted);
  text-decoration: none;
  font-weight: 400;
  opacity: 0;
}

.doc-body h2:hover .anchor,
.doc-body h3:hover .anchor,
.doc-body h4:hover .anchor,
.doc-body .anchor:focus-visible {
  opacity: 1;
}

.doc-body .anchor:hover {
  color: var(--accent);
}

@media (hover: none) {
  .doc-body .anchor {
    opacity: 0.45;
  }
}

.doc-body ul,
.doc-body ol {
  padding-left: 1.4rem;
  margin: 0 0 1.1rem;
}

.doc-body li {
  margin: 0.25rem 0;
}

.doc-body li > p {
  margin: 0 0 0.4rem;
}

.doc-body ul > li::marker {
  color: var(--accent);
}

.doc-body hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 2rem 0;
}

.doc-body blockquote {
  margin: 0 0 1.1rem;
  padding: 0.2rem 1rem;
  border-left: 3px solid var(--line);
  color: var(--muted);
}

/* Numbered lists are steps. */

.doc-body ol {
  list-style: none;
  counter-reset: step;
  padding-left: 0;
}

.doc-body ol > li {
  counter-increment: step;
  position: relative;
  padding-left: 2.4rem;
  margin: 0.55rem 0;
  min-height: 1.7rem;
}

.doc-body ol > li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0.05rem;
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}

.doc-body ol > li:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 0.8rem;
  top: 1.85rem;
  bottom: -0.55rem;
  width: 1px;
  background: var(--line);
}

/* Code, keys */

.doc-body code {
  font-family: var(--docs-mono);
}

.doc-body pre {
  margin: 0 0 1.2rem;
  padding: 0.9rem 1.1rem;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
  line-height: 1.5;
  font-size: 0.88rem;
}

.doc-body pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
  overflow-wrap: normal;
  white-space: pre;
}

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0.05em 0.42em;
  font: 600 0.8em/1.45 var(--docs-mono, ui-monospace, monospace);
  text-align: center;
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  white-space: nowrap;
  vertical-align: 0.08em;
}

/* Tables: their own scroll box on small screens. */

.table-wrap {
  overflow-x: auto;
  margin: 0 0 1.3rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}

.table-wrap table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.92rem;
  line-height: 1.5;
}

.table-wrap th,
.table-wrap td {
  text-align: left;
  vertical-align: top;
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid var(--line);
}

.table-wrap th {
  background: var(--bg-soft);
  font-weight: 650;
  white-space: nowrap;
}

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

.table-wrap tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--bg-soft) 60%, transparent);
}

.table-wrap td:first-child {
  min-width: 9rem;
}

/* Names in tables break only when they can't fit, not anywhere. */
.table-wrap code {
  overflow-wrap: break-word;
}

/* Callouts: > [!NOTE], [!TIP], [!IMPORTANT], [!WARNING] */

.callout {
  --c: var(--accent);
  margin: 0 0 1.2rem;
  padding: 0.8rem 1.1rem;
  border: 1px solid color-mix(in srgb, var(--c) 35%, var(--line));
  border-left: 4px solid var(--c);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--c) 8%, var(--card));
}

.callout.tip {
  --c: #1a9f5a;
}

.callout.warning {
  --c: #d4880f;
}

.callout.important {
  --c: #c2417a;
}

.callout-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0 0 0.3rem;
  font-weight: 650;
  color: var(--c);
}

.callout-title svg {
  fill: currentColor;
  flex: none;
}

.callout > :last-child {
  margin-bottom: 0;
}

/* Folded detail: <details><summary>Advanced</summary> … */

.doc-body details {
  margin: 0 0 1.2rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-soft);
}

.doc-body details > summary {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 1rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--fg);
  list-style: none;
  border-radius: var(--radius);
}

.doc-body details > summary::-webkit-details-marker {
  display: none;
}

.doc-body details > summary::before {
  content: "";
  width: 0.45em;
  height: 0.45em;
  border-right: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  transform: rotate(-45deg);
  flex: none;
}

.doc-body details[open] > summary::before {
  transform: rotate(45deg);
}

.doc-body details > summary:hover {
  color: var(--accent);
}

.doc-body details > summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.doc-body details[open] > summary {
  border-bottom: 1px solid var(--line);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.doc-body details > :not(summary) {
  margin-left: 1rem;
  margin-right: 1rem;
}

.doc-body details > summary + * {
  margin-top: 0.9rem;
}

.doc-body details > :last-child {
  margin-bottom: 1rem;
}

.doc-body details .table-wrap,
.doc-body details pre {
  background: var(--card);
}

/* Footer: source link, previous / next */

.doc-foot {
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}

.doc-source {
  font-size: 0.88rem;
  color: var(--muted);
}

.pager {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
  margin-top: 1rem;
}

.pager a {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.85rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  text-decoration: none;
  min-width: 0;
}

.pager a:hover {
  border-color: var(--accent);
}

.pager-next {
  text-align: right;
  grid-column: -2;
}

.pager-dir {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.pager-prev .pager-dir::before {
  content: "← ";
}

.pager-next .pager-dir::after {
  content: " →";
}

.pager-title {
  font-weight: 600;
  color: var(--fg);
}

.pager a:hover .pager-title {
  color: var(--accent);
}

@media (prefers-reduced-motion: no-preference) {
  .docs-menu > summary::after,
  .doc-body details > summary::before {
    transition: transform 0.15s ease;
  }

  .doc-body .anchor,
  .docs-group a,
  .pager a {
    transition: opacity 0.15s, color 0.15s, border-color 0.15s;
  }

  html:has(.docs) {
    scroll-behavior: smooth;
  }
}
