/* Hope Council — shared chrome + helpers for interior wireframe pages.
   Built on the Dooley Wireframe Kit. Grayscale only. Links are relative to
   the prototype-pages/ folder (siblings are bare filenames; the home page
   lives one level up). Content-populated: production copy in place of greeked
   bars. Loaded by each Get Help page before its own *.app.jsx. */

const GK = window.DooleyWireframeKit_e41309;
const { useState: ghUseState } = React;

const HOME_HREF = "../Hope Council - Home.html";
const go = (href) => () => { window.location.href = href; };

/* ---- shared layout helpers (mirrors the home wireframe vocabulary) ------- */

function Dot({ n, anno, top = -11, right = -11, left }) {
  const { Annotation } = GK;
  if (!anno) return null;
  return React.createElement(Annotation, {
    n,
    style: { position: "absolute", top, right: left === undefined ? right : undefined, left, zIndex: 3 },
  });
}

function Para({ text, color = "var(--wf-ink-soft)", size = "var(--wf-text-body)", style, maxWidth }) {
  const arr = Array.isArray(text) ? text : [text];
  return (
    <div style={{ display: "flex", flexDirection: "column", gap: 12, maxWidth, ...style }}>
      {arr.map((t, i) => (
        <p key={i} style={{ margin: 0, font: `var(--wf-weight-regular) ${size}/var(--wf-leading-body) var(--wf-font-sans)`, color, textWrap: "pretty" }}>{t}</p>
      ))}
    </div>
  );
}

function Band({ fill = "surface", id, label, children, pad = "56px 56px", style }) {
  const fills = { surface: "var(--wf-surface)", zone: "var(--wf-zone)", alt: "var(--wf-zone-alt)" };
  return (
    <section data-screen-label={label} id={id} style={{ background: fills[fill], borderTop: "var(--wf-border)", ...style }}>
      <div style={{ maxWidth: 1160, margin: "0 auto", padding: pad }}>{children}</div>
    </section>
  );
}

function SectionHead({ kicker, title, intro, center, maxTitle = 640, introWidth = 760 }) {
  return (
    <div style={{ display: "flex", flexDirection: "column", gap: 14, alignItems: center ? "center" : "flex-start", textAlign: center ? "center" : "left", marginBottom: 32 }}>
      {kicker ? (
        <span style={{ font: "var(--wf-weight-bold) var(--wf-text-label)/1.2 var(--wf-font-sans)", letterSpacing: "var(--wf-tracking-label)", textTransform: "uppercase", color: "var(--wf-ink-muted)" }}>{kicker}</span>
      ) : null}
      <h2 style={{ margin: 0, font: "var(--wf-weight-bold) var(--wf-text-h2)/var(--wf-leading-tight) var(--wf-font-sans)", color: "var(--wf-ink)", maxWidth: maxTitle, textWrap: "balance" }}>{title}</h2>
      {intro ? (
        <Para text={intro} maxWidth={center ? 680 : introWidth} style={{ alignItems: center ? "center" : "flex-start", textAlign: center ? "center" : "left", marginLeft: center ? "auto" : 0, marginRight: center ? "auto" : 0 }} />
      ) : null}
    </div>
  );
}

// CTA marker row used inside cards — one or more real CTA labels routed to
// real targets. Rendered as underlined links with a ▸ marker.
function CardCtas({ ctas }) {
  if (!ctas || !ctas.length) return null;
  return (
    <div style={{ marginTop: "auto", paddingTop: 6, display: "flex", flexDirection: "column", gap: 7 }}>
      {ctas.map((c, i) => (
        <a key={i} href={c[1]} style={{ display: "inline-flex", alignItems: "center", gap: 6, font: "var(--wf-weight-bold) var(--wf-text-small)/1.2 var(--wf-font-sans)", color: "var(--wf-ink)", textDecoration: "none" }}>
          <span style={{ textDecoration: "underline", textUnderlineOffset: 3 }}>{c[0]}</span>
          <span aria-hidden="true">▸</span>
        </a>
      ))}
    </div>
  );
}

// Content card: real title, optional ICO slot, body copy, optional CTA links.
function WireCard({ title, body, ctas, icon = false, big = false, num }) {
  const { ImgPlaceholder } = GK;
  return (
    <div style={{ border: "var(--wf-border)", borderRadius: "var(--wf-radius)", background: "var(--wf-surface)", padding: big ? 22 : 18, display: "flex", flexDirection: "column", gap: big ? 14 : 12, height: "100%" }}>
      {num !== undefined ? (
        <span style={{ display: "inline-flex", alignItems: "center", justifyContent: "center", width: 30, height: 30, borderRadius: "50%", border: "var(--wf-border-strong)", font: "var(--wf-weight-bold) var(--wf-text-small)/1 var(--wf-font-mono)", color: "var(--wf-ink)", flexShrink: 0 }}>{num}</span>
      ) : null}
      {icon ? <ImgPlaceholder kind="image" label="ICO" width={40} height={40} style={{ aspectRatio: "auto", flexShrink: 0 }} /> : null}
      <h3 style={{ margin: 0, font: `var(--wf-weight-bold) ${big ? "var(--wf-text-h3)" : "15px"}/1.25 var(--wf-font-sans)`, color: "var(--wf-ink)" }}>{title}</h3>
      {body ? <Para text={body} size="var(--wf-text-small)" /> : null}
      <CardCtas ctas={ctas} />
    </div>
  );
}

// Card whose body is a set of quoted example lines (e.g. "Try saying this").
function QuoteCard({ title, quotes }) {
  return (
    <div style={{ border: "var(--wf-border)", borderRadius: "var(--wf-radius)", background: "var(--wf-surface)", padding: 18, display: "flex", flexDirection: "column", gap: 12, height: "100%" }}>
      <h3 style={{ margin: 0, font: "var(--wf-weight-bold) 15px/1.25 var(--wf-font-sans)", color: "var(--wf-ink)" }}>{title}</h3>
      <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
        {quotes.map((q, i) => (
          <p key={i} style={{ margin: 0, paddingLeft: 14, borderLeft: "2px solid var(--wf-ink)", font: "var(--wf-weight-regular) var(--wf-text-small)/var(--wf-leading-body) var(--wf-font-sans)", color: "var(--wf-ink-soft)", fontStyle: "italic" }}>{q}</p>
        ))}
      </div>
    </div>
  );
}

