:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #eef0f4; --fg: #1b2029; --doux: #5f6878; --ligne: #dde1e8;
  --accent: #2f5d8a; --accent-fg: #ffffff; --moi: #e3ecf6; --danger: #b3261e; --ok: #1f7a4d; --attention: #8a5a00;
  --rayon: 12px; --police: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171d; --surface: #1c2029; --surface-2: #252a35; --fg: #e7eaf0; --doux: #9aa3b3; --ligne: #2e3442;
    --accent: #8db6e0; --accent-fg: #0f1520; --moi: #23324a; --danger: #f2a39c; --ok: #7fd1a7; --attention: #f0c36a; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14171d; --surface: #1c2029; --surface-2: #252a35; --fg: #e7eaf0; --doux: #9aa3b3; --ligne: #2e3442;
  --accent: #8db6e0; --accent-fg: #0f1520; --moi: #23324a; --danger: #f2a39c; --ok: #7fd1a7; --attention: #f0c36a; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.5 var(--police); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
.doux { color: var(--doux); }
.erreur { color: var(--danger); min-height: 1.5em; margin: 0; }

/* Connexion */
#connexion { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.carte-connexion { width: min(360px, 100%); background: var(--surface); border: 1px solid var(--ligne); border-radius: var(--rayon); padding: 24px; display: grid; gap: 12px; }
.carte-connexion h1 { margin: 0; font-size: 1.4rem; }
.carte-connexion p { margin: 0; }
input, textarea, select { font: inherit; color: var(--fg); background: var(--surface-2); border: 1px solid var(--ligne); border-radius: 10px; padding: 10px 12px; }
.carte-connexion button { background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 10px; padding: 10px; font-weight: 600; }

/* Barre */
#appli { height: 100dvh; display: flex; flex-direction: column; }
.barre { display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); border-bottom: 1px solid var(--ligne); background: var(--surface); }
.titre-fil { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; font-weight: 600; }
#titre-fil { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pastille { font-size: .75rem; font-weight: 500; color: var(--doux); white-space: nowrap; }
.pastille.travaille { color: var(--accent); }
.icone { background: none; border: 1px solid transparent; border-radius: 8px; min-width: 36px; height: 36px; display: inline-grid; place-items: center; text-decoration: none; color: var(--fg); font-size: 1rem; }
.icone:hover { background: var(--surface-2); }
.bascule[aria-pressed="true"] { background: var(--moi); border-color: var(--accent); }
.mobile-seul { display: none; }

/* Tiroir */
#tiroir { position: fixed; z-index: 20; top: 0; left: 0; bottom: 0; width: min(320px, 88vw); background: var(--surface); border-right: 1px solid var(--ligne); padding: 12px; padding-top: max(12px, env(safe-area-inset-top)); display: flex; flex-direction: column; gap: 10px; box-shadow: 0 0 40px rgb(0 0 0 / .25); }
#btn-nouveau { width: 100%; background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 10px; padding: 10px; font-weight: 600; }
#liste-fils { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; display: grid; gap: 2px; align-content: start; }
#liste-fils button { width: 100%; text-align: left; background: none; border: 0; border-radius: 8px; padding: 8px 10px; display: grid; gap: 1px; }
#liste-fils button:hover, #liste-fils button[aria-current="true"] { background: var(--surface-2); }
#liste-fils .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#liste-fils .d { font-size: .75rem; color: var(--doux); }
.importer summary { color: var(--doux); font-size: .85rem; cursor: pointer; }
.importer form { display: flex; gap: 6px; margin-top: 6px; }
.importer input { flex: 1; min-width: 0; font-size: .8rem; padding: 6px 8px; }
.importer button, .lien { background: none; border: 1px solid var(--ligne); border-radius: 8px; padding: 6px 10px; font-size: .85rem; }
.lien { border: 0; color: var(--doux); text-align: left; }

