/* ==========================================================================
   Passerelle LM Studio — feuille de style
   Mobile d'abord. Aucune police ni ressource externe : tout vient du serveur,
   l'interface fonctionne donc sans le moindre accès Internet.
   ========================================================================== */

:root {
  --fond: #0f1115;
  --fond-2: #161a21;
  --fond-3: #1e232c;
  --fond-survol: #252b36;
  --bord: #2a313d;
  --texte: #e6e9ef;
  --texte-doux: #9aa4b5;
  --texte-faible: #6b7688;
  --accent: #5b9cff;
  --accent-fonce: #3d7fe0;
  --accent-doux: rgba(91, 156, 255, 0.14);
  --danger: #ff6b6b;
  --succes: #4ade80;
  --alerte: #fbbf24;
  --bulle-moi: #24395c;
  --bulle-lui: #191e26;
  --sur-accent: #101010;
  --voile: rgba(0, 0, 0, 0.58);
  /* Reglages d'affichage pilotes depuis le panneau Reglages. */
  --echelle-texte: 1;
  --espacement-messages: 14px;
  --police-lecture: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --rayon: 14px;
  --rayon-s: 9px;
  --ombre: 0 10px 34px rgba(0, 0, 0, 0.45);
  --largeur-tiroir: 290px;
  /* Hauteur réellement visible : recalculée par app.js via visualViewport,
     car sur Android Chrome le clavier virtuel ne réduit pas 100vh. */
  --hauteur-vue: 100dvh;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
}

/* Mode « suivre le systeme » : ces valeurs ne s'appliquent que si AUCUN theme
   explicite n'est choisi. La garde porte donc sur l'absence de l'attribut, pas
   sur une valeur particuliere, sinon les themes clairs choisis a la main se
   feraient ecraser des que le telephone passe en mode sombre. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --fond: #f6f7f9;
    --fond-2: #ffffff;
    --fond-3: #eef0f4;
    --fond-survol: #e4e7ed;
    --bord: #d8dce4;
    --texte: #1b1f27;
    --texte-doux: #5a6472;
    --texte-faible: #8b95a4;
    --accent: #2563eb;
    --accent-fonce: #1d4ed8;
    --accent-doux: rgba(37, 99, 235, 0.10);
    --bulle-moi: #dbe7ff;
    --bulle-lui: #ffffff;
    --ombre: 0 10px 30px rgba(20, 30, 50, 0.12);
    /* Ces quatre-la manquaient : ils cascadaient depuis :root, ou ils sont
       calibres pour un fond sombre, et tombaient a 1,7:1 sur fond clair. */
    --danger: #c62828;
    --succes: #1b7f3b;
    --alerte: #8a5a00;
    --sur-accent: #ffffff;
    --voile: rgba(60, 70, 90, 0.45);
  }
}

* { box-sizing: border-box; }

/* L'attribut `hidden` du HTML n'est qu'une regle `display:none` de la feuille
   du navigateur : n'importe quel selecteur de classe qui fixe `display` la
   bat en specificite. Comme presque tous nos blocs masquables sont des flex
   ou des grid, il faut retablir la priorite explicitement, sinon les panneaux
   s'affichent tous par-dessus l'ecran de connexion. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  /* Empêche Android d'agrandir tout seul les textes en mode paysage. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  background: var(--fond);
  color: var(--texte);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

.ic { width: 22px; height: 22px; fill: none; stroke: currentColor;
      stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------------------------------------------------------- boutons */

button { font: inherit; color: inherit; cursor: pointer; }

.bouton-icone {
  display: grid; place-items: center;
  width: 42px; height: 42px; flex: 0 0 auto;
  background: transparent; border: 0; border-radius: var(--rayon-s);
  color: var(--texte-doux);
  -webkit-tap-highlight-color: transparent;
  transition: background .15s, color .15s;
}
.bouton-icone:hover { background: var(--fond-survol); color: var(--texte); }
.bouton-icone:active { transform: scale(.94); }

.bouton-principal {
  width: 100%; padding: 13px 18px;
  background: var(--accent); color: var(--sur-accent);
  border: 0; border-radius: var(--rayon-s);
  font-weight: 600; font-size: 16px;
  transition: background .15s, opacity .15s;
}
.bouton-principal:hover { background: var(--accent-fonce); }
.bouton-principal:disabled { opacity: .55; cursor: not-allowed; }

