/* ================================================================
   AI Chat Widget
   ================================================================ */
.chat-btn {
  position: fixed; bottom: 24px; left: 24px; z-index: 9999;
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(102,126,234,0.4);
  transition: transform .2s, box-shadow .2s;
}
.chat-btn:hover { transform: scale(1.1); box-shadow: 0 6px 28px rgba(102,126,234,0.55); }
.chat-btn svg { width: 24px; height: 24px; }
.chat-btn .close-icon { display: none; }
.chat-btn.is-open .chat-icon { display: none; }
.chat-btn.is-open .close-icon { display: block; }

/* Chat always on the left so it never overlaps with WhatsApp (always right) */
[dir="rtl"] .chat-btn { left: 24px; right: auto; }

.chat-panel {
  position: fixed; bottom: 92px; left: 24px; z-index: 9998;
  width: 360px; max-height: 520px;
  background: #fff; border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
  display: none; flex-direction: column;
  overflow: hidden;
  animation: chat-slide-up .25s ease;
}
.chat-panel.is-open { display: flex; }

[dir="rtl"] .chat-panel { left: 24px; right: auto; }

@keyframes chat-slide-up {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff; padding: 16px 20px;
  display: flex; align-items: center; gap: 12px;
}
.chat-header h3 { margin: 0; font-size: 0.95rem; font-weight: 600; flex: 1; }
.chat-header .chat-clear-btn {
  background: rgba(255,255,255,0.2); border: none; color: #fff;
  width: 28px; height: 28px; border-radius: 50%;
  cursor: pointer; font-size: 0.7rem;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.chat-header .chat-clear-btn:hover { background: rgba(255,255,255,0.35); }

.chat-messages {
  flex: 1; overflow-y: auto; padding: 16px;
  min-height: 200px; max-height: 340px;
  background: #f8f9fe;
}
.chat-msg {
  margin-bottom: 12px; max-width: 85%;
  padding: 10px 14px; border-radius: 14px;
  font-size: 0.85rem; line-height: 1.55;
  word-wrap: break-word;
  animation: msg-in .2s ease;
}
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.chat-msg.user {
  background: #667eea; color: #fff;
  margin-left: auto; border-bottom-right-radius: 4px;
}
.chat-msg.bot {
  background: #eef0ff; color: #1a1a2e;
  margin-right: auto; border-bottom-left-radius: 4px;
}
[dir="rtl"] .chat-msg.user { margin-left: 0; margin-right: auto; border-bottom-right-radius: 14px; border-bottom-left-radius: 4px; }
[dir="rtl"] .chat-msg.bot { margin-right: 0; margin-left: auto; border-bottom-left-radius: 14px; border-bottom-right-radius: 4px; }
[dir="rtl"] .chat-btn-link { margin-left: 0 !important; margin-right: auto !important; }

.chat-typing {
  display: flex; gap: 4px; align-items: center;
  padding: 10px 14px; margin-bottom: 12px; max-width: 85%;
  background: #eef0ff; border-radius: 14px;
  border-bottom-left-radius: 4px;
  margin-right: auto;
}
[dir="rtl"] .chat-typing { margin-right: auto; margin-left: auto; border-bottom-left-radius: 14px; border-bottom-right-radius: 4px; }
.chat-typing span {
  width: 7px; height: 7px; background: #667eea; border-radius: 50%;
  animation: typing-dot 1.2s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes typing-dot {
  0%, 60%, 100% { opacity: .3; transform: scale(.8); }
  30% { opacity: 1; transform: scale(1.1); }
}

.chat-input-wrap {
  display: flex; padding: 10px 12px; gap: 8px;
  border-top: 1px solid #eee; background: #fff;
}
.chat-input-wrap input {
  flex: 1; border: 1px solid #ddd; border-radius: 24px;
  padding: 10px 14px; font-size: 0.85rem; outline: none;
  transition: border-color .2s;
}
.chat-input-wrap input:focus { border-color: #667eea; }
.chat-input-wrap button {
  width: 40px; height: 40px; border-radius: 50%;
  background: #667eea; color: #fff; border: none;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .2s; flex-shrink: 0;
}
.chat-input-wrap button:hover { background: #5a6fd6; }
.chat-input-wrap button:disabled { opacity: .5; cursor: default; }
.chat-input-wrap button svg { width: 18px; height: 18px; }

.chat-msg-wrap { margin-bottom: 12px; }
.chat-btn-link {
  display: inline-block !important; margin-top: 8px !important; margin-left: auto;
  padding: 8px 18px !important; border-radius: 24px !important;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
  color: #fff !important; font-size: 0.85rem !important; font-weight: 500 !important;
  text-decoration: none !important; border: none !important;
  transition: opacity .2s !important; cursor: pointer !important;
}
[dir="rtl"] .chat-btn-link { margin-left: 0 !important; margin-right: auto !important; }
.chat-btn-link:hover { opacity: .85 !important; color: #fff !important; }
.chat-error {
  background: #fff0f0; color: #d33;
  padding: 8px 14px; margin-bottom: 8px;
  border-radius: 10px; font-size: 0.8rem;
}

.chat-welcome {
  text-align: center; color: #666; font-size: 0.85rem;
  padding: 40px 16px;
}
.chat-welcome .welcome-icon { font-size: 2.5rem; margin-bottom: 12px; }
.chat-welcome h4 { margin: 0 0 6px; color: #333; font-size: 1rem; }
.chat-welcome p { margin: 0; line-height: 1.5; }

@media (max-width: 480px) {
  .chat-panel { width: calc(100vw - 32px); left: 16px; bottom: 84px; max-height: 70vh; }
  [dir="rtl"] .chat-panel { left: 16px; right: auto; }
  .chat-btn { left: 16px; }
  [dir="rtl"] .chat-btn { left: 16px; right: auto; }
}
