:root {
  --chat-cream: #f6f3ec;
  --chat-warm-white: #fffdf8;
  --chat-soft-white: #fbfaf6;
  --chat-olive: #515944;
  --chat-olive-2: #68715b;
  --chat-sage: #dde3d1;
  --chat-sage-2: #edf1e7;
  --chat-gold: #8a6617;
  --chat-gold-soft: #cbb987;
  --chat-text: #3f4336;
  --chat-muted: #7c7d70;
  --chat-line: rgba(81, 89, 68, 0.14);
  --chat-shadow: 0 24px 70px rgba(47, 52, 39, 0.16);
  --chat-radius-xl: 32px;
  --chat-radius-lg: 24px;
  --chat-radius-md: 18px;
  --chat-transition: 220ms ease;
}

/* CHAT WIDGET */
.ai-chat-widget {
  position: fixed;
  right: 44px;
  bottom: 34px;
  width: min(470px, calc(100vw - 40px));
  height: min(720px, calc(100vh - 110px));
  display: flex;
  flex-direction: column;
  border: 1px solid var(--chat-line);
  border-radius: var(--chat-radius-xl);
  background: rgba(255, 253, 248, 0.92);
  backdrop-filter: blur(24px);
  box-shadow: var(--chat-shadow);
  overflow: hidden;
  z-index: 2000; /* Higher than header and cart */
  animation: chatEnter 680ms cubic-bezier(.18,.88,.26,1) both;
  transform-origin: 85% 100%;
}

.ai-chat-widget.is-minimized {
  display: none !important;
}

.chat-header {
  min-height: 84px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--chat-line);
  background: rgba(255, 253, 248, 0.76);
}

.chat-avatar {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(145deg, #e9eddf, #cdd5bd);
  color: var(--chat-olive);
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-size: 28px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.7);
  flex: 0 0 auto;
}

.chat-title-wrap {
  flex: 1;
  min-width: 0;
}

.chat-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 750;
  font-size: 16px;
  color: var(--chat-text);
}

.online-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #65a447;
  box-shadow: 0 0 0 0 rgba(101, 164, 71, 0.5);
  animation: pulseDot 1.8s ease infinite;
}

.chat-subtitle {
  margin-top: 3px;
  color: var(--chat-muted);
  font-size: 13px;
}

.chat-controls {
  display: flex;
  gap: 8px;
}

.chat-control {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 0;
  background: transparent;
  color: var(--chat-text);
  font-size: 20px;
  cursor: pointer;
  transition: background var(--chat-transition), transform var(--chat-transition);
  display: grid;
  place-items: center;
}

.chat-control:hover {
  background: rgba(81, 89, 68, 0.08);
  transform: translateY(-1px);
}

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 22px 20px 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(81, 89, 68, 0.24) transparent;
}

.chat-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  animation: messageIn 450ms ease both;
}

.chat-row.user {
  justify-content: flex-end;
}

.mini-avatar {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(81, 89, 68, 0.16);
  color: var(--chat-olive);
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  background: rgba(255,255,255,0.62);
  flex: 0 0 auto;
}

.bubble-wrap {
  max-width: 82%;
}

.bubble {
  padding: 14px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.45;
  box-shadow: 0 8px 24px rgba(63, 67, 54, 0.055);
}

.assistant .bubble {
  background: rgba(255, 255, 255, 0.72);
  border-top-left-radius: 6px;
  color: rgba(63, 67, 54, 0.9);
}

.user .bubble {
  background: var(--chat-sage);
  border-top-right-radius: 6px;
  color: var(--chat-text);
}

.time {
  margin-top: 5px;
  font-size: 11px;
  color: rgba(63, 67, 54, 0.44);
}

.user .time {
  text-align: right;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 18px 0 22px 38px;
  animation: messageIn 500ms ease both 120ms;
}

.quick-chip {
  border: 1px solid rgba(138, 102, 23, 0.28);
  color: #735619;
  background: rgba(255, 253, 248, 0.62);
  border-radius: 999px;
  padding: 10px 15px;
  font-size: 13px;
  cursor: pointer;
  transition: transform var(--chat-transition), background var(--chat-transition), box-shadow var(--chat-transition);
}

.quick-chip:hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 25px rgba(138, 102, 23, 0.1);
}

.product-suggestions {
  display: grid;
  gap: 10px;
  margin: -4px 0 14px 38px;
  animation: cardIn 480ms ease both 170ms;
}

.mini-product-card {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 14px;
  align-items: center;
  border: 1px solid rgba(81, 89, 68, 0.13);
  border-radius: 18px;
  padding: 10px;
  background: rgba(255,255,255,0.62);
  box-shadow: 0 10px 26px rgba(63, 67, 54, 0.05);
  transition: transform var(--chat-transition), box-shadow var(--chat-transition), border-color var(--chat-transition);
}

.mini-product-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 34px rgba(63, 67, 54, 0.09);
  border-color: rgba(138, 102, 23, 0.24);
}

.mini-product-img {
  width: 72px;
  height: 72px;
  border-radius: 14px;
  background:
    radial-gradient(circle at 50% 30%, rgba(255,255,255,0.85), transparent 32%),
    linear-gradient(145deg, #f4d8a4, #c98226);
  position: relative;
  overflow: hidden;
  background-size: cover !important;
  background-position: center !important;
}

.mini-product-img.has-image {
  background: transparent;
}

.mini-product-img.has-image::after {
  display: none !important;
}

.mini-product-card:nth-child(2) .mini-product-img {
  background:
    radial-gradient(circle at 50% 30%, rgba(255,255,255,0.78), transparent 32%),
    linear-gradient(145deg, #f2c679, #9f5a1f);
}

.mini-product-img::after {
  content: "";
  position: absolute;
  width: 30px;
  height: 48px;
  left: 22px;
  bottom: 8px;
  border-radius: 12px 12px 7px 7px;
  background: rgba(255,255,255,0.72);
  box-shadow: inset 0 -18px 0 rgba(138, 102, 23, 0.16);
}

.mini-product-info h4 {
  font-size: 14px;
  font-weight: 720;
  margin-bottom: 4px;
  color: var(--chat-text);
}

.mini-product-info p {
  font-size: 12px;
  color: var(--chat-muted);
  line-height: 1.35;
}

.mini-product-price {
  margin-top: 5px;
  font-size: 14px;
  font-weight: 800;
  color: #3e3d31;
}

.chat-product-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-quantity-control {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(81, 89, 68, 0.06);
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid rgba(81, 89, 68, 0.1);
}

.chat-quantity-btn {
  background: transparent;
  border: none;
  color: var(--chat-olive);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
}

.chat-quantity-btn:hover {
  opacity: 0.7;
}

.chat-quantity-value {
  font-size: 14px;
  font-weight: 700;
  color: var(--chat-text);
  min-width: 14px;
  text-align: center;
}

.chat-add-cart-btn {
  border: 1px solid rgba(138, 102, 23, 0.45);
  background: rgba(138, 102, 23, 0.1);
  color: var(--chat-gold);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--chat-transition);
  white-space: nowrap;
}

.chat-add-cart-btn:hover {
  background: var(--chat-gold);
  color: white;
  transform: translateY(-1px);
}

.typing-row {
  display: none;
  margin: 4px 0 12px;
}

.typing-row.is-visible {
  display: flex;
}

.typing-bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  width: fit-content;
  padding: 13px 15px;
  border-radius: 18px;
  border-top-left-radius: 6px;
  background: rgba(255,255,255,0.72);
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(81, 89, 68, 0.5);
  animation: typing 1s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 120ms; }
.typing-dot:nth-child(3) { animation-delay: 240ms; }

.chat-input-area {
  padding: 14px 20px 10px;
  border-top: 1px solid rgba(81, 89, 68, 0.08);
  background: rgba(255, 253, 248, 0.82);
}

.input-shell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  border: 1px solid rgba(81, 89, 68, 0.14);
  border-radius: 999px;
  padding: 6px 7px 6px 18px;
  background: rgba(255,255,255,0.72);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.8);
  transition: border-color var(--chat-transition), box-shadow var(--chat-transition);
}

.input-shell:focus-within {
  border-color: rgba(138, 102, 23, 0.42);
  box-shadow: 0 0 0 4px rgba(138, 102, 23, 0.08);
}

.chat-input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  font-size: 14px;
  color: var(--chat-text);
}

.chat-input::placeholder {
  color: rgba(63, 67, 54, 0.42);
}

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0;
  display: grid;
  place-items: center;
  background: var(--chat-olive);
  color: white;
  cursor: pointer;
  transition: transform var(--chat-transition), background var(--chat-transition), box-shadow var(--chat-transition);
}

.send-btn:hover {
  transform: translateY(-1px) scale(1.03);
  background: var(--chat-gold);
  box-shadow: 0 12px 26px rgba(138, 102, 23, 0.18);
}

.chat-footer-note {
  padding: 0 20px 16px;
  text-align: center;
  color: var(--chat-muted);
  font-size: 12px;
  background: rgba(255, 253, 248, 0.82);
}

.human-link {
  color: var(--chat-gold);
  text-decoration: none;
  font-weight: 700;
}

.floating-chat-button {
  display: none;
  position: fixed;
  right: 34px;
  bottom: 30px;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  border: 1px solid rgba(81, 89, 68, 0.1);
  background: #fffdf8;
  color: #515944;
  box-shadow: 0 24px 70px rgba(47, 52, 39, 0.16);
  z-index: 1999;
  cursor: pointer;
  animation: chatEnter 450ms ease both;
  place-items: center;
}

.floating-chat-button.is-visible {
  display: grid;
}

/* ANIMATIONS */
@keyframes chatEnter {
  from {
    opacity: 0;
    transform: translateY(34px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

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

@keyframes pulseDot {
  0% { box-shadow: 0 0 0 0 rgba(101, 164, 71, 0.45); }
  70% { box-shadow: 0 0 0 8px rgba(101, 164, 71, 0); }
  100% { box-shadow: 0 0 0 0 rgba(101, 164, 71, 0); }
}

@keyframes typing {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.38;
  }
  40% {
    transform: translateY(-4px);
    opacity: 0.9;
  }
}

/* RESPONSIVE */
@media (max-width: 860px) {
  .ai-chat-widget {
    right: 14px;
    left: 14px;
    bottom: 14px;
    width: auto;
    height: min(76vh, 720px);
    border-radius: 28px;
  }

  .bubble-wrap {
    max-width: 88%;
  }

  .mini-product-card {
    grid-template-columns: 60px 1fr;
  }

  .chat-product-actions {
    grid-column: 1 / -1;
    justify-content: space-between;
    width: 100%;
    margin-top: 8px;
  }
  
  .chat-quantity-control {
    flex: 0 0 auto;
  }
  
  .chat-add-cart-btn {
    flex: 1;
    text-align: center;
  }
}
