/* ─── CHAT WIDGET — Adapté aux couleurs site-assistantcourtier-com ─── */

/* ─── FAB ─── */

.chat-widget__fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10001;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  background: var(--p2-ink);
  color: var(--p2-sand);
  cursor: pointer;
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.2),
    0 8px 32px rgba(0, 0, 0, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s cubic-bezier(0.34, 1.3, 0.64, 1), box-shadow 0.25s ease;
}

.chat-widget__fab:hover {
  transform: scale(1.1);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.25),
    0 12px 40px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.chat-widget__fab:active {
  transform: scale(0.95);
}

.chat-widget__fab svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
  transition: transform 0.3s cubic-bezier(0.34, 1.3, 0.64, 1), opacity 0.2s;
}

.chat-widget__fab--open .chat-widget__icon-chat { display: none; }
.chat-widget__fab--open .chat-widget__icon-close { display: block; }
.chat-widget__fab:not(.chat-widget__fab--open) .chat-widget__icon-close { display: none; }

/* Pulse subtil au repos */
@keyframes chat-fab-pulse {
  0%, 100% { box-shadow: 0 2px 8px rgba(0,0,0,0.2), 0 8px 32px rgba(0,0,0,0.15), 0 0 0 0 rgba(var(--p2-terra-rgb),0); }
  50% { box-shadow: 0 2px 8px rgba(0,0,0,0.2), 0 8px 32px rgba(0,0,0,0.15), 0 0 0 8px rgba(var(--p2-terra-rgb),0.08); }
}

.chat-widget__fab:not(.chat-widget__fab--open) {
  animation: chat-fab-pulse 4s ease-in-out infinite;
}

.chat-widget__fab:hover {
  animation: none;
}

/* ─── PANEL ─── */

.chat-widget__panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  z-index: 10000;
  width: 400px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100dvh - 120px);
  border-radius: 20px;
  background: var(--p2-sand);
  color: var(--p2-ink);
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.08),
    0 16px 64px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(0.97);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.22, 1, 0.36, 1), transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.chat-widget__panel--visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ─── HEADER ─── */

.chat-widget__header {
  padding: 18px 20px;
  background: var(--p2-ink);
  color: var(--p2-sand);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.chat-widget__header::after {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
}

.chat-widget__header-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--p2-terra-light);
  flex-shrink: 0;
  box-shadow: 0 0 6px rgba(var(--p2-terra-rgb), 0.4);
  animation: chat-dot-glow 3s ease-in-out infinite;
}

@keyframes chat-dot-glow {
  0%, 100% { box-shadow: 0 0 4px rgba(var(--p2-terra-rgb), 0.3); }
  50% { box-shadow: 0 0 8px rgba(var(--p2-terra-rgb), 0.5); }
}

.chat-widget__header-title {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.chat-widget__header-sub {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  opacity: 0.35;
  margin-left: auto;
}

/* ─── MESSAGES ─── */

.chat-widget__messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.chat-widget__messages::-webkit-scrollbar {
  width: 4px;
}

.chat-widget__messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-widget__messages::-webkit-scrollbar-thumb {
  background: rgba(var(--p2-ink-rgb), 0.12);
  border-radius: 2px;
}

/* ─── MESSAGE BUBBLES ─── */

.chat-widget__msg {
  max-width: 88%;
  padding: 11px 15px;
  border-radius: 14px;
  font-family: 'Bricolage Grotesque', system-ui, sans-serif;
  font-size: 13.5px;
  line-height: 1.55;
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: chat-msg-in 0.25s cubic-bezier(0.22, 1, 0.36, 1) both;
}

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

.chat-widget__msg--assistant {
  align-self: flex-start;
  background: var(--p2-cream);
  border: 1px solid rgba(var(--p2-terra-rgb), 0.08);
  border-bottom-left-radius: 4px;
  white-space: normal;
}

.chat-widget__msg--assistant strong {
  font-weight: 700;
  color: var(--p2-ink);
}

.chat-widget__msg--assistant em {
  font-style: italic;
}

.chat-widget__msg--assistant code {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.88em;
  background: rgba(var(--p2-terra-rgb), 0.08);
  padding: 1px 5px;
  border-radius: 4px;
}

.chat-widget__msg--assistant ul,
.chat-widget__msg--assistant ol {
  margin: 6px 0;
  padding-left: 18px;
}

.chat-widget__msg--assistant li {
  margin: 3px 0;
}

.chat-widget__msg--assistant li::marker {
  color: var(--p2-terra);
}

.chat-widget__msg--user {
  align-self: flex-end;
  background: var(--p2-ink);
  color: var(--p2-sand);
  border-bottom-right-radius: 4px;
}

/* ─── WELCOME + STARTERS ─── */

.chat-widget__welcome-zone {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 4px 0 8px;
}

.chat-widget__welcome-text {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: 19px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--p2-ink);
  letter-spacing: -0.2px;
}