/* ---- Breadcrumbs --------------------------------------------------------- */

// trail: array of [label, href] for ancestors and [label] (no href) for the
// current page. Ancestors are underlined links; current page is muted.
function Crumbs({ trail }) {
  const sep = <span aria-hidden="true" style={{ color: "var(--wf-ink-faint)", margin: "0 8px" }}>/</span>;
  const link = { color: "var(--wf-ink)", textDecoration: "underline", textUnderlineOffset: 2 };
  return (
    <nav aria-label="Breadcrumb" style={{ fontSize: "var(--wf-text-small)", color: "var(--wf-ink-muted)", marginBottom: 26 }}>
      {trail.map((t, i) => (
        <React.Fragment key={i}>
          {i > 0 ? sep : null}
          {t[1] ? <a href={t[1]} style={link}>{t[0]}</a> : <span>{t[0]}</span>}
        </React.Fragment>
      ))}
    </nav>
  );
}

/* ---- Stat block (impact numbers) ----------------------------------------- */

function StatBlock({ value, label, note, big }) {
  return (
    <div style={{ border: "var(--wf-border)", borderRadius: "var(--wf-radius)", background: "var(--wf-surface)", padding: "26px 24px", display: "flex", flexDirection: "column", gap: 8, height: "100%" }}>
      <span style={{ font: `var(--wf-weight-bold) ${big ? "52px" : "44px"}/1 var(--wf-font-sans)`, color: "var(--wf-ink)", letterSpacing: "-0.015em" }}>{value}</span>
      <span style={{ fontSize: "var(--wf-text-body)", color: "var(--wf-ink-soft)", lineHeight: 1.45 }}>{label}</span>
      {note ? <span style={{ fontSize: "var(--wf-text-small)", color: "var(--wf-ink-muted)", lineHeight: 1.4 }}>{note}</span> : null}
    </div>
  );
}

/* ---- Wireframe form (Contact section forms) -----------------------------
   fields: [{ label, type, required, placeholder, options, full }]
   type: text | email | tel | select | textarea | checkbox | checkgroup | radiogroup
   checkgroup/radiogroup use `options: []`. `full` spans both columns. */

function WireForm({ title, intro, fields, submit = "Submit", note, cols = 2 }) {
  const { CtaButton } = GK;
  const star = (req) => req ? <span aria-hidden="true" style={{ color: "var(--wf-ink)" }}> *</span> : null;
  const lbl = (f) => (
    <label style={{ font: "var(--wf-weight-bold) var(--wf-text-small)/1.3 var(--wf-font-sans)", color: "var(--wf-ink)" }}>{f.label}{star(f.required)}</label>
  );
  const box = (h) => ({ border: "var(--wf-border-strong)", borderRadius: "var(--wf-radius)", background: "var(--wf-surface)", height: h, display: "flex", alignItems: "center", padding: "0 12px", fontSize: "var(--wf-text-small)", color: "var(--wf-ink-faint)" });
  const field = (f, i) => {
    const span = (f.full || f.type === "textarea" || f.type === "checkgroup" || f.type === "radiogroup" || f.type === "checkbox") ? cols : 1;
    let control;
    if (f.type === "textarea") control = <div style={{ ...box(84), alignItems: "flex-start", paddingTop: 10 }}>{f.placeholder || ""}</div>;
    else if (f.type === "select") control = <div style={{ ...box(40), justifyContent: "space-between" }}><span>{f.placeholder || "Select one\u2026"}</span><span aria-hidden="true" style={{ color: "var(--wf-ink-muted)" }}>{"\u25be"}</span></div>;
    else if (f.type === "checkbox") return (
      <div key={i} style={{ gridColumn: `span ${span}`, display: "flex", gap: 10, alignItems: "flex-start" }}>
        <span aria-hidden="true" style={{ width: 18, height: 18, border: "var(--wf-border-strong)", borderRadius: 2, flexShrink: 0, marginTop: 1 }} />
        <span style={{ fontSize: "var(--wf-text-small)", color: "var(--wf-ink-soft)", lineHeight: 1.4 }}>{f.label}{star(f.required)}</span>
      </div>
    );
    else if (f.type === "checkgroup" || f.type === "radiogroup") {
      const shape = f.type === "radiogroup" ? "50%" : "2px";
      control = (
        <div style={{ display: "flex", flexWrap: "wrap", gap: "8px 20px" }}>
          {f.options.map((o, oi) => (
            <span key={oi} style={{ display: "inline-flex", gap: 8, alignItems: "center" }}>
              <span aria-hidden="true" style={{ width: 16, height: 16, border: "var(--wf-border-strong)", borderRadius: shape, flexShrink: 0 }} />
              <span style={{ fontSize: "var(--wf-text-small)", color: "var(--wf-ink-soft)" }}>{o}</span>
            </span>
          ))}
        </div>
      );
    }
    else control = <div style={box(40)}>{f.placeholder || ""}</div>;
    return (
      <div key={i} style={{ gridColumn: `span ${span}`, display: "flex", flexDirection: "column", gap: 6 }}>
        {lbl(f)}
        {control}
      </div>
    );
  };
  return (
    <div style={{ border: "var(--wf-border-strong)", borderRadius: "var(--wf-radius)", background: "var(--wf-surface)", padding: "28px 32px", maxWidth: 760 }}>
      {title ? <h3 style={{ margin: "0 0 6px", font: "var(--wf-weight-bold) var(--wf-text-h2)/1.2 var(--wf-font-sans)", color: "var(--wf-ink)" }}>{title}</h3> : null}
      {intro ? <p style={{ margin: "0 0 18px", fontSize: "var(--wf-text-small)", color: "var(--wf-ink-soft)", lineHeight: 1.5 }}>{intro}</p> : null}
      <div style={{ display: "grid", gridTemplateColumns: `repeat(${cols}, 1fr)`, gap: 16 }}>
        {fields.map((f, i) => field(f, i))}
      </div>
      <div style={{ marginTop: 20 }}>
        <CtaButton label={submit} size="lg" style={{ whiteSpace: "nowrap" }} />
      </div>
      {note ? <p style={{ margin: "16px 0 0", fontSize: "var(--wf-text-small)", color: "var(--wf-ink-muted)", lineHeight: 1.5 }}>{note}</p> : null}
    </div>
  );
}

