:root {
  --bg: #f4f6f5;
  --panel: #ffffff;
  --text: #1c2421;
  --muted: #5f6b66;
  --line: #e2e7e4;
  --accent: #0b6e4f;
  --accent-text: #ffffff;
  --in-bubble: #ffffff;
  --out-bubble: #dcf3e6;
  --bot-bubble: #e7eefb;
  --warn-bg: #fff4d6;
  --warn-text: #6b4e00;
  --danger: #b42318;
  --badge: #0b6e4f;
  --handoff: #c2410c;
  --chat-bg: #eef1ef;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1412;
    --panel: #161d1a;
    --text: #e6ece9;
    --muted: #94a39c;
    --line: #26302c;
    --accent: #2fb381;
    --accent-text: #06120d;
    --in-bubble: #1e2723;
    --out-bubble: #1c3a2d;
    --bot-bubble: #1d2a40;
    --warn-bg: #3a2f0f;
    --warn-text: #f3d68a;
    --danger: #f97066;
    --badge: #2fb381;
    --handoff: #fb923c;
    --chat-bg: #111815;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.error { color: var(--danger); min-height: 1.2em; margin: 6px 0 0; font-size: 14px; }

button.primary {
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: 10px;
  padding: 10px 16px; font-weight: 600; cursor: pointer;
}
button.primary:disabled { opacity: 0.55; cursor: default; }
button.ghost {
  background: none; border: 0; padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: 18px;
  color: var(--muted);
}
button.ghost:hover { background: var(--line); }
button.ghost.small-text { font-size: 13px; }

/* Connexion */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 24px; display: grid; gap: 12px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card input {
  padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
}

/* Disposition */
.shell { height: 100%; display: grid; grid-template-columns: minmax(280px, 360px) 1fr; }
.list-pane, .thread-pane { min-height: 0; display: flex; flex-direction: column; }
.list-pane { background: var(--panel); border-right: 1px solid var(--line); }
.thread-pane { background: var(--chat-bg); }

.bar {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line); min-height: 58px;
}
.bar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.bar-title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Interrupteur */
.switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.track { width: 38px; height: 22px; border-radius: 11px; background: var(--line); position: relative; transition: background .15s; }
.thumb { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--panel); box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track .thumb { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-label { font-size: 13px; color: var(--muted); }

.warning { background: var(--warn-bg); color: var(--warn-text); padding: 8px 12px; font-size: 13.5px; }
.handoff { background: var(--warn-bg); color: var(--handoff); padding: 8px 12px; font-size: 13.5px; font-weight: 600; }

/* Liste des conversations */
.conversations { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conv {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 12px 14px;
  border-bottom: 1px solid var(--line); cursor: pointer;
}
.conv:hover, .conv.active { background: var(--bg); }
.conv-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 12px; color: var(--muted); text-align: right; }
.conv-last { color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-tags { display: flex; gap: 4px; justify-content: flex-end; align-items: center; }
.badge { background: var(--badge); color: var(--accent-text); border-radius: 10px; padding: 0 7px; font-size: 12px; font-weight: 700; min-width: 20px; text-align: center; }
.tag { font-size: 11px; border-radius: 6px; padding: 1px 6px; border: 1px solid var(--line); color: var(--muted); }
.tag.handoff-tag { color: var(--handoff); border-color: currentColor; font-weight: 600; }
.empty { padding: 32px 16px; text-align: center; }

/* Fil de discussion */
.no-thread { margin: auto; padding: 16px; }
.thread { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.back { display: none; }
.messages { list-style: none; margin: 0; padding: 14px 12px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: min(78%, 560px); padding: 7px 10px 5px; border-radius: 12px; box-shadow: var(--shadow); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.in { align-self: flex-start; background: var(--in-bubble); border-top-left-radius: 4px; }
.msg.out { align-self: flex-end; background: var(--out-bubble); border-top-right-radius: 4px; }
.msg.out.bot { background: var(--bot-bubble); }
.msg-meta { display: flex; gap: 6px; justify-content: flex-end; font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.msg-error { color: var(--danger); font-size: 12px; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); border-radius: 8px; padding: 2px 10px; margin: 6px 0; }

.composer {
  display: flex; gap: 8px; padding: 10px 12px; background: var(--panel); border-top: 1px solid var(--line);
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg);
}
.composer-error { padding: 0 12px 8px; background: var(--panel); margin: 0; }

/* Téléphone : une seule colonne */
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .thread-pane { display: none; }
  .shell.show-thread .list-pane { display: none; }
  .shell.show-thread .thread-pane { display: flex; }
  .back { display: inline-block; }
  .no-thread { display: none; }
}

/* Page « MCP » */
body.page { height: auto; min-height: 100%; }
.page-bar { position: sticky; top: 0; z-index: 1; }
.ghost-link { color: var(--accent); font-weight: 600; text-decoration: none; padding: 6px 10px; border-radius: 8px; }
.ghost-link:hover { background: var(--line); }
.page-main { max-width: 860px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { margin: 0 0 10px; font-size: 17px; }
.rows { margin: 0; display: grid; gap: 0; }
.row { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row dt { color: var(--muted); }
.row dd { margin: 0; overflow-wrap: anywhere; }
.pill { display: inline-block; font-size: 11.5px; font-weight: 700; border-radius: 6px; padding: 1px 7px; }
.pill.ok { background: var(--out-bubble); color: var(--accent); }
.pill.ko { background: var(--warn-bg); color: var(--handoff); }
code { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg); border-radius: 6px; padding: 1px 5px; overflow-wrap: anywhere; }
button.mini { font-size: 12px; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; }
.tools { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.tools li { border-top: 1px solid var(--line); padding-top: 10px; }
.tools li:first-child { border-top: 0; padding-top: 0; }
.tools p { margin: 4px 0 0; }
.warning a, .page-main a { color: inherit; }
@media (max-width: 600px) { .row { grid-template-columns: 1fr; gap: 2px; } }
