<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <title>DSGVO Datenauskunft - BreakPilot</title>
    <style>
        @page {
            size: A4;
            margin: 2cm 1.5cm;
            @top-right {
                content: "Seite " counter(page) " von " counter(pages);
                font-size: 9pt;
                color: #666;
            }
            @bottom-center {
                content: "BreakPilot - Vertraulich";
                font-size: 8pt;
                color: #999;
            }
        }

        * {
            box-sizing: border-box;
        }

        body {
            font-family: 'Helvetica Neue', Arial, sans-serif;
            font-size: 10pt;
            line-height: 1.5;
            color: #333;
            margin: 0;
            padding: 0;
        }

        /* Header */
        .header {
            border-bottom: 3px solid #2563eb;
            padding-bottom: 20px;
            margin-bottom: 30px;
        }

        .header-top {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
        }

        .logo {
            font-size: 24pt;
            font-weight: bold;
            color: #2563eb;
        }

        .logo span {
            color: #1e40af;
        }

        .header-info {
            text-align: right;
            font-size: 9pt;
            color: #666;
        }

        .document-title {
            font-size: 18pt;
            font-weight: bold;
            color: #1f2937;
            margin-top: 15px;
            margin-bottom: 5px;
        }

        .document-subtitle {
            font-size: 11pt;
            color: #6b7280;
        }

        /* Sections */
        .section {
            margin-bottom: 25px;
            page-break-inside: avoid;
        }

        .section-title {
            font-size: 14pt;
            font-weight: bold;
            color: #1f2937;
            border-bottom: 2px solid #e5e7eb;
            padding-bottom: 8px;
            margin-bottom: 15px;
        }

        .section-number {
            color: #2563eb;
            margin-right: 8px;
        }

        /* Tables */
        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 15px;
            font-size: 9pt;
        }

        th {
            background-color: #f3f4f6;
            color: #374151;
            font-weight: 600;
            text-align: left;
            padding: 10px 8px;
            border: 1px solid #d1d5db;
        }

        td {
            padding: 8px;
            border: 1px solid #e5e7eb;
            vertical-align: top;
        }

        tr:nth-child(even) {
            background-color: #f9fafb;
        }

        /* Info boxes */
        .info-box {
            background-color: #f0f9ff;
            border-left: 4px solid #2563eb;
            padding: 12px 15px;
            margin: 15px 0;
            font-size: 9pt;
        }

        .warning-box {
            background-color: #fef3c7;
            border-left: 4px solid #f59e0b;
            padding: 12px 15px;
            margin: 15px 0;
            font-size: 9pt;
        }

        /* Key-value pairs */
        .kv-grid {
            display: grid;
            grid-template-columns: 180px 1fr;
            gap: 8px 15px;
            margin-bottom: 15px;
        }

        .kv-label {
            font-weight: 600;
            color: #4b5563;
        }

        .kv-value {
            color: #1f2937;
        }

        /* Status badges */
        .badge {
            display: inline-block;
            padding: 2px 8px;
            border-radius: 4px;
            font-size: 8pt;
            font-weight: 600;
        }

        .badge-green {
            background-color: #d1fae5;
            color: #065f46;
        }

        .badge-red {
            background-color: #fee2e2;
            color: #991b1b;
        }

        .badge-yellow {
            background-color: #fef3c7;
            color: #92400e;
        }

        .badge-blue {
            background-color: #dbeafe;
            color: #1e40af;
        }

        /* Footer */
        .footer {
            margin-top: 40px;
            padding-top: 20px;
            border-top: 1px solid #e5e7eb;
            font-size: 8pt;
            color: #6b7280;
        }

        .footer-grid {
            display: grid;
            grid-template-columns: 1fr 1fr 1fr;
            gap: 20px;
        }

        .footer-section h4 {
            font-size: 9pt;
            font-weight: 600;
            color: #374151;
            margin-bottom: 8px;
        }

        /* Page break utilities */
        .page-break {
            page-break-before: always;
        }

        .no-break {
            page-break-inside: avoid;
        }

        /* Retention periods */
        .retention-table td:last-child {
            text-align: center;
            font-weight: 600;
        }
    </style>
