@font-face {
  font-family: "Archivo";
  src: url("/fonts/archivo.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #faf9f4;
  --surface: #ffffff;
  --ink: #111111;
  --muted: #55524a;
  --faint: #6b675d;
  --line: #e6e2d6;
  --line-soft: #efece3;
  --field: #cfcabb;
  --accent: #ffd23f;
  --accent-soft: #fff6cc;
  --danger: #a3342a;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.5 "Archivo", -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

h1 {
  margin: 0;
  font-size: 34px;
  font-weight: 750;
  font-stretch: 106%;
  line-height: 1.05;
  letter-spacing: -.015em;
}
h2 { margin: 0; font-size: 18px; font-weight: 750; line-height: 1.25; }

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Accueil */
.welcome {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px max(18px, env(safe-area-inset-right)) max(32px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.welcome-header { display: flex; flex-direction: column; gap: 14px; padding: 0 4px; }
.eyebrow {
  margin: 0;
  display: flex; align-items: center; gap: 8px;
  color: var(--muted);
  font-size: 13px; font-weight: 700;
}
.eyebrow::before {
  content: "";
  width: 10px; height: 10px; border-radius: 3px;
  background: var(--accent);
}
.subtitle { margin: -6px 0 0; font-size: 19px; font-weight: 650; line-height: 1.25; text-wrap: balance; }
.lead { margin: 0; color: var(--muted); font-size: 17px; text-wrap: pretty; }
.lead-strong { color: var(--ink); }

.notice { display: flex; flex-direction: column; gap: 10px; }
.notice h2 { margin: 0 0 2px 4px; }
.notice ul {
  margin: 0; padding: 0; list-style: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.notice li {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
  text-wrap: pretty;
}
.notice li:last-child { border-bottom: 0; }
.notice strong { font-weight: 750; }

.consent {
  position: relative;
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: 16px;
  font-weight: 650; line-height: 1.45;
  cursor: pointer;
}
.consent:has(input:focus-visible) { outline: 3px solid var(--ink); outline-offset: 2px; }
.consent input {
  position: absolute; width: 24px; height: 24px; margin: 0;
  opacity: 0; cursor: pointer;
}
.check {
  flex: none;
  display: flex; align-items: center; justify-content: center;
  width: 24px; height: 24px;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: 7px;
  font-size: 13px; font-weight: 900; line-height: 1;
  transition: background-color 120ms ease;
}
.consent input:checked + .check { background: var(--accent); }
.consent input:checked + .check::after { content: "✓"; }

.group-picker { display: flex; flex-direction: column; gap: 10px; }
.group-picker h2 { margin: 0 0 2px 4px; }
.groups { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.groups button {
  height: 62px;
  background: var(--surface);
  border: 1.5px solid var(--field);
  border-radius: 14px;
  color: var(--ink);
  font-size: 25px; font-weight: 750;
  transition: background-color 120ms ease, border-color 120ms ease;
}
.groups button:focus-visible { background: var(--accent); border-color: var(--ink); }
.groups button:disabled {
  background: var(--bg);
  border: 1.5px dashed var(--field);
  color: #a9a497;
  cursor: not-allowed;
}
.error { margin: 0; color: var(--danger); font-size: 15px; font-weight: 700; }

/* Conversation */
.chat {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
.chat-header {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 14px max(16px, env(safe-area-inset-right), calc((100% - 760px) / 2)) 12px max(16px, env(safe-area-inset-left), calc((100% - 760px) / 2));
}
.chat-title { display: flex; align-items: center; gap: 12px; }
.chat-title strong { font-size: 19px; font-weight: 750; }
.group-badge {
  flex: none;
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px;
  background: var(--accent);
  border-radius: 12px;
  font-size: 24px; font-weight: 850; font-stretch: 112%;
}
.task {
  display: grid; grid-template-columns: 1fr; gap: 8px;
  margin: 0; padding: 10px 12px;
  background: var(--accent-soft);
  border-radius: 12px;
}
.task div { display: flex; flex-direction: column; gap: 1px; }
.task dt { color: var(--muted); font-size: 12px; font-weight: 600; }
.task dd { margin: 0; font-size: 16px; font-weight: 650; line-height: 1.3; }
.chat-actions { display: flex; gap: 16px; margin: -4px 0 -8px; }
.link {
  min-height: 44px; padding: 0;
  background: none; border: 0;
  color: var(--muted);
  font-size: 13.5px; font-weight: 600;
  text-decoration: underline; text-underline-offset: 3px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px max(18px, env(safe-area-inset-right), calc((100% - 760px) / 2)) 16px max(18px, env(safe-area-inset-left), calc((100% - 760px) / 2));
}
/* Ancre une conversation courte en bas sans bloquer le défilement d'une longue. */
.messages::before { content: ""; margin-top: auto; }
.empty { margin: auto 0; color: var(--muted); font-size: 16px; text-align: center; }

.message { overflow-wrap: anywhere; white-space: pre-wrap; }
.message.user {
  align-self: flex-end;
  max-width: 82%;
  padding: 10px 15px;
  background: var(--ink);
  border-radius: 18px 18px 6px 18px;
  color: #fff;
  font-size: 16px; line-height: 1.45;
}
.message.assistant { display: flex; flex-direction: column; gap: 4px; font-size: 16.5px; line-height: 1.55; }
.message-label {
  display: flex; align-items: center; gap: 6px;
  color: var(--muted);
  font-size: 12px; font-weight: 700; line-height: 1.5;
}
.message-label::before {
  content: "";
  width: 8px; height: 8px; border-radius: 2px;
  background: var(--accent);
}
.message-body { text-wrap: pretty; }
.message.pending .message-body { display: none; }
.message.failed {
  align-self: flex-start;
  padding: 10px 14px;
  background: #fbeeec;
  border: 1px solid #e6c5c0;
  border-radius: 14px;
  color: var(--danger);
  font-size: 15px;
}

.composer {
  flex: none;
  display: flex; gap: 8px; align-items: flex-end;
  width: min(760px, calc(100% - 24px));
  margin: 8px auto 4px;
  padding: 5px 5px 5px 14px;
  background: var(--surface);
  border: 1.5px solid var(--field);
  border-radius: 18px;
  transition: border-color 120ms ease;
}
.composer:focus-within { border-color: var(--ink); }
.composer textarea {
  flex: 1; min-width: 0; min-height: 44px; max-height: 160px;
  padding: 11px 0; resize: none;
  background: transparent; border: 0; outline: 0;
  /* 16 px minimum : iOS ne zoome pas au focus. */
  font-size: 17px; line-height: 22px;
}
.composer textarea::placeholder { color: var(--faint); }
.composer button {
  flex: none;
  height: 44px; padding: 0 18px;
  background: var(--accent);
  border: 0; border-radius: 13px;
  color: var(--ink);
  font-size: 15px; font-weight: 750;
  transition: background-color 120ms ease, color 120ms ease;
}
.composer button:disabled { opacity: .5; cursor: not-allowed; }
.reminder {
  flex: none;
  margin: 0;
  padding: 6px 20px max(16px, env(safe-area-inset-bottom));
  color: var(--faint);
  font-size: 12px; text-align: center;
}

/* Le survol reste collé après un toucher : réservé aux appareils avec souris. */
@media (hover: hover) {
  .groups button:hover:not(:disabled) { background: var(--accent); border-color: var(--ink); }
  .link:hover { color: var(--ink); }
  .composer button:hover:not(:disabled) { background: var(--ink); color: var(--accent); }
}

@media (min-width: 700px) {
  .task { grid-template-columns: 1fr 1fr; gap: 8px 16px; }
}
