/* =====================================================================
   SOL · KHUNG CHAT (nạp ở mọi trang, sau nen.css)
   Nâng bảng chat của nen.css thành khung trò chuyện kiểu Messenger:
   bong bóng chữ, thẻ nút, băng thẻ trượt ngang, trả lời nhanh, ảnh, video, tệp, đính kèm.
   Lớp mới mang tiền tố chat- ; lớp cũ .chat__* của nen.css chỉ chỉnh thêm, không đổi tên.
   ===================================================================== */

/* ---------- khung bảng ---------- */
.chat__bang { width: 388px; height: 640px; max-height: calc(100vh - 124px); max-height: calc(100dvh - 124px); }
.chat__dau { padding: 14px 12px 14px 16px; gap: 10px; }
.chat .chat-dau-nut { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: background .15s; }
.chat .chat-dau-nut:hover { background: rgba(255,255,255,.18); }
.chat .chat-dau-nut .ic { width: 19px; height: 19px; }
.chat__than { padding: 14px 14px 16px; gap: 5px; overflow-x: hidden; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: rgba(179,145,84,.4) transparent; }
.chat__than:focus-visible { outline: 2px solid var(--vang); outline-offset: -2px; }
.chat :is(button, a, textarea, video):focus-visible { outline: 2px solid var(--vang-dam); outline-offset: 2px; }

