/* Cetas Lite — compléments au design system Cetas (uniquement les briques absentes de Cetas). */

[hidden] {
  display: none !important;
}

/* Titre de sidebar : "Cetas Lite" est plus long que "Cetas" → on ajuste. */
.sidebar-title {
  font-size: 1.2rem;
  justify-content: flex-start;
  flex-wrap: nowrap;
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.settings-head h2 {
  font-size: 1.05rem;
  font-weight: 600;
}

.settings-body {
  max-height: 62vh;
  overflow-y: auto;
  padding-right: 4px;
}

.settings-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.settings-section {
  margin-top: 22px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.settings-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.settings-section-head h3 {
  font-size: 0.95rem;
}

.settings-status {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.small-btn,
.primary-btn {
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 0.82rem;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.small-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.primary-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.primary-btn:hover {
  background: var(--accent-dark);
}

/* --- API et Modèles : editeur structure --- */
.fam-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  background: var(--bg-hover);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 14px;
}

.fam-tab {
  flex: 1 1 auto;
  padding: 7px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
}

.fam-tab:hover:not(.active) {
  color: var(--text);
}

.fam-tab.active {
  background: var(--bg-input);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.mode-block {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
  background: var(--bg-input);
}

.mode-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

.mode-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.mode-rule {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.pool-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 0;
}

.pool-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.pool-rank {
  font-size: 0.68rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.pool-name {
  flex: 1;
  min-width: 0;
  font-size: 0.8rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pool-provider {
  font-size: 0.68rem;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
}

.pool-price {
  font-size: 0.68rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.pool-actions {
  display: flex;
  gap: 1px;
}

.pool-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 5px;
  font-size: 0.85rem;
  line-height: 1;
}

.pool-btn:hover:not(:disabled) {
  color: var(--accent);
  background: var(--bg-hover);
}

.pool-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.pool-btn.danger:hover:not(:disabled) {
  color: var(--danger);
}

.pool-empty {
  font-size: 0.76rem;
  color: var(--text-secondary);
  padding: 6px 8px;
}

.pool-add {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.pool-model-select {
  flex: 1;
  min-width: 0;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--text);
  font-size: 0.8rem;
  font-family: inherit;
}

.mcp-panel,
.caps-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
}

.mcp-row,
.caps-row {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
}

.mcp-row {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.mcp-name,
.caps-name {
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

.caps-name {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.mcp-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}

.caps-check {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.caps-add {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

/* --- Inputs secondaires (thème, mode, effort) --- */
.theme-select,
.plus-menu-select,
.topbar select {
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 8px;
  padding: 5px 8px;
  color: var(--text);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
}

.plus-menu-select {
  flex: 1;
  min-width: 0;
}

.plus-menu-select + .plus-menu-select {
  margin-left: 6px;
}

.plus-menu-state {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 600;
}

/* --- Boutons icône génériques --- */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-secondary);
  padding: 4px 6px;
  cursor: pointer;
  line-height: 1;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  color: var(--accent);
  background: var(--accent-light);
}

/* --- Stop --- */
.stop-btn {
  background: var(--danger);
  border: 1px solid var(--danger);
  color: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.8rem;
  cursor: pointer;
}

/* --- Note système (compaction) --- */
.msg-system {
  max-width: 800px;
  margin: 6px auto;
  padding: 4px 14px;
  font-size: 0.76rem;
  font-style: italic;
  color: var(--text-secondary);
  text-align: center;
}

/* --- Pièces jointes --- */
.attach-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
  max-width: 800px;
  margin: 0 auto 6px;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 999px;
  padding: 3px 6px 3px 10px;
  font-size: 0.78rem;
  max-width: 260px;
}

.attach-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Carte de pièce jointe : icône/vignette, nom, aperçu 1 ligne, × */
.attach-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 84px;
  padding: 10px 6px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.attach-card:hover,
.attach-card:focus-visible {
  border-color: var(--accent);
  background: var(--bg-hover, var(--bg-input));
  outline: none;
}

.attach-card-thumb {
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.attach-card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
}

.attach-card-thumb.is-loading {
  background: var(--bg-hover, rgba(0, 0, 0, 0.05));
  border-radius: 6px;
  opacity: 0.7;
}

.attach-card-thumb.is-loading .attach-spinner {
  width: 14px;
  height: 14px;
  border-width: 2px;
}

.attach-card-icon {
  width: 34px;
  height: 34px;
  color: var(--text-secondary);
}

.attach-card-icon svg {
  width: 100%;
  height: 100%;
}

.attach-card-name {
  width: 100%;
  text-align: center;
  font-size: 0.72rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attach-card-snippet {
  width: 100%;
  text-align: center;
  font-size: 0.62rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0.85;
}

/* Bouton « Enregistrer » à côté de « Copier » sur les blocs de code */
.message-text pre {
  position: relative;
}

.code-save-btn {
  position: absolute;
  top: 6px;
  right: 62px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 0.72rem;
  font-family: inherit;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 1;
}

.message-text pre:hover .code-save-btn {
  opacity: 1;
}

.code-save-btn:hover {
  background: rgba(0, 0, 0, 0.7);
}

body.dark .code-save-btn {
  background: rgba(255, 255, 255, 0.2);
}

body.dark .code-save-btn:hover {
  background: rgba(255, 255, 255, 0.35);
}

/* Indicateur de lecture discret sur la carte (spinner + libellé) */
.attach-reading {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
  font-size: 0.62rem;
  color: var(--text-secondary);
  opacity: 0.85;
  max-width: 100%;
}

.attach-spinner {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border: 1.5px solid var(--border-input);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: attach-spin 0.8s linear infinite;
}

@keyframes attach-spin {
  to { transform: rotate(360deg); }
}

.msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.attach-card-inline {
  width: 96px;
}

.attach-card-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--border-input);
  background: var(--bg-input);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.attach-card-remove:hover {
  color: var(--danger);
  border-color: var(--danger);
}

/* Modal pièce jointe */
.attach-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.72);
}

.attach-modal-content {
  display: flex;
  flex-direction: column;
  width: 92vw;
  height: 90vh;
  max-width: 1400px;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 10px;
  overflow: hidden;
}

.attach-modal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-input);
}

.attach-modal-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.85rem;
}

.attach-modal-download,
.attach-modal-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 2px 6px;
  text-decoration: none;
}

.attach-modal-download:hover,
.attach-modal-close:hover {
  color: var(--text-primary);
}

