Create a complete presentation on capnographs

Asking for Preferences
Reading File
Reading File
Searching the Web

capnography ICU anesthesia waveform interpretation clinical applications 2024

Reading File
Finding Sources
Reading Web Page

https://respiratory-therapy.com/department-management/clinic…

Reading File
Reading File
Finding Sources
Reading File
Finding Sources
Reading File
Reading File
Reading File
Finding Sources
Running Command

mkdir -p /home/daytona/workspace/capnography-pptx && ls /home/daytona/workspace/…

Writing File

~/capnography-pptx/build.js

const pptxgen = require("pptxgenjs");

const pres = new pptxgen();
pres.layout = "LAYOUT_16x9";
pres.author = "Orris";
pres.title = "Capnography: Principles, Waveforms & Clinical Applications";

// ─── COLOR PALETTE ───────────────────────────────────────────────────────────
// Dark teal dominates; neon lime accent; white text; slate mid-tone
const C = {
  bg:      "0D1B2A",   // deep navy  (slide backgrounds)
  bgMid:   "112233",   // slightly lighter navy
  teal:    "0B7A75",   // teal – section headers, shapes
  tealLt:  "0FA3A0",   // lighter teal – subheadings
  lime:    "C8F04D",   // neon lime accent
  white:   "FFFFFF",
  offWht:  "D6E4E4",
  slate:   "4A7896",   // muted blue-gray
  warn:    "F28B30",   // amber for alerts/warnings
  red:     "E05252",
  green:   "50C878",
};

// ─── HELPER ──────────────────────────────────────────────────────────────────
function darkSlide(slide) {
  slide.background = { color: C.bg };
}
function addTag(slide, text, x, y) {
  slide.addShape(pres.shapes.RECTANGLE, { x, y, w: 1.3, h: 0.28, fill: { color: C.lime } });
  slide.addText(text, { x, y, w: 1.3, h: 0.28, fontSize: 8, bold: true, color: C.bg, align: "center", valign: "middle", margin: 0 });
}
function addSection(slide, label) {
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 0.45, fill: { color: C.teal } });
  slide.addText(label, { x: 0.2, y: 0, w: 9.6, h: 0.45, fontSize: 11, bold: true, color: C.white, valign: "middle", margin: 0, charSpacing: 2 });
}
function addTitle(slide, title, sub) {
  slide.addText(title, { x: 0.35, y: 0.6, w: 9.3, h: 0.75, fontSize: 26, bold: true, color: C.white });
  if (sub) slide.addText(sub, { x: 0.35, y: 1.35, w: 9.3, h: 0.35, fontSize: 13, color: C.tealLt, italic: true });
}
function addFooter(slide, text) {
  slide.addText(text, { x: 0.3, y: 5.3, w: 9.4, h: 0.25, fontSize: 7.5, color: C.slate, align: "right" });
}
function bullet(text, sub) {
  const arr = [{ text, options: { bullet: true, bold: false } }];
  if (sub) arr.push({ text: "\n  " + sub, options: { fontSize: 10, color: C.offWht, breakLine: false } });
  return arr;
}

// ─── WAVEFORM DRAWING HELPER ─────────────────────────────────────────────────
// Draws a simplified capnogram shape using line objects
function drawCapnogram(slide, x, y, w, h, options = {}) {
  // options: color, label, etco2Val, phase3slope (0=flat, positive = upward slope for COPD)
  const col  = options.color  || C.lime;
  const lw   = options.lw     || 2;
  const slope = options.slope  || 0;      // extra height added across phase 3

  // Coordinate helpers (inches) from local 0,0
  const px = (fx) => x + fx * w;
  const py = (fy) => y + h - fy * h;

  // One breath: baseline → upstroke → plateau → downstroke → baseline
  // Relative x fractions: 0→0.1 baseline; 0.1→0.25 upstroke; 0.25→0.65 plateau; 0.65→0.75 downstroke; 0.75→1.0 next baseline
  const pts = [
    { x: px(0),    y: py(0) },
    { x: px(0.12), y: py(0) },
    { x: px(0.22), y: py(0.85) },
    { x: px(0.65), y: py(0.85 + slope) },
    { x: px(0.75), y: py(0) },
    { x: px(1.0),  y: py(0) },
  ];

  // Draw line segments
  for (let i = 0; i < pts.length - 1; i++) {
    slide.addShape(pres.shapes.LINE, {
      x: pts[i].x, y: pts[i].y, w: pts[i+1].x - pts[i].x, h: Math.abs(pts[i+1].y - pts[i].y),
      line: { color: col, width: lw },
      flipV: pts[i+1].y < pts[i].y,
    });
  }

  // ETCO2 label
  if (options.etco2Label) {
    slide.addText(options.etco2Label, {
      x: px(0.5), y: py(1.0) - 0.22, w: 1.5, h: 0.22,
      fontSize: 9, color: col, bold: true, align: "center",
    });
  }
  // Phase labels
  if (options.phaseLabels) {
    const labels = [
      { t: "I", fx: 0.06, fy: -0.15 },
      { t: "II", fx: 0.17, fy: 0.5 },
      { t: "III", fx: 0.45, fy: 1.0 },
    ];
    labels.forEach(l => {
      slide.addText(l.t, {
        x: px(l.fx) - 0.12, y: py(l.fy) - 0.22, w: 0.24, h: 0.22,
        fontSize: 8, color: C.offWht, align: "center",
      });
    });
  }
}

// ─── SLIDE 1: TITLE ──────────────────────────────────────────────────────────
{
  const s = pres.addSlide();
  s.background = { color: C.bg };

  // Teal accent bar left
  s.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 0.18, h: 5.625, fill: { color: C.teal } });
  // Lime accent line
  s.addShape(pres.shapes.RECTANGLE, { x: 0.18, y: 0, w: 0.06, h: 5.625, fill: { color: C.lime } });

  s.addText("CAPNOGRAPHY", {
    x: 0.5, y: 0.7, w: 9.0, h: 1.1, fontSize: 52, bold: true, color: C.white,
    charSpacing: 4,
  });
  s.addText("Principles, Waveforms & Clinical Applications", {
    x: 0.5, y: 1.85, w: 9.0, h: 0.5, fontSize: 20, color: C.tealLt, italic: false,
  });
  s.addShape(pres.shapes.RECTANGLE, { x: 0.5, y: 2.45, w: 3.5, h: 0.04, fill: { color: C.lime } });
  s.addText("For ICU & Anesthesia Clinicians", {
    x: 0.5, y: 2.6, w: 6, h: 0.35, fontSize: 13, color: C.offWht,
  });
  s.addText("Comprehensive Review  |  2026", {
    x: 0.5, y: 5.15, w: 9, h: 0.3, fontSize: 10, color: C.slate,
  });
}

// ─── SLIDE 2: TABLE OF CONTENTS ──────────────────────────────────────────────
{
  const s = pres.addSlide();
  darkSlide(s);
  addSection(s, "OVERVIEW");
  addTitle(s, "What We Will Cover");

  const sections = [
    ["01", "Fundamentals of CO₂ Physiology"],
    ["02", "Types of Capnographs & Technology"],
    ["03", "The Normal Capnogram (Phases I–IV)"],
    ["04", "Capnogram Waveform Interpretation"],
    ["05", "ETCO₂ vs PaCO₂ – The Gradient"],
    ["06", "Applications in Anesthesia"],
    ["07", "ICU Applications & Ventilator Management"],
    ["08", "Capnography in Resuscitation (CPR/ROSC)"],
    ["09", "Abnormal Waveform Patterns"],
    ["10", "Troubleshooting & Pitfalls"],
  ];
  const col1 = sections.slice(0, 5);
  const col2 = sections.slice(5);
  [[col1, 0.35], [col2, 5.15]].forEach(([items, xOff]) => {
    items.forEach((item, i) => {
      const yy = 1.9 + i * 0.65;
      s.addShape(pres.shapes.RECTANGLE, { x: xOff, y: yy, w: 0.48, h: 0.42, fill: { color: C.teal } });
      s.addText(item[0], { x: xOff, y: yy, w: 0.48, h: 0.42, fontSize: 12, bold: true, color: C.lime, align: "center", valign: "middle", margin: 0 });
      s.addText(item[1], { x: xOff + 0.58, y: yy + 0.05, w: 4.4, h: 0.32, fontSize: 12, color: C.offWht });
    });
  });
  addFooter(s, "Morgan & Mikhail's Clinical Anesthesiology, 7e | Barash Clinical Anesthesia, 9e | Miller's Anesthesia, 10e");
}

// ─── SLIDE 3: CO₂ PHYSIOLOGY ─────────────────────────────────────────────────
{
  const s = pres.addSlide();
  darkSlide(s);
  addSection(s, "SECTION 01  |  CO₂ PHYSIOLOGY");
  addTitle(s, "Why CO₂ Monitoring Matters", "CO₂ is the end-product of aerobic metabolism — its measurement reflects ventilation, perfusion, and metabolism simultaneously");

  const points = [
    ["Cellular Production", "CO₂ produced during aerobic metabolism (~200 mL/min at rest); increases with fever, malignant hyperthermia, sepsis"],
    ["Transport in Blood", "~70% as bicarbonate (HCO₃⁻), ~23% bound to Hb (carbaminohemoglobin), ~7% dissolved in plasma"],
    ["Alveolar Exchange", "Diffuses rapidly across alveolar membrane; PaCO₂ normally 35–45 mmHg"],
    ["ETCO₂ Relationship", "ETCO₂ ≈ PaCO₂ − 2 to 5 mmHg in healthy lungs; gradient widens with dead space or low cardiac output"],
    ["Clinical Equation", "ETCO₂ = f (CO₂ production, alveolar ventilation, cardiac output, V/Q matching)"],
  ];

  points.forEach((p, i) => {
    const yy = 1.85 + i * 0.66;
    s.addShape(pres.shapes.RECTANGLE, { x: 0.35, y: yy, w: 2.2, h: 0.42, fill: { color: C.teal } });
    s.addText(p[0], { x: 0.35, y: yy, w: 2.2, h: 0.42, fontSize: 10.5, bold: true, color: C.lime, align: "center", valign: "middle", margin: 0 });
    s.addText(p[1], { x: 2.7, y: yy + 0.04, w: 7.0, h: 0.38, fontSize: 11, color: C.offWht });
  });

  addFooter(s, "Morgan & Mikhail's Clinical Anesthesiology, 7e, p.226 | Barash Clinical Anesthesia 9e, Ch.26");
}

// ─── SLIDE 4: TYPES OF CAPNOGRAPHS ──────────────────────────────────────────
{
  const s = pres.addSlide();
  darkSlide(s);
  addSection(s, "SECTION 02  |  TECHNOLOGY");
  addTitle(s, "Types of Capnographs", "Understanding the hardware guides optimal use and troubleshooting");

  // Two columns
  const boxes = [
    {
      title: "SIDESTREAM (Diverting)",
      color: C.teal,
      items: [
        "Aspirates gas from circuit via fine tubing (50–250 mL/min)",
        "CO₂ measured in bedside sample cell",
        "Works for intubated & non-intubated patients",
        "Prone to moisture condensation → blocked tubing",
        "~20–50 ms delay (lag time)",
        "Can be used with nasal cannula or face mask",
      ],
    },
    {
      title: "MAINSTREAM (Non-diverting)",
      color: C.slate,
      items: [
        "Sensor sits directly in-line with the breathing circuit",
        "No gas aspiration — measures at airway",
        "Faster response, no lag",
        "Heavier sensor may increase dead space",
        "Risk of secretion contamination of sensor window",
        "Primarily for intubated/ventilated patients",
      ],
    },
  ];

  boxes.forEach((b, col) => {
    const xOff = 0.35 + col * 4.85;
    s.addShape(pres.shapes.RECTANGLE, { x: xOff, y: 1.75, w: 4.5, h: 0.42, fill: { color: b.color } });
    s.addText(b.title, { x: xOff, y: 1.75, w: 4.5, h: 0.42, fontSize: 12, bold: true, color: C.lime, align: "center", valign: "middle", margin: 0 });
    const textArr = b.items.map((item, i) => ({
      text: item, options: { bullet: true, breakLine: i < b.items.length - 1 },
    }));
    s.addText(textArr, { x: xOff, y: 2.25, w: 4.5, h: 3.0, fontSize: 10.5, color: C.offWht, valign: "top" });
  });

  // Bottom note
  s.addShape(pres.shapes.RECTANGLE, { x: 0.35, y: 5.1, w: 9.3, h: 0.3, fill: { color: C.bgMid } });
  s.addText("Both rely on Beer–Lambert law: infrared light absorption by CO₂ is proportional to CO₂ concentration", {
    x: 0.35, y: 5.1, w: 9.3, h: 0.3, fontSize: 9.5, color: C.lime, align: "center", valign: "middle", margin: 0,
  });
}

