<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Loans Report - {{ now()->format('M d, Y') }}</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            font-size: 14px;
            line-height: 1.6;
            margin: 0;
            padding: 20px;
        }
        .header {
            text-align: center;
            margin-bottom: 30px;
            border-bottom: 2px solid #28a745;
            padding-bottom: 20px;
        }
        .header h1 {
            margin: 0;
            color: #28a745;
            font-size: 24px;
        }
        .header p {
            margin: 5px 0;
            color: #666;
        }
        .stats {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 15px;
            margin-bottom: 30px;
            page-break-inside: avoid;
        }
        .stat-box {
            border: 1px solid #28a745;
            padding: 15px;
            text-align: center;
            background: #f9f9f9;
        }
        .stat-number {
            font-size: 20px;
            font-weight: bold;
            color: #28a745;
            display: block;
        }
        .stat-label {
            font-size: 10px;
            color: #666;
            text-transform: uppercase;
            margin-top: 5px;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }
        th, td {
            border: 1px solid #28a745;
            padding: 10px;
            text-align: left;
            vertical-align: top;
        }
        th {
            background: #ffc107;
            font-weight: bold;
            font-size: 11px;
            text-transform: uppercase;
            color: #333;
        }
        .status-badge {
            padding: 3px 8px;
            border-radius: 3px;
            font-size: 10px;
            font-weight: bold;
            text-transform: uppercase;
        }
        .status-pending { background: #fff3cd; color: #856404; }
        .status-approved { background: #d1ecf1; color: #0c5460; }
        .status-disbursed { background: #d4edda; color: #155724; }
        .status-active { background: #cce5ff; color: #004085; }
        .status-completed { background: #d4edda; color: #155724; }
        .status-rejected { background: #f8d7da; color: #721c24; }
        .status-paused { background: #fff3cd; color: #856404; }
        .status-closed { background: #e2e3e5; color: #383d41; }
        .footer {
            margin-top: 30px;
            padding-top: 20px;
            border-top: 1px solid #28a745;
            text-align: center;
            font-size: 10px;
            color: #666;
        }
        @media print {
            body { margin: 0; }
            .no-print { display: none; }
        }
    </style>
</head>
<body>
    <div class="header">
        <h1>Loans Management Report</h1>
        <p>Generated on: {{ now()->format('F d, Y \a\t H:i') }}</p>
        <p>Period: {{ request('start_date', 'All time') }} to {{ request('end_date', 'Present') }}</p>
    </div>

    <div class="stats">
        <div class="stat-box">
            <span class="stat-number">{{ $stats['total'] }}</span>
            <span class="stat-label">Total Loans</span>
        </div>
        <div class="stat-box">
            <span class="stat-number">${{ number_format($stats['total_amount'], 2) }}</span>
            <span class="stat-label">Total Amount</span>
        </div>
        <div class="stat-box">
            <span class="stat-number">{{ $stats['approved'] }}</span>
            <span class="stat-label">Approved</span>
        </div>
        <div class="stat-box">
            <span class="stat-number">{{ $stats['disbursed'] }}</span>
            <span class="stat-label">Disbursed</span>
        </div>
    </div>

    <table>
        <thead>
            <tr>
                <th>Loan Number</th>
                <th>Client</th>
                <th>Amount</th>
                <th>Interest Rate</th>
                <th>Status</th>
                <th>Application Date</th>
                <th>Loan Type</th>
            </tr>
        </thead>
        <tbody>
            @forelse($loans as $loan)
            <tr>
                <td>{{ $loan->loan_number }}</td>
                <td>
                    {{ $loan->client->first_name }} {{ $loan->client->last_name }}<br>
                    <small>{{ $loan->client->client_number }}</small>
                </td>
                <td>${{ number_format($loan->amount, 2) }}</td>
                <td>{{ $loan->interest_rate }}%</td>
                <td>
                    <span class="status-badge status-{{ $loan->status }}">
                        {{ ucfirst($loan->status) }}
                    </span>
                </td>
                <td>{{ $loan->application_date->format('M d, Y') }}</td>
                <td>{{ ucfirst($loan->loan_type) }}</td>
            </tr>
            @empty
            <tr>
                <td colspan="7" style="text-align: center; padding: 20px;">
                    No loans found matching the criteria.
                </td>
            </tr>
            @endforelse
        </tbody>
    </table>

    <div class="footer">
        <p>This report was generated by Credora Loan Management System</p>
        <p>© {{ date('Y') }} Credora. All rights reserved.</p>
    </div>

    <script>
        window.onload = function() {
            window.print();
        }
    </script>
</body>
</html>
