/* ================= EMOJI PICKER, EMOJI TO & THẢ CẢM XÚC ================= */

/* ---------- Nút emoji trong ô nhập ---------- */
.chat-composer-container { position: relative; }
.composer-box { padding-left: 6px; }

.emoji-btn {
  background: transparent;
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 22px;
  flex-shrink: 0;
  align-self: flex-end;
  margin-bottom: 1px;
}
.emoji-btn:hover,
.emoji-btn.active {
  color: var(--primary-color);
  background: #eef4ff;
}
.emoji-btn.active i { transform: scale(1.08); }
.emoji-btn i { transition: transform 0.15s ease; }
.emoji-btn:disabled { opacity: 0.5; cursor: default; background: transparent; color: var(--text-muted); }

/* ---------- Bảng chọn emoji ---------- */
.emoji-popover {
  position: absolute;
  left: 18px;
  bottom: calc(100% - 4px);
  z-index: 60;
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: 18px;
  box-shadow: var(--shadow-popup);
  overflow: hidden;
  transform-origin: bottom left;
  animation: emojiPopIn 0.18s cubic-bezier(0.34, 1.4, 0.64, 1);
}
.emoji-popover.hidden { display: none; }
@keyframes emojiPopIn {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.emoji-popover emoji-picker {
  display: block;
  width: 352px;
  height: 380px;
  --border-size: 0;
  --background: #ffffff;
  --indicator-color: var(--primary-color);
  --input-border-color: var(--border-light);
  --input-border-radius: 12px;
  --input-font-size: 14px;
  --input-padding: 0.45rem 0.75rem;
  --outline-color: rgba(37, 99, 235, 0.35);
  --button-hover-background: #eef4ff;
  --button-active-background: #dbeafe;
  --category-font-color: var(--text-secondary);
  --emoji-size: 1.45rem;
  --emoji-padding: 0.42rem;
  --num-columns: 8;
}

/* Bảng dự phòng khi không tải được thư viện */
.emoji-fallback-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 10px;
  width: 340px;
  max-height: 280px;
  overflow-y: auto;
}
.emoji-fallback-btn {
  border: none;
  background: transparent;
  font-size: 23px;
  line-height: 1;
  padding: 7px 0;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.12s, transform 0.12s;
}
.emoji-fallback-btn:hover { background: #eef4ff; transform: scale(1.15); }

/* ---------- Emoji to (tin chỉ có 1-3 emoji) ---------- */
.msg-item.jumbo .msg-bubble {
  background: transparent !important;
  border-color: transparent !important;
  box-shadow: none !important;
  padding: 0 2px;
}
.msg-item.jumbo .msg-orig {
  line-height: 1.15;
  letter-spacing: 2px;
}
.msg-item.jumbo-1 .msg-orig { font-size: 52px; }
.msg-item.jumbo-2 .msg-orig { font-size: 42px; }
.msg-item.jumbo-3 .msg-orig { font-size: 36px; }
.msg-item.jumbo .msg-trans-row { display: none !important; }
.msg-item.jumbo .msg-time-bottom { margin-top: 0; }
.msg-item.jumbo.is-new .msg-orig {
  display: inline-block;
  animation: jumboPop 0.42s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes jumboPop {
  0% { opacity: 0; transform: scale(0.3) rotate(-8deg); }
  70% { opacity: 1; transform: scale(1.12) rotate(2deg); }
  100% { transform: scale(1) rotate(0); }
}

/* ---------- Hàng bong bóng + nút thả cảm xúc ---------- */
.msg-bubble-row {
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  min-width: 0;
}
.msg-item.me .msg-bubble-row { flex-direction: row-reverse; }
.msg-bubble-row .msg-bubble { min-width: 0; }

.msg-react-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}
.msg-item:hover .msg-react-btn,
.msg-item.reacting .msg-react-btn {
  opacity: 1;
  pointer-events: auto;
}
.msg-react-btn:hover { background: #eef4ff; color: var(--primary-color); }

.msg-item.reacting .msg-bubble {
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.22), var(--shadow-sm);
}
.msg-item.jumbo.reacting .msg-bubble { box-shadow: none !important; }

/* Thiết bị cảm ứng: không có hover -> dùng giữ lâu; tắt menu chọn chữ mặc định trên bong bóng */
@media (hover: none) {
  .msg-react-btn { display: none; }
  .msg-bubble {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }
  .msg-item.reacting .msg-bubble { transform: scale(0.98); transition: transform 0.15s; }
}

/* ---------- Chip cảm xúc dưới tin nhắn ---------- */
.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: -7px;
  padding: 0 8px;
  position: relative;
  z-index: 1;
}
.msg-reactions:empty { display: none; }
.msg-item.me .msg-reactions { justify-content: flex-end; }
.msg-item.jumbo .msg-reactions { margin-top: 0; }

