/* =========================================================
   chat.css — mise en page responsive de Chat Youpi
   Aucun changement du HTML ou du JavaScript nécessaire.
   ========================================================= */

/* ---------- Base ---------- */

* {
    box-sizing: border-box;
}

html {
    font-size: 100%;
}

body {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1rem;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

/* ---------- Titre ---------- */

h2 {
    margin: 0 0 1rem;
    text-align: center;
}

/* L'image de Youpi reste centrée sans dimension fixe. */
body > p:has(img[src*="imageDeYoupi"]) {
    margin: 0 0 1.25rem;
    text-align: center;
}

body > p:has(img[src*="imageDeYoupi"]) img {
    display: inline-block;
    max-width: min(100%, 280px);
    height: auto;
}

/* ---------- Réglages ---------- */

fieldset {
    width: 100%;
    margin: 1rem 0;
    padding: 1rem;
    border: 1px solid currentColor;
    border-radius: 0.5rem;
}

fieldset legend {
    padding: 0 0.4rem;
    font-weight: 700;
}

fieldset label {
    display: block;
    margin: 0.6rem 0;
}

fieldset select {
    width: 100%;
    max-width: 100%;
    min-height: 2.5rem;
    padding: 0.35rem;
    font: inherit;
}

#aideVoix {
    margin: 0.25rem 0 0.75rem;
}

/* Le champ Rôle est très long : il utilise toute la largeur disponible. */
#role {
    display: block;
    width: 100% !important;
    min-height: 2.5rem;
    padding: 0.4rem;
    font: inherit;
}

/* ---------- Zone d'état ---------- */

#statut {
    min-height: 1.5em;
    margin: 0.5rem 0;
}

/* ---------- Zone de conversation ---------- */

#chat {
    width: 100%;
    height: clamp(18rem, 48vh, 34rem);
    overflow-y: auto;
    margin: 1.25rem 0;
    padding: 1rem;
    border: 1px solid currentColor;
    border-radius: 0.5rem;
    line-height: 1.6;
}

/* Les messages restent séparés et faciles à parcourir au lecteur d'écran. */
#chat .msg-user,
#chat .msg-youpi,
#chat .thinking {
    margin: 0 0 0.9rem;
}

#chat .msg-user {
    font-weight: 600;
}

#chat .msg-youpi {
    font-weight: 400;
}

/* ---------- Saisie du message ---------- */

/*
   Le HTML contient actuellement :
   label
   input
   br
   br
   bouton Envoyer
   bouton terminer la conversation

   Les <br> sont masqués uniquement autour de la saisie afin que
   Flexbox puisse organiser proprement les commandes.
*/

label[for="message"] {
    display: block;
    margin-top: 0.5rem;
    font-weight: 600;
}

#message {
    display: inline-block;
    width: calc(100% - 12rem) !important;
    min-height: 2.75rem;
    margin: 0;
    padding: 0.45rem 0.6rem;
    font: inherit;
    vertical-align: middle;
}

/*
   Les boutons suivent directement le champ dans le HTML.
   On leur donne une taille confortable au clavier et au tactile.
*/
#envoyer,
#finConversation,
#arreterVoix {
    min-height: 2.75rem;
    padding: 0.45rem 0.9rem;
    font: inherit;
    cursor: pointer;
}

#envoyer {
    margin-left: 0.5rem;
}

/*
   Le bouton de fin reste clairement séparé de l'envoi.
   Sur écran large, il apparaît sur sa propre ligne.
*/
#finConversation {
    display: block;
    margin-top: 0.75rem;
}

/*
   Le HTML contient deux <br> après #message.
   On les neutralise visuellement : ils ne doivent pas créer
   un grand espace entre le champ et le bouton Envoyer.
*/
#message + br,
#message + br + br {
    display: none;
}

/* ---------- Pied de page ---------- */

footer {
    margin-top: 2rem !important;
    padding-top: 1rem !important;
}

footer img {
    max-width: 84px;
    height: auto;
}

/* ---------- Tablette ---------- */

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

    #chat {
        height: clamp(16rem, 45vh, 28rem);
    }

    #message {
        width: calc(100% - 10rem) !important;
    }

    #envoyer {
        margin-left: 0.35rem;
    }
}

/* ---------- Téléphone ---------- */

@media (max-width: 520px) {
    body {
        padding: 0.65rem;
    }

    h2 {
        font-size: 1.35rem;
    }

    fieldset {
        padding: 0.75rem;
    }

    #chat {
        height: 45vh;
        min-height: 14rem;
        padding: 0.75rem;
    }

    /*
       Sur téléphone, le champ prend toute la largeur.
       Envoyer vient immédiatement après : il est donc
       directement accessible au clavier et au lecteur d'écran.
    */
    #message {
        display: block;
        width: 100% !important;
        margin-bottom: 0.5rem;
    }

    #envoyer {
        display: inline-block;
        margin-left: 0;
    }

    #finConversation {
        display: block;
        width: 100%;
        margin-top: 0.75rem;
    }
}

/* ---------- Très petit écran ---------- */

@media (max-width: 360px) {
    body {
        padding: 0.5rem;
    }

    #chat {
        height: 42vh;
        min-height: 12rem;
    }

    #envoyer,
    #finConversation,
    #arreterVoix {
        width: 100%;
    }

    #envoyer {
        margin-top: 0;
    }
}

/* ---------- Respect de la préférence de mouvement réduit ---------- */

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

/* ---------- Focus clavier / lecteur d'écran ---------- */

:focus-visible {
    outline: 3px solid currentColor;
    outline-offset: 3px;
}
