/*
 * Toutes les couleurs et tous les espacements du projet vivent ici. Aucune
 * valeur en dur ailleurs : c'est ce qui garde la console cohérente sans
 * framework ni design system.
 *
 * Les jetons reprennent le système visuel du prototype Yelda (yelda-prototype/
 * assets/styles.css) : top bar bleue, sidebar sur canvas clair, grandes
 * surfaces blanches à sections filetées, pilules de statut à fond doux.
 */
:root {
  /* Marque */
  --blue: #2f6ded;
  --blue-dark: #2558c9;
  --blue-soft: #eaf1fe;
  --blue-line: #c7dbfb;

  /* Le violet est la couleur du RAG sur toute la page d'un appel : la phrase
     d'attente dans le fil, l'étage de recherche dans le waterfall. Une seule
     teinte, déclarée une seule fois. */
  --violet: #6b4bc8;
  --violet-bg: #f3effc;
  --violet-line: #ddd2f4;

  /* Canvas et surfaces */
  --bg: #f7f9fc;
  --surface: #ffffff;
  --surface-2: #fafcff;
  --track: #eef2f7;
  --hover: #f0f4fa;
  --border: #e4eaf1;
  --border-strong: #c7d4e4;

  /* Texte */
  --text: #33475b;
  --text-sec: #7c8fa4;
  --text-faint: #9aabbd;

  /* Accent (alias, pour les composants génériques) */
  --accent: var(--blue);
  --accent-hover: var(--blue-dark);
  --on-accent: #ffffff;

  /* Encres et fonds d'état */
  --ok: #1a7f52;
  --ok-bg: #e9f5ef;
  --warn: #9a6a12;
  --warn-bg: #fdf3e2;
  --warn-line: #f0d6a0;
  --danger: #b23b2e;
  --danger-bg: #fbeae7;
  --danger-line: #f0c4bd;
  --danger-hover: #9a3226;
  --neutral: #94a3b8;
  --amber: #f59e0b;

  /* Encodage des étages d'un tour, au même titre que les classes .chart-*.
     Cinq teintes distinctes sont nécessaires pour cinq étages ; elles ne
     servent à rien d'autre, et aucune n'apparaît en dur dans un composant. */
  --stage-detect: var(--blue);
  --stage-retrieval: var(--violet);
  --stage-llm2: #7aa9f7;
  --stage-sentence: var(--ok);
  --stage-tts: #b8790a; /* var(--amber) assombri, pour du texte blanc */
  --stage-speech: var(--border-strong);
  --stage-remainder: var(--neutral);
  --ink-dark: #1a1a2e;

  /* Espacements */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* Formes */
  --radius: 12px;
  --radius-md: 10px;
  --radius-sm: 7px;
  --panel-shadow: 0 1px 2px rgba(16, 32, 60, 0.04), 0 4px 16px rgba(16, 32, 60, 0.05);
  --pop-shadow: 0 12px 32px rgba(16, 32, 60, 0.18);
  --modal-shadow: 0 24px 60px rgba(16, 32, 60, 0.3);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Chrome */
  --topbar-h: 62px;
  --sidebar-w: 240px;
  --content-max: 1320px;
  --gutter: clamp(16px, 2vw, 40px);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  overflow: hidden;
}

#app {
  height: 100%;
}

a {
  color: var(--blue);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  color: var(--text);
}
h1 {
  font-size: 20px;
  font-weight: 700;
}
h2 {
  font-size: 16px;
}
h3 {
  font-size: 14px;
}

code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--track);
  padding: 1px 6px;
  border-radius: 5px;
}

/* ---------- chrome : top bar bleue + sidebar + contenu ---------- */

.shell {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  flex-shrink: 0;
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  background: var(--blue);
  color: #fff;
  padding: 0 var(--gutter) 0 0;
}

.logo-block {
  display: flex;
  align-items: center;
  gap: 11px;
  width: var(--sidebar-w);
  flex-shrink: 0;
  padding: 8px 14px 8px 20px;
  color: #fff;
}
.logo-block:hover {
  text-decoration: none;
}
.logo-block:hover .logo {
  transform: scale(1.06);
}

/* Le glyphe blanc de la marque, servi par /brand : c'est une image, et non
   plus une pastille portant une lettre. */
.logo {
  width: 34px;
  height: 34px;
  border-radius: 7px;
  display: block;
  flex-shrink: 0;
  transition: transform 0.12s;
}

.brand {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}
.brand-name {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.brand-kind {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.75;
}

.page-title {
  font-size: 18px;
  font-weight: 600;
  padding-left: 26px;
  white-space: nowrap;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding-left: 18px;
  font-size: 13px;
}

/* ---------- l'identité, à droite de la barre du haut ---------- */

/* Qui est connecté. Sur la top bar bleue, donc en encre blanche : la pilule
   `admin` s'éclaircit toute seule par la règle `.topbar .badge`. */
.identity {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  color: #fff;
  font-size: 13px;
}
.identity:hover {
  text-decoration: none;
}
.identity:hover .identity-name {
  text-decoration: underline;
}

.identity-name {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

/* Rond de 28 px, ici comme dans la table Team : un seul jeton de taille. */
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  background: var(--track);
}

/* Le repli quand Google n'a pas donné de photo. */
.avatar-initials {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--blue-soft);
  color: var(--blue);
}

/* Dans une table, la colonne d'avatar ne prend que sa largeur. */
td.avatar-cell,
th.avatar-cell {
  width: 28px;
  padding-right: 0;
}

/* Le rôle dans la table Team. Sans largeur minimale, la colonne se réduit à la
   flèche du select et « Member » devient illisible. */
.role-select {
  min-width: 110px;
}

