/* ============================================================
   CHAT — macOS-style community chat window
   ============================================================ */

.chat-window {
  margin-top: 18px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 40px 90px -30px rgba(var(--shadow-rgb), .8), 0 0 0 1px rgba(var(--hl-rgb), .03) inset;
  background: var(--bg2);
}

/* ---- Title bar ---- */
.chat-titlebar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: linear-gradient(180deg, #2A2350, #211B43);
  border-bottom: 1px solid var(--line-soft);
}

.chat-lights { display: flex; gap: 8px; }
.chat-lights__dot {
  width: 13px; height: 13px;
  border-radius: 50%;
  display: block;
}
.chat-lights__dot--red    { background: #FF5F57; }
.chat-lights__dot--yellow { background: #FEBC2E; }
.chat-lights__dot--green  { background: #28C840; }

.chat-titlebar__title {
  flex: 1;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

/* ---- Chat body (1 cột: chỉ còn .chat-main sau khi gộp vào Bảng tin) ---- */
.chat-body {
  display: flex;
  height: 540px;
}
.chat-main { min-height: 0; }   /* cho phép cột co lại để cuộn, không đẩy ô nhập */

/* ---- Main chat area ---- */
.chat-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;   /* mỏ neo cho lớp quà bay + sheet donate */
}

.chat-main__head {
  padding: 13px 18px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.chat-main__room-name { font-weight: 700; font-size: 15px; }
.chat-main__online    { color: var(--faint); font-size: 12px; }

.chat-messages {
  flex: 1;
  min-height: 0;            /* cho phép co lại + cuộn, không đẩy thanh nhập tin */
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}
.chat-messages > * { flex-shrink: 0; }
.chat-empty { text-align: center; color: var(--faint); font-size: 13px; padding: 30px 16px; margin: auto; }

/* ---- Băng chuyền quà gần đây ---- */
.chat-ticker[hidden] { display: none !important; }
.chat-ticker {
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
  padding: 7px 14px; border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(90deg, rgba(var(--gold-rgb), .1), rgba(var(--pink-rgb), .06));
  overflow: hidden;
}
.chat-ticker__label { font-size: 11px; font-weight: 800; color: var(--gold); flex-shrink: 0; white-space: nowrap; }
.chat-ticker__label { padding-right: 10px; border-right: 1px solid var(--line-soft); }
.chat-ticker__track {
  flex: 1; min-width: 0; overflow: hidden;
  -webkit-mask-image: linear-gradient(90deg, transparent, rgba(var(--shadow-rgb),1) 4%, rgba(var(--shadow-rgb),1) 96%, transparent);
          mask-image: linear-gradient(90deg, transparent, rgba(var(--shadow-rgb),1) 4%, rgba(var(--shadow-rgb),1) 96%, transparent);
}
.chat-ticker__strip {
  display: flex; gap: 28px; width: max-content; white-space: nowrap;
  animation: chat-marquee 30s linear infinite;
}
.chat-ticker:hover .chat-ticker__strip { animation-play-state: paused; }
@keyframes chat-marquee { from { transform: translateX(0); } to { transform: translateX(-50%); } }
.chat-ticker__item { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.chat-ticker__item b { color: var(--gold); font-weight: 700; }

/* ---- Message types ---- */
.chat-msg { display: flex; gap: 11px; position: relative; }

.chat-msg__av {
  width: 36px; height: 36px;
  border-radius: 10px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
  color: var(--on-cyan);
}

.chat-msg__av img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; }
.chat-msg__main { flex: 1; min-width: 0; }
.chat-msg__head { display: flex; align-items: baseline; gap: 8px; }
.chat-msg__name { font-weight: 700; font-size: 13.5px; }
/* Avatar + tên bấm được → mở menu 4 chức năng */
.chat-msg__av, .chat-msg__name { cursor: pointer; }
.chat-msg__av:hover { filter: brightness(1.08); }
.chat-msg__name:hover { text-decoration: underline; }
.chat-msg__time { color: var(--faint); font-size: 11px; }
.chat-msg__text { color: var(--ink-soft); font-size: 13.5px; line-height: 1.55; word-break: break-word; }
.chat-msg__body { color: var(--ink-soft); font-size: 13.5px; line-height: 1.5; margin-top: 2px; }

/* Tin gộp nhóm (Discord-style): không avatar, thụt lề, giờ hiện khi hover */
.chat-msg--grp { gap: 0; padding-left: 47px; position: relative; margin-top: -9px; }
.chat-msg--grp .chat-msg__stamp {
  position: absolute; left: 0; width: 42px; text-align: right; padding-right: 5px;
  color: var(--faint); font-size: 10px; line-height: 1.7; opacity: 0; transition: opacity var(--ease);
}
.chat-msg--grp:hover .chat-msg__stamp { opacity: 1; }

/* Vạch ngăn ngày */
.chat-day { display: flex; align-items: center; gap: 12px; margin: 8px 2px 2px;
  color: var(--faint); font-size: 11.5px; font-weight: 700; }
.chat-day::before, .chat-day::after { content: ''; height: 1px; flex: 1; background: var(--line-soft); }

/* Ô tìm người nhận + gợi ý (dùng chung donate phòng & tặng quà túi đồ) */
.cgs-pick { position: relative; flex: 1; min-width: 0; }
.cgs-pick > input { width: 100%; }
.cgs-sug {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 30;
  max-height: 210px; overflow-y: auto; padding: 5px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 11px;
  box-shadow: 0 16px 40px -12px rgba(var(--shadow-rgb), .6);
}
.cgs-sug__item {
  display: flex; align-items: center; gap: 9px; width: 100%; border: 0; background: transparent;
  color: var(--ink); font-size: 13px; font-weight: 600; padding: 8px 9px; border-radius: 9px; cursor: pointer; text-align: left;
}
.cgs-sug__item:hover { background: var(--surface2); }
.cgs-sug__av { width: 26px; height: 26px; border-radius: 50%; overflow: hidden; flex-shrink: 0;
  display: grid; place-items: center; font-size: 14px; background: linear-gradient(135deg, var(--violet2), var(--cyan)); }
.cgs-sug__av img { width: 100%; height: 100%; object-fit: cover; }
.cgs-sug__tag { margin-left: auto; font-size: 10px; font-weight: 700; color: var(--cyan);
  background: rgba(var(--cyan-rgb), .12); padding: 2px 7px; border-radius: 8px; }

/* System message */
.chat-msg--system { justify-content: center; }
.chat-msg--system .chat-msg__sys {
  color: var(--faint);
  font-size: 12px;
  background: var(--surface);
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--line-soft);
}

/* Gift message */
.chat-gift-msg {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 14px;
  margin-top: 2px;
  background: linear-gradient(120deg, rgba(var(--gold-rgb), .16), rgba(var(--pink-rgb), .1));
  border: 1px solid rgba(var(--gold-rgb), .35);
  position: relative;
}
.chat-gift-msg__icon {
  font-size: 30px;
  animation: wobble 1.6s ease-in-out infinite;
  flex-shrink: 0;
}
.chat-gift-msg__text { font-size: 13px; line-height: 1.5; }
.chat-gift-msg__text b { color: var(--gold); }
.chat-gift-msg__note { margin-top: 4px; font-size: 12px; font-style: italic; color: var(--ink); opacity: .9; }
@keyframes wobble { 0%,100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg); } }

/* ---- Công cụ kiểm duyệt của Admin (xoá mọi tin · sửa tin của mình) ---- */
.chat-msg--system { position: relative; }
.chat-mod {
  position: absolute; top: 2px; right: 2px; z-index: 5;
  display: none; gap: 4px;
  padding: 3px; border-radius: 9px;
  background: rgba(var(--bg-rgb), .86);
  border: 1px solid var(--line);
  box-shadow: 0 6px 18px -8px rgba(var(--shadow-rgb), .7);
}
.chat-msg:hover > .chat-mod,
.chat-msg--grp:hover > .chat-mod,
.chat-msg--system:hover > .chat-mod,
.chat-gift-msg:hover > .chat-mod { display: flex; }
.chat-mod__btn {
  width: 26px; height: 26px; border-radius: 7px;
  border: 0; background: transparent; cursor: pointer;
  font-size: 13px; line-height: 1; display: grid; place-items: center;
  transition: background var(--ease);
}
.chat-mod__btn:hover { background: var(--surface2); }
.chat-mod__btn--del:hover { background: rgba(var(--red-rgb), .18); }

.chat-edit {
  width: 100%; box-sizing: border-box;
  background: var(--surface); border: 1px solid var(--pink); border-radius: 8px;
  color: var(--ink); font-family: inherit; font-size: 13.5px; padding: 6px 9px; outline: none;
}
.chat-msg__edited { font-style: normal; color: var(--faint); font-size: 11px; }

/* avatar ảnh trong tin nhắn */
.chat-msg__av { overflow: hidden; }
.chat-msg__av img { width: 100%; height: 100%; object-fit: cover; }
.chat-msg__head { display: flex; align-items: baseline; gap: 8px; }
.chat-msg.is-me { flex-direction: row-reverse; }
.chat-msg.is-me .chat-msg__bubble { align-items: flex-end; }
.chat-msg.is-me .chat-msg__head { flex-direction: row-reverse; }

/* ---- Chat input ---- */
.chat-input {
  padding: 12px 16px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.chat-input__gift {
  width: 38px; height: 38px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 16px;
  display: grid; place-items: center;
  transition: border-color var(--ease);
  flex-shrink: 0;
}
.chat-input__gift:hover { border-color: var(--pink); }

.chat-input__field {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
}
.chat-input__emoji {
  border: 0; background: transparent; color: var(--faint);
  font-size: 17px; line-height: 1; cursor: pointer; padding: 0;
  transition: transform var(--ease), filter var(--ease); flex-shrink: 0;
}
.chat-input__emoji:hover { transform: scale(1.15); filter: brightness(1.2); }

/* Bảng chọn emoji (bật lên trên ô nhập) */
.chat-emoji-pop {
  position: absolute;
  left: 0; bottom: calc(100% + 10px);
  z-index: 30;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  width: min(340px, 78vw); max-height: 220px; overflow-y: auto;
  padding: 8px; border-radius: 14px;
  background: var(--surface2); border: 1px solid var(--line);
  box-shadow: 0 20px 44px -18px rgba(var(--shadow-rgb), .75);
  animation: fade-in .14s ease;
}
.chat-emoji-pop__e {
  border: 0; background: transparent; cursor: pointer;
  font-size: 20px; padding: 5px; border-radius: 9px; line-height: 1;
  transition: background var(--ease), transform var(--ease);
}
.chat-emoji-pop__e:hover { background: var(--surface); transform: scale(1.18); }
.chat-input__field input {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  outline: none;
}
.chat-input__field input::placeholder { color: var(--faint); }

.chat-input__send {
  width: 40px; height: 40px;
  border-radius: 11px;
  border: 0;
  background: linear-gradient(135deg, var(--pink), var(--violet));
  color: var(--on-accent);
  font-size: 15px;
  display: grid; place-items: center;
  flex-shrink: 0;
  transition: filter var(--ease);
}
.chat-input__send:hover { filter: brightness(1.1); }

/* ---- Members sidebar ---- */
.chat-members {
  border-left: 1px solid var(--line-soft);
  padding: 14px 12px;
  background: rgba(var(--shadow-rgb), .12);
  overflow-y: auto;
}

.chat-members__group {
  color: var(--faint);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 6px 8px 8px;
}

.chat-member {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--ease);
  white-space: nowrap;
  width: 100%; border: 0; background: transparent; text-align: left;
}
.chat-member:hover { background: var(--surface); color: var(--ink); }
.chat-member__nm { overflow: hidden; text-overflow: ellipsis; }
.chat-member__nm em { font-style: normal; color: var(--faint); font-weight: 500; font-size: 11px; }
.chat-member__av img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }

/* ---- Menu hành động thành viên ---- */
.chat-mpop {
  position: fixed; z-index: 90; width: 200px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 13px;
  box-shadow: 0 18px 44px -12px rgba(var(--shadow-rgb), .7); animation: fade-in .14s ease;
}
.chat-mpop__name {
  font-size: 12px; font-weight: 800; color: var(--ink); padding: 7px 10px 8px;
  border-bottom: 1px solid var(--line-soft); margin-bottom: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-mpop__item {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  color: var(--ink); font-size: 13px; font-weight: 600; padding: 9px 10px; border-radius: 9px;
  cursor: pointer; transition: background var(--ease);
}
.chat-mpop__item:hover { background: var(--surface2); }
.chat-mpop__item b { color: var(--pink); }

.chat-member__av {
  width: 28px; height: 28px;
  border-radius: 8px;
  display: grid; place-items: center;
  font-size: 12px;
  color: var(--on-cyan);
  font-weight: 700;
  position: relative;
  flex-shrink: 0;
}
.chat-member__dot {
  position: absolute;
  right: -2px; bottom: -2px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--green);
  border: 2px solid var(--bg2);
}

/* ---- Message bubble (used by dynamic chat.js) ---- */
.chat-msg__bubble {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chat-msg__text {
  color: var(--ink-soft);
  font-size: 13.5px;
  line-height: 1.5;
}

/* ---- System message inline text ---- */
.chat-msg--system {
  display: flex;
  justify-content: center;
}
.chat-msg--system::before { display: none; }

/* ---- Gift picker popup ---- */
.chat-gift-picker {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  z-index: 20;
  box-shadow: 0 16px 40px -12px rgba(var(--shadow-rgb), .7);
  animation: fade-in .15s ease;
}

.chat-gift-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--line-soft);
  background: var(--bg2);
  font-size: 22px;
  transition: border-color var(--ease), transform var(--ease);
}
.chat-gift-opt small { font-size: 10px; color: var(--gold); font-weight: 700; }
.chat-gift-opt:hover { border-color: var(--pink); transform: scale(1.05); }