// ─── SLIDE 5: NORMAL CAPNOGRAM PHASES ────────────────────────────────────────
{
  const s = pres.addSlide();
  darkSlide(s);
  addSection(s, "SECTION 03  |  NORMAL CAPNOGRAM");
  addTitle(s, "The Four Phases of a Normal Capnogram");

  // Draw axes
  // Y-axis label
  s.addText("CO₂ (mmHg)", { x: 0.1, y: 1.7, w: 0.9, h: 2.0, fontSize: 9, color: C.slate, rotate: 270 });
  // Axis lines
  s.addShape(pres.shapes.LINE, { x: 0.85, y: 1.6, w: 0.001, h: 2.8, line: { color: C.slate, width: 1 } });
  s.addShape(pres.shapes.LINE, { x: 0.85, y: 4.4, w: 8.8,  h: 0.001, line: { color: C.slate, width: 1 } });
  s.addText("Time →", { x: 8.5, y: 4.45, w: 1.5, h: 0.25, fontSize: 9, color: C.slate });

  // Scale markers
  ["0", "20", "40"].forEach((v, i) => {
    const yPos = 4.4 - i * 1.3;
    s.addText(v, { x: 0.5, y: yPos - 0.12, w: 0.34, h: 0.25, fontSize: 8, color: C.slate, align: "right" });
    s.addShape(pres.shapes.LINE, { x: 0.82, y: yPos, w: 0.1, h: 0.001, line: { color: C.slate, width: 1 } });
  });

  // Draw two breath cycles
  const breathW = 3.8;
  [1.05, 5.05].forEach(startX => {
    // Phase I: baseline (0 CO2)
    s.addShape(pres.shapes.LINE, { x: startX, y: 4.15, w: 0.55, h: 0.001, line: { color: C.lime, width: 3 } });
    // Phase II: upstroke
    s.addShape(pres.shapes.LINE, { x: startX + 0.55, y: 4.15, w: 0.45, h: 1.9, line: { color: C.lime, width: 3 }, flipV: true });
    // Phase III: alveolar plateau
    s.addShape(pres.shapes.LINE, { x: startX + 1.0, y: 2.25, w: 1.7, h: 0.001, line: { color: C.lime, width: 3 } });
    // ETCO2 dot/mark
    s.addShape(pres.shapes.OVAL, { x: startX + 2.67, y: 2.17, w: 0.16, h: 0.16, fill: { color: C.warn } });
    // Phase IV: downstroke (inspiration)
    s.addShape(pres.shapes.LINE, { x: startX + 2.7, y: 2.25, w: 0.4, h: 1.9, line: { color: C.lime, width: 3 }, flipV: false });
    // Next baseline
    s.addShape(pres.shapes.LINE, { x: startX + 3.1, y: 4.15, w: 0.7, h: 0.001, line: { color: C.lime, width: 3 } });
  });

  // Phase annotations (first breath)
  const phaseData = [
    { label: "Phase I", desc: "Dead space gas\n(0 CO₂)", x: 1.05, y: 4.5 },
    { label: "Phase II", desc: "Transition — dead\nspace → alveolar", x: 1.55, y: 3.5 },
    { label: "Phase III", desc: "Alveolar plateau\n(CO₂ rich gas)", x: 2.1,  y: 1.7 },
    { label: "ETCO₂", desc: "End-tidal point\n(35–45 mmHg)", x: 2.8,  y: 1.4 },
    { label: "Phase IV", desc: "Inspiration\n(rapid ↓ to 0)", x: 3.5,  y: 3.4 },
  ];

  phaseData.forEach(p => {
    s.addShape(pres.shapes.ROUNDED_RECTANGLE, { x: p.x, y: p.y, w: 1.7, h: 0.7, fill: { color: C.bgMid }, line: { color: C.teal, width: 1 }, rectRadius: 0.05 });
    s.addText([{ text: p.label + "\n", options: { bold: true, color: C.tealLt, breakLine: true } }, { text: p.desc, options: { color: C.offWht } }], {
      x: p.x, y: p.y, w: 1.7, h: 0.7, fontSize: 9, align: "center", valign: "middle",
    });
  });

  addFooter(s, "Barash Clinical Anesthesia 9e, Fig.26-3 | Morgan & Mikhail's Clinical Anesthesiology 7e, p.228");
}

// ─── SLIDE 6: WAVEFORM INTERPRETATION ────────────────────────────────────────
{
  const s = pres.addSlide();
  darkSlide(s);
  addSection(s, "SECTION 04  |  WAVEFORM INTERPRETATION");
  addTitle(s, "Reading the Capnogram — Key Parameters");

  const params = [
    { name: "ETCO₂ Value", normal: "35–45 mmHg", high: "> 45 mmHg → hypoventilation, ↑ CO₂ production, rebreathing", low: "< 35 mmHg → hyperventilation, ↓ perfusion, air embolism, leak" },
    { name: "Baseline", normal: "0 mmHg", high: "Elevated baseline → rebreathing (faulty valve, exhausted CO₂ absorbent)" },
    { name: "Phase III Slope", normal: "Nearly horizontal", high: "Upsloping ('shark fin') → obstructive disease (asthma, COPD), bronchospasm" },
    { name: "Phase II Slope", normal: "Steep, rapid", low: "Gradual upstroke → uneven emptying, V/Q mismatch, partial obstruction" },
    { name: "Waveform Height", normal: "Stable breath-to-breath", high: "Sudden ↓ → disconnection, embolism, cardiac arrest" },
  ];

  const headers = ["Parameter", "Normal", "Elevated / Abnormal"];
  const colW = [2.2, 2.0, 5.4];
  const colX = [0.3, 2.6, 4.7];
  headers.forEach((h, i) => {
    s.addShape(pres.shapes.RECTANGLE, { x: colX[i], y: 1.75, w: colW[i] - 0.1, h: 0.38, fill: { color: C.teal } });
    s.addText(h, { x: colX[i], y: 1.75, w: colW[i] - 0.1, h: 0.38, fontSize: 10, bold: true, color: C.white, align: "center", valign: "middle", margin: 0 });
  });

  params.forEach((p, i) => {
    const yy = 2.22 + i * 0.58;
    const rowBg = i % 2 === 0 ? C.bgMid : C.bg;
    colX.forEach((cx, ci) => {
      s.addShape(pres.shapes.RECTANGLE, { x: cx, y: yy, w: colW[ci] - 0.1, h: 0.52, fill: { color: rowBg } });
    });
    s.addText(p.name, { x: colX[0], y: yy + 0.04, w: colW[0] - 0.1, h: 0.44, fontSize: 10, bold: true, color: C.lime, align: "center", valign: "middle" });
    s.addText(p.normal || "—", { x: colX[1], y: yy + 0.04, w: colW[1] - 0.1, h: 0.44, fontSize: 9.5, color: C.green, align: "center", valign: "middle" });
    const abnText = [p.high, p.low].filter(Boolean).join("\n");
    s.addText(abnText, { x: colX[2] + 0.05, y: yy + 0.04, w: colW[2] - 0.2, h: 0.44, fontSize: 9, color: C.offWht, valign: "middle" });
  });

  addFooter(s, "Morgan & Mikhail's Clinical Anesthesiology 7e | Barash Clinical Anesthesia 9e, Ch.26");
}

// ─── SLIDE 7: ETCO₂ vs PaCO₂ GRADIENT ───────────────────────────────────────
{
  const s = pres.addSlide();
  darkSlide(s);
  addSection(s, "SECTION 05  |  ETCO₂–PaCO₂ GRADIENT");
  addTitle(s, "The (a-ET)CO₂ Gradient — Clinical Significance", "Normal gradient: 2–5 mmHg. Widening = increased alveolar dead space");

  // Gradient explanation box
  s.addShape(pres.shapes.ROUNDED_RECTANGLE, { x: 0.35, y: 1.85, w: 4.3, h: 1.35, fill: { color: C.bgMid }, line: { color: C.lime, width: 1.5 }, rectRadius: 0.08 });
  s.addText("PaCO₂ − ETCO₂ = Alveolar Dead Space Fraction", { x: 0.45, y: 1.9, w: 4.1, h: 0.38, fontSize: 12, bold: true, color: C.lime, align: "center" });
  s.addText("AVDSf = (PaCO₂ − PETCO₂) / PaCO₂\n\nNormal: 0.04–0.10  |  Concerning: > 0.20", { x: 0.45, y: 2.3, w: 4.1, h: 0.75, fontSize: 11, color: C.offWht, align: "center" });

  const causes = [
    { title: "Gradient WIDENS (↑ dead space)", color: C.warn, items: ["Pulmonary embolism", "Air/fat/venous embolism", "Cardiac arrest / ↓ CO", "Hypotension / hypovolemia", "PEEP overdistension", "Pulmonary hypertension"] },
    { title: "Gradient NARROWS", color: C.green, items: ["Improvement in cardiac output", "Successful ROSC", "Resolution of embolism", "Fluid resuscitation"] },
  ];

  causes.forEach((c, i) => {
    const xOff = 4.95 + i * 2.6;
    s.addShape(pres.shapes.RECTANGLE, { x: xOff, y: 1.85, w: 2.4, h: 0.38, fill: { color: c.color } });
    s.addText(c.title, { x: xOff, y: 1.85, w: 2.4, h: 0.38, fontSize: 9, bold: true, color: C.bg, align: "center", valign: "middle", margin: 0 });
    const textArr = c.items.map((item, idx) => ({ text: item, options: { bullet: true, breakLine: idx < c.items.length - 1 } }));
    s.addText(textArr, { x: xOff, y: 2.28, w: 2.4, h: 2.5, fontSize: 10, color: C.offWht });
  });

  // Clinical pearl
  s.addShape(pres.shapes.RECTANGLE, { x: 0.35, y: 4.85, w: 9.3, h: 0.48, fill: { color: C.teal } });
  s.addText("⚡  PEARL: A sudden drop in ETCO₂ without a change in ventilation settings should immediately prompt evaluation for embolism, circuit disconnection, or cardiac event", {
    x: 0.45, y: 4.85, w: 9.1, h: 0.48, fontSize: 10.5, color: C.white, valign: "middle",
  });
  addFooter(s, "Morgan & Mikhail's 7e, p.227-228 | Miller's Anesthesia 10e | Sabiston Textbook of Surgery");
}

// ─── SLIDE 8: APPLICATIONS IN ANESTHESIA ────────────────────────────────────
{
  const s = pres.addSlide();
  darkSlide(s);
  addSection(s, "SECTION 06  |  ANESTHESIA APPLICATIONS");
  addTitle(s, "Capnography in the Operating Room", "Mandatory monitoring for all procedures requiring general anesthesia");

  const apps = [
    { icon: "✔", title: "ETT Placement Confirmation", detail: "Detects esophageal intubation within 3–5 breaths; 100% sensitivity for colorimetric and waveform methods. Does NOT reliably detect mainstem intubation." },
    { icon: "⚠", title: "Circuit Integrity", detail: "Sudden loss of waveform → disconnection. Inspired CO₂ > 0 → rebreathing (valve failure, exhausted absorbent)." },
    { icon: "🔥", title: "Malignant Hyperthermia", detail: "Marked rise in ETCO₂ is often the earliest sign — occurs before temperature spike. Prompts immediate dantrolene therapy." },
    { icon: "💉", title: "Ventilator Management", detail: "Titrate RR/TV to maintain ETCO₂ 35–45 mmHg. Hyperventilation causes cerebral vasoconstriction — critical in neurosurgery." },
    { icon: "🫁", title: "Air/Venous Embolism Detection", detail: "Acute, sudden fall in ETCO₂ (often ≥ 3 mmHg) is a sensitive early sign. Most reliable if preceded by stable tracing." },
    { icon: "😴", title: "MAC / Sedation Monitoring", detail: "Sidestream capnography via nasal cannula detects apnea 4 min before SpO₂ falls. Respiratory depression 17.6× more likely detected vs. standard monitoring alone." },
  ];

  apps.forEach((a, i) => {
    const col = i % 2;
    const row = Math.floor(i / 2);
    const xOff = 0.35 + col * 4.85;
    const yOff = 1.85 + row * 1.2;
    s.addShape(pres.shapes.ROUNDED_RECTANGLE, { x: xOff, y: yOff, w: 4.6, h: 1.08, fill: { color: C.bgMid }, line: { color: C.teal, width: 1 }, rectRadius: 0.06 });
    s.addText(a.icon + "  " + a.title, { x: xOff + 0.1, y: yOff + 0.04, w: 4.3, h: 0.3, fontSize: 11, bold: true, color: C.lime });
    s.addText(a.detail, { x: xOff + 0.1, y: yOff + 0.34, w: 4.35, h: 0.65, fontSize: 9.5, color: C.offWht });
  });

  addFooter(s, "Morgan & Mikhail's 7e, p.227 | Barash 9e (MAC monitoring) | Tintinalli's Emergency Medicine");
}

// ─── SLIDE 9: ICU & VENTILATOR MANAGEMENT ────────────────────────────────────
{
  const s = pres.addSlide();
  darkSlide(s);
  addSection(s, "SECTION 07  |  ICU APPLICATIONS");
  addTitle(s, "Capnography in the ICU & Mechanical Ventilation");

  const items = [
    ["Continuous Ventilation Monitoring", "Real-time trend of ETCO₂ avoids frequent ABGs. Rising ETCO₂ trend may indicate fatigue, increasing CO₂ production, or inadequate MV."],
    ["PEEP Titration (Volumetric)", "Volumetric capnography (VCap) plots CO₂ vs. exhaled volume. Optimal PEEP = minimum alveolar dead space without overdistension."],
    ["Dead Space Assessment", "AVDSf = (PaCO₂ − PETCO₂)/PaCO₂. Values > 0.20 associated with increased mortality in ARDS (multiple pediatric/adult ICU studies)."],
    ["Bronchodilator Response", "VCap phase III slope decreases after effective bronchodilator therapy — objective assessment of airway obstruction response."],
    ["Weaning from Ventilation", "Stable ETCO₂ during SBT suggests adequate ventilatory reserve. Rapid rise or waveform irregularity → readiness in question."],
    ["Non-Invasive Scenarios", "Transcutaneous CO₂ (TcCO₂) used in HFV, neonates, and non-intubated monitoring. Sidestream adapters for NIV masks available."],
  ];

  items.forEach((item, i) => {
    const yy = 1.82 + i * 0.59;
    s.addShape(pres.shapes.RECTANGLE, { x: 0.35, y: yy, w: 2.5, h: 0.45, fill: { color: i % 2 === 0 ? C.teal : C.slate } });
    s.addText(item[0], { x: 0.35, y: yy, w: 2.5, h: 0.45, fontSize: 10, bold: true, color: C.lime, align: "center", valign: "middle", margin: 0 });
    s.addText(item[1], { x: 2.95, y: yy + 0.03, w: 6.75, h: 0.44, fontSize: 10.5, color: C.offWht });
  });

  addFooter(s, "Miller's Anesthesia 10e, p.11316 | Schwartz's Principles of Surgery 11e | Sabiston Textbook of Surgery");
}