.bouton-secondaire {
  padding: 13px 18px; background: var(--fond-3); color: var(--texte);
  border: 1px solid var(--bord); border-radius: var(--rayon-s); font-weight: 600;
}
.bouton-secondaire.danger { color: var(--danger); border-color: transparent; }
.bouton-secondaire.danger:hover { background: rgba(255, 107, 107, .12); }

.bouton-texte {
  background: none; border: 0; color: var(--accent);
  font-weight: 600; font-size: 15px; padding: 8px 6px;
}

:where(button, a, input, select, textarea):focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ------------------------------------------------------- écran connexion */

.ecran-connexion {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 24px calc(16px + env(safe-area-inset-left)) calc(24px + env(safe-area-inset-bottom));
  background:
    radial-gradient(900px 520px at 50% -10%, var(--accent-doux), transparent 70%),
    var(--fond);
  overflow-y: auto;
}

.carte-connexion {
  width: 100%; max-width: 380px;
  background: var(--fond-2);
  border: 1px solid var(--bord);
  border-radius: var(--rayon);
  padding: 30px 24px 24px;
  box-shadow: var(--ombre);
}
.logo-connexion { color: var(--accent); display: grid; place-items: center; margin-bottom: 10px; }
.carte-connexion h1 { margin: 0; font-size: 22px; text-align: center; }
.sous-titre { margin: 4px 0 22px; text-align: center; color: var(--texte-doux); font-size: 14px; }

.champ { display: block; margin-bottom: 16px; }
.champ > span { display: block; margin-bottom: 6px; font-size: 13px;
                font-weight: 600; color: var(--texte-doux); }
.champ input, .champ select, .champ textarea {
  width: 100%; padding: 12px 14px;
  background: var(--fond-3); color: var(--texte);
  border: 1px solid var(--bord); border-radius: var(--rayon-s);
  /* 16px minimum : en dessous, Safari/Chrome mobile zooment à la mise au point. */
  font-size: 16px; font-family: inherit;
}
.champ textarea { resize: vertical; line-height: 1.5; }
.champ.mini > span { font-size: 12px; }
.champ.mini { margin-bottom: 10px; }

.case { display: flex; align-items: center; gap: 9px; margin-bottom: 18px;
        font-size: 14px; color: var(--texte-doux); cursor: pointer; }
.case input { width: 18px; height: 18px; accent-color: var(--accent); }

.erreur { margin: 14px 0 0; padding: 10px 12px; font-size: 14px;
          color: var(--danger); background: rgba(255,107,107,.1);
          border-radius: var(--rayon-s); }
.note { margin: 18px 0 0; font-size: 12.5px; color: var(--texte-faible); line-height: 1.5; }
.note code { font-family: var(--mono); font-size: 12px; background: var(--fond-3);
             padding: 1px 5px; border-radius: 4px; }
.aide { margin: -8px 0 16px; font-size: 12.5px; color: var(--texte-faible); line-height: 1.5; }

/* ------------------------------------------------------------ application */

.application { display: block; height: var(--hauteur-vue); overflow: hidden; }

/* ----- tiroir ----- */

.voile { position: fixed; inset: 0; background: var(--voile); z-index: 30;
         animation: apparait .18s ease; }
@keyframes apparait { from { opacity: 0 } to { opacity: 1 } }

.tiroir {
  position: fixed; top: 0; left: 0; z-index: 31;
  width: var(--largeur-tiroir); height: 100%;
  display: flex; flex-direction: column;
  background: var(--fond-2); border-right: 1px solid var(--bord);
  transform: translateX(-100%);
  transition: transform .22s cubic-bezier(.4,0,.2,1);
  padding-left: env(safe-area-inset-left);
}
.tiroir.ouvert { transform: translateX(0); }

.tete-tiroir {
  display: flex; align-items: center; gap: 6px;
  padding: calc(10px + env(safe-area-inset-top)) 8px 10px;
  border-bottom: 1px solid var(--bord);
}
.tete-tiroir strong { flex: 1; font-size: 16px; }

.liste-discussions { flex: 1; overflow-y: auto; padding: 8px; -webkit-overflow-scrolling: touch; }

