/* Chat widget styles */
:root {
  --chat-primary: #2563eb;
  --chat-primary-dark: #1d4ed8;
  --chat-bg: #ffffff;
  --chat-header: #2563eb;
  --chat-text: #1f2937;
  --chat-muted: #6b7280;
  --chat-user-bubble: #2563eb;
  --chat-bot-bubble: #f3f4f6;
  --chat-radius: 16px;
}

.chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Toggle button */
.chat-widget__toggle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--chat-primary);
  color: #fff;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, background 0.2s;
}

.chat-widget__toggle:hover {
  background: var(--chat-primary-dark);
  transform: scale(1.05);
}

.chat-widget__toggle svg {
  width: 28px;
  height: 28px;
}

.chat-widget__toggle .chat-widget__close-icon {
  display: none;
}

/* Open state */
.chat-widget--open .chat-widget__toggle .chat-widget__open-icon {
  display: none;
}

.chat-widget--open .chat-widget__toggle .chat-widget__close-icon {
  display: block;
}

/* Panel */
.chat-widget__panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 370px;
  max-width: calc(100vw - 48px);
  height: 540px;
  max-height: calc(100vh - 120px);
  background: var(--chat-bg);
  border-radius: var(--chat-radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  display: none;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: chat-pop 0.2s ease-out;
}

.chat-widget--open .chat-widget__panel {
  display: flex;
}

@keyframes chat-pop {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Header */
.chat-widget__header {
  background: var(--chat-header);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-widget__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.chat-widget__title {
  font-weight: 600;
  font-size: 15px;
}

.chat-widget__status {
  font-size: 12px;
  opacity: 0.9;
}

/* Messages area */
.chat-widget__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--chat-bg);
}

.chat-widget__message {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: chat-fade 0.2s ease-out;
}

@keyframes chat-fade {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-widget__message--user {
  align-self: flex-end;
  background: var(--chat-user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-widget__message--bot {
  align-self: flex-start;
  background: var(--chat-bot-bubble);
  color: var(--chat-text);
  border-bottom-left-radius: 4px;
}

.chat-widget__message--error {
  align-self: flex-start;
  background: #fee2e2;
  color: #b91c1c;
}

/* Typing indicator */
.chat-widget__typing {
  align-self: flex-start;
  display: none;
  padding: 12px 14px;
  background: var(--chat-bot-bubble);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}

.chat-widget__typing--visible {
  display: flex;
  gap: 4px;
}

.chat-widget__typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--chat-muted);
  animation: chat-bounce 1.2s infinite;
}

.chat-widget__typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.chat-widget__typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes chat-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-6px);
  }
}

/* Input area */
.chat-widget__inputzone {
  border-top: 1px solid #e5e7eb;
  padding: 12px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-widget__input {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  resize: none;
  max-height: 120px;
  box-sizing: border-box;
}

.chat-widget__input:focus {
  border-color: var(--chat-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.chat-widget__send {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 12px;
  background: var(--chat-primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.chat-widget__send:hover {
  background: var(--chat-primary-dark);
}

.chat-widget__send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-widget__send svg {
  width: 20px;
  height: 20px;
}

/* Scrollbar */
.chat-widget__messages::-webkit-scrollbar {
  width: 6px;
}

.chat-widget__messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}