/* chat-input needs position:relative for picker to anchor */
.chat-input { position: relative; }

/* ---- Sheet donate / tặng quà công khai (overlay trong khung phòng) ---- */
.chat-giftsheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 25;
  max-height: 92%; overflow-y: auto;
  padding: 16px 18px;
  background: linear-gradient(180deg, var(--surface), var(--bg2));
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -20px 50px -16px rgba(var(--shadow-rgb), .6);
  animation: chat-gs-up .2s ease;
}
@keyframes chat-gs-up { from { transform: translateY(24px); opacity: 0; } }
.chat-giftsheet[hidden] { display: none; }
.chat-gs__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.chat-gs__title { font-size: 15px; }
.chat-gs__x { border: 0; background: var(--surface2); color: var(--ink); width: 28px; height: 28px;
  border-radius: 8px; cursor: pointer; font-size: 13px; }
.chat-gs__x:hover { background: var(--line); }
.chat-gs__row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.chat-gs__label { font-size: 12px; font-weight: 700; color: var(--muted); margin: 2px 0 8px; }
.chat-gs__row .chat-gs__label { margin: 0; flex-shrink: 0; }
.chat-gs__select, .chat-gs__input, .chat-gs__note {
  width: 100%; background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  border-radius: 10px; padding: 9px 12px; font-family: inherit; font-size: 13.5px;
}
.chat-gs__select:focus, .chat-gs__input:focus, .chat-gs__note:focus { outline: none; border-color: var(--pink); }
.chat-gs__note { resize: none; min-height: 50px; margin: 10px 0; }
.chat-gs__input { margin-bottom: 0; }
.chat-gs__amts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-bottom: 9px; }
.chat-gs__amt {
  border: 1px solid var(--line); background: var(--surface); color: var(--gold);
  font-family: var(--font-mono); font-weight: 800; font-size: 13px; padding: 9px 4px;
  border-radius: 10px; cursor: pointer; transition: border-color var(--ease), background var(--ease), transform var(--ease);
}
.chat-gs__amt:hover { border-color: var(--gold); transform: translateY(-1px); }
.chat-gs__amt.is-selected { border-color: var(--gold); background: rgba(var(--gold-rgb), .16); color: var(--on-accent); }
.chat-gs__warn { font-size: 12.5px; color: var(--gold); background: rgba(var(--gold-rgb), .1);
  border: 1px solid rgba(var(--gold-rgb), .3); padding: 8px 11px; border-radius: 10px; margin: 10px 0 0; }
