/* ── CHAT WIDGET ── */
#chatWidget {
  position: fixed;
  right: clamp(16px,3vw,28px);
  bottom: clamp(16px,3vw,28px);
  z-index: 500;
  font-family: 'Kanit', sans-serif;
}

#chatToggle {
  width: 58px; height: 58px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(123deg, var(--purple-1) 7%, var(--purple-2) 37%, var(--purple-3) 72%, var(--orange) 100%);
  box-shadow: 0 8px 24px rgba(182,0,168,0.35);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s;
}
#chatToggle:hover { transform: scale(1.06); }
#chatToggle svg { width: 26px; height: 26px; stroke: #fff; fill: none; stroke-width: 1.8; }
#chatToggle .icon-close { display: none; }
#chatWidget.open #chatToggle .icon-chat { display: none; }
#chatWidget.open #chatToggle .icon-close { display: block; }

.chat-panel {
  position: absolute;
  bottom: 74px;
  right: 0;
  width: min(340px, calc(100vw - 32px));
  height: min(480px, calc(100vh - 140px));
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  visibility: hidden;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0.2s;
}
#chatWidget.open .chat-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  visibility: visible;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0s;
}

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(123deg, var(--purple-1) 7%, var(--purple-2) 60%, var(--purple-3) 100%);
  flex-shrink: 0;
}
.chat-header-info { display: flex; align-items: center; gap: 10px; }
.chat-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255,255,255,0.18);
  color: #fff; font-weight: 700; font-size: 0.75rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.chat-header-info strong { display: block; color: #fff; font-size: 0.85rem; font-weight: 600; }
.chat-header-info span { display: block; color: rgba(255,255,255,0.75); font-size: 0.68rem; }
.chat-header-close {
  width: 28px; height: 28px; border-radius: 50%;
  border: none; background: rgba(255,255,255,0.12); color: #fff;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.chat-header-close svg { width: 14px; height: 14px; stroke: #fff; fill: none; stroke-width: 2; }

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-body::-webkit-scrollbar { width: 6px; }
.chat-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.chat-msg {
  max-width: 84%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 0.82rem;
  line-height: 1.55;
  animation: chatIn 0.25s ease;
  white-space: pre-line; /* preserves \n line breaks in multi-line bot replies */
}
@keyframes chatIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.chat-msg.bot {
  align-self: flex-start;
  background: rgba(215,226,234,0.08);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.chat-msg.user {
  align-self: flex-end;
  background: var(--purple-2);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-result-card {
  align-self: flex-start;
  max-width: 84%;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(215,226,234,0.04);
}
.chat-result-card img { width: 100%; display: block; height: 110px; object-fit: cover; }
.chat-result-card a {
  display: block;
  padding: 9px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--purple-2);
  text-decoration: none;
}
.chat-result-card a:hover { text-decoration: underline; }

.chat-quick-replies {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 12px 16px 16px;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
}
.chat-qr-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.75rem;
  padding: 8px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.chat-qr-btn:hover { border-color: var(--purple-2); color: var(--purple-2); background: rgba(182,0,168,0.06); }

.chat-form {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-form input,
.chat-form textarea {
  width: 100%;
  background: rgba(215,226,234,0.06);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.8rem;
  padding: 9px 11px;
  resize: none;
}
.chat-form input:focus,
.chat-form textarea:focus { outline: none; border-color: var(--purple-2); }
.chat-form button {
  align-self: flex-end;
  border: none;
  background: linear-gradient(123deg, var(--purple-1) 7%, var(--purple-2) 37%, var(--purple-3) 72%, var(--orange) 100%);
  color: #fff;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 18px;
  border-radius: 999px;
  cursor: pointer;
  flex-shrink: 0;
}

/* Free-text "type your question" row (#chatTextRow), rendered above quick replies */
#chatTextRow { padding-bottom: 10px; }
#chatTextRow > div { align-items: center; }
#chatTextRow input { flex: 1; margin: 0; }
#chatTextRow button { align-self: center; padding: 9px 16px; }

@media (max-width: 480px) {
  .chat-panel { width: calc(100vw - 24px); height: calc(100vh - 120px); right: -6px; }
}