<?php include "../autoload.php"; ?>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&display=swap');
        .gradient-bg {
            background: linear-gradient(135deg, #1e40af 0%, #60a5fa 100%);
        }
        .result-card {
            background: linear-gradient(145deg, #ffffff, #f0f7ff);
            box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
            transition: transform 0.3s ease, opacity 0.3s ease;
        }
        .result-card.hidden {
            transform: translateY(20px);
            opacity: 0;
        }
        .result-card:not(.hidden) {
            transform: translateY(0);
            opacity: 1;
        }
        .input-container {
            background: linear-gradient(145deg, #ffffff, #f9fafb);
            transition: all 0.3s ease;
        }
        .input-container:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
        }
        .range-input::-webkit-slider-thumb {
            -webkit-appearance: none;
            appearance: none;
            width: 20px;
            height: 20px;
            background: #1e40af;
            border-radius: 50%;
            cursor: pointer;
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
        }
        .range-input::-moz-range-thumb {
            width: 20px;
            height: 20px;
            background: #1e40af;
            border-radius: 50%;
            cursor: pointer;
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
        }
        .btn-primary {
            transition: all 0.3s ease;
        }
        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
        }
        .visual-container {
            background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><rect fill="%23f3f4f6" width="100" height="100"/><circle cx="50" cy="50" r="30" fill="%23dbeafe" opacity="0.5"/></svg>') repeat;
            border-radius: 12px;
            box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.05);
        }
        select {
            appearance: none;
            background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24"><path fill="%234b5563" d="M7 10l5 5 5-5H7z"/></svg>');
            background-repeat: no-repeat;
            background-position: right 0.75rem center;
            background-size: 12px;
        }
    </style>

    <div class="x">
        <div class="x">
            <!-- Input Form -->
            <div class="mb-12">
                <h2 class="text-3xl font-semibold text-gray-800 mb-6">Enter Your Dining Table, Chairs & Area Details</h2>
                <p class="text-gray-500 mb-8 text-lg">Input dimensions to check if your dining table and chairs fit in your dining area.</p>
                <form id="diningTableFitForm" class="space-y-8">
                    <div class="grid grid-cols-1 md:grid-cols-4 gap-6">
                        <div class="space-y-3">
                            <label for="tableWidth" class="block text-sm font-medium text-gray-700">Table Width (ft)</label>
                            <div class="relative flex items-center">
                                <i data-lucide="table" class="absolute left-4 top-1/2 transform -translate-y-1/2 text-gray-400"></i>
                                <input type="number" id="tableWidth" class="pl-12 pr-4 py-3 block w-full rounded-lg border-gray-300 shadow-sm focus:border-blue-600 focus:ring focus:ring-blue-600 focus:ring-opacity-50 text-lg" placeholder="6.0" step="0.1" min="3" max="12" value="6.0" required>
                            </div>
                            <input type="range" id="tableWidthRange" class="range-input w-full h-2 bg-gray-200 rounded-lg cursor-pointer" min="3" max="12" step="0.1" value="6">
                            <p id="tableWidthValue" class="text-sm text-gray-500">6.0 ft</p>
                        </div>
                        <div class="space-y-3">
                            <label for="tableDepth" class="block text-sm font-medium text-gray-700">Table Depth (ft)</label>
                            <div class="relative flex items-center">
                                <i data-lucide="expand" class="absolute left-4 top-1/2 transform -translate-y-1/2 text-gray-400"></i>
                                <input type="number" id="tableDepth" class="pl-12 pr-4 py-3 block w-full rounded-lg border-gray-300 shadow-sm focus:border-blue-600 focus:ring focus:ring-blue-600 focus:ring-opacity-50 text-lg" placeholder="4.0" step="0.1" min="2" max="8" value="4.0" required>
                            </div>
                            <input type="range" id="tableDepthRange" class="range-input w-full h-2 bg-gray-200 rounded-lg cursor-pointer" min="2" max="8" step="0.1" value="4">
                            <p id="tableDepthValue" class="text-sm text-gray-500">4.0 ft</p>
                        </div>
                        <div class="space-y-3">
                            <label for="chairWidth" class="block text-sm font-medium text-gray-700">Chair Width (ft)</label>
                            <div class="relative flex items-center">
                                <i data-lucide="armchair" class="absolute left-4 top-1/2 transform -translate-y-1/2 text-gray-400"></i>
                                <input type="number" id="chairWidth" class="pl-12 pr-4 py-3 block w-full rounded-lg border-gray-300 shadow-sm focus:border-blue-600 focus:ring focus:ring-blue-600 focus:ring-opacity-50 text-lg" placeholder="2.0" step="0.1" min="1.5" max="3" value="2.0" required>
                            </div>
                            <input type="range" id="chairWidthRange" class="range-input w-full h-2 bg-gray-200 rounded-lg cursor-pointer" min="1.5" max="3" step="0.1" value="2">
                            <p id="chairWidthValue" class="text-sm text-gray-500">2.0 ft</p>
                        </div>
                        <div class="space-y-3">
                            <label for="chairCount" class="block text-sm font-medium text-gray-700">Number of Chairs</label>
                            <div class="relative flex items-center">
                                <i data-lucide="users" class="absolute left-4 top-1/2 transform -translate-y-1/2 text-gray-400"></i>
                                <input type="number" id="chairCount" class="pl-12 pr-4 py-3 block w-full rounded-lg border-gray-300 shadow-sm focus:border-blue-600 focus:ring focus:ring-blue-600 focus:ring-opacity-50 text-lg" placeholder="6" min="2" max="12" value="6" required>
                            </div>
                        </div>
                    </div>
                    <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                        <div class="space-y-3">
                            <label for="areaWidth" class="block text-sm font-medium text-gray-700">Dining Area Width (ft)</label>
                            <div class="relative flex items-center">
                                <i data-lucide="ruler" class="absolute left-4 top-1/2 transform -translate-y-1/2 text-gray-400"></i>
                                <input type="number" id="areaWidth" class="pl-12 pr-4 py-3 block w-full rounded-lg border-gray-300 shadow-sm focus:border-blue-600 focus:ring focus:ring-blue-600 focus:ring-opacity-50 text-lg" placeholder="12.0" step="0.1" min="8" max="20" value="12.0" required>
                            </div>
                            <input type="range" id="areaWidthRange" class="range-input w-full h-2 bg-gray-200 rounded-lg cursor-pointer" min="8" max="20" step="0.1" value="12">
                            <p id="areaWidthValue" class="text-sm text-gray-500">12.0 ft</p>
                        </div>
                        <div class="space-y-3">
                            <label for="areaDepth" class="block text-sm font-medium text-gray-700">Dining Area Depth (ft)</label>
                            <div class="relative flex items-center">
                                <i data-lucide="expand" class="absolute left-4 top-1/2 transform -translate-y-1/2 text-gray-400"></i>
                                <input type="number" id="areaDepth" class="pl-12 pr-4 py-3 block w-full rounded-lg border-gray-300 shadow-sm focus:border-blue-600 focus:ring focus:ring-blue-600 focus:ring-opacity-50 text-lg" placeholder="10.0" step="0.1" min="6" max="20" value="10.0" required>
                            </div>
                            <input type="range" id="areaDepthRange" class="range-input w-full h-2 bg-gray-200 rounded-lg cursor-pointer" min="6" max="20" step="0.1" value="10">
                            <p id="areaDepthValue" class="text-sm text-gray-500">10.0 ft</p>
                        </div>
                        <div class="space-y-3">
                            <label for="walkingSpace" class="block text-sm font-medium text-gray-700">Desired Walking Space (ft)</label>
                            <div class="relative flex items-center">
                                <i data-lucide="footprints" class="absolute left-4 top-1/2 transform -translate-y-1/2 text-gray-400"></i>
                                <input type="number" id="walkingSpace" class="pl-12 pr-4 py-3 block w-full rounded-lg border-gray-300 shadow-sm focus:border-blue-600 focus:ring focus:ring-blue-600 focus:ring-opacity-50 text-lg" placeholder="3.0" step="0.1" min="2" max="5" value="3.0" required>
                            </div>
                            <input type="range" id="walkingSpaceRange" class="range-input w-full h-2 bg-gray-200 rounded-lg cursor-pointer" min="2" max="5" step="0.1" value="3">
                            <p id="walkingSpaceValue" class="text-sm text-gray-500">3.0 ft</p>
                        </div>
                    </div>
                    <button type="submit" class="btn-primary w-full bg-blue-600 text-white py-4 px-8 rounded-xl hover:bg-blue-700 flex items-center justify-center text-lg">
                        <i data-lucide="search" class="mr-3 h-5 w-5"></i>
                        Check Dining Table Fit
                    </button>
                </form>
            </div>

            <!-- Result Section -->
            <div id="resultSection" class="result-card rounded-2xl p-10 hidden">
                <h2 class="text-3xl font-semibold text-gray-800 mb-6 flex items-center">
                    <i data-lucide="check-circle-2" class="mr-3 text-green-500 h-7 w-7"></i>
                    Your Dining Table Fit Assessment
                </h2>
                <div id="resultOutput" class="text-gray-700 space-y-6 text-base">
                    <!-- Results will be dynamically inserted here -->
                </div>
                <div class="mt-10 flex flex-col md:flex-row justify-between items-center gap-6">
                    <div class="flex items-center text-blue-600">
                        <i data-lucide="info" class="mr-2 h-5 w-5"></i>
                        <p class="text-sm font-medium">Based on interior design and furniture layout standards.</p>
                    </div>
                    <button id="downloadPdf" class="btn-primary bg-green-600 text-white py-3 px-8 rounded-xl hover:bg-green-700 flex items-center text-base">
                        <i data-lucide="download" class="mr-2 h-5 w-5"></i>
                        Download PDF Report
                    </button>
                </div>
                <!-- Visual Representation -->
                <div class="mt-10 visual-container p-8">
                    <h3 class="text-xl font-medium text-gray-800 mb-4 flex items-center">
                        <i data-lucide="table" class="mr-3 text-blue-500 h-6 w-6"></i>
                        Interactive Dining Table & Area Visualization
                    </h3>
                    <div class="relative w-full h-96 bg-gray-200 rounded-xl overflow-hidden shadow-lg">
                        <canvas id="diningCanvas" class="w-full h-full"></canvas>
                    </div>
                    <p class="text-sm text-gray-600 mt-4">Visualization showing the dining table, chairs, and walking space scaled to the dining area.</p>
                </div>
                <!-- Expert Insights -->
                <div class="mt-10 bg-blue-50 p-8 rounded-xl shadow-sm">
                    <h3 class="text-xl font-medium text-gray-800 mb-4 flex items-center">
                        <i data-lucide="lightbulb" class="mr-3 text-yellow-500 h-6 w-6"></i>
                        Expert Insights for Dining Area Layout
                    </h3>
                    <ul class="list-none space-y-4 text-gray-700 text-sm">
                        <li class="flex items-start">
                            <i data-lucide="check" class="mr-2 text-green-500 h-5 w-5"></i>
                            <span><strong>Clearance:</strong> Allow 3 ft around the table for comfortable chair access and movement.</span>
                        </li>
                        <li class="flex items-start">
                            <i data-lucide="check" class="mr-2 text-green-500 h-5 w-5"></i>
                            <span><strong>Chair Spacing:</strong> Place chairs 2 ft apart for comfort; adjust based on table size.</span>
                        </li>
                        <li class="flex items-start">
                            <i data-lucide="check" class="mr-2 text-green-500 h-5 w-5"></i>
                            <span><strong>Room Shape:</strong> Ensure table shape complements room layout (rectangular for long rooms, round for square).</span>
                        </li>
                        <li class="flex items-start">
                            <i data-lucide="check" class="mr-2 text-green-500 h-5 w-5"></i>
                            <span><strong>Lighting:</strong> Center table under lighting fixtures for optimal ambiance.</span>
                        </li>
                        <li class="flex items-start">
                            <i data-lucide="check" class="mr-2 text-green-500 h-5 w-5"></i>
                            <span><strong>Traffic Flow:</strong> Maintain clear pathways to avoid obstructing room access.</span>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>

    <script>
        // Initialize Lucid Icons
        lucide.createIcons();

        // Sync range and number inputs
        function syncInputs(numberId, rangeId, valueId, unit = 'ft') {
            const numberInput = document.getElementById(numberId);
            const rangeInput = document.getElementById(rangeId);
            const valueDisplay = document.getElementById(valueId);

            numberInput.addEventListener('input', () => {
                rangeInput.value = numberInput.value;
                valueDisplay.textContent = `${parseFloat(numberInput.value).toFixed(1)} ${unit}`;
            });
            rangeInput.addEventListener('input', () => {
                numberInput.value = rangeInput.value;
                valueDisplay.textContent = `${parseFloat(rangeInput.value).toFixed(1)} ${unit}`;
            });
        }

        syncInputs('tableWidth', 'tableWidthRange', 'tableWidthValue');
        syncInputs('tableDepth', 'tableDepthRange', 'tableDepthValue');
        syncInputs('chairWidth', 'chairWidthRange', 'chairWidthValue');
        syncInputs('areaWidth', 'areaWidthRange', 'areaWidthValue');
        syncInputs('areaDepth', 'areaDepthRange', 'areaDepthValue');
        syncInputs('walkingSpace', 'walkingSpaceRange', 'walkingSpaceValue');

        // Form Submission
        document.getElementById('diningTableFitForm').addEventListener('submit', function (e) {
            e.preventDefault();
            calculateDiningTableFit();
        });

        function calculateDiningTableFit() {
            const tableWidth = parseFloat(document.getElementById('tableWidth').value);
            const tableDepth = parseFloat(document.getElementById('tableDepth').value);
            const chairWidth = parseFloat(document.getElementById('chairWidth').value);
            const chairCount = parseInt(document.getElementById('chairCount').value);
            const areaWidth = parseFloat(document.getElementById('areaWidth').value);
            const areaDepth = parseFloat(document.getElementById('areaDepth').value);
            const walkingSpace = parseFloat(document.getElementById('walkingSpace').value);

            if (!tableWidth || !tableDepth || !chairWidth || !chairCount || !areaWidth || !areaDepth || !walkingSpace ||
                tableWidth < 3 || tableDepth < 2 || chairWidth < 1.5 || chairCount < 2 || areaWidth < 8 || areaDepth < 6 || walkingSpace < 2) {
                alert('Please enter valid values (Table Width ≥ 3 ft, Depth ≥ 2 ft, Chair Width ≥ 1.5 ft, Chair Count ≥ 2, Area Width ≥ 8 ft, Depth ≥ 6 ft, Walking Space ≥ 2 ft).');
                return;
            }

            // Calculate space needed: table + chairs (2 ft depth for each chair) + walking space
            const chairsPerSide = Math.floor(chairCount / 4); // 2 sides for width, 2 for depth
            const totalWidth = tableWidth + (chairWidth * 2) + (walkingSpace * 2); // Chairs on both sides + walking space
            const totalDepth = tableDepth + (2 * 2) + (walkingSpace * 2); // 2 ft chair depth + walking space

            // Check fit
            const widthFit = areaWidth >= totalWidth;
            const depthFit = areaDepth >= totalDepth;
            const overallFit = widthFit && depthFit ? 'Yes' : 'No';

            // Calculate clearances
            const widthClearance = areaWidth - totalWidth;
            const depthClearance = areaDepth - totalDepth;

            // Generate output
            const output = `
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6 bg-white p-6 rounded-xl shadow-sm">
                    <div>
                        <p class="font-medium text-gray-700">Table Dimensions</p>
                        <p class="text-xl text-blue-600 font-semibold">${tableWidth.toFixed(1)} x ${tableDepth.toFixed(1)} ft</p>
                    </div>
                    <div>
                        <p class="font-medium text-gray-700">Chair Details</p>
                        <p class="text-lg">${chairWidth.toFixed(1)} ft width, ${chairCount} chairs</p>
                    </div>
                    <div>
                        <p class="font-medium text-gray-700">Dining Area Dimensions</p>
                        <p class="text-lg">${areaWidth.toFixed(1)} x ${areaDepth.toFixed(1)} ft</p>
                    </div>
                    <div>
                        <p class="font-medium text-gray-700">Walking Space</p>
                        <p class="text-lg">${walkingSpace.toFixed(1)} ft</p>
                    </div>
                    <div>
                        <p class="font-medium text-gray-700">Fit Assessment</p>
                        <p class="text-lg ${overallFit === 'Yes' ? 'text-green-600' : 'text-red-600'} font-semibold">
                            ${overallFit === 'Yes' ? 'Perfect Fit' : 'May Not Fit Comfortably'}
                        </p>
                        <p class="text-sm text-gray-600">${
                            overallFit === 'Yes' 
                                ? `The table and chairs fit with ${widthClearance.toFixed(1)} ft width clearance and ${depthClearance.toFixed(1)} ft depth clearance.`
                                : `Issues: ${
                                    !widthFit ? `Insufficient width clearance (need ≥${totalWidth.toFixed(1)} ft, have ${areaWidth.toFixed(1)} ft). ` : ''
                                }${
                                    !depthFit ? `Insufficient depth clearance (need ≥${totalDepth.toFixed(1)} ft, have ${areaDepth.toFixed(1)} ft). ` : ''
                                }`
                        }</p>
                    </div>
                </div>
                <div class="bg-blue-50 p-4 rounded-lg">
                    <p class="text-sm"><span class="font-medium">Tip:</span> Measure your dining area carefully, accounting for doorways and other furniture.</p>
                </div>
            `;

            document.getElementById('resultOutput').innerHTML = output;
            document.getElementById('resultSection').classList.remove('hidden');

            // Draw visualization
            drawVisualization(tableWidth, tableDepth, chairWidth, chairCount, areaWidth, areaDepth, walkingSpace);

            // Setup PDF download
            setupPdfDownload(tableWidth, tableDepth, chairWidth, chairCount, areaWidth, areaDepth, walkingSpace, overallFit, widthClearance, depthClearance);
        }

        function drawVisualization(tableWidth, tableDepth, chairWidth, chairCount, areaWidth, areaDepth, walkingSpace) {
            const canvas = document.getElementById('diningCanvas');
            const ctx = canvas.getContext('2d');
            canvas.width = canvas.offsetWidth;
            canvas.height = canvas.offsetHeight;

            // Clear canvas
            ctx.clearRect(0, 0, canvas.width, canvas.height);

            // Scale factors
            const scale = canvas.width / (areaWidth * 1.5); // Scale to fit canvas
            const tableW = tableWidth * scale;
            const tableH = tableDepth * scale;
            const chairW = chairWidth * scale;
            const chairH = 2 * scale; // Standard chair depth
            const areaW = areaWidth * scale;
            const areaH = areaDepth * scale;
            const walkW = walkingSpace * scale;

            // Draw background
            const gradient = ctx.createLinearGradient(0, 0, 0, canvas.height);
            gradient.addColorStop(0, '#e5e7eb');
            gradient.addColorStop(1, '#d1d5db');
            ctx.fillStyle = gradient;
            ctx.fillRect(0, 0, canvas.width, canvas.height);

            // Draw floor
            ctx.fillStyle = 'rgba(120, 113, 108, 0.2)';
            ctx.fillRect(0, canvas.height * 0.7, canvas.width, canvas.height * 0.3);

            // Draw dining area outline (dashed)
            ctx.strokeStyle = '#1e40af';
            ctx.lineWidth = 2;
            ctx.setLineDash([5, 5]);
            ctx.strokeRect(canvas.width * 0.55, canvas.height * 0.2, areaW, areaH);
            ctx.fillStyle = '#bfdbfe';
            ctx.globalAlpha = 0.3;
            ctx.fillRect(canvas.width * 0.55, canvas.height * 0.2, areaW, areaH);
            ctx.globalAlpha = 1.0;
            ctx.setLineDash([]);

            // Draw table with realistic effects
            ctx.shadowColor = 'rgba(0, 0, 0, 0.4)';
            ctx.shadowBlur = 15;
            ctx.shadowOffsetX = 8;
            ctx.shadowOffsetY = 8;
            ctx.fillStyle = '#4b5563';
            const tableX = canvas.width * 0.15 + walkW;
            const tableY = canvas.height * 0.3 + walkW;
            ctx.fillRect(tableX, tableY, tableW, tableH);

            // Draw table texture
            const tableGradient = ctx.createLinearGradient(tableX, tableY, tableX + tableW, tableY + tableH);
            tableGradient.addColorStop(0, 'rgba(255, 255, 255, 0.15)');
            tableGradient.addColorStop(1, 'rgba(255, 255, 255, 0.05)');
            ctx.fillStyle = tableGradient;
            ctx.fillRect(tableX + 5, tableY + 5, tableW - 10, tableH - 10);

            // Draw chairs (simplified, 2 per side for visualization)
            ctx.fillStyle = '#2d3748';
            const chairsPerSide = Math.floor(chairCount / 4);
            const chairSpacing = tableW / (chairsPerSide + 1);
            for (let i = 0; i < chairsPerSide; i++) {
                // Top side
                ctx.fillRect(tableX + (i + 1) * chairSpacing - chairW / 2, tableY - chairH, chairW, chairH);
                // Bottom side
                ctx.fillRect(tableX + (i + 1) * chairSpacing - chairW / 2, tableY + tableH, chairW, chairH);
            }
            for (let i = 0; i < chairsPerSide; i++) {
                // Left side
                ctx.fillRect(tableX - chairH, tableY + (i + 1) * (tableH / (chairsPerSide + 1)) - chairW / 2, chairH, chairW);
                // Right side
                ctx.fillRect(tableX + tableW, tableY + (i + 1) * (tableH / (chairsPerSide + 1)) - chairW / 2, chairH, chairW);
            }

            // Draw text
            ctx.shadowColor = 'transparent';
            ctx.fillStyle = '#ffffff';
            ctx.font = 'bold 18px Poppins';
            ctx.textAlign = 'center';
            ctx.fillText(`Table (${tableWidth.toFixed(1)} x ${tableDepth.toFixed(1)} ft)`, tableX + tableW / 2, tableY + tableH / 2);
            ctx.fillStyle = '#1e40af';
            ctx.fillText(`Dining Area (${areaWidth.toFixed(1)} x ${areaDepth.toFixed(1)} ft)`, canvas.width * 0.55 + areaW / 2, canvas.height * 0.2 + areaH / 2);
            ctx.font = '14px Poppins';
            ctx.fillStyle = '#4b5563';
            ctx.fillText(`Table & Chairs vs. Dining Area`, canvas.width / 2, canvas.height - 30);
        }

        function setupPdfDownload(tableWidth, tableDepth, chairWidth, chairCount, areaWidth, areaDepth, walkingSpace, overallFit, widthClearance, depthClearance) {
            document.getElementById('downloadPdf').onclick = function () {
                const { jsPDF } = window.jspdf;
                const doc = new jsPDF();

                // Header
                doc.setFont('helvetica', 'bold');
                doc.setFontSize(20);
                doc.setTextColor(31, 64, 175);
                doc.text('HomeFit Tools - Dining Table Fit Assessment Report', 20, 20);

                doc.setFont('helvetica', 'normal');
                doc.setFontSize(10);
                doc.setTextColor(100, 100, 100);
                doc.text(`Generated on: ${new Date().toLocaleString()}`, 20, 28);

                // Results
                doc.setFontSize(14);
                doc.setTextColor(0, 0, 0);
                doc.text('Your Dining Table Fit Assessment', 20, 40);

                doc.setFontSize(11);
                doc.text(`Table Dimensions: ${tableWidth.toFixed(1)} x ${tableDepth.toFixed(1)} ft`, 20, 50);
                doc.text(`Chair Details: ${chairWidth.toFixed(1)} ft width, ${chairCount} chairs`, 20, 58);
                doc.text(`Dining Area Dimensions: ${areaWidth.toFixed(1)} x ${areaDepth.toFixed(1)} ft`, 20, 66);
                doc.text(`Walking Space: ${walkingSpace.toFixed(1)} ft`, 20, 74);
                doc.text(`Fit Assessment: ${overallFit === 'Yes' ? 'Perfect Fit' : 'May Not Fit Comfortably'}`, 20, 82);
                doc.text(`Clearances: ${widthClearance.toFixed(1)} ft (width), ${depthClearance.toFixed(1)} ft (depth)`, 20, 90);
                doc.text(`Recommendation: ${
                    overallFit === 'Yes' 
                        ? 'The dining table and chairs fit well in your dining area.' 
                        : 'Consider a smaller table or fewer chairs.'
                }`, 20, 98);

                // Expert Insights
                doc.setFont('helvetica', 'bold');
                doc.setFontSize(12);
                doc.text('Expert Insights', 20, 110);
                doc.setFont('helvetica', 'normal');
                doc.setFontSize(10);
                doc.text('• Clearance: Allow 3 ft around the table for chair access.', 20, 118);
                doc.text('• Chair Spacing: Place chairs 2 ft apart for comfort.', 20, 126);
                doc.text('• Room Shape: Match table shape to room layout.', 20, 134);
                doc.text('• Lighting: Center table under lighting fixtures.', 20, 142);
                doc.text('• Traffic Flow: Maintain clear pathways for access.', 20, 150);

                doc.save('HomeFit_Dining_Table_Fit_Assessment.pdf');
            };
        }
    </script>