/* =====================================================================
   COACH HORS LIGNE (js/coach.js)
   Panneau à droite sur ordinateur, feuille du bas sur mobile. Mêmes
   tokens que le reste de l'app : surface, texte, accent, relief doux
   réservé au panneau (carte de premier niveau) et au bouton d'envoi.
   ===================================================================== */

.coach-root { position: fixed; inset: 0; z-index: 1200; pointer-events: none; }
.coach-backdrop {
  position: absolute; inset: 0; background: rgba(0, 0, 0, 0.35);
  opacity: 0; transition: opacity 0.2s ease;
}
.coach-panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(420px, 100vw);
  display: flex; flex-direction: column;
  background: var(--surface); color: var(--text);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 32px rgba(0, 0, 0, 0.25);
  transform: translateX(105%); transition: transform 0.25s ease;
}
.coach-root.open { pointer-events: auto; }
.coach-root.open .coach-backdrop { opacity: 1; }
.coach-root.open .coach-panel { transform: none; }
@media (min-width: 1100px) {
  /* Assez de place : le coach se tient à côté du contenu sans l'assombrir. */
  .coach-backdrop { display: none; }
  .coach-root.open { pointer-events: none; }
  .coach-root.open .coach-panel { pointer-events: auto; }
}

.coach-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 14px 12px 16px; border-bottom: 1px solid var(--border);
}
.coach-avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.coach-avatar svg { width: 18px; height: 18px; }
.coach-id { flex: 1; min-width: 0; }
.coach-name { font-weight: 700; font-size: 15px; }
.coach-sub { font-size: 12px; color: var(--text-2); }

.coach-log {
  flex: 1; overflow-y: auto; padding: 14px 16px 8px;
  display: flex; flex-direction: column; gap: 10px;
  overscroll-behavior: contain;
}
/* Une ligne = une bulle ; côté coach, un petit avatar sur la première
   bulle de chaque réponse, un retrait aligné sur les suivantes. */
.coach-row { display: flex; align-items: flex-end; gap: 8px; animation: coachIn 0.22s ease-out both; }
.coach-row-me { justify-content: flex-end; animation-name: coachInMe; }
.coach-row.is-cont { margin-top: -6px; }
.coach-mini {
  width: 26px; height: 26px; flex: none; border-radius: 50%;
  display: grid; place-items: center; color: var(--accent); background: var(--accent-soft);
}
.coach-row.is-cont .coach-mini { background: transparent; }
.coach-mini svg { width: 14px; height: 14px; }
.coach-msg { max-width: 86%; font-size: 14px; line-height: 1.5; min-width: 0; overflow-wrap: anywhere; }
.coach-me {
  background: var(--accent); color: #fff;
  padding: 8px 12px; border-radius: 18px 18px 4px 18px;
}
.coach-coach {
  background: var(--surface-2);
  padding: 10px 12px; border-radius: 18px 18px 18px 4px;
  display: flex; flex-direction: column; gap: 8px;
}
.coach-row.is-cont .coach-coach { border-top-left-radius: 6px; }

/* « Le coach écrit… » : trois points qui rebondissent. */
.coach-row.is-dots .coach-coach { padding: 12px 14px; }
.coach-dots { display: inline-flex; gap: 4px; align-items: center; height: 10px; }
.coach-dots i {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-3);
  animation: coachDot 1.1s infinite ease-in-out;
}
.coach-dots i:nth-child(2) { animation-delay: 0.15s; }
.coach-dots i:nth-child(3) { animation-delay: 0.3s; }
.coach-panel.is-typing .coach-sub { color: var(--accent); }
.coach-panel.is-typing .coach-avatar { animation: coachPulse 1.2s infinite ease-in-out; }

/* Révélation progressive : un bloc pas encore « écrit » ne prend pas de
   place visible (pas de puce de liste vide), puis apparaît. */
.coach-wait { display: none !important; }
.coach-in { animation: coachFade 0.3s ease-out both; }

@keyframes coachIn { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes coachInMe { from { opacity: 0; transform: translateX(10px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes coachDot { 0%, 60%, 100% { transform: translateY(0); opacity: 0.45; } 30% { transform: translateY(-4px); opacity: 1; } }
@keyframes coachPulse { 0%, 100% { box-shadow: 0 0 0 0 var(--accent-soft); } 50% { box-shadow: 0 0 0 5px var(--accent-soft); } }
@keyframes coachFade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.coach-part p { margin: 0; }
.coach-part ul { margin: 4px 0 0; padding-left: 18px; }
.coach-part li { margin: 2px 0; }
.coach-part-title { font-weight: 700; font-size: 13px; margin-bottom: 2px; }
.coach-meta { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 2px; }
.coach-warn { border-left: 3px solid var(--warning, #e0a030); padding-left: 8px; }
.coach-alert { border-left: 3px solid var(--danger); padding-left: 8px; }
.coach-alert .coach-part-title { color: var(--danger); }
.coach-src { margin-top: 4px !important; font-size: 11px; color: var(--text-3); }
.coach-info { border-left: 3px solid var(--accent); padding-left: 8px; color: var(--text-2); }
.coach-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }

.coach-chips {
  display: flex; gap: 6px; padding: 6px 16px 8px;
  overflow-x: auto; scrollbar-width: none;
}
.coach-chips::-webkit-scrollbar { display: none; }
.coach-chip {
  flex: none; font: inherit; font-size: 13px; cursor: pointer;
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: transparent; color: var(--text);
}
.coach-chip:hover { border-color: var(--accent); color: var(--accent); }

.coach-form {
  display: flex; gap: 8px; padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.coach-input {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; /* 16 px : pas de zoom iOS */
  padding: 10px 14px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
}
.coach-input:focus { outline: none; border-color: var(--accent); }
.coach-send { border-radius: 50%; width: 44px; height: 44px; padding: 0; display: grid; place-items: center; }

/* Mobile : feuille du bas, au-dessus de la barre de navigation. */
@media (max-width: 768px) {
  .coach-panel {
    top: auto; left: 0; right: 0; width: 100%;
    height: min(86vh, 720px); height: min(86dvh, 720px);
    border-left: 0; border-top: 1px solid var(--border);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -12px 32px rgba(0, 0, 0, 0.3);
    transform: translateY(105%);
  }
  .coach-head::before {
    content: ""; position: absolute; top: 6px; left: 50%; width: 36px; height: 4px;
    margin-left: -18px; border-radius: 2px; background: var(--border-strong);
  }
  .coach-head { position: relative; padding-top: 18px; }
}
html.coach-open { overflow: hidden; }
@media (min-width: 1100px) { html.coach-open { overflow: auto; } }

.coach-why svg { width: 14px; height: 14px; vertical-align: -0.15em; }
.topbar-btn.coach-btn[aria-expanded="true"] { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  .coach-panel, .coach-backdrop { transition: none; }
  .coach-row, .coach-in, .coach-dots i, .coach-panel.is-typing .coach-avatar { animation: none; }
}
