              "Unknown variables: " + esc(unknown.join(", "))) : null),
          (warns.length ? el("div", {class:"notice err", style:"font-size:.82rem;margin-bottom:10px"},
              "Validation: " + esc(warns.join("; "))) : null),
          el("div", {class:"pv-frame"}, el("iframe", {srcdoc: d.rendered_html})));
        openModal("Preview — " + tname, node, { xw:true, buttons:[{label:"Close",kind:"btn secondary",onClick:(c)=>c()}]});
      } catch (err) { toast("Preview failed: " + err.message, "err"); }
    }
    if (b.dataset.edit) {
      const d = await GET(`/templates/${id}`);
      editorModal(d);
    }
    if (b.dataset.dup) {
      const d = await POST(`/templates/${id}/duplicate`);
      toast(`Duplicated (new id ${d.id})`, "ok"); await load();
    }
    if (b.dataset.pdf) {
      b.disabled = true; b.textContent = "Rendering…";
      try {
        const d = await POST(`/templates/${id}/test-pdf`);
        const blob = b64Blob(d.pdf_base64, "application/pdf");
        dlBlob(blob, `template_${id}_test.pdf`);
---
keys: ['id', 'name', 'subject_hint', 'body_html', 'body_text', 'variables', 'unknown_variables']
body_text repr: ''
