/* Variables CSS pour une meilleure maintenabilité */
:root {
    --primary-red: #dc2626;
    --secondary-red: #b91c1c;
    --light-red: #fef2f2;
    --dark-red: #991b1b;
    --accent-red: #f87171;
    --text-dark: #1f2937;
    --text-light: #6b7280;
    --white: #ffffff;
    --light-gray: #f9fafb;
    --border-gray: #e5e7eb;
    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--text-dark);
    background: linear-gradient(135deg, var(--light-red) 0%, var(--light-gray) 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 900px;
    margin: 0 auto;
}

/* En-tête principal */
h1 {
    text-align: center;
    color: var(--primary-red);
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 4px rgba(220, 38, 38, 0.1);
}

.subtitle {
    text-align: center;
    color: var(--text-light);
    font-size: 1.1rem;
    margin-bottom: 2rem;
}

/* Barre utilisateur */
.user-bar {
    background: var(--white);
    padding: 1rem 2rem;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 4px solid var(--primary-red);
}

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

.logout-btn {
    color: var(--primary-red);
    text-decoration: none;
    font-weight: 600;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    transition: all 0.3s ease;
    border: 1px solid var(--primary-red);
}

.logout-btn:hover {
    background: var(--primary-red);
    color: var(--white);
    transform: translateY(-1px);
}

/* Formulaires et conteneurs principaux */
form, #quiz, #results, .auth-container {
    background: var(--white);
    padding: 2rem;
    margin: 1.5rem 0;
    border-radius: 16px;
    box-shadow: var(--shadow);
    border-top: 4px solid var(--primary-red);
    position: relative;
    overflow: hidden;
}

form::before, #quiz::before, #results::before, .auth-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--primary-red), var(--accent-red), var(--primary-red));
}

/* Questions du quiz */
.question {
    background: var(--light-gray);
    margin-bottom: 2rem;
    padding: 1.5rem;
    border-radius: 12px;
    border-left: 4px solid var(--accent-red);
    transition: all 0.3s ease;
}

.question:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.question p {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 1rem;
}

.question label {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    margin: 0.5rem 0;
    background: var(--white);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.question label:hover {
    background: var(--light-red);
    border-color: var(--accent-red);
    transform: translateX(5px);
}

.question input[type="radio"] {
    margin-right: 0.75rem;
    transform: scale(1.2);
    accent-color: var(--primary-red);
}

/* Champs de formulaire */
input[type="text"], input[type="password"] {
    width: 100%;
    padding: 1rem;
    margin: 0.75rem 0;
    border: 2px solid var(--border-gray);
    border-radius: 10px;
    font-size: 1rem;
    transition: all 0.3s ease;
    background: var(--white);
}

input[type="text"]:focus, input[type="password"]:focus {
    outline: none;
    border-color: var(--primary-red);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
    transform: translateY(-1px);
}

/* Labels */
label:not(.question label) {
    display: block;
    margin: 1rem 0 0.5rem;
    font-weight: 600;
    color: var(--text-dark);
}

/* Boutons */
button, .btn {
    background: linear-gradient(135deg, var(--primary-red), var(--secondary-red));
    color: var(--white);
    padding: 1rem 2rem;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
    display: block;
    margin: 1.5rem auto;
    min-width: 200px;
    position: relative;
    overflow: hidden;
}

button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
    background: linear-gradient(135deg, var(--secondary-red), var(--dark-red));
}

button:hover::before {
    left: 100%;
}

button:active {
    transform: translateY(0);
}

/* Résultats */
#results {
    background: linear-gradient(135deg, var(--white), var(--light-red));
}

.score-display {
    text-align: center;
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-red);
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--white);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}

.result-item {
    background: var(--white);
    margin: 1rem 0;
    padding: 1rem;
    border-radius: 8px;
    border-left: 4px solid var(--accent-red);
}

/* Liens */
a {
    color: var(--primary-red);
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s ease;
}

a:hover {
    color: var(--secondary-red);
    text-decoration: underline;
}

/* Messages d'erreur */
.error {
    background: #fef2f2;
    color: #dc2626;
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid #fecaca;
    margin: 1rem 0;
    font-weight: 600;
}

.success {
    background: #f0fdf4;
    color: #16a34a;
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid #bbf7d0;
    margin: 1rem 0;
    font-weight: 600;
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.question {
    animation: fadeInUp 0.6s ease forwards;
}

.question:nth-child(2) { animation-delay: 0.1s; }
.question:nth-child(3) { animation-delay: 0.2s; }
.question:nth-child(4) { animation-delay: 0.3s; }
.question:nth-child(5) { animation-delay: 0.4s; }

/* Loading spinner */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-gray);
    border-top: 4px solid var(--primary-red);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Design responsive */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    h1 {
        font-size: 2rem;
    }
    
    .user-bar {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    form, #quiz, #results {
        padding: 1.5rem;
        margin: 1rem 0;
    }
    
    .question {
        padding: 1rem;
    }
    
    button {
        min-width: auto;
        width: 100%;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.75rem;
    }
    
    .question label {
        font-size: 0.9rem;
    }
    
    form, #quiz, #results {
        padding: 1rem;
    }
}

