/* ============================================
   COMMON.CSS - Styles partagés Français & Maths
   Contient : polices scolaires, variables CSS,
   reset, layout, composants de formulaire,
   styles de la feuille d'exercice, etc.
   ============================================ */

/* ============================================
   POLICE EMOJI SYSTÈME (fix v0.10.2)
   Sur Linux/Electron, sans-serif (DejaVu Sans) capture les
   glyphes emoji avec une boîte vide au lieu de céder la main
   à Noto Color Emoji. Ce @font-face crée un alias virtuel
   'SystemEmoji' qui pointe vers les polices emoji locales
   via local(), et unicode-range le réserve aux seuls caractères
   concernés. Chromium/Electron respecte unicode-range même
   sans bundler la police.
   ============================================ */
@font-face {
    font-family: 'SystemEmoji';
    src: local('Noto Color Emoji'),
         local('Apple Color Emoji'),
         local('Twemoji Mozilla'),
         local('Segoe UI Emoji');
    /* Plages Unicode ciblées : emoji couleur, dingbats, pictogrammes, flèches */
    unicode-range:
        U+00A9, U+00AE,          /* © ® */
        U+203C, U+2049,          /* ‼ ⁉ */
        U+2122, U+2139,          /* ™ ℹ */
        U+2194-2199,             /* flèches multi-directionnelles */
        U+21A9-21AA,             /* ↩ ↪ */
        U+231A-231B, U+23E9-23F3, U+23F8-23FA, /* horloges, chrono */
        U+25AA-25AB, U+25B6, U+25C0, U+25FB-25FE,
        U+2600-27FF,             /* divers symboles, dingbats */
        U+2934-2935, U+2B05-2B07, U+2B1B-2B1C, U+2B50, U+2B55,
        U+3030, U+303D, U+3297, U+3299,
        U+1F000-1F02F,           /* Mahjong, dominos */
        U+1F0A0-1F0FF,           /* Cartes à jouer */
        U+1F100-1F1FF,           /* Enclosed alphanumeric supplement, drapeaux */
        U+1F200-1F2FF,           /* Enclosed ideographic supplement */
        U+1F300-1F9FF,           /* Emoji principaux (météo, nourriture, visages, activités…) */
        U+1FA00-1FA6F,           /* Échecs, sport */
        U+1FA70-1FAFF;           /* Emoji récents */
}

/* ============================================
   POLICES SCOLAIRES
   7 polices pour l'écriture et l'accessibilité
   Fichiers dans le dossier /fonts/
   ============================================ */
