/* API documentation pages (Lighthouse Lights and Water Heater Twin). Loaded after redesign.css, which provides the site tokens,
   Geist and Geist Mono, the shell (.rd-shell, .rd-side, .rd-main) and the tile base (.rd-tile). Only the components below are new. */

/* Status colours from the sagar.build style guide's status table. They are tokens, so the rest of this file uses names only. */
:root {
  --api-ok-text: #1E6B45;
  --api-ok-fill: #E3F1E8;
  --api-warn-text: #7A5300;
  --api-warn-fill: #FBEFD2;
  --api-crit-text: #A3161A;
  --api-crit-fill: #FBE0DF;
  --api-stale-text: #5B5E66;
  --api-stale-fill: #ECEDEF;
  --api-info-text: #2A4F86;
  --api-info-fill: #E2EAF6;
  --api-note-fill: #ECEDEF;
}

/* Focus: a 2 px outline in currentColor, offset 3 px, on every interactive element. */
.rd-body :focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }

/* Sidebar: the site's sidebar card, with the API's own sub-links under the current section. */
.api-side { flex: 0 0 232px; width: 232px; }
.api-side .rd-nav a { color: var(--ink); }
.api-nav { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }
.api-nav a { display: flex; align-items: center; justify-content: space-between; min-height: 44px; padding: 0 12px; border-radius: 12px; color: var(--ink); text-decoration: none; font-size: 15px; }
.api-nav a[aria-current="page"] { background: var(--soft); font-weight: 500; }
.api-nav a[aria-current="page"]::after { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--brand); }
.api-topbar-brand { display: flex; align-items: center; gap: 10px; text-decoration: none; min-height: 44px; }
.api-topbar-brand .api-brand-title { font-size: 15px; }
.api-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.api-link-card { display: flex; flex-direction: column; gap: 10px; padding: 22px 24px; border-radius: 18px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); text-decoration: none; min-width: 0; }
.api-link-title { font-size: 17px; font-weight: 600; color: var(--ink); display: flex; justify-content: space-between; gap: 8px; }
.api-link-title span { color: var(--brand-text); }
.api-foot-links { display: flex; flex-wrap: wrap; gap: 12px 28px; }
.api-foot-links a { display: inline-flex; align-items: center; min-height: 44px; color: var(--brand-text); text-decoration: none; font-size: 15px; font-weight: 500; }
.api-foot-links a:hover { text-decoration: underline; }
.api-request { display: flex; flex-direction: column; gap: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.api-request:first-of-type { border-top: 0; padding-top: 0; }
.api-sub { display: flex; flex-direction: column; gap: 2px; margin: 0 0 4px 12px; padding: 0 0 0 12px; border-left: 1px solid var(--line); list-style: none; }
.api-sub a { display: flex; align-items: center; min-height: 44px; padding: 0 10px; border-radius: 10px; font-family: var(--mono); font-size: 13px; color: var(--muted); text-decoration: none; }
.api-sub a[aria-current="location"] { color: var(--ink); font-weight: 500; background: var(--soft); }
.api-side-foot { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.api-side-foot a { display: flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 12px; color: var(--ink); text-decoration: none; font-size: 15px; }

/* Menu button: shown below 900 px, and only when JavaScript is on. */
.api-menu-toggle {
  display: none; align-items: center; justify-content: center; min-height: 44px; min-width: 88px; padding: 0 18px;
  border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); color: var(--ink);
  font: inherit; font-size: 15px; font-weight: 500; cursor: pointer;
}
.api-topbar { display: none; align-items: center; justify-content: space-between; gap: 12px; }

/* Cards and page head. Inner padding 28-36 px on documentation pages. */
.api-head { padding: 32px 36px; display: flex; flex-direction: column; gap: 16px; }
.api-card { padding: 28px 32px; display: flex; flex-direction: column; gap: 16px; }
.api-h1 { font-size: 40px; line-height: 1.1; letter-spacing: -0.03em; font-weight: 500; color: var(--ink); }
.api-h2 { font-size: 26px; line-height: 1.2; letter-spacing: -0.02em; font-weight: 500; color: var(--ink); }
.api-h3 { font-size: 17px; line-height: 1.35; font-weight: 600; color: var(--ink); }
.api-lead { font-size: 17px; line-height: 1.55; color: var(--body); max-width: 60ch; }
.api-muted { color: var(--muted); font-size: 15px; line-height: 1.55; }
.api-two-tone { color: var(--head-muted); }
.api-payoff { color: var(--ink); }
.api-h2--lg { font-size: 36px; line-height: 1.1; letter-spacing: -0.03em; }
.api-display { font-size: 64px; line-height: 1; letter-spacing: -0.05em; font-weight: 600; color: var(--brand-text); }
.api-brand-block { display: flex; align-items: center; gap: 12px; }
.api-brand-title { font-size: 17px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; }
.api-brand-sub { font-size: 13px; color: var(--muted); }

/* Notices: plain text labels with a fill, never colour alone. */
.api-notice { padding: 14px 18px; border-radius: 14px; background: var(--api-note-fill); color: var(--body); font-size: 15px; line-height: 1.5; }
.api-notice strong { font-weight: 600; color: var(--ink); }
.api-notice--info { background: var(--api-info-fill); color: var(--api-info-text); }
.api-notice--info strong { color: var(--api-info-text); }
.api-notice--warn { background: var(--api-warn-fill); color: var(--api-warn-text); }
.api-notice--warn strong { color: var(--api-warn-text); }
.api-notice--crit { background: var(--api-crit-fill); color: var(--api-crit-text); }
.api-notice--crit strong { color: var(--api-crit-text); }
.api-notice--callout { background: var(--highlight); color: var(--ink); }

/* Chips: the base URL, the version and the key line. */
.api-chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.api-chip {
  display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 6px 14px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-size: 14px;
}
.api-chip code { font-family: var(--mono); font-size: 13px; color: var(--ink); }
.api-chip-label { color: var(--muted); font-size: 13px; }

/* Code blocks: a labelled header with a copy button, and a body that scrolls inside its own box. */
.api-code { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); overflow: hidden; min-width: 0; }
.api-code-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--line); }
.api-code-label { font-family: var(--mono); font-size: 12px; color: var(--muted); letter-spacing: 0.02em; }
.api-code pre {
  margin: 0; padding: 16px; overflow-x: auto; font-family: var(--mono); font-size: 14px; line-height: 1.6; color: var(--ink);
  white-space: pre;
}
.api-code code { font-family: var(--mono); }
.api-str { color: var(--brand-text); }

