/* ============ Variables ============ */
:root {
    --couleur-principale: #1f4e79;
    --couleur-accent: #e8833a;
    --fond: #f4f6f9;
    --fond-carte: #ffffff;
    --texte: #222831;
    --texte-doux: #6b7280;
    --bordure: #dde2e8;
    --largeur-volet: 260px;
    --duree: .3s;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--texte);
    background: var(--fond);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--couleur-principale); }

/* ============ Header ============ */
.site-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;   /* titre parfaitement centré */
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--couleur-principale);
    color: #fff;
}
.header-titres { text-align: center; }
.header-titres h1 { margin: 0; font-size: 1.9rem; letter-spacing: .02em; }
.sous-titre { margin: .25rem 0 0; opacity: .85; }
.header-logo { justify-self: start; }
.header-deconnexion { justify-self: end; }
.header-deconnexion form { margin: 0; }
.btn-deconnexion {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .2rem;
    padding: .4rem .6rem;
    border: 1px solid transparent;
    border-radius: 6px;
    background: none;
    color: #fff;
    font: inherit;
    font-size: .75rem;
    cursor: pointer;
    transition: background .2s, border-color .2s;
}
.btn-deconnexion:hover, .btn-deconnexion:focus-visible {
    background: rgba(255, 255, 255, .15);
    border-color: rgba(255, 255, 255, .4);
    outline: none;
}

/* Nom de l'utilisateur connecté (zone centrale) */
.utilisateur-connecte {
    max-width: 900px;
    margin: 0 auto .6rem;
    text-align: right;
    font-size: .8rem;
    color: var(--texte-doux);
}
.utilisateur-connecte strong { color: var(--texte); font-weight: 600; }
.header-logo img { height: 64px; width: auto; display: block; }

/* ============ Corps : 3 colonnes ============ */
.page {
    flex: 1;
    display: flex;
    align-items: stretch;
    min-height: 0;
}

.volet {
    width: var(--largeur-volet);
    flex-shrink: 0;
    background: var(--fond-carte);
    overflow: hidden;
    transition: width var(--duree) ease;
}
.volet-gauche { border-right: 1px solid var(--bordure); }
.volet-droit  { border-left: 1px solid var(--bordure); }
.volet.masque { width: 0; border: none; }

.volet-contenu {
    width: var(--largeur-volet);   /* contenu fixe : pas de reflow pendant l'animation */
    padding: 1rem;
    height: 100%;
    overflow-y: auto;
}
.volet-titre {
    margin: 0 0 1rem;
    font-size: 1.1rem;
    color: var(--couleur-principale);
    border-bottom: 2px solid var(--couleur-accent);
    padding-bottom: .4rem;
}

/* Boutons afficher / masquer */
.bascule {
    flex-shrink: 0;
    width: 18px;
    border: none;
    background: #e9edf2;
    color: var(--couleur-principale);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 1rem;
    transition: background .2s;
}
.bascule:hover, .bascule:focus-visible { background: var(--couleur-accent); color: #fff; outline: none; }
.bascule .fleche { display: inline-block; transition: transform var(--duree); }
.bascule[aria-expanded="false"] .fleche { transform: rotate(180deg); }

/* Volet gauche : catégories */
.categorie { margin-bottom: 1.1rem; }
.categorie h3 {
    margin: 0 0 .35rem;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--texte-doux);
}
.categorie ul { list-style: none; margin: 0; padding: 0; }
.categorie li a {
    display: block;
    padding: .3rem .5rem;
    border-radius: 4px;
    text-decoration: none;
    font-size: .93rem;
}
.categorie li a:hover { background: var(--fond); }
.vide { margin: 0; font-size: .85rem; font-style: italic; color: var(--texte-doux); padding: .2rem .5rem; }

/* Volet droit : élèves */
.liste-eleves { list-style: none; margin: 0; padding: 0; }
.eleve + .eleve { border-top: 1px solid var(--bordure); }
.eleve-nom {
    width: 100%;
    display: flex;
    justify-content: space-between;
    gap: .5rem;
    padding: .55rem .4rem;
    background: none;
    border: none;
    text-align: left;
    font: inherit;
    font-size: .93rem;
    color: var(--texte);
    cursor: pointer;
    border-radius: 4px;
}
.eleve-nom:hover { background: var(--fond); }
.eleve-nom[aria-expanded="true"] { color: var(--couleur-principale); font-weight: 600; }
.classe { color: var(--texte-doux); font-weight: normal; white-space: nowrap; }
.eleve-ecrits {
    list-style: none;
    margin: 0 0 .5rem;
    padding: .2rem 0 .2rem .8rem;
    border-left: 3px solid var(--couleur-accent);
    margin-left: .4rem;
}
.eleve-ecrits a { display: block; padding: .2rem .3rem; font-size: .88rem; text-decoration: none; }
.eleve-ecrits a:hover { text-decoration: underline; }

/* ============ Conteneur central ============ */
.centre {
    flex: 1;
    min-width: 0;
    padding: 1.5rem;
}

/* ============ Éditeur ============ */
.editeur {
    max-width: 900px;
    margin: 0 auto;
    background: var(--fond-carte);
    border: 1px solid var(--bordure);
    border-radius: 8px;
    padding: 1.5rem;
}
.editeur h2 { margin-top: 0; color: var(--couleur-principale); }

