<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>CarBaBa</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    </head>
   
    <body style="margin:0;padding:20px;font-family:Arial,Helvetica,sans-serif;color:#000000;background:#fff;">
    <?php
        $vehicleMot = isset($lead) && !empty($lead->vehicle_mot_data_json) ? json_decode($lead->vehicle_mot_data_json, true) : [];
        $roadTaxMot = isset($lead) && !empty($lead->mot_taxed_json) ? json_decode($lead->mot_taxed_json, true) : [];
        $vehicleData = $vehicleMot['vehicleData'] ?? [];
        $vehicleInformation = $vehicleMot['vehicleInformation'] ?? [];
        $motMileageSummary = $vehicleMot['motMileageSummary'] ?? [];
        $motTestList = $vehicleMot['motTestList'] ?? [];
        $vehicleTaxCo2Emissions = $vehicleMot['vehicleTaxCo2Emissions'] ?? [];
        $general = $vehicleMot['general'] ?? [];
        $consumption = $vehicleMot['consumption'] ?? [];
        $performance = $vehicleMot['performance'] ?? [];
        $dimensions = $vehicleMot['dimensions'] ?? [];
        $safety = $vehicleMot['safety'] ?? [];
        $importExport = $vehicleMot['importExport'] ?? [];
        $classificationDetails = $vehicleMot['classificationDetails'] ?? [];
        $smmtDetails = $vehicleMot['smmtDetails'] ?? [];
        $colourChange = $vehicleMot['colourChange'] ?? [];
        $scrapDestruction = $vehicleMot['scrapDestruction'] ?? [];
        $V5CCertificates = $vehicleMot['V5CCertificates'] ?? [];
        // dd(asset('backend/assets/images/carbaba-logo.png'));
    ?>
        <table cellpadding="0" cellspacing="0" border="0" style="width:100%;margin:0;border-collapse:collapse;font-family:Arial,Helvetica,sans-serif;">
            <tr>
                <td align="center" style="text-align: center;padding: 10px 0 20px;">
                    <img src="{{ asset('backend/assets/images/carbaba-logo.png') }}" alt="carbaba-logo" border="0" width="230" height="33" />
                </td>
            </tr>

            <tr>
                <td style="border-bottom: 2px solid #efebeb;padding-bottom: 20px;">
                    <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;font-family:Arial,Helvetica,sans-serif;">
                        <tr>
                            <td>
                                <table cellpadding="0" cellspacing="0" border="0" style="width: 130px; border-collapse:separate;border: 1px solid #f8ef16; font-family:Arial,Helvetica,sans-serif;border-radius: 5px;background-color: #f8ef16;">
                                    <tr>
                                        <td style="width: 20px;"><img src="{{ asset('backend/assets/images/enter-reg.png') }}" alt="enter-reg" border="0" width="20" height="40" style="display: block;"></td>
                                        <td style="padding:0 5px; text-align: center;font-weight: bold;"><?= $vehicleInformation['Vrm']?? "***" ?></td>
                                    </tr>
                                </table>
                            </td>
                            <td style="color: #000000;font-size: 16px;text-align: right;font-weight: bold;">
                                Report created on  <?= date('d/M/Y').' at '.date('h:i:s') ?>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>

            <tr>
                <td align="center" style="text-align: center;font-size: 26px;color: #716d6a;padding: 20px 0;font-family:Arial,Helvetica,sans-serif;">
                    <strong>YOUR VEHICLE DATA</strong>
                </td>
            </tr>
            <!-- SECTION 1: Vehicle Data -->
            @php
       function renderStatusCard($label, $status = null, $customValue = null, $dates = null) {
    // ✅ Default green check
    $borderColor = '#4CAF50';
    $icon = asset('backend/assets/images/checkIcon.png');
    $valueHtml = '<img src="'.$icon.'" width="26" height="26" style="display:block;" alt="check"/>';

    // Boolean-like status
    if ($status === true) {
        $borderColor = '#F44336';
        $icon = asset('backend/assets/images/closeIcon.png');
        $valueHtml = '<img src="'.$icon.'" width="26" height="26" style="display:block;" alt="close"/>';
    } elseif ($status === false) {
        $borderColor = '#4CAF50';
        $icon = asset('backend/assets/images/checkIcon.png');
        $valueHtml = '<img src="'.$icon.'" width="26" height="26" style="display:block;" alt="check"/>';
    }

    // ✅ Special case: Taxi
    if ($label === 'Taxi') {
        if ($status === true) {
            $borderColor = '#F44336';
            $icon = asset('backend/assets/images/closeIcon.png');
            $valueHtml = '<img src="'.$icon.'" width="26" height="26" style="display:block;" alt="close"/>';
        } elseif ($status === false) {
            $borderColor = '#4CAF50';
            $icon = asset('backend/assets/images/checkIcon.png');
            $valueHtml = '<img src="'.$icon.'" width="26" height="26" style="display:block;" alt="check"/>';
        } else {
            // null → blank/placeholder
            $borderColor = '#4CAF50';
            $valueHtml = '<span style="color:#999;font-size:18px;">***</span>';
        }
    }

    // ✅ Special case: Mileage
    if ($label === 'Mileage') {

        if (!empty($status)) {
            // Mileage exists → red ❌ icon
            $borderColor = '#F44336';
            $icon = asset('backend/assets/images/closeIcon.png');
            $valueHtml = '<img src="'.$icon.'" width="26" height="26" style="display:block;" alt="close"/>';
        } else {
            // Mileage empty → green ✅ icon
            $borderColor = '#4CAF50';
            $icon = asset('backend/assets/images/checkIcon.png');
            $valueHtml = '<img src="'.$icon.'" width="26" height="26" style="display:block;" alt="check"/>';
        }
    }


    if ($label === 'Plate Change') {

        if (!empty($status)) {
            // Mileage exists → red ❌ icon
            $borderColor = '#f49320';
            $icon = asset('backend/assets/images/alertIcon.png');
            $valueHtml = '<img src="'.$icon.'" width="26" height="26" style="display:block;" alt="close"/>';
        } else {
            // Mileage empty → green ✅ icon
            $borderColor = '#4CAF50';
            $icon = asset('backend/assets/images/checkIcon.png');
            $valueHtml = '<img src="'.$icon.'" width="26" height="26" style="display:block;" alt="check"/>';
        }
    }

    // ✅ Special case: Keepers count
    if ($customValue !== null) {
        if ($label === 'Keepers') {
            $keepers = (int) $customValue;
            if ($keepers <= 3) {
                $borderColor = '#4CAF50';
            } elseif ($keepers <= 6) {
                $borderColor = '#FF9800';
            } else {
                $borderColor = '#F44336';
            }
        }

        return '
            <td style="padding-right: 10px;width:20%;box-sizing:border-box;vertical-align:top;">
                <table cellpadding="0" cellspacing="0" border="0" 
                    style="width:100%;border-collapse:separate;border:2px solid '.$borderColor.';border-radius:12px;">
                    <tr>
                        <td style="padding:8px;box-sizing:border-box;">
                            <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;">
                                <tr>
                                    <td style="color:#000;font-size:14px;"><strong>'.$label.'</strong></td>
                                    <td style="font-size: 19px;width:25px;text-align:right;font-weight:bold;">'.$customValue.'</td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>';
    }

    // ✅ Dates list (Keepers history)
    if ($dates !== null && is_array($dates)) {
        $count = count($dates);
        $borderColor = $count <= 3 ? '#4CAF50' : ($count <= 6 ? '#FF9800' : '#F44336');

        $datesHtml = '';
        foreach ($dates as $index => $d) {
            $dateFormatted = !empty($d['date']) ? date('d-M-y', strtotime($d['date'])) : '';
            $padding = $index > 0 ? 'padding-top:7px;' : '';
            $datesHtml .= '<div style="'.$padding.'"><strong style="color:#f49320">'.$dateFormatted.'</strong></div>';
        }

        return '
            <td style="padding-right: 0;width:20%;box-sizing:border-box;vertical-align:top;">
                <table cellpadding="0" cellspacing="0" border="0" 
                    style="width:100%;border-collapse:separate;border:2px solid '.$borderColor.';border-radius:12px;">
                    <tr>
                        <td style="padding:8px;box-sizing:border-box;" align="top" valign="top">
                            <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;">
                                <tr>
                                    <td style="color:#000;font-size:14px;vertical-align:top;"><strong>'.$label.'</strong></td>
                                    <td style="width:70px;color:#f49320;font-size:14px;text-align:right;vertical-align:top;">
                                        '.$datesHtml.'
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>';
    }

    // ✅ Default card (with icon)
    return '<td style="padding-right:10px;width:20%;box-sizing:border-box;vertical-align:top;">
            <table cellpadding="0" cellspacing="0" border="0" 
                style="width:100%;border-collapse:separate;border:2px solid '.$borderColor.';border-radius:12px;">
                <tr>
                    <td style="padding:8px;box-sizing:border-box;">
                        <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;">
                            <tr>
                                <td style="color:#000;font-size:14px;"><strong>'.$label.'</strong></td>
                                <td style="width:26px;text-align:right;">'.$valueHtml.'</td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </td>';
}




            @endphp

            <tr>
                <td style="padding-bottom: 20px;">
                    <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;font-family:Arial,Helvetica,sans-serif;">
                        <tr>
                            {!! renderStatusCard('Scrapped', $vehicleInformation['Scrapped'] ?? null) !!}
                            {!! renderStatusCard('Exported', $vehicleInformation['Exported'] ?? null) !!}
                            {!! renderStatusCard('Imported', $vehicleInformation['Imported'] ?? null) !!}
                            {!! renderStatusCard('Plate Change', $vehicleData['plateChange'] ?? null) !!}
                            {!! renderStatusCard('Colour Change', $vehicleData['colourChange'] ?? null) !!}
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td style="padding-bottom: 20px;">
                    <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;font-family:Arial,Helvetica,sans-serif;">
                        <tr>
                            {!! renderStatusCard('Mileage', $vehicleData['mileage'] ?? null) !!}
                            {!! renderStatusCard('Taxi', $vehicleData['taxi'] ?? null) !!}
                            {!! renderStatusCard('Recall', (isset($motMileageSummary['recall']) && $motMileageSummary['recall'] === 'yes')) !!}
                            {!! renderStatusCard('Keepers', null, $vehicleData['totalKeepers'] ?? '***') !!}
                            {!! renderStatusCard('Keeper', null, null, $vehicleData['keeperChanged'] ?? []) !!}
                        </tr>
                    </table>
                </td>
            </tr>

            <!-- SECTION 2: Untaxed + MOT -->
                    <?php if(!empty($roadTaxMot)){?>

            <tr>
                <td style="padding: 20px 0;">
                    <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;font-family:Arial,Helvetica,sans-serif;">
                        <tr>
                            <!-- TAX CARD -->
                            <td style="padding-right: 1%;width: 49%;box-sizing: border-box;vertical-align: top;">
                                <?php
                                    $isTaxed = isset($roadTaxMot['taxStatus']) ? (strtolower($roadTaxMot['taxStatus']) !== 'sorn') : null;
                                    $taxDueDate = $roadTaxMot['taxDueDate'] ?? null;
                                    $taxDueInDays = $roadTaxMot['taxDueInDays'] ?? null;

                                    $taxIcon = $isTaxed
                                        ? asset('backend/assets/images/checkIcon-large.png')
                                        : asset('backend/assets/images/closeIcon-large.png');
                                ?>
                                <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:separate;border: 2px solid <?= $isTaxed ? '#5ab31b' : '#F44336' ?>;border-radius: 12px;">
                                    <tr>
                                        <td style="padding: 20px;box-sizing: border-box;border-bottom: 2px solid #dadada;">
                                            <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;">
                                                <tr>
                                                    <td style="width: 40px;">
                                                        <img src="<?= $taxIcon ?>" alt="statusIcon" border="0" width="40" height="40" style="display: block;" />
                                                    </td>
                                                    <td style="padding-left: 15px;">
                                                        <div style="color: #000000;font-size: 18px;"><strong><?= $isTaxed ? 'Taxed' : 'Untaxed' ?></strong></div>
                                                        <div style="color: #646464;font-size: 14px;">
                                                            <?php if ($taxDueDate): ?>
                                                                Tax due: <?= date('d-M-y', strtotime($taxDueDate)) ?>
                                                                <?= isset($taxDueInDays) ? " - {$taxDueInDays} days remaining" : '' ?>
                                                            <?php else: ?>
                                                                Tax due: N/A
                                                            <?php endif; ?>
                                                        </div>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="padding: 20px;">
                                            <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;">
                                                <tr><td style="width:60%;font-size:14px;font-weight:bold;padding:10px 0;">Vehicle Make</td>
                                                    <td style="width:40%;text-align:right;font-size:14px;padding:10px 0;"><?= htmlspecialchars((string)($roadTaxMot['make'] ?? '***')) ?></td></tr>

                                                <tr><td style="font-size:14px;font-weight:bold;padding:10px 0;">Fuel Type</td>
                                                    <td style="text-align:right;font-size:14px;padding:10px 0;"><?= htmlspecialchars((string)($roadTaxMot['fuelType'] ?? '***')) ?></td></tr>

                                                <tr><td style="font-size:14px;font-weight:bold;padding:10px 0;">Cylinder Capacity</td>
                                                    <td style="text-align:right;font-size:14px;padding:10px 0;"><?= htmlspecialchars((string)($roadTaxMot['engineCapacity'] ?? '***')) ?></td></tr>

                                                <tr><td style="font-size:14px;font-weight:bold;padding:10px 0;">Vehicle Colour</td>
                                                    <td style="text-align:right;font-size:14px;padding:10px 0;"><?= htmlspecialchars((string)($roadTaxMot['colour'] ?? '***')) ?></td></tr>

                                                <tr><td style="font-size:14px;font-weight:bold;padding:10px 0;">Euro Stats</td>
                                                    <td style="text-align:right;font-size:14px;padding:10px 0;"><?= htmlspecialchars((string)($roadTaxMot['euroStatus'] ?? '***')) ?></td></tr>

                                                <tr><td style="font-size:14px;font-weight:bold;padding:10px 0;">Co2 Emissions</td>
                                                    <td style="text-align:right;font-size:14px;padding:10px 0;"><?= htmlspecialchars((string)($roadTaxMot['co2Emissions'] ?? ($vehicleMot['co2emission'] ?? '***'))) ?></td></tr>

                                                <tr><td style="font-size:14px;font-weight:bold;padding:10px 0;">Real Driving Emissions (RDE)</td>
                                                    <td style="text-align:right;font-size:14px;padding:10px 0;"><?= htmlspecialchars((string)($roadTaxMot['rde'] ?? '***')) ?></td></tr>

                                                <tr><td style="font-size:14px;font-weight:bold;padding:10px 0;">Wheelplan</td>
                                                    <td style="text-align:right;font-size:14px;padding:10px 0;"><?= htmlspecialchars((string)($roadTaxMot['wheelplan'] ?? '***')) ?></td></tr>

                                                <tr><td style="font-size:14px;font-weight:bold;padding:10px 0;">Ulez Compliance</td>
                                                    <td style="text-align:right;font-size:14px;padding:10px 0;">
                                                        <a href="https://tfl.gov.uk/modes/driving/check-your-vehicle/" target="_blank">Check TFL</a>
                                                    </td></tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                            </td>

                            <!-- MOT CARD -->
                            <td style="padding-left: 1%;width: 49%;box-sizing: border-box;vertical-align: top;">
                                <?php
                                    $motStatus = $roadTaxMot['motStatus'] ?? null;
                                    $isMotValid = ($motStatus && strtolower($motStatus) === 'valid');
                                    $motExpiryDate = $roadTaxMot['motExpiryDate'] ?? null;
                                    $motExpiryInDays = $roadTaxMot['motExpiryInDays'] ?? null;

                                    $motIcon = $isMotValid
                                        ? asset('backend/assets/images/checkIcon-large.png')
                                        : asset('backend/assets/images/closeIcon-large.png');
                                ?>
                                <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:separate;border: 2px solid <?= $isMotValid ? '#5ab31b' : '#F44336' ?>;border-radius: 12px;">
                                    <tr>
                                        <td style="padding: 20px;box-sizing: border-box;border-bottom: 2px solid #dadada;">
                                            <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;">
                                                <tr>
                                                    <td style="width: 40px;">
                                                        <img src="<?= $motIcon ?>" alt="motIcon" border="0" width="40" height="40" style="display: block;" />
                                                    </td>
                                                    <td style="padding-left: 15px;">
                                                        <div style="color: #000000;font-size: 18px;"><strong>MOT Status</strong></div>
                                                        <div style="color: #646464;font-size: 14px;">
                                                            <?php if ($motExpiryDate): ?>
                                                                Expires <?= date('d-M-y', strtotime($motExpiryDate)) ?>
                                                                <?= isset($motExpiryInDays) ? " - {$motExpiryInDays} days remaining" : '' ?>
                                                            <?php else: ?>
                                                                Expired on: N/A
                                                            <?php endif; ?>
                                                        </div>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="padding: 20px;">
                                            <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;">
                                                <tr><td style="width:70%;font-size:14px;font-weight:bold;padding:10px 0;">Year Of Manufacture</td>
                                                    <td style="width:30%;text-align:right;font-size:14px;padding:10px 0;"><?= htmlspecialchars((string)($roadTaxMot['yearOfManufacture'] ?? '***')) ?></td></tr>

                                                <tr><td style="font-size:14px;font-weight:bold;padding:10px 0;">Date Of First Registration</td>
                                                    <td style="text-align:right;font-size:14px;padding:10px 0;"><?= !empty($roadTaxMot['monthOfFirstRegistration']) ? date('M-y', strtotime($roadTaxMot['monthOfFirstRegistration'])) : '***' ?></td></tr>

                                                <tr><td style="font-size:14px;font-weight:bold;padding:10px 0;">Date Of Last V5C (logbook) Issued</td>
                                                    <td style="text-align:right;font-size:14px;padding:10px 0;"><?= !empty($roadTaxMot['dateOfLastV5CIssued']) ? date('d-M-y', strtotime($roadTaxMot['dateOfLastV5CIssued'])) : '***' ?></td></tr>

                                                <tr><td style="font-size:14px;font-weight:bold;padding:10px 0;">Export Marker</td>
                                                    <td style="text-align:right;font-size:14px;padding:10px 0;"><?= !empty($roadTaxMot['markedForExport'])? htmlspecialchars((string)($roadTaxMot['markedForExport'] ? 'Yes':'No')):"***" ?></td></tr>

                                                <tr><td style="font-size:14px;font-weight:bold;padding:10px 0;">Vehicle Type Approval</td>
                                                    <td style="text-align:right;font-size:14px;padding:10px 0;"><?= htmlspecialchars((string)($roadTaxMot['typeApproval'] ?? '***')) ?></td></tr>

                                                <tr><td style="font-size:14px;font-weight:bold;padding:10px 0;">Revenue Weight</td>
                                                    <td style="text-align:right;font-size:14px;padding:10px 0;"><?= htmlspecialchars((string)($roadTaxMot['revenueWeight'] ?? '***')) ?></td></tr>

                                                <tr><td style="font-size:14px;font-weight:bold;padding:10px 0;">Vehicle Status</td>
                                                    <td style="text-align:right;font-size:14px;padding:10px 0;"><?= htmlspecialchars((string)($roadTaxMot['taxStatus'] ?? '***')) ?></td></tr>

                                                <tr><td style="font-size:14px;font-weight:bold;padding:10px 0;">MOT Status</td>
                                                    <td style="text-align:right;font-size:14px;padding:10px 0;"><?= htmlspecialchars((string)($roadTaxMot['motStatus'] ?? '***')) ?></td></tr>
                                                    <tr><td style="font-size:14px;font-weight:bold;padding:10px 0;">&nbsp;</td>
                                                    <td style="text-align:right;font-size:14px;padding:10px 0;">&nbsp;</td></tr>
                                                    
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
<?php } ?>

            <!-- SECTION 3: MOT & Mileage Summary -->
            @php
               function renderSummaryCard($title, $value, $icon = null) {
        return '
        <td style="padding-right: 1%;width: 49%;box-sizing: border-box;vertical-align: top;padding-bottom: 15px;">
            <table cellpadding="0" cellspacing="0" border="0"
                style="width: 100%;border-collapse: separate;
                        font-family: Arial, Helvetica, sans-serif;
                        border: 2px solid #efebeb;border-radius: 12px;
                        border-spacing: 15px;">
                <tr>
                    <td style="width: 26px;height: 30px;">' .
                        ($icon ? '<img src="'. asset($icon) .'" alt="icon" border="0" width="26" height="26" style="display:block;" />' : '&nbsp;') .
                    '</td>
                    <td style="font-size: 14px;font-weight: bold;">'. $title .'</td>
                    <td style="text-align: right;font-size: 14px;">'. $value .'</td>
                </tr>
            </table>
        </td>';
    }
            @endphp

            <tr>
    <td align="center" style="text-align: center;font-size: 26px;color: #716d6a;padding: 20px 0;font-family:Arial,Helvetica,sans-serif;">
        <strong>Mot & Mileage Summary</strong>
    </td>