/* ---- Directory listing (Local Directories pages) ------------------------
   item: { name, addr, phone, site, note }. phone renders as a tel: link;
   site as an external link; addr + note are plain text. */

function telHref(p) { return "tel:" + String(p).replace(/[^0-9]/g, ""); }

function DirectoryRow({ name, addr, phone, site, note }) {
  const lnk = { color: "var(--wf-ink)", textDecoration: "underline", textUnderlineOffset: 2, fontWeight: "var(--wf-weight-bold)" };
  return (
    <div style={{ border: "var(--wf-border)", borderRadius: "var(--wf-radius)", background: "var(--wf-surface)", padding: "16px 20px", display: "flex", flexDirection: "column", gap: 5 }}>
      <span style={{ font: "var(--wf-weight-bold) var(--wf-text-h3)/1.25 var(--wf-font-sans)", color: "var(--wf-ink)" }}>{name}</span>
      {addr ? <span style={{ fontSize: "var(--wf-text-small)", color: "var(--wf-ink-soft)", lineHeight: 1.45 }}>{addr}</span> : null}
      {(phone || site) ? (
        <span style={{ fontSize: "var(--wf-text-small)", color: "var(--wf-ink-soft)" }}>
          {phone ? <a href={telHref(phone)} style={lnk}>{phone}</a> : null}
          {phone && site ? <span aria-hidden="true" style={{ color: "var(--wf-ink-faint)", margin: "0 8px" }}>·</span> : null}
          {site ? <a href={(/^https?:/.test(site) ? site : "https://" + site)} target="_blank" rel="noopener" style={{ ...lnk, fontWeight: "var(--wf-weight-regular)" }}>{site}</a> : null}
        </span>
      ) : null}
      {note ? <span style={{ fontSize: "var(--wf-text-small)", color: "var(--wf-ink-muted)", lineHeight: 1.45 }}>{note}</span> : null}
    </div>
  );
}

function DirectoryList({ items, cols = 1 }) {
  return (
    <div style={{ display: "grid", gridTemplateColumns: `repeat(${cols}, 1fr)`, gap: 14 }}>
      {items.map((it, i) => <DirectoryRow key={i} {...it} />)}
    </div>
  );
}

/* ---- Emergency box (numbered overdose-response steps + CTAs) ------------- */

function EmergencyBox({ anno, n, label = "Emergency Box", title, steps, closing, ctas, fill = "surface" }) {
  const { CtaButton } = GK;
  return (
    <Band fill={fill} label={label} pad="0 56px 8px">
      <div style={{ position: "relative", border: "3px solid var(--wf-ink)", borderRadius: "var(--wf-radius)", background: "var(--wf-zone)", padding: "26px 30px" }}>
        {n !== undefined ? <Dot n={n} anno={anno} /> : null}
        <h2 style={{ margin: "0 0 16px", font: "var(--wf-weight-bold) var(--wf-text-h2)/1.2 var(--wf-font-sans)", color: "var(--wf-ink)" }}>{title}</h2>
        <ol style={{ margin: 0, padding: 0, listStyle: "none", display: "flex", flexDirection: "column", gap: 11 }}>
          {steps.map((s, i) => (
            <li key={i} style={{ display: "flex", gap: 14, alignItems: "baseline", fontSize: "var(--wf-text-h3)", color: "var(--wf-ink-soft)", lineHeight: 1.4 }}>
              <span aria-hidden="true" style={{ flexShrink: 0, display: "inline-flex", alignItems: "center", justifyContent: "center", width: 28, height: 28, borderRadius: "50%", background: "var(--wf-ink)", color: "var(--wf-cta-ink)", font: "var(--wf-weight-bold) var(--wf-text-small)/1 var(--wf-font-mono)" }}>{i + 1}</span>
              <span>{s}</span>
            </li>
          ))}
        </ol>
        {closing ? <p style={{ margin: "16px 0 0", fontSize: "var(--wf-text-body)", color: "var(--wf-ink-soft)", lineHeight: 1.55, fontStyle: "italic" }}>{closing}</p> : null}
        {ctas && ctas.length ? (
          <div style={{ display: "flex", flexWrap: "wrap", gap: 12, marginTop: 18 }}>
            {ctas.map((c, i) => <CtaButton key={i} label={c[0]} emphasis={i === 0 ? "primary" : "secondary"} style={{ whiteSpace: "nowrap" }} onClick={go(c[1])} />)}
          </div>
        ) : null}
      </div>
    </Band>
  );
}

/* ---- Crisis callout (condensed bordered crisis paragraph) ---------------- */

function CrisisCallout({ anno, n, label = "Crisis Callout", title, fill = "surface", children }) {
  return (
    <Band fill={fill} label={label} pad="0 56px 8px">
      <div style={{ position: "relative", border: "2px solid var(--wf-ink)", borderRadius: "var(--wf-radius)", background: "var(--wf-zone)", padding: "22px 28px" }}>
        {n !== undefined ? <Dot n={n} anno={anno} /> : null}
        {title ? <h2 style={{ margin: "0 0 10px", font: "var(--wf-weight-bold) var(--wf-text-h3)/1.2 var(--wf-font-sans)", color: "var(--wf-ink)" }}>{title}</h2> : null}
        <p style={{ margin: 0, fontSize: "var(--wf-text-body)", color: "var(--wf-ink-soft)", lineHeight: 1.6, textWrap: "pretty" }}>{children}</p>
      </div>
    </Band>
  );
}

/* ---- Signs list (substance pages: "Worth a conversation if…") ------------ */

function SignsList({ items, closing, note }) {
  return (
    <div style={{ maxWidth: 820 }}>
      <ul style={{ margin: 0, padding: 0, listStyle: "none", display: "grid", gridTemplateColumns: "repeat(2, 1fr)", gap: "10px 28px" }}>
        {items.map((it, i) => (
          <li key={i} style={{ position: "relative", paddingLeft: 22, fontSize: "var(--wf-text-body)", color: "var(--wf-ink-soft)", lineHeight: 1.5 }}>
            <span aria-hidden="true" style={{ position: "absolute", left: 0, color: "var(--wf-ink)", fontWeight: "var(--wf-weight-bold)" }}>▸</span>{it}
          </li>
        ))}
      </ul>
      {closing ? <p style={{ margin: "22px 0 0", fontSize: "var(--wf-text-h3)", color: "var(--wf-ink-soft)", lineHeight: 1.5, fontWeight: "var(--wf-weight-bold)", textWrap: "pretty" }}>{closing}</p> : null}
      {note ? <p style={{ margin: "14px 0 0", fontSize: "var(--wf-text-small)", color: "var(--wf-ink-muted)", lineHeight: 1.5, fontStyle: "italic" }}>{note}</p> : null}
    </div>
  );
}