// ─── SLIDE 10: RESUSCITATION ─────────────────────────────────────────────────
{
  const s = pres.addSlide();
  darkSlide(s);
  addSection(s, "SECTION 08  |  CPR & RESUSCITATION");
  addTitle(s, "Capnography During Cardiac Arrest", "AHA guidelines recommend continuous waveform capnography for all intubated patients during CPR");

  // Key metrics
  const metrics = [
    { val: "< 10 mmHg", label: "ETCO₂ at 20 min", desc: "Strongly predicts failure of resuscitation; consider termination of efforts (in context)" },
    { val: "> 35 mmHg", label: "Sudden spike in ETCO₂", desc: "Suggests Return of Spontaneous Circulation (ROSC) — may precede other ROSC signs" },
    { val: "≥ 10–20 mmHg", label: "Target during CPR", desc: "Adequate ETCO₂ during CPR correlates with cardiac output and chest compression quality" },
    { val: "17.6×", label: "ETCO₂ = Cardiac Output proxy", desc: "ETCO₂ correlates with cardiac output during CPR — as perfusion improves, more alveoli are perfused (↓ dead space)" },
  ];

  metrics.forEach((m, i) => {
    const xOff = 0.35 + (i % 2) * 4.85;
    const yOff = 2.05 + Math.floor(i / 2) * 1.55;
    s.addShape(pres.shapes.ROUNDED_RECTANGLE, { x: xOff, y: yOff, w: 4.5, h: 1.4, fill: { color: C.bgMid }, line: { color: C.warn, width: 1.5 }, rectRadius: 0.08 });
    s.addText(m.val, { x: xOff + 0.1, y: yOff + 0.05, w: 4.2, h: 0.55, fontSize: 22, bold: true, color: C.warn, align: "center" });
    s.addText(m.label, { x: xOff + 0.1, y: yOff + 0.55, w: 4.2, h: 0.3, fontSize: 10, bold: true, color: C.tealLt, align: "center" });
    s.addText(m.desc, { x: xOff + 0.1, y: yOff + 0.85, w: 4.2, h: 0.48, fontSize: 9.5, color: C.offWht, align: "center" });
  });

  addFooter(s, "Roberts & Hedges' Clinical Procedures, p.4051 | Rosen's Emergency Medicine | AHA ACLS 2020 Guidelines");
}

// ─── SLIDE 11: ABNORMAL PATTERNS ─────────────────────────────────────────────
{
  const s = pres.addSlide();
  darkSlide(s);
  addSection(s, "SECTION 09  |  ABNORMAL PATTERNS");
  addTitle(s, "Abnormal Capnogram Patterns — Quick Reference");

  const patterns = [
    { name: "Shark Fin / Upsloping Ph III", cause: "Bronchospasm, COPD, asthma, partial obstruction", etco2: "Normal–↑", color: C.warn },
    { name: "Flat Line (No Waveform)", cause: "Esophageal intubation, circuit disconnection, apnea, cardiac arrest with no output", etco2: "≈ 0", color: C.red },
    { name: "Elevated Baseline", cause: "CO₂ rebreathing: expiratory valve failure, exhausted absorbent, low fresh gas flow", etco2: "↑ baseline", color: C.warn },
    { name: "Curare Cleft (Ph III notch)", cause: "Spontaneous breathing effort during controlled ventilation — partial reversal or light anesthesia", etco2: "Normal", color: C.tealLt },
    { name: "Sudden ↓ ETCO₂ to Zero", cause: "Circuit disconnect, extubation, cardiac arrest, kinked/blocked ETT", etco2: "→ 0", color: C.red },
    { name: "Gradual ↑ ETCO₂", cause: "Hypoventilation, increasing CO₂ production (fever, MH, sepsis), rebreathing, laparoscopy CO₂ absorption", etco2: "> 45 mmHg", color: C.warn },
    { name: "Gradual ↓ ETCO₂", cause: "Hyperventilation, hypothermia, ↓ cardiac output, pulmonary embolism, blood loss", etco2: "< 35 mmHg", color: C.tealLt },
    { name: "Oscillating Baseline", cause: "Cardiogenic oscillations (cardiac movement during expiration); heartbeat visible in waveform", etco2: "Normal", color: C.slate },
  ];

  patterns.forEach((p, i) => {
    const col = i % 2;
    const row = Math.floor(i / 2);
    const xOff = 0.3 + col * 4.9;
    const yOff = 1.82 + row * 0.86;
    s.addShape(pres.shapes.RECTANGLE, { x: xOff, y: yOff, w: 0.12, h: 0.72, fill: { color: p.color } });
    s.addShape(pres.shapes.ROUNDED_RECTANGLE, { x: xOff + 0.15, y: yOff, w: 4.55, h: 0.72, fill: { color: C.bgMid }, rectRadius: 0.04 });
    s.addText(p.name, { x: xOff + 0.25, y: yOff + 0.03, w: 4.3, h: 0.27, fontSize: 10.5, bold: true, color: p.color });
    s.addText("Cause: " + p.cause + "    ETCO₂: " + p.etco2, { x: xOff + 0.25, y: yOff + 0.32, w: 4.3, h: 0.36, fontSize: 9, color: C.offWht });
  });

  addFooter(s, "Morgan & Mikhail's 7e, Fig.6-3 | Barash 9e | Tintinalli's Emergency Medicine");
}

// ─── SLIDE 12: COPD & OBSTRUCTIVE DISEASE ────────────────────────────────────
{
  const s = pres.addSlide();
  darkSlide(s);
  addSection(s, "SECTION 09  |  SPECIFIC PATTERNS: OBSTRUCTIVE DISEASE");
  addTitle(s, "Capnogram in COPD & Bronchospasm", "Phase III slope is the hallmark of obstructive ventilation");

  // Left: description
  s.addShape(pres.shapes.ROUNDED_RECTANGLE, { x: 0.35, y: 1.85, w: 4.3, h: 3.2, fill: { color: C.bgMid }, line: { color: C.teal, width: 1 }, rectRadius: 0.08 });
  s.addText("Pathophysiology of the 'Shark Fin'", { x: 0.45, y: 1.95, w: 4.1, h: 0.35, fontSize: 12, bold: true, color: C.lime });
  const copdPoints = [
    "In obstructive disease, airway caliber is non-uniform",
    "Fast-emptying alveoli clear CO₂ early in expiration",
    "Slow-emptying alveoli continue releasing CO₂ late",
    "Result: progressive rise throughout Phase III (upslope)",
    "No true plateau is ever reached before next inspiration",
    "ETCO₂ actually underestimates PaCO₂ — gradient widens",
    "Severity of bronchospasm correlates with slope steepness",
    "Response to bronchodilator: slope flattens measurably",
  ];
  const copdArr = copdPoints.map((p, i) => ({ text: p, options: { bullet: true, breakLine: i < copdPoints.length - 1 } }));
  s.addText(copdArr, { x: 0.45, y: 2.35, w: 4.1, h: 2.6, fontSize: 10, color: C.offWht });

  // Right: drawn waveform comparison
  s.addText("Normal vs COPD Capnogram", { x: 4.9, y: 1.9, w: 4.8, h: 0.35, fontSize: 11, bold: true, color: C.tealLt, align: "center" });

  // Axes
  s.addShape(pres.shapes.LINE, { x: 5.0, y: 2.35, w: 0.001, h: 2.5, line: { color: C.slate, width: 1 } });
  s.addShape(pres.shapes.LINE, { x: 5.0, y: 4.85, w: 4.6, h: 0.001, line: { color: C.slate, width: 1 } });

  // Normal waveform (green)
  s.addShape(pres.shapes.LINE, { x: 5.05, y: 4.65, w: 0.4, h: 0.001, line: { color: C.green, width: 2 } });
  s.addShape(pres.shapes.LINE, { x: 5.45, y: 4.65, w: 0.3, h: 1.5, line: { color: C.green, width: 2 }, flipV: true });
  s.addShape(pres.shapes.LINE, { x: 5.75, y: 3.15, w: 1.0, h: 0.001, line: { color: C.green, width: 2 } });
  s.addShape(pres.shapes.LINE, { x: 6.75, y: 3.15, w: 0.3, h: 1.5, line: { color: C.green, width: 2 }, flipV: false });
  s.addShape(pres.shapes.LINE, { x: 7.05, y: 4.65, w: 0.5, h: 0.001, line: { color: C.green, width: 2 } });
  s.addText("Normal", { x: 5.9, y: 2.9, w: 1.2, h: 0.22, fontSize: 9, color: C.green, align: "center" });

  // COPD waveform (orange) — upsloping
  s.addShape(pres.shapes.LINE, { x: 5.05, y: 4.82, w: 0.4, h: 0.001, line: { color: C.warn, width: 2.5 } });
  s.addShape(pres.shapes.LINE, { x: 5.45, y: 4.82, w: 0.35, h: 1.7, line: { color: C.warn, width: 2.5 }, flipV: true });
  // Sloped plateau
  s.addShape(pres.shapes.LINE, { x: 5.80, y: 3.12, w: 1.0, h: 0.55, line: { color: C.warn, width: 2.5 }, flipV: true });
  s.addShape(pres.shapes.LINE, { x: 6.80, y: 2.57, w: 0.25, h: 2.25, line: { color: C.warn, width: 2.5 }, flipV: false });
  s.addShape(pres.shapes.LINE, { x: 7.05, y: 4.82, w: 0.5, h: 0.001, line: { color: C.warn, width: 2.5 } });
  s.addText("COPD / Bronchospasm", { x: 5.7, y: 2.3, w: 2.3, h: 0.22, fontSize: 9, color: C.warn, align: "center" });

  s.addText("Phase III upslope →\n'Shark fin' pattern", { x: 6.8, y: 2.75, w: 1.8, h: 0.45, fontSize: 8.5, color: C.warn, italic: true });

  addFooter(s, "Morgan & Mikhail's 7e, Fig.6-3B | Miller's Anesthesia 10e");
}

// ─── SLIDE 13: REBREATHING PATTERNS ──────────────────────────────────────────
{
  const s = pres.addSlide();
  darkSlide(s);
  addSection(s, "SECTION 09  |  SPECIFIC PATTERNS: REBREATHING");
  addTitle(s, "Rebreathing — Elevated Baseline on Capnogram");

  // Left: causes
  s.addShape(pres.shapes.RECTANGLE, { x: 0.35, y: 1.82, w: 4.3, h: 0.4, fill: { color: C.teal } });
  s.addText("Causes of Elevated CO₂ Baseline", { x: 0.35, y: 1.82, w: 4.3, h: 0.4, fontSize: 11, bold: true, color: C.lime, align: "center", valign: "middle", margin: 0 });

  const causes = [
    ["Exhausted CO₂ absorbent", "Soda lime / Baralyme saturated; CO₂ passes unreacted into inspiratory limb"],
    ["Expiratory valve failure", "Exhaled gas refluxes into inspiratory side; continuous CO₂ in inspiratory phase"],
    ["Inspiratory valve failure", "Partial failure — some rebreathing; not fully apparent as part of inspiration still 0 CO₂"],
    ["High rebreathing circuit", "Mapleson circuits without adequate fresh gas flow allow CO₂ accumulation"],
    ["Long breathing tubing", "Increased dead space in circuit — CO₂ remains in tubing at start of inspiration"],
  ];

  causes.forEach((c, i) => {
    const yy = 2.3 + i * 0.58;
    s.addShape(pres.shapes.RECTANGLE, { x: 0.35, y: yy, w: 0.1, h: 0.48, fill: { color: C.lime } });
    s.addText(c[0], { x: 0.55, y: yy + 0.02, w: 4.0, h: 0.22, fontSize: 10.5, bold: true, color: C.tealLt });
    s.addText(c[1], { x: 0.55, y: yy + 0.24, w: 4.0, h: 0.22, fontSize: 9.5, color: C.offWht });
  });

  // Right: waveform illustration
  s.addText("Elevated Baseline Pattern", { x: 5.0, y: 1.9, w: 4.7, h: 0.35, fontSize: 11, bold: true, color: C.tealLt, align: "center" });
  s.addShape(pres.shapes.LINE, { x: 5.1, y: 2.4, w: 0.001, h: 2.3, line: { color: C.slate, width: 1 } });
  s.addShape(pres.shapes.LINE, { x: 5.1, y: 4.7, w: 4.5, h: 0.001, line: { color: C.slate, width: 1 } });

  // Normal (green)
  s.addShape(pres.shapes.LINE, { x: 5.15, y: 4.5, w: 0.45, h: 0.001, line: { color: C.green, width: 2 } });
  s.addShape(pres.shapes.LINE, { x: 5.6,  y: 4.5, w: 0.3, h: 1.5, line: { color: C.green, width: 2 }, flipV: true });
  s.addShape(pres.shapes.LINE, { x: 5.9,  y: 3.0, w: 0.9, h: 0.001, line: { color: C.green, width: 2 } });
  s.addShape(pres.shapes.LINE, { x: 6.8,  y: 3.0, w: 0.28, h: 1.5, line: { color: C.green, width: 2 } });
  s.addShape(pres.shapes.LINE, { x: 7.08, y: 4.5, w: 0.5, h: 0.001, line: { color: C.green, width: 2 } });
  s.addText("Normal", { x: 5.95, y: 2.75, w: 1.0, h: 0.22, fontSize: 8.5, color: C.green, align: "center" });

  // Rebreathing (red) — elevated baseline
  const baseY = 4.0; // elevated from 4.5
  s.addShape(pres.shapes.LINE, { x: 5.15, y: baseY, w: 0.45, h: 0.001, line: { color: C.red, width: 2.5 } });
  s.addShape(pres.shapes.LINE, { x: 5.6,  y: baseY, w: 0.3, h: 1.0, line: { color: C.red, width: 2.5 }, flipV: true });
  s.addShape(pres.shapes.LINE, { x: 5.9,  y: 3.0, w: 0.9, h: 0.001, line: { color: C.red, width: 2.5 } });
  s.addShape(pres.shapes.LINE, { x: 6.8,  y: 3.0, w: 0.28, h: 1.0, line: { color: C.red, width: 2.5 } });
  s.addShape(pres.shapes.LINE, { x: 7.08, y: baseY, w: 0.5, h: 0.001, line: { color: C.red, width: 2.5 } });
  s.addText("Rebreathing", { x: 5.95, y: 3.7, w: 1.1, h: 0.22, fontSize: 8.5, color: C.red, align: "center" });

  // Annotation arrows
  s.addShape(pres.shapes.LINE, { x: 7.75, y: baseY, w: 0.5, h: 0.001, line: { color: C.red, width: 1.5 } });
  s.addShape(pres.shapes.LINE, { x: 7.75, y: 4.5, w: 0.5, h: 0.001, line: { color: C.green, width: 1.5 } });
  s.addShape(pres.shapes.LINE, { x: 8.0, y: baseY, w: 0.001, h: 0.5, line: { color: C.warn, width: 1.5 } });
  s.addText("Elevated\nbaseline\n(rebreathing)", { x: 8.1, y: baseY - 0.1, w: 1.4, h: 0.7, fontSize: 8.5, color: C.warn });

  addFooter(s, "Morgan & Mikhail's 7e, p.228 (Fig.6-3D,E) | Barash Clinical Anesthesia 9e");
}

