/* ============================================================
   Chaty docs — layout + markdown rendering.
   Sits on top of styles.css and reuses its theme tokens, so the
   docs inherit dark/light and the site's typography wholesale.
   ============================================================ */

.docs-body { background: var(--bg); }

/* ---------- Shell: sticky sidebar + content column ---------- */
.docs-shell {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 108px 24px 80px;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  gap: 48px;
  align-items: start;
}

.docs-side {
  position: sticky;
  top: 96px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  padding-right: 8px;
  scrollbar-width: thin;
}

.docs-side-head {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 4px 0 12px 12px;
}

.docs-toc a {
  display: block;
  padding: 7px 12px;
  border-radius: 9px;
  font-size: 15.5px;
  color: var(--text-dim);
  border-left: 2px solid transparent;
  transition: color 0.15s var(--ease), background 0.15s var(--ease);
}
.docs-toc a:hover { color: var(--text); background: var(--surface); }
.docs-toc a.active {
  color: var(--accent);
  background: var(--glow);
  font-weight: 600;
}
.docs-toc .toc-sub { margin: 2px 0 6px; }
.docs-toc .toc-sub a {
  font-size: 14px;
  padding: 4.5px 12px 4.5px 24px;
  color: var(--text-faint);
}
.docs-toc .toc-sub a:hover { color: var(--text-dim); background: none; }
.docs-toc .toc-sub a.active { color: var(--accent); background: none; }

/* Sidebar search */
.docs-search-wrap {
  position: relative;
  margin: 2px 2px 16px;
}
.docs-search-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
}
.docs-search {
  width: 100%;
  font: inherit;
  font-size: 14.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 10px;
  padding: 9px 12px 9px 34px;
  outline: none;
  transition: border-color 0.15s;
}
.docs-search::placeholder { color: var(--text-faint); }
.docs-search:focus { border-color: var(--accent); }
.docs-search::-webkit-search-cancel-button { -webkit-appearance: none; }

.docs-search-results { margin: 0 2px 16px; }
.docs-search-results a {
  display: block;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  background: var(--surface);
  transition: border-color 0.15s;
}
.docs-search-results a:hover { border-color: var(--accent); }
.docs-search-results .sr-sec {
  display: block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 2px;
}
.docs-search-results .sr-head {
  display: block;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
}
.docs-search-results .sr-snip {
  display: block;
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
  margin-top: 3px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.docs-search-results mark {
  background: var(--glow);
  color: var(--accent);
  border-radius: 3px;
  padding: 0 1px;
}
.docs-search-empty {
  color: var(--text-faint);
  font-size: 13.5px;
  padding: 8px 12px;
}

.docs-toc-toggle { display: none; }

.docs-loading {
  color: var(--text-faint);
  font-size: 15px;
  padding: 40px 0;
}

/* ---------- Markdown body ---------- */
.docs-main { min-width: 0; }

.md { font-size: 16.5px; line-height: 1.72; }

.md section { padding-bottom: 10px; }

.md h1 {
  font-family: var(--font-display);
  font-size: clamp(30px, 4vw, 38px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 8px 0 10px;
}

.md h2 {
  font-family: var(--font-display);
  font-size: 23px;
  font-weight: 650;
  letter-spacing: -0.015em;
  margin: 40px 0 10px;
  padding-top: 6px;
}
.md h3 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 650;
  margin: 28px 0 8px;
}
.md h4 { font-size: 16px; margin: 22px 0 6px; }

.md p { margin: 0 0 14px; color: var(--text); }
.md section > p:first-of-type { color: var(--text-dim); font-size: 17.5px; }

.md a { color: var(--accent); }
.md a:hover { text-decoration: underline; text-underline-offset: 3px; }

.md ul, .md ol { margin: 0 0 16px; padding-left: 24px; }
.md li { margin-bottom: 6px; }
.md li::marker { color: var(--text-faint); }

.md strong { font-weight: 650; }
.md em { color: inherit; font-style: italic; }

.md hr { border: none; border-top: 1px solid var(--border); margin: 28px 0; }

/* Inline code */
.md code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.12em 0.42em;
  white-space: nowrap;
}

