<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<style>
@page {
  size: A4 landscape;
  margin: 1.5cm 2cm;
  @bottom-center {
    content: "Seite " counter(page) " von " counter(pages);
    font-size: 9px;
    color: #666;
  }
}
body {
  font-family: 'Helvetica', 'Arial', sans-serif;
  font-size: 10px;
  color: #222;
  margin: 0;
  padding: 0;
}
h1 {
  font-size: 20px;
  color: #1a365d;
  margin-bottom: 4px;
}
.subtitle {
  font-size: 10px;
  color: #666;
  margin-bottom: 20px;
}
table {
  width: 100%;
  border-collapse: collapse;
}
thead th {
  background: #1a365d;
  color: #fff;
  padding: 8px 10px;
  text-align: left;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
tbody td {
  padding: 5px 10px;
  border-bottom: 1px solid #e0e0e0;
}
tbody tr:nth-child(even) {
  background: #f7f7f7;
}
.action-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 8px;
  font-weight: 600;
}
.action-create { background: #e6f4ea; color: #1b7334; }
.action-update { background: #e8f0fe; color: #1a56c4; }
.action-delete { background: #fce8e6; color: #c5221f; }
.action-read   { background: #f0f0f0; color: #555; }
@media print {
  body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  thead { display: table-header-group; }
  tr { page-break-inside: avoid; }
}
</style>
</head>
<body>
<h1>{{ title|default('Audit-Log') }}</h1>
<div class="subtitle">Erstellt am: {{ generated_at|default('') }} &nbsp;|&nbsp; Einträge: {{ entries|length }}{% if date_from|default('') %} &nbsp;|&nbsp; Von: {{ date_from }}{% endif %}{% if date_to|default('') %} &nbsp;|&nbsp; Bis: {{ date_to }}{% endif %}</div>
<table>
  <thead>
    <tr>
      <th>#</th>
      <th>Zeitstempel</th>
      <th>Benutzer</th>
      <th>Aktion</th>
      <th>Entität</th>
      <th>Entität-ID</th>
      <th>Details</th>
    </tr>
  </thead>
  <tbody>
    {% for entry in entries %}
    <tr>
      <td>{{ loop.index }}</td>
      <td>{{ entry.timestamp|default('') }}</td>
      <td>{{ entry.user|default('—') }}</td>
      <td>
        {% set action = entry.action|default('read') %}
        <span class="action-badge action-{{ action|lower }}">{{ action|upper }}</span>
      </td>
      <td>{{ entry.entity|default('—') }}</td>
      <td>{{ entry.entity_id|default('—') }}</td>
      <td>{{ entry.details|default('—') }}</td>
    </tr>
    {% endfor %}
  </tbody>
</table>
{% if entries|length == 0 %}
<p style="text-align:center; padding:40px; color:#999;">Keine Audit-Log-Einträge gefunden.</p>
{% endif %}
</body>
</html>