// ─── SLIDE 14: LAPAROSCOPY & SPECIAL CASES ───────────────────────────────────
{
  const s = pres.addSlide();
  darkSlide(s);
  addSection(s, "SECTION 09  |  SPECIFIC SCENARIOS");
  addTitle(s, "Capnography in Special Clinical Scenarios");

  const cases = [
    {
      title: "Laparoscopic Surgery",
      color: C.teal,
      items: [
        "CO₂ insufflation → systemic absorption → ETCO₂ rises",
        "Increase MV by 15–25% to compensate",
        "Trendelenburg position impairs diaphragm excursion",
        "Sudden massive rise → subcutaneous emphysema or CO₂ embolism",
        "Monitor closely — surgeon should be notified of persistent ↑ ETCO₂",
      ],
    },
    {
      title: "Pregnancy & Obstetric Anesthesia",
      color: C.tealLt,
      items: [
        "Baseline PaCO₂ is lower (≈ 32 mmHg) due to progesterone-driven hyperventilation",
        "Target ETCO₂ 30–32 mmHg to reflect this physiological state",
        "Avoid hypocapnia — causes uterine vasoconstriction",
        "Useful in monitoring failed intubation situations",
      ],
    },
    {
      title: "Pediatric Patients",
      color: C.warn,
      items: [
        "High RR → insufficient time for alveolar plateau — ETCO₂ often underestimates PaCO₂",
        "Low tidal volumes → sidestream aspiration dilutes sample",
        "Mainstream sensors may increase dead space significantly",
        "Consider TcCO₂ monitoring in neonates / very small infants",
        "Low aspiration rate (<50 mL/min) may under-read ETCO₂",
      ],
    },
    {
      title: "Neurological / Neurosurgery",
      color: C.red,
      items: [
        "Cerebral vasoreactivity to CO₂: every 1 mmHg ↑ PaCO₂ → ~4% ↑ CBF",
        "ICP management: target ETCO₂ 35 mmHg; avoid >45 (↑ ICP)",
        "Deliberate hyperventilation (ETCO₂ 30–35) for acute ICP crises",
        "Sitting position: high risk of air embolism — monitor ETCO₂ + N₂",
      ],
    },
  ];

  cases.forEach((c, i) => {
    const xOff = 0.3 + (i % 2) * 4.9;
    const yOff = 1.82 + Math.floor(i / 2) * 1.85;
    s.addShape(pres.shapes.RECTANGLE, { x: xOff, y: yOff, w: 4.55, h: 0.38, fill: { color: c.color } });
    s.addText(c.title, { x: xOff, y: yOff, w: 4.55, h: 0.38, fontSize: 10.5, bold: true, color: C.bg, align: "center", valign: "middle", margin: 0 });
    const arr = c.items.map((item, idx) => ({ text: item, options: { bullet: true, breakLine: idx < c.items.length - 1 } }));
    s.addText(arr, { x: xOff + 0.05, y: yOff + 0.4, w: 4.45, h: 1.35, fontSize: 9.5, color: C.offWht });
  });

  addFooter(s, "Morgan & Mikhail's 7e | Barash Clinical Anesthesia 9e | Roberts & Hedges' Clinical Procedures");
}

// ─── SLIDE 15: TROUBLESHOOTING ────────────────────────────────────────────────
{
  const s = pres.addSlide();
  darkSlide(s);
  addSection(s, "SECTION 10  |  TROUBLESHOOTING");
  addTitle(s, "Troubleshooting Capnograph Problems", "Artifacts and technical failures must be distinguished from true physiological events");

  const issues = [
    { problem: "No waveform displayed", causes: ["Circuit disconnection", "Esophageal intubation", "Cardiac arrest", "Sensor or cable failure"], action: "Check circuit → confirm ETT placement → assess patient", color: C.red },
    { problem: "Sidestream: blocked sampling line", causes: ["Water condensation in tubing", "Secretions / mucus in line", "Kinked tubing"], action: "Replace sampling line; use water trap; use heated tubing", color: C.warn },
    { problem: "Readings consistently low", causes: ["Leak around ETT cuff", "Low aspiration rate diluting sample (pediatric)", "High RR with no alveolar plateau"], action: "Check cuff pressure; verify sampling rate; consider mainstream sensor", color: C.tealLt },
    { problem: "Inspired CO₂ > 0 (baseline elevated)", causes: ["Exhausted CO₂ absorbent", "Valve malfunction (inspiratory or expiratory)", "Excessive rebreathing in Mapleson circuit"], action: "Replace absorbent; test circle system valves; ↑ fresh gas flow", color: C.warn },
    { problem: "Sudden high spike then loss", causes: ["Sampling line punctured or open to air", "Patient coughed or strained during measurement"], action: "Replace sampling line; reassess", color: C.slate },
  ];

  issues.forEach((iss, i) => {
    const yy = 1.8 + i * 0.7;
    s.addShape(pres.shapes.RECTANGLE, { x: 0.3, y: yy, w: 0.1, h: 0.58, fill: { color: iss.color } });
    s.addShape(pres.shapes.ROUNDED_RECTANGLE, { x: 0.45, y: yy, w: 9.2, h: 0.58, fill: { color: C.bgMid }, rectRadius: 0.04 });
    s.addText(iss.problem, { x: 0.55, y: yy + 0.03, w: 2.3, h: 0.25, fontSize: 10.5, bold: true, color: iss.color });
    s.addText("Causes: " + iss.causes.join(" | "), { x: 0.55, y: yy + 0.28, w: 5.2, h: 0.22, fontSize: 9, color: C.offWht });
    s.addShape(pres.shapes.RECTANGLE, { x: 5.85, y: yy + 0.06, w: 3.65, h: 0.46, fill: { color: C.bg }, line: { color: iss.color, width: 0.5 } });
    s.addText("▶  " + iss.action, { x: 5.9, y: yy + 0.06, w: 3.55, h: 0.46, fontSize: 9, color: C.lime, valign: "middle" });
  });

  addFooter(s, "Morgan & Mikhail's 7e, p.228 | Barash 9e | Tintinalli's Emergency Medicine");
}

// ─── SLIDE 16: DETECTION TABLE ────────────────────────────────────────────────
{
  const s = pres.addSlide();
  darkSlide(s);
  addSection(s, "SECTION 06–07  |  CRITICAL EVENTS DETECTION");
  addTitle(s, "Critical Events Detected by Capnography", "Based on Barash Clinical Anesthesia 9e, Table 26-1");

  const events = [
    ["Esophageal intubation", "CO₂ absent after 3–5 breaths", "Immediate re-intubation", C.red],
    ["Circuit disconnection", "Sudden loss of waveform", "Check all connections", C.red],
    ["Malignant hyperthermia", "Rapid ↑ ETCO₂, early sign", "Dantrolene, cooling, trigger removal", C.red],
    ["Air / venous embolism", "Acute ↓ ETCO₂ (↑ dead space)", "Position change, aspiration, notify surgeon", C.warn],
    ["Bronchospasm", "Upsloping Phase III (shark fin)", "Bronchodilator, ↑ inspiratory time", C.warn],
    ["Pulmonary embolism", "Gradual ↓ ETCO₂, ↑ gradient", "CT angiography, anticoagulation", C.warn],
    ["Rebreathing", "Elevated inspiratory CO₂ baseline", "Replace absorbent, check valves", C.tealLt],
    ["Cardiac arrest / low CO", "Very low or absent ETCO₂", "CPR quality assessment; ETCO₂ target ≥10 mmHg", C.red],
    ["ROSC", "Sudden spike in ETCO₂ > 35 mmHg", "Pulse check; post-ROSC care", C.green],
    ["Hypoventilation", "Gradual ↑ ETCO₂ > 45 mmHg", "↑ RR or TV; check sedation level", C.warn],
  ];

  const colHeaders = ["Event", "Capnographic Finding", "Clinical Action"];
  const colW2 = [2.4, 3.2, 4.0];
  const colX2 = [0.3, 2.8, 6.1];

  colHeaders.forEach((h, ci) => {
    s.addShape(pres.shapes.RECTANGLE, { x: colX2[ci], y: 1.72, w: colW2[ci] - 0.1, h: 0.35, fill: { color: C.teal } });
    s.addText(h, { x: colX2[ci], y: 1.72, w: colW2[ci] - 0.1, h: 0.35, fontSize: 10, bold: true, color: C.white, align: "center", valign: "middle", margin: 0 });
  });

  events.forEach((e, i) => {
    const yy = 2.14 + i * 0.33;
    const rowBg = i % 2 === 0 ? C.bgMid : C.bg;
    s.addShape(pres.shapes.RECTANGLE, { x: 0.3, y: yy, w: 0.08, h: 0.3, fill: { color: e[3] } });
    colX2.forEach((cx, ci) => {
      s.addShape(pres.shapes.RECTANGLE, { x: cx, y: yy, w: colW2[ci] - 0.1, h: 0.3, fill: { color: rowBg } });
    });
    s.addText(e[0], { x: colX2[0] + 0.05, y: yy + 0.02, w: colW2[0] - 0.15, h: 0.26, fontSize: 9, bold: true, color: e[3], valign: "middle" });
    s.addText(e[1], { x: colX2[1] + 0.05, y: yy + 0.02, w: colW2[1] - 0.15, h: 0.26, fontSize: 9, color: C.offWht, valign: "middle" });
    s.addText(e[2], { x: colX2[2] + 0.05, y: yy + 0.02, w: colW2[2] - 0.15, h: 0.26, fontSize: 9, color: C.offWht, valign: "middle" });
  });

  addFooter(s, "Barash Clinical Anesthesia 9e, Table 26-1 | Morgan & Mikhail's 7e | Roberts & Hedges' Clinical Procedures");
}

// ─── SLIDE 17: GUIDELINES & STANDARDS ────────────────────────────────────────
{
  const s = pres.addSlide();
  darkSlide(s);
  addSection(s, "GUIDELINES & STANDARDS");
  addTitle(s, "Capnography: Guidelines & Mandatory Standards");

  const guidelines = [
    { org: "ASA", year: "2011+", text: "Continuous waveform capnography is mandatory for all patients receiving general anesthesia. Also recommended during moderate/deep sedation." },
    { org: "AHA ACLS", year: "2020", text: "Waveform capnography required to confirm and monitor ETT placement. ETCO₂ < 10 mmHg after 20 min CPR may guide termination decisions." },
    { org: "WHO", year: "2009", text: "Pulse oximetry AND capnography identified as essential monitoring for safe surgery globally — part of the Safe Surgery Saves Lives initiative." },
    { org: "AAGBI / RCoA", year: "2021", text: "Capnography is mandatory for any patient with a tracheal tube or supraglottic device under general anaesthesia." },
    { org: "80+ Societies", year: "2015–2024", text: "Over 80 clinical societies have recommended capnography in >100 guidelines — spanning anesthesia, emergency medicine, critical care, and procedural sedation." },
  ];

  guidelines.forEach((g, i) => {
    const yy = 1.85 + i * 0.7;
    s.addShape(pres.shapes.RECTANGLE, { x: 0.35, y: yy, w: 0.9, h: 0.56, fill: { color: C.teal } });
    s.addText(g.org, { x: 0.35, y: yy, w: 0.9, h: 0.35, fontSize: 11, bold: true, color: C.lime, align: "center", valign: "middle", margin: 0 });
    s.addText(g.year, { x: 0.35, y: yy + 0.33, w: 0.9, h: 0.22, fontSize: 9, color: C.white, align: "center", valign: "middle", margin: 0 });
    s.addText(g.text, { x: 1.35, y: yy + 0.05, w: 8.3, h: 0.5, fontSize: 10.5, color: C.offWht });
  });

  s.addShape(pres.shapes.RECTANGLE, { x: 0.35, y: 5.2, w: 9.3, h: 0.25, fill: { color: C.bgMid } });
  s.addText("Capnography is now considered standard of care — not optional — in any setting where a patient's airway is managed or sedation is administered", {
    x: 0.4, y: 5.2, w: 9.2, h: 0.25, fontSize: 9, color: C.lime, align: "center", valign: "middle",
  });
  addFooter(s, "ASA Standards 2011 | AHA ACLS Guidelines 2020 | WHO Safe Surgery Initiative | Respiratory Therapy 2024 review");
}

// ─── SLIDE 18: CLINICAL DECISION ALGORITHM ───────────────────────────────────
{
  const s = pres.addSlide();
  darkSlide(s);
  addSection(s, "CLINICAL DECISION SUPPORT");
  addTitle(s, "Systematic Approach to an Abnormal Capnogram");

  // Flow: Step-by-step
  const steps = [
    { n: "1", q: "Is there a waveform?", yes: "YES → proceed", no: "NO → check circuit, ETT, patient" },
    { n: "2", q: "Is the baseline (inspired CO₂) = 0?", yes: "YES → proceed", no: "NO → rebreathing (valve/absorbent)" },
    { n: "3", q: "Is ETCO₂ 35–45 mmHg?", yes: "YES → normal ventilation", no: "NO → characterize further" },
    { n: "4", q: "ETCO₂ HIGH (> 45)?", yes: "Hypoventilation / ↑ production → ↑ MV, check MH, sepsis", no: "LOW (< 35) → ↑ dead space (PE, embolism, ↓ CO, hyperventilation)" },
    { n: "5", q: "Phase III slope — flat or upsloping?", yes: "Flat = normal or hyperventilation", no: "Upsloping = obstructive disease → bronchodilator, ↑ exp time" },
  ];

  steps.forEach((step, i) => {
    const yy = 1.78 + i * 0.72;
    s.addShape(pres.shapes.OVAL, { x: 0.35, y: yy, w: 0.5, h: 0.5, fill: { color: C.teal } });
    s.addText(step.n, { x: 0.35, y: yy, w: 0.5, h: 0.5, fontSize: 14, bold: true, color: C.lime, align: "center", valign: "middle", margin: 0 });
    s.addShape(pres.shapes.ROUNDED_RECTANGLE, { x: 0.95, y: yy, w: 3.5, h: 0.5, fill: { color: C.bgMid }, line: { color: C.teal, width: 1 }, rectRadius: 0.05 });
    s.addText(step.q, { x: 1.0, y: yy + 0.05, w: 3.4, h: 0.4, fontSize: 10, bold: true, color: C.white, valign: "middle" });
    s.addShape(pres.shapes.ROUNDED_RECTANGLE, { x: 4.55, y: yy, w: 2.2, h: 0.5, fill: { color: C.bg }, line: { color: C.green, width: 1 }, rectRadius: 0.04 });
    s.addText("✔  " + step.yes, { x: 4.6, y: yy + 0.04, w: 2.1, h: 0.42, fontSize: 8.5, color: C.green, valign: "middle" });
    s.addShape(pres.shapes.ROUNDED_RECTANGLE, { x: 6.85, y: yy, w: 2.8, h: 0.5, fill: { color: C.bg }, line: { color: C.warn, width: 1 }, rectRadius: 0.04 });
    s.addText("✘  " + step.no, { x: 6.9, y: yy + 0.04, w: 2.7, h: 0.42, fontSize: 8.5, color: C.warn, valign: "middle" });
  });

  addTag(s, "ALGORITHM", 9.3, 0.5);
  addFooter(s, "Adapted from Respiratory Therapy (Farquharson & Spratt, 2024) | Morgan & Mikhail's 7e");
}

