<!doctype html><html><head><meta charset="utf-8"><title>{{ $document->document_number }}</title>
<style>:root{--brand:{{ $document->template?->accent_color ?: '#3454d1' }}}body{font-family:Arial,sans-serif;max-width:960px;margin:30px auto;color:#243047;padding:0 20px}.header{background:var(--brand);color:#fff;padding:28px;border-radius:8px}.header h1{margin:0}table{width:100%;border-collapse:collapse;margin-top:24px}th{background:#f2f5fa}th,td{padding:11px;border:1px solid #dfe4ec;text-align:left}.total{text-align:right;font-size:1.3rem;margin:25px 0}.decision{padding:20px;border:1px solid #dfe4ec;border-radius:8px;margin-top:25px}.btn{border:0;color:#fff;padding:10px 18px;border-radius:5px;cursor:pointer}.accept{background:#28a745}.reject{background:#dc3545}textarea{width:100%;min-height:80px;margin:10px 0}</style></head>
<body>
@if(session('success'))<p style="color:#198754">{{ session('success') }}</p>@endif
<div class="header"><h1>{{ ucfirst($document->type) }}</h1><strong>{{ $document->document_number }}</strong><div>{{ $document->template?->header_text }}</div></div>
<p>Issue: {{ $document->issue_date?->format('Y-m-d') }} · Due: {{ $document->due_date?->format('Y-m-d') ?: '—' }} · Status: {{ ucwords(str_replace('_',' ',$document->status)) }}</p>
<table><thead><tr><th>Product / Description</th><th>Qty</th><th>Price</th><th>Discount</th><th>Tax</th><th>Total</th></tr></thead><tbody>
@foreach($document->lines as $line)<tr><td>{{ $line->product?->product_name ?: $line->description }}</td><td>{{ $line->quantity }}</td><td>{{ number_format($line->unit_price,2) }}</td><td>{{ number_format($line->discount,2) }}</td><td>{{ number_format($line->tax,2) }}</td><td>{{ number_format($line->line_total,2) }}</td></tr>@endforeach
</tbody></table>
<div class="total">Subtotal {{ $document->currency }} {{ number_format($document->subtotal,2) }}<br>Discount {{ number_format($document->discount,2) }} · Tax {{ number_format($document->tax,2) }}<br><strong>Total {{ $document->currency }} {{ number_format($document->total,2) }}</strong></div>
@if($document->payments->count())<h3>Payment History</h3><table><tr><th>Date</th><th>Type</th><th>Status</th><th>Method</th><th>Reference</th><th>Amount</th></tr>@foreach($document->payments as $payment)<tr><td>{{ $payment->paid_at?->format('Y-m-d H:i') }}</td><td>{{ ucfirst($payment->payment_type) }}</td><td>{{ ucfirst($payment->status) }}</td><td>{{ $payment->method }}</td><td>{{ $payment->reference }}</td><td>{{ in_array($payment->payment_type,['refund','reversal'])?'-':'' }}{{ number_format($payment->amount,2) }}</td></tr>@endforeach</table>@endif
@if($document->status === 'sent' && $document->acceptance_token)
<div class="decision"><h3>Customer Decision</h3><form method="POST" action="{{ route('trade-documents.customer-decision',$document->acceptance_token) }}">@csrf<textarea name="comment" placeholder="Optional comments"></textarea><button class="btn accept" name="decision" value="accepted">Accept</button> <button class="btn reject" name="decision" value="rejected">Reject</button></form></div>
@elseif($document->customer_decision)<div class="decision"><strong>Decision: {{ ucfirst($document->customer_decision) }}</strong><p>{{ $document->customer_comment }}</p></div>@endif
@if($document->notes)<p>{{ $document->notes }}</p>@endif
<footer>{{ $document->template?->footer_text }}</footer>
</body></html>
