<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <title>Bilan de compétences</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 2em; }
        h1, h2 { color: #059669; }
        .student-info { margin-bottom: 2em; }
        .domain-table { width: 100%; border-collapse: collapse; margin-bottom: 2em; }
        .domain-header th {
            background: #d1fae5;
            color: #065f46;
            font-size: 1.1em;
            padding: 0.7em;
            text-align: left;
        }
        .category-row td {
            background: #f0fdf4;
            color: #059669;
            font-weight: bold;
            font-size: 1em;
            padding: 0.6em;
        }
        th, td { border: 1px solid #e5e7eb; padding: 0.5em; }
        th.competence-header { background: #d1fae5; }
        td.competence-nom { word-break: break-word; max-width: 320px; }
    </style>
</head>
<body>
    <h1>Bilan de compétences</h1>
    <div class="student-info">
        <strong>Élève :</strong> {{ student.last_name }} {{ student.first_name }}<br>
        <strong>Niveau :</strong> {{ student.level }}<br>
        <strong>Classe :</strong> {{ student.class_name }}<br>
        <strong>Période :</strong> {{ period }}<br>
        <strong>Date :</strong> {{ date }}
    </div>

    {% for domaine in domaines %}
    <table class="domain-table" {% if not forloop.first %}style="page-break-before: always;"{% endif %}>
        <thead>
            <tr class="domain-header">
                <th colspan="4" style="text-align:center">{{ domaine.nom }}</th>
            </tr>
            <tr>
                <th class="competence-header" style="min-width: 120px;">Compétences</th>
                <th class="competence-header" style="width: 28px; text-align:center;">1</th>
                <th class="competence-header" style="width: 28px; text-align:center;">2</th>
                <th class="competence-header" style="width: 28px; text-align:center;">3</th>
            </tr>
        </thead>
        <tbody>
            {% for categorie in domaine.categories %}
            <tr class="category-row">
                <td colspan="4">{{ categorie.nom }}</td>
            </tr>
                {% for competence in categorie.competences %}
                <tr>
                    <td class="competence-nom">{{ competence.nom }}</td>
                    {% for note in "123" %}
                    <td style="text-align:center; width:28px;">
                        {% if competence.score|stringformat:"s" == note %}
                            <span style="color:#059669; font-weight:bold; font-size:1.1em;">&#10003;</span>
                        {% endif %}
                    </td>
                    {% endfor %}
                </tr>
                {% endfor %}
            {% endfor %}
        </tbody>
    </table>
    {% endfor %}

    <div style="margin-top: 60px; padding: 0; max-width: 700px;">
        <div style="
            min-height: 180px;
            background: #fff;
            border: 1.5px dashed #a7f3d0;
            border-radius: 12px;
            padding: 24px 24px 18px 24px;
            display: flex;
            flex-direction: column;
            justify-content: flex-start;
            position: relative;
            margin-bottom: 64px; /* Augmente l'espace après l'encadré */
        ">
            <div style="font-weight: bold; color: #059669; font-size: 1.25em; display: flex; align-items: center; gap: 8px; margin-bottom: 8px;">
                <span>Appréciation générale / Commentaire : </span>
            </div>
            <!-- Espace vide pour écrire -->
            <div style="flex:1;"></div>
            <div style="flex:1;"></div>
            <div style="flex:1;"></div>
            <div style="flex:1;"></div>
            <div style="flex:1;"></div>
            <div style="flex:1;"></div>
            <div style="flex:1;"></div>
        </div>
        <div style="display: flex; justify-content: flex-end; gap: 48px; margin-top: 32px;">
            <div>
                <span style="font-weight: bold; color: #059669;font-size: 1.25em;">Date :</span>
                <span style="display: inline-block; min-width: 120px; border-bottom: 1.5px solid #a7f3d0; margin-left: 8px;">&nbsp;</span>
            </div>
            <div>
                <span style="font-weight: bold; color: #059669;font-size: 1.25em;">Signature :</span>
                <span style="display: inline-block; min-width: 180px; border-bottom: 2px solid #059669; margin-left: 8px;">&nbsp;</span>
            </div>
        </div>
    </div>
</body>
</html>