/* ─── API documentation page (/data/api) ──────────────────────────────
   Builds on lightcurves-page.css for the portal shell (top navbar,
   left sidebar, logo). Everything here is scoped to body.api-page.     */

body.api-page {
  --api-ink: #1a1a1a;
  --api-ink-2: #4a4a52;
  --api-ink-3: #7a7a85;
  --api-line: #e4e4ea;
  --api-surface: #ffffff;
  --api-tint: #f3f3f6;
  --api-green: #0b6e4f;
  --api-green-bg: #e0f3e9;
  --api-red: #a8321f;
  --api-red-bg: #fbe9e5;
  --api-link: #2f5fa8;
  --api-quote: #8FA8FF;

  --code-bg: #1e1e1e;
  --code-bg-2: #262628;
  --code-line: #343437;
  --code-ink: #d4d4d4;
  --code-ink-2: #8f8f96;

  --mono: 'Source Code Pro', 'Courier New', monospace;
  --nav-h: 100px;
}

/* ─── Sidebar: table of contents ─────────────────────────────────── */
body.api-page #lightcurves-navigation.api-sidebar {
  gap: 0;
  justify-content: space-between;
  overflow-y: auto;
}

.api-toc {
  width: 100%;
}

.api-toc-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--api-ink-3);
  margin: 0 0 12px 12px;
}

.api-toc-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.api-toc-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--api-ink-2);
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.api-toc-link:hover {
  color: var(--api-ink);
  background-color: var(--api-tint);
}

.api-toc-link.is-current {
  color: var(--api-ink);
  background-color: #E9E9ED;
  font-weight: 600;
}

.api-toc-method {
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--api-green);
  background: var(--api-green-bg);
  border-radius: 4px;
  padding: 2px 5px;
}

.api-key-card {
  width: 100%;
  margin-top: 24px;
  padding: 16px;
  border: 1px solid var(--api-line);
  border-radius: 12px;
  background: #fafafb;
  font-size: 0.85rem;
  color: var(--api-ink-2);
  line-height: 1.45;
}

.api-key-card-title {
  font-weight: 600;
  color: var(--api-ink);
  margin-bottom: 4px;
}

.api-key-card-btn {
  display: inline-block;
  margin-top: 10px;
  padding: 7px 12px;
  border-radius: 8px;
  background: var(--api-green-bg);
  color: var(--api-green);
  font-weight: 700;
  font-size: 0.82rem;
  text-decoration: none;
  transition: background-color 0.15s ease;
}

.api-key-card-btn:hover {
  background: #d0e3d9;
}

/* ─── Main column ────────────────────────────────────────────────── */
body.api-page main.api-docs {
  margin-top: var(--nav-h);
  padding: 56px 56px 120px;
  color: var(--api-ink);
}

.api-docs code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--api-tint);
  border: 1px solid var(--api-line);
  border-radius: 5px;
  padding: 1px 5px;
  white-space: nowrap;
}

.api-docs a {
  color: var(--api-link);
  text-decoration: underline;
  text-decoration-color: rgba(47, 95, 168, 0.3);
  text-underline-offset: 3px;
}

.api-docs a:hover {
  text-decoration-color: currentColor;
}

.api-section {
  max-width: 1240px;
  margin: 0 auto;
  padding: 56px 0;
  border-top: 1px solid var(--api-line);
  scroll-margin-top: calc(var(--nav-h) + 16px);
}

.api-section.api-hero {
  border-top: none;
  padding-top: 8px;
}

/* ─── Hero ───────────────────────────────────────────────────────── */
.api-kicker {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--api-green);
  margin-bottom: 10px;
}

