/* Docs layer — extends styles.css. Loads after it and only adds
   docs-specific layout, reference components, and syntax tokens. */

:root,
[data-theme="dark"] {
  --tok-comment: var(--fg-faint);
  --tok-string: var(--up-text);
  --tok-keyword: var(--focus);
  --tok-number: var(--verifying-text);
  --tok-key: var(--fg);
  --tok-punct: var(--fg-faint);
  --tok-cmd: var(--fg);
  --tok-flag: var(--focus);
  --tok-var: var(--verifying-text);
  --method-post-bg: #002451;
  --method-post-text: #47a8ff;
}

[data-theme="light"] {
  --tok-string: var(--up-text);
  --tok-number: var(--verifying-text);
  --method-post-bg: #e8f1ff;
  --method-post-text: #006bff;
}

/* ---- Layout ---- */

.docs-layout {
  display: grid;
  width: min(1200px, calc(100% - 40px));
  margin-inline: auto;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: clamp(40px, 6vw, 96px);
  align-items: start;
}

.docs-sidebar {
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 72px);
  overflow-y: auto;
  padding: 40px 0 60px;
  scrollbar-width: none;
}

.docs-sidebar::-webkit-scrollbar {
  display: none;
}

.docs-sidebar nav {
  display: grid;
  gap: 28px;
}

.sidebar-group > p {
  margin: 0 0 8px;
  padding-left: 10px;
}

.sidebar-group a {
  display: block;
  padding: 5px 10px;
  border-radius: 6px;
  color: var(--fg-muted);
  font-size: 13px;
  transition:
    color 150ms ease,
    background 150ms ease;
}

.sidebar-group a:hover {
  background: var(--hover);
  color: var(--fg);
}

.sidebar-group a.active {
  background: var(--chip-bg);
  color: var(--fg);
  font-weight: 500;
}

.sidebar-group a.sub {
  display: none;
  padding-left: 22px;
  font-size: 12px;
}

.sidebar-group.expanded a.sub {
  display: block;
}

.docs-main {
  min-width: 0;
  max-width: 820px;
  padding-bottom: 140px;
}

/* ---- Mobile contents bar ---- */

