<% if (!laeufe.length) { %>
    <p class="text-sm text-gray-500 dark:text-gray-400">Noch kein Suchlauf durchgeführt.</p>
<% } else { %>
    <div class="overflow-x-auto">
        <table class="w-full text-sm">
            <thead>
                <tr class="text-left text-xs uppercase tracking-wide text-gray-500 dark:text-gray-400 border-b border-gray-200 dark:border-gray-700">
                    <th class="py-2 pr-4 font-medium">Zeitpunkt</th>
                    <th class="py-2 pr-4 font-medium">Auslöser</th>
                    <th class="py-2 pr-4 font-medium">Status</th>
                    <th class="py-2 pr-4 font-medium">Ergebnis</th>
                </tr>
            </thead>
            <tbody>
                <% laeufe.forEach(function (l) {
                     var badge = {
                       angefordert: 'bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-200',
                       laeuft:      'bg-blue-100 text-blue-800 dark:bg-blue-900/40 dark:text-blue-300',
                       fertig:      'bg-green-100 text-green-800 dark:bg-green-900/40 dark:text-green-300',
                       fehler:      'bg-red-100 text-red-800 dark:bg-red-900/40 dark:text-red-300'
                     }[l.status] || 'bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-200';
                     var text = {
                       angefordert: 'wartet', laeuft: 'läuft…', fertig: 'fertig', fehler: 'Fehler'
                     }[l.status] || l.status;
                     var zeit = l.gestartet_at || l.angefordert_at;
                %>
                    <tr class="border-b border-gray-100 dark:border-gray-700/60">
                        <td class="py-2 pr-4 text-gray-700 dark:text-gray-300 whitespace-nowrap">
                            <%= zeit ? new Date(zeit + 'Z').toLocaleString('de-DE', { dateStyle: 'short', timeStyle: 'short' }) : '–' %>
                        </td>
                        <td class="py-2 pr-4 text-gray-500 dark:text-gray-400">
                            <%= l.ausloeser === 'zeitplan' ? 'Zeitplan' : 'manuell' %>
                        </td>
                        <td class="py-2 pr-4">
                            <span class="inline-block px-2 py-0.5 rounded text-xs font-medium <%= badge %>"><%= text %></span>
                        </td>
                        <td class="py-2 pr-4 text-gray-700 dark:text-gray-300">
                            <% if (l.status === 'fertig') { %>
                                <span class="font-medium text-green-700 dark:text-green-400"><%= l.neu || 0 %> neu</span>,
                                <%= l.dubletten || 0 %> Dubletten, <%= l.verworfen || 0 %> verworfen
                            <% } else if (l.status === 'fehler') { %>
                                <span class="text-red-700 dark:text-red-400" title="<%= l.fehler || '' %>">
                                    <%= (l.fehler || 'Unbekannter Fehler').slice(0, 80) %>
                                </span>
                            <% } else { %>
                                <span class="text-gray-400 dark:text-gray-500">–</span>
                            <% } %>
                        </td>
                    </tr>
                <% }); %>
            </tbody>
        </table>
    </div>
<% } %>