.api-title {
  font-size: clamp(2.1rem, 3.4vw, 2.9rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.05;
  margin-bottom: 16px;
}

.api-lede {
  max-width: 640px;
  font-size: 1.12rem;
  line-height: 1.6;
  color: var(--api-ink-2);
}

.api-steps {
  margin-top: 36px;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.api-step {
  position: relative;
  padding: 22px 22px 20px;
  background: var(--api-surface);
  border: 1px solid var(--api-line);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(20, 20, 40, 0.04);
}

.api-step-num {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  margin-bottom: 14px;
  border-radius: 50%;
  background: var(--api-ink);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
}

.api-step h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.api-step p {
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--api-ink-2);
}

.api-step code {
  white-space: normal;
  word-break: break-word;
}

.api-docs .api-step-cmd {
  display: block;
  margin-top: 10px;
  padding: 8px 10px;
  /* wrap only at the space after "export", never inside the variable or key */
  white-space: normal;
  font-size: 0.8rem;
  line-height: 1.5;
}

.api-docs .api-step-cmd span {
  white-space: nowrap;
}

/* ─── Section layout: prose + sticky code panel ──────────────────── */
.api-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 520px);
  gap: 48px;
  align-items: start;
}

.api-prose {
  max-width: 640px;
  font-size: 0.98rem;
  line-height: 1.65;
  color: var(--api-ink-2);
}

.api-prose-wide {
  max-width: 880px;
}

.api-prose > p + p {
  margin-top: 14px;
}

.api-h2 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
  margin-bottom: 14px;
}

.api-docs .api-h2 a {
  color: var(--api-ink);
  text-decoration: none;
}

.api-docs .api-h2 a::after {
  content: "#";
  margin-left: 10px;
  color: var(--api-ink-3);
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.api-docs .api-h2 a:hover::after,
.api-docs .api-h2 a:focus-visible::after {
  opacity: 1;
}

.api-h3 {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--api-ink);
  margin: 36px 0 12px;
}

.api-muted {
  font-size: 0.92rem;
  color: var(--api-ink-3);
  margin-bottom: 14px;
}

.api-endpoint {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  padding: 6px 12px 6px 6px;
  background: var(--api-surface);
  border: 1px solid var(--api-line);
  border-radius: 10px;
}

.api-docs .api-endpoint code {
  border: none;
  background: none;
  padding: 0;
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--api-ink);
}

.api-method {
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--api-green);
  background: var(--api-green-bg);
  border-radius: 6px;
  padding: 4px 8px;
}

.api-callout {
  margin: 18px 0;
  padding: 14px 16px;
  background: #F7F9FC;
  border-left: 4px solid var(--api-quote);
  border-radius: 0 10px 10px 0;
  font-size: 0.93rem;
  line-height: 1.55;
}

.api-callout strong {
  color: var(--api-ink);
}

/* ─── Parameter lists ────────────────────────────────────────────── */
.api-params {
  border-top: 1px solid var(--api-line);
}

.api-param {
  padding: 14px 0;
  border-bottom: 1px solid var(--api-line);
}

.api-param dt {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.api-docs .api-param dt code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--api-ink);
}

.api-type {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--api-ink-3);
}

.api-req {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--api-red);
  background: var(--api-red-bg);
  border-radius: 4px;
  padding: 1px 6px;
}

.api-param dd {
  font-size: 0.93rem;
  line-height: 1.55;
}

/* ─── Tables ─────────────────────────────────────────────────────── */
.api-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  background: var(--api-surface);
  border: 1px solid var(--api-line);
  border-radius: 12px;
  overflow: hidden;
  border-spacing: 0;
}

.api-table th {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--api-ink-3);
  background: #fafafb;
  padding: 10px 14px;
  border-bottom: 1px solid var(--api-line);
}

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

.api-table tr:last-child td {
  border-bottom: none;
}

.api-table td:first-child {
  width: 34%;
  white-space: nowrap;
}

.api-flags td:first-child {
  width: 64px;
}

/* ─── Status pills ───────────────────────────────────────────────── */
.api-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 600;
}

.api-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.api-status-ok { color: #2e9d6d; }
.api-status-err { color: #d05a43; }

/* ─── Code panels ────────────────────────────────────────────────── */
.api-panel-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.api-sticky {
  position: sticky;
  top: calc(var(--nav-h) + 24px);
}

.api-panel {
  background: var(--code-bg);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 12px 32px -12px rgba(10, 10, 30, 0.35);
}

.api-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  padding: 0 10px 0 16px;
  background: var(--code-bg-2);
  border-bottom: 1px solid var(--code-line);
}

.api-panel-title {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--code-ink-2);
}

