/*
 * endpoint.css — Stripe-style API reference rendering for an
 * `endpoint` entity referenced from a page via an entity_ref block.
 *
 * Layout:
 *   .endpoint
 *     .endpoint-header (method badge, path, scope chip, summary)
 *     .endpoint-grid (two columns at lg+)
 *       .endpoint-doc   — description, param tables, errors
 *       .endpoint-side  — tabbed code samples + sample response
 */

.endpoint {
  margin: var(--space-8) 0;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-lg);
  background: hsl(var(--card));
  overflow: hidden;
}

/* ---- Header ---- */
.endpoint-header {
  padding: var(--space-5) var(--space-5);
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--background));
}
.endpoint-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.25;
  margin: 0 0 var(--space-3);
  color: hsl(var(--foreground));
  scroll-margin-top: 6rem; /* sticky-header offset for in-page jumps */
}
.endpoint-anchor-link {
  color: inherit;
  text-decoration: none;
}
.endpoint-anchor-link:hover {
  color: hsl(var(--primary));
}
.endpoint-header-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}
.endpoint-summary {
  margin-top: var(--space-1);
  font-size: var(--text-sm);
  color: hsl(var(--muted-foreground));
  line-height: var(--leading-snug);
}

/* Method badge — coloured per HTTP verb. */
.endpoint-method {
  display: inline-flex;
  align-items: center;
  padding: var(--space-0_5) var(--space-2);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  border: 1px solid transparent;
}
.endpoint-method--get    { color: hsl(142 70% 60%); background: hsl(142 70% 25% / 0.18); border-color: hsl(142 70% 35% / 0.4); }
.endpoint-method--post   { color: hsl(210 90% 70%); background: hsl(210 90% 35% / 0.18); border-color: hsl(210 90% 45% / 0.4); }
.endpoint-method--put    { color: hsl(38 90% 65%);  background: hsl(38 90% 30% / 0.18);  border-color: hsl(38 90% 40% / 0.4);  }
.endpoint-method--patch  { color: hsl(38 90% 65%);  background: hsl(38 90% 30% / 0.18);  border-color: hsl(38 90% 40% / 0.4);  }
.endpoint-method--delete { color: hsl(0 80% 70%);   background: hsl(0 80% 35% / 0.18);   border-color: hsl(0 80% 45% / 0.4);   }

.endpoint-path {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: hsl(var(--foreground));
  background: transparent;
  padding: 0;
}

.endpoint-scope {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-0_5) var(--space-2);
  border-radius: var(--radius-sm);
  border: 1px solid hsl(var(--border));
  background: hsl(var(--muted) / 0.4);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: hsl(var(--muted-foreground));
}
.endpoint-scope svg {
  width: 0.875rem;
  height: 0.875rem;
}

/* ---- Body grid ----
   Two-column only at ≥1440px. Below that the right-rail TOC + left
   sidebar leave the article column too narrow for two side-by-side
   panels (code samples would overflow horizontally). Single-column
   stacks doc above samples and uses full width. */
.endpoint-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
}
@media (min-width: 1440px) {
  .endpoint-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}

.endpoint-doc {
  padding: var(--space-5);
  min-width: 0;
}
@media (min-width: 1440px) {
  .endpoint-doc {
    border-right: 1px solid hsl(var(--border));
  }
}

.endpoint-side {
  padding: var(--space-5);
  background: hsl(var(--background));
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  min-width: 0;  /* lets nested <pre> shrink instead of forcing horizontal scroll */
}

/* ---- Description ---- */
.endpoint-description {
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  color: hsl(var(--foreground) / 0.9);
}

/* ---- Section titles within an endpoint ---- */
.endpoint-section-title {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: hsl(var(--muted-foreground));
  margin: var(--space-6) 0 var(--space-2_5) 0;
}
.endpoint-doc > :first-child + .endpoint-section-title,
.endpoint-doc > .endpoint-section-title:first-child {
  margin-top: 0;
}

/* ---- Param tables ---- */
.endpoint-params {
  margin: var(--space-5) 0 0 0;
}
.endpoint-param-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.endpoint-param-table thead th {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid hsl(var(--border));
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: hsl(var(--muted-foreground));
}
.endpoint-param-table tbody td {
  padding: var(--space-3);
  border-bottom: 1px solid hsl(var(--border) / 0.5);
  vertical-align: top;
}
.endpoint-param-table tbody tr:last-child td {
  border-bottom: 0;
}
/* Param + error descriptions go through the markdown renderer, which
   wraps every block in <p>. The default <p> margins stack on top of
   the cell's padding and produce a visible empty line above the text.
   Strip the first/last <p>'s vertical margins so single-paragraph
   descriptions sit flush with the cell, while multi-paragraph ones
   keep their inter-paragraph spacing. */
