ERPETT

<div id=<div id="pet-emergency-hub" class="peh">
  <style>
    :root{
      /* Brand (calm + clinical + premium) */
      --navy:#0B1F3B;
      --teal:#0EA5A4;
      --ice:#F6FAFF;
      --card:#FFFFFF;
      --border:#E5EDF7;
      --text:#0B1220;
      --muted:#5B6B7F;
      --shadow: 0 14px 40px rgba(11,31,59,.10);

      /* Decision colors */
      --green-bg:#E9F7EF; --green-bd:#34C759;
      --yellow-bg:#FFF6DB; --yellow-bd:#F59E0B;
      --red-bg:#FFE7EA;   --red-bd:#EF4444;

      --btn:#0B1F3B; --btnText:#fff;
      --btnAlt:#ffffff; --btnAltText:#0B1F3B;

      --radius:18px;
    }

    .peh{
      font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
      color:var(--text);
      max-width: 1040px;
      margin: 0 auto;
      padding: 18px;
      background: transparent;
    }
    .peh *{ box-sizing:border-box; }

    .peh .topbar{
      border:1px solid var(--border);
      background: linear-gradient(180deg, #ffffff, var(--ice));
      border-radius: var(--radius);
      padding: 18px;
      box-shadow: var(--shadow);
    }
    .peh h1{
      font-size: 28px;
      margin: 0 0 6px;
      letter-spacing: -0.03em;
      color: var(--navy);
    }
    @media (min-width: 760px){ .peh h1{ font-size: 34px; } }

    .peh .sub{
      margin: 0;
      color: var(--muted);
      line-height: 1.35;
      max-width: 82ch;
    }

    .peh .row{
      display:flex;
      flex-wrap:wrap;
      align-items:center;
      justify-content:space-between;
      gap:12px;
      margin-top: 14px;
    }

    .peh .pillrow{ display:flex; flex-wrap:wrap; gap:10px; }
    .peh .pill{
      border:1px solid var(--border);
      background:#fff;
      border-radius:999px;
      padding:8px 12px;
      font-size: 13px;
      color: var(--muted);
      display:flex; align-items:center; gap:8px;
      user-select:none;
    }
    .peh .pill b{ color: var(--navy); font-weight: 750; }

    .peh .selector{
      display:flex; align-items:center; gap:10px; flex-wrap:wrap;
    }
    .peh .seg{
      display:inline-flex;
      border:1px solid var(--border);
      background:#fff;
      border-radius:999px;
      overflow:hidden;
    }
    .peh .seg button{
      border:0;
      padding:8px 12px;
      cursor:pointer;
      background: transparent;
      color: var(--muted);
      font-weight: 750;
      font-size: 13px;
    }
    .peh .seg button.active{
      background: rgba(14,165,164,.12);
      color: var(--navy);
    }

    .peh .actions{ display:flex; gap:10px; flex-wrap:wrap; }

    .peh .btn{
      appearance:none;
      border:1px solid transparent;
      border-radius: 14px;
      padding: 10px 14px;
      font-weight: 800;
      cursor:pointer;
      background: var(--btn);
      color: var(--btnText);
      transition: transform .06s ease, opacity .12s ease, box-shadow .12s ease;
      box-shadow: 0 10px 22px rgba(11,31,59,.10);
    }
    .peh .btn:active{ transform: translateY(1px); }
    .peh .btn.alt{
      background: var(--btnAlt);
      color: var(--btnAltText);
      border-color: var(--border);
      box-shadow: none;
    }

    .peh .card{
      border:1px solid var(--border);
      background:var(--card);
      border-radius: var(--radius);
      padding: 16px;
      box-shadow: 0 10px 26px rgba(11,31,59,.08);
      margin-top: 14px;
    }

    .peh .grid{
      margin-top: 14px;
      display:grid;
      grid-template-columns: repeat(2, minmax(0,1fr));
      gap: 12px;
    }
    @media (min-width: 760px){
      .peh .grid{ grid-template-columns: repeat(4, minmax(0,1fr)); }
    }

    .peh .dashbtn{
      width:100%;
      display:flex;
      flex-direction:column;
      align-items:flex-start;
      gap:8px;
      padding: 14px;
      border-radius: 16px;
      border:1px solid var(--border);
      background:#fff;
      cursor:pointer;
      transition: transform .06s ease, box-shadow .12s ease, border-color .12s ease;
      text-align:left;
      min-height: 98px;
      position:relative;
      overflow:hidden;
    }
    .peh .dashbtn::after{
      content:"";
      position:absolute;
      inset:-60px -60px auto auto;
      width:120px; height:120px;
      background: radial-gradient(circle at center, rgba(14,165,164,.18), rgba(14,165,164,0));
      transform: rotate(20deg);
      pointer-events:none;
    }
    .peh .dashbtn:hover{
      box-shadow: 0 14px 30px rgba(11,31,59,.12);
      border-color: rgba(14,165,164,.35);
    }
    .peh .dashbtn:active{ transform: translateY(1px); }
    .peh .dashbtn .title{
      font-weight: 900;
      font-size: 15px;
      letter-spacing: -0.01em;
      color: var(--navy);
    }
    .peh .dashbtn .desc{
      color: var(--muted);
      font-size: 13px;
      line-height: 1.25;
    }

    .peh .panel{
      margin-top: 14px;
      border:1px solid var(--border);
      border-radius: var(--radius);
      background:#fff;
      box-shadow: var(--shadow);
      overflow:hidden;
      display:none;
    }
    .peh .panel.active{ display:block; }

    .peh .panelhead{
      padding: 16px;
      border-bottom:1px solid var(--border);
      background: linear-gradient(180deg, #ffffff, #FBFDFF);
      display:flex;
      align-items:flex-start;
      justify-content:space-between;
      gap: 12px;
      flex-wrap:wrap;
    }
    .peh .panelhead h2{
      margin: 0;
      font-size: 20px;
      letter-spacing: -0.02em;
      color: var(--navy);
    }
    .peh .panelhead p{
      margin: 6px 0 0;
      color: var(--muted);
      font-size: 13px;
      line-height: 1.35;
      max-width: 80ch;
    }

    .peh .flow{
      padding: 16px;
      display:grid;
      gap: 12px;
    }

    .peh .q{
      border:1px solid var(--border);
      border-radius: 16px;
      padding: 14px;
      background: #fff;
    }
    .peh .q .qtitle{
      font-weight: 950;
      margin: 0 0 8px;
      letter-spacing: -0.01em;
      color: var(--navy);
      font-size: 15px;
    }
    .peh .q .qhelp{
      margin: 0 0 10px;
      color: var(--muted);
      font-size: 13px;
      line-height: 1.3;
    }
    .peh .q .qbtns{ display:flex; gap:10px; flex-wrap:wrap; }

    .peh .result{
      border-radius: var(--radius);
      padding: 14px;
      border: 2px solid var(--border);
      display:none;
    }
    .peh .result.show{ display:block; }
    .peh .result .rtitle{
      margin: 0 0 6px;
      font-weight: 1000;
      letter-spacing:-0.01em;
      color: var(--navy);
    }
    .peh .result .rtext{
      margin: 0 0 8px;
      color: var(--text);
      line-height: 1.35;
      font-size: 14px;
    }
    .peh .result ul{
      margin: 0;
      padding-left: 18px;
      color: var(--text);
      line-height: 1.35;
      font-size: 14px;
    }

    .peh .green{ background: var(--green-bg); border-color: var(--green-bd); }
    .peh .yellow{ background: var(--yellow-bg); border-color: var(--yellow-bd); }
    .peh .red{ background: var(--red-bg); border-color: var(--red-bd); }

    .peh .footerNote{
      margin-top: 14px;
      border:1px solid var(--border);
      background:#fff;
      border-radius: var(--radius);
      padding: 14px;
      color: var(--muted);
      font-size: 13px;
      line-height: 1.35;
    }
    .peh .footerNote b{ color: var(--navy); }

    .peh .tiny{
      font-size: 12px;
      color: var(--muted);
    }
  </style>

  <!-- HEADER -->
  <div class="topbar">
    <h1>Pet Emergency Decision Hub</h1>
    <p class="sub">
      For <b>dogs & cats</b>. Answer quick questions and get the safest next step in <b>under 3 minutes</b>.
      Built for stressed owners—simple, clear, and mobile-first.
    </p>

    <div class="row">
      <div class="pillrow" aria-label="Quick guidance">
        <div class="pill">🟢 <b>Monitor</b> at home</div>
        <div class="pill">🟡 <b>Call</b> your vet today</div>
        <div class="pill">🔴 <b>Emergency</b> now</div>
        <div class="pill">⏱ Typical use: <b>60–180s</b></div>
      </div>

      <div class="selector" aria-label="Species selector">
        <div class="tiny"><b>Species:</b></div>
        <div class="seg" role="tablist" aria-label="Species">
          <button type="button" id="peh-sp-dog" class="active" role="tab" aria-selected="true">Dog</button>
          <button type="button" id="peh-sp-cat" role="tab" aria-selected="false">Cat</button>
        </div>
        <div class="actions">
          <button class="btn alt" type="button" id="peh-resetAll">Reset</button>
          <button class="btn alt" type="button" id="peh-openDisclaimer">Disclaimer</button>
        </div>
      </div>
    </div>
  </div>

  <!-- DASHBOARD -->
  <div class="card" aria-label="Dashboard">
    <div style="display:flex; align-items:flex-end; justify-content:space-between; gap:12px; flex-wrap:wrap;">
      <div>
        <div style="font-weight:1000; letter-spacing:-0.01em; font-size:18px; color:var(--navy);">Choose what you see right now</div>
        <div style="color:var(--muted); font-size:13px; margin-top:4px;">
          Start with the most obvious symptom. When in doubt, choose the safer option.
        </div>
      </div>
      <div class="tiny">Includes <b>12</b> high-frequency emergency flows (dogs & cats).</div>
    </div>

    <div class="grid" role="navigation" aria-label="Emergency categories">
      <button class="dashbtn" type="button" data-flow="vomiting">
        <div class="title">Vomiting</div><div class="desc">Repeated vomiting, blood, weakness</div>
      </button>
      <button class="dashbtn" type="button" data-flow="diarrhea">
        <div class="title">Diarrhea</div><div class="desc">Blood, dehydration risk, severe lethargy</div>
      </button>
      <button class="dashbtn" type="button" data-flow="breathing">
        <div class="title">Breathing trouble</div><div class="desc">Open-mouth breathing, blue gums</div>
      </button>
      <button class="dashbtn" type="button" data-flow="seizure">
        <div class="title">Seizure</div><div class="desc">Duration, clusters, first-time seizure</div>
      </button>

      <button class="dashbtn" type="button" data-flow="trauma">
        <div class="title">Trauma / injury</div><div class="desc">Hit/fall, bleeding, severe pain</div>
      </button>
      <button class="dashbtn" type="button" data-flow="bloat">
        <div class="title">Swollen belly</div><div class="desc">Bloat suspicion, pain, retching</div>
      </button>
      <button class="dashbtn" type="button" data-flow="lethargy">
        <div class="title">Lethargy / collapse</div><div class="desc">Not responsive, weak, pale gums</div>
      </button>
      <button class="dashbtn" type="button" data-flow="urinary">
        <div class="title">Can’t pee / straining</div><div class="desc">Urinary blockage risk (cats critical)</div>
      </button>

      <button class="dashbtn" type="button" data-flow="poison">
        <div class="title">Poison / toxin</div><div class="desc">Chocolate, meds, plants, chemicals</div>
      </button>
      <button class="dashbtn" type="button" data-flow="allergic">
        <div class="title">Allergic reaction</div><div class="desc">Face swelling, hives, breathing issues</div>
      </button>
      <button class="dashbtn" type="button" data-flow="heat">
        <div class="title">Heatstroke</div><div class="desc">Overheating, collapse, heavy panting</div>
      </button>
      <button class="dashbtn" type="button" data-flow="eye">
        <div class="title">Eye emergency</div><div class="desc">Squinting, swelling, trauma, sudden cloudiness</div>
      </button>
    </div>
  </div>

  <!-- DYNAMIC PANEL (rendered by JS) -->
  <section class="panel" id="peh-panel-flow" aria-label="Flow panel">
    <div class="panelhead">
      <div>
        <h2 id="peh-flow-title">Flow Title</h2>
        <p id="peh-flow-sub">Flow subtitle</p>
      </div>
      <div class="actions">
        <button class="btn alt" type="button" id="peh-back">Back to dashboard</button>
        <button class="btn alt" type="button" id="peh-resetFlow">Reset this flow</button>
      </div>
    </div>
    <div class="flow" id="peh-flow-body"></div>
  </section>

  <!-- DISCLAIMER PANEL -->
  <section class="panel" id="peh-panel-disclaimer" aria-label="Disclaimer">
    <div class="panelhead">
      <div>
        <h2>Disclaimer</h2>
        <p>Educational decision support only (not diagnosis or treatment).</p>
      </div>
      <div class="actions">
        <button class="btn alt" type="button" id="peh-closeDisclaimer">Close</button>
      </div>
    </div>
    <div class="flow">
      <div class="q">
        <p class="qtitle">Important</p>
        <p class="qhelp">
          This tool is educational and does not replace veterinary evaluation. It does not diagnose conditions or prescribe treatment.
          If you believe your pet is in danger, contact a veterinarian or emergency clinic immediately.
        </p>
        <p class="qhelp">
          If your pet is unresponsive, has severe breathing difficulty, collapses, has uncontrolled bleeding, or has blue/gray gums/tongue → treat as an emergency.
        </p>
      </div>
    </div>
  </section>

  <div class="footerNote" role="note" aria-label="Footer disclaimer">
    <b>Disclaimer:</b> Educational use only. Not a diagnosis or treatment plan.
    If your pet is unresponsive, has breathing distress, collapses, has severe bleeding, or blue/gray gums/tongue → seek <b>emergency veterinary care</b>.
  </div>

  <script>
    (function(){
      const root = document.getElementById('pet-emergency-hub');

      // ---- State
      let species = 'dog'; // 'dog' | 'cat'
      let currentFlowKey = null;
      let currentNodeId = null;

      // ---- Elements
      const panelFlow = document.getElementById('peh-panel-flow');
      const panelDisclaimer = document.getElementById('peh-panel-disclaimer');
      const titleEl = document.getElementById('peh-flow-title');
      const subEl = document.getElementById('peh-flow-sub');
      const bodyEl = document.getElementById('peh-flow-body');

      // ---- Helpers
      function hidePanels(){
        panelFlow.classList.remove('active');
        panelDisclaimer.classList.remove('active');
      }
      function scrollToTop(){
        root.scrollIntoView({behavior:'smooth', block:'start'});
      }
      function setSpecies(sp){
        species = sp;
        document.getElementById('peh-sp-dog').classList.toggle('active', sp==='dog');
        document.getElementById('peh-sp-cat').classList.toggle('active', sp==='cat');
        document.getElementById('peh-sp-dog').setAttribute('aria-selected', sp==='dog');
        document.getElementById('peh-sp-cat').setAttribute('aria-selected', sp==='cat');
        // If flow open, re-render current node text (for species-specific strings)
        if(currentFlowKey){ renderNode(currentFlowKey, currentNodeId); }
      }

      function text(t){
        // Allows function or string
        return (typeof t === 'function') ? t(species) : t;
      }

      function showResult(level, title, desc, bullets){
        const cls = level === 'red' ? 'red' : level === 'yellow' ? 'yellow' : 'green';
        const icon = level === 'red' ? '🔴' : level === 'yellow' ? '🟡' : '🟢';
        const label = level === 'red' ? 'EMERGENCY NOW' : level === 'yellow' ? 'CALL YOUR VET TODAY' : 'MONITOR AT HOME';

        bodyEl.innerHTML = `
          <div class="result ${cls} show" aria-live="polite">
            <p class="rtitle">${icon} ${label}</p>
            <p class="rtext"><b>${title}</b> — ${desc}</p>
            <ul>
              ${bullets.map(b=>`<li>${b}</li>`).join('')}
            </ul>
          </div>
          <div class="q">
            <p class="qtitle">Quick safety notes</p>
            <p class="qhelp">
              Keep your pet calm, avoid unnecessary handling, and bring any suspect toxin/medication packaging if relevant.
              When in doubt, choose the safer option.
            </p>
          </div>
        `;
        bodyEl.scrollIntoView({behavior:'smooth', block:'start'});
      }

      function renderNode(flowKey, nodeId){
        const flow = FLOWS[flowKey];
        const node = flow.nodes[nodeId];
        currentFlowKey = flowKey;
        currentNodeId = nodeId;

        // Header
        titleEl.textContent = flow.title;
        subEl.textContent = text(flow.subtitle);

        // Node UI
        const qTitle = text(node.q);
        const qHelp = text(node.help);

        bodyEl.innerHTML = `
          <div class="q">
            <p class="qtitle">${qTitle}</p>
            ${qHelp ? `<p class="qhelp">${qHelp}</p>` : ``}
            <div class="qbtns">
              ${node.answers.map(a => `
                <button class="btn ${a.style==='alt' ? 'alt' : ''}" type="button"
                        data-answer="${a.value}" data-next="${a.next || ''}"
                        data-level="${a.level || ''}">
                  ${a.label}
                </button>
              `).join('')}
            </div>
          </div>
          ${node.note ? `<div class="q"><p class="qtitle">Tip</p><p class="qhelp">${text(node.note)}</p></div>` : ``}
        `;

        // Bind answer clicks
        bodyEl.querySelectorAll('button[data-answer]').forEach(btn=>{
          btn.addEventListener('click', ()=>{
            const next = btn.getAttribute('data-next');
            const level = btn.getAttribute('data-level');
            const ansVal = btn.getAttribute('data-answer');

            if(level){
              const res = node.results[ansVal];
              showResult(level, text(res.title), text(res.desc), res.bullets.map(text));
              return;
            }
            if(next){
              renderNode(flowKey, next);
              return;
            }
          });
        });

        bodyEl.scrollIntoView({behavior:'smooth', block:'start'});
      }

      function openFlow(flowKey){
        hidePanels();
        panelFlow.classList.add('active');
        const flow = FLOWS[flowKey];
        currentFlowKey = flowKey;
        currentNodeId = flow.start;
        renderNode(flowKey, flow.start);
      }

      function resetFlow(){
        if(!currentFlowKey) return;
        const flow = FLOWS[currentFlowKey];
        renderNode(currentFlowKey, flow.start);
      }

      // ---- Flows (12) — built for DOGS & CATS
      // Notes:
      // - Keep it non-diagnostic: triage level only.
      // - Conservative: ambiguous cases tend to Yellow.
      const FLOWS = {
        vomiting: {
          title: "Vomiting",
          subtitle: (sp)=> sp==='cat'
            ? "Use this flow if your cat is vomiting or retching."
            : "Use this flow if your dog is vomiting.",
          start: "v1",
          nodes: {
            v1: {
              q: (sp)=>`Is your ${sp} unresponsive, collapsing, or too weak to stand?`,
              help: "Severe weakness can indicate shock or a serious internal problem.",
              answers: [
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"v2", style:"alt"}
              ],
              results: {
                yes: {
                  title:"Immediate risk",
                  desc:"Go to emergency veterinary care now.",
                  bullets:[
                    "Keep warm and transport safely.",
                    "Do not force food or large amounts of water.",
                    "Bring recent meds and any suspected toxin/food."
                  ]
                }
              }
            },
            v2: {
              q: "Is there blood in vomit, black/tarry stool, or a painful/swollen abdomen?",
              help: "These are high-risk red flags.",
              answers: [
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"v3", style:"alt"}
              ],
              results: {
                yes: {
                  title:"Red flags present",
                  desc:"Treat as an emergency.",
                  bullets:[
                    "Transport calmly; avoid stress/excitement.",
                    "Don’t give human medications.",
                    "If possible, note how long symptoms have been present."
                  ]
                }
              }
            },
            v3: {
              q: "Has vomiting happened 3+ times in 1 hour OR continued for 6+ hours?",
              help: "Repeated vomiting raises dehydration risk quickly.",
              answers: [
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", next:"v4", style:"alt"}
              ],
              results: {
                yes: {
                  title:"Needs same-day guidance",
                  desc:"Call your vet today for next steps.",
                  bullets:[
                    "Offer small sips of water only if not vomiting constantly.",
                    "Monitor gum color and energy level.",
                    "If your pet becomes weak/collapses → emergency."
                  ]
                }
              }
            },
            v4: {
              q: "Is your pet acting normal otherwise (bright, alert, normal breathing)?",
              help: "If vomiting was isolated and your pet is normal, monitoring can be reasonable.",
              answers: [
                {label:"Yes", value:"yes", level:"green"},
                {label:"No", value:"no", level:"yellow", style:"alt"}
              ],
              results: {
                yes: {
                  title:"Likely safe to monitor",
                  desc:"Monitor at home and re-check frequently.",
                  bullets:[
                    "Observe closely for 12 hours.",
                    "If vomiting repeats or energy drops → call your vet.",
                    "If you suspect toxin ingestion → use the Poison/Toxin flow."
                  ]
                },
                no: {
                  title:"Not back to normal",
                  desc:"Call your vet today.",
                  bullets:[
                    "Low energy + vomiting can worsen fast.",
                    "If breathing changes or collapse occurs → emergency.",
                    "Prepare a short timeline of symptoms for your vet."
                  ]
                }
              }
            }
          }
        },

        diarrhea: {
          title:"Diarrhea",
          subtitle:(sp)=> sp==='cat'
            ? "Use this flow if your cat has diarrhea or frequent loose stool."
            : "Use this flow if your dog has diarrhea.",
          start:"d1",
          nodes:{
            d1:{
              q:(sp)=>`Is your ${sp} unresponsive, collapsing, or extremely weak?`,
              help:"Severe weakness can be dehydration or shock.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"d2", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Severe systemic signs",
                  desc:"Emergency evaluation is recommended now.",
                  bullets:[
                    "Keep warm and transport safely.",
                    "Do not give human anti-diarrhea meds.",
                    "Bring any stool photo if helpful."
                  ]
                }
              }
            },
            d2:{
              q:"Is there large amounts of blood, black/tarry stool, or severe belly pain?",
              help:"These are red flags for serious GI disease.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"d3", style:"alt"}
              ],
              results:{
                yes:{
                  title:"High-risk GI signs",
                  desc:"Treat as emergency now.",
                  bullets:[
                    "Avoid food until a vet advises otherwise.",
                    "Offer small water amounts if your pet can drink.",
                    "If vomiting is also present → higher urgency."
                  ]
                }
              }
            },
            d3:{
              q:"Is diarrhea very frequent (every 1–2 hours) OR lasting more than 24 hours?",
              help:"Prolonged or very frequent diarrhea can dehydrate quickly.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", next:"d4", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Same-day guidance needed",
                  desc:"Call your vet today.",
                  bullets:[
                    "Monitor hydration and energy.",
                    "If your pet stops drinking or becomes weak → emergency.",
                    "If toxin exposure suspected → use Poison/Toxin flow."
                  ]
                }
              }
            },
            d4:{
              q:"Is your pet otherwise bright/normal and drinking water?",
              help:"Mild, short diarrhea with normal energy can often be monitored.",
              answers:[
                {label:"Yes", value:"yes", level:"green"},
                {label:"No", value:"no", level:"yellow", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Monitor likely OK",
                  desc:"Monitor at home and reassess.",
                  bullets:[
                    "Watch for vomiting, blood, or worsening lethargy.",
                    "If diarrhea persists beyond 24 hours → call your vet.",
                    "For cats: if not eating + diarrhea → call your vet sooner."
                  ]
                },
                no:{
                  title:"Not normal baseline",
                  desc:"Call your vet today.",
                  bullets:[
                    "Low appetite/low energy increases urgency.",
                    "If dehydration signs appear → emergency.",
                    "Prepare a timeline (start time, frequency, any diet changes)."
                  ]
                }
              }
            }
          }
        },

        breathing:{
          title:"Breathing trouble",
          subtitle:(sp)=> sp==='cat'
            ? "Cats: open-mouth breathing at rest is always concerning."
            : "Dogs: breathing distress can deteriorate quickly.",
          start:"b1",
          nodes:{
            b1:{
              q:"Are the gums/tongue blue/gray OR is your pet collapsing/unresponsive?",
              help:"This can indicate poor oxygenation or shock.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"b2", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Severe oxygen/shock risk",
                  desc:"Emergency care now.",
                  bullets:[
                    "Keep calm, minimal handling.",
                    "Transport immediately; keep cool (not cold).",
                    "Do not force food/water."
                  ]
                }
              }
            },
            b2:{
              q:(sp)=> sp==='cat'
                ? "Is your cat open-mouth breathing at rest OR breathing with obvious effort?"
                : "Is your dog struggling to breathe OR breathing with obvious effort?",
              help:"Effortful breathing is more important than the number of breaths.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"b3", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Respiratory distress",
                  desc:"Emergency now.",
                  bullets:[
                    "Keep your pet calm; avoid restraint if it worsens breathing.",
                    "Use AC / cool environment.",
                    "Go now even if symptoms come and go."
                  ]
                }
              }
            },
            b3:{
              q:"Is there new persistent cough, noisy breathing (wheeze/stridor), or extreme panting at rest?",
              help:"Could be airway disease, pain, fever, heart/lung issues.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", level:"green", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Needs same-day vet advice",
                  desc:"Call your vet today (same-day).",
                  bullets:[
                    "Keep activity low and environment cool.",
                    "If effort increases or gums turn pale/blue → emergency.",
                    "Avoid smoke, perfumes, and heat."
                  ]
                },
                no:{
                  title:"Likely safe to monitor (if mild/transient)",
                  desc:"Monitor at home and reassess soon.",
                  bullets:[
                    "Re-check at rest after 10 minutes.",
                    "If it persists or worsens → call your vet today.",
                    "Cats: if any open-mouth breathing occurs → emergency."
                  ]
                }
              }
            }
          }
        },

        seizure:{
          title:"Seizure",
          subtitle:(sp)=>`Safety first. Time it if possible. ${sp==='cat' ? 'Cats can hide toxin exposures—be alert.' : 'Dogs may cluster—watch closely.'}`,
          start:"s1",
          nodes:{
            s1:{
              q:"Did the seizure last 5+ minutes OR are there multiple seizures without full recovery?",
              help:"This is an emergency risk (status/cluster).",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"s2", style:"alt"}
              ],
              results:{
                yes:{
                  title:"High-risk seizure pattern",
                  desc:"Emergency now.",
                  bullets:[
                    "Do not put hands near the mouth.",
                    "Dark/quiet environment; avoid stairs.",
                    "Transport immediately; note duration and number of seizures."
                  ]
                }
              }
            },
            s2:{
              q:"Is this the first seizure ever OR possible toxin exposure OR head trauma?",
              help:"First-time seizures usually need same-day evaluation.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", next:"s3", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Needs same-day evaluation",
                  desc:"Call your vet today; go sooner if worsening.",
                  bullets:[
                    "Record what you saw + exact timing if possible.",
                    "If another seizure occurs → emergency.",
                    "If toxin suspected → use Poison/Toxin flow and go urgently."
                  ]
                }
              }
            },
            s3:{
              q:"After 60 minutes, is your pet still unable to walk normally or very disoriented?",
              help:"Prolonged post-ictal signs can be concerning.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", level:"green", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Prolonged recovery",
                  desc:"Call your vet today (same-day).",
                  bullets:[
                    "Keep calm and restrict activity.",
                    "If repeated seizures occur → emergency.",
                    "Keep away from stairs/water until normal."
                  ]
                },
                no:{
                  title:"Isolated brief seizure",
                  desc:"Monitor at home and schedule a vet discussion if it happens again.",
                  bullets:[
                    "Observe closely for the next 24 hours.",
                    "If another seizure occurs → emergency or call your vet immediately.",
                    "Avoid triggers: stress, overheating, flashing lights."
                  ]
                }
              }
            }
          }
        },

        trauma:{
          title:"Trauma / injury",
          subtitle:(sp)=>`Falls, hit-by-car, bite wounds, limping, bleeding. ${sp==='cat' ? 'Cats may hide pain—don’t underestimate.' : ''}`,
          start:"t1",
          nodes:{
            t1:{
              q:"Is there heavy bleeding that won’t stop in 5 minutes OR collapse/pale gums?",
              help:"Major bleeding/shock signs are emergencies.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"t2", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Shock/major bleeding risk",
                  desc:"Emergency now.",
                  bullets:[
                    "Apply firm pressure with clean cloth/gauze.",
                    "Minimize movement; keep warm.",
                    "Transport immediately; consider towel as stretcher."
                  ]
                }
              }
            },
            t2:{
              q:"Is your pet unable to bear weight OR has obvious deformity OR severe pain/vocalizing?",
              help:"Possible fracture/dislocation or significant internal injury.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", next:"t3", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Significant injury likely",
                  desc:"Call your vet today; go to emergency if pain is severe or worsening.",
                  bullets:[
                    "Restrict movement; crate/box transport if possible.",
                    "Do not give human pain meds.",
                    "If breathing changes or collapse occurs → emergency."
                  ]
                }
              }
            },
            t3:{
              q:"Is it a small wound/minor limp AND your pet is comfortable at rest?",
              help:"Minor injuries can be monitored, but watch for swelling/worsening pain.",
              answers:[
                {label:"Yes", value:"yes", level:"green"},
                {label:"No", value:"no", level:"yellow", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Monitor likely OK",
                  desc:"Monitor and reassess within 12–24 hours.",
                  bullets:[
                    "Restrict activity; avoid stairs/jumping.",
                    "If swelling/pain increases → call your vet.",
                    "If bite wound → call your vet today (infection risk)."
                  ]
                },
                no:{
                  title:"Not clearly mild",
                  desc:"Call your vet today for guidance.",
                  bullets:[
                    "Pain that persists warrants evaluation.",
                    "If your pet becomes weak/collapses → emergency.",
                    "Keep activity restricted until checked."
                  ]
                }
              }
            }
          }
        },

        bloat:{
          title:"Swollen belly / bloat suspicion",
          subtitle:(sp)=> sp==='cat'
            ? "Cats: bloating can be serious—use this triage if abdomen looks suddenly enlarged or painful."
            : "Dogs: bloat/GDV is time-critical—don’t wait if red flags are present.",
          start:"g1",
          nodes:{
            g1:{
              q:(sp)=> sp==='dog'
                ? "Is your dog repeatedly retching/dry-heaving with little or no vomit?"
                : "Is your cat repeatedly retching with little/no vomit OR showing acute severe discomfort?",
              help:"Retching + swollen abdomen can be an emergency.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"g2", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Time-critical red flag",
                  desc:"Emergency now.",
                  bullets:[
                    "Do not give food or water.",
                    "Transport immediately; keep calm.",
                    "Time matters—go now."
                  ]
                }
              }
            },
            g2:{
              q:"Is the abdomen suddenly swollen/hard OR is there severe belly pain (restless, crying, hunched)?",
              help:"Sudden distension/pain can signal dangerous conditions.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"g3", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Severe abdominal concern",
                  desc:"Emergency now.",
                  bullets:[
                    "Avoid handling the abdomen.",
                    "Keep calm; transport immediately.",
                    "If collapse/weakness occurs → urgent emergency."
                  ]
                }
              }
            },
            g3:{
              q:"Is your pet still eating/drinking normally and acting normal otherwise?",
              help:"Mild bloating with normal behavior is less urgent but still needs watchfulness.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", level:"yellow", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Needs vet advice soon",
                  desc:"Call your vet today (same-day) to be safe.",
                  bullets:[
                    "If pain or swelling worsens → emergency.",
                    "If vomiting/retching begins → emergency.",
                    "Avoid heavy meals until advised."
                  ]
                },
                no:{
                  title:"Not normal baseline",
                  desc:"Call your vet today; go emergency if pain or weakness increases.",
                  bullets:[
                    "Abdominal issues can change quickly.",
                    "If breathing difficulty or collapse occurs → emergency.",
                    "Keep activity minimal."
                  ]
                }
              }
            }
          }
        },

        lethargy:{
          title:"Lethargy / collapse",
          subtitle:(sp)=>`Use this flow for sudden weakness, collapse, or “not acting like themselves.”`,
          start:"l1",
          nodes:{
            l1:{
              q:(sp)=>`Is your ${sp} unresponsive, collapsed, or unable to stand?`,
              help:"This is a high-risk sign.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"l2", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Severe systemic concern",
                  desc:"Emergency now.",
                  bullets:[
                    "Check breathing; transport immediately.",
                    "Keep warm; minimal handling.",
                    "Bring medication list + timeline of symptoms."
                  ]
                }
              }
            },
            l2:{
              q:"Are gums very pale/white OR is breathing labored?",
              help:"Pale gums + weakness can indicate shock/anemia; labored breathing is urgent.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"l3", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Potential shock/respiratory risk",
                  desc:"Emergency now.",
                  bullets:[
                    "Keep calm and transport quickly.",
                    "Do not delay for food/water.",
                    "Avoid overheating; use a cool environment."
                  ]
                }
              }
            },
            l3:{
              q:"Is your pet refusing food/water OR much less active than normal for 12+ hours?",
              help:"Prolonged lethargy needs vet guidance.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", level:"green", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Needs same-day guidance",
                  desc:"Call your vet today.",
                  bullets:[
                    "If vomiting/diarrhea is present, dehydration risk is higher.",
                    "If weakness worsens or collapse occurs → emergency.",
                    "Cats: not eating for 24 hours warrants faster vet contact."
                  ]
                },
                no:{
                  title:"Mild/transient lethargy",
                  desc:"Monitor at home and reassess soon.",
                  bullets:[
                    "Re-check in 2–4 hours.",
                    "If symptoms persist beyond 12 hours → call your vet.",
                    "If breathing changes or collapse occurs → emergency."
                  ]
                }
              }
            }
          }
        },

        urinary:{
          title:"Can’t pee / straining",
          subtitle:(sp)=> sp==='cat'
            ? "Cats: urinary blockage can become life-threatening fast."
            : "Dogs: straining can be UTI, obstruction, or pain—triage carefully.",
          start:"u1",
          nodes:{
            u1:{
              q:(sp)=> sp==='cat'
                ? "Is your cat repeatedly going to the litter box with little/no urine OR crying/straining?"
                : "Is your dog straining to urinate with little/no urine output?",
              help:"Little/no urine can mean obstruction (higher risk in cats).",
              answers:[
                {label:"Yes", value:"yes", next:"u2"},
                {label:"No", value:"no", level:"yellow", style:"alt"}
              ],
              results:{
                no:{
                  title:"Urinary concern still possible",
                  desc:"Call your vet today (same-day).",
                  bullets:[
                    "If urine output drops or your pet strains → use this flow again.",
                    "If vomiting/lethargy develops → higher urgency.",
                    "Cats: if any doubt about output → treat more urgently."
                  ]
                }
              }
            },
            u2:{
              q:"Is your pet lethargic, vomiting, painful belly, or vocalizing in distress?",
              help:"Systemic signs + urinary obstruction are emergencies.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"u3", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Obstruction with systemic signs",
                  desc:"Emergency now.",
                  bullets:[
                    "Do not wait—this can deteriorate quickly.",
                    "Transport immediately.",
                    "Do not give human meds."
                  ]
                }
              }
            },
            u3:{
              q:(sp)=> sp==='cat'
                ? "Has there been little/no urine for 6–8 hours OR your cat is repeatedly straining?"
                : "Has there been little/no urine for 12 hours OR repeated straining episodes?",
              help:"Time without urine increases risk.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", level:"yellow", style:"alt"}
              ],
              results:{
                yes:{
                  title:"High obstruction risk",
                  desc:"Emergency now (especially for cats).",
                  bullets:[
                    "Keep calm; transport immediately.",
                    "Bring a brief timeline (when last normal urination was).",
                    "Cats: this is a common emergency—don’t delay."
                  ]
                },
                no:{
                  title:"Needs same-day vet visit",
                  desc:"Call your vet today (same-day).",
                  bullets:[
                    "Watch urine output closely.",
                    "If output decreases or vomiting/lethargy begins → emergency.",
                    "Avoid stress; keep access to water."
                  ]
                }
              }
            }
          }
        },

        poison:{
          title:"Poison / toxin exposure",
          subtitle:(sp)=>`Chocolate, medications, plants, chemicals, essential oils, rodenticides—time matters.`,
          start:"p1",
          nodes:{
            p1:{
              q:"Did you witness ingestion OR strongly suspect exposure to a toxin/medication/chemical?",
              help:"If yes, treat as urgent. If unknown but signs are severe, also urgent.",
              answers:[
                {label:"Yes", value:"yes", next:"p2"},
                {label:"Not sure", value:"maybe", next:"p3", style:"alt"},
                {label:"No", value:"no", next:"p3", style:"alt"}
              ]
            },
            p2:{
              q:"Is your pet having seizures, collapse, severe breathing trouble, or uncontrolled vomiting?",
              help:"These are emergency signs after possible toxin exposure.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"p4", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Severe toxin signs",
                  desc:"Emergency now.",
                  bullets:[
                    "Bring packaging/label or a photo of it.",
                    "Do not induce vomiting unless a professional instructs you.",
                    "Transport immediately; keep calm."
                  ]
                }
              }
            },
            p3:{
              q:"Even without known exposure, are there severe signs (collapse, seizures, blue gums, severe lethargy)?",
              help:"Severe signs always escalate to emergency.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", level:"yellow", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Severe signs present",
                  desc:"Emergency now.",
                  bullets:[
                    "Transport immediately.",
                    "Bring timeline of symptoms.",
                    "If you later find a toxin source, bring packaging."
                  ]
                },
                no:{
                  title:"Possible exposure / mild signs",
                  desc:"Call your vet or a poison hotline today (urgent).",
                  bullets:[
                    "Gather details: what, how much, when, pet’s weight.",
                    "Do not give home remedies or human meds.",
                    "If symptoms worsen → emergency."
                  ]
                }
              }
            },
            p4:{
              q:"Was ingestion within the last 2 hours?",
              help:"Earlier intervention can be more effective.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", level:"yellow", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Urgent exposure window",
                  desc:"Call your vet/poison hotline immediately (same-day).",
                  bullets:[
                    "Have packaging/photos ready.",
                    "Do not induce vomiting unless instructed.",
                    "If severe signs start → emergency."
                  ]
                },
                no:{
                  title:"Still urgent",
                  desc:"Call your vet/poison hotline today for guidance.",
                  bullets:[
                    "Some toxins have delayed effects.",
                    "Monitor closely for new signs.",
                    "If severe signs appear → emergency."
                  ]
                }
              }
            }
          }
        },

        allergic:{
          title:"Allergic reaction",
          subtitle:(sp)=>`Hives, itching, facial swelling, vomiting, breathing changes.`,
          start:"a1",
          nodes:{
            a1:{
              q:"Is there difficulty breathing, collapse, or blue/gray gums/tongue?",
              help:"These can indicate anaphylaxis or severe airway compromise.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"a2", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Possible severe reaction",
                  desc:"Emergency now.",
                  bullets:[
                    "Transport immediately.",
                    "Keep calm; avoid exertion.",
                    "Bring any suspect food/medications (label/photo)."
                  ]
                }
              }
            },
            a2:{
              q:"Is there facial swelling (eyes/lips), widespread hives, or repeated vomiting after exposure?",
              help:"Moderate reactions need same-day guidance; swelling can worsen.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", next:"a3", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Moderate allergic reaction",
                  desc:"Call your vet today (same-day).",
                  bullets:[
                    "Monitor breathing closely for worsening.",
                    "If breathing changes or collapse occurs → emergency.",
                    "Avoid re-exposure to suspected trigger."
                  ]
                }
              }
            },
            a3:{
              q:"Is it mild itching with normal breathing and no swelling?",
              help:"Mild reactions can be monitored briefly, but they can progress.",
              answers:[
                {label:"Yes", value:"yes", level:"green"},
                {label:"No", value:"no", level:"yellow", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Mild reaction",
                  desc:"Monitor at home and reassess frequently.",
                  bullets:[
                    "If swelling, vomiting, or breathing changes develop → emergency/call vet.",
                    "Keep pet calm; avoid heat/exercise.",
                    "Consider vet advice if it persists."
                  ]
                },
                no:{
                  title:"Not clearly mild",
                  desc:"Call your vet today.",
                  bullets:[
                    "Reactions can escalate unexpectedly.",
                    "Watch for breathing changes.",
                    "If collapse/blue gums → emergency."
                  ]
                }
              }
            }
          }
        },

        heat:{
          title:"Heatstroke / overheating",
          subtitle:(sp)=>`Hot environment, heavy panting, weakness—time matters.`,
          start:"h1",
          nodes:{
            h1:{
              q:(sp)=> sp==='cat'
                ? "Is your cat open-mouth breathing, collapsing, or extremely weak after heat exposure?"
                : "Is your dog collapsing, unresponsive, or unable to stand after heat/exertion?",
              help:"Severe overheating can be life-threatening.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"h2", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Severe heat illness risk",
                  desc:"Emergency now.",
                  bullets:[
                    "Move to cool area immediately (AC).",
                    "Cool with room-temperature water (not ice-cold).",
                    "Transport to emergency vet now."
                  ]
                }
              }
            },
            h2:{
              q:"Is there extreme panting at rest, vomiting/diarrhea, or disorientation?",
              help:"These suggest significant heat stress.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"h3", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Significant heat stress",
                  desc:"Emergency now.",
                  bullets:[
                    "Start gentle cooling while preparing transport.",
                    "Do not force water if vomiting.",
                    "Keep pet calm and cool."
                  ]
                }
              }
            },
            h3:{
              q:"Mild overheating only (panting) and improves quickly within 10 minutes of cooling?",
              help:"If it resolves rapidly and pet returns to normal, monitoring may be reasonable.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", level:"red", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Still needs vet guidance",
                  desc:"Call your vet today—heat illness can have delayed effects.",
                  bullets:[
                    "Keep resting in a cool area.",
                    "Watch for vomiting, weakness, collapse.",
                    "If symptoms return → emergency."
                  ]
                },
                no:{
                  title:"Not improving quickly",
                  desc:"Emergency now.",
                  bullets:[
                    "Continue gentle cooling en route.",
                    "Avoid ice baths (can cause vasoconstriction/shock).",
                    "Transport immediately."
                  ]
                }
              }
            }
          }
        },

        eye:{
          title:"Eye emergency",
          subtitle:(sp)=>`Eye pain can worsen fast; early action protects vision.`,
          start:"e1",
          nodes:{
            e1:{
              q:"Is the eye bulging out, or is there a deep cut/penetrating injury?",
              help:"These are vision-threatening emergencies.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"e2", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Vision-threatening injury",
                  desc:"Emergency now.",
                  bullets:[
                    "Prevent rubbing (cone/collar if available).",
                    "Do not apply human eye drops unless instructed.",
                    "Transport immediately."
                  ]
                }
              }
            },
            e2:{
              q:"Is your pet squinting/holding eye closed, with significant redness, swelling, or sudden cloudiness?",
              help:"These often need same-day treatment to prevent complications.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", next:"e3", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Likely painful eye condition",
                  desc:"Call your vet today (same-day).",
                  bullets:[
                    "Prevent rubbing; keep calm.",
                    "If discharge becomes thick/green or pain worsens → urgent visit.",
                    "If eye becomes suddenly blue/gray/cloudy → emergency sooner."
                  ]
                }
              }
            },
            e3:{
              q:"Mild irritation only (minor tearing) and pet is not squinting?",
              help:"Mild irritation can be monitored briefly, but eyes change quickly.",
              answers:[
                {label:"Yes", value:"yes", level:"green"},
                {label:"No", value:"no", level:"yellow", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Monitor briefly",
                  desc:"Monitor at home for a short period.",
                  bullets:[
                    "If squinting/pain starts → call your vet today.",
                    "If swelling or cloudiness appears → urgent vet visit.",
                    "Prevent rubbing."
                  ]
                },
                no:{
                  title:"Not clearly mild",
                  desc:"Call your vet today.",
                  bullets:[
                    "Eye issues can worsen fast.",
                    "Prevent rubbing; keep calm.",
                    "If bulging/trauma suspected → emergency."
                  ]
                }
              }
            }
          }
        }
      };

      // ---- Wire up dashboard
      root.querySelectorAll('.dashbtn').forEach(btn=>{
        btn.addEventListener('click', ()=>{
          const flowKey = btn.getAttribute('data-flow');
          openFlow(flowKey);
        });
      });

      // ---- Species buttons
      document.getElementById('peh-sp-dog').addEventListener('click', ()=> setSpecies('dog'));
      document.getElementById('peh-sp-cat').addEventListener('click', ()=> setSpecies('cat'));

      // ---- Back / reset flow
      document.getElementById('peh-back').addEventListener('click', ()=>{
        currentFlowKey = null;
        currentNodeId = null;
        hidePanels();
        scrollToTop();
      });
      document.getElementById('peh-resetFlow').addEventListener('click', resetFlow);

      // ---- Reset all
      document.getElementById('peh-resetAll').addEventListener('click', ()=>{
        currentFlowKey = null;
        currentNodeId = null;
        hidePanels();
        scrollToTop();
      });

      // ---- Disclaimer
      document.getElementById('peh-openDisclaimer').addEventListener('click', ()=>{
        hidePanels();
        panelDisclaimer.classList.add('active');
        panelDisclaimer.scrollIntoView({behavior:'smooth', block:'start'});
      });
      document.getElementById('peh-closeDisclaimer').addEventListener('click', ()=>{
        panelDisclaimer.classList.remove('active');
        scrollToTop();
      });

      // Init
      hidePanels();
      setSpecies('dog');
    })();
  </script>