/* ---- Image strip (substance pages: "What It Looks Like Now") -------------
   items: [{ label, note, caption }]. Renders labeled IMG placeholders that
   carry the copy's art direction (note), with a caption beneath each — ready
   for real or AI-generated photography in the design phase. */

function ImageStrip({ items, cols }) {
  const { ImgPlaceholder } = GK;
  return (
    <div style={{ display: "grid", gridTemplateColumns: `repeat(${cols || items.length}, 1fr)`, gap: 18 }}>
      {items.map((it, i) => (
        <figure key={i} style={{ margin: 0, display: "flex", flexDirection: "column", gap: 10 }}>
          <ImgPlaceholder kind="image" label="IMG" note={it.note} style={{ aspectRatio: "4 / 3", borderRadius: "var(--wf-radius)" }} />
          <figcaption style={{ fontSize: "var(--wf-text-small)", color: "var(--wf-ink-soft)", lineHeight: 1.45, textWrap: "pretty" }}>
            <strong style={{ color: "var(--wf-ink)" }}>{it.label}.</strong> {it.caption}
          </figcaption>
        </figure>
      ))}
    </div>
  );
}

/* ---- Source / review note (substance pages footer) ----------------------- */

function SourceNote({ text }) {
  return (
    <Band fill="surface" label="Sources And Review" pad="8px 56px 40px">
      <p style={{ margin: 0, maxWidth: 820, fontSize: "var(--wf-text-small)", color: "var(--wf-ink-muted)", lineHeight: 1.5, borderTop: "var(--wf-border)", paddingTop: 16 }}>
        {text} <span style={{ fontStyle: "italic" }}>[Content review date displays here.]</span>
      </p>
    </Band>
  );
}

/* ---- Page header (.page-intro equivalent) -------------------------------- */

function PageHeader({ anno, eyebrow, title, lead, primary, secondary = [], n }) {
  const { CtaButton } = GK;
  return (
    <Band fill="surface" label="Page Header" style={{ borderTop: "none" }} pad="48px 56px 40px">
      <div style={{ position: "relative", maxWidth: 880, display: "flex", flexDirection: "column", gap: 18 }}>
        {n !== undefined ? <Dot n={n} anno={anno} top={-12} left={-12} /> : null}
        {eyebrow ? (
          <span style={{ font: "var(--wf-weight-bold) var(--wf-text-label)/1.3 var(--wf-font-sans)", letterSpacing: "var(--wf-tracking-label)", textTransform: "uppercase", color: "var(--wf-ink-muted)" }}>{eyebrow}</span>
        ) : null}
        <h1 style={{ margin: 0, font: "var(--wf-weight-bold) var(--wf-text-h1)/var(--wf-leading-tight) var(--wf-font-sans)", color: "var(--wf-ink)", textWrap: "balance" }}>{title}</h1>
        <Para text={lead} size="var(--wf-text-h3)" />
        <div style={{ display: "flex", flexWrap: "wrap", gap: 12, marginTop: 6 }}>
          {primary ? <CtaButton label={primary[0]} size="lg" style={{ whiteSpace: "nowrap" }} onClick={go(primary[1])} /> : null}
          {secondary.map((s, i) => (
            <CtaButton key={i} label={s[0]} emphasis="secondary" size="lg" style={{ whiteSpace: "nowrap" }} onClick={go(s[1])} />
          ))}
        </div>
      </div>
    </Band>
  );
}

/* ---- Urgent Help Panel (shared) ------------------------------------------ */

function UrgentHelpPanel({ anno, n, related }) {
  const tel = { color: "var(--wf-ink)", fontWeight: "var(--wf-weight-bold)", textDecoration: "underline", textUnderlineOffset: 2 };
  const lines = [
    ["If someone is in immediate danger, call ", "911", "tel:911", "."],
    ["If someone may be overdosing, call ", "911", "tel:911", ", give naloxone if available, and stay with the person until help arrives."],
    ["For mental health or substance use crisis support, call or text ", "988", "tel:988", "."],
    ["For local 24/7 crisis support, call ", "262-657-7188", "tel:2626577188", "."],
    ["For Hope Council support during business hours, call ", "262-658-8166", "tel:2626588166", "."],
  ];
  return (
    <Band fill="surface" label="Urgent Help Panel" pad="0 56px 8px">
      <div style={{ position: "relative", border: "2px solid var(--wf-ink)", borderRadius: "var(--wf-radius)", background: "var(--wf-zone)", padding: "28px 32px" }}>
        {n !== undefined ? <Dot n={n} anno={anno} /> : null}
        <div style={{ display: "grid", gridTemplateColumns: related ? "1.6fr 1fr" : "1fr", gap: 36 }}>
          <div style={{ display: "flex", flexDirection: "column", gap: 14 }}>
            <h2 style={{ margin: 0, font: "var(--wf-weight-bold) var(--wf-text-h3)/1.2 var(--wf-font-sans)", color: "var(--wf-ink)" }}>Need help right now?</h2>
            <p style={{ margin: 0, fontSize: "var(--wf-text-body)", color: "var(--wf-ink-soft)" }}>If this is an emergency, use the fastest help available.</p>
            <ul style={{ margin: 0, padding: 0, listStyle: "none", display: "flex", flexDirection: "column", gap: 9 }}>
              {lines.map((l, i) => (
                <li key={i} style={{ fontSize: "var(--wf-text-body)", color: "var(--wf-ink-soft)", paddingLeft: 16, position: "relative", lineHeight: 1.5 }}>
                  <span aria-hidden="true" style={{ position: "absolute", left: 0, color: "var(--wf-ink)" }}>—</span>
                  {l[0]}<a href={l[2]} style={tel}>{l[1]}</a>{l[3]}
                </li>
              ))}
            </ul>
          </div>
          {related ? (
            <div style={{ display: "flex", flexDirection: "column", gap: 10, borderLeft: "var(--wf-border)", paddingLeft: 28 }}>
              <span style={{ font: "var(--wf-weight-bold) var(--wf-text-label)/1.2 var(--wf-font-sans)", letterSpacing: "var(--wf-tracking-label)", textTransform: "uppercase", color: "var(--wf-ink-muted)" }}>Related Links</span>
              {related.map((r, i) => (
                <a key={i} href={r[1]} style={{ fontSize: "var(--wf-text-body)", color: "var(--wf-ink)", textDecoration: "underline", textUnderlineOffset: 3 }}>{r[0]}</a>
              ))}
            </div>
          ) : null}
        </div>
      </div>
    </Band>
  );
}

