/* Shared documentation shell.
 *
 * Every page under /docs/ links this instead of inlining its own <style>. Before it existed each
 * page carried a private copy of the same tokens, so a colour or spacing change had to be made
 * seven times and, in practice, drifted. The docs e2e suite asserts no page has an inline <style>.
 *
 * Layout: a persistent left sidebar plus one reading column. The previous top bar flattened the six
 * sections declared in pages.json into a single wrapping row of twelve equal-weight links, which
 * cost the reader both the grouping and any sense of where they were.
 *
 * Logical properties throughout (inline-start/end, not left/right) so the Arabic landing page's
 * RTL direction flows without a second stylesheet.
 */
:root {
  --pf-green: #16a34a;
  --pf-blue: #2563eb;
  --pf-text: #0f172a;
  --pf-muted: #475569;
  --pf-faint: #64748b;
  --pf-bg: #ffffff;
  --pf-card: #ffffff;
  --pf-soft: #f1f5f9;
  --pf-border: #e2e8f0;
  --pf-hover: #f8fafc;
  --pf-active-bg: rgba(22, 163, 74, 0.09);
  --pf-selection: rgba(22, 163, 74, 0.18);
  --pf-grad: linear-gradient(135deg, var(--pf-green), var(--pf-blue));
  --pf-radius: 12px;
  --pf-radius-sm: 8px;

  /* 4-unit base: the middle steps an 8-only scale misses are what give the sidebar its cadence. */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 72px;

  --pf-sidebar: 264px;
  --pf-measure: 70ch;   /* body measure, inside the craft floor's 65–75ch */
  --pf-max: 840px;      /* retained: content pages still constrain wide media to this */
}

