:root {
  --fond: #0B1416;
  --surface: #13242B;
  --surface-2: #1B3139;
  --texte: #EDF4F3;
  --texte-2: #A9BFBD;
  --mer: #2EC4B6;
  --corail: #FF6B57;
  --sable: #E8D9B5;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--fond);
  color: var(--texte);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 17px;
  line-height: 1.5;
  min-height: 100%;
  min-height: 100dvh;
}

a { color: var(--mer); text-decoration: none; }
a:hover, a:focus { text-decoration: underline; }

.wrap {
  max-width: 68ch;
  margin: 0 auto;
  padding: 24px 16px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}

h1 {
  font-size: 22px;
  font-weight: 600;
  color: var(--sable);
  margin: 0 0 8px;
}

h2 {
  font-size: 17px;
  font-weight: 600;
  color: var(--sable);
  margin: 24px 0 8px;
}

.muted { color: var(--texte-2); font-size: 13px; }
.err {
  color: var(--fond);
  background: var(--corail);
  padding: 12px 16px;
  border-radius: 12px;
  margin: 16px 0;
}

label {
  display: block;
  margin: 16px 0 8px;
  color: var(--texte-2);
  font-size: 13px;
}

input[type="email"],
input[type="password"],
input[type="text"],
textarea {
  width: 100%;
  min-height: 44px;
  padding: 12px 16px;
  border: 0;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--texte);
  font: inherit;
}

input:focus, textarea:focus {
  outline: 2px solid var(--mer);
  outline-offset: 2px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 12px 24px;
  margin: 16px 0 0;
  border: 0;
  border-radius: 12px;
  background: var(--mer);
  color: var(--fond);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn:focus { outline: 2px solid var(--sable); outline-offset: 2px; }
.btn-corail { background: var(--corail); }
.btn-ghost {
  background: transparent;
  border: 0;
  color: var(--texte-2);
  font: inherit;
  padding: 8px;
  min-height: 44px;
  cursor: pointer;
}

.btn-ghost:hover,
.btn-ghost:focus-visible {
  color: var(--mer);
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
}

.brand {
  font-size: 22px;
  font-weight: 600;
  color: var(--mer);
  letter-spacing: 0.02em;
}

.auth-card { margin-top: 48px; }
.auth-card p { margin: 0 0 24px; color: var(--texte-2); }
.auth-links { margin-top: 24px; }
.auth-links a { margin-right: 16px; }

/* Chat layout */
.chat-app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh;
  max-width: 68ch;
  margin: 0 auto;
}

.chat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: var(--fond);
  border-bottom: 1px solid var(--surface-2);
  flex-shrink: 0;
}

.chat-top nav { display: flex; gap: 8px; align-items: center; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bubble {
  max-width: 92%;
  padding: 12px 16px;
  border-radius: 12px;
  animation: fadein 120ms ease-out;
}

@keyframes fadein {
  from { opacity: 0; }
  to { opacity: 1; }
}

.bubble.user {
  align-self: flex-end;
  background: var(--mer);
  color: var(--fond);
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--surface);
  color: var(--texte);
}

/* Le modèle répond par paragraphes et listes : sans pre-wrap, tout est collé
   sur une seule ligne dans la bulle. */
.bubble .body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.sources {
  margin-top: 8px;
  font-size: 13px;
  color: var(--texte-2);
}

.sources a {
  display: inline-block;
  margin-right: 12px;
  margin-top: 4px;
}

.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--fond);
  border-top: 1px solid var(--surface-2);
  flex-shrink: 0;
}

.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  resize: none;
}

.composer .send {
  border-radius: 999px;
  width: 44px;
  height: 44px;
  padding: 0;
  flex-shrink: 0;
}

.composer .send svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
}

.gap-note {
  color: var(--corail);
  font-size: 13px;
  margin-top: 8px;
}

.admin table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
}
.admin th, .admin td {
  text-align: left;
  padding: 8px 4px;
  border-bottom: 1px solid var(--surface-2);
  font-size: 13px;
  color: var(--texte-2);
}
.admin .stat {
  font-size: 22px;
  color: var(--sable);
  font-weight: 600;
}
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 24px 0;
}
.stat-box {
  background: var(--surface);
  border-radius: 12px;
  padding: 16px;
}