</head>
<body>
    <!-- Header -->
    <div class="header">
        <div class="header-top">
            <div class="logo">Break<span>Pilot</span></div>
            <div class="header-info">
                <strong>Erstellungsdatum:</strong> {{ export_date }}<br>
                <strong>Dokument-ID:</strong> {{ document_id }}
            </div>
        </div>
        <div class="document-title">Auskunft uber gespeicherte personenbezogene Daten</div>
        <div class="document-subtitle">Gemaß Art. 15 DSGVO (Datenschutz-Grundverordnung)</div>
    </div>

    <!-- Section 1: Personal Data -->
    <div class="section">
        <h2 class="section-title"><span class="section-number">1.</span> Ihre personlichen Daten</h2>

        <div class="kv-grid">
            <div class="kv-label">Benutzer-ID:</div>
            <div class="kv-value">{{ user.id }}</div>

            <div class="kv-label">E-Mail-Adresse:</div>
            <div class="kv-value">{{ user.email }}</div>

            {% if user.name %}
            <div class="kv-label">Name:</div>
            <div class="kv-value">{{ user.name }}</div>
            {% endif %}

            <div class="kv-label">Registriert am:</div>
            <div class="kv-value">{{ user.created_at | format_datetime }}</div>

            {% if user.last_login %}
            <div class="kv-label">Letzter Login:</div>
            <div class="kv-value">{{ user.last_login | format_datetime }}</div>
            {% endif %}

            <div class="kv-label">Kontostatus:</div>
            <div class="kv-value">
                {% if user.account_status == 'active' %}
                <span class="badge badge-green">Aktiv</span>
                {% elif user.account_status == 'suspended' %}
                <span class="badge badge-yellow">Gesperrt</span>
                {% else %}
                <span class="badge badge-blue">{{ user.account_status }}</span>
                {% endif %}
            </div>
        </div>
    </div>

    <!-- Section 2: Consent History -->
    <div class="section">
        <h2 class="section-title"><span class="section-number">2.</span> Einwilligungen & Zustimmungen</h2>

        {% if consents %}
        <table>
            <thead>
                <tr>
                    <th style="width: 25%">Dokument</th>
                    <th style="width: 15%">Version</th>
                    <th style="width: 15%">Status</th>
                    <th style="width: 25%">Zugestimmt am</th>
                    <th style="width: 20%">Widerrufen am</th>
                </tr>
            </thead>
            <tbody>
                {% for consent in consents %}
                <tr>
                    <td>{{ consent.document_name }}</td>
                    <td>{{ consent.version }}</td>
                    <td>
                        {% if consent.consented %}
                        <span class="badge badge-green">Zugestimmt</span>
                        {% else %}
                        <span class="badge badge-red">Widerrufen</span>
                        {% endif %}
                    </td>
                    <td>{{ consent.consented_at | format_datetime }}</td>
                    <td>{{ consent.withdrawn_at | format_datetime if consent.withdrawn_at else '-' }}</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        {% else %}
        <div class="info-box">Keine Einwilligungen vorhanden.</div>
        {% endif %}
    </div>

    <!-- Section 3: Cookie Preferences -->
    <div class="section">
        <h2 class="section-title"><span class="section-number">3.</span> Cookie-Praferenzen</h2>

        {% if cookie_consents %}
        <table>
            <thead>
                <tr>
                    <th style="width: 30%">Kategorie</th>
                    <th style="width: 20%">Status</th>
                    <th style="width: 25%">Aktualisiert am</th>
                    <th style="width: 25%">Beschreibung</th>
                </tr>
            </thead>
            <tbody>
                {% for cookie in cookie_consents %}
                <tr>
                    <td><strong>{{ cookie.category }}</strong></td>
                    <td>
                        {% if cookie.consented %}
                        <span class="badge badge-green">Akzeptiert</span>
                        {% else %}
                        <span class="badge badge-red">Abgelehnt</span>
                        {% endif %}
                    </td>
                    <td>{{ cookie.updated_at | format_datetime }}</td>
                    <td>{{ cookie.description | default('-', true) }}</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        {% else %}
        <div class="info-box">Keine Cookie-Praferenzen gespeichert.</div>
        {% endif %}
    </div>

    <!-- Section 4: Activity Log -->
    <div class="section page-break">
        <h2 class="section-title"><span class="section-number">4.</span> Aktivitatsprotokoll</h2>

        <div class="info-box">
            Die folgenden Aktivitaten wurden in Ihrem Konto protokolliert.
            IP-Adressen werden nach 4 Wochen automatisch anonymisiert.
        </div>

        {% if audit_logs %}
        <table>
            <thead>
                <tr>
                    <th style="width: 20%">Datum</th>
                    <th style="width: 25%">Aktion</th>
                    <th style="width: 20%">IP-Adresse</th>
                    <th style="width: 35%">Details</th>
                </tr>
            </thead>
            <tbody>
                {% for log in audit_logs[:50] %}
                <tr>
                    <td>{{ log.created_at | format_datetime }}</td>
                    <td>{{ log.action | translate_action }}</td>
                    <td>{{ log.ip_address | default('Anonymisiert', true) }}</td>
                    <td>{{ log.details | default('-', true) }}</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        {% if audit_logs | length > 50 %}
        <div class="info-box">
            Es werden die letzten 50 Einträge angezeigt.
            Insgesamt {{ audit_logs | length }} Aktivitaten protokolliert.
        </div>
        {% endif %}
        {% else %}
        <div class="info-box">Kein Aktivitatsprotokoll vorhanden.</div>
        {% endif %}
    </div>

    <!-- Section 5: Data Retention -->
    <div class="section">
        <h2 class="section-title"><span class="section-number">5.</span> Datenkategorien & Loschfristen</h2>

        <table class="retention-table">
            <thead>
                <tr>
                    <th style="width: 30%">Datenkategorie</th>
                    <th style="width: 45%">Beschreibung</th>
                    <th style="width: 25%">Loschfrist</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td><strong>Stammdaten</strong></td>
                    <td>Name, E-Mail-Adresse, Kontoinformationen</td>
                    <td><span class="badge badge-blue">Account-Loschung + 30 Tage</span></td>
                </tr>
                <tr>
                    <td><strong>Einwilligungen</strong></td>
                    <td>Consent-Entscheidungen, Dokumentversionen</td>
                    <td><span class="badge badge-blue">3 Jahre nach Widerruf</span></td>
                </tr>
                <tr>
                    <td><strong>IP-Adressen</strong></td>
                    <td>Technische Protokollierung bei Aktionen</td>
                    <td><span class="badge badge-green">4 Wochen</span></td>
                </tr>
                <tr>
                    <td><strong>Session-Daten</strong></td>
                    <td>Login-Tokens, Sitzungsinformationen</td>
                    <td><span class="badge badge-green">Nach Sitzungsende</span></td>
                </tr>
                <tr>
                    <td><strong>Audit-Log</strong></td>
                    <td>Protokoll aller datenschutzrelevanten Aktionen</td>
                    <td><span class="badge badge-yellow">3 Jahre (personenbezogen)</span></td>
                </tr>
                <tr>
                    <td><strong>Analytics (Opt-in)</strong></td>
                    <td>Nutzungsstatistiken, falls zugestimmt</td>
                    <td><span class="badge badge-blue">26 Monate</span></td>
                </tr>
                <tr>
                    <td><strong>Marketing (Opt-in)</strong></td>
                    <td>Werbe-Identifier, falls zugestimmt</td>
                    <td><span class="badge badge-blue">12 Monate</span></td>
                </tr>
            </tbody>
        </table>
    </div>

    <!-- Section 6: Your Rights -->
    <div class="section">
        <h2 class="section-title"><span class="section-number">6.</span> Ihre Rechte nach DSGVO</h2>

        <table>
            <thead>
                <tr>
                    <th style="width: 25%">Recht</th>
                    <th style="width: 15%">Artikel</th>
                    <th style="width: 60%">Beschreibung</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td><strong>Auskunftsrecht</strong></td>
                    <td>Art. 15</td>
                    <td>Sie haben das Recht, Auskunft uber Ihre gespeicherten Daten zu erhalten (dieses Dokument).</td>
                </tr>
                <tr>
                    <td><strong>Berichtigungsrecht</strong></td>
                    <td>Art. 16</td>
                    <td>Sie konnen die Berichtigung unrichtiger Daten verlangen.</td>
                </tr>
                <tr>
                    <td><strong>Loschungsrecht</strong></td>
                    <td>Art. 17</td>
                    <td>Sie konnen die Loschung Ihrer Daten verlangen ("Recht auf Vergessenwerden").</td>
                </tr>
                <tr>
                    <td><strong>Einschrankungsrecht</strong></td>
                    <td>Art. 18</td>
                    <td>Sie konnen die Einschrankung der Verarbeitung verlangen.</td>
                </tr>
                <tr>
                    <td><strong>Datenubertragbarkeit</strong></td>
                    <td>Art. 20</td>
                    <td>Sie konnen Ihre Daten in einem maschinenlesbaren Format erhalten.</td>
                </tr>
                <tr>
                    <td><strong>Widerspruchsrecht</strong></td>
                    <td>Art. 21</td>
                    <td>Sie konnen der Verarbeitung Ihrer Daten widersprechen.</td>
                </tr>
            </tbody>
        </table>
    </div>

    <!-- Footer -->
    <div class="footer">
        <div class="footer-grid">
            <div class="footer-section">
                <h4>Verantwortlicher</h4>
                {{ company_name | default('BreakPilot GmbH', true) }}<br>
                {{ company_address | default('Musterstraße 1', true) }}<br>
                {{ company_city | default('12345 Musterstadt', true) }}
            </div>
            <div class="footer-section">
                <h4>Datenschutzbeauftragter</h4>
                {{ dpo_name | default('Datenschutzbeauftragter', true) }}<br>
                E-Mail: {{ dpo_email | default('datenschutz@breakpilot.app', true) }}
            </div>
            <div class="footer-section">
                <h4>Aufsichtsbehorde</h4>
                Sie haben das Recht, sich bei der zustandigen<br>
                Datenschutz-Aufsichtsbehorde zu beschweren.
            </div>
        </div>

        <div style="margin-top: 20px; text-align: center; font-size: 7pt; color: #9ca3af;">
            Dieses Dokument wurde automatisch erstellt am {{ export_date }}.
            Es enthalt alle zum Zeitpunkt der Erstellung uber Sie gespeicherten personenbezogenen Daten.
        </div>
    </div>
</body>
</html>
