/* Code generator (web/snippets.py, templates/partials/snippets/generator.html, js/gp-snippets.js; docs/components.md
   "Code generator", docs/snippets.md). Loaded only by pages that show one (the support article view adds it when the
   body has a generator, also in a proposal preview and the help panel embed). Kit source:
   design/redesign/kit/css/gp-snippets.css.

   Design v2 roles (docs/design-guide.md): a calm tool card on a linen tray radius 24 (like the field reference's
   tools): a 40 px white disc with the code icon, the title and intro; the fields as the form rules say (white inputs
   radius 12, 1.5 px strong line, label navy 600, help 14 muted, an error in the error colour with a "!" mark, never
   colour alone); a muted privacy line with a lock. The code sits in one white well (radius 16, 2 px hairline): a bar
   with its label and the copy button (the card's one cobalt button), then the code in mono, NOT wrapped (Twig/JS
   lines stay readable) in its own scroll box (keyboard-focusable). The filled-in values and, without JS, the tokens
   to replace get the accent tint. The layout follows the card's own width (container query): fields stacked on a
   phone and in the ~400 px help panel (body.is-embed), side by side from 560 px.

   States: without JS the form, the waiting line, the privacy line and the copy button stay hidden ([hidden]) and the
   code shows with the sentence what to replace. gp-snippets.js adds .is-live and data-state="waiting" | "ready".
   Print: the code (filled in when it is ready, else the template + the sentence), never the form. */

.sn { margin: 1.8em 0 0; padding: 20px 16px 16px; border-radius: 24px; background: var(--gp-stone); color: var(--gp-ink);
  font-size: 16px; line-height: 24px; }
@media (min-width: 768px) { .sn { padding: 24px; } }
/* the card's inside is laid out by its own width (the 720 column, a phone, the ~400 px help panel) */
.sn-card, .sn-output { container-type: inline-size; }
.prose--article .sn { margin-top: 1.8em; }
.sn [hidden] { display: none !important; }
.sn p { margin: 0; }
.sn a { color: var(--gp-link); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: .18em; }
.sn a:hover { color: var(--gp-link-hover); }
.sn :not(pre) > code { padding: .1em .42em; border: 1px solid var(--gp-hairline); border-radius: 6px; background: var(--gp-page);
  color: var(--gp-heading); font-family: var(--gp-font-mono); font-size: .86em; overflow-wrap: anywhere; }
.sn-card { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }

/* ---- head: icon disc + title on one line, the intro under both (narrow) or under the title (wider) ------------- */
.sn-head { display: grid; grid-template-columns: 40px minmax(0, 1fr); align-items: center; gap: 10px 14px; }
.sn-head__icon { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px;
  border-radius: 50%; background: var(--gp-page); color: var(--gp-heading);
  --icon-surface: var(--gp-page); --icon-line: var(--gp-heading); --icon-accent: var(--gp-action); }
.prose--article .sn .sn-title, .sn-title { margin: 0; color: var(--gp-heading); font-size: 20px; line-height: 28px; font-weight: 600;
  letter-spacing: -.01em; }
.sn-intro { grid-column: 1 / -1; color: var(--gp-ink); font-size: 15px; line-height: 22px; }

/* ---- the fields (docs/styleguide.md "Forms") ------------------------------------------------------------------ */
.sn-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.sn-field { display: grid; grid-template-rows: auto auto auto auto; align-content: start; gap: 4px; min-width: 0; }
.sn-label { color: var(--gp-heading); font-size: 15px; line-height: 22px; font-weight: 600; }
.sn-help { color: var(--gp-muted); font-size: 14px; line-height: 20px; }
.sn-input {
  width: 100%; min-height: 48px; margin: 4px 0 0; padding: 10px 14px; border: 1.5px solid var(--gp-line-strong); border-radius: 12px;
  background: var(--gp-page); color: var(--gp-ink); font: 400 16px/24px var(--gp-font-sans); font-variant-numeric: tabular-nums;
  letter-spacing: .02em; -webkit-appearance: none; appearance: none;
}
.sn-input:focus { border-color: var(--gp-focus); outline: none; box-shadow: 0 0 0 3px rgba(36, 95, 212, .22); }
.sn-input[aria-invalid="true"] { border-color: var(--gp-error); }
.sn-input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px rgba(180, 35, 24, .18); }
.sn-error { display: flex; align-items: flex-start; gap: 8px; color: var(--gp-error); font-size: 14px; line-height: 20px; font-weight: 500; }
.sn-error:empty { display: none; }
.sn-error::before { content: "!"; flex: none; width: 18px; height: 18px; margin-top: 1px; border-radius: 50%; background: var(--gp-error);
  color: var(--gp-page); font: 700 12px/18px var(--gp-font-sans); text-align: center; }

