/* examples.css — demo examples chrome (W4; W6.A.B refactored 2026-05-08;
 * W6.C.B.1 split-out 2026-05-08 evening).
 *
 * Owns the layout for `_partials/example.php` consumers. Tokens-only
 * (every value via --demo-*).
 *
 * Loads `dist/builder.css` (engine tokens — --bjs-*) and the demo-tier
 * primitive `.demo-code-popover` (migrated out of src/builder.css per
 * the W6.A.B redirect — see MINI_BUILDER_PRIMITIVE.md + DISCOVERIES.md
 * D13.A.B).
 *
 * `mini-builder.css` is INTENTIONALLY NOT imported here. Phase B examples
 * (basic/backend) opt into it via `$pageExtraStylesheets` set by
 * _partials/example.php whenever `$exampleMiniBuilder` is non-null. Phase
 * C.B cookbook entries deliberately skip the shared variant CSS — each
 * cookbook dir ships its own self-contained `style.css` (per
 * MINI_BUILDER_PRIMITIVE.md "Cookbook-entry pattern" — every behaviour
 * readable to a stranger / D6.2 buyer-package readiness rule).
 */

@import url('/dist/builder.css');
@import url('/assets/css/code-popover.css');

.demo-example {
  display: flex;
  flex-direction: column;
  gap: var(--demo-space-9);
  padding-bottom: var(--demo-space-10);
}

.demo-example__hero,
.demo-example__steps,
.demo-example__embed,
.demo-example__code,
.demo-example__notes,
.demo-example__next {
  /* Each section centers its inner block at content-max. */
}

.demo-example__hero-inner,
.demo-example__steps-inner,
.demo-example__embed-inner,
.demo-example__code-inner,
.demo-example__notes-inner,
.demo-example__related-inner,
.demo-example__next-inner {
  max-width: var(--demo-content-max);
  margin: 0 auto;
  padding: 0 var(--demo-space-6);
}

.demo-example__section-title {
  margin: 0 0 var(--demo-space-4);
  font-size: var(--demo-fs-xl);
  font-weight: var(--demo-fw-bold);
  letter-spacing: var(--demo-ls-heading);
  color: var(--demo-text-strong);
}

/* ──────────────────────────────────────────────
 * Hero
 * ────────────────────────────────────────────── */

.demo-example__hero {
  position: relative;
  padding-top: var(--demo-space-9);
  padding-bottom: var(--demo-space-7);
  background:
    radial-gradient(60% 80% at 80% 0%, var(--demo-accent-soft), transparent 70%),
    radial-gradient(40% 60% at 0% 30%, var(--demo-accent-soft), transparent 70%),
    var(--demo-bg);
}

/* Breadcrumb (W6.F.C.1) — semantic <nav><ol> with three crumbs:
 * Examples → <Tier> → <example title>. The two ancestor crumbs are
 * links to the hub + tier section so the buyer can step back one
 * level without bouncing through the home page; the leaf carries
 * aria-current="page" so screen readers announce position. */
.demo-example__crumbs {
  margin-bottom: var(--demo-space-3);
  font-size: var(--demo-fs-sm);
  color: var(--demo-text-muted);
}
.demo-example__crumbs-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--demo-space-2);
}
.demo-example__crumb-item {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}
.demo-example__crumb {
  color: var(--demo-text-muted);
  text-decoration: none;
  border-radius: var(--demo-radius-sm);
  padding: 2px 4px;
  margin: -2px -4px;
}
a.demo-example__crumb {
  transition: color 120ms ease, background 120ms ease;
}
a.demo-example__crumb:hover { color: var(--demo-text); }
a.demo-example__crumb:focus-visible {
  outline: 2px solid var(--demo-accent);
  outline-offset: 2px;
  color: var(--demo-text);
}
.demo-example__crumb--current {
  color: var(--demo-text);
  font-weight: var(--demo-fw-medium);
  /* Keep the leaf within the hero on narrow screens — long titles
   * (e.g. extensions/4-i18n-locale-pack) ellipsize rather than
   * line-wrapping the breadcrumb visually. */
  max-width: min(56ch, 100%);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.demo-example__crumb-sep {
  color: var(--demo-text-muted);
  user-select: none;
}

.demo-example__pills {
  margin-bottom: var(--demo-space-3);
}

.demo-example__title {
  margin: 0 0 var(--demo-space-3);
  font-size: clamp(var(--demo-fs-2xl), 4vw, var(--demo-fs-3xl));
  font-weight: var(--demo-fw-display);
  line-height: var(--demo-lh-display);
  letter-spacing: var(--demo-ls-display);
  color: var(--demo-text-strong);
  max-width: 24ch;
}

.demo-example__lede {
  margin: 0;
  font-size: var(--demo-fs-lg);
  line-height: var(--demo-lh-body);
  color: var(--demo-text);
  max-width: 60ch;
}

/* ──────────────────────────────────────────────
 * Steps strip
 * ────────────────────────────────────────────── */

.demo-example__step-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--demo-space-5);
}