.item-discussion {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 11px 10px; margin-bottom: 3px;
  background: none; border: 0; border-radius: var(--rayon-s);
  text-align: left; color: var(--texte-doux);
}
.item-discussion:hover { background: var(--fond-survol); }
.item-discussion.actif { background: var(--accent-doux); color: var(--texte); }
.item-discussion .titre {
  flex: 1; min-width: 0; font-size: 14.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.item-discussion .effacer { opacity: 0; flex: 0 0 auto; width: 30px; height: 30px;
                            color: var(--texte-faible); }
.item-discussion:hover .effacer, .item-discussion.actif .effacer { opacity: 1; }
.item-discussion .effacer:hover { color: var(--danger); }
.item-discussion .effacer .ic { width: 17px; height: 17px; }

.pied-tiroir { border-top: 1px solid var(--bord); padding: 8px;
               padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
.lien-pied {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 11px 10px; background: none; border: 0; border-radius: var(--rayon-s);
  color: var(--texte-doux); font-size: 14.5px; text-align: left;
}
.lien-pied:hover { background: var(--fond-survol); color: var(--texte); }
.lien-pied.danger:hover { color: var(--danger); }
.lien-pied .ic { width: 18px; height: 18px; flex: 0 0 auto; }

/* ----- colonne principale ----- */

.principal {
  display: flex; flex-direction: column;
  height: var(--hauteur-vue);
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
}

.barre-haut {
  display: flex; align-items: center; gap: 4px;
  padding: calc(6px + env(safe-area-inset-top)) 6px 6px;
  background: var(--fond-2); border-bottom: 1px solid var(--bord);
  flex: 0 0 auto;
}
.selecteurs { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.select-compact {
  max-width: 100%; padding: 2px 4px;
  background: none; border: 0; color: var(--texte);
  font-size: 15.5px; font-weight: 600; font-family: inherit;
}
.ligne-modele { display: flex; align-items: center; gap: 6px; padding-left: 4px; }
.nom-modele { font-size: 11.5px; color: var(--texte-faible);
              overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pastille { width: 7px; height: 7px; border-radius: 50%; background: var(--texte-faible);
            flex: 0 0 auto; transition: background .3s; }
.pastille.ok { background: var(--succes); }
.pastille.ko { background: var(--danger); }
.pastille.charge { background: var(--alerte); }

/* ----- fil de discussion ----- */

.fil {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 12px 8px;
  display: flex; flex-direction: column; gap: 14px;
  overscroll-behavior: contain;
}

.message { display: flex; flex-direction: column; max-width: 100%; }
.message.moi { align-items: flex-end; }

.bulle-msg {
  max-width: 88%; padding: 11px 14px;
  border-radius: var(--rayon); border: 1px solid transparent;
  font-size: 15.5px; line-height: 1.6;
  overflow-wrap: anywhere;
}
.message.moi .bulle-msg { background: var(--bulle-moi); border-bottom-right-radius: 5px; }
.message.lui .bulle-msg { background: var(--bulle-lui); border-color: var(--bord);
                          border-bottom-left-radius: 5px; }
.message.erreur-msg .bulle-msg { background: rgba(255,107,107,.1);
                                 border-color: rgba(255,107,107,.35); color: var(--danger); }

.bulle-msg > :first-child { margin-top: 0; }
.bulle-msg > :last-child { margin-bottom: 0; }
.bulle-msg p { margin: 0 0 10px; }
.bulle-msg h1, .bulle-msg h2, .bulle-msg h3 { margin: 16px 0 8px; line-height: 1.3; }
.bulle-msg h1 { font-size: 20px; } .bulle-msg h2 { font-size: 18px; }
.bulle-msg h3 { font-size: 16.5px; }
.bulle-msg ul, .bulle-msg ol { margin: 0 0 10px; padding-left: 22px; }
.bulle-msg li { margin-bottom: 4px; }
.bulle-msg a { color: var(--accent); }
.bulle-msg hr { border: 0; border-top: 1px solid var(--bord); margin: 14px 0; }
.bulle-msg blockquote { margin: 0 0 10px; padding: 2px 0 2px 12px;
                        border-left: 3px solid var(--bord); color: var(--texte-doux); }
.bulle-msg code {
  font-family: var(--mono); font-size: .88em;
  background: var(--fond-3); padding: 2px 5px; border-radius: 5px;
}
.bulle-msg pre {
  margin: 0 0 10px; padding: 12px 13px;
  background: var(--fond-3); border: 1px solid var(--bord); border-radius: var(--rayon-s);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.bulle-msg pre code { background: none; padding: 0; font-size: 13.2px; line-height: 1.55; }
.bulle-msg table { border-collapse: collapse; margin: 0 0 10px; display: block;
                   overflow-x: auto; max-width: 100%; }
.bulle-msg th, .bulle-msg td { border: 1px solid var(--bord); padding: 6px 10px;
                               text-align: left; font-size: 14px; }
.bulle-msg th { background: var(--fond-3); }

.images-msg { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.images-msg img { max-width: 160px; max-height: 160px; border-radius: var(--rayon-s);
                  border: 1px solid var(--bord); }

.curseur::after {
  content: ""; display: inline-block; width: 8px; height: 1.05em;
  margin-left: 2px; vertical-align: text-bottom;
  background: var(--accent); border-radius: 1px;
  animation: clignote 1s steps(2, start) infinite;
}
@keyframes clignote { to { visibility: hidden } }

.outils-msg { display: flex; gap: 2px; margin-top: 4px; padding: 0 2px;
              opacity: 0; transition: opacity .15s; }
.message:hover .outils-msg, .outils-msg.visible { opacity: 1; }
.outils-msg button { background: none; border: 0; padding: 5px 7px; border-radius: 6px;
                     color: var(--texte-faible); font-size: 12px;
                     display: flex; align-items: center; gap: 4px; }
.outils-msg button:hover { background: var(--fond-survol); color: var(--texte); }
.outils-msg .ic { width: 14px; height: 14px; }
.stats-msg { font-size: 11px; color: var(--texte-faible); padding: 2px 4px 0;
             font-variant-numeric: tabular-nums; }

/* ----- accueil ----- */

.accueil { flex: 1; display: flex; flex-direction: column; justify-content: center;
           align-items: center; text-align: center; padding: 20px 24px; gap: 6px; }
.accueil h2 { margin: 0; font-size: 21px; }
.accueil p { margin: 0; color: var(--texte-doux); font-size: 14.5px; max-width: 420px; }

/* ----- composeur ----- */

.composeur {
  flex: 0 0 auto;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: var(--fond-2); border-top: 1px solid var(--bord);
}
.apercus-images { display: flex; gap: 6px; flex-wrap: wrap; padding: 2px 2px 8px; }
.apercu { position: relative; width: 62px; height: 62px; }
.apercu img { width: 100%; height: 100%; object-fit: cover; border-radius: var(--rayon-s);
              border: 1px solid var(--bord); }
.apercu button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px;
                 border-radius: 50%; background: var(--danger); color: #fff; border: 0;
                 display: grid; place-items: center; font-size: 13px; line-height: 1; }

.ligne-saisie { display: flex; align-items: flex-end; gap: 6px; }
#saisie-message {
  flex: 1; min-height: 44px; max-height: 40vh;
  padding: 11px 14px; resize: none;
  background: var(--fond-3); color: var(--texte);
  border: 1px solid var(--bord); border-radius: 22px;
  font-size: 16px; font-family: inherit; line-height: 1.45;
}
#saisie-message::placeholder { color: var(--texte-faible); }

.bouton-envoi {
  flex: 0 0 auto; width: 44px; height: 44px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--sur-accent); border: 0; border-radius: 50%;
  transition: background .15s, transform .1s;
}
.bouton-envoi:hover { background: var(--accent-fonce); }
.bouton-envoi:active { transform: scale(.93); }
.bouton-envoi:disabled { opacity: .4; cursor: not-allowed; }
.bouton-envoi.stop { background: var(--danger); }
.joindre { color: var(--texte-doux); }

.barre-info { min-height: 15px; padding: 5px 8px 0; font-size: 11.5px;
              color: var(--texte-faible); font-variant-numeric: tabular-nums; }

/* ----- panneaux coulissants ----- */

.panneau {
  position: fixed; inset: 0; z-index: 40;
  display: flex; flex-direction: column;
  background: var(--fond);
  animation: monte .2s cubic-bezier(.4,0,.2,1);
}
@keyframes monte { from { transform: translateY(14px); opacity: .4 } to { transform: none; opacity: 1 } }

.tete-panneau {
  display: flex; align-items: center; gap: 6px; flex: 0 0 auto;
  padding: calc(8px + env(safe-area-inset-top)) 8px 8px;
  background: var(--fond-2); border-bottom: 1px solid var(--bord);
}
.tete-panneau strong { flex: 1; font-size: 16.5px; }

.corps-panneau {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 18px calc(16px + env(safe-area-inset-left))
           calc(28px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-right));
  max-width: 680px; width: 100%; margin: 0 auto;
}
.actions-panneau { display: flex; gap: 10px; margin-top: 22px; }
.actions-panneau .bouton-principal { flex: 2; }
.actions-panneau .bouton-secondaire { flex: 1; }

.avance { margin-bottom: 18px; border: 1px solid var(--bord); border-radius: var(--rayon-s);
          overflow: hidden; }
.avance summary { padding: 12px 14px; background: var(--fond-2); cursor: pointer;
                  font-size: 14.5px; font-weight: 600; color: var(--texte-doux); }
.avance[open] summary { border-bottom: 1px solid var(--bord); }
.grille-params { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; padding: 14px; }

/* ----- bloc d'état ----- */

.bloc-etat { margin-bottom: 16px; background: var(--fond-2); border: 1px solid var(--bord);
             border-radius: var(--rayon-s); overflow: hidden; }
.bloc-etat h3 { margin: 0; padding: 12px 14px; font-size: 14px;
                background: var(--fond-3); border-bottom: 1px solid var(--bord);
                display: flex; align-items: center; gap: 8px; }
.bloc-etat dl { margin: 0; padding: 6px 14px 12px; }
.bloc-etat dt { font-size: 12px; color: var(--texte-faible); margin-top: 10px; }
.bloc-etat dd { margin: 2px 0 0; font-size: 14px; overflow-wrap: anywhere; }
.bloc-etat dd.mono { font-family: var(--mono); font-size: 12.8px; }
.liste-appareils { list-style: none; margin: 0; padding: 6px 14px 12px; }
.liste-appareils li { display: flex; align-items: center; gap: 8px; padding: 5px 0;
                      font-size: 14px; }
.liste-modeles { list-style: none; margin: 0; padding: 6px 14px 12px; }
.liste-modeles li { padding: 7px 0; font-size: 13.5px; border-top: 1px solid var(--bord);
                    display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.liste-modeles li:first-child { border-top: 0; }
.etiquette { font-size: 10.5px; padding: 2px 7px; border-radius: 20px;
             background: var(--fond-3); color: var(--texte-doux); border: 1px solid var(--bord);
             text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }
.etiquette.vert { color: var(--succes); border-color: rgba(74,222,128,.4);
                  background: rgba(74,222,128,.1); }
.etiquette.bleu { color: var(--accent); border-color: rgba(91,156,255,.4);
                  background: var(--accent-doux); }

/* ----- notification flottante ----- */

.bulle {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 60;
  max-width: calc(100vw - 32px);
  padding: 11px 18px; border-radius: 24px;
  background: var(--fond-3); color: var(--texte);
  border: 1px solid var(--bord); box-shadow: var(--ombre);
  font-size: 14px; text-align: center;
  animation: monte .2s ease;
}

/* ----- écrans larges ----- */

@media (min-width: 900px) {
  .application { display: grid; grid-template-columns: var(--largeur-tiroir) 1fr; }
  .tiroir { position: relative; transform: none; height: var(--hauteur-vue); }
  .voile { display: none !important; }
  #ouvrir-tiroir, #fermer-tiroir { display: none; }
  .fil { padding: 24px 28px 10px; }
  .bulle-msg { max-width: 74%; font-size: 15.5px; }
  .composeur { padding: 12px 28px calc(14px + env(safe-area-inset-bottom)); }
  .ligne-saisie { max-width: 820px; margin: 0 auto; }
  .barre-info { max-width: 820px; margin: 0 auto; }
  .panneau { inset: 0 0 0 var(--largeur-tiroir); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ----- bloc « réflexion » (delta.reasoning_content) ----- */

.reflexion {
  margin: 0 0 10px;
  border: 1px dashed var(--bord);
  border-radius: var(--rayon-s);
  background: color-mix(in srgb, var(--fond-3) 60%, transparent);
}
.reflexion summary {
  display: flex; align-items: center; gap: 7px;
  padding: 8px 11px; cursor: pointer;
  color: var(--texte-faible); font-size: 13px; list-style: none;
  -webkit-tap-highlight-color: transparent;
}
.reflexion summary::-webkit-details-marker { display: none; }
.reflexion summary .ic { width: 15px; height: 15px; flex: 0 0 auto; }
.reflexion summary::after {
  content: "▸"; margin-left: auto; font-size: 11px;
  transition: transform .15s; color: var(--texte-faible);
}
.reflexion[open] summary::after { transform: rotate(90deg); }
.etiquette-reflexion { font-weight: 600; letter-spacing: .01em; }
.corps-reflexion {
  padding: 0 12px 11px;
  font-size: 13.5px; line-height: 1.55; color: var(--texte-doux);
  white-space: pre-wrap; overflow-wrap: anywhere;
  max-height: 260px; overflow-y: auto;
}

.avis-vide {
  color: var(--alerte); font-size: 14.5px; line-height: 1.55;
}

/* Encart explicatif sous une grille de paramètres. Défini ici et pas en
   style= dans le HTML : notre propre CSP (style-src 'self') bloque les
   attributs de style en ligne. */
.aide-encadree { padding: 0 14px 12px; margin: 0; }

/* Rangées de boutons secondaires dans le panneau des personnages. */
.rangee-boutons { display: flex; gap: 8px; flex-wrap: wrap; margin: -8px 0 16px; }
.rangee-boutons.encadree { padding: 0 14px 12px; margin: 0; }
.bouton-secondaire.petit { padding: 8px 13px; font-size: 13.5px; font-weight: 500; }

/* ==========================================================================
   Réglages d'affichage pilotés par l'utilisateur
   ========================================================================== */

/* L'échelle s'applique sur le texte de lecture, pas sur les contrôles : un
   bouton qui grossit avec le texte finit par déborder de la barre du haut. */
.bulle-msg { font-size: calc(15.5px * var(--echelle-texte));
             font-family: var(--police-lecture); }
.corps-reflexion { font-size: calc(13.5px * var(--echelle-texte)); }
.fil { gap: var(--espacement-messages); }

/* ==========================================================================
   Panneaux Réglages et Mémoire
   ========================================================================== */

.section-reglages {
  margin-bottom: 14px; border: 1px solid var(--bord);
  border-radius: var(--rayon-s); overflow: hidden; background: var(--fond-2);
}
.section-reglages > summary {
  padding: 14px; cursor: pointer; font-size: 15px; font-weight: 600;
  color: var(--texte); list-style: none;
  display: flex; align-items: center; gap: 8px;
  -webkit-tap-highlight-color: transparent;
}
.section-reglages > summary::-webkit-details-marker { display: none; }
.section-reglages > summary::after {
  content: "▸"; margin-left: auto; color: var(--texte-faible);
  transition: transform .15s;
}
.section-reglages[open] > summary::after { transform: rotate(90deg); }
.section-reglages[open] > summary { border-bottom: 1px solid var(--bord); }
.contenu-section { padding: 16px 14px 6px; }
.section-reglages.danger-section > summary { color: var(--alerte); }

.etiquette-champ {
  display: block; margin-bottom: 8px; font-size: 13px;
  font-weight: 600; color: var(--texte-doux);
}
.avertissement {
  color: var(--alerte); background: color-mix(in srgb, var(--alerte) 10%, transparent);
  border-left: 3px solid var(--alerte); padding: 10px 12px;
  border-radius: 0 var(--rayon-s) var(--rayon-s) 0; margin: 0 0 16px;
}
.succes-message {
  margin: 14px 0 0; padding: 10px 12px; font-size: 14px; color: var(--succes);
  background: color-mix(in srgb, var(--succes) 12%, transparent);
  border-radius: var(--rayon-s);
}

input[type="range"] {
  width: 100%; accent-color: var(--accent); margin: 4px 0 0;
  height: 26px; background: transparent;
}

/* ----- grille des thèmes ----- */

.grille-themes {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 9px; margin-bottom: 18px;
}
.carte-theme {
  padding: 0; border: 2px solid var(--bord); border-radius: var(--rayon-s);
  background: var(--fond-3); overflow: hidden; cursor: pointer;
  transition: border-color .15s, transform .1s; text-align: left;
}
.carte-theme:hover { transform: translateY(-2px); }
.carte-theme.actif { border-color: var(--accent); }
.apercu-theme { height: 40px; display: flex; }
.apercu-theme span { flex: 1; }
.apercu-theme span:nth-child(2) { flex: 0 0 22px; }
.apercu-theme span:nth-child(3) { flex: 0 0 14px; }
.nom-theme {
  display: block; padding: 7px 9px; font-size: 12.5px;
  color: var(--texte); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis;
}

/* ----- mémoire ----- */

.bandeau-memoire {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px;
}
.tuile-memoire {
  flex: 1 1 88px; padding: 11px 12px; background: var(--fond-2);
  border: 1px solid var(--bord); border-radius: var(--rayon-s);
}
.tuile-memoire b { display: block; font-size: 20px; line-height: 1.2; }
.tuile-memoire span { font-size: 11.5px; color: var(--texte-faible); }

.barre-recherche { display: flex; gap: 8px; margin-bottom: 14px; }
.barre-recherche input, .barre-recherche select {
  padding: 11px 13px; background: var(--fond-3); color: var(--texte);
  border: 1px solid var(--bord); border-radius: var(--rayon-s);
  font-size: 16px; font-family: inherit;
}
.barre-recherche input { flex: 1; min-width: 0; }

.liste-souvenirs { display: flex; flex-direction: column; gap: 8px; }
.carte-souvenir {
  width: 100%; padding: 12px 13px; text-align: left;
  background: var(--fond-2); border: 1px solid var(--bord);
  border-radius: var(--rayon-s); color: inherit;
}
.carte-souvenir:hover { background: var(--fond-survol); }
.tete-souvenir { display: flex; align-items: center; gap: 7px; margin-bottom: 5px; }
.tete-souvenir b { font-size: 14.5px; flex: 1; min-width: 0;
                   overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.corps-souvenir {
  font-size: 13px; color: var(--texte-doux); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.vide-liste { padding: 26px 12px; text-align: center; color: var(--texte-faible);
              font-size: 14px; }

/* Sur un écran étroit, le sélecteur de catégorie écrasait le champ de
   recherche au point de le rendre inutilisable : on les empile. */
@media (max-width: 460px) {
  .barre-recherche { flex-direction: column; }
  .barre-recherche select { width: 100%; }
}

/* ==========================================================================
   Appareils
   ========================================================================== */

.liste-appareils-connexion { display: flex; flex-direction: column; gap: 8px;
                             margin-bottom: 18px; }
.liste-appareils-connexion:empty { display: none; }
.choix-appareil {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 12px 13px; text-align: left;
  background: var(--fond-3); border: 1px solid var(--bord);
  border-radius: var(--rayon-s); color: inherit;
}
.choix-appareil:hover { background: var(--fond-survol); border-color: var(--accent); }
.choix-appareil .ic { width: 19px; height: 19px; flex: 0 0 auto; color: var(--texte-doux); }
.choix-appareil .infos { flex: 1; min-width: 0; }
.choix-appareil b { display: block; font-size: 14.5px; font-weight: 600;
                    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.choix-appareil small { font-size: 11.5px; color: var(--texte-faible); }

.liste-appareils-reglages { display: flex; flex-direction: column; gap: 9px; }
.carte-appareil {
  padding: 12px 13px; background: var(--fond-3);
  border: 1px solid var(--bord); border-radius: var(--rayon-s);
}
.carte-appareil.inactif { opacity: .55; }
.tete-appareil { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.tete-appareil b { flex: 1; min-width: 0; font-size: 14.5px;
                   overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-appareil { font-size: 11.5px; color: var(--texte-faible); line-height: 1.6; }
.actions-appareil { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.actions-appareil button {
  padding: 7px 11px; font-size: 12.5px; font-weight: 500;
  background: var(--fond-2); color: var(--texte-doux);
  border: 1px solid var(--bord); border-radius: var(--rayon-s);
}
.actions-appareil button:hover { background: var(--fond-survol); color: var(--texte); }
.actions-appareil button.danger { color: var(--danger); }