@font-face {
    font-family: 'Marelle';
    src: url('../fonts/Marelle-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'MarelleBaton';
    src: url('../fonts/MarelleBaton-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'OpenDyslexic';
    src: url('../fonts/OpenDyslexic.woff') format('woff');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'BelleAllureScript';
    src: url('../fonts/BelleAllureScript.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Luciole';
    src: url('../fonts/Luciole-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'EcritureARomainLigne';
    src: url('../fonts/EcritureARomainLigne.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* ============================================
   VARIABLES CSS GLOBALES
   --couleur-primaire et --couleur-secondaire
   sont surchargées par chaque vue (Français/Maths)
   ============================================ */
:root {
    /* Couleurs — contraste renforcé */
    --couleur-primaire: #1e40af;
    --couleur-secondaire: #1e40af;
    --couleur-accent: #c53030;
    --couleur-fond: #f0ede8;
    --couleur-papier: #ffffff;
    --couleur-texte: #111827;
    --couleur-texte-clair: #374151;
    --couleur-bordure: #9ca3af;
    --couleur-succes: #16a34a;
    --ombre-douce: 0 4px 20px rgba(0, 0, 0, 0.12);
    --ombre-carte: 0 2px 8px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* ════════════════════════════════════════════
       DESIGN TOKENS — refonte ergo v5.9
       Variables centralisant les valeurs structurelles des écrans refondus en v5.6-v5.8
       (Suivi, Sidebar, Plans, Brevets, bilan élève). Modifier ici impacte uniformément.
       NB : ne pas utiliser ces tokens dans les vues Français/Maths où --couleur-primaire
       est surchargée — ils sont conçus pour les composants partagés.
       ════════════════════════════════════════════ */

    /* Tailles de cibles cliquables — référence WCAG 2.2 AA = 24px min */
    --cible-sm: 32px;   /* éléments secondaires (chips cliquables, badges) */
    --cible-md: 36px;   /* boutons standards, actions de carte, fermeture modale */
    --cible-lg: 44px;   /* items navigation sidebar, cellule tableau de suivi */
    --cible-xl: 48px;   /* lignes brevet bilan, avatars principaux */

    /* Tailles d'icônes et marqueurs visuels */
    --icone-sm: 18px;   /* icônes du footer sidebar */
    --icone-md: 22px;   /* icônes principales sidebar */
    --icone-lg: 28px;   /* case à cocher du bilan */
    --icone-xl: 48px;   /* avatar carte élève */

    /* Tailles de typographie */
    --texte-xs: 11px;   /* métadonnées discrètes */
    --texte-sm: 13px;   /* labels secondaires, footer items, stats */
    --texte-base: 14px; /* corps de texte, boutons, items nav */
    --texte-md: 15px;   /* titres de cartes */
    --texte-lg: 16px;   /* noms d'élèves, titres compacts */
    --texte-xl: 18px;   /* titres de section */
    --texte-2xl: 22px;  /* titres principaux */

    /* Espacements (gaps, paddings) */
    --espace-xs: 4px;
    --espace-sm: 6px;
    --espace-md: 8px;
    --espace-lg: 10px;
    --espace-xl: 12px;
    --espace-2xl: 14px;
    --espace-3xl: 16px;
    --espace-4xl: 24px;

    /* Rayons de bordure */
    --radius-sm: 6px;     /* tags, mini badges */
    --radius-md: 8px;     /* boutons, items navigation */
    --radius-lg: 10px;    /* éléments médians */
    --radius-xl: 12px;    /* cartes principales, modales */
    --radius-pill: 999px; /* pills, badges arrondis */

    /* Couleurs sémantiques additionnelles (utilisables hors vues Français/Maths) */
    --couleur-warning: #f59e0b;
    --couleur-danger: #dc2626;
    --couleur-info: #3b82f6;
    --couleur-texte-secondaire: #6b7280;
    --couleur-texte-tertiaire: #9ca3af;
    --couleur-bordure-douce: #e5e7eb;
    --couleur-bordure-hover: #d1d5db;
    --couleur-surface: #ffffff;
    --couleur-surface-douce: #f9fafb;
    --couleur-surface-grise: #f3f4f6;
}

/* ============================================
   RESET ET STYLES DE BASE
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Sécurité : tous les inputs number doivent être assez larges pour 2-3 chiffres */
input[type="number"] {
    min-width: 68px;
}

body {
    /* SystemEmoji EN PREMIER (fix v0.10.2) : l'alias @font-face réserve les plages Unicode
       emoji à la police système (Noto Color Emoji / Apple Color Emoji…) via unicode-range,
       avant que sans-serif ne les capture avec un glyphe vide. */
    font-family: 'SystemEmoji', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                 'Noto Color Emoji', 'Apple Color Emoji', 'Twemoji Mozilla', 'Segoe UI Emoji',
                 'Helvetica Neue', sans-serif;
    background-color: var(--couleur-fond);
    color: var(--couleur-texte);
    height: 100vh;
    margin: 0;
    overflow: hidden;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   LAYOUT PRINCIPAL : SIDEBAR + CONTENU
   ============================================ */
#app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* === SIDEBAR === */
/* === SIDEBAR === (refonte ergo v5.6 : dépliée par défaut + items 44px + icônes SVG) */
.sidebar {
    width: 220px;
    min-width: 220px;
    background: linear-gradient(180deg, #0f2440 0%, #1a3354 100%);
    color: white;
    display: flex;
    flex-direction: column;
    transition: width 0.2s ease, min-width 0.2s ease;
    overflow: visible;
    z-index: 200;
    box-shadow: 2px 0 12px rgba(0,0,0,0.15);
    position: relative;
    height: 100vh;
}
/* Mode replié (compact) : largeur 64px, on n'affiche que les icônes */
.sidebar.compact { width: 64px; min-width: 64px; overflow: hidden; }

/* Zone scrollable entre header et footer */
.sidebar-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; }
.sidebar.compact .sidebar-scroll { overflow-y: visible; }

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    min-height: 48px;
    overflow: hidden;
    white-space: nowrap;
    position: relative;
    flex-shrink: 0;
}
.sidebar-logo {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 13px;
    flex-shrink: 0;
    color: #93c5fd;
}
/* Titre et version : visibles par défaut, masqués en mode compact */
.sidebar-title { font-weight: 700; font-size: var(--texte-md); transition: opacity 0.15s; }
.sidebar.compact .sidebar-title { opacity: 0; }
.sidebar-version { font-size: var(--texte-xs); color: rgba(255,255,255,0.5); transition: opacity 0.15s; }
.sidebar.compact .sidebar-version { opacity: 0; }

/* Version dans le logo quand replié (tooltip au survol du header) */
.sidebar.compact .sidebar-header::after {
    content: attr(data-version);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    background: #1e293b;
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    margin-left: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    z-index: 300;
}
.sidebar.compact .sidebar-header:hover::after { opacity: 1; }

/* Labels de section (Exercices / Gestion) — visibles par défaut */
.sidebar-section-label {
    padding: var(--espace-2xl) 0 var(--espace-xs) 18px;
    font-size: var(--texte-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.4);
    transition: opacity 0.15s;
}
.sidebar.compact .sidebar-section-label { opacity: 0; height: 0; padding: 0; overflow: hidden; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 4px 8px; }

/* Items de navigation — cible 44px de haut, icône 22px à gauche, label 14px */
/* Utilise les design tokens v5.9 pour cohérence : --cible-lg, --texte-base, --espace-* */
.sidebar-item {
    display: flex;
    align-items: center;
    gap: var(--espace-xl);
    padding: var(--espace-lg) var(--espace-2xl);
    min-height: var(--cible-lg);
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    color: rgba(255,255,255,0.75);
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
    font-size: var(--texte-base);
    font-weight: 500;
    font-family: inherit;
    white-space: nowrap;
    text-align: left;
    width: 100%;
    position: relative;
}
.sidebar-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
/* Item actif : fond légèrement rehaussé + barre latérale colorée selon --couleur-section */
.sidebar-item.active {
    background: rgba(255,255,255,0.13);
    color: #fff;
    font-weight: 600;
}
.sidebar-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    /* --couleur-section est défini en style inline sur chaque item dans index.html */
    background: var(--couleur-section, #60a5fa);
}

/* Conteneur de l'icône SVG (22x22) — token --icone-md */
.sidebar-icon {
    width: var(--icone-md);
    height: var(--icone-md);
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.sidebar-icon svg { width: var(--icone-md); height: var(--icone-md); }
/* Ancien fallback texte (laissé en compatibilité pour éviter un layout cassé sur d'éventuels boutons non migrés) */
/* Label : visible par défaut, masqué en mode compact */
.sidebar-label { font-size: var(--texte-base); transition: opacity 0.15s; }
.sidebar.compact .sidebar-label { opacity: 0; pointer-events: none; }

.sidebar-badge {
    display: inline-block;
    background: #e53e3e;
    color: white;
    border-radius: var(--radius-lg);
    padding: 2px var(--espace-md);
    font-size: var(--texte-xs);
    font-weight: 700;
    line-height: 1.4;
    margin-left: auto;
}
.sidebar.compact .sidebar-badge { display: none; }

/* Footer : items plus discrets (cible-sm) pour distinguer hiérarchiquement */
.sidebar-footer {
    padding: var(--espace-sm) var(--espace-md);
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-shrink: 0;
}
.sidebar-footer-btn { min-height: 38px; padding: var(--espace-md) var(--espace-2xl); font-size: var(--texte-sm); color: rgba(255,255,255,0.6); }
.sidebar-footer-btn:hover { color: #fff; background: rgba(255,255,255,0.08); }
.sidebar-footer-btn .sidebar-icon svg { width: var(--icone-sm); height: var(--icone-sm); }
.sidebar-backup { display: flex; flex-direction: column; gap: 2px; }

/* Toggle dans le header (chevron qui pivote) */
.sidebar-toggle-top {
    margin-left: auto;
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,0.5);
    transition: color 0.2s, transform 0.2s;
    flex-shrink: 0;
}
.sidebar.compact .sidebar-toggle-top { transform: rotate(180deg); }
.sidebar-header:hover .sidebar-toggle-top { color: #fff; }

/* Toggle en bas (Replier / Déplier) */
.sidebar-toggle-bottom {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 8px 14px;
    min-height: 38px;
    border: none;
    border-radius: 8px;
    background: rgba(255,255,255,0.06);
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    transition: all 0.15s;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    text-align: left;
    margin-top: 4px;
}
.sidebar-toggle-bottom:hover { background: rgba(255,255,255,0.15); color: #fff; }
.sidebar-toggle-bottom .sidebar-icon { width: 22px; height: 22px; transition: transform 0.2s; }
.sidebar.compact .sidebar-toggle-bottom .sidebar-icon { transform: rotate(180deg); }
.sidebar.compact .sidebar-toggle-bottom .sidebar-label { opacity: 0; }

/* Tooltip au survol (sidebar compacte) */
.sidebar.compact .sidebar-item[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    background: #1e293b;
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    margin-left: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    z-index: 300;
}
.sidebar.compact .sidebar-item[data-tooltip]:hover::after { opacity: 1; }

.badge {
    display: inline-block;
    background: #e53e3e;
    color: white;
    border-radius: 10px;
    padding: 1px 6px;
    font-size: 0.7rem;
    margin-left: 3px;
    font-weight: 700;
    line-height: 1.4;
}

/* ============================================
   CONTENEUR PRINCIPAL DES VUES
   ============================================ */
#content-container {
    flex: 1;
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
    height: 100vh;
}

.vue {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    overflow-y: auto;
}

.vue.active {
    display: block;
}

/* ============================================
   EN-TÊTE DE CHAQUE VUE (Français / Maths)
   Titre + boutons d'action (panier, PDF)
   ============================================ */
/* Boutons flottants (FAB) — hover */
.fab-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.3) !important;
}

/* FAB Plans — Export tous les plans */
.fab-plans {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: #fff;
    border: none;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(16,185,129,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: transform 0.15s, box-shadow 0.15s;
}
.fab-plans:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 20px rgba(16,185,129,0.5);
}

/* ============================================
   LAYOUT PRINCIPAL - Panneau config + Aperçu
   Disposition responsive : colonne sur mobile, côte à côte sur desktop
   ============================================ */
.conteneur-principal {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 52px);
    overflow-x: hidden;
}

@media (min-width: 1024px) {
    .conteneur-principal {
        flex-direction: row;
    }
}

/* Panneau de configuration (gauche) */
.panneau-config {
    background: white;
    padding: 1.25rem;
    border-right: 1px solid var(--couleur-bordure);
    box-shadow: var(--ombre-carte);
}

@media (min-width: 1024px) {
    .panneau-config {
        flex: 1;
        min-width: 340px;
        max-height: calc(100vh - 52px);
        overflow-y: auto;
        position: sticky;
        top: 0;
        padding: 1.25rem 1rem;
    }
}

@media (max-width: 700px) {
    .panneau-config { padding: 0.75rem; }
}

.panneau-config h2 {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1.35rem;
    color: var(--couleur-primaire);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.panneau-config h2::before {
    content: '✦';
    font-size: 0.8rem;
    color: var(--couleur-accent);
}

/* Zone d'aperçu (droite) - Contient la feuille d'exercice */
.zone-apercu {
    flex: 2;
    background: var(--couleur-fond);
    padding: 1rem;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
    overflow-x: hidden;
    min-width: 0;
}

@media (max-width: 700px) {
    .zone-apercu { padding: 0.5rem; }
}

/* ============================================
   OPTIONS GLOBALES (police, taille, niveaux)
   Bloc de configuration partagé entre vues
   ============================================ */
.option-row {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.option-row select {
    flex: 1;
}

/* ============================================
   ÉLÉMENTS DE FORMULAIRE
   Inputs, selects, nombres, ranges
   ============================================ */
select, input[type="number"] {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--couleur-bordure);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--couleur-texte);
    background: white;
    transition: var(--transition);
    cursor: pointer;
}

select:focus, input[type="number"]:focus {
    outline: none;
    border-color: var(--couleur-secondaire);
    box-shadow: 0 0 0 2px rgba(44, 82, 130, 0.1);
}

input[type="number"] {
    width: 70px;
    text-align: center;
}

/* Curseur de zoom */
input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 6px;
    background: var(--couleur-bordure);
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--couleur-primaire);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(26, 54, 93, 0.3);
    transition: var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    background: var(--couleur-secondaire);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--couleur-primaire);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(26, 54, 93, 0.3);
}

/* ============================================
   LISTE DES EXERCICES (accordéon)
   Chaque exercice est un item cliquable qui
   déplie sa configuration quand activé
   ============================================ */
.liste-exercices {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.exercice-item {
    border: 2px solid var(--couleur-bordure);
    border-radius: 8px;
    overflow: hidden;
    transition: var(--transition);
}

.exercice-item:hover {
    border-color: var(--couleur-secondaire);
}

.exercice-item.actif {
    border-color: var(--couleur-primaire);
    box-shadow: var(--ombre-carte);
}

/* Badge coche sur exercice actif */
.exercice-item.actif .exercice-header::after {
    content: '✓';
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    background: #38a169;
    color: white;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
    margin-left: auto;
}

/* Compteur dans les catégories */
.categorie-count {
    display: none;
    position: absolute;
    top: -4px;
    right: -4px;
    background: #38a169;
    color: white;
    font-size: 10px;
    font-weight: 700;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    line-height: 18px;
    text-align: center;
}
.categorie-count.has-count {
    display: block;
}
.categorie-btn {
    position: relative;
}

/* Résumé des exercices actifs */
#exercices-actifs-resume {
    background: #ebf8ff;
    border: 1.5px solid #90cdf4;
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 10px;
}
#exercices-actifs-resume .resume-titre {
    font-size: 11px;
    font-weight: 700;
    color: #1e40af;
    margin-bottom: 6px;
}
#exercices-actifs-resume .resume-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
#exercices-actifs-resume .resume-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    background: white;
    border: 1px solid #bee3f8;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
    color: #2d3748;
    cursor: default;
}
#exercices-actifs-resume .resume-tag-x {
    cursor: pointer;
    color: #c53030;
    font-weight: 700;
    font-size: 13px;
    line-height: 1;
    margin-left: 2px;
}
#exercices-actifs-resume .resume-tag-x:hover {
    color: #e53e3e;
}