.chat-gs__btns { display: flex; gap: 8px; margin: 13px 0 4px; }
.chat-gs__gifts { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.chat-gs__gift {
  border: 1px solid var(--line); background: var(--surface2); border-radius: 11px;
  padding: 9px 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px;
  transition: border-color var(--ease), transform var(--ease); font-size: 21px;
}
.chat-gs__gift:hover { border-color: var(--gold); transform: translateY(-2px); }
.chat-gs__gift.is-selected { border-color: var(--gold); background: rgba(var(--gold-rgb), .18); transform: translateY(-2px); }
.chat-gs__gift small { font-size: 10px; font-weight: 700; color: var(--gold); font-family: var(--font-mono); }

/* ---- Hiệu ứng quà bay ---- */
.chat-fly { position: absolute; inset: 0; pointer-events: none; z-index: 22; overflow: hidden; }
.chat-fly__item {
  position: absolute; bottom: 64px; will-change: transform, opacity;
  filter: drop-shadow(0 4px 12px rgba(var(--shadow-rgb), .4));
  animation: chat-rise 3.8s ease-in forwards;
}
@keyframes chat-rise {
  0%   { transform: translateY(0) scale(.5); opacity: 0; }
  16%  { opacity: 1; }
  100% { transform: translateY(-460px) translateX(var(--dx,0)) scale(1.3) rotate(16deg); opacity: 0; }
}
.chat-fly__burst {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%,-50%);
  font-size: 110px; filter: drop-shadow(0 12px 32px rgba(var(--pink-rgb), .7));
  animation: chat-burst 2.4s cubic-bezier(.2,.9,.3,1.3) forwards;
}
@keyframes chat-burst {
  0%   { transform: translate(-50%,-50%) scale(.2); opacity: 0; }
  26%  { transform: translate(-50%,-50%) scale(1.2); opacity: 1; }
  70%  { transform: translate(-50%,-50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%,-60%) scale(1.12); opacity: 0; }
}