.api-panel-note {
  padding: 10px 16px 14px;
  font-size: 0.76rem;
  line-height: 1.5;
  color: var(--code-ink-2);
  border-top: 1px solid var(--code-line);
}

.api-docs .api-panel-note code {
  background: #2c2c2f;
  border-color: #3a3a3e;
  color: var(--code-ink);
}

.api-code {
  margin: 0;
  padding: 16px 18px 18px;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.65;
  color: var(--code-ink);
  white-space: pre;
  overflow-x: auto;
  tab-size: 2;
  max-height: 460px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #4a4a4f transparent;
}

.api-code[hidden],
.api-panel-note[hidden] {
  display: none;
}

/* Syntax colours: same family as the old Frames CLI box */
.tok-cmd  { color: #4ec9b0; }
.tok-flag { color: #569cd6; }
.tok-str  { color: #ce9178; }
.tok-url  { color: #dcdcaa; }
.tok-key  { color: #9cdcfe; }
.tok-num  { color: #b5cea8; }
.tok-kw   { color: #c586c0; }
.tok-lit  { color: #569cd6; }
.tok-com  { color: #6a9955; font-style: italic; }
.tok-punc { color: #8f8f96; }

/* Language tabs */
.api-tabs {
  display: flex;
  gap: 2px;
  align-self: stretch;
}

.api-tab {
  position: relative;
  padding: 0 12px;
  background: none;
  border: none;
  font: 500 0.82rem 'Inter', sans-serif;
  color: var(--code-ink-2);
  cursor: pointer;
  transition: color 0.15s ease;
}

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

.api-tab.is-active {
  color: #fff;
}

.api-tab.is-active::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: #4ec9b0;
}

.api-copy {
  padding: 6px 12px;
  border: 1px solid #3c3c40;
  border-radius: 7px;
  background: #2e2e31;
  color: var(--code-ink);
  font: 500 0.78rem 'Inter', sans-serif;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.api-copy:hover {
  background: #38383c;
}

.api-copy.is-done {
  color: #7fdcb5;
  border-color: #2e6b55;
}

/* Request builder fields */
.api-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
  padding: 14px 16px 16px;
  border-bottom: 1px solid var(--code-line);
  background: #222224;
}

.api-fields label,
.api-flagpick legend {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--code-ink-2);
}

/* Label text + hint on one line, so every field's input starts at the same height */
.api-field-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.api-field-hint {
  display: inline;
  margin-left: 4px;
  font-weight: 400;
  color: #67676e;
}

.api-field-wide {
  grid-column: 1 / -1;
}

.api-fields input[type="text"],
.api-fields select {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  background: #171718;
  border: 1px solid #3a3a3e;
  border-radius: 7px;
  color: #ececec;
  font: 0.82rem var(--mono);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.api-fields select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #8f8f96 50%), linear-gradient(135deg, #8f8f96 50%, transparent 50%);
  background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 26px;
}

.api-fields input[type="text"]::placeholder {
  color: #5c5c63;
}

.api-fields input[type="text"]:focus,
.api-fields select:focus {
  outline: none;
  border-color: #4ec9b0;
  box-shadow: 0 0 0 3px rgba(78, 201, 176, 0.15);
}

.api-fields input.is-invalid {
  border-color: #d05a43;
}

.api-fields .api-check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  align-self: end;
  height: 34px;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--code-ink);
  cursor: pointer;
}

.api-check input,
.api-flagpick input {
  accent-color: #4ec9b0;
}

.api-flagpick {
  border: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.api-flagpick legend {
  flex-direction: row;
  gap: 6px;
  margin-bottom: 6px;
  padding: 0;
}

.api-flagpick label {
  flex-direction: row;
  cursor: pointer;
}

.api-flagpick label input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.api-flagpick label span {
  min-width: 34px;
  padding: 5px 8px;
  text-align: center;
  border: 1px solid #3a3a3e;
  border-radius: 7px;
  background: #171718;
  font: 500 0.78rem var(--mono);
  color: var(--code-ink-2);
  transition: all 0.15s ease;
}

.api-flagpick label input:checked + span {
  color: #0f2b23;
  background: #4ec9b0;
  border-color: #4ec9b0;
}

.api-flagpick label input:focus-visible + span {
  box-shadow: 0 0 0 3px rgba(78, 201, 176, 0.3);
}

.api-fields .api-check:has(input:disabled),
.api-flagpick:has(input:disabled) {
  opacity: 0.4;
  cursor: not-allowed;
}

.api-flagpick label:has(input:disabled) {
  pointer-events: none;
}

/* Format segmented control */
.api-seg {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}

.api-seg-label {
  margin-right: 8px;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--code-ink-2);
}

.api-seg button {
  padding: 5px 11px;
  border: 1px solid #3a3a3e;
  border-radius: 7px;
  background: transparent;
  color: var(--code-ink-2);
  font: 500 0.78rem 'Inter', sans-serif;
  cursor: pointer;
  transition: all 0.15s ease;
}

.api-seg button:hover {
  color: var(--code-ink);
}

.api-seg button.is-active {
  background: #ececec;
  border-color: #ececec;
  color: #1a1a1a;
}

/* ─── Limits ─────────────────────────────────────────────────────── */
.api-quota {
  margin: 8px 0 16px;
  padding: 20px 24px;
  background: var(--api-surface);
  border: 1px solid var(--api-line);
  border-radius: 14px;
}

.api-quota-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--api-ink);
  margin-bottom: 4px;
}

.api-quota p + p {
  font-size: 0.93rem;
  line-height: 1.55;
}

.api-tips {
  padding-left: 20px;
}

.api-tips li + li {
  margin-top: 8px;
}

.api-quote {
  margin-top: 16px;
  padding: 16px 20px;
  background: #F7F9FC;
  border-left: 4px solid var(--api-quote);
  border-radius: 0 10px 10px 0;
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--api-ink);
}

/* ─── Entrance motion ────────────────────────────────────────────── */
@media (prefers-reduced-motion: no-preference) {
  .api-hero > * {
    animation: api-rise 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) both;
  }
  .api-hero > :nth-child(2) { animation-delay: 0.05s; }
  .api-hero > :nth-child(3) { animation-delay: 0.1s; }
  .api-hero > :nth-child(4) { animation-delay: 0.15s; }
  .api-hero > :nth-child(5) { animation-delay: 0.2s; }

  @keyframes api-rise {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: none; }
  }
}

/* ─── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 1280px) {
  .api-split {
    grid-template-columns: minmax(0, 1fr);
    gap: 28px;
  }
  .api-sticky {
    position: static;
  }
  .api-prose {
    max-width: 760px;
  }
  .api-panel-col {
    max-width: 760px;
  }
}

@media (max-width: 900px) {
  body.api-page #lightcurves-navigation.api-sidebar {
    display: none;
  }
  body.api-page #top-navbar {
    left: 0;
    width: 100%;
    padding: 0 16px;
  }
  body.api-page .top-nav-links {
    margin-left: 0;
    gap: 8px;
  }
  body.api-page main.api-docs {
    margin-left: 0;
    padding: 40px 24px 96px;
  }
  .api-steps {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 600px) {
  body.api-page {
    --nav-h: 64px;
  }
  body.api-page #top-navbar {
    height: var(--nav-h);
  }
  body.api-page .top-nav-btn,
  body.api-page .top-nav-btn.active {
    font-size: 15px;
    padding: 8px 10px;
  }
  body.api-page .user-greeting {
    display: none;
  }
  body.api-page .top-nav-btn.account-btn {
    margin-left: 0 !important;
    font-size: 13px;
    padding: 7px 10px;
  }
  body.api-page main.api-docs {
    padding: 28px 16px 80px;
  }
  .api-section {
    padding: 40px 0;
  }
  .api-fields {
    grid-template-columns: minmax(0, 1fr);
  }
  .api-table td:first-child {
    white-space: normal;
    width: 40%;
  }
  .api-docs code {
    white-space: normal;
    word-break: break-word;
  }
}
