/* Le fil de conversation (planches « Chat · 1 à 4 » et « 5 · La machine
   travaille »). Les échanges de la session s'empilent dans #thread ;
   #exchange porte celui en cours. On sait à la lettre qui parle : ta bulle
   en vert plein, pepi en romain (--font-voice), la machine en chasse fixe. */

#thread, #exchange { display: contents; }
.turn {
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: pp-rise var(--dur-in) var(--ease-out) both;
}
.turn-date {
  display: flex;
  align-items: center;
  gap: 12px;
  font: 500 12px/1 var(--font-ui);
  color: var(--ink-3);
}
.turn-date::before, .turn-date::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* --- Ta bulle : vert plein, plus de dégradé. --- */
.user-wrap {
  align-self: flex-end;
  max-width: 80%;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.msg.user {
  background: var(--accent);
  color: var(--on-accent);
  padding: 10px 16px;
  border-radius: var(--r-4) var(--r-4) 6px var(--r-4);
  font: var(--fw-regular) 15px/1.45 var(--font-ui);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.user-tools { display: flex; gap: 6px; }
/* Les outils ne servent qu'au dernier message : modifier un échange
   ancien n'aurait pas de sens, et le fil resterait encombré. */
#thread .user-tools { display: none; }

/* --- La machine travaille : le point gagne un satellite, une phrase en
   français dit ce qu'il fait, les étapes faites se rangent dessous. --- */
.work { display: flex; flex-direction: column; gap: 12px; }
.work[hidden] { display: none; }
.work-status { display: flex; align-items: center; gap: 10px; }
.work-sentence { flex: 1; min-width: 0; font: 500 15px/1.4 var(--font-ui); color: var(--ink-2); }
.work-clock { font: 500 12.5px/1 var(--font-machine); color: var(--ink-3); }
.work-steps {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-left: 30px;
}
.work-steps:empty { display: none; }
.work-step { display: flex; align-items: flex-start; gap: 8px; }
.work-step > .ic { margin-top: 2px; color: var(--accent-text); }
.work-step-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.work-step-label { font: 450 13px/1.4 var(--font-ui); color: var(--ink-2); }
.work-step-machine { font: 450 12px/1.3 var(--font-machine); color: var(--ink-3); overflow-wrap: anywhere; }
.work-step-time { font: 450 12px/1.4 var(--font-machine); color: var(--ink-3); }
.work-step.summary .work-step-label { color: var(--ink-3); }

/* Passé vingt secondes, pepi rend sa liberté : la promesse est vraie, le
   travail vit côté serveur et l'alerte « réponse prête » existe. */
.work-slow {
  margin-left: 30px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  padding: 14px 14px 14px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.work-slow[hidden] { display: none; }
.work-slow p { flex: 1 1 260px; font: 450 14px/1.5 var(--font-ui); color: var(--ink-2); }
.notify-button {
  height: 36px;
  padding: 0 14px 0 11px;
  border-radius: var(--r-full);
  border: 1px solid var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent-text);
  font: 600 13px/1 var(--font-ui);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
}
.notify-button:disabled { cursor: default; }

/* --- Fini : tout se replie en une ligne de machine, ouvrable. --- */
.activity { align-self: flex-start; max-width: 100%; }
.activity[hidden] { display: none; }
.activity summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  margin-left: -8px;
  padding: 0 8px;
  border-radius: var(--r-2);
  color: var(--ink-3);
  font: 450 12px/1.3 var(--font-machine);
  cursor: pointer;
  user-select: none;
}
.activity summary::-webkit-details-marker { display: none; }
.activity-dot {
  width: 8px;
  height: 8px;
  margin: 0 4px;
  flex: none;
  border-radius: var(--r-full);
  background: var(--accent);
}
.activity.failed .activity-dot { background: var(--danger); }
.activity summary .ic { transition: transform var(--dur-in) var(--ease-out); }
.activity[open] summary .ic { transform: rotate(180deg); }
@media (hover: hover) {
  .activity summary:hover { background: var(--paper-sunk); color: var(--ink-2); }
}
.activity-body {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  background: var(--surface);
  overflow: hidden;
}
.activity-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font: 450 12px/1.4 var(--font-machine);
  color: var(--ink-3);
}
.activity-meta .activity-copy { margin-left: auto; }
.activity-tokens.warn { color: var(--warn); }
.activity-tokens:empty, .activity-tokens[hidden] { display: none; }
/* Mode debug : la trace en clair sous le résumé d'activité. Scroll
   horizontal propre plutôt qu'un retour à la ligne au milieu d'un nom de
   service — une ligne de trace se lit d'un bloc ou pas du tout. */