.demo-example__step {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: var(--demo-space-4);
  padding: var(--demo-space-5) var(--demo-space-6);
  background: var(--demo-bg-elevated);
  border: 1px solid var(--demo-border);
  border-radius: var(--demo-radius-lg);
}

.demo-example__step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-top: 2px;
  border-radius: var(--demo-radius-pill);
  background: var(--demo-primary);
  color: var(--demo-primary-fg);
  font-size: var(--demo-fs-md);
  font-weight: var(--demo-fw-bold);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.demo-example__step-body {
  display: flex;
  flex-direction: column;
  gap: var(--demo-space-3);
  min-width: 0;
}

.demo-example__step-title {
  margin: 0;
  font-size: var(--demo-fs-md);
  font-weight: var(--demo-fw-bold);
  color: var(--demo-text-strong);
}

.demo-example__step-text {
  margin: 0;
  font-size: var(--demo-fs-sm);
  line-height: var(--demo-lh-body);
  color: var(--demo-text-secondary);
}

/* ──────────────────────────────────────────────
 * Live embed (iframe of /builder.php)
 * ────────────────────────────────────────────── */

.demo-example__embed-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--demo-space-3);
  margin-bottom: var(--demo-space-4);
}

.demo-example__embed-frame {
  width: 100%;
  height: var(--demo-embed-h, 720px);
  background: var(--demo-bg-elevated);
  border: 1px solid var(--demo-border);
  border-radius: var(--demo-radius-lg);
  box-shadow: var(--demo-shadow-md);
  overflow: hidden;
}

.demo-example__iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--demo-bg);
}

@media (max-width: 768px) {
  .demo-example__embed-frame { height: clamp(480px, 80vh, 720px); }
}

/* ──────────────────────────────────────────────
 * Code blocks (the whole snippet)
 * ────────────────────────────────────────────── */

.demo-example__code-lede {
  margin: 0 0 var(--demo-space-4);
  font-size: var(--demo-fs-md);
  color: var(--demo-text-secondary);
  max-width: 60ch;
}

.demo-example__code-title {
  margin: var(--demo-space-5) 0 var(--demo-space-3);
  font-size: var(--demo-fs-md);
  font-weight: var(--demo-fw-semibold);
  color: var(--demo-text-strong);
}
.demo-example__code-title:first-of-type {
  margin-top: 0;
}

.demo-example__code-inner .demo-code-popover {
  margin-bottom: var(--demo-space-4);
}
.demo-example__code-inner .demo-code-popover:last-child {
  margin-bottom: 0;
}

.demo-example__steps-inner .demo-code-popover {
  margin-top: var(--demo-space-2);
}

/* ──────────────────────────────────────────────
 * Notes
 * ────────────────────────────────────────────── */

.demo-example__notes-body {
  padding: var(--demo-space-5) var(--demo-space-6);
  background: var(--demo-bg-elevated);
  border: 1px solid var(--demo-border);
  border-left: 3px solid var(--demo-accent);
  border-radius: var(--demo-radius-md);
  font-size: var(--demo-fs-sm);
  line-height: var(--demo-lh-body);
  color: var(--demo-text-secondary);
}
.demo-example__notes-body p { margin: 0 0 var(--demo-space-3); }
.demo-example__notes-body p:last-child { margin: 0; }
.demo-example__notes-body ul,
.demo-example__notes-body ol {
  margin: 0 0 var(--demo-space-3);
  padding-left: var(--demo-space-5);
}
.demo-example__notes-body li { margin-bottom: var(--demo-space-1); }
.demo-example__notes-body strong { color: var(--demo-text); }

/* ──────────────────────────────────────────────
 * W6.F.B.1 — Related examples cross-tier strip
 *
 * Sits between Notes and the intra-tier "More examples" grid. Each card
 * crosses a tier boundary and carries a 1-sentence rationale so the
 * buyer's next hop is suggested, not just listed. Reciprocal graph —
 * every (A → B) edge implies (B → A); demo-related-reciprocity.spec.js
 * gates against asymmetric link rot.
 * ────────────────────────────────────────────── */