</tr>
<tr>
    <td>
        <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;font-family:Arial,Helvetica,sans-serif;">
            <tr>
                {!! renderSummaryCard('Total Test', $motMileageSummary['totalTests'] ?? '***') !!}
                @php
                    $passRate = $motMileageSummary['passRatePercentage'] ?? null;
                    if ($passRate !== null) {
                        if ($passRate >= 80) {
                            $passRateIcon = 'backend/assets/images/checkIcon.png';
                        } elseif ($passRate >= 70) {
                            $passRateIcon = 'backend/assets/images/alertIcon.png';
                        } else {
                            $passRateIcon = 'backend/assets/images/closeIcon.png';
                        }
                    } else {
                        $passRateIcon = 'backend/assets/images/closeIcon.png';
                    }
                @endphp
                {!! renderSummaryCard('Pass Rate', isset($passRate) ? $passRate.'%' : '***', $passRateIcon) !!}
            </tr>
            <tr>
                {!! renderSummaryCard('Test Passed', $motMileageSummary['totalPassed'] ?? '***', 'backend/assets/images/checkIcon.png') !!}
                {!! renderSummaryCard('Pass Rate With Advisory', isset($motMileageSummary['passRateWithAdvisory']) ? $motMileageSummary['passRateWithAdvisory'].'%' : '***', 'backend/assets/images/alertIcon.png') !!}
            </tr>
            <tr>
                {!! renderSummaryCard('Passed With Advisory', $motMileageSummary['passedWithAdvisory'] ?? '***', 'backend/assets/images/alertIcon.png') !!}
                {!! renderSummaryCard('Pass Rate Without Advisory', isset($motMileageSummary['passRateWithoutAdvisory']) ? $motMileageSummary['passRateWithoutAdvisory'].'%' : '***', 'backend/assets/images/checkIcon.png') !!}
            </tr>
            <tr>
                {!! renderSummaryCard('Total Items Advised', $motMileageSummary['totalItemsAdvised'] ?? '***', 'backend/assets/images/alertIcon.png') !!}
                {!! renderSummaryCard('Mileage Issues', !empty($motMileageSummary['mileageIssue']) ? 'Yes' : 'No', !empty($motMileageSummary['mileageIssue']) ? 'backend/assets/images/closeIcon.png':'backend/assets/images/checkIcon.png') !!}
            </tr>
            <tr>
                {!! renderSummaryCard('Advisory Average/Per MOT', $motMileageSummary['advisoryAverage'] ?? '***', 'backend/assets/images/alertIcon.png') !!}
                {!! renderSummaryCard('Last MOT Mileage', isset($motMileageSummary['lastMileage']) ? $motMileageSummary['lastMileage'].' '.($motMileageSummary['lastMileageUnit'] ?? '') : '***') !!}
            </tr>
            <tr>
                {!! renderSummaryCard('Test Failed', $motMileageSummary['totalFailed'] ?? '***', 'backend/assets/images/closeIcon.png') !!}
                {!! renderSummaryCard('Est Current Mileage', isset($motMileageSummary['currentMileage']) ? $motMileageSummary['currentMileage'].' '.($motMileageSummary['lastMileageUnit'] ?? '') : '***') !!}
            </tr>
            <tr>
                {!! renderSummaryCard('Total Items Failed', $motMileageSummary['totalItemsFailed'] ?? '***', 'backend/assets/images/closeIcon.png') !!}
                {!! renderSummaryCard('Average Mileage', isset($motMileageSummary['avgMileagePerYear']) ? $motMileageSummary['avgMileagePerYear'].' Miles/Year' : '***') !!}
            </tr>
            <tr>
                @php
                    $taxiIcon = !empty($motMileageSummary['taxi']) ? 'backend/assets/images/closeIcon.png' : 'backend/assets/images/checkIcon.png';
                @endphp
                {!! renderSummaryCard('Taxi/Rent a Car Use', !empty($motMileageSummary['taxi']) ? 'Might be' : 'Might not', $taxiIcon) !!}
             @php
    $mileage = $motMileageSummary['avgMileagePerYear'] ?? null;
    if ($mileage === null) {
        $mileageStatusValue = '***';
        $mileageStatusIcon = 'backend/assets/images/alertIcon.png'; // fallback icon
    } elseif ($mileage < 6000) {
        $mileageStatusValue = 'Below Average';
        $mileageStatusIcon = 'backend/assets/images/checkIcon.png';
    } elseif ($mileage >= 6000 && $mileage <= 8000) {
        $mileageStatusValue = 'Average';
        $mileageStatusIcon = 'backend/assets/images/icon03.png';
    } else {
        $mileageStatusValue = 'Above Average';
        $mileageStatusIcon = 'backend/assets/images/closeIcon.png';
    }
@endphp

{!! renderSummaryCard('Mileage Status', $mileageStatusValue, $mileageStatusIcon) !!}
            </tr>
        </table>
    </td>