.attach-modal-body {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.attach-modal-stage {
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.attach-modal-img {
  max-width: 100%;
  max-height: 100%;
  cursor: grab;
  transform-origin: center center;
  user-select: none;
}

.attach-modal-img.dragging {
  cursor: grabbing;
}

.attach-modal-pdf {
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
}

.attach-modal-pre {
  margin: 0;
  width: 100%;
  padding: 14px 16px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.attach-modal-empty {
  align-self: center;
  margin: auto;
  color: var(--text-secondary);
  font-size: 0.85rem;
  padding: 24px;
}

.attach-remove {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 4px;
}

.attach-remove:hover {
  color: var(--danger);
}

/* --- Blocs outils (riches) --- */
.msg-tool,
.stream-waiting {
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}

.msg-tool {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-msg-assistant);
  overflow: hidden;
}

.msg-tool summary {
  cursor: pointer;
  padding: 8px 12px;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

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

.tool-body {
  border-top: 1px solid var(--border);
}

.tool-body pre,
.tool-result {
  margin: 0;
  padding: 10px 12px;
  font-size: 0.78rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.tool-result a {
  color: var(--link);
  text-decoration: underline;
}

/* --- Rendu dédié rag_search / rag_read : compact et structuré ---
   Pas de gros bloc monospacé brut : un <details> avec un item par
   passage (titre, chemin, extrait) ou un aperçu borné pour la lecture. */
.rag-result {
  margin: 6px 0;
}
.rag-summary {
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  list-style: none;
}
.rag-summary::-webkit-details-marker {
  display: none;
}
.rag-summary::before {
  content: "▸ ";
  color: var(--muted, #888);
}
.rag-result[open] > .rag-summary::before {
  content: "▾ ";
}
.rag-hit-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}
.rag-hit {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--surface, transparent);
}
.rag-hit-head {
  font-size: 0.82rem;
}
.rag-hit-ref {
  font-weight: 700;
  color: var(--link);
}
.rag-hit-title {
  font-weight: 600;
}
.rag-hit-path {
  font-size: 0.72rem;
  color: var(--muted, #888);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-wrap: anywhere;
}
.rag-hit-snippet {
  font-size: 0.78rem;
  margin-top: 4px;
  color: var(--text);
}
.rag-read-body {
  margin-top: 6px;
}

/* --- Pastilles d'outils en thème sombre : fond et texte explicites ---
   Les variables suffisent en théorie, mais en pratique des pastilles
   blanches ont été observées en mode sombre : ces règles plus spécifiques
   garantissent un rendu sombre quoi qu'il arrive. */
body.dark .msg-tool {
  background: #2b2b2b;
  border-color: #3d3d3d;
}

body.dark .msg-tool summary {
  color: #d2d2d2;
}

body.dark .msg-tool .tool-name {
  color: #f0f0f0;
}

body.dark .msg-tool .tool-hint {
  color: #a9a9a9;
}

body.dark .msg-tool .tool-result {
  color: #d8d8d8;
}

body.dark.hard-dark .msg-tool {
  background: #0b0b0b;
  border-color: #242424;
}

/* --- Lignes d'outils façon Harness : une ligne compacte, pas de pastille ---
   "✨ Tool call · Read · chemin" — le détail (args/résultat) reste
   accessible en dépliant la ligne. */
.msg-tool.harness-tool,
body.dark .msg-tool.harness-tool,
body.dark.hard-dark .msg-tool.harness-tool {
  background: transparent;
  border: none;
  border-radius: 0;
  margin: 2px auto;
  overflow: visible;
}

.msg-tool.harness-tool > summary {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 3px 8px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  cursor: pointer;
  list-style: none;
  border-radius: 6px;
  white-space: nowrap;
  overflow: hidden;
}

.msg-tool.harness-tool > summary::-webkit-details-marker {
  display: none;
}

.msg-tool.harness-tool > summary:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.msg-tool.harness-tool .tool-spark {
  font-size: 0.72rem;
  flex: 0 0 auto;
}

.msg-tool.harness-tool.running .tool-spark {
  animation: harness-pulse 1.1s ease-in-out infinite;
}

@keyframes harness-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

.msg-tool.harness-tool .tool-kind {
  flex: 0 0 auto;
}

.msg-tool.harness-tool .tool-sep {
  opacity: 0.45;
  flex: 0 0 auto;
}

.msg-tool.harness-tool .tool-name {
  flex: 0 0 auto;
}

.msg-tool.harness-tool .tool-hint {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.msg-tool.harness-tool .tool-body {
  border-top: none;
  border-left: 2px solid var(--border);
  margin: 2px 0 8px 20px;
  border-radius: 0;
}

/* Libellé d'attente : anneau de points mini inline + message rotatif +
   compteur réel ("◌ Consultation des archives… 5s"). */
.wait-label {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-top: 0;
  font-size: 0.78rem;
  color: var(--text-secondary);
  text-align: left;
}

.tool-diff {
  display: flex;
  flex-direction: column;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  border-top: 1px solid var(--border);
}

.diff-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 6px 10px;
  font-size: 0.75rem;
  background: rgba(0, 0, 0, 0.03);
}

.diff-file {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.diff-stats {
  flex-shrink: 0;
  color: var(--text-secondary);
  font-weight: 600;
}

.diff-body {
  max-height: 340px;
  overflow-y: auto;
}

.diff-row {
  display: flex;
  align-items: baseline;
  min-width: 0;
}

.diff-gutter {
  width: 3em;
  flex-shrink: 0;
  text-align: right;
  padding-right: 8px;
  color: var(--text-secondary);
  user-select: none;
  opacity: 0.7;
}

.diff-sign {
  width: 1.4em;
  flex-shrink: 0;
  user-select: none;
  font-weight: 700;
}

.diff-code {
  flex: 1;
  min-width: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding-right: 8px;
}

.diff-add {
  background: rgba(34, 197, 94, 0.12);
}

.diff-add .diff-code,
.diff-add .diff-sign {
  color: #15803d;
}

.diff-del {
  background: rgba(220, 38, 38, 0.1);
}

.diff-del .diff-code,
.diff-del .diff-sign {
  color: #b91c1c;
}

.diff-ctx {
  color: var(--text-secondary);
}

.chat-todo-list {
  margin: 6px 0;
  padding-left: 18px;
  font-size: 0.82rem;
}

.chat-todo-item.todo-completed {
  color: var(--text-secondary);
  text-decoration: line-through;
}

/* --- Cartes d'approbation (outils sensibles / plan) --- */
.msg-approval {
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  border: 1px solid var(--warning-border, #b45309);
  border-left: 4px solid var(--warning-border, #b45309);
  border-radius: 10px;
  background: var(--bg-msg-assistant);
  padding: 10px 12px;
}

.approval-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}

.approval-title {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text);
}

.approval-hint {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  margin-bottom: 6px;
  overflow-wrap: anywhere;
}

.approval-plan {
  margin: 0 0 8px 0;
  padding: 8px 10px;
  font-size: 0.8rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 6px;
  max-height: 260px;
  overflow-y: auto;
}

.approval-args summary {
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.approval-args pre {
  margin: 6px 0;
  font-size: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.approval-status {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin: 8px 0;
}

.approval-status.approved {
  color: #15803d;
  font-weight: 600;
}

.approval-status.denied {
  color: #b91c1c;
  font-weight: 600;
}

.approval-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.approval-actions button {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.8rem;
  cursor: pointer;
  background: var(--bg);
  color: var(--text);
}

.approval-actions button:disabled {
  opacity: 0.45;
  cursor: default;
}

.approval-actions .btn-approve {
  background: #15803d;
  border-color: #15803d;
  color: #fff;
  font-weight: 600;
}

.approval-actions .btn-deny {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #fff;
}

/* --- Sidebar : en-tête de liste --- */
.conv-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 6px 0;
}

.conv-head-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

/* --- Scrim mobile --- */
.sidebar-scrim {
  display: none;
}

.conv-empty {
  font-size: 0.78rem;
  color: var(--text-secondary);
  padding: 8px 10px;
}

@media (max-width: 768px) {
  .sidebar-scrim.show {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgba(0, 0, 0, 0.45);
  }
}

/* ============================================================
   Loader rond "Marex" pendant la generation — repris trait pour trait
   du CETAS complet. Couleur = var(--accent) : suit le theme et la
   palette selectionnee.
   ============================================================ */
.marex-loader {
  position: relative;
  width: 72px;
  height: 72px;
  display: block;
  margin: 4px 0 10px;
  color: var(--accent, #6c63ff);
}
.marex-loader .loader {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 200px;
  height: 200px;
  margin: -100px 0 0 -100px;
  border-radius: 50%;
  overflow: hidden;
  transform: scale(0.36);
  background: radial-gradient(circle, color-mix(in srgb, currentColor 5%, transparent) 30%, transparent 70%);
}
.marex-loader .loader::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 4px solid transparent;
  border-top-color: color-mix(in srgb, currentColor 60%, transparent);
  animation: marex-loader-spin 2s linear infinite;
}
.marex-loader .loader::after {
  content: "";
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  background: conic-gradient(from 90deg, color-mix(in srgb, currentColor 20%, transparent), transparent);
  filter: blur(2px);
  animation: marex-loader-spin-reverse 1.5s linear infinite;
}
.marex-loader .loader__inner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 30px;
  height: 30px;
  background: currentColor;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 15px color-mix(in srgb, currentColor 60%, transparent);
  animation: marex-loader-pulse 1s ease-in-out infinite;
}
.marex-loader .loader__orbit {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  animation: marex-loader-orbit 3s linear infinite;
}
.marex-loader .loader__dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  background: color-mix(in srgb, currentColor 80%, transparent);
  border-radius: 50%;
}
.marex-loader .loader__dot:nth-child(1) { transform: rotate(0deg) translate(60px); }
.marex-loader .loader__dot:nth-child(2) { transform: rotate(90deg) translate(60px); }
.marex-loader .loader__dot:nth-child(3) { transform: rotate(180deg) translate(60px); }
.marex-loader .loader__dot:nth-child(4) { transform: rotate(270deg) translate(60px); }
/* Variante mini du loader (indicateur d'attente inline, ~14 px) : meme
   animation d'anneau de points, geometrie adaptee a la petite taille. */
.marex-loader--mini {
  width: 14px;
  height: 14px;
  margin: 0 6px 0 0;
  display: inline-block;
  vertical-align: -2px;
}
.marex-loader--mini .loader {
  position: static;
  width: 14px;
  height: 14px;
  margin: 0;
  border: none;
  background: none;
  overflow: visible;
  transform: none;
}
.marex-loader--mini .loader::before,
.marex-loader--mini .loader::after { content: none; }
.marex-loader--mini .loader__inner {
  width: 3px;
  height: 3px;
  box-shadow: none;
}
.marex-loader--mini .loader__orbit { animation-duration: 1.6s; }
.marex-loader--mini .loader__dot { width: 2px; height: 2px; }
.marex-loader--mini .loader__dot:nth-child(1) { transform: rotate(0deg) translate(5px); }
.marex-loader--mini .loader__dot:nth-child(2) { transform: rotate(90deg) translate(5px); }
.marex-loader--mini .loader__dot:nth-child(3) { transform: rotate(180deg) translate(5px); }
.marex-loader--mini .loader__dot:nth-child(4) { transform: rotate(270deg) translate(5px); }
@media (prefers-reduced-motion: reduce) {
  .marex-loader--mini .loader__orbit { animation: none; }
}

@keyframes marex-loader-spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes marex-loader-spin-reverse { 0% { transform: rotate(0deg); } 100% { transform: rotate(-360deg); } }
@keyframes marex-loader-pulse { 0%, 100% { transform: translate(-50%, -50%) scale(1); } 50% { transform: translate(-50%, -50%) scale(1.2); } }
@keyframes marex-loader-orbit { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Stats live sous le loader pendant la generation (monospace). */
.gen-stats-live {
  display: block;
  font-size: 11px;
  color: var(--text-secondary, #8b949e);
  padding: 2px 4px 0;
  font-family: monospace;
  opacity: 0.75;
}

/* ============================================================
   Panneau Raisonnement (slide-out droit)
   ============================================================ */
.reason-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 320px;
  max-width: 85vw;
  height: 100dvh;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateX(102%);
  transition: transform 0.25s ease;
  z-index: 120;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12);
}
.reason-panel.open {
  transform: translateX(0);
}
.reason-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.reason-panel-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.reason-spinner {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent, #2563eb);
  animation: reason-spin 0.8s linear infinite;
}
@keyframes reason-spin {
  to { transform: rotate(360deg); }
}
.reason-panel-close {
  background: none;
  border: none;
  color: var(--text-secondary, #8b949e);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}
.reason-panel-close:hover {
  background: var(--bg-hover, rgba(127, 127, 127, 0.15));
  color: var(--text);
}
.reason-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--text-secondary, #8b949e);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.reason-panel-empty {
  color: var(--text-muted, #6b7280);
  font-style: italic;
  font-size: 0.8rem;
}

/* Bloc informations de la requete (cf. capture : Modèle, Temps de
   génération, Input, Output - t/s, Contexte, Coût). */
.reason-info {
  white-space: normal;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  line-height: 1.75;
}
.ri-row {
  display: flex;
  gap: 6px;
  align-items: baseline;
}
.ri-k {
  color: var(--text-secondary, #8b949e);
  flex-shrink: 0;
}
.ri-accent {
  color: var(--accent, #2563eb);
  font-weight: 600;
}
/* En-tête "REASONING" au-dessus du texte de raisonnement. */
.reason-sec {
  white-space: normal;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-secondary, #8b949e);
  margin: 2px 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
/* Bouton de traduction du raisonnement (DeepThink Global). */
.reason-translate-btn {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--border, #d0d7de);
  background: transparent;
  color: var(--text-secondary, #8b949e);
  cursor: pointer;
  font-family: inherit;
}
.reason-translate-btn:hover:not(:disabled) {
  color: var(--accent, #2563eb);
  border-color: var(--accent, #2563eb);
}
.reason-translate-btn:disabled {
  opacity: 0.55;
  cursor: default;
}
.reason-translate-btn.on {
  color: var(--accent, #2563eb);
  border-color: var(--accent, #2563eb);
}
/* Bloc de traduction DeepThink : affiché SOUS le raisonnement original,
   jamais en remplacement. */
.reason-translation {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--border, #d0d7de);
}
.reason-trans-sec {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent, #2563eb);
  margin-bottom: 6px;
}
.reason-translation-text {
  white-space: pre-wrap;
}
.reason-translation-error .reason-translation-text {
  color: var(--text-secondary, #8b949e);
  font-style: italic;
}
/* DeepThink Global : titres de lignes de réglages. */
.dt-row-title {
  font-weight: 600;
  font-size: 0.85rem;
  margin: 14px 0 6px;
  color: var(--text, inherit);
}
.dt-row-title:first-child {
  margin-top: 2px;
}
.reason-text {
  white-space: pre-wrap;
}
/* Historique des tours : un bloc par tour, les suivants s'ajoutent EN
   DESSOUS des précédents (jamais de remplacement). */
.reason-turn + .reason-turn {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border, #d0d7de);
}
/* Surlignage bref quand le bouton "Raisonnement" fait défiler vers un tour. */
.reason-turn.reason-flash {
  animation: reason-flash 1.6s ease-out;
}
@keyframes reason-flash {
  0% {
    background: color-mix(in srgb, var(--accent, #2563eb) 14%, transparent);
    border-radius: 6px;
  }
  100% {
    background: transparent;
  }
}
/* Vue Agents : le texte de raisonnement du panneau latéral n'a aucune
   couleur définie et hérite d'un contexte sombre -> invisible sur fond
   noir. On force la couleur claire du thème Marex (toujours dark).
   (marex-agents.css est généré : ne pas y toucher.) */
#marex-view .side-panel-body .reason-text {
  color: var(--text-primary, #f2f2f4);
  font-size: 12.5px;
  line-height: 1.6;
}

/* Bouton "Raisonnement" au-dessus de chaque requete ayant produit du
   raisonnement : reconsulte le panneau (remplace le bouton flottant). */
/* En-tete "Raisonnement" en tete de la bulle assistant (ref CETAS complet) */
.reason-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin: 0 0 8px 0;
  padding: 2px 2px 8px 2px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--accent, #2563eb);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}
.reason-btn[hidden] {
  display: none;
}
.reason-btn:hover {
  filter: brightness(1.2);
}

/* ============================================================
   Pied de message : "Modèle · temps · tokens (tok/s)"
   ============================================================ */
.turn-stats {
  font-size: 0.72rem;
  color: var(--text-muted, #6b7280);
  margin-top: 6px;
  padding-left: 2px;
  user-select: text;
}
.message-wrapper.assistant-wrapper .turn-stats {
  color: var(--text-secondary, #8b949e);
}

/* ============================================================
   Ligne de tokens au-dessus du champ de saisie
   ============================================================ */
.turn-token-line {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--text-secondary, #8b949e);
  padding: 0 10px 6px;
}
.turn-token-sep {
  opacity: 0.5;
}

/* ============================================================
   Métriques de la sidebar
   ============================================================ */
.sb-metrics {
  margin: 10px 0 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}
.sb-metrics-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted, #6b7280);
  margin-bottom: 8px;
}
.sb-metric {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.72rem;
}
.sb-metric:last-child {
  margin-bottom: 0;
}
.sb-metric-label {
  width: 44px;
  flex-shrink: 0;
  color: var(--text-secondary, #8b949e);
}
.sb-metric-bar {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-hover, rgba(127, 127, 127, 0.18));
  overflow: hidden;
}
.sb-metric-fill {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: var(--success, #22c55e);
  transition: width 0.6s ease, background 0.6s ease;
}
.sb-metric-val {
  min-width: 64px;
  text-align: right;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.sb-metric-net .sb-metric-val {
  min-width: 0;
  flex: 1;
  text-align: right;
}

/* ---- Défilement ThreadView (façon référence) ---- */
.thread-to-bottom {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border, #2a2f3a);
  background: var(--surface-2, #1a1f2b);
  color: var(--text, #e6e9f0);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  opacity: 0.92;
  transition: transform 0.15s ease, opacity 0.15s ease, border-color 0.15s ease;
}
.thread-to-bottom:hover {
  transform: translateY(-2px);
  opacity: 1;
  border-color: var(--accent, #4f8cff);
}
.thread-to-bottom.has-new {
  border-color: var(--accent, #4f8cff);
  animation: thread-to-bottom-pulse 1.6s ease-in-out infinite;
}
@keyframes thread-to-bottom-pulse {
  0%, 100% { box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35); }
  50% { box-shadow: 0 6px 22px rgba(79, 140, 255, 0.55); }
}

/* Sentinelle d'élagage : début de conversation retiré du DOM (historique serveur intact). */
.history-cut {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim, #8b93a5);
  padding: 10px 16px;
  margin: 8px auto;
  max-width: 560px;
  border-top: 1px dashed var(--border, #2a2f3a);
  border-bottom: 1px dashed var(--border, #2a2f3a);
}

/* ---- Recherche web : indicateur + panneau Sources ---- */
.search-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  color: var(--text-secondary, #9aa3b2);
  font-size: 0.85rem;
}
.search-spinner {
  width: 16px;
  height: 16px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--border-light, #2a2f3a);
  border-top-color: var(--accent, #4aa8ff);
  animation: search-spin 0.7s linear infinite;
}
@keyframes search-spin {
  to { transform: rotate(360deg); }
}
.citations-block {
  margin: 12px 0 4px;
  padding-top: 10px;
  border-top: 1px solid var(--border-light, #2a2f3a);
}
.citations-title {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary, #9aa3b2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}
.citations-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
@media (max-width: 900px) {
  .citations-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.citation-hidden { display: none; }
.citation-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  height: 100%;
  padding: 10px 12px;
  background: var(--bg-hover, rgba(255,255,255,0.04));
  border: 1px solid var(--border-light, #2a2f3a);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text, #e8ecf1);
  transition: border-color 0.15s, transform 0.1s;
}
.citation-card:hover {
  border-color: var(--accent, #4aa8ff);
  transform: translateY(-1px);
}
.citation-card-head {
  display: flex;
  align-items: center;
  gap: 6px;
}
.citation-favicon {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  background: hsl(var(--citation-hue, 210) 42% 44%);
  /* Image de favicon (URL blob) appliquee par loadFavicon() : elle couvre la
     pastille a initiale. Sans image, la pastille reste telle quelle. */
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  user-select: none;
}
.citation-domain {
  font-size: 0.72rem;
  color: var(--text-secondary, #9aa3b2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.citation-num {
  margin-left: auto;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-secondary, #9aa3b2);
  flex: none;
}
.citation-card-title {
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.citation-more {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 58px;
  padding: 10px 12px;
  background: var(--bg-hover, rgba(255,255,255,0.04));
  border: 1px dashed var(--border-light, #2a2f3a);
  border-radius: 10px;
  color: var(--text-secondary, #9aa3b2);
  font-size: 0.8rem;
  cursor: pointer;
}
.citation-more:hover {
  color: var(--text, #e8ecf1);
  border-color: var(--accent, #4aa8ff);
}

/* --- Réglages : bouton Recharger (plugins) ------------------------------ */
.audio-setting-btn {
  background: var(--bg-input, #1a2230);
  border: 1px solid var(--border-input, #2c3a4f);
  border-radius: 6px;
  color: var(--text, #e8ecf1);
  font-size: 0.8rem;
  padding: 5px 12px;
  cursor: pointer;
}
.audio-setting-btn:hover {
  border-color: var(--accent, #4aa8ff);
  color: var(--accent, #4aa8ff);
}
.audio-setting-btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.rp-mcp-status {
  font-size: 0.78rem;
  color: var(--text-dim, #9aa7ba);
  text-align: right;
  flex: 1;
  min-width: 0;
}

/* --- Globe / Thinking du composer (mode Agent : thinking verrouillé) --- */
.input-icon-btn.locked {
  cursor: default;
}
.input-icon-btn.locked:hover {
  color: inherit;
}

/* --- Éditeur MAREX.md (Réglages) --- */
.marex-editor-block {
  padding: 4px 18px 14px;
}
.marex-textarea {
  width: 100%;
  resize: vertical;
  min-height: 140px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border, #d9dee6);
  background: var(--input-bg, #fff);
  color: var(--text-primary, #1c2333);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.5;
}
.marex-textarea:focus {
  outline: none;
  border-color: var(--accent, #3B87CE);
}
.marex-editor-block .rp-mcp-status {
  display: block;
  margin-top: 6px;
  text-align: left;
}

/* ============================================================
   Typographie du chat resserree facon Claude — vue principale
   uniquement (la vue Agents reste identique a Marexcode).
   Le moteur markdown enveloppe les items de liste "laches" dans
   un <p> : sans la regle li > p, la marge du paragraphe s'ajoute
   a celle de l'item et les puces s'ecartent trop.
   ============================================================ */
#chat-container .message-text {
  line-height: 1.55;
}
#chat-container .message-text p {
  margin: 0 0 0.45em 0;
}
#chat-container .message-text li > p {
  margin: 0;
}
#chat-container .message-text li {
  margin: 0.22em 0;
}
#chat-container .message-text ul,
#chat-container .message-text ol {
  margin: 0.35em 0;
}
#chat-container .message-text h1,
#chat-container .message-text h2,
#chat-container .message-text h3 {
  margin: 0.5em 0 0.25em 0;
}

/* ============================================================
   Blocs de code du chat : fond integre au design (plus de gris
   flottant) + bordure fine. Le <code> interne reste transparent
   pour laisser parler le fond du <pre>. Vue principale
   uniquement (la vue Agents reste identique a Marexcode).
   ============================================================ */
#chat-container .message-text pre {
  background: var(--bg-sidebar, #fafafa);
  border: 1px solid var(--border, #eaeaea);
}
#chat-container .message-text pre code {
  background: transparent;
}

/* ============================================================
   Flèche "retour en bas" façon DeepSeek.
   En mode clair, le fond sombre (--surface-2 absent) sortait tout
   noir : pastille blanche désormais.
   ============================================================ */
.thread-to-bottom {
  width: 32px;
  height: 32px;
  background: #ffffff;
  border: 1px solid rgba(15, 23, 42, 0.10);
  color: #374151;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
}
body.dark .thread-to-bottom {
  background: var(--surface-2, #1a1f2b);
  border-color: var(--border, #2a2f3a);
  color: var(--text, #e6e9f0);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
/* Vue principale : flèche centrée juste au-dessus du composer
   (la vue Agents garde sa position d'origine). */
.input-area > .thread-to-bottom {
  position: absolute;
  left: 50%;
  right: auto;
  bottom: calc(100% + 10px);
  transform: translateX(-50%);
}
.input-area > .thread-to-bottom:hover {
  transform: translateX(-50%) translateY(-2px);
}

/* ============================================================
   Panneau flottant "Requêtes" façon DeepSeek : sommaire des requêtes
   sur le côté du chat. Fond transparent : au repos on ne voit que des
   traits ; le texte de la requête apparaît au survol, juste à côté
   du trait. Clic = défilement vers le message.
   Vue principale uniquement.
   ============================================================ */
.requests-panel {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 25;
  max-height: 46vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 6px 2px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
}
.requests-panel[hidden] {
  display: none;
}
.request-item {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  width: auto;
  background: none;
  border: none;
  padding: 5px 2px;
  font-family: inherit;
  cursor: pointer;
}
.request-item-trait {
  flex: none;
  width: 22px;
  height: 3px;
  border-radius: 2px;
  background: var(--text-tertiary, #c3c9d2);
  transition: background 0.15s ease;
}
/* Le texte est replié par défaut : seul le trait est visible. */
.request-item-label {
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 0.8rem;
  color: var(--text-secondary, #6b7280);
  transition: max-width 0.18s ease, opacity 0.15s ease, margin 0.18s ease;
}
/* Au survol : le texte se déploie juste à côté du trait. */
.request-item:hover .request-item-label {
  max-width: 200px;
  opacity: 1;
  margin-right: 6px;
  color: var(--accent, #2563eb);
}
.request-item:hover .request-item-trait {
  background: var(--accent, #2563eb);
}
/* Ligne active (requête la plus proche du haut) : trait accentué. */
.request-item.active .request-item-trait {
  background: var(--accent, #2563eb);
}
@media (max-width: 1100px) {
  .requests-panel {
    display: none;
  }
}

/* ---- Historique façon DeepSeek : sections par date ---- */
.conv-section-header {
  padding: 10px 10px 4px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-secondary, #9aa0aa);
  text-transform: none;
  user-select: none;
}

/* --- Sessions : surlignage de la session affichée --- */
.conv-item.active {
  background: var(--bg-hover, rgba(127, 140, 160, 0.14));
  border-left: 2px solid var(--accent);
}

/* ---------- Hero façon Gemini (chat vide) ---------- */
/* Le placeholder hérite d'une opacité 0.5 : le hero doit être opaque. */
.empty-chat-placeholder:has(.chat-hero) {
  opacity: 1;
  gap: 0;
}
.chat-hero {
  position: relative;
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 24px;
  box-sizing: border-box;
  overflow: hidden;
}
/* Halo d'ambiance derrière le composer (mode clair : discret). */
.hero-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(620px 340px at 50% 46%, rgba(59, 130, 246, 0.13), transparent 70%),
    radial-gradient(440px 260px at 42% 40%, rgba(168, 85, 247, 0.09), transparent 70%);
}
/* Mode sombre : halo bleu/violet plus présent, comme la référence. */
body.dark .hero-glow {
  background:
    radial-gradient(660px 370px at 50% 46%, rgba(59, 130, 246, 0.20), transparent 70%),
    radial-gradient(480px 300px at 42% 40%, rgba(139, 92, 246, 0.14), transparent 70%);
}
.hero-title {
  position: relative;
  z-index: 1;
  margin: 0 0 36px;
  text-align: center;
  font-size: clamp(2rem, 4.5vw, 3.2rem);
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text);
}
body.dark .hero-title {
  color: #d7d7d7;
  font-weight: 400;
}
.hero-composer-slot {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 768px;
}
/* Le vrai composer, remonté dans le hero : carte flottante arrondie. */
.hero-composer-slot .input-area {
  background: transparent;
  padding: 0;
}
.hero-composer-slot .input-row {
  max-width: none;
}
.hero-composer-slot .input-wrapper {
  border-radius: 28px;
  padding: 10px 14px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.10);
}
body.dark .hero-composer-slot .input-wrapper {
  box-shadow: 0 14px 48px rgba(0, 0, 0, 0.50);
}
/* En mode hero, la barre de tokens du bas n'a rien à afficher. */
body.hero-mode .token-bar {
  display: none;
}
/* L'alerte modèle remonte avec le composer : pleine largeur du slot. */
.hero-composer-slot .model-alert {
  margin: 0 0 12px;
}
/* L'indicateur de sélection (famille · mode) sous le composer du hero. */
.hero-composer-slot .input-hint {
  max-width: none;
  padding-top: 10px;
}

/* --- Thème sombre : tout le texte des conversations en blanc ---
   Verrou anti "texte noir sur fond noir" : ces règles ciblées par ID
   priment sur tout le reste. La coloration syntaxique (spans hljs dans
   pre code) est préservée : les spans ne sont pas ciblés. */
body.dark #marex-view .message-text,
body.dark #chat-container .message-text,
body.dark #marex-view .message-text p,
body.dark #chat-container .message-text p,
body.dark #marex-view .message-text li,
body.dark #chat-container .message-text li,
body.dark #marex-view .message-text div,
body.dark #chat-container .message-text div,
body.dark #marex-view .message-text strong,
body.dark #chat-container .message-text strong,
body.dark #marex-view .message-text em,
body.dark #chat-container .message-text em,
body.dark #marex-view .message-text b,
body.dark #chat-container .message-text b,
body.dark #marex-view .message-text i,
body.dark #chat-container .message-text i,
body.dark #marex-view .message-text h1,
body.dark #chat-container .message-text h1,
body.dark #marex-view .message-text h2,
body.dark #chat-container .message-text h2,
body.dark #marex-view .message-text h3,
body.dark #chat-container .message-text h3,
body.dark #marex-view .message-text h4,
body.dark #chat-container .message-text h4,
body.dark #marex-view .message-text blockquote,
body.dark #chat-container .message-text blockquote,
body.dark #marex-view .message-text td,
body.dark #chat-container .message-text td,
body.dark #marex-view .message-text th,
body.dark #chat-container .message-text th,
body.dark #marex-view .message-text pre,
body.dark #chat-container .message-text pre,
body.dark #marex-view .message-text code,
body.dark #chat-container .message-text code,
body.dark #marex-view .message-text a,
body.dark #chat-container .message-text a {
  color: #f2f2f4;
}

body.dark #marex-view .message-text a,
body.dark #chat-container .message-text a {
  text-decoration: underline;
}

/* Lignes d'outils, résultats, stats : blanc lisible aussi. */
body.dark #marex-view .msg-tool.harness-tool > summary,
body.dark #chat-container .msg-tool.harness-tool > summary,
body.dark #marex-view .msg-tool.harness-tool .tool-kind,
body.dark #chat-container .msg-tool.harness-tool .tool-kind,
body.dark #marex-view .msg-tool.harness-tool .tool-name,
body.dark #chat-container .msg-tool.harness-tool .tool-name,
body.dark #marex-view .msg-tool.harness-tool .tool-hint,
body.dark #chat-container .msg-tool.harness-tool .tool-hint,
body.dark #marex-view .msg-tool.harness-tool .tool-sep,
body.dark #chat-container .msg-tool.harness-tool .tool-sep,
body.dark #marex-view .tool-result,
body.dark #chat-container .tool-result,
body.dark #marex-view .search-status-text,
body.dark #chat-container .search-status-text {
  color: #f2f2f4;
}

body.dark #marex-view .turn-stats,
body.dark #chat-container .turn-stats,
body.dark #marex-view .wait-label,
body.dark #chat-container .wait-label,
body.dark #marex-view .gen-stats-live,
body.dark #chat-container .gen-stats-live {
  color: #dcdcdf;
}

/* === Thème sombre : blanc intégral — sidebar + composer + footer (polices uniquement) ===
   Ces libellés sont gris par design (texte secondaire) ; en thème sombre
   ils passent en blanc explicite, sélecteurs scopés par ID donc prioritaires.
   Aucun fond n'est modifié, uniquement la couleur de police. */
body.dark #marex-view .mx-search-input,
body.dark #marex-view .mx-search-input::placeholder,
body.dark #marex-view .sb-group-label,
body.dark #marex-view .sb-project-header,
body.dark #marex-view .sb-project-header span,
body.dark #marex-view .sb-active-sub,
body.dark #marex-view .sb-tree-empty,
body.dark #marex-view .sb-mini-label,
body.dark #marex-view .sb-new-project-btn,
body.dark #marex-view .sb-hist-item,
body.dark #marex-view .sb-hist-item .sb-hist-label,
body.dark #marex-view .mx-pbar-name,
body.dark #marex-view .mx-pbar-sub,
body.dark #marex-view #mx-input,
body.dark #marex-view #mx-input::placeholder,
body.dark #marex-view #mx-token-counter,
body.dark #marex-view .mx-mode-hint,
body.dark #marex-view #mx-label-effort,
body.dark #marex-view #mx-label-perm,
body.dark #marex-view #mx-label-model,
body.dark #marex-view #mx-label-project {
  color: #f2f2f4;
}

/* Les placeholders restent à pleine opacité (sinon le navigateur les atténue). */
body.dark #marex-view .mx-search-input::placeholder,
body.dark #marex-view #mx-input::placeholder {
  opacity: 1;
}

/* ============================================================
   Vue Agents : variables applicatives réalignées
   ------------------------------------------------------------
   #marex-view est TOUJOURS sombre (marex-agents.css : fond #000) et ne
   redéfinissait que --text-primary/secondary/tertiary. Or les composants du
   fil (.tool-result, .turn-stats, .message-text, .msg-tool…) utilisent les
   variables du thème APPLICATIF (--text, --text-muted, --border, --link…).
   En thème clair, ces composants héritaient donc de valeurs sombres →
   texte noir sur fond noir (résultat d'outil illisible, « cat » noir).
   On réaligne ces variables DANS la portée #marex-view : la vue Agents est
   sombre quelle que soit la préférence de l'application.
   ============================================================ */
#marex-view {
  --bg: #000000;
  --bg-app: #000000;
  --bg-sidebar: #15161b;
  --bg-tertiary: #15161b;
  --bg-hover: #1f2024;
  --bg-active: #25262b;
  --bg-input: #1f2024;
  --bg-input-btn: #1f2024;
  --border: #25262b;
  --border-color: #25262b;
  --border-light: #25262b;
  --text: #f2f2f4;
  --text-primary: #f2f2f4;
  --text-secondary: #9a9ba3;
  --text-tertiary: #6b6d76;
  --text-muted: #9a9ba3;
  --link: #5ec8f2;
  --accent: #5ec8f2;
  --accent-light: rgba(94, 200, 242, 0.12);
  /* Indispensable : « color » est INHÉRITÉE (valeur calculée). Redéfinir
     --text dans la portée ne suffit pas — body a déjà calculé sa couleur.
     On force donc la couleur du conteneur, que tout le fil hérite. */
  color: var(--text);
}

/* ============================================================
   Fil agent façon OpenCode : thought, thinking, expand, diff
   ------------------------------------------------------------
   Scopé #marex-view / #chat-container SANS body.dark : la vue
   Agents est toujours sombre quel que soit le thème applicatif.
   ============================================================ */

/* "+ Thought: 2.9s" — temps de réflexion du modèle avant son action.
   #marex-view est toujours sombre (orange clair) ; #chat-container suit
   le thème applicatif (orange sombre en clair, clair en sombre). */
#marex-view .thought-line {
  padding: 3px 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  color: #e8a33d;
}
#chat-container .thought-line {
  padding: 3px 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  color: #b45309;
}
body.dark #chat-container .thought-line {
  color: #e8a33d;
}
#marex-view .thought-prefix,
#chat-container .thought-prefix {
  font-weight: 700;
}

/* "thinking" + spinner pendant la réflexion de l'agent. */
#marex-view .thinking-indicator,
#chat-container .thinking-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 2px;
  font-size: 0.82rem;
  color: var(--text-secondary);
}
#marex-view .thinking-spinner {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  border: 2px solid rgba(140, 140, 150, 0.35);
  border-top-color: #e8a33d;
  border-radius: 50%;
  animation: mx-thinking-spin 0.8s linear infinite;
}
#chat-container .thinking-spinner {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  border: 2px solid rgba(140, 140, 150, 0.35);
  border-top-color: #b45309;
  border-radius: 50%;
  animation: mx-thinking-spin 0.8s linear infinite;
}
body.dark #chat-container .thinking-spinner {
  border-top-color: #e8a33d;
}
@keyframes mx-thinking-spin {
  to { transform: rotate(360deg); }
}

/* Statut façon OpenCode pendant l'exécution d'un outil ("Writing command",
   "Preparing edit") : ligne transitoire, même esthétique que thought-line. */
#marex-view .agent-status {
  padding: 3px 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  color: #e8a33d;
}
#chat-container .agent-status {
  padding: 3px 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  color: #b45309;
}
body.dark #chat-container .agent-status {
  color: #e8a33d;
}

/* Bouton Expand / Collapse des lectures de fichiers. */
#marex-view .tool-expand-btn,
#chat-container .tool-expand-btn {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 5px 10px;
  font-size: 0.75rem;
  font-family: inherit;
  text-align: center;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
#marex-view .tool-expand-btn:hover,
#chat-container .tool-expand-btn:hover {
  color: var(--text);
  border-color: var(--text-tertiary);
}

/* Diff lisible sur le fond noir permanent de la vue Agents
   (les verts/rouges du thème clair sont illisibles sur noir). */
#marex-view .diff-add {
  background: rgba(34, 197, 94, 0.16);
}
#marex-view .diff-add .diff-code,
#marex-view .diff-add .diff-sign {
  color: #4ade80;
}
#marex-view .diff-del {
  background: rgba(248, 113, 113, 0.13);
}
#marex-view .diff-del .diff-code,
#marex-view .diff-del .diff-sign {
  color: #f87171;
}
/* ============================================================
   Module Agentic — style OpenCode (vue Agents uniquement)
   ------------------------------------------------------------
   Reproduction web du TUI opencode
   (internal/tui/components/chat/message.go + theme/opencode.go) :
   fond #212121, texte #e0e0e0, messages et outils en blocs à bordure
   gauche épaisse (assistant : primaire #fab283, utilisateur :
   secondaire #5c9cf5), outils en texte atténué #6a6a6a, erreurs
   #e06c75, diffs aux couleurs du TUI.
   Scopé #marex-view.ac-opencode SANS body.dark : la vue Agents est
   toujours sombre quel que soit le thème applicatif.
   ============================================================ */

#marex-view.ac-opencode {
  --text: #e0e0e0;
  --text-primary: #e0e0e0;
  background: #212121;
  color: #e0e0e0;
}

/* Messages : blocs pleine largeur à bordure gauche épaisse, sans bulle. */
#marex-view.ac-opencode .mx-chat-log .message-wrapper-user {
  justify-content: flex-start;
}
#marex-view.ac-opencode .mx-chat-log .message {
  max-width: 100%;
  width: 100%;
  padding: 4px 0 4px 12px;
  border: none;
  border-left: 3px solid #fab283;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: #e0e0e0;
}
#marex-view.ac-opencode .mx-chat-log .message-wrapper-user .message {
  border-left-color: #5c9cf5;
}
#marex-view.ac-opencode .mx-chat-log .message-wrapper-assistant .message {
  border-left-color: #fab283;
}
#marex-view.ac-opencode .mx-chat-log .message-error {
  border-left-color: #e06c75;
  background: transparent;
}
#marex-view.ac-opencode .mx-chat-log .message-error .message-text {
  color: #e06c75;
}
/* Pas d'effet shimmer en streaming : le TUI n'en a pas. */
#marex-view.ac-opencode .mx-chat-log .message-assistant.streaming {
  background: transparent;
  animation: none;
}
#marex-view.ac-opencode .mx-chat-log .message-assistant.streaming::before {
  display: none;
}

/* Outils : bordure atténuée, en-tête "Nom: paramètres". */
#marex-view.ac-opencode .oc-tool {
  border-left: 3px solid #6a6a6a;
  padding: 2px 0 2px 12px;
  margin: 10px 0;
}
#marex-view.ac-opencode .oc-tool-head {
  color: #6a6a6a;
  font-size: 0.85rem;
}
#marex-view.ac-opencode .oc-tool-head .oc-tool-name {
  font-weight: 600;
}
#marex-view.ac-opencode .oc-tool-body {
  margin-top: 4px;
}
#marex-view.ac-opencode .oc-tool-body .tool-result,
#marex-view.ac-opencode .oc-tool-body pre.tool-result {
  color: #6a6a6a;
  background: transparent;
  border: none;
  padding: 0;
  margin: 4px 0;
}
#marex-view.ac-opencode .oc-tool-error {
  color: #e06c75;
  background: transparent;
  border: none;
  padding: 0;
  margin: 4px 0;
  white-space: pre-wrap;
}
/* "Thinking..." façon TUI : primaire + gras. */
#marex-view.ac-opencode .thinking-indicator {
  color: #fab283;
  font-weight: 700;
}
#marex-view.ac-opencode .thinking-spinner {
  border-top-color: #fab283;
}
/* Pied de réponse : " modèle (durée)", atténué. */
#marex-view.ac-opencode .oc-turn-stats {
  color: #6a6a6a;
  font-size: 0.75rem;
  padding: 2px 0 2px 12px;
}
/* Diffs aux couleurs exactes du TUI opencode (mode sombre). */
#marex-view.ac-opencode .tool-diff {
  border-top: none;
}
#marex-view.ac-opencode .diff-head {
  background: transparent;
  padding-left: 0;
}
#marex-view.ac-opencode .diff-add {
  background: #303a30;
}
#marex-view.ac-opencode .diff-add .diff-code,
#marex-view.ac-opencode .diff-add .diff-sign {
  color: #478247;
}
#marex-view.ac-opencode .diff-del {
  background: #3a3030;
}
#marex-view.ac-opencode .diff-del .diff-code,
#marex-view.ac-opencode .diff-del .diff-sign {
  color: #7c4444;
}
#marex-view.ac-opencode .diff-gutter {
  color: #888888;
}
#marex-view.ac-opencode .diff-ctx {
  color: #6a6a6a;
}

