/* ===== Léonard : style « Atelier 3D » =====
   Fond strié comme des couches d'impression, orange PLA, angles chanfreinés,
   messages qui « s'impriment » de bas en haut. */

* { box-sizing: border-box; margin: 0; }

:root {
  --fond: #161719;
  --plateau: #1C1D20;     /* en-tête, saisie */
  --piece: #24262A;       /* bulles de Léonard, cartes */
  --trait: #3A3C42;
  --pla: #FF7A1A;         /* l'orange */
  --pla-sombre: #E86A0C;
  --encre-pla: #1A0E04;   /* texte posé sur l'orange */
  --texte: #ECEDEE;
  --doux: #A3A6AD;
  --erreur: #FF6B6B;
  --chanfrein: 10px;
}

html, body { height: 100%; }

body {
  display: flex;
  flex-direction: column;
  background-color: var(--fond);
  background-image: repeating-linear-gradient(0deg, rgba(255,255,255,.028) 0 1px, transparent 1px 4px);
  color: var(--texte);
  font: 16px/1.45 "Archivo", system-ui, sans-serif;
  font-variation-settings: "wdth" 100;
  -webkit-font-smoothing: antialiased;
}

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

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

/* ---------- En-tête ---------- */
.entete {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 16px 12px;
  padding-top: max(16px, env(safe-area-inset-top));
  background: var(--plateau);
  border-bottom: 2px solid var(--pla);
}
.identite { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.identite h1 {
  font-size: 25px; line-height: 1; font-weight: 800;
  font-variation-settings: "wdth" 125;
}
.statut { font-size: 12px; color: var(--doux); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.outils { display: flex; align-items: center; gap: 6px; }

.btn-icone {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--trait); background: transparent; color: var(--texte);
  clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
}
.btn-icone:hover { border-color: var(--pla); color: var(--pla); }

/* Avatar qui s'imprime */
.couche { fill: var(--pla); transform-box: fill-box; transform-origin: center; transform: scaleX(0); animation: couche .18s ease-out forwards; animation-delay: calc(var(--i) * 70ms); }
.couche.sombre { fill: var(--pla-sombre); }
.yeux { fill: var(--fond); }
.buse { animation: buse 2.4s ease-in-out infinite; }
.avatar-grand.reflechit .buse { animation-duration: .7s; }
@keyframes couche { to { transform: scaleX(1); } }
@keyframes buse { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(34px); } }

/* Jauge bobine */
.jauge { position: relative; display: flex; flex-direction: column; align-items: center; cursor: default; }
.jauge-arc { stroke: var(--pla); transition: stroke-dasharray .8s ease, stroke .5s ease; }
.jauge-arc.moyen { stroke: #F5B400; }
.jauge-arc.haut { stroke: var(--erreur); }
.jauge-texte { font-size: 10px; color: var(--doux); margin-top: 1px; white-space: nowrap; }

/* ---------- Conversation ---------- */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.msg { max-width: 84%; padding: 11px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Toi : orange, chanfrein en bas à droite */
.msg.user {
  background: var(--pla); color: var(--encre-pla); font-weight: 600;
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - var(--chanfrein)), calc(100% - var(--chanfrein)) 100%, 0 100%);
}

/* Léonard : avatar + pièce grise, chanfrein en haut à gauche */
.ligne.assistant .msg { max-width: calc(92% - 38px); }
.avatar-mini { flex: 0 0 auto; width: 30px; height: 32px; }
.msg.assistant {
  background: var(--piece);
  clip-path: polygon(var(--chanfrein) 0, 100% 0, 100% 100%, 0 100%, 0 var(--chanfrein));
}

/* Rappels et alertes : contour pointillé orange, comme une pièce en attente d'impression */
.msg.rappel {
  width: 100%; max-width: none;
  display: flex; align-items: center; gap: 10px;
  border: 2px dashed var(--pla); color: #FFD2B0; font-size: 15px;
}
.msg.rappel svg { flex: 0 0 auto; }

.msg.error {
  max-width: 92%;
  border: 2px solid var(--erreur); color: var(--erreur); font-size: 14px;
}

