/* ==========================================================================
   Trợ lý AI — bong bóng nổi + khung chat, thẻ sản phẩm ngay trong câu trả lời
   ========================================================================== */
.chat-fab {
  position: fixed;
  right: clamp(14px, 2.4vw, 26px);
  bottom: clamp(14px, 2.4vw, 26px);
  z-index: 890;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 13px 18px 13px 14px;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 999px;
  background: linear-gradient(135deg, #2f6a49 0%, #1d4630 100%);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 18px 40px -18px rgba(20, 45, 30, .8), 0 2px 0 rgba(255, 255, 255, .12) inset;
  transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease;
}
.chat-fab:hover { transform: translateY(-2px); box-shadow: 0 22px 48px -18px rgba(20, 45, 30, .85); }
.chat-fab i {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .16);
}
.chat-fab svg { width: 16px; height: 16px; }
.chat-fab .chat-fab-dot {
  position: absolute;
  top: 7px; left: 26px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #7ce0a4;
  box-shadow: 0 0 0 3px rgba(124, 224, 164, .25);
}
body.chat-open .chat-fab { opacity: 0; pointer-events: none; transform: scale(.9); }

.chat-panel {
  position: fixed;
  right: clamp(12px, 2.2vw, 26px);
  bottom: clamp(12px, 2.2vw, 26px);
  z-index: 892;
  width: min(404px, calc(100vw - 24px));
  height: min(620px, calc(100dvh - 120px));
  display: flex;
  flex-direction: column;
  border-radius: 22px;
  overflow: hidden;
  background: #fffdf9;
  border: 1px solid #e6ddcf;
  box-shadow: 0 34px 80px -30px rgba(24, 34, 26, .55), 0 2px 0 rgba(255, 255, 255, .8) inset;
  font-family: inherit;
  animation: chat-in .22s cubic-bezier(.2, .8, .3, 1);
}
.chat-panel.hidden { display: none; }
@keyframes chat-in { from { opacity: 0; transform: translateY(14px) scale(.98); } }

.chat-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 14px;
  background: linear-gradient(135deg, #2f6a49, #1d4630);
  color: #fff;
}
.chat-ava {
  position: relative;
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .14);
  flex: 0 0 auto;
}
.chat-ava svg { width: 20px; height: 20px; }
.chat-ava b {
  position: absolute; right: 1px; bottom: 1px;
  width: 10px; height: 10px; border-radius: 50%;
  background: #7ce0a4; border: 2px solid #245037;
}
.chat-title { display: flex; flex-direction: column; gap: 2px; line-height: 1.2; flex: 1; }
.chat-title strong { font-size: 14.5px; font-weight: 650; letter-spacing: .01em; }
.chat-title small { font-size: 11.5px; color: #b7d0c0; }
.chat-x {
  width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .2);
  background: rgba(255, 255, 255, .08);
  color: #fff; cursor: pointer; font-size: 15px; line-height: 1;
}
.chat-x:hover { background: rgba(255, 255, 255, .18); }

.chat-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background:
    radial-gradient(120% 80% at 100% 0%, #f3f8f2 0%, transparent 55%),
    radial-gradient(100% 70% at 0% 100%, #fbf5ea 0%, transparent 60%),
    #fffdf9;
  scrollbar-width: thin;
}

.chat-msg { display: flex; flex-direction: column; gap: 8px; max-width: 100%; }
.chat-msg.user { align-items: flex-end; }
.chat-bubble {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: 16px;
  font-size: 13.6px;
  line-height: 1.55;
  color: #1f2b23;
  background: #fff;
  border: 1px solid #e8e0d2;
  box-shadow: 0 8px 20px -18px rgba(30, 40, 30, .5);
  overflow-wrap: anywhere;
}
.chat-msg.bot .chat-bubble { border-bottom-left-radius: 6px; }
.chat-msg.user .chat-bubble {
  background: #2f6a49;
  border-color: #2f6a49;
  color: #fff;
  border-bottom-right-radius: 6px;
}
.chat-bubble p { margin: 0 0 7px; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble strong { font-weight: 650; color: #1b3a28; }
.chat-msg.user .chat-bubble strong { color: #fff; }
.chat-bubble .chat-line { display: block; }
.chat-bubble .chat-line.bullet { padding-left: 14px; position: relative; }
.chat-bubble .chat-line.bullet::before {
  content: "";
  position: absolute; left: 2px; top: .68em;
  width: 5px; height: 5px; border-radius: 50%; background: #7aa78c;
}

.chat-cards {
  display: flex;
  gap: 9px;
  overflow-x: auto;
  padding: 2px 2px 6px;
  scroll-snap-type: x mandatory;
  scrollbar-width: thin;
}
.chat-card {
  flex: 0 0 148px;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px;
  border-radius: 14px;
  border: 1px solid #e6ddcf;
  background: #fff;
  cursor: pointer;
  text-align: left;
  font: inherit;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.chat-card:hover { transform: translateY(-2px); border-color: #bcd4c4; box-shadow: 0 14px 24px -20px rgba(20, 50, 30, .7); }
.chat-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #f7f4ee;
  border-radius: 9px;
}
.chat-card b {
  font-size: 11.8px;
  font-weight: 600;
  line-height: 1.35;
  color: #22302a;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.7em;
}
.chat-card span { font-size: 12px; font-weight: 700; color: #a8341b; }
.chat-card small { font-size: 10.5px; color: #7b8a80; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-typing { display: inline-flex; gap: 4px; align-items: center; padding: 2px 2px 0; }
.chat-typing i {
  width: 6px; height: 6px; border-radius: 50%; background: #8fa99a;
  animation: chat-blink 1.1s infinite ease-in-out;
}
.chat-typing i:nth-child(2) { animation-delay: .15s; }
.chat-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes chat-blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

.chat-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 14px 10px; background: #fffdf9; }
.chat-chip {
  border: 1px solid #d6e4da;
  background: #f2f8f3;
  color: #2b5a3d;
  border-radius: 999px;
  padding: 6px 11px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.chat-chip:hover { background: #e6f2ea; border-color: #a9c8b6; }

.chat-foot { border-top: 1px solid #eee5d8; background: #fffdf9; padding: 9px 10px 11px; }
.chat-form { display: flex; align-items: flex-end; gap: 8px; }
.chat-form textarea {
  flex: 1;
  resize: none;
  min-height: 42px;
  max-height: 108px;
  padding: 11px 13px;
  border-radius: 14px;
  border: 1px solid #ddd2c1;
  background: #fff;
  font: inherit;
  font-size: 13.5px;
  line-height: 1.4;
  color: #1f2b23;
}
.chat-form textarea:focus { outline: 2px solid rgba(47, 106, 73, .25); border-color: #8fb8a0; }
.chat-send {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  border-radius: 13px;
  border: 0;
  background: linear-gradient(135deg, #2f6a49, #1d4630);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.chat-send:disabled { opacity: .55; cursor: default; }
.chat-send svg { width: 18px; height: 18px; }
.chat-note { margin: 7px 2px 0; font-size: 10.5px; color: #93a094; text-align: center; }
.chat-note b { color: #2f6a49; font-weight: 600; }

@media (max-width: 560px) {
  .chat-panel {
    right: 0; left: 0; bottom: 0;
    width: 100vw;
    height: 88dvh;
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
  }
  .chat-fab span { display: none; }
  .chat-fab { padding: 14px; }
}
