<!DOCTYPE html>
<html lang="pt">
<head>
    <meta charset="UTF-8">
    <title>Detalhes da Prova</title>
    <style>
        body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; padding: 20px; background-color: #f9f9f9; }
        h2 { color: #333; border-bottom: 2px solid #007bff; padding-bottom: 10px; }
        
        .info-box { background: #fff; padding: 20px; border-radius: 8px; margin-bottom: 20px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
        .info-box p { margin: 5px 0; color: #555; }
        
        table { width: 100%; border-collapse: collapse; background: white; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
        th, td { border: 1px solid #ddd; padding: 12px; text-align: left; vertical-align: top; }
        th { background-color: #343a40; color: white; text-transform: uppercase; font-size: 0.9em; }
        
        /* Estilos de Status */
        .linha-correta { background-color: #d4edda; } /* Verde suave */
        .linha-errada { background-color: #fff; } /* Branco padrão */
        
        /* Estilos de Alerta de Fraude */
        .alerta-fraude { background-color: #ffe6e6 !important; } /* Vermelho suave */
        .texto-fraude { color: #dc3545; font-weight: bold; font-size: 0.9em; display: block; margin-top: 5px; }
        
        .alerta-atencao { background-color: #fff3cd !important; } /* Amarelo suave */
        .texto-atencao { color: #856404; font-weight: bold; font-size: 0.9em; display: block; margin-top: 5px; }

        /* Estilo das Opções (Evidências) */
        .opcoes-container { margin-top: 8px; font-size: 0.9em; color: #666; border-top: 1px dashed #eee; padding-top: 5px; }
        .opcao-item { display: block; margin-bottom: 2px; }
        .gabarito-badge { background-color: #28a745; color: white; padding: 2px 6px; border-radius: 4px; font-size: 0.8em; margin-left: 5px; }

        .btn-voltar { display: inline-block; margin-top: 20px; padding: 10px 25px; background: #007bff; color: white; text-decoration: none; border-radius: 5px; transition: background 0.3s; }
        .btn-voltar:hover { background: #0056b3; }
    </style>
</head>
<body>

    <h2>Análise Detalhada da Prova (Evidências)</h2>

    <div class="info-box">
        <p><strong>Candidato:</strong> {{ candidato.nome_completo }} ({{ candidato.numero_candidato }})</p>
        <p><strong>Curso:</strong> {{ candidato.curso_desejado }}</p>
        <p><strong>Nota Final:</strong> {{ resultado.nota_final }} valores</p>
        <p><strong>Média de Tempo por Pergunta:</strong> {{ resultado.media_tempo_fmt }}</p>
    </div>

    <table>
        <thead>
            <tr>
                <th style="width: 50px;">#</th>
                <th style="width: 100px;">Categoria</th>
                <th>Enunciado e Opções (Evidência)</th>
                <th style="width: 80px; text-align: center;">Resp.<br>Dada</th>
                <th style="width: 80px; text-align: center;">Gabarito</th>
                <th style="width: 80px;">Tempo</th>
                <th style="width: 150px;">Análise do Sistema</th>
            </tr>
        </thead>
        <tbody>
            {% for q in prova %}
            <tr class="{{ q.alerta_classe if q.alerta_classe else ('linha-correta' if q.foi_correta else 'linha-errada') }}">
                
                <td>{{ loop.index }}</td>
                <td>{{ q.categoria }}</td>
                
                <td>
                    <strong>{{ q.enunciado }}</strong>
                    
                    <div class="opcoes-container">
                        <span class="opcao-item">A) {{ q.opcao_a }} {% if q.resposta_correta == 'A' %}<span class="gabarito-badge">Correta</span>{% endif %}</span>
                        <span class="opcao-item">B) {{ q.opcao_b }} {% if q.resposta_correta == 'B' %}<span class="gabarito-badge">Correta</span>{% endif %}</span>
                        <span class="opcao-item">C) {{ q.opcao_c }} {% if q.resposta_correta == 'C' %}<span class="gabarito-badge">Correta</span>{% endif %}</span>
                        <span class="opcao-item">D) {{ q.opcao_d }} {% if q.resposta_correta == 'D' %}<span class="gabarito-badge">Correta</span>{% endif %}</span>
                    </div>
                </td>
                
                <td style="text-align: center; font-weight: bold;">{{ q.resposta_dada }}</td>
                <td style="text-align: center;">{{ q.resposta_correta }}</td>
                
                <td>{{ q.tempo_fmt }}</td>
                
                <td>
                    {% if q.foi_correta %}
                        <span style="color: green;">✔ Correto</span>
                    {% else %}
                        <span style="color: red;">✖ Errado</span>
                    {% endif %}
                    
                    {% if q.alerta_texto %}
                        <span class="{{ 'texto-fraude' if 'CHUTE' in q.alerta_texto else 'texto-atencao' }}">
                            {{ q.alerta_texto }}
                        </span>
                    {% endif %}
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>

    <a href="/admin" class="btn-voltar">Voltar ao Painel</a>

</body>
</html>
