/* ─── EDAP AI Chat Widget ─── */
:root {
  --chat-primary: #4F46E5;
  --chat-primary-hover: #4338CA;
  --chat-bg: #ffffff;
  --chat-header-bg: linear-gradient(135deg, #4F46E5 0%, #3730A3 100%);
  --chat-user-bg: #4F46E5;
  --chat-user-text: #ffffff;
  --chat-bot-bg: #F3F4F6;
  --chat-bot-text: #1F2937;
  --chat-border: #E5E7EB;
  --chat-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
  --chat-radius: 16px;
  --chat-font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ─── Chat Launcher (pill FAB) ─── */
.edap-chat-fab {
  position: fixed;
  bottom: 90px;
  right: 24px;
  height: 52px;
  padding: 0 22px 0 16px;
  border-radius: 26px;
  background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 16px rgba(79, 70, 229, 0.35);
  z-index: 9998;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  font-family: 'Plus Jakarta Sans', var(--chat-font);
}
.edap-chat-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(79, 70, 229, 0.45);
}
.edap-chat-fab-icon {
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.edap-chat-fab-icon svg {
  width: 24px;
  height: 24px;
}
.edap-chat-fab-label {
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.edap-chat-fab.open {
  padding: 0 18px;
  gap: 8px;
}
.edap-chat-fab.open .edap-chat-fab-label {
  display: none;
}

/* Hide HubSpot chat widget — replaced by EDAP AI Assistant */
#hubspot-messages-iframe-container { display: none !important; }

/* ─── Chat Window ─── */
.edap-chat-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 400px;
  max-width: calc(100vw - 32px);
  height: 680px;
  max-height: calc(100vh - 120px);
  background: var(--chat-bg);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  font-family: var(--chat-font);
}
.edap-chat-window.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ─── Header ─── */
.edap-chat-header {
  background: var(--chat-header-bg);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.edap-chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.edap-chat-avatar svg {
  width: 32px;
  height: 32px;
}
.edap-chat-header-info h4 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: 'Plus Jakarta Sans', var(--chat-font);
}
.edap-chat-header-info p {
  margin: 2px 0 0;
  font-size: 0.75rem;
  opacity: 0.85;
  color: #fff !important;
}
.edap-chat-close {
  margin-left: auto;
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  opacity: 0.8;
  transition: opacity 0.2s;
}
.edap-chat-close:hover { opacity: 1; }

/* ─── Messages Area ─── */
.edap-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.edap-chat-messages { scrollbar-width: thin; scrollbar-color: #D1D5DB transparent; }
.edap-chat-messages::-webkit-scrollbar { width: 4px; }
.edap-chat-messages::-webkit-scrollbar-track { background: transparent; }
.edap-chat-messages::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 4px; }

/* ─── Message Bubbles ─── */
.chat-msg {
  display: flex;
  gap: 8px;
  max-width: 88%;
  animation: msg-in 0.3s ease;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.chat-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg.bot { align-self: flex-start; }

.chat-msg-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.7rem;
  margin-top: 2px;
}
.chat-msg.bot .chat-msg-icon {
  background: var(--chat-primary);
  color: #fff;
}
.chat-msg.user .chat-msg-icon {
  background: #E5E7EB;
  color: #6B7280;
}

.chat-msg-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-break: break-word;
}
.chat-msg.user .chat-msg-bubble {
  background: var(--chat-user-bg);
  color: var(--chat-user-text);
  border-bottom-right-radius: 4px;
}
.chat-msg.bot .chat-msg-bubble {
  background: var(--chat-bot-bg);
  color: var(--chat-bot-text);
  border-bottom-left-radius: 4px;
}

/* Markdown in bot messages */
.chat-msg.bot .chat-msg-bubble p { margin: 0 0 8px; }
.chat-msg.bot .chat-msg-bubble p:last-child { margin-bottom: 0; }
.chat-msg.bot .chat-msg-bubble ul,
.chat-msg.bot .chat-msg-bubble ol {
  margin: 4px 0 8px;
  padding-left: 18px;
}
.chat-msg.bot .chat-msg-bubble li { margin-bottom: 2px; }
.chat-msg.bot .chat-msg-bubble strong { font-weight: 600; }
.chat-msg.bot .chat-msg-bubble a {
  color: var(--chat-primary);
  text-decoration: underline;
}

/* ─── Feedback Buttons ─── */
.chat-msg-feedback {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}
.chat-msg-feedback button {
  background: none;
  border: 1px solid #E5E7EB;
  border-radius: 6px;
  padding: 3px 8px;
  cursor: pointer;
  font-size: 0.75rem;
  color: #9CA3AF;
  transition: all 0.2s;
}
.chat-msg-feedback button:hover {
  border-color: var(--chat-primary);
  color: var(--chat-primary);
}
.chat-msg-feedback button.active {
  background: var(--chat-primary);
  border-color: var(--chat-primary);
  color: #fff;
}

/* ─── Typing Indicator ─── */
.chat-typing {
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  background: var(--chat-bot-bg);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  width: fit-content;
  align-self: flex-start;
}
.chat-typing span {
  width: 6px;
  height: 6px;
  background: #9CA3AF;
  border-radius: 50%;
  animation: typing-dot 1.4s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ─── Input Area ─── */
.edap-chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--chat-border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
  background: #FAFAFA;
}
.edap-chat-input {
  flex: 1;
  border: 1px solid var(--chat-border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.875rem;
  font-family: var(--chat-font);
  resize: none;
  outline: none;
  max-height: 80px;
  line-height: 1.4;
  transition: border-color 0.2s;
  background: #fff;
}
.edap-chat-input:focus {
  border-color: var(--chat-primary);
}
.edap-chat-input::placeholder {
  color: #9CA3AF;
}
.edap-chat-send {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--chat-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}
.edap-chat-send:hover { background: var(--chat-primary-hover); }
.edap-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }
.edap-chat-send svg { width: 18px; height: 18px; }

/* ─── Footer ─── */
.edap-chat-footer {
  text-align: center;
  padding: 6px;
  font-size: 0.68rem;
  color: #9CA3AF;
  border-top: 1px solid var(--chat-border);
  flex-shrink: 0;
  background: #FAFAFA;
}

/* ─── Quick Action Chips ─── */
.chat-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 4px;
}
.chat-quick-btn {
  background: #fff;
  border: 1px solid var(--chat-border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.78rem;
  color: var(--chat-primary);
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--chat-font);
  white-space: nowrap;
}
.chat-quick-btn:hover {
  background: var(--chat-primary);
  color: #fff;
  border-color: var(--chat-primary);
}

