<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>{{ $quotation->quotation_number }}</title>
    <style>
        @page {
            margin: 25px 30px; /* TOP/BOTTOM, LEFT/RIGHT */
        }

        body {
            font-family: DejaVu Sans, sans-serif;
            font-size: 11px;
            color: #111;
            margin: 0;
            padding: 0;
        }

        .container {
            width: 100%;
        }

        h1 {
            font-size: 18px;
            margin: 0 0 8px 0;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 10px;
        }

        th, td {
            border: 1px solid #ddd;
            padding: 6px 8px;
            text-align: left;
        }

        th {
            background: #f5f5f5;
            font-weight: bold;
        }

        .right {
            text-align: right;
        }

        .muted {
            color: #666;
        }

        .totals td {
            border: none;
            padding: 4px 8px;
        }

        .totals tr:last-child td {
            font-weight: bold;
            font-size: 12px;
            border-top: 2px solid #333;
            padding-top: 8px;
        }
        </style>
</head>
<body>
    <div>
        <h1>Quotation {{ $quotation->quotation_number }}</h1>
        <p class="muted">
            @if($company->company_name ?? null)
                {{ $company->company_name }}<br>
            @endif
            Issue: {{ $quotation->issue_date->format('M d, Y') }}
            @if($quotation->expiry_date)
                &nbsp;|&nbsp; Expires: {{ $quotation->expiry_date->format('M d, Y') }}
            @endif
        </p>
    </div>

    <p><strong>Bill to</strong><br>
        {{ $quotation->customer->name ?? 'Customer' }}<br>
        @if($quotation->customer->email ?? null)
            <span class="muted">{{ $quotation->customer->email }}</span><br>
        @endif
    </p>

    <table>
        <thead>
            <tr>
                <th>Description</th>
                <th class="right">Qty</th>
                <th class="right">Unit</th>
                <th class="right">Tax %</th>
                <th class="right">Amount</th>
            </tr>
        </thead>
        <tbody>
            @foreach($quotation->items as $item)
                <tr>
                    <td>{{ $item->description }}</td>
                    <td class="right">{{ number_format($item->quantity, 2) }}</td>
                    <td class="right">{{ $quotation->currency }} {{ number_format($item->unit_price, 2) }}</td>
                    <td class="right">{{ number_format($item->tax_rate, 2) }}</td>
                    <td class="right">{{ $quotation->currency }} {{ number_format($item->total, 2) }}</td>
                </tr>
            @endforeach
        </tbody>
    </table>

    <table class="totals" style="width: 50%; margin-left: auto; margin-top: 16px;">
        <tr>
            <td class="right">Subtotal</td>
            <td class="right">{{ $quotation->currency }} {{ number_format($quotation->subtotal, 2) }}</td>
        </tr>
        @if($quotation->tax_amount > 0)
            <tr>
                <td class="right">Tax</td>
                <td class="right">{{ $quotation->currency }} {{ number_format($quotation->tax_amount, 2) }}</td>
            </tr>
        @endif
        @if($quotation->discount_amount > 0)
            <tr>
                <td class="right">Discount</td>
                <td class="right">-{{ $quotation->currency }} {{ number_format($quotation->discount_amount, 2) }}</td>
            </tr>
        @endif
        <tr>
            <td class="right">Total</td>
            <td class="right">{{ $quotation->currency }} {{ number_format($quotation->total, 2) }}</td>
        </tr>
    </table>

    @if($quotation->notes)
        <p style="margin-top: 20px;"><strong>Notes</strong><br>{{ $quotation->notes }}</p>
    @endif
    @if($quotation->terms)
        <p style="margin-top: 12px;"><strong>Terms</strong><br>{{ $quotation->terms }}</p>
    @endif
</body>
</html>
