/* Interface — sobre, lisible, deux thèmes.
   Les couleurs sont des variables : une déclinaison par client se fera ici. */

:root {
  --fond:        #f4f5f7;
  --surface:     #ffffff;
  --surface-2:   #eef0f4;
  --trait:       #e0e3e9;
  --texte:       #16191f;
  --texte-doux:  #4a515c;
  --texte-faible:#69707c;
  --accent:      #4f6bed;
  --accent-doux: #e9edfc;
  --alerte:      #cf4d38;
  --rayon: 12px;
  --ombre: 0 1px 2px rgba(20,24,32,.06), 0 12px 30px -20px rgba(20,24,32,.30);
  --police: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* Thème sombre — celui d'Open WebUI : quasi noir, propre, bien contrasté. */
@media (prefers-color-scheme: dark) {
  :root {
    --fond:        #0e1014;
    --surface:     #171a20;
    --surface-2:   #21252e;
    --trait:       #2b313b;
    --texte:       #ecedf1;
    --texte-doux:  #b3bcc9;
    --texte-faible:#8b93a1;
    --accent:      #7f96ff;
    --accent-doux: #1e2540;
    --alerte:      #ec8a6f;
    --ombre: 0 1px 2px rgba(0,0,0,.5), 0 14px 34px -22px rgba(0,0,0,.95);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font-family: var(--police);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }

/* ── Connexion ───────────────────────────────────────────────────────────── */
.connexion {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.carte {
  background: var(--surface);
  border: 1px solid var(--trait);
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
  padding: 2rem;
  width: min(100%, 22rem);
  display: flex;
  flex-direction: column;
  gap: .55rem;
}

.carte h1 { margin: 0; font-size: 1.4rem; letter-spacing: -.02em; }
.sous-titre { margin: 0 0 .9rem; color: var(--texte-doux); font-size: .9rem; }

.carte label {
  font-size: .78rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--texte-faible);
  margin-top: .5rem;
}

.carte input {
  background: var(--surface-2);
  border: 1px solid var(--trait);
  border-radius: 6px;
  padding: .6rem .7rem;
}

.carte input:focus-visible,
.saisie textarea:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.carte button {
  margin-top: 1.1rem;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 6px;
  padding: .65rem;
  font-weight: 600;
  cursor: pointer;
}
.carte button:hover { filter: brightness(1.08); }

.erreur {
  margin: .3rem 0 0;
  color: var(--alerte);
  font-size: .88rem;
}

/* ── Ossature ────────────────────────────────────────────────────────────── */
.app {
  height: 100%;
  display: grid;
  grid-template-columns: 17.5rem minmax(0, 1fr);
}

.panneau {
  background: var(--surface-2);
  border-right: 1px solid var(--trait);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panneau-tete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: 1rem 1rem .8rem;
  border-bottom: 1px solid var(--trait);
}

.marque { font-weight: 650; letter-spacing: -.01em; }

.bouton-discret {
  background: transparent;
  border: 1px solid var(--trait);
  border-radius: 6px;
  padding: .28rem .6rem;
  font-size: .82rem;
  color: var(--texte-doux);
  text-decoration: none;
  cursor: pointer;
}
.bouton-discret:hover { background: var(--surface); color: var(--texte); }

.liste-sessions {
  flex: 1;
  overflow-y: auto;
  padding: .6rem;
  display: flex;
  flex-direction: column;
  gap: .2rem;
}

.session {
  display: flex;
  flex-direction: column;
  gap: .1rem;
  padding: .5rem .6rem;
  border-radius: 6px;
  text-decoration: none;
  color: var(--texte-doux);
}
.session:hover { background: var(--surface); }
.session.actif { background: var(--accent-doux); color: var(--texte); }

.session-titre {
  font-size: .87rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-meta { font-size: .72rem; color: var(--texte-faible); }

.vide { color: var(--texte-faible); font-size: .85rem; padding: .5rem .6rem; }

/* ── Onglets Fils / Tâches ─────────────────────────────────────────────────── */
.onglets { display: flex; gap: .3rem; padding: .6rem .6rem 0; }
.onglet {
  flex: 1;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: .35rem .5rem;
  font: inherit;
  font-size: .82rem;
  color: var(--texte-doux);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
}
.onglet:hover { background: var(--surface); }
.onglet.actif {
  background: var(--surface);
  border-color: var(--trait);
  color: var(--texte);
  font-weight: 600;
}
.badge {
  min-width: 1.15rem;
  padding: 0 .3rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: .7rem;
  line-height: 1.15rem;
  text-align: center;
}

.volet { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.volet[hidden] { display: none; }

/* ── Liste des tâches ──────────────────────────────────────────────────────── */
.liste-taches {
  flex: 1;
  overflow-y: auto;
  padding: .5rem .6rem;
  display: flex;
  flex-direction: column;
  gap: .1rem;
}
.tache-groupe {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--texte-faible);
  padding: .7rem .6rem .25rem;
}
.tache-groupe.retard { color: var(--alerte); }
.tache-ligne {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  padding: .45rem .6rem;
  border-radius: 6px;
}
.tache-ligne:hover { background: var(--surface); }
.tache-check {
  margin-top: .1rem;
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  cursor: pointer;
  flex: none;
}
.tache-corps { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .1rem; }
.tache-libelle { font-size: .87rem; color: var(--texte); overflow-wrap: anywhere; }
.tache-meta { font-size: .72rem; color: var(--texte-faible); }
.tache-suppr {
  flex: none;
  background: transparent;
  border: none;
  color: var(--texte-faible);
  cursor: pointer;
  padding: .1rem .25rem;
  opacity: 0;
  transition: opacity .12s;
}
.tache-ligne:hover .tache-suppr,
.tache-suppr:focus-visible { opacity: 1; }
.tache-suppr:hover { color: var(--alerte); }
.tache-ligne.faite { opacity: .45; }
.tache-ligne.faite .tache-libelle { text-decoration: line-through; }

/* ── Documents (corpus / RAG) ──────────────────────────────────────────────── */
.doc-tete { display: flex; gap: .4rem; padding: .6rem .6rem .3rem; align-items: center; }
.doc-filtre {
  flex: 1; min-width: 0;
  background: var(--surface); border: 1px solid var(--trait); border-radius: 6px;
  padding: .35rem .55rem; font: inherit; font-size: .82rem; color: var(--texte);
}
.doc-filtre:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.doc-ajout {
  flex: none; width: 1.9rem; height: 1.9rem; border-radius: 6px;
  border: 1px solid var(--trait); background: var(--surface);
  display: grid; place-items: center; font-size: 1.2rem; line-height: 1;
  color: var(--accent); cursor: pointer;
}
.doc-ajout:hover { background: var(--accent-doux); }
.doc-etat { font-size: .78rem; color: var(--texte-doux); padding: .1rem .7rem .3rem; margin: 0; }
.doc-etat.erreur { color: var(--alerte); }

.liste-docs { flex: 1; overflow-y: auto; padding: .3rem .6rem .6rem;
  display: flex; flex-direction: column; gap: .15rem; }
.doc-ligne {
  display: flex; align-items: flex-start; gap: .5rem;
  padding: .5rem .6rem; border-radius: 6px;
}
.doc-ligne:hover { background: var(--surface); }
.doc-icone { flex: none; margin-top: .1rem; font-size: .95rem; line-height: 1; }
.doc-icone.ok { color: var(--accent); }
.doc-icone.attente { color: var(--texte-faible); }
.doc-icone.orphelin { color: var(--alerte); }
.doc-corps { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .15rem; }
.doc-nom { font-size: .84rem; color: var(--texte); overflow-wrap: anywhere; }
.doc-meta { font-size: .72rem; color: var(--texte-faible); display: flex; flex-wrap: wrap; gap: .3rem; }
.doc-tag {
  font-size: .68rem; padding: .02rem .35rem; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--trait); color: var(--texte-doux);
}
.doc-actions { flex: none; display: flex; gap: .1rem; }
.doc-actions button {
  background: transparent; border: none; cursor: pointer; padding: .15rem .3rem;
  color: var(--texte-faible); font-size: .8rem; border-radius: 5px;
}
.doc-actions button:hover { background: var(--surface-2); color: var(--texte); }
.doc-actions .doc-suppr:hover { color: var(--alerte); }
.doc-ligne.occupe { opacity: .5; pointer-events: none; }

.panneau-pied {
  border-top: 1px solid var(--trait);
  padding: .7rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}
.compte { font-size: .85rem; color: var(--texte-doux); }

/* ── Conversation ────────────────────────────────────────────────────────── */
.conversation {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
}

.fil {
  overflow-y: auto;
  padding: 1.6rem clamp(1rem, 5vw, 3rem);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.accueil { margin: auto; text-align: center; color: var(--texte-doux); }
.accueil h1 { margin: 0 0 .3rem; font-size: 1.5rem; letter-spacing: -.02em; color: var(--texte); }

.message { display: flex; }
.message.utilisateur { justify-content: flex-end; }

.bulle {
  max-width: min(46rem, 82%);
  padding: .75rem 1.05rem;
  border-radius: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.assistant .bulle {
  background: var(--surface);
  border: 1px solid var(--trait);
}
.message.utilisateur .bulle {
  background: var(--accent);
  color: #fff;
}

.bulle.attente::after {
  content: "▍";
  animation: clignote 1s steps(2) infinite;
  color: var(--texte-faible);
}

/* Ce que l'agent est en train de faire. Remplace le curseur nu : cinq secondes
   de silence paraissent longues, cinq secondes de « je cherche dans les
   documents » paraissent normales. */
.bulle.attente[data-statut]::after {
  content: attr(data-statut) " …";
  font-size: .88rem;
  font-style: italic;
  color: var(--texte-faible);
  animation: respire 1.6s ease-in-out infinite;
}
@keyframes respire { 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) {
  .bulle.attente[data-statut]::after { animation: none; }
}
@keyframes clignote { 50% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .bulle.attente::after { animation: none; }
}

/* ── Saisie ──────────────────────────────────────────────────────────────── */
.saisie {
  border-top: 1px solid var(--trait);
  background: var(--surface);
  padding: .8rem clamp(1rem, 5vw, 3rem);
  display: flex;
  gap: .6rem;
  align-items: flex-end;
}

.saisie textarea {
  flex: 1;
  resize: none;
  max-height: 9rem;
  background: var(--surface-2);
  border: 1px solid var(--trait);
  border-radius: 14px;
  padding: .65rem .85rem;
}
.saisie textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }

.saisie button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 14px;
  padding: .65rem 1.2rem;
  font-weight: 600;
  cursor: pointer;
}
.saisie button:hover:not(:disabled) { filter: brightness(1.08); }
.saisie button:disabled { opacity: .5; cursor: default; }

/* ── Étroit ──────────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .panneau { display: none; }
}

/* ── Contenu rendu depuis le markdown ────────────────────────────────────── */
/* La bulle passe en flux normal : le pre-wrap ne vaut que pour le texte brut. */
.message.assistant .bulle { white-space: normal; }

.bulle > :first-child { margin-top: 0; }
.bulle > :last-child  { margin-bottom: 0; }

.bulle p { margin: 0 0 .6rem; }
.bulle h3, .bulle h4, .bulle h5, .bulle h6 {
  margin: 1rem 0 .4rem;
  line-height: 1.3;
  letter-spacing: -.01em;
}
.bulle h3 { font-size: 1.1rem; }
.bulle h4 { font-size: 1rem; }
.bulle h5, .bulle h6 { font-size: .93rem; color: var(--texte-doux); }

.bulle ul, .bulle ol { margin: 0 0 .6rem; padding-left: 1.3rem; }
.bulle li { margin: .15rem 0; }

.bulle blockquote {
  margin: .6rem 0;
  padding: .1rem 0 .1rem .8rem;
  border-left: 3px solid var(--trait);
  color: var(--texte-doux);
}

.bulle code {
  background: var(--surface-2);
  border: 1px solid var(--trait);
  border-radius: 4px;
  padding: .05rem .3rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .88em;
}

.bulle pre {
  background: var(--surface-2);
  border: 1px solid var(--trait);
  border-radius: 6px;
  padding: .7rem .85rem;
  margin: .6rem 0;
  overflow-x: auto;
}
.bulle pre code { background: none; border: 0; padding: 0; font-size: .85em; }

.bulle hr { border: 0; border-top: 1px solid var(--trait); margin: .9rem 0; }

.bulle a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

/* Citation vers un document : elle doit se REMARQUER comme vérifiable.
   C'est le geste qui distingue l'outil du gadget — un conseiller qui peut
   ouvrir la page en un clic ne se demande pas si l'assistant a inventé. */
.bulle a.citation {
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
  padding: .05rem .3rem .05rem .25rem;
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  white-space: nowrap;
}
/* Le 📗 est écrit par le modèle juste avant : inutile d'en ajouter un second. */
.bulle a.citation:hover { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.bulle a.citation:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Un tableau large défile dans son cadre, la page ne part jamais de travers. */
.table-defilante { overflow-x: auto; margin: .6rem 0; }
.bulle table { border-collapse: collapse; font-size: .92em; }
.bulle th, .bulle td {
  border: 1px solid var(--trait);
  padding: .35rem .6rem;
  text-align: left;
  vertical-align: top;
}
.bulle th { background: var(--surface-2); font-weight: 620; }
.bulle td { font-variant-numeric: tabular-nums; }

/* Dans une bulle utilisateur (fond accentué), on adapte les fonds internes. */
.message.utilisateur .bulle code,
.message.utilisateur .bulle pre { background: rgba(255,255,255,.16); border-color: rgba(255,255,255,.28); }
.message.utilisateur .bulle a { color: #fff; }

/* ── Ligne de conversation avec suppression ──────────────────────────────── */
.session-ligne {
  display: flex;
  align-items: center;
  border-radius: 6px;
}
.session-ligne:hover { background: var(--surface); }
.session-ligne.actif { background: var(--accent-doux); }
.session-ligne.actif .session { color: var(--texte); }

.session-ligne .session { flex: 1; min-width: 0; }
.session-ligne .session:hover { background: transparent; }

.supprimer {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.7rem;
  height: 1.7rem;
  padding: 0;
  margin-right: .2rem;
  background: transparent;
  border: 0;
  color: var(--texte-faible);
  border-radius: 5px;
  cursor: pointer;
  /* Visible seulement au survol : la corbeille ne doit pas attirer l'œil
     en permanence, mais rester atteignable au clavier. */
  opacity: 0;
  transition: opacity .12s;
}
.session-ligne:hover .supprimer,
.supprimer:focus-visible { opacity: 1; }
.supprimer:hover { color: var(--alerte); background: var(--fond); }

@media (prefers-reduced-motion: reduce) { .supprimer { transition: none; } }
/* Sans survol possible (tactile), la corbeille reste affichée. */
@media (hover: none) { .supprimer { opacity: 1; } }

/* ── Pied de panneau : réglages et sortie ────────────────────────────────── */
.bouton-roue {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: transparent;
  border: 1px solid var(--trait);
  border-radius: 6px;
  padding: .3rem .6rem;
  font-size: .82rem;
  color: var(--texte-doux);
  cursor: pointer;
}
.bouton-roue:hover { background: var(--surface); color: var(--texte); }
.bouton-roue svg { flex: none; }

/* ── Boîte de réglages ───────────────────────────────────────────────────── */
#reglages {
  border: 1px solid var(--trait);
  border-radius: var(--rayon);
  background: var(--surface);
  color: var(--texte);
  padding: 0;
  width: min(100%, 26rem);
  box-shadow: var(--ombre);
}
#reglages::backdrop { background: rgba(0, 0, 0, .45); }

.reglages-forme {
  display: flex;
  flex-direction: column;
  gap: .9rem;
  padding: 1.6rem;
}
.reglages-forme h2 { margin: 0; font-size: 1.15rem; letter-spacing: -.015em; }
.reglages-intro { margin: -.4rem 0 .2rem; font-size: .86rem; color: var(--texte-doux); }

.champ { display: flex; flex-direction: column; gap: .3rem; }
.champ label {
  font-size: .9rem;
  font-weight: 600;
  color: var(--texte);
}
.champ input, .champ select {
  background: var(--surface-2);
  color: var(--texte);
  border: 1px solid var(--trait);
  border-radius: 8px;
  padding: .55rem .7rem;
  font-size: .95rem;
}
.champ input::placeholder { color: var(--texte-faible); }
.champ input:focus-visible, .champ select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
.champ .aide { font-size: .82rem; color: var(--texte-doux); line-height: 1.45; }

.reglages-etat { margin: 0; font-size: .84rem; color: var(--accent); min-height: 1.2em; }
.reglages-etat.erreur { color: var(--alerte); }

.reglages-actions {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  margin-top: .3rem;
}
.bouton-plein {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 6px;
  padding: .5rem 1rem;
  font-weight: 600;
  cursor: pointer;
}
.bouton-plein:disabled { opacity: .6; cursor: default; }

/* ── Barre de liste : tout sélectionner, compteur, suppression ───────────── */
.barre-liste {
  display: flex;
  align-items: center;
  gap: .5rem;
  /* Alignée sur le retrait des lignes de conversation, pour que les cases
     à cocher se superposent verticalement. */
  padding: .45rem .6rem .45rem .95rem;
  margin: .4rem .6rem 0;
  border: 1px solid transparent;
  border-radius: 6px;
  min-height: 2rem;
}
.barre-liste.actif {
  background: var(--accent-doux);
  border-color: var(--trait);
}

.barre-liste-texte {
  flex: 1;
  min-width: 0;
  font-size: .78rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--texte-faible);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.barre-liste.actif .barre-liste-texte {
  color: var(--texte);
  text-transform: none;
  letter-spacing: 0;
  font-size: .84rem;
}

.choix-tout, .choix-session {
  flex: none;
  width: .95rem;
  height: .95rem;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.bouton-corbeille {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.7rem;
  height: 1.7rem;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 5px;
  color: var(--alerte);
  cursor: pointer;
}
.bouton-corbeille:hover { background: var(--surface); }
.bouton-corbeille:disabled { opacity: .5; cursor: default; }

/* Les cases restent discrètes tant qu'on ne sélectionne pas. */
.choix-session { opacity: 0; transition: opacity .12s; }
.session-ligne:hover .choix-session,
.choix-session:focus-visible,
.choix-session:checked,
body.en-selection .choix-session { opacity: 1; }

@media (prefers-reduced-motion: reduce) { .choix-session { transition: none; } }
@media (hover: none) { .choix-session { opacity: 1; } }

/* La ligne de conversation laisse la place à la case. */
.session-ligne { padding-left: .35rem; gap: .35rem; }


/* ── Appareils appariés (passerelles de messagerie) ──────────────────────── */
.appareils { margin: 1rem 0 .2rem; padding-top: .9rem; border-top: 1px solid var(--trait); }
.appareils h3 { margin: 0 0 .3rem; font-size: .95rem; }
.reglages-aide { margin: 0 0 .6rem; font-size: .85rem; color: var(--texte-doux); }
.appareils-ligne { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; }

/* Le code se lit à voix haute et se tape sur un clavier de téléphone :
   espacé, en chasse fixe, assez gros pour ne pas confondre deux caractères. */
.code-appariement {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.25rem;
  letter-spacing: .22em;
  font-weight: 600;
  color: var(--accent);
}
.liste-appareils { list-style: none; margin: .7rem 0 0; padding: 0; display: grid; gap: .35rem; }
.liste-appareils li {
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  font-size: .85rem; color: var(--texte-doux);
}


/* ── Deux qualités de source, lisibles en diagonale ──────────────────────── */
/* Un conseiller doit voir SANS LIRE ce qu'il peut répéter à un client et ce
   qu'il doit vérifier. La couleur fait ce travail avant le texte. */
.bulle strong:has(a.citation) {
  background: color-mix(in srgb, var(--ok, #2e7d5b) 12%, transparent);
  border-radius: 4px;
  padding: .05rem .25rem;
}
