:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --user: #2563eb;
  --bot: #334155;
  --danger: #ef4444;
}
* { box-sizing: border-box; }
/* l'attribut hidden doit l'emporter sur les display:grid/flex ci-dessous */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 17px;
}

/* --- Connexion --- */
.login { display: grid; place-items: center; height: 100%; padding: 20px; }
.login-card {
  background: var(--panel); border-radius: 16px; padding: 32px;
  width: 100%; max-width: 380px; box-shadow: 0 10px 40px rgba(0,0,0,.35);
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; }
.subtitle { color: var(--muted); margin: 0 0 24px; }
form label { display: block; margin-bottom: 16px; font-size: 15px; color: var(--muted); }
input, textarea {
  width: 100%; margin-top: 6px; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--panel-2); background: #0b1220; color: var(--text);
  font-size: 16px; font-family: inherit;
}
button {
  background: var(--accent); color: white; border: 0; border-radius: 10px;
  padding: 12px 18px; font-size: 16px; cursor: pointer; font-weight: 600;
}
button:hover { background: var(--accent-2); }
button.ghost { background: transparent; border: 1px solid var(--panel-2); color: var(--muted); font-weight: 500; padding: 8px 14px; }
button:disabled { opacity: .5; cursor: default; }
.error { color: var(--danger); font-size: 14px; margin: 8px 0 0; }

/* --- Application : barre latérale + chat --- */
.app { display: flex; height: 100%; }

.sidebar {
  width: 280px; flex-shrink: 0; background: var(--panel);
  border-right: 1px solid var(--panel-2); display: flex; flex-direction: column;
}
.sidebar-head { padding: 14px; }
.new-btn { width: 100%; }
.conv-list { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 0 8px; }
.conv-item {
  display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-radius: 10px;
  cursor: pointer; color: var(--text); font-size: 15px;
}
.conv-item:hover { background: var(--panel-2); }
.conv-item.active { background: var(--panel-2); }
.conv-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-del {
  background: transparent; color: var(--muted); border: 0; font-size: 20px; line-height: 1;
  padding: 0 4px; opacity: 0; cursor: pointer; font-weight: 400;
}
.conv-item:hover .conv-del { opacity: 1; }
.conv-del:hover { color: var(--danger); background: transparent; }
.sidebar-foot {
  padding: 14px; border-top: 1px solid var(--panel-2);
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px;
}
.sidebar-foot #who { font-weight: 600; }
.sidebar-foot .ghost { margin-left: auto; }

.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.mobilebar {
  display: none; align-items: center; gap: 12px; padding: 10px 14px;
  background: var(--panel); border-bottom: 1px solid var(--panel-2);
}
.pill { background: var(--panel-2); color: var(--text); border-radius: 999px; padding: 3px 12px; font-size: 13px; }

.messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 760px; padding: 14px 18px; border-radius: 16px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--user); color: white; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--bot); border-bottom-left-radius: 4px; }
.msg.note { align-self: flex-start; background: transparent; color: var(--muted); font-size: 14px; font-style: italic; padding: 2px 8px; }
.welcome { color: var(--muted); text-align: center; margin: auto; max-width: 520px; line-height: 1.6; }
.welcome-hint { font-size: 14px; }

/* --- Application de la conversation --- */
.appbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 20px; border-bottom: 1px solid var(--panel-2); font-size: 15px; color: var(--muted);
}
.appbar select {
  background: #0b1220; color: var(--text); border: 1px solid var(--panel-2); border-radius: 10px;
  padding: 7px 12px; font-size: 15px; font-family: inherit; max-width: 100%;
}
.appbar select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* --- « Pas bon » sous une réponse --- */
.msg.bot .fb {
  display: block; margin-top: 8px; background: transparent; border: 0; padding: 0;
  color: var(--muted); font-size: 13px; font-weight: 400; opacity: .55; white-space: normal;
}
.msg.bot:hover .fb, .msg.bot .fb:focus-visible, .msg.bot .fb:disabled { opacity: 1; }
.msg.bot .fb:hover { background: transparent; color: var(--text); }
@media (hover: none) { .msg.bot .fb { opacity: .8; } }

