/* Chat Embed Styling */
#gift-btn.gift-button {
    display: none;
}
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  background: #161616;
  font-family: 'Open Sans', sans-serif;
  font-size: 16px;
  color: #D0D0D0;
}

#chat-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

#messages {
  list-style: none;
  padding: 10px;
  margin: 0;
  background: #2C2C2C;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

#messages li {
  display: flex;
  background: #1E1E1E;
  padding: 10px;
  margin-bottom: 10px;
  border-radius: 8px;
}

/* Avatar on the left */
#messages li > img {
  width: 45px;
  height: 45px;
  border-radius: 5px;
  margin-right: 10px;
  object-fit: cover;
}

/* Main content column */
.message-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.right-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

/* Top row: name, time และปุ่ม admin */
.message-content .msg-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.message-content .username {
  font-weight: bold;
  color: #00bfff;
  text-decoration: none;
}

.message-content .msg-time {
  font-size: 13px;
  color: #888;
  margin-left: auto; /* ดันไปฝั่งขวา */
}

.right-actions .msg-time {
  order: 3; /* เวลาอยู่ขวาสุด */
}

.msg-time {
  color: #8A8A8A;
  font-size: 80%;
}

/* Container ปุ่ม Delete / Ban */
.admin-actions {
  display: flex;
  gap: 6px;
}

/* ปุ่ม Delete และ Ban */
button.delete-button,
button.ban-button {
  padding: 2px 6px;
  background: #262424;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

button.delete-button:hover,
button.ban-button:hover {
  background: #444;
}

/* Message text */
.message-content .msg-body {
  margin-top: 5px;
  color: #fff;
  font-size: 15px;
  word-break: break-word;
}

#form {
  display: flex;
  background: #0C0C0C;
  padding: 10px;
}

#input {
  flex: 1;
  background: #1E1E1E;
  border: none;
  padding: 10px;
  font-size: 16px;
  color: #D0D0D0;
  border-radius: 4px;
}

#input:focus {
  outline: none;
}

button {
  margin-left: 1px;
  padding: 10px 16px;
  background: #F3E994;
  color: #181818;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
}

button:hover {
  background: #f5f0a8;
}

/* Scrollbar Styling */
#messages::-webkit-scrollbar {
  width: 6px;
}
#messages::-webkit-scrollbar-thumb {
  background-color: #888;
  border-radius: 10px;
}
#messages::-webkit-scrollbar-thumb:hover {
  background-color: #555;
}
#messages::-webkit-scrollbar-track {
  background: #333;
  border-radius: 10px;
}

/* read more */
.msg-body {
  max-height: 12em;  /* ประมาณ 8 บรรทัด (line-height ~1.5em) */
  overflow: hidden;
  position: relative;
}

.msg-body.expanded {
  max-height: none;
}

.read-more-btn {
  display: inline-block;
  color: #00bcd4;
  cursor: pointer;
  margin-top: 0.5em;
}

.right-actions .ban-button,
.right-actions .delete-button {
  order: 1; /* ปุ่มอยู่ก่อนเวลา */
  padding: 2px 6px;
  background: #262424;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.right-actions .ban-button:hover,
.right-actions .delete-button:hover {
  background: #b42c29;
}

.date-separator {
  display: flex;               /* ใช้ flex */
  align-items: center;         /* กึ่งกลางแนวตั้ง */
  justify-content: center;     /* กึ่งกลางแนวนอน */
  margin: 12px 0;
  font-size: 13px;
  color: #ccc;
  font-weight: bold;
  gap: 8px;                     /* ระยะห่างระหว่างเส้นกับข้อความ */
}

.date-separator::before,
.date-separator::after {
  content: "";
  flex: 1;                      /* ให้เส้นยืดเต็มด้านซ้ายและขวา */
  height: 1px;
  background: #444;
}

.date-separator span {
  background: #2C2C2C;
  padding: 2px 8px;
  border-radius: 4px;
}

.date-separator::before { left: 0; }
.date-separator::after  { right: 0; }

.bbcode-img {
  display: block;
  max-height: 130px;   /* จำกัดความสูงเป็นหลัก */
  height: auto;        /* ให้คงอัตราส่วนตามความสูง */
  width: auto;         /* ให้กว้างตามอัตราส่วน */
  max-width: 100%;     /* ป้องกันเกินความกว้าง container */
  object-fit: contain; /* ไม่ครอป แต่ให้ภาพทั้งหมดแสดง */
  border-radius: 4px;
  margin-top: 5px;
}

/* === BBCode Toolbar === */
.bbcode-toolbar {
  display: flex;
  justify-content: flex-start;
  gap: 8px;
  background: #0C0C0C;
  padding: 8px 10px;
}

.bbcode-toolbar button {
  background: #1E1E1E;
  border: none;
  color: #D0D0D0;
  padding: 6px 10px;
  font-size: 14px;
  border-radius: 4px;
  cursor: pointer;
}

.bbcode-toolbar button:hover {
  background: #333;
}

.sticker-popup {
    display: grid;
    grid-template-columns: repeat(5, 1fr); /* ✅ 5 คอลัมน์คงที่ */
    gap: 6px;
    position: absolute;
    background: #222;
    padding: 8px;
    border: 1px solid #444;
    border-radius: 8px;
    max-width: 245px;        /* ✅ กว้างพอสำหรับ 5 ช่อง */
    max-height: 175px;       /* ✅ มี scroll เมื่อเกิน */
    overflow-y: auto;
    z-index: 999;
}

.sticker-popup img {
    width: 40px;
    height: 40px;
    cursor: pointer;
    border-radius: 4px;
    transition: transform 0.15s ease-in-out;
}

.sticker-popup img:hover {
    transform: scale(1.1);
}

.gift-popup {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  position: absolute;
  background: #222;
  padding: 8px;
  border: 1px solid #444;
  border-radius: 8px;
  max-width: 280px;
  max-height: 180px;
  overflow-y: auto;
}

.gift-item {
  width: 48px;
  height: 48px;
  position: relative;
  cursor: pointer;
}

.gift-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 6px;
}

