/* ============================================================================
   RING — documentation portal (site/docs/**)
   Reads design tokens from theme.css; per-book accent arrives as
   --book-accent / --book-accent-soft inline on <body>.
   ============================================================================ */

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; background: var(--surface); }
body.doc-body {
  margin: 0; background: var(--surface); color: var(--text);
  font-family: var(--font); font-size: 16px; line-height: 1.6;
  --book-accent: var(--accent);
  --book-accent-soft: var(--accent-soft);
}

/* ---- top bar ----------------------------------------------------------- */
.doc-topbar { background: var(--surface-dark); color: #fff; position: sticky; top: 0; z-index: 40; }
.doc-topbar__inner {
  max-width: 1400px; margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; gap: 18px;
}
.doc-topbar .brand { color: #fff; text-decoration: none; font-weight: 800; letter-spacing: .05em; }
.doc-topbar .brand__by { color: #9CA3AF; font-weight: 500; margin-left: 6px; font-size: .85rem; }
.doc-topbar__links { margin-left: auto; display: flex; gap: 18px; align-items: center; }
.doc-topbar__links a { color: #D1D5DB; text-decoration: none; font-size: .92rem; }
.doc-topbar__links a:hover { color: #fff; }
.doc-topbar__pdf { border: 1px solid #4B5563; border-radius: 8px; padding: 5px 12px; }
.doc-navtoggle { display: none; background: none; border: 1px solid #4B5563; color: #D1D5DB;
  border-radius: 8px; padding: 5px 10px; font: inherit; font-size: .9rem; cursor: pointer; }

/* ---- three-column layout ---------------------------------------------- */
.doc-layout {
  max-width: 1400px; margin: 0 auto; padding: 0 20px;
  display: grid; grid-template-columns: 250px minmax(0, 1fr) 220px; gap: 36px;
}
.doc-main { min-width: 0; padding: 28px 0 64px; }

/* ---- sidebar ----------------------------------------------------------- */
.doc-sidebar {
  padding: 28px 0 40px; border-right: 1px solid var(--border);
  position: sticky; top: 49px; align-self: start;
  max-height: calc(100vh - 49px); overflow-y: auto;
}
.doc-sidebar__eyebrow {
  text-transform: uppercase; letter-spacing: .1em; font-size: .68rem;
  font-weight: 700; color: var(--text-faint); margin-bottom: 6px;
}
.doc-sidebar__title {
  display: block; font-size: 1.15rem; font-weight: 800; color: var(--text);
  text-decoration: none; margin-bottom: 18px; line-height: 1.25;
}
.doc-sidebar__title:hover { color: var(--book-accent); }
.doc-chapters { list-style: none; margin: 0 0 20px; padding: 0; }
.doc-chapters a {
  display: block; padding: 7px 12px; margin: 1px 0; border-radius: 8px;
  color: var(--text-muted); text-decoration: none; font-size: .92rem; line-height: 1.35;
  border-left: 3px solid transparent;
}
.doc-chapters a:hover { background: var(--card-inset); color: var(--text); }
.doc-chapters a.is-active {
  background: var(--book-accent-soft); color: var(--text); font-weight: 600;
  border-left-color: var(--book-accent);
}
.btn-pdf {
  display: inline-block; padding: 8px 14px; border: 1px solid var(--border-strong);
  border-radius: 8px; text-decoration: none; color: var(--text); font-size: .88rem;
  background: var(--card);
}
.btn-pdf:hover { border-color: var(--book-accent); color: var(--book-accent); }

/* ---- content prose ------------------------------------------------------ */
.doc-prose { max-width: 76ch; }
.doc-prose h1 { font-size: var(--fs-h1); letter-spacing: -.01em; line-height: 1.15; margin: 8px 0 18px; }
.doc-prose h2 {
  font-size: var(--fs-h2); letter-spacing: -.01em; margin: 40px 0 10px;
  padding-top: 8px; border-top: 1px solid var(--border);
}
.doc-prose h3 { font-size: var(--fs-h3); margin: 26px 0 8px; }
.doc-prose h4 { font-size: 1rem; margin: 20px 0 6px; }
.doc-prose p { margin: 10px 0; }
.doc-prose a { color: var(--book-accent); }
.doc-prose li { margin: 6px 0; }
.doc-prose ul, .doc-prose ol { padding-left: 24px; }
.doc-prose hr { border: 0; border-top: 1px solid var(--border); margin: 28px 0; }
.doc-prose img { max-width: 100%; border-radius: 8px; border: 1px solid var(--border); }
.doc-shot { margin: 20px 0 28px; max-width: none; }
.doc-shot a { display: block; line-height: 0; }
.doc-shot img {
  display: block; width: 100%; border-radius: 10px; border: 1px solid var(--border-strong);
  box-shadow: 0 4px 18px rgba(15, 23, 42, .14); cursor: zoom-in;
}
.doc-shot figcaption { margin-top: 8px; font-size: .82rem; color: var(--text-faint); }

/* Screenshots were rendering clamped to the 76ch prose measure above — around
   45% of a real app capture's native width, small enough that no label or
   button caption in the image is legible. At wide viewports let a figure
   break out of that measure and span the full content column plus the gap
   that leads into the right-hand "On this page" rail, stopping short of the
   rail itself. Uses a container query on .doc-main (the content column) so
   the breakout tracks the actual column width instead of a guessed pixel
   value; falls back to the unbroken 76ch width in browsers without support. */
@media (min-width: 1121px) {
  .doc-main { container-type: inline-size; }
}
@supports (container-type: inline-size) {
  @media (min-width: 1121px) {
    .doc-prose .doc-shot { width: calc(100cqi + 36px); }
  }
}

.doc-prose .anchor {
  opacity: 0; margin-left: 8px; font-weight: 400; text-decoration: none;
  color: var(--text-faint); font-size: .85em;
}
.doc-prose h1:hover .anchor, .doc-prose h2:hover .anchor,
.doc-prose h3:hover .anchor, .doc-prose h4:hover .anchor { opacity: 1; }

.doc-prose code {
  font-family: var(--font-mono); font-size: .86em;
  background: var(--card-inset); border: 1px solid var(--border);
  border-radius: 5px; padding: 1px 5px; overflow-wrap: anywhere;
}
.doc-prose pre {
  background: var(--surface-dark); color: #E5E7EB; border-radius: 10px;
  padding: 14px 18px; overflow-x: auto; font-size: .85rem; line-height: 1.5;
}
.doc-prose pre code { background: none; border: 0; padding: 0; color: inherit; }

.doc-prose blockquote {
  margin: 16px 0; padding: 12px 18px; border-left: 4px solid var(--book-accent);
  background: var(--book-accent-soft); border-radius: 0 10px 10px 0;
}
.doc-prose blockquote p { margin: 6px 0; }

/* A wide table gets its own horizontal scrollbar inside this wrapper rather
   than either squeezing its columns unreadably or forcing the page body to
   scroll sideways. `min-width: 100%` (not `width: 100%`) is what makes this
   work: the table still fills the column when it fits, but is free to grow
   past it — into the wrapper's own scroll area — when its content demands
   more room than that. */
.tablewrap { overflow-x: auto; max-width: 100%; margin: 16px 0; border: 1px solid var(--border); border-radius: 10px; }
.doc-prose table { border-collapse: collapse; min-width: 100%; table-layout: auto; font-size: .92rem; }
.doc-prose th, .doc-prose td { text-align: left; padding: 9px 13px; border-bottom: 1px solid var(--border); vertical-align: top; }
.doc-prose th { background: var(--card-inset); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.doc-prose tr:last-child td { border-bottom: 0; }

/* Internal-repo reference chip: a path like Ring/Services/Foo.cs that isn't
   a hyperlink (merged_code is private, so a real <a> here would 404 for
   every reader without repo access — see assemble-docs.js SRCREF_PREFIX).
   Deliberately subtler than a normal inline <code> so it reads as a
   citation, not as copy-pasteable syntax. */
.doc-prose .srcref {
  background: none; border: 0; padding: 0;
  color: var(--text-faint); font-size: .84em;
}

/* ---- collapsed provenance / "Sources verified" ------------------------- */
.doc-evidence {
  margin: 12px 0; padding: 2px 0; font-size: .9rem; color: var(--text-muted);
}
.doc-evidence summary {
  cursor: pointer; list-style: none; color: var(--text-faint);
  font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 700;
}
.doc-evidence summary::-webkit-details-marker { display: none; }
.doc-evidence summary::before { content: "\25B8  "; }
.doc-evidence[open] summary::before { content: "\25BE  "; }
.doc-evidence summary h2 { display: inline; font: inherit; margin: 0; border: 0; padding: 0; letter-spacing: inherit; text-transform: inherit; color: inherit; }
.doc-evidence summary .anchor { display: none; }
.doc-evidence > *:not(summary) { margin-top: 10px; }

/* ---- right-hand "on this page" toc ------------------------------------- */
.doc-toc {
  padding: 28px 0 40px; position: sticky; top: 49px; align-self: start;
  max-height: calc(100vh - 49px); overflow-y: auto; font-size: .85rem;
}
.doc-toc__title { text-transform: uppercase; letter-spacing: .1em; font-size: .68rem; font-weight: 700; color: var(--text-faint); margin-bottom: 8px; }
.doc-toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
.doc-toc li.toc-d3 { padding-left: 12px; }
.doc-toc a {
  display: block; padding: 4px 12px; color: var(--text-muted); text-decoration: none;
  border-left: 2px solid transparent; margin-left: -1px; line-height: 1.35;
}
.doc-toc a:hover { color: var(--text); }
.doc-toc a.is-here { color: var(--book-accent); border-left-color: var(--book-accent); font-weight: 600; }

/* ---- pager + footer ----------------------------------------------------- */
.doc-pager {
  display: flex; justify-content: space-between; gap: 16px;
  margin: 44px 0 0; max-width: 76ch;
}
.doc-pager a {
  flex: 0 1 48%; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; text-decoration: none; background: var(--card);
}
.doc-pager a:hover { border-color: var(--book-accent); }
.doc-pager__next { text-align: right; margin-left: auto; }
.doc-pager__dir { display: block; font-size: .75rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: .07em; }
.doc-pager__title { display: block; color: var(--book-accent); font-weight: 600; margin-top: 3px; }
.doc-foot { max-width: 76ch; margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--border); color: var(--text-faint); font-size: .82rem; }
.doc-foot--portal { max-width: 1100px; margin: 0 auto; padding: 16px 20px 48px; }

/* ---- portal (docs landing) ---------------------------------------------- */
.portal-hero { background: var(--hero-gradient); color: #fff; padding: 52px 20px 46px; }
.portal-hero__inner { max-width: 1100px; margin: 0 auto; }
.portal-hero__eyebrow { text-transform: uppercase; letter-spacing: .14em; font-weight: 800; font-size: .72rem; color: var(--text-on-accent-muted); margin-bottom: 10px; }
.portal-hero h1 { font-size: clamp(1.9rem, 4vw, 2.6rem); margin: 0 0 12px; letter-spacing: -.01em; }
.portal-hero p { color: #DCE7FF; max-width: 68ch; margin: 0; }
.portal {
  max-width: 1100px; margin: 0 auto; padding: 36px 20px 24px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 22px;
}
.portal-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 22px 24px 18px; border-top: 4px solid var(--book-accent);
  display: flex; flex-direction: column;
}
.portal-card__eyebrow { text-transform: uppercase; letter-spacing: .1em; font-size: .68rem; font-weight: 700; color: var(--text-faint); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.portal-card__badge {
  text-transform: none; letter-spacing: normal; font-weight: 700; font-size: .72rem;
  color: var(--warn); background: var(--warn-soft); border: 1px solid var(--warn);
  border-radius: 999px; padding: 2px 10px;
}
.portal-card h2 { margin: 8px 0 8px; font-size: 1.3rem; }
.portal-card h2 a { color: var(--text); text-decoration: none; }
.portal-card h2 a:hover { color: var(--book-accent); }
.portal-card > p { color: var(--text-muted); font-size: .93rem; margin: 0 0 14px; }
.portal-card__actions { display: flex; gap: 10px; margin-bottom: 14px; }
.portal-card .btn { text-decoration: none; border-radius: 8px; padding: 8px 14px; font-size: .88rem; font-weight: 600; }
.portal-card .btn--primary { background: var(--book-accent); color: #fff; }
.portal-card .btn--ghost { border: 1px solid var(--border-strong); color: var(--text); }
.portal-card .btn--ghost:hover { border-color: var(--book-accent); color: var(--book-accent); }
.portal-card__chapters { list-style: none; margin: 0; padding: 12px 0 0; border-top: 1px solid var(--border); font-size: .88rem; }
.portal-card__chapters li { margin: 5px 0; }
.portal-card__chapters a { color: var(--text-muted); text-decoration: none; }
.portal-card__chapters a:hover { color: var(--book-accent); }

/* ---- index page of a book ----------------------------------------------- */
.doc-prose--index h1 { border: 0; }

/* ---- responsive --------------------------------------------------------- */
@media (max-width: 1120px) {
  .doc-layout { grid-template-columns: 240px minmax(0, 1fr); }
  .doc-toc { display: none; }
}
@media (max-width: 800px) {
  .doc-layout { grid-template-columns: minmax(0, 1fr); }
  .doc-navtoggle { display: inline-block; margin-left: auto; }
  .doc-topbar__links { margin-left: 0; }
  .doc-sidebar {
    display: none; position: static; max-height: none;
    border-right: 0; border-bottom: 1px solid var(--border); padding: 18px 0;
  }
  .doc-sidebar.is-open { display: block; }
}

/* ---- print (screen pages) ----------------------------------------------- */
@media print {
  .doc-topbar, .doc-sidebar, .doc-toc, .doc-pager, .doc-navtoggle { display: none !important; }
  .doc-layout { display: block; }
  body.doc-body { background: #fff; }
  .doc-prose { max-width: none; }
  .doc-prose .anchor { display: none; }
}