/* ---- Quick Links grid ---------------------------------------------------- */

function LinkGrid({ links, cols = 3 }) {
  return (
    <div style={{ display: "grid", gridTemplateColumns: `repeat(${cols}, 1fr)`, gap: 14 }}>
      {links.map((l, i) => (
        <a key={i} href={l[1]} style={{ display: "flex", justifyContent: "space-between", alignItems: "center", gap: 12, border: "var(--wf-border)", borderRadius: "var(--wf-radius)", padding: "14px 16px", background: "var(--wf-surface)", textDecoration: "none" }}>
          <span style={{ font: "var(--wf-weight-bold) 15px/1.3 var(--wf-font-sans)", color: "var(--wf-ink)" }}>{l[0]}</span>
          <span aria-hidden="true" style={{ color: "var(--wf-ink-muted)", flexShrink: 0 }}>▸</span>
        </a>
      ))}
    </div>
  );
}

/* ---- Bulleted / definition lists ----------------------------------------- */

function BulletList({ items, marker = "▸", columns = 1 }) {
  return (
    <ul style={{ margin: 0, padding: 0, listStyle: "none", display: "grid", gridTemplateColumns: `repeat(${columns}, 1fr)`, gap: "8px 28px" }}>
      {items.map((it, i) => (
        <li key={i} style={{ position: "relative", paddingLeft: 22, fontSize: "var(--wf-text-body)", color: "var(--wf-ink-soft)", lineHeight: 1.5 }}>
          <span aria-hidden="true" style={{ position: "absolute", left: 0, color: "var(--wf-ink)", fontWeight: "var(--wf-weight-bold)" }}>{marker}</span>{it}
        </li>
      ))}
    </ul>
  );
}

function DefinitionList({ rows }) {
  return (
    <dl style={{ margin: 0, display: "grid", gridTemplateColumns: "max-content 1fr", gap: "10px 24px" }}>
      {rows.map((r, i) => (
        <React.Fragment key={i}>
          <dt style={{ font: "var(--wf-weight-bold) var(--wf-text-body)/1.4 var(--wf-font-sans)", color: "var(--wf-ink)" }}>{r[0]}</dt>
          <dd style={{ margin: 0, fontSize: "var(--wf-text-body)", color: "var(--wf-ink-soft)", lineHeight: 1.5 }}>{r[1]}</dd>
        </React.Fragment>
      ))}
    </dl>
  );
}

/* ---- Fee table ----------------------------------------------------------- */

function FeeTable({ title, caption, rows, notes }) {
  return (
    <div style={{ border: "var(--wf-border)", borderRadius: "var(--wf-radius)", background: "var(--wf-surface)", overflow: "hidden", display: "flex", flexDirection: "column" }}>
      {title ? (
        <div style={{ padding: "14px 18px", borderBottom: "var(--wf-border-strong)", background: "var(--wf-zone)" }}>
          <h3 style={{ margin: 0, font: "var(--wf-weight-bold) var(--wf-text-h3)/1.25 var(--wf-font-sans)", color: "var(--wf-ink)" }}>{title}</h3>
          {caption ? <p style={{ margin: "6px 0 0", fontSize: "var(--wf-text-small)", color: "var(--wf-ink-muted)", lineHeight: 1.5 }}>{caption}</p> : null}
        </div>
      ) : null}
      <table style={{ width: "100%", borderCollapse: "collapse", fontSize: "var(--wf-text-body)" }}>
        <tbody>
          {rows.map((r, i) => (
            <tr key={i} style={{ borderTop: i === 0 ? "none" : "1px solid var(--wf-line-soft)" }}>
              <td style={{ padding: "11px 18px", color: "var(--wf-ink-soft)", lineHeight: 1.45 }}>{r[0]}</td>
              <td style={{ padding: "11px 18px", textAlign: "right", whiteSpace: "nowrap", fontWeight: "var(--wf-weight-bold)", color: "var(--wf-ink)" }}>{r[1]}</td>
            </tr>
          ))}
        </tbody>
      </table>
      {notes && notes.length ? (
        <div style={{ padding: "14px 18px", borderTop: "var(--wf-border)", display: "flex", flexDirection: "column", gap: 8 }}>
          {notes.map((nNote, i) => (
            <p key={i} style={{ margin: 0, fontSize: "var(--wf-text-small)", color: "var(--wf-ink-muted)", lineHeight: 1.5 }}>{nNote}</p>
          ))}
        </div>
      ) : null}
    </div>
  );
}

/* ---- Testimonial block --------------------------------------------------- */

function Testimonial({ quote, attribution }) {
  return (
    <figure style={{ margin: 0, border: "var(--wf-border-strong)", borderRadius: "var(--wf-radius)", background: "var(--wf-zone)", padding: "32px 36px", display: "flex", flexDirection: "column", gap: 16 }}>
      <span aria-hidden="true" style={{ font: "var(--wf-weight-bold) 48px/0.6 var(--wf-font-sans)", color: "var(--wf-ink-muted)" }}>&ldquo;</span>
      <blockquote style={{ margin: 0, font: "var(--wf-weight-regular) var(--wf-text-h3)/1.45 var(--wf-font-sans)", color: "var(--wf-ink)", textWrap: "pretty" }}>{quote}</blockquote>
      <figcaption style={{ fontSize: "var(--wf-text-body)", fontWeight: "var(--wf-weight-bold)", color: "var(--wf-ink-soft)" }}>{attribution}</figcaption>
    </figure>
  );
}

/* ---- Featured program block (Loved Ones Support Group) ------------------- */

