{% if total_findings %}
<div style="display:flex; gap:1.5rem; padding:0.3rem 0; margin-bottom:1rem; border-bottom:1px solid var(--pico-color-gray-500); font-size:0.82rem; opacity:0.8; flex-wrap:wrap;">
    <span>{{ t('total_scans_label', request.state.lang) }}: <strong>{{ total_scans }}</strong></span>
    <span>{{ t('flagged_scans_label', request.state.lang) }}: <strong>{{ flagged_scans }}</strong></span>
    <span>{{ t('col_findings', request.state.lang) }}: <strong>{{ total_findings }}</strong></span>
    <span>{{ t('llm_analyzed', request.state.lang) }}: <strong>{{ llm_analyzed }}</strong></span>
    <span>{{ t('llm_pending', request.state.lang) }}: <strong>{{ llm_pending }}</strong></span>
</div>
{% endif %}
{% if top_rules %}
<article class="dash-block" style="margin-bottom:1rem;">
    <h3>{{ t('heading_top_rules', request.state.lang) }}</h3>
    <table class="compact">
        <tbody>
        {% for r in top_rules %}
            <tr><td><strong>{{ r.rule }}</strong></td><td>{{ r.count }}</td></tr>
        {% endfor %}
        </tbody>
    </table>
</article>
{% endif %}
{% if latest_flagged %}
<article class="dash-block dash-block-warn">
    <h3>{{ t('heading_latest_flagged', request.state.lang) }}</h3>
    <table class="compact">
        <thead><tr><th>{{ t('col_package', request.state.lang) }}</th><th>{{ t('col_version', request.state.lang) }}</th><th>{{ t('col_findings', request.state.lang) }}</th><th>{{ t('col_time', request.state.lang) }}</th></tr></thead>
        <tbody>
        {% for s in latest_flagged %}
            <tr>
                <td><a href="/scans/{{ s.id }}"><strong class="flagged">{{ s.package_name }}</strong></a></td>
                <td>{{ s.package_version }}</td>
                <td><span class="flagged">{{ s.total_findings }}</span></td>
                <td>{{ s.started_at.strftime('%m-%d %H:%M') if s.started_at }}</td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
</article>
{% endif %}

<article class="dash-block" style="margin-top: 0;">
    <h3>{{ t('heading_latest_scans', request.state.lang) }}</h3>
    <table class="compact">
        <thead>
            <tr><th>{{ t('col_package', request.state.lang) }}</th><th>{{ t('col_version', request.state.lang) }}</th><th>{{ t('col_repo', request.state.lang) }}</th><th>{{ t('col_status', request.state.lang) }}</th><th></th><th>{{ t('col_time', request.state.lang) }}</th></tr>
        </thead>
        <tbody>
        {% for s in latest_scans %}
            <tr>
                <td><a href="/packages/{{ s.package_name | urlencode }}/{{ s.package_version | urlencode }}">{{ s.package_name }}</a></td>
                <td>{{ s.package_version }}</td>
                <td><small>{{ s.repository }}</small></td>
                <td>
                    {% with status=s.status %}{% include "_status_badge.html" %}{% endwith %}
                </td>
                <td>{% if s.flagged %}<span class="flagged">⚠ {{ s.total_findings }}</span>{% elif s.status == 'completed' %}<span class="clean">✓</span>{% else %}<span>-</span>{% endif %}</td>
                <td>{{ s.started_at.strftime('%m-%d %H:%M') if s.started_at }}</td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
    <small><a href="/scans">{{ t('view_all_scans', request.state.lang) }}</a></small>
</article>

<small style="opacity: 0.4;">{{ t('refresh_hint', request.state.lang, now.strftime('%H:%M:%S')) }}</small>