.sn-privacy { display: flex; align-items: flex-start; gap: 8px; color: var(--gp-muted); font-size: 14px; line-height: 20px; }
.sn-privacy__icon { flex: none; margin-top: 2px; color: var(--gp-muted); --icon-line: currentColor; --icon-accent: currentColor; }

/* ---- the result: the sentence without JS, the waiting line, the code well ------------------------------------- */
.sn-nojs { margin-top: 18px !important; font-size: 15px; line-height: 22px; }
.sn-waiting { margin-top: 18px !important; padding: 14px 16px; border: 2px dashed var(--gp-line-strong); border-radius: 16px;
  color: var(--gp-muted); font-size: 15px; line-height: 22px; }
.sn-output { margin-top: 18px; min-width: 0; border: 2px solid var(--gp-hairline); border-radius: 16px; background: var(--gp-page); }
.sn-output__bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; min-height: 52px;
  padding: 6px 6px 6px 16px; border-bottom: 1px solid var(--gp-hairline); }
.sn-output__label { color: var(--gp-heading); font-size: 14px; line-height: 20px; font-weight: 600; }
.sn-copy {
  display: inline-flex; flex: none; align-items: center; gap: 8px; min-height: 40px; margin: 0; padding: 0 16px; border: 0;
  border-radius: 10px; background: var(--gp-action); color: var(--gp-action-text); font: 600 15px/20px var(--gp-font-sans);
  cursor: pointer; transition: background-color var(--gp-dur-colour) var(--gp-ease);
}
.sn-copy:hover { background: var(--gp-action-hover); }
.sn-copy:focus-visible { outline: 2px solid var(--gp-focus); outline-offset: 2px; }
.sn-copy__icon { flex: none; color: currentColor; --icon-line: currentColor; --icon-accent: currentColor; }
.sn-copy.is-done, .sn-copy.is-done:hover { background: var(--gp-status-bg); color: var(--gp-status-text); }

/* the code: not wrapped, its own scroll box (both ways); beats .prose--article pre (wraps, no scroll) */
.sn .sn-code {
  max-height: 26rem; margin: 0; padding: 14px 16px; overflow: auto; border: 0; border-radius: 0 0 14px 14px; background: var(--gp-page);
  color: var(--gp-ink); font-family: var(--gp-font-mono); font-size: 13px; line-height: 20px; tab-size: 2; white-space: pre;
  overflow-wrap: normal; scrollbar-width: thin;
}
.sn .sn-code:focus-visible { outline: 2px solid var(--gp-focus); outline-offset: -2px; }
.sn .sn-code code { display: block; width: max-content; min-width: 100%; padding: 0; border: 0; background: none; color: inherit;
  font: inherit; white-space: inherit; }
.sn .sn-token, .sn .sn-value { padding: 0; border-radius: 3px; background: var(--gp-accent-tint); color: var(--gp-heading);
  box-shadow: 0 0 0 2px var(--gp-accent-tint); }
.sn-note { padding: 0 16px 12px; color: var(--gp-ink); font-size: 14px; line-height: 20px; }
.sn-note:empty { display: none; }

/* ---- states (gp-snippets.js) ---------------------------------------------------------------------------------- */
.sn.is-live .sn-nojs { display: none; }
.sn.is-live[data-state="waiting"] .sn-output { display: none; }
.sn.is-live[data-state="ready"] .sn-waiting { display: none !important; }

/* ---- wider: more room, the fields side by side (their inputs on one line: subgrid) ---------------------------- */
@container (min-width: 560px) {
  .sn-form { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); column-gap: 20px; }
  .sn-field { grid-row: span 4; grid-template-rows: subgrid; row-gap: 4px; }
}
@container (min-width: 600px) {
  .sn-head { row-gap: 2px; }
  .sn-intro { grid-column: 2; }
  .sn .sn-code { tab-size: 4; }
}

@media (prefers-reduced-motion: reduce) { .sn-copy { transition: none; } }

/* ---- print: the code, never the form --------------------------------------------------------------------------- */
@media print {
  .sn { padding: 0; background: none; }
  .sn-head { display: block; }
  .sn-intro { margin-top: 4px !important; }
  .sn-head__icon, .sn-form, .sn-privacy, .sn-waiting, .sn-copy, .sn-note { display: none !important; }
  .sn.is-live .sn-output { display: block !important; }
  .sn.is-live:not([data-state="ready"]) .sn-nojs { display: block !important; }
  .sn-output { border-width: 1px; }
  .sn .sn-code { max-height: none; overflow: visible; white-space: pre-wrap; overflow-wrap: anywhere; }
  .sn .sn-code code { width: auto; }
}