.chat-widget__welcome-sub {
  font-family: 'Bricolage Grotesque', system-ui, sans-serif;
  font-size: 12.5px;
  color: rgba(var(--p2-ink-rgb), 0.45);
  line-height: 1.5;
  margin-top: -8px;
}

.chat-widget__starters {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-widget__starter {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(var(--p2-terra-rgb), 0.1);
  background: var(--p2-cream);
  cursor: pointer;
  font-family: 'Bricolage Grotesque', system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.4;
  color: var(--p2-ink);
  text-align: left;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
  animation: chat-starter-in 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.chat-widget__starter:nth-child(1) { animation-delay: 0.1s; }
.chat-widget__starter:nth-child(2) { animation-delay: 0.17s; }
.chat-widget__starter:nth-child(3) { animation-delay: 0.24s; }
.chat-widget__starter:nth-child(4) { animation-delay: 0.31s; }

@keyframes chat-starter-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-widget__starter:hover {
  border-color: rgba(var(--p2-terra-rgb), 0.25);
  background: rgba(var(--p2-terra-rgb), 0.04);
}

.chat-widget__starter:active {
  transform: scale(0.98);
}

.chat-widget__starter-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(var(--p2-terra-rgb), 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
}

.chat-widget__starter-text {
  flex: 1;
}

.chat-widget__starter-arrow {
  font-family: 'Bricolage Grotesque', system-ui, sans-serif;
  font-size: 14px;
  color: rgba(var(--p2-ink-rgb), 0.2);
  transition: color 0.2s, transform 0.2s;
  flex-shrink: 0;
}

.chat-widget__starter:hover .chat-widget__starter-arrow {
  color: var(--p2-terra);
  transform: translateX(2px);
}

/* ─── TYPING INDICATOR ─── */

.chat-widget__typing {
  align-self: flex-start;
  display: flex;
  gap: 5px;
  padding: 12px 16px;
  background: var(--p2-cream);
  border: 1px solid rgba(var(--p2-terra-rgb), 0.08);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  animation: chat-msg-in 0.25s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.chat-widget__typing-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--p2-terra);
  opacity: 0.3;
  animation: chat-bounce 1.4s ease-in-out infinite;
}

.chat-widget__typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-widget__typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes chat-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
  30% { transform: translateY(-4px); opacity: 0.8; }
}

/* ─── INPUT ─── */

.chat-widget__input-area {
  padding: 12px 14px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(var(--p2-ink-rgb), 0.05);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
  background: var(--p2-sand);
}

.chat-widget__input {
  flex: 1;
  border: 1.5px solid rgba(var(--p2-ink-rgb), 0.08);
  border-radius: 12px;
  padding: 10px 14px;
  font-family: 'Bricolage Grotesque', system-ui, sans-serif;
  font-size: 13.5px;
  line-height: 1.4;
  resize: none;
  min-height: 40px;
  max-height: 100px;
  background: var(--p2-cream);
  color: var(--p2-ink);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-widget__input:focus {
  border-color: var(--p2-terra);
  box-shadow: 0 0 0 3px rgba(var(--p2-terra-rgb), 0.08);
}

.chat-widget__input::placeholder {
  color: rgba(var(--p2-ink-rgb), 0.3);
}

.chat-widget__send {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: var(--p2-ink);
  color: var(--p2-sand);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
}

.chat-widget__send:hover {
  background: var(--p2-warm);
}

.chat-widget__send:active {
  transform: scale(0.93);
}

.chat-widget__send:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

.chat-widget__send:disabled:active {
  transform: none;
}

.chat-widget__send svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* ─── ERROR ─── */

.chat-widget__error {
  align-self: center;
  font-size: 12px;
  color: #b44;
  text-align: center;
  padding: 6px 14px;
  background: rgba(187, 68, 68, 0.05);
  border-radius: 8px;
  animation: chat-msg-in 0.25s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* ─── MOBILE ─── */

@media (max-width: 480px) {
  .chat-widget__panel {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .chat-widget__fab--open {
    display: none;
  }

  .chat-widget__header {
    padding: 16px;
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
  }

  .chat-widget__close-mobile {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.06);
    color: var(--p2-sand);
    cursor: pointer;
    margin-left: auto;
    border-radius: 8px;
    transition: background 0.15s;
  }

  .chat-widget__close-mobile:hover {
    background: rgba(255, 255, 255, 0.12);
  }

  .chat-widget__welcome-text {
    font-size: 22px;
  }
}

@media (min-width: 481px) {
  .chat-widget__close-mobile {
    display: none;
  }
}
