:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --side: #ecebe5;
  --text: #1d1d1b;
  --muted: #6b6a64;
  --line: #dcdad2;
  --accent: #1f5f8b;
  --accent-text: #ffffff;
  --user: #e3edf4;
  --code: #f0efe9;
  --danger: #a3271f;
  --ok: #2c6e49;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171817;
    --panel: #1f201f;
    --side: #131413;
    --text: #e9e8e3;
    --muted: #9a9993;
    --line: #333432;
    --accent: #6fb1dc;
    --accent-text: #0e1a22;
    --user: #24313a;
    --code: #282a28;
    --danger: #e3837b;
    --ok: #7fc49b;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; margin-top: 1.6rem; }
p { margin: .5rem 0; }
.muted { color: var(--muted); }
.small { font-size: .82rem; margin-top: .2rem; }
.error { color: var(--danger); min-height: 1.4em; }
code, pre { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .88em; }
code { background: var(--code); padding: .1em .35em; border-radius: 4px; }
pre { background: var(--code); padding: .8rem 1rem; border-radius: 8px; overflow-x: auto; margin: .6rem 0; }
pre code { background: none; padding: 0; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border-radius: 8px; border: 1px solid transparent; padding: .5rem .9rem; background: none; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.ghost { border-color: var(--line); }
.ghost:hover { background: var(--side); }
.danger { color: var(--danger); }
.danger-fill { background: var(--danger); color: #fff; font-weight: 600; }
.link { padding: .3rem 0; color: var(--muted); text-align: left; }
.link:hover { color: var(--text); text-decoration: underline; }
.wide { width: 100%; }
input, select, textarea {
  width: 100%; padding: .55rem .7rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel);
}
label { display: block; margin-top: .9rem; margin-bottom: .25rem; font-size: .88rem; color: var(--muted); }

/* Connexion */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 1.6rem;
}
.login-card button { width: 100%; margin-top: 1.1rem; }

/* Application */
.app { height: 100%; display: grid; grid-template-columns: 260px 1fr; }
.sidebar {
  background: var(--side); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 14px; gap: 12px; min-height: 0;
}
.brand { font-weight: 700; font-size: 1.15rem; letter-spacing: .02em; }
.sessions { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.session {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: .45rem .6rem; border-radius: 8px; text-align: left;
}
.session:hover { background: var(--line); }
.session.current { background: var(--panel); border-color: var(--line); }
.session .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.dot.alive { background: var(--ok); }
.dot.busy { background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .dot.busy { animation: none; } }
.sidebar-foot { display: flex; flex-direction: column; border-top: 1px solid var(--line); padding-top: 8px; }
.empty { color: var(--muted); font-size: .9rem; padding: .4rem .2rem; }

.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; height: 100%; }
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.chat-head p { margin: 0; font-size: .82rem; }
.chat-actions { display: flex; gap: 8px; flex: none; }
.messages { flex: 1; overflow-y: auto; padding: 20px; min-height: 0; }
.messages > * { max-width: 780px; margin-left: auto; margin-right: auto; }
.msg { margin-bottom: 14px; overflow-wrap: anywhere; }
.msg.user { background: var(--user); padding: .7rem .95rem; border-radius: 12px; white-space: pre-wrap; }
.msg.assistant p:first-child { margin-top: 0; }
.msg.note { font-size: .86rem; color: var(--muted); }
.msg.note.bad { color: var(--danger); }
.tool {
  display: block; font-size: .84rem; color: var(--muted); border-left: 3px solid var(--line);
  padding: .15rem .7rem; margin-bottom: 8px; overflow-wrap: anywhere;
}
.tool.denied { border-left-color: var(--danger); color: var(--danger); }
.welcome { color: var(--muted); text-align: center; margin-top: 18vh; }

.composer {
  display: flex; gap: 10px; align-items: flex-end;
  padding: 14px 20px; border-top: 1px solid var(--line); background: var(--panel);
}
.composer textarea { flex: 1; resize: none; min-height: 2.7rem; max-height: 40vh; }
.composer button { flex: none; }

/* Documentation */
.docs { overflow-y: auto; padding: 24px 20px 60px; height: 100%; }
.docs > * { max-width: 780px; margin-left: auto; margin-right: auto; }
.docs > button { display: block; margin-bottom: 1.2rem; }
.docs table { display: block; overflow-x: auto; border-collapse: collapse; width: 100%; margin: .6rem auto; font-size: .92rem; }
.docs th, .docs td { text-align: left; padding: .4rem .7rem .4rem 0; border-bottom: 1px solid var(--line); vertical-align: top; }

/* Fenêtre « nouvelle session » */
dialog {
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text);
  padding: 1.4rem; width: min(420px, calc(100% - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 1.3rem; }

/* Téléphone */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); max-height: 38vh; padding: 10px 16px; }
  .chat-head, .composer, .messages { padding-left: 16px; padding-right: 16px; }
}
