/* ==========================================================================
   API documentation page (api-docs.html): top bar, contents on the left,
   the guide on the right. Colours come from base.css only, so both themes work.
   ========================================================================== */

.docs-page {
  --docs-top-h: 60px;
  background: var(--bg);
}

html {
  scroll-padding-top: calc(60px + 1rem);
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  z-index: 50;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--on-brand);
  font-weight: 700;
}
.skip-link:focus {
  top: 0.6rem;
  text-decoration: none;
}

/* ---------- Top bar ---------- */
.docs-top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  height: var(--docs-top-h);
  padding: 0 clamp(1rem, 3vw, 1.75rem);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.docs-top-title {
  padding-left: 0.9rem;
  border-left: 1px solid var(--border);
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
}
.docs-top-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
}
.docs-nav-toggle {
  display: none;
}

/* ---------- Layout ---------- */
.docs-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  max-width: 1240px;
  margin: 0 auto;
}

.docs-nav {
  position: sticky;
  top: var(--docs-top-h);
  align-self: start;
  max-height: calc(100vh - var(--docs-top-h));
  overflow-y: auto;
  padding: 1.5rem 1rem 2rem clamp(1rem, 3vw, 1.75rem);
  font-size: var(--fs-sm);
}
.docs-nav-group + .docs-nav-group {
  margin-top: 1.1rem;
}
.docs-nav-title {
  margin-bottom: 0.3rem;
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.docs-nav ul {
  margin: 0;
  padding: 0;
  list-style: none;
}
.docs-nav a {
  display: block;
  padding: 0.28rem 0.7rem;
  border-left: 2px solid var(--border);
  color: var(--text-2);
}
.docs-nav a:hover {
  color: var(--text);
  text-decoration: none;
  border-left-color: var(--border-strong);
}
.docs-nav a[aria-current="true"] {
  color: var(--primary);
  font-weight: 600;
  border-left-color: var(--primary);
}

.docs-main {
  min-width: 0;
  max-width: 880px;
  padding: 1.5rem clamp(1rem, 4vw, 3rem) 4rem;
  outline: none;
}

/* ---------- Text ---------- */
.doc-section {
  padding: 2.25rem 0 0.5rem;
}
.doc-section + .doc-section {
  margin-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.doc-section h2 {
  font-size: var(--fs-xl);
  letter-spacing: -0.01em;
}
#introduction h2 {
  font-size: var(--fs-2xl);
}
.doc-section h3 {
  margin-top: 2rem;
  font-size: var(--fs-lg);
}
.doc-sub {
  margin-top: 0.5rem;
}
.doc-section .lead {
  margin-top: 0.5rem;
  font-size: var(--fs-md);
  color: var(--text-2);
}
.docs-main p,
.docs-main ul,
.docs-main ol {
  margin: 0.85rem 0 0;
  color: var(--text-2);
  line-height: 1.7;
}
.docs-main ul,
.docs-main ol {
  padding-left: 1.3rem;
}
.docs-main li + li {
  margin-top: 0.4rem;
}
.docs-main strong {
  color: var(--text);
}
.docs-main :not(pre) > code {
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--surface-3);
  color: var(--text);
  font-size: 0.86em;
  overflow-wrap: anywhere;
}

ol.steps {
  counter-reset: step;
  padding-left: 0;
  list-style: none;
}
ol.steps > li {
  position: relative;
  padding-left: 2.25rem;
}
ol.steps > li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: var(--fs-xs);
  font-weight: 700;
}

