<!doctype html>
<html lang="tr">
<head>
    <meta charset="utf-8">
    <title>Ajans Yönetim Raporu</title>
    <style>
        body{font-family:Arial,Helvetica,sans-serif;color:#1f2937;margin:0;background:#f3f4f6} .wrap{max-width:1100px;margin:0 auto;background:#fff;min-height:100vh} .hero{background:#111827;color:#fff;padding:36px} .hero h1{margin:0 0 8px;font-size:28px}.hero p{margin:0;color:#d1d5db}.section{padding:24px 36px;border-bottom:1px solid #e5e7eb}.grid{display:grid;grid-template-columns:repeat(4,1fr);gap:14px}.card{border:1px solid #e5e7eb;border-radius:12px;padding:16px}.label{font-size:12px;color:#6b7280}.value{font-size:24px;font-weight:700;margin-top:6px}table{width:100%;border-collapse:collapse}th,td{border-bottom:1px solid #e5e7eb;text-align:left;padding:10px;font-size:13px}th{background:#f9fafb}.pill{display:inline-block;padding:4px 8px;border-radius:999px;background:#eef2ff;color:#3730a3;font-size:12px}.rec{background:#f9fafb;border-left:4px solid #4f46e5;padding:12px;margin:8px 0;border-radius:8px}
    </style>
</head>
<body>
<div class="wrap">
    <div class="hero">
        <span class="pill">{{ $payload['summary']['title'] }}</span>
        <h1>Ajans KPI / Yönetim Raporu</h1>
        <p>{{ $payload['summary']['range_label'] }} · Oluşturma: {{ $payload['summary']['generated_at'] }}</p>
    </div>

    <div class="section">
        <h2>Yönetici Özeti</h2>
        <p>{{ $payload['summary']['text'] }}</p>
        @foreach($payload['recommendations'] as $recommendation)
            <div class="rec">{{ $recommendation }}</div>
        @endforeach
    </div>

    <div class="section">
        <h2>Ana KPI'lar</h2>
        <div class="grid">
            <div class="card"><div class="label">Ajans Sağlığı</div><div class="value">{{ $payload['overall_score'] }}/100</div></div>
            <div class="card"><div class="label">Toplam Müşteri</div><div class="value">{{ $payload['kpis']['total_clients'] ?? 0 }}</div></div>
            <div class="card"><div class="label">Riskli Müşteri</div><div class="value">{{ $payload['kpis']['risk_clients'] ?? 0 }}</div></div>
            <div class="card"><div class="label">API Hatası</div><div class="value">{{ $payload['kpis']['api_errors'] ?? 0 }}</div></div>
        </div>
    </div>

    <div class="section">
        <h2>Riskli Müşteriler</h2>
        <table>
            <thead><tr><th>Müşteri</th><th>Skor</th><th>Durum</th><th>Risk</th></tr></thead>
            <tbody>
            @forelse($payload['risk_clients'] as $client)
                <tr><td>{{ $client['company_name'] }}</td><td>{{ $client['score'] }}/100</td><td>{{ $client['status_label'] }}</td><td>{{ $client['risk_count'] }}</td></tr>
            @empty
                <tr><td colspan="4">Riskli müşteri yok.</td></tr>
            @endforelse
            </tbody>
        </table>
    </div>

    <div class="section">
        <h2>Kanal Sağlığı</h2>
        <table>
            <thead><tr><th>Kanal</th><th>Toplam</th><th>Aktif</th><th>Hata</th><th>Skor</th></tr></thead>
            <tbody>
            @foreach($payload['channel_health'] as $item)
                <tr><td>{{ $item['label'] }}</td><td>{{ $item['total'] }}</td><td>{{ $item['active'] }}</td><td>{{ $item['errors'] }}</td><td>{{ $item['score'] }}/100</td></tr>
            @endforeach
            </tbody>
        </table>
    </div>
</div>
</body>
</html>