.docs-contents-bar {
  position: sticky;
  z-index: 90;
  top: 62px;
  display: none;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.docs-contents-bar button {
  display: flex;
  width: 100%;
  min-height: 44px;
  align-items: center;
  gap: 8px;
  padding: 0 20px;
  background: transparent;
  color: var(--fg-muted);
  font-size: 13px;
  font-weight: 500;
}

.docs-contents-bar .chevron-icon {
  width: 14px;
  height: 14px;
  transition: transform 200ms ease;
}

.docs-contents-bar button[aria-expanded="true"] .chevron-icon {
  transform: rotate(180deg);
}

/* ---- Article typography ---- */

.docs-hero {
  padding: clamp(48px, 7vw, 88px) 0 clamp(30px, 4vw, 48px);
}

.docs-hero h1 {
  max-width: 640px;
  margin-top: 16px;
  font-size: clamp(38px, 5vw, 54px);
  letter-spacing: -0.045em;
  line-height: 1.02;
}

.docs-hero .lede {
  margin-top: 20px;
  font-size: clamp(16px, 2vw, 19px);
}

.docs-section {
  padding-top: clamp(56px, 7vw, 84px);
}

.docs-section > h2 {
  margin-top: 14px;
  font-size: clamp(28px, 3.4vw, 36px);
  font-weight: 500;
  letter-spacing: -0.045em;
  line-height: 1.05;
}

.docs-section .section-lede {
  max-width: 620px;
  margin-top: 14px;
  color: var(--fg-muted);
  font-size: 15px;
  line-height: 1.55;
}

.docs-sub {
  padding-top: clamp(36px, 5vw, 52px);
}

.docs-sub > h3 {
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.03em;
}

.docs-sub > h4 {
  margin: 28px 0 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.docs-main p {
  color: var(--fg-muted);
  font-size: 14px;
  line-height: 1.65;
}

.docs-sub > p,
.endpoint-doc > p {
  margin-top: 10px;
}

.docs-section > p + p,
.docs-sub > p + p,
.endpoint-doc > p + p,
.step > p + p {
  margin-top: 16px;
}

.docs-main p strong {
  color: var(--fg);
  font-weight: 500;
}

.docs-main code:not(pre code) {
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--code-bg);
  color: var(--fg);
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 12px;
}

/* Chip-bearing text needs taller line boxes so wrapped chips don't touch */
.docs-main :is(p, li, td, dd):has(> code) {
  line-height: 1.9;
}

.docs-main a:not(.sidebar-group a):not(.button) {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: var(--border-hover);
  text-underline-offset: 3px;
  transition: text-decoration-color 150ms ease;
}

.docs-main a:not(.sidebar-group a):not(.button):hover {
  text-decoration-color: var(--fg);
}

.docs-main ul,
.docs-main ol {
  margin: 12px 0 0;
  padding-left: 20px;
  color: var(--fg-muted);
  font-size: 14px;
  line-height: 1.65;
}

.docs-main li + li {
  margin-top: 6px;
}

.docs-main li::marker {
  color: var(--fg-faint);
}

/* Heading anchors */

/* html already applies scroll-padding-top: 71px, and the two offsets add,
   so keep this margin small enough that a clicked heading lands inside the
   scrollspy's 120px detection window */
.anchor-heading {
  position: relative;
  scroll-margin-top: 24px;
}

.anchor-heading .anchor-link {
  position: absolute;
  top: 50%;
  left: -22px;
  color: var(--fg-faint);
  font-weight: 400;
  opacity: 0;
  transform: translateY(-50%);
  transition:
    opacity 150ms ease,
    color 150ms ease;
}

.anchor-heading:hover .anchor-link,
.anchor-link:focus-visible {
  opacity: 1;
}

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

/* ---- Callouts ---- */

.callout {
  display: grid;
  grid-template-columns: 15px minmax(0, 1fr);
  gap: 0 12px;
  margin-top: 20px;
  padding: 14px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
}

.callout > div {
  display: contents;
}

.callout-icon {
  grid-column: 1;
  grid-row: 1;
  align-self: center;
  width: 15px;
  height: 15px;
  color: var(--fg-muted);
}

.callout p {
  grid-column: 2;
  font-size: 13px;
  line-height: 1.6;
}

.callout p:first-child {
  grid-row: 1;
  margin-bottom: 2px;
  color: var(--fg);
  font-weight: 500;
}

.callout p:last-child {
  grid-row: 2;
}

.callout.warn .callout-icon,
.callout.danger .callout-icon {
  transform: translateY(1.5px);
}

.callout.warn .callout-icon {
  color: var(--verifying-text);
}

.callout.danger .callout-icon {
  color: var(--down-text);
}

/* ---- Reference tables ---- */

.ref-table-shell {
  margin-top: 20px;
  overflow-x: auto;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
}

.ref-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.ref-table th {
  height: 38px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border-strong);
  color: var(--fg-faint);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

.ref-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--fg-muted);
  line-height: 1.5;
  vertical-align: top;
}

.ref-table tr:last-child td {
  border-bottom: 0;
}

.ref-table td:first-child {
  color: var(--fg);
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 12px;
  white-space: nowrap;
}

.ref-table .muted {
  color: var(--fg-faint);
}

/* ---- Method badges, scope chips ---- */

.method {
  display: inline-flex;
  align-items: center;
  padding: 3px 7px;
  border-radius: 5px;
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.method.get {
  background: var(--up-bg);
  color: var(--up-text);
}
.method.post {
  background: var(--method-post-bg);
  color: var(--method-post-text);
}
.method.patch {
  background: var(--verifying-bg);
  color: var(--verifying-text);
}
.method.delete {
  background: var(--down-bg);
  color: var(--down-text);
}

.scope-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--fg-muted);
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 10px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}

/* ---- Code blocks ---- */

.code-block {
  overflow: hidden;
  margin: 20px 0 0;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--code-bg);
}

.code-block figcaption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  padding: 0 8px 0 14px;
  border-bottom: 1px solid var(--border);
}