/* ---------- hàng tin và bong bóng ---------- */
.chat-hang { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; min-width: 0; }
.chat-hang--khach { align-items: flex-end; }
.chat-hang--bot + .chat-hang--khach, .chat-hang--khach + .chat-hang--bot { margin-top: 9px; }
.chat .chat__tin { max-width: 84%; padding: 10px 14px; border-radius: 18px; font-size: 14.5px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 1px 2px rgba(36,36,27,.07); }
.chat-hang--bot .chat__tin { border-bottom-left-radius: 6px; }
.chat .chat__tin--khach { border-bottom-right-radius: 6px; box-shadow: none; }
.chat-link { color: var(--vang-dam); text-decoration: underline; text-underline-offset: 2px; }
.chat__tin--khach .chat-link { color: #fff; }
.chat-gio { align-self: center; font-size: 12px; color: var(--chu-3); margin: 8px 0 4px; letter-spacing: .01em; }
.chat-gio:first-child { margin-top: 0; }
.chat-luu-y { align-self: center; max-width: 92%; text-align: center; font-size: 13px; line-height: 1.45; color: #8A4B1F; background: #FBEBD3; border: 1px solid #EBCB9A; border-radius: 12px; padding: 8px 12px; margin: 6px 0; }

/* ---------- thẻ nút (button template) và hàng nút CTA ---------- */
.chat-the-nut { max-width: 88%; background: #fff; border-radius: 18px; border-bottom-left-radius: 6px; overflow: hidden; box-shadow: 0 1px 2px rgba(36,36,27,.07); }
.chat-the-nut__chu { padding: 11px 14px 12px; font-size: 14.5px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-nut-day { display: flex; flex-direction: column; }
.chat-cta { display: flex; align-items: center; justify-content: center; min-height: 42px; padding: 8px 12px; border-top: 1px solid rgba(179,145,84,.24); color: var(--vang-dam); font-size: 14px; font-weight: 600; line-height: 1.25; text-align: center; background: #fff; transition: background .15s, color .15s; cursor: pointer; }
.chat-cta:hover { background: var(--kem-sang); color: var(--muc); }
.chat-cta:active { background: var(--kem-dam); }

/* ---------- dải trượt ngang dùng chung ---------- */
.chat-truot { position: relative; align-self: stretch; margin: 0 -14px; min-width: 0; }
.chat-truot__duong { display: flex; gap: 10px; overflow-x: auto; padding: 2px 14px 6px; scroll-snap-type: x mandatory; scroll-padding: 0 14px; scrollbar-width: none; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
.chat-truot__duong::-webkit-scrollbar { display: none; }
.chat-truot__mui { display: none; position: absolute; top: 50%; z-index: 2; width: 34px; height: 34px; margin-top: -17px; border-radius: 50%; background: #fff; color: var(--vang-dam); border: 1px solid rgba(179,145,84,.45); box-shadow: 0 4px 12px rgba(36,36,27,.18); align-items: center; justify-content: center; }
.chat-truot__mui .ic { width: 18px; height: 18px; }
.chat-truot__mui--lui { left: 6px; }
.chat-truot__mui--toi { right: 6px; }
.chat-truot__mui:hover { background: var(--vang); color: #fff; border-color: var(--vang); }
@media (hover: hover) and (pointer: fine) { .chat-truot__mui { display: flex; } }

/* ---------- băng thẻ (generic template) ---------- */
.chat-the { flex: 0 0 260px; width: 260px; scroll-snap-align: start; display: flex; flex-direction: column; background: #fff; border-radius: 16px; overflow: hidden; border: 1px solid rgba(179,145,84,.26); box-shadow: 0 2px 8px rgba(36,36,27,.07); }
.chat-the__anh { display: block; aspect-ratio: 1.91 / 1; background: var(--kem-dam); overflow: hidden; }
.chat-the__anh img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .4s; }
a.chat-the__anh:hover img { transform: scale(1.04); }
.chat-the__than { padding: 10px 12px 11px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.chat-the__td { font-size: 14.5px; font-weight: 600; line-height: 1.35; color: var(--muc); }
.chat-the__phu { font-size: 13px; line-height: 1.4; color: var(--chu-2); }
.chat-bang-the .chat-truot__mui { top: 64px; margin-top: -17px; }

/* ---------- trả lời nhanh ---------- */
.chat-nhanh { margin-top: 6px; }
.chat-nhanh .chat-truot__duong { gap: 8px; padding-bottom: 2px; scroll-snap-type: none; }
.chat-nhanh__nut { flex: 0 0 auto; min-height: 38px; padding: 7px 15px; border-radius: 20px; border: 1.5px solid var(--vang); background: #fff; color: var(--vang-dam); font-size: 14px; font-weight: 600; white-space: nowrap; transition: background .15s, color .15s; }
.chat-nhanh__nut:hover { background: var(--vang); color: #fff; }
.chat-nhanh .chat-truot__mui { width: 30px; height: 30px; margin-top: -15px; }
.chat-nhanh .chat-truot__mui--toi { box-shadow: -14px 0 10px 4px #FBF7EF, 0 4px 12px rgba(36,36,27,.18); }
.chat-nhanh .chat-truot__mui--lui { box-shadow: 14px 0 10px 4px #FBF7EF, 0 4px 12px rgba(36,36,27,.18); }

/* ---------- ảnh, video, tệp ---------- */
.chat-anh { display: block; max-width: 72%; border-radius: 16px; overflow: hidden; background: var(--kem-dam); line-height: 0; cursor: zoom-in; box-shadow: 0 1px 2px rgba(36,36,27,.07); }
.chat-anh img { display: block; width: 100%; max-height: 260px; min-height: 60px; object-fit: cover; }
.chat-anh--loi { width: 120px; height: 80px; cursor: default; }
.chat-video { display: block; max-width: 72%; max-height: 330px; border-radius: 16px; background: #1A1815; }
.chat-tep { display: inline-flex; align-items: center; gap: 9px; max-width: 84%; padding: 10px 14px; background: #fff; border: 1px solid rgba(179,145,84,.3); border-radius: 14px; color: var(--vang-dam); font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.chat-tep .ic { width: 20px; height: 20px; flex-shrink: 0; }

/* ---------- đang soạn ---------- */
.chat .chat-soan__bong { display: inline-flex; align-items: center; gap: 4px; padding: 13px 14px; }
.chat-soan__bong i { width: 7px; height: 7px; border-radius: 50%; background: var(--vang); opacity: .35; animation: chatSoan 1.1s infinite ease-in-out; }
.chat-soan__bong i:nth-child(2) { animation-delay: .16s; }
.chat-soan__bong i:nth-child(3) { animation-delay: .32s; }
@keyframes chatSoan { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }

/* ---------- chân: khay đính kèm và ô nhập ---------- */
.chat .chat-chan { padding: 10px 10px 12px; gap: 8px; background: #fff; }
.chat-khay { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 0; }
.chat-khay__o { position: relative; flex: 0 0 64px; width: 64px; height: 64px; border-radius: 12px; overflow: hidden; background: var(--kem-dam); border: 1px solid rgba(179,145,84,.35); }
.chat-khay__o img, .chat-khay__o video { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat-khay__o.dang-tai img, .chat-khay__o.dang-tai video { opacity: .55; }
.chat-khay__bo { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; background: rgba(26,24,21,.72); color: #fff; font-size: 15px; line-height: 22px; text-align: center; }
.chat-khay__o.dang-tai .chat-khay__bo { display: none; }
.chat-khay__td { position: absolute; left: 5px; right: 5px; bottom: 5px; height: 5px; border-radius: 3px; background: rgba(255,255,255,.75); overflow: hidden; }
.chat-khay__td i { display: block; height: 100%; width: 0; background: var(--vang-dam); transition: width .15s; }
.chat-go { display: flex; align-items: flex-end; gap: 6px; }
.chat-go__kem { width: 42px; height: 42px; border-radius: 50%; color: var(--vang-dam); display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: background .15s; }
.chat-go__kem:hover { background: var(--kem); }
.chat-go__kem:disabled { opacity: .45; }
.chat-go__kem .ic { width: 21px; height: 21px; }
.chat-go textarea { flex: 1; min-width: 0; height: 42px; min-height: 42px; max-height: 120px; resize: none; border: 1px solid var(--vang-mo); border-radius: 21px; padding: 10px 15px; font: inherit; font-size: 14.5px; line-height: 1.4; color: var(--muc); background: #fff; outline: none; overflow-y: auto; scrollbar-width: none; }
.chat-go textarea:focus { border-color: var(--vang); box-shadow: 0 0 0 3px var(--vang-nen); }
.chat-go textarea::placeholder { color: var(--chu-3); }
.chat-go__gui { width: 42px; height: 42px; border-radius: 50%; background: var(--vang); color: #fff; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: background .15s, opacity .15s, transform .15s; }
.chat-go__gui:hover:not(:disabled) { background: var(--vang-dam); }
.chat-go__gui:active:not(:disabled) { transform: scale(.94); }
.chat-go__gui:disabled { opacity: .45; cursor: default; }
.chat-go__gui .ic { width: 18px; height: 18px; }

/* ---------- điện thoại: bảng chat gần toàn màn hình ---------- */
@media (max-width: 768px) {
  .chat__bang { left: 0; right: 0; top: 0; bottom: auto; width: 100%; max-width: none; height: 100vh; height: 100dvh; max-height: none; border: 0; border-radius: 0; box-shadow: none; }
  .chat__dau { padding-top: max(12px, env(safe-area-inset-top)); }
  .chat .chat-dau-nut { width: 44px; height: 44px; }
  .chat .chat-chan { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .chat .chat__tin, .chat-the-nut__chu { font-size: 16px; }
  .chat-the { flex-basis: min(76vw, 280px); width: min(76vw, 280px); }
  .chat-the__td { font-size: 16px; }
  .chat-the__phu { font-size: 14px; }
  .chat-cta { min-height: 46px; font-size: 15px; }
  .chat-nhanh__nut { min-height: 44px; font-size: 15px; padding: 9px 16px; }
  .chat-gio, .chat-luu-y { font-size: 13px; }
  .chat-go textarea { font-size: 16px; height: 44px; min-height: 44px; border-radius: 22px; }
  .chat-go__kem, .chat-go__gui { width: 44px; height: 44px; }
  .chat-anh, .chat-video { max-width: 78%; }
  /* đang mở chat: nút nổi nằm sau bảng nên ẩn; trang phía sau không cuộn theo */
  body .chat.chat-dang-mo { opacity: 1; pointer-events: auto; }
  .chat.chat-dang-mo .chat__fab { display: none; }
  html.chat-khoa, html.chat-khoa body { overflow: hidden; }
}
@media (prefers-reduced-motion: reduce) { .chat-soan__bong i { animation: none; opacity: .6; } }

/* thẻ tệp như Messenger: ô biểu tượng có đuôi tệp, tên tệp, dòng phụ */
.chat .chat-tep { display: flex; align-items: center; gap: 11px; max-width: 84%; min-width: 0; padding: 10px 14px 10px 10px; background: #fff; border: 1px solid rgba(179,145,84,.3); border-radius: 16px; color: var(--muc); text-decoration: none; box-shadow: 0 1px 2px rgba(36,36,27,.07); }
.chat .chat-tep:hover { border-color: var(--vang); }
.chat-tep__ic { position: relative; flex: 0 0 40px; width: 40px; height: 48px; display: flex; align-items: center; justify-content: center; border-radius: 8px; background: var(--kem); color: var(--vang-dam); }
.chat-tep__ic .ic { width: 26px; height: 26px; }
.chat-tep__ic b { position: absolute; left: 3px; right: 3px; bottom: 5px; padding: 1px 0; border-radius: 3px; background: var(--vang-dam); color: #fff; font-size: 9px; font-weight: 700; letter-spacing: .04em; line-height: 1.25; text-align: center; }
.chat-tep__chu { display: flex; flex-direction: column; min-width: 0; }
.chat-tep__ten { font-size: 14px; font-weight: 600; line-height: 1.35; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.chat-tep__chu small { font-size: 12.5px; color: var(--chu-3); margin-top: 2px; }
.chat-hang--khach .chat-tep { align-self: flex-end; }
.chat-khay__tep { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 4px; color: var(--vang-dam); background: #fff; }
.chat-khay__tep .ic { width: 22px; height: 22px; }
.chat-khay__tep span { max-width: 100%; font-size: 10px; line-height: 1.2; color: var(--chu-2); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
/* tin do lễ tân gửi thay bot */
.chat-nv { font-size: 12px; font-weight: 600; color: var(--vang-dam); margin: 0 0 3px 4px; letter-spacing: .02em; }
/* số tin mới trên nút chat */
.chat__fab { position: relative; }
.chat__dem { position: absolute; top: -2px; right: -2px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: #C0392B; color: #fff; font-size: 12px; font-weight: 700; line-height: 22px; text-align: center; box-shadow: 0 0 0 2px #fff; pointer-events: none; }
.chat-dang-mo .chat__dem { display: none; }
