/* SnapTik – khung chat hỗ trợ trực tuyến (nút nổi góc phải) */
.chat { position: fixed; right: 20px; bottom: 20px; z-index: 90; font-size: .9375rem; }
.chat[hidden] { display: none; }

/* Nút mở */
.chat__launcher {
  position: relative; display: inline-flex; align-items: center; gap: 10px;
  padding: 12px 18px 12px 14px; border: 0; border-radius: var(--r-pill); cursor: pointer;
  color: #fff; font: 600 .9375rem/1 var(--font); letter-spacing: .02em;
  background: var(--grad-cta); box-shadow: 0 12px 30px rgb(255 79 216 / .35), inset 0 1px 0 rgb(255 255 255 / .3);
  transition: transform var(--dur-fast), box-shadow var(--dur-fast);
}
.chat__launcher:hover { transform: translateY(-2px); box-shadow: 0 16px 36px rgb(255 79 216 / .45); }
.chat__launcher:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
.chat__launcher-ic { display: grid; place-items: center; }
.chat__dot { position: absolute; left: 32px; top: 9px; width: 10px; height: 10px; border-radius: 50%; background: #8a84aa; border: 2px solid #c03ad8; }
.chat.is-online .chat__dot { background: #22c55e; }
.chat__badge { position: absolute; top: -6px; right: -6px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: #fff; color: #c026d3; font-size: .75rem; line-height: 22px; text-align: center; box-shadow: 0 4px 10px rgb(0 0 0 / .3); }
.chat.is-open .chat__launcher { display: none; }

/* Gợi ý chat khi tải lỗi */
.chat__nudge {
  position: absolute; right: 0; bottom: calc(100% + 12px); width: min(300px, calc(100vw - 40px));
  padding: 14px 14px 12px; border-radius: var(--r-lg);
  background: #1a1033; border: 1px solid rgb(255 79 216 / .45); box-shadow: var(--shadow-card);
  animation: chat-in .35s var(--ease-out);
}
.chat__nudge p { margin: 0 0 10px; color: var(--text-primary); line-height: 1.5; }
.chat__nudge-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chat__nudge-x { border: 0; background: none; color: var(--text-tertiary); cursor: pointer; padding: 6px; }
.chat.is-open .chat__nudge { display: none; }

/* Khung chat */
.chat__panel {
  display: flex; flex-direction: column; width: 370px; height: min(580px, calc(100vh - 40px));
  border-radius: var(--r-xl); overflow: hidden;
  background: #120a26; border: 1px solid var(--glass-border); box-shadow: 0 30px 70px rgb(0 0 0 / .55), 0 0 0 1px rgb(168 85 247 / .15);
  animation: chat-in .3s var(--ease-out);
}
.chat__panel[hidden] { display: none; }
@keyframes chat-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }
@media (prefers-reduced-motion: reduce) { .chat__panel, .chat__nudge { animation: none; } }

.chat__head { display: flex; align-items: center; gap: 12px; padding: 14px 14px 14px 16px; background: linear-gradient(135deg, rgb(255 79 216 / .22), rgb(168 85 247 / .18)); border-bottom: 1px solid var(--glass-border-soft); }
.chat__avatar { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--grad-cta); color: #fff; }
.chat__head-text { flex: 1; min-width: 0; }
.chat__title { margin: 0; font-size: 1.0625rem; letter-spacing: .01em; }
.chat__status { display: flex; align-items: center; gap: 6px; margin: 2px 0 0; color: var(--text-secondary); font-size: .8125rem; }
.chat__status i { width: 8px; height: 8px; border-radius: 50%; background: #8a84aa; flex: none; }
.chat.is-online .chat__status i { background: #22c55e; box-shadow: 0 0 0 3px rgb(34 197 94 / .2); }
.chat__close { border: 0; background: rgb(255 255 255 / .06); color: var(--text-primary); width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; }
.chat__close:hover { background: rgb(255 255 255 / .12); }

.chat__body { flex: 1; overflow-y: auto; padding: 16px; overscroll-behavior: contain; }
.chat__msgs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.chat__msg { display: flex; flex-direction: column; max-width: 84%; }
.chat__msg--admin { align-self: flex-start; }
.chat__msg--visitor { align-self: flex-end; align-items: flex-end; }
.chat__bubble { padding: 10px 13px; border-radius: 16px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans Thai', sans-serif; font-size: .9rem; }
.chat__msg--admin .chat__bubble { background: rgb(255 255 255 / .07); color: var(--text-primary); border-bottom-left-radius: 5px; }
.chat__msg--visitor .chat__bubble { background: var(--grad-cta); color: #fff; border-bottom-right-radius: 5px; }
.chat__msg.is-failed .chat__bubble { opacity: .55; }
.chat__time { margin-top: 3px; font-size: .6875rem; color: var(--text-tertiary); }
.chat__msg.is-failed .chat__time { color: #f87171; }
.chat__typing { display: inline-flex; gap: 4px; padding: 12px 14px; }

.chat__topics { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chat__topics[hidden] { display: none; }
.chat__topic {
  border: 1px solid rgb(255 79 216 / .45); background: rgb(255 79 216 / .08); color: var(--text-primary);
  padding: 8px 12px; border-radius: var(--r-pill); font: 500 .8125rem/1.2 var(--font); cursor: pointer; letter-spacing: .02em;
}
.chat__topic:hover { background: rgb(255 79 216 / .2); }

.chat__email { margin-top: 12px; padding: 12px; border-radius: var(--r-md); background: rgb(255 255 255 / .04); border: 1px dashed var(--glass-border); }
.chat__email[hidden] { display: none; }
.chat__email label { display: block; margin-bottom: 8px; color: var(--text-secondary); font-size: .8125rem; line-height: 1.45; }
.chat__email-row { display: flex; gap: 8px; }
.chat__email input { flex: 1; min-width: 0; padding: 9px 12px; border-radius: var(--r-sm); border: 1px solid var(--glass-border); background: rgb(0 0 0 / .25); color: var(--text-primary); font: inherit; font-size: .875rem; }
.chat__email-note { margin: 6px 0 0; font-size: .75rem; color: var(--text-secondary); }
.chat__email-note:empty { display: none; }
.chat__email-note.is-bad { color: #f87171; }

.chat__attach { display: flex; align-items: center; gap: 8px; margin: 0 12px; padding: 7px 10px; border-radius: var(--r-sm); background: rgb(248 113 113 / .1); color: #fca5a5; font-size: .75rem; }
.chat__attach[hidden] { display: none; }
.chat__attach span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat__attach b { font-weight: 500; color: var(--text-primary); }
.chat__attach button { border: 0; background: none; color: inherit; cursor: pointer; padding: 2px; }

.chat__composer { display: flex; align-items: flex-end; gap: 8px; margin: 10px 12px 0; padding: 6px 6px 6px 14px; border-radius: 22px; background: rgb(255 255 255 / .06); border: 1px solid var(--glass-border-soft); }
.chat__composer:focus-within { border-color: rgb(255 79 216 / .6); }
.chat__composer textarea { flex: 1; min-height: 22px; max-height: 120px; padding: 7px 0; resize: none; border: 0; outline: 0; background: none; color: var(--text-primary); font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans Thai', sans-serif; font-size: .9375rem; line-height: 1.45; }
.chat__composer textarea::placeholder { color: var(--text-tertiary); }
.chat__send { display: grid; place-items: center; flex: none; width: 38px; height: 38px; border: 0; border-radius: 50%; background: var(--grad-cta); color: #fff; cursor: pointer; }
.chat__send:disabled { opacity: .5; cursor: default; }
.chat__hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.chat__foot { margin: 6px 12px 10px; text-align: center; color: var(--text-tertiary); font-size: .6875rem; }

/* Điện thoại: khung chat toàn màn hình, nút gọn chỉ còn biểu tượng */
@media (max-width: 640px) {
  .chat { right: 14px; bottom: 14px; }
  .chat__launcher { padding: 14px; }
  .chat__launcher-label { display: none; }
  .chat__dot { left: auto; right: 8px; top: 8px; }
  .chat.is-open { inset: 0; right: 0; bottom: 0; }
  .chat__panel { width: 100%; height: 100%; height: 100dvh; border-radius: 0; border: 0; }
  body.chat-lock { overflow: hidden; }
}

/* Tin trả lời tự động + "đang soạn tin" */
.chat__msg--bot .chat__bubble { background: rgb(168 85 247 / .12); border: 1px solid rgb(168 85 247 / .3); }
.chat__typing { display: inline-flex; align-items: center; gap: 4px; padding: 13px 14px; }
.chat__typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-secondary); animation: chat-dot 1.2s infinite ease-in-out; }
.chat__typing i:nth-child(2) { animation-delay: .15s; }
.chat__typing i:nth-child(3) { animation-delay: .3s; }
@keyframes chat-dot { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* Bong bóng xem trước câu trả lời khi khách quay lại site */
.chat__reply { border-color: rgb(34 197 94 / .45); }
.chat__reply-head { display: flex; align-items: center; gap: 8px; margin: 0 0 6px !important; font-weight: 600; font-size: .875rem; color: var(--text-primary); }
.chat__reply-av { display: grid; place-items: center; flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--grad-cta); color: #fff; }
.chat__reply-text { margin: 0 0 12px !important; padding: 10px 12px; border-radius: 12px; border-bottom-left-radius: 4px; background: rgb(255 255 255 / .07); color: var(--text-secondary) !important; font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans Thai', sans-serif; font-size: .875rem; line-height: 1.5; overflow-wrap: anywhere; }