.btn-top {
  background: #fff;
  color: var(--text);
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-top:hover:not(:disabled) {
  background: var(--blue-soft);
  border-color: transparent;
}

.layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ---------- le panneau de chat écrit (chrome) ---------- */

/* L'état pressé du bouton de la barre du haut. `.btn-top` est déjà blanc sur
   le bleu : deux jetons existants suffisent à le teinter, et aucune couleur
   n'est inventée ici. */
.btn-top[aria-pressed='true'] {
  background: var(--blue-soft);
  color: var(--blue-dark);
}

/* L'emplacement du bouton dans la barre : vide, il ne prend pas de place. */
.chat-slot {
  display: contents;
}

/* Troisième enfant de `.layout`, après `.content`. Il ne touche pas à
   `main > *` : `.content` rétrécit par flex, et le porteur de largeur reste
   unique. */
.chat-drawer {
  width: 400px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
}

/* Sa propre règle, obligatoire : une feuille d'auteur qui pose `display: flex`
   bat le `display: none` du navigateur à spécificité égale, et le panneau
   s'ouvrirait tout seul. Le piège documenté des popovers. */
.chat-drawer[hidden] {
  display: none;
}

.chat-head {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}

/* Deux rangées : le nom et la fermeture d'abord, les actions ensuite. Le × doit
   rester en haut à droite quoi qu'il arrive à la seconde rangée. */
.chat-head-top,
.chat-head-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.chat-title {
  font-weight: 600;
  margin-right: auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-head-actions .chat-link {
  margin-right: auto;
}

.chat-version {
  width: auto;
  max-width: 150px;
  font-size: 12.5px;
  padding: 4px 8px;
}

.chat-link {
  font-size: 12px;
  color: var(--blue);
}

/* Le × ferme la conversation : il est désactivé le temps d'un tour, parce qu'un
   raccroché en plein tour écrirait un rapport sans le dernier échange. */
.chat-x {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  padding: 0 var(--space-2);
  color: var(--text-sec);
  cursor: pointer;
}
.chat-x:hover:not(:disabled) {
  color: var(--text);
}
.chat-x:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Ce que le texte ne teste pas, dit sur place : c'est là qu'on est en train de
   conclure qu'un agent est prêt. */
.chat-notes {
  flex-shrink: 0;
  padding: var(--space-2) var(--space-4);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-sec);
}
.chat-notes p {
  margin: 2px 0;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
}

.chat-line {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

/* Mêmes règles que les bulles du fil d'un appel, à la largeur près : le panneau
   est étroit. `break-word` et jamais `anywhere` — `anywhere` fait tomber la
   largeur min-content à un caractère. */
.chat-msg {
  max-width: 88%;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: 13px;
  line-height: 1.5;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}
.chat-msg.agent {
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
}
.chat-msg.user {
  align-self: flex-end;
  background: var(--blue-soft);
  border: 1px solid var(--blue-line);
  border-bottom-right-radius: 3px;
}
.chat-msg.system {
  align-self: center;
  max-width: none;
  background: var(--danger-bg);
  border: 1px solid var(--danger-line);
  color: var(--danger);
  font-size: 12px;
}

/* La phrase d'attente, au-dessus de la réponse : reprend l'aspect du filler du
   fil d'appel, dans le violet qui dit le RAG partout. */
.chat-wait {
  align-self: flex-start;
  max-width: 88%;
  padding: var(--space-1) var(--space-3);
  background: var(--violet-bg);
  border: 1px solid var(--violet-line);
  border-radius: var(--radius-sm);
  color: var(--violet);
  font-size: 12px;
  font-style: italic;
}

.chat-note {
  align-self: flex-start;
  font-size: 11px;
  color: var(--text-faint);
}

.chat-meta {
  align-self: flex-start;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  font-size: 11px;
  color: var(--text-sec);
}
.chat-meta-item {
  font-family: var(--mono);
}

/* L'agent écrit : trois points, le temps du tour. */
.chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 5px;
  padding: var(--space-3);
}
.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: chat-blink 1.2s infinite ease-in-out;
}
.chat-typing span:nth-child(2) {
  animation-delay: 0.2s;
}
.chat-typing span:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes chat-blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
  }
  40% {
    opacity: 1;
  }
}

.chat-foot {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: var(--space-3) var(--space-4);
}

.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
}

.chat-input {
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: 56px;
  resize: none;
  font: inherit;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.4;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}

.chat-count {
  margin-top: var(--space-1);
  font-size: 11px;
  color: var(--text-faint);
}

/* Le point de repli de `.inspector` : au-dessous, le panneau recouvre au lieu
   de pousser — une table de conversations à 300 px n'est plus une table. */
@media (max-width: 1180px) {
  .chat-drawer {
    position: fixed;
    right: 0;
    top: var(--topbar-h);
    bottom: 0;
    z-index: 30;
    box-shadow: var(--pop-shadow);
  }
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--border);
  padding: 14px 12px;
  overflow-y: auto;
}

.nav-section {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  padding: 16px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  margin-bottom: 2px;
  border-radius: 8px;
  color: var(--text);
  font-size: 13.5px;
  transition: background 0.12s;
}
.nav-item:hover {
  background: var(--hover);
  text-decoration: none;
}
.nav-item.active {
  background: var(--blue);
  color: #fff;
  font-weight: 600;
}
.nav-icon {
  width: 20px;
  text-align: center;
  font-size: 15px;
  flex-shrink: 0;
}
.nav-label {
  flex: 1;
  line-height: 1.25;
}

.sidebar-spacer {
  flex: 1;
}

/* Pied de sidebar : où tourne cette console (région, base). */
.sidebar-env {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  border-top: 1px solid var(--border);
}
.sidebar-env .env-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}
.sidebar-env .row {
  gap: 6px;
}

.content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

main {
  flex: 1;
  overflow-y: auto;
  scrollbar-gutter: stable both-edges;
  padding: 26px 0 var(--space-7);
}

/* Le seul porteur de largeur : tout le contenu d'une vue passe par ce cadre. */
main > * {
  width: min(100% - 2 * var(--gutter), var(--content-max));
  margin-left: auto;
  margin-right: auto;
}

/* Les vues de mesure (Conversations, Tests) prennent toute la fenêtre : leur
   contenu est une table dense et un inspecteur, pas de la prose. Les autres
   restent cadrées — un champ de prompt à 2000 px est inutilisable.
   La classe est posée par shell() à partir de la route, jamais par une vue. */
main.wide > * {
  width: calc(100% - 2 * var(--gutter));
  max-width: none;
}

/* ---------- en-tête de page ---------- */

.page-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}
.page-head .spacer {
  flex: 1;
}
.page-head .back {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sec);
}
.page-head .back:hover {
  color: var(--blue);
  text-decoration: none;
}

/* ---------- surfaces ---------- */

/* La grande surface blanche qui « flotte » sur le canvas. */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--panel-shadow);
  padding: 20px 24px;
}
.card + .card {
  margin-top: var(--space-4);
}
.card > h2 {
  margin-bottom: var(--space-4);
}
.card.flush {
  padding: 0;
  overflow: hidden;
}
/* Sous-blocs d'une surface, séparés par un filet fin — jamais des cartes
   empilées. */