.gift-item span {
  color: #fff;
  flex: 1;
}
.gift-item small {
  color: #aaa;
}

.gift-message {
  background: #222;
  color: #fff;
  font-size: 14px;
  padding: 6px 10px;
  margin: 4px 0;
  border-radius: 6px;
  margin-left: 1px;
  list-style: none;
}

.gift-message strong {
  color: #f8d34b;
  margin-left: 2px;
}

.gift-message span {
  color: #ff6f61;
}

#combo-counter {
  background: #ff4081;
  color: #fff;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 18px;
  font-weight: bold;
  position: fixed;
  top: 20px;
  right: 20px;
  display: none;
  z-index: 1000;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

.combo-popup {
  position: fixed;
  bottom: 100px;
  right: 20px;
  background: linear-gradient(135deg, rgba(255,64,129,0.95), rgba(255,105,180,0.95));
  color: #fff;
  display: flex;
  align-items: center;
  padding: 10px 15px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  font-family: 'Prompt', sans-serif;
  z-index: 9999;
  transform: scale(0.9);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.combo-popup.show {
  transform: scale(1);
  opacity: 1;
}

.combo-left {
  display: flex;
  align-items: center;
}

.combo-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid #fff;
  margin-right: 10px;
}

.combo-info {
  display: flex;
  flex-direction: column;
  font-size: 14px;
}

.combo-name {
  font-weight: bold;
  font-size: 16px;
}

.combo-gift {
  font-size: 14px;
  opacity: 0.9;
}

.combo-count {
  font-size: 36px;
  font-weight: bold;
  margin-left: 20px;
  text-shadow: 0 0 8px rgba(255,255,255,0.6), 0 2px 4px rgba(0,0,0,0.6);
}

.gift-icon-small {
  width: 24px;
  height: 24px;
  vertical-align: middle;
  margin-left: 5px;
}

.gift-img {
  width: 32px;
  height: 32px;
  vertical-align: middle;
  margin-left: 6px;
  border-radius: 4px;
}

.gift-message {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
}

#messages li .giftsmall-img {
  width: 25px;
  height: 25px;
  object-fit: contain;
  vertical-align: middle;
  margin-right: 1px;
}

.gift-combo-popup {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  align-items: center;
  background: transparent;
  transform: scale(1);
  transition: transform 0.15s ease, opacity 0.3s ease;
  opacity: 1;
}

.gift-combo-popup.show {
  opacity: 1;
}

.gift-combo-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  color: white;
  padding: 12px 18px;
  border-radius: 14px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  background: linear-gradient(135deg, rgba(255,64,129,0.95), rgba(255,105,180,0.95)); /* เพิ่มอันนี้ */
}

.combo-count-with-img {
  display: flex;
  align-items: center;
  gap: 8px;
}

.gift-combo-img {
  width: 52px;
  height: 52px;
  margin-right: 6px;
  border-radius: 8px;
  object-fit: cover;
  vertical-align: middle;
}

.chat-warning {
  position: fixed;
  top: 20px; /* ชิดบน */
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: #bf1111; /* พื้นหลังเข้มทึบ */
  color: #fff;
  padding: 14px 24px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: bold;
  opacity: 0;
  z-index: 9999;
  transition: all 0.3s ease;
  text-align: center;
  white-space: pre-line; /* รองรับขึ้นบรรทัดใหม่ */
  box-shadow: 0 4px 12px rgba(0,0,0,0.6);
}

.chat-warning.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.gift-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.2s;
}

.gift-item:hover .gift-overlay {
  opacity: 1;
}

.gift-name {
  font-size: 12px;
  font-weight: bold;
}

.gift-price {
  font-size: 11px;
  color: #ffeb3b;
}

.gift-send {
  margin-top: 2px;
  background: #ff4081;
  color: white;
  border: none;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
}