/* --- Panneau Crédit API (Paramètres) --- */
.credit-row {
  border: 1px solid var(--mx-border, #e0e0e0);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  align-items: center;
}
.credit-row.credit-exhausted {
  border-color: #d33;
  background: rgba(221, 51, 51, 0.06);
}
.credit-label { font-weight: 600; }
.credit-value { font-size: 1.2em; font-weight: 700; grid-column: 2; grid-row: 1; }
.credit-edit { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; }
.credit-edit input { width: 160px; }
.credit-badge {
  display: inline-block;
  font-size: 0.75em;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
  vertical-align: middle;
}
.credit-badge-ok { background: #1a7f37; color: #fff; }
.credit-badge-bad { background: #d33; color: #fff; }
.credit-badge-neutral { background: #888; color: #fff; }
.credit-src { font-size: 0.8em; color: #888; font-weight: 400; }
.credits-actions { margin-top: 12px; display: flex; gap: 10px; align-items: center; }
/* --- Avertissement crédit épuisé (Sélecteur) --- */
.credit-warn-banner {
  border: 2px solid #d33;
  background: rgba(221, 51, 51, 0.08);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 10px 0;
  font-weight: 600;
}

/* ---- Questions suggérées : chips de la diversion d'accueil (itération 4) ---- */
.suggest-intro {
  font-size: 0.9rem;
  opacity: 0.85;
  margin-bottom: 4px;
}
.suggest-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.suggest-chip {
  cursor: pointer;
  border: 1px solid var(--border-input);
  background: var(--bg-input);
  color: inherit;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.85rem;
  line-height: 1.3;
  max-width: 100%;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}
.suggest-chip:hover {
  border-color: var(--accent, #4f8cff);
  background: var(--bg-hover, rgba(79, 140, 255, 0.08));
}
.suggest-chip-more {
  border-style: dashed;
  opacity: 0.75;
}