.card-section {
  padding: 22px 0;
  border-top: 1px solid var(--border);
}
.card-section:first-child {
  border-top: none;
  padding-top: 2px;
}
.card-section:last-child {
  padding-bottom: 2px;
}
.card-section > h2 {
  margin-bottom: var(--space-4);
}
.card-section-sub {
  font-size: 12.5px;
  color: var(--text-sec);
  margin: -12px 0 16px;
}

.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0 var(--space-5);
}

/* Deux surfaces côte à côte (repli en colonne sous 720 px de contenu). */
.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: var(--space-4);
  align-items: start;
  margin-top: var(--space-4);
}
.two-col > .card + .card {
  margin-top: 0;
}
.two-col + .card {
  margin-top: var(--space-4);
}

.hint {
  font-size: 12.5px;
  color: var(--text-sec);
}

/* ---------- formulaires ---------- */

.field {
  display: block;
  margin-bottom: 18px;
}

.field > .label,
.label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-sec);
}

.field .hint {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-faint);
}

input[type='text'],
input[type='password'],
input[type='number'],
input[type='search'],
select,
textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 13px;
}
input:disabled,
select:disabled,
textarea:disabled {
  background: var(--track);
  color: var(--text-sec);
}

textarea {
  min-height: 220px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-soft);
}

.counter {
  float: right;
  font-weight: 400;
  color: var(--text-faint);
}

/* ---------- boutons ---------- */

button {
  padding: 9px 15px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
button:hover:not(:disabled) {
  background: var(--hover);
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: var(--on-accent);
}
button.primary:hover:not(:disabled) {
  background: var(--blue-dark);
  border-color: var(--blue-dark);
}

button.danger {
  background: var(--surface);
  border-color: var(--danger-line);
  color: var(--danger);
}
button.danger:hover:not(:disabled) {
  background: var(--danger-bg);
}

button.small {
  padding: 5px 10px;
  font-size: 12px;
}

/* ---------- onglets (pilules) ---------- */

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.tab,
a.tab,
button.tab {
  padding: 9px 15px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-sec);
  font-size: 13px;
  font-weight: 500;
  text-transform: none;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.tab:hover,
a.tab:hover,
button.tab:hover:not(:disabled) {
  background: color-mix(in srgb, var(--text) 6%, transparent);
  color: var(--text);
  text-decoration: none;
}
.tab[aria-selected='true'],
a.tab[aria-selected='true'],
button.tab[aria-selected='true'] {
  background: var(--blue);
  color: #fff;
  font-weight: 600;
}
.agent-tabs {
  margin-bottom: var(--space-4);
}
.tabs.compact .tab {
  padding: 6px 12px;
  font-size: 12.5px;
}

/* ---------- tableaux ---------- */

/* Table « cadrée » du prototype : bordure fine, coins arrondis, en-tête
   discret. border-collapse: separate pour garder le cadre arrondi. */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

th,
td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 13px;
}

th {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-sec);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--surface-2);
  white-space: nowrap;
}
thead th:first-child {
  border-top-left-radius: var(--radius-md);
}
thead th:last-child {
  border-top-right-radius: var(--radius-md);
}
tbody tr:last-child td:first-child {
  border-bottom-left-radius: var(--radius-md);
}
tbody tr:last-child td:last-child {
  border-bottom-right-radius: var(--radius-md);
}

tbody tr:last-child td {
  border-bottom: none;
}
tbody tr:hover td {
  background: var(--surface-2);
}

td.num {
  font-family: var(--mono);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.card > table + .hint,
.card > table + p {
  margin: var(--space-4) 0 0;
}
.card > p:first-child {
  margin-top: 0;
}
.card > .empty:only-child,
.card > .loading:only-child {
  margin: 0;
}

/* Le tableau des tours a huit colonnes : il défile plutôt que d'écraser la page. */
.scroll-x {
  overflow-x: auto;
}
.card.scroll-x > table {
  min-width: 720px;
}

/* ---------- états ---------- */

.empty,
.loading {
  padding: var(--space-6);
  text-align: center;
  color: var(--text-sec);
  font-size: 13.5px;
}
.empty p {
  margin: 0 0 var(--space-3);
}
main > .loading {
  padding-top: var(--space-7);
}

/* Pilules : fond doux + encre, comme les statuts du prototype. */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--track);
  color: var(--text-sec);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.ok {
  background: var(--ok-bg);
  color: var(--ok);
}
.badge.warn {
  background: var(--warn-bg);
  color: var(--warn);
}
.badge.danger {
  background: var(--danger-bg);
  color: var(--danger);
}
.badge.blue {
  background: var(--blue-soft);
  color: var(--blue);
}
/* Sur la top bar bleue, la pilule s'éclaircit. */
.topbar .badge {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}

/* ---------- notifications ---------- */

#toasts {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  max-width: 520px;
  pointer-events: none;
}

.toast {
  padding: 11px 18px;
  background: var(--ink-dark);
  color: #fff;
  border-radius: 8px;
  border-left: 3px solid transparent;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  font-size: 13px;
  font-weight: 500;
}
.toast.ok {
  border-left-color: #3fb984;
}
.toast.error {
  border-left-color: #ef6b5e;
}
.toast.info {
  border-left-color: var(--blue);
}

/* ---------- écran de connexion ---------- */

.login-wrap {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  background: var(--bg);
}
.login-card {
  width: 380px;
  padding: 28px 28px 24px;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
/* Sur la carte blanche, la tuile : elle porte son propre fond. */
.login-brand .logo {
  width: 40px;
  height: 40px;
  border-radius: 9px;
}
.login-card h1 {
  font-size: 18px;
}
.login-card .intro {
  margin: 0 0 18px;
}
.login-card button.primary {
  width: 100%;
  padding: 10px 15px;
}
.login-card .error {
  margin-top: var(--space-3);
  color: var(--danger);
  font-size: 12.5px;
  min-height: 1em;
}

/* Le bouton Google : fond blanc, bordure, logo — la charte Google, rendue avec
   les jetons existants. Le logo lui-même est le seul endroit de la console où
   une couleur n'est pas un jeton : un logo repeint n'est plus le logo. */
.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 10px 15px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}
.btn-google:hover {
  background: var(--hover);
  text-decoration: none;
}

