/* Design system open-codex (blueprint §4.1). Le sombre est une palette repensée, pas un inverse. */
:root {
  --bg: #f8f9fc; --panel: #ffffff; --ink: #1a2233; --muted: #6b7280;
  --accent: #4f46e5; --accent-ink: #ffffff; --line: #e3e6f0;
  --bubble: #eef0f7; --ok: #16a34a; --warn: #d97706; --err: #dc2626;
  --radius: 12px; --shadow: 0 1px 3px rgba(16,24,40,.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
[data-theme="dark"] {
  --bg: #0d1220; --panel: #151b2e; --ink: #e6e9f2; --muted: #8a93a8;
  --accent: #818cf8; --accent-ink: #0d1220; --line: #232b45; --bubble: #1c2440; --shadow: none;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
code, pre { font-family: var(--mono); font-size: .9em; }
pre { background: var(--bubble); border: 1px solid var(--line); border-radius: 10px; padding: 12px; overflow-x: auto; }
:not(pre) > code { background: var(--bubble); padding: 1px 5px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.error { color: var(--err); min-height: 1.2em; margin: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }

.brand { font-weight: 700; letter-spacing: -.02em; font-size: 1.1rem; margin: 0; }
.brand span { color: var(--accent); }

/* Boutons */
.btn { border: 1px solid transparent; border-radius: 10px; padding: 9px 16px; font: inherit; font-weight: 500;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; transition: background .15s, opacity .15s; color: var(--ink); background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { opacity: .9; }
.btn-ghost { border-color: var(--line); }
.btn-ghost:hover { background: var(--bubble); }
.btn-sm { padding: 5px 10px; font-size: .88em; }
.btn-block { width: 100%; }
input, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; outline: none; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.badge { font-size: .75em; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; }

/* Connexion */
.login { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.login-card .brand { font-size: 1.6rem; }
.login-card label { font-weight: 500; font-size: .9em; }

/* Mise en page */
.app { display: flex; height: 100dvh; }
.sidebar { width: 270px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; }
.sidebar-head, .sidebar-foot { display: flex; align-items: center; gap: 8px; padding: 14px; }
.sidebar-head { justify-content: space-between; }
.sidebar-foot { border-top: 1px solid var(--line); }
.sidebar-foot #me-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-list { flex: 1; overflow-y: auto; padding: 0 8px; }
.conv-item { display: flex; align-items: center; gap: 4px; border-radius: 10px; padding: 8px 10px; cursor: pointer; color: var(--ink); }
.conv-item:hover { background: var(--bubble); }
.conv-item.active { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.conv-item .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .93em; }
.conv-item .del { visibility: hidden; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.conv-item:hover .del { visibility: visible; }
.conv-item .del:hover { color: var(--err); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.conv-title { flex: 1; margin: 0; font-size: 1rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { display: none; }

.thread { flex: 1; overflow-y: auto; padding: 24px 20px; display: flex; flex-direction: column; gap: 18px; }
.thread > * { width: 100%; max-width: 780px; margin: 0 auto; }
.empty { text-align: center; margin: auto; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg .bubble { border-radius: 14px; padding: 10px 14px; max-width: 85%; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--bubble); }
.msg.assistant .bubble { max-width: 100%; padding-left: 0; }
.msg .bubble p { margin: 0 0 .6em; }
.msg .bubble p:last-child { margin-bottom: 0; }
.msg.error .bubble { color: var(--err); border: 1px solid color-mix(in srgb, var(--err) 40%, transparent); }
.cursor::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

.composer { display: flex; gap: 8px; align-items: flex-end; padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
  max-width: 820px; width: 100%; margin: 0 auto; }
.composer textarea { flex: 1; resize: none; max-height: 40vh; }

.backdrop { display: none; }

/* Mobile ≤ 700 px : tiroir latéral (bottom tab bar en M6) */
@media (max-width: 700px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; width: 82vw; max-width: 320px; }
  .app.drawer .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  .app.drawer .backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 10; }
  .menu-btn { display: inline-flex; }
  .topbar, .thread { padding-left: 12px; padding-right: 12px; }
  .composer { padding-left: 12px; padding-right: 12px; }
  .conv-item .del { visibility: visible; }
}