/* styles.css - Styles complémentaires */
.loading {
    text-align: center;
    padding: 2rem;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #dc2626;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.error {
    background-color: #fee2e2;
    border: 1px solid #fecaca;
    color: #dc2626;
    padding: 1rem;
    border-radius: 0.5rem;
    margin: 1rem 0;
    text-align: center;
}

.success {
    background-color: #dcfce7;
    border: 1px solid #bbf7d0;
    color: #16a34a;
    padding: 1rem;
    border-radius: 0.5rem;
    margin: 1rem 0;
    text-align: center;
}

.quiz-header {
    text-align: center;
    margin-bottom: 2rem;
}

.question {
    background-color: white;
    border-radius: 0.5rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    animation: fadeIn 0.5s ease forwards;
    opacity: 0;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.options {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    margin-top: 1rem;
}

.options label {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    background-color: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
}

.options label:hover {
    background-color: #f3f4f6;
    border-color: #d1d5db;
}

.options input[type="radio"] {
    margin-right: 0.75rem;
}

#submitQuiz {
    display: block;
    width: 100%;
    padding: 1rem;
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: 1.125rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin: 2rem 0;
}

#submitQuiz:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

#submitQuiz:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.results-header {
    text-align: center;
    margin-bottom: 2rem;
}

.score-display {
    margin: 1.5rem 0;
}

.score-number {
    font-size: 3rem;
    font-weight: 700;
    color: #dc2626;
}

.score-percentage {
    font-size: 1.5rem;
    color: #6b7280;
    margin-bottom: 0.5rem;
}

.score-message {
    font-size: 1.25rem;
    font-weight: 600;
}

.stats {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin: 1rem 0;
}

.stat-item {
    background-color: #f9fafb;
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
}

.errors-section {
    margin-top: 2rem;
}

.result-item {
    background-color: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 0.5rem;
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.refresh-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: #dc2626;
    color: white;
    border: none;
    border-radius: 0.375rem;
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-weight: 600;
}

.refresh-btn:hover {
    background: #b91c1c;
}

@media (max-width: 768px) {
    .stats {
        flex-direction: column;
        gap: 1rem;
    }
    
    .options {
        grid-template-columns: 1fr;
    }
}

/* ===== CORRECTION RESPONSIVE : boutons user-bar ===== */
@media (max-width: 768px) {
    .user-bar {
        flex-direction: column;   /* un élément par ligne */
        gap: .75rem;              /* espacement entre les liens */
        text-align: center;
    }

    .user-actions {
        display: flex;
        flex-direction: column;   /* empile les boutons */
        width: 100%;
        gap: .5rem;
    }

    .logout-btn {
        width: 100%;              /* boutons pleine largeur */
        max-width: 220px;         /* mais pas trop larges */
        margin: 0 auto;           /* centré */
    }
}

/* ===== CLASSEMENT – RESPONSIVE ===== */
@media (max-width: 768px) {
    /* conteneur plus petit + scroll horizontal si nécessaire */
    .ranking-container {
        padding: .5rem;
        overflow-x: auto;   /* scroll horizontal */
    }

    /* tableau compact */
    .ranking-table {
        min-width: 600px;   /* largeur mini pour rester lisible */
        font-size: .85rem;
    }

    /* cellules réduites */
    .ranking-table th,
    .ranking-table td {
        padding: .5rem .4rem;
        white-space: nowrap; /* évite le retour à la ligne */
    }

    /* on masque la colonne “Dernier quiz” qui prend beaucoup de place */
    .ranking-table th:nth-child(7),
    .ranking-table td:nth-child(7) {
        display: none;
    }

    /* badges rôle plus petits */
    .role-badge {
        font-size: .7rem;
        padding: .15rem .4rem;
    }

    /* centrer la position (#) */
    .position {
        width: 40px;
        text-align: center;
    }
}

/* très petits écrans (<= 480 px) */
@media (max-width: 480px) {
    .ranking-table {
        font-size: .8rem;
        min-width: 520px;
    }

    /* on cache aussi “Meilleur score” pour gagner encore de la place */
    .ranking-table th:nth-child(6),
    .ranking-table td:nth-child(6) {
        display: none;
    }
}

/* ===== HISTORIQUE – RESPONSIVE ===== */
@media (max-width: 768px) {
    /* conteneur plus petit + scroll horizontal si nécessaire */
    .profile-container {
        padding: .5rem;
        overflow-x: auto;
    }

    /* tableau compact */
    .history-table {
        min-width: 300px;
        font-size: .85rem;
    }

    /* cellules réduites */
    .history-table th,
    .history-table td {
        padding: .5rem .4rem;
        white-space: nowrap;
    }

    /* on masque la colonne “Performance” qui prend de la place */
    .history-table th:nth-child(3),
    .history-table td:nth-child(3) {
        display: none;
    }

    /* badges score plus petits */
    .score-badge {
        font-size: .7rem;
        padding: .2rem .5rem;
    }
}

/* très petits écrans (<= 480 px) */
@media (max-width: 480px) {
    .history-table {
        font-size: .8rem;
        min-width: 300px;
    }

    /* on cache aussi “Date” pour ne garder que Score */
    .history-table th:nth-child(1),
    .history-table td:nth-child(1) {
        display: none;
    }
}