/* ══════════════════════════════════════════════════════════════════════════════════
   FaultLine wiki shell — the SHARED chrome for both wiki properties.

   Consumed by:
     • saas/landing/wiki*.html        (marketing origin — loads landing.css first)
     • saas/dashboard/help/*          (app origin — loads its own inline token block)

   The point of this file is that those two surfaces stop looking like two products.
   It ships LAYOUT + STRUCTURE ONLY and deliberately declares NO new colours: every
   colour here is `var(--…)` resolved from whatever token block the host page already
   loaded (landing.css :root, or the help wiki's inline :root). Load it AFTER the host
   stylesheet:

       <link rel="stylesheet" href="landing.css">
       <link rel="stylesheet" href="/shared/wiki-shell.css">

   Because the tokens come from the host, light mode is free: landing.css already
   swaps the whole set under :root[data-theme="light"] and @media (prefers-color-scheme:
   light), and the help wiki swaps it under :root[data-theme="light"] + its data-accent
   variants. Nothing in this file hard-codes a hue that would survive that swap.

   No build step, no imports, no external fonts/images/requests.
   ══════════════════════════════════════════════════════════════════════════════════ */

/* ── token bridge ─────────────────────────────────────────────────────────────
   NOT a palette. Each alias forwards a token the host page defines; the literal
   after the comma is only a FALLBACK for hosts that never declared it, and every
   fallback is copied verbatim from landing.css's dark :root — so a page that is
   missing a token gets landing's value rather than an invented one.

   Concretely: landing.css defines all of these; the help wiki's inline block
   defines --bg/--bg-soft/--fg/--muted/--border/--accent/--accent-dim/--danger/
   --warn/--mono but NOT --bg-card, --accent-glow, --accent-halo or --on-accent.
   Those four are the ones that actually fall back today.

   --wiki-sticky-top is the height of the host's sticky top bar. It defaults to 0
   and wiki-shell.js overwrites it on <html> with the measured header height, so
   the sticky sidebar and every scroll-margin below stay in step with whatever
   chrome the host page happens to have. A page may also set it by hand; the JS
   leaves any author-declared non-zero value alone.
   ───────────────────────────────────────────────────────────────────────────── */
:root {
  --wiki-card:      var(--bg-card, var(--bg-soft, #141614));
  --wiki-glow:      var(--accent-glow, rgba(63,185,80,0.16));
  --wiki-halo:      var(--accent-halo, rgba(63,185,80,0.55));
  --wiki-on-accent: var(--on-accent, #05160B);
  /* neutral wash for hover states — grey at low alpha reads correctly in BOTH
     themes, which a tinted background would not. Same trick the help wiki uses. */
  --wiki-hover:     rgba(127,127,127,.08);
  --wiki-hover-on:  rgba(127,127,127,.14);

  --wiki-sticky-top: 0px;   /* set by wiki-shell.js from the measured header */
  --wiki-gap:        12px;  /* breathing room under a sticky header when jumping */
  --wiki-sidebar-w:  264px;
  --wiki-maxw:       1320px;
}

/* ══════════════════════════════════════════════════════════════════════════════
   1. SHELL — the two-column MediaWiki frame: persistent rail + article column.
   The table of contents is IN-ARTICLE (like MediaWiki), not a third rail, so both
   properties can use the identical grid regardless of viewport.
   ══════════════════════════════════════════════════════════════════════════════ */
.wiki-shell {
  display: grid;
  grid-template-columns: var(--wiki-sidebar-w) minmax(0, 1fr);
  align-items: start;
  gap: 0;
  max-width: var(--wiki-maxw);
  margin: 0 auto;
}

/* ══════════════════════════════════════════════════════════════════════════════
   2. SIDEBAR — the persistent left rail.
   Styled by ELEMENT rather than by bespoke child classes, so either property can
   write plain <nav><ul><li><a> markup and get the house look with no extra hooks.
   ══════════════════════════════════════════════════════════════════════════════ */
.wiki-sidebar {
  position: sticky;
  top: var(--wiki-sticky-top);
  align-self: start;
  max-height: calc(100vh - var(--wiki-sticky-top));
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
  padding: 20px 12px 40px;
  border-right: 1px solid var(--border);
  background: var(--bg-soft);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  scrollbar-width: thin;
}

/* group labels: any heading in the rail, or an explicit .wiki-sidebar-label */
.wiki-sidebar h2,
.wiki-sidebar h3,
.wiki-sidebar h4,
.wiki-sidebar .wiki-sidebar-label {
  margin: 14px 0 4px;
  padding: 0 6px;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
  border: 0;
}
.wiki-sidebar h2::before,
.wiki-sidebar h3::before,
.wiki-sidebar h4::before,
.wiki-sidebar .wiki-sidebar-label::before { content: "▾ "; color: var(--accent); }

.wiki-sidebar ul,
.wiki-sidebar ol { list-style: none; margin: 0 0 12px; padding: 0; }
.wiki-sidebar li { margin: 0; }

.wiki-sidebar a {
  display: block;
  position: relative;
  padding: 5px 8px 5px 22px;
  color: var(--fg);
  text-decoration: none;
  border-left: 2px solid transparent;
  overflow-wrap: anywhere;
}
.wiki-sidebar a::before {
  content: "·";
  position: absolute;
  left: 10px;
  color: var(--muted);
}
.wiki-sidebar a:hover { background: var(--wiki-hover); text-decoration: none; color: var(--fg); }

/* current page — aria-current is the accessible source of truth; .is-active is
   accepted too for pages that only mark state with a class. */
.wiki-sidebar a[aria-current],
.wiki-sidebar a.is-active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--wiki-hover);
}
.wiki-sidebar a[aria-current]::before,
.wiki-sidebar a.is-active::before { color: var(--accent); }

/* the search filter hides non-matches with the `hidden` property — this rule has
   to out-specify `.wiki-sidebar a { display:block }` above, and it does (0,2,1). */
.wiki-sidebar a[hidden],
.wiki-sidebar li[hidden],
.wiki-sidebar ul[hidden],
.wiki-sidebar ol[hidden],
.wiki-sidebar [hidden] { display: none; }

/* ── sidebar search ─────────────────────────────────────────────────────────── */
#wiki-search {
  width: 100%;
  padding: 7px 9px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 2px;
  font-family: var(--mono);
  font-size: 12px;
}
#wiki-search::placeholder { color: var(--muted); }
#wiki-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* match count — rendered by wiki-shell.js next to the input if the page has not
   supplied its own #wiki-search-count. aria-live is set in the JS, not here. */
