<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Laporan Transaksi - {{ $dateFromFormatted }} s/d {{ $dateToFormatted }}</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            font-size: 12px;
            color: #1e293b;
            background: #f8fafc;
            padding: 20px;
        }
        .container {
            max-width: 900px;
            margin: 0 auto;
            background: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 4px 20px rgba(0,0,0,0.1);
        }
        .header {
            text-align: center;
            margin-bottom: 30px;
            padding-bottom: 20px;
            border-bottom: 2px solid #14b8a6;
        }
        .header h1 {
            color: #14b8a6;
            font-size: 24px;
            margin-bottom: 5px;
        }
        .header p {
            color: #64748b;
            font-size: 14px;
        }
        .summary {
            display: flex;
            justify-content: space-between;
            margin-bottom: 25px;
            gap: 15px;
        }
        .summary-card {
            flex: 1;
            padding: 15px;
            border-radius: 8px;
            text-align: center;
        }
        .summary-card.income {
            background: #ecfdf5;
            border: 1px solid #10b981;
        }
        .summary-card.expense {
            background: #fef2f2;
            border: 1px solid #f43f5e;
        }
        .summary-card.balance {
            background: #f0fdfa;
            border: 1px solid #14b8a6;
        }
        .summary-card h3 {
            font-size: 11px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            margin-bottom: 5px;
        }
        .summary-card.income h3 { color: #059669; }
        .summary-card.expense h3 { color: #e11d48; }
        .summary-card.balance h3 { color: #0d9488; }
        .summary-card .amount {
            font-size: 18px;
            font-weight: bold;
        }
        .summary-card.income .amount { color: #10b981; }
        .summary-card.expense .amount { color: #f43f5e; }
        .summary-card.balance .amount { color: #14b8a6; }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 10px;
        }
        th {
            background: #14b8a6;
            color: white;
            padding: 12px 8px;
            text-align: left;
            font-size: 11px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }
        th:first-child { border-radius: 6px 0 0 0; }
        th:last-child { border-radius: 0 6px 0 0; }
        td {
            padding: 10px 8px;
            border-bottom: 1px solid #e2e8f0;
        }
        tr:hover {
            background: #f8fafc;
        }
        .type-income {
            color: #10b981;
            font-weight: 600;
        }
        .type-expense {
            color: #f43f5e;
            font-weight: 600;
        }
        .amount-cell {
            text-align: right;
            font-weight: 600;
            font-family: 'Courier New', monospace;
        }
        .footer {
            margin-top: 30px;
            padding-top: 20px;
            border-top: 1px solid #e2e8f0;
            text-align: center;
            color: #94a3b8;
            font-size: 11px;
        }
        .print-btn {
            display: block;
            width: 200px;
            margin: 20px auto;
            padding: 12px 24px;
            background: linear-gradient(135deg, #14b8a6, #0d9488);
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            text-align: center;
        }
        .print-btn:hover {
            opacity: 0.9;
        }
        @media print {
            body { background: white; padding: 0; }
            .container { box-shadow: none; padding: 0; }
            .print-btn { display: none; }
            .no-print { display: none; }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>📊 Laporan Transaksi</h1>
            <p>Periode: {{ $dateFromFormatted }} s/d {{ $dateToFormatted }}</p>
        </div>

        <div class="summary">
            <div class="summary-card income">
                <h3>Total Pemasukan</h3>
                <div class="amount">Rp {{ number_format($totalIncome, 0, ',', '.') }}</div>
            </div>
            <div class="summary-card expense">
                <h3>Total Pengeluaran</h3>
                <div class="amount">Rp {{ number_format($totalExpense, 0, ',', '.') }}</div>
            </div>
            <div class="summary-card balance">
                <h3>Selisih</h3>
                <div class="amount">Rp {{ number_format($balance, 0, ',', '.') }}</div>
            </div>
        </div>

        <table>
            <thead>
                <tr>
                    <th>Tanggal</th>
                    <th>Tipe</th>
                    <th>Kategori</th>
                    <th>Akun</th>
                    <th style="text-align: right">Jumlah</th>
                    <th>Deskripsi</th>
                </tr>
            </thead>
            <tbody>
                @forelse($transactions as $t)
                <tr>
                    <td>{{ $t->date->format('d/m/Y') }}</td>
                    <td class="{{ $t->type === 'income' ? 'type-income' : 'type-expense' }}">
                        {{ $t->type === 'income' ? 'Pemasukan' : 'Pengeluaran' }}
                    </td>
                    <td>{{ $t->category->name ?? '-' }}</td>
                    <td>{{ $t->account->name ?? '-' }}</td>
                    <td class="amount-cell {{ $t->type === 'income' ? 'type-income' : 'type-expense' }}">
                        Rp {{ number_format($t->amount, 0, ',', '.') }}
                    </td>
                    <td>{{ $t->description ?? '-' }}</td>
                </tr>
                @empty
                <tr>
                    <td colspan="6" style="text-align: center; padding: 30px; color: #94a3b8;">
                        Tidak ada transaksi pada periode ini
                    </td>
                </tr>
                @endforelse
            </tbody>
        </table>

        <button class="print-btn no-print" onclick="window.print()">
            🖨️ Cetak / Simpan PDF
        </button>

        <div class="footer">
            <p>Dicetak pada: {{ now()->format('d F Y H:i:s') }} | MyMoney - Kelola Keuangan Pribadi</p>
        </div>
    </div>
</body>
</html>