</tr>

            <!-- SECTION 5: MOT Test List -->
            <tr>
                <td align="center" style="text-align: center;font-size: 26px;color: #716d6a;padding: 25px 0 20px;font-family:Arial,Helvetica,sans-serif;vertical-align: middle;">
                    <table cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;font-family:Arial,Helvetica,sans-serif;margin: 0 auto;">
                        <tr>
                            <td style="padding-right: 10px;">
                                <img src="{{ asset('backend/assets/images/icon04.png') }}" alt="MOT Test List" border="0" width="40" height="35" style="display: block;" />
                            </td>
                            <td>
                                <strong>MOT Test List</strong>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    {{-- Header row --}}
                    <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;font-family:Arial,Helvetica,sans-serif;background-color: #999999;border-radius: 12px 12px 0 0;">
                        <tr>
                            <th style="vertical-align: top;color: #ffffff;font-size: 14px;padding: 15px;text-align: center;width:16%;border-right: 1px solid #ffffff;box-sizing: border-box;">Date</th>
                            <th style="vertical-align: top;color: #ffffff;font-size: 14px;padding: 15px;text-align: center;width:20%;border-right: 1px solid #ffffff;box-sizing: border-box;">Result</th>
                            <th style="vertical-align: top;color: #ffffff;font-size: 14px;padding: 15px;text-align: center;width:16%;border-right: 1px solid #ffffff;box-sizing: border-box;">Mileage</th>
                            <th style="vertical-align: top;color: #ffffff;font-size: 14px;padding: 15px;text-align: center;width:16%;border-right: 1px solid #ffffff;box-sizing: border-box;">Difference</th>
                            <th style="vertical-align: top;color: #ffffff;font-size: 14px;padding: 15px;text-align: center;width:16%;border-right: 1px solid #ffffff;box-sizing: border-box;">Days</th>
                            <th style="vertical-align: top;color: #ffffff;font-size: 14px;padding: 15px;text-align: center;width:16%;box-sizing: border-box;">Reason</th>
                        </tr>
                    </table>
                </td>
            </tr>

            @php
                // Build combined timeline
                $combinedEvents = [];

                $hasKm = false;
                $hasMi = false;
                $hasMileageRev = false;
                $hasTaxi = false;

                if (!empty($vehicleMot['mileageHistory'])) {
                    foreach ($vehicleMot['mileageHistory'] as $mileage) {
                        $unit = strtolower($mileage['unit'] ?? '');
                        if ($unit === 'km') $hasKm = true;
                        if ($unit === 'mi') $hasMi = true;
                        if (!empty($mileage['mileage_reverse'])) $hasMileageRev = true;
                        if (!empty($mileage['taxi'])) $hasTaxi = true;
                    }
                }

                $warnKmMixed = $hasKm && $hasMi;

                if (!empty($vehicleMot['motTestList']['motList'])) {
                    foreach ($vehicleMot['motTestList']['motList'] as $test) {
                        $combinedEvents[] = ['type' => 'mot', 'data' => $test, 'date' => $test['date'] ?? ''];
                    }
                }
                if (!empty($vehicleMot['motTestList']['keepersChange']['data'])) {
                    foreach ($vehicleMot['motTestList']['keepersChange']['data'] as $keeper) {
                        $combinedEvents[] = ['type' => 'keeper', 'data' => $keeper, 'date' => $keeper['date'] ?? ''];
                    }
                }
                if (!empty($vehicleMot['motTestList']['plateChange'])) {
                    foreach ($vehicleMot['motTestList']['plateChange'] as $plate) {
                        $combinedEvents[] = ['type' => 'plate', 'data' => $plate, 'date' => $plate['date'] ?? ''];
                    }
                }

                // Sort by date (newest first)
                usort($combinedEvents, function($a, $b) {
                    $dateA = strtotime($a['date']);
                    $dateB = strtotime($b['date']);
                    return $dateB - $dateA;
                });
            @endphp

            @foreach ($combinedEvents as $event)
                @if ($event['type'] === 'mot')
                    @php
                        $test = $event['data'];
                        $isPass = isset($test['result']) && strtoupper($test['result']) === 'PASSED';
                        $borderColor = $isPass ? '#5ab31b' : '#f22d1c';
                        $icon = $isPass ? 'checkIcon.png' : 'closeIcon.png';
                    @endphp
                    <tr>
                        <td style="padding-top: 15px;">
                            <table cellpadding="0" cellspacing="0" border="0" 
                                style="width:100%;border-collapse:separate;border: 2px solid {{ $borderColor }};font-family:Arial,Helvetica,sans-serif;border-radius: 12px;">
                                <tr>
                                    {{-- Date --}}
                                    <td style="vertical-align: middle;font-size: 14px;padding: 15px;text-align: center;font-weight: bold;width:16%;">
                                        {{ !empty($test['date']) ? date('d-M-y', strtotime($test['date'])) : '' }}
                                    </td>

                                    {{-- Result with icon --}}
                                    <td style="vertical-align: middle;font-size: 14px;padding: 15px 5px;text-align: center;font-weight: bold;width:20%;">
                                        <table cellpadding="0" cellspacing="0" border="0" 
                                            style="width: 100%; border-collapse:separate;border: 2px solid {{ $borderColor }};border-radius: 12px;margin: 0 auto;">
                                            <tr>
                                                <td style="border-right: 2px solid {{ $borderColor }};padding: 5px;width: 42px;">
                                                    <img src="{{ asset('backend/assets/images/' . $icon) }}" width="26" height="26" style="display: block;" />
                                                </td>
                                                <td style="padding: 5px;">{{ $isPass ? 'PASS' : 'FAIL' }}</td>
                                            </tr>
                                        </table>
                                    </td>

                                    {{-- Mileage --}}
                                    <td style="vertical-align: middle;font-size: 14px;padding: 15px;text-align: center;font-weight: bold;width:16%;">
                                        {{ $test['mileage'] ?? '' }} {{ $test['unit'] ?? '' }}
                                    </td>

                                    {{-- Difference --}}
                                    <td style="vertical-align: middle;font-size: 14px;padding: 15px;text-align: center;font-weight: bold;width:16%;">
                                        {{ $test['difference'] ?? '0' }}
                                    </td>

                                    {{-- Days --}}
                                    <td style="vertical-align: middle;font-size: 14px;padding: 15px;text-align: center;font-weight: bold;width:16%;">
                                        {{ $test['days'] ?? '0' }}
                                    </td>

                                    {{-- Reason --}}
                                    <td style="vertical-align: middle;font-size: 14px;padding: 15px;text-align: center;font-weight: bold;width:16%;">
                                        Failures({{ count($test['failure'] ?? []) }}) <br/>
                                        Advisories({{ count($test['advisory'] ?? []) }})
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                @elseif ($event['type'] === 'keeper')
                    @php $keeper = $event['data']; @endphp
                    <tr>
                        <td style="padding-top: 15px;">
                            <table cellpadding="0" cellspacing="0" border="0" 
                                style="width:100%;border-collapse:separate;border: 2px solid #f49320;font-family:Arial,Helvetica,sans-serif;border-radius: 12px;">
                                <tr>
                                    {{-- Date --}}
                                    <td style="vertical-align: middle;font-size: 14px;padding: 15px;text-align: center;font-weight: bold;width:16%;">
                                        {{ !empty($keeper['date']) ? date('d-M-y', strtotime($keeper['date'])) : '' }}
                                    </td>

                                    {{-- Keeper Info with icon --}}
                                    <td style="vertical-align: middle;font-size: 14px;padding: 15px 5px;text-align: center;font-weight: bold;width:20%;">
                                        <table cellpadding="0" cellspacing="0" border="0" 
                                            style="width: 100%; border-collapse:separate;border: 2px solid #f49320;border-radius: 12px;margin: 0 auto;">
                                            <tr>
                                                <td style="border-right: 2px solid #f49320;padding: 5px;width: 42px;">
                                                    <img src="{{ asset('backend/assets/images/alertIcon.png') }}" width="26" height="26" style="display: block;" />
                                                </td>
                                                <td style="padding: 5px;">KEEPER {{ $keeper['count'] ?? '' }}</td>
                                            </tr>
                                        </table>
                                    </td>

                                    {{-- Empty columns --}}
                                    <td style="vertical-align: middle;font-size: 14px;padding: 15px;text-align: center;width:16%;">&nbsp;</td>
                                    <td style="vertical-align: middle;font-size: 14px;padding: 15px;text-align: center;width:16%;">&nbsp;</td>
                                    <td style="vertical-align: middle;font-size: 14px;padding: 15px;text-align: center;width:16%;">&nbsp;</td>
                                    <td style="vertical-align: middle;font-size: 14px;padding: 15px;text-align: center;width:16%;">&nbsp;</td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                @elseif ($event['type'] === 'plate')
                    @php $plate = $event['data']; @endphp
                    <tr>
                        <td style="padding-top: 15px;">
                            <table cellpadding="0" cellspacing="0" border="0" 
                                style="width:100%;border-collapse:separate;border: 2px solid #f49320;font-family:Arial,Helvetica,sans-serif;border-radius: 12px;">
                                <tr>
                                    {{-- Date --}}
                                    <td style="vertical-align: middle;font-size: 14px;padding: 15px;text-align: center;font-weight: bold;width:16%;">
                                        {{ !empty($plate['date']) ? date('d-M-y', strtotime($plate['date'])) : '' }}
                                    </td>

                                    {{-- Plate Info with icon --}}
                                    <td style="vertical-align: middle;font-size: 14px;padding: 15px 5px;text-align: center;font-weight: bold;width:20%;">
                                        <table cellpadding="0" cellspacing="0" border="0" 
                                            style="width: 100%; border-collapse:separate;border: 2px solid #f49320;border-radius: 12px;margin: 0 auto;">
                                            <tr>
                                                <td style="border-right: 2px solid #f49320;padding: 5px;width: 42px;">
                                                    <img src="{{ asset('backend/assets/images/alertIcon.png') }}" width="26" height="26" style="display: block;" />
                                                </td>
                                                <td style="padding: 5px;">PLATE {{ $plate['count'] ?? '' }}</td>
                                            </tr>
                                        </table>
                                    </td>

                                    {{-- Plate Transition --}}
                                    <td colspan="2" style="vertical-align: middle;font-size: 14px;padding: 15px;text-align: center;font-weight: bold;width:32%;">
                                        <table cellpadding="0" cellspacing="0" border="0" style="width:100%; text-align: center;font-weight: bold;vertical-align: middle;font-size: 14px;">
                                            <tr>
                                                <td>
                                                    <table cellpadding="0" cellspacing="0" border="0" 
                                                        style="width: 100%; border-collapse:separate;border: 1px solid #000;font-family:Arial,Helvetica,sans-serif;border-radius: 5px;">
                                                        <tr>
                                                            <td style="width: 17px;">
                                                                <img src="{{ asset('backend/assets/images/enter-reg.png') }}" width="17" height="34" style="display: block;" />
                                                            </td>
                                                            <td style="padding:0 5px; text-align:center;">{{ $plate['previous'] ?? '' }}</td>
                                                        </tr>
                                                    </table>
                                                </td>
                                                <td style="">
                                                    <img src="{{ asset('backend/assets/images/arrowIcon1.png') }}" width="26" height="6" />
                                                </td>
                                                <td>
                                                    <table cellpadding="0" cellspacing="0" border="0" 
                                                        style="width: 100%; border-collapse:separate;border: 1px solid #000;font-family:Arial,Helvetica,sans-serif;border-radius: 5px;">
                                                        <tr>
                                                            <td style="width: 17px;">
                                                                <img src="{{ asset('backend/assets/images/enter-reg.png') }}" width="17" height="34" style="display: block;" />
                                                            </td>
                                                            <td style="padding:0 5px; text-align:center;">{{ $plate['current'] ?? '' }}</td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                     <td style="vertical-align: middle;font-size: 14px;padding: 15px;text-align: center;font-weight: bold;width:16%;">
                                        {{'' }}
                                    </td>

                                    {{-- Empty --}}
                                    <td style="vertical-align: middle;font-size: 14px;padding: 15px;text-align: center;width:16%;">&nbsp;</td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                @endif
            @endforeach
           

            <!-- SECTION: Mileage History -->
        <tr>
    <td align="center" style="text-align: center; font-size: 26px; color: #716d6a; padding: 40px 0 20px; font-family: Arial, Helvetica, sans-serif;">
        <strong>Mileage History</strong>
    </td>
</tr>

<!-- Table Header -->
<tr>
    <td>
        <table cellpadding="0" cellspacing="0" border="0"
            style="width:100%; border-collapse:collapse; font-family: Arial, Helvetica, sans-serif; background-color: #999999; border-radius: 12px 12px 0 0;">
            <tr>
                <th style="color:#ffffff; font-size:14px; padding:15px; text-align:center; width:20%; border-right:1px solid #ffffff;">S No.</th>
                <th style="color:#ffffff; font-size:14px; padding:15px; text-align:center; width:20%; border-right:1px solid #ffffff;">Date</th>
                <th style="color:#ffffff; font-size:14px; padding:15px; text-align:center; width:20%; border-right:1px solid #ffffff;">Mileage</th>
                <th style="color:#ffffff; font-size:14px; padding:15px; text-align:center; width:20%; border-right:1px solid #ffffff;">Difference</th>
                <th style="color:#ffffff; font-size:14px; padding:15px; text-align:center; width:20%;">Days</th>
            </tr>
        </table>
    </td>
</tr>

<?php
// Prepare combinedEvents
$combinedEvents = [];

// Add mileage history
if (!empty($vehicleMot['mileageHistory'])) {
    foreach ($vehicleMot['mileageHistory'] as $mileage) {
        $date = !empty($mileage['date']) ? date('Y-m-d', strtotime($mileage['date'])) : '';
        if (!$date) continue;
        $combinedEvents[$date]['mileage'][] = $mileage;
    }
}

// Add keeper changes
if (!empty($vehicleMot['motTestList']['keepersChange']['data'])) {
    foreach ($vehicleMot['motTestList']['keepersChange']['data'] as $keeper) {
        $date = !empty($keeper['date']) ? date('Y-m-d', strtotime($keeper['date'])) : '';
        if (!$date) continue;
        $combinedEvents[$date]['keeper'][] = $keeper;
    }
}

// Add plate changes
if (!empty($vehicleMot['motTestList']['plateChange'])) {
    foreach ($vehicleMot['motTestList']['plateChange'] as $plate) {
        $date = !empty($plate['date']) ? date('Y-m-d', strtotime($plate['date'])) : '';
        if (!$date) continue;
        $combinedEvents[$date]['plate'][] = $plate;
    }
}

// Sort by date DESC
uksort($combinedEvents, function($a, $b) {
    return strtotime($b) - strtotime($a);
});

// Serial numbers only for mileage rows
// Count all mileage events first
$totalMileage = 0;
foreach ($combinedEvents as $date => $event) {
    if (!empty($event['mileage']) && empty($event['keeper'])) {
        $totalMileage += count($event['mileage']);
    }
}
$sno = $totalMileage;

// Loop through combined events
foreach ($combinedEvents as $date => $event):

    // --- Mileage rows ---
    if (!empty($event['mileage'])):
        foreach ($event['mileage'] as $mileage):

            $isTaxi = !empty($mileage['taxi']);
            $isKm   = strtolower($mileage['unit'] ?? '') === 'km';
            $isRev  = !empty($mileage['mileage_reverse']);

            // Default row style
            $rowBg = "#ffffff"; $rowCol = "#000"; $rowBold = "normal";

            if ($isTaxi) {
                $rowBg = "#e6f2ff"; $rowCol = "#1565c0"; $rowBold = "bold";
            }
            if ($isRev) {
                $rowBg = "#ffebee"; $rowCol = "#c62828"; $rowBold = "bold";
            }
            if ($isKm) {
                $rowBg = "#fff8e1"; $rowCol = "#ef6c00"; $rowBold = "bold";
            }

            // Collect labels (keeper/plate info for this same date)
            $labels = [];
            // if (!empty($event['keeper'])) {
            //     foreach ($event['keeper'] as $k) {
            //         $labels[] = "Keeper " . htmlspecialchars((string)($k['count'] ?? ''));
            //     }
            // }

if (!empty($event['plate'])) {
    foreach ($event['plate'] as $plate) {

        $labels[] = '<table cellpadding="0" cellspacing="0" border="0" 
                        style="text-align:center; font-weight:bold; vertical-align:middle; font-size:14px; margin:0 auto;">
                        <tr>
                            <td style="width:120px; text-align:center;">
                                <table cellpadding="0" cellspacing="0" border="0" 
                                       style="width:120px; border-collapse:separate; border:1px solid #000; border-radius:5px; font-family:Arial,Helvetica,sans-serif;">
                                    <tr>
                                        <td style="width:17px;">
                                            <img src="'.asset('backend/assets/images/enter-reg.png').'" 
                                                alt="enter-reg" width="17" height="34" style="display:block;" border="0" />
                                        </td>
                                        <td style="padding:0 5px;color: black; text-align:center;">'.htmlspecialchars($plate['previous'] ?? '***').'</td>
                                    </tr>
                                </table>
                            </td>

                            <td style="width:40px; text-align:center;padding: 15px 0 15px 15px;">
                                <img src="'.asset('backend/assets/images/arrowIcon1.png').'" 
                                     alt="arrow" width="26" height="6" style="display:block;" border="0" />
                            </td>

                            <td style="width:120px; text-align:center;">
                                <table cellpadding="0" cellspacing="0" border="0" 
                                       style="width:120px; border-collapse:separate; border:1px solid #000; border-radius:5px; font-family:Arial,Helvetica,sans-serif;">
                                    <tr>
                                        <td style="width:17px;">
                                            <img src="'.asset('backend/assets/images/enter-reg.png').'" 
                                                 alt="enter-reg" width="17" height="34" style="display:block;" border="0" />
                                        </td>
                                        <td style="padding:0 5px;color: black; text-align:center;">'.htmlspecialchars($plate['current'] ?? '***').'</td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>';
    }
}