@media (prefers-color-scheme: dark) {
  :root {
    --pf-text: #e5e7eb;
    --pf-muted: #94a3b8;
    --pf-faint: #7c8ba1;
    --pf-bg: #0b1220;
    --pf-card: #111827;
    --pf-soft: #0f172a;
    --pf-border: #1f2937;
    --pf-hover: #131c2e;
    --pf-active-bg: rgba(34, 197, 94, 0.14);
    --pf-selection: rgba(34, 197, 94, 0.26);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

body {
  margin: 0;
  background: var(--pf-bg);
  color: var(--pf-text);
  font: 16px/1.7 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Browser surfaces we did not draw still belong to the design. */
::selection { background: var(--pf-selection); color: var(--pf-text); }
:focus-visible {
  outline: 2px solid var(--pf-green);
  outline-offset: 2px;
  border-radius: var(--s-1);
}
* { scrollbar-width: thin; scrollbar-color: var(--pf-border) transparent; }
*::-webkit-scrollbar { inline-size: 10px; block-size: 10px; }
*::-webkit-scrollbar-thumb { background: var(--pf-border); border-radius: 999px; }
*::-webkit-scrollbar-thumb:hover { background: var(--pf-faint); }
*::-webkit-scrollbar-track { background: transparent; }

.skip {
  position: absolute; inset-inline-start: -9999px; inset-block-start: var(--s-2);
  padding: var(--s-2) var(--s-4); background: var(--pf-card); color: var(--pf-text);
  border: 1px solid var(--pf-border); border-radius: var(--pf-radius-sm); z-index: 40;
  text-decoration: none; font-size: 14px; font-weight: 600;
}
.skip:focus { inset-inline-start: var(--s-4); }

/* ---------------------------------------------------------------- shell */

.shell {
  display: grid;
  grid-template-columns: var(--pf-sidebar) minmax(0, 1fr);
  align-items: start;
  min-block-size: 100vh;
}

.sidebar {
  position: sticky;
  inset-block-start: 0;
  block-size: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-inline-end: 1px solid var(--pf-border);
  background: var(--pf-card);
  padding: var(--s-5) var(--s-4) var(--s-7);
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
}

.brand {
  display: flex; align-items: center; gap: var(--s-2);
  font-weight: 700; font-size: 15px; letter-spacing: -0.01em;
  color: inherit; text-decoration: none;
  padding-inline: var(--s-2);
}
.brand img { inline-size: 26px; block-size: 26px; }

/* Generated from pages.json — see build-shell.mjs. Grouped, because the grouping is real. */
.nav-links { display: flex; flex-direction: column; gap: var(--s-5); }
.nav-group { display: flex; flex-direction: column; gap: var(--s-1); }
.nav-group > h2 {
  margin: 0 0 var(--s-1);
  padding-inline: var(--s-2);
  font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--pf-faint);
}
.nav-links a {
  display: block;
  padding: 7px var(--s-2);
  border-radius: var(--pf-radius-sm);
  color: var(--pf-muted);
  text-decoration: none;
  font-size: 14px;
  line-height: 1.45;
  transition: background-color .12s ease, color .12s ease;
}
.nav-links a:hover { background: var(--pf-hover); color: var(--pf-text); }
.nav-links a.active {
  background: var(--pf-active-bg);
  color: var(--pf-green);
  font-weight: 600;
}

.nav-btn { display: none; }

/* --------------------------------------------------------------- content */

.content { min-inline-size: 0; padding: var(--s-7) var(--s-6) var(--s-8); }
.wrap { max-inline-size: var(--pf-max); margin-inline: auto; }
.content .wrap > * { max-inline-size: var(--pf-measure); }
/* Wide artefacts are exempt from the reading measure — they need the room. */
.content .wrap > pre,
.content .wrap > table,
.content .wrap > .cards,
.content .wrap > .table-wrap { max-inline-size: none; }

h1 {
  font-size: clamp(30px, 2.4vw + 20px, 38px);
  line-height: 1.15;
  letter-spacing: -0.022em;
  margin: 0 0 var(--s-3);
  text-wrap: balance;
}
h2 {
  font-size: 22px; line-height: 1.3; letter-spacing: -0.015em;
  margin-block: var(--s-8) var(--s-3);
  padding-block-start: var(--s-5);
  border-block-start: 1px solid var(--pf-border);
  text-wrap: balance;
}
/* The first section needs no rule and no chasm: the lead already separated it, and the page should
   start reading immediately rather than opening with 128px of nothing. */
.lead + h2,
#docs-index > h2:first-child {
  margin-block-start: var(--s-6);
  padding-block-start: 0;
  border-block-start: 0;
}

/* The index's generated sections are grandchildren of .wrap, so the measure cap on direct children
   misses them. */
#docs-index > h2 { max-inline-size: var(--pf-measure); }

h3 {
  font-size: 17px; line-height: 1.4; letter-spacing: -0.01em;
  margin-block: var(--s-6) var(--s-2);
  text-wrap: balance;
}
p { margin-block: 0 var(--s-4); }
.lead {
  color: var(--pf-muted);
  font-size: 18px;
  line-height: 1.6;
  margin: 0 0 var(--s-6);
}
.note { color: var(--pf-muted); font-size: 14px; }

a { color: var(--pf-blue); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }

ul, ol { padding-inline-start: var(--s-5); margin-block: 0 var(--s-4); }
li { margin-block-end: var(--s-2); }

/* The eyebrow above <h1> is gone: the sidebar already says where you are. `.badge` survives for
   inline status marks inside prose. */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px;
  font-weight: 600; background: var(--pf-soft); color: var(--pf-muted);
}

code {
  background: var(--pf-soft); padding: 2px 6px; border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em;
  font-variant-ligatures: none;
}
pre {
  background: var(--pf-soft);
  border: 1px solid var(--pf-border);
  padding: var(--s-4);
  border-radius: var(--pf-radius);
  overflow-x: auto; /* wide samples scroll inside the block, never the page */
  margin-block: 0 var(--s-4);
  font-size: 13.5px;
  line-height: 1.6;
}
pre code { background: none; padding: 0; font-size: inherit; }

