<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Bon de Livraison {{ $deliveryNote->number }}</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            font-size: 12px;
            line-height: 1.4;
            color: #333;
        }
        .header {
            border-bottom: 2px solid #007bff;
            padding-bottom: 20px;
            margin-bottom: 30px;
        }
        .company-info {
            float: left;
            width: 50%;
        }
        .delivery-info {
            float: right;
            width: 45%;
            text-align: right;
        }
        .client-info {
            margin: 30px 0;
            clear: both;
        }
        .table {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0;
        }
        .table th, .table td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }
        .table th {
            background-color: #f8f9fa;
            font-weight: bold;
        }
        .text-right {
            text-align: right;
        }
        .text-center {
            text-align: center;
        }
        .total {
            float: right;
            width: 300px;
            margin-top: 20px;
        }
        .total-row {
            display: flex;
            justify-content: space-between;
            padding: 5px 0;
        }
        .total-row.final {
            border-top: 2px solid #333;
            font-weight: bold;
            font-size: 14px;
        }
        .footer {
            margin-top: 50px;
            padding-top: 20px;
            border-top: 1px solid #ddd;
            clear: both;
            font-size: 11px;
            color: #666;
        }
        .footer-fixed {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            height: 60px;
            background: white;
            border-top: 1px solid #ddd;
            padding: 10px 20px;
            font-size: 10px;
            color: #666;
            z-index: 1000;
        }
        @page {
            margin-bottom: 80px;
        }
        body {
            margin-bottom: 80px;
        }
        .clearfix::after {
            content: "";
            display: table;
            clear: both;
        }
    </style>
</head>
<body>
    <div class="header clearfix">
        <div class="company-info">
            <p>
                <strong>{{ $company ? $company->name : 'Mon Entreprise' }}</strong><br>
                @if($company && $company->address){{ $company->address }}@else Ville @endif<br>
                @if($company && $company->phone){{ $company->phone }}@else Téléphone @endif<br>
                <strong>Bon de livraison N°:</strong> {{ $deliveryNote->number }}<br>
                <strong>Date livraison:</strong> {{ $deliveryNote->date->format('d/m/Y') }}
            </p>
        </div>
        <div class="delivery-info">
            <p>
                <strong>Livré à:</strong><br>
                <strong>{{ $deliveryNote->client->name ?? 'Client' }}</strong><br>
                {{ $deliveryNote->client->address ?? '' }}<br>
                @if($deliveryNote->client->ice)ICE: {{ $deliveryNote->client->ice }}<br>@endif
                @if($deliveryNote->client->phone)Tél: {{ $deliveryNote->client->phone }}<br>@endif
                @if($deliveryNote->client->email)Email: {{ $deliveryNote->client->email }}@endif
            </p>
        </div>
    </div>

    <table class="table">
        <thead>
            <tr>
                <th>Produit/Service</th>
                <th class="text-center">Qté</th>
                <th>Unité</th>
            </tr>
        </thead>
        <tbody>
            @foreach($deliveryNote->items as $item)
            <tr>
                <td>{{ $item->product_name }}</td>
                <td class="text-center">{{ $item->quantity }}</td>
                <td>{{ $item->unit }}</td>
            </tr>
            @endforeach
        </tbody>
    </table>



    @if($deliveryNote->notes)
    <div class="notes" style="margin-top: 40px; clear: both;">
        <h4>Notes:</h4>
        <p>{{ $deliveryNote->notes }}</p>
    </div>
    @endif

    @if($company && $company->footer_template)
    <div class="footer-fixed">
        {!! nl2br(e($company->footer_template)) !!}
    </div>
    @endif
</body>
</html>