/*
 * The developer hub at /developers: the guide (static prose, tables, code)
 * and the API reference rendered by docs.js. Layers on tokens.css and
 * base.css; reads only token colours so dark mode follows the rest of Polls
 * automatically. Wide things (tables, code) scroll inside their own box so a
 * phone never scrolls the page sideways.
 */

:root {
  --docs-header: 56px;
  --docs-nav: 288px;
  --code-bg: color-mix(in srgb, var(--fg) 4%, var(--surface));
  --code-fg: var(--fg);
  --m-get: var(--success);
  --m-post: var(--accent);
  --m-put: var(--warning);
  --m-patch: var(--warning);
  --m-delete: var(--danger);
}

html {
  scroll-padding-top: calc(var(--docs-header) + 12px);
}

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

/* ---------- header ---------- */

.docs-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: var(--docs-header);
  padding-inline: 1rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}

.docs-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--fg);
  font-weight: 700;
  font-size: 1.0625rem;
  text-decoration: none;
}

.docs-brand-sub {
  padding: 0.05em 0.5em;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.8125rem;
}

.docs-version {
  color: var(--muted);
  font-size: 0.8125rem;
  font-family: var(--font-mono);
}

.docs-header-actions {
  margin-left: auto;
  display: flex;
  gap: 0.5rem;
}

.docs-menu {
  display: none;
  width: 40px;
  padding: 0;
  font-size: 1.125rem;
}

/* ---------- layout ---------- */

.docs-layout {
  display: grid;
  grid-template-columns: var(--docs-nav) minmax(0, 1fr);
  min-height: calc(100dvh - var(--docs-header));
}

.docs-nav {
  position: sticky;
  top: var(--docs-header);
  height: calc(100dvh - var(--docs-header));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem 0.75rem 2rem;
  border-right: 1px solid var(--border);
  background: var(--bg);
}

.docs-main {
  min-width: 0;
  padding: 2rem clamp(1rem, 4vw, 3rem) 6rem;
}

.docs-main:focus {
  outline: none;
}

.docs-content {
  max-width: 920px;
}

/* ---------- nav ---------- */

.docs-search {
  position: relative;
  margin-bottom: 1rem;
}

.docs-search .input {
  min-height: 38px;
  padding-right: 2.25rem;
  font-size: max(0.9375rem, 16px);
}

.docs-search .input:focus + .docs-search-key,
.docs-search .input:not(:placeholder-shown) + .docs-search-key {
  display: none;
}

.docs-search-key {
  position: absolute;
  right: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 0.75rem;
}

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