.exercice-header {
    display: flex;
    align-items: center;
    padding: 0.85rem 1rem;
    cursor: pointer;
    background: white;
    transition: var(--transition);
    gap: 0.75rem;
}

.exercice-header:hover {
    background: var(--couleur-fond);
}

.exercice-icon {
    font-size: 1.25rem;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--couleur-fond);
    border-radius: 6px;
}

.exercice-info {
    flex: 1;
}

.exercice-info h4 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--couleur-primaire);
    margin-bottom: 0.1rem;
}

.exercice-info p {
    font-size: 0.8rem;
    color: var(--couleur-texte-clair);
}

.exercice-chevron {
    color: var(--couleur-texte-clair);
    transition: var(--transition);
    font-size: 0.8rem;
}

/* Configuration d'un exercice (panneau déplié) */
.exercice-config {
    display: none;
    padding: 1rem;
    background: var(--couleur-fond);
    border-top: 1px solid var(--couleur-bordure);
}

.exercice-item.config-open .exercice-config {
    display: block;
    animation: slideDown 0.3s ease;
}

.exercice-item.config-open .exercice-chevron {
    transform: rotate(180deg);
}

/* Bouton Ajouter dans chaque config */
.btn-ajouter-feuille {
    display: block;
    width: 100%;
    padding: 10px;
    margin-top: 10px;
    background: #38a169;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}
.btn-ajouter-feuille:hover {
    background: #2f855a;
    transform: translateY(-1px);
}

/* Exercice en preview (brouillon — fond jaune bien visible) */
.exercice-feuille.exercice-preview {
    background: #fef3c7 !important;
    border: 2px dashed #d97706 !important;
    border-radius: 8px !important;
    position: relative !important;
}
.exercice-feuille.exercice-preview::after {
    content: '⏳ Brouillon — cliquez "Ajouter à la feuille" pour confirmer';
    display: block;
    text-align: center;
    padding: 6px;
    font-size: 11px;
    font-weight: 600;
    color: #92400e;
    background: #fde68a;
    border-top: 1px dashed #d97706;
    margin-top: 8px;
}

/* Exercice confirmé (figé sur la feuille) */
.exercice-confirmed {
    position: relative;
}

/* Bouton × pour retirer un exercice de la feuille */
.btn-retirer-exercice {
    position: absolute;
    top: 4px;
    right: 4px;
    background: none;
    border: none;
    color: #c53030;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 6px;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 2;
}
.exercice-feuille:hover .btn-retirer-exercice {
    opacity: 1;
}
.btn-retirer-exercice:hover {
    background: #fed7d7;
}

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

/* Boutons de configuration */
/* ============================================
   FEUILLE D'EXERCICE (aperçu A4)
   Zone blanche simulant une page A4
   ============================================ */
.feuille-wrapper {
    transform-origin: top center;
    transition: transform 0.3s ease;
}

.feuille {
    background: var(--couleur-papier);
    width: 210mm;
    min-height: 297mm;
    padding: 20mm;
    box-shadow: var(--ombre-douce);
    border-radius: 6px;
    position: relative;
}

/* Barre colorée décorative en haut de la feuille */
.feuille::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--couleur-primaire), var(--couleur-accent));
    border-radius: 6px 4px 0 0;
}

