/* Chat Widget - Floating chat button + expandable panel */

.chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: inherit;
}

[dir="rtl"] .chat-widget {
  right: auto;
  left: 24px;
}

/* Toggle Button */
.chat-toggle-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.4);
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-toggle-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(37, 99, 235, 0.5);
}

.chat-toggle-btn.active {
  display: none;
}

/* Chat Panel */
.chat-panel {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 400px;
  height: 520px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: chatSlideUp 0.25s ease-out;
}

[dir="rtl"] .chat-panel {
  right: auto;
  left: 0;
}

@keyframes chatSlideUp {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.chat-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-header-title i {
  font-size: 1rem;
}

.chat-close-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.85);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
  line-height: 1;
}

.chat-close-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

/* Messages Area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8fafc;
}

.chat-messages::-webkit-scrollbar {
  width: 5px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

/* Message Bubbles */
.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.chat-msg-user {
  align-self: flex-end;
  background: #2563eb;
  color: #fff;
  border-bottom-right-radius: 4px;
}

[dir="rtl"] .chat-msg-user {
  border-bottom-right-radius: 14px;
  border-bottom-left-radius: 4px;
}

.chat-msg-assistant {
  align-self: flex-start;
  background: #fff;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}

[dir="rtl"] .chat-msg-assistant {
  border-bottom-left-radius: 14px;
  border-bottom-right-radius: 4px;
}

/* Tool call indicators */
.chat-msg-tool {
  align-self: flex-start;
  max-width: 90%;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.78rem;
  color: #64748b;
  background: #f1f5f9;
  border: 1px dashed #cbd5e1;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-msg-tool i {
  font-size: 0.7rem;
}

/* Typing indicator */
.chat-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 16px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}

.chat-typing-dot {
  width: 7px;
  height: 7px;
  background: #94a3b8;
  border-radius: 50%;
  animation: chatTyping 1.2s infinite ease-in-out;
}

.chat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes chatTyping {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Input Area */
.chat-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid #e2e8f0;
  background: #fff;
  flex-shrink: 0;
}

.chat-input-area input {
  flex: 1;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s;
  background: #f8fafc;
}

.chat-input-area input:focus {
  border-color: #2563eb;
  background: #fff;
}

.chat-input-area input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#chatSend {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  background: #2563eb;
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}

#chatSend:hover {
  background: #1d4ed8;
}

#chatSend:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}

/* Welcome message */
.chat-welcome {
  text-align: center;
  padding: 32px 20px;
  color: #64748b;
}

.chat-welcome i {
  font-size: 2.2rem;
  color: #2563eb;
  margin-bottom: 12px;
  display: block;
}

.chat-welcome h6 {
  color: #1e293b;
  font-weight: 600;
  margin-bottom: 6px;
}

.chat-welcome p {
  font-size: 0.82rem;
  margin: 0;
}

/* Responsive */
@media (max-width: 480px) {
  .chat-panel {
    width: calc(100vw - 32px);
    height: calc(100vh - 100px);
    bottom: 0;
    right: -8px;
    border-radius: 16px 16px 0 0;
  }
}