.endpoint-param-table tbody td > p:first-child,
.endpoint-error-desc > p:first-child {
  margin-top: 0;
}
.endpoint-param-table tbody td > p:last-child,
.endpoint-error-desc > p:last-child {
  margin-bottom: 0;
}

.endpoint-param-name {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  background: transparent;
  padding: 0;
  color: hsl(var(--foreground));
}
.endpoint-param-required {
  display: inline-block;
  margin-left: var(--space-1_5);
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: hsl(0 80% 70%);
}
.endpoint-param-type {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  background: transparent;
  padding: 0;
  color: hsl(var(--muted-foreground));
}
.endpoint-param-meta {
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  color: hsl(var(--muted-foreground));
}
.endpoint-param-meta code {
  font-family: var(--font-mono);
  background: hsl(var(--muted));
  padding: var(--space-0_5) var(--space-1);
  border-radius: var(--radius-sm);
  font-size: 0.95em;
}

/* ---- Errors list ---- */
.endpoint-errors-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.endpoint-error {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: var(--space-2_5);
  align-items: baseline;
  font-size: var(--text-sm);
}
.endpoint-error-status {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  background: hsl(var(--muted));
  padding: var(--space-0_5) var(--space-1_5);
  border-radius: var(--radius-sm);
}
.endpoint-error-code {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  background: transparent;
  padding: 0;
  color: hsl(var(--foreground));
}
.endpoint-error-desc {
  color: hsl(var(--muted-foreground));
}

/* ---- Tabbed code samples ---- */
.endpoint-code-samples {
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  overflow: hidden;
  background: hsl(0 0% 0% / 0.3);
}
.endpoint-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--card));
}
.endpoint-tab {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  cursor: pointer;
  transition: color 150ms ease, border-color 150ms ease, background-color 150ms ease;
}
.endpoint-tab:hover {
  color: hsl(var(--foreground));
  background: hsl(var(--accent) / 0.4);
}
.endpoint-tab.is-active {
  color: hsl(var(--foreground));
  border-bottom-color: hsl(var(--foreground));
}
.endpoint-tab-panels {
  position: relative;
}
.endpoint-tab-panel {
  display: none;
  margin: 0;
  position: relative;  /* hosts the absolute copy button overlay */
  min-width: 0;
}
.endpoint-tab-panel.is-active {
  display: block;
}
.endpoint-tab-panel pre {
  margin: 0;
  padding: var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: var(--leading-normal);
  color: hsl(var(--foreground) / 0.95);
  overflow-x: auto;  /* long lines scroll inside the pre, not the layout */
  white-space: pre;
  max-width: 100%;
}

/* ---- Response ---- */
.endpoint-response {
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  background: hsl(0 0% 0% / 0.3);
  overflow: hidden;
}
.endpoint-response-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  background: hsl(var(--card));
  border-bottom: 1px solid hsl(var(--border));
}
.endpoint-response-header .endpoint-section-title {
  margin: 0;
}
.endpoint-response-status {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  color: hsl(142 70% 60%);
  background: hsl(142 70% 25% / 0.18);
  padding: var(--space-0_5) var(--space-1_5);
  border-radius: var(--radius-sm);
}
.endpoint-response-body summary {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.endpoint-response-body summary::-webkit-details-marker { display: none; }
.endpoint-response-body summary::before {
  content: "▸ ";
  display: inline-block;
  margin-right: var(--space-1);
  transition: transform 150ms ease;
}
.endpoint-response-body[open] summary::before {
  content: "▾ ";
}
.endpoint-response-body pre {
  margin: 0;
  padding: var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: var(--leading-normal);
  color: hsl(var(--foreground) / 0.9);
  overflow-x: auto;
  white-space: pre;
  border-top: 1px solid hsl(var(--border));
  max-width: 100%;
}
.endpoint-response-body-inner {
  min-width: 0;
}

/* ---- Copy buttons ----
   Two styles:
   - .endpoint-copy-btn — overlay in the top-right corner of a code block
     (used for tab panels + response body).
   - .endpoint-path     — the path itself is a copyable button; text on the
     left, copy icon on the right, swaps to a check on .is-copied.
   Both use .endpoint-copy-icon spans with --done variant so the JS only
   has to toggle .is-copied on the trigger. */

.endpoint-copy-btn {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  opacity: 0;
  transition: opacity 150ms ease, color 150ms ease, background-color 150ms ease;
  z-index: 1;
}
.endpoint-copy-btn svg {
  width: 0.875rem;
  height: 0.875rem;
}
.endpoint-tab-panel,
.endpoint-response-body-inner {
  position: relative;
}
.endpoint-tab-panel:hover .endpoint-copy-btn,
.endpoint-tab-panel.is-active .endpoint-copy-btn,
.endpoint-response-body-inner:hover .endpoint-copy-btn,
.endpoint-copy-btn:focus-visible {
  opacity: 1;
}
.endpoint-copy-btn:hover {
  color: hsl(var(--foreground));
  background: hsl(var(--accent));
}

/* Path is a button itself (so the whole pill is clickable). */
.endpoint-path {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-0_5) var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  color: hsl(var(--foreground));
  transition: background-color 150ms ease, border-color 150ms ease;
}
.endpoint-path:hover {
  background: hsl(var(--muted) / 0.5);
  border-color: hsl(var(--border));
}
.endpoint-path code {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  background: transparent;
  padding: 0;
  color: inherit;
}
.endpoint-path .endpoint-copy-icon {
  display: inline-flex;
  width: 0.875rem;
  height: 0.875rem;
  color: hsl(var(--muted-foreground));
  opacity: 0;
  transition: opacity 150ms ease;
}
.endpoint-path:hover .endpoint-copy-icon,
.endpoint-path:focus-visible .endpoint-copy-icon {
  opacity: 1;
}
.endpoint-path .endpoint-copy-icon svg {
  width: 100%;
  height: 100%;
}

