/* Assistant IA des sites Kechlab : bouton flottant, panneau, bulles. Plein écran sur téléphone. */

.kc { position: fixed; z-index: 65; right: 14px; bottom: max(14px, env(safe-area-inset-bottom)); }
.mode-demo .kc { bottom: calc(max(10px, env(safe-area-inset-bottom)) + 72px); }

.kc-fab {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; width: 60px; height: 60px; padding: 0;
  border-radius: 999px; border: 1px solid rgba(255, 255, 255, .18); background: var(--accent); color: var(--on-accent);
  box-shadow: 0 18px 40px -14px color-mix(in srgb, var(--accent) 80%, #000), 0 0 0 6px color-mix(in srgb, var(--accent) 16%, transparent);
  font: 700 .95rem/1 var(--sans); cursor: pointer; transition: transform .35s var(--ease), box-shadow .35s var(--ease);
}
.kc-fab .i { width: 26px; height: 26px; }
.kc-fab:hover { transform: translateY(-3px) scale(1.03); }
.kc-fab__label { display: none; }
.kc.is-open .kc-fab { transform: scale(.9); opacity: 0; pointer-events: none; }
.kc-fab:focus-visible { outline: 2px solid var(--ivory); outline-offset: 4px; }
@media (prefers-reduced-motion: no-preference) {
  .kc:not(.is-open) .kc-fab { animation: kc-in .8s .6s var(--ease) both; }
}
@keyframes kc-in { from { opacity: 0; transform: translateY(16px) scale(.9); } }

/* Bulle d'accueil (démo) : à gauche du bouton, sans couvrir les boutons du héros */
.kc-hint {
  position: absolute; right: calc(100% + 10px); bottom: 4px; display: flex; align-items: center; gap: 2px;
  width: max-content; max-width: min(280px, calc(100vw - 104px)); padding: 4px 2px 4px 4px;
  border-radius: 20px 20px 6px 20px; background: var(--ivory); color: var(--ink); box-shadow: 0 24px 50px -18px rgba(0, 0, 0, .6);
}
.kc-hint[hidden] { display: none; }
.kc-hint__go {
  display: grid; gap: 2px; min-height: 44px; padding: 6px 4px 6px 12px; border: 0; background: none; color: var(--ink); text-align: left;
  font: 400 .84rem/1.3 var(--sans);
}
.kc-hint__go strong { font-weight: 700; font-size: .92rem; }
.kc-hint__x { display: grid; place-items: center; width: 40px; height: 44px; flex: none; border-radius: 50%; border: 0; background: transparent; color: var(--ink); }
.kc-hint :focus-visible { outline-color: var(--ink); }
@media (prefers-reduced-motion: no-preference) {
  .kc-hint:not([hidden]) { animation: kc-pop .5s var(--ease) both; }
}
@keyframes kc-pop { from { opacity: 0; transform: translateX(10px) scale(.96); transform-origin: right center; } }

/* Panneau */
.kc-panel {
  position: fixed; inset: 0; z-index: 95; display: flex; flex-direction: column;
  height: 100dvh; background: var(--surface); color: var(--text);
}
.kc-panel[hidden] { display: none; }
@media (prefers-reduced-motion: no-preference) {
  .kc-panel:not([hidden]) { animation: kc-panel .45s var(--ease) both; }
}
@keyframes kc-panel { from { opacity: 0; transform: translateY(24px); } }

.kc-head {
  display: flex; align-items: center; gap: 12px; padding: calc(12px + env(safe-area-inset-top)) 12px 12px 16px;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.kc-avatar { width: 40px; height: 40px; font-size: .9rem; }
.kc-head__txt { flex: 1; min-width: 0; }
.kc-title { margin: 0; font: 700 1rem/1.2 var(--sans); letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kc-sub { display: flex; align-items: center; gap: 6px; margin: 2px 0 0; font-size: .82rem; color: var(--muted); }
.kc-dot { width: 7px; height: 7px; border-radius: 50%; background: #3fbf7f; }
.kc-close { display: grid; place-items: center; width: 44px; height: 44px; flex: none; border-radius: 50%; border: 1px solid var(--line); background: var(--soft); color: var(--text); }

.kc-log { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 18px 14px 8px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.kc-msg { max-width: 86%; }
.kc-msg p { margin: 0; padding: 11px 15px; border-radius: 20px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .98rem; line-height: 1.45; }
.kc-msg--assistant { align-self: flex-start; }
.kc-msg--assistant p { background: var(--field, color-mix(in srgb, var(--text) 6%, var(--surface))); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.kc-msg--user { align-self: flex-end; }
.kc-msg--user p { background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 6px; }
.kc-typing { display: inline-flex; gap: 5px; padding: 15px 16px; border-radius: 20px 20px 20px 6px; background: color-mix(in srgb, var(--text) 6%, var(--surface)); border: 1px solid var(--line); }
.kc-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); opacity: .5; }
@media (prefers-reduced-motion: no-preference) {
  .kc-typing span { animation: kc-dot 1.2s infinite ease-in-out; }
  .kc-typing span:nth-child(2) { animation-delay: .15s; }
  .kc-typing span:nth-child(3) { animation-delay: .3s; }
}
@keyframes kc-dot { 0%, 80%, 100% { transform: translateY(0); opacity: .4; } 40% { transform: translateY(-4px); opacity: 1; } }
.kc-note { align-self: stretch; padding: 12px 14px; border-radius: 16px; background: color-mix(in srgb, var(--accent) 10%, transparent); border: 1px dashed color-mix(in srgb, var(--accent) 40%, transparent); font-size: .92rem; }
.kc-note p { margin: 0; }
.kc-note__row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.kc-act { display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-weight: 600; text-decoration: none; }

.kc-chips { display: flex; gap: 8px; padding: 4px 14px 10px; overflow-x: auto; scrollbar-width: none; }
.kc-chips[hidden] { display: none; }
.kc-chips::-webkit-scrollbar { display: none; }
.kc-chip {
  flex: none; min-height: 44px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line-2, var(--line));
  background: transparent; color: var(--text); font: 500 .92rem/1 var(--sans); white-space: nowrap; transition: background .2s, border-color .2s;
}
.kc-chip:hover { background: var(--soft); border-color: var(--accent); }

.kc-form { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--surface); }
.kc-form textarea {
  flex: 1; min-height: 48px; max-height: 140px; padding: 12px 16px; border-radius: 24px; border: 1px solid var(--line-2, var(--line));
  background: color-mix(in srgb, var(--text) 4%, var(--surface)); color: var(--text); font-size: 1rem; line-height: 1.4; resize: none;
}
.kc-form textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.kc-send { display: grid; place-items: center; width: 48px; height: 48px; flex: none; border-radius: 50%; border: 0; background: var(--accent); color: var(--on-accent); }
.kc-send .i { width: 20px; height: 20px; }
.kc-foot { margin: 0; padding: 0 16px calc(10px + env(safe-area-inset-bottom)); font-size: .76rem; color: var(--muted); background: var(--surface); }

/* Bureau : panneau flottant */
@media (min-width: 641px) {
  .kc-fab { width: auto; padding: 0 22px 0 18px; }
  .kc-fab__label { display: inline; }
  .kc-panel {
    inset: auto 20px 20px auto; width: 400px; height: min(640px, calc(100svh - 120px)); border-radius: 26px; overflow: hidden;
    border: 1px solid var(--line); box-shadow: 0 40px 90px -30px rgba(0, 0, 0, .6);
  }
  .mode-demo .kc-panel { bottom: 92px; height: min(620px, calc(100svh - 190px)); }
  .kc-head { padding-top: 14px; }
  .kc-foot { padding-bottom: 12px; }
}