?>


<tr>
    <td style="padding-top: 15px;">
        <?php if(!empty($event['keeper']) && $mileage['difference']!="0" && empty($mileage['difference'])){ 
            foreach ($event['keeper'] as $keeper){ ?>
                <table cellpadding="0" cellspacing="0" border="0" 
                   style="width:100%; border:2px solid #f49320; border-radius:12px; background:#fff3e0; color:#ef6c00; font-weight:bold; font-family: Arial, Helvetica, sans-serif;">
                   <tr>
                   <td style="font-size:14px; padding:15px; text-align:center; width:20%;;">Keeper <?= htmlspecialchars((string)($keeper['count'] ?? '')) ?></td>
                <td style="font-size:14px; padding:15px; text-align:center; width:20%;"><?= !empty($keeper['date']) ? date('d-M-y', strtotime($keeper['date'])) : '' ?></td>
                <td style="font-size:14px; padding:15px; text-align:center; width:20%;"></td>
                    <td style="font-size:14px; padding:15px; text-align:center; width:20%;"><?= htmlspecialchars((string)($mileage['difference'] ?? '')) ?> <?= !empty($mileage['difference']) ? 'keeper' : '' ?></td>
                <td style="font-size:14px; padding:15px; text-align:center; width:20%;"></td>

                     </tr>
        </table>
                <?php } }else{ ?>
                        <table cellpadding="0" cellspacing="0" border="0" 
                   style="width:100%; border-collapse:separate; border:2px solid <?php echo !empty($labels) ? '#ff9800' : '#efebeb'; ?>; border-radius:12px; background:<?= $rowBg ?>; color:<?= $rowCol ?>; font-weight:<?= $rowBold ?>; font-family: Arial, Helvetica, sans-serif;">
                   <tr>
                    <td style="font-size:14px; padding:15px; text-align:center; width:20%;"><?= $sno-- ?></td>
                <td style="font-size:14px; padding:15px; text-align:center; width:20%;"><?= !empty($mileage['date']) ? date('d-M-y', strtotime($mileage['date'])) : '' ?></td>
                <td style="font-size:14px; padding:15px; text-align:center; width:20%;">
                    <?= htmlspecialchars((string)($mileage['mileage'] ?? '')) ?>
                    <?= htmlspecialchars((string)($mileage['unit'] ?? '')) ?>
                    <?php if (!empty($labels)): ?>
                        <div style="margin-top:2px; color:#FF9800; font-weight:bold;"><?= implode(' • ', $labels) ?></div>
                    <?php endif; ?>
                </td>
                <td style="font-size:14px; padding:15px; text-align:center; width:20%;"><?= htmlspecialchars((string)($mileage['difference'] ?? '')) ?> <?= !empty($mileage['difference']) ? 'MI' : '' ?></td>
                <td style="font-size:14px; padding:15px; text-align:center; width:20%;"><?= htmlspecialchars((string)($mileage['days'] ?? '')) ?></td>
            </tr>
        </table>
                <?php } ?>
            
    </td>
</tr>
<?php
        endforeach;
    endif;

    // --- Keeper rows (only if no mileage on that date) ---
    if (empty($event['mileage']) && !empty($event['keeper'])):
        foreach ($event['keeper'] as $keeper):
?>
<tr>
    <td style="padding-top: 10px;">
        <table cellpadding="0" cellspacing="0" border="0"
            style="width:100%; border:2px solid #f49320; border-radius:12px; background:#fff3e0; color:#ef6c00; font-weight:bold; font-family: Arial, Helvetica, sans-serif;">
            <tr>
                <td style="font-size:14px; padding:10px; text-align:center; width:20%;">Keeper <?= htmlspecialchars((string)($keeper['count'] ?? '')) ?></td>
                <td style="font-size:14px; padding:10px; text-align:center; width:20%;"><?= !empty($keeper['date']) ? date('d-M-y', strtotime($keeper['date'])) : '' ?></td>
                <td colspan="3" style="font-size:14px; padding:10px; text-align:center; width:60%;">&nbsp;</td>
            </tr>
        </table>
    </td>
</tr>
<?php
        endforeach;
    endif;

    // --- Plate rows (only if no mileage on that date) ---
    if (empty($event['mileage']) && !empty($event['plate'])):
        foreach ($event['plate'] as $plate):
?>
<tr>
    <td style="padding-top: 10px;">
        <table cellpadding="0" cellspacing="0" border="0"
            style="width:100%; border:2px solid #003399; border-radius:12px; background:#f0f4ff; color:#003399; font-weight:bold; font-family: Arial, Helvetica, sans-serif;">
            <tr>
                <td style="font-size:14px; padding:10px; text-align:center; width:20%;">Plate Change</td>
                <td style="font-size:14px; padding:10px; text-align:center; width:20%;"><?= !empty($plate['date']) ? date('d-M-y', strtotime($plate['date'])) : '' ?></td>
                <td colspan="3" style="font-size:14px; padding:10px; text-align:center; width:60%;">
                    <?= htmlspecialchars((string)($plate['previous'] ?? '')) ?> → <?= htmlspecialchars((string)($plate['current'] ?? '')) ?>
                </td>
            </tr>
        </table>
    </td>
</tr>
<?php
        endforeach;
    endif;

endforeach;

?>





<!-- ... Your legend and warning messages go here unchanged ... -->
<!-- Legend Row -->
<tr>
  <td style="padding: 30px 10px; text-align:center; font-family: Arial, Helvetica, sans-serif;">
    <table cellpadding="0" cellspacing="0" border="0" align="center" style="border-collapse:collapse;">
      <tr>
        <td style="padding:0 15px;">
          <table cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;">
            <tr>
              <td style="border:1px solid #f49320; background:#fff3e4; border-radius:5px; width:20px; height:20px;">&nbsp;</td>
              <td style="font-size:13px; font-weight:bold; padding-left:8px; color:#f49320;">Km / Mileage</td>
            </tr>
          </table>
        </td>
        <td style="padding:0 15px;">
          <table cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;">
            <tr>
              <td style="border:1px solid #ed382f; background:#ffdfe0; border-radius:5px; width:20px; height:20px;">&nbsp;</td>
              <td style="font-size:13px; font-weight:bold; padding-left:8px; color:#c62828;">Mileage Reverse</td>
            </tr>
          </table>
        </td>
        <td style="padding:0 15px;">
          <table cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;">
            <tr>
              <td style="border:1px solid #16a7e0; background:#ddefff; border-radius:5px; width:20px; height:20px;">&nbsp;</td>
              <td style="font-size:13px; font-weight:bold; padding-left:8px; color:#1565c0;">Taxi MOT gaps</td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
  </td>
</tr>

<!-- Conditional Warning Row -->
<?php if ($warnKmMixed || $hasMileageRev || $hasTaxi): ?>
<tr>
  <td style="padding: 20px 10px; font-family: Arial, Helvetica, sans-serif;">
    <table width="100%" cellpadding="12" cellspacing="0" border="0" style="border-collapse:collapse; text-align:center;">
      <tr>
        <?php if ($warnKmMixed): ?>
          <td style="background:#fff8e1; border:1px solid #ef6c00; border-radius:6px; color:#ef6c00;">
            <div style="font-size:14px; font-weight:bold;">Miles / KMs Warning</div>
            <div style="font-size:12px; margin-top:4px;">A mixture of Miles and KMs has been detected in the MOT history.</div>
          </td>
        <?php endif; ?>

        <?php if ($hasMileageRev): ?>
          <td style="background:#ffebee; border:1px solid #c62828; border-radius:6px; color:#c62828;">
            <div style="font-size:14px; font-weight:bold;">Mileage Reverse</div>
            <div style="font-size:12px; margin-top:4px;">A discrepancy in mileage has been detected in the MOT history.</div>
          </td>
        <?php endif; ?>

        <?php if ($hasTaxi): ?>
          <td style="background:#e6f2ff; border:1px solid #1565c0; border-radius:6px; color:#1565c0;">
            <div style="font-size:14px; font-weight:bold;">Taxi MOT gaps</div>
            <div style="font-size:12px; margin-top:4px;">This vehicle may have been used commercially (3 consecutive 6-month MOTs).</div>
          </td>
        <?php endif; ?>
      </tr>
    </table>
  </td>
</tr>
<?php endif; ?>




            <!-- Vehicle Information -->
            <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0"
                        style="width:100%;border-collapse:separate;
                                border: 2px solid #16a7e0;border-radius: 12px;
                                font-family:Arial,Helvetica,sans-serif;">
                        <tr>
                            <th colspan="4"
                                style="border-bottom: 2px solid #dadada;padding:20px 10px;
                                    box-sizing: border-box;font-size: 26px;
                                    text-align: center;color: #716d6a;">
                                Vehicle Information
                            </th>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;
                                    font-size: 14px;padding: 10px;width: 30%;">Vehicle Registration Mark</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;
                                    padding: 10px;width: 20%;">
                                <?= htmlspecialchars((string)($vehicleInformation['Vrm'] ?? '***')) ?>
                            </td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;
                                    font-size: 14px;padding: 10px;width: 30%;">Make &amp; Model</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;
                                    padding: 10px;width: 20%;">
                                <?= htmlspecialchars((string)($vehicleInformation['Make'] ?? '***')) ?>
                                <?= htmlspecialchars((string)($vehicleInformation['Model'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Make</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['Make'] ?? '***')) ?>
                            </td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Model</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['Model'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Engine Capacity</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['EngineCapacity'] ?? '***')) ?>
                            </td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Year of Manufacture</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['YearOfManufacture'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Fuel</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['Fuel'] ?? '***')) ?>
                            </td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Date First Registered</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= !empty($vehicleInformation['DateFirstRegistered']) ? date('d-M-y', strtotime($vehicleInformation['DateFirstRegistered'])) : '***' ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Premium Vehicle Year 2 to 6 - Twelve Month</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">***</td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Date of 1st Registration in UK</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= !empty($vehicleInformation['DateFirstRegisteredUk']) ? date('d-M-y', strtotime($vehicleInformation['DateFirstRegisteredUk'])) : '***' ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Colour</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['Colour'] ?? '***')) ?>
                            </td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Year-Month 1st Registered</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['YearMonthFirstRegistered'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">CO2 Emissions</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['Co2Emissions'] ?? ($vehicleMot['co2emission'] ?? '***'))) ?>
                            </td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Transmission</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['Transmission'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Gear Count</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['GearCount'] ?? '***')) ?>
                            </td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Transmission Type</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['TransmissionType'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Engine Number</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['EngineNumber'] ?? '***')) ?>
                            </td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Transmission Code</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['TransmissionCode'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Gross Weight</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['GrossWeight'] ?? '***')) ?>
                            </td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Door Plan Code</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['DoorPlanCode'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Maximum Permissable Mass</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['MaximumPermissableMass'] ?? '***')) ?>
                            </td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">MVRIS Model Code</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['MVRISModelCode'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Seating Capacity</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['SeatingCapacity'] ?? '***')) ?>
                            </td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">MVRIS Make Code</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['MVRISMakeCode'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Wheel Plan</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['WheelPlan'] ?? '***')) ?>
                            </td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Used Before First Registration</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= !empty($vehicleInformation['UsedBeforeFirstRegistration']) ? 'Yes' : 'No' ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Vehicle Class</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['VehicleClass'] ?? '***')) ?>
                            </td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Vin Confirmation Flag</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleInformation['VinConfirmationFlag'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Date Of Last Update</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">
                                <?= !empty($vehicleInformation['DateOfLastUpdate']) ? date('d-M-y H:i:s', strtotime($vehicleInformation['DateOfLastUpdate'])) : '***' ?>
                            </td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">&nbsp;</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;">&nbsp;</td>
                        </tr>

                    </table>
                </td>
            </tr>


            <!-- General Information -->
            <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0"
                        style="width:100%;border-collapse:separate;border: 2px solid #16a7e0;
                                border-radius: 12px; font-family:Arial,Helvetica,sans-serif;">
                        <tr>
                            <th colspan="4"
                                style="border-bottom: 2px solid #dadada;padding:20px 10px;box-sizing: border-box;
                                    font-size: 26px;text-align: center;color: #716d6a;">
                                General Information
                            </th>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;
                                    font-size: 14px;padding: 10px;width: 30%;">Make</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;
                                    padding: 10px;width: 20%;"><?= htmlspecialchars((string)($general['Engine']['Make'] ?? '***')) ?></td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;
                                    font-size: 14px;padding: 10px;width: 30%;">Euro Status</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;
                                    padding: 10px;width: 20%;"><?= htmlspecialchars((string)($general['EuroStatus'] ?? '***')) ?></td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Aspiration</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['Engine']['Aspiration'] ?? '***')) ?></td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Fuel System</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['Engine']['FuelSystem'] ?? '***')) ?></td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Number Of Cylinders</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['Engine']['NumberOfCylinders'] ?? '***')) ?></td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Fuel Delivery</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['Engine']['FuelDelivery'] ?? '***')) ?></td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Valves Per Cylinder</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['Engine']['ValvesPerCylinder'] ?? '***')) ?></td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Fuel Catalyst</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['Engine']['FuelCatalyst'] ?? '***')) ?></td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Cylinder Arrangement</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['Engine']['CylinderArrangement'] ?? '***')) ?></td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Stroke</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['Engine']['Stroke'] ?? '***')) ?></td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Valve Gear</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['Engine']['ValveGear'] ?? '***')) ?></td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Location</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['Engine']['Location'] ?? '***')) ?></td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Description</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['Engine']['Description'] ?? '***')) ?></td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Bore</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['Engine']['Bore'] ?? '***')) ?></td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Power Delivery</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['PowerDelivery'] ?? '***')) ?></td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Type Approval Category</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['TypeApprovalCategory'] ?? '***')) ?></td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Driving Axle</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['DrivingAxle'] ?? '***')) ?></td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Primary Fuel Flag</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['PrimaryFuelFlag'] ?? '***')) ?></td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Series Description</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['SeriesDescription'] ?? '***')) ?></td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Driver Position</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['DriverPosition'] ?? '***')) ?></td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Data Version Number</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['DataVersionNumber'] ?? '***')) ?></td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">Is Limited Edition</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= !empty($general['IsLimitedEdition']) ? 'Yes' : 'No' ?></td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">EV Battery Capacity</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['ElectricVehicleBattery']['Capacity'] ?? '***')) ?></td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">EV Battery Charge Port</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['ElectricVehicleBattery']['ChargePort'] ?? '***')) ?></td>
                        </tr>

                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">EV Battery Charge Time</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['ElectricVehicleBattery']['ChargeTime'] ?? '***')) ?></td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;font-size: 14px;padding: 10px;">EV Battery Type</td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;padding: 10px;"><?= htmlspecialchars((string)($general['ElectricVehicleBattery']['Type'] ?? '***')) ?></td>
                        </tr>

                    </table>
                </td>
            </tr>

            <!-- Previous Keepers -->
           <tr>
    <td style="vertical-align: top;padding-bottom: 30px;">
        <table cellpadding="0" cellspacing="0" border="0"
            style="width:100%;border-collapse:separate;border: 2px solid #16a7e0;
                    border-radius: 12px; font-family:Arial,Helvetica,sans-serif;">
            
            <!-- Header -->
            <tr>
                <th colspan="4"
                    style="border-bottom: 2px solid #dadada;padding:20px 10px;
                        box-sizing: border-box;font-size: 26px;
                        text-align: center;color: #716d6a;">
                    Previous Keepers
                </th>
            </tr>

            <!-- Summary Row -->
            <tr>
                <td style="vertical-align: top;text-align: left;font-weight: bold;
                        font-size: 14px;padding: 10px;width: 30%;">
                    Total Keepers
                </td>
                <td style="vertical-align: top;text-align: right;font-size: 14px;
                        padding: 10px;width: 20%;">
                    <?= htmlspecialchars((string)($vehicleMot['motTestList']['keepersChange']['total'] ?? '***')) ?>
                </td>
                <td style="vertical-align: top;text-align: left;font-weight: bold;
                        font-size: 14px;padding: 10px;width: 30%;">
                    Keeper Data Count
                </td>
                <td style="vertical-align: top;text-align: right;font-size: 14px;
                        padding: 10px;width: 20%;">
                    <?= htmlspecialchars((string)($vehicleMot['motTestList']['keepersChange']['numberofprevioukeeper'] ?? '***')) ?>
                </td>
            </tr>

            <!-- Dynamic Keeper Rows -->
            <?php if (!empty($vehicleMot['motTestList']['keepersChange']['data'])): ?>
                <?php foreach ($vehicleMot['motTestList']['keepersChange']['data'] as $index => $keeper): ?>
                    <tr <?= $index % 2 === 0 ? '' : 'style="background:#f9f9f9;"' ?>>
                        <td colspan="2" style="vertical-align: top;text-align: left;font-weight: bold;
                                font-size: 14px;padding: 10px;width: 50%;">
                            <?= htmlspecialchars($keeper['keeper_count_text'] ?? '***') ?>
                        </td>
                        <td colspan="2" style="vertical-align: top;text-align: right;font-size: 14px;
                                padding: 10px;width: 50%;">
                            <?php if (!empty($keeper['date'])): ?>
                                <?= date('d-M-y', strtotime($keeper['date'])) ?>
                            <?php else: ?>
                                ***
                            <?php endif; ?>
                        </td>
                    </tr>
                <?php endforeach; ?>
            <?php else: ?>
                <tr>
                    <td colspan="4" align="center" style="padding:10px; color:#999;">
                        No keeper history available
                    </td>
                </tr>
            <?php endif; ?>

        </table>
    </td>