/* « ─── or ─── » : un filet coupé par le mot, et seulement quand il y a deux
   portes à séparer. */
.login-or {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-4) 0;
  color: var(--text-faint);
  font-size: 12px;
}
.login-or::before,
.login-or::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Le refus rapporté par ?auth_error= : au-dessus des portes, parce qu'il parle
   de la tentative précédente, pas du champ qui suit. */
.login-refusal {
  margin-bottom: var(--space-4);
  padding: 10px 12px;
  border: 1px solid var(--warn-line);
  border-radius: var(--radius-sm);
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 12.5px;
}

/* ---------- sélecteur de voix ---------- */

.voice-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}
.voice-toolbar .spacer {
  flex: 1;
}
.voice-toolbar select,
.voice-toolbar input[type='search'] {
  width: auto;
  min-width: 160px;
}

.voice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-3);
  max-height: 460px;
  overflow-y: auto;
  padding: 2px;
}

.voice {
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.voice:hover {
  border-color: var(--border-strong);
}
.voice.selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-soft);
}
.voice .name {
  font-weight: 600;
}
.voice .desc {
  margin: var(--space-1) 0 var(--space-3);
  font-size: 12px;
  color: var(--text-sec);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.voice .actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.voice .ttfb {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-sec);
}

/* ---------- bloc repliable ---------- */

details.advanced {
  margin-top: var(--space-4);
  border-top: 1px solid var(--border);
  padding-top: var(--space-4);
}
details.advanced > summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-sec);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  list-style: none;
  user-select: none;
}
details.advanced > summary::-webkit-details-marker {
  display: none;
}
details.advanced > summary::before {
  content: '▸ ';
}
details.advanced[open] > summary::before {
  content: '▾ ';
}
details.advanced > .body {
  margin-top: var(--space-4);
}
.card-section > details.advanced {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}

/* La barre d'actions suit le défilement : un prompt long ne doit pas obliger à
   remonter pour enregistrer. Surface blanche posée sur le bas du canvas. */
.sticky-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-top: var(--space-5);
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 -4px 16px rgba(16, 32, 60, 0.06), var(--panel-shadow);
}
.sticky-actions .spacer {
  flex: 1;
}
.sticky-actions input,
.sticky-actions select {
  width: auto;
}
.sticky-actions .group {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* ---------- filtres ---------- */

.filters {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: 12px 16px;
  margin-bottom: var(--space-4);
}
.filters .label {
  margin: 0;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.filters select {
  width: auto;
  min-width: 150px;
}
/* Un champ de recherche dans une barre de filtres se range à côté des listes,
   pas sur sa propre ligne — sinon la barre a deux hauteurs selon l'écran. */
.filters input[type='search'] {
  width: auto;
  min-width: 180px;
}

/* ---------- latence ---------- */

/* La latence est l'information principale d'une ligne : elle est lue avant le
   reste, donc plus grosse et colorée par rapport à la cible. */
.latency {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.latency.ok {
  color: var(--ok);
}
.latency.warn {
  color: var(--warn);
}
.latency.danger {
  color: var(--danger);
}

tbody tr.slowest {
  box-shadow: inset 3px 0 0 var(--amber);
}

/* La durée de parole du client n'est pas une latence : encre estompée, aucun
   seuil, et une colonne à part de la série des mesures. */
td.speech,
th.speech {
  color: var(--text-faint);
}

/* Trois groupes dans la table dense : ce que le client a dit, la décomposition,
   les latences perçues. Un filet vertical les sépare — sans lui, quinze
   colonnes de chiffres se lisent comme une seule. */
td.group,
th.group {
  border-left: 1px solid var(--border);
}

/* L'extrait est tronqué **par CSS**, jamais coupé en JavaScript : la valeur
   complète reste dans le title, donc au survol. */
td.excerpt {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- fil de conversation et inspecteur ---------- */

/* Les deux panneaux d'onglet se montrent et se cachent — ils ne se re-rendent
   jamais, sinon le flux SSE d'un appel en cours mourrait à chaque bascule.
   La règle explicite est obligatoire : une feuille d'auteur qui poserait un
   display bat le display:none du navigateur à spécificité égale. */
.tab-panel[hidden] {
  display: none;
}

/* Le fil à gauche, l'inspecteur à droite. Aucun de ces conteneurs ne prend
   d'overflow : le sticky de l'inspecteur colle par rapport à main, et un
   overflow intermédiaire le tuerait silencieusement. */
.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 520px;
  gap: var(--space-5);
  align-items: start;
}
@media (max-width: 1180px) {
  .split {
    grid-template-columns: minmax(0, 1fr);
  }
}

.inspector {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
  /* Sur l'élément lui-même, jamais sur un ancêtre : un extrait de document
     long défile dans le panneau au lieu d'allonger la page. */
  max-height: calc(100vh - var(--topbar-h) - var(--space-6));
  overflow-y: auto;
}
.inspector > .card {
  margin: 0;
}

/* La conversation elle-même. Le fil ne porte aucune surface : ce sont les
   bulles qui se voient, et une carte par tour les mettrait en concurrence. */
.chat {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}

/* Un tour entier — question, attente, réponse, mesures — est un seul bouton :
   les mesures appartiennent au tour, et une bulle seule n'aurait rien à
   montrer dans l'inspecteur. C'est un <button> : le clavier vient
   gratuitement. */
.pair {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-3);
  text-align: left;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s;
}
.pair:hover {
  background: var(--surface-2);
}
/* Sélectionnée, la paire prend une surface blanche à bordure bleue claire :
   le fond ne doit pas concurrencer les bulles, qui sont ce qu'on lit. */
.pair[aria-current='true'] {
  background: var(--surface);
  border-color: var(--blue-line);
}

/* Une bulle. Les 74 % seuls donneraient 110 caractères par ligne sur un grand
   écran ; les 62ch bornent la mesure sans casser l'effet de conversation. */
.msg {
  max-width: min(74%, 62ch);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: 13.5px;
  line-height: 1.55;
  /* break-word, et surtout pas anywhere : anywhere fait tomber la largeur
     min-content d'une bulle à un caractère, donc la colonne du fil peut se
     réduire jusqu'à une lettre par ligne quand la place manque — le bug qu'on
     vient précisément de retirer de la page. break-word coupe un mot trop long
     à l'affichage sans mentir sur la largeur dont le texte a besoin. */
  overflow-wrap: break-word;
}

/* Le client à gauche, l'agent à droite : l'alignement dit qui parle sans
   qu'on ait à lire une étiquette. Le coin carré est du côté du locuteur. */
.msg.client {
  align-self: flex-start;
  background: var(--track);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
  color: var(--text);
}
.msg.agent {
  align-self: flex-end;
  background: var(--blue-soft);
  border: 1px solid var(--blue-line);
  border-bottom-right-radius: 3px;
  color: var(--text);
}
/* La lecture a été coupée par l'appelant : le bord bas s'interrompt. C'est un
   fait de la conversation, pas un badge de métadonnée. */
.msg.agent.aborted {
  border-bottom-style: dashed;
  /* Assez contrasté pour se voir : le contour clair de la bulle, en pointillé,
     ne se distinguait pas d'un bord plein. */
  border-bottom-color: var(--blue);
}
/* L'accueil n'a pas de bulle client : la mention prend sa place plutôt que de
   laisser le tour commencer dans le vide. */
.msg.system {
  align-self: center;
  max-width: none;
  padding: var(--space-1) var(--space-3);
  color: var(--text-faint);
  font-size: 12px;
}
/* La phrase d'attente est une interjection, pas une réponse : plus étroite,
   en italique, dans le violet qui dit le RAG partout sur cette page. */
.msg.filler {
  align-self: flex-end;
  max-width: min(42%, 30ch);
  padding: var(--space-2) var(--space-3);
  background: var(--violet-bg);
  border: 1px solid var(--violet-line);
  color: var(--violet);
  font-size: 12.5px;
  font-style: italic;
}

/* Ce que l'agent a généré et que le vidage du buffer a jeté : personne ne l'a
   entendu, et ce n'est pas dans l'historique du modèle. Estompé, jamais masqué —
   c'est ce qu'il allait dire, et c'est ce qui explique la suite. */
.msg .unheard {
  color: var(--text-faint);
}

/* Durée d'élocution du client, sous sa bulle : neutre, hors de toute série de
   latences, et sans le moindre seuil de couleur. */
.msg-speech {
  align-self: flex-start;
  padding-left: var(--space-2);
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-faint);
}

/* Le ton que le modèle a demandé, juste avant ce qu'il a dit. */
.msg-tags {
  display: flex;
  align-self: flex-end;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* Les mesures du tour, du côté de l'agent : c'est sa réponse qu'elles datent. */
.pair-meta {
  display: flex;
  align-self: flex-end;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
}
.turn-idx {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-faint);
}
.turn-pill {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
}
.turn-pill-label {
  font-size: 11px;
  color: var(--text-faint);
}

/* ---------- recherche, dans l'inspecteur ---------- */

/* La reformulation du modèle, dans un bloc à elle : c'est elle qu'on relit
   quand une réponse est mauvaise. */
.rag-query {
  margin: var(--space-3) 0 var(--space-2);
  padding: var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 12.5px;
  overflow-wrap: anywhere;
}
.rag-hits {
  margin: var(--space-3) 0 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.rag-hit-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2);
}
.rag-hit-title {
  font-size: 12.5px;
  font-weight: 600;
}
.rag-hit-snippet {
  margin: 4px 0 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-sec);
  /* Le symptôme d'origine : ce texte se cassait une lettre par ligne dans une
     cellule de tableau. Il a maintenant la largeur du panneau. */
  overflow-wrap: anywhere;
}