function FeaturedBlock({ anno, n, label, title, body, details, cta }) {
  const { CtaButton } = GK;
  return (
    <Band fill="zone" label={label}>
      <div style={{ position: "relative", border: "var(--wf-border-strong)", borderRadius: "var(--wf-radius)", background: "var(--wf-surface)", padding: "36px 40px" }}>
        {n !== undefined ? <Dot n={n} anno={anno} /> : null}
        <div style={{ display: "grid", gridTemplateColumns: "1.5fr 1fr", gap: 44 }}>
          <div style={{ display: "flex", flexDirection: "column", gap: 16 }}>
            <h2 style={{ margin: 0, font: "var(--wf-weight-bold) var(--wf-text-h2)/1.2 var(--wf-font-sans)", color: "var(--wf-ink)", textWrap: "balance" }}>{title}</h2>
            <Para text={body} />
          </div>
          <div style={{ display: "flex", flexDirection: "column", gap: 18, borderLeft: "var(--wf-border)", paddingLeft: 36, justifyContent: "center" }}>
            <span style={{ font: "var(--wf-weight-bold) var(--wf-text-label)/1.2 var(--wf-font-sans)", letterSpacing: "var(--wf-tracking-label)", textTransform: "uppercase", color: "var(--wf-ink-muted)" }}>Details</span>
            <DefinitionList rows={details} />
            {cta ? <CtaButton label={cta[0]} style={{ whiteSpace: "nowrap", alignSelf: "flex-start" }} onClick={go(cta[1])} /> : null}
          </div>
        </div>
      </div>
    </Band>
  );
}

/* ---- FAQ preview --------------------------------------------------------- */

function FaqItem({ q, a, open, onToggle }) {
  return (
    <div style={{ borderTop: "var(--wf-border)" }}>
      <button type="button" onClick={onToggle} aria-expanded={open}
        style={{ width: "100%", display: "flex", alignItems: "center", justifyContent: "space-between", gap: 16, padding: "16px 4px", background: "none", border: "none", cursor: "pointer", textAlign: "left", font: "var(--wf-weight-bold) var(--wf-text-h3)/1.3 var(--wf-font-sans)", color: "var(--wf-ink)" }}>
        {q}<span aria-hidden="true" style={{ color: "var(--wf-ink-muted)", fontSize: 13, flexShrink: 0 }}>{open ? "▴" : "▾"}</span>
      </button>
      {open ? (
        <div style={{ padding: "0 4px 18px" }}>
          <Para text={a} />
        </div>
      ) : null}
    </div>
  );
}

function FaqPreview({ anno, n, faqs }) {
  const [open, setOpen] = ghUseState(0);
  return (
    <Band fill="surface" label="FAQ Preview">
      <div style={{ position: "relative", maxWidth: 820, margin: "0 auto" }}>
        {n !== undefined ? <Dot n={n} anno={anno} top={-12} right={-12} /> : null}
        <SectionHead title="Common Questions" center />
        <div style={{ borderBottom: "var(--wf-border)" }}>
          {faqs.map((f, i) => (
            <FaqItem key={i} q={f[0]} a={f[1]} open={open === i} onToggle={() => setOpen(open === i ? -1 : i)} />
          ))}
        </div>
      </div>
    </Band>
  );
}

/* ---- Global chrome: utility strip ---------------------------------------- */

function SiteUtilityStrip({ anno, n }) {
  const link = { color: "var(--wf-ink)", textDecoration: "underline", textUnderlineOffset: 2 };
  return (
    <div style={{ position: "relative", background: "var(--wf-zone-alt)", borderBottom: "var(--wf-border-strong)" }}>
      {n !== undefined ? <Dot n={n} anno={anno} top={8} right={8} /> : null}
      <div style={{ maxWidth: 1160, margin: "0 auto", padding: "8px 56px", display: "flex", flexWrap: "wrap", justifyContent: "space-between", gap: 16, fontSize: "var(--wf-text-small)", color: "var(--wf-ink-soft)" }}>
        <span style={{ maxWidth: 640 }}>
          Need help now? If someone is in immediate danger or may be overdosing, call <a href="tel:911" style={link}>911</a>. For mental health or substance use crisis support, call or text <a href="tel:988" style={link}>988</a>. Local 24/7 crisis support: <a href="tel:2626577188" style={link}>262-657-7188</a>.
        </span>
        <span style={{ display: "flex", gap: 18, alignItems: "center" }}>
          <a href="tel:2626588166" style={link}>262-658-8166</a>
          <span style={{ color: "var(--wf-ink-muted)" }}>6103 39th Ave., Kenosha, WI 53142</span>
          <a href="donate.html" style={{ ...link, fontWeight: "var(--wf-weight-bold)" }}>Donate</a>
        </span>
      </div>
    </div>
  );
}

/* ---- Global chrome: primary navigation ----------------------------------- */