</tr>



            <!-- V5C Certificate issue details -->
            <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0"
                        style="width:100%;border-collapse:separate;border: 2px solid #16a7e0;
                                border-radius: 12px; font-family:Arial,Helvetica,sans-serif;">

                        <!-- Header -->
                        <tr>
                            <th colspan="4"
                                style="border-bottom: 2px solid #dadada;padding:20px 10px;
                                    box-sizing: border-box;font-size: 26px;
                                    text-align: center;color: #716d6a;">
                                V5C Certificate issue details
                            </th>
                        </tr>

                        <!-- Dynamic Row -->
                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;
                                    font-size: 14px;padding: 10px;width: 30%;">
                                V5C Certificate Count
                            </td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;
                                    padding: 10px;width: 20%;">
                                <?= ($V5CCertificates && is_array($V5CCertificates)) ? count($V5CCertificates) : '***' ?>
                            </td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;
                                    font-size: 14px;padding: 10px;width: 30%;">
                                Certificate Dates
                            </td>
                            <td style="vertical-align: top;text-align: right;font-size: 14px;
                                    padding: 10px;width: 20%;">
                                <?php if (!empty($V5CCertificates) && is_array($V5CCertificates)): ?>
                                    <?php foreach ($V5CCertificates as $date): ?>
                                        <?= !empty($date) ? date('d-M-y', strtotime($date)) : '' ?><br>
                                    <?php endforeach; ?>
                                <?php else: ?>
                                    ***
                                <?php endif; ?>
                            </td>
                        </tr>

                    </table>
                </td>
            </tr>


            <!-- V5C Tax Co2 Emissions -->
            <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0"
                        style="width:100%;border-collapse:separate;border: 2px solid #16a7e0;
                                border-radius: 12px; font-family:Arial,Helvetica,sans-serif;">

                        <!-- Header -->
                        <tr>
                            <th colspan="4"
                                style="border-bottom: 2px solid #dadada;padding:20px 10px;
                                    box-sizing: border-box;font-size: 26px;
                                    text-align: center;color: #716d6a;">
                                Vehicle Tax &amp; CO2 Emissions
                            </th>
                        </tr>

                        <!-- Rows -->
                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;width: 30%;">Standard Six Month</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;width: 20%;">
                                <?= htmlspecialchars((string)($vehicleTaxCo2Emissions['StandardSixMonth']['Amount'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;width: 30%;">Per Month</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;width: 20%;">
                                <?= htmlspecialchars((string)($vehicleTaxCo2Emissions['StandardSixMonth']['PerMonth'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Standard Twelve Month</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleTaxCo2Emissions['StandardTwelveMonth']['Amount'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Per Month</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleTaxCo2Emissions['StandardTwelveMonth']['PerMonth'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">First Year Six Month</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">---</td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Per Month</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">---</td>
                        </tr>

                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">First Year Twelve Month</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleTaxCo2Emissions['First Year Twelve Month']['Amount'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Per Month</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleTaxCo2Emissions['First Year Twelve Month']['PerMonth'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Premium Vehicle Year 2 to 6 - Six Month</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">---</td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Per Month</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">---</td>
                        </tr>

                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Premium Vehicle Year 2 to 6 - Twelve Month</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">---</td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Per Month</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">---</td>
                        </tr>

                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">VED CO₂ Emissions</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleTaxCo2Emissions['VedCo2Emissions'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">VED Band</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleTaxCo2Emissions['VedBand'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">VED CO₂ Band</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($vehicleTaxCo2Emissions['VedCo2Band'] ?? '***')) ?>
                            </td>
                            <td style="font-size: 14px;padding: 10px;">&nbsp;</td>
                            <td style="font-size: 14px;padding: 10px;">&nbsp;</td>
                        </tr>

                    </table>
                </td>
            </tr>

            <!-- Performance Information -->
            <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0"
                        style="width:100%;border-collapse:separate;border: 2px solid #16a7e0;
                                border-radius: 12px; font-family:Arial,Helvetica,sans-serif;">
                        <!-- Header -->
                        <tr>
                            <th colspan="4"
                                style="border-bottom: 2px solid #dadada;padding:20px 10px;
                                    box-sizing: border-box;font-size: 26px;
                                    text-align: center;color: #716d6a;">
                                Performance Information
                            </th>
                        </tr>

                        <!-- Rows -->
                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;width: 30%;">Torque FtLb</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;width: 20%;">
                                <?= htmlspecialchars((string)($performance['Torque']['FtLb'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;width: 30%;">Power Rpm</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;width: 20%;">
                                <?= htmlspecialchars((string)($performance['Power']['Rpm'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Torque Rpm</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($performance['Torque']['Rpm'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Power Bhp</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($performance['Power']['Bhp'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Torque Nm</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($performance['Torque']['Nm'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Power Kw</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($performance['Power']['Kw'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Co₂</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($performance['Co2'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">NoiseLevel</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($performance['NoiseLevel'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Max Speed Mph</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($performance['MaxSpeed']['Mph'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Particles</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($performance['Particles'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Max Speed Kph</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($performance['MaxSpeed']['Kph'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Data Version Number</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($performance['DataVersionNumber'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Acceleration Zero To 60Mph</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($performance['Acceleration']['ZeroTo60Mph'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Acceleration Mph</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($performance['Acceleration']['Mph'] ?? '***')) ?>
                            </td>
                        </tr>

                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Acceleration Zero To 100Kph</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($performance['Acceleration']['ZeroTo100Kph'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Acceleration Kph</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">
                                <?= htmlspecialchars((string)($performance['Acceleration']['Kph'] ?? '***')) ?>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>

            <!-- Consumption -->
            <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0" 
                        style="width:100%;border-collapse:separate;
                                border: 2px solid #16a7e0;
                                border-radius: 12px; 
                                font-family:Arial,Helvetica,sans-serif;">
                        <tr>
                            <th colspan="4" 
                                style="border-bottom: 2px solid #dadada;
                                    padding:20px 10px;
                                    box-sizing: border-box;
                                    font-size: 26px;
                                    text-align: center;
                                    color: #716d6a;">
                                Consumption
                            </th>
                        </tr>

                        <!-- Combined -->
                        <tr>
                            <td style="vertical-align: top;text-align: left;
                                    font-weight: bold;font-size: 14px;
                                    padding: 10px;width: 30%;">Combined Mpg</td>
                            <td style="vertical-align: top;text-align: right;
                                    font-size: 14px;padding: 10px;width: 20%;">
                                <?= htmlspecialchars((string)($consumption['Combined']['Mpg'] ?? '***')) ?>
                            </td>
                            <td style="vertical-align: top;text-align: left;
                                    font-weight: bold;font-size: 14px;
                                    padding: 10px;width: 30%;">Combined Lkm</td>
                            <td style="vertical-align: top;text-align: right;
                                    font-size: 14px;padding: 10px;width: 20%;">
                                <?= htmlspecialchars((string)($consumption['Combined']['Lkm'] ?? '***')) ?>
                            </td>
                        </tr>

                        <!-- ExtraUrban -->
                        <tr>
                            <td style="vertical-align: top;text-align: left;
                                    font-weight: bold;font-size: 14px;
                                    padding: 10px;width: 30%;">ExtraUrban Mpg</td>
                            <td style="vertical-align: top;text-align: right;
                                    font-size: 14px;padding: 10px;width: 20%;">
                                <?= htmlspecialchars((string)($consumption['ExtraUrban']['Mpg'] ?? '***')) ?>
                            </td>
                            <td style="vertical-align: top;text-align: left;
                                    font-weight: bold;font-size: 14px;
                                    padding: 10px;width: 30%;">ExtraUrban Lkm</td>
                            <td style="vertical-align: top;text-align: right;
                                    font-size: 14px;padding: 10px;width: 20%;">
                                <?= htmlspecialchars((string)($consumption['ExtraUrban']['Lkm'] ?? '***')) ?>
                            </td>
                        </tr>

                        <!-- UrbanCold -->
                        <tr>
                            <td style="vertical-align: top;text-align: left;
                                    font-weight: bold;font-size: 14px;
                                    padding: 10px;width: 30%;">UrbanCold Mpg</td>
                            <td style="vertical-align: top;text-align: right;
                                    font-size: 14px;padding: 10px;width: 20%;">
                                <?= htmlspecialchars((string)($consumption['UrbanCold']['Mpg'] ?? '***')) ?>
                            </td>
                            <td style="vertical-align: top;text-align: left;
                                    font-weight: bold;font-size: 14px;
                                    padding: 10px;width: 30%;">UrbanCold Lkm</td>
                            <td style="vertical-align: top;text-align: right;
                                    font-size: 14px;padding: 10px;width: 20%;">
                                <?= htmlspecialchars((string)($consumption['UrbanCold']['Lkm'] ?? '***')) ?>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>

            <!-- Plate Change History -->
            <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0" 
                        style="width:100%;border-collapse:separate;
                                border: 2px solid <?= !empty($vehicleData['plateChange']) ? '#FF9800;' : '#4CAF50;' ?>;
                                border-radius: 12px; 
                                font-family:Arial,Helvetica,sans-serif;">
                        
                        <!-- Header -->
                        <tr>
                            <th align="center" colspan="4" 
                                style="border-bottom: 2px solid #dadada;
                                    padding:20px 10px;
                                    box-sizing: border-box;
                                    font-size: 26px;
                                    text-align: center;
                                    color: #716d6a;
                                    vertical-align: middle;">
                                <table cellpadding="0" cellspacing="0" border="0" 
                                    style="border-collapse:collapse;font-family:Arial,Helvetica,sans-serif;margin: 0 auto;">
                                    <tr>
                                        <td style="padding-right: 10px;">
                                            <?php if (!empty($vehicleData['plateChange'])): ?>
                                                <img src="{{ asset('backend/assets/images/alertIcon.png') }}" 
                                                    alt="alertIcon" border="0" width="26" height="26" style="display: block;" />
                                            <?php else: ?>
                                                <img src="{{ asset('backend/assets/images/checkIcon.png') }}" 
                                                    alt="tickIcon" border="0" width="26" height="26" style="display: block;" />
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            Plate Change History
                                        </td>
                                    </tr>
                                </table>
                            </th>
                        </tr>

                        <!-- Plate Change Count -->
                        <tr>
                            <td style="vertical-align: top;text-align: left;
                                    font-weight: bold;font-size: 14px;
                                    padding: 10px;width: 30%;">Plate Change Count</td>
                            <td style="vertical-align: top;text-align: left;
                                    font-size: 14px;padding: 10px;width: 20%;">
                                <?= isset($vehicleMot['motTestList']['plateChange']) 
                                        ? count($vehicleMot['motTestList']['plateChange']) 
                                        : '***' ?>
                            </td>
                            <td style="vertical-align: top;text-align: left;font-size: 14px;
                                    padding: 10px;width: 30%;">&nbsp;</td>
                            <td style="vertical-align: top;text-align: left;font-size: 14px;
                                    padding: 10px;width: 20%;">&nbsp;</td>
                        </tr>

                        <!-- Dynamic Plate Change Rows -->
                        <?php if(isset($vehicleMot['motTestList']['plateChange'])): ?>
                            <?php foreach($vehicleMot['motTestList']['plateChange'] as $index => $pltchang): ?>
                                <tr>
                                    <!-- Serial / Index -->
                                    <td style="vertical-align: middle;text-align: left;
                                            font-weight: bold;font-size: 14px;
                                            padding: 10px;width: 30%;">
                                        <?= $index+1 ?>
                                    </td>

                                    <!-- Date -->
                                    <td style="vertical-align: middle;text-align: left;
                                            font-size: 14px;padding: 10px;width: 20%;">
                                        <?= !empty($pltchang['date']) ? date('d-M-y', strtotime($pltchang['date'])) : '***' ?>
                                    </td>

                                    <!-- Plates Comparison -->
                                    <td colspan="2" style="vertical-align: middle;text-align: left;
                                                        font-size: 14px;padding: 10px;width:80%">
                                        <table cellpadding="0" cellspacing="0" border="0" 
                                            style="text-align: center;font-weight: bold;
                                                    vertical-align: middle;font-size: 14px;margin:0 20%;">
                                            <tr>
                                                <!-- Previous Plate -->
                                                <td>
                                                    <table cellpadding="0" cellspacing="0" border="0" 
                                                        style="width: 100%; border-collapse:separate;
                                                                border: 1px solid #000000;
                                                                font-family:Arial,Helvetica,sans-serif;
                                                                border-radius: 5px;">
                                                        <tr>
                                                            <td style="width: 17px;">
                                                                <img src="{{ asset('backend/assets/images/enter-reg.png') }}" 
                                                                    alt="enter-reg" border="0" width="17" height="34" style="display: block;">
                                                            </td>
                                                            <td style="padding:0 15px;"><?= htmlspecialchars((string)($pltchang['previous'] ?? '***')) ?></td>
                                                        </tr>
                                                    </table>
                                                </td>

                                                <!-- Arrow -->
                                                <td style="width: 17px; ">
                                                    <img src="{{ asset('backend/assets/images/arrowIcon1.png') }}"  
                                                        alt="arrowIcon1" border="0" width="26" height="6" style="display: block; margin:0 10px;" />
                                                </td>

                                                <!-- Current Plate -->
                                                <td>
                                                    <table cellpadding="0" cellspacing="0" border="0" 
                                                        style="width: 100%; border-collapse:separate;
                                                                border: 1px solid #000000;
                                                                font-family:Arial,Helvetica,sans-serif;
                                                                border-radius: 5px;">
                                                        <tr>
                                                            <td style="width: 17px;">
                                                                <img src="{{ asset('backend/assets/images/enter-reg.png') }}" 
                                                                    alt="enter-reg" border="0" width="17" height="34" style="display: block;">
                                                            </td>
                                                            <td style="padding:0 15px;"><?= htmlspecialchars((string)($pltchang['current'] ?? '***')) ?></td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </table>
                </td>
            </tr>

                <!-- Import/Export Section -->
            <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0" 
                        style="width:100%;border-collapse:separate;border: 2px solid <?= !empty($importExport['imported']) ? '#F44336;' : '#4CAF50;' ?>;
                                border-radius: 12px; font-family:Arial,Helvetica,sans-serif;">
                        
                        <!-- Header -->
                        <tr>
                            <th align="center" colspan="4" 
                                style="text-align: center; border-bottom: 2px solid #dadada;
                                    padding:20px 10px;box-sizing: border-box;font-size: 26px;
                                    color: #716d6a;vertical-align: middle;font-family:Arial,Helvetica,sans-serif;">
                                <table cellpadding="0" cellspacing="0" border="0" 
                                    style="border-collapse:collapse;font-family:Arial,Helvetica,sans-serif;margin: 0 auto;">
                                    <tr>
                                        <td style="padding-right: 10px;">
                                            @if(!empty($importExport['exported']) || !empty($importExport['imported']))
                                                <img src="{{ asset('backend/assets/images/closeIcon.png') }}" 
                                                    alt="alertIcon" border="0" width="26" height="26" style="display: block;" />
                                            @else
                                                <img src="{{ asset('backend/assets/images/checkIcon.png') }}" 
                                                    alt="checkIcon" border="0" width="26" height="26" style="display: block;" />
                                            @endif
                                        </td>
                                        <td>
                                            Import/Export
                                        </td>
                                    </tr>
                                </table>
                            </th>
                        </tr>

                        <!-- Exported Row -->
                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;
                                    font-size: 14px;padding: 10px;width: 30%;">Exported</td>
                            <td style="vertical-align: top;text-align: right;font-weight: bold;
                                    font-size: 14px;padding: 10px;width: 20%;">
                                {{ !empty($importExport['exported']) ? 'Yes' : 'No' }}
                            </td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;
                                    font-size: 14px;padding: 10px;width: 30%;">Export Date</td>
                            <td style="vertical-align: top;text-align: right;font-weight: bold;
                                    font-size: 14px;padding: 10px;width: 20%;">
                                {{ !empty($importExport['dateExported']) ? date('d-M-y', strtotime($importExport['dateExported'])) : '***' }}
                            </td>
                        </tr>

                        <!-- Imported Row -->
                        <tr>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;
                                    font-size: 14px;padding: 10px;width: 30%;">Imported</td>
                            <td style="vertical-align: top;text-align: right;font-weight: bold;
                                    font-size: 14px;padding: 10px;width: 20%;">
                                {{ !empty($importExport['imported']) ? 'Yes' : 'No' }}
                            </td>
                            <td style="vertical-align: top;text-align: left;font-weight: bold;
                                    font-size: 14px;padding: 10px;width: 30%;">&nbsp;</td>
                            <td style="vertical-align: top;text-align: right;font-weight: bold;
                                    font-size: 14px;padding: 10px;width: 20%;">&nbsp;</td>
                        </tr>
                    </table>
                </td>
            </tr>

            <!-- Scrap Destructions -->
            <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0"
                        style="width:100%;border-collapse:separate;border: 2px solid <?= !empty($scrapDestruction['scrapped']) ? '#F44336;' : '#4CAF50;' ?>;
                            border-radius: 12px; font-family:Arial,Helvetica,sans-serif;">
                        <!-- Header -->
                        <tr>
                            <th colspan="4"
                                style="border-bottom: 2px solid #dadada;padding:20px 10px;
                                    font-size: 26px;text-align: center;color: #716d6a;">
                                <table cellpadding="0" cellspacing="0" border="0"
                                    style="border-collapse:collapse;margin: 0 auto;">
                                    <tr>
                                        <td style="padding-right: 10px;">
                                            <?php if(!empty($scrapDestruction['scrapped'])){ ?> 
                                                <img src="{{ asset('backend/assets/images/closeIcon.png') }}"
                                                alt="checkIcon" border="0" width="26" height="26" style="display: block;" />                                         
                                                <?php }else{ ?>

                                                   <img src="{{ asset('backend/assets/images/checkIcon.png') }}"
                                                alt="checkIcon" border="0" width="26" height="26" style="display: block;" />

                                                <?php } ?>
                                        </td>
                                        <td>Scrap Destructions</td>
                                    </tr>
                                </table>
                            </th>
                        </tr>
                        <!-- Rows -->
                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Scrapped</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ !empty($scrapDestruction['scrapped']) ? 'Yes' : 'No' }}</td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Date of Scrapped</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $scrapDestruction['dateofScapped'] ? date('d-M-y', strtotime($scrapDestruction['dateofScapped'])) :'***' }}</td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Certificate of Destruction Issued</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ !empty($scrapDestruction['certificateofDestructionIssued']) ? 'Yes' : 'No' }}</td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Vehicle ID Check Count</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $scrapDestruction['vehicleIdCheckCount'] ?? '***' }}</td>
                        </tr>
                    </table>
                </td>
            </tr>

            <!-- Colour Changes -->
            <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0"
                        style="width:100%;border-collapse:separate;border: 2px solid <?= $colourChange['NumberOfPreviousColours'] ? '#F44336;' : '#4CAF50;' ?>;
                            border-radius: 12px; font-family:Arial,Helvetica,sans-serif;">
                        <!-- Header -->
                        <tr>
                            <th colspan="4"
                                style="border-bottom: 2px solid #dadada;padding:20px 10px;
                                    font-size: 26px;text-align: center;color: #716d6a;">
                                <table cellpadding="0" cellspacing="0" border="0"
                                    style="border-collapse:collapse;margin: 0 auto;">
                                    <tr>
                                        <td style="padding-right: 10px;">
                                            <?php if($colourChange['NumberOfPreviousColours']){ ?>
                                                                                                                                                <img src="{{ asset('backend/assets/images/closeIcon.png') }}"
                                                alt="checkIcon" border="0" width="26" height="26" style="display: block;" />
                                                 <?php }else{ ?>

                                                                                           <img src="{{ asset('backend/assets/images/checkIcon.png') }}"
                                                alt="checkIcon" border="0" width="26" height="26" style="display: block;" />

                                                    <?php } ?>
                                        </td>
                                        <td>Colour Changes</td>
                                    </tr>
                                </table>
                            </th>
                        </tr>
                        <!-- Rows -->
                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Current Colour</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $colourChange['CurrentColour'] ?? '***' }}</td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Number Of Previous Colours</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $colourChange['NumberOfPreviousColours'] ?? '***' }}</td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Last Colour</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $colourChange['LastColour'] ?? '***' }}</td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Date Of Last Colour Change</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $colourChange['DateOfLastColourChange'] ? date('d-M-y', strtotime($colourChange['DateOfLastColourChange'])) :'***' }}</td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Original Colour</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $colourChange['OriginalColour'] ?? '***' }}</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                    </table>
                </td>
            </tr>

            <!-- Previous VRM -->
            <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0"
                        style="width:100%;border-collapse:separate;border: 2px solid <?= isset($vehicleInformation['PreviousVrmNi']) ? '#F44336' : '#4CAF50' ?>;
                            border-radius: 12px; font-family:Arial,Helvetica,sans-serif;">
                        <!-- Header -->
                        <tr>
                            <th colspan="4"
                                style="border-bottom: 2px solid #dadada;padding:20px 10px;
                                    font-size: 26px;text-align: center;color: #716d6a;">
                                <table cellpadding="0" cellspacing="0" border="0"
                                    style="border-collapse:collapse;margin: 0 auto;">
                                    <tr>
                                        <td style="padding-right: 10px;">
                                            <img src="{{ asset('backend/assets/images/checkIcon.png') }}"
                                                alt="checkIcon" border="0" width="26" height="26" style="display: block;" />
                                        </td>
                                        <td>Previous VRM</td>
                                    </tr>
                                </table>
                            </th>
                        </tr>
                        <!-- Rows -->
                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Previous Northern Ireland</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $vehicleInformation['PreviousVrmNi'] ?? '***' }}</td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Previous UK VRM</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $vehicleInformation['PreviousVrmGb'] ?? '***' }}</td>
                        </tr>
                    </table>
                </td>
            </tr>

            <!-- Dimensions -->
            <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0"
                        style="width:100%;border-collapse:separate;border: 2px solid #16a7e0;
                            border-radius: 12px; font-family:Arial,Helvetica,sans-serif;">
                        <!-- Header -->
                        <tr>
                            <th colspan="4"
                                style="border-bottom: 2px solid #dadada;padding:20px 10px;
                                    font-size: 26px;text-align: center;color: #716d6a;">
                                Dimensions
                            </th>
                        </tr>
                        <!-- Rows -->
                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Gross Vehicle Weight</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $dimensions['GrossVehicleWeight'] ?? '***' }}</td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Height</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $dimensions['Height'] ?? '***' }}</td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Gross Combined Weight</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $dimensions['GrossCombinedWeight'] ?? '***' }}</td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Width</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $dimensions['Width'] ?? '***' }}</td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Kerb Weight</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $dimensions['KerbWeight'] ?? '***' }}</td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Car Length</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $dimensions['CarLength'] ?? '***' }}</td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Unladen Weight</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $dimensions['UnladenWeight'] ?? '***' }}</td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Wheel Base</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $dimensions['WheelBase'] ?? '***' }}</td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Fuel Tank Capacity</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $dimensions['FuelTankCapacity'] ?? '***' }}</td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Pay Load Weight</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $dimensions['PayLoadWeight'] ?? '***' }}</td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Number Of Doors</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $dimensions['NumberOfDoors'] ?? '***' }}</td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Gross Train Weight</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $dimensions['GrossTrainWeight'] ?? '***' }}</td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Number Of Seats</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $dimensions['NumberOfSeats'] ?? '***' }}</td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Payload Volume</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $dimensions['PayloadVolume'] ?? '***' }}</td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Rigid Artic</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $dimensions['RigidArtic'] ?? '***' }}</td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Load Length</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $dimensions['LoadLength'] ?? '***' }}</td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Number Of Axles</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $dimensions['NumberOfAxles'] ?? '***' }}</td>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Data Version Number</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $dimensions['DataVersionNumber'] ?? '***' }}</td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;font-size: 14px;padding: 10px;">Body Shape</td>
                            <td style="text-align: right;font-size: 14px;padding: 10px;">{{ $dimensions['BodyShape'] ?? 'NA' }}</td>
                            
                        </tr>
                    </table>
                </td>
            </tr>


            <!-- Safety -->
            <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0" 
                        style="width:100%;border-collapse:separate;
                                border: 2px solid #16a7e0;border-radius: 12px;
                                font-family:Arial,Helvetica,sans-serif;">
                        <tr>
                            <th colspan="4" 
                                style="border-bottom: 2px solid #dadada;
                                    padding:20px 10px;box-sizing: border-box;
                                    font-size: 26px;text-align: center;
                                    color: #716d6a;">Safety</th>
                        </tr>
                        <tr>
                            <td style="vertical-align: top;text-align: left;
                                    font-weight: bold;font-size: 14px;
                                    padding: 10px;width: 30%;">Adult</td>
                            <td style="vertical-align: top;text-align: right;
                                    font-size: 14px;padding: 10px;width: 20%;">
                                <?= htmlspecialchars((string)($safety['EuroNcap']['Adult'] ?? '***')) ?>
                            </td>
                            <td style="vertical-align: top;text-align: left;
                                    font-weight: bold;font-size: 14px;
                                    padding: 10px;width: 30%;">Child</td>
                            <td style="vertical-align: top;text-align: right;
                                    font-size: 14px;padding: 10px;width: 20%;">
                                <?= htmlspecialchars((string)($safety['EuroNcap']['Child'] ?? '***')) ?>
                            </td>
                        </tr>
                        <tr>
                            <td style="vertical-align: top;text-align: left;
                                    font-weight: bold;font-size: 14px;
                                    padding: 10px;width: 30%;">Pedestrian</td>
                            <td style="vertical-align: top;text-align: right;
                                    font-size: 14px;padding: 10px;width: 20%;">
                                <?= htmlspecialchars((string)($safety['EuroNcap']['Pedestrian'] ?? '***')) ?>
                            </td>
                            <td style="vertical-align: top;text-align: left;
                                    font-weight: bold;font-size: 14px;
                                    padding: 10px;width: 30%;">&nbsp;</td>
                            <td style="vertical-align: top;text-align: right;
                                    font-size: 14px;padding: 10px;width: 20%;">&nbsp;</td>
                        </tr>
                    </table>
                </td>
            </tr>

            <!-- Classification Details -->
            <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0" 
                        style="width:100%;border-collapse:separate;
                                border: 2px solid #16a7e0;border-radius: 12px;
                                font-family:Arial,Helvetica,sans-serif;">
                        <tr>
                            <th colspan="4" style="border-bottom: 2px solid #dadada;
                                                padding:20px 10px;box-sizing: border-box;
                                                font-size: 26px;text-align: center;
                                                color: #716d6a;">Classification Details</th>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">SMMT Make</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($classificationDetails['Smmt']['Make'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">DVLA Make</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($classificationDetails['Dvla']['Make'] ?? '***')) ?>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">SMMT Range</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($classificationDetails['Smmt']['Range'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">DVLA Model</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($classificationDetails['Dvla']['Model'] ?? '***')) ?>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">SMMT Trim</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($classificationDetails['Smmt']['Trim'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">Is Electric Vehicle</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($classificationDetails['Ukvd']['IsElectricVehicle'] ?? '***')) ?>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">SMMT Mvris MakeCode</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($classificationDetails['Smmt']['Mvris']['MakeCode'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">Is GB General Format</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($classificationDetails['VrmFormat']['IsGBGeneralFormat'] ?? '***')) ?>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">SMMT Mvris ModelCode</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($classificationDetails['Mvris']['ModelCode'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">Is NI General Format</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($classificationDetails['VrmFormat']['IsNIGeneralFormat'] ?? '***')) ?>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>




            <!-- Smmt Details -->
              <!-- Smmt Details -->
           <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0" 
                        style="width:100%;border-collapse:separate;
                                border: 2px solid #16a7e0;border-radius: 12px;
                                font-family:Arial,Helvetica,sans-serif;">
                        <tr>
                            <th colspan="4" style="border-bottom: 2px solid #dadada;
                                                padding:20px 10px;box-sizing: border-box;
                                                font-size: 26px;text-align: center;
                                                color: #716d6a;">Smmt Details</th>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">Marque</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($smmtDetails['Marque'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">Range</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($smmtDetails['Range'] ?? '***')) ?>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">Model Variant</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($smmtDetails['ModelVariant'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">Fuel Type</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($smmtDetails['FuelType'] ?? '***')) ?>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">Nominal Engine Capacity</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($smmtDetails['NominalEngineCapacity'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">Transmission</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($smmtDetails['Transmission'] ?? '***')) ?>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">Engine Capacity</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($smmtDetails['EngineCapacity'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">Number Of Doors</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($smmtDetails['NumberOfDoors'] ?? '***')) ?>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">Body Style</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($smmtDetails['BodyStyle'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">Number Of Gears</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($smmtDetails['NumberOfGears'] ?? '***')) ?>
                            </td>
                        </tr>

                         <tr>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">DriveType</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($smmtDetails['DriveType'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">SysSetup Date</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= $smmtDetails['SysSetupDate'] ? date('d-M-y', strtotime($smmtDetails['SysSetupDate'])):'***' ?>
                            </td>
                        </tr>
                         <tr>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">Country Of Origin</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($smmtDetails['CountryOfOrigin'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">Visibility Date</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= $smmtDetails['VisibilityDate'] ? date('d-M-y', strtotime($smmtDetails['VisibilityDate'])):'***' ?>
                            </td>
                        </tr>
                         <tr>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">Series</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($smmtDetails['Series'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">TerminateDate</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= $smmtDetails['TerminateDate'] ? date('d-M-y', strtotime($smmtDetails['TerminateDate'])):'***' ?>
                            </td>
                        </tr>
                         <tr>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">Marque Code</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($smmtDetails['MarqueCode'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">Cab Type</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($smmtDetails['CabType'] ?? '***')) ?>
                            </td>
                        </tr>
                         <tr>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">Market Sector Code</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($smmtDetails['MarketSectorCode'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">Data Version Number</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($smmtDetails['DataVersionNumber'] ?? '***')) ?>
                            </td>
                        </tr>
                         <tr>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;">Model Code</td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                                <?= htmlspecialchars((string)($smmtDetails['ModelCode'] ?? '***')) ?>
                            </td>
                            <td style="font-weight: bold;padding:10px;width:30%;
                                    font-size:14px;"></td>
                            <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"></td>
                        </tr>
                    </table>
                </td>
            </tr>

 <?php if(!empty($vehicleMot['electricVehicleData'])){ ?>
            <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:separate;
                                border: 2px solid #16a7e0;border-radius: 12px;
                                font-family:Arial,Helvetica,sans-serif;">
                        <tbody><tr>
                            <th colspan="4" style="border-bottom: 2px solid #dadada;
                                                padding:20px 10px;box-sizing: border-box;
                                                font-size: 26px;text-align: center;
                                                color: #716d6a;">Electrical Vehicle Data</th>
                        </tr>


        <!-- Each row: Label + Value -->
        <tr>
          <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Watt-Hours / Mile</td>
          <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)(isset($vehicleMot['electricVehicleData']['WhMile'])?  $vehicleMot['electricVehicleData']['WhMile']:'***')) ?></td>
       
          <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Max Miles per Charge Hour</td>
          <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)(isset($vehicleMot['electricVehicleData']['MaxMilesPerChargeHour'])?  $vehicleMot['electricVehicleData']['MaxMilesPerChargeHour']:'***')) ?></td>
        </tr>
        <tr >
          <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Zero Emission Miles</td>
          <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)(isset($vehicleMot['electricVehicleData']['ZeroEmissionMiles'])?  $vehicleMot['electricVehicleData']['ZeroEmissionMiles']:'***')) ?></td>

          
          <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Max Miles per Charge Minute</td>
          <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)(isset($vehicleMot['electricVehicleData']['MaxMilesPerChargeMinute'])?  $vehicleMot['electricVehicleData']['MaxMilesPerChargeMinute']:'***')) ?></td>
        </tr>
        <tr>
          <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Manufacturer Warranty Miles</td>
          <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)(isset($vehicleMot['electricVehicleData']['ManufacturerWarrantyMiles'])?  $vehicleMot['electricVehicleData']['ManufacturerWarrantyMiles']:'***')) ?></td>
       
          <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Vehicle Type</td>
          <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)(isset($vehicleMot['electricVehicleData']['VehicleType'])?  $vehicleMot['electricVehicleData']['VehicleType']:'***')) ?></td>
        </tr>
        <tr >
          <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Manufacturer Warranty Months</td>
          <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)(isset($vehicleMot['electricVehicleData']['ManufacturerWarrantyMonths'])?  $vehicleMot['electricVehicleData']['ManufacturerWarrantyMonths']:'***')) ?></td>
       
          <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Tesla Supercharger Compatible</td>
          <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)(isset($vehicleMot['electricVehicleData']['TeslaSuperchargerCompatible'])?  $vehicleMot['electricVehicleData']['TeslaSuperchargerCompatible']:'***')) ?></td>
        </tr>
        <tr>
          <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Max Range Miles</td>
          <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)(isset($vehicleMot['electricVehicleData']['MaxRangeMiles'])?  $vehicleMot['electricVehicleData']['MaxRangeMiles']:'***')) ?></td>
       
          <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Max KW Charge Input</td>
          <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)(isset($vehicleMot['electricVehicleData']['MaxKwChargeInput'])?  $vehicleMot['electricVehicleData']['MaxKwChargeInput']:'***')) ?></td>
        </tr>
        <tr >
          <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Max Range Km</td>
          <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)(isset($vehicleMot['electricVehicleData']['MaxRangeKm'])?  $vehicleMot['electricVehicleData']['MaxRangeKm']:'***')) ?></td>
       
          <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">OTA Upgradable</td>
          <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)(isset($vehicleMot['electricVehicleData']['OtaUpgradable'])? 'TRUE':'FALSE')) ?></td>
        </tr>
        <tr>
          <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">CO2</td>
          <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)(isset($vehicleMot['electricVehicleData']['Co2'])?  $vehicleMot['electricVehicleData']['Co2']:'***')) ?> g/km</td>
       
          <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Latest OTA Version</td>
          <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)(isset($vehicleMot['electricVehicleData']['LatestOtaVersion'])?  $vehicleMot['electricVehicleData']['LatestOtaVersion']:'***')) ?></td>
        </tr>
        <tr >
          <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Drag Coefficient</td>
          <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)(isset($vehicleMot['electricVehicleData']['DragCoefficient'])?  $vehicleMot['electricVehicleData']['DragCoefficient']:'***')) ?></td>
       
          <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Hardware Version</td>
          <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)(isset($vehicleMot['electricVehicleData']['HwVersion'])?  $vehicleMot['electricVehicleData']['HwVersion']:'***')) ?></td>
        </tr>
        <tr>
          <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Drivetrain Version Description</td>
          <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)(isset($vehicleMot['electricVehicleData']['DrivetrainVersionDescription'])?  $vehicleMot['electricVehicleData']['DrivetrainVersionDescription']:'***')) ?></td>
       
          <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Is Electric Vehicle</td>
          <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)(isset($vehicleMot['electricVehicleData']['Identification']['IsElectricVehicle']) ? 'YES' : 'NO' )) ?></td>
        </tr>

      </table>
    </div>
  </td>
