<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Cycle {{ $cycle->cycle_number }} Report — {{ $cycle->pond->name }}</title>
    <style>
        body { font-family: DejaVu Sans, sans-serif; font-size: 11px; color: #1f2937; }
        h1 { font-size: 18px; color: #16a34a; margin-bottom: 4px; }
        h2 { font-size: 13px; border-bottom: 1px solid #e5e7eb; padding-bottom: 4px; margin-top: 16px; }
        .grid { display: flex; gap: 12px; margin-bottom: 12px; }
        .stat { flex: 1; background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 6px; padding: 8px; }
        .stat-label { font-size: 9px; color: #6b7280; text-transform: uppercase; }
        .stat-value { font-size: 16px; font-weight: bold; margin-top: 2px; }
        table { width: 100%; border-collapse: collapse; margin-top: 6px; }
        th { background: #f3f4f6; text-align: left; padding: 4px 8px; font-size: 9px; text-transform: uppercase; color: #6b7280; }
        td { padding: 4px 8px; border-bottom: 1px solid #f3f4f6; }
        .text-green { color: #16a34a; } .text-red { color: #dc2626; }
        .footer { margin-top: 24px; text-align: center; font-size: 9px; color: #9ca3af; }
    </style>
</head>
<body>
    <h1>FishFarm RMS</h1>
    <p><strong>Cycle Summary Report</strong> &mdash; {{ $cycle->pond->name }}, Cycle #{{ $cycle->cycle_number }}</p>
    <p>Period: {{ $cycle->start_date->format('d M Y') }} – {{ $cycle->end_date?->format('d M Y') ?? 'Open' }} &nbsp;|&nbsp; Duration: {{ $cycle->days_elapsed }} days</p>

    <h2>Financial Summary</h2>
    <div class="grid">
        <div class="stat"><div class="stat-label">Revenue</div><div class="stat-value text-green">₦{{ number_format($totalRevenue) }}</div></div>
        <div class="stat"><div class="stat-label">Expenses</div><div class="stat-value text-red">₦{{ number_format($totalExpenses) }}</div></div>
        <div class="stat"><div class="stat-label">Gross Profit</div><div class="stat-value {{ ($totalRevenue - $totalExpenses) >= 0 ? 'text-green' : 'text-red' }}">₦{{ number_format($totalRevenue - $totalExpenses) }}</div></div>
        <div class="stat"><div class="stat-label">ROI</div><div class="stat-value">{{ $roi ? $roi . '%' : '—' }}</div></div>
    </div>
    <div class="grid">
        <div class="stat"><div class="stat-label">FCR</div><div class="stat-value">{{ $fcr ?? '—' }}</div></div>
        <div class="stat"><div class="stat-label">Cost/kg</div><div class="stat-value">{{ $costPerKg ? '₦'.number_format($costPerKg) : '—' }}</div></div>
        <div class="stat"><div class="stat-label">Revenue/kg</div><div class="stat-value">{{ $revenuePerKg ? '₦'.number_format($revenuePerKg) : '—' }}</div></div>
        <div class="stat"><div class="stat-label">Harvest Weight</div><div class="stat-value">{{ $cycle->harvestRecord ? number_format($cycle->harvestRecord->total_weight_kg, 1).' kg' : '—' }}</div></div>
    </div>

    <h2>Stocking</h2>
    <table>
        <tr><th>Species</th><th>Quantity</th><th>Avg Weight</th><th>Cost</th></tr>
        @foreach($cycle->stockingRecords as $sr)
        <tr>
            <td>{{ $sr->species }}</td>
            <td>{{ number_format($sr->quantity) }}</td>
            <td>{{ $sr->avg_weight_g }}g</td>
            <td>₦{{ number_format($sr->total_cost) }}</td>
        </tr>
        @endforeach
    </table>

    <div class="footer">Generated by FishFarm RMS &mdash; {{ now()->format('d M Y H:i') }}</div>
</body>
</html>