</div>"pet-emergency-hub" class="peh">
  <style>
    :root{
      /* Brand (calm + clinical + premium) */
      --navy:#0B1F3B;
      --teal:#0EA5A4;
      --ice:#F6FAFF;
      --card:#FFFFFF;
      --border:#E5EDF7;
      --text:#0B1220;
      --muted:#5B6B7F;
      --shadow: 0 14px 40px rgba(11,31,59,.10);

      /* Decision colors */
      --green-bg:#E9F7EF; --green-bd:#34C759;
      --yellow-bg:#FFF6DB; --yellow-bd:#F59E0B;
      --red-bg:#FFE7EA;   --red-bd:#EF4444;

      --btn:#0B1F3B; --btnText:#fff;
      --btnAlt:#ffffff; --btnAltText:#0B1F3B;

      --radius:18px;
    }

    .peh{
      font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
      color:var(--text);
      max-width: 1040px;
      margin: 0 auto;
      padding: 18px;
      background: transparent;
    }
    .peh *{ box-sizing:border-box; }

    .peh .topbar{
      border:1px solid var(--border);
      background: linear-gradient(180deg, #ffffff, var(--ice));
      border-radius: var(--radius);
      padding: 18px;
      box-shadow: var(--shadow);
    }
    .peh h1{
      font-size: 28px;
      margin: 0 0 6px;
      letter-spacing: -0.03em;
      color: var(--navy);
    }
    @media (min-width: 760px){ .peh h1{ font-size: 34px; } }

    .peh .sub{
      margin: 0;
      color: var(--muted);
      line-height: 1.35;
      max-width: 82ch;
    }

    .peh .row{
      display:flex;
      flex-wrap:wrap;
      align-items:center;
      justify-content:space-between;
      gap:12px;
      margin-top: 14px;
    }

    .peh .pillrow{ display:flex; flex-wrap:wrap; gap:10px; }
    .peh .pill{
      border:1px solid var(--border);
      background:#fff;
      border-radius:999px;
      padding:8px 12px;
      font-size: 13px;
      color: var(--muted);
      display:flex; align-items:center; gap:8px;
      user-select:none;
    }
    .peh .pill b{ color: var(--navy); font-weight: 750; }

    .peh .selector{
      display:flex; align-items:center; gap:10px; flex-wrap:wrap;
    }
    .peh .seg{
      display:inline-flex;
      border:1px solid var(--border);
      background:#fff;
      border-radius:999px;
      overflow:hidden;
    }
    .peh .seg button{
      border:0;
      padding:8px 12px;
      cursor:pointer;
      background: transparent;
      color: var(--muted);
      font-weight: 750;
      font-size: 13px;
    }
    .peh .seg button.active{
      background: rgba(14,165,164,.12);
      color: var(--navy);
    }

    .peh .actions{ display:flex; gap:10px; flex-wrap:wrap; }

    .peh .btn{
      appearance:none;
      border:1px solid transparent;
      border-radius: 14px;
      padding: 10px 14px;
      font-weight: 800;
      cursor:pointer;
      background: var(--btn);
      color: var(--btnText);
      transition: transform .06s ease, opacity .12s ease, box-shadow .12s ease;
      box-shadow: 0 10px 22px rgba(11,31,59,.10);
    }
    .peh .btn:active{ transform: translateY(1px); }
    .peh .btn.alt{
      background: var(--btnAlt);
      color: var(--btnAltText);
      border-color: var(--border);
      box-shadow: none;
    }

    .peh .card{
      border:1px solid var(--border);
      background:var(--card);
      border-radius: var(--radius);
      padding: 16px;
      box-shadow: 0 10px 26px rgba(11,31,59,.08);
      margin-top: 14px;
    }

    .peh .grid{
      margin-top: 14px;
      display:grid;
      grid-template-columns: repeat(2, minmax(0,1fr));
      gap: 12px;
    }
    @media (min-width: 760px){
      .peh .grid{ grid-template-columns: repeat(4, minmax(0,1fr)); }
    }

    .peh .dashbtn{
      width:100%;
      display:flex;
      flex-direction:column;
      align-items:flex-start;
      gap:8px;
      padding: 14px;
      border-radius: 16px;
      border:1px solid var(--border);
      background:#fff;
      cursor:pointer;
      transition: transform .06s ease, box-shadow .12s ease, border-color .12s ease;
      text-align:left;
      min-height: 98px;
      position:relative;
      overflow:hidden;
    }
    .peh .dashbtn::after{
      content:"";
      position:absolute;
      inset:-60px -60px auto auto;
      width:120px; height:120px;
      background: radial-gradient(circle at center, rgba(14,165,164,.18), rgba(14,165,164,0));
      transform: rotate(20deg);
      pointer-events:none;
    }
    .peh .dashbtn:hover{
      box-shadow: 0 14px 30px rgba(11,31,59,.12);
      border-color: rgba(14,165,164,.35);
    }
    .peh .dashbtn:active{ transform: translateY(1px); }
    .peh .dashbtn .title{
      font-weight: 900;
      font-size: 15px;
      letter-spacing: -0.01em;
      color: var(--navy);
    }
    .peh .dashbtn .desc{
      color: var(--muted);
      font-size: 13px;
      line-height: 1.25;
    }

    .peh .panel{
      margin-top: 14px;
      border:1px solid var(--border);
      border-radius: var(--radius);
      background:#fff;
      box-shadow: var(--shadow);
      overflow:hidden;
      display:none;
    }
    .peh .panel.active{ display:block; }

    .peh .panelhead{
      padding: 16px;
      border-bottom:1px solid var(--border);
      background: linear-gradient(180deg, #ffffff, #FBFDFF);
      display:flex;
      align-items:flex-start;
      justify-content:space-between;
      gap: 12px;
      flex-wrap:wrap;
    }
    .peh .panelhead h2{
      margin: 0;
      font-size: 20px;
      letter-spacing: -0.02em;
      color: var(--navy);
    }
    .peh .panelhead p{
      margin: 6px 0 0;
      color: var(--muted);
      font-size: 13px;
      line-height: 1.35;
      max-width: 80ch;
    }

    .peh .flow{
      padding: 16px;
      display:grid;
      gap: 12px;
    }

    .peh .q{
      border:1px solid var(--border);
      border-radius: 16px;
      padding: 14px;
      background: #fff;
    }
    .peh .q .qtitle{
      font-weight: 950;
      margin: 0 0 8px;
      letter-spacing: -0.01em;
      color: var(--navy);
      font-size: 15px;
    }
    .peh .q .qhelp{
      margin: 0 0 10px;
      color: var(--muted);
      font-size: 13px;
      line-height: 1.3;
    }
    .peh .q .qbtns{ display:flex; gap:10px; flex-wrap:wrap; }

    .peh .result{
      border-radius: var(--radius);
      padding: 14px;
      border: 2px solid var(--border);
      display:none;
    }
    .peh .result.show{ display:block; }
    .peh .result .rtitle{
      margin: 0 0 6px;
      font-weight: 1000;
      letter-spacing:-0.01em;
      color: var(--navy);
    }
    .peh .result .rtext{
      margin: 0 0 8px;
      color: var(--text);
      line-height: 1.35;
      font-size: 14px;
    }
    .peh .result ul{
      margin: 0;
      padding-left: 18px;
      color: var(--text);
      line-height: 1.35;
      font-size: 14px;
    }

    .peh .green{ background: var(--green-bg); border-color: var(--green-bd); }
    .peh .yellow{ background: var(--yellow-bg); border-color: var(--yellow-bd); }
    .peh .red{ background: var(--red-bg); border-color: var(--red-bd); }

    .peh .footerNote{
      margin-top: 14px;
      border:1px solid var(--border);
      background:#fff;
      border-radius: var(--radius);
      padding: 14px;
      color: var(--muted);
      font-size: 13px;
      line-height: 1.35;
    }
    .peh .footerNote b{ color: var(--navy); }

    .peh .tiny{
      font-size: 12px;
      color: var(--muted);
    }
  </style>

  <!-- HEADER -->
  <div class="topbar">
    <h1>Pet Emergency Decision Hub</h1>
    <p class="sub">
      For <b>dogs & cats</b>. Answer quick questions and get the safest next step in <b>under 3 minutes</b>.
      Built for stressed owners—simple, clear, and mobile-first.
    </p>

    <div class="row">
      <div class="pillrow" aria-label="Quick guidance">
        <div class="pill">🟢 <b>Monitor</b> at home</div>
        <div class="pill">🟡 <b>Call</b> your vet today</div>
        <div class="pill">🔴 <b>Emergency</b> now</div>
        <div class="pill">⏱ Typical use: <b>60–180s</b></div>
      </div>

      <div class="selector" aria-label="Species selector">
        <div class="tiny"><b>Species:</b></div>
        <div class="seg" role="tablist" aria-label="Species">
          <button type="button" id="peh-sp-dog" class="active" role="tab" aria-selected="true">Dog</button>
          <button type="button" id="peh-sp-cat" role="tab" aria-selected="false">Cat</button>
        </div>
        <div class="actions">
          <button class="btn alt" type="button" id="peh-resetAll">Reset</button>
          <button class="btn alt" type="button" id="peh-openDisclaimer">Disclaimer</button>
        </div>
      </div>
    </div>
  </div>

  <!-- DASHBOARD -->
  <div class="card" aria-label="Dashboard">
    <div style="display:flex; align-items:flex-end; justify-content:space-between; gap:12px; flex-wrap:wrap;">
      <div>
        <div style="font-weight:1000; letter-spacing:-0.01em; font-size:18px; color:var(--navy);">Choose what you see right now</div>
        <div style="color:var(--muted); font-size:13px; margin-top:4px;">
          Start with the most obvious symptom. When in doubt, choose the safer option.
        </div>
      </div>
      <div class="tiny">Includes <b>12</b> high-frequency emergency flows (dogs & cats).</div>
    </div>

    <div class="grid" role="navigation" aria-label="Emergency categories">
      <button class="dashbtn" type="button" data-flow="vomiting">
        <div class="title">Vomiting</div><div class="desc">Repeated vomiting, blood, weakness</div>
      </button>
      <button class="dashbtn" type="button" data-flow="diarrhea">
        <div class="title">Diarrhea</div><div class="desc">Blood, dehydration risk, severe lethargy</div>
      </button>
      <button class="dashbtn" type="button" data-flow="breathing">
        <div class="title">Breathing trouble</div><div class="desc">Open-mouth breathing, blue gums</div>
      </button>
      <button class="dashbtn" type="button" data-flow="seizure">
        <div class="title">Seizure</div><div class="desc">Duration, clusters, first-time seizure</div>
      </button>

      <button class="dashbtn" type="button" data-flow="trauma">
        <div class="title">Trauma / injury</div><div class="desc">Hit/fall, bleeding, severe pain</div>
      </button>
      <button class="dashbtn" type="button" data-flow="bloat">
        <div class="title">Swollen belly</div><div class="desc">Bloat suspicion, pain, retching</div>
      </button>
      <button class="dashbtn" type="button" data-flow="lethargy">
        <div class="title">Lethargy / collapse</div><div class="desc">Not responsive, weak, pale gums</div>
      </button>
      <button class="dashbtn" type="button" data-flow="urinary">
        <div class="title">Can’t pee / straining</div><div class="desc">Urinary blockage risk (cats critical)</div>
      </button>

      <button class="dashbtn" type="button" data-flow="poison">
        <div class="title">Poison / toxin</div><div class="desc">Chocolate, meds, plants, chemicals</div>
      </button>
      <button class="dashbtn" type="button" data-flow="allergic">
        <div class="title">Allergic reaction</div><div class="desc">Face swelling, hives, breathing issues</div>
      </button>
      <button class="dashbtn" type="button" data-flow="heat">
        <div class="title">Heatstroke</div><div class="desc">Overheating, collapse, heavy panting</div>
      </button>
      <button class="dashbtn" type="button" data-flow="eye">
        <div class="title">Eye emergency</div><div class="desc">Squinting, swelling, trauma, sudden cloudiness</div>
      </button>
    </div>
  </div>

  <!-- DYNAMIC PANEL (rendered by JS) -->
  <section class="panel" id="peh-panel-flow" aria-label="Flow panel">
    <div class="panelhead">
      <div>
        <h2 id="peh-flow-title">Flow Title</h2>
        <p id="peh-flow-sub">Flow subtitle</p>
      </div>
      <div class="actions">
        <button class="btn alt" type="button" id="peh-back">Back to dashboard</button>
        <button class="btn alt" type="button" id="peh-resetFlow">Reset this flow</button>
      </div>
    </div>
    <div class="flow" id="peh-flow-body"></div>
  </section>

  <!-- DISCLAIMER PANEL -->
  <section class="panel" id="peh-panel-disclaimer" aria-label="Disclaimer">
    <div class="panelhead">
      <div>
        <h2>Disclaimer</h2>
        <p>Educational decision support only (not diagnosis or treatment).</p>
      </div>
      <div class="actions">
        <button class="btn alt" type="button" id="peh-closeDisclaimer">Close</button>
      </div>
    </div>
    <div class="flow">
      <div class="q">
        <p class="qtitle">Important</p>
        <p class="qhelp">
          This tool is educational and does not replace veterinary evaluation. It does not diagnose conditions or prescribe treatment.
          If you believe your pet is in danger, contact a veterinarian or emergency clinic immediately.
        </p>
        <p class="qhelp">
          If your pet is unresponsive, has severe breathing difficulty, collapses, has uncontrolled bleeding, or has blue/gray gums/tongue → treat as an emergency.
        </p>
      </div>
    </div>
  </section>

  <div class="footerNote" role="note" aria-label="Footer disclaimer">
    <b>Disclaimer:</b> Educational use only. Not a diagnosis or treatment plan.
    If your pet is unresponsive, has breathing distress, collapses, has severe bleeding, or blue/gray gums/tongue → seek <b>emergency veterinary care</b>.
  </div>

  <script>
    (function(){
      const root = document.getElementById('pet-emergency-hub');

      // ---- State
      let species = 'dog'; // 'dog' | 'cat'
      let currentFlowKey = null;
      let currentNodeId = null;

      // ---- Elements
      const panelFlow = document.getElementById('peh-panel-flow');
      const panelDisclaimer = document.getElementById('peh-panel-disclaimer');
      const titleEl = document.getElementById('peh-flow-title');
      const subEl = document.getElementById('peh-flow-sub');
      const bodyEl = document.getElementById('peh-flow-body');

      // ---- Helpers
      function hidePanels(){
        panelFlow.classList.remove('active');
        panelDisclaimer.classList.remove('active');
      }
      function scrollToTop(){
        root.scrollIntoView({behavior:'smooth', block:'start'});
      }
      function setSpecies(sp){
        species = sp;
        document.getElementById('peh-sp-dog').classList.toggle('active', sp==='dog');
        document.getElementById('peh-sp-cat').classList.toggle('active', sp==='cat');
        document.getElementById('peh-sp-dog').setAttribute('aria-selected', sp==='dog');
        document.getElementById('peh-sp-cat').setAttribute('aria-selected', sp==='cat');
        // If flow open, re-render current node text (for species-specific strings)
        if(currentFlowKey){ renderNode(currentFlowKey, currentNodeId); }
      }

      function text(t){
        // Allows function or string
        return (typeof t === 'function') ? t(species) : t;
      }

      function showResult(level, title, desc, bullets){
        const cls = level === 'red' ? 'red' : level === 'yellow' ? 'yellow' : 'green';
        const icon = level === 'red' ? '🔴' : level === 'yellow' ? '🟡' : '🟢';
        const label = level === 'red' ? 'EMERGENCY NOW' : level === 'yellow' ? 'CALL YOUR VET TODAY' : 'MONITOR AT HOME';

        bodyEl.innerHTML = `
          <div class="result ${cls} show" aria-live="polite">
            <p class="rtitle">${icon} ${label}</p>
            <p class="rtext"><b>${title}</b> — ${desc}</p>
            <ul>
              ${bullets.map(b=>`<li>${b}</li>`).join('')}
            </ul>
          </div>
          <div class="q">
            <p class="qtitle">Quick safety notes</p>
            <p class="qhelp">
              Keep your pet calm, avoid unnecessary handling, and bring any suspect toxin/medication packaging if relevant.
              When in doubt, choose the safer option.
            </p>
          </div>
        `;
        bodyEl.scrollIntoView({behavior:'smooth', block:'start'});
      }

      function renderNode(flowKey, nodeId){
        const flow = FLOWS[flowKey];
        const node = flow.nodes[nodeId];
        currentFlowKey = flowKey;
        currentNodeId = nodeId;

        // Header
        titleEl.textContent = flow.title;
        subEl.textContent = text(flow.subtitle);

        // Node UI
        const qTitle = text(node.q);
        const qHelp = text(node.help);

        bodyEl.innerHTML = `
          <div class="q">
            <p class="qtitle">${qTitle}</p>
            ${qHelp ? `<p class="qhelp">${qHelp}</p>` : ``}
            <div class="qbtns">
              ${node.answers.map(a => `
                <button class="btn ${a.style==='alt' ? 'alt' : ''}" type="button"
                        data-answer="${a.value}" data-next="${a.next || ''}"
                        data-level="${a.level || ''}">
                  ${a.label}
                </button>
              `).join('')}
            </div>
          </div>
          ${node.note ? `<div class="q"><p class="qtitle">Tip</p><p class="qhelp">${text(node.note)}</p></div>` : ``}
        `;

        // Bind answer clicks
        bodyEl.querySelectorAll('button[data-answer]').forEach(btn=>{
          btn.addEventListener('click', ()=>{
            const next = btn.getAttribute('data-next');
            const level = btn.getAttribute('data-level');
            const ansVal = btn.getAttribute('data-answer');

            if(level){
              const res = node.results[ansVal];
              showResult(level, text(res.title), text(res.desc), res.bullets.map(text));
              return;
            }
            if(next){
              renderNode(flowKey, next);
              return;
            }
          });
        });

        bodyEl.scrollIntoView({behavior:'smooth', block:'start'});
      }

      function openFlow(flowKey){
        hidePanels();
        panelFlow.classList.add('active');
        const flow = FLOWS[flowKey];
        currentFlowKey = flowKey;
        currentNodeId = flow.start;
        renderNode(flowKey, flow.start);
      }

      function resetFlow(){
        if(!currentFlowKey) return;
        const flow = FLOWS[currentFlowKey];
        renderNode(currentFlowKey, flow.start);
      }

      // ---- Flows (12) — built for DOGS & CATS
      // Notes:
      // - Keep it non-diagnostic: triage level only.
      // - Conservative: ambiguous cases tend to Yellow.
      const FLOWS = {
        vomiting: {
          title: "Vomiting",
          subtitle: (sp)=> sp==='cat'
            ? "Use this flow if your cat is vomiting or retching."
            : "Use this flow if your dog is vomiting.",
          start: "v1",
          nodes: {
            v1: {
              q: (sp)=>`Is your ${sp} unresponsive, collapsing, or too weak to stand?`,
              help: "Severe weakness can indicate shock or a serious internal problem.",
              answers: [
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"v2", style:"alt"}
              ],
              results: {
                yes: {
                  title:"Immediate risk",
                  desc:"Go to emergency veterinary care now.",
                  bullets:[
                    "Keep warm and transport safely.",
                    "Do not force food or large amounts of water.",
                    "Bring recent meds and any suspected toxin/food."
                  ]
                }
              }
            },
            v2: {
              q: "Is there blood in vomit, black/tarry stool, or a painful/swollen abdomen?",
              help: "These are high-risk red flags.",
              answers: [
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"v3", style:"alt"}
              ],
              results: {
                yes: {
                  title:"Red flags present",
                  desc:"Treat as an emergency.",
                  bullets:[
                    "Transport calmly; avoid stress/excitement.",
                    "Don’t give human medications.",
                    "If possible, note how long symptoms have been present."
                  ]
                }
              }
            },
            v3: {
              q: "Has vomiting happened 3+ times in 1 hour OR continued for 6+ hours?",
              help: "Repeated vomiting raises dehydration risk quickly.",
              answers: [
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", next:"v4", style:"alt"}
              ],
              results: {
                yes: {
                  title:"Needs same-day guidance",
                  desc:"Call your vet today for next steps.",
                  bullets:[
                    "Offer small sips of water only if not vomiting constantly.",
                    "Monitor gum color and energy level.",
                    "If your pet becomes weak/collapses → emergency."
                  ]
                }
              }
            },
            v4: {
              q: "Is your pet acting normal otherwise (bright, alert, normal breathing)?",
              help: "If vomiting was isolated and your pet is normal, monitoring can be reasonable.",
              answers: [
                {label:"Yes", value:"yes", level:"green"},
                {label:"No", value:"no", level:"yellow", style:"alt"}
              ],
              results: {
                yes: {
                  title:"Likely safe to monitor",
                  desc:"Monitor at home and re-check frequently.",
                  bullets:[
                    "Observe closely for 12 hours.",
                    "If vomiting repeats or energy drops → call your vet.",
                    "If you suspect toxin ingestion → use the Poison/Toxin flow."
                  ]
                },
                no: {
                  title:"Not back to normal",
                  desc:"Call your vet today.",
                  bullets:[
                    "Low energy + vomiting can worsen fast.",
                    "If breathing changes or collapse occurs → emergency.",
                    "Prepare a short timeline of symptoms for your vet."
                  ]
                }
              }
            }
          }
        },

        diarrhea: {
          title:"Diarrhea",
          subtitle:(sp)=> sp==='cat'
            ? "Use this flow if your cat has diarrhea or frequent loose stool."
            : "Use this flow if your dog has diarrhea.",
          start:"d1",
          nodes:{
            d1:{
              q:(sp)=>`Is your ${sp} unresponsive, collapsing, or extremely weak?`,
              help:"Severe weakness can be dehydration or shock.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"d2", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Severe systemic signs",
                  desc:"Emergency evaluation is recommended now.",
                  bullets:[
                    "Keep warm and transport safely.",
                    "Do not give human anti-diarrhea meds.",
                    "Bring any stool photo if helpful."
                  ]
                }
              }
            },
            d2:{
              q:"Is there large amounts of blood, black/tarry stool, or severe belly pain?",
              help:"These are red flags for serious GI disease.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"d3", style:"alt"}
              ],
              results:{
                yes:{
                  title:"High-risk GI signs",
                  desc:"Treat as emergency now.",
                  bullets:[
                    "Avoid food until a vet advises otherwise.",
                    "Offer small water amounts if your pet can drink.",
                    "If vomiting is also present → higher urgency."
                  ]
                }
              }
            },
            d3:{
              q:"Is diarrhea very frequent (every 1–2 hours) OR lasting more than 24 hours?",
              help:"Prolonged or very frequent diarrhea can dehydrate quickly.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", next:"d4", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Same-day guidance needed",
                  desc:"Call your vet today.",
                  bullets:[
                    "Monitor hydration and energy.",
                    "If your pet stops drinking or becomes weak → emergency.",
                    "If toxin exposure suspected → use Poison/Toxin flow."
                  ]
                }
              }
            },
            d4:{
              q:"Is your pet otherwise bright/normal and drinking water?",
              help:"Mild, short diarrhea with normal energy can often be monitored.",
              answers:[
                {label:"Yes", value:"yes", level:"green"},
                {label:"No", value:"no", level:"yellow", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Monitor likely OK",
                  desc:"Monitor at home and reassess.",
                  bullets:[
                    "Watch for vomiting, blood, or worsening lethargy.",
                    "If diarrhea persists beyond 24 hours → call your vet.",
                    "For cats: if not eating + diarrhea → call your vet sooner."
                  ]
                },
                no:{
                  title:"Not normal baseline",
                  desc:"Call your vet today.",
                  bullets:[
                    "Low appetite/low energy increases urgency.",
                    "If dehydration signs appear → emergency.",
                    "Prepare a timeline (start time, frequency, any diet changes)."
                  ]
                }
              }
            }
          }
        },

        breathing:{
          title:"Breathing trouble",
          subtitle:(sp)=> sp==='cat'
            ? "Cats: open-mouth breathing at rest is always concerning."
            : "Dogs: breathing distress can deteriorate quickly.",
          start:"b1",
          nodes:{
            b1:{
              q:"Are the gums/tongue blue/gray OR is your pet collapsing/unresponsive?",
              help:"This can indicate poor oxygenation or shock.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"b2", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Severe oxygen/shock risk",
                  desc:"Emergency care now.",
                  bullets:[
                    "Keep calm, minimal handling.",
                    "Transport immediately; keep cool (not cold).",
                    "Do not force food/water."
                  ]
                }
              }
            },
            b2:{
              q:(sp)=> sp==='cat'
                ? "Is your cat open-mouth breathing at rest OR breathing with obvious effort?"
                : "Is your dog struggling to breathe OR breathing with obvious effort?",
              help:"Effortful breathing is more important than the number of breaths.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"b3", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Respiratory distress",
                  desc:"Emergency now.",
                  bullets:[
                    "Keep your pet calm; avoid restraint if it worsens breathing.",
                    "Use AC / cool environment.",
                    "Go now even if symptoms come and go."
                  ]
                }
              }
            },
            b3:{
              q:"Is there new persistent cough, noisy breathing (wheeze/stridor), or extreme panting at rest?",
              help:"Could be airway disease, pain, fever, heart/lung issues.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", level:"green", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Needs same-day vet advice",
                  desc:"Call your vet today (same-day).",
                  bullets:[
                    "Keep activity low and environment cool.",
                    "If effort increases or gums turn pale/blue → emergency.",
                    "Avoid smoke, perfumes, and heat."
                  ]
                },
                no:{
                  title:"Likely safe to monitor (if mild/transient)",
                  desc:"Monitor at home and reassess soon.",
                  bullets:[
                    "Re-check at rest after 10 minutes.",
                    "If it persists or worsens → call your vet today.",
                    "Cats: if any open-mouth breathing occurs → emergency."
                  ]
                }
              }
            }
          }
        },

        seizure:{
          title:"Seizure",
          subtitle:(sp)=>`Safety first. Time it if possible. ${sp==='cat' ? 'Cats can hide toxin exposures—be alert.' : 'Dogs may cluster—watch closely.'}`,
          start:"s1",
          nodes:{
            s1:{
              q:"Did the seizure last 5+ minutes OR are there multiple seizures without full recovery?",
              help:"This is an emergency risk (status/cluster).",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"s2", style:"alt"}
              ],
              results:{
                yes:{
                  title:"High-risk seizure pattern",
                  desc:"Emergency now.",
                  bullets:[
                    "Do not put hands near the mouth.",
                    "Dark/quiet environment; avoid stairs.",
                    "Transport immediately; note duration and number of seizures."
                  ]
                }
              }
            },
            s2:{
              q:"Is this the first seizure ever OR possible toxin exposure OR head trauma?",
              help:"First-time seizures usually need same-day evaluation.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", next:"s3", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Needs same-day evaluation",
                  desc:"Call your vet today; go sooner if worsening.",
                  bullets:[
                    "Record what you saw + exact timing if possible.",
                    "If another seizure occurs → emergency.",
                    "If toxin suspected → use Poison/Toxin flow and go urgently."
                  ]
                }
              }
            },
            s3:{
              q:"After 60 minutes, is your pet still unable to walk normally or very disoriented?",
              help:"Prolonged post-ictal signs can be concerning.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", level:"green", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Prolonged recovery",
                  desc:"Call your vet today (same-day).",
                  bullets:[
                    "Keep calm and restrict activity.",
                    "If repeated seizures occur → emergency.",
                    "Keep away from stairs/water until normal."
                  ]
                },
                no:{
                  title:"Isolated brief seizure",
                  desc:"Monitor at home and schedule a vet discussion if it happens again.",
                  bullets:[
                    "Observe closely for the next 24 hours.",
                    "If another seizure occurs → emergency or call your vet immediately.",
                    "Avoid triggers: stress, overheating, flashing lights."
                  ]
                }
              }
            }
          }
        },

        trauma:{
          title:"Trauma / injury",
          subtitle:(sp)=>`Falls, hit-by-car, bite wounds, limping, bleeding. ${sp==='cat' ? 'Cats may hide pain—don’t underestimate.' : ''}`,
          start:"t1",
          nodes:{
            t1:{
              q:"Is there heavy bleeding that won’t stop in 5 minutes OR collapse/pale gums?",
              help:"Major bleeding/shock signs are emergencies.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"t2", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Shock/major bleeding risk",
                  desc:"Emergency now.",
                  bullets:[
                    "Apply firm pressure with clean cloth/gauze.",
                    "Minimize movement; keep warm.",
                    "Transport immediately; consider towel as stretcher."
                  ]
                }
              }
            },
            t2:{
              q:"Is your pet unable to bear weight OR has obvious deformity OR severe pain/vocalizing?",
              help:"Possible fracture/dislocation or significant internal injury.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", next:"t3", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Significant injury likely",
                  desc:"Call your vet today; go to emergency if pain is severe or worsening.",
                  bullets:[
                    "Restrict movement; crate/box transport if possible.",
                    "Do not give human pain meds.",
                    "If breathing changes or collapse occurs → emergency."
                  ]
                }
              }
            },
            t3:{
              q:"Is it a small wound/minor limp AND your pet is comfortable at rest?",
              help:"Minor injuries can be monitored, but watch for swelling/worsening pain.",
              answers:[
                {label:"Yes", value:"yes", level:"green"},
                {label:"No", value:"no", level:"yellow", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Monitor likely OK",
                  desc:"Monitor and reassess within 12–24 hours.",
                  bullets:[
                    "Restrict activity; avoid stairs/jumping.",
                    "If swelling/pain increases → call your vet.",
                    "If bite wound → call your vet today (infection risk)."
                  ]
                },
                no:{
                  title:"Not clearly mild",
                  desc:"Call your vet today for guidance.",
                  bullets:[
                    "Pain that persists warrants evaluation.",
                    "If your pet becomes weak/collapses → emergency.",
                    "Keep activity restricted until checked."
                  ]
                }
              }
            }
          }
        },

        bloat:{
          title:"Swollen belly / bloat suspicion",
          subtitle:(sp)=> sp==='cat'
            ? "Cats: bloating can be serious—use this triage if abdomen looks suddenly enlarged or painful."
            : "Dogs: bloat/GDV is time-critical—don’t wait if red flags are present.",
          start:"g1",
          nodes:{
            g1:{
              q:(sp)=> sp==='dog'
                ? "Is your dog repeatedly retching/dry-heaving with little or no vomit?"
                : "Is your cat repeatedly retching with little/no vomit OR showing acute severe discomfort?",
              help:"Retching + swollen abdomen can be an emergency.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"g2", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Time-critical red flag",
                  desc:"Emergency now.",
                  bullets:[
                    "Do not give food or water.",
                    "Transport immediately; keep calm.",
                    "Time matters—go now."
                  ]
                }
              }
            },
            g2:{
              q:"Is the abdomen suddenly swollen/hard OR is there severe belly pain (restless, crying, hunched)?",
              help:"Sudden distension/pain can signal dangerous conditions.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"g3", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Severe abdominal concern",
                  desc:"Emergency now.",
                  bullets:[
                    "Avoid handling the abdomen.",
                    "Keep calm; transport immediately.",
                    "If collapse/weakness occurs → urgent emergency."
                  ]
                }
              }
            },
            g3:{
              q:"Is your pet still eating/drinking normally and acting normal otherwise?",
              help:"Mild bloating with normal behavior is less urgent but still needs watchfulness.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", level:"yellow", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Needs vet advice soon",
                  desc:"Call your vet today (same-day) to be safe.",
                  bullets:[
                    "If pain or swelling worsens → emergency.",
                    "If vomiting/retching begins → emergency.",
                    "Avoid heavy meals until advised."
                  ]
                },
                no:{
                  title:"Not normal baseline",
                  desc:"Call your vet today; go emergency if pain or weakness increases.",
                  bullets:[
                    "Abdominal issues can change quickly.",
                    "If breathing difficulty or collapse occurs → emergency.",
                    "Keep activity minimal."
                  ]
                }
              }
            }
          }
        },

        lethargy:{
          title:"Lethargy / collapse",
          subtitle:(sp)=>`Use this flow for sudden weakness, collapse, or “not acting like themselves.”`,
          start:"l1",
          nodes:{
            l1:{
              q:(sp)=>`Is your ${sp} unresponsive, collapsed, or unable to stand?`,
              help:"This is a high-risk sign.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"l2", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Severe systemic concern",
                  desc:"Emergency now.",
                  bullets:[
                    "Check breathing; transport immediately.",
                    "Keep warm; minimal handling.",
                    "Bring medication list + timeline of symptoms."
                  ]
                }
              }
            },
            l2:{
              q:"Are gums very pale/white OR is breathing labored?",
              help:"Pale gums + weakness can indicate shock/anemia; labored breathing is urgent.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"l3", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Potential shock/respiratory risk",
                  desc:"Emergency now.",
                  bullets:[
                    "Keep calm and transport quickly.",
                    "Do not delay for food/water.",
                    "Avoid overheating; use a cool environment."
                  ]
                }
              }
            },
            l3:{
              q:"Is your pet refusing food/water OR much less active than normal for 12+ hours?",
              help:"Prolonged lethargy needs vet guidance.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", level:"green", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Needs same-day guidance",
                  desc:"Call your vet today.",
                  bullets:[
                    "If vomiting/diarrhea is present, dehydration risk is higher.",
                    "If weakness worsens or collapse occurs → emergency.",
                    "Cats: not eating for 24 hours warrants faster vet contact."
                  ]
                },
                no:{
                  title:"Mild/transient lethargy",
                  desc:"Monitor at home and reassess soon.",
                  bullets:[
                    "Re-check in 2–4 hours.",
                    "If symptoms persist beyond 12 hours → call your vet.",
                    "If breathing changes or collapse occurs → emergency."
                  ]
                }
              }
            }
          }
        },

        urinary:{
          title:"Can’t pee / straining",
          subtitle:(sp)=> sp==='cat'
            ? "Cats: urinary blockage can become life-threatening fast."
            : "Dogs: straining can be UTI, obstruction, or pain—triage carefully.",
          start:"u1",
          nodes:{
            u1:{
              q:(sp)=> sp==='cat'
                ? "Is your cat repeatedly going to the litter box with little/no urine OR crying/straining?"
                : "Is your dog straining to urinate with little/no urine output?",
              help:"Little/no urine can mean obstruction (higher risk in cats).",
              answers:[
                {label:"Yes", value:"yes", next:"u2"},
                {label:"No", value:"no", level:"yellow", style:"alt"}
              ],
              results:{
                no:{
                  title:"Urinary concern still possible",
                  desc:"Call your vet today (same-day).",
                  bullets:[
                    "If urine output drops or your pet strains → use this flow again.",
                    "If vomiting/lethargy develops → higher urgency.",
                    "Cats: if any doubt about output → treat more urgently."
                  ]
                }
              }
            },
            u2:{
              q:"Is your pet lethargic, vomiting, painful belly, or vocalizing in distress?",
              help:"Systemic signs + urinary obstruction are emergencies.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"u3", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Obstruction with systemic signs",
                  desc:"Emergency now.",
                  bullets:[
                    "Do not wait—this can deteriorate quickly.",
                    "Transport immediately.",
                    "Do not give human meds."
                  ]
                }
              }
            },
            u3:{
              q:(sp)=> sp==='cat'
                ? "Has there been little/no urine for 6–8 hours OR your cat is repeatedly straining?"
                : "Has there been little/no urine for 12 hours OR repeated straining episodes?",
              help:"Time without urine increases risk.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", level:"yellow", style:"alt"}
              ],
              results:{
                yes:{
                  title:"High obstruction risk",
                  desc:"Emergency now (especially for cats).",
                  bullets:[
                    "Keep calm; transport immediately.",
                    "Bring a brief timeline (when last normal urination was).",
                    "Cats: this is a common emergency—don’t delay."
                  ]
                },
                no:{
                  title:"Needs same-day vet visit",
                  desc:"Call your vet today (same-day).",
                  bullets:[
                    "Watch urine output closely.",
                    "If output decreases or vomiting/lethargy begins → emergency.",
                    "Avoid stress; keep access to water."
                  ]
                }
              }
            }
          }
        },

        poison:{
          title:"Poison / toxin exposure",
          subtitle:(sp)=>`Chocolate, medications, plants, chemicals, essential oils, rodenticides—time matters.`,
          start:"p1",
          nodes:{
            p1:{
              q:"Did you witness ingestion OR strongly suspect exposure to a toxin/medication/chemical?",
              help:"If yes, treat as urgent. If unknown but signs are severe, also urgent.",
              answers:[
                {label:"Yes", value:"yes", next:"p2"},
                {label:"Not sure", value:"maybe", next:"p3", style:"alt"},
                {label:"No", value:"no", next:"p3", style:"alt"}
              ]
            },
            p2:{
              q:"Is your pet having seizures, collapse, severe breathing trouble, or uncontrolled vomiting?",
              help:"These are emergency signs after possible toxin exposure.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"p4", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Severe toxin signs",
                  desc:"Emergency now.",
                  bullets:[
                    "Bring packaging/label or a photo of it.",
                    "Do not induce vomiting unless a professional instructs you.",
                    "Transport immediately; keep calm."
                  ]
                }
              }
            },
            p3:{
              q:"Even without known exposure, are there severe signs (collapse, seizures, blue gums, severe lethargy)?",
              help:"Severe signs always escalate to emergency.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", level:"yellow", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Severe signs present",
                  desc:"Emergency now.",
                  bullets:[
                    "Transport immediately.",
                    "Bring timeline of symptoms.",
                    "If you later find a toxin source, bring packaging."
                  ]
                },
                no:{
                  title:"Possible exposure / mild signs",
                  desc:"Call your vet or a poison hotline today (urgent).",
                  bullets:[
                    "Gather details: what, how much, when, pet’s weight.",
                    "Do not give home remedies or human meds.",
                    "If symptoms worsen → emergency."
                  ]
                }
              }
            },
            p4:{
              q:"Was ingestion within the last 2 hours?",
              help:"Earlier intervention can be more effective.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", level:"yellow", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Urgent exposure window",
                  desc:"Call your vet/poison hotline immediately (same-day).",
                  bullets:[
                    "Have packaging/photos ready.",
                    "Do not induce vomiting unless instructed.",
                    "If severe signs start → emergency."
                  ]
                },
                no:{
                  title:"Still urgent",
                  desc:"Call your vet/poison hotline today for guidance.",
                  bullets:[
                    "Some toxins have delayed effects.",
                    "Monitor closely for new signs.",
                    "If severe signs appear → emergency."
                  ]
                }
              }
            }
          }
        },

        allergic:{
          title:"Allergic reaction",
          subtitle:(sp)=>`Hives, itching, facial swelling, vomiting, breathing changes.`,
          start:"a1",
          nodes:{
            a1:{
              q:"Is there difficulty breathing, collapse, or blue/gray gums/tongue?",
              help:"These can indicate anaphylaxis or severe airway compromise.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"a2", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Possible severe reaction",
                  desc:"Emergency now.",
                  bullets:[
                    "Transport immediately.",
                    "Keep calm; avoid exertion.",
                    "Bring any suspect food/medications (label/photo)."
                  ]
                }
              }
            },
            a2:{
              q:"Is there facial swelling (eyes/lips), widespread hives, or repeated vomiting after exposure?",
              help:"Moderate reactions need same-day guidance; swelling can worsen.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", next:"a3", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Moderate allergic reaction",
                  desc:"Call your vet today (same-day).",
                  bullets:[
                    "Monitor breathing closely for worsening.",
                    "If breathing changes or collapse occurs → emergency.",
                    "Avoid re-exposure to suspected trigger."
                  ]
                }
              }
            },
            a3:{
              q:"Is it mild itching with normal breathing and no swelling?",
              help:"Mild reactions can be monitored briefly, but they can progress.",
              answers:[
                {label:"Yes", value:"yes", level:"green"},
                {label:"No", value:"no", level:"yellow", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Mild reaction",
                  desc:"Monitor at home and reassess frequently.",
                  bullets:[
                    "If swelling, vomiting, or breathing changes develop → emergency/call vet.",
                    "Keep pet calm; avoid heat/exercise.",
                    "Consider vet advice if it persists."
                  ]
                },
                no:{
                  title:"Not clearly mild",
                  desc:"Call your vet today.",
                  bullets:[
                    "Reactions can escalate unexpectedly.",
                    "Watch for breathing changes.",
                    "If collapse/blue gums → emergency."
                  ]
                }
              }
            }
          }
        },

        heat:{
          title:"Heatstroke / overheating",
          subtitle:(sp)=>`Hot environment, heavy panting, weakness—time matters.`,
          start:"h1",
          nodes:{
            h1:{
              q:(sp)=> sp==='cat'
                ? "Is your cat open-mouth breathing, collapsing, or extremely weak after heat exposure?"
                : "Is your dog collapsing, unresponsive, or unable to stand after heat/exertion?",
              help:"Severe overheating can be life-threatening.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"h2", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Severe heat illness risk",
                  desc:"Emergency now.",
                  bullets:[
                    "Move to cool area immediately (AC).",
                    "Cool with room-temperature water (not ice-cold).",
                    "Transport to emergency vet now."
                  ]
                }
              }
            },
            h2:{
              q:"Is there extreme panting at rest, vomiting/diarrhea, or disorientation?",
              help:"These suggest significant heat stress.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"h3", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Significant heat stress",
                  desc:"Emergency now.",
                  bullets:[
                    "Start gentle cooling while preparing transport.",
                    "Do not force water if vomiting.",
                    "Keep pet calm and cool."
                  ]
                }
              }
            },
            h3:{
              q:"Mild overheating only (panting) and improves quickly within 10 minutes of cooling?",
              help:"If it resolves rapidly and pet returns to normal, monitoring may be reasonable.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", level:"red", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Still needs vet guidance",
                  desc:"Call your vet today—heat illness can have delayed effects.",
                  bullets:[
                    "Keep resting in a cool area.",
                    "Watch for vomiting, weakness, collapse.",
                    "If symptoms return → emergency."
                  ]
                },
                no:{
                  title:"Not improving quickly",
                  desc:"Emergency now.",
                  bullets:[
                    "Continue gentle cooling en route.",
                    "Avoid ice baths (can cause vasoconstriction/shock).",
                    "Transport immediately."
                  ]
                }
              }
            }
          }
        },

        eye:{
          title:"Eye emergency",
          subtitle:(sp)=>`Eye pain can worsen fast; early action protects vision.`,
          start:"e1",
          nodes:{
            e1:{
              q:"Is the eye bulging out, or is there a deep cut/penetrating injury?",
              help:"These are vision-threatening emergencies.",
              answers:[
                {label:"Yes", value:"yes", level:"red"},
                {label:"No", value:"no", next:"e2", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Vision-threatening injury",
                  desc:"Emergency now.",
                  bullets:[
                    "Prevent rubbing (cone/collar if available).",
                    "Do not apply human eye drops unless instructed.",
                    "Transport immediately."
                  ]
                }
              }
            },
            e2:{
              q:"Is your pet squinting/holding eye closed, with significant redness, swelling, or sudden cloudiness?",
              help:"These often need same-day treatment to prevent complications.",
              answers:[
                {label:"Yes", value:"yes", level:"yellow"},
                {label:"No", value:"no", next:"e3", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Likely painful eye condition",
                  desc:"Call your vet today (same-day).",
                  bullets:[
                    "Prevent rubbing; keep calm.",
                    "If discharge becomes thick/green or pain worsens → urgent visit.",
                    "If eye becomes suddenly blue/gray/cloudy → emergency sooner."
                  ]
                }
              }
            },
            e3:{
              q:"Mild irritation only (minor tearing) and pet is not squinting?",
              help:"Mild irritation can be monitored briefly, but eyes change quickly.",
              answers:[
                {label:"Yes", value:"yes", level:"green"},
                {label:"No", value:"no", level:"yellow", style:"alt"}
              ],
              results:{
                yes:{
                  title:"Monitor briefly",
                  desc:"Monitor at home for a short period.",
                  bullets:[
                    "If squinting/pain starts → call your vet today.",
                    "If swelling or cloudiness appears → urgent vet visit.",
                    "Prevent rubbing."
                  ]
                },
                no:{
                  title:"Not clearly mild",
                  desc:"Call your vet today.",
                  bullets:[
                    "Eye issues can worsen fast.",
                    "Prevent rubbing; keep calm.",
                    "If bulging/trauma suspected → emergency."
                  ]
                }
              }
            }
          }
        }
      };

      // ---- Wire up dashboard
      root.querySelectorAll('.dashbtn').forEach(btn=>{
        btn.addEventListener('click', ()=>{
          const flowKey = btn.getAttribute('data-flow');
          openFlow(flowKey);
        });
      });

      // ---- Species buttons
      document.getElementById('peh-sp-dog').addEventListener('click', ()=> setSpecies('dog'));
      document.getElementById('peh-sp-cat').addEventListener('click', ()=> setSpecies('cat'));

      // ---- Back / reset flow
      document.getElementById('peh-back').addEventListener('click', ()=>{
        currentFlowKey = null;
        currentNodeId = null;
        hidePanels();
        scrollToTop();
      });
      document.getElementById('peh-resetFlow').addEventListener('click', resetFlow);

      // ---- Reset all
      document.getElementById('peh-resetAll').addEventListener('click', ()=>{
        currentFlowKey = null;
        currentNodeId = null;
        hidePanels();
        scrollToTop();
      });

      // ---- Disclaimer
      document.getElementById('peh-openDisclaimer').addEventListener('click', ()=>{
        hidePanels();
        panelDisclaimer.classList.add('active');
        panelDisclaimer.scrollIntoView({behavior:'smooth', block:'start'});
      });
      document.getElementById('peh-closeDisclaimer').addEventListener('click', ()=>{
        panelDisclaimer.classList.remove('active');
        scrollToTop();
      });

      // Init
      hidePanels();
      setSpecies('dog');
    })();
  </script>
</div>