.activity-debug {
  margin: 0;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-sunk);
  font: 450 11.5px/1.5 var(--font-machine);
  color: var(--ink-2);
  white-space: pre;
  overflow-x: auto;
}
.activity-debug[hidden] { display: none; }
.activity-log {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 42vh;
  max-height: 42dvh;
  overflow-y: auto;
}
.act-entry .act-label { font: 500 13px/1.4 var(--font-ui); color: var(--ink); }
.act-entry.status .act-label { color: var(--accent-text); }
.act-entry .act-when { font: 450 12px/1 var(--font-machine); color: var(--ink-3); margin-left: 8px; }
.act-entry pre {
  margin-top: 4px;
  background: var(--paper-sunk);
  border-radius: var(--r-1);
  padding: 6px 10px;
  font: 450 12px/1.5 var(--font-machine);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 9rem;
  overflow-y: auto;
  color: var(--ink-2);
}
.act-entry.reasoning pre { font: italic 400 14px/1.5 var(--font-voice); }

/* --- La réponse, dans la voix de pepi. --- */
.msg.bot {
  align-self: stretch;
  overflow-wrap: anywhere;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.msg.bot .label { display: none; }
.msg.bot .body {
  font: 400 17px/28px var(--font-voice);
  color: var(--ink);
  max-width: var(--measure);
}
.msg.bot .body:empty { display: none; }
.msg.bot .body strong { font-weight: 600; }
.msg.bot .body p { margin: 0 0 0.75em; }
.msg.bot .body p:last-child { margin-bottom: 0; }
.msg.bot .body ul, .msg.bot .body ol { margin: 0 0 0.75em 1.3em; }
.msg.bot .body li { margin-bottom: 0.3em; }
.msg.bot .body code {
  background: var(--paper-sunk);
  border-radius: var(--r-1);
  padding: 0.1em 0.4em;
  font: 450 0.8em var(--font-machine);
}
.msg.bot .body a { color: var(--accent-text); text-underline-offset: 3px; }
.msg.bot .body pre {
  background: var(--paper-sunk);
  border-radius: var(--r-2);
  padding: 12px 14px;
  margin: 0 0 0.75em;
  overflow-x: auto;
}
.msg.bot .body pre code { background: none; padding: 0; font-size: 13px; line-height: 1.6; }
.msg.bot .body h4, .msg.bot .body h5, .msg.bot .body h6 {
  font: 650 17px/1.4 var(--font-ui);
  margin: 1em 0 0.4em;
}
.msg.bot .body h4:first-child { margin-top: 0; }
/* Formules larges : défilement local, pas de débordement de la bulle. */
.msg.bot .body .katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.msg.bot .body .interrupted, .msg.bot .body .canvas-note {
  font: 450 13px/1.4 var(--font-ui);
  color: var(--ink-3);
}
.msg.bot .body .canvas-note { font-style: italic; }

.msg.error .body {
  background: var(--danger-soft);
  border: 1px solid var(--danger-line);
  color: var(--danger);
  border-radius: var(--r-3);
  padding: 12px 16px;
  font: 450 15px/1.5 var(--font-ui);
}

/* Les actions sous une réponse : copier, écouter, utile / pas utile. */
.answer-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.answer-actions:empty { display: none; }
.speak-button.playing { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent-text); }
.speak-button.loading { color: var(--ink-3); }
.rate-button.active { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent-text); }

/* --- Sources web. --- */
.msg.bot .sources { display: flex; flex-direction: column; gap: 8px; }
.sources-title {
  font: var(--fw-strong) 12px/1.3 var(--font-ui);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.sources-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.sources-list a {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-height: 44px;
  text-decoration: none;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  padding: 8px 12px;
}
@media (hover: hover) {
  .sources-list a:hover { border-color: var(--line-strong); }
}
.sources-list .src-index { flex-shrink: 0; font: 450 12px/1 var(--font-machine); color: var(--ink-3); }
.sources-list .src-meta { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.sources-list .src-name { font: 500 14px/1.35 var(--font-ui); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sources-list .src-host { font: 450 12px/1.3 var(--font-machine); color: var(--ink-3); }

#canvas-rich, .canvas-rich { width: 100%; }
.canvas-frame {
  width: 100%;
  height: 58vh;
  height: 58dvh;
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  background: var(--surface);
}

@media (max-width: 760px) {
  .user-wrap { max-width: 88%; }
  .work-steps, .work-slow { margin-left: 0; padding-left: 30px; }
  .work-slow { margin-left: 30px; padding-left: 14px; }
}