</tr>
<?php } ?>


<?php if (!empty($vehicleMot['electricVehicleData']['BatteryDetailsList'])): ?>
  <?php foreach ($vehicleMot['electricVehicleData']['BatteryDetailsList'] as $index => $battery): ?>
  
     <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:separate;
                                border: 2px solid #16a7e0;border-radius: 12px;
                                font-family:Arial,Helvetica,sans-serif;">
                        <tbody><tr>
                            <th colspan="4" style="border-bottom: 2px solid #dadada;
                                                padding:20px 10px;box-sizing: border-box;
                                                font-size: 26px;text-align: center;
                                                color: #716d6a;"> Battery Details - <?= $index + 1 ?></th>
                        </tr>
           

            <!-- Each row: Label + Value -->
            <tr>
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Capacity KWH</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;" ><?= htmlspecialchars((string)($battery['CapacityKwh'] ?? '***')) ?></td>
            

              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Chemistry</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($battery['Chemistry'] ?? '***')) ?></td>
            <tr >                
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Battery Description</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($battery['BatteryDescription'] ?? '***')) ?></td>
            
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Battery Location</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($battery['BatteryLocation'] ?? '***')) ?></td>
            </tr>
            <tr>
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Voltage</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($battery['Voltage'] ?? '***')) ?></td>
            
            
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Battery Warranty Miles</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;" >
                <?= htmlspecialchars((string)($battery['BatteryWarrantyMonths'] ?? '***')) ?> months /
                <?= htmlspecialchars((string)($battery['BatteryWarrantyMiles'] ?? '***')) ?>
              </td>
            </tr>