.wiki-search-count {
  margin: 6px 0 10px;
  padding: 0 2px;
  min-height: 1em;
  font-size: 10px;
  letter-spacing: .5px;
  color: var(--muted);
}
.wiki-search-count.is-empty { color: var(--warn); }

/* the "press / to search" hint the help wiki already shows */
.wiki-sidebar .wiki-kbd {
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 3px;
  padding: 0 5px; font-size: 11px; background: var(--bg-soft);
}

/* ══════════════════════════════════════════════════════════════════════════════
   3. CONTENT — the article column.
   `min-width: 0` on the grid child is what actually stops a long <pre> or a wide
   table from blowing the column (and therefore the page) out horizontally; grid
   items default to min-width:auto and refuse to shrink below their content.
   ══════════════════════════════════════════════════════════════════════════════ */
.wiki-content {
  min-width: 0;
  max-width: 100%;
  padding: 26px 40px 72px;
  overflow-wrap: break-word;
  font-family: var(--mono);
}
.wiki-content img,
.wiki-content svg,
.wiki-content video,
.wiki-content iframe { max-width: 100%; height: auto; }

/* ── article title ──────────────────────────────────────────────────────────
   The ⊢ turnstile is FaultLine's mark; the treatment (Georgia serif, accent,
   soft halo) is lifted from landing.css `.brand .mark` so the wiki wears the
   same badge as the nav rather than a second one. */
.wiki-firstHeading {
  margin: 0 0 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  font-size: clamp(24px, 3.4vw, 34px);
  font-weight: 700;
  letter-spacing: -.5px;
  line-height: 1.15;
}
.wiki-firstHeading::before {
  content: "⊢";
  margin-right: .45em;
  font-family: Georgia, 'Times New Roman', serif;
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 14px var(--wiki-halo);
}
/* the standing subtitle under a title, if the page uses one */
.wiki-content .wiki-lede { margin: 0 0 22px; color: var(--muted); font-size: 13px; line-height: 1.6; }

/* ── section headings ───────────────────────────────────────────────────────
   ▸ for h2 and # for h3 are the console/help-wiki motifs; kept, so a section in
   the marketing wiki and a section in the app wiki read identically. Sentence
   case is preserved (no text-transform) because article headings are prose and
   MediaWiki section rules are the reference. scroll-margin-top keeps a jumped-to
   heading clear of the host's sticky bar for NATIVE scrolls, using the same
   number wiki-shell.js uses for scripted ones. */
.wiki-content h2,
.wiki-content h3,
.wiki-content h4 { scroll-margin-top: calc(var(--wiki-sticky-top) + var(--wiki-gap)); }
.wiki-content h2 {
  margin: 34px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: .3px;
}
.wiki-content h2::before { content: "▸ "; color: var(--accent); }
.wiki-content h3 {
  margin: 22px 0 8px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .3px;
  color: var(--fg);
}
.wiki-content h3::before { content: "# "; color: var(--accent); }