.code-lang {
  color: var(--fg-faint);
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.code-tabs {
  display: flex;
  gap: 2px;
}

.code-tab {
  min-height: 26px;
  padding: 0 10px;
  border-radius: 5px;
  background: transparent;
  color: var(--fg-faint);
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  transition:
    color 150ms ease,
    background 150ms ease;
}

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

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

.code-copy {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  border-radius: 5px;
  background: transparent;
  color: var(--fg-faint);
  font-size: 11px;
  font-weight: 500;
  transition:
    color 150ms ease,
    background 150ms ease;
}

.code-copy:hover {
  background: var(--hover);
  color: var(--fg);
}

.code-copy.success {
  color: var(--up-text);
}

.code-block pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
}

.code-block code {
  display: block;
  color: var(--fg);
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.7;
  white-space: pre;
}

.code-tab-panel code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.tok-comment {
  color: var(--tok-comment);
}
.tok-string {
  color: var(--tok-string);
}
.tok-keyword {
  color: var(--tok-keyword);
}
.tok-number {
  color: var(--tok-number);
}
.tok-key {
  color: var(--tok-key);
  font-weight: 500;
}
.tok-punct {
  color: var(--tok-punct);
}
.tok-cmd {
  color: var(--tok-cmd);
  font-weight: 500;
}
.tok-flag {
  color: var(--tok-flag);
}
.tok-var {
  color: var(--tok-var);
}

/* ---- API endpoint rows ---- */

.endpoint {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: clamp(24px, 3vw, 44px);
  padding: 36px 0;
  border-top: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
  margin-top: 36px;
}

.endpoint-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 14px;
  font-weight: 500;
}

.endpoint-title .path {
  padding: 0;
  border: 0;
  background: none;
  color: var(--fg);
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 13px;
}

.endpoint-doc .scope-chip {
  margin-top: 12px;
}

.endpoint-doc .ref-table-shell {
  margin-top: 18px;
}

.endpoint-code {
  min-width: 0;
}

.endpoint-code .code-block:first-child {
  margin-top: 0;
}

/* ---- Deploy steps ---- */

.step-list {
  display: grid;
  margin-top: 8px;
}

.step {
  position: relative;
  padding: 26px 0 26px 44px;
}

.step + .step {
  border-top: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}

.step-index {
  position: absolute;
  top: 26px;
  left: 0;
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--fg-muted);
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 11px;
}

.step > h4 {
  margin: 2px 0 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.step > p {
  margin-top: 8px;
}

/* ---- Email previews ---- */

.email-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-top: 20px;
}

.email-preview {
  display: grid;
  grid-template-areas:
    "title meta"
    "body  lines"
    "cta   lines"
    "foot  foot";
  grid-template-columns: minmax(0, 1fr) minmax(180px, auto);
  column-gap: 32px;
  padding: 20px 22px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--bg);
  box-shadow: 0 1px 2px rgb(0 0 0 / 14%);
}

.email-preview .email-meta {
  grid-area: meta;
  justify-content: flex-end;
  gap: 12px;
}

.email-preview h4 {
  grid-area: title;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.email-preview > p:not(.email-lines) {
  grid-area: body;
  margin-top: 6px;
  font-size: 12.5px;
  line-height: 1.55;
}

.email-preview .email-lines {
  grid-area: lines;
  align-self: end;
  margin: 0;
  color: var(--fg-faint);
  font-size: 11px;
  line-height: 1.7;
  text-align: right;
}

.email-cta {
  grid-area: cta;
  display: inline-flex;
  justify-self: start;
  margin-top: 14px;
  padding: 6px 11px;
  border-radius: 6px;
  background: var(--primary-bg);
  color: var(--primary-fg);
  font-size: 11px;
  font-weight: 500;
}

.email-foot {
  grid-area: foot;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--fg-muted);
  font-size: 11px;
}

.email-foot .status-dot {
  width: 7px;
  height: 7px;
}

/* ---- Misc docs components ---- */

.docs-main kbd {
  padding: 2px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface-raised);
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 11px;
}

