{% extends 'base.html' %}
{% block title %}Cluster #{{ cluster.cluster_label }} - Run #{{ run.display_id }}{% endblock %}
{% block content %}
<div class="card">
    <a href="{% url 'analysis:cluster_overview' run.display_id %}" style="color:#4361ee;text-decoration:none;font-size:0.9rem;">← Back to overview</a>
    <h2 style="margin-top:0.5rem;">Cluster #{{ cluster.cluster_label }}</h2>
    <p>{{ cluster.size }} entities ({{ cluster.proportion|floatformat:2 }}% of total)</p>
    <p>Silhouette Score: {{ cluster.silhouette_score|floatformat:4|default:"-" }}</p>
</div>

<div class="grid-2">
    <div class="card">
        <h2>Feature Summary (top 50)</h2>
        <table>
            <thead>
                <tr>
                    <th>Feature</th>
                    <th>Mean</th>
                    <th>Std</th>
                    <th>Median</th>
                    <th>Dist. Score</th>
                </tr>
            </thead>
            <tbody>
                {% for f in features %}
                <tr>
                    <td><code>{{ f.feature_name }}</code></td>
                    <td>{{ f.mean|floatformat:3|default:"-" }}</td>
                    <td>{{ f.std|floatformat:3|default:"-" }}</td>
                    <td>{{ f.median|floatformat:3|default:"-" }}</td>
                    <td>{{ f.distinguishing_score|floatformat:3|default:"-" }}</td>
                </tr>
                {% empty %}
                <tr><td colspan="5">No features</td></tr>
                {% endfor %}
            </tbody>
        </table>
    </div>

    <div class="card">
        <h2>Entities (top 50)</h2>
        <table>
            <thead>
                <tr>
                    <th>Entity</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                {% for e in entities %}
                <tr>
                    <td><code>{{ e.entity_value }}</code></td>
                    <td><a href="{% url 'analysis:entity_profile' e.id %}" class="btn btn-primary">Profile</a></td>
                </tr>
                {% empty %}
                <tr><td colspan="2">No entities</td></tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>
{% endblock %}