<tr >
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Battery Warranty Months</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($battery['BatteryWarrantyMonths'] ?? '***')) ?></td>
            

            <?php if ($index === 0): ?>
                <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Battery Details Count</td>
                <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;" ><?= htmlspecialchars((string)($vehicleMot['electricVehicleData']['BatteryDetailsCount'] ?? '***')) ?></td>
                                           
              <?php endif; ?>
            </tr>

          </table>
        </div>
      </td>
    </tr>
  <?php endforeach; ?>
<?php endif; ?>






                    <!-- MOT Test List -->


                    <?php if (!empty($vehicleMot['electricVehicleData']['ChargePortDetailsList'])): ?>
  <?php foreach ($vehicleMot['electricVehicleData']['ChargePortDetailsList'] as $index => $port): ?>
    
    <!-- Charge Port Details Card -->
       <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:separate;
                                border: 2px solid #16a7e0;border-radius: 12px;
                                font-family:Arial,Helvetica,sans-serif;">
                        <tbody><tr>
                            <th colspan="4" style="border-bottom: 2px solid #dadada;
                                                padding:20px 10px;box-sizing: border-box;
                                                font-size: 26px;text-align: center;
                                                color: #716d6a;"> Charge Port Details - <?= $index + 1 ?></th>
                        </tr>
           
        
            <!-- Key/Value Rows -->
            <tr>
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Port Type</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($port['PortType'] ?? '***')) ?></td>

              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Max Charge Power Kw</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($port['MaxChargePowerKw'] ?? '***')) ?></td>
            </tr>

            <tr >
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Port Location</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($port['PortLocation'] ?? '***')) ?></td>

              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Charge Port Count</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($vehicleMot['electricVehicleData']['ChargePortCount'] ?? '***')) ?></td>
            </tr>

            <?php if ($index === 0): ?>
              <tr>
                <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Charge Port Details Count</td>
                <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;" colspan="3"><?= htmlspecialchars((string)($vehicleMot['electricVehicleData']['ChargePortDetailsCount'] ?? '***')) ?></td>
              </tr>
            <?php endif; ?>

          </table>
        </div>
      </td>
    </tr>

    <!-- Charge Times Table -->
    <?php if (!empty($port['ChargeTimes']['AverageChargeTimes10To80Percent'])): ?>
        <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:separate;
                                border: 2px solid #16a7e0;border-radius: 12px;
                                font-family:Arial,Helvetica,sans-serif;">
                        <tbody><tr>
                            <th colspan="4" style="border-bottom: 2px solid #dadada;
                                                padding:20px 10px;box-sizing: border-box;
                                                font-size: 26px;text-align: center;
                                                color: #716d6a;">Average Charge Times 10 To 80 Percent</th>
                        </tr>

              <!-- Charge Times -->
              <?php foreach ($port['ChargeTimes']['AverageChargeTimes10To80Percent'] as $time): ?>
                <tr>
                  <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Charge Port Kw</td>
                  <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($time['ChargePortKw'] ?? '***')) ?></td>

                  <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Time In Minutes</td>
                  <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($time['TimeInMinutes'] ?? 0)) ?></td>
                </tr>
              <?php endforeach; ?>

            </table>
          </div>
        </td>
      </tr>
    <?php endif; ?>

  <?php endforeach; ?>
