<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Shareholder Report — {{ $shareholder->name }}</title>
    <style>
        body { font-family: DejaVu Sans, sans-serif; font-size: 12px; color: #222; margin: 30px; }
        h1 { font-size: 20px; margin-bottom: 2px; }
        .subtitle { font-size: 11px; color: #666; margin-bottom: 20px; }
        .info-grid { width: 100%; margin-bottom: 20px; border-collapse: collapse; }
        .info-grid td { padding: 6px 10px; border: 1px solid #e0e0e0; width: 25%; }
        .info-label { font-size: 10px; color: #888; display: block; margin-bottom: 2px; }
        .info-value { font-weight: bold; font-size: 13px; }
        .value-green { color: #065f46; }
        .value-red { color: #991b1b; }
        .value-blue { color: #1e3a8a; }
        table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
        th { background: #1a56db; color: #fff; padding: 8px 10px; text-align: left; font-size: 11px; }
        td { padding: 7px 10px; border-bottom: 1px solid #e0e0e0; }
        .text-right { text-align: right; }
        .total-row td { font-weight: bold; background: #f0f4ff; border-top: 2px solid #1a56db; }
        .badge-active { background: #d1fae5; color: #065f46; padding: 2px 8px; border-radius: 4px; font-size: 10px; }
        .badge-inactive { background: #e5e7eb; color: #374151; padding: 2px 8px; border-radius: 4px; font-size: 10px; }
    </style>
</head>
<body>

    <h1>{{ __('Shareholder Report') }}</h1>
    <div class="subtitle">
        {{ $shareholder->name }}
        &nbsp;<span class="{{ $shareholder->is_active ? 'badge-active' : 'badge-inactive' }}">{{ $shareholder->is_active ? __('Active') : __('Inactive') }}</span>
        &nbsp;&nbsp;|&nbsp;&nbsp;{{ __('Generated') }}: {{ now()->format('Y-m-d H:i') }}
    </div>

    {{-- Summary --}}
    <table class="info-grid">
        <tr>
            <td>
                <span class="info-label">{{ __('Total Investment') }}</span>
                <span class="info-value value-green">{{ number_format($shareholder->total_investment, 2) }}</span>
            </td>
            <td>
                <span class="info-label">{{ __('Investment Withdrawn') }}</span>
                <span class="info-value value-red">{{ number_format($shareholder->total_withdrawal, 2) }}</span>
            </td>
            <td>
                <span class="info-label">{{ __('Net Investment') }}</span>
                <span class="info-value">{{ number_format($shareholder->net_investment, 2) }}</span>
            </td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>
                <span class="info-label">{{ __('Total Profit') }}</span>
                <span class="info-value value-blue">{{ number_format($shareholder->total_profit, 2) }}</span>
            </td>
            <td>
                <span class="info-label">{{ __('Profit Withdrawn') }}</span>
                <span class="info-value value-red">{{ number_format($shareholder->total_profit_withdrawal, 2) }}</span>
            </td>
            <td>
                <span class="info-label">{{ __('Net Profit') }}</span>
                <span class="info-value value-blue">{{ number_format($shareholder->net_profit, 2) }}</span>
            </td>
            <td>&nbsp;</td>
        </tr>
    </table>

    {{-- Transactions --}}
    @if($shareholder->transactions->isNotEmpty())
    <h3 style="font-size:14px; margin-bottom:8px;">{{ __('Transaction History') }}</h3>
    <table>
        <thead>
            <tr>
                <th>#</th>
                <th>{{ __('Date') }}</th>
                <th>{{ __('Type') }}</th>
                <th class="text-right">{{ __('Amount') }}</th>
                <th>{{ __('Notes') }}</th>
            </tr>
        </thead>
        <tbody>
            @php $runningBalance = 0; @endphp
            @foreach($shareholder->transactions as $i => $tx)
            <tr>
                <td>{{ $i + 1 }}</td>
                <td>{{ $tx->transaction_date->format('Y-m-d') }}</td>
                <td>{{ $tx->type_label }}</td>
                <td class="text-right">{{ number_format($tx->amount, 2) }}</td>
                <td>{{ $tx->notes }}</td>
            </tr>
            @endforeach
        </tbody>
        <tfoot>
            <tr class="total-row">
                <td colspan="3">{{ __('Total Transactions') }}</td>
                <td class="text-right">{{ number_format($shareholder->transactions->sum('amount'), 2) }}</td>
                <td></td>
            </tr>
        </tfoot>
    </table>
    @else
        <p style="color:#999;">{{ __('No transactions recorded for this shareholder.') }}</p>
    @endif

</body>
</html>
