/* Messagerie — même palette que planningrevision (sombre par défaut, clair automatique). */
:root {
  --bg:        #0b0d12;
  --bg-soft:   #11141c;
  --surface:   rgba(255,255,255,.035);
  --surface-2: rgba(255,255,255,.06);
  --border:    rgba(255,255,255,.09);
  --border-2:  rgba(255,255,255,.16);
  --text:      #e9ecf5;
  --text-dim:  #9aa3b8;
  --text-mute: #6b7488;
  --accent:    #8b5cf6;
  --accent-2:  #22d3ee;
  --mine:      linear-gradient(135deg, #7c4ff0, #5b6cf2);
  --mine-text: #ffffff;
  --ok:        #10b981;
  --warn:      #f59e0b;
  --danger:    #ef4444;
  --radius:    18px;
  --app-h:     100dvh;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:        #f6f7fb;
    --bg-soft:   #ffffff;
    --surface:   #ffffff;
    --surface-2: #eef0f6;
    --border:    rgba(15,23,42,.09);
    --border-2:  rgba(15,23,42,.18);
    --text:      #0f172a;
    --text-dim:  #566078;
    --text-mute: #8b94a9;
    color-scheme: light;
  }
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;              /* seule la zone de messages défile */
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9;
      stroke-linecap: round; stroke-linejoin: round; }

/* hauteur = viewport visible (clavier iOS compris, mis à jour par app.js) */
.app {
  display: flex; flex-direction: column;
  height: var(--app-h);
  max-width: 760px; margin: 0 auto;
}

/* ---------- Barre du haut ---------- */
.topbar {
  flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 10px calc(16px + env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklab, var(--bg) 90%, transparent);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 11px; flex: none;
  display: grid; place-items: center; color: #0b0d12;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 20px -6px var(--accent);
}
.brand-mark svg { width: 18px; height: 18px; stroke-width: 2.2; }
.brand h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
.brand p  { margin: 0; font-size: 12px; color: var(--text-mute); display: flex; align-items: center; gap: 6px; }

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-mute); flex: none; }
.dot.on   { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in oklab, var(--ok) 25%, transparent); }
.dot.wait { background: var(--warn); }
.dot.err  { background: var(--danger); }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-dim);
}
.icon-btn[aria-expanded="true"] { color: var(--text); border-color: var(--border-2); background: var(--surface-2); }

/* ---------- Réglages ---------- */
.settings {
  flex: none;
  padding: 14px calc(16px + env(safe-area-inset-right)) 16px calc(16px + env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}
.settings form { display: grid; gap: 12px; }
.settings label { display: grid; gap: 5px; }
.settings label span { font-size: 12.5px; font-weight: 600; color: var(--text-dim); }
.settings input {
  width: 100%; padding: 11px 13px;
  font-size: 16px;                       /* ≥ 16px : pas de zoom auto sur iOS */
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; outline: none;
}
.settings input:focus { border-color: var(--accent); }
.hint { margin: 0; font-size: 12.5px; color: var(--text-mute); }
.hint code { font-size: 12.5px; color: var(--text); letter-spacing: .04em; }
.hint.err { color: var(--danger); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  border: 1px solid var(--border);
}
.btn.primary { border: 0; color: #fff; background: linear-gradient(135deg, var(--accent), #5b6cf2); }
.btn.primary:disabled { opacity: .6; }
.btn.ghost { background: var(--surface); color: var(--text-dim); }

/* ---------- Fil de discussion ---------- */
.chat {
  flex: 1; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 14px calc(12px + env(safe-area-inset-right)) 10px calc(12px + env(safe-area-inset-left));
}
.older { display: block; margin: 0 auto 12px; font-size: 13px; padding: 7px 14px; }
.empty { text-align: center; color: var(--text-mute); font-size: 13.5px; margin-top: 30vh; }

.messages { display: flex; flex-direction: column; gap: 3px; }

.day {
  align-self: center; margin: 12px 0 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; color: var(--text-mute);
  background: var(--surface); border: 1px solid var(--border);
}

.msg {
  max-width: min(82%, 520px);
  padding: 8px 12px 6px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 6px;
}
.msg.mine {
  align-self: flex-end;
  background: var(--mine); color: var(--mine-text); border-color: transparent;
  border-bottom-left-radius: var(--radius); border-bottom-right-radius: 6px;
}
/* espace entre deux expéditeurs différents */
.msg.first { margin-top: 8px; }
.msg .who { font-size: 11.5px; font-weight: 650; color: var(--accent-2); margin-bottom: 1px; }
.msg.mine .who { display: none; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .meta {
  display: flex; justify-content: flex-end; gap: 4px;
  font-size: 10.5px; margin-top: 2px; color: var(--text-mute);
  font-variant-numeric: tabular-nums;
}
.msg.mine .meta { color: rgba(255,255,255,.72); }
.msg.pending { opacity: .65; }
.msg.failed  { outline: 1px solid var(--danger); }
.msg.locked .text { font-style: italic; color: var(--text-mute); }

/* ---------- Zone de saisie ---------- */
.composer {
  flex: none;
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px calc(10px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left));
  border-top: 1px solid var(--border);
  background: color-mix(in oklab, var(--bg) 92%, transparent);
}
.composer textarea {
  flex: 1; min-width: 0; resize: none;
  max-height: 140px;
  padding: 10px 14px;
  font-size: 16px; line-height: 1.35;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px; outline: none;
}
.composer textarea:focus { border-color: var(--border-2); }
.send {
  width: 42px; height: 42px; border-radius: 50%; flex: none; border: 0;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.send:disabled { opacity: .4; }
.send svg { stroke-width: 2.4; }