.nav-section + .nav-section {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.nav-section-title {
  margin: 0 0 0.35rem;
  padding-inline: 0.5rem;
  color: var(--fg);
  font-size: 0.875rem;
  font-weight: 700;
}

.nav-section-link {
  display: block;
  margin-inline: -0.5rem;
  padding: 0.25rem 0.5rem;
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
}

.nav-section-link:hover {
  background: var(--surface-2);
}

.nav-section-link.is-active {
  background: var(--accent-soft);
}

.nav-group {
  margin-top: 0.85rem;
}

.nav-tag {
  margin: 0 0 0.25rem;
  padding-inline: 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

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

.nav-tag a:hover {
  color: var(--fg);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 32px;
  padding: 0.25rem 0.5rem;
  border-radius: 8px;
  color: var(--fg);
  font-size: 0.875rem;
  text-decoration: none;
}

.nav-link:hover {
  background: var(--surface-2);
}

.nav-link.is-active {
  background: var(--accent-soft);
  color: var(--fg);
  box-shadow: inset 3px 0 0 var(--accent);
}

.nav-path {
  min-width: 0;
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}

.docs-nav-empty {
  padding: 0.5rem;
  font-size: 0.875rem;
}

/* ---------- method + status badges ---------- */

.method {
  --m: var(--muted);
  display: inline-block;
  min-width: 3.6em;
  padding: 0.15em 0.45em;
  border-radius: 6px;
  background: color-mix(in srgb, var(--m) 14%, transparent);
  color: var(--m);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.5;
  text-align: center;
  flex: none;
}

.method-sm {
  min-width: 3.2em;
  font-size: 0.6875rem;
}

.method-get { --m: var(--m-get); }
.method-post { --m: var(--m-post); }
.method-put { --m: var(--m-put); }
.method-patch { --m: var(--m-patch); }
.method-delete { --m: var(--m-delete); }

.status {
  --s: var(--muted);
  display: inline-block;
  min-width: 2.8em;
  padding: 0.05em 0.4em;
  border-radius: 6px;
  background: color-mix(in srgb, var(--s) 14%, transparent);
  color: var(--s);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 700;
  text-align: center;
}

.status-2xx { --s: var(--success); }
.status-4xx { --s: var(--warning); }
.status-5xx { --s: var(--danger); }

/* ---------- guide ---------- */

.guide-section + .guide-section {
  margin-top: 3.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.guide-section > h1 {
  margin: 0.75rem 0 0.75rem;
}

.prose {
  overflow-wrap: break-word;
}

.prose > * + * {
  margin-top: 0.85rem;
}

.prose > h2 {
  margin-bottom: 0.25rem;
}

.prose > h3,
.prose > h2.overview-h {
  margin-top: 2.25rem;
  font-size: 1.1875rem;
}

.prose > h3 + *,
.prose > h2.overview-h + * {
  margin-top: 0.6rem;
}

.prose ul,
.prose ol {
  padding-left: 1.25rem;
}

.prose li + li {
  margin-top: 0.4rem;
}

.prose li > ul {
  margin-top: 0.4rem;
}

.lead {
  color: var(--muted);
  font-size: 1.125rem;
  max-width: 44rem;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.feature {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.feature-title {
  font-size: 1.0625rem;
}

.feature p {
  color: var(--muted);
  font-size: 0.9375rem;
}

.feature p:last-child {
  margin-top: auto;
  padding-top: 0.25rem;
  font-weight: 600;
}

/* Callouts: a note, or a warning that matters for safety. */
.callout {
  padding: 0.85rem 1rem 0.9rem;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 6%, var(--surface));
}

.callout-warning {
  border-color: color-mix(in srgb, var(--warning) 35%, var(--border));
  border-left-color: var(--warning);
  background: color-mix(in srgb, var(--warning) 7%, var(--surface));
}

.callout > * + * {
  margin-top: 0.35rem;
}

.callout-title {
  font-weight: 650;
}

/* ---------- reference section ---------- */

.reference {
  margin-top: 3.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.reference-title {
  margin-bottom: 1rem;
}

.intro-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  font-size: 0.875rem;
}

.intro > * + * {
  margin-top: 0.75rem;
}

.intro-details {
  margin-top: 1rem;
  background: var(--surface);
}

.intro-details > .md {
  padding: 0.25rem 0.5rem 0.75rem;
}

.intro-more {
  font-weight: 600;
}

/* ---------- intro + markdown ---------- */

.intro-lead {
  color: var(--muted);
  font-size: 1.125rem;
}

.intro-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.intro-card ul {
  margin: 0.5rem 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
  font-size: 0.9375rem;
}

.intro-card-title {
  font-size: 1rem;
}

.md {
  overflow-wrap: anywhere;
}

.md > * + * {
  margin-top: 0.75rem;
}

.md .md-h {
  margin-top: 2rem;
}

.md h2.md-h {
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.md ul,
.md ol {
  padding-left: 1.25rem;
}

.md li + li {
  margin-top: 0.3rem;
}

:not(pre) > code {
  padding: 0.1em 0.35em;
  border-radius: 5px;
  background: var(--surface-2);
  font-size: 0.85em;
  overflow-wrap: anywhere;
}

/* ---------- code blocks ---------- */

.code-wrap {
  position: relative;
  margin-top: 0.75rem;
}

.code {
  margin: 0;
  max-height: 480px;
  overflow: auto;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--code-bg);
  color: var(--code-fg);
  font-size: 0.8125rem;
  line-height: 1.55;
  tab-size: 2;
}

/* Guide examples are meant to be read whole; the reference's can be long. */
.guide-section .code {
  max-height: none;
}

.code:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.code-wrap > .code {
  padding-top: 2.1rem;
}

.code-copy {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  z-index: 1;
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.75rem;
  opacity: 0.85;
}

.code-copy:hover,
.code-copy:focus-visible {
  color: var(--fg);
  opacity: 1;
}

/* ---------- sections + operations ---------- */

.tag-section {
  margin-top: 3.5rem;
}

.tag-title {
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border);
  font-size: clamp(1.25rem, 1.05rem + 0.8vw, 1.5rem);
}

.tag-desc {
  margin-top: 0.5rem;
  color: var(--muted);
}

.op {
  margin-top: 1.5rem;
  padding: 1.25rem 1.25rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.op:target {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
}

.op-title {
  font-size: 1.1875rem;
}

.op-anchor {
  color: inherit;
  text-decoration: none;
}

.op-anchor:hover {
  text-decoration: underline;
}

.op-line {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.6rem;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius);
  background: var(--surface-2);
  overflow-x: auto;
}

.path {
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  white-space: nowrap;
}

.path-param {
  color: var(--accent);
}

.op-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.5rem;
  margin-top: 0.65rem;
  font-size: 0.875rem;
}

.op-id {
  margin-left: auto;
  color: var(--muted);
}

.auth {
  padding: 0.05em 0.55em;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 600;
}

.auth-public { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.auth-user { background: var(--accent-soft); color: var(--accent); }
.auth-session { background: color-mix(in srgb, var(--warning) 14%, transparent); color: var(--warning); }

.op-desc {
  margin-top: 1rem;
}

.op-sub {
  margin: 1.5rem 0 0.5rem;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.media-type {
  font-size: 0.875rem;
  color: var(--muted);
}

/* ---------- parameters table ---------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.params,
.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

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

.params tr:last-child td,
.doc-table tr:last-child td {
  border-bottom: 0;
}

.params th,
.doc-table th {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8125rem;
}

.params td > * + * {
  margin-top: 0.35rem;
}

/* Guide tables: keep keys and commands on one line; the box scrolls instead. */
.doc-table {
  background: var(--surface);
}

.doc-table td:first-child {
  white-space: nowrap;
}

.doc-table td:first-child code,
.doc-table td code {
  overflow-wrap: normal;
}

.doc-table td:not(:first-child) {
  min-width: 12rem;
}

/* ---------- schema tree ---------- */

.tree-node > summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.4rem;
  padding: 0.35rem 0.25rem 0.35rem 1.15rem;
  position: relative;
  cursor: pointer;
  list-style: none;
  border-radius: 6px;
}

.tree-node > summary::-webkit-details-marker {
  display: none;
}

.tree-node > summary::before {
  content: "";
  position: absolute;
  left: 0.3rem;
  top: 0.75em;
  width: 0.4rem;
  height: 0.4rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s var(--ease);
}

.tree-node[open] > summary::before {
  transform: rotate(45deg);
}

.tree-node > summary:hover {
  background: var(--surface-2);
}

.tree-node > summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

.tree-root {
  margin-top: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.25rem 0.5rem;
}

.tree {
  padding-left: 0.9rem;
  margin-left: 0.45rem;
  border-left: 1px dashed var(--border);
}

.tree-root > .tree {
  border-left: 0;
  padding-left: 0.25rem;
  margin-left: 0;
}

.tree-props,
.tree-variants {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree-props > li + li,
.tree-variants > li + li {
  border-top: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}

.tree-leaf {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.4rem;
  padding: 0.35rem 0.25rem 0.35rem 1.15rem;
}

.tree-leaf > .tree-desc,
.tree-node > .tree-desc {
  flex-basis: 100%;
}

.tree-name {
  font-weight: 600;
  color: var(--fg);
}

code.tree-name {
  background: transparent;
  padding: 0;
}

.tree-type {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--muted);
}

.tree-req {
  margin-left: 0.35rem;
  color: var(--danger);
  font-size: 0.75rem;
  font-weight: 600;
}

.tree-chip {
  padding: 0 0.4em;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.tree-chip code {
  background: transparent;
  padding: 0;
}

.tree-desc {
  color: var(--muted);
  font-size: 0.875rem;
  padding-left: 1.15rem;
}

.tree-leaf > .tree-desc {
  padding-left: 0;
}

.tree-desc > * + * {
  margin-top: 0.35rem;
}

.tree-note {
  margin: 0.5rem 0 0.25rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
}

code.tree-disc {
  color: var(--accent);
}

.schema-link {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}

/* ---------- responses ---------- */

.responses {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.resp + .resp {
  border-top: 1px solid var(--border);
}

.resp > summary {
  padding: 0.6rem 0.75rem 0.6rem 1.6rem;
}

.resp > summary::before {
  left: 0.7rem;
  top: 1.05em;
}

.resp[open] {
  padding-bottom: 0.75rem;
}

.resp > :not(summary) {
  margin-inline: 0.75rem;
}

.status-reason {
  font-weight: 600;
  font-size: 0.9375rem;
}

.status-desc {
  flex-basis: 100%;
  color: var(--muted);
  font-size: 0.875rem;
}

.resp-headers {
  margin: 0 0 0.5rem;
  padding-left: 1.1rem;
  font-size: 0.875rem;
}

/* ---------- tabs ---------- */

.tabs-box {
  margin-top: 0.5rem;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
}

.tab {
  margin-bottom: -1px;
  padding: 0.4rem 0.8rem;
  border: 1px solid transparent;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
}

.tab:hover {
  color: var(--fg);
}

.tab[aria-selected="true"] {
  border-color: var(--border);
  border-bottom-color: var(--surface);
  background: var(--surface);
  color: var(--fg);
}

.tab-panel > .code-wrap:first-child {
  margin-top: 0.5rem;
}

/* ---------- schemas section ---------- */

.schema {
  margin-top: 0.5rem;
}

.schema > .tree-root {
  background: var(--surface);
}

.schema-name {
  font-weight: 650;
  font-family: var(--font-mono);
  font-size: 0.9375rem;
}

.schema:target > .tree-root {
  border-color: var(--accent);
}

/* ---------- states ---------- */

.docs-loading {
  padding: 3rem 0;
}

.docs-error {
  max-width: 640px;
  padding: 1rem 1.25rem;
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--danger) 9%, var(--surface));
}

.docs-error p + p {
  margin-top: 0.5rem;
}

/* ---------- small screens ---------- */

@media (max-width: 900px) {
  .docs-menu {
    display: inline-flex;
  }

  .docs-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .docs-nav {
    position: fixed;
    inset: var(--docs-header) auto 0 0;
    z-index: 25;
    width: min(320px, 86vw);
    height: auto;
    transform: translateX(-102%);
    visibility: hidden;
    transition: transform 0.2s var(--ease), visibility 0.2s;
    box-shadow: var(--shadow);
  }

  /* Visible at once on opening (so the filter box can take focus straight
     away), and only hidden once the slide out has finished on closing. */
  body.nav-open .docs-nav {
    transform: none;
    visibility: visible;
    transition: transform 0.2s var(--ease);
  }

  body.nav-open::after {
    content: "";
    position: fixed;
    inset: var(--docs-header) 0 0 0;
    z-index: 20;
    background: rgb(0 0 0 / 35%);
  }

  .docs-main {
    padding-top: 1.25rem;
  }
}

@media (max-width: 560px) {
  .docs-header {
    gap: 0.5rem;
    padding-inline: 0.5rem;
  }

  .docs-hide-sm,
  .docs-version {
    display: none;
  }

  .docs-header-actions .btn {
    padding-inline: 0.6em;
  }

  .op {
    padding: 1rem 0.85rem 1.25rem;
    margin-inline: -0.25rem;
  }

  .op-id {
    margin-left: 0;
    flex-basis: 100%;
  }

  .tree {
    padding-left: 0.5rem;
    margin-left: 0.25rem;
  }
}