.champs-ligne { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.champ { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; }
.champ-titre { flex: 1; min-width: 220px; }
.champ input, .champ select {
    font: inherit;
    padding: .5rem .6rem;
    border: 1px solid var(--bordure);
    border-radius: 5px;
}
.champ input:focus, .champ select:focus { outline: 2px solid var(--couleur-principale); outline-offset: -1px; }

.barre-outils {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .25rem;
    padding: .4rem;
    border: 1px solid var(--bordure);
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    background: #f8fafc;
}
.barre-outils button {
    font: inherit;
    font-size: .85rem;
    min-width: 32px;
    padding: .3rem .5rem;
    border: 1px solid transparent;
    border-radius: 4px;
    background: none;
    cursor: pointer;
}
.barre-outils button:hover { background: #fff; border-color: var(--bordure); }
.barre-outils button.actif { background: var(--couleur-principale); color: #fff; }
.separateur { width: 1px; height: 22px; background: var(--bordure); margin: 0 .2rem; }

.zone-texte {
    min-height: 360px;
    padding: 1rem;
    border: 1px solid var(--bordure);
    border-radius: 0 0 6px 6px;
    line-height: 1.6;
    overflow-y: auto;
}
.zone-texte:focus { outline: 2px solid var(--couleur-principale); outline-offset: -1px; }
.zone-texte:empty::before { content: attr(data-placeholder); color: var(--texte-doux); }
.zone-texte blockquote { border-left: 3px solid var(--couleur-accent); margin: .5rem 0; padding-left: 1rem; color: var(--texte-doux); }

.pied-editeur {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 1rem;
}
.compteur { font-size: .85rem; color: var(--texte-doux); }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.btn { font: inherit; padding: .55rem 1.1rem; border-radius: 5px; cursor: pointer; border: 1px solid var(--couleur-principale); }
.btn-principal { background: var(--couleur-principale); color: #fff; }
.btn-principal:hover { background: #163a5c; }
.btn-secondaire { background: #fff; color: var(--couleur-principale); }
.btn-secondaire:hover { background: var(--fond); }

.message { padding: .7rem 1rem; border-radius: 5px; }
.message-succes { background: #e6f4ea; color: #1e6b34; }
.message-erreur { background: #fdecea; color: #a12a1f; }

/* ============ Footer ============ */
.site-footer {
    min-height: 50px;
    background: var(--couleur-principale);
}

/* ============ Petits écrans ============ */
@media (max-width: 900px) {
    :root { --largeur-volet: 220px; }
    .header-titres h1 { font-size: 1.4rem; }
    .header-logo img { height: 44px; }
    .centre { padding: 1rem; }
}
@media (max-width: 640px) {
    .site-header { grid-template-columns: auto 1fr auto; gap: .8rem; padding: .8rem 1rem; }
    .sous-titre { display: none; }
    .texte-deconnexion { display: none; }
}

/* ============ Pièce jointe ============ */
.piece-jointe {
    margin-top: 1.2rem;
    padding: 1rem;
    border: 1px dashed var(--bordure);
    border-radius: 6px;
    background: #f8fafc;
}
.piece-jointe > label { display: block; margin-bottom: .5rem; }
.piece-jointe .aide { display: block; font-size: .85rem; color: var(--texte-doux); font-weight: normal; }
.fichier-actuel { margin: 0 0 .6rem; font-size: .9rem; }
.fichier-actuel .supprimer { margin-left: .8rem; color: #a12a1f; font-size: .85rem; }
.erreur-fichier { margin: .5rem 0 0; color: #a12a1f; font-size: .9rem; }

/* ============ Page de connexion ============ */
.page-connexion {
    justify-content: center;
    align-items: center;
    padding: 1rem;
    background: linear-gradient(160deg, var(--couleur-principale), #163a5c);
}
.connexion {
    width: 100%;
    max-width: 380px;
    background: var(--fond-carte);
    border-radius: 10px;
    padding: 2rem 1.8rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
    text-align: center;
}
.connexion-logo {
    width: 64px;
    height: 64px;
    background: var(--couleur-principale);
    border-radius: 50%;
    padding: 4px;
}
.connexion h1 { margin: .6rem 0 0; color: var(--couleur-principale); }
.connexion-sous-titre { margin: .2rem 0 1.4rem; color: var(--texte-doux); font-size: .9rem; }
.connexion form { display: flex; flex-direction: column; text-align: left; }
.connexion label { font-size: .9rem; margin: .8rem 0 .3rem; }
.connexion input {
    font: inherit;
    padding: .6rem .7rem;
    border: 1px solid var(--bordure);
    border-radius: 5px;
}
.connexion input:focus { outline: 2px solid var(--couleur-principale); outline-offset: -1px; }
.connexion button { margin-top: 1.4rem; padding: .7rem; }
.connexion .message { text-align: left; }

/* ============ Volets sur petit écran ============ */
/* Pas d'animation tant que script.js n'a pas fixé l'état des volets */
.js:not(.js-pret) .volet,
.js:not(.js-pret) .bascule .fleche { transition: none; }

@media (max-width: 768px) {
    .page { position: relative; }

    /* Les volets passent par-dessus l'éditeur au lieu de le pousser */
    .volet {
        position: absolute;
        top: 0;
        bottom: 0;
        z-index: 20;
        max-width: calc(100% - 36px);          /* laisse les deux boutons visibles */
        box-shadow: 0 0 24px rgba(0, 0, 0, .25);
    }
    .volet-gauche { left: 18px; }
    .volet-droit  { right: 18px; }
    .volet.masque { box-shadow: none; }

    .volet-contenu { max-width: 100%; }

    /* Fermés dès le chargement, avant même l'exécution de script.js */
    .js:not(.js-pret) .volet { width: 0; border: none; box-shadow: none; }

    .centre { padding: .8rem; }
    .editeur { padding: 1rem; }
}
