/* ===== CHAT WIDGET ===== */

#chat-btn {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 900;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: transparent;
  color: var(--bg);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 24px rgba(0,0,0,0.25);
  transition: transform 0.2s, box-shadow 0.2s;
  padding: 0;
  overflow: hidden;
}

body.chat-open #chat-btn {
  background: var(--text);
  overflow: visible;
  width: 52px;
  height: 52px;
}

#chat-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(0,0,0,0.25);
}

#chat-btn .chat-icon-open  { display: flex; align-items: center; justify-content: center; width: 64px; height: 64px; border-radius: 50%; overflow: hidden; }
#chat-btn .chat-icon-close { display: none; }

body.chat-open #chat-btn .chat-icon-open  { display: none;  }
body.chat-open #chat-btn .chat-icon-close { display: block; }

#chat-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 14px;
  height: 14px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid var(--bg);
  animation: chatPulse 2s ease-in-out infinite;
}

@keyframes chatPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%       { transform: scale(1.2); opacity: 0.7; }
}

body.chat-open #chat-badge { display: none; }

#chat-panel {
  position: fixed;
  bottom: 92px;
  right: 28px;
  z-index: 899;
  width: 340px;
  max-height: 520px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 12px 48px rgba(0,0,0,0.14);
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.22,1,0.36,1);
}

body.chat-open #chat-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

.chat-header-info { flex: 1; }

.chat-header-name {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.chat-header-status {
  font-size: 0.72rem;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 5px;
}

.chat-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
}

/* Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.chat-msg {
  display: flex;
  gap: 8px;
  max-width: 100%;
}

.chat-msg.bot { align-items: flex-end; }
.chat-msg.user { flex-direction: row-reverse; }

.chat-msg-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  font-size: 0.6rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  align-self: flex-end;
}

.chat-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.84rem;
  line-height: 1.55;
  max-width: 240px;
  word-break: break-word;
}

.chat-msg.bot  .chat-bubble {
  background: var(--bg-alt);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.chat-msg.user .chat-bubble {
  background: var(--text);
  color: var(--bg);
  border-bottom-right-radius: 4px;
}

/* Structured rows inside bubble */
.chat-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 0;
  font-size: 0.82rem;
  line-height: 1.4;
}

.chat-ic {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  opacity: 0.55;
}

.chat-ic svg {
  display: block;
}

.chat-contact-block {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Typing indicator */
.chat-typing .chat-bubble {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 12px 16px;
}

.chat-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: typingDot 1.2s ease-in-out infinite;
}

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

@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%            { transform: translateY(-5px); opacity: 1; }
}

/* Quick replies */
.chat-chips {
  padding: 0 16px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}

.chat-chip {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 0.76rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.chat-chip:hover {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

/* Input */
.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 9px 14px;
  font-size: 0.84rem;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

#chat-input:focus { border-color: var(--text); }
#chat-input::placeholder { color: var(--text-faint); }

#chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s;
}

#chat-send:hover { transform: scale(1.08); }

@media (max-width: 480px) {
  #chat-panel {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 84px;
  }
  #chat-btn { right: 16px; bottom: 20px; }
}