/* Code blocks */
.md pre {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  margin: 6px 0 18px;
  overflow-x: auto;
  box-shadow: 0 8px 26px -18px var(--shadow);
}
.md pre code {
  background: none;
  border: none;
  padding: 0;
  white-space: pre;
  font-size: 13.5px;
  line-height: 1.62;
  color: var(--text);
}
.md pre .code-lang {
  position: absolute;
  top: 8px;
  right: 44px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  user-select: none;
}
.md pre .code-copy {
  position: absolute;
  top: 6px;
  right: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  border-radius: 7px;
  width: 28px;
  height: 26px;
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, border-color 0.15s;
}
.md pre:hover .code-copy { opacity: 1; }
.md pre .code-copy:hover { color: var(--accent); border-color: var(--accent); }
.md pre .code-copy.ok { color: var(--accent); border-color: var(--accent); opacity: 1; }

/* Callouts — blockquotes are rendered as note boxes */
.md blockquote {
  margin: 0 0 18px;
  padding: 13px 18px;
  background: var(--glow);
  border: 1px solid color-mix(in srgb, var(--accent) 26%, transparent);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
}
.md blockquote p { margin: 0; color: var(--text); font-size: 15.5px; }
.md blockquote p + p { margin-top: 8px; }

/* Tables */
.md .table-wrap { overflow-x: auto; margin: 6px 0 18px; }
.md table {
  border-collapse: collapse;
  width: 100%;
  font-size: 14.5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.md th, .md td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.md th {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: var(--surface-2);
}
.md tr:last-child td { border-bottom: none; }
.md td code { white-space: nowrap; }

/* Screenshots */
.md img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  box-shadow: 0 18px 48px -24px var(--shadow);
  display: block;
  margin: 6px 0 6px;
}
.md figure { margin: 20px 0 22px; }
.md figcaption {
  font-size: 13.5px;
  color: var(--text-faint);
  margin-top: 10px;
  text-align: center;
}

/* Keyboard keys */
.md kbd {
  font-family: var(--font-mono);
  font-size: 0.82em;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 0.1em 0.45em;
}

/* Prev / next footer nav */
.docs-endnav {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-top: 44px;
}
.docs-endnav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  font-size: 14.5px;
  color: var(--text-dim);
  transition: border-color 0.15s, transform 0.15s var(--ease);
}
.docs-endnav a:hover { border-color: var(--accent); color: var(--text); transform: translateY(-2px); }
.docs-endnav a b { display: block; color: var(--text); font-size: 15.5px; margin-top: 2px; }
.docs-endnav .docs-endnav-next { text-align: right; }
.docs-endnav a[hidden] { visibility: hidden; }

.docs-footer { margin-top: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 920px) {
  .docs-shell {
    grid-template-columns: 1fr;
    padding-top: 92px;
    gap: 12px;
  }
  .docs-toc-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    align-self: start;
    border: 1px solid var(--border-2);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    border-radius: 10px;
    padding: 9px 14px;
    cursor: pointer;
  }
  .docs-toc-toggle svg { transition: transform 0.2s var(--ease); }
  .docs-toc-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
  .docs-side {
    display: none;
    position: static;
    max-height: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    padding: 14px 10px;
  }
  .docs-side.open { display: block; }
  .docs-toc a { padding: 10px 12px; font-size: 16px; }
  .docs-toc .toc-sub a { padding: 7px 12px 7px 24px; font-size: 14.5px; }
  .md { font-size: 16px; }
  .md h1 { font-size: 28px; }
  .md h2 { font-size: 21px; }
  .md pre { padding: 13px 14px; }
  .md pre .code-copy { opacity: 1; }
  /* long inline code (paths, commands) must wrap on narrow screens */
  .md p code, .md li code, .md blockquote code {
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .docs-endnav { flex-direction: column; }
  .docs-endnav .docs-endnav-next { text-align: left; }
  .docs-endnav a[hidden] { display: none; }
}

/* The Docs badge widens the brand; on phones the GitHub icon (also in
   the burger menu) gives its space back so the burger keeps its margin. */
@media (max-width: 560px) {
  .docs-body .nav-actions .ghost-link.gh { display: none; }
}
/* Very narrow phones: icon + Docs badge carry the brand alone. */
@media (max-width: 380px) {
  .docs-body .brand-word { display: none; }
  .docs-body .brand-docs { margin-left: 2px; }
}

/* Brand "Docs" badge in the nav */
.brand-docs {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.05em;
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  background: var(--glow);
  border-radius: 7px;
  padding: 2px 8px;
  margin-left: 10px;
  transform: translateY(-1px);
}