/* ---------- waterfall des étages d'un tour ---------- */

.wf-svg {
  display: block;
  width: 100%;
  height: auto;
}
.wf-row-label {
  fill: var(--text-faint);
  font-size: 9.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.wf-axis {
  fill: var(--text-faint);
  font-family: var(--mono);
  font-size: 9px;
}
.wf-tick {
  stroke: var(--border-strong);
  stroke-width: 1;
}
/* Le repère du premier audio sortant : sur un tour avec attente, c'est le
   filler qui part là. */
.wf-mark {
  stroke: var(--text-sec);
  stroke-width: 1;
  stroke-dasharray: 2 3;
}
/* Parole du client : hachurée, neutre, hors de toute somme et sans seuil. */
.wf-hatch-line {
  fill: var(--stage-speech);
}
.wf-speech {
  stroke: var(--stage-speech);
  stroke-width: 1;
}
/* L'attente est de l'audio joué, pas un étage : elle emprunte le bleu doux. */
.wf-waiting {
  fill: var(--blue-soft);
  stroke: var(--blue);
  stroke-width: 1;
}

.wf-seg {
  shape-rendering: crispEdges;
}
.wf-detect,
.wf-swatch.wf-detect {
  fill: var(--stage-detect);
  background: var(--stage-detect);
}
.wf-retrieval,
.wf-swatch.wf-retrieval {
  fill: var(--stage-retrieval);
  background: var(--stage-retrieval);
}
.wf-llm2,
.wf-swatch.wf-llm2 {
  fill: var(--stage-llm2);
  background: var(--stage-llm2);
}
.wf-sentence,
.wf-swatch.wf-sentence {
  fill: var(--stage-sentence);
  background: var(--stage-sentence);
}
.wf-tts,
.wf-swatch.wf-tts {
  fill: var(--stage-tts);
  background: var(--stage-tts);
}
.wf-remainder,
.wf-swatch.wf-remainder {
  fill: var(--stage-remainder);
  background: var(--stage-remainder);
}

.wf-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin-top: var(--space-2);
}
.wf-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-sec);
}
.wf-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}
/* La ligne de contrôle affiche littéralement l'addition : elle n'est pas
   décorative, c'est elle qui fera repérer le jour où le tracer et l'affichage
   divergeront. */
.wf-control {
  margin: var(--space-2) 0 0;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
}

/* ---------- tuiles KPI ---------- */

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  padding: 0;
  overflow: hidden;
}
.stat {
  flex: 1 1 150px;
  padding: 16px 20px;
  border-right: 1px solid var(--border);
  min-width: 0;
}
.stat:last-child {
  border-right: none;
}
.stat-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-sec);
}
.stat-value {
  margin-top: 4px;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.05;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.stat-note {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-sec);
}
.stat-row > .stat-note {
  flex-basis: 100%;
  margin: 0;
  padding: 8px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

/* ---------- paires clé / valeur ---------- */

.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 10px var(--space-5);
  align-items: baseline;
}
.kv-key {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-sec);
}
.kv-value {
  font-family: var(--mono);
  font-size: 12.5px;
  /* anywhere, pas break-all : on ne coupe un mot que si la place manque
     vraiment. break-all cassait des URLs au milieu d'une ligne à moitié vide. */
  overflow-wrap: anywhere;
}