/* Copy button: default, copied and focused states. Hidden unless JavaScript is on. */
.api-copy {
  display: none; align-items: center; justify-content: center; min-height: 44px; min-width: 96px; padding: 0 16px;
  border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; flex: none;
}
.js .api-copy { display: inline-flex; }
.api-copy:hover { border-color: var(--control-border, var(--muted)); }
.api-copy.is-copied { background: var(--api-ok-fill); border-color: var(--api-ok-text); color: var(--api-ok-text); }
.api-copy:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }

/* Screen-reader-only text, used for the polite "Copied" announcement. */
.api-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Tables. Column headings are Geist Mono uppercase 11 px. Rows are at least 56 px tall. Wide tables scroll in their own box. */
.api-table-wrap { overflow-x: auto; border-radius: 14px; }
.api-table { width: 100%; border-collapse: collapse; font-size: 15px; line-height: 1.5; }
.api-table th {
  text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line-strong);
  font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
  white-space: nowrap;
}
.api-table td { padding: 14px; min-height: 56px; border-bottom: 1px solid var(--line); vertical-align: top; color: var(--body); }
.api-table td code, .api-table th code { font-family: var(--mono); font-size: 13px; color: var(--ink); }
.api-table tr.is-highlighted td { background: var(--highlight); }

/* Endpoint cards: a method label, the path, then parameters, example request and response, and error chips. */
.api-endpoint { scroll-margin-top: 24px; }
.api-method {
  display: inline-flex; align-items: center; min-height: 26px; padding: 2px 10px; border-radius: 8px;
  background: var(--ink); color: var(--on-brand); font-family: var(--mono); font-size: 12px; font-weight: 500;
}
.api-path { font-family: var(--mono); font-size: 15px; color: var(--ink); overflow-wrap: anywhere; }
.api-endpoint-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }

/* Error chips link to their row on the Errors page. */
.api-error-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.api-error-chip {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); text-decoration: none; font-size: 14px;
}
.api-error-chip code { font-family: var(--mono); font-size: 13px; }

/* Error rows: the target of an error link or a problem "type" URL. The highlight is a fill and an inset ring, never colour alone. */
.api-error-row { scroll-margin-top: 80px; }
.api-error-row.is-highlighted td { background: var(--highlight); box-shadow: inset 0 0 0 1px var(--brand); }
.api-error-row:target td { background: var(--highlight); }

