:root {
  --bg: #f6f6f6;
  --panel: #ffffff;
  --border: #e2e4ea;
  --text: #16181d;
  --muted: #5d6576;
  --accent: #1457b8;
  --accent-soft: #e8f0fb;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --ok: #1f7a3d;
  --user-bubble: #1457b8;
  font-family: Inter, Avenir, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); overflow: hidden; }
[hidden] { display: none !important; }

button, .button, input, select, textarea { font: inherit; color: inherit; }
button, .button {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 8px;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
button:hover, .button:hover { border-color: #c4c8d2; }
button:disabled { opacity: 0.55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #104a9e; }
button.block { width: 100%; justify-content: center; }
button.link { border: none; background: none; padding: 0.2rem 0.3rem; color: var(--accent); }
button.link:hover { text-decoration: underline; }
button.danger, .danger { color: var(--danger); }
button.icon { border: none; background: none; font-size: 1.2rem; padding: 0.2rem 0.5rem; }
input, select, textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  background: #fff;
  width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid #8fb4ea; outline-offset: 1px; }
label { display: block; text-align: left; font-size: 0.9rem; color: var(--muted); margin: 0.6rem 0; }
label > input, label > textarea { margin-top: 0.25rem; color: var(--text); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--danger); min-height: 1.2em; font-size: 0.9rem; margin: 0.4rem 0; }
.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }

/* --- connexion --- */
.login-screen { height: 100%; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 2rem; text-align: center;
}
.login-card h1 { margin: 0; font-size: 1.5rem; }
.login-card button.primary { width: 100%; justify-content: center; margin-top: 0.6rem; padding: 0.6rem; }
.login-card a.button.primary {
  display: flex; width: 100%; justify-content: center; margin-top: 1.2rem; padding: 0.6rem; box-sizing: border-box;
  border-radius: 8px; background: var(--accent); color: #fff; text-decoration: none; font-weight: 600;
}
.login-card a.button.primary:hover { filter: brightness(1.08); }
.login-card label { text-align: left; }
.login-card .error.ok { color: var(--muted); }

/* --- application --- */
.app { display: grid; grid-template-columns: 270px 1fr; height: 100%; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 1rem 0.8rem; gap: 0.8rem; min-height: 0;
}
.sidebar-head { display: flex; justify-content: space-between; align-items: center; padding: 0 0.3rem; }
.project-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.project-item {
  border: none; background: none; text-align: left; width: 100%; border-radius: 8px;
  padding: 0.5rem 0.6rem; display: grid; grid-template-columns: 1.4rem 1fr; gap: 0.1rem 0.4rem;
}
.project-item:hover { background: #f1f3f7; }
.project-item.active, .project-item.open { background: #f1f3f7; }
.project-item.open .name { font-weight: 600; }
.conversation-list { display: flex; flex-direction: column; gap: 1px; margin: 2px 0 8px 1.6rem; border-left: 2px solid var(--border); padding-left: 0.4rem; }
.conversation-item { display: grid; grid-template-columns: 1fr auto auto; align-items: center; border-radius: 7px; }
.conversation-item:hover { background: #f4f5f8; }
.conversation-item.active { background: var(--accent-soft); }
.conversation-item.new { border: none; background: none; color: var(--accent); font-size: 0.88rem; padding: 0.3rem 0.5rem; text-align: left; display: block; width: 100%; }
.conversation-item.new.active { background: var(--accent-soft); }
.conversation-open { border: none; background: none; text-align: left; padding: 0.3rem 0.5rem; min-width: 0; width: 100%; display: flex; flex-direction: column; align-items: flex-start; gap: 0; overflow: hidden; }
.conversation-open .ctitle { max-width: 100%; font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-open .cmeta { font-size: 0.72rem; color: var(--muted); }
.icon-small { border: none; background: none; padding: 0.15rem 0.3rem; font-size: 0.8rem; opacity: 0; color: var(--muted); }
.conversation-item:hover .icon-small, .conversation-item.active .icon-small, .icon-small:focus-visible { opacity: 1; }
.crumb { color: var(--muted); }
.conversation-title { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 36ch; }
.project-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-item .meta { grid-column: 2; font-size: 0.78rem; color: var(--muted); }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 0.7rem; font-size: 0.9rem; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 0.5rem; padding: 0.7rem 1.2rem; border-bottom: 1px solid var(--border); background: var(--panel); min-height: 56px; }
.project-header { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; flex: 1; min-width: 0; }
.project-header h2 { margin: 0; font-size: 1.1rem; cursor: text; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40ch; }
.project-header select { width: auto; max-width: 260px; padding: 0.3rem 0.5rem; font-size: 0.9rem; }
.project-header #delete-project { margin-left: auto; }
.badge { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 0.1rem 0.6rem; font-size: 0.8rem; white-space: nowrap; }
.rename-input { max-width: 320px; }

.empty-state { flex: 1; overflow-y: auto; padding: 3rem 1.5rem; text-align: center; }
.kind-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 280px)); gap: 1rem; justify-content: center; margin-top: 1.5rem; }
.kind-card {
  display: flex; flex-direction: column; align-items: flex-start; text-align: left; gap: 0.3rem;
  padding: 1.1rem; border-radius: 12px; border: 1px solid var(--border); background: var(--panel);
}
.kind-card .icon { font-size: 1.6rem; }
.kind-card strong { font-size: 1.05rem; }
.kind-card span.desc { color: var(--muted); font-size: 0.9rem; }
.kind-card:hover, .kind-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.kind-cards.compact { grid-template-columns: 1fr 1fr; margin-top: 0.5rem; }

.workspace { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* --- fichiers --- */
.files-panel { border-bottom: 1px solid var(--border); background: #fbfbfc; padding: 0.6rem 1.2rem; max-height: 45%; overflow-y: auto; }
.files-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.files-head .button { font-size: 0.9rem; padding: 0.35rem 0.75rem; }
.dropzone {
  margin: 0.6rem 0; border: 2px dashed #c9cfdb; border-radius: 10px; padding: 0.9rem;
  text-align: center; color: var(--muted); font-size: 0.9rem;
}
.dropzone.over, .files-panel.over .dropzone { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.file-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.file-list li {
  display: grid; grid-template-columns: 1fr auto auto; gap: 0.6rem; align-items: center;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 0.35rem 0.6rem; font-size: 0.9rem;
}
.file-list .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list .fstatus { font-size: 0.82rem; color: var(--muted); white-space: nowrap; }
.file-list .fstatus.ready { color: var(--ok); }
.file-list .fstatus.error { color: var(--danger); white-space: normal; }
.file-list .ferror { grid-column: 1 / -1; color: var(--danger); font-size: 0.82rem; }

/* --- conversation --- */
.chat-log { flex: 1; overflow-y: auto; padding: 1.2rem; display: flex; flex-direction: column; gap: 0.7rem; }
.chat-log .hint { margin: auto; color: var(--muted); text-align: center; max-width: 520px; }
.msg { max-width: min(860px, 92%); border-radius: 12px; padding: 0.65rem 0.95rem; overflow-wrap: anywhere; }
.msg-user { align-self: flex-end; background: var(--user-bubble); color: #fff; white-space: pre-wrap; }
.msg-assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--border); }
.msg-assistant p { margin: 0.25rem 0; }
.msg-assistant h2, .msg-assistant h3, .msg-assistant h4 { margin: 0.6rem 0 0.3rem; }
/* Retrait des <li> (sans <ul>/<ol> autour, voir renderMarkdown) : assez
   large pour le numéro de li.numbered::before (-1.4em), « 10. » compris. */
.msg-assistant li { margin-left: 1.6em; }
.msg-assistant pre { background: #f3f4f7; padding: 0.6rem; border-radius: 8px; overflow-x: auto; }
.msg-assistant code { background: #f3f4f7; padding: 0 0.25rem; border-radius: 4px; font-size: 0.9em; }
.msg-assistant pre code { background: none; padding: 0; }
.msg-assistant table { border-collapse: collapse; margin: 0.5rem 0; display: block; overflow-x: auto; }
.msg-assistant th, .msg-assistant td { border: 1px solid var(--border); padding: 0.3rem 0.5rem; text-align: left; }
.msg-assistant a { color: var(--accent); }
.msg-assistant blockquote { margin: 0.3rem 0; padding: 0.2rem 0.7rem; border-left: 3px solid #c9d6ea; color: #3b4558; }
.msg-actions { display: flex; gap: 0.3rem; margin-top: 0.4rem; }
.msg-actions button { font-size: 0.8rem; padding: 0.15rem 0.5rem; }
.msg-error { align-self: flex-start; background: var(--danger-soft); border: 1px solid #f3c2bc; color: #6b1a12; }
.msg-error-title { font-weight: 600; }
.msg-advice { align-self: flex-start; background: #fff7e0; border: 1px solid #f0d58a; color: #5c4300; }
.msg-advice-title { font-weight: 600; }
.msg-error-text { white-space: pre-wrap; font-size: 0.92rem; }
.activity {
  align-self: flex-start; font-size: 0.85rem; color: var(--muted); background: none;
  border-left: 3px solid var(--border); padding: 0.1rem 0.6rem; max-width: 92%;
}
.activity details summary { cursor: pointer; }
.activity ul { margin: 0.3rem 0 0; padding-left: 1.1rem; }

.chat-form { border-top: 1px solid var(--border); background: var(--panel); padding: 0.7rem 1.2rem 1rem; }
.chat-status { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.4rem; }
.chat-status::before { content: ""; display: inline-block; width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--accent); margin-right: 0.45rem; animation: pulse 1.2s infinite ease-in-out; }
@keyframes pulse { 50% { opacity: 0.25; } }
.composer { display: flex; gap: 0.5rem; align-items: flex-end; }
.composer textarea { resize: none; max-height: 40vh; min-height: 2.8rem; }

dialog { border: 1px solid var(--border); border-radius: 14px; padding: 1.3rem; width: min(560px, 94vw); }
dialog::backdrop { background: rgba(20, 24, 33, 0.35); }
dialog h3 { margin-top: 0; }

.only-mobile { display: none; }
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 25% 0 0; z-index: 10; transform: translateX(-105%); transition: transform 0.2s; box-shadow: 0 0 30px rgba(0,0,0,0.2); }
  .sidebar.open { transform: none; }
  .only-mobile { display: inline-flex; }
  .topbar, .chat-log, .chat-form, .files-panel { padding-left: 0.8rem; padding-right: 0.8rem; }
  .project-header h2 { max-width: 20ch; }
  .crumb, .conversation-title { display: none; }
  .icon-small { opacity: 1; }
  .kind-cards.compact { grid-template-columns: 1fr; }
}

/* --- workflows --- */
.workflows-button { justify-content: center; }
dialog.wide { width: min(820px, 96vw); }
.workflows-list { list-style: none; margin: 0.8rem 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow-y: auto; }
.workflows-list li { display: grid; grid-template-columns: 1fr auto auto; gap: 0.5rem; align-items: center; border: 1px solid var(--border); border-radius: 10px; padding: 0.5rem 0.7rem; }
.workflows-list .wbadges, .workflows-list .wactions { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.share-pill { border-radius: 999px; padding: 0.05rem 0.55rem; font-size: 0.78rem; white-space: nowrap; background: #e9f6ee; color: #1d6b3a; }
.org-note { background: #f3f7fc; border-radius: 8px; padding: 0.5rem 0.7rem; }
@media (max-width: 640px) { .workflows-list li { grid-template-columns: 1fr; } .workflows-list .wbadges, .workflows-list .wactions { justify-content: flex-start; } }
.workflows-list .wtitle { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kind-pill { border-radius: 999px; padding: 0.05rem 0.55rem; font-size: 0.78rem; white-space: nowrap; }
.kind-pill.discussion { background: #eef1f5; color: #3d4757; }
.kind-pill.analysis { background: #e8f0fb; color: #1457b8; }
.kind-pill.generation { background: #fdf0e3; color: #9a4b07; }
.workflow-kinds { border: 1px solid var(--border); border-radius: 10px; padding: 0.4rem 0.8rem 0.6rem; margin: 0.6rem 0; }
.workflow-kinds legend { color: var(--muted); font-size: 0.9rem; padding: 0 0.3rem; }
.workflow-kinds label { display: flex; gap: 0.5rem; align-items: flex-start; color: var(--text); margin: 0.35rem 0; }
.workflow-kinds input { width: auto; margin-top: 0.3rem; }
.workflow-kinds small { display: block; color: var(--muted); }
.workflow-edit-head { align-items: flex-end; }
.workflow-edit-head .grow { flex: 1; }
.workflow-edit-head select { width: auto; }
.tabs { display: flex; gap: 0.3rem; margin: 0.3rem 0; }
.tab { padding: 0.25rem 0.8rem; font-size: 0.9rem; }
.tab.active { background: var(--accent-soft); border-color: #bcd0ef; color: var(--accent); }
#workflow-content { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.88rem; resize: vertical; }
.workflow-preview { max-height: 50vh; overflow-y: auto; max-width: none; border-radius: 10px; padding: 0.6rem 1rem; }
.workflow-ai { margin-top: 0.5rem; flex-wrap: nowrap; }
.workflow-ai input { flex: 1; }
.workflow-launcher { position: relative; }
.workflow-menu {
  position: absolute; bottom: calc(100% + 6px); left: 0; z-index: 5; background: var(--panel);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(20, 24, 33, 0.15);
  width: min(360px, 80vw); max-height: 50vh; overflow-y: auto; padding: 0.3rem;
}
.workflow-menu button { width: 100%; border: none; border-radius: 7px; text-align: left; display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.45rem 0.6rem; }
.workflow-menu button:hover:not(:disabled) { background: #f1f3f7; }
.workflow-menu button:disabled { opacity: 0.5; }
.workflow-menu .hint { padding: 0.5rem 0.6rem; font-size: 0.85rem; color: var(--muted); }
.workflow-chip { display: flex; justify-content: space-between; align-items: center; background: var(--accent-soft); color: var(--accent); border-radius: 8px; padding: 0.25rem 0.6rem; margin-bottom: 0.4rem; font-size: 0.9rem; }
.msg-user .workflow-launch { font-weight: 600; }
.msg-user details { margin-top: 0.3rem; font-size: 0.88rem; }
.msg-user details summary { cursor: pointer; opacity: 0.85; }
.msg-user details .workflow-body { background: #fff; color: var(--text); border-radius: 8px; padding: 0.4rem 0.7rem; margin-top: 0.3rem; white-space: normal; }
.workflow-preview { background: var(--panel); border: 1px solid var(--border); }
.workflow-preview p, .msg-user .workflow-body p { margin: 0.25rem 0; }
.workflow-preview h2, .workflow-preview h3, .workflow-preview h4,
.msg-user .workflow-body h2, .msg-user .workflow-body h3, .msg-user .workflow-body h4 { margin: 0.6rem 0 0.3rem; font-size: 1rem; }
.workflow-preview li, .msg-user .workflow-body li { margin-left: 1.6em; }

/* Listes numérotées du Markdown (étapes d'un workflow, réponses) : le
   numéro écrit par le modèle est conservé. */
li.numbered { list-style: none; position: relative; }
li.numbered::before { content: attr(data-n) "."; position: absolute; left: -1.4em; width: 1.2em; text-align: right; font-variant-numeric: tabular-nums; }

/* --- avancement du workflow en cours --- */
.workflow-panel { border-bottom: 1px solid var(--border); background: #fbfbfc; padding: 0.5rem 1.2rem; max-height: 40%; overflow-y: auto; font-size: 0.92rem; }
.workflow-panel summary { cursor: pointer; display: flex; gap: 0.6rem; align-items: baseline; font-weight: 600; list-style: none; }
.workflow-panel summary::before { content: "▾"; color: var(--muted); }
.workflow-panel:not([open]) summary::before { content: "▸"; }
.workflow-panel .wp-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workflow-panel .wp-progress { margin-left: auto; color: var(--muted); font-weight: 400; white-space: nowrap; }
.workflow-panel.finished .wp-progress { color: var(--ok); }
.workflow-panel .wp-goal { margin: 0.4rem 0 0.2rem; color: var(--muted); }
.workflow-panel .wp-empty { margin: 0.4rem 0; font-style: italic; }
.wp-steps { list-style: none; margin: 0.3rem 0; padding: 0; display: flex; flex-direction: column; gap: 0.15rem; }
.wp-steps li { display: grid; grid-template-columns: 1.4rem 1fr; align-items: baseline; }
.wp-steps li::before { content: attr(data-icon); text-align: center; color: var(--muted); }
.wp-steps li.in_progress { font-weight: 600; color: var(--accent); }
.wp-steps li.in_progress::before { color: var(--accent); }
.wp-steps li.done { color: var(--muted); }
.wp-steps li.done::before { color: var(--ok); }
.wp-steps li.blocked { color: var(--danger); }
.wp-steps li.blocked::before { color: var(--danger); }
.wp-steps li.skipped { color: var(--muted); text-decoration: line-through; }
.workflow-panel .wp-actions { text-align: right; }
.workflow-stop-line { align-self: center; color: var(--muted); font-size: 0.85rem; }
@media (max-width: 760px) { .workflow-panel { padding-left: 0.8rem; padding-right: 0.8rem; } }

/* Contenu plus large que la bulle (formule, tableau, lien) : jamais rogné à
   gauche. WebKit (application macOS, Safari) centre une formule trop large
   des deux côtés, ce qui cachait son début ; on la colle à gauche avec
   défilement horizontal, et elle reste centrée quand elle tient. */
.msg { min-width: 0; overflow-wrap: anywhere; }
.msg .katex-display { overflow-x: auto; overflow-y: hidden; text-align: left; padding: 0.15em 0; }
.msg .katex-display > .katex { width: max-content; max-width: none; margin-left: auto; margin-right: auto; text-align: left; }
.msg .katex { overflow-wrap: normal; }

/* --- réponse en cours (voir setBusy / blockedWhileBusy dans app.js) -------- */
.busy-banner {
  margin: 0.2rem 0;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  background: #fff7e0;
  border: 1px solid #f0d58a;
  color: #6b4e00;
  font-size: 0.85rem;
  line-height: 1.35;
}
.busy-banner.flash { animation: busy-flash 0.9s ease-out; }
@keyframes busy-flash { 0%, 40% { background: #ffe08a; border-color: #d9a400; } }
.app-busy .project-item:not(.open),
.app-busy .conversation-item:not(.active) { opacity: 0.45; cursor: not-allowed; }
.app-busy .project-item:not(.open):hover,
.app-busy .conversation-item:not(.active):hover { background: transparent; }
.app-busy .project-item:not(.open) *,
.app-busy .conversation-item:not(.active) * { cursor: not-allowed; }
.app-busy .conversation-item .icon-small { visibility: hidden; }
.app-busy .conversation-item.active .ctitle::after,
.app-busy .conversation-item.new.active::after {
  content: " ⏳";
  animation: busy-pulse 1.4s ease-in-out infinite;
}
@keyframes busy-pulse { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) {
  .busy-banner.flash,
  .app-busy .conversation-item.active .ctitle::after,
  .app-busy .conversation-item.new.active::after { animation: none; }
}
#logout-button:disabled { opacity: 0.45; cursor: not-allowed; }

/* =============================================================================
   Refonte IHM : rendre la place à la conversation (octobre 2026), comme dans
   l'application (claude/cahier-des-charges-ihm-conversation.md). En-tête sur
   une ligne (coût et suppression dans le menu ⋯), fichiers repliés sur une
   ligne, workflow en bandeau au-dessus de la saisie, saisie avec barre
   d'outils, colonne de lecture centrée, barre latérale repliable.
   ============================================================================= */

.icon-button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0; border: none; border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.icon-button:hover { background: #f1f3f7; }
.only-desktop { display: inline-flex; }
.nav-icon { width: 1.2em; text-align: center; flex-shrink: 0; }

/* --- barre latérale --- */
.app { grid-template-columns: 256px 1fr; transition: grid-template-columns 0.15s ease; }
.sidebar { padding: 0.8rem 0.7rem; gap: 0.6rem; }
.sidebar-head { min-height: 32px; }
#new-project-button { padding: 0.45rem 0.8rem; }
.sidebar-foot { display: flex; flex-direction: column; gap: 0.4rem; padding-top: 0.5rem; }
.nav-button { border: none; background: none; width: 100%; justify-content: flex-start; padding: 0.4rem 0.5rem; border-radius: 6px; font-size: 0.92rem; }
.nav-button:hover { background: #f1f3f7; }
a.nav-button { color: inherit; text-decoration: none; }
.empty-help { margin-top: 1.5rem; }
.empty-help a { color: var(--accent); }
.sidebar-user { padding: 0 0.3rem; font-size: 0.85rem; }
.sidebar-user .row { gap: 0.2rem 0.5rem; }

/* Barre repliée en rail : icônes seules (bureau uniquement). */
@media (min-width: 761px) {
.app.sidebar-collapsed { grid-template-columns: 60px 1fr; }
.sidebar-collapsed .sidebar { padding: 0.8rem 0.4rem; align-items: center; }
.sidebar-collapsed .app-name,
.sidebar-collapsed .nav-label,
.sidebar-collapsed .project-item .name,
.sidebar-collapsed .project-item .meta,
.sidebar-collapsed .conversation-list,
.sidebar-collapsed .project-list > p,
.sidebar-collapsed .sidebar-user,
.sidebar-collapsed .busy-banner { display: none !important; }
.sidebar-collapsed .sidebar-head { justify-content: center; padding: 0; }
.sidebar-collapsed #new-project-button { width: 40px; padding: 0.45rem 0; }
.sidebar-collapsed .project-list { width: 100%; align-items: center; }
.sidebar-collapsed .project-item { width: 40px; display: flex; justify-content: center; padding: 0.45rem 0; }
.sidebar-collapsed .sidebar-foot { width: 100%; align-items: center; }
.sidebar-collapsed .nav-button { width: 40px; justify-content: center; padding: 0.45rem 0; }
}

/* --- en-tête sur une ligne --- */
.topbar { padding: 0 1rem; min-height: 52px; }
.project-header { flex-wrap: nowrap; gap: 0.5rem; }
.project-header h2 { font-size: 1.05rem; flex: 0 1 auto; min-width: 6rem; max-width: none; }
.conversation-title { flex: 0 2 auto; min-width: 0; max-width: 36ch; }
.header-spacer { flex: 1; }
.project-header select { flex-shrink: 0; max-width: 15rem; font-size: 0.85rem; padding: 0.25rem 0.45rem; }
.badge { flex-shrink: 0; }
.header-more { position: relative; flex-shrink: 0; }
.header-more > summary { list-style: none; }
.header-more > summary::-webkit-details-marker { display: none; }
.header-more-menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 15rem;
  display: flex; flex-direction: column; gap: 0.2rem; padding: 0.4rem;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(20, 24, 33, 0.15);
}
.header-more-menu > span { padding: 0.3rem 0.5rem; }
.menu-item { border: none; background: none; width: 100%; justify-content: flex-start; padding: 0.4rem 0.5rem; border-radius: 6px; font-size: 0.92rem; }
.menu-item:hover { background: #f1f3f7; }

/* --- fichiers : une ligne, liste dépliable --- */
.files-panel { padding: 0.35rem 1rem; max-height: 40%; }
.files-head .button { font-size: 0.85rem; padding: 0.25rem 0.7rem; }
#files-toggle { font-size: 0.9rem; }

/* --- fil : colonne de lecture centrée --- */
.main { background: var(--panel); }
.chat-log { padding: 1.2rem max(1rem, calc((100% - 820px) / 2)) 0.8rem; gap: 1rem; }
.msg { max-width: 100%; }
.msg-assistant { align-self: stretch; background: none; border: none; padding: 0.1rem 0; }
.msg-user { max-width: 80%; background: #eef1f7; color: var(--text); }
.msg-user details .workflow-body { border: 1px solid var(--border); }

/* --- bas d'écran : suivi, workflow, saisie --- */
.chat-form {
  border-top: none; background: none; width: 100%; max-width: calc(820px + 2rem); margin: 0 auto;
  padding: 0 1rem 0.9rem; display: flex; flex-direction: column; gap: 0.4rem;
}
.chat-status { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.workflow-chip { margin: 0; }

.workflow-panel { position: relative; max-height: none; overflow: visible; padding: 0; border: 1px solid var(--border); border-radius: 8px; background: #f7f8fa; }
.workflow-panel summary { padding: 0.35rem 0.75rem; align-items: center; gap: 0.6rem; }
.workflow-panel summary::before,
.workflow-panel:not([open]) summary::before { content: "▶"; color: var(--accent); font-size: 0.8em; }
.workflow-panel .wp-title { flex-shrink: 1; max-width: 40%; }
.wp-bar { display: flex; gap: 3px; flex-shrink: 0; }
.wp-bar span { width: 14px; height: 4px; border-radius: 2px; background: #d5d9e1; }
.wp-bar span.done { background: var(--accent); }
.wp-bar span.in_progress { background: #8fb0e0; }
.wp-bar span.blocked { background: var(--danger); }
.wp-bar span.skipped { background: #e8eaef; }
.workflow-panel .wp-progress { margin-left: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.wp-toggle { flex-shrink: 0; color: var(--accent); font-weight: 400; }
.workflow-panel[open] .wp-toggle { font-size: 0; }
.workflow-panel[open] .wp-toggle::after { content: "Masquer"; font-size: 0.92rem; }
.wp-body {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); z-index: 6;
  max-height: 50vh; overflow-y: auto; padding: 0.6rem 1rem;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(20, 24, 33, 0.15);
}

.composer {
  flex-direction: column; align-items: stretch; gap: 0;
  border: 1px solid #cfd4dd; border-radius: 12px; background: var(--panel); box-shadow: 0 1px 2px rgba(20, 24, 33, 0.06);
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea { border: none; border-radius: 12px 12px 0 0; min-height: 2.6rem; padding: 0.65rem 0.85rem 0.25rem; }
.composer textarea:focus { outline: none; }
.composer-toolbar { display: flex; align-items: center; gap: 0.5rem; padding: 0.3rem 0.5rem 0.5rem; }
.composer-spacer { flex: 1; }
.composer-toolbar #workflow-button, .composer-toolbar #image-button { font-size: 0.88rem; padding: 0.3rem 0.7rem; }
.composer-toolbar #send-button, .composer-toolbar #stop-button { padding: 0.35rem 0.95rem; }

@media (max-width: 760px) {
  .only-desktop { display: none; }
  .app, .app.sidebar-collapsed { grid-template-columns: 1fr; }
  .topbar { padding: 0 0.6rem; }
  .project-header h2 { min-width: 0; }
  .project-header select { max-width: 8.5rem; }
  .project-header .badge { display: none; }
  .chat-log { padding-left: 0.8rem; padding-right: 0.8rem; }
  .chat-form { padding: 0 0.6rem 0.6rem; }
  .files-panel { padding-left: 0.8rem; padding-right: 0.8rem; }
}

/* Titres de projets et de conversations : en entier au survol (et pour le
   projet ouvert), sur plusieurs lignes si besoin, au lieu d'être coupés. */
.project-item:hover .name,
.project-item.open .name,
.conversation-item:hover .conversation-open .ctitle {
  white-space: normal;
  overflow: visible;
  overflow-wrap: anywhere;
}

/* La liste des projets défile au lieu de se tasser (même cause que dans
   l'application : lignes rétrécies quand la liste dépasse la hauteur). */
.project-list > * { flex-shrink: 0; }

/* État d'indexation des fichiers prêts (voir INDEX_LABELS dans app.js). */
.file-list .fstatus.index-indexing,
.file-list .fstatus.index-pending { color: var(--muted); }
.file-list .fstatus.index-failed { color: #9a4b07; }

/* --- confidentialité : phrase secrète, code de récupération, modes --- */
.login-card.wide { max-width: 460px; }
.login-card p.muted.small { text-align: left; }
label.check { display: flex; gap: 0.5rem; align-items: flex-start; color: var(--text); }
label.check input { width: auto; margin-top: 0.3rem; flex-shrink: 0; }
.recovery-code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 1.15rem; letter-spacing: 0.04em;
  background: var(--accent-soft); border: 1px dashed var(--accent); border-radius: 10px;
  padding: 0.8rem; margin: 0.8rem 0; text-align: center; word-break: break-all; user-select: all;
}
.privacy-notice {
  margin: 0.5rem 1rem 0; padding: 0.5rem 0.8rem; border-radius: 8px; font-size: 0.88rem;
  background: var(--accent-soft); color: var(--text);
}
#storage-select { max-width: 13rem; }
.settings-section { border-top: 1px solid var(--border); padding-top: 0.6rem; margin-top: 0.8rem; }
.settings-section h4 { margin: 0.2rem 0 0.3rem; }
#settings-dialog > h3 { margin-top: 0; }
@media (max-width: 720px) {
  #storage-select { max-width: 3.4rem; }
}

.activity li.skipped { opacity: 0.7; }

/* --- Mes données (transparency.js) --- */
dialog.transparency-dialog { width: min(1080px, 96vw); height: min(860px, 92vh); display: none; flex-direction: column; gap: 0.6rem; }
dialog.transparency-dialog[open] { display: flex; }
.transparency-head { display: flex; align-items: center; justify-content: space-between; }
.transparency-head h3 { margin: 0; }
.transparency-body { flex: 1; min-height: 0; }

/* --- Sources citées (sources.js) : pastilles numérotées, bulle du passage -- */
.src-chip {
  display: inline-flex; align-items: center; justify-content: center; min-width: 1.5em; height: 1.45em;
  margin: 0 0.12em; padding: 0 0.35em; border: 1px solid #c9dccd; border-radius: 5px; box-shadow: none;
  background: #eef6ef; color: #1f6b3a; font: inherit; font-size: 0.72em; font-weight: 600; line-height: 1;
  vertical-align: 0.18em; cursor: pointer;
}
.src-chip:hover, .src-chip:focus-visible { background: #dcefe0; border-color: #1f7a3d; outline: none; }
button.src-chip[aria-expanded="true"] { background: #1f7a3d; border-color: #1f7a3d; color: #fff; }
.src-chip.src-missing { background: #fdecea; border-color: #f2c4bf; color: #b42318; }
.src-chip.src-missing[aria-expanded="true"] { background: #b42318; border-color: #b42318; color: #fff; }
.src-list { margin-top: 0.7em; padding-top: 0.5em; border-top: 1px solid rgba(0, 0, 0, 0.08); font-size: 0.86em; }
.src-list > summary { cursor: pointer; color: #5d6576; font-weight: 500; width: fit-content; }
.src-list > summary::marker { color: #8a93a3; }
.src-items { margin: 0.35em 0 0; padding-left: 0; list-style: none; }
.src-items li { margin: 0.15em 0; }
.src-ref { display: inline-flex; align-items: baseline; gap: 0.5em; border: none; background: none; box-shadow: none; padding: 0; font: inherit; color: #1457b8; cursor: pointer; text-align: left; }
.src-ref:hover { text-decoration: underline; }
.src-n { display: inline-flex; justify-content: center; min-width: 1.5em; padding: 0 0.3em; border: 1px solid #c9dccd; border-radius: 5px; background: #eef6ef; color: #1f6b3a; font-size: 0.85em; font-weight: 600; }
.src-warning { margin: 0.4em 0 0; color: #b42318; font-size: 0.9em; }
.src-pop {
  position: fixed; z-index: 1000; box-sizing: border-box; /* pas d'overflow : il couperait la flèche */
  padding: 0.75em 0.9em; border: 1px solid #c9dccd; border-radius: 10px; background: #fff; color: #16181d;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18); font-size: 13.5px; line-height: 1.5; text-align: left;
}
.src-pop::before {
  content: ""; position: absolute; top: -7px; left: calc(var(--src-arrow, 50%) - 6px); width: 12px; height: 12px;
  background: inherit; border-left: 1px solid #c9dccd; border-top: 1px solid #c9dccd; transform: rotate(45deg);
}
.src-pop.src-pop-up::before { top: auto; bottom: -7px; transform: rotate(225deg); }
.src-pop-head { display: flex; justify-content: space-between; gap: 0.8em; align-items: flex-start; }
.src-pop-head strong { word-break: break-word; }
.src-close { border: none; background: none; box-shadow: none; padding: 0 0.2em; cursor: pointer; color: #5d6576; font: inherit; }
.src-meta { color: #5d6576; font-size: 0.88em; margin-top: 0.15em; }
.src-text { margin: 0.5em 0 0; padding: 0 0 0 0.7em; border-left: 3px solid #1f7a3d; white-space: pre-wrap; color: inherit; max-height: min(16em, 45vh); overflow: auto; }
.src-actions { display: flex; flex-wrap: wrap; gap: 0.7em; align-items: center; margin-top: 0.6em; }
.src-open { font: inherit; font-size: 0.95em; padding: 0.2em 0.7em; border-radius: 6px; border: 1px solid #c4c8d2; background: #fff; box-shadow: none; cursor: pointer; }
.src-hint { color: #5d6576; font-size: 0.88em; }

/* Images jointes à une question (voir addImages dans app.js). */
.image-tray { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.5rem; }
.image-thumb { position: relative; width: 72px; height: 72px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #f6f7f9; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.image-thumb img { width: 100%; height: 100%; object-fit: cover; }
.image-thumb.preparing { font-size: 1.4rem; }
.image-remove { position: absolute; top: 2px; right: 2px; padding: 0 0.3rem; min-height: 0; line-height: 1.3; font-size: 0.75rem; border-radius: 6px; background: rgba(255, 255, 255, 0.92); }
.chat-form.image-over { outline: 2px dashed var(--accent); outline-offset: 4px; border-radius: 10px; }
.msg-images { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.35rem; }
.msg-images img { max-height: 160px; max-width: 100%; border-radius: 8px; cursor: zoom-in; background: #fff; }
.msg-images img.zoomed { max-height: none; cursor: zoom-out; }

/* Questions de l'assistant (outil ask_user, voir app.js) */
.ask-card {
  align-self: flex-start; width: min(36rem, 100%); margin: 0.4rem 0;
  border: 1px solid #c9d6f2; border-left: 4px solid var(--accent); border-radius: 10px;
  background: var(--accent-soft); padding: 0.75rem 0.9rem;
  display: flex; flex-direction: column; gap: 0.55rem; outline: none;
}
.ask-card-live { animation: ask-card-in 0.25s ease-out, ask-card-pulse 2.4s ease-in-out 0.3s 3; }
.ask-card-live:focus, .ask-card-live:focus-within { box-shadow: 0 0 0 3px rgba(20, 87, 184, 0.18); }
.ask-card-head { font-size: 0.78rem; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: 0.03em; }
.ask-card-question { font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; }
.ask-card-options { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.ask-option {
  display: inline-flex; align-items: center; gap: 0.45rem; padding: 0.38rem 0.85rem;
  border: 1px solid #b8c7ea; border-radius: 999px; background: #fff; color: #1d3b7a; font: inherit; font-size: 0.92rem;
  cursor: pointer; transition: background 0.12s, border-color 0.12s, transform 0.08s;
}
.ask-option:hover { background: #e8efff; border-color: var(--accent); }
.ask-option:active { transform: scale(0.97); }
.ask-option-key {
  display: inline-grid; place-items: center; width: 1.35em; height: 1.35em; border-radius: 50%;
  background: #dfe8f8; color: var(--accent); font-size: 0.75rem; font-weight: 700; line-height: 1;
}
.ask-option.ask-option-chosen, .ask-option.ask-option-chosen:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.ask-option-chosen .ask-option-key { background: rgba(255, 255, 255, 0.25); color: #fff; }
.ask-option-static { cursor: default; opacity: 0.55; }
.ask-option-static.ask-option-chosen { opacity: 1; }
.ask-card-actions { display: flex; gap: 0.45rem; align-items: center; flex-wrap: wrap; }
.ask-card-other { flex: 1 1 12rem; min-width: 0; padding: 0.42rem 0.7rem; border: 1px solid var(--border); border-radius: 8px; font: inherit; font-size: 0.92rem; }
.ask-card-skip { color: var(--muted); text-decoration: underline; }
.ask-card-hint { font-size: 0.78rem; color: var(--muted); }
.ask-card-result { font-size: 0.9rem; color: var(--ok); font-weight: 600; }
.ask-card-result.ask-card-result-muted { color: var(--muted); font-weight: 500; }
.ask-card-done { background: transparent; border-color: var(--border); border-left-color: #8fb08f; }
.ask-card-done .ask-card-head { color: var(--muted); }
@keyframes ask-card-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes ask-card-pulse { 0%, 100% { border-left-color: var(--accent); } 50% { border-left-color: #8fb0f0; } }
