<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Invoice {{ $invoice->invoice_number ?? '' }}</title>
    @include('invoices.templates.partials._pdf-head-compact')
</head>
<body>
<div class="pdf-wrap" style="max-width:100%;">
<table style="width:100%; border-collapse:collapse; font-family:DejaVu Sans, sans-serif; font-size:14px;">
    @if(!empty($showWatermark))
    <tr>
        <td style="padding:10px 12px; text-align:center; background-color:#fef2f2; color:#dc2626; font-weight:bold; font-size:14px;">UNLICENSED COPY</td>
    </tr>
    @endif

    <tr>
        <td style="padding:0 0 14px 0;" class="pdf-section">
            <table style="width:100%; border-collapse:collapse; background-color:#137fec; color:#ffffff;">
                <tr>
                    <td style="padding:14px 16px; text-align:center;">
                        @if($logoDataUri)
                            <img src="{{ $logoDataUri }}" alt="" style="max-width:200px; max-height:64px;">
                        @endif
                        <div style="font-size:20px; font-weight:600; letter-spacing:1px; padding-top:8px;">{{ $companySettings->company_name ?? config('app.name') }}</div>
                        <div style="font-size:13px; letter-spacing:3px; text-transform:uppercase; padding-top:6px;">INVOICE</div>
                    </td>
                </tr>
            </table>
        </td>
    </tr>

    <tr>
        <td style="padding:0 0 14px 0;" class="pdf-section">
            <table style="width:100%; border-collapse:collapse; border-bottom:1px solid #e5e7eb;">
                <tr>
                    <td style="width:50%; vertical-align:top; padding:10px 12px 10px 0;">
                        <div style="font-size:11px; color:#9ca3af; text-transform:uppercase;">Invoice number</div>
                        <div style="font-size:16px; font-weight:600;">{{ $invoice->invoice_number ?? '—' }}</div>
                        <div style="font-size:11px; color:#9ca3af; text-transform:uppercase; padding-top:8px;">Issue date</div>
                        <div style="font-size:14px;">{{ $issueDate->format('M d, Y') }}</div>
                    </td>
                    <td style="width:50%; vertical-align:top; padding:10px 0 10px 12px;">
                        <div style="font-size:11px; color:#9ca3af; text-transform:uppercase;">Due date</div>
                        <div style="font-size:14px;">{{ $dueDate->format('M d, Y') }}</div>
                        @if($invoice->status ?? null)
                        <div style="font-size:11px; color:#9ca3af; text-transform:uppercase; padding-top:8px;">Status</div>
                        <div style="font-size:14px;">{{ ucfirst((string) $invoice->status) }}</div>
                        @endif
                    </td>
                </tr>
            </table>
        </td>
    </tr>

    <tr>
        <td style="padding:0 0 14px 0;" class="pdf-section">
            <table style="width:100%; border-collapse:collapse;">
                <tr>
                    @if($invoice->customer)
                    <td style="width:50%; vertical-align:top; padding:12px; background-color:#137fec; color:#ffffff;">
                        <table style="width:100%; border-collapse:collapse;">
                            <tr><td style="font-size:11px; font-weight:bold; text-transform:uppercase; padding:0 0 6px 0;">Bill to</td></tr>
                            <tr><td style="font-size:15px; font-weight:600; padding:0 0 4px 0;">{{ $invoice->customer->name }}</td></tr>
                            <tr><td style="font-size:13px; line-height:1.45; opacity:0.95;">
                                @if($invoice->customer->email)
                                    {{ $invoice->customer->email }}@if($invoice->customer->phone || $invoice->customer->address), @endif
                                @endif
                                @if($invoice->customer->phone)
                                    {{ $invoice->customer->phone }}@if($invoice->customer->address), @endif
                                @endif
                                @if($invoice->customer->address){{ $invoice->customer->address }}@endif
                            </td></tr>
                        </table>
                    </td>
                    @endif
                    <td style="width:{{ $invoice->customer ? '50%' : '100%' }}; vertical-align:top; padding:12px; background-color:#137fec; color:#ffffff;">
                        <table style="width:100%; border-collapse:collapse;">
                            <tr><td style="font-size:11px; font-weight:bold; text-transform:uppercase; padding:0 0 6px 0;">Company</td></tr>
                            <tr><td style="font-size:13px; line-height:1.45; opacity:0.95;">
                                @if($companySettings->company_name){{ $companySettings->company_name }}@endif
                                @if($companySettings->company_address)@if($companySettings->company_name), @endif{{ $companySettings->company_address }}@endif
                                @if($companySettings->company_phone)@if($companySettings->company_name || $companySettings->company_address), @endif{{ $companySettings->company_phone }}@endif
                                @if($companySettings->company_email)@if($companySettings->company_name || $companySettings->company_address || $companySettings->company_phone), @endif{{ $companySettings->company_email }}@endif
                            </td></tr>
                        </table>
                    </td>
                </tr>
            </table>
        </td>
    </tr>

    @include('invoices.templates.partials._pdf-items-totals-footer', [
        'thBg' => '#ffffff',
        'thText' => '#111827',
        'thBorderBottom' => '#e5e7eb',
        'accent' => '#137fec',
        'paymentBg' => '#eff6ff',
        'paymentBorder' => '#bfdbfe',
        'paymentTitle' => '#1d4ed8',
        'paymentText' => '#1e3a8a',
    ])
</table>
</div>
</body>
</html>