/* ─── Session Rating Overlay ─── */
.edap-chat-rating-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.96);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  border-radius: var(--chat-radius);
}
.edap-chat-rating-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}
.edap-rating-content {
  text-align: center;
  padding: 24px;
  position: relative;
}
.edap-rating-skip {
  position: absolute;
  top: -8px;
  right: -8px;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: #9CA3AF;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}
.edap-rating-skip:hover { color: #4B5563; }
.edap-rating-title {
  font-family: 'Plus Jakarta Sans', var(--chat-font);
  font-size: 1.1rem;
  font-weight: 600;
  color: #1F2937;
  margin: 0 0 20px;
}
.edap-rating-options {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 16px;
}
.edap-rating-options button {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  border: 2px solid var(--chat-border);
  background: #fff;
  font-size: 1.6rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.edap-rating-options button:hover {
  border-color: var(--chat-primary);
  transform: scale(1.12);
}
.edap-rating-options button.selected {
  border-color: var(--chat-primary);
  background: var(--chat-primary);
  transform: scale(1.15);
}
.edap-rating-sub {
  font-size: 0.78rem;
  color: #9CA3AF;
  margin: 0;
}

/* ─── Mobile Responsive ─── */
@media (max-width: 480px) {
  .edap-chat-window {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }
  .edap-chat-input-area {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  .edap-chat-fab {
    bottom: 16px;
    right: 16px;
    height: 46px;
    padding: 0 16px 0 12px;
  }
  .edap-chat-fab.open {
    display: none;
  }
}