// ─── SLIDE 19: KEY NUMBERS ────────────────────────────────────────────────────
{
  const s = pres.addSlide();
  darkSlide(s);
  addSection(s, "QUICK REFERENCE");
  addTitle(s, "Key Numbers Every Clinician Should Know");

  const nums = [
    { val: "35–45", unit: "mmHg", label: "Normal ETCO₂ range" },
    { val: "2–5",   unit: "mmHg", label: "Normal PaCO₂–ETCO₂ gradient" },
    { val: "< 10",  unit: "mmHg", label: "ETCO₂ during CPR → predicts failure" },
    { val: "> 35",  unit: "mmHg", label: "Sudden ETCO₂ spike → suspect ROSC" },
    { val: "0",     unit: "mmHg", label: "Inspired CO₂ (normal baseline)" },
    { val: "≈ 4 min", unit: "", label: "Time advantage over SpO₂ in detecting apnea" },
    { val: "17.6×", unit: "more likely", label: "Resp depression detected with capnography vs. standard monitoring" },
    { val: "100%",  unit: "sensitivity", label: "Waveform capnography for ETT placement confirmation" },
    { val: "0.04–0.10", unit: "AVDSf", label: "Normal alveolar dead space fraction" },
    { val: "> 0.20",    unit: "AVDSf", label: "Concerning dead space fraction → investigate" },
  ];

  nums.forEach((n, i) => {
    const col = i % 2;
    const row = Math.floor(i / 2);
    const xOff = 0.35 + col * 4.9;
    const yOff = 1.82 + row * 0.73;
    s.addShape(pres.shapes.ROUNDED_RECTANGLE, { x: xOff, y: yOff, w: 4.6, h: 0.64, fill: { color: C.bgMid }, line: { color: C.teal, width: 0.8 }, rectRadius: 0.05 });
    s.addText(n.val, { x: xOff + 0.1, y: yOff + 0.06, w: 1.6, h: 0.52, fontSize: 20, bold: true, color: C.lime, align: "center", valign: "middle" });
    s.addText(n.unit, { x: xOff + 1.65, y: yOff + 0.06, w: 1.0, h: 0.25, fontSize: 8.5, color: C.tealLt });
    s.addText(n.label, { x: xOff + 1.65, y: yOff + 0.3, w: 2.85, h: 0.28, fontSize: 9.5, color: C.offWht });
  });

  addFooter(s, "Morgan & Mikhail's 7e | Barash 9e | Rosen's EM | Barash MAC monitoring | Respiratory Therapy 2024");
}

// ─── SLIDE 20: SUMMARY & CLOSING ─────────────────────────────────────────────
{
  const s = pres.addSlide();
  s.background = { color: C.bg };

  // Teal accent bar left
  s.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 0.18, h: 5.625, fill: { color: C.teal } });
  s.addShape(pres.shapes.RECTANGLE, { x: 0.18, y: 0, w: 0.06, h: 5.625, fill: { color: C.lime } });

  s.addText("KEY TAKEAWAYS", {
    x: 0.5, y: 0.35, w: 9, h: 0.5, fontSize: 24, bold: true, color: C.lime, charSpacing: 3,
  });

  const takehomes = [
    "Capnography measures CO₂ across ventilation, perfusion, and metabolism — a single waveform reflects all three",
    "Normal ETCO₂ is 35–45 mmHg; a 2–5 mmHg gradient vs PaCO₂ reflects healthy lungs",
    "Waveform capnography is mandatory in GA, ACLS, and strongly recommended for all sedated patients",
    "Sudden loss of waveform → circuit disconnection or esophageal intubation until proven otherwise",
    "Upsloping Phase III (shark fin) = obstructive airways disease; treat the cause",
    "Elevated baseline = rebreathing; check valves and CO₂ absorbent",
    "During CPR: ETCO₂ ≥ 10 mmHg targets quality compressions; sudden spike = suspect ROSC",
    "The (a-ET)CO₂ gradient is an indirect window into alveolar dead space and cardiac output",
  ];

  const arr = takehomes.map((t, i) => ({
    text: "  " + t, options: { bullet: { code: "25CF", color: C.lime }, color: i % 2 === 0 ? C.white : C.offWht, breakLine: i < takehomes.length - 1, fontSize: 11 },
  }));
  s.addText(arr, { x: 0.5, y: 0.95, w: 9.1, h: 4.3, valign: "top" });

  s.addText("Capnography 2026  |  For ICU & Anesthesia Clinicians", {
    x: 0.5, y: 5.25, w: 9.1, h: 0.25, fontSize: 9, color: C.slate, align: "right",
  });
}

// ─── WRITE FILE ───────────────────────────────────────────────────────────────
pres.writeFile({ fileName: "/home/daytona/workspace/capnography-pptx/Capnography_ICU_Anesthesia.pptx" })
  .then(() => console.log("✅  Presentation saved successfully"))
  .catch(err => { console.error("❌  Error:", err); process.exit(1); });
Running Command

cd /home/daytona/workspace/capnography-pptx && node build.js 2>&1

Running Command

ls -lh /home/daytona/workspace/capnography-pptx/Capnography_ICU_Anesthesia.pptx

Your presentation is ready:

Capnography ICU Anesthesia

Presentation · PPTX


What's inside — 20 slides, deep navy/teal/lime palette

#SlideHighlights
1TitleBold cover with accent bars
2Table of Contents10 section navigator
3CO₂ PhysiologyProduction, transport, alveolar exchange, the ETCO₂ equation
4Types of CapnographsSidestream vs mainstream — pros/cons, Beer-Lambert law
5Normal Capnogram PhasesDrawn waveform with Phase I–IV annotations, ETCO₂ point labeled
6Waveform InterpretationTable of key parameters (baseline, Phase II/III slope, height) with normal/abnormal values
7ETCO₂–PaCO₂ GradientAVDSf formula, causes of widening/narrowing, clinical pearl on sudden drops
8OR ApplicationsETT confirmation, malignant hyperthermia, air embolism, MAC/sedation monitoring
9ICU / Ventilator ManagementPEEP titration via volumetric capnography, AVDSf in ARDS, weaning, NIV
10CPR & ResuscitationAHA 2020 guidance, ETCO₂ targets, ROSC spike, CPR quality metrics
11Abnormal Patterns Quick Ref8 patterns: shark fin, flat line, elevated baseline, curare cleft, etc.
12COPD / BronchospasmPathophysiology of the shark fin; drawn normal vs COPD waveform comparison
13Rebreathing PatternsCauses of elevated baseline; drawn comparison of normal vs rebreathing
14Special ScenariosLaparoscopy, pregnancy, pediatrics, neurosurgery — ICP and CO₂ management
15Troubleshooting5 common hardware/clinical problems with action steps
16Critical Events Table10-row reference table (Barash Table 26-1 adapted) with color-coded severity
17Guidelines & StandardsASA, AHA ACLS 2020, WHO, AAGBI/RCoA, 80+ societies endorsement
18Decision Algorithm5-step systematic "abnormal capnogram" flowchart
19Key Numbers10 critical values every clinician must know at a glance
20Key Takeaways8 concise summary bullets
Content is sourced from Morgan & Mikhail's Clinical Anesthesiology 7e, Barash Clinical Anesthesia 9e, Miller's Anesthesia 10e, Rosen's Emergency Medicine, and Roberts & Hedges' Clinical Procedures.

Not downloading

Running Command

ls -lh /home/daytona/workspace/capnography-pptx/ && file /home/daytona/workspace…

Running Command

cp /home/daytona/workspace/capnography-pptx/Capnography_ICU_Anesthesia.pptx /hom…

Try this direct link:

Capnography ICU Anesthesia

Presentation · PPTX

If that still doesn't work, here are a few things to try:
  1. Right-click the link → "Save link as..." instead of clicking directly
  2. Try a different browser - Chrome and Edge tend to handle sandbox file downloads most reliably
  3. Check your browser's download folder - the file may have already downloaded silently without a prompt
The file is confirmed present at 448 KB and is a valid PPTX (ZIP) format. Let me know if you're still having trouble and I can convert it to PDF or try another approach.

Still same issue

Reading File
Running Command

cd /home/daytona/workspace/capnography-pptx && libreoffice --headless --convert-…

Running Command

mkdir -p /home/daytona/workspace/capnography-pptx/output && libreoffice --headle…

Running Command

chmod 777 /home/daytona/workspace/capnography-pptx/output && libreoffice --headl…

Running Command

cp /home/daytona/workspace/capnography-pptx/Capnography_ICU_Anesthesia.pptx /tmp…

Running Command

cp /tmp/capo.pdf /home/daytona/workspace/capnography-pptx/Capnography_ICU_Anesth…

Both formats are now available. Try either link:
PDF (251 KB):

Capnography ICU Anesthesia

PDF Document · PDF

PowerPoint (448 KB):

Capnography ICU Anesthesia

Presentation · PPTX

The PDF was converted directly from the PPTX via LibreOffice, so all 20 slides are there. If you still can't download, let me know what environment you're using (browser, OS) and I can try a different delivery method.

Tried on crome and safari

Running Command

base64 /home/daytona/workspace/capnography-pptx/Capnography_ICU_Anesthesia.pdf |…

Running Command

python3 -c " import base64, json with open('/home/daytona/workspace/capnography…

Try this HTML page — open it and click the button to trigger the download directly from the browser:

download

HTML File · HTML

If that link also doesn't open, the sandbox file serving itself may be restricted in your deployment. In that case, the most reliable workaround is:
  1. Ask your platform admin if sandbox file downloads are enabled — some Orris deployments restrict /home/daytona/workspace/ access from the browser.
  2. Alternatively, I can generate the entire presentation content as a Google Slides-compatible export or produce a detailed Word (.docx) version which may have a different delivery path.
Would you like me to try the Word format, or is there another format/method you'd prefer?

Create a Google Slides-compatible JSON export

Writing File

~/capnography-pptx/Capnography_GoogleSlides.gs

/**
 * CAPNOGRAPHY - ICU & ANESTHESIA CLINICIANS
 * Google Apps Script — paste this into script.google.com (or Tools > Script editor
 * inside any Google Slides file) and run createCapnographyPresentation().
 *
 * HOW TO USE:
 *  1. Go to https://script.google.com  → New Project
 *  2. Delete any existing code, paste this entire file
 *  3. Click Run → createCapnographyPresentation
 *  4. Grant permissions when prompted
 *  5. A new Google Slides presentation opens in your Drive
 */

// ─── PALETTE ─────────────────────────────────────────────────────────────────
var BG     = '#0D1B2A';
var TEAL   = '#0B7A75';
var TEALLT = '#0FA3A0';
var LIME   = '#C8F04D';
var WHITE  = '#FFFFFF';
var OFFWHT = '#D6E4E4';
var SLATE  = '#4A7896';
var WARN   = '#F28B30';
var RED    = '#E05252';
var GREEN  = '#50C878';
var BGMID  = '#112233';

// ─── HELPERS ─────────────────────────────────────────────────────────────────
function setSlide(slide) {
  slide.getBackground().setSolidFill(HexColor(BG));
  return slide;
}

function HexColor(hex) {
  hex = hex.replace('#','');
  return {
    red:   parseInt(hex.substring(0,2),16)/255,
    green: parseInt(hex.substring(2,4),16)/255,
    blue:  parseInt(hex.substring(4,6),16)/255
  };
}

function addRect(slide, x, y, w, h, fillHex, borderHex) {
  var shape = slide.insertShape(SlidesApp.ShapeType.RECTANGLE,
    emu(x), emu(y), emu(w), emu(h));
  shape.getFill().setSolidFill(HexColor(fillHex));
  if (borderHex) {
    shape.getBorder().getLineFill().setSolidFill(HexColor(borderHex));
    shape.getBorder().setWeight(1);
  } else {
    shape.getBorder().setTransparent();
  }
  return shape;
}

function addText(slide, text, x, y, w, h, opts) {
  opts = opts || {};
  var shape = slide.insertTextBox(text, emu(x), emu(y), emu(w), emu(h));
  shape.getBorder().setTransparent();
  shape.getFill().setTransparent();
  var tf = shape.getText();
  var style = tf.getTextStyle();
  style.setFontSize(opts.fontSize || 12);
  style.setForegroundColor(HexColor(opts.color || WHITE));
  style.setBold(opts.bold || false);
  style.setItalic(opts.italic || false);
  if (opts.fontFace) style.setFontFamily(opts.fontFace);
  var para = tf.getParagraphs()[0].getRange().getParagraphStyle();
  para.setParagraphAlignment(
    opts.align === 'center' ? SlidesApp.ParagraphAlignment.CENTER :
    opts.align === 'right'  ? SlidesApp.ParagraphAlignment.END :
    SlidesApp.ParagraphAlignment.START
  );
  return shape;
}

// Convert inches to EMUs (English Metric Units) — Google Slides API uses EMUs
function emu(inches) { return inches * 914400; }

// Section header bar
function sectionBar(slide, label) {
  addRect(slide, 0, 0, 10, 0.42, TEAL);
  addText(slide, label, 0.15, 0.02, 9.7, 0.38,
    {fontSize:10, bold:true, color:WHITE});
}

// Slide title + subtitle
function slideTitle(slide, title, sub) {
  addText(slide, title, 0.3, 0.55, 9.4, 0.75,
    {fontSize:24, bold:true, color:WHITE});
  if (sub) addText(slide, sub, 0.3, 1.32, 9.4, 0.38,
    {fontSize:12, color:TEALLT, italic:true});
}

