<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Advance Report</title>
    <style>
        body {
            font-family: DejaVu Sans, sans-serif;
            font-size: 11px;
            color: #0f172a;
        }
        .header {
            margin-bottom: 18px;
        }
        .title {
            font-size: 20px;
            font-weight: bold;
        }
        .sub {
            color: #475569;
            font-size: 11px;
        }
        .summary {
            margin: 16px 0;
        }
        .summary td {
            border: 1px solid #cbd5e1;
            padding: 8px;
        }
        table {
            width: 100%;
            border-collapse: collapse;
        }
        th, td {
            border: 1px solid #cbd5e1;
            padding: 6px;
        }
        th {
            background: #f8fafc;
        }
        .text-right {
            text-align: right;
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="title">Advance Report</div>
        <div class="sub">
            Search = {{ $filters['search'] ?: 'All' }},
            Status = {{ $filters['status'] ?: 'Active + Partial Adjusted' }}
        </div>
    </div>

    <table class="summary">
        <tr>
            <td><strong>Total Advance</strong><br>৳ {{ number_format($totals['amount'], 2) }}</td>
            <td><strong>Total Adjusted</strong><br>৳ {{ number_format($totals['adjusted'], 2) }}</td>
            <td><strong>Total Outstanding</strong><br>৳ {{ number_format($totals['outstanding'], 2) }}</td>
        </tr>
    </table>

    <table>
        <thead>
            <tr>
                <th style="width: 10%;">Date</th>
                <th style="width: 18%;">Employee</th>
                <th style="width: 14%;">Employee Code</th>
                <th style="width: 16%;">Account</th>
                <th class="text-right" style="width: 12%;">Amount</th>
                <th class="text-right" style="width: 12%;">Adjusted</th>
                <th class="text-right" style="width: 12%;">Remaining</th>
                <th style="width: 10%;">Status</th>
            </tr>
        </thead>
        <tbody>
            @forelse($advances as $advance)
                <tr>
                    <td>{{ optional($advance->advance_date)->format('d M Y') }}</td>
                    <td>{{ $advance->employee?->name ?? '-' }}</td>
                    <td>{{ $advance->employee?->employee_code ?? '-' }}</td>
                    <td>{{ $advance->account?->name ?? '-' }}</td>
                    <td class="text-right">{{ number_format($advance->amount, 2) }}</td>
                    <td class="text-right">{{ number_format($advance->adjusted_amount, 2) }}</td>
                    <td class="text-right">{{ number_format($advance->remaining_amount, 2) }}</td>
                    <td>{{ ucwords(str_replace('_', ' ', $advance->status)) }}</td>
                </tr>
            @empty
                <tr>
                    <td colspan="8" style="text-align:center;">No advance found.</td>
                </tr>
            @endforelse
        </tbody>
    </table>
</body>
</html>