<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{{ $quotation->quotation_number }}</title>
    <style>
        @page { margin: 10mm 11mm; size: A4 portrait; }
        * { box-sizing: border-box; }
        html, body { margin: 0; padding: 0; width: 100%; max-width: 100%; }
        body {
            font-family: DejaVu Sans, sans-serif;
            font-size: 11px;
            line-height: 1.4;
            color: #111827;
        }
        table { width: 100%; border-collapse: collapse; table-layout: auto; }
        td, th { padding: 6px 8px; vertical-align: top; word-wrap: break-word; }
        thead tr { page-break-inside: avoid; }
        .right { text-align: right; }
        .muted { color: #4b5563; font-size: 10px; }
        .banner { background: #2563eb; color: #fff; }
        .pdf-logo { max-height: 56px; max-width: 200px; width: auto; height: auto; background: #fff; padding: 4px 8px; display: block; }
        strong { font-weight: bold; }
    </style>
</head>
<body>
<table class="banner" style="margin-bottom:14px;">
    <tr>
        <td style="padding:16px 18px;" width="70%">
            <div style="font-size:22px;font-weight:bold;">Sales Proposal</div>
            <div style="font-size:12px;opacity:0.95;margin-top:6px;">Professional Service Quotation</div>
            <div style="font-size:15px;font-weight:bold;margin-top:10px;">Quote #{{ $quotation->quotation_number }}</div>
            <div style="font-size:11px;margin-top:8px;">Date: {{ $quotation->issue_date->format('F d, Y') }} | Valid: {{ $quotation->expiry_date ? $quotation->expiry_date->format('F d, Y') : '—' }}</div>
        </td>
        <td style="padding:16px 18px;" width="30%" class="right" valign="middle">
            @if(!empty($pdfLogoUri ?? null))
                <img src="{{ $pdfLogoUri }}" alt="" class="pdf-logo" width="200" height="56">
            @endif
        </td>
    </tr>
</table>

<table style="background:#f3f4f6;border:1px solid #d1d5db;margin-bottom:14px;">
    <tr><td style="padding:14px 16px;">
        <div style="font-size:10px;font-weight:bold;text-transform:uppercase;color:#374151;">Prepared For</div>
        @if($quotation->customer)
        <div style="font-size:16px;font-weight:bold;margin-top:6px;">{{ $quotation->customer->name }}</div>
        <div class="muted" style="font-size:11px;line-height:1.55;">
            @if($quotation->customer->email){{ $quotation->customer->email }}<br>@endif
            @if($quotation->customer->phone){{ $quotation->customer->phone }}<br>@endif
            @if($quotation->customer->address){{ $quotation->customer->address }}@endif
        </div>
        @endif
    </td></tr>
</table>

@if($quotation->notes)
<table style="margin-bottom:14px;"><tr><td style="font-size:13px;font-weight:bold;color:#1d4ed8;">Service Description</td></tr>
<tr><td class="muted" style="font-size:11px;line-height:1.5;">{{ $quotation->notes }}</td></tr></table>
@endif

<table style="margin-bottom:14px;">
    @forelse($quotation->items as $item)
    @php $line = ($item->quantity * $item->unit_price) * (1 + (($item->tax_rate ?? 0) / 100)); @endphp
    <tr>
        <td style="border-bottom:1px solid #e5e7eb;padding:10px 8px;">
            <strong style="font-size:12px;">{{ $item->description }}</strong>
            @if($item->notes)
                <br><span class="muted" style="font-size:10px;">{{ $item->notes }}</span>
            @endif
            <div class="muted" style="font-size:10px;margin-top:4px;">
                Qty {{ number_format($item->quantity, 2) }} × {{ $quotation->currency }} {{ number_format($item->unit_price, 2) }}
                @if($item->tax_rate)
                    + {{ $item->tax_rate }}% tax
                @endif
            </div>
        </td>
        <td class="right" style="border-bottom:1px solid #e5e7eb;padding:10px 8px;font-weight:bold;font-size:12px;">{{ $quotation->currency }} {{ number_format($line, 2) }}</td>
    </tr>
    @empty
    <tr><td colspan="2" class="muted" style="text-align:center;padding:14px;">No items</td></tr>
    @endforelse
</table>

<table style="border:3px solid #2563eb;background:#eff6ff;margin-bottom:14px;">
    <tr><td colspan="2" style="padding:12px 14px;font-size:13px;font-weight:bold;color:#1e40af;">Pricing Summary</td></tr>
    <tr><td style="padding:8px 14px;font-weight:bold;">Subtotal</td><td class="right" style="padding:8px 14px;font-weight:bold;">{{ $quotation->currency }} {{ number_format($quotation->subtotal, 2) }}</td></tr>
    @if(($quotation->tax_amount ?? 0) > 0)
    <tr><td style="padding:6px 14px;font-weight:bold;">Tax</td><td class="right" style="padding:6px 14px;font-weight:bold;">{{ $quotation->currency }} {{ number_format($quotation->tax_amount, 2) }}</td></tr>
    @endif
    @if(($quotation->discount_amount ?? 0) > 0)
    <tr><td style="padding:6px 14px;font-weight:bold;">Discount</td><td class="right" style="padding:6px 14px;font-weight:bold;">-{{ $quotation->currency }} {{ number_format($quotation->discount_amount, 2) }}</td></tr>
    @endif
    <tr><td style="padding:12px 14px;font-size:16px;font-weight:bold;border-top:3px solid #2563eb;">Total</td><td class="right" style="padding:12px 14px;font-size:16px;font-weight:bold;border-top:3px solid #2563eb;">{{ $quotation->currency }} {{ number_format($quotation->total, 2) }}</td></tr>
</table>

<table style="margin-top:12px;">
    <tr><td style="font-size:12px;font-weight:bold;padding-bottom:8px;">Acceptance</td></tr>
    <tr>
        <td width="50%" style="padding-right:10px;"><div style="border-bottom:2px solid #111827;min-height:44px;"></div><div class="muted" style="font-size:10px;margin-top:4px;">Client Signature</div></td>
        <td width="50%" style="padding-left:10px;"><div style="border-bottom:2px solid #111827;min-height:44px;"></div><div class="muted" style="font-size:10px;margin-top:4px;">Date</div></td>
    </tr>
</table>

@if($quotation->terms)
<table style="margin-top:14px;"><tr><td style="font-size:11px;line-height:1.5;"><strong>Terms:</strong> {{ $quotation->terms }}</td></tr></table>
@endif
</body>
</html>