.demo-example__related {
  margin-top: var(--demo-space-7);
}
.demo-example__related-inner {
  display: grid;
  gap: var(--demo-space-5);
}
.demo-example__related-header {
  display: grid;
  gap: var(--demo-space-2);
}
.demo-example__related-lede {
  margin: 0;
  font-size: var(--demo-fs-sm);
  color: var(--demo-text-secondary);
  max-width: 56ch;
}
.demo-example__related-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--demo-space-4);
}
@media (min-width: 768px) {
  .demo-example__related-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1280px) {
  /* Single row when a 4-card example renders on a wide viewport, so the
   * strip reads as one horizontal sweep rather than a 2×2 block. */
  .demo-example__related[data-related-count="4"] .demo-example__related-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .demo-example__related[data-related-count="3"] .demo-example__related-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.demo-example__related-card {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: var(--demo-space-3);
  padding: var(--demo-space-5);
  text-decoration: none;
  color: inherit;
  height: 100%;
  transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}
.demo-example__related-card:hover {
  border-color: var(--demo-accent);
  transform: translateY(-2px);
  box-shadow: var(--demo-shadow-md);
}
.demo-example__related-card:focus-visible {
  outline: 2px solid var(--demo-accent);
  outline-offset: 2px;
}
.demo-example__related-card:active {
  transform: translateY(0);
  box-shadow: var(--demo-shadow-sm);
}

.demo-example__related-pill {
  /* Pill is a self-aligning chip — width hugs the label, no stretch. */
  justify-self: start;
  font-size: var(--demo-fs-xs);
  letter-spacing: var(--demo-ls-caps);
}
.demo-example__related-title {
  margin: 0;
  font-size: var(--demo-fs-md);
  font-weight: var(--demo-fw-semibold);
  color: var(--demo-text);
  line-height: var(--demo-lh-tight);
}
.demo-example__related-why {
  margin: 0;
  font-size: var(--demo-fs-sm);
  line-height: var(--demo-lh-body);
  color: var(--demo-text-secondary);
}
/* Tighten inline <code> chips inside the rationale so they read as
 * lightweight type-stack swaps, not full code-block emphasis. */
.demo-example__related-why code {
  font-family: var(--demo-font-mono);
  font-size: 0.92em;
  padding: 1px 5px;
  border-radius: var(--demo-radius-sm);
  background: var(--demo-accent-soft);
  color: var(--demo-accent);
  white-space: nowrap;
}
.demo-example__related-cta {
  display: inline-flex;
  align-items: center;
  gap: var(--demo-space-1);
  font-size: var(--demo-fs-sm);
  font-weight: var(--demo-fw-semibold);
  color: var(--demo-text);
  transition: transform 160ms ease, color 160ms ease;
}
.demo-example__related-cta .material-symbols-outlined {
  font-size: 18px;
  transition: transform 160ms ease;
}
.demo-example__related-card:hover .demo-example__related-cta {
  color: var(--demo-accent);
}
.demo-example__related-card:hover .demo-example__related-cta .material-symbols-outlined {
  transform: translateX(4px);
}

@media (prefers-reduced-motion: reduce) {
  .demo-example__related-card,
  .demo-example__related-card .demo-example__related-cta,
  .demo-example__related-card .demo-example__related-cta .material-symbols-outlined {
    transition: none;
  }
  .demo-example__related-card:hover {
    transform: none;
  }
  .demo-example__related-card:hover .demo-example__related-cta .material-symbols-outlined {
    transform: none;
  }
}

/* ──────────────────────────────────────────────
 * Next-up grid
 * ────────────────────────────────────────────── */

.demo-example__next-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  /* `minmax(0, 1fr)` (vs bare `1fr` = `minmax(auto, 1fr)`) lets columns
   * shrink below their content size, so a long sibling title cannot
   * widen the track past 1/N of the container and force the page into
   * horizontal scroll. Pairs with `min-width: 0` on the flex card +
   * `text-overflow: ellipsis` on the title (Lesson 72-3). */
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--demo-space-4);
}
@media (max-width: 768px) {
  .demo-example__next-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (min-width: 1024px) {
  .demo-example__next-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.demo-example__next-card {
  display: flex;
  align-items: center;
  gap: var(--demo-space-3);
  /* `min-width: 0` on the flex container lets the grid track honour its
   * `minmax(0, 1fr)` clamp; without it the auto-min-content size of the
   * flex children pushes the card past the track and breaks the title's
   * ellipsis (companion to the grid clamp above). */
  min-width: 0;
  padding: var(--demo-space-4);
  background: var(--demo-bg-elevated);
  border: 1px solid var(--demo-border);
  border-radius: var(--demo-radius-md);
  text-decoration: none;
  color: inherit;
  transition: border-color 160ms ease, transform 160ms ease;
}
.demo-example__next-card:hover {
  border-color: var(--demo-text-muted);
  transform: translateY(-2px);
}
.demo-example__next-card:focus-visible {
  outline: 2px solid var(--demo-accent);
  outline-offset: 2px;
}

.demo-example__next-num {
  font-size: var(--demo-fs-xs);
  font-weight: var(--demo-fw-semibold);
  letter-spacing: var(--demo-ls-caps);
  color: var(--demo-text-muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.demo-example__next-title {
  font-size: var(--demo-fs-sm);
  font-weight: var(--demo-fw-semibold);
  color: var(--demo-text);
  flex: 1 1 auto;
  /* `min-width: 0` overrides the flex-item default of `min-width: auto`
   * (= min-content). Without this override, the next-title would refuse
   * to shrink below its longest unbroken word and the ellipsis below
   * never fires. */
  min-width: 0;
  /* Truncate long titles */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.demo-example__next-card .material-symbols-outlined {
  font-size: 18px;
  color: var(--demo-text-muted);
  flex-shrink: 0;
  transition: transform 160ms ease;
}
.demo-example__next-card:hover .material-symbols-outlined {
  transform: translateX(4px);
  color: var(--demo-text);
}

@media (prefers-reduced-motion: reduce) {
  .demo-example__next-card:hover { transform: none; }
  .demo-example__next-card:hover .material-symbols-outlined { transform: none; }
}

/* ─── W5 — Backend example primitives ─────────────────────────────────────
 * Two interactive panels embedded in $exampleNotes:
 *   - .demo-auth-form    (W5.3 live auth round-trip form)
 *   - .demo-realtime     (W5.4 side-by-side editor + viewer + status)
 * Both reuse the shared `.demo-form-control` + `.demo-btn` primitives
 * defined in app.css; this section only adds layout + status semantics
 * so they read as "embedded mini-apps" inside the Notes section.
 */

.demo-auth-form {
  display: grid;
  gap: var(--demo-space-3);
  padding: var(--demo-space-5);
  margin: var(--demo-space-5) 0;
  border: 1px solid var(--demo-border);
  border-radius: var(--demo-radius-md);
  background: var(--demo-bg-elevated);
}
.demo-auth-form__row {
  display: grid;
  grid-template-columns: 130px 1fr;
  align-items: center;
  gap: var(--demo-space-3);
}
.demo-auth-form__row label {
  font-weight: var(--demo-fw-medium);
  color: var(--demo-text);
  font-size: var(--demo-fs-sm);
}
.demo-auth-form__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--demo-space-2);
  padding-top: var(--demo-space-2);
  border-top: 1px solid var(--demo-border);
}
.demo-auth-form__result {
  margin: 0;
  padding: var(--demo-space-3);
  border-radius: var(--demo-radius-sm);
  background: var(--demo-bg);
  color: var(--demo-text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--demo-fs-xs);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--demo-border);
  max-height: 220px;
  overflow: auto;
}

@media (max-width: 600px) {
  .demo-auth-form__row {
    grid-template-columns: 1fr;
    gap: var(--demo-space-1);
  }
}

.demo-realtime {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--demo-space-5);
  padding: var(--demo-space-5);
  margin: var(--demo-space-5) 0;
  border: 1px solid var(--demo-border);
  border-radius: var(--demo-radius-md);
  background: var(--demo-bg-elevated);
}
.demo-realtime__col {
  display: flex;
  flex-direction: column;
  gap: var(--demo-space-3);
  min-width: 0;
}
.demo-realtime__col-title {
  margin: 0;
  font-size: var(--demo-fs-sm);
  font-weight: var(--demo-fw-semibold);
  color: var(--demo-text-strong);
  letter-spacing: var(--demo-ls-caps);
  text-transform: uppercase;
}
.demo-realtime__editor {
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--demo-fs-sm);
  line-height: 1.55;
  min-height: 140px;
}
.demo-realtime__view {
  margin: 0;
  padding: var(--demo-space-3);
  border-radius: var(--demo-radius-sm);
  background: var(--demo-bg);
  color: var(--demo-text);
  border: 1px solid var(--demo-border);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--demo-fs-sm);
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 140px;
}
.demo-realtime__actions {
  display: flex;
  align-items: center;
  gap: var(--demo-space-3);
  flex-wrap: wrap;
}
.demo-realtime__status {
  font-size: var(--demo-fs-xs);
  font-weight: var(--demo-fw-medium);
  color: var(--demo-text-secondary);
  padding: 4px 10px;
  border-radius: var(--demo-radius-pill);
  background: var(--demo-bg);
  border: 1px solid var(--demo-border);
}
.demo-realtime__status[data-state='fresh'] {
  color: var(--demo-success);
  border-color: color-mix(in srgb, var(--demo-success) 30%, transparent);
  background: color-mix(in srgb, var(--demo-success) 8%, var(--demo-bg));
}
.demo-realtime__status[data-state='error'] {
  color: var(--demo-error);
  border-color: color-mix(in srgb, var(--demo-error) 30%, transparent);
  background: color-mix(in srgb, var(--demo-error) 8%, var(--demo-bg));
}
.demo-realtime__hint {
  margin: 0;
  font-size: var(--demo-fs-xs);
  color: var(--demo-text-secondary);
}

@media (max-width: 760px) {
  .demo-realtime { grid-template-columns: 1fr; }
}