/* Extrait de configuration, ou chunk d’un document : même bloc monospace. */
pre.snapshot,
pre.chunk {
  max-height: 320px;
  overflow: auto;
  margin: var(--space-2) 0 var(--space-4);
  padding: var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- graphique ---------- */

.chart {
  display: block;
  width: 100%;
  height: auto;
  max-height: 280px;
  margin-top: var(--space-2);
}
.chart-grid {
  stroke: var(--border);
  stroke-width: 1;
}
.chart-axis {
  fill: var(--text-faint);
  font-family: var(--mono);
  font-size: 10px;
}
.chart-target {
  stroke: var(--amber);
  stroke-width: 1;
  stroke-dasharray: 4 4;
}
.chart-target-label {
  fill: var(--warn);
  font-size: 10px;
  font-weight: 600;
}
.chart-line {
  fill: none;
  stroke: var(--blue);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
/* Zone de surveillance, pas frontière : un aplat très clair entre 800 et
   1000 ms, sous la grille du reste du graphe. */
.chart-band {
  fill: var(--warn-bg);
}
.chart-dot {
  stroke: var(--surface);
  stroke-width: 1.5;
}
/* Les points prennent la bande de `latencyTone()`, comme partout ailleurs. */
.chart-dot.ok {
  fill: var(--ok);
}
.chart-dot.warn {
  fill: var(--amber);
}
.chart-dot.danger {
  fill: var(--danger);
}
.chart-empty {
  fill: var(--text-faint);
  font-size: 13px;
}

/* ---------- vue live ---------- */

.live-log {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
  font-size: 13px;
}
.live-line {
  display: flex;
  gap: var(--space-3);
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.live-kind {
  flex: 0 0 64px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
}
.live-line.partial {
  opacity: 0.6;
}
.live-line.agent {
  background: var(--blue-soft);
  border-color: transparent;
}
.live-line.agent .live-kind {
  color: var(--blue);
}
.live-line.metrics {
  font-family: var(--mono);
  color: var(--text-sec);
}

/* ---------- versionnage ---------- */

/* Bandeau d'état sous le nom de l'agent : où en sont published et draft. */
.version-banner {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-5);
  align-items: center;
  padding: 10px 16px;
  margin-bottom: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.version-state {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

/* Un numéro pointe sur un brouillon : la couleur dit que ce n'est pas normal. */
select.target-draft {
  border-color: var(--warn-line);
  background: var(--warn-bg);
  color: var(--warn);
}

.warn-note {
  color: var(--warn);
  font-size: 12.5px;
}
.ok-note {
  color: var(--ok);
}

.read-only-banner {
  border-left: 4px solid var(--border-strong);
}

.link-button {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- diff ---------- */

.diff-before {
  color: var(--danger);
}
.diff-after {
  color: var(--ok);
}

/* Le diff de texte défile plutôt que d'écraser la page : un prompt a des
   lignes longues, et les couper changerait ce qu'on lit. */
.diff-block {
  margin-top: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.7;
  background: var(--surface-2);
}
.diff-line {
  display: flex;
  gap: var(--space-3);
  padding: 0 var(--space-3);
  white-space: pre;
}
.diff-sign {
  width: 1ch;
  flex: none;
  color: var(--text-faint);
  user-select: none;
}
.diff-line.same {
  color: var(--text-sec);
}
.diff-line.add {
  background: var(--ok-bg);
  color: var(--ok);
}
.diff-line.del {
  background: var(--danger-bg);
  color: var(--danger);
}
.diff-line.add .diff-sign {
  color: var(--ok);
}
.diff-line.del .diff-sign {
  color: var(--danger);
}

/* ---------- dialogue modal ---------- */

.modal {
  width: min(680px, calc(100vw - 2 * var(--space-5)));
  padding: 24px;
  background: var(--surface);
  color: var(--text);
  border: none;
  border-radius: 14px;
  box-shadow: var(--modal-shadow);
}
.modal::backdrop {
  background: rgba(16, 32, 60, 0.45);
}
.modal-title {
  margin: 0 0 12px;
  font-size: 17px;
  font-weight: 700;
}
.modal-body {
  max-height: min(60vh, 520px);
  overflow-y: auto;
  font-size: 13.5px;
  line-height: 1.6;
}
.modal-body p {
  margin: 0 0 10px;
}
.modal-body textarea {
  min-height: 90px;
  font-family: var(--font);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

/* ---------- petits écrans ---------- */

@media (max-width: 900px) {
  :root {
    --sidebar-w: 200px;
  }
  .page-title {
    padding-left: 16px;
  }
}

/* ---------- sélecteur d'organisation ---------- */

/* Il remplace le bloc de marque dans la barre du haut : c'est du chrome, rendu
   par app.js. Aucune couleur nouvelle — les jetons du prototype suffisent. */
.org-block {
  position: relative;
  flex-shrink: 0;
}

/* Un <button> qui doit ressembler au bloc de marque : la règle globale des
   boutons lui poserait sinon un fond blanc et une bordure. */
button.org-trigger {
  background: none;
  border: none;
  border-radius: 0;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: #fff;
}
button.org-trigger:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
}

.org-chevron {
  margin-left: auto;
  font-size: 11px;
  opacity: 0.8;
}

/* `display: flex` l'emporterait sur le `display: none` que le navigateur donne
   à [hidden] : même spécificité, mais feuille d'auteur contre feuille du
   navigateur. Sans cette règle le popover s'affiche ouvert au chargement. */
.org-popover[hidden] {
  display: none;
}

.org-popover {
  position: absolute;
  top: calc(100% - 4px);
  left: 12px;
  z-index: 40;
  width: 300px;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--pop-shadow);
  padding: var(--space-2);
  color: var(--text);
}

.org-search {
  margin-bottom: var(--space-2);
}

.org-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.org-option {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13.5px;
}
.org-option:hover {
  background: var(--hover);
  text-decoration: none;
}
.org-option.current {
  background: var(--blue-soft);
  font-weight: 600;
}
.org-option-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.org-option-slug {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
  flex-shrink: 0;
}

.org-none {
  padding: 10px;
  color: var(--text-sec);
  font-size: 13px;
}

/* Les deux écrans de niveau instance, côte à côte au pied du sélecteur : le
   filet est porté par le pied, pas par chaque lien, sinon il en resterait deux. */
.org-footer {
  display: flex;
  gap: var(--space-4);
  margin-top: var(--space-2);
  border-top: 1px solid var(--border);
}

.org-manage {
  padding: 9px 10px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-sec);
}
.org-manage:hover {
  color: var(--blue);
  text-decoration: none;
}

/* ---------- rangée de compteurs ---------- */

/* Les trois chiffres au-dessus de la liste d'agents. Ils viennent de /v1/stats,
   jamais d'une agrégation inventée dans le navigateur. */
.counters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.counter-tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--panel-shadow);
  padding: 16px 20px;
}
.counter-value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text);
}
.counter-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}
.counter-hint {
  font-size: 11.5px;
  color: var(--text-sec);
}

