<!doctype html>
<html lang="es">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style>
        @page { margin: 28px 30px 58px; }
        body { color: #17211b; font-family: DejaVu Sans, sans-serif; font-size: 8px; margin: 0; }
        h1 { font-size: 21px; margin: 0 0 3px; }
        .subtitle { color: #66736b; margin: 0 0 18px; }
        table { border-collapse: collapse; table-layout: fixed; width: 100%; }
        thead { display: table-header-group; }
        tr { page-break-inside: avoid; }
        th { background: #26382e; color: #fff; font-size: 7px; letter-spacing: .35px; padding: 7px 5px; text-align: left; text-transform: uppercase; }
        td { border-bottom: 1px solid #dfe7e2; overflow-wrap: break-word; padding: 7px 5px; vertical-align: top; }
        tbody tr:nth-child(even) { background: #f7f9f8; }
        .date { width: 10%; }
        .time { width: 7%; }
        .sale { width: 8%; }
        .customer { width: 17%; }
        .attribute { width: 10%; }
        .value { width: 16%; }
        .actor { width: 16%; }
        .empty { color: #66736b; padding: 24px; text-align: center; }
    </style>
</head>
<body>
    <h1>Historial de modificaciones de ventas</h1>
    <p class="subtitle">{{ $tenant->nombre }} · Generado el {{ $generatedAt->copy()->timezone($timeZone)->format('d/m/Y H:i') }}</p>

    <table>
        <thead>
            <tr>
                <th class="date">Fecha</th>
                <th class="time">Hora</th>
                <th class="sale">Venta</th>
                <th class="customer">Cliente</th>
                <th class="attribute">Campo</th>
                <th class="value">Valor anterior</th>
                <th class="value">Valor nuevo</th>
                <th class="actor">Modificado por</th>
            </tr>
        </thead>
        <tbody>
            @forelse ($modifications as $modification)
                @php($sale = $modification->trackable)
                <tr>
                    <td>{{ $modification->changed_at->copy()->timezone($timeZone)->format('d/m/Y') }}</td>
                    <td>{{ $modification->changed_at->copy()->timezone($timeZone)->format('H:i:s') }}</td>
                    <td>#{{ $modification->trackable_id }}</td>
                    <td>{{ $sale?->nombre_apellido ?: 'Sin nombre' }}</td>
                    <td>{{ $modification->attribute }}</td>
                    <td>{{ $modification->old_value ?? '-' }}</td>
                    <td>{{ $modification->new_value ?? '-' }}</td>
                    <td>{{ $modification->user?->nombre_apellido ?? 'Sistema' }}</td>
                </tr>
            @empty
                <tr><td class="empty" colspan="8">Todavía no hay modificaciones registradas.</td></tr>
            @endforelse
        </tbody>
    </table>

</body>
</html>