/* Phone and tablet. The sidebar moves into a menu below 900 px, and the top bar stays on screen. */
@media (max-width: 899px) {
  .js .api-menu-toggle { display: inline-flex; }
  .js .api-topbar { display: flex; position: sticky; top: 0; z-index: 5; padding: 8px 0 12px; background: var(--ground); }
  .js .api-side { display: none; }
  .js .api-side.is-open { display: flex; }
  .api-topbar { display: flex; }
  .api-h1 { font-size: 32px; }
  .api-display { font-size: 48px; }
  .api-h2--lg { font-size: 30px; }
  .api-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
  .api-cards { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 480px) {
  .api-head, .api-card { padding: 22px 20px; }
  .api-table td, .api-table th { padding: 10px; }
}

/* Brand and topbar blocks (display set so the text spans stack). */
.api-brand-title, .api-brand-sub { display: block; }

/* Headings on documentation pages take their spacing from their parent's gap, not from browser defaults. */
.api-display, .api-h2, .api-h3 { margin: 0; }

/* Concepts: two columns of cards, collapsing to one. */
.api-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.api-columns > div { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
@media (max-width: 899px) { .api-columns { grid-template-columns: minmax(0, 1fr); } }

/* Timeline: one cycle, lit segments in the brand colour on a soft track. */
.api-timeline { position: relative; height: 28px; border-radius: 10px; background: var(--soft); overflow: hidden; }
.api-timeline-seg { position: absolute; top: 0; bottom: 0; background: var(--brand); border-radius: 4px; }
.api-timeline-axis { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 12px; color: var(--muted); }
/* Fault window on a timeline: a labelled band in the crit tokens, so the state is text as well as colour. */
.api-timeline-fault { position: absolute; top: 0; bottom: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; white-space: nowrap; background: var(--api-crit-fill); color: var(--api-crit-text); font-size: 12px; font-weight: 500; box-shadow: inset 0 0 0 1px var(--api-crit-text); }
/* Axis labels placed at their true positions on the timeline, with the first and last labels kept inside the track. */
.api-timeline-axis--scaled { position: relative; display: block; height: 1.6em; }
.api-timeline-axis--scaled span { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.api-timeline-axis--scaled span:first-child { transform: none; }
.api-timeline-axis--scaled span:last-child { transform: translateX(-100%); }
/* Matrix marks: a filled dot for reported, a dash for not reported. The words are visually hidden text. */
.api-dot { position: relative; color: var(--brand-text); font-size: 16px; line-height: 1; }
.api-dash { position: relative; color: var(--muted); }

/* The anchor on each error row: a text link, sized for touch. */
.api-anchor { display: inline-flex; align-items: center; min-width: 44px; min-height: 44px; justify-content: center; color: var(--muted); text-decoration: none; font-family: var(--mono); }

/* Tables keep a readable width and scroll inside their own box on phones, rather than squeezing their columns. */
.api-table { min-width: 520px; }
.api-anchor { min-width: 0; padding: 0 6px; min-height: 44px; }

/* Brand band for one key number, with the site's dot grid. */
.api-limit-band { background: var(--brand); color: var(--on-brand); border-radius: 26px; padding: 32px 36px; background-image: radial-gradient(var(--dots) 1px, transparent 1px); background-size: 18px 18px; }
.api-limit-number { display: flex; flex-direction: column; gap: 8px; margin: 0; }
.api-limit-value { font-size: 96px; line-height: 0.95; font-weight: 600; letter-spacing: -0.05em; }
.api-limit-unit { font-size: 17px; color: var(--on-brand-muted); }
.api-facts { display: flex; flex-direction: column; margin: 0; }
.api-facts > div { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.api-facts dt { color: var(--muted); }
.api-facts dd { margin: 0; text-align: right; color: var(--ink); }
.api-fact-label { font-size: 15px; font-weight: 600; color: var(--ink); margin: 0; }
.api-source-link { color: var(--brand-text); text-decoration: underline; overflow-wrap: anywhere; min-height: 44px; display: inline-flex; align-items: center; }

/* Inline code may wrap at any point, so a long URL cannot force sideways scrolling. Code blocks scroll in their own box. */
.rd-body p code, .rd-body td code, .rd-body dd code, .rd-body li code, .rd-body h2 code, .rd-body h3 code { overflow-wrap: anywhere; white-space: normal; }

/* Simple two-part lists: a name on the left, a value or count on the right. */
.api-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.api-list li { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 16px; padding: 12px 0; border-bottom: 1px solid var(--line); color: var(--ink); }
.api-list li:last-child { border-bottom: 0; }
.api-list li code { font-family: var(--mono); font-size: 13px; color: var(--muted); margin-left: 8px; }