/* ---------- réglages d'organisation ---------- */

/* Une valeur qu'on lit et qu'on ne modifie pas : le slug. Mise en monospace
   pour dire qu'elle est un identifiant, pas une phrase. */
.mono {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
}

/* La carte de suppression : bordée de la couleur d'alerte, pas remplie —
   c'est un avertissement, pas une erreur en cours. */
.card.danger-zone {
  border-color: var(--danger-line);
}
.card.danger-zone > h2 {
  color: var(--danger);
}

/* ---------- journal d'audit ---------- */

/* Une chronologie se lit en diagonale : l'heure, le canal, l'acteur, puis la
   phrase. Les quatre premières colonnes sont donc de largeur fixe, et seule la
   phrase respire — sinon deux lignes voisines ne s'alignent plus et l'œil doit
   relire chacune. */
.activity-day {
  font-size: 13px;
  color: var(--text-sec);
  margin: 0 0 var(--space-3);
}
.activity-list {
  display: flex;
  flex-direction: column;
}
.activity-entry {
  border-top: 1px solid var(--border);
  padding: var(--space-2) 0;
}
.activity-entry:first-child {
  border-top: none;
}

/* Les événements d'une même requête, dépliés : un filet à gauche, pas une
   boîte. Créer un agent, c'est trois lignes qui se lisent comme un seul geste —
   repliées, on n'en montre qu'une. */
.activity-group {
  margin: var(--space-2) 0 var(--space-2) calc(5ch + var(--space-3));
  padding-left: var(--space-3);
  border-left: 2px solid var(--border-strong);
}
.activity-group .activity-entry {
  border-top: none;
  padding: var(--space-1) 0;
}

.activity-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
}
.activity-time {
  flex: none;
  width: 5ch;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text-faint);
}
/* Assez large pour « claude-thomas · publish » et pour « console · 92.184.x.x » :
   c'est l'acteur qu'on cherche des yeux en premier, et une colonne qui le coupe
   oblige à survoler chaque ligne pour le lire. */
.activity-actor {
  flex: none;
  width: 26ch;
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  min-width: 0;
}
.activity-actor > span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.activity-actor .hint {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Les deux colonnes que seule la vue d'organisation ajoute : l'agent concerné et
   la cible. Largeurs fixes pour la même raison que le reste — une chronologie se
   lit en colonnes, pas ligne à ligne. */
.activity-agent {
  flex: none;
  width: 16ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.activity-target {
  flex: none;
  width: 16ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.activity-action {
  flex: 1 1 auto;
  min-width: 0;
}
.activity-summary {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-sec);
  font-size: 13px;
}
.activity-chevron {
  flex: none;
  width: 2.5ch;
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 0;
}
.activity-chevron:hover {
  color: var(--text);
}

/* Le déroulé : décalé sous la ligne, sur le fond doux des surfaces secondaires,
   pour qu'on voie tout de suite à quelle ligne il appartient. */
.activity-detail {
  margin: var(--space-2) 0 var(--space-3) calc(5ch + var(--space-3));
  padding: var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}

/* ===================== Agent tests ===================== */
/* Same tokens as everywhere else: no new colour is invented here. A grid of
   cells is read as colour before it is read as numbers, so the three state
   backgrounds already in the palette are exactly what it needs. */

.test-launch {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-3);
}

.test-launch-actions {
  justify-content: space-between;
  margin-top: var(--space-4);
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
}

.check {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

.check .count {
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.estimate {
  font-size: 13px;
  color: var(--text-sec);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 6px);
  padding: var(--space-2) var(--space-3);
}

.test-grid td,
.test-grid th {
  vertical-align: middle;
}

.test-grid th.persona {
  text-align: center;
  white-space: nowrap;
}

.test-grid td.scen {
  min-width: 260px;
}

.test-grid .theme {
  display: inline-block;
  margin-right: var(--space-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
}

.cell-attempts {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
}

.cell {
  display: inline-block;
  min-width: 46px;
  text-align: center;
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm, 6px);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 13px;
}

.cell-ok {
  background: var(--ok-bg);
  color: var(--ok);
}
.cell-warn {
  background: var(--warn-bg);
  color: var(--warn);
}
.cell-danger {
  background: var(--danger-bg);
  color: var(--danger);
}
/* An error is not a failure: it gets the warning ground, never the danger one. */
.cell-error {
  background: var(--warn-bg);
  color: var(--warn);
}
.cell-pending {
  background: var(--track);
  color: var(--text-faint);
}

.attempt {
  display: inline-block;
  min-width: 18px;
  text-align: center;
  font-size: 11px;
  border-radius: 4px;
  padding: 1px 3px;
  text-decoration: none;
  border: 1px solid var(--border);
  color: var(--text-sec);
}
.attempt.ok {
  border-color: var(--ok);
  color: var(--ok);
}
.attempt.danger {
  border-color: var(--danger-line);
  color: var(--danger);
}
.attempt.muted {
  color: var(--text-faint);
}

/* ---------- one simulation ---------- */

.sim-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(320px, 1fr);
  gap: var(--space-4);
  align-items: start;
}

@media (max-width: 1100px) {
  .sim-layout {
    grid-template-columns: 1fr;
  }
}

.transcript td.role {
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  white-space: nowrap;
}

/* The waiting phrase was heard but is not part of the answer, and it never
   entered the history: italics is the whole difference. */
.transcript .filler {
  margin: var(--space-1) 0 0;
  font-style: italic;
  font-size: 12px;
  color: var(--text-faint);
}

/* The turn a verdict cites, so the eye lands on it. */
.transcript tr.evidence {
  background: var(--blue-soft);
}

.verdict {
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}
.verdict:last-child {
  border-bottom: none;
}

.verdict-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.verdict-text {
  font-weight: 600;
  color: var(--text);
}

.verdict-reason {
  margin: var(--space-2) 0 0;
  font-size: 13px;
  color: var(--text-sec);
}

.verdict-evidence {
  margin: var(--space-1) 0 0;
  font-size: 12px;
}

.thumbs {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.thumb {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 6px);
  padding: 2px var(--space-2);
  cursor: pointer;
  font-size: 14px;
  line-height: 1.4;
}
.thumb.on {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.thumbs .who {
  font-size: 12px;
  color: var(--text-faint);
}

.mono-small {
  font-family: var(--mono, ui-monospace, monospace);
  font-size: 12px;
}

/* The run header borrows the stat row of the call view, inside a card section
   rather than as a card of its own: it needs its own top border and no
   horizontal padding of its own. */
.test-stats {
  margin: var(--space-4) calc(-1 * var(--space-5)) calc(-1 * var(--space-4));
  border-top: 1px solid var(--border);
}
.test-stats .stat:last-child {
  border-right: none;
}

.mono-small > div {
  overflow-wrap: anywhere;
}

/* A cell that is itself the link keeps the colour and loses the underline. */
a.cell {
  text-decoration: none;
}
a.cell:hover {
  outline: 1px solid var(--border-strong);
}

/* The one-line facts under a simulation header. Without a gap they read as one
   long word, which is exactly how the first screenshot came out. */
.meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin-top: var(--space-2);
  font-size: 13px;
  color: var(--text-sec);
}

/* ---------- issues ---------- */

.issue {
  display: grid;
  grid-template-columns: max-content 1fr max-content;
  gap: var(--space-3);
  align-items: start;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}
.issue:last-child {
  border-bottom: none;
}

/* Severity is the sort order made visible: what should never have been said
   comes first, and reads as such. */
.sev {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm, 6px);
  background: var(--track);
  color: var(--text-sec);
  white-space: nowrap;
}
.sev.compliance {
  background: var(--danger-bg);
  color: var(--danger);
}
.sev.task {
  background: var(--warn-bg);
  color: var(--warn);
}