const NAV = [
  { label: "Get Help", href: "get-help.html", items: [
    ["Find Help", "get-help.html"],
    ["For Myself", "get-help-for-myself.html"],
    ["For a Loved One", "get-help-for-a-loved-one.html"],
  ] },
  { label: "About", href: "about.html", items: [
    ["About Us", "about.html"],
    ["Mission & History", "mission-history.html"],
    ["Staff & Board", "staff-board.html"],
    ["Partners & Funders", "partners-funders.html"],
    ["Impact", "impact.html"],
    ["News", "news.html"],
    ["Recovery Meeting Calendar", "recovery-meeting-calendar.html"],
  ] },
  { label: "Get Involved", href: "get-involved.html", items: [
    ["Ways to Help", "get-involved.html"],
    ["Volunteer", "volunteer.html"],
    ["Careers", "careers.html"],
    ["Share Your Story", "share-your-story.html"],
    ["Sponsor", "sponsor.html"],
    ["Donate", "donate.html"],
    ["Events", "events.html"],
  ] },
  { label: "Programs & Services", href: "programs-services.html", wide: true, groups: [
    { head: ["Services Overview", "programs-services.html"], items: [] },
    { head: ["Court-Referred & Diversion", "court-referred-diversion.html"], items: [
      ["Intoxicated Driver Program", "intoxicated-driver-program.html"],
      ["AODA Assessments", "aoda-assessments.html"],
      ["UDAAP", "udaap.html"],
      ["Hold-Open / Alternative Agreements", "hold-open-alternative-agreements.html"],
    ] },
    { head: ["Alcohol & Drug Testing", "alcohol-drug-testing.html"], items: [
      ["Direct Biomarker", "direct-biomarker.html"],
      ["Urine Testing", "urine-testing.html"],
      ["Breathalyzer", "breathalyzer.html"],
      ["Child Guard", "child-guard.html"],
    ] },
    { head: ["Family Services", "family-services.html"], items: [
      ["Supervised Visitation / Parenting Time", "supervised-visitation-parenting-time.html"],
      ["Loved Ones Support Group", "loved-ones-support-group.html"],
      ["Parent Peer Support", "parent-peer-support.html"],
    ] },
    { head: ["Prevention & Advocacy", "prevention-advocacy.html"], items: [
      ["Evidence-Based Prevention Programming", "evidence-based-prevention-programming.html"],
      ["Mental Health First Aid", "mental-health-first-aid.html"],
      ["Kenosha County Substance Abuse Coalition", "kenosha-county-substance-abuse-coalition.html"],
      ["KRW Tobacco-Free Coalition", "krw-tobacco-free-coalition.html"],
    ] },
    { head: ["Treatment", "treatment.html"], items: [
      ["Peer Support", "peer-support.html"],
      ["Moral Reconation Therapy", "moral-reconation-therapy.html"],
      ["Individual & Group Counseling", "individual-group-counseling.html"],
    ] },
    { head: ["Risk Reduction", "risk-reduction.html"], items: [
      ["Public Health Vending Machine", "public-health-vending-machine.html"],
      ["Safer-Use Support & Supplies", "safer-use-support-supplies.html"],
    ] },
  ] },
  { label: "Resources", href: "resources.html", wide: true, groups: [
    { head: ["Resource Library", "resources.html"], items: [] },
    { head: ["Substance Information", "substance-information.html"], items: [
      ["Alcohol", "alcohol.html"],
      ["Cannabis", "cannabis.html"],
      ["Opioids", "opioids.html"],
      ["Fentanyl & Xylazine", "fentanyl-xylazine.html"],
      ["Vaping & E-Cigarettes", "vaping.html"],
      ["Tobacco & Nicotine", "tobacco-nicotine.html"],
    ] },
    { head: ["Youth and Teens", "youth-and-teens.html"], items: [
      ["Talking to Youth About Substance Use", "talking-to-youth-about-substance-use.html"],
      ["Talking to Teens About Substance Use", "talking-to-teens-about-substance-use.html"],
      ["Vaping & Nicotine", "vaping-nicotine.html"],
    ] },
    { head: ["Recovery & Support", "recovery-support.html"], items: [
      ["Recovery Options", "recovery-options.html"],
      ["Supporting a Loved One", "supporting-a-loved-one.html"],
      ["Stigma & Language", "stigma-and-language.html"],
      ["How to Help Someone Who Does Not Want Help", "help-someone-who-does-not-want-help.html"],
    ] },
    { head: ["Overdose Prevention", "overdose-prevention.html"], items: [
      ["Signs of Opioid Overdose", "signs-of-opioid-overdose.html"],
      ["How to Use Naloxone", "how-to-use-naloxone.html"],
      ["After an Overdose", "after-an-overdose.html"],
    ] },
    { head: ["Local Directories", "local-directories.html"], items: [
      ["Treatment Providers", "treatment-providers.html"],
      ["MAT Providers", "mat-providers.html"],
      ["Crisis & Immediate Support", "crisis-and-immediate-support.html"],
      ["Safe Medication Disposal", "safe-medication-disposal.html"],
      ["Syringe Service Providers", "syringe-service-providers.html"],
      ["Vending Machines", "vending-machines.html"],
    ] },
  ] },
  { label: "Contact", href: "contact.html", items: [
    ["Contact Us", "contact.html"],
    ["General Inquiry", "general-inquiry.html"],
    ["Referral Form", "referral-form.html"],
    ["Intoxicated Driver Intake Form", "idp-intake-form.html"],
    ["Volunteer Interest", "volunteer-interest.html"],
    ["Request a Speaker", "request-a-speaker.html"],
  ] },
];

function DropLink({ label, href, strong }) {
  const [hover, setHover] = ghUseState(false);
  return (
    <a href={href}
      onMouseEnter={() => setHover(true)} onMouseLeave={() => setHover(false)}
      style={{ display: "block", padding: "5px 8px", margin: "1px -8px", borderRadius: "var(--wf-radius)", fontSize: strong ? "var(--wf-text-body)" : "var(--wf-text-small)", fontWeight: strong ? "var(--wf-weight-bold)" : "var(--wf-weight-regular)", color: hover || strong ? "var(--wf-ink)" : "var(--wf-ink-soft)", background: hover ? "var(--wf-zone)" : "transparent", textDecoration: hover ? "underline" : "none", textUnderlineOffset: 2 }}>{label}</a>
  );
}

