/*
 * The reference view — and, because the guides use the same two-column shell,
 * theirs as well.
 *
 * Tokens, the top bar, the wordmark and the buttons are in `shell.css`, which
 * every view shares. What is here is the reading layout: the contents rail,
 * the endpoint list, the schema tree, the live demos, and the delivery-option
 * rows (`.co…`) that the front page and the toolbox draw too — one option row
 * looks the same wherever it appears.
 *
 * `.ref-layout` and `.ref-empty` are renamed from `.layout` and `.empty` for
 * the same reason: the toolbox had its own, differently sized, and one page
 * cannot have two.
 */

/* ── Layout ───────────────────────────────────────────────────────────── */

.ref-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: 28px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 22px 18px 100px;
}

/*
 * The contents rail lives inside a `<details>`.
 *
 * On a wide screen the disclosure is invisible furniture: `js/main.js` holds it
 * open, the summary is hidden, and this is the sticky column it always was. On
 * a phone the rail used to stack ABOVE the article, which put thirty-odd
 * endpoint links between the reader and the first sentence — so there it
 * collapses to a single row that says "Contents", and closes itself again once
 * a link is followed.
 */
.contents {
  position: sticky;
  top: calc(var(--header-h) + 22px);
  align-self: start;
  max-height: calc(100vh - var(--header-h) - 44px);
  overflow-y: auto;
  padding-right: 6px;
}

.contents-toggle {
  display: none;
}

.sidebar {
  min-width: 0;
}

.sidebar h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
  margin: 16px 0 6px;
}

.sidebar h3:first-child {
  margin-top: 0;
}

/*
 * Grid rather than flex, for the same reason the method is pinned rather than
 * baseline-aligned: the path is allowed to WRAP now, and a wrapped second line
 * must not run back underneath the method badge.
 */
.sidebar a {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: start;
  gap: 4px 8px;
  padding: 5px 8px;
  border-radius: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.4;
}

.sidebar a:hover {
  background: var(--surface-2);
  color: var(--text);
}

.sidebar a.active {
  position: relative;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
}

.sidebar a.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 5px;
  bottom: 5px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--violet);
}

.sidebar .sb-method {
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 700;
  line-height: 1.95;
  letter-spacing: 0.03em;
  color: var(--text-faint);
}

/* Four methods, four colours. In a list of 33 rows this is what turns reading
   into scanning — and it is the one place a non-brand colour is the right
   answer, because "green means POST" is older than any of our palettes. */
.sidebar .sb-method[data-method="GET"] {
  color: var(--get);
}
.sidebar .sb-method[data-method="POST"] {
  color: var(--post);
}
.sidebar .sb-method[data-method="PUT"],
.sidebar .sb-method[data-method="PATCH"] {
  color: var(--put);
}
.sidebar .sb-method[data-method="DELETE"] {
  color: var(--delete);
}

/*
 * The path wraps instead of being clipped with an ellipsis. Truncating the END
 * of an API path removes exactly the part that distinguishes it: five of these
 * begin `/profile/managerships/`, and the old rule rendered them as five
 * identical rows reading `/profile/managerships/{managersh…`. Mono, because
 * these are literals, and `overflow-wrap` so a long segment breaks rather than
 * widening the column.
 */
.sidebar .sb-path {
  font-family: var(--mono);
  font-size: 12px;
  overflow-wrap: anywhere;
}

/* The one row that is prose and not a path. */
.sidebar a:not(:has(.sb-method)) {
  grid-template-columns: minmax(0, 1fr);
}

.sidebar a:not(:has(.sb-method)) .sb-path {
  font-family: inherit;
  font-size: 13px;
}

main {
  min-width: 0;
}

@media (max-width: 900px) {
  .ref-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
    padding: 14px 14px 72px;
  }

  .contents {
    position: static;
    max-height: none;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
  }

  .contents-toggle {
    display: block;
    padding: 11px 14px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    list-style: none;
  }

  /* Two selectors, because Safari still uses the WebKit pseudo-element for
     the marker and ignores `list-style: none` on a summary. */
  .contents-toggle::-webkit-details-marker {
    display: none;
  }

  .contents-toggle::after {
    content: "▾";
    float: right;
    color: var(--text-faint);
  }

  .contents[open] .contents-toggle::after {
    content: "▴";
  }

  .contents[open] .contents-toggle {
    border-bottom: 1px solid var(--border);
  }

  .sidebar {
    padding: 10px 8px 12px;
    max-height: 60vh;
    overflow-y: auto;
  }
}

/* ── Prose ────────────────────────────────────────────────────────────── */

.prose {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  margin-bottom: 14px;
  scroll-margin-top: calc(var(--header-h) + 16px);
}

.prose:last-of-type {
  margin-bottom: 24px;
}

/* The first `h2` in a section is the section's own title and needs no space
   above it — that space is the card's padding. Inside one, it still does. */
.prose > h2:first-child {
  margin-top: 0;
}

.prose h1 {
  font-size: 30px;
  line-height: 1.1;
  margin-bottom: 10px;
}

.prose h2 {
  font-size: 20px;
  margin: 28px 0 10px;
}

.prose p {
  margin: 0 0 12px;
  max-width: 68ch;
}

.prose ul {
  margin: 0 0 12px;
  padding-left: 20px;
  max-width: 68ch;
}

.prose li {
  margin-bottom: 5px;
}

.lede {
  font-size: 16px;
  color: var(--text-muted);
}

table.simple {
  width: 100%;
  border-collapse: collapse;
  margin: 4px 0 14px;
  font-size: 13.5px;
}

table.simple th,
table.simple td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.simple th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
}

.scroll-x {
  overflow-x: auto;
}

/* ── Endpoints ────────────────────────────────────────────────────────── */

.group-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
  margin: 28px 0 10px;
}

.endpoint {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  scroll-margin-top: calc(var(--header-h) + 16px);
  overflow: hidden;
}

.endpoint-head {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 13px 16px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.endpoint-head:hover {
  background: var(--surface-2);
}

.method {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text-muted);
}

.method[data-m="GET"] {
  background: var(--get-soft);
  color: var(--get);
}

.method[data-m="POST"] {
  background: var(--post-soft);
  color: var(--post);
}

.method[data-m="PUT"] {
  background: var(--put-soft);
  color: var(--put);
}

.method[data-m="DELETE"] {
  background: var(--delete-soft);
  color: var(--delete);
}

.ep-path {
  font-family: var(--mono);
  font-size: 13.5px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.ep-summary {
  flex: 1;
  min-width: 0;
  color: var(--text-muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.endpoint-body {
  padding: 0 16px 16px;
  border-top: 1px solid var(--border);
}

.endpoint-body h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin: 18px 0 6px;
}

.tag {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  white-space: nowrap;
}

.tag[data-tone="danger"] {
  background: var(--danger-soft);
  color: var(--danger);
}

.tag[data-tone="warn"] {
  background: var(--warn-soft);
  color: var(--warn);
}

.tag[data-tone="ok"] {
  background: var(--ok-soft);
  color: var(--ok);
}

.tag[data-tone="info"] {
  background: var(--brand-soft);
  color: var(--brand);
}

.note {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  margin: 12px 0;
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 13.5px;
}

.note[data-tone="danger"] {
  border-left-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

.note[data-tone="warn"] {
  border-left-color: var(--warn);
  background: var(--warn-soft);
  color: var(--warn);
}

.note[data-tone="info"] {
  border-left-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand);
}

pre.code {
  margin: 0 0 12px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  line-height: 1.5;
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

/* ── Live demos ───────────────────────────────────────────────────────── */

/*
 * The banner that says whose account the Run buttons call. Lavender, not the
 * amber of a warning: this is an offer, not a caveat, and the caveats inside
 * it read better when the block is not already shouting.
 */
.demo-banner {
  margin: 18px 0 22px;
  padding: 16px 18px;
  border: 1px solid var(--brand-line);
  border-radius: var(--radius);
  background: var(--brand-soft);
}

.demo-banner-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
  color: var(--brand);
}

.demo-banner-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--violet);
}

