<x-filament-panels::page>
@php $rows = $this->getRows(); @endphp
<style>
.kpi-toolbar { display:flex; align-items:center; gap:12px; margin-bottom:18px; background:white; padding:12px 16px; border-radius:8px; border:1px solid #e2e8f0; }
.dark .kpi-toolbar { background:#1f2937; border-color:#374151; }
.kpi-period { font-size:16px; font-weight:600; min-width:200px; text-align:center; }
.kpi-btn { padding:6px 12px; border:1px solid #cbd5e1; border-radius:6px; background:white; cursor:pointer; }
.kpi-table { width:100%; border-collapse:collapse; background:white; border-radius:8px; overflow:hidden; border:1px solid #e2e8f0; }
.dark .kpi-table { background:#1f2937; border-color:#374151; }
.kpi-table th, .kpi-table td { padding:10px 14px; text-align:left; border-bottom:1px solid #e2e8f0; }
.kpi-table th { background:#f7fafc; font-size:12px; text-transform:uppercase; letter-spacing:.3px; color:#4a5568; }
.kpi-table tr:last-child td { border-bottom:none; }
.kpi-badge { display:inline-block; padding:2px 8px; border-radius:4px; font-size:12px; font-weight:600; }
.kpi-green { background:#dcfce7; color:#15803d; }
.kpi-amber { background:#fef3c7; color:#92400e; }
.kpi-red { background:#fee2e2; color:#991b1b; }
.kpi-gray { background:#f1f5f9; color:#475569; }
.kpi-empty { padding:32px; text-align:center; color:#718096; }
</style>

<div class="kpi-toolbar">
    <button class="kpi-btn" wire:click="shiftMonth(-1)">◀ Luna precedentă</button>
    <div class="kpi-period">{{ $this->getPeriodLabel() }}</div>
    <button class="kpi-btn" wire:click="shiftMonth(1)">Luna următoare ▶</button>
</div>

@if (empty($rows))
    <div class="kpi-empty">Niciun mecanic nu a finalizat lucrări în această perioadă.</div>
@else
    <table class="kpi-table">
        <thead>
            <tr>
                <th>Mecanic</th>
                <th>Lucrări</th>
                <th>Norma ore</th>
                <th>Real ore</th>
                <th>Eficiență</th>
                <th>Venit manopere</th>
            </tr>
        </thead>
        <tbody>
            @foreach ($rows as $r)
                <tr>
                    <td style="font-weight:600">{{ $r['master_name'] }}</td>
                    <td>{{ $r['tasks_done'] }}</td>
                    <td>{{ $r['norm_hours'] }}</td>
                    <td>{{ $r['actual_hours'] }}</td>
                    <td>@if ($r['efficiency_pct'] !== null)<span class="kpi-badge kpi-{{ $r['efficiency_class'] }}">{{ $r['efficiency_pct'] }}%</span>@else <span class="kpi-badge kpi-gray">—</span>@endif</td>
                    <td>{{ number_format($r['revenue'], 0, '.', ' ') }} MDL</td>
                </tr>
            @endforeach
        </tbody>
    </table>
@endif
</x-filament-panels::page>
