 if ($result) {
        $success_message = "Shipment added successfully!";
        
        // Generate receipt HTML to display
        $receipt_html = '
        <div class="receipt-container">
            <div class="receipt">
                <!-- Receipt Header -->
                <div class="receipt-header">
                    <i class="fas fa-truck logo"></i>
                    <h1>GoGlide Express</h1>
                    <p>Shipping Receipt | Track Your Package</p>
                </div>
                
                <!-- Receipt Body -->
                <div class="receipt-body">
                    <!-- Tracking Section -->
                    <div class="tracking-section">
                        <div>
                            <div class="tracking-info">
                                <i class="fas fa-barcode"></i>
                                <strong>Tracking Number:</strong> 
                                <span class="tracking-number">' . htmlspecialchars($tracking_number) . '</span>
                            </div>
                            <div class="date-info">Issued: ' . date('F j, Y') . '</div>
                            ' . (!empty($note) ? '<div class="note-info"><strong>Note:</strong> ' . htmlspecialchars($note) . '</div>' : '') . '
                        </div>
                        <div class="qr-placeholder"><i class="fas fa-shipping-fast fa-4x text-primary"></i></div>
                    </div>
                    
                    <!-- Shipment Details -->
                    <div class="details-grid">
                        <div class="detail-card">
                            <h4><i class="fas fa-user"></i> Sender</h4>
                            <p><strong>Name:</strong> ' . htmlspecialchars($sender_name) . '</p>
                            <p><strong>Origin:</strong> ' . htmlspecialchars($origin) . '</p>
                        </div>
                        <div class="detail-card">
                            <h4><i class="fas fa-map-marker-alt"></i> Receiver</h4>
                            <p><strong>Name:</strong> ' . htmlspecialchars($receiver_name) . '</p>
                            <p><strong>Destination:</strong> ' . htmlspecialchars($destination) . '</p>
                            <p><strong>Address:</strong> ' . htmlspecialchars($receiver_address) . '</p>
                        </div>
                    </div>
                    
                    <!-- Package Details -->
                    <table class="package-table">
                        <thead>
                            <tr>
                                <th><i class="fas fa-box"></i> Package Type</th>
                                <th><i class="fas fa-weight"></i> Weight</th>
                                <th><i class="fas fa-check-circle"></i> Status</th>
                                <th><i class="fas fa-calendar-alt"></i> Expected Delivery</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>' . htmlspecialchars($shipment_type) . '</td>
                                <td>' . htmlspecialchars($weight) . ' kg</td>
                                <td>' . htmlspecialchars($status) . '</td>
                                <td>' . htmlspecialchars($delivery_date) . '</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                
                <!-- Receipt Footer -->
                <div class="receipt-footer">
                    <p class="footer-services">Fast. Secure. Reliable. Worldwide.</p>
                    <p>Thank you for trusting GoGlide Express with your delivery needs.</p>
                    <div class="footer-links">
                        <a href="https://app.goglideexpress.com">app.goglideexpress.com</a> |
                        <a href="mailto:support@goglideexpress.com">support@goglideexpress.com</a> |
                        <a href="tel:+2348001234567">+234 800 123 4567</a>
                    </div>
                    <div class="footer-links" style="margin-top: 10px;">
                        <a href="#"><i class="fab fa-twitter"></i></a>
                        <a href="#"><i class="fab fa-instagram"></i></a>
                        <a href="#"><i class="fab fa-linkedin"></i></a>
                    </div>
                    <p class="terms">All shipments are subject to GoGlide Express Terms and Conditions. Visit our website for details.</p>
                </div>
            </div>
        </div>
        <style>
            :root {
                --primary: #1E90FF;
                --accent: #FF6B6B;
                --neutral: #F8FAFC;
                --dark: #2D3748;
                --gray: #6B7280;
                --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            }

            * {
                margin: 0;
                padding: 0;
                box-sizing: border-box;
                font-family: "Inter", sans-serif;
            }

            .receipt-container {
                margin: 40px auto;
                max-width: 900px;
                background: linear-gradient(135deg, #ffffff, var(--neutral));
                border-radius: 16px;
                overflow: hidden;
                box-shadow: var(--shadow);
            }

            .receipt-header {
                background: linear-gradient(90deg, var(--primary), #4682B4);
                color: white;
                padding: 30px;
                text-align: center;
                position: relative;
            }

            .receipt-header h1 {
                font-size: 28px;
                font-weight: 700;
                margin-bottom: 8px;
                letter-spacing: 1px;
            }

            .receipt-header p {
                font-size: 16px;
                opacity: 0.9;
            }

            .receipt-header .logo {
                position: absolute;
                top: 20px;
                left: 20px;
                font-size: 24px;
            }

            .receipt-body {
                padding: 30px;
                display: grid;
                gap: 20px;
            }

            .tracking-section {
                background: var(--neutral);
                padding: 20px;
                border-radius: 12px;
                display: flex;
                justify-content: space-between;
                align-items: center;
                border-left: 5px solid var(--primary);
                transition: transform 0.3s;
            }

            .tracking-section:hover {
                transform: translateY(-2px);
            }

            .tracking-info {
                display: flex;
                align-items: center;
                gap: 10px;
            }

            .tracking-info i {
                color: var(--primary);
                font-size: 20px;
            }

            .tracking-number {
                font-size: 20px;
                font-weight: 600;
                color: var(--primary);
            }

            .date-info {
                font-size: 14px;
                color: var(--gray);
            }

            .note-info {
                margin-top: 8px;
                font-size: 14px;
                color: var(--dark);
                padding: 8px;
                background-color: #f0f8ff;
                border-radius: 4px;
                border-left: 3px solid var(--primary);
            }

            .qr-placeholder {
                width: 80px;
                height: 80px;
                background: #e0e0e0 url("https://via.placeholder.com/80?text=QR") center/cover;
                border-radius: 8px;
            }

            .details-grid {
                display: grid;
                grid-template-columns: 1fr 1fr;
                gap: 20px;
            }

            .detail-card {
                background: white;
                padding: 20px;
                border-radius: 12px;
                box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
                transition: transform 0.3s;
            }

            .detail-card:hover {
                transform: translateY(-2px);
            }

            .detail-card h4 {
                font-size: 18px;
                color: var(--primary);
                margin-bottom: 12px;
                display: flex;
                align-items: center;
                gap: 8px;
            }

            .detail-card h4 i {
                color: var(--accent);
            }

            .detail-card p {
                font-size: 14px;
                color: var(--dark);
                margin: 8px 0;
                line-height: 1.5;
            }

            .package-table {
                width: 100%;
                border-collapse: collapse;
                background: white;
                border-radius: 12px;
                overflow: hidden;
                box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
            }

            .package-table th, .package-table td {
                padding: 15px;
                text-align: left;
                font-size: 14px;
            }

            .package-table th {
                background: var(--neutral);
                color: var(--gray);
                font-weight: 500;
            }

            .package-table td {
                border-top: 1px solid #e5e7eb;
                color: var(--dark);
            }

            .package-table i {
                margin-right: 8px;
                color: var(--primary);
            }

            .receipt-footer {
                background: var(--neutral);
                padding: 20px;
                text-align: center;
                border-top: 1px solid #e5e7eb;
                font-size: 14px;
                color: var(--gray);
            }

            .footer-links a {
                color: var(--primary);
                text-decoration: none;
                margin: 0 10px;
                transition: color 0.3s;
            }

            .footer-links a:hover {
                color: var(--accent);
            }

            .footer-services {
                margin: 10px 0;
                font-weight: 500;
                color: var(--dark);
            }

            .terms {
                font-size: 12px;
                margin-top: 10px;
                opacity: 0.8;
            }

            .download-section {
                text-align: center;
                margin: 30px 0;
            }

            .btn-download {
                background: var(--primary);
                color: white;
                padding: 12px 24px;
                border: none;
                border-radius: 8px;
                font-size: 16px;
                cursor: pointer;
                display: inline-flex;
                align-items: center;
                gap: 8px;
                transition: background 0.3s, transform 0.2s;
            }

            .btn-download:hover {
                background: #4682B4;
                transform: translateY(-2px);
            }

            @media (max-width: 768px) {
                .receipt-container {
                    margin: 20px;
                }

                .details-grid {
                    grid-template-columns: 1fr;
                }

                .tracking-section {
                    flex-direction: column;
                    align-items: flex-start;
                    gap: 15px;
                }

                .qr-placeholder {
                    margin-left: auto;
                }
            }

            @media print {
                .receipt-container {
                    box-shadow: none;
                    border: none;
                }

                .btn-download, .alert-success {
                    display: none;
                }

                .receipt-footer {
                    page-break-inside: avoid;
                }
            }
        </style>
        ';
        
        // Add external dependencies and JavaScript for downloading receipt as PNG
        echo '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">';
        echo '<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">';
        echo '<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>';
        echo '<script>
            function downloadReceipt() {
                const element = document.querySelector(".receipt");
                html2canvas(element, { scale: 2 }).then(canvas => {
                    const link = document.createElement("a");
                    link.download = "GoGlide_Receipt_' . htmlspecialchars($tracking_number) . '.png";
                    link.href = canvas.toDataURL("image/png");
                    link.click();
                }).catch(error => {
                    console.error("Error generating receipt image:", error);
                    alert("Failed to download receipt. Please try again.");
                });
            }
        </script>';
        
        // Display success message and receipt
        echo '<div class="alert alert-success">' . htmlspecialchars($success_message) . '</div>';
        echo $receipt_html;
        echo '<div class="download-section">
                <button onclick="downloadReceipt()" class="btn-download">
                    <i class="fas fa-download"></i> Download Receipt as PNG
                </button>
              </div>';
       