function SiteNav({ anno, n, active }) {
  const { ImgPlaceholder, CtaButton } = GK;
  const [open, setOpen] = ghUseState(-1);
  const [homeHover, setHomeHover] = ghUseState(false);
  const closeTimer = React.useRef(null);
  const cancelClose = () => { if (closeTimer.current) { clearTimeout(closeTimer.current); closeTimer.current = null; } };
  const openHub = (i) => { cancelClose(); setOpen(i); };
  const scheduleClose = () => { cancelClose(); closeTimer.current = setTimeout(() => setOpen(-1), 180); };
  const itemStyle = (isActive) => ({
    display: "inline-flex", alignItems: "center", gap: 5, cursor: "pointer", padding: "6px 2px",
    font: `var(--wf-weight-${isActive ? "bold" : "medium"}) var(--wf-text-body)/1 var(--wf-font-sans)`,
    color: "var(--wf-ink)", background: "none", border: "none",
    borderBottom: isActive ? "2px solid var(--wf-ink)" : "2px solid transparent",
  });
  return (
    <div style={{ position: "relative", background: "var(--wf-surface)", borderBottom: "var(--wf-border-strong)", zIndex: 5 }}>
      {n !== undefined ? <Dot n={n} anno={anno} top={10} right={8} /> : null}
      <div style={{ maxWidth: 1160, margin: "0 auto", padding: "14px 56px", display: "flex", alignItems: "center", justifyContent: "space-between", gap: 24 }}>
        <a href={HOME_HREF} style={{ flexShrink: 0 }}>
          <ImgPlaceholder kind="logo" width={132} height={40} style={{ aspectRatio: "auto" }} />
        </a>
        <nav style={{ display: "flex", alignItems: "center", gap: 22 }} onMouseEnter={cancelClose} onMouseLeave={scheduleClose}>
          <a href={HOME_HREF} style={{ ...itemStyle(homeHover), textDecoration: "none" }} onMouseEnter={() => { openHub(-1); setHomeHover(true); }} onMouseLeave={() => setHomeHover(false)}>Home</a>
          {NAV.map((hub, i) => (
            <div key={i} style={{ position: "relative" }} onMouseEnter={() => openHub(i)}>
              <a href={hub.href} style={{ ...itemStyle(hub.label === active || open === i), textDecoration: "none" }} aria-haspopup="true" aria-expanded={open === i}>
                {hub.label}<span aria-hidden="true" style={{ fontSize: 9, color: "var(--wf-ink-muted)" }}>▾</span>
              </a>
              {open === i ? (
                <div style={{ position: "absolute", top: "100%", left: hub.wide ? "auto" : 0, right: hub.wide ? 0 : "auto", paddingTop: 8, zIndex: 10 }}>
                  <div style={{ background: "var(--wf-surface)", border: "var(--wf-border-strong)", borderRadius: "var(--wf-radius)", padding: hub.wide ? 20 : "12px 16px", minWidth: hub.wide ? 720 : 240 }}>
                  {hub.wide ? (
                    <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: "18px 28px" }}>
                      {hub.groups.map((g, gi) => (
                        <div key={gi}>
                          <DropLink label={g.head[0]} href={g.head[1]} strong />
                          {g.items.map((it, ii) => <DropLink key={ii} label={it[0]} href={it[1]} />)}
                        </div>
                      ))}
                    </div>
                  ) : (
                    hub.items.map((it, ii) => <DropLink key={ii} label={it[0]} href={it[1]} strong={ii === 0} />)
                  )}
                  </div>
                </div>
              ) : null}
            </div>
          ))}
          <span onMouseEnter={() => openHub(-1)}><CtaButton label="Get Help" size="sm" style={{ whiteSpace: "nowrap" }} onClick={go("get-help.html")} /></span>
        </nav>
      </div>
    </div>
  );
}

/* ---- Global chrome: footer ----------------------------------------------- */

function SiteFooter() {
  const { FooterBlock } = GK;
  return (
    <FooterBlock
      columns={[
        { heading: "Get Help", links: ["Find Help", "For Myself", "For a Loved One"] },
        { heading: "Programs & Services", links: ["Court-Referred & Diversion", "Testing", "Family Services", "Treatment", "Risk Reduction"] },
        { heading: "Resources", links: ["Substance Information", "Youth & Teens", "Recovery & Support", "Overdose Prevention", "Local Directories"] },
        { heading: "About & Involved", links: ["About Us", "Impact", "Volunteer", "Donate", "Contact"] },
      ]}
      legal="Hope Council website prototype. Copy on this page is production copy under client review."
    />
  );
}

/* ---- Review chrome: toolbar + page shell --------------------------------- */

function Toolbar({ anno, setAnno, grid, setGrid }) {
  const btn = (activeBtn) => ({
    font: "var(--wf-weight-bold) var(--wf-text-small)/1 var(--wf-font-mono)",
    padding: "7px 12px", borderRadius: "var(--wf-radius)", cursor: "pointer",
    border: "var(--wf-border-strong)",
    background: activeBtn ? "var(--wf-ink)" : "var(--wf-surface)",
    color: activeBtn ? "var(--wf-cta-ink)" : "var(--wf-ink-soft)",
  });
  return (
    <div style={{ display: "flex", gap: 8, alignItems: "center", marginBottom: 16 }}>
      <span style={{ font: "var(--wf-weight-bold) 10px/1 var(--wf-font-mono)", letterSpacing: "0.06em", textTransform: "uppercase", color: "var(--wf-ink-faint)", marginRight: 4 }}>Review</span>
      <button type="button" style={btn(anno)} onClick={() => setAnno(!anno)}>Annotations {anno ? "ON" : "OFF"}</button>
      <button type="button" style={btn(grid)} onClick={() => setGrid(!grid)}>Grid {grid ? "ON" : "OFF"}</button>
    </div>
  );
}

// PageShell — review toolbar + bordered page frame + annotation rail.
// `children` is a render function receiving the live `anno` flag.
function PageShell({ title, template, version, date, note, active, annotations, children }) {
  const { PageFrame, AnnotationList } = GK;
  const [anno, setAnno] = ghUseState(true);
  const [grid, setGrid] = ghUseState(false);
  return (
    <div style={{ minHeight: "100vh", padding: "28px 28px 80px", overflowX: "auto" }}>
      <div style={{ width: "fit-content", margin: "0 auto", display: "flex", flexDirection: "column" }}>
        <Toolbar anno={anno} setAnno={setAnno} grid={grid} setGrid={setGrid} />
        <div style={{ display: "flex", gap: 28, alignItems: "flex-start" }}>
          <div style={{ flex: "0 0 1280px", width: 1280 }}>
            <PageFrame title={title} template={template} version={version} date={date} note={note} width={1280} maxWidth={1280} showGrid={grid}>
              <SiteUtilityStrip anno={anno} n={1} />
              <SiteNav anno={anno} n={2} active={active} />
              {children(anno)}
              <SiteFooter />
            </PageFrame>
          </div>
          {anno ? (
            <div style={{ flex: "0 0 320px", position: "sticky", top: 28, maxHeight: "calc(100vh - 56px)", overflowY: "auto" }}>
              <AnnotationList title={`Annotations — ${title}`} items={annotations} />
            </div>
          ) : null}
        </div>
      </div>
    </div>
  );
}

Object.assign(window, {
  ghGo: go, ghHOME: HOME_HREF,
  Dot, Para, Band, SectionHead, CardCtas, WireCard, QuoteCard, Crumbs, StatBlock,
  SignsList, ImageStrip, SourceNote, CrisisCallout, EmergencyBox, DirectoryList, DirectoryRow, WireForm,
  PageHeader, UrgentHelpPanel, LinkGrid, BulletList, DefinitionList,
  FeeTable, Testimonial, FeaturedBlock, FaqItem, FaqPreview,
  SiteUtilityStrip, SiteNav, SiteFooter, Toolbar, PageShell,
});