<?php endif; ?>


<?php if (!empty($vehicleMot['electricVehicleData']['MotorDetailsList'])): ?>
  <?php foreach ($vehicleMot['electricVehicleData']['MotorDetailsList'] as $index => $motor): ?>
    <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:separate;
                                border: 2px solid #16a7e0;border-radius: 12px;
                                font-family:Arial,Helvetica,sans-serif;">
                        <tbody><tr>
                            <th colspan="4" style="border-bottom: 2px solid #dadada;
                                                padding:20px 10px;box-sizing: border-box;
                                                font-size: 26px;text-align: center;
                                                color: #716d6a;"> Motor Details List - <?= $index + 1 ?></th>
                        </tr>

           

            <!-- Rows: Label + Value -->
            <tr>
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Manufacturer</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($motor['Manufacturer'] ?? '***')) ?></td>
          
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Motor Type</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($motor['MotorType'] ?? '***')) ?></td>
  </tr>

            <tr >
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Model</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($motor['Model'] ?? '***')) ?></td>
            
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Power Kw</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($motor['PowerKw'] ?? '***')) ?></td>
</tr>

            <tr>
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Max Torque Nm</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($motor['MaxTorqueNm'] ?? '***')) ?></td>
           
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Regenerative Braking</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;">
                <?= (!empty($motor['RegenBraking']) && $motor['RegenBraking']) ? 'Yes' : 'No' ?>
              </td>
               </tr>

            <tr >

              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Motor Location</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($motor['MotorLocation'] ?? '***')) ?></td>

              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Max Power RPM</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($motor['MaxPowerRpm'] ?? '***')) ?></td>
            </tr>

            <tr style="">
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Additional Info</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($motor['AdditionalInformation'] ?? '***')) ?></td>
           
            <?php if ($index === 0): ?>
             
                <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Motor Details Count</td>
                <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($vehicleMot['electricVehicleData']['MotorDetailsCount'] ?? '***')) ?></td>
              </tr>
            <?php endif; ?>

          </table>
        </div>
      </td>
    </tr>
  <?php endforeach; ?>
<?php endif; ?>



<?php if (!empty($vehicleMot['electricVehicleData']['TransmissionDetailsList'])): ?>
  <?php foreach ($vehicleMot['electricVehicleData']['TransmissionDetailsList'] as $index => $item): ?>
    <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:separate;
                                border: 2px solid #16a7e0;border-radius: 12px;
                                font-family:Arial,Helvetica,sans-serif;">
                        <tbody><tr>
                            <th colspan="4" style="border-bottom: 2px solid #dadada;
                                                padding:20px 10px;box-sizing: border-box;
                                                font-size: 26px;text-align: center;
                                                color: #716d6a;">  Transmission Details - <?= $index + 1 ?></th>
                        </tr>

        

            <tr>
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px; width:50%; font-size:14px;">Transmission Type</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($item['TransmissionType'] ?? '***')) ?></td>
         
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Number of Gears</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($item['NumberOfGears'] ?? '***')) ?></td>
   </tr>

            <tr >
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Transmission Location</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($item['TransmissionLocation'] ?? '***')) ?></td>
           
            <?php if ($index === 0): ?>
           
                <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Transmission Details Count</td>
                <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($vehicleMot['electricVehicleData']['TransmissionDetailsCount'] ?? '***')) ?></td>
              </tr>
            <?php endif; ?>

          </table>
        </div>
      </td>
    </tr>
  <?php endforeach; ?>
<?php endif; ?>

<?php if (!empty($vehicleMot['electricVehicleData']['RangeFigures']['RangeTestCycleDetailsList'])): ?>
  <?php foreach ($vehicleMot['electricVehicleData']['RangeFigures']['RangeTestCycleDetailsList'] as $index => $range): ?>
    <tr>
                <td style="vertical-align: top;padding-bottom: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:separate;
                                border: 2px solid #16a7e0;border-radius: 12px;
                                font-family:Arial,Helvetica,sans-serif;">
                        <tbody><tr>
                            <th colspan="4" style="border-bottom: 2px solid #dadada;
                                                padding:20px 10px;box-sizing: border-box;
                                                font-size: 26px;text-align: center;
                                                color: #716d6a;">  Range Test Cycle Details List</th>
                        </tr>

            <tr>
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px; width:50%; font-size:14px;">Combined Range Miles</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;" ><?= htmlspecialchars((string)($range['CombinedRangeMiles'] ?? '***')) ?></td>
          
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">City Range Miles</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($range['CityRangeMiles'] ?? '***')) ?></td>
  </tr>

            <tr >
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">Combined Range KM</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($range['CombinedRangeKm'] ?? '***')) ?></td>
          
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">City Range KM</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($range['CityRangeKm'] ?? '***')) ?></td>
  </tr>

            <tr>
              <td style="font-weight: bold;padding:10px;width:30%; font-size:14px;">EV Range Test Type</td>
              <td style="text-align:right;padding:10px;width:20%;
                                    font-size:14px;"><?= htmlspecialchars((string)($range['EvRangeTestType'] ?? '***')) ?></td>
            </tr>

          </table>
        </div>
      </td>
    </tr>
  <?php endforeach; ?>
<?php endif; ?>


            <!-- MOT Test List -->
            <tr>
                <td align="center" style="text-align: center;font-size: 26px;color: #716d6a;padding: 25px 0 20px;font-family:Arial,Helvetica,sans-serif;vertical-align: middle;">
                    <table cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;font-family:Arial,Helvetica,sans-serif;margin: 0 auto;">
                        <tr>
                            <td style="padding-right: 10px;">
                                <img src="{{ asset('backend/assets/images/icon04.png') }}" alt="MOT Test List" border="0" width="40" height="35" style="display: block;" />
                            </td>
                            <td>
                                <strong>MOT Test List</strong>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <!-- Table Header -->
                    <table cellpadding="0" cellspacing="0" border="0" 
                        style="width:100%;border-collapse:collapse;
                            font-family:Arial,Helvetica,sans-serif;
                            background-color: #999999;border-radius: 12px 12px 0 0;">
                        <tr>
                            <th style="color:#fff;font-size:14px;padding:15px;text-align:center;width:16%;border-right:1px solid #fff;">Date</th>
                            <th style="color:#fff;font-size:14px;padding:15px;text-align:center;width:20%;border-right:1px solid #fff;">Result</th>
                            <th style="color:#fff;font-size:14px;padding:15px;text-align:center;width:16%;border-right:1px solid #fff;">Mileage</th>
                            <th style="color:#fff;font-size:14px;padding:15px;text-align:center;width:16%;border-right:1px solid #fff;">Test Number</th>
                        </tr>
                    </table>
                </td>
            </tr>

            <?php foreach (($vehicleMot['motTestList']['motList'] ?? []) as $test): ?>
            <?php
                $isPass = isset($test['result']) && strtoupper($test['result']) === 'PASSED';
                $borderColor = $isPass ? '#5ab31b' : '#f22d1c';
                $icon = $isPass 
                    ? asset('backend/assets/images/checkIcon.png') 
                    : asset('backend/assets/images/closeIcon.png');

                $date = !empty($test['date']) ? date('d-M-y', strtotime($test['date'])) : '***';
                $mileage = !empty($test['mileage']) ? $test['mileage'].' '.($test['unit'] ?? '') : '***';
                $testNo = $test['motTesNumber'] ?? '***';
            ?>
       <tr>
    <!-- Summary Row -->
    <td style="padding-top:15px;">
        <table cellpadding="0" cellspacing="0" border="0" 
            style="width:100%;border-collapse:separate;
                border:2px solid <?=$borderColor?>;
                font-family:Arial,Helvetica,sans-serif;
                border-radius:12px;">
            <tr>
                <!-- Date -->
                <td style="font-size:14px;padding:15px;text-align:center;font-weight:bold;width:16%;box-sizing:border-box;">
                    <?=htmlspecialchars($date)?>
                </td>

                <!-- Result -->
                <td style="padding:15px 5px;text-align:center;font-weight:bold;width:20%;box-sizing:border-box;">
                    <table cellpadding="0" cellspacing="0" border="0" 
                        style="width:100%;border-collapse:separate;
                            border:2px solid <?=$borderColor?>;
                            border-radius:12px;margin:0 auto;">
                        <tr>
                            <td style="border-right:2px solid <?=$borderColor?>;padding:5px;width:42px;">
                                <img src="<?=$icon?>" width="26" height="26" alt="<?= $isPass ? 'PASS' : 'FAIL' ?>" style="display:block;" />
                            </td>
                            <td style="padding:5px;"><?= $isPass ? 'PASS' : 'FAIL' ?></td>
                        </tr>
                    </table>
                </td>

                <!-- Mileage -->
                <td style="font-size:14px;padding:15px;text-align:center;font-weight:bold;width:16%;">
                    <?=htmlspecialchars($mileage)?>
                </td>

                <!-- Test Number -->
                <td style="font-size:14px;padding:15px;text-align:center;font-weight:bold;width:16%;">
                    <?=htmlspecialchars($testNo)?>
                </td>
            </tr>
        </table>
    </td>
</tr>

<!-- Details Row -->
<tr>
    <td style="padding:10px 20px; border-radius:0 0 12px 12px;">
        <?php if (!empty($test['advisory'])): ?>
            <div style="margin-bottom:12px;">
                <div style="font-size:15px; font-weight:bold; margin-bottom:6px;">Advisories</div>
                <?php foreach ($test['advisory'] as $adv): ?>
                    <div style="margin-bottom:6px;">
                        <?php if (!empty($adv['type'])): ?>
                            <span style="background:<?= htmlspecialchars($adv['type'])=="USER ENTERED"? '#16aad6':($adv['type']=="MINOR"? '#5ab31b':'#f19e23;') ?>; color:#fff; font-size:14px; font-weight:bold; padding:3px 8px; border-radius:4px; margin-right:6px;">
                                <?= htmlspecialchars($adv['type']) ?>
                            </span>
                        <?php endif; ?>
                        <span style="font-size:15px"><?= htmlspecialchars($adv['text'] ?? '') ?></span>
                    </div>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>

       

        <?php if (!empty($test['failure'])): ?>
            <div>
                <div style="font-size:15px; font-weight:bold; margin-bottom:6px;">Failures</div>
                <?php foreach ($test['failure'] as $fail): ?>
                    <div style="margin-bottom:6px;">
                        <?php if (!empty($fail['type'])): ?>
                            <span style="background:#d9534f; color:#fff; font-size:14px; font-weight:bold; padding:3px 8px; border-radius:4px; margin-right:6px;">
                                <?= htmlspecialchars($fail['type']) ?>
                            </span>
                        <?php endif; ?>
                        <span style="font-size:15px"><?= htmlspecialchars($fail['text'] ?? '') ?></span>
                    </div>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>

         <?php if (!empty($test['prsText'])): ?>
            <div style="margin-bottom:12px;">
                 <?php if (empty($test['failure']) && !empty($test['prsText'])){ ?>
                <div style="font-size:15px; font-weight:bold; margin-bottom:6px;">Failures</div>
                <?php } ?>

                <?php foreach ($test['prsText'] as $prs): ?>
                    <div style="margin-bottom:6px;">
                        <span style="background:#297dc5; color:#fff; font-size:14px; font-weight:bold; padding:3px 8px; border-radius:4px; margin-right:6px;">
                            PRS
                        </span>
                       <span style="font-size:15px"> <?= htmlspecialchars($prs['text'] ?? '') ?></span>
                    </div>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>
    </td>
</tr>

            <?php endforeach; ?>


             <!-- Disclaimer -->
            <tr>
                <td style="padding-top: 30px;">
                    <table cellpadding="0" cellspacing="0" border="0" 
                        style="width:100%;border-collapse:collapse;
                                font-family:Arial,Helvetica,sans-serif;
                                border-radius:20px;
                                background-color:#edf7f9;">
                        <!-- Heading -->
                        <tr>
                            <th style="text-align:center;color:#000000;
                                    font-size:20px;
                                    padding:20px;">
                                Disclaimer
                            </th>
                        </tr>
                        <!-- Content Rows -->
                        <tr>
                            <td style="font-size:14px;padding:0 20px 15px;line-height:1.6;">
                                CarBaBa provides free vehicle data but does not guarantee its precision. 
                                Although we strive to maintain up-to-date and accurate information, we are not 
                                responsible for any discrepancies, errors, or omissions. Users should independently 
                                verify details before making transactions and assume complete responsibility 
                                and liability for how they utilize the data.
                            </td>
                        </tr>
                        <tr>
                            <td style="font-size:14px;padding:0 20px 15px;line-height:1.6;">
                                Our platform is intended for general public use and not for commercial purposes. 
                                Traders should seek paid data services from providers like Experian or HPI.
                            </td>
                        </tr>
                        <tr>
                            <td style="font-size:14px;padding:0 20px 15px;line-height:1.6;">
                                We reserve the right to modify or discontinue vehicle data at any time. 
                                Users cannot demand continued access to this free service.
                            </td>
                        </tr>
                        <tr>
                            <td style="font-size:14px;padding:0 20px 15px;line-height:1.6;">
                                Additionally, our data cannot be used as legal evidence in any court 
                                or official capacity.
                            </td>
                        </tr>
                        <tr>
                            <td style="font-size:14px;padding:0 20px 15px;line-height:1.6;">
                                For any inaccuracies or suggestions, please contact us via our website. 
                                While we appreciate feedback, response times may vary due to high email volumes.
                            </td>
                        </tr>
                        <tr>
                            <td style="font-size:14px;padding:0 20px 15px;line-height:1.6;">
                                Our calculation of average mileage per year may be inaccurate if the MOT records 
                                include a combination of miles and kilometres.
                            </td>
                        </tr>
                        <tr>
                            <td style="font-size:14px;padding:0 20px 20px;line-height:1.6;">
                                If a vehicle has three consecutive 6-month MOTs, we classify it as being used for 
                                taxi or commercial purposes. However, in rare cases, this classification may be incorrect.
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>

        </table>
    </body>
</html>