﻿/* ==========================================================================
   chat.css — ปุ่มแชทลอย + หน้าต่างแชทตอบคำถามอัตโนมัติ
   ========================================================================== */

.chat {
  position: fixed;
  right: 22px; bottom: 22px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

/* ---------- ปุ่มลัด (โทร / LINE) ---------- */
.chat__quick { display: flex; flex-direction: column; gap: 10px; transition: opacity .2s, transform .2s; }
.chat.is-open .chat__quick { opacity: 0; transform: translateY(10px); pointer-events: none; }
.chat__fab {
  display: grid;
  place-items: center;
  width: 50px; height: 50px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  box-shadow: 0 8px 20px rgba(11, 42, 91, .25);
  transition: transform .2s;
}
.chat__fab:hover { transform: scale(1.07); color: #fff; }
.chat__fab svg { width: 24px; height: 24px; }
.chat__fab--tel { background: var(--c-primary); }
.chat__fab--line { background: var(--c-line-app); }

.chat__toggle {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 58px;
  padding: 0 22px 0 18px;
  border: 0;
  border-radius: 999px;
  background: var(--c-navy-2);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  box-shadow: 0 10px 24px rgba(11, 42, 91, .3);
}
.chat__toggle svg { width: 24px; height: 24px; }
.chat__toggle::before {
  content: "";
  position: absolute;
  top: 8px; left: 38px;
  width: 10px; height: 10px;
  border: 2px solid var(--c-navy-2);
  border-radius: 50%;
  background: #39d98a;
}
.chat.is-open .chat__toggle::before { display: none; }
.chat__toggle .is-close { display: none; }
.chat.is-open .chat__toggle .is-open-icon { display: none; }
.chat.is-open .chat__toggle .is-close { display: block; }

/* ---------- หน้าต่างแชท ---------- */
.chat__window {
  display: flex;
  flex-direction: column;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 500px;
  max-height: calc(100vh - 120px);
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: #fff;
  box-shadow: 0 24px 60px rgba(11, 42, 91, .28);
  transform-origin: bottom right;
  animation: chat-pop .25s var(--ease);
}
.chat__window[hidden] { display: none; }

.chat__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(120deg, var(--c-primary), var(--c-navy-2));
  color: #fff;
}
.chat__avatar {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: #fff;
  overflow: hidden;
}
.chat__avatar img { width: 36px; height: auto; }
.chat__head strong { display: block; font-size: 15px; }
.chat__head small { display: flex; align-items: center; gap: 6px; font-size: 12px; opacity: .85; }
.chat__head small::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--dot, #39d98a); }

.chat__body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--c-tint-2);
}
.msg {
  max-width: 85%;
  margin-bottom: 10px;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-line;
  animation: fade-up .25s var(--ease);
}
.msg--bot { background: #fff; border: 1px solid var(--c-line); border-bottom-left-radius: 4px; }
.msg--user { margin-left: auto; background: var(--c-primary); color: #fff; border-bottom-right-radius: 4px; }
.msg a { font-weight: 700; }

.chat__chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.chat__chip {
  padding: 6px 12px;
  border: 1px solid #bcd0ea;
  border-radius: 999px;
  background: #fff;
  color: var(--c-primary);
  font-size: 13px;
  transition: background .2s, color .2s;
}
.chat__chip:hover { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }

.chat__foot {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--c-line);
}
.chat__foot .input { min-height: 40px; font-size: 14px; }
.chat__send {
  flex: none;
  width: 40px; height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--c-primary);
  color: #fff;
}
.chat__send svg { width: 18px; height: 18px; margin: auto; }

@keyframes chat-pop { from { opacity: 0; transform: scale(.92) translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- กำลังพิมพ์... ---------- */
.msg--typing { display: inline-flex; gap: 4px; padding: 12px 14px; }
.msg--typing i {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #9fb3cf;
  animation: typing 1s infinite ease-in-out;
}
.msg--typing i:nth-child(2) { animation-delay: .15s; }
.msg--typing i:nth-child(3) { animation-delay: .3s; }
@keyframes typing { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

.msg__time { display: block; margin-top: 2px; font-size: 11px; opacity: .6; }
.chat__chip--line { border-color: var(--c-line-app); color: #07a547; }
.chat__chip--line:hover { background: var(--c-line-app); border-color: var(--c-line-app); color: #fff; }

.chat__handoff {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--c-line);
  background: #fff;
  font-size: 12.5px;
  color: var(--c-muted);
}
.chat__handoff button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border: 0;
  border-radius: 999px;
  background: var(--c-line-app);
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
}
.chat__handoff svg { width: 14px; height: 14px; }

/* ---------- ปุ่มกลับขึ้นด้านบน ---------- */
.back-top {
  position: fixed;
  left: 22px; bottom: 22px;
  z-index: 110;
  display: grid;
  place-items: center;
  width: 46px; height: 46px;
  border: 1px solid var(--c-line);
  border-radius: 50%;
  background: #fff;
  color: var(--c-primary);
  box-shadow: var(--shadow-sm);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity .25s, transform .25s;
}
.back-top.is-show { opacity: 1; transform: none; pointer-events: auto; }
.back-top svg { width: 18px; height: 18px; }