// Footer
function footer(slide, text) {
  addText(slide, text, 0.3, 5.28, 9.4, 0.22,
    {fontSize:7, color:SLATE, align:'right'});
}

// Colored label box + body text row
function labelRow(slide, label, body, x, y, w, labelW, labelColor, rowBg) {
  if (rowBg) addRect(slide, x, y, w, 0.5, rowBg);
  addRect(slide, x, y, labelW, 0.5, labelColor || TEAL);
  addText(slide, label, x, y, labelW, 0.5,
    {fontSize:10, bold:true, color:LIME, align:'center'});
  addText(slide, body, x + labelW + 0.1, y + 0.05, w - labelW - 0.15, 0.42,
    {fontSize:10.5, color:OFFWHT});
}

// ─── MAIN FUNCTION ────────────────────────────────────────────────────────────
function createCapnographyPresentation() {
  var pres = SlidesApp.create('Capnography — ICU & Anesthesia Clinicians');
  // Remove default blank slide
  var slides = pres.getSlides();

  // ── SLIDE 1: TITLE ──────────────────────────────────────────────────────────
  var s = slides[0];
  s.getBackground().setSolidFill(HexColor(BG));
  addRect(s, 0, 0, 0.18, 5.625, TEAL);
  addRect(s, 0.18, 0, 0.06, 5.625, LIME);
  addText(s, 'CAPNOGRAPHY', 0.5, 0.6, 9.0, 1.1,
    {fontSize:48, bold:true, color:WHITE});
  addText(s, 'Principles, Waveforms & Clinical Applications',
    0.5, 1.8, 9.0, 0.5, {fontSize:20, color:TEALLT});
  addRect(s, 0.5, 2.42, 3.5, 0.05, LIME);
  addText(s, 'For ICU & Anesthesia Clinicians | 2026',
    0.5, 2.6, 7.0, 0.38, {fontSize:14, color:OFFWHT});
  addText(s, 'Sources: Morgan & Mikhail 7e · Barash Clinical Anesthesia 9e · Miller\'s Anesthesia 10e',
    0.5, 5.15, 9.0, 0.28, {fontSize:8.5, color:SLATE});

  // ── SLIDE 2: TABLE OF CONTENTS ───────────────────────────────────────────
  s = pres.appendSlide();
  s.getBackground().setSolidFill(HexColor(BG));
  sectionBar(s, 'OVERVIEW');
  slideTitle(s, 'What We Will Cover');
  var toc = [
    ['01','CO₂ Physiology'],['02','Types of Capnographs'],
    ['03','Normal Capnogram Phases'],['04','Waveform Interpretation'],
    ['05','ETCO₂ vs PaCO₂ Gradient'],['06','Applications in Anesthesia'],
    ['07','ICU & Ventilator Management'],['08','Capnography in Resuscitation'],
    ['09','Abnormal Waveform Patterns'],['10','Troubleshooting & Pitfalls'],
  ];
  toc.forEach(function(item, i) {
    var col = i < 5 ? 0 : 1;
    var row = i < 5 ? i : i - 5;
    var xo = 0.35 + col * 4.85;
    var yo = 1.85 + row * 0.64;
    addRect(s, xo, yo, 0.46, 0.42, TEAL);
    addText(s, item[0], xo, yo, 0.46, 0.42,
      {fontSize:12, bold:true, color:LIME, align:'center'});
    addText(s, item[1], xo + 0.56, yo + 0.06, 4.1, 0.32,
      {fontSize:12, color:OFFWHT});
  });
  footer(s, 'Morgan & Mikhail 7e | Barash 9e | Miller\'s 10e');

  // ── SLIDE 3: CO₂ PHYSIOLOGY ─────────────────────────────────────────────
  s = pres.appendSlide();
  s.getBackground().setSolidFill(HexColor(BG));
  sectionBar(s, 'SECTION 01  |  CO₂ PHYSIOLOGY');
  slideTitle(s, 'Why CO₂ Monitoring Matters',
    'CO₂ is the end-product of aerobic metabolism — reflects ventilation, perfusion & metabolism simultaneously');
  var phys = [
    ['Cellular Production','CO₂ produced during aerobic metabolism (~200 mL/min at rest); increases with fever, MH, sepsis'],
    ['Blood Transport','~70% as HCO₃⁻ (bicarbonate), ~23% bound to Hb (carbaminoHb), ~7% dissolved in plasma'],
    ['Alveolar Exchange','Diffuses rapidly across alveolar membrane; normal PaCO₂ = 35–45 mmHg'],
    ['ETCO₂ Relationship','ETCO₂ ≈ PaCO₂ − 2 to 5 mmHg in healthy lungs; gradient widens with dead space or low cardiac output'],
    ['Clinical Equation','ETCO₂ = f(CO₂ production, alveolar ventilation, cardiac output, V/Q matching)'],
  ];
  phys.forEach(function(p, i) {
    labelRow(s, p[0], p[1], 0.35, 1.82 + i*0.64, 9.3, 2.2, TEAL, i%2===0?BGMID:BG);
  });
  footer(s, 'Morgan & Mikhail\'s Clinical Anesthesiology 7e, p.226 | Barash Clinical Anesthesia 9e, Ch.26');

  // ── SLIDE 4: TYPES OF CAPNOGRAPHS ───────────────────────────────────────
  s = pres.appendSlide();
  s.getBackground().setSolidFill(HexColor(BG));
  sectionBar(s, 'SECTION 02  |  TECHNOLOGY');
  slideTitle(s, 'Types of Capnographs',
    'Understanding the hardware guides optimal use and troubleshooting');
  var types = [
    {title:'SIDESTREAM (Diverting)', color:TEAL, items:[
      '• Aspirates gas from circuit via fine tubing (50–250 mL/min)',
      '• CO₂ measured in bedside sample cell',
      '• Works for intubated AND non-intubated patients',
      '• Prone to moisture condensation → blocked tubing',
      '• ~20–50 ms lag time',
      '• Usable with nasal cannula or face mask',
    ]},
    {title:'MAINSTREAM (Non-diverting)', color:SLATE, items:[
      '• Sensor sits in-line with breathing circuit',
      '• No gas aspiration — measures at the airway',
      '• Faster response, virtually no lag',
      '• Heavier sensor may increase dead space',
      '• Risk of secretion contamination of sensor window',
      '• Primarily for intubated / ventilated patients',
    ]},
  ];
  types.forEach(function(t, col) {
    var xo = 0.35 + col * 4.85;
    addRect(s, xo, 1.75, 4.5, 0.42, t.color);
    addText(s, t.title, xo, 1.75, 4.5, 0.42,
      {fontSize:12, bold:true, color:LIME, align:'center'});
    addText(s, t.items.join('\n'), xo + 0.05, 2.25, 4.4, 3.0,
      {fontSize:10.5, color:OFFWHT});
  });
  addRect(s, 0.35, 5.08, 9.3, 0.32, BGMID);
  addText(s, 'Both rely on Beer–Lambert law: infrared light absorption by CO₂ ∝ CO₂ concentration',
    0.35, 5.08, 9.3, 0.32, {fontSize:9.5, color:LIME, align:'center'});
  footer(s, 'Morgan & Mikhail\'s 7e, p.226');

  // ── SLIDE 5: NORMAL CAPNOGRAM PHASES ────────────────────────────────────
  s = pres.appendSlide();
  s.getBackground().setSolidFill(HexColor(BG));
  sectionBar(s, 'SECTION 03  |  NORMAL CAPNOGRAM');
  slideTitle(s, 'The Four Phases of a Normal Capnogram');
  var phases = [
    {name:'Phase I',   desc:'Dead space gas — no CO₂ (baseline = 0 mmHg)'},
    {name:'Phase II',  desc:'Transition zone — dead space mixes with alveolar gas; rapid upstroke'},
    {name:'Phase III', desc:'Alveolar plateau — CO₂-rich alveolar gas; nearly horizontal in healthy lungs'},
    {name:'ETCO₂',     desc:'End-tidal point = highest CO₂ value per breath (normal 35–45 mmHg)'},
    {name:'Phase IV',  desc:'Inspiration — rapid fall to 0 as fresh gas enters'},
  ];
  phases.forEach(function(p, i) {
    addRect(s, 0.35, 1.82 + i*0.65, 2.1, 0.55, TEAL);
    addText(s, p.name, 0.35, 1.82 + i*0.65, 2.1, 0.55,
      {fontSize:12, bold:true, color:LIME, align:'center'});
    addText(s, p.desc, 2.55, 1.87 + i*0.65, 7.1, 0.45,
      {fontSize:11, color:OFFWHT});
  });
  // Capnogram ASCII art as a text element
  var wave = [
    '         ETCO₂ (35-45 mmHg)',
    '          ___________↑',
    '         /            \\',
    '        /              \\',
    '  ______/                \\______',
    '  Ph I    Ph II  Ph III   Ph IV',
  ].join('\n');
  addRect(s, 5.5, 1.82, 4.1, 2.3, BGMID, TEALLT);
  addText(s, wave, 5.6, 1.9, 3.9, 2.1,
    {fontSize:11, color:LIME, fontFace:'Courier New'});
  addText(s, '↑ Y-axis: CO₂ concentration    → X-axis: Time',
    5.5, 4.15, 4.1, 0.3, {fontSize:9, color:SLATE, align:'center'});
  footer(s, 'Barash Clinical Anesthesia 9e, Fig.26-3 | Morgan & Mikhail\'s 7e, p.228');

  // ── SLIDE 6: WAVEFORM INTERPRETATION ────────────────────────────────────
  s = pres.appendSlide();
  s.getBackground().setSolidFill(HexColor(BG));
  sectionBar(s, 'SECTION 04  |  WAVEFORM INTERPRETATION');
  slideTitle(s, 'Reading the Capnogram — Key Parameters');
  var params = [
    ['ETCO₂ Value','35–45 mmHg','HIGH >45: hypoventilation, ↑CO₂ production, rebreathing\nLOW <35: hyperventilation, ↓perfusion, air embolism, leak'],
    ['Baseline','0 mmHg','Elevated baseline → rebreathing (faulty valve, exhausted CO₂ absorbent)'],
    ['Phase III Slope','Nearly horizontal','Upsloping ("shark fin") → obstructive disease (asthma, COPD, bronchospasm)'],
    ['Phase II Slope','Steep & rapid','Gradual upstroke → uneven emptying, V/Q mismatch, partial obstruction'],
    ['Waveform Height','Stable breath-to-breath','Sudden ↓ → disconnection, embolism, cardiac arrest'],
  ];
  var colHdrs = ['Parameter','Normal','Elevated / Abnormal'];
  var cw = [2.1, 1.9, 5.5]; var cx = [0.3, 2.5, 4.5];
  colHdrs.forEach(function(h, ci) {
    addRect(s, cx[ci], 1.72, cw[ci]-0.1, 0.38, TEAL);
    addText(s, h, cx[ci], 1.72, cw[ci]-0.1, 0.38,
      {fontSize:10, bold:true, color:WHITE, align:'center'});
  });
  params.forEach(function(p, i) {
    var yy = 2.18 + i*0.6;
    var bg = i%2===0 ? BGMID : BG;
    cx.forEach(function(x, ci) {
      addRect(s, x, yy, cw[ci]-0.1, 0.54, bg);
    });
    addText(s, p[0], cx[0]+0.05, yy+0.05, cw[0]-0.2, 0.44,
      {fontSize:10, bold:true, color:LIME});
    addText(s, p[1], cx[1]+0.05, yy+0.05, cw[1]-0.2, 0.44,
      {fontSize:9.5, color:GREEN});
    addText(s, p[2], cx[2]+0.05, yy+0.05, cw[2]-0.2, 0.44,
      {fontSize:9, color:OFFWHT});
  });
  footer(s, 'Morgan & Mikhail\'s 7e | Barash Clinical Anesthesia 9e, Ch.26');

  // ── SLIDE 7: ETCO₂ – PaCO₂ GRADIENT ────────────────────────────────────
  s = pres.appendSlide();
  s.getBackground().setSolidFill(HexColor(BG));
  sectionBar(s, 'SECTION 05  |  ETCO₂–PaCO₂ GRADIENT');
  slideTitle(s, 'The (a-ET)CO₂ Gradient — Clinical Significance',
    'Normal gradient: 2–5 mmHg. Widening = increased alveolar dead space');
  addRect(s, 0.35, 1.82, 4.3, 1.4, BGMID, LIME);
  addText(s, 'PaCO₂ − ETCO₂ = Alveolar Dead Space', 0.45, 1.88, 4.1, 0.4,
    {fontSize:13, bold:true, color:LIME, align:'center'});
  addText(s, 'AVDSf = (PaCO₂ − PETCO₂) / PaCO₂\n\nNormal: 0.04–0.10  |  Concerning: > 0.20',
    0.45, 2.32, 4.1, 0.78, {fontSize:11, color:OFFWHT, align:'center'});
  var gradCauses = [
    {title:'Gradient WIDENS (↑ dead space)', color:WARN,
     items:'• Pulmonary embolism\n• Air/fat/venous embolism\n• Cardiac arrest / ↓CO\n• Hypotension / hypovolemia\n• PEEP overdistension\n• Pulmonary hypertension'},
    {title:'Gradient NARROWS', color:GREEN,
     items:'• Improvement in cardiac output\n• Successful ROSC\n• Resolution of embolism\n• Fluid resuscitation'},
  ];
  gradCauses.forEach(function(c, i) {
    var xo = 4.95 + i*2.7;
    addRect(s, xo, 1.82, 2.55, 0.4, c.color);
    addText(s, c.title, xo, 1.82, 2.55, 0.4,
      {fontSize:9.5, bold:true, color:BG, align:'center'});
    addText(s, c.items, xo+0.05, 2.28, 2.45, 2.5,
      {fontSize:10, color:OFFWHT});
  });
  addRect(s, 0.35, 4.85, 9.3, 0.48, TEAL);
  addText(s, '⚡ PEARL: A sudden drop in ETCO₂ without ventilation change → evaluate immediately for embolism, disconnection, or cardiac event',
    0.45, 4.85, 9.1, 0.48, {fontSize:10.5, color:WHITE});
  footer(s, 'Morgan & Mikhail\'s 7e, p.227-228 | Miller\'s Anesthesia 10e | Sabiston Textbook of Surgery');

  // ── SLIDE 8: ANESTHESIA APPLICATIONS ────────────────────────────────────
  s = pres.appendSlide();
  s.getBackground().setSolidFill(HexColor(BG));
  sectionBar(s, 'SECTION 06  |  ANESTHESIA APPLICATIONS');
  slideTitle(s, 'Capnography in the Operating Room',
    'Mandatory monitoring for all general anesthesia procedures');
  var apps = [
    ['✔ ETT Placement Confirmation','Detects esophageal intubation within 3–5 breaths; 100% sensitivity. Does NOT reliably detect mainstem intubation.'],
    ['⚠ Circuit Integrity','Sudden loss of waveform → disconnection. Inspired CO₂ > 0 → rebreathing (valve failure, exhausted absorbent).'],
    ['🔥 Malignant Hyperthermia','Marked rise in ETCO₂ is often the earliest sign — occurs before temperature spike. Prompt dantrolene therapy.'],
    ['💉 Ventilator Management','Titrate RR/TV to maintain ETCO₂ 35–45 mmHg. Hyperventilation causes cerebral vasoconstriction — critical in neurosurgery.'],
    ['🫁 Air/Venous Embolism','Acute sudden fall in ETCO₂ (≥3 mmHg) is a sensitive early sign. Most reliable if preceded by stable tracing.'],
    ['😴 MAC / Sedation Monitoring','Sidestream via nasal cannula detects apnea 4 min before SpO₂ falls. Respiratory depression 17.6× more likely detected vs standard monitoring.'],
  ];
  apps.forEach(function(a, i) {
    var col = i%2; var row = Math.floor(i/2);
    var xo = 0.35 + col*4.85; var yo = 1.82 + row*1.22;
    addRect(s, xo, yo, 4.6, 1.1, BGMID, TEAL);
    addText(s, a[0], xo+0.1, yo+0.04, 4.35, 0.32,
      {fontSize:11, bold:true, color:LIME});
    addText(s, a[1], xo+0.1, yo+0.38, 4.35, 0.65,
      {fontSize:9.5, color:OFFWHT});
  });
  footer(s, 'Morgan & Mikhail\'s 7e, p.227 | Barash 9e (MAC) | Tintinalli\'s Emergency Medicine');

  // ── SLIDE 9: ICU APPLICATIONS ────────────────────────────────────────────
  s = pres.appendSlide();
  s.getBackground().setSolidFill(HexColor(BG));
  sectionBar(s, 'SECTION 07  |  ICU APPLICATIONS');
  slideTitle(s, 'Capnography in the ICU & Mechanical Ventilation');
  var icu = [
    ['Continuous Monitoring','Real-time ETCO₂ trend avoids frequent ABGs. Rising trend may indicate fatigue, ↑CO₂ production, or inadequate MV.'],
    ['PEEP Titration (VCap)','Volumetric capnography plots CO₂ vs exhaled volume. Optimal PEEP = minimum alveolar dead space without overdistension.'],
    ['Dead Space Assessment','AVDSf = (PaCO₂ − PETCO₂)/PaCO₂. Values >0.20 associated with increased ICU mortality in ARDS.'],
    ['Bronchodilator Response','VCap Phase III slope decreases after effective bronchodilator — objective measure of airway obstruction response.'],
    ['Weaning Assessment','Stable ETCO₂ during SBT suggests adequate ventilatory reserve. Rapid rise or waveform irregularity → reassess readiness.'],
    ['Non-invasive Scenarios','TcCO₂ used in HFV and neonates. Sidestream adapters available for NIV masks and standard nasal cannulae.'],
  ];
  icu.forEach(function(item, i) {
    labelRow(s, item[0], item[1], 0.35, 1.82+i*0.59, 9.3, 2.5,
      i%2===0 ? TEAL : SLATE, i%2===0 ? BGMID : BG);
  });
  footer(s, 'Miller\'s Anesthesia 10e, p.11316 | Schwartz\'s Principles of Surgery 11e | Sabiston Textbook of Surgery');

  // ── SLIDE 10: CPR & RESUSCITATION ────────────────────────────────────────
  s = pres.appendSlide();
  s.getBackground().setSolidFill(HexColor(BG));
  sectionBar(s, 'SECTION 08  |  CPR & RESUSCITATION');
  slideTitle(s, 'Capnography During Cardiac Arrest',
    'AHA 2020: continuous waveform capnography required for all intubated patients during CPR');
  var cpr = [
    ['< 10 mmHg','ETCO₂ at 20 min CPR','Strongly predicts resuscitation failure; consider termination in context'],
    ['> 35 mmHg','Sudden spike in ETCO₂','Suggests ROSC — may precede pulse detection and other clinical signs'],
    ['≥ 10–20 mmHg','Target during CPR','Adequate ETCO₂ correlates with cardiac output and compression quality'],
    ['ETCO₂ = CO proxy','During CPR','As perfusion ↑, more alveoli are perfused → ↓ dead space → ↑ ETCO₂'],
  ];
  cpr.forEach(function(m, i) {
    var xo = 0.35 + (i%2)*4.85; var yo = 2.05 + Math.floor(i/2)*1.6;
    addRect(s, xo, yo, 4.6, 1.45, BGMID, WARN);
    addText(s, m[0], xo+0.1, yo+0.04, 4.4, 0.58,
      {fontSize:22, bold:true, color:WARN, align:'center'});
    addText(s, m[1], xo+0.1, yo+0.62, 4.4, 0.3,
      {fontSize:10, bold:true, color:TEALLT, align:'center'});
    addText(s, m[2], xo+0.1, yo+0.94, 4.4, 0.44,
      {fontSize:9.5, color:OFFWHT, align:'center'});
  });
  footer(s, 'Roberts & Hedges\' Clinical Procedures, p.4051 | Rosen\'s Emergency Medicine | AHA ACLS 2020');

  // ── SLIDE 11: ABNORMAL PATTERNS ──────────────────────────────────────────
  s = pres.appendSlide();
  s.getBackground().setSolidFill(HexColor(BG));
  sectionBar(s, 'SECTION 09  |  ABNORMAL PATTERNS');
  slideTitle(s, 'Abnormal Capnogram Patterns — Quick Reference');
  var pats = [
    [RED,   '"Shark Fin" / Upsloping Ph III','Bronchospasm, COPD, asthma, partial obstruction','Normal–↑'],
    [RED,   'Flat Line (No Waveform)','Esophageal intubation, circuit disconnection, apnea, cardiac arrest','≈ 0'],
    [WARN,  'Elevated Baseline','CO₂ rebreathing: expiratory valve failure, exhausted absorbent','↑ baseline'],
    [TEALLT,'Curare Cleft (Ph III notch)','Spontaneous breathing during controlled ventilation — light anesthesia','Normal'],
    [RED,   'Sudden ↓ ETCO₂ to Zero','Circuit disconnect, extubation, cardiac arrest, blocked/kinked ETT','→ 0'],
    [WARN,  'Gradual ↑ ETCO₂','Hypoventilation, ↑CO₂ production (fever, MH, sepsis), laparoscopy','> 45 mmHg'],
    [TEALLT,'Gradual ↓ ETCO₂','Hyperventilation, hypothermia, ↓CO, pulmonary embolism, blood loss','< 35 mmHg'],
    [SLATE, 'Oscillating Baseline','Cardiogenic oscillations — heartbeat artifact visible in waveform','Normal'],
  ];
  pats.forEach(function(p, i) {
    var col = i%2; var row = Math.floor(i/2);
    var xo = 0.3 + col*4.9; var yo = 1.82 + row*0.88;
    addRect(s, xo,      yo, 0.12, 0.74, p[0]);
    addRect(s, xo+0.15, yo, 4.55, 0.74, BGMID);
    addText(s, p[1], xo+0.25, yo+0.03, 4.3, 0.3,
      {fontSize:10.5, bold:true, color:p[0]});
    addText(s, 'Cause: '+p[2]+'   |   ETCO₂: '+p[3], xo+0.25, yo+0.36, 4.3, 0.34,
      {fontSize:9, color:OFFWHT});
  });
  footer(s, 'Morgan & Mikhail\'s 7e, Fig.6-3 | Barash 9e | Tintinalli\'s Emergency Medicine');

  // ── SLIDE 12: COPD / BRONCHOSPASM ────────────────────────────────────────
  s = pres.appendSlide();
  s.getBackground().setSolidFill(HexColor(BG));
  sectionBar(s, 'SECTION 09  |  OBSTRUCTIVE DISEASE');
  slideTitle(s, 'The "Shark Fin" — COPD & Bronchospasm',
    'Phase III upslope is the hallmark of obstructive ventilation');
  addRect(s, 0.35, 1.82, 4.3, 3.2, BGMID, TEAL);
  addText(s, 'Pathophysiology', 0.45, 1.9, 4.1, 0.32,
    {fontSize:12, bold:true, color:LIME});
  var copdTxt = [
    '• Non-uniform airway caliber in obstructive disease',
    '• Fast-emptying alveoli clear CO₂ early in expiration',
    '• Slow-emptying alveoli release CO₂ late',
    '• Result: progressive rise throughout Phase III',
    '• No true plateau reached before next inspiration',
    '• ETCO₂ UNDERESTIMATES PaCO₂ — gradient widens',
    '• Slope steepness correlates with severity',
    '• Response to bronchodilator: slope flattens measurably',
  ].join('\n');
  addText(s, copdTxt, 0.45, 2.28, 4.1, 2.6, {fontSize:10, color:OFFWHT});
  // Waveform comparison
  addRect(s, 4.8, 1.82, 4.8, 3.2, BGMID, SLATE);
  addText(s, 'Normal vs COPD Capnogram', 4.9, 1.88, 4.6, 0.32,
    {fontSize:11, bold:true, color:TEALLT, align:'center'});
  var normalWave = '         __________\n        /          \\\n_______/            \\______\n\n← Normal (flat plateau)';
  var copdWave  = '             _____/\n           /\n__________/\n\n← COPD (upsloping Phase III)';
  addRect(s, 4.9, 2.25, 2.1, 1.3, BG, GREEN);
  addText(s, normalWave, 4.95, 2.3, 2.0, 1.2,
    {fontSize:9, color:GREEN, fontFace:'Courier New'});
  addRect(s, 7.15, 2.25, 2.1, 1.3, BG, WARN);
  addText(s, copdWave, 7.2, 2.3, 2.0, 1.2,
    {fontSize:9, color:WARN, fontFace:'Courier New'});
  addText(s, 'Clinical response: administer bronchodilator → upslope should flatten\nIncrease expiratory time (↓ I:E ratio) to allow full exhalation',
    4.9, 3.65, 4.6, 0.9, {fontSize:10, color:OFFWHT});
  footer(s, 'Morgan & Mikhail\'s 7e, Fig.6-3B | Miller\'s Anesthesia 10e');

  // ── SLIDE 13: REBREATHING ────────────────────────────────────────────────
  s = pres.appendSlide();
  s.getBackground().setSolidFill(HexColor(BG));
  sectionBar(s, 'SECTION 09  |  REBREATHING PATTERNS');
  slideTitle(s, 'Rebreathing — Elevated Baseline on Capnogram');
  var rbCauses = [
    ['Exhausted CO₂ Absorbent','Soda lime / Baralyme saturated; CO₂ passes unreacted into inspiratory limb → hypercapnia'],
    ['Expiratory Valve Failure','Exhaled gas refluxes into inspiratory side; CO₂ present throughout inspiratory phase'],
    ['Inspiratory Valve Failure','Partial failure — some rebreathing; not fully apparent as part of inspiration still reads 0'],
    ['Mapleson Circuits','Inadequate fresh gas flow in Mapleson circuits allows CO₂ accumulation in rebreathing limb'],
    ['Excessive Tubing Dead Space','Long breathing tubing → CO₂ remains in tubing at start of next inspiration'],
  ];
  rbCauses.forEach(function(c, i) {
    var yy = 1.82 + i*0.6;
    addRect(s, 0.35, yy, 0.1, 0.5, LIME);
    addText(s, c[0], 0.55, yy+0.02, 3.5, 0.24, {fontSize:10.5, bold:true, color:TEALLT});
    addText(s, c[1], 0.55, yy+0.26, 7.5, 0.24, {fontSize:9.5, color:OFFWHT});
  });
  addRect(s, 0.35, 5.0, 9.3, 0.38, BGMID, RED);
  addText(s, '🔧 Fix: replace CO₂ absorbent → test circle system valves → increase fresh gas flow → check for Mapleson circuit misuse',
    0.45, 5.0, 9.1, 0.38, {fontSize:10, color:WHITE});
  footer(s, 'Morgan & Mikhail\'s 7e, p.228 (Fig.6-3D,E) | Barash Clinical Anesthesia 9e');

  // ── SLIDE 14: SPECIAL SCENARIOS ──────────────────────────────────────────
  s = pres.appendSlide();
  s.getBackground().setSolidFill(HexColor(BG));
  sectionBar(s, 'SECTION 09  |  SPECIAL SCENARIOS');
  slideTitle(s, 'Capnography in Special Clinical Scenarios');
  var specials = [
    {title:'Laparoscopic Surgery', color:TEAL,
     text:'CO₂ insufflation → systemic absorption → ETCO₂ rises\n↑ MV by 15–25% to compensate\nTrendelenburg impairs diaphragm\nSudden massive ↑ → subcutaneous emphysema or CO₂ embolism'},
    {title:'Pregnancy / Obstetrics', color:TEALLT,
     text:'Baseline PaCO₂ lower (≈32 mmHg) — progesterone-driven hyperventilation\nTarget ETCO₂ 30–32 mmHg\nAvoid hypocapnia → uterine vasoconstriction\nUseful in failed intubation scenarios'},
    {title:'Pediatric Patients', color:WARN,
     text:'High RR → no alveolar plateau — ETCO₂ underestimates PaCO₂\nLow TV → sidestream aspiration dilutes sample\nMainstream sensor may increase dead space significantly\nConsider TcCO₂ monitoring in neonates'},
    {title:'Neurosurgery / ↑ICP', color:RED,
     text:'Each 1 mmHg ↑ PaCO₂ → ~4% ↑ CBF\nTarget ETCO₂ 35 mmHg; avoid >45 (↑ICP)\nDeliberate hyperventilation (ETCO₂ 30–35) for acute ICP crisis\nSitting position: high air embolism risk — monitor ETCO₂ + N₂'},
  ];
  specials.forEach(function(sp, i) {
    var xo = 0.3 + (i%2)*4.9; var yo = 1.82 + Math.floor(i/2)*1.88;
    addRect(s, xo, yo, 4.55, 0.4, sp.color);
    addText(s, sp.title, xo, yo, 4.55, 0.4,
      {fontSize:11, bold:true, color:BG, align:'center'});
    addText(s, sp.text, xo+0.05, yo+0.44, 4.45, 1.35, {fontSize:10, color:OFFWHT});
  });
  footer(s, 'Morgan & Mikhail\'s 7e | Barash Clinical Anesthesia 9e | Roberts & Hedges\'');

  // ── SLIDE 15: TROUBLESHOOTING ─────────────────────────────────────────────
  s = pres.appendSlide();
  s.getBackground().setSolidFill(HexColor(BG));
  sectionBar(s, 'SECTION 10  |  TROUBLESHOOTING');
  slideTitle(s, 'Troubleshooting Capnograph Problems',
    'Artifacts and technical failures must be distinguished from true physiological events');
  var trbl = [
    [RED,   'No waveform displayed',       'Circuit disconnection | Esophageal intubation | Cardiac arrest | Sensor failure',   'Check circuit → confirm ETT → assess patient'],
    [WARN,  'Blocked sidestream line',      'Water condensation | Mucus / secretions | Kinked tubing',                           'Replace sampling line; use water trap; use heated tubing'],
    [TEALLT,'Readings consistently low',   'ETT cuff leak | Low aspiration rate (pediatric) | High RR / no plateau',            'Check cuff pressure; verify sampling rate; consider mainstream'],
    [WARN,  'Inspired CO₂ > 0',            'Exhausted CO₂ absorbent | Valve malfunction | Mapleson rebreathing',                'Replace absorbent; test valves; ↑ fresh gas flow'],
    [SLATE, 'Sudden spike then loss',       'Sampling line open to air | Patient coughed / strained',                            'Replace sampling line; reassess'],
  ];
  trbl.forEach(function(t, i) {
    var yy = 1.8 + i*0.71;
    addRect(s, 0.3, yy, 0.1, 0.6, t[0]);
    addRect(s, 0.45, yy, 9.2, 0.6, BGMID);
    addText(s, t[1], 0.55, yy+0.03, 2.5, 0.26, {fontSize:10.5, bold:true, color:t[0]});
    addText(s, 'Causes: '+t[2], 0.55, yy+0.32, 5.2, 0.22, {fontSize:9, color:OFFWHT});
    addRect(s, 5.85, yy+0.06, 3.65, 0.48, BG);
    addText(s, '▶ '+t[3], 5.9, yy+0.06, 3.55, 0.48, {fontSize:9, color:LIME});
  });
  footer(s, 'Morgan & Mikhail\'s 7e, p.228 | Barash 9e | Tintinalli\'s Emergency Medicine');

  // ── SLIDE 16: CRITICAL EVENTS TABLE ──────────────────────────────────────
  s = pres.appendSlide();
  s.getBackground().setSolidFill(HexColor(BG));
  sectionBar(s, 'CRITICAL EVENTS DETECTION');
  slideTitle(s, 'Critical Events Detected by Capnography',
    'Based on Barash Clinical Anesthesia 9e, Table 26-1');
  var events = [
    [RED,   'Esophageal intubation',    'CO₂ absent after 3–5 breaths',             'Immediate re-intubation'],
    [RED,   'Circuit disconnection',    'Sudden loss of waveform',                  'Check all connections'],
    [RED,   'Malignant hyperthermia',   'Rapid ↑ ETCO₂, earliest sign',            'Dantrolene, cooling, remove trigger'],
    [WARN,  'Air/venous embolism',      'Acute ↓ ETCO₂ (↑ dead space)',            'Position, aspiration, notify surgeon'],
    [WARN,  'Bronchospasm',             'Upsloping Phase III (shark fin)',           'Bronchodilator, ↑ expiratory time'],
    [WARN,  'Pulmonary embolism',       'Gradual ↓ ETCO₂, ↑ gradient',            'CT-PA, anticoagulation'],
    [TEALLT,'Rebreathing',             'Elevated inspiratory CO₂ baseline',         'Replace absorbent, check valves'],
    [RED,   'Cardiac arrest',           'Very low or absent ETCO₂',                 'CPR quality; target ETCO₂ ≥10 mmHg'],
    [GREEN, 'ROSC',                     'Sudden spike in ETCO₂ >35 mmHg',          'Pulse check; post-ROSC care'],
    [WARN,  'Hypoventilation',          'Gradual ↑ ETCO₂ >45 mmHg',               '↑ RR or TV; check sedation depth'],
  ];
  var ch2 = ['Event','Capnographic Finding','Clinical Action'];
  var cw2 = [2.4,3.2,3.9]; var cx2 = [0.3,2.8,6.1];
  ch2.forEach(function(h, ci) {
    addRect(s, cx2[ci], 1.72, cw2[ci]-0.1, 0.36, TEAL);
    addText(s, h, cx2[ci], 1.72, cw2[ci]-0.1, 0.36,
      {fontSize:10, bold:true, color:WHITE, align:'center'});
  });
  events.forEach(function(e, i) {
    var yy = 2.15 + i*0.33;
    var bg = i%2===0 ? BGMID : BG;
    addRect(s, 0.3, yy, 0.08, 0.3, e[0]);
    cx2.forEach(function(x, ci) {
      addRect(s, x, yy, cw2[ci]-0.1, 0.3, bg);
    });
    addText(s, e[1], cx2[0]+0.05, yy+0.02, cw2[0]-0.15, 0.26,
      {fontSize:9, bold:true, color:e[0]});
    addText(s, e[2], cx2[1]+0.05, yy+0.02, cw2[1]-0.15, 0.26,
      {fontSize:9, color:OFFWHT});
    addText(s, e[3], cx2[2]+0.05, yy+0.02, cw2[2]-0.15, 0.26,
      {fontSize:9, color:OFFWHT});
  });
  footer(s, 'Barash Clinical Anesthesia 9e, Table 26-1 | Morgan & Mikhail\'s 7e | Roberts & Hedges\'');

  // ── SLIDE 17: GUIDELINES ──────────────────────────────────────────────────
  s = pres.appendSlide();
  s.getBackground().setSolidFill(HexColor(BG));
  sectionBar(s, 'GUIDELINES & STANDARDS');
  slideTitle(s, 'Capnography: Mandatory Standards & Guidelines');
  var gls = [
    ['ASA','2011+','Continuous waveform capnography mandatory for all patients receiving general anesthesia. Also recommended for moderate/deep sedation.'],
    ['AHA ACLS','2020','Waveform capnography required to confirm and monitor ETT placement. ETCO₂ <10 mmHg at 20 min CPR may guide termination decisions.'],
    ['WHO','2009','Pulse oximetry AND capnography identified as essential monitoring for safe surgery globally — Safe Surgery Saves Lives initiative.'],
    ['AAGBI/RCoA','2021','Capnography is mandatory for any patient with a tracheal tube or supraglottic device under general anaesthesia.'],
    ['80+ Societies','2015–2024','Over 80 clinical societies have recommended capnography in >100 guidelines spanning anesthesia, emergency medicine, critical care, and procedural sedation.'],
  ];
  gls.forEach(function(g, i) {
    var yy = 1.82 + i*0.7;
    addRect(s, 0.35, yy, 1.1, 0.58, TEAL);
    addText(s, g[0], 0.35, yy, 1.1, 0.36, {fontSize:11, bold:true, color:LIME, align:'center'});
    addText(s, g[1], 0.35, yy+0.34, 1.1, 0.24, {fontSize:9, color:WHITE, align:'center'});
    addText(s, g[2], 1.55, yy+0.06, 8.1, 0.5, {fontSize:10.5, color:OFFWHT});
  });
  addRect(s, 0.35, 5.2, 9.3, 0.25, BGMID);
  addText(s, 'Capnography is standard of care — not optional — wherever airway management or sedation is administered',
    0.4, 5.2, 9.2, 0.25, {fontSize:9, color:LIME, align:'center'});
  footer(s, 'ASA Standards 2011 | AHA ACLS 2020 | WHO Safe Surgery | Respiratory Therapy 2024');

  // ── SLIDE 18: DECISION ALGORITHM ─────────────────────────────────────────
  s = pres.appendSlide();
  s.getBackground().setSolidFill(HexColor(BG));
  sectionBar(s, 'CLINICAL DECISION SUPPORT');
  slideTitle(s, 'Systematic Approach to an Abnormal Capnogram');
  var algo = [
    ['1','Is there a waveform?','YES → proceed to step 2','NO → check circuit, ETT position, patient status'],
    ['2','Is baseline (inspired CO₂) = 0?','YES → proceed to step 3','NO → rebreathing (check valve / absorbent)'],
    ['3','Is ETCO₂ 35–45 mmHg?','YES → normal ventilation ✓','NO → characterize further (steps 4–5)'],
    ['4','ETCO₂ HIGH (>45 mmHg)?','YES → hypoventilation / ↑CO₂ production → ↑MV, check MH, sepsis','LOW (<35) → ↑dead space (PE, embolism, ↓CO, hyperventilation)'],
    ['5','Phase III slope — flat or upsloping?','Flat → normal or hyperventilation','Upsloping → obstructive disease → bronchodilator, ↑expiratory time'],
  ];
  algo.forEach(function(step, i) {
    var yy = 1.78 + i*0.73;
    addRect(s, 0.35, yy, 0.48, 0.52, TEAL);
    addText(s, step[0], 0.35, yy, 0.48, 0.52,
      {fontSize:14, bold:true, color:LIME, align:'center'});
    addRect(s, 0.93, yy, 3.4, 0.52, BGMID);
    addText(s, step[1], 0.98, yy+0.06, 3.3, 0.42,
      {fontSize:10, bold:true, color:WHITE});
    addRect(s, 4.43, yy, 2.5, 0.52, BG);
    addText(s, '✔ '+step[2], 4.48, yy+0.04, 2.4, 0.44,
      {fontSize:8.5, color:GREEN});
    addRect(s, 7.03, yy, 2.65, 0.52, BG);
    addText(s, '✘ '+step[3], 7.08, yy+0.04, 2.55, 0.44,
      {fontSize:8.5, color:WARN});
  });
  footer(s, 'Adapted from Respiratory Therapy (Farquharson & Spratt, 2024) | Morgan & Mikhail\'s 7e');

  // ── SLIDE 19: KEY NUMBERS ─────────────────────────────────────────────────
  s = pres.appendSlide();
  s.getBackground().setSolidFill(HexColor(BG));
  sectionBar(s, 'QUICK REFERENCE');
  slideTitle(s, 'Key Numbers Every Clinician Should Know');
  var nums = [
    ['35–45 mmHg', 'Normal ETCO₂ range'],
    ['2–5 mmHg',   'Normal PaCO₂–ETCO₂ gradient (healthy lungs)'],
    ['< 10 mmHg',  'ETCO₂ during CPR → predicts resuscitation failure'],
    ['> 35 mmHg',  'Sudden ETCO₂ spike → suspect ROSC'],
    ['0 mmHg',     'Normal inspired CO₂ baseline'],
    ['≈ 4 min',    'Time advantage vs SpO₂ in detecting apnea/hypoventilation'],
    ['17.6×',      'More likely to detect respiratory depression vs standard monitoring'],
    ['100%',       'Sensitivity of waveform capnography for ETT placement confirmation'],
    ['0.04–0.10',  'Normal alveolar dead space fraction (AVDSf)'],
    ['> 0.20',     'Concerning AVDSf — investigate dead space cause'],
  ];
  nums.forEach(function(n, i) {
    var col = i%2; var row = Math.floor(i/2);
    var xo = 0.35 + col*4.9; var yo = 1.82 + row*0.72;
    addRect(s, xo, yo, 4.6, 0.64, BGMID, TEAL);
    addText(s, n[0], xo+0.08, yo+0.06, 1.6, 0.52,
      {fontSize:20, bold:true, color:LIME, align:'center'});
    addText(s, n[1], xo+1.75, yo+0.18, 2.75, 0.3,
      {fontSize:10, color:OFFWHT});
  });
  footer(s, 'Morgan & Mikhail\'s 7e | Barash 9e | Rosen\'s EM | Respiratory Therapy 2024');

  // ── SLIDE 20: TAKEAWAYS ───────────────────────────────────────────────────
  s = pres.appendSlide();
  s.getBackground().setSolidFill(HexColor(BG));
  addRect(s, 0, 0, 0.18, 5.625, TEAL);
  addRect(s, 0.18, 0, 0.06, 5.625, LIME);
  addText(s, 'KEY TAKEAWAYS', 0.5, 0.3, 9.0, 0.5,
    {fontSize:22, bold:true, color:LIME});
  var tks = [
    'Capnography measures CO₂ across ventilation, perfusion & metabolism — one waveform reflects all three.',
    'Normal ETCO₂ is 35–45 mmHg; a 2–5 mmHg gradient vs PaCO₂ reflects healthy lungs.',
    'Waveform capnography is mandatory in GA, ACLS, and strongly recommended for all sedated patients.',
    'Sudden loss of waveform = circuit disconnection or esophageal intubation until proven otherwise.',
    'Upsloping Phase III ("shark fin") = obstructive airways disease — treat the underlying cause.',
    'Elevated baseline = rebreathing — check valves and CO₂ absorbent immediately.',
    'During CPR: ETCO₂ ≥10 mmHg targets quality compressions; sudden spike = suspect ROSC.',
    'The (a-ET)CO₂ gradient is an indirect window into alveolar dead space and cardiac output.',
  ];
  addText(s, tks.map(function(t){ return '● ' + t; }).join('\n\n'),
    0.5, 0.95, 9.1, 4.4, {fontSize:11, color:OFFWHT});
  addText(s, 'Capnography 2026  |  ICU & Anesthesia Clinicians', 0.5, 5.25, 9.1, 0.25,
    {fontSize:9, color:SLATE, align:'right'});

  // ── DONE ──────────────────────────────────────────────────────────────────
  Logger.log('✅ Presentation created: ' + pres.getUrl());
  SlidesApp.getUi().alert(
    '✅ Done! Your Capnography presentation has been created.\n\nURL: ' + pres.getUrl()
  );
}
Reading File
Your credits are exhausted. You can purchase a top-up or subscribe to a plan to continue using Orris. If you're already subscribed, your daily credits will reset tomorrow.
This is a shared conversation. Sign in to Orris to start your own chat.