.gift-send:hover {
  background: #f50057;
}

.gift-overlay .gift-price {
  font-size: 13px;
  margin-bottom: 6px;
  color: #ffeb3b;
}

.gift-overlay .gift-send {
  background: #ff4081;
  color: white;
  border: none;
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
}

.gift-overlay .gift-send:hover {
  background: #f50057;
}

/* Popup หลัก */
.gift-popup-grid {
  display: grid;
  grid-template-columns: repeat(5, 60px);
  gap: 12px;
  padding: 12px;
  background: rgba(0,0,0,0.9);
  border-radius: 10px;
  z-index: 9999;
  backdrop-filter: blur(6px);
}

/* ไอคอนของขวัญ */
.gift-item-grid {
  width: 60px;
  height: 60px;
  cursor: pointer;
  display: flex;
  align-items: center;
  background: rgba(255,255,255,0.08); /* ✅ พื้นหลังจาง */
  border-radius: 12px;                 /* ✅ ขอบมน */
  justify-content: center;
}
.gift-item-grid img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 8px;
  transition: transform 0.2s;
}
.gift-item-grid:hover img {
  transform: scale(1.1);
}

/* Hover effect */
.gift-item-grid:hover {
  background: rgba(255,255,255,0.15);  /* hover สว่างขึ้น */
  transform: scale(1.08);
}

/* Hover Card */
.gift-hover-card {
  width: 140px;
  padding: 10px;
  background: #222;
  border-radius: 10px;
  text-align: center;
  color: #fff;
  z-index: 1000;
  box-shadow: 0 2px 10px rgba(0,0,0,0.5);
}
.gift-hover-card {
  transform: translateY(-10px) scale(0.98);
  transition: opacity 200ms ease, transform 200ms ease;
  pointer-events: auto;
  transform-origin: top center;
}

.gift-hover-card.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.gift-hover-card.hide {
  opacity: 0;
  transform: translateY(-10px) scale(0.95);
  pointer-events: none;
}

.gift-card-img {
  width: 60px;
  height: 60px;
  object-fit: contain;
  margin-bottom: 5px;
}
.gift-card-name {
  font-weight: bold;
  font-size: 14px;
  margin-bottom: 2px;
}
.gift-card-price {
  font-size: 12px;
  color: #ffda79;
  margin-bottom: 6px;
}
.gift-card-send {
  background: #ff4081;
  border: none;
  color: #fff;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}
.gift-card-send:hover {
  background: #e91e63;
}
.toolbar-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #0C0C0C;
  border-bottom: 1px solid #333;
  padding: 8px 10px;
}
.gift-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}
.gift-button {
  font-size: 18px;
  padding: 4px 8px;
  background: #1E1E1E;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}
.gift-button:hover {
  background: #333;
}
.gift-balance {
  display: flex;
  justify-content: center;
  gap: 15px;
  padding: 5px 0 8px;
  font-weight: bold;
  font-size: 14px;
  color: #fff;
}

/* ==== Balance Bar ด้านบน ==== */
.gift-balance-bar {
  grid-column: 1 / -1; /* ให้กินเต็มความกว้าง */
  text-align: center;
  font-size: 14px;
  margin-bottom: 6px;
  padding: 4px 0;
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 8px;
}

/* ==== Animation ==== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ==== Flex Message Bubble ==== */
.flex-message {
  background: #091026;
  padding: 10px;
  border-radius: 10px;
  margin: 1px 0;
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.flex-row {
  display: flex;
  gap: 15px;
  align-items: flex-start;
}

.flex-thumb {
  width: 170px;
  height: auto;
  border-radius: 8px;
  object-fit: cover;
}

.flex-info {
  flex: 1;
}

.flex-title {
  margin: 0;
  font-size: 18px;
  font-weight: bold;
  color: #fff;
}

.flex-subtitle {
  margin: 5px 0;
  color: #ccc;
  font-size: 14px;
}

.flex-meta {
  margin: 2px 0;
  font-size: 13px;
  color: #aaa;
}

.flex-button {
  display: inline-block;
  background: #ff9800;
  color: #fff;
  padding: 6px 16px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: bold;
  margin-top: 10px;
  margin-bottom: 4px;
  transition: background 0.3s;
}

.flex-button:hover {
  background: #e68900;
}

.flex-message .username {
  display: block;
  font-weight: bold;
  color: #ffcc00;
  font-size: 14px;
  margin-bottom: 6px;
  margin-top: -4px;
  padding-left: 4px;
}

.flex-divider {
  border: 0;
  border-top: 1px solid #444;
  margin: 8px 0 6px;
}

.flex-meta-local {
  margin: 2px 0;
  font-size: 13px;
  color: #b53737;
}

@media (max-width: 480px) {
  .flex-thumb {
    width: 120px;
  }
  .flex-title {
    font-size: 16px;
  }
  .flex-button {
    padding: 6px 12px;
    font-size: 14px;
  }
}