:root {
  --bg: #F6F4EF;
  --surface: #FFFFFF;
  --sidebar: #EEEBE3;
  --ink: #1C2321;
  --ink-2: #4B5552;
  --ink-3: #848C88;
  --line: #E1DDD2;
  --accent: #0E5E5C;
  --accent-ink: #FFFFFF;
  --accent-soft: #DCEBE8;
  --gold: #C9922E;
  --ok: #2F7D4F;
  --warn: #B7791F;
  --err: #B23A3A;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(28, 35, 33, .06), 0 6px 24px rgba(28, 35, 33, .06);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151A19; --surface: #1D2422; --sidebar: #111615; --ink: #ECEFED; --ink-2: #B5BDB9; --ink-3: #7D8783;
    --line: #2C3533; --accent: #3FA79F; --accent-ink: #0B1211; --accent-soft: #1F3533; --gold: #E2B35A;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 24px rgba(0,0,0,.25); color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.55 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- Boutons ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 10px; font-weight: 500; font-size: 14px; white-space: nowrap; }
.btn:hover { border-color: var(--ink-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--primary, .btn--accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn--primary:hover, .btn--accent:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn--ghost { background: transparent; }
.btn--danger { color: var(--err); }
.btn--block { width: 100%; justify-content: center; padding: 11px; }
.btn--sm { padding: 5px 10px; font-size: 13px; }
.icon-btn { width: 34px; height: 34px; display: inline-grid; place-items: center; border: 0; background: transparent; border-radius: 9px; color: var(--ink-2); font-size: 18px; }
.icon-btn:hover { background: var(--line); color: var(--ink); }

/* ---------- Connexion ---------- */
.login-page { display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 600px at 20% -10%, var(--accent-soft), transparent), var(--bg); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 36px 32px; box-shadow: var(--shadow); }
.login-sub { color: var(--ink-2); margin: 10px 0 24px; }
.login-card label { display: block; font-weight: 500; font-size: 14px; margin-bottom: 14px; }
.login-card input { display: block; width: 100%; margin-top: 6px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; font: inherit; background: var(--bg); color: var(--ink); }
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.form-error { color: var(--err); font-size: 14px; margin: 0 0 12px; }
.login-foot { color: var(--ink-3); font-size: 13px; text-align: center; margin: 18px 0 0; }

.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; letter-spacing: -.01em; }
.brand b { font-weight: 700; color: var(--accent); }
.brand--lg { font-size: 22px; }

/* ---------- Mise en page ---------- */
.layout { display: grid; grid-template-columns: 280px 1fr; height: 100vh; height: 100dvh; }
.sidebar { background: var(--sidebar); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; padding: 14px 12px; gap: 12px; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px; }
.btn--new { justify-content: flex-start; background: var(--surface); }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -4px; padding: 0 4px; }
.conv-group { font-size: 12px; color: var(--ink-3); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 12px 10px 4px; }
.conv-item { display: flex; align-items: center; gap: 6px; border: 0; background: transparent; text-align: left; padding: 8px 10px; border-radius: 9px; color: var(--ink-2); font-size: 14px; }
.conv-item span { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.conv-item:hover { background: rgba(0,0,0,.04); color: var(--ink); }
.conv-item.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.conv-item .del { opacity: 0; font-size: 13px; padding: 2px 6px; border-radius: 6px; color: var(--ink-3); }
.conv-item:hover .del { opacity: 1; }
.conv-item .del:hover { color: var(--err); background: var(--line); }
.sidebar-foot { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 12px; }
.env-links { display: flex; flex-direction: column; gap: 2px; }
.env-link { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 8px; color: var(--ink-2); text-decoration: none; font-size: 14px; }
.env-link:hover { background: rgba(0,0,0,.04); color: var(--ink); }
.env-link::after { content: "↗"; margin-left: auto; color: var(--ink-3); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.env-link--recette .dot { background: var(--gold); }
.env-link--prod .dot { background: var(--ok); }
.me { display: flex; align-items: center; gap: 10px; padding: 4px 6px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 600; font-size: 14px; flex: none; }
.me-txt { flex: 1; min-width: 0; line-height: 1.25; }
.me-txt strong { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-txt small { color: var(--ink-3); font-size: 12px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 20px; border-bottom: 1px solid var(--line); min-height: 58px; }
.conv-title { font-size: 15px; font-weight: 600; margin: 0; flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; cursor: text; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.mode-badge { font-size: 12px; font-weight: 600; color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); padding: 4px 9px; border-radius: 99px; }

/* ---------- Fil de discussion ---------- */
.thread { flex: 1; overflow-y: auto; padding: 28px 20px 12px; scroll-behavior: smooth; }
.thread > * { max-width: 780px; margin-left: auto; margin-right: auto; }
.empty { text-align: center; padding-top: 10vh; }
.empty h2 { font-size: 28px; letter-spacing: -.02em; margin: 0 0 10px; font-weight: 650; }
.empty p { color: var(--ink-2); max-width: 520px; margin: 0 auto 28px; }
.suggestions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; text-align: left; }
.suggestion { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 14px; font-size: 14px; color: var(--ink-2); text-align: left; }
.suggestion:hover { border-color: var(--accent); color: var(--ink); }

.msg { margin-bottom: 26px; display: flex; flex-direction: column; }
.msg-user { align-items: flex-end; }
.msg-user .bubble { background: var(--surface); border: 1px solid var(--line); border-radius: 18px 18px 4px 18px; padding: 10px 16px; max-width: 85%; white-space: pre-wrap; word-wrap: break-word; }
.msg-author { font-size: 12px; color: var(--ink-3); margin: 0 6px 4px; }
.msg-files { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 6px; max-width: 85%; }
.file-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; background: var(--accent-soft); color: var(--ink); border-radius: 8px; padding: 4px 10px; }
.msg-assistant .who { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.msg-assistant .who img { width: 22px; height: 22px; }
.md { overflow-wrap: anywhere; }
.md p { margin: 0 0 .7em; }
.md ul, .md ol { padding-left: 1.3em; margin: 0 0 .7em; }
.md code { font-family: var(--mono); font-size: .88em; background: var(--line); padding: 1px 5px; border-radius: 5px; }
.md pre { background: var(--sidebar); padding: 12px; border-radius: 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md h1, .md h2, .md h3 { font-size: 1.05em; margin: 1em 0 .4em; }
.status-line { display: flex; align-items: center; gap: 10px; color: var(--ink-2); font-size: 14px; margin: 4px 0 8px; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.steps { margin: 2px 0 10px; font-size: 13px; color: var(--ink-3); }
.steps summary { cursor: pointer; list-style: none; display: inline-flex; gap: 6px; align-items: center; padding: 3px 8px; border-radius: 7px; }
.steps summary:hover { background: var(--line); color: var(--ink-2); }
.steps summary::before { content: "▸"; transition: transform .15s; }
.steps[open] summary::before { transform: rotate(90deg); }
.steps ol { list-style: none; margin: 6px 0 0; padding: 0 0 0 10px; border-left: 2px solid var(--line); }
.steps li { padding: 2px 0 2px 10px; }

.deploy-card { display: flex; align-items: center; gap: 12px; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 14px; margin-top: 6px; box-shadow: var(--shadow); }
.deploy-card .ico { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: color-mix(in srgb, var(--gold) 18%, transparent); color: var(--gold); flex: none; font-size: 16px; }
.deploy-card.ok .ico { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.deploy-card.ko .ico { background: color-mix(in srgb, var(--err) 14%, transparent); color: var(--err); }
.deploy-card .txt { flex: 1; min-width: 0; }
.deploy-card strong { display: block; font-size: 14px; }
.deploy-card small { color: var(--ink-3); font-size: 13px; }
.error-line { color: var(--err); font-size: 14px; }

/* ---------- Saisie ---------- */
.composer { margin: 0 auto 18px; width: calc(100% - 40px); max-width: 780px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); padding: 10px 12px 8px; transition: border-color .15s; }
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.composer textarea { width: 100%; resize: none; border: 0; outline: 0; background: transparent; font: inherit; color: var(--ink); padding: 6px 6px 4px; max-height: 260px; min-height: 28px; }
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.composer-left { display: flex; align-items: center; gap: 2px; min-width: 0; }
.hint { font-size: 12px; color: var(--ink-3); margin-left: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.send-btn { width: 36px; height: 36px; border: 0; border-radius: 11px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }
.send-btn:disabled { background: var(--line); color: var(--ink-3); cursor: not-allowed; }
.mic.recording { color: #fff; background: var(--err); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--err) 45%, transparent); } 50% { box-shadow: 0 0 0 7px transparent; } }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; }
.attachments:not(:empty) { padding: 4px 4px 8px; }
.att { position: relative; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 5px 28px 5px 6px; font-size: 13px; max-width: 220px; background: var(--bg); }
.att img, .att .att-ico { width: 38px; height: 38px; border-radius: 7px; object-fit: cover; flex: none; }
.att .att-ico { display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 11px; }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att small { display: block; color: var(--ink-3); font-size: 11px; }
.att button { position: absolute; top: 3px; right: 3px; border: 0; background: transparent; color: var(--ink-3); width: 20px; height: 20px; border-radius: 6px; font-size: 12px; }
.att button:hover { background: var(--line); color: var(--ink); }

.drop-overlay { position: fixed; inset: 0; background: color-mix(in srgb, var(--accent) 16%, transparent); backdrop-filter: blur(2px); display: none; place-items: center; z-index: 50; pointer-events: none; }
.drop-overlay div { border: 2px dashed var(--accent); background: var(--surface); padding: 28px 40px; border-radius: 18px; font-weight: 600; color: var(--accent); }
.drop-overlay.show { display: grid; }

/* ---------- Panneau latéral ---------- */
.panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100vw); background: var(--surface); border-left: 1px solid var(--line); box-shadow: -10px 0 40px rgba(0,0,0,.12); transform: translateX(105%); transition: transform .22s ease; z-index: 40; display: flex; flex-direction: column; }
.panel.open { transform: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.panel-head h2 { font-size: 17px; margin: 0; }
.panel-body { flex: 1; overflow-y: auto; padding: 18px 20px 28px; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.25); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 39; }
.scrim.show { opacity: 1; pointer-events: auto; }
.tabs { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; margin-bottom: 16px; }
.tabs button { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; font-size: 14px; color: var(--ink-2); }
.tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }
.section { margin-bottom: 24px; }
.section h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); margin: 0 0 10px; }
.note { color: var(--ink-2); font-size: 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-top: 1px solid var(--line); font-size: 14px; }
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .grow strong { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.list .grow small { color: var(--ink-3); font-size: 12px; }
.tag { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap; }
.tag--held { background: color-mix(in srgb, var(--gold) 18%, transparent); border-color: transparent; color: var(--warn); }
.tag--ok { background: color-mix(in srgb, var(--ok) 15%, transparent); border-color: transparent; color: var(--ok); }
.tag--ko { background: color-mix(in srgb, var(--err) 13%, transparent); border-color: transparent; color: var(--err); }
.mono { font-family: var(--mono); font-size: 12px; color: var(--ink-3); }
.scores { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px; }
.score { border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-align: center; }
.score b { display: block; font-size: 26px; letter-spacing: -.02em; }
.score small { color: var(--ink-3); font-size: 12px; }
.score.good b { color: var(--ok); } .score.mid b { color: var(--warn); } .score.bad b { color: var(--err); }
.issue-level { font-size: 11px; font-weight: 700; text-transform: uppercase; width: 92px; flex: none; }
.lvl-critique { color: var(--err); } .lvl-erreur { color: var(--err); } .lvl-avertissement { color: var(--warn); } .lvl-info { color: var(--ink-3); }
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
.field { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); font: inherit; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.data th { color: var(--ink-3); font-weight: 600; font-size: 12px; text-transform: uppercase; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 60; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.only-mobile { display: none; }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 290px; z-index: 45; transform: translateX(-105%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .only-mobile { display: inline-grid; }
  .topbar { padding: 8px 12px; }
  .top-actions .btn { padding: 6px 9px; font-size: 13px; }
  #btn-usage, .mode-badge { display: none; }
  .hint { display: none; }
  .composer { width: calc(100% - 20px); margin-bottom: 10px; }
  .thread { padding: 18px 12px 8px; }
  .scores { grid-template-columns: repeat(2, 1fr); }
  .suggestions { grid-template-columns: 1fr; }
}