/* --- QCM (questions à choix multiple) --- */
.msg.qcm { align-self: flex-start; background: var(--bot); max-width: 620px; padding: 16px 18px; }
.qcm-block { margin-bottom: 12px; }
.qcm-q { font-weight: 600; margin-bottom: 10px; }
.qcm-opts { display: flex; flex-direction: column; gap: 8px; }
.qcm-opt {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  width: 100%; text-align: left; background: #0b1220; border: 1px solid var(--panel-2);
  color: var(--text); border-radius: 10px; padding: 11px 14px; font-weight: 500; cursor: pointer;
}
.qcm-opt:hover { border-color: var(--accent); background: #0d1730; }
.qcm-opt.sel { border-color: var(--accent); background: #16264d; }
.qcm-opt.sel .qcm-label::before { content: "✓ "; color: #4ade80; }
.qcm-label { font-size: 16px; }
.qcm-desc { font-size: 13px; color: var(--muted); font-weight: 400; }
.qcm-valider { margin-top: 6px; width: 100%; }
.qcm.answered { opacity: .7; }
.qcm.answered .qcm-opt { cursor: default; }
.qcm.answered .qcm-opt:not(.sel) { display: none; }
.qcm.answered .qcm-valider { display: none; }

/* --- Bandeau d'activité (actions de Claude, séparées du fil) --- */
.activity { background: #172033; border-top: 1px solid var(--panel-2); }
.activity-head {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  background: transparent; border: 0; color: var(--muted); padding: 10px 20px;
  font-size: 14px; font-weight: 500; cursor: pointer; border-radius: 0;
}
.activity-head:hover { background: rgba(255,255,255,.03); }
.activity-head-left { display: inline-flex; align-items: center; gap: 8px; }
.activity-log { max-height: 120px; overflow-y: auto; padding: 0 20px 12px; font-size: 13px; color: var(--muted); }
.act-line { padding: 3px 0; white-space: pre-wrap; word-wrap: break-word; }
.activity.collapsed .activity-log { display: none; }
.chev { transition: transform .15s ease; }
.activity.collapsed .chev { transform: rotate(-90deg); }
.spinner {
  display: none; width: 13px; height: 13px; border: 2px solid var(--panel-2);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite;
}
.activity.working .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* état « en cours » vs « terminé » */
.activity.working { border-left: 3px solid var(--accent); }
.activity.working #activity-label { color: var(--text); }
.activity.done { background: #0e2a1c; border-left: 3px solid #22c55e; }
.activity.done #activity-label { color: #4ade80; font-weight: 700; }
.activity.done { animation: doneflash .5s ease; }
@keyframes doneflash { from { background: #14532d; } to { background: #0e2a1c; } }

/* --- images jointes (bouton 📎, collage Ctrl+V, glisser-déposer) --- */
.msg-img { max-width: 260px; max-height: 260px; border-radius: 10px; margin-top: 6px; display: block; }
.attach-preview { display: flex; gap: 10px; flex-wrap: wrap; padding: 8px 20px; background: var(--panel); border-top: 1px solid var(--panel-2); }
.attach-item { position: relative; }
.attach-item img { max-height: 90px; max-width: 140px; border-radius: 8px; display: block; background: var(--panel-2); min-width: 40px; min-height: 40px; }
.attach-item button {
  position: absolute; top: -7px; right: -7px; background: var(--danger); color: #fff; border: 0;
  border-radius: 50%; width: 22px; height: 22px; padding: 0; font-size: 15px; line-height: 1; cursor: pointer;
}
.attach-item.attach-file { display: flex; align-items: center; }
.attach-item.attach-file span {
  display: block; max-width: 200px; padding: 8px 14px; border-radius: 8px; background: var(--panel-2);
  font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.msg-file {
  display: inline-block; margin-top: 6px; padding: 6px 12px; border-radius: 8px; background: var(--panel-2);
  font-size: 13px;
}
.attach { background: transparent; border: 1px solid var(--panel-2); font-size: 20px; padding: 0 12px; align-self: flex-end; }
.attach:hover { background: var(--panel-2); }
.chat.dragging { outline: 2px dashed var(--accent); outline-offset: -6px; }

/* --- file d'attente : demandes empilées pendant que Claude travaille --- */
.queue { padding: 8px 20px 10px; background: var(--panel); border-top: 1px solid var(--panel-2); }
.queue-head { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
#queue-label { flex: 1; }
.queue-btn { font-size: 13px; padding: 4px 10px; font-weight: 500; }
.queue-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.queue-item {
  display: flex; align-items: center; gap: 8px; background: #0b1220;
  border: 1px dashed var(--panel-2); border-radius: 8px; padding: 6px 10px; font-size: 14px;
}
.queue-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.queue-del { background: transparent; color: var(--muted); border: 0; font-size: 18px; line-height: 1; padding: 0 4px; cursor: pointer; }
.queue-del:hover { color: var(--danger); background: transparent; }

/* --- étapes en direct --- */
.msg.tasks { align-self: flex-start; background: var(--bot); max-width: 620px; }
.tasks-h { font-weight: 600; margin-bottom: 8px; }
.task-line { padding: 3px 0; }
.task-line.completed { color: var(--muted); text-decoration: line-through; }

/* --- confirmation action sensible --- */
.msg.confirm { align-self: flex-start; background: #3a2a12; border: 1px solid #a16207; max-width: 620px; }
.confirm-h { font-weight: 700; color: #fbbf24; margin-bottom: 8px; }
.confirm-cmd { font-family: ui-monospace, monospace; font-size: 13px; background: #0b1220; padding: 8px 10px; border-radius: 8px; margin-bottom: 8px; overflow-x: auto; }
.confirm-q { margin-bottom: 10px; }
.confirm-row { display: flex; gap: 10px; }
.confirm-yes { background: #16a34a; }
.confirm-yes:hover { background: #15803d; }
.confirm.answered .confirm-row { display: none; }

/* --- bouton renommer --- */
.conv-ren { background: transparent; color: var(--muted); border: 0; font-size: 14px; padding: 0 2px; opacity: 0; cursor: pointer; }
.conv-item:hover .conv-ren { opacity: 1; }
.conv-ren:hover { color: var(--text); background: transparent; }

/* --- bouton arrêter (séparé d'Envoyer : on peut empiler pendant un tour) --- */
.stop-btn { background: var(--danger); }
.stop-btn:hover { background: #dc2626; }

.composer { display: flex; gap: 10px; padding: 16px 20px; background: var(--panel); border-top: 1px solid var(--panel-2); }
.composer textarea { flex: 1; resize: none; max-height: 160px; margin: 0; }
.composer button { align-self: flex-end; }

.typing { display: inline-flex; gap: 4px; }
.typing span { width: 7px; height: 7px; background: var(--muted); border-radius: 50%; animation: blink 1.2s infinite both; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2 } 40% { opacity: 1 } }

/* --- Mobile : la barre latérale devient un tiroir --- */
@media (max-width: 720px) {
  body { font-size: 16px; }
  .mobilebar { display: flex; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 20;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.4);
  }
  .sidebar.open { transform: translateX(0); }
  .messages { padding: 16px; }
}

/* --- Atelier : rendu du code et du texte mis en forme dans les réponses --- */
:root { --accent: #7c3aed; --accent-2: #6d28d9; --user: #6d28d9; }
.msg.bot.md { white-space: normal; }
.msg.bot.md p { margin: 0 0 10px; white-space: pre-wrap; }
.msg.bot.md p:last-child { margin-bottom: 0; }
.msg.bot.md h1, .msg.bot.md h2, .msg.bot.md h3 { font-size: 17px; margin: 12px 0 6px; }
.msg.bot.md ul, .msg.bot.md ol { margin: 4px 0 10px; padding-left: 22px; }
.msg.bot.md li { margin: 2px 0; }
.msg code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; background: #0b1220; padding: 1px 6px; border-radius: 5px; }
.msg pre { background: #0b1220; border: 1px solid var(--panel-2); border-radius: 10px; padding: 12px 14px; overflow-x: auto; margin: 8px 0 10px; white-space: pre; }
.msg pre code { background: transparent; padding: 0; font-size: 13.5px; line-height: 1.45; }
.msg.bot.md a { color: #c4b5fd; }
.apercu-link { display: block; text-align: center; text-decoration: none; margin-bottom: 8px; padding: 8px 14px; border-radius: 10px; background: #1e1b4b; color: #c4b5fd; border: 1px solid #4c1d95; font-weight: 600; font-size: 14px; width: 100%; }
.apercu-link:hover { background: #2e1065; }