.base-url {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.8rem;
  margin-top: 1.25rem;
  padding: 0.8rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.base-url-label {
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.docs-main .base-url-value {
  padding: 0;
  background: none;
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}

.callout {
  margin-top: 1.1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--info);
  border-radius: var(--radius);
  background: var(--info-soft);
}
.callout-warn {
  border-left-color: var(--warn);
  background: var(--warn-soft);
}
.docs-main .callout p {
  margin-top: 0;
  color: var(--text);
}
.docs-main .callout .callout-title {
  margin-bottom: 0.25rem;
  font-weight: 700;
}

/* ---------- Endpoints ---------- */
.endpoint {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.7rem;
  margin-top: 1rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.endpoint + .endpoint {
  margin-top: 0.5rem;
}
.http-method {
  padding: 0.12rem 0.5rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.03em;
}
.http-get {
  background: var(--info-soft);
  color: var(--info-text);
}
.http-post {
  background: var(--ok-soft);
  color: var(--ok-text);
}
.http-delete {
  background: var(--danger-soft);
  color: var(--danger-text);
}
.docs-main .endpoint-path {
  padding: 0;
  background: none;
  font-size: var(--fs-sm);
  font-weight: 600;
  overflow-wrap: anywhere;
}
.endpoint-scope {
  margin-left: auto;
  padding: 0.12rem 0.55rem;
  border-radius: var(--radius-pill);
  background: var(--primary-soft);
  color: var(--primary);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
}
.endpoint-scope.is-any {
  background: var(--neutral-soft);
  color: var(--text-2);
  font-family: var(--font);
}

/* ---------- Tables ---------- */
.docs-table {
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.docs-table .table td {
  vertical-align: top;
  color: var(--text-2);
  line-height: 1.55;
}
.docs-table .table td:first-child {
  white-space: nowrap;
  color: var(--text);
}
.docs-table.fields .table td:first-child,
.docs-table.events .table td:first-child {
  white-space: normal;
  min-width: 10rem;
}
.docs-main .docs-table td:first-child code {
  white-space: nowrap;
  overflow-wrap: normal;
}
.docs-table .type {
  color: var(--muted);
  font-size: var(--fs-xs);
  white-space: nowrap;
}
.docs-table .req {
  display: inline-block;
  margin-left: 0.25rem;
  color: var(--danger-text);
  font-size: var(--fs-xs);
  font-weight: 600;
}

/* ---------- Code ---------- */
.doc-code {
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  min-width: 0;
  overflow: hidden;
}
.doc-code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 2.25rem;
  padding: 0.2rem 0.35rem 0.2rem 0.9rem;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.doc-code pre {
  margin: 0;
  max-height: 34rem;
  padding: 0.85rem 1rem;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: 1.65;
  color: var(--text);
  tab-size: 2;
}
.doc-code pre:focus-visible {
  outline: none;
  box-shadow: inset var(--focus-ring);
}
.doc-code code {
  font-family: inherit;
  font-size: inherit;
}

/* Language tabs (built by api-docs.js; without it every language shows, one after another). */
.code-tabs.is-ready {
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  overflow: hidden;
}
.code-tabs.is-ready .doc-code {
  margin: 0;
  border: 0;
  border-radius: 0;
}
.code-tabs-bar {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.25rem 0.35rem 0 0.4rem;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.code-tabs-bar .tab {
  padding: 0.45rem 0.7rem;
  font-size: var(--fs-xs);
}
.code-tabs-bar .copy-btn {
  margin-left: auto;
}
.code-tabs.is-ready .doc-code-head {
  display: none;
}

/* ---------- Footer ---------- */
.docs-foot {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: var(--fs-sm);
}

/* ---------- Narrow screens: contents fold behind a button ---------- */
@media (max-width: 900px) {
  .docs-layout {
    display: block;
  }
  .docs-nav {
    position: static;
    max-height: none;
    padding: 1rem clamp(1rem, 4vw, 3rem);
    border-bottom: 1px solid var(--border);
    background: var(--surface);
  }
  .js .docs-nav {
    position: fixed;
    top: var(--docs-top-h);
    left: 0;
    right: 0;
    z-index: 15;
    max-height: calc(100vh - var(--docs-top-h));
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
  }
  .js .docs-nav:not(.is-open) {
    display: none;
  }
  .js .docs-nav-toggle {
    display: inline-flex;
  }
  .docs-nav ul {
    columns: 2;
    column-gap: 1rem;
  }
  .docs-nav li {
    break-inside: avoid;
  }
}

@media (max-width: 600px) {
  .docs-top {
    gap: 0.5rem;
  }
  /* Only the mark stays of the wordmark, next to "API docs". */
  .docs-top .wordmark > span:not(.mark),
  .docs-top-link {
    display: none;
  }
  .docs-top-title {
    padding-left: 0;
    border-left: 0;
  }
  .docs-top-actions {
    gap: 0.2rem;
  }
  .endpoint-scope {
    margin-left: 0;
  }
  .docs-nav ul {
    columns: 1;
  }

  /* Tables become one card per row: the first cells side by side, the description below them. */
  .docs-table thead {
    display: none;
  }
  .docs-table .table tr {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: baseline;
    gap: 0.2rem 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
  }
  .docs-table .table tbody tr:last-child {
    border-bottom: 0;
  }
  .docs-table .table td {
    padding: 0;
    border: 0;
  }
  .docs-table .table td:last-child {
    grid-column: 1 / -1;
  }
  .docs-table.fields .table td:first-child,
  .docs-table.events .table td:first-child {
    min-width: 0;
  }
}