/* Plan : chat | aperçu */
.plan { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(340px, 44%) minmax(0, 1fr); }
.colonne-chat { min-width: 0; display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--ligne); }
#fil { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 100%; overflow-wrap: anywhere; }
.msg.moi { align-self: flex-end; background: var(--moi); border-radius: 14px 14px 4px 14px; padding: 8px 12px; max-width: 88%; white-space: pre-wrap; }
.msg.moi .voix { font-size: .72rem; color: var(--doux); display: block; }
.msg.claude { line-height: 1.55; }
.msg.claude p { margin: 0 0 .6em; }
.msg.claude p:last-child { margin-bottom: 0; }
.msg.claude pre { background: var(--surface-2); border: 1px solid var(--ligne); border-radius: 8px; padding: 10px; overflow-x: auto; font: .82rem/1.45 var(--mono); }
.msg.claude code { overflow-wrap: anywhere; font: .86em var(--mono); background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.msg.claude pre code { background: none; padding: 0; }
.msg.claude ul, .msg.claude ol { margin: 0 0 .6em; padding-left: 1.3em; }
.msg.claude h1, .msg.claude h2, .msg.claude h3 { font-size: 1rem; margin: .4em 0; }
.msg.claude a { color: var(--accent); }
.msg.claude table { border-collapse: collapse; font-size: .85rem; display: block; overflow-x: auto; }
.msg.claude td, .msg.claude th { border: 1px solid var(--ligne); padding: 4px 8px; }
.outil { font: .8rem/1.4 var(--mono); color: var(--doux); border-left: 2px solid var(--ligne); padding: 2px 0 2px 10px; }
.outil { min-width: 0; }
.outil summary { cursor: pointer; list-style: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.outil summary::before { content: "▸ "; }
.outil[open] summary::before { content: "▾ "; }
.outil.erreur-outil { border-left-color: var(--danger); }
.outil pre { white-space: pre-wrap; margin: 4px 0 0; max-height: 240px; overflow: auto; }
.accord { border: 1px solid var(--attention); background: color-mix(in srgb, var(--attention) 10%, var(--surface)); border-radius: var(--rayon); padding: 12px; display: grid; gap: 8px; }
.accord .q { font-weight: 600; }
.accord pre { margin: 0; font: .78rem/1.4 var(--mono); white-space: pre-wrap; max-height: 200px; overflow: auto; background: var(--surface); padding: 8px; border-radius: 8px; }
.accord .actions { display: flex; gap: 8px; }
.accord button { border: 0; border-radius: 8px; padding: 8px 14px; font-weight: 600; }
.accord .oui { background: var(--ok); color: #fff; }
.accord .non { background: var(--surface-2); border: 1px solid var(--ligne); }
.accord.decide { border-color: var(--ligne); background: none; opacity: .75; }
.fin { font-size: .72rem; color: var(--doux); }
.msg-erreur { color: var(--danger); font-size: .9rem; }
.curseur::after { content: "▍"; animation: clignote 1s steps(1) infinite; color: var(--accent); }
@keyframes clignote { 50% { opacity: 0; } }
.accueil { margin: auto; text-align: center; color: var(--doux); max-width: 40ch; }

/* Composer */
#composer { border-top: 1px solid var(--ligne); background: var(--surface); padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.ligne-composer { display: flex; gap: 8px; align-items: flex-end; }
#saisie { flex: 1; resize: none; max-height: 40vh; min-height: 42px; }
.rond { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--ligne); background: var(--surface-2); flex: none; display: grid; place-items: center; }
.rond.plein { background: var(--accent); color: var(--accent-fg); border: 0; }
.rond.danger { background: var(--danger); color: #fff; border: 0; }
#btn-micro[aria-pressed="true"] { background: var(--danger); color: #fff; border: 0; animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 50%, transparent); } 50% { box-shadow: 0 0 0 8px transparent; } }
.transcription { font-size: .9rem; color: var(--doux); font-style: italic; padding: 0 4px 8px; }

/* Aperçu */
.colonne-apercu { display: flex; flex-direction: column; min-height: 0; background: var(--surface-2); }
.barre-apercu { display: flex; gap: 6px; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--ligne); background: var(--surface); }
#choix-apercu { flex: 1; min-width: 0; padding: 6px 8px; }
.cadre-zone { flex: 1; min-height: 0; position: relative; display: flex; justify-content: center; }
#cadre { border: 0; width: 100%; height: 100%; background: #fff; transition: width .2s; }
.cadre-zone.telephone #cadre { width: 390px; max-width: 100%; border-left: 1px solid var(--ligne); border-right: 1px solid var(--ligne); }
.vide { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; padding: 24px; gap: 4px; }
.vide p { margin: 0; }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 8px 14px; border-radius: 10px; font-size: .9rem; z-index: 30; max-width: calc(100vw - 32px); }

@media (max-width: 820px) {
  .mobile-seul { display: inline-grid; }
  .plan { grid-template-columns: minmax(0, 1fr); }
  .colonne-chat { border-right: 0; }
  .plan .colonne-apercu { display: none; }
  .plan.vue-apercu .colonne-apercu { display: flex; }
  .plan.vue-apercu .colonne-chat { display: none; }
  #fil { padding: 12px 16px; }
}
