/* Palette vert sauge / vert profond. Mobile d'abord. */
:root {
  --deep: #1f3d2f;
  --deep-2: #2e5641;
  --sage: #9fb596;
  --sage-light: #e3eadd;
  --sage-pale: #f0f4ec;
  --bg: #f7f8f4;
  --surface: #ffffff;
  --text: #1c2b22;
  --muted: #536357;
  --border: #cdd8c6;
  --danger: #9b2c2c;
  --focus: #c98a2e;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font);
}
a { color: var(--deep-2); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--deep);
  color: #fff;
}
.brand { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-weight: 700; letter-spacing: .01em; }
.brand-sub { font-size: .8rem; color: var(--sage-light); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar .btn-ghost { color: #fff; border-color: rgba(255,255,255,.4); }
.topbar .btn-primary { background: var(--sage-light); color: var(--deep); }

/* ---------- Boutons ---------- */
button, .btn-primary, .btn-outline, .btn-ghost, .btn-danger {
  font: inherit; cursor: pointer; border-radius: 10px; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; text-align: center;
}
.btn-primary { background: var(--deep); color: #fff; border: 0; padding: 12px 18px; font-weight: 600; }
.btn-primary:hover { background: var(--deep-2); }
.btn-primary:disabled { background: #9aa79e; cursor: not-allowed; }
.btn-outline { background: var(--surface); color: var(--deep); border: 1.5px solid var(--deep); padding: 11px 18px; font-weight: 600; }
.btn-ghost { background: transparent; color: var(--deep); border: 1.5px solid var(--border); padding: 8px 12px; }
.btn-danger { background: var(--danger); color: #fff; border: 0; padding: 12px 18px; font-weight: 600; }
.btn-small { padding: 8px 12px; font-size: .9rem; }
.btn-block { width: 100%; }
.link-danger { background: none; border: 0; padding: 4px 0; color: var(--danger); text-decoration: underline; font-size: .85rem; }

/* ---------- Mise en page ---------- */
main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 16px; }
.loading { color: var(--muted); text-align: center; margin-top: 40px; }
.banner-error, .form-error {
  color: var(--danger); background: #fbeeee; border: 1px solid #ebc7c7;
  border-radius: 10px; padding: 10px 12px; margin: 10px 0; font-size: .95rem;
}
.notice-ok { color: var(--deep); background: var(--sage-light); border-radius: 10px; padding: 10px 12px; }

/* ---------- Formulaire d'entrée ---------- */
.entry h1 { font-size: 1.35rem; margin: 0 0 6px; color: var(--deep); }
.entry-intro { margin: 0 0 16px; color: var(--muted); }
.grid-2 { display: grid; gap: 0 12px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-weight: 600; font-size: .95rem; }
.field input {
  font: inherit; font-weight: 400; padding: 11px 12px; border: 1.5px solid var(--border);
  border-radius: 10px; background: #fff; color: var(--text); width: 100%;
}
.field input:focus { border-color: var(--deep-2); outline: none; box-shadow: 0 0 0 3px var(--sage-light); }
.optional { font-weight: 400; color: var(--muted); }
.notice {
  font-size: .88rem; color: var(--muted); background: var(--sage-pale);
  border-left: 4px solid var(--sage); border-radius: 8px; padding: 10px 12px; margin: 6px 0 14px;
}
.notice p { margin: 0; }
.consent { display: flex; gap: 10px; align-items: flex-start; font-size: .95rem; margin-bottom: 14px; }
.consent input { width: 20px; height: 20px; margin-top: 2px; flex: none; accent-color: var(--deep); }
.turnstile { min-height: 65px; margin-bottom: 12px; }
.hint { font-size: .85rem; color: var(--muted); margin: 8px 0 0; text-align: center; }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; gap: 14px; }
.welcome { background: var(--sage-light); border-color: var(--sage); }
.welcome { padding: 12px 16px; }
.welcome summary { cursor: pointer; font-weight: 600; color: var(--deep); }
.welcome p { margin: 8px 0 2px; font-size: .95rem; }

.themes { display: flex; flex-direction: column; gap: 8px; }
.theme-row {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px;
  scrollbar-width: thin; -webkit-overflow-scrolling: touch;
}
.chip {
  flex: none; padding: 7px 13px; border-radius: 999px; font-size: .88rem;
  border: 1.5px solid var(--sage); background: var(--surface); color: var(--deep);
}
.chip[aria-selected="true"] { background: var(--deep); border-color: var(--deep); color: #fff; }
.theme-panel {
  display: flex; flex-direction: column; gap: 6px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 10px;
  max-height: 45vh; overflow-y: auto;
}
.question {
  text-align: left; justify-content: flex-start; padding: 9px 11px; font-size: .92rem;
  background: var(--sage-pale); border: 1px solid transparent; color: var(--text); border-radius: 10px;
}
.question:hover { border-color: var(--sage); }

.messages { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 92%; padding: 10px 14px; border-radius: 16px; overflow-wrap: anywhere; }
.msg-user { align-self: flex-end; background: var(--deep); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg-bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg-bot p { margin: 0 0 8px; }
.msg-bot p:last-child, .msg-bot ul:last-child, .msg-bot ol:last-child { margin-bottom: 0; }
.msg-bot ul, .msg-bot ol { margin: 0 0 8px; padding-left: 20px; }
.msg-bot h3, .msg-bot h4 { margin: 4px 0 6px; font-size: 1rem; }
.msg-bot code { background: var(--sage-pale); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--sage); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; opacity: .7; } }

.composer {
  position: sticky; bottom: 0; background: var(--bg);
  padding: 8px 0 max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.composer-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.counter { font-size: .85rem; font-weight: 600; color: var(--deep-2); }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; font: inherit; resize: none; padding: 11px 12px; min-height: 46px; max-height: 160px;
  border: 1.5px solid var(--border); border-radius: 12px; background: #fff; color: var(--text);
}
.composer textarea:focus { border-color: var(--deep-2); outline: none; box-shadow: 0 0 0 3px var(--sage-light); }
.composer textarea:disabled { background: #eef1ec; }
.disclaimer { font-size: .78rem; color: var(--muted); margin: 6px 0 0; }

/* ---------- Pied de page ---------- */
.footer { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 10px; text-align: center; padding: 14px 16px 22px; font-size: .88rem; color: var(--muted); }

/* ---------- Fenêtres ---------- */
.dialog {
  border: 0; border-radius: var(--radius); padding: 20px 18px; width: min(420px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(20, 40, 30, .25);
}
.dialog::backdrop { background: rgba(20, 35, 27, .45); }
.dialog h2 { margin: 0 0 12px; font-size: 1.15rem; color: var(--deep); }
.contact-list { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 8px; }
.contact-list a { overflow-wrap: anywhere; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ---------- Page de confidentialité ---------- */
.doc h1 { font-size: 1.4rem; color: var(--deep); margin-top: 0; }
.doc h2 { font-size: 1.15rem; color: var(--deep); margin-top: 1.6em; }
.doc h3 { font-size: 1rem; color: var(--deep-2); margin-top: 1.4em; }
.doc blockquote { margin: 0 0 16px; padding: 10px 14px; background: #fbf5e8; border-left: 4px solid var(--focus); border-radius: 8px; }
.doc blockquote p { margin: 0; }
.doc hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
.doc code { background: var(--sage-pale); padding: 1px 5px; border-radius: 5px; font-size: .9em; }

/* ---------- Écrans plus larges ---------- */
@media (min-width: 600px) {
  main { padding: 24px; }
  .card { padding: 24px; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .msg { max-width: 82%; }
}
