<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Web Sentinel - Rapport de Sécurité</title>
    <style>
        :root {
            --primary-color: #2563eb;
            --secondary-color: #64748b;
            --success-color: #10b981;
            --warning-color: #f59e0b;
            --danger-color: #ef4444;
            --critical-color: #dc2626;
            --info-color: #06b6d4;
            --bg-light: #f8fafc;
            --bg-dark: #1e293b;
            --text-dark: #1e293b;
            --text-light: #64748b;
            --border-color: #e2e8f0;
            --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
            --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            line-height: 1.6;
            color: var(--text-dark);
            background: var(--bg-light);
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }

        .header {
            background: linear-gradient(135deg, var(--primary-color), #3b82f6);
            color: white;
            padding: 40px 0;
            margin-bottom: 30px;
            border-radius: 12px;
            box-shadow: var(--shadow-lg);
        }

        .header-content {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
            text-align: center;
        }

        .header h1 {
            font-size: 2.5rem;
            margin-bottom: 10px;
            font-weight: 700;
        }

        .header .subtitle {
            font-size: 1.2rem;
            opacity: 0.9;
        }

        .scan-info {
            background: white;
            padding: 25px;
            border-radius: 12px;
            box-shadow: var(--shadow);
            margin-bottom: 30px;
            border-left: 4px solid var(--primary-color);
        }

        .scan-meta {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 20px;
            margin-bottom: 20px;
        }

        .meta-item {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .meta-icon {
            font-size: 1.2rem;
            width: 24px;
            text-align: center;
        }

        .meta-label {
            font-weight: 600;
            color: var(--text-dark);
        }

        .meta-value {
            color: var(--text-light);
        }

        .summary-cards {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }

        .summary-card {
            background: white;
            padding: 25px;
            border-radius: 12px;
            box-shadow: var(--shadow);
            text-align: center;
            border-top: 4px solid;
        }

        .summary-card.critical { border-top-color: var(--critical-color); }
        .summary-card.high { border-top-color: var(--danger-color); }
        .summary-card.medium { border-top-color: var(--warning-color); }
        .summary-card.low { border-top-color: var(--info-color); }
        .summary-card.info { border-top-color: var(--success-color); }

        .card-number {
            font-size: 2.5rem;
            font-weight: 700;
            margin-bottom: 5px;
        }

        .card-label {
            font-size: 0.9rem;
            color: var(--text-light);
            text-transform: uppercase;
            letter-spacing: 1px;
        }

        .section {
            background: white;
            margin-bottom: 30px;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: var(--shadow);
        }

        .section-header {
            background: var(--bg-light);
            padding: 20px 25px;
            border-bottom: 1px solid var(--border-color);
        }

        .section-title {
            font-size: 1.5rem;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .section-content {
            padding: 25px;
        }

        .findings-table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 15px;
        }

        .findings-table th,
        .findings-table td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid var(--border-color);
        }

        .findings-table th {
            background: var(--bg-light);
            font-weight: 600;
            color: var(--text-dark);
            font-size: 0.9rem;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .findings-table tbody tr:hover {
            background: var(--bg-light);
        }

        .severity-badge {
            display: inline-block;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 0.8rem;
            font-weight: 600;
            text-transform: uppercase;
            color: white;
        }

        .severity-critical { background: var(--critical-color); }
        .severity-high { background: var(--danger-color); }
        .severity-medium { background: var(--warning-color); }
        .severity-low { background: var(--info-color); }
        .severity-info { background: var(--success-color); }

        .module-badge {
            display: inline-block;
            padding: 3px 8px;
            background: var(--bg-light);
            border: 1px solid var(--border-color);
            border-radius: 6px;
            font-size: 0.8rem;
            font-weight: 500;
            color: var(--text-dark);
        }

        .finding-details {
            display: none;
            background: var(--bg-light);
            padding: 20px;
            margin: 10px 0;
            border-radius: 8px;
            border-left: 4px solid var(--primary-color);
        }

        .finding-details.show {
            display: block;
        }

        .detail-section {
            margin-bottom: 15px;
        }

        .detail-title {
            font-weight: 600;
            color: var(--text-dark);
            margin-bottom: 8px;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .detail-content {
            color: var(--text-light);
            line-height: 1.6;
        }

        .evidence-code {
            background: #f1f5f9;
            border: 1px solid var(--border-color);
            border-radius: 6px;
            padding: 12px;
            font-family: 'Monaco', 'Menlo', monospace;
            font-size: 0.9rem;
            overflow-x: auto;
        }

        .toggle-btn {
            background: none;
            border: none;
            color: var(--primary-color);
            cursor: pointer;
            font-size: 0.9rem;
            padding: 4px 8px;
            border-radius: 4px;
            transition: background 0.2s;
        }

        .toggle-btn:hover {
            background: var(--bg-light);
        }

        .no-findings {
            text-align: center;
            padding: 40px;
            color: var(--text-light);
        }

        .regression-section {
            background: #fef2f2;
            border-left: 4px solid var(--danger-color);
        }

        .improvement-section {
            background: #f0fdf4;
            border-left: 4px solid var(--success-color);
        }

        .footer {
            text-align: center;
            padding: 30px;
            color: var(--text-light);
            font-size: 0.9rem;
        }

        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
            margin-top: 20px;
        }

        .stat-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 12px 0;
            border-bottom: 1px solid var(--border-color);
        }

        .stat-item:last-child {
            border-bottom: none;
        }

        .chart-container {
            height: 300px;
            margin: 20px 0;
        }

        .progress-bar {
            background: var(--bg-light);
            border-radius: 10px;
            overflow: hidden;
            height: 8px;
            margin-top: 8px;
        }

        .progress-fill {
            height: 100%;
            background: linear-gradient(90deg, var(--success-color), var(--primary-color));
            transition: width 0.3s ease;
        }

        @media (max-width: 768px) {
            .container {
                padding: 10px;
            }
            
            .header h1 {
                font-size: 2rem;
            }
            
            .summary-cards {
                grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
            }
            
            .findings-table {
                font-size: 0.9rem;
            }
            
            .findings-table th,
            .findings-table td {
                padding: 8px 10px;
            }
        }

        .fade-in {
            animation: fadeIn 0.5s ease-in;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="header-content">
            <h1>🛡️ Web Sentinel</h1>
            <p class="subtitle">Rapport de Sécurité Web</p>
        </div>
    </div>

    <div class="container">
        <!-- Informations du scan -->
        <section class="scan-info fade-in">
            <div class="scan-meta">
                <div class="meta-item">
                    <span class="meta-icon">🌐</span>
                    <span class="meta-label">Domaine:</span>
                    <span class="meta-value">{{ domain }}</span>
                </div>
                <div class="meta-item">
                    <span class="meta-icon">📅</span>
                    <span class="meta-label">Date du scan:</span>
                    <span class="meta-value">{{ scan_date }}</span>
                </div>
                <div class="meta-item">
                    <span class="meta-icon">⏱️</span>
                    <span class="meta-label">Durée:</span>
                    <span class="meta-value">{{ duration }}</span>
                </div>
                <div class="meta-item">
                    <span class="meta-icon">🔧</span>
                    <span class="meta-label">Modules:</span>
                    <span class="meta-value">{{ modules_count }} modules</span>
                </div>
            </div>
        </section>

        <!-- Résumé par sévérité -->
        <section class="summary-cards fade-in">
            <div class="summary-card critical">
                <div class="card-number" style="color: var(--critical-color)">{{ critical_count }}</div>
                <div class="card-label">Critique</div>
            </div>
            <div class="summary-card high">
                <div class="card-number" style="color: var(--danger-color)">{{ high_count }}</div>
                <div class="card-label">Élevé</div>
            </div>
            <div class="summary-card medium">
                <div class="card-number" style="color: var(--warning-color)">{{ medium_count }}</div>
                <div class="card-label">Moyen</div>
            </div>
            <div class="summary-card low">
                <div class="card-number" style="color: var(--info-color)">{{ low_count }}</div>
                <div class="card-label">Faible</div>
            </div>
            <div class="summary-card info">
                <div class="card-number" style="color: var(--success-color)">{{ info_count }}</div>
                <div class="card-label">Info</div>
            </div>
        </section>

        <!-- Score de sécurité -->
        <section class="section fade-in">
            <div class="section-header">
                <h2 class="section-title">
                    <span>📊</span>
                    Score de Sécurité
                </h2>
            </div>
            <div class="section-content">
                <div style="display: flex; align-items: center; gap: 20px; margin-bottom: 20px;">
                    <div style="font-size: 3rem; font-weight: 700; color: var(--primary-color);">
                        {{ security_score }}/100
                    </div>
                    <div style="flex: 1;">
                        <div class="progress-bar">
                            <div class="progress-fill" style="width: {{ security_score }}%"></div>
                        </div>
                        <p style="margin-top: 10px; color: var(--text-light);">
                            {{ security_level }}
                        </p>
                    </div>
                </div>
                <div class="stats-grid">
                    <div>
                        <div class="stat-item">
                            <span>Tests réussis</span>
                            <span style="color: var(--success-color); font-weight: 600;">{{ passed_tests }}</span>
                        </div>
                        <div class="stat-item">
                            <span>Tests échoués</span>
                            <span style="color: var(--danger-color); font-weight: 600;">{{ failed_tests }}</span>
                        </div>
                        <div class="stat-item">
                            <span>Couverture OWASP</span>
                            <span style="color: var(--primary-color); font-weight: 600;">{{ owasp_coverage }}%</span>
                        </div>
                    </div>
                    <div>
                        <div class="stat-item">
                            <span>Certificat SSL</span>
                            <span style="color: {{ ssl_status_color }}; font-weight: 600;">{{ ssl_status }}</span>
                        </div>
                        <div class="stat-item">
                            <span>En-têtes de sécurité</span>
                            <span style="color: {{ headers_status_color }}; font-weight: 600;">{{ headers_status }}</span>
                        </div>
                        <div class="stat-item">
                            <span>Protection XSS</span>
                            <span style="color: {{ xss_status_color }}; font-weight: 600;">{{ xss_status }}</span>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Régressions (si présentes) -->
        {% if regressions %}
        <section class="section regression-section fade-in">
            <div class="section-header">
                <h2 class="section-title">
                    <span>⚠️</span>
                    Nouvelles Vulnérabilités Détectées
                </h2>
            </div>
            <div class="section-content">
                <p style="margin-bottom: 20px; color: var(--danger-color); font-weight: 600;">
                    {{ regressions|length }} nouvelle(s) vulnérabilité(s) détectée(s) depuis le dernier scan.
                </p>
                <table class="findings-table">
                    <thead>
                        <tr>
                            <th>Module</th>
                            <th>Sévérité</th>
                            <th>Titre</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for finding in regressions %}
                        <tr>
                            <td><span class="module-badge">{{ finding.check }}</span></td>
                            <td><span class="severity-badge severity-{{ finding.severity }}">{{ finding.severity }}</span></td>
                            <td>{{ finding.title }}</td>
                            <td><button class="toggle-btn" onclick="toggleDetails('regression-{{ loop.index }}')">Détails</button></td>
                        </tr>
                        <tr>
                            <td colspan="4">
                                <div id="regression-{{ loop.index }}" class="finding-details">
                                    <div class="detail-section">
                                        <div class="detail-title">📝 Description</div>
                                        <div class="detail-content">{{ finding.description }}</div>
                                    </div>
                                    <div class="detail-section">
                                        <div class="detail-title">💡 Recommandation</div>
                                        <div class="detail-content">{{ finding.remediation }}</div>
                                    </div>
                                    {% if finding.evidence %}
                                    <div class="detail-section">
                                        <div class="detail-title">🔍 Preuves</div>
                                        <div class="evidence-code">{{ finding.evidence }}</div>
                                    </div>
                                    {% endif %}
                                </div>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </section>
        {% endif %}

        <!-- Améliorations (si présentes) -->
        {% if resolved %}
        <section class="section improvement-section fade-in">
            <div class="section-header">
                <h2 class="section-title">
                    <span>✅</span>
                    Vulnérabilités Corrigées
                </h2>
            </div>
            <div class="section-content">
                <p style="margin-bottom: 20px; color: var(--success-color); font-weight: 600;">
                    {{ resolved|length }} vulnérabilité(s) corrigée(s) depuis le dernier scan.
                </p>
                <table class="findings-table">
                    <thead>
                        <tr>
                            <th>Module</th>
                            <th>Titre</th>
                            <th>Statut</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for finding in resolved %}
                        <tr>
                            <td><span class="module-badge">{{ finding.check }}</span></td>
                            <td>{{ finding.title }}</td>
                            <td><span style="color: var(--success-color); font-weight: 600;">✅ Corrigé</span></td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </section>
        {% endif %}

        <!-- Observations détaillées -->
        <section class="section fade-in">
            <div class="section-header">
                <h2 class="section-title">
                    <span>🔍</span>
                    Observations Détaillées
                </h2>
            </div>
            <div class="section-content">
                {% if findings %}
                <table class="findings-table">
                    <thead>
                        <tr>
                            <th>Module</th>
                            <th>Sévérité</th>
                            <th>Titre</th>
                            <th>Impact</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for finding in findings %}
                        <tr>
                            <td><span class="module-badge">{{ finding.check }}</span></td>
                            <td><span class="severity-badge severity-{{ finding.severity }}">{{ finding.severity }}</span></td>
                            <td>{{ finding.title }}</td>
                            <td>{{ finding.impact or "N/A" }}</td>
                            <td><button class="toggle-btn" onclick="toggleDetails('finding-{{ loop.index }}')">Détails</button></td>
                        </tr>
                        <tr>
                            <td colspan="5">
                                <div id="finding-{{ loop.index }}" class="finding-details">
                                    <div class="detail-section">
                                        <div class="detail-title">📝 Description</div>
                                        <div class="detail-content">{{ finding.description }}</div>
                                    </div>
                                    <div class="detail-section">
                                        <div class="detail-title">💡 Recommandation</div>
                                        <div class="detail-content">{{ finding.remediation }}</div>
                                    </div>
                                    {% if finding.evidence %}
                                    <div class="detail-section">
                                        <div class="detail-title">🔍 Preuves</div>
                                        <div class="evidence-code">{{ finding.evidence }}</div>
                                    </div>
                                    {% endif %}
                                    {% if finding.impact %}
                                    <div class="detail-section">
                                        <div class="detail-title">💥 Impact</div>
                                        <div class="detail-content">{{ finding.impact }}</div>
                                    </div>
                                    {% endif %}
                                </div>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
                {% else %}
                <div class="no-findings">
                    <h3>🎉 Excellent !</h3>
                    <p>Aucune vulnérabilité détectée pour ce domaine.</p>
                </div>
                {% endif %}
            </div>
        </section>

        <!-- Recommandations générales -->
        <section class="section fade-in">
            <div class="section-header">
                <h2 class="section-title">
                    <span>💡</span>
                    Recommandations Générales
                </h2>
            </div>
            <div class="section-content">
                <div style="display: grid; gap: 20px;">
                    <div style="background: var(--bg-light); padding: 20px; border-radius: 8px; border-left: 4px solid var(--primary-color);">
                        <h4 style="margin-bottom: 10px;">🔐 Chiffrement et Certificats</h4>
                        <p>Assurez-vous que tous les certificats SSL/TLS sont valides, à jour et utilisent des algorithmes de chiffrement modernes.</p>
                    </div>
                    <div style="background: var(--bg-light); padding: 20px; border-radius: 8px; border-left: 4px solid var(--warning-color);">
                        <h4 style="margin-bottom: 10px;">🛡️ En-têtes de Sécurité</h4>
                        <p>Configurez tous les en-têtes de sécurité essentiels : CSP, HSTS, X-Frame-Options, etc.</p>
                    </div>
                    <div style="background: var(--bg-light); padding: 20px; border-radius: 8px; border-left: 4px solid var(--info-color);">
                        <h4 style="margin-bottom: 10px;">🔍 Surveillance Continue</h4>
                        <p>Effectuez des scans réguliers pour détecter rapidement les nouvelles vulnérabilités.</p>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <div class="footer">
        <p>Rapport généré par Web Sentinel le {{ generation_date }}</p>
        <p>Pour plus d'informations sur la sécurité web, consultez les guides OWASP</p>
    </div>

    <script>
        function toggleDetails(elementId) {
            const details = document.getElementById(elementId);
            if (details.classList.contains('show')) {
                details.classList.remove('show');
            } else {
                details.classList.add('show');
            }
        }

        // Animation des cartes au chargement
        document.addEventListener('DOMContentLoaded', function() {
            const cards = document.querySelectorAll('.summary-card');
            cards.forEach((card, index) => {
                setTimeout(() => {
                    card.style.animation = 'fadeIn 0.5s ease-in';
                }, index * 100);
            });
        });

        // Mise à jour de la barre de progression
        window.addEventListener('load', function() {
            const progressBar = document.querySelector('.progress-fill');
            if (progressBar) {
                setTimeout(() => {
                    progressBar.style.width = progressBar.style.width;
                }, 500);
            }
        });
    </script>
</body>
</html>