/* ── Chat Widget ─────────────────────────────────────────── */

/* Floating button */
.chat-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent, #1a1a2e);
  color: #fff;
  border: none;
  cursor: pointer;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  transition: transform .2s, box-shadow .2s;
}
.chat-btn:hover { transform: scale(1.08); box-shadow: 0 6px 24px rgba(0,0,0,.3); }
.chat-btn.open svg:first-child { display: none; }
.chat-btn:not(.open) .chat-btn-close { display: none; }

/* Greeting bubble */
.chat-bubble {
  position: fixed;
  bottom: 90px;
  right: 24px;
  max-width: 260px;
  background: #fff;
  border-radius: 12px 12px 4px 12px;
  padding: 12px 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,.12);
  z-index: 9998;
  font-size: .88rem;
  line-height: 1.4;
  animation: chatBubbleIn .4s ease;
}
.chat-bubble-text { color: #333; }
.chat-bubble-close {
  position: absolute;
  top: 4px;
  right: 8px;
  background: none;
  border: none;
  font-size: 16px;
  color: #999;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

@keyframes chatBubbleIn {
  from { opacity: 0; transform: translateY(10px) scale(.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Chat window */
.chat-window {
  position: fixed;
  bottom: 90px;
  right: 24px;
  width: 380px;
  height: 520px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,.18);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: chatWindowIn .3s ease;
}

@keyframes chatWindowIn {
  from { opacity: 0; transform: translateY(20px) scale(.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--accent, #1a1a2e);
  color: #fff;
}
.chat-header-info { display: flex; align-items: center; gap: 10px; }
.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .8rem;
  letter-spacing: 1px;
}
.chat-title { font-weight: 600; font-size: .92rem; display: block; }
.chat-subtitle { font-size: .72rem; opacity: .7; display: block; }
.chat-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  opacity: .7;
  transition: opacity .2s;
}
.chat-close:hover { opacity: 1; }

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8f9fa;
}

/* Message bubbles */
.chat-msg { max-width: 85%; animation: chatMsgIn .25s ease; }
.chat-msg-text { word-wrap: break-word; overflow-wrap: break-word; }
.chat-msg-user {
  align-self: flex-end;
  background: var(--accent, #1a1a2e);
  color: #fff;
  border-radius: 16px 16px 4px 16px;
  padding: 10px 14px;
  font-size: .88rem;
  line-height: 1.45;
}
.chat-msg-assistant {
  align-self: flex-start;
  background: #fff;
  color: #333;
  border-radius: 16px 16px 16px 4px;
  padding: 10px 14px;
  font-size: .88rem;
  line-height: 1.45;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

@keyframes chatMsgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Contact collection card ──────────────────────────────── */
.chat-contact-card {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 1px 6px rgba(0,0,0,.08);
  border: 1px solid #e8e8e8;
  animation: chatMsgIn .3s ease;
}
.chat-contact-title {
  font-size: .88rem;
  font-weight: 600;
  color: #333;
  margin-bottom: 12px;
}
.chat-contact-form { display: flex; flex-direction: column; gap: 8px; }
.chat-contact-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: .85rem;
  font-family: inherit;
  outline: none;
  box-sizing: border-box;
  transition: border-color .2s;
}
.chat-contact-input:focus { border-color: var(--accent, #1a1a2e); }
.chat-contact-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.chat-contact-skip {
  flex: 1;
  padding: 8px;
  background: #f5f5f5;
  border: 1px solid #ddd;
  border-radius: 8px;
  cursor: pointer;
  font-size: .82rem;
  color: #666;
  transition: background .2s;
}
.chat-contact-skip:hover { background: #eee; }
.chat-contact-submit {
  flex: 1;
  padding: 8px;
  background: var(--accent, #1a1a2e);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: .82rem;
  font-weight: 600;
  transition: opacity .2s;
}
.chat-contact-submit:hover { opacity: .9; }

/* Typing indicator */
.chat-typing {
  align-self: flex-start;
  background: #fff;
  border-radius: 16px 16px 16px 4px;
  padding: 12px 18px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.chat-typing-dots {
  display: flex;
  gap: 4px;
}
.chat-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #999;
  animation: chatDot 1.2s infinite;
}
.chat-typing-dots span:nth-child(2) { animation-delay: .2s; }
.chat-typing-dots span:nth-child(3) { animation-delay: .4s; }

@keyframes chatDot {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Product cards */
.chat-products { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.chat-product-card {
  display: flex;
  gap: 10px;
  background: #fff;
  border: 1px solid #eee;
  border-radius: 10px;
  padding: 8px;
  text-decoration: none;
  color: inherit;
  transition: border-color .2s, box-shadow .2s;
}
.chat-product-card:hover { border-color: var(--accent, #1a1a2e); box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.chat-product-img {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  object-fit: cover;
  background: #f0f0f0;
  flex-shrink: 0;
}
.chat-product-info { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.chat-product-name { font-size: .82rem; font-weight: 600; color: #333; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-product-price { font-size: .78rem; color: var(--accent, #1a1a2e); font-weight: 600; }

/* ── Quick replies ─────────────────────────────────────────── */
.chat-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.chat-quick-reply {
  background: #fff;
  border: 1.5px solid var(--accent, #1a1a2e);
  border-radius: 20px;
  padding: 7px 16px;
  font-size: .8rem;
  cursor: pointer;
  color: var(--accent, #1a1a2e);
  font-weight: 500;
  transition: all .2s;
  white-space: nowrap;
}
.chat-quick-reply:hover {
  background: var(--accent, #1a1a2e);
  color: #fff;
}

/* ── Rating ────────────────────────────────────────────────── */
.chat-rating { display: flex; gap: 6px; margin-top: 6px; }
.chat-rating-btn {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  color: #999;
  transition: all .2s;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  position: relative;
}
.chat-rating-btn:hover { border-color: #999; color: #555; background: #f8f8f8; }

/* SVG-based thumbs icons via CSS */
.chat-rating-up::before,
.chat-rating-down::before {
  content: '';
  display: block;
  width: 14px;
  height: 14px;
  background: currentColor;
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
}
.chat-rating-up::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M1 21h4V9H1v12zm22-11c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M1 21h4V9H1v12zm22-11c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2z'/%3E%3C/svg%3E");
}
.chat-rating-down::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L9.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm4 0v12h4V3h-4z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L9.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm4 0v12h4V3h-4z'/%3E%3C/svg%3E");
}

.chat-rating-thanks { font-size: .72rem; color: #999; display: flex; align-items: center; }

/* Input area */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  padding: 10px 12px;
  border-top: 1px solid #eee;
  gap: 8px;
  background: #fff;
}
.chat-input {
  flex: 1;
  border: 1px solid #e0e0e0;
  border-radius: 20px;
  padding: 8px 16px;
  font-size: .88rem;
  resize: none;
  outline: none;
  max-height: 80px;
  line-height: 1.4;
  font-family: inherit;
  transition: border-color .2s;
}
.chat-input:focus { border-color: var(--accent, #1a1a2e); }
.chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent, #1a1a2e);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity .2s;
}
.chat-send:disabled { opacity: .4; cursor: default; }

/* Footer */
.chat-footer {
  padding: 6px 12px 10px;
  text-align: center;
  background: #fff;
}
.chat-escalate-btn {
  background: none;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 6px 16px;
  font-size: .78rem;
  color: #666;
  cursor: pointer;
  transition: all .2s;
  width: 100%;
}
.chat-escalate-btn:hover { border-color: #999; color: #333; }

/* Modal */
.chat-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: chatFadeIn .2s ease;
}
.chat-modal-content {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  max-width: 380px;
  width: calc(100% - 40px);
  box-shadow: 0 16px 48px rgba(0,0,0,.2);
}
.chat-modal-content h3 { margin: 0 0 4px; font-size: 1.1rem; color: #333; }
.chat-modal-content p { margin: 0 0 16px; font-size: .85rem; color: #666; }
.chat-modal-content input,
.chat-modal-content textarea {
  display: block;
  width: 100%;
  padding: 10px 14px;
  margin-bottom: 10px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: .88rem;
  font-family: inherit;
  outline: none;
  box-sizing: border-box;
}
.chat-modal-content input:focus,
.chat-modal-content textarea:focus { border-color: var(--accent, #1a1a2e); }
.chat-modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.chat-modal-cancel {
  flex: 1;
  padding: 10px;
  background: #f5f5f5;
  border: 1px solid #ddd;
  border-radius: 8px;
  cursor: pointer;
  font-size: .88rem;
}
.chat-modal-submit {
  flex: 1;
  padding: 10px;
  background: var(--accent, #1a1a2e);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: .88rem;
  font-weight: 600;
}

@keyframes chatFadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── Mobile ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .chat-window {
    bottom: 0;
    right: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    animation: chatSlideUp .3s ease;
  }
  .chat-btn { bottom: 16px; right: 16px; }
  .chat-bubble { bottom: 80px; right: 16px; }

  @keyframes chatSlideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
}
