<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <title>Zeugnis - {{ data.student_name }}</title>
</head>
<body>
    <div class="certificate-header">
        {% if data.school_info %}
        <div class="school-name" style="font-size: 14pt;">{{ data.school_info.name }}</div>
        {% endif %}
        <div class="certificate-title">
            {% if data.certificate_type == 'halbjahr' %}
            Halbjahreszeugnis
            {% elif data.certificate_type == 'jahres' %}
            Jahreszeugnis
            {% elif data.certificate_type == 'abschluss' %}
            Abschlusszeugnis
            {% else %}
            Zeugnis
            {% endif %}
        </div>
        <div>Schuljahr {{ data.school_year }}</div>
    </div>

    <div class="student-info">
        <table style="width: 100%;">
            <tr>
                <td><strong>Name:</strong> {{ data.student_name }}</td>
                <td><strong>Geburtsdatum:</strong> {{ data.student_birthdate }}</td>
            </tr>
            <tr>
                <td><strong>Klasse:</strong> {{ data.student_class }}</td>
                <td>&nbsp;</td>
            </tr>
        </table>
    </div>

    <h3>Leistungen</h3>
    <table class="grades-table">
        <thead>
            <tr>
                <th style="width: 60%;">Fach</th>
                <th style="width: 20%;">Note</th>
                <th style="width: 20%;">Punkte</th>
            </tr>
        </thead>
        <tbody>
            {% for subject in data.subjects %}
            <tr>
                <td>{{ subject.name }}</td>
                <td class="grade-cell" style="color: {{ subject.grade | grade_color }};">
                    {{ subject.grade }}
                </td>
                <td class="grade-cell">{{ subject.points | default('-') }}</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>

    {% if data.social_behavior or data.work_behavior %}
    <h3>Verhalten</h3>
    <table class="grades-table" style="width: 50%;">
        {% if data.social_behavior %}
        <tr>
            <td>Sozialverhalten</td>
            <td class="grade-cell">{{ data.social_behavior }}</td>
        </tr>
        {% endif %}
        {% if data.work_behavior %}
        <tr>
            <td>Arbeitsverhalten</td>
            <td class="grade-cell">{{ data.work_behavior }}</td>
        </tr>
        {% endif %}
    </table>
    {% endif %}

    <div class="attendance-box">
        <strong>Versäumte Tage:</strong> {{ data.attendance.days_absent | default(0) }}
        (davon entschuldigt: {{ data.attendance.days_excused | default(0) }},
        unentschuldigt: {{ data.attendance.days_unexcused | default(0) }})
    </div>

    {% if data.remarks %}
    <div style="margin-bottom: 20px;">
        <strong>Bemerkungen:</strong><br>
        {{ data.remarks }}
    </div>
    {% endif %}

    <div style="margin-top: 30px;">
        <strong>Ausgestellt am:</strong> {{ data.issue_date }}
    </div>

    <div class="signatures-row">
        <div class="signature-block">
            <div class="signature-line">{{ data.class_teacher }}</div>
            <div style="font-size: 9pt;">Klassenlehrer/in</div>
        </div>
        <div class="signature-block">
            <div class="signature-line">{{ data.principal }}</div>
            <div style="font-size: 9pt;">Schulleiter/in</div>
        </div>
    </div>

    <div style="text-align: center; margin-top: 40px;">
        <div style="font-size: 9pt; color: #666;">Siegel der Schule</div>
    </div>

    <div style="font-size: 8pt; color: #999; margin-top: 30px; text-align: center;">
        Erstellt mit BreakPilot | {{ generated_at }}
    </div>
</body>
</html>