.demo-banner p:last-child {
  margin-bottom: 0;
}

.demo {
  margin-bottom: 14px;
}

.demo-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}

/* The exact request the button will send, shown before it is sent. */
.demo-url {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.demo-run:disabled {
  opacity: 0.6;
  cursor: progress;
}

.demo-sent {
  max-height: 220px;
  overflow: auto;
}

.demo-status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 12.5px;
}

.demo-code {
  padding: 2px 8px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--text-muted);
}

.demo-status[data-ok="true"] .demo-code {
  background: var(--ok-soft);
  color: var(--ok);
}

.demo-status[data-ok="false"] .demo-code {
  background: var(--danger-soft);
  color: var(--danger);
}

/*
 * A response is capped rather than left to run: `/agreements` answers 108 kB,
 * and an uncapped `<pre>` pushed every endpoint below it off the end of the
 * page. It scrolls in place instead.
 */
.demo-body {
  max-height: 380px;
  overflow: auto;
  margin-bottom: 0;
}

.demo-none {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Delivery options ─────────────────────────────────────────────────── */

/*
 * The checkout mock. It is styled as a CONTROL, not as a code sample: the
 * point of the tab is that these are the rows a buyer sees, and a JSON dump
 * with a border would have made that point badly.
 */
.co {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.co-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(var(--surface-2), var(--surface));
  font-size: 13.5px;
}

.co-list {
  display: flex;
  flex-direction: column;
}

.co-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.co-option:last-child {
  border-bottom: 0;
}

.co-option:hover {
  background: var(--brand-soft);
}

.co-option:has(input:checked) {
  background: var(--brand-soft);
  box-shadow: inset 3px 0 0 var(--violet);
}

.co-option input {
  accent-color: var(--brand);
  width: 16px;
  height: 16px;
  margin: 0;
}

.co-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.co-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 14px;
}

.co-carrier {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.co-meta {
  font-size: 12.5px;
  color: var(--text-muted);
}

.co-price {
  font-size: 14.5px;
  font-weight: 700;
  white-space: nowrap;
}

.co-distance {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.co-errors {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 12.5px;
}

.co-errors-note {
  display: block;
  margin-top: 6px;
  color: var(--text-muted);
}

.co-note {
  margin: 10px 0 0;
  padding: 0 16px 14px;
  font-size: 12.5px;
}

.demo-raw {
  margin-top: 12px;
}

.demo-raw summary {
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text-muted);
}

.demo-raw summary:hover {
  color: var(--brand);
}

.demo-raw pre {
  margin-top: 10px;
}

/* ── Schema tree ──────────────────────────────────────────────────────── */

.schema {
  font-family: var(--mono);
  font-size: 12.8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--surface-2);
  overflow-x: auto;
}

.schema ul {
  list-style: none;
  margin: 0;
  padding-left: 16px;
}

.schema > ul {
  padding-left: 0;
}

.schema li {
  padding: 1px 0;
}

.field-name {
  color: var(--get);
  font-weight: 600;
}

.field-type {
  color: var(--text-muted);
}

.field-req {
  color: var(--danger);
  font-weight: 700;
}

.field-enum {
  color: var(--post);
}

.field-desc {
  display: block;
  padding-left: 16px;
  color: var(--text-faint);
  font-family: inherit;
  white-space: pre-wrap;
}

.toggle {
  border: 0;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  font: inherit;
  padding: 0 4px 0 0;
}

.muted {
  color: var(--text-muted);
}

.loading {
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
}

.ref-empty {
  padding: 30px;
  text-align: center;
  color: var(--text-muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

footer.page-foot {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 18px 60px;
  color: var(--text-faint);
  font-size: 12.5px;
}
