<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>{{ $meta['title'] ?? 'Subscription Report' }}</title>
    <style>
        body { font-family: 'Helvetica', Arial, sans-serif; font-size: 12px; color: #333; margin: 40px; }
        table.data { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
        table.data th { background-color: #1d4ed8; color: white; padding: 8px 12px; text-align: left; font-size: 11px; text-transform: uppercase; }
        table.data th.text-right { text-align: right; }
        table.data th.text-center { text-align: center; }
        table.data td { padding: 8px 12px; border-bottom: 1px solid #eee; }
        table.data tr:nth-child(even) { background-color: #f8fafc; }
        .section-title { font-size: 14px; font-weight: bold; color: #1d4ed8; margin: 20px 0 10px; border-bottom: 1px solid #e2e8f0; padding-bottom: 5px; }
        .metrics-grid { width: 100%; margin-bottom: 20px; }
        .metrics-grid td { padding: 8px; width: 33%; }
        .metric-box { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 4px; padding: 12px; text-align: center; }
        .metric-value { font-size: 20px; font-weight: bold; }
        .metric-label { font-size: 10px; color: #64748b; text-transform: uppercase; margin-top: 4px; }
        .color-green { color: #16a34a; }
        .color-red { color: #dc2626; }
        .color-blue { color: #1d4ed8; }
        .footer { margin-top: 40px; text-align: center; font-size: 10px; color: #999; border-top: 1px solid #eee; padding-top: 15px; }
    </style>
</head>
<body>
    @include('reports._header')

    <table class="metrics-grid">
        <tr>
            <td>
                <div class="metric-box">
                    <div class="metric-value color-green">{{ $data['new_subscriptions'] ?? 0 }}</div>
                    <div class="metric-label">New Subscriptions</div>
                </div>
            </td>
            <td>
                <div class="metric-box">
                    <div class="metric-value color-red">{{ $data['cancelled_subscriptions'] ?? 0 }}</div>
                    <div class="metric-label">Cancelled</div>
                </div>
            </td>
            <td>
                <div class="metric-box">
                    <div class="metric-value" style="color: {{ ($data['churn_rate'] ?? 0) < 3 ? '#16a34a' : (($data['churn_rate'] ?? 0) <= 7 ? '#ca8a04' : '#dc2626') }}">
                        {{ $data['churn_rate'] ?? 0 }}%
                    </div>
                    <div class="metric-label">Churn Rate</div>
                </div>
            </td>
        </tr>
    </table>

    <div class="section-title">Monthly Recurring Revenue</div>
    <table class="data">
        <thead>
            <tr>
                <th>Metric</th>
                <th class="text-right" style="text-align: right;">Value</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>MRR at Start</td>
                <td style="text-align: right;">${{ number_format($data['mrr_start'] ?? 0, 2) }}</td>
            </tr>
            <tr>
                <td>MRR at End</td>
                <td style="text-align: right;">${{ number_format($data['mrr_end'] ?? 0, 2) }}</td>
            </tr>
            <tr>
                <td><strong>MRR Change</strong></td>
                <td style="text-align: right; color: {{ ($data['mrr_change'] ?? 0) >= 0 ? '#16a34a' : '#dc2626' }}">
                    <strong>{{ ($data['mrr_change'] ?? 0) >= 0 ? '+' : '' }}${{ number_format($data['mrr_change'] ?? 0, 2) }}</strong>
                </td>
            </tr>
        </tbody>
    </table>

    @if(!empty($data['by_plan']))
        <div class="section-title">Breakdown by Plan</div>
        <table class="data">
            <thead>
                <tr>
                    <th>Plan</th>
                    <th class="text-center" style="text-align: center;">New</th>
                    <th class="text-center" style="text-align: center;">Cancelled</th>
                    <th class="text-center" style="text-align: center;">Active</th>
                </tr>
            </thead>
            <tbody>
                @foreach($data['by_plan'] as $row)
                    <tr>
                        <td>{{ $row['plan'] }}</td>
                        <td style="text-align: center; color: #16a34a;">{{ $row['new'] }}</td>
                        <td style="text-align: center; color: #dc2626;">{{ $row['cancelled'] }}</td>
                        <td style="text-align: center;">{{ $row['active'] }}</td>
                    </tr>
                @endforeach
            </tbody>
        </table>
    @endif

    <div class="footer">
        <p>EZSCALE &mdash; Cloud Infrastructure Services &mdash; support@ezscale.cloud</p>
    </div>
</body>
</html>