/* ---- Screen skeletons ---- */

.ui-mock {
  margin-top: 16px;
}

.ui-mock .dv-head {
  justify-content: flex-start;
}

.ui-mock .dv-head span:not(.dv-live) {
  color: var(--fg-faint);
}

.sk-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
}

.sk-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--surface-raised);
}

.sk-bar.faint {
  height: 6px;
  background: var(--surface);
}

.sk-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sk-row.between {
  justify-content: space-between;
}

.sk-col {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 6px;
}

.sk-list > .sk-row,
.sk-tr {
  padding: 9px 0;
}

.sk-list > .sk-row + .sk-row,
.sk-list > .sk-tr + .sk-tr {
  border-top: 1px solid var(--border);
}

.sk-thead,
.sk-tr {
  display: grid;
  grid-template-columns: var(--cols, 1fr);
  align-items: center;
  gap: 10px;
}

.sk-pill {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  height: 16px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-raised);
  color: var(--fg-faint);
  font-size: 10px;
  white-space: nowrap;
}

.sk-pill.active {
  background: var(--hover);
  color: var(--fg-muted);
}

.sk-btn {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  height: 22px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--fg-muted);
  font-size: 11px;
  white-space: nowrap;
}

.sk-btn.primary {
  border-color: transparent;
  background: var(--primary-bg);
  color: var(--primary-fg);
}

.sk-label {
  color: var(--fg-faint);
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sk-title {
  color: var(--fg);
  font-size: 13px;
  font-weight: 600;
}

.sk-note {
  color: var(--fg-muted);
  font-size: 12px;
}

.sk-dot-step {
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--border-strong);
}

.sk-dot-step.active {
  background: var(--fg);
}

.ui-mock .code-tabs {
  padding: 8px 14px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
}

.sk-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}

.sk-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sk-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 10px;
}

.sk-cols {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

.sk-thead {
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-strong);
}

.sk-thead span {
  color: var(--fg-faint);
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sk-segments {
  display: flex;
  flex: 1;
  gap: 2px;
  height: 14px;
}

.sk-segments span {
  flex: 1;
  border-radius: 2px;
  background: var(--up);
  opacity: 0.45;
}

.sk-segments span.down {
  background: var(--down);
  opacity: 0.9;
}

.sk-segments span.verifying {
  background: var(--verifying);
  opacity: 0.9;
}

.sk-spark {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 40px;
}

.sk-spark span {
  flex: 1;
  border-radius: 1px;
  background: var(--surface-raised);
}

.sk-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 120px;
  flex: 0 0 auto;
  padding-right: 14px;
  border-right: 1px solid var(--border);
}

.sk-nav-item {
  display: flex;
  align-items: center;
  padding: 7px 8px;
  border-radius: 5px;
  color: var(--fg-muted);
  font-size: 12px;
}

.sk-nav-item.active {
  background: var(--hover);
  color: var(--fg);
}

.sk-shell {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

/* ---- Responsive ---- */

@media (max-width: 860px) {
  .docs-layout {
    grid-template-columns: 1fr;
    width: min(100% - 28px, 1360px);
  }

  .docs-contents-bar {
    display: block;
  }

  .docs-sidebar {
    position: fixed;
    z-index: 89;
    top: 106px;
    right: 14px;
    left: 14px;
    display: none;
    max-height: min(60vh, 520px);
    padding: 14px;
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    background: var(--bg);
    box-shadow: var(--shadow);
  }

  .docs-sidebar.open {
    display: block;
  }

  .docs-main {
    max-width: none;
  }

  .endpoint {
    grid-template-columns: 1fr;
  }

  .email-preview {
    grid-template-areas:
      "meta"
      "title"
      "body"
      "lines"
      "cta"
      "foot";
    grid-template-columns: 1fr;
  }

  .email-preview .email-meta {
    justify-content: space-between;
  }

  .email-preview h4 {
    margin-top: 12px;
  }

  .email-preview .email-lines {
    margin-top: 10px;
    text-align: left;
  }

  .anchor-heading .anchor-link {
    display: none;
  }
}
