@php
    $kpis = $report->kpis ?? [];
    $summary = $report->summary ?? [];
@endphp
<!doctype html>
<html lang="tr">
<head>
    <meta charset="utf-8">
    <title>{{ $report->periodLabel() }} Ajans Yönetim Raporu</title>
</head>
<body style="font-family:Arial, Helvetica, sans-serif;background:#f5f7fb;margin:0;padding:24px;color:#1f2937;">
    <table width="100%" cellpadding="0" cellspacing="0" role="presentation" style="max-width:760px;margin:0 auto;background:#ffffff;border-radius:14px;overflow:hidden;border:1px solid #e5e7eb;">
        <tr>
            <td style="padding:26px 30px;background:#101827;color:#ffffff;">
                <h1 style="margin:0;font-size:24px;">{{ $report->periodLabel() }} Ajans Yönetim Raporu</h1>
                <p style="margin:8px 0 0;color:#cbd5e1;">{{ optional($report->date_from)->format('d.m.Y') }} - {{ optional($report->date_to)->format('d.m.Y') }}</p>
            </td>
        </tr>
        <tr>
            <td style="padding:26px 30px;">
                @if(!empty($note))
                    <p style="font-size:15px;line-height:1.6;margin-top:0;">{{ $note }}</p>
                @endif

                <div style="padding:18px;background:#f8fafc;border:1px solid #e5e7eb;border-radius:12px;margin-bottom:18px;">
                    <strong>Yönetici Özeti</strong>
                    <p style="margin:8px 0 0;line-height:1.6;">{{ $summary['text'] ?? 'Ajans yönetim raporu oluşturuldu.' }}</p>
                </div>

                <table width="100%" cellpadding="0" cellspacing="0" role="presentation" style="margin-bottom:18px;">
                    <tr>
                        <td style="padding:12px;background:#eef2ff;border-radius:10px;width:25%;"><strong>Skor</strong><br>{{ $report->overall_score }}/100</td>
                        <td style="padding:12px;background:#fef3c7;border-radius:10px;width:25%;"><strong>Riskli Müşteri</strong><br>{{ $kpis['risk_clients'] ?? 0 }}</td>
                        <td style="padding:12px;background:#ecfeff;border-radius:10px;width:25%;"><strong>API Hatası</strong><br>{{ $kpis['api_errors'] ?? 0 }}</td>
                        <td style="padding:12px;background:#f0fdf4;border-radius:10px;width:25%;"><strong>Gönderilen Mail</strong><br>{{ $kpis['emails_sent'] ?? 0 }}</td>
                    </tr>
                </table>

                @if(!empty($report->recommendations))
                    <h3 style="font-size:17px;margin:0 0 10px;">Önerilen Aksiyonlar</h3>
                    <ul style="margin-top:0;line-height:1.7;">
                        @foreach(array_slice($report->recommendations, 0, 6) as $recommendation)
                            <li>{{ $recommendation }}</li>
                        @endforeach
                    </ul>
                @endif

                <p style="font-size:13px;color:#64748b;line-height:1.6;">HTML ve CSV çıktıları ek olarak gönderildiyse mail eklerinde yer alır. Panelden raporu tekrar oluşturabilir veya tekrar gönderebilirsiniz.</p>
            </td>
        </tr>
    </table>
</body>
</html>