/* ============================================================
   EMBED — khung chat nhúng trong Bảng tin (cột phải, ghim & cao
   full màn hình, cuộn tin riêng). 1 cột duy nhất (bỏ rooms/members).
   ============================================================ */
.chat-window--embed {
  margin-top: 0;
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--topbar-h) - 32px);
  max-height: 920px;
}
.chat-window--embed .chat-body {
  display: flex;            /* 1 cột: chỉ còn .chat-main */
  grid-template-columns: none;
  grid-template-rows: none;
  height: auto;
  flex: 1;
  min-height: 0;
}
.chat-window--embed .chat-main { flex: 1; }

/* Nút mở bảng thành viên online + huy hiệu số đếm */
.chat-main__members {
  margin-left: auto; flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  font-size: 12.5px; font-weight: 700; border-radius: 9px; padding: 5px 10px;
  cursor: pointer; transition: border-color var(--ease), color var(--ease);
}
.chat-main__members:hover { border-color: var(--cyan); color: var(--ink); }
.chat-main__members b { color: var(--green); font-family: var(--font-mono); }

/* Bảng thành viên online xổ ra (anchored trong .chat-main) */
.chat-members--pop {
  position: absolute; top: 50px; right: 12px; z-index: 30;
  width: 232px; max-height: 64%;
  border: 1px solid var(--line);
  border-radius: 13px; background: var(--surface);
  box-shadow: 0 18px 44px -12px rgba(var(--shadow-rgb), .7);
  animation: fade-in .14s ease;
}
.chat-members--pop[hidden] { display: none; }

/* ---- Responsive ---- */
@media (max-width: 920px) {
  .chat-body { grid-template-columns: 1fr; height: auto; }
  .chat-rooms,
  .chat-members { display: none; }
  .chat-members--pop { display: block; }   /* bảng xổ vẫn dùng được trên mobile */
  .chat-members--pop[hidden] { display: none; }
  .chat-messages { height: 400px; }
}
