<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>{{ __('medbilling::lang.claim') }} {{ $claim->claim_no }}</title>
    <style>
        body { font-family: DejaVu Sans, Arial, sans-serif; font-size: 12px; color: #222; margin: 24px; }
        h1 { font-size: 18px; margin: 0 0 4px; }
        .muted { color: #666; }
        table { width: 100%; border-collapse: collapse; margin-top: 12px; }
        th, td { border: 1px solid #999; padding: 6px 8px; text-align: left; }
        th { background: #f2f2f2; }
        .text-right { text-align: right; }
        .meta td { border: none; padding: 2px 8px 2px 0; }
        .totals td { border: none; padding: 2px 0; }
        .print-btn { margin-bottom: 12px; }
        @media print { .print-btn { display: none; } }
    </style>
</head>
<body>
    <div class="print-btn"><button onclick="window.print()">Print</button></div>

    <h1>{{ __('medbilling::lang.claim') }} — {{ $claim->claim_no }}</h1>
    <div class="muted">{{ optional($business)->name }}</div>

    <table class="meta" style="margin-top:12px;">
        <tr>
            <td><strong>{{ __('medbilling::lang.patient') }}:</strong> {{ $patientName }}</td>
            <td><strong>{{ __('medbilling::lang.payer') }}:</strong> {{ optional($claim->payer)->name }}</td>
        </tr>
        <tr>
            <td><strong>{{ __('medbilling::lang.policy_number') }}:</strong> {{ optional($claim->policy)->policy_number ?: '—' }}</td>
            <td><strong>{{ __('medbilling::lang.status') }}:</strong> {{ __('medbilling::lang.claim_status_' . $claim->status) }}</td>
        </tr>
        <tr>
            <td><strong>{{ __('medbilling::lang.pre_auth_no') }}:</strong> {{ $claim->pre_auth_no ?: '—' }}</td>
            <td><strong>{{ __('medbilling::lang.transaction') }}:</strong> {{ $claim->transaction_id ? '#' . $claim->transaction_id : '—' }}</td>
        </tr>
    </table>

    <table>
        <thead><tr>
            <th>{{ __('medbilling::lang.description') }}</th>
            <th class="text-right">{{ __('medbilling::lang.claimed_amount') }}</th>
            <th class="text-right">{{ __('medbilling::lang.approved_amount') }}</th>
            <th>{{ __('medbilling::lang.denied_reason') }}</th>
        </tr></thead>
        <tbody>
        @foreach($claim->items as $item)
            <tr>
                <td>{{ $item->description }}</td>
                <td class="text-right">{{ number_format($item->claimed_amount, 2) }}</td>
                <td class="text-right">{{ $item->approved_amount !== null ? number_format($item->approved_amount, 2) : '—' }}</td>
                <td>{{ $item->denied_reason ?: '' }}</td>
            </tr>
        @endforeach
        </tbody>
    </table>

    <table class="totals" style="width:40%; margin-left:60%; margin-top:12px;">
        <tr><td>{{ __('medbilling::lang.total_claimed') }}</td><td class="text-right">{{ number_format($claim->total_claimed, 2) }}</td></tr>
        <tr><td>{{ __('medbilling::lang.total_approved') }}</td><td class="text-right">{{ $claim->total_approved !== null ? number_format($claim->total_approved, 2) : '—' }}</td></tr>
        <tr><td>{{ __('medbilling::lang.patient_share') }}</td><td class="text-right">{{ number_format($claim->patient_share, 2) }}</td></tr>
        <tr><td>{{ __('medbilling::lang.payer_share') }}</td><td class="text-right">{{ number_format($claim->payer_share, 2) }}</td></tr>
    </table>

    @if($claim->denial_reason)
        <p><strong>{{ __('medbilling::lang.denied_reason') }}:</strong> {{ $claim->denial_reason }}</p>
    @endif
</body>
</html>