.wiki-content p { margin: 10px 0; }
.wiki-content ul,
.wiki-content ol { margin: 10px 0; padding-left: 22px; }
.wiki-content li { margin: 5px 0; }
.wiki-content strong { color: var(--fg); font-weight: 600; }
.wiki-content blockquote {
  margin: 14px 0; padding: 2px 0 2px 14px;
  border-left: 2px solid var(--accent-dim); color: var(--muted);
}

/* ── code ───────────────────────────────────────────────────────────────────
   A <pre> is the classic horizontal-overflow culprit: it scrolls INSIDE its own
   box (overflow-x + max-width) so the column itself never does. */
.wiki-content code {
  font-family: var(--mono);
  font-size: 12px;
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--bg-soft);
  color: var(--accent);
}
.wiki-content pre {
  margin: 14px 0;
  padding: 12px 14px;
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent);
  border-radius: 3px;
  background: var(--bg-soft);
  font-size: 12px;
  line-height: 1.65;
}
.wiki-content pre code { padding: 0; border: 0; background: none; color: var(--fg); }

/* ── tables ─────────────────────────────────────────────────────────────────
   Two supported shapes, both of which scroll inside their own container:
     1. <div class="table-wrap"><table>…  — preferred; the table keeps real
        table layout and the wrapper scrolls (the help wiki already ships this).
     2. a bare <table> — made `display:block` so IT scrolls. Slightly weaker
        column sizing, but a bare table can never break the page open. */
.wiki-content .table-wrap { margin: 16px 0; max-width: 100%; overflow-x: auto; }
.wiki-content table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  margin: 16px 0;
  border-collapse: collapse;
  font-size: 12px;
}
.wiki-content .table-wrap > table { display: table; width: 100%; margin: 0; overflow: visible; }
.wiki-content th,
.wiki-content td { border: 1px solid var(--border); padding: 7px 9px; text-align: left; vertical-align: top; }
.wiki-content th {
  background: var(--bg-soft); color: var(--accent);
  text-transform: uppercase; letter-spacing: .5px; font-size: 11px;
}

/* ══════════════════════════════════════════════════════════════════════════════
   4. IN-ARTICLE TABLE OF CONTENTS — nav.wiki-toc, filled by wiki-shell.js.
   MediaWiki's shrink-to-fit boxed TOC with dotted section numbers (1, 1.1, …),
   drawn here with CSS counters so the numbering survives any edit to the list.
   ══════════════════════════════════════════════════════════════════════════════ */
.wiki-toc {
  display: table;              /* shrink-to-fit, like MediaWiki's TOC box */
  max-width: 100%;
  margin: 22px 0 26px;
  padding: 12px 20px 14px 16px;
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent);
  border-radius: 3px;
  background: var(--wiki-card);
  font-size: 12.5px;
  line-height: 1.55;
}
.wiki-toc-title {
  margin-bottom: 8px;
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
}
.wiki-toc-title::before { content: "▸ "; color: var(--accent); }
.wiki-toc ol { list-style: none; counter-reset: wiki-toc; margin: 0; padding: 0; }
.wiki-toc ol ol { margin-top: 2px; padding-left: 14px; }
.wiki-toc li { counter-increment: wiki-toc; margin: 3px 0; }
.wiki-toc a { color: var(--fg); text-decoration: none; }
.wiki-toc a::before { content: counters(wiki-toc, ".") "\00a0 "; color: var(--muted); }
.wiki-toc a:hover { color: var(--accent); text-decoration: underline; }
.wiki-toc a:hover::before { color: var(--accent); }

/* ══════════════════════════════════════════════════════════════════════════════
   5. PER-HEADING PERMALINK — the § appended by wiki-shell.js.
   Faded until the heading is hovered, but ALWAYS revealed on keyboard focus and
   on touch (where there is no hover), so it is never keyboard- or finger-only-
   inaccessible.
   ══════════════════════════════════════════════════════════════════════════════ */
.wiki-anchor {
  margin-left: .5em;
  color: var(--muted);
  font-weight: 400;
  text-decoration: none;
  opacity: 0;
  transition: opacity .12s ease, color .12s ease;
}
.wiki-content h2:hover > .wiki-anchor,
.wiki-content h3:hover > .wiki-anchor,
.wiki-content h4:hover > .wiki-anchor,
.wiki-anchor:focus,
.wiki-anchor:focus-visible { opacity: 1; color: var(--accent); text-decoration: none; }
.wiki-anchor:hover { color: var(--accent); text-decoration: none; }
@media (hover: none) { .wiki-anchor { opacity: .5; } }
@media (prefers-reduced-motion: reduce) { .wiki-anchor { transition: none; } }

