/* Sapienic developer docs. Sits on top of sales.css (brand tokens, header, footer) and lays the page out
   the way developer documentation usually is: a sticky tab bar, a section nav on the left, the article in
   the middle and "On this page" on the right. Colors come from the sales.css tokens; every text/background
   pair here meets WCAG 2.2 AA (navy and --muted on white, sage-50, peri-50 and peach-50). */

.docs-page { --bar-h: 52px; --side-w: 264px; --onpage-w: 224px; background: var(--bg); }
.docs-page :is(h2, h3, h4)[id], .docs-page section[id], .docs-page .tool[id] { scroll-margin-top: calc(var(--bar-h) + 20px); }

/* ── Tab bar ─────────────────────────────────────────────────────────── */
.docs-bar { position: sticky; top: 0; z-index: 30; background: #fff; border-bottom: 1px solid var(--line); }
.docs-bar-inner { display: flex; align-items: center; gap: 28px; height: var(--bar-h); max-width: 1440px; margin: 0 auto; padding: 0 var(--gutter); }
.docs-bar-title { font-weight: 800; font-size: 16px; letter-spacing: -0.02em; text-decoration: none; white-space: nowrap; }
.docs-tabs { display: flex; align-self: stretch; gap: 4px; margin-right: auto; overflow-x: auto; scrollbar-width: none; }
.docs-tabs::-webkit-scrollbar { display: none; }
.docs-tabs a {
  display: flex; align-items: center; padding: 0 12px; white-space: nowrap;
  font-size: 14px; font-weight: 600; color: var(--muted); text-decoration: none;
  border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.docs-tabs a:hover { color: var(--ink); background: var(--bg-2); }
.docs-tabs a[aria-current="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.docs-bar .btn { white-space: nowrap; }

/* ── Three columns ───────────────────────────────────────────────────── */
.docs-shell {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr) var(--onpage-w);
  max-width: 1440px; margin: 0 auto;
}

/* Left: section nav */
.docs-side { border-right: 1px solid var(--line); background: var(--bg-2); }
.docs-side-toggle { position: sticky; top: var(--bar-h); max-height: calc(100vh - var(--bar-h)); overflow-y: auto; padding: 20px 12px 40px; }
.docs-side-toggle > summary { display: none; }
.docs-nav ol { list-style: none; margin: 0; padding: 0; }
.docs-nav > ol > li + li { margin-top: 2px; }
.docs-nav a, .docs-nav-group {
  display: block; padding: 7px 12px; border-radius: 0 999px 999px 0;
  font-size: 14px; line-height: 1.35; text-decoration: none; color: var(--ink);
}
.docs-nav-group { margin-top: 14px; font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.docs-nav > ol > li > a { font-weight: 600; }
.docs-nav li li a { padding-left: 22px; color: var(--ink-2); }
.docs-nav a:hover { background: var(--bg-3); }
.docs-nav a[aria-current="true"] { background: var(--peri-100); color: var(--ink); font-weight: 700; box-shadow: inset 3px 0 0 var(--ink); }

/* Middle: the article */
.docs-main { min-width: 0; padding: 24px clamp(20px, 4vw, 56px) 80px; }
.crumbs ol { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0 0 20px; padding: 0; font-size: 13px; color: var(--muted); }
.crumbs li + li::before { content: "›"; margin-right: 6px; color: var(--faint); }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--ink); }
.crumbs [aria-current] { color: var(--ink); font-weight: 600; }
.docs-head { max-width: 780px; padding-bottom: 28px; margin-bottom: 8px; border-bottom: 1px solid var(--line); }
.docs-head h1 { font-size: clamp(30px, 3.4vw, 42px); line-height: 1.1; }
.docs-head .lead { margin: 14px 0 0; }
.docs-help { max-width: 780px; margin: 48px 0 0; padding-top: 20px; border-top: 1px solid var(--line); font-size: 14px; color: var(--muted); }

.doc { max-width: 780px; }
.doc > section { padding: 36px 0 12px; }
.doc > section + section { border-top: 1px solid var(--line); margin-top: 28px; }
.doc h2 { font-size: clamp(24px, 2.6vw, 32px); line-height: 1.15; font-weight: 800; margin: 0 0 14px; }
.doc h3 { font-size: 20px; line-height: 1.3; margin: 40px 0 10px; }
.doc h4 { font-size: 16px; margin: 24px 0 8px; }
.doc p, .doc li, .doc dd { font-size: 15px; line-height: 1.7; }
.doc p { margin: 0 0 14px; }
.doc a { color: var(--brand-700); text-underline-offset: 2px; }
.doc a:hover { color: var(--ink); }
.doc :not(pre) > code {
  padding: 1px 5px; border-radius: 4px; background: var(--bg-3);
  font: 600 0.88em/1.4 var(--mono); overflow-wrap: anywhere;
}
.doc .muted { color: var(--muted); }
.doc .small { font-size: 13px; color: var(--muted); }

/* Steps */
.doc ol.steps-list { list-style: none; counter-reset: st; margin: 20px 0; padding: 0; }
.doc ol.steps-list > li { counter-increment: st; position: relative; padding: 4px 0 22px 48px; }
.doc ol.steps-list > li::before {
  content: counter(st); position: absolute; left: 0; top: 2px;
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
  background: var(--ink); color: #fff; font-size: 14px; font-weight: 700;
}
.doc ol.steps-list > li:not(:last-child)::after { content: ""; position: absolute; left: 14px; top: 38px; bottom: 4px; width: 2px; background: var(--line); }

/* Definition lists */
.doc dl.defs { margin: 16px 0; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.doc dl.defs > div { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 16px; padding: 12px 16px; }
.doc dl.defs > div + div { border-top: 1px solid var(--line); }
.doc dl.defs dt { font-size: 14px; font-weight: 700; }
.doc dl.defs dd { margin: 0; }
@media (max-width: 560px) { .doc dl.defs > div { grid-template-columns: 1fr; gap: 4px; } }

/* Tables */
.table-wrap { overflow-x: auto; margin: 16px 0; border: 1px solid var(--line); border-radius: var(--r-sm); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 1.5; }
table.data th, table.data td { padding: 10px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
table.data tbody tr:last-child > * { border-bottom: 0; }
table.data thead th { background: var(--bg-2); font-size: 13px; font-weight: 700; white-space: nowrap; }
table.data td { overflow-wrap: anywhere; }
table.data .mono { font: 600 13px/1.5 var(--mono); }
table.data tr.group th { background: var(--bg-2); padding-top: 14px; font-size: 13px; font-weight: 800; }
.yes { font-weight: 700; color: var(--ok); }
.no { color: var(--muted); }
.method {
  display: inline-block; min-width: 54px; padding: 1px 6px; border-radius: 4px; text-align: center;
  font: 700 11px/1.6 var(--mono); letter-spacing: 0.03em; background: var(--peri-100); color: var(--ink);
}
.path { font: 400 13px/1.5 var(--mono); overflow-wrap: anywhere; }

/* Code blocks */
.code { position: relative; margin: 16px 0; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--bg-2); overflow: hidden; }
.code-head { display: flex; align-items: center; justify-content: space-between; min-height: 36px; padding-left: 14px; background: var(--bg-3); border-bottom: 1px solid var(--line); }
.code-head .label { font-size: 12px; font-weight: 700; color: var(--muted); }
.code pre { margin: 0; padding: 14px 16px; overflow-x: auto; font: 400 13px/1.65 var(--mono); color: var(--ink); tab-size: 2; }
.code pre code { font: inherit; background: none; padding: 0; }
.copy-btn {
  align-self: stretch; padding: 0 14px; border: 0; border-left: 1px solid var(--line); background: transparent;
  font-size: 12px; font-weight: 700; color: var(--ink); cursor: pointer;
}
.copy-btn:hover { background: var(--ink); color: #fff; }
.code:not(:has(.code-head)) .copy-btn { position: absolute; top: 0; right: 0; height: 32px; border-bottom: 1px solid var(--line); }

/* Callouts */
.note { margin: 20px 0; padding: 14px 16px; border-radius: var(--r-sm); background: var(--peri-50); border-left: 4px solid var(--ink); font-size: 14px; line-height: 1.6; }
.note p { font: inherit; margin: 0; }
.note.caution { background: var(--peach-50); border-left-color: var(--orange-ink); }

/* Live tool reference (rendered by docs.js) */
.tool-index { display: flex; flex-wrap: wrap; gap: 6px; margin: 16px 0; padding: 0; list-style: none; }
.tool-index a { display: inline-block; padding: 3px 9px; border-radius: 999px; background: var(--bg-2); border: 1px solid var(--line); font-size: 12.5px; text-decoration: none; color: var(--ink); }
.tool-index a:hover { background: var(--peri-100); }
.tool { margin: 16px 0; padding: 18px 20px 6px; border: 1px solid var(--line); border-radius: var(--r-sm); }
.tool-name { margin: 0; font: 700 16px/1.3 var(--mono); letter-spacing: 0; overflow-wrap: anywhere; }
.tool-name a { color: var(--ink); text-decoration: none; }
.tool-name a:hover { text-decoration: underline; }
.tool-title { margin: 4px 0 8px; font-size: 13px; color: var(--muted); }
.tool-desc { max-width: 44em; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 8px; padding: 0; list-style: none; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; border: 1px solid var(--line); color: var(--muted); }
.badge.ro { background: var(--mint-100); border-color: var(--mint-300); color: var(--ok); }
.badge.destructive { background: var(--peach-50); border-color: var(--peach-300); color: var(--orange-ink); }
.params td:first-child { white-space: nowrap; }
.params .pname { font: 700 13px/1.5 var(--mono); }
.params .ptype { font: 400 12.5px/1.5 var(--mono); color: var(--ink-2); overflow-wrap: anywhere; }
.params .req { font-size: 12px; font-weight: 700; color: var(--orange-ink); }
.params .opt { font-size: 12px; color: var(--muted); }
.params .constraint { display: block; font-size: 12.5px; color: var(--muted); }
@media (min-width: 700px) {
  table.params { table-layout: fixed; }
  table.params th:nth-child(1) { width: 25%; }
  table.params th:nth-child(2) { width: 27%; }
  table.params th:nth-child(3) { width: 13%; }
}
@media (max-width: 699px) {
  table.data.params, table.data.params tbody, table.data.params tr, table.data.params td { display: block; }
  table.data.params thead { display: none; }
  table.data.params tr { display: flex; flex-wrap: wrap; align-items: baseline; padding: 10px 14px; border-bottom: 1px solid var(--line); }
  table.data.params td { padding: 0; border: 0; }
  table.data.params td:nth-child(3) { order: 1; margin-left: 10px; }
  table.data.params td:nth-child(2) { order: 2; width: 100%; margin: 4px 0 6px; }
  table.data.params td:nth-child(4) { order: 3; width: 100%; }
}
@media (max-width: 599px) {
  table.data.endpoints, table.data.endpoints tbody, table.data.endpoints th, table.data.endpoints td { display: block; }
  table.data.endpoints thead { display: none; }
  table.data.endpoints tr { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
  table.data.endpoints tr.group { padding: 0; }
  table.data.endpoints tr.group th { width: 100%; }
  table.data.endpoints td { padding: 0; border: 0; }
  table.data.endpoints td:nth-child(2) { flex: 1 1 0; min-width: 0; }
  table.data.endpoints td:nth-child(3) { width: 100%; margin-top: 4px; }
}
.no-params { font-size: 13px; color: var(--muted); margin: 8px 0 16px; }
.tool-loading { padding: 16px 0; font-size: 14px; color: var(--muted); }
.tool-error { margin: 16px 0; padding: 16px 18px; border-radius: var(--r-sm); background: var(--peach-50); border-left: 4px solid var(--orange-ink); font-size: 14px; }
.tool-error strong { display: block; margin-bottom: 6px; }
.tool-error .btn { margin-top: 10px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Right: on this page */
.docs-onpage { padding: 28px 20px 40px 8px; }
.docs-onpage > * { position: sticky; }
.docs-onpage-label { top: calc(var(--bar-h) + 28px); margin: 0 0 10px; font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.docs-onpage nav { top: calc(var(--bar-h) + 56px); max-height: calc(100vh - var(--bar-h) - 80px); overflow-y: auto; }
.docs-onpage ol { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.docs-onpage a { display: block; margin-left: -2px; padding: 5px 0 5px 14px; border-left: 2px solid transparent; font-size: 13px; line-height: 1.4; color: var(--muted); text-decoration: none; }
.docs-onpage li.sub a { padding-left: 26px; }
.docs-onpage a:hover { color: var(--ink); }
.docs-onpage a[aria-current="true"] { color: var(--ink); font-weight: 700; border-left-color: var(--ink); }

/* ── Smaller screens ─────────────────────────────────────────────────── */
@media (max-width: 1180px) {
  .docs-shell { grid-template-columns: var(--side-w) minmax(0, 1fr); }
  .docs-onpage { display: none; }
}
@media (max-width: 860px) {
  .docs-bar .btn { display: none; }
  .docs-bar-inner { gap: 12px; }
  .docs-shell { grid-template-columns: minmax(0, 1fr); }
  .docs-side { position: sticky; top: var(--bar-h); z-index: 20; border-right: 0; border-bottom: 1px solid var(--line); }
  .docs-nav { max-height: calc(100vh - var(--bar-h) - 120px); overflow-y: auto; }
  .docs-side-toggle { position: static; max-height: none; padding: 0; }
  .docs-side-toggle > summary {
    display: flex; align-items: center; gap: 8px; padding: 12px var(--gutter); cursor: pointer;
    font-size: 14px; font-weight: 700; list-style: none;
  }
  .docs-side-toggle > summary::-webkit-details-marker { display: none; }
  .docs-side-toggle > summary::before { content: "☰"; font-weight: 400; }
  .docs-side-toggle[open] > summary { border-bottom: 1px solid var(--line); }
  .docs-nav { padding: 8px 12px 16px; }
  .docs-main { padding: 20px var(--gutter) 64px; }
}