.issue .crit {
  font-weight: 600;
  color: var(--text);
}
.issue .diag {
  margin-top: var(--space-1);
  font-size: 13px;
  color: var(--text-sec);
}
.issue .links {
  margin-top: var(--space-1);
  font-size: 12px;
  color: var(--text-faint);
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.issue .ratio {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}
.issue .ratio.danger {
  color: var(--danger);
}
.issue .ratio.warn {
  color: var(--warn);
}

/* ---------- comparing two runs ---------- */

.compare-select {
  font-size: 13px;
  max-width: 260px;
}

.compare-grid td.status {
  font-size: 12px;
  color: var(--text-faint);
  white-space: nowrap;
}
/* Only the two that matter get a ground: unchanged cells are the majority. */
.compare-grid tr.row-regressed {
  background: var(--danger-bg);
}
.compare-grid tr.row-improved {
  background: var(--ok-bg);
}

/* ---------- scenarios ---------- */

.sub-tabs {
  margin-bottom: var(--space-4);
}

.scenario,
.proposal {
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}
.scenario:last-child,
.proposal:last-child {
  border-bottom: none;
}

.scenario-head,
.proposal-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.scenario-actions {
  margin-left: auto;
}

.scenario-goal,
.proposal-goal {
  margin: var(--space-2) 0 0;
  font-size: 13px;
  color: var(--text-sec);
}

.proposal-criteria {
  margin: var(--space-2) 0 0;
  padding-left: var(--space-4);
  font-size: 13px;
  color: var(--text-sec);
}
.proposal-criteria li {
  margin-bottom: var(--space-1);
}

.proposal {
  display: flex;
  gap: var(--space-3);
  align-items: start;
  cursor: pointer;
}

.builtin-list {
  margin-top: var(--space-3);
}

/* Le prompt d'une persona est lu, pas parcouru : il garde ses retours à la
   ligne, et il est plafonné pour qu'une liste de personas reste une liste. */
.persona-prompt {
  margin: var(--space-2) 0 0;
  padding: var(--space-2) var(--space-3);
  max-height: 9.5em;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-sec);
  white-space: pre-wrap;
}

.trait-pills {
  margin-top: var(--space-2);
}

/* L'éditeur de persona n'a pas de grille de critères à loger : il tient dans la
   modale, contrairement à `.scenario-editor` et à ses 760 px imposés. */
.persona-editor {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.criterion-row {
  display: grid;
  grid-template-columns: 140px 130px 120px minmax(0, 1fr) 160px max-content;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
@media (max-width: 900px) {
  .criterion-row {
    grid-template-columns: 1fr;
  }
}

.scenario-editor {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: min(760px, 80vw);
}

/* The sub-line pulls itself up under a heading that is a direct child of the
   section. After a `.row` — a heading with buttons beside it — that pull lands
   on top of the heading instead. */
.row + .card-section-sub {
  margin-top: 0;
}

/* ---------- Demo page tab ----------
   Une colonne de réglages, un aperçu à droite. Le `.split` du projet fait déjà
   les deux colonnes ; ce qui suit ne pose que ce qui lui est propre. Aucune
   couleur nouvelle : tout vient des jetons de `:root`. */

.demo-col {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  min-width: 0;
}

/* Le lien doit se lire en entier d'un coup d'œil : c'est ce qu'on relit avant
   de l'envoyer à un prospect, et un champ qui le tronque au milieu du token
   fait douter qu'on ait copié le bon. */
.demo-link-row {
  flex-wrap: wrap;
}

.demo-url {
  flex: 1 1 22rem;
  min-width: 0;
  font-family: var(--mono);
  font-size: 0.8125rem;
  color: var(--text-sec);
  background: var(--surface-2);
}

.demo-line option:disabled {
  color: var(--text-faint);
}

/* L'aperçu est la vraie page, dans la vraie iframe que la CSP autorise
   (`frame-ancestors 'self'`). Format paysage : c'est ainsi qu'un prospect
   l'ouvrira le plus souvent, et c'est le seul cadrage où la composition
   centrée se juge. */
.demo-preview {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.demo-preview-card {
  position: sticky;
  top: var(--space-5);
}

@media (max-width: 1180px) {
  .demo-preview-card {
    position: static;
  }
}