/* « Léonard imprime sa réponse » */
.impression { display: flex; flex-direction: column; gap: 6px; width: 170px; padding: 4px 0; }
.impression span { font-size: 12px; color: var(--doux); }
.impression .rail { height: 6px; background: #2F3136; overflow: hidden; }
.impression .avance { height: 6px; width: 30%; background: var(--pla); animation: avance 2.2s ease-in-out infinite alternate; }
@keyframes avance { from { width: 8%; } to { width: 92%; } }

/* Chaque message vit dans une « ligne » : c'est elle qui s'anime,
   la bulle garde ses angles chanfreinés (deux clip-path séparés). */
.ligne { display: flex; align-items: flex-end; gap: 8px; }
.ligne.user { justify-content: flex-end; }
.ligne.assistant { justify-content: flex-start; }
.ligne.rappel, .ligne.brouillon, .ligne.error { justify-content: center; }

/* Arrivée : le message s'imprime de bas en haut, couche par couche */
.ligne.imprime { animation: imprime .7s steps(12) both; }
.ligne.imprime .avatar-mini { animation: pop .3s ease-out .5s both; }
@keyframes imprime { from { clip-path: inset(100% 0 0 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Brouillon de mail ---------- */
.msg.brouillon {
  width: 100%; max-width: none;
  background: var(--piece);
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px;
  white-space: normal;
  clip-path: polygon(14px 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%, 0 14px);
}
.brouillon-titre { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--doux); }
.champ { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.champ span { width: 44px; color: var(--doux); }
.msg.brouillon input, .msg.brouillon textarea {
  flex: 1; width: 100%;
  padding: 8px 10px;
  border: 2px solid var(--trait); background: var(--fond); color: var(--texte);
  font: inherit; font-size: 15px;
  resize: vertical;
}
.msg.brouillon input:focus, .msg.brouillon textarea:focus { border-color: var(--pla); outline: none; }
.msg.brouillon input:disabled, .msg.brouillon textarea:disabled { opacity: .6; }
.brouillon-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-action {
  height: 46px; padding: 0 14px;
  border: 2px solid var(--trait); background: transparent; color: var(--texte);
  font-weight: 600; font-size: 14px;
}
.btn-action.primaire {
  flex: 1; border: none; background: var(--pla); color: var(--encre-pla);
  font-weight: 700; font-size: 15px; font-variation-settings: "wdth" 115;
}
.btn-action.discret { border-color: transparent; color: var(--doux); font-weight: 500; }
.btn-action:disabled { opacity: .5; cursor: default; }
.brouillon-statut { font-size: 14px; color: var(--doux); }
.brouillon-statut.ok { color: var(--pla); font-weight: 600; }

/* ---------- Saisie ---------- */
.saisie {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 12px 14px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  background: var(--plateau);
}
.saisie textarea {
  flex: 1; resize: none;
  min-height: 48px; max-height: 140px;
  padding: 12px 14px;
  border: 2px solid var(--trait); background: var(--fond); color: var(--texte);
  font: inherit; font-size: 16px;
}
.saisie textarea:focus { border-color: var(--pla); outline: none; }
.btn-envoi {
  width: 48px; height: 48px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  border: none; background: var(--pla); color: var(--encre-pla);
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
  transition: transform .1s ease;
}
.btn-envoi:active { transform: translateY(2px); }
.btn-envoi:disabled { opacity: .45; cursor: default; }

/* Boutons photo / micro dans la saisie */
.saisie .btn-icone { width: 48px; height: 48px; flex: 0 0 auto; }
.btn-icone.petit { width: 36px; height: 36px; }
.btn-icone[aria-pressed="true"] { border-color: var(--pla); color: var(--pla); }
#voix-btn .barre { display: inline; }
#voix-btn .ondes { display: none; }
#voix-btn[aria-pressed="true"] .barre { display: none; }
#voix-btn[aria-pressed="true"] .ondes { display: inline; }

/* Micro qui écoute : pulsation orange */
#micro-btn.ecoute { background: var(--pla); color: var(--encre-pla); border-color: var(--pla); animation: ecoute 1.2s ease-in-out infinite; }
@keyframes ecoute { 0%, 100% { filter: none; } 50% { filter: brightness(1.25); } }

/* Aperçu de la photo jointe */
.apercu {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px 0;
  background: var(--plateau);
  font-size: 13px; color: var(--doux);
}
.apercu img { width: 48px; height: 48px; object-fit: cover; border: 2px solid var(--pla); }
.apercu span { flex: 1; }

/* Photo dans ta bulle */
.msg.user img { display: block; max-width: 100%; max-height: 220px; margin-bottom: 8px; }

/* Grand écran : la conversation reste lisible au centre */
@media (min-width: 720px) {
  #messages, .saisie, .entete, .apercu { padding-left: max(14px, calc((100% - 680px) / 2)); padding-right: max(14px, calc((100% - 680px) / 2)); }
}

@media (max-width: 380px) {
  .statut { display: none; }
  .saisie .btn-icone, .btn-envoi { width: 44px; height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .couche { transform: none; }
}

/* ---------- Page de connexion ---------- */
.page-login { align-items: center; justify-content: center; }
.login {
  width: min(360px, 100% - 32px);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 32px 24px;
  background: var(--plateau);
  clip-path: polygon(16px 0, 100% 0, 100% calc(100% - 16px), calc(100% - 16px) 100%, 0 100%, 0 16px);
}
.login h1 { font-size: 34px; font-weight: 800; font-variation-settings: "wdth" 125; }
.login-form { width: 100%; display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.login-form label { font-size: 13px; color: var(--doux); }
.login-form input {
  height: 48px; padding: 0 14px;
  border: 2px solid var(--trait); background: var(--fond); color: var(--texte);
  font: inherit; font-size: 16px;
}
.login-form input:focus { border-color: var(--pla); outline: none; }
.login-form .btn-action.primaire { flex: none; height: 48px; }
.login-erreur { min-height: 20px; font-size: 14px; color: var(--erreur); }