/* Header de la feuille (Titre + Nom/Date) */
.feuille-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--couleur-primaire);
}

/* En-tête enrichi (v0.14.2) : titre de séquence saisi par l'enseignant et case
   « vérifié », pour donner à la feuille imprimée un statut de vrai document de classe. */
.feuille-sous-titre-input {
    display: block;
    width: 100%;
    max-width: 320px;
    margin-top: 0.3rem;
    padding: 3px 6px;
    border: 1px dashed transparent;
    border-radius: 5px;
    font-family: inherit;
    font-size: 0.85em;
    color: #4b5563;
    background: transparent;
}
.feuille-sous-titre-input:hover {
    border-color: #d1d5db;
}
.feuille-sous-titre-input:focus {
    outline: none;
    border: 1px solid var(--couleur-primaire);
    background: #fff;
    color: #111827;
}
.feuille-sous-titre-input::placeholder {
    color: #9ca3af;
    font-style: italic;
}
/* Vide et non focus : n'apparaît pas du tout sur le PDF (pas de cadre fantôme) */
.feuille-sous-titre-input:placeholder-shown:not(:focus) {
    border-color: transparent;
}
.feuille-verifie {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    font-size: 0.85em;
    color: #6b7280;
}
.feuille-verifie-case {
    width: 14px;
    height: 14px;
    border: 1.5px solid #9ca3af;
    border-radius: 3px;
    display: inline-block;
    flex-shrink: 0;
}
@media print {
    .feuille-sous-titre-input { border-color: transparent !important; }
}

