`;
});
const resultsHTML = `
`;
resultsContainer.innerHTML = resultsHTML;
resultsContainer.classList.remove('hidden');
document.getElementById('download-pdf-btn').addEventListener('click', downloadPdf);
resultsContainer.scrollIntoView({ behavior: 'smooth' });
}
function downloadPdf() {
if (!planResults) return;
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
// Header
doc.setFontSize(22);
doc.setFont('helvetica', 'bold');
doc.text('Holistic Body Detox & Cleansing Guide', 105, 20, { align: 'center' });
doc.setFontSize(16);
doc.text(`Your Goal: ${planResults.title.replace(' Plan', '')}`, 105, 28, { align: 'center' });
// Table of Plan
const tableData = planResults.days.map(day => [day.day, day.focus, day.plan.join('\n')]);
doc.autoTable({
startY: 40,
head: [['Day', 'Focus', 'Action Steps']],
body: tableData,
theme: 'grid',
headStyles: { fillColor: [16, 185, 129] }, // emerald-500
columnStyles: { 2: { cellWidth: 90 } }
});
let finalY = doc.autoTable.previous.finalY;
// Disclaimer
if (finalY > 240) { doc.addPage(); finalY = 20; }
doc.setFontSize(12);
doc.setFont('helvetica', 'bold');
doc.setTextColor(239, 68, 68); // Red
doc.text('Important Medical Disclaimer', 14, finalY + 15);
doc.setFontSize(10);
doc.setTextColor(0, 0, 0); // Black
const disclaimerText = doc.splitTextToSize("This guide provides general wellness suggestions and is NOT a medical detox protocol. Always consult a qualified healthcare professional before making significant dietary changes.", 180);
doc.text(disclaimerText, 14, finalY + 22);
doc.save(`Detox-Plan-${planResults.title.replace(' ', '-')}.pdf`);
}
// --- EVENT LISTENERS ---
generateBtn.addEventListener('click', generatePlan);
});
Your 7-Day Gentle Detox Plan
Goal: ${planResults.title.replace(' Plan', '')}
${daysHTML}
