<?php $pageTitle = 'Reports'; ?>
<div class="panel">
    <div class="panel-header">
        <div><p class="eyebrow">Reports</p><h2>Business Reports</h2><p class="muted">Review revenue, fleet performance, invoices, and maintenance costs.</p></div>
        <form method="get" action="<?= url('/reports') ?>" class="search-form">
            <input type="date" name="start" value="<?= e($start) ?>">
            <input type="date" name="end" value="<?= e($end) ?>">
            <button class="btn btn-primary" type="submit">Filter</button>
        </form>
    </div>
    <div class="stats-grid">
        <div class="stat-card"><span>Loads</span><strong><?= e((string) ($summary['total_loads'] ?? 0)) ?></strong><small>Selected period</small></div>
        <div class="stat-card highlight"><span>Revenue</span><strong><?= money($summary['revenue'] ?? 0) ?></strong><small>Selected period</small></div>
        <div class="stat-card"><span>Miles</span><strong><?= number_format((float) ($summary['miles'] ?? 0)) ?></strong><small>Selected period</small></div>
        <div class="stat-card"><span>Maintenance</span><strong><?= money($maintenanceCost) ?></strong><small>This month</small></div>
    </div>
</div>
<div class="content-grid two-col" style="margin-top:18px;">
    <div class="panel"><div class="panel-header"><div><p class="eyebrow">Drivers</p><h2>Driver Performance</h2></div></div><?php $rows=$driverReport; $nameKey='name'; require app_path('Views/reports/simple_performance_table.php'); ?></div>
    <div class="panel"><div class="panel-header"><div><p class="eyebrow">Trucks</p><h2>Truck Performance</h2></div></div><?php $rows=$truckReport; $nameKey='unit_number'; require app_path('Views/reports/simple_performance_table.php'); ?></div>
</div>
<div class="content-grid two-col" style="margin-top:18px;">
    <div class="panel"><div class="panel-header"><div><p class="eyebrow">Brokers</p><h2>Broker Revenue</h2></div></div><div class="table-wrap"><table><thead><tr><th>Broker</th><th>Loads</th><th>Revenue</th></tr></thead><tbody><?php foreach ($brokerReport as $row): ?><tr><td><?= e($row['company_name']) ?></td><td><?= e((string) $row['loads_count']) ?></td><td><?= money($row['revenue']) ?></td></tr><?php endforeach; ?><?php if (!$brokerReport): ?><tr><td colspan="3" class="empty">No broker data.</td></tr><?php endif; ?></tbody></table></div></div>
    <div class="panel"><div class="panel-header"><div><p class="eyebrow">Invoices</p><h2>Invoice Status</h2></div></div><div class="table-wrap"><table><thead><tr><th>Status</th><th>Count</th><th>Amount</th></tr></thead><tbody><?php foreach ($invoiceSummary as $row): ?><tr><td><span class="badge badge-<?= status_class($row['status']) ?>"><?= e(readable_status($row['status'])) ?></span></td><td><?= e((string) $row['total']) ?></td><td><?= money($row['amount']) ?></td></tr><?php endforeach; ?><?php if (!$invoiceSummary): ?><tr><td colspan="3" class="empty">No invoice data.</td></tr><?php endif; ?></tbody></table></div></div>
</div>
