/* ===== Chat Widget ===== */
#cw-toggle {
  position: fixed;
  bottom: 22px;
  left: 22px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  font-size: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(99,102,241,.45);
  z-index: 10000;
  transition: transform .2s, box-shadow .2s;
  border: none;
  line-height: 1;
  user-select: none;
}
#cw-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(99,102,241,.55);
}

#cw-panel {
  position: fixed;
  bottom: 84px;
  left: 22px;
  width: 340px;
  max-height: min(480px, calc(100vh - 110px));
  max-height: min(480px, calc(100dvh - 110px));
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(0,0,0,.18);
  z-index: 10001;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  direction: rtl;
}
#cw-panel.cw-open {
  display: flex;
}

/* Header */
#cw-header {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
#cw-header-title {
  font-weight: 600;
  font-size: 15px;
}
#cw-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  opacity: .8;
  transition: opacity .15s;
}
#cw-close:hover { opacity: 1; }

/* Messages area */
#cw-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 100px;
  scroll-behavior: smooth;
}

.cw-msg {
  max-width: 85%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: cwFadeIn .25s ease;
}
@keyframes cwFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.cw-msg-bot {
  align-self: flex-start;
  background: #f3f4f6;
  color: #1f2937;
  border-bottom-right-radius: 4px;
}
.cw-msg-user {
  align-self: flex-end;
  background: #6366f1;
  color: #fff;
  border-bottom-left-radius: 4px;
}

/* Quick action buttons */
.cw-quick-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px 8px;
}
.cw-quick-btn {
  background: #eef2ff;
  color: #4338ca;
  border: 1px solid #c7d2fe;
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 12.5px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
  font-family: inherit;
}
.cw-quick-btn:hover {
  background: #c7d2fe;
  border-color: #a5b4fc;
}
.cw-quick-btn.cw-human-btn {
  background: #fef3c7;
  color: #92400e;
  border-color: #fcd34d;
}
.cw-quick-btn.cw-human-btn:hover {
  background: #fde68a;
  border-color: #f59e0b;
}

/* Input area */
#cw-input-area {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  border-top: 1px solid #e5e7eb;
  flex-shrink: 0;
  min-height: 44px;
  background: #fff;
}
#cw-input {
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  outline: none;
  padding: 11px 14px;
  font-size: 13.5px;
  font-family: inherit;
  direction: rtl;
  background: #f9fafb;
  box-sizing: border-box;
}
#cw-input::placeholder {
  color: #9ca3af;
}
#cw-send {
  flex-shrink: 0;
  background: none;
  color: #6366f1;
  border: none;
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color .15s, transform .15s;
  padding: 0;
}
#cw-send:hover {
  color: #4f46e5;
  transform: scale(1.15);
}
#cw-send svg {
  display: block;
  transform: scaleX(-1);
}

/* Typing indicator */
.cw-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 8px 13px;
  align-self: flex-start;
}
.cw-typing span {
  width: 7px;
  height: 7px;
  background: #9ca3af;
  border-radius: 50%;
  animation: cwBounce .6s infinite alternate;
}
.cw-typing span:nth-child(2) { animation-delay: .2s; }
.cw-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes cwBounce {
  to { transform: translateY(-5px); opacity: .4; }
}

/* Animated message entry */
.cw-msg-enter {
  animation: cwSlideIn .35s ease;
}
@keyframes cwSlideIn {
  from { opacity: 0; transform: translateY(10px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* WhatsApp handoff button */
.cw-quick-btn.cw-wa-btn {
  background: #dcfce7;
  color: #166534;
  border-color: #86efac;
  font-weight: 600;
}
.cw-quick-btn.cw-wa-btn:hover {
  background: #bbf7d0;
  border-color: #4ade80;
}

/* Proactive nudge bubble */
#cw-nudge {
  position: fixed;
  bottom: 80px;
  left: 22px;
  background: #fff;
  color: #1f2937;
  padding: 10px 16px;
  border-radius: 12px 12px 0 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
  font-size: 13.5px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  z-index: 10002;
  cursor: pointer;
  direction: rtl;
  animation: cwNudgeIn .5s ease;
  transition: opacity .3s;
}
#cw-nudge:hover {
  background: #f3f4f6;
}
@keyframes cwNudgeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Pulse animation for toggle button */
.cw-pulse {
  animation: cwPulse 1.5s ease-in-out infinite;
}
@keyframes cwPulse {
  0%, 100% { box-shadow: 0 4px 14px rgba(99,102,241,.45); }
  50% { box-shadow: 0 4px 24px rgba(99,102,241,.8), 0 0 0 8px rgba(99,102,241,.15); }
}

/* Responsive */
@media (max-width: 420px) {
  #cw-panel {
    left: 8px;
    right: 8px;
    width: auto;
    bottom: 78px;
  }
  #cw-nudge {
    left: 8px;
    bottom: 78px;
  }
}