/* ══════════════════════════════════════════════════════════════════════════════
   6. ARTICLE FURNITURE — categories, references, last-updated.
   ══════════════════════════════════════════════════════════════════════════════ */

/* ── categories ─────────────────────────────────────────────────────────────
   MediaWiki's footer strip. The label ("Categories:") is the AUTHOR's markup —
   nothing is injected here, so a page can call it Topics, Tags, or nothing. */
.wiki-catlinks {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  margin-top: 36px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg-soft);
  font-size: 12px;
  letter-spacing: .5px;
  color: var(--muted);
}
.wiki-catlinks ul,
.wiki-catlinks ol { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; list-style: none; margin: 0; padding: 0; }
.wiki-catlinks li { margin: 0; }
.wiki-catlinks li + li::before { content: "|"; margin-right: 10px; color: var(--border); }
.wiki-catlinks a { color: var(--accent); text-decoration: none; }
.wiki-catlinks a:hover { text-decoration: underline; }

/* ── references ─────────────────────────────────────────────────────────────
   An <ol class="wiki-refs">. `li:target` lights up the entry a citation link
   just jumped to — the reader needs to see WHICH reference they landed on.
   Long bare URLs break rather than widen the column. */
.wiki-refs {
  margin: 16px 0 0;
  padding-left: 26px;
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted);
}
.wiki-refs li {
  margin: 6px 0;
  padding: 2px 6px;
  border-radius: 2px;
  scroll-margin-top: calc(var(--wiki-sticky-top) + var(--wiki-gap));
}
.wiki-refs li::marker { color: var(--accent); }
.wiki-refs a { overflow-wrap: anywhere; word-break: break-word; }
.wiki-refs li:target { background: var(--wiki-glow); box-shadow: inset 2px 0 0 var(--accent); color: var(--fg); }

/* ── last updated ───────────────────────────────────────────────────────────
   A quiet provenance line. Text is the author's (a <time datetime> belongs
   here); this only sets the voice. */
.wiki-updated {
  margin-top: 26px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  font-size: 11px;
  letter-spacing: .5px;
  color: var(--muted);
}
.wiki-updated time { color: var(--fg); }

/* ══════════════════════════════════════════════════════════════════════════════
   7. FOCUS — the help wiki has no global :focus-visible rule (landing.css does),
   so the shell brings its own for everything it owns. Accessibility floor, and
   it matches landing.css's "neon halo" focus treatment.
   ══════════════════════════════════════════════════════════════════════════════ */
.wiki-shell a:focus-visible,
.wiki-shell button:focus-visible,
.wiki-shell input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ══════════════════════════════════════════════════════════════════════════════
   8. RESPONSIVE — the rail collapses; the column never scrolls sideways.
   ══════════════════════════════════════════════════════════════════════════════ */
@media (max-width: 1040px) {
  :root { --wiki-sidebar-w: 224px; }
  .wiki-content { padding: 24px 26px 64px; }
}

/* Below this width the grid goes single-column and the rail COLLAPSES: it stops
   being a full-height sticky column and becomes a short, self-scrolling strip
   above the article. Pure CSS, so it works with no JS and no toggle button. */
@media (max-width: 820px) {
  .wiki-shell { grid-template-columns: minmax(0, 1fr); }
  .wiki-sidebar {
    position: static;
    max-height: 42vh;
    padding: 12px 14px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .wiki-content { padding: 20px 18px 56px; }
  .wiki-firstHeading { font-size: clamp(21px, 6vw, 28px); }
}

/* Optional off-canvas drawer, for a page that DOES ship a menu button: add
   `.is-collapsed` to hide the rail and `.is-open` to slide it back over the
   article. Nothing in wiki-shell.js sets these — they are here so a host page
   can wire its own toggle without re-inventing the styling. */
@media (max-width: 820px) {
  .wiki-sidebar.is-collapsed { display: none; }
  .wiki-sidebar.is-open {
    display: block;
    position: fixed;
    inset: var(--wiki-sticky-top) auto 0 0;
    z-index: 40;
    width: 82%;
    max-width: 320px;
    max-height: none;
    border-right: 1px solid var(--border);
    box-shadow: 0 0 40px -8px rgba(0,0,0,.6);
  }
}

/* ══════════════════════════════════════════════════════════════════════════════
   9. PRINT — the rail, the TOC and the § permalinks are navigation, not content.
   ══════════════════════════════════════════════════════════════════════════════ */
@media print {
  .wiki-shell { display: block; max-width: none; }
  .wiki-sidebar,
  .wiki-toc,
  .wiki-anchor { display: none !important; }
  .wiki-content { padding: 0; }
  .wiki-content pre { white-space: pre-wrap; overflow: visible; }
  .wiki-content table { display: table; overflow: visible; }
}
