/* HONTONTCHE — interface de discussion (style messagerie IA), mobile d'abord. */
:root {
  --bg: #fbf7f2;
  --surface: #ffffff;
  --side: #f3ede5;
  --ink: #1f1b24;
  --muted: #6b6470;
  --line: #e7ddd2;
  --brand: #0e6e6d;
  --brand-ink: #ffffff;
  --brand-soft: #e3f1f0;
  --accent: #f2675a;
  --user: #0e6e6d;
  --user-ink: #ffffff;
  --bot: #ffffff;
  --code: #f4efe9;
  --radius: 18px;
  --shadow: 0 6px 24px rgba(31, 27, 36, 0.08);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14121a;
    --surface: #1d1a24;
    --side: #19161f;
    --ink: #f3eef6;
    --muted: #a59eab;
    --line: #2e2936;
    --brand: #37b3ac;
    --brand-ink: #0b1d1c;
    --brand-soft: #173533;
    --accent: #ff8a7a;
    --user: #237f7b;
    --user-ink: #ffffff;
    --bot: #1d1a24;
    --code: #26222e;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--font); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
button, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { display: grid; grid-template-columns: 290px minmax(0, 1fr); height: 100dvh; }

/* ---------- panneau latéral ---------- */
.side { display: flex; flex-direction: column; background: var(--side); border-right: 1px solid var(--line); min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 8px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand strong { display: block; font-size: 1.05rem; letter-spacing: 0.06em; }
.brand small { display: block; font-size: 0.78rem; color: var(--muted); }
.new-chat { margin: 6px 12px 10px; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-align: left; font-weight: 600; box-shadow: var(--shadow); }
.new-chat:hover { border-color: var(--brand); }
.convs { flex: 1; overflow-y: auto; padding: 4px 8px 12px; scrollbar-width: thin; }
.convs p.empty { color: var(--muted); font-size: 0.85rem; padding: 8px 10px; }
.conv { display: flex; align-items: center; gap: 4px; border-radius: 10px; }
.conv a { flex: 1; min-width: 0; padding: 9px 10px; color: var(--ink); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.92rem; }
.conv.on, .conv:hover { background: color-mix(in srgb, var(--brand) 12%, transparent); }
.conv .del { opacity: 0; border: 0; background: none; cursor: pointer; padding: 6px 8px; color: var(--muted); border-radius: 8px; }
.conv:hover .del, .conv.on .del, .conv .del:focus-visible { opacity: 1; }
.side-foot { padding: 12px 14px 16px; border-top: 1px solid var(--line); font-size: 0.84rem; display: grid; gap: 8px; }
.help-line { margin: 0; padding: 10px 12px; border-radius: 12px; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--ink); }
.amp { color: var(--muted); text-decoration: none; }
.amp:hover { color: var(--brand); }
.link-btn { border: 0; background: none; padding: 0; color: var(--brand); cursor: pointer; text-align: left; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- zone principale ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.top { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 5; padding-top: max(10px, env(safe-area-inset-top)); }
.top-title { flex: 1; display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
.top-title strong { letter-spacing: 0.08em; font-size: 0.98rem; }
.top-title span { font-size: 0.75rem; color: var(--muted); }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 12px; border: 1px solid transparent; background: none; cursor: pointer; }
.icon-btn:hover { background: color-mix(in srgb, var(--brand) 10%, transparent); }
.only-mobile { display: none; }

.thread { flex: 1; overflow-y: auto; padding: 18px 16px 8px; scroll-behavior: smooth; overscroll-behavior: contain; }
.thread > * { max-width: 760px; margin-left: auto; margin-right: auto; }

/* accueil */
.welcome { text-align: center; padding: 6vh 4px 12px; }
.welcome img { width: 76px; height: 76px; }
.welcome h1 { margin: 14px 0 4px; font-size: clamp(1.5rem, 4vw, 2rem); letter-spacing: 0.02em; }
.welcome .devise { margin: 0; color: var(--accent); font-weight: 700; }
.welcome p.intro { margin: 12px auto 22px; max-width: 520px; color: var(--muted); }
.chips { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; text-align: left; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 12px 14px; cursor: pointer; box-shadow: var(--shadow); line-height: 1.35; }
.chip:hover { border-color: var(--brand); }
.chip b { display: block; font-size: 0.95rem; }
.chip span { font-size: 0.82rem; color: var(--muted); }

/* messages */
.msg { display: flex; gap: 10px; margin: 0 auto 18px; }
.msg.user { justify-content: flex-end; }
.msg .avatar { width: 32px; height: 32px; flex: none; border-radius: 50%; margin-top: 2px; }
.bubble { max-width: min(85%, 640px); border-radius: var(--radius); padding: 11px 15px; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user); color: var(--user-ink); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.msg.bot .bubble { background: var(--bot); border: 1px solid var(--line); border-top-left-radius: 6px; box-shadow: var(--shadow); max-width: min(92%, 680px); }
.msg.bot .bubble > :first-child { margin-top: 0; }
.msg.bot .bubble > :last-child { margin-bottom: 0; }
.bubble p { margin: 0 0 0.7em; }
.bubble ul, .bubble ol { margin: 0 0 0.7em; padding-left: 1.3em; }
.bubble li { margin: 0.2em 0; }
.bubble h3, .bubble h4 { margin: 0.8em 0 0.3em; font-size: 1rem; }
.bubble code { background: var(--code); padding: 0.1em 0.35em; border-radius: 6px; font-size: 0.92em; }
.bubble a { word-break: break-word; }
.sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.sources span { width: 100%; font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.sources a { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 5px 10px; border-radius: 999px; background: var(--brand-soft); color: var(--ink); font-size: 0.8rem; text-decoration: none; }
.sources a b { color: var(--brand); }
.sources a em { font-style: normal; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.tools { display: flex; gap: 6px; margin-top: 6px; }
.tools button { border: 0; background: none; color: var(--muted); font-size: 0.8rem; padding: 4px 8px; border-radius: 8px; cursor: pointer; }
.tools button:hover { background: color-mix(in srgb, var(--brand) 10%, transparent); color: var(--ink); }
.error { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)) !important; }
.retry { margin-top: 8px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 6px 12px; cursor: pointer; }

/* « en train d'écrire » */
.typing { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.9rem; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--brand); opacity: 0.35; animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* zone de saisie */
.composer { padding: 8px 14px calc(10px + env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--bg) 70%, transparent); }
.box { max-width: 760px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 6px 6px 6px 16px; box-shadow: var(--shadow); }
.box:focus-within { border-color: var(--brand); }
textarea { flex: 1; border: 0; outline: 0; resize: none; background: transparent; padding: 9px 0; max-height: 180px; line-height: 1.45; font-size: 16px; }
.send { flex: none; width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--brand); color: var(--brand-ink); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.send:disabled { opacity: 0.35; cursor: default; }
.disclaimer { max-width: 760px; margin: 6px auto 0; text-align: center; font-size: 0.74rem; color: var(--muted); }

/* fenêtres */
.modal { border: 0; padding: 0; border-radius: 22px; width: min(520px, calc(100vw - 28px)); max-height: calc(100dvh - 28px); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); }
.modal::backdrop { background: rgba(15, 12, 20, 0.55); backdrop-filter: blur(3px); }
.modal-body { padding: 26px 24px 22px; text-align: center; overflow-y: auto; }
.modal-body.left { text-align: left; }
.modal h2 { margin: 10px 0 6px; font-size: 1.35rem; }
.modal h3 { margin: 18px 0 4px; font-size: 1rem; }
.modal .lead { color: var(--muted); margin: 0 0 14px; }
.facts { text-align: left; padding: 0; margin: 0 0 14px; list-style: none; display: grid; gap: 8px; }
.facts li { padding: 10px 12px; border-radius: 12px; background: color-mix(in srgb, var(--brand) 8%, transparent); font-size: 0.92rem; }
.small { font-size: 0.8rem; color: var(--muted); }
.btn { display: inline-flex; justify-content: center; align-items: center; min-height: 46px; padding: 10px 22px; border-radius: 999px; border: 0; background: var(--brand); color: var(--brand-ink); font-weight: 700; cursor: pointer; width: 100%; margin-top: 8px; }
.btn.ghost { background: none; border: 1px solid var(--line); color: var(--ink); }
.btn.danger { color: #c0392b; }
.actions { display: grid; gap: 8px; margin-top: 18px; }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .only-mobile { display: inline-flex; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(310px, 86vw); z-index: 30; transform: translateX(-102%); transition: transform 0.22s ease; padding-top: env(safe-area-inset-top); visibility: hidden; }
  .app.open .side { transform: none; visibility: visible; box-shadow: 0 0 40px rgba(0, 0, 0, 0.3); }
  .scrim { position: fixed; inset: 0; background: rgba(15, 12, 20, 0.5); z-index: 25; }
  .chips { gap: 8px; }
  .chip { padding: 11px 12px; text-align: left; }
  .chip span { display: none; }
  .welcome { padding-top: 2vh; }
  .welcome img { width: 60px; height: 60px; }
  .welcome h1 { font-size: 1.35rem; }
  .welcome p.intro { margin: 8px auto 16px; font-size: 0.95rem; }
  .bubble { max-width: 88%; }
  .msg.bot .avatar { width: 28px; height: 28px; }
  .msg.bot .bubble { max-width: calc(100% - 38px); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
