/* Styles pour la page de statistiques de lecture */

.statistics-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
    overflow-y: auto;
}

.statistics-modal.active {
    display: flex;
}

.statistics-container {
    background: white;
    border-radius: 20px;
    padding: 30px;
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    position: relative;
}

.statistics-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
}

.statistics-header h2 {
    margin: 0;
    color: #333;
    font-size: 28px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.statistics-header h2 i {
    color: #ff6b6b;
}

.statistics-close-btn {
    background: transparent;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    padding: 5px 10px;
    border-radius: 5px;
    transition: all 0.3s ease;
}

.statistics-close-btn:hover {
    background: #f0f0f0;
    color: #333;
}

.profile-info {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 30px;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.profile-info h3 {
    margin: 0 0 10px 0;
    font-size: 24px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.profile-info p {
    margin: 5px 0;
    opacity: 0.9;
    font-size: 14px;
}

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

.stat-card {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border-radius: 15px;
    padding: 25px;
    text-align: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #667eea, #764ba2);
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.stat-card.primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.stat-card.success {
    background: linear-gradient(135deg, #84fab0 0%, #8fd3f4 100%);
    color: #333;
}

.stat-card.warning {
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
    color: #333;
}

.stat-card .stat-icon {
    font-size: 36px;
    margin-bottom: 15px;
    opacity: 0.9;
}

.stat-card .stat-value {
    font-size: 42px;
    font-weight: bold;
    margin: 10px 0;
    line-height: 1;
}

.stat-card .stat-label {
    font-size: 14px;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.recent-activity {
    margin-top: 30px;
}

/* Les trois sections de la modale — « Par histoire », « Séances de lecture »
   et « Activité récente » — portaient trois fois le même titre à l'identique,
   dans deux fichiers différents. Une seule règle depuis le Lot 5, tâche 3. */
.recent-activity h3,
.reading-sessions h3,
.by-story h3,
.tracked-words h3 {
    color: #333;
    font-size: 20px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.reading-sessions h3,
.by-story h3,
.tracked-words h3 {
    margin-bottom: 8px;   /* un chapeau les suit, il porte l'écart restant */
}

.reading-sessions h3 i,
.by-story h3 i,
.tracked-words h3 i {
    color: #667eea;
}

/* Chapeau d'une section : la phrase qui évite un contresens de lecture — la
   règle des trois minutes pour les séances, ce que recouvre la vue par
   histoire. */
.reading-sessions-note,
.by-story-note,
.tracked-words-note {
    margin: 0 0 15px;
    font-size: 13px;
    line-height: 1.45;
    color: #666;
}

/* --------- Ossature commune des deux listes du Lot 5 --------- */
/* `.story-list` et `.session-list` sont la même boîte, `.story-item` et
   `.session-item` la même carte. Écrites deux fois, elles auraient divergé au
   premier ajustement d'espacement. */
.stats-list {
    background: #f8f9fa;
    border-radius: 15px;
    padding: 20px;
    max-height: 340px;
    overflow-y: auto;
}

.stats-list-item {
    background: white;
    padding: 14px 16px;
    border-radius: 10px;
    margin-bottom: 10px;
    border-left: 4px solid #667eea;
}

.stats-list-item:last-child {
    margin-bottom: 0;
}

/* Menée jusqu'au bout : la seule distinction visuelle des deux listes, parce
   que c'est la seule qui se lit d'un coup d'œil. */
.stats-list-item.finished {
    border-left-color: #2ecc71;
}

/* --------- Vue par histoire (Lot 5, tâche 3) --------- */
.by-story {
    margin-top: 30px;
}

.story-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.story-title {
    font-weight: bold;
    color: #333;
    min-width: 0;
    overflow-wrap: anywhere;
}

.story-badge {
    flex: 0 0 auto;
    font-size: 12px;
    font-weight: 700;
    color: #1e8449;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* La barre reprend `.progress-bar` : ici sur fond blanc, la piste grise et le
   remplissage violet d'origine conviennent tels quels — seule la hauteur est
   réduite, une ligne de liste n'ayant pas le poids d'une carte. */
.story-progress {
    height: 6px;
    margin-top: 10px;
}

.story-meta {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    font-size: 12px;
    color: #666;
}

/* « lue 3 fois » : la réponse à la question posée, mise en avant parmi les
   métadonnées. */
.story-readings {
    font-weight: 700;
    color: #4a4a4a;
}

/* Histoire lue avant l'enregistrement des séances : le nombre de lectures est
   inconnu, et le dire vaut mieux que l'inventer. */
.story-unmeasured {
    font-weight: 500;
    font-style: italic;
    color: #777;
}

.story-more {
    margin: 12px 0 0;
    text-align: center;
    font-size: 12px;
    color: #777;
}

.activity-list {
    background: #f8f9fa;
    border-radius: 15px;
    padding: 20px;
    max-height: 300px;
    overflow-y: auto;
}

.activity-item {
    background: white;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 15px;
    transition: all 0.3s ease;
    border-left: 4px solid #667eea;
}

.activity-item:last-child {
    margin-bottom: 0;
}

.activity-item:hover {
    transform: translateX(5px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.activity-icon {
    font-size: 24px;
    color: #667eea;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f0f0;
    border-radius: 50%;
}

.activity-details {
    flex: 1;
}

.activity-title {
    font-weight: bold;
    color: #333;
    margin-bottom: 5px;
    /* Un titre d'histoire personnalisée peut être long et sans espace. Le
       débordement ne se voyait pas tant que `getBookTitle()` renvoyait
       toujours `null` (corrigé au Lot 5, tâche 3) : les titres apparus depuis
       poussaient la liste en défilement horizontal sur 375 px. Même traitement
       que `.story-title` et `.session-title`. */
    min-width: 0;
    overflow-wrap: anywhere;
}

.activity-meta {
    font-size: 12px;
    color: #666;
    display: flex;
    gap: 15px;
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: #999;
}

.empty-state i {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: 0.3;
}

.empty-state p {
    font-size: 16px;
}

/* Ligne fine sous le chiffre d'une carte : d'où il vient, ou ce qu'il
   rapporte. Deux cartes s'en servent — « Histoires terminées » (sur combien
   de commencées) et « Minutes de lecture » (mesure ou estimation) — d'où sa
   place ici plutôt que dans la feuille d'un seul module.
   L'état `.measured`, lui, appartient aux séances de lecture et reste dans
   css/imagilire-mini-reading-session.css. */
.stat-card .stat-source {
    margin-top: 10px;
    font-size: 11px;
    line-height: 1.35;
    opacity: 0.85;
    text-transform: none;   /* `.stat-label` est en capitales, pas ceci */
    letter-spacing: 0;
    font-weight: 500;
}

/* Définies depuis l'origine et employées nulle part jusqu'au Lot 5, tâche 2 :
   la carte « Histoires terminées » leur donne enfin un usage. */
.progress-bar {
    background: #e0e0e0;
    border-radius: 10px;
    height: 8px;
    margin-top: 10px;
    overflow: hidden;
}

.progress-fill {
    background: linear-gradient(90deg, #667eea, #764ba2);
    height: 100%;
    border-radius: 10px;
    transition: width 0.5s ease;
}

/* La carte primaire porte **le même dégradé violet** que `.progress-fill` :
   sans cette reprise, la barre serait violette sur violet, c'est-à-dire
   invisible. Blanc translucide pour le fond, blanc plein pour le remplissage. */
.stat-card.primary .progress-bar {
    background: rgba(255, 255, 255, 0.28);
}

.stat-card.primary .progress-fill {
    background: #fff;
}

/* --------- Mots suivis (Lot 5, tâche 4) --------- */
.tracked-words {
    margin-top: 30px;
}

.word-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

/* Le mot lui-même est la donnée de la ligne : plus gros que tout le reste, et
   en minuscules comme il a été saisi — pas de `text-transform`, la casse d'un
   mot corrigé fait partie de la correction. */
.word-text {
    font-size: 17px;
    font-weight: bold;
    color: #333;
    min-width: 0;
    overflow-wrap: anywhere;
}

.word-badge {
    flex: 0 0 auto;
    font-size: 11px;
    font-weight: 700;
    color: #4c51bf;
    background: #eef0fb;
    border-radius: 20px;
    padding: 3px 10px;
    white-space: nowrap;
}

.word-meta {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    font-size: 12px;
    color: #666;
}

/* Le découpage retenu — « i • ma • gi • li • re ». C'est *la* correction :
   il se lit avant la date. */
.word-split {
    font-weight: 700;
    color: #4a4a4a;
    letter-spacing: 0.3px;
}

/* Mot présent dans le dictionnaire avant l'existence du journal : sa date est
   inconnue, et l'italique le dit sans occuper une ligne de plus — même
   traitement que « lectures non comptées » de la vue par histoire. */
.word-undated {
    font-style: italic;
    color: #777;
}

/* Retiré du dictionnaire depuis : la ligne reste — le mot a posé problème un
   jour — mais s'efface, pour qu'on ne la lise pas comme une correction encore
   active. */
.word-item.word-removed {
    border-left-color: #b0b0b0;
    opacity: 0.75;
}

.word-removed-badge {
    color: #7a7a7a;
    font-weight: 600;
}

/* --------- Export CSV (Lot 5, tâche 5) --------- */
.stats-export {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 2px solid #e0e0e0;
}

.stats-export h3 {
    color: #333;
    font-size: 20px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.stats-export h3 i {
    color: #667eea;
}

/* « Rien n'est envoyé sur Internet » est écrit ici et pas seulement dans la
   documentation : c'est la question que se pose un adulte au moment d'exporter
   les données de lecture d'un enfant, et le moment où il faut y répondre. */
.stats-export-note {
    margin: 0 0 15px;
    font-size: 13px;
    line-height: 1.45;
    color: #666;
}

.stats-export-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.stats-export-btn {
    flex: 1 1 200px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 18px;
    border: 2px solid #667eea;
    border-radius: 10px;
    background: white;
    color: #4c51bf;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.stats-export-btn:hover,
.stats-export-btn:focus-visible {
    background: #667eea;
    color: white;
}

/* Le retour après un clic : combien de lignes, ou pourquoi il n'y en a pas.
   `role="status"` le fait annoncer aux lecteurs d'écran — un téléchargement
   est par nature silencieux, et sans cette phrase rien ne distingue « fichier
   créé » de « bouton sans effet ». */
.stats-export-status {
    margin: 12px 0 0;
    font-size: 13px;
    color: #4c51bf;
    font-weight: 600;
}

/* Écrans étroits : les deux listes du Lot 5 partagent leur boîte, donc aussi
   son ajustement. */
@media (max-width: 600px) {
    .stats-list {
        padding: 14px;
        max-height: 55vh;
    }

    .story-head,
    .word-head {
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
    }

    /* Deux boutons côte à côte tiennent mal en 375 px : ils s'empilent, en
       pleine largeur, plutôt que de couper leurs libellés. */
    .stats-export-btn {
        flex: 1 1 100%;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .statistics-container {
        padding: 20px;
        max-height: 95vh;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .stat-card .stat-value {
        font-size: 36px;
    }
    
    .statistics-header h2 {
        font-size: 22px;
    }
}

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

.stat-card {
    animation: fadeIn 0.5s ease forwards;
}

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