/* ============================================================================
   AF2L — Widget Chatbot · v1.0.0 (30/09/2026)
   ----------------------------------------------------------------------------
   100 % préfixé `af2lcb-` : aucune fuite de style vers le site hôte,
   aucune variable globale :root — les tokens vivent dans .af2lcb-root.
   Responsive < 480 px · prefers-reduced-motion respecté · focus visible.
   ============================================================================ */

.af2lcb-root {
  /* Design system AF2L — tokens scopés au widget */
  --af2lcb-indigo: #6366f1;
  --af2lcb-cyan: #06b6d4;
  --af2lcb-violet: #8b5cf6;
  --af2lcb-bg: #0a0a0f;
  --af2lcb-surface: #14141c;
  --af2lcb-surface-2: #1b1b25;
  --af2lcb-text: #f8fafc;
  --af2lcb-text-dim: #a5aac4;
  --af2lcb-border: rgba(99, 102, 241, 0.28);
  --af2lcb-radius: 16px;
  --af2lcb-radius-sm: 14px;
  --af2lcb-shadow: 0 18px 50px rgba(0, 0, 0, 0.45), 0 4px 14px rgba(0, 0, 0, 0.3);
  --af2lcb-ease: cubic-bezier(0.22, 1, 0.36, 1);

  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 2147483000;
  font-family: 'Poppins', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--af2lcb-text);
}

.af2lcb-root *,
.af2lcb-root *::before,
.af2lcb-root *::after {
  box-sizing: border-box;
}

/* ---------------------------------------------------------------- bulle */
.af2lcb-bubble {
  position: relative;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: #ffffff;
  background: linear-gradient(135deg, var(--af2lcb-indigo), var(--af2lcb-violet));
  box-shadow: 0 10px 30px rgba(99, 102, 241, 0.45), 0 3px 10px rgba(0, 0, 0, 0.35);
  transition: transform 0.25s var(--af2lcb-ease), box-shadow 0.25s var(--af2lcb-ease);
}

.af2lcb-bubble__icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease, transform 0.25s var(--af2lcb-ease);
}

.af2lcb-bubble__icon svg {
  width: 26px;
  height: 26px;
}

.af2lcb-bubble__icon--close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.6);
}

.af2lcb-bubble.is-open .af2lcb-bubble__icon--chat {
  opacity: 0;
  transform: rotate(90deg) scale(0.6);
}

.af2lcb-bubble.is-open .af2lcb-bubble__icon--close {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

@media (hover: hover) {
  .af2lcb-bubble:hover {
    transform: translateY(-2px) scale(1.06);
    box-shadow: 0 14px 36px rgba(99, 102, 241, 0.55), 0 4px 12px rgba(0, 0, 0, 0.35);
  }
}

.af2lcb-bubble:active {
  transform: scale(0.95);
}

.af2lcb-bubble:focus-visible {
  outline: 3px solid rgba(6, 182, 212, 0.7);
  outline-offset: 3px;
}

/* --------------------------------------------------------------- panneau */
.af2lcb-panel[hidden] {
  display: none;
}

.af2lcb-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 14px);
  display: flex;
  flex-direction: column;
  /* Blindage anti-collision : le site hôte style des balises nues
     (ex. section { padding:100px 0 } sur aiaf2l.com). Le panneau est
     une <div> ET on force tout à zéro — aucun héritage possible. */
  margin: 0;
  padding: 0;
  width: min(340px, calc(100vw - 40px));
  height: min(480px, calc(100vh - 120px));
  max-height: min(480px, calc(100vh - 120px));
  overflow: hidden;
  background: var(--af2lcb-bg);
  border: 1px solid var(--af2lcb-border);
  border-radius: var(--af2lcb-radius);
  box-shadow: var(--af2lcb-shadow);
  transform-origin: bottom right;
  opacity: 0;
  transform: translateY(10px) scale(0.96);
  transition: opacity 0.24s var(--af2lcb-ease), transform 0.24s var(--af2lcb-ease);
}

@supports (height: 100dvh) {
  .af2lcb-panel {
    height: min(480px, calc(100dvh - 120px));
    max-height: min(480px, calc(100dvh - 120px));
  }
}

.af2lcb-panel.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* ---------------------------------------------------------------- header */
.af2lcb-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  margin: 0;
  padding: 14px 14px 14px 16px;
  background: linear-gradient(160deg, rgba(99, 102, 241, 0.18), rgba(139, 92, 246, 0.08) 55%, transparent);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  flex: 0 0 auto;
}

.af2lcb-header__avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 50%;
  color: #ffffff;
  background: linear-gradient(135deg, var(--af2lcb-indigo), var(--af2lcb-cyan));
}

.af2lcb-header__avatar svg {
  width: 18px;
  height: 18px;
}

/* v1.2 — avatar : personnage détouré par-dessus le disque dégradé */
.af2lcb-header__avatar-img {
  display: none;
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.af2lcb-header__avatar--logo svg {
  display: none;
}

.af2lcb-header__avatar--logo .af2lcb-header__avatar-img {
  display: block;
  filter: drop-shadow(0 1px 1px rgba(10, 10, 15, 0.18));
}

.af2lcb-header__title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--af2lcb-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.af2lcb-header__title small {
  display: block;
  font-size: 11.5px;
  font-weight: 400;
  color: var(--af2lcb-text-dim);
}

.af2lcb-header__new {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: var(--af2lcb-text-dim);
  background: transparent;
  transition: background 0.2s ease, color 0.2s ease;
}

.af2lcb-header__new svg {
  width: 17px;
  height: 17px;
}

@media (hover: hover) {
  .af2lcb-header__new:hover {
    color: var(--af2lcb-text);
    background: rgba(139, 92, 246, 0.2);
  }
}

.af2lcb-header__new:focus-visible {
  outline: 2px solid var(--af2lcb-cyan);
  outline-offset: 2px;
}

.af2lcb-header__new:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ------------------------------------------------------------- messages */
.af2lcb-log {
  flex: 1 1 auto;
  min-height: 0; /* indispensable pour que le flex item scrolle au lieu de pousser la hauteur */
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(99, 102, 241, 0.5) transparent;
}

.af2lcb-log::-webkit-scrollbar {
  width: 6px;
}

.af2lcb-log::-webkit-scrollbar-thumb {
  border-radius: 3px;
  background: rgba(99, 102, 241, 0.5);
}

.af2lcb-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: var(--af2lcb-radius-sm);
  font-size: 13.8px;
  line-height: 1.55;
  animation: af2lcb-msg-in 0.24s var(--af2lcb-ease) both;
}

.af2lcb-msg--user {
  align-self: flex-end;
  color: #ffffff;
  background: var(--af2lcb-indigo);
  border-bottom-right-radius: 4px;
  box-shadow: 0 3px 12px rgba(99, 102, 241, 0.35);
}

.af2lcb-msg--bot {
  align-self: flex-start;
  color: var(--af2lcb-text);
  background: var(--af2lcb-surface);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-bottom-left-radius: 4px;
}

.af2lcb-msg__text {
  margin: 0;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.af2lcb-msg__link {
  display: inline-block;
  margin-top: 4px;
  color: var(--af2lcb-cyan);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.af2lcb-msg__link:hover,
.af2lcb-msg__link:focus-visible {
  color: #22d3ee;
}

@keyframes af2lcb-msg-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* indicateur « en train d'écrire » */
.af2lcb-msg--typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 13px 16px;
}

.af2lcb-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--af2lcb-violet);
  animation: af2lcb-bounce 1.2s ease-in-out infinite;
}

.af2lcb-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.af2lcb-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes af2lcb-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* notice système (rate limit) */
.af2lcb-notice {
  align-self: center;
  max-width: 90%;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.4;
  text-align: center;
  color: #c4b5fd;
  background: rgba(139, 92, 246, 0.12);
  border: 1px solid rgba(139, 92, 246, 0.3);
  animation: af2lcb-msg-in 0.2s var(--af2lcb-ease) both;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.af2lcb-notice.is-leaving {
  opacity: 0;
  transform: translateY(-4px);
}

/* ----------------------------------------------------------------- form */
.af2lcb-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  margin: 0;
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(10, 10, 15, 0.6);
  flex: 0 0 auto;
}

.af2lcb-form__input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--af2lcb-text);
  background: var(--af2lcb-surface-2);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 12px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.af2lcb-form__input::placeholder {
  color: #7a7f9a;
}

.af2lcb-form__input:focus {
  outline: none;
  border-color: var(--af2lcb-indigo);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

.af2lcb-form__input:disabled {
  opacity: 0.6;
}

.af2lcb-form__send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  color: #ffffff;
  background: var(--af2lcb-indigo);
  transition: background 0.2s ease, transform 0.2s var(--af2lcb-ease);
}

.af2lcb-form__send svg {
  width: 19px;
  height: 19px;
}

@media (hover: hover) {
  .af2lcb-form__send:not(:disabled):hover {
    background: var(--af2lcb-violet);
    transform: translateY(-1px);
  }
}

.af2lcb-form__send:not(:disabled):active {
  transform: translateY(0);
}

.af2lcb-form__send:focus-visible {
  outline: 2px solid var(--af2lcb-cyan);
  outline-offset: 2px;
}

.af2lcb-form__send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ------------------------------------------------------------ responsive */
@media (max-width: 480px) {
  .af2lcb-root {
    right: 12px;
    bottom: 12px;
  }

  .af2lcb-bubble {
    width: 52px;
    height: 52px;
  }

  .af2lcb-panel {
    right: -12px;
    bottom: calc(100% + 12px);
    width: calc(100vw - 24px);
    height: min(480px, calc(100vh - 96px));
    max-height: min(480px, calc(100vh - 96px));
    border-radius: var(--af2lcb-radius-sm);
  }

  @supports (height: 100dvh) {
    .af2lcb-panel {
      height: min(480px, calc(100dvh - 96px));
      max-height: min(480px, calc(100dvh - 96px));
    }
  }

  .af2lcb-log {
    padding: 12px;
  }

  .af2lcb-msg {
    max-width: 88%;
  }
}

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

/* ------------------------------------------------------------- impression */
@media print {
  .af2lcb-root {
    display: none !important;
  }
}