/* Icon swap: default = copy icon, .is-copied = check icon.
   Both icons live in the markup; we just flip which is visible. */
.endpoint-copy-icon--done {
  display: none;
}
.is-copied .endpoint-copy-icon {
  display: none;
}
.is-copied .endpoint-copy-icon--done {
  display: inline-flex;
  color: hsl(142 70% 60%);
  opacity: 1 !important;
}

/* ---- Missing/unknown entity ---- */
.entity-ref--missing,
.entity-ref--unknown {
  margin: var(--space-4) 0;
  padding: var(--space-3) var(--space-4);
  border: 1px dashed hsl(var(--border));
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: hsl(var(--muted-foreground));
}

/* ============================================================
 * Light-theme scope override
 *
 * The endpoint card stays dark even when the page is in light mode —
 * code reference UIs read better on dark regardless of surrounding
 * page theme (Stripe, Vercel, Linear all do this).
 *
 * Mechanism: re-declare the design tokens *inside* the .endpoint /
 * .block-code subtree. Every selector inside the card already uses
 * hsl(var(--foreground)) / hsl(var(--card)) / etc., so scoping the
 * variables here flips the entire component back to dark without
 * touching individual rules.
 * ============================================================ */
:root[data-theme="light"] .endpoint,
:root[data-theme="light"] .block-code {
  --background: 0 0% 4%;
  --foreground: 0 0% 98%;
  --card: 0 0% 7%;
  --card-foreground: 0 0% 98%;
  --popover: 0 0% 7%;
  --popover-foreground: 0 0% 98%;
  --secondary: 0 0% 14%;
  --secondary-foreground: 0 0% 98%;
  --muted: 0 0% 10%;
  --muted-foreground: 0 0% 60%;
  --accent: 0 0% 14%;
  --accent-foreground: 0 0% 98%;
  --border: 0 0% 14%;

  /* Easydocs aliases that rendered with light values get pinned dark too. */
  --color-bg: hsl(0 0% 4%);
  --color-surface: hsl(0 0% 7%);
  --color-surface-raised: hsl(0 0% 7%);
  --color-surface-inset: hsl(0 0% 10%);
  --color-text: hsl(0 0% 98%);
  --color-text-secondary: hsl(0 0% 60%);
  --color-border: hsl(0 0% 14%);
  --color-inline-code-bg: hsl(0 0% 14%);
  --color-inline-code-border: hsl(0 0% 18%);
  --color-inline-code-text: hsl(0 0% 98%);
  --color-code-bg: hsl(0 0% 0% / 0.3);
  --color-code-border: hsl(0 0% 14%);
  --color-code-text: hsl(0 0% 98% / 0.95);
  --color-code-header: hsl(0 0% 7%);
}

/* The card has its own background as a non-token literal so it stays
   dark regardless of where the parent's --card resolves. */
:root[data-theme="light"] .endpoint,
:root[data-theme="light"] .block-code {
  background: hsl(0 0% 7%);
  border-color: hsl(0 0% 14%);
  color: hsl(0 0% 98%);
}