.reaction-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 24px;
  padding: 0 7px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-light);
  background: #ffffff;
  box-shadow: 0 2px 6px -2px rgba(15, 23, 42, 0.16);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: transform 0.12s, background 0.12s, border-color 0.12s;
  animation: chipIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.reaction-chip:hover { transform: translateY(-1px); border-color: #cbd5e1; }
.reaction-chip.mine {
  background: #eef4ff;
  border-color: #93c5fd;
  color: var(--primary-color);
}
.reaction-emoji { font-size: 14px; line-height: 1; }
.reaction-count { line-height: 1; }
@keyframes chipIn {
  from { opacity: 0; transform: scale(0.5); }
  to { opacity: 1; transform: scale(1); }
}

/* ---------- Thanh chọn cảm xúc nổi ---------- */
.reaction-bar {
  position: fixed;
  z-index: 1200;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px 6px;
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-popup);
  animation: reactionBarIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.reaction-bar.hidden { display: none; }
@keyframes reactionBarIn {
  from { opacity: 0; transform: translateY(6px) scale(0.9); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.reaction-opt {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: transparent;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.16s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.15s;
  animation: reactionOptIn 0.32s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.reaction-opt:nth-child(2) { animation-delay: 0.025s; }
.reaction-opt:nth-child(3) { animation-delay: 0.05s; }
.reaction-opt:nth-child(4) { animation-delay: 0.075s; }
.reaction-opt:nth-child(5) { animation-delay: 0.1s; }
.reaction-opt:nth-child(6) { animation-delay: 0.125s; }
@keyframes reactionOptIn {
  from { opacity: 0; transform: translateY(8px) scale(0.6); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.reaction-opt:hover { transform: scale(1.3) translateY(-3px); }
.reaction-opt.active { background: #dbeafe; }

.reaction-copy {
  font-size: 19px;
  color: var(--text-secondary);
}
.reaction-copy:hover {
  transform: none;
  background: #f1f5f9;
  color: var(--primary-color);
}
.reaction-bar-divider {
  width: 1px;
  height: 22px;
  background: var(--border-light);
  margin: 0 3px;
}

/* ---------- Thông báo nhỏ (đã sao chép...) ---------- */
.mini-toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 10px);
  z-index: 1300;
  background: rgba(15, 23, 42, 0.9);
  color: #ffffff;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-card);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.mini-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Điện thoại ---------- */
@media (max-width: 768px) {
  .emoji-popover {
    left: 8px;
    right: 8px;
    bottom: calc(100% + 2px);
    border-radius: 16px;
  }
  .emoji-popover emoji-picker {
    width: 100%;
    height: 300px;
    --emoji-size: 1.6rem;
    --emoji-padding: 0.38rem;
  }
  .emoji-fallback-grid { width: 100%; }
  .emoji-btn { width: 32px; height: 32px; font-size: 21px; }
}
@media (max-width: 480px) {
  .reaction-opt { width: 36px; height: 36px; font-size: 23px; }
}
