:root {
  --bg: #0f172a;
  --bg-elev: #1e293b;
  --bg-elev2: #334155;
  --fg: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
  --user: #1d4ed8;
  --assistant: #1f2937;
  --error: #ef4444;
  --border: #334155;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--fg);
}

/* ---- Login ---- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--bg-elev);
  padding: 2rem 2.5rem;
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0,0,0,.4);
  min-width: 320px;
}
.login-card h1 { margin: 0 0 .25rem; font-size: 1.6rem; }
.subtitle { color: var(--muted); margin: 0 0 1.5rem; font-size: .9rem; }
.login-card form { display: flex; flex-direction: column; gap: .75rem; }
.login-card label { font-size: .85rem; color: var(--muted); }
.login-card input {
  padding: .7rem .9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-size: 1rem;
}
.login-card input:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
button {
  padding: .7rem 1.2rem;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #0f172a;
  font-weight: 600;
  cursor: pointer;
  font-size: 1rem;
  transition: background .15s;
}
button:hover:not(:disabled) { background: var(--accent-hover); }
button:disabled { opacity: .5; cursor: not-allowed; }
.error {
  background: rgba(239,68,68,.15);
  color: var(--error);
  padding: .6rem .8rem;
  border-radius: 8px;
  border: 1px solid rgba(239,68,68,.4);
  margin-bottom: .5rem;
  font-size: .9rem;
}

/* ---- Chat ---- */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: .8rem 1.2rem;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 1.1rem; }
.model-badge {
  color: var(--muted); font-size: .8rem;
  padding: .15rem .6rem;
  border: 1px solid var(--border); border-radius: 12px;
}
.logout-form { margin-left: auto; margin-bottom: 0; }
.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  font-weight: 500;
}
.ghost:hover:not(:disabled) { background: var(--bg-elev2); color: var(--fg); }

.chat-app {
  display: flex; flex-direction: column;
  height: calc(100vh - 57px);
  max-width: 900px; margin: 0 auto;
  padding: 1rem;
}
.messages {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: .75rem;
  padding-bottom: 1rem;
}
.messages:empty::before {
  content: "Tape un message pour démarrer…";
  color: var(--muted);
  text-align: center;
  margin-top: 2rem;
  font-style: italic;
}
.msg {
  padding: .8rem 1rem;
  border-radius: var(--radius);
  max-width: 85%;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg-user { align-self: flex-end; background: var(--user); }
.msg-assistant { align-self: flex-start; background: var(--assistant); border: 1px solid var(--border); }
.msg-error { align-self: stretch; background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.4); color: var(--error); }
.msg pre {
  background: rgba(0,0,0,.4);
  padding: .6rem .8rem;
  border-radius: 6px;
  overflow-x: auto;
  margin: .4rem 0;
  font-size: .9em;
}
.msg code {
  background: rgba(0,0,0,.4);
  padding: .1rem .35rem;
  border-radius: 4px;
  font-size: .9em;
  font-family: "SF Mono", Consolas, monospace;
}
.msg pre code { background: transparent; padding: 0; }
.typing { color: var(--muted); font-style: italic; opacity: .8; }

.composer { display: flex; flex-direction: column; gap: .5rem; padding-top: .5rem; border-top: 1px solid var(--border); }
.composer textarea {
  width: 100%;
  padding: .7rem .9rem;
  background: var(--bg-elev);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
}
.composer textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.composer-actions { display: flex; gap: .5rem; justify-content: flex-end; }