.feuille-titre-principal {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1.8rem;
    font-weight: 600;
    color: var(--couleur-primaire);
    margin-bottom: 0.3rem;
}

.feuille-info {
    text-align: right;
    font-size: 0.95rem;
    line-height: 1.55;
}

.feuille-info strong {
    color: var(--couleur-primaire);
    font-weight: 600;
}

/* État vide de la feuille */
.feuille-vide {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 400px;
    color: var(--couleur-texte-clair);
    text-align: center;
}

.feuille-vide-icone {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.feuille-vide h3 {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--couleur-primaire);
    opacity: 0.7;
}

.feuille-vide p {
    font-size: 0.95rem;
    max-width: 280px;
}

/* Conteneur des exercices sur la feuille */
.exercices-container {
    display: none;
}

.exercices-container.visible {
    display: block;
}

/* Style d'un exercice individuel sur la feuille */
.exercice-feuille {
    margin-bottom: 2rem;
    padding-top: 1.5rem;
}

.exercice-feuille:last-child {
    margin-bottom: 0;
}

/* Titre de l'exercice (Ex.1 - ✏️ Consigne) */
.exercice-feuille-titre {
    /* Une seule famille de police pour tout le document (v0.14.1) */
    font-family: inherit;
    font-size: 1.1em;
    font-weight: 700;
    color: var(--couleur-primaire);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Numéro de l'exercice (pastille ronde) */
.exercice-numero {
    background: var(--couleur-primaire);
    color: white;
    width: 1.5em;
    height: 1.5em;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85em;
    flex-shrink: 0;
}

.exercice-icone {
    font-size: 1.1em;
    flex-shrink: 0;
}

/* Contenu de l'exercice */
.exercice-feuille-contenu {
    line-height: 2.2;
}

/* ============================================
   NIVEAUX DE CLASSE (CP, CE1, CE2, CM1, CM2)
   Badges colorés pour indiquer les niveaux visés
   ============================================ */
.niveau-btn {
    display: inline-block;
    padding: 8px 16px;
    border: 2px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    color: white;
    transition: all 0.3s;
    user-select: none;
}

.niveau-btn.cp-style { background: linear-gradient(135deg, #FF6B6B 0%, #FF8E53 100%); border-color: #FF6B6B; }
.niveau-btn.ce1-style { background: linear-gradient(135deg, #4ECDC4 0%, #44A08D 100%); border-color: #4ECDC4; }
.niveau-btn.ce2-style { background: linear-gradient(135deg, #95E1D3 0%, #38B2AC 100%); border-color: #95E1D3; }
.niveau-btn.cm1-style { background: linear-gradient(135deg, #F9D423 0%, #F6A623 100%); border-color: #F9D423; }
.niveau-btn.cm2-style { background: linear-gradient(135deg, #A8E6CF 0%, #56CCF2 100%); border-color: #A8E6CF; }

.niveau-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.niveau-btn.active {
    border: 3px solid #1e40af;
    box-shadow: 0 0 0 3px rgba(26, 54, 93, 0.2);
}

/* ============================================
   OPTIONS D'AFFICHAGE PAR EXERCICE
   Bloc config intégré dans chaque exercice
   ============================================ */
.options-exercice {
    background: white;
    padding: 0.75rem;
    border-radius: 6px;
    margin-bottom: 0.75rem;
    border: 1px solid var(--couleur-bordure);
}

.options-exercice label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--couleur-primaire);
    margin-bottom: 0.4rem;
}

.options-exercice .option-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.options-exercice select {
    flex: 1;
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
}

.options-exercice input[type="number"] {
    width: 60px;
    padding: 0.4rem;
    font-size: 0.85rem;
}

.unite-px {
    font-size: 0.8rem;
    color: var(--couleur-texte-clair);
}

/* ============================================
   NOTIFICATION TOAST
   Feedback visuel (ex: "Exercice ajouté au panier")
   ============================================ */
.notification-toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--couleur-succes);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transform: translateX(150%);
    transition: transform 0.3s ease;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.notification-toast.show {
    transform: translateX(0);
}

/* ============================================
   RACCOURCIS CLAVIER (barre d'aide en bas)
   ============================================ */
.keyboard-hints {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: 1000;
}

.keyboard-hints.show { opacity: 1; }
.keyboard-hints kbd {
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 6px;
    border-radius: 6px;
    margin: 0 2px;
}

/* ============================================
   BOUTON TEXTE SOURCE
   ============================================ */
.btn-texte-source {
    padding: 6px 14px;
    border: 1.5px solid var(--couleur-secondaire);
    border-radius: 8px;
    background: #fff;
    color: var(--couleur-secondaire);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    white-space: nowrap;
}
.btn-texte-source:hover {
    background: var(--couleur-secondaire);
    color: #fff;
}
.btn-texte-source-has {
    background: #eff6ff;
    border-color: var(--couleur-primaire);
    color: var(--couleur-primaire);
}
.btn-texte-source-active {
    background: var(--couleur-secondaire);
    color: #fff;
    border-color: var(--couleur-secondaire);
}

/* Bouton « Texte source » en bas du panneau de configuration : masqué par défaut (desktop) */
.btn-texte-source-bas {
    display: none;
}

/* Sur mobile : on masque le bouton d'en-tête (trop à l'étroit à côté du titre) et on
   affiche à la place un bouton pleine largeur en bas du panneau de configuration. */
@media (max-width: 900px) {
    #btn-texte-source {
        display: none;
    }
    .btn-texte-source-bas {
        display: block;
        width: 100%;
        margin-top: 1rem;
        padding: 12px 14px;
        font-size: 14px;
    }
}

/* ============================================
   INFO DE CONFIGURATION
   Encadré avec bordure latérale
   ============================================ */
.config-info {
    font-size: 0.8rem;
    color: var(--couleur-texte-clair);
    margin-bottom: 0.75rem;
    padding: 0.5rem;
    background: rgba(26, 54, 93, 0.05);
    border-radius: 6px;
    border-left: 3px solid var(--couleur-primaire);
}

/* ============================================
   FOCUS RING — Accessibilité clavier
   ============================================ */
.btn-brevet:focus-visible, .sidebar-item:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* ============================================
   HAMBURGER MENU — Mobile uniquement
   ============================================ */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 400;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: none;
    background: #1e40af;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    align-items: center;
    justify-content: center;
}
@media (max-width: 600px) {
    .mobile-menu-btn { display: flex; }
}

.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 250;
}
@media (max-width: 600px) {
    #content-container { margin-left: 0 !important; }
}

/* ── PIDAPI toggle visibility ── */
body.pidapi-disabled .pidapi-only { display: none !important; }

/* ── Flash attention animation ── */
@keyframes flash-attention {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
  25% { transform: scale(1.08); box-shadow: 0 0 0 8px rgba(59, 130, 246, 0.4); background: #3b82f6; color: #fff; }
  50% { transform: scale(1); box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2); }
  75% { transform: scale(1.08); box-shadow: 0 0 0 8px rgba(59, 130, 246, 0.4); background: #3b82f6; color: #fff; }
}
.flash-attention {
  animation: flash-attention 1.5s ease-in-out 2;
  z-index: 10;
  position: relative;
}

/* ════════════════════════════════════════════════
   NAVIGATION MOBILE — barre fixe en bas d'écran
   Visible ≤ 900px, remplace la sidebar latérale
   ════════════════════════════════════════════════ */

#mobile-bottom-nav {
    display: none; /* masqué sur desktop */
}

@media (max-width: 900px) {
    /* Masquer la sidebar latérale */
    #app-sidebar {
        display: none !important;
    }

    /* Le contenu prend toute la largeur + espace pour la barre du haut */
    #content-container {
        margin-left: 0 !important;
        padding-top: 62px !important; /* hauteur de la barre de navigation */
    }

    /* Barre de navigation fixe en HAUT */
    #mobile-bottom-nav {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 62px;
        background: #ffffff;
        border-bottom: 1px solid #e2e8f0;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
        z-index: 1000;
        padding-top: env(safe-area-inset-top, 0); /* encoche iPhone */
    }

    .mobile-nav-btn {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        border: none;
        background: transparent;
        cursor: pointer;
        padding: 6px 2px;
        min-width: 0;
        position: relative;
        transition: background 0.15s;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-nav-btn:active {
        background: #f1f5f9;
    }

    /* Icône SVG (refonte v0.9.4 puis v0.9.6 : SVG renforcé avec attributs HTML pour Brave Android) */
    /* Les attributs width="22" height="22" viewBox="0 0 24 24" sont posés directement sur le <svg> en HTML, */
    /* et ces règles CSS verrouillent en complément (max-width pour éviter tout débordement). */
    .mobile-nav-icon {
        width: 22px;
        height: 22px;
        max-width: 22px;
        max-height: 22px;
        flex-shrink: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        opacity: 0.5;
        transition: opacity 0.15s, transform 0.15s;
        overflow: hidden;
    }
    .mobile-nav-icon > svg {
        width: 22px !important;
        height: 22px !important;
        max-width: 22px;
        max-height: 22px;
        display: block;
    }

    /* Icône texte (pour le bouton "Plus") */
    .mobile-nav-dot-txt {
        font-size: 20px;
        line-height: 18px;
        height: 18px;
        color: #94a3b8;
        font-weight: 700;
    }

    /* Libellé */
    .mobile-nav-label {
        font-size: 10px;
        font-weight: 600;
        color: #94a3b8;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
        transition: color 0.15s;
    }

    /* État actif : icône bien visible + texte foncé */
    .mobile-nav-btn.active .mobile-nav-icon {
        opacity: 1;
        transform: scale(1.05);
    }

    .mobile-nav-btn.active .mobile-nav-label {
        color: #1e293b;
    }

    /* Badge panier */
    .mobile-nav-badge {
        position: absolute;
        top: 4px;
        right: 50%;
        transform: translateX(20px);
        background: #ef4444;
        color: #fff;
        font-size: 9px;
        font-weight: 700;
        min-width: 15px;
        height: 15px;
        border-radius: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0 3px;
    }

    .mobile-nav-badge:empty,
    .mobile-nav-badge[data-count="0"] {
        display: none;
    }

    /* Le bouton flottant "ajouter au panier" reste en bas (la barre est en haut maintenant) */
}

/* Très petits écrans : réduire un peu */
@media (max-width: 360px) {
    .mobile-nav-label { font-size: 9px; }
    .mobile-nav-icon { width: 20px; height: 20px; max-width: 20px; max-height: 20px; }
    .mobile-nav-icon > svg { width: 20px !important; height: 20px !important; }
}

/* ════════════════════════════════════════════════
   TOGGLE CONFIG / APERÇU — mobile uniquement
   Bascule entre le panneau de config et l'aperçu
   au lieu de les empiler verticalement
   ════════════════════════════════════════════════ */

.mobile-panel-toggle {
    display: none; /* masqué sur desktop */
}

@media (max-width: 900px) {
    .mobile-panel-toggle {
        display: flex;
        position: sticky;
        top: 62px; /* juste sous la barre de navigation */
        z-index: 500;
        background: #ffffff;
        border-bottom: 1px solid #e2e8f0;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
        padding: 6px;
        gap: 6px;
    }

    .mpt-btn {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        padding: 11px 8px;
        border: 1.5px solid #e2e8f0;
        border-radius: 8px;
        background: #f8fafc;
        color: #64748b;
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.15s;
        -webkit-tap-highlight-color: transparent;
    }

    .mpt-btn.active {
        background: #3b82f6;
        border-color: #3b82f6;
        color: #ffffff;
    }

    .mpt-badge {
        background: rgba(255, 255, 255, 0.3);
        color: inherit;
        font-size: 11px;
        font-weight: 700;
        min-width: 18px;
        height: 18px;
        border-radius: 9px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0 4px;
    }

    .mpt-btn:not(.active) .mpt-badge {
        background: #e2e8f0;
        color: #64748b;
    }

    .mpt-badge:empty,
    .mpt-badge[data-count="0"] {
        display: none;
    }

    /* Affichage conditionnel des panneaux selon la bascule */
    .conteneur-principal.view-apercu .panneau-config {
        display: none;
    }

    .conteneur-principal:not(.view-apercu) .panneau-apercu {
        display: none;
    }

    /* Les panneaux prennent toute la largeur */
    .conteneur-principal .panneau-config,
    .conteneur-principal .panneau-apercu {
        width: 100%;
        border-right: none;
    }
}

/* ════════════════════════════════════════════════
   ONGLETS DE CATÉGORIE SCROLLABLES — mobile
   Au lieu de passer à la ligne (wrap), les onglets
   défilent horizontalement au doigt
   ════════════════════════════════════════════════ */

@media (max-width: 900px) {
    .categories-menu {
        flex-wrap: nowrap !important;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
        padding-bottom: 4px;
        /* Masquer la barre de défilement tout en gardant le scroll */
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none; /* IE/Edge */
        /* Dégradé de fondu sur le bord droit pour indiquer qu'il y a plus */
        -webkit-mask-image: linear-gradient(to right, #000 92%, transparent 100%);
        mask-image: linear-gradient(to right, #000 92%, transparent 100%);
    }

    .categories-menu::-webkit-scrollbar {
        display: none; /* Chrome/Safari */
    }

    /* Les onglets gardent leur largeur naturelle, pas d'étirement */
    .categories-menu .categorie-btn {
        flex: 0 0 auto !important;
        scroll-snap-align: start;
        min-width: 72px;
    }
}
