/* Thème Gruvbox. Clair par défaut, sombre selon le système (auto), ou forcé
   par l'utilisateur : data-theme="light" ou "dark" sur <html> (theme.js). */
:root {
  --bg: #fbf1c7;
  --panel: #f9f5d7;
  --side: #f2e5bc;
  --text: #3c3836;
  --muted: #7c6f64;
  --line: #d5c4a1;
  --accent: #076678;
  --accent-text: #fbf1c7;
  --gold: #b57614;
  --user: #ebdbb2;
  --code-bg: #f2e5bc;
  --danger: #9d0006;
  --ok: #79740e;
  --warn: #af3a03;
  --add-bg: #e5e7b4;
  --add: #79740e;
  --del-bg: #f3d3c0;
  --del: #9d0006;
  color-scheme: light;
  --radius: 10px;
  --mono: ui-monospace, "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #282828;
    --panel: #32302f;
    --side: #1d2021;
    --text: #ebdbb2;
    --muted: #a89984;
    --line: #504945;
    --accent: #fabd2f;
    --accent-text: #282828;
    --gold: #fabd2f;
    --user: #3c3836;
    --code-bg: #1d2021;
    --danger: #fb4934;
    --ok: #b8bb26;
    --warn: #fe8019;
    --add-bg: #3e3e28;
    --add: #b8bb26;
    --del-bg: #482d2a;
    --del: #fb4934;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #282828;
  --panel: #32302f;
  --side: #1d2021;
  --text: #ebdbb2;
  --muted: #a89984;
  --line: #504945;
  --accent: #fabd2f;
  --accent-text: #282828;
  --gold: #fabd2f;
  --user: #3c3836;
  --code-bg: #1d2021;
  --danger: #fb4934;
  --ok: #b8bb26;
  --warn: #fe8019;
  --add-bg: #3e3e28;
  --add: #b8bb26;
  --del-bg: #482d2a;
  --del: #fb4934;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--sans); }
button { font: inherit; cursor: pointer; border-radius: 7px; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 5px 12px; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.danger { color: var(--danger); border-color: var(--danger); }
button.primary, #send-btn, .login-card button { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.link { border: none; background: none; padding: 2px 4px; color: var(--muted); }
button.link:hover { color: var(--text); text-decoration: underline; }
button.icon { border: none; background: none; font-size: 20px; padding: 2px 8px; }
.muted { color: var(--muted); font-size: 13px; }
a { color: var(--accent); }
code, pre { font-family: var(--mono); font-size: 13px; }

/* --- connexion --- */
.login-page { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.login-card { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.login-card h1 { display: flex; align-items: center; gap: 10px; margin: 0 0 18px; font-size: 22px; }
.login-card label { display: block; margin-bottom: 14px; font-size: 14px; }
.login-card input { display: block; width: 100%; margin-top: 4px; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; }
.login-card button { width: 100%; padding: 9px; }
.login-error { color: var(--danger); background: var(--del-bg); padding: 8px 10px; border-radius: 8px; font-size: 14px; }

/* --- structure --- */
#app { display: grid; grid-template-columns: 280px 1fr; height: 100%; }
#sidebar { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 8px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.status-line { display: flex; align-items: center; gap: 6px; padding: 0 14px 10px; font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); }
.dot.ko { background: var(--danger); }
#conv-list { flex: 1; overflow-y: auto; padding: 0 6px; }
.conv-item { display: block; width: 100%; text-align: left; border: none; background: none; padding: 8px 10px; border-radius: 8px; margin-bottom: 2px; }
.conv-item:hover { background: var(--panel); }
.conv-item.active { background: var(--panel); box-shadow: inset 3px 0 0 var(--accent); }
.conv-item .t { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.conv-item .s { display: flex; gap: 6px; align-items: center; font-size: 11.5px; color: var(--muted); }
.badge { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.badge.run { color: var(--accent); border-color: var(--accent); }
.badge.wait { color: var(--warn); border-color: var(--warn); }
.badge.taint { color: var(--danger); border-color: var(--danger); }
.side-foot { display: flex; flex-wrap: wrap; gap: 2px 6px; padding: 10px; border-top: 1px solid var(--line); }
.side-foot form { margin: 0; }

#main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#conv-head { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
#toggle-side { display: none; }
.title-wrap { flex: 1; min-width: 0; }
#conv-title { font-size: 16px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-actions { display: flex; align-items: center; gap: 8px; }
.run-state { font-size: 12.5px; color: var(--muted); }
.run-state.running::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 6px; animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .3 } to { opacity: 1 } }

#messages { flex: 1; overflow-y: auto; padding: 18px max(18px, calc((100% - 860px) / 2)); }
.empty { color: var(--muted); text-align: center; margin-top: 18vh; }
.msg { margin: 0 0 16px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble { background: var(--user); border-radius: 14px 14px 4px 14px; padding: 9px 14px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user .skill-tag { display: block; font-size: 11.5px; color: var(--gold); margin-bottom: 2px; }
.msg .time { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; text-align: right; }
.msg.assistant .body { overflow-wrap: anywhere; }
.msg.assistant.partial .body::after { content: " ▍"; color: var(--accent); }
.note { font-size: 12.5px; color: var(--muted); text-align: center; margin: 10px 0 16px; }
.note.err { color: var(--danger); }
.note.taint { color: var(--danger); }

details.reasoning { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
details.reasoning summary { cursor: pointer; user-select: none; }
details.reasoning .r-body { white-space: pre-wrap; border-left: 2px solid var(--line); padding: 4px 0 4px 10px; margin-top: 4px; max-height: 360px; overflow-y: auto; }

.tool { border: 1px solid var(--line); border-radius: var(--radius); margin: 8px 0; background: var(--panel); font-size: 13px; }
.tool > summary { list-style: none; cursor: pointer; padding: 6px 10px; display: flex; gap: 8px; align-items: center; }
.tool > summary::-webkit-details-marker { display: none; }
.tool > summary::before { content: "▸"; color: var(--muted); }
.tool[open] > summary::before { content: "▾"; }
.tool .name { font-family: var(--mono); font-weight: 600; }
.tool .args-short { color: var(--muted); font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.tool .st { font-size: 11.5px; }
.tool .st.ok { color: var(--ok); }
.tool .st.err { color: var(--danger); }
.tool .st.wait { color: var(--warn); }
.tool pre { margin: 0; padding: 8px 10px; border-top: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 420px; overflow-y: auto; background: var(--code-bg); }

.approval { border: 1.5px solid var(--warn); border-radius: var(--radius); padding: 10px 12px; margin: 8px 0 16px; background: var(--panel); }
.approval.tainted { border-color: var(--danger); }
.approval .a-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.approval .a-sum { font-weight: 600; }
.approval .a-warn { color: var(--danger); font-size: 12.5px; margin: 4px 0; }
.approval pre { max-height: 360px; overflow: auto; background: var(--code-bg); padding: 8px 10px; border-radius: 7px; margin: 8px 0; white-space: pre-wrap; }
.approval pre.a-headers { margin: 8px 0 6px; padding: 6px 10px; font-size: 12.5px; }
.approval textarea { width: 100%; min-height: 90px; font: 13px var(--mono); border-radius: 7px; border: 1px solid var(--line); background: var(--bg); color: var(--text); padding: 8px; }
.approval .a-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.approval .a-actions input { flex: 1; min-width: 140px; padding: 5px 8px; border-radius: 7px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; }
.approval.resolved { border-color: var(--line); opacity: .8; }
.approval .a-result { font-size: 13px; color: var(--muted); }

#composer { position: relative; display: flex; gap: 8px; padding: 12px max(18px, calc((100% - 860px) / 2)) 16px; border-top: 1px solid var(--line); background: var(--panel); }
#input { flex: 1; resize: none; max-height: 40vh; overflow-y: hidden; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; }
#input:focus { outline: none; border-color: var(--accent); }
#skill-suggest { position: absolute; bottom: 100%; left: max(18px, calc((100% - 860px) / 2)); margin: 0 0 4px; padding: 4px; list-style: none; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; max-height: 240px; overflow-y: auto; min-width: 280px; box-shadow: 0 6px 20px rgba(0,0,0,.15); }
#skill-suggest li { padding: 5px 8px; border-radius: 6px; cursor: pointer; font-size: 13.5px; }
#skill-suggest li.sel, #skill-suggest li:hover { background: var(--user); }
#skill-suggest .d { color: var(--muted); font-size: 12px; display: block; }

#panel { flex: 1; overflow-y: auto; padding: 18px max(18px, calc((100% - 860px) / 2)); }
#panel h2 { font-size: 17px; margin-top: 0; }
#panel table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
#panel th, #panel td { border-bottom: 1px solid var(--line); text-align: left; padding: 6px 8px; vertical-align: top; }

/* --- réglages --- */
.settings h3 { font-size: 16px; margin: 0 0 10px; }
.settings h4 { font-size: 14px; margin: 16px 0 8px; }
.settings-nav { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 6px 0 14px; font-size: 13.5px; }
.settings-section { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 16px; background: var(--panel); }
.settings-banner:empty { display: none; }
.settings-banner { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; border: 1.5px solid var(--warn); border-radius: var(--radius); padding: 8px 12px; margin: 0 0 14px; font-size: 13.5px; }
.f-row { display: grid; gap: 4px; margin: 0 0 12px; }
.f-row.f-check { display: flex; gap: 8px; align-items: center; }
.settings-section hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
.f-label { font-size: 13.5px; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.f-help { font-size: 12.5px; }
.f-row input, .f-row select, .f-row textarea, .oauth-flow input { font: inherit; padding: 6px 9px; border-radius: 7px; border: 1px solid var(--line); background: var(--bg); color: var(--text); width: 100%; }
.f-row.f-check input { width: auto; }
.f-row textarea { font-family: var(--mono); font-size: 13px; resize: vertical; }
.f-row input:disabled, .f-row textarea:disabled { opacity: .6; }
.badge.src { font-weight: 400; }
.conn-card { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 0 0 10px; }
.conn-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 8px; }
.check-lines { list-style: none; padding: 0; margin: 8px 0 0; font-size: 13px; }
.check-lines li.err { color: var(--danger); }
.check-lines li.ok { color: var(--ok); }
.oauth-flow { display: grid; gap: 6px; margin-top: 10px; font-size: 13.5px; }
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; width: min(380px, 100%); display: grid; gap: 10px; }
.modal h2 { margin: 0; font-size: 17px; }
.modal input { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.modal-actions { display: flex; gap: 8px; }

#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 10; }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent); padding: 8px 12px; border-radius: 8px; max-width: 360px; font-size: 13.5px; box-shadow: 0 6px 20px rgba(0,0,0,.15); }
.toast.err { border-left-color: var(--danger); }

/* --- markdown --- */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md .md-table { margin: 0 0 10px; }
.md h2, .md h3, .md h4, .md h5, .md h6 { margin: 16px 0 8px; line-height: 1.3; }
.md h2 { font-size: 18px; } .md h3 { font-size: 16px; } .md h4, .md h5, .md h6 { font-size: 15px; }
.md ul, .md ol { padding-left: 22px; }
.md li.task { list-style: none; margin-left: -20px; }
.md blockquote { border-left: 3px solid var(--line); padding-left: 12px; color: var(--muted); }
.md code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
.md pre.md-code { position: relative; background: var(--code-bg); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.md pre.md-code code { background: none; padding: 0; }
.md-copy { position: absolute; top: 6px; right: 6px; font-size: 11px; padding: 1px 7px; opacity: 0; }
pre.md-code:hover .md-copy { opacity: 1; }
.md .md-table { overflow-x: auto; }
.md table { border-collapse: collapse; font-size: 14px; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 9px; }
.md th { background: var(--code-bg); }
.md hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }
.md-img { color: var(--muted); font-style: italic; }
.d-add { color: var(--add); background: var(--add-bg); display: block; }
.d-del { color: var(--del); background: var(--del-bg); display: block; }
.d-hunk { color: var(--muted); display: block; }
.d-file { font-weight: 600; display: block; }
.d-ctx { display: block; }

@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  #sidebar { position: fixed; inset: 0 25% 0 0; z-index: 5; transform: translateX(-100%); transition: transform .2s; }
  #app.side-open #sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  #toggle-side { display: block; }
  .msg.user .bubble { max-width: 95%; }
}

/* --- mémoire --- */
.proposal .a-actions { margin-top: 6px; }
.proposal p { margin: 4px 0; }
#panel details { margin: 18px 0; }
#panel details summary { cursor: pointer; color: var(--muted); font-size: 13.5px; margin-bottom: 8px; }
#panel .conn-card .md { margin: 4px 0 8px; font-size: 13.5px; }

/* --- auto mode --- */
.auto-toggle { font-size: 13px; padding: 3px 10px; border-radius: 999px; }
.auto-toggle.on { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }
.approval .a-auto { color: var(--muted); font-size: 12.5px; margin: 4px 0; font-style: italic; }

/* --- focus aux couleurs du thème --- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline-offset: 0; }

/* --- barre latérale : accueil, recherche, sections --- */
a.brand { color: inherit; text-decoration: none; }
.side-search { padding: 0 10px 6px; }
.side-search input { width: 100%; font: inherit; font-size: 13.5px; padding: 5px 9px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel); color: var(--text); }
.side-section { display: block; width: 100%; text-align: left; border: none; background: none; color: var(--muted); font-size: 12.5px; padding: 10px 10px 4px; }
.side-section:hover { color: var(--text); }
.conv-item .snip { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* --- contamination et validations en attente --- */
.taint-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 8px max(18px, calc((100% - 860px) / 2)); font-size: 13px; border-bottom: 1px solid var(--line); background: var(--panel); color: var(--danger); }
.taint-bar span { flex: 1; min-width: 220px; }
.approval-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 6px max(18px, calc((100% - 860px) / 2)); font-size: 13px; border-top: 1px solid var(--warn); background: var(--panel); }
.approval-bar > span:first-child { font-weight: 600; color: var(--warn); }
.approval .a-why { font-size: 13px; margin: 4px 0; }

/* --- accueil --- */
.home { display: grid; gap: 16px; }
.home-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; background: var(--panel); }
.home-card h2 { font-size: 15px; margin: 0 0 10px; }
.home-row { display: block; width: 100%; text-align: left; margin: 0 0 6px; padding: 8px 10px; background: var(--bg); }
.home-row .muted { font-size: 12.5px; }
.report { border-top: 1px solid var(--line); padding: 8px 0; }
.report:first-of-type { border-top: none; }
.report summary { cursor: pointer; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.report .md { margin: 10px 0; }
.stats { display: flex; flex-wrap: wrap; gap: 10px; }
.stat { display: grid; padding: 8px 12px; border-radius: 8px; background: var(--bg); min-width: 110px; }
.stat strong { font-size: 20px; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.hl strong { color: var(--warn); }
table.jobs td.actions { white-space: nowrap; }
table.jobs td.actions button { margin: 0 4px 4px 0; }
.err-line { color: var(--danger); font-size: 12.5px; }

/* --- lectures repliées --- */
.tool-group { margin: 6px 0 10px; }
.tool-group > summary { cursor: pointer; font-size: 13px; color: var(--muted); padding: 4px 10px; border: 1px dashed var(--line); border-radius: 8px; list-style-position: inside; }
.tool-group > summary:hover { color: var(--text); border-color: var(--accent); }
.tool-group[open] > summary { margin-bottom: 6px; }
.tool-group > .msg { margin-left: 12px; }

/* --- historique et édition des propositions --- */
.history { margin: 8px 0 4px; padding: 8px 10px; border-radius: 8px; background: var(--bg); font-size: 13px; }
.history .h-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 3px 0; }
.history .h-view { margin: 4px 0 8px; }
#panel tr.h-line td { border-bottom: none; padding: 0 8px; }
.p-edit { display: grid; gap: 6px; margin: 8px 0; }
.p-edit input, .p-edit select, .p-edit textarea { font: inherit; padding: 6px 9px; border-radius: 7px; border: 1px solid var(--line); background: var(--bg); color: var(--text); width: 100%; }
.p-edit textarea { font-family: var(--mono); font-size: 13px; resize: vertical; }
.tools > .tool-group { margin: 4px 0; }

/* --- activité de l'agent pendant une réponse --- */
.activity-bar { display: flex; gap: 8px; align-items: center; padding: 6px max(18px, calc((100% - 860px) / 2)); font-size: 13px; color: var(--text); border-top: 1px solid var(--line); background: var(--panel); white-space: nowrap; overflow: hidden; }
.activity-bar span:last-child { overflow: hidden; text-overflow: ellipsis; }
.activity-bar .dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite alternate; }
#input { min-height: 2.75em; }