table {
  inline-size: 100%; border-collapse: collapse; margin-block: 0 var(--s-4);
  display: block; overflow-x: auto; font-variant-numeric: tabular-nums;
}
th, td { text-align: start; padding: 10px var(--s-3); border-block-end: 1px solid var(--pf-border); font-size: 14px; }
th { color: var(--pf-muted); font-weight: 600; white-space: nowrap; }

/* Index listing. A grouped list, not a card grid: the reader is choosing a topic from a known set,
   and twelve equal boxes make that choice slower, not faster. */
.doc-list { display: flex; flex-direction: column; gap: var(--s-1); margin-block-end: var(--s-6); max-inline-size: var(--pf-measure); }
.doc-list a {
  display: block; padding: var(--s-3) var(--s-4);
  border-radius: var(--pf-radius-sm); text-decoration: none; color: inherit;
  transition: background-color .12s ease;
}
.doc-list a:hover { background: var(--pf-hover); }
.doc-list strong { display: block; font-size: 15px; font-weight: 600; color: var(--pf-text); margin-block-end: 2px; }
.doc-list span { display: block; font-size: 14px; line-height: 1.55; color: var(--pf-muted); }

.cards { display: grid; gap: var(--s-3); grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.card {
  display: block; padding: var(--s-4) var(--s-5); border: 1px solid var(--pf-border);
  border-radius: var(--pf-radius); background: var(--pf-card); text-decoration: none; color: inherit;
  transition: border-color .15s ease;
}
.card:hover { border-color: var(--pf-green); }
.card h3 { margin: 0 0 var(--s-1); font-size: 16px; }
.card p { margin: 0; color: var(--pf-muted); font-size: 14px; }

footer {
  border-block-start: 1px solid var(--pf-border);
  margin-block-start: var(--s-8);
  padding-block: var(--s-5);
  color: var(--pf-muted);
  font-size: 14px;
}
footer .wrap { max-inline-size: var(--pf-max); }

/* ------------------------------------------------------------ responsive */

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }

  .sidebar {
    position: static;
    block-size: auto;
    overflow: visible;
    border-inline-end: 0;
    border-block-end: 1px solid var(--pf-border);
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    padding: var(--s-3) var(--s-4);
  }

  /* Collapsed by default so the article, not the index, owns the first screen. */
  .nav-links {
    display: none;
    position: absolute;
    inset-inline: 0;
    inset-block-start: 100%;
    z-index: 30;
    background: var(--pf-card);
    border-block-end: 1px solid var(--pf-border);
    /* Generous bottom padding so the last group ends on whitespace. At 70vh the panel cut a group
       label in half with the article showing through underneath, which reads as a broken overlay
       rather than a scrollable one. dvh keeps it right when mobile browser chrome retracts. */
    padding: var(--s-4) var(--s-4) var(--s-6);
    gap: var(--s-4);
    max-block-size: calc(100dvh - 64px);
    overflow-y: auto;
    box-shadow: 0 14px 28px -14px rgba(15, 23, 42, 0.32);
  }
  .sidebar { position: relative; }
  body.nav-open .nav-links { display: flex; }

  .nav-btn {
    display: inline-flex; align-items: center; gap: var(--s-2);
    min-block-size: 40px; padding: var(--s-2) var(--s-3);
    background: transparent; border: 1px solid var(--pf-border);
    border-radius: var(--pf-radius-sm); color: var(--pf-text);
    font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  }
  .nav-btn:hover { background: var(--pf-hover); }

  /* Without JS the button cannot toggle, so the list must not be unreachable. */
  .no-js .nav-links { display: flex; position: static; box-shadow: none; padding: 0; border: 0; }
  .no-js .nav-btn { display: none; }
  .no-js .sidebar { flex-direction: column; align-items: stretch; }

  .content { padding: var(--s-6) var(--s-4) var(--s-7); }
}
