<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Salary Sheet - {{ $payroll->month->format('F Y') }}</title>
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body { font-family: DejaVu Sans, sans-serif; font-size: 10px; color: #1a1a2e; }
        .header { background: #1a1a2e; color: #fff; padding: 16px 24px; margin-bottom: 20px; }
        .header h1 { font-size: 15px; font-weight: bold; }
        .header p { font-size: 10px; opacity: 0.7; margin-top: 2px; }
        table { width: 100%; border-collapse: collapse; margin: 0 16px; width: calc(100% - 32px); }
        th { background: #f3f4f6; padding: 6px 8px; text-align: left; font-size: 8px; text-transform: uppercase; letter-spacing: 0.05em; color: #6b7280; border-bottom: 2px solid #e5e7eb; }
        td { padding: 6px 8px; border-bottom: 1px solid #f3f4f6; font-size: 10px; }
        .num { text-align: right; }
        .ctr { text-align: center; }
        tr:nth-child(even) td { background: #f9fafb; }
        .total-row td { background: #1a1a2e !important; color: #fff; font-weight: bold; font-size: 11px; border-top: 2px solid #374151; }
        .footer { text-align: center; font-size: 9px; color: #9ca3af; margin-top: 20px; }
        .tax { color: #b45309; }
        .add { color: #059669; }
        .ded { color: #dc2626; }
    </style>
</head>
<body>
    <div class="header">
        <h1>{{ $companyName }} — Salary Sheet</h1>
        <p>Period: {{ $payroll->month->format('F Y') }} &nbsp;|&nbsp; Status: {{ ucfirst($payroll->status) }} &nbsp;|&nbsp; Generated: {{ now()->format('d M Y H:i') }}</p>
    </div>

    <table>
        <thead>
            <tr>
                <th>#</th>
                <th>Employee</th>
                <th>Department</th>
                <th class="num">Gross</th>
                <th class="num">Earnings</th>
                <th class="num">Income Tax</th>
                <th class="num">Loan</th>
                <th class="ctr">Addition</th>
                <th class="ctr">Deduction</th>
                <th class="num">Net Salary</th>
            </tr>
        </thead>
        <tbody>
            @php $totalNet = 0; $i = 1; @endphp
            @foreach($payroll->items as $item)
            <tr>
                <td>{{ $i++ }}</td>
                <td>{{ $item->employee->name }}</td>
                <td>{{ $item->employee->employeeProfile?->departmentRel?->name ?? '-' }}</td>
                <td class="num">{{ number_format($item->gross_salary, 2) }}</td>
                <td class="num">{{ number_format($item->total_earnings, 2) }}</td>
                <td class="num tax">{{ $item->tax_deduction > 0 ? '−'.number_format($item->tax_deduction, 2) : '—' }}</td>
                <td class="num ded">{{ $item->loan_deduction > 0 ? '−'.number_format($item->loan_deduction, 2) : '—' }}</td>
                <td class="ctr add">{{ $item->addition_adjustment > 0 ? '+'.number_format($item->addition_adjustment, 2) : '—' }}</td>
                <td class="ctr ded">{{ $item->deduction_adjustment > 0 ? '−'.number_format($item->deduction_adjustment, 2) : '—' }}</td>
                <td class="num">{{ number_format($item->net_salary, 2) }}</td>
            </tr>
            @php $totalNet += $item->net_salary; @endphp
            @endforeach
            <tr class="total-row">
                <td colspan="9">Total ({{ $payroll->items->count() }} employees)</td>
                <td class="num">{{ number_format($totalNet, 2) }}</td>
            </tr>
        </tbody>
    </table>

    <div class="footer">
        {{ $companyName }} &mdash; Confidential &mdash; {{ now()->format('d F Y') }}
    </div>
</body>
</html>
