<?php
/** @var array $expense */
/** @var array $tenant */
$companyName = \Core\Settings::get('company_name') ?: APP_NAME;
?>
<style>
    body { font-family: sans-serif; color: #1e2d3d; font-size: 10pt; }
    .brand { color: #0b2545; font-weight: 800; font-size: 16pt; }
    .sub { color: #6b7a8d; font-size: 9pt; text-transform: uppercase; letter-spacing: 1.5px; }
    h1 { font-size: 18pt; margin: 8mm 0 2mm; color: #0b2545; }
    h2 { font-size: 12pt; margin: 6mm 0 2mm; color: #1a4d8c; border-bottom: 1px solid #d1d5db; padding-bottom: 1mm; }
    table.def { width: 100%; border-collapse: collapse; margin: 2mm 0 4mm; }
    table.def td { padding: 1mm 2mm; vertical-align: top; }
    table.def td.k { color: #6b7a8d; width: 25%; text-transform: uppercase; font-size: 8pt; letter-spacing: .5px; }
    table.def td.v { color: #1e2d3d; font-weight: 600; }
    .amount-box { background: #f7f9fc; padding: 5mm; border-radius: 3mm; text-align: right; margin: 3mm 0; }
    .amount-box .a { font-size: 24pt; font-weight: 800; color: #0b2545; }
    .amount-box .l { color: #6b7a8d; font-size: 9pt; text-transform: uppercase; letter-spacing: 1px; }
    .sig-row { margin-top: 8mm; display: flex; gap: 15mm; }
    .sig { flex: 1; border-top: 1px solid #1e2d3d; padding-top: 2mm; font-size: 8pt; color: #6b7a8d; }
    .foot { margin-top: 12mm; color: #94a3b8; font-size: 7pt; text-align: center; }
</style>

<div>
    <div class="brand"><?= e($companyName) ?></div>
    <div class="sub"><?= e($tenant['name'] ?? '') ?> · Expense Voucher</div>
</div>

<h1><?= e($expense['code'] ?? '#' . $expense['expense_id']) ?> · <?= e($expense['title']) ?></h1>

<div class="amount-box">
    <div class="l">Total</div>
    <div class="a"><?= e($expense['currency']) ?> <?= number_format((float) $expense['amount'], 2) ?></div>
</div>

<h2>Details</h2>
<table class="def">
    <tr><td class="k">Date</td>       <td class="v"><?= e($expense['expense_date'] ?? '—') ?></td>
        <td class="k">Category</td>    <td class="v"><?= e($expense['category_name'] ?? '—') ?></td></tr>
    <tr><td class="k">Status</td>     <td class="v"><?= e(strtoupper($expense['status'])) ?></td>
        <td class="k">Payment</td>     <td class="v"><?= e($expense['payment_method'] ?? '—') ?></td></tr>
    <tr><td class="k">Vendor</td>     <td class="v"><?= e($expense['vendor'] ?? '—') ?></td>
        <td class="k">Receipt Ref</td> <td class="v"><?= e($expense['receipt_ref'] ?? '—') ?></td></tr>
    <tr><td class="k">Submitter</td>  <td class="v"><?= e($expense['submitter_username'] ?? '—') ?></td>
        <td class="k">Approver</td>    <td class="v"><?= e($expense['approver_username'] ?? '—') ?></td></tr>
    <tr><td class="k">Submitted</td>  <td class="v"><?= e($expense['submitted_at'] ?? '—') ?></td>
        <td class="k">Approved</td>    <td class="v"><?= e($expense['approved_at'] ?? '—') ?></td></tr>
    <tr><td class="k">Work Order</td> <td class="v"><?= e($expense['wo_title'] ?? '—') ?></td>
        <td class="k">Asset</td>       <td class="v"><?= e($expense['asset_name'] ?? '—') ?></td></tr>
</table>

<?php if (!empty($expense['description'])): ?>
    <h2>Description</h2>
    <p><?= nl2br(e($expense['description'])) ?></p>
<?php endif; ?>

<?php if (!empty($expense['approval_note'])): ?>
    <h2>Approval Note</h2>
    <p><?= nl2br(e($expense['approval_note'])) ?></p>
<?php endif; ?>

<div class="sig-row">
    <div class="sig">Submitter signature &nbsp; · &nbsp; Date</div>
    <div class="sig">Approver signature &nbsp; · &nbsp; Date</div>
</div>

<div class="foot">
    Generated <?= date('Y-m-d H:i') ?> · <?= e($companyName) ?>
</div>
