/* chat.css — ช่องแชท (คู่กับ chat.js) สีครีม/ทอง/กรมท่า เข้าชุดกับ UI ซากุระ
   ตำแหน่ง: หน้าแรก = มุมซ้ายล่าง ใต้ปุ่มร้านค้า/ช่องเก็บของ · โต๊ะเล่น = มุมซ้ายล่าง ใต้ไพ่เกิดของคนฝั่งซ้าย เหนือปุ่มเรียงไพ่ (.gx-tools)
   ภาพนิ่งทั้งหมด ไม่มีอนิเมชันวน → ไม่ต้องกัน prefers-reduced-motion
   Extend: ขยับ/ย่อช่องที่ตัวแปร --chx-* ของแต่ละหน้า (data-mode) */

.chx {
  --chx-w: min(30vw, 520px);
  --chx-h: 40vh;
  --chx-left: 3vw;
  --chx-bottom: 3vh;
  --chx-ink: #3a2748;
  --chx-gold: #d9b56a;
  position: fixed;
  left: var(--chx-left);
  bottom: var(--chx-bottom);
  z-index: 6; /* เหนือโต๊ะ/ป้ายที่นั่ง แต่ใต้หน้าต่างผล/หน้าต่างอื่น */
  display: flex;
  flex-direction: column;
  width: var(--chx-w);
  height: var(--chx-h);
  box-sizing: border-box;
  border: 0.25vh solid var(--chx-gold);
  border-radius: 1.6vh;
  /* พื้นโปร่ง 80% (เหลือทึบ 20%) ให้เห็นโต๊ะ/ฉากด้านหลัง (เจ้าของสั่ง) — ตัวหนังสือยังทึบเต็ม + เงาสีครีมช่วยให้อ่านออกบนพื้นลาย */
  background: linear-gradient(180deg, #fffaf033, #f6e8cd33);
  text-shadow:
    0 0 0.4vh #fffaf0,
    0 0 0.8vh #fffaf0;
  box-shadow:
    0 0.8vh 1.8vh #0006,
    inset 0 0 0 0.2vh #fff8;
  color: var(--chx-ink);
  font:
    600 max(11px, 2vh) / 1.35 Sarabun,
    sans-serif;
  overflow: hidden;
}
/* โต๊ะเล่น: มุมซ้ายล่างชิดขอบล่าง (ปุ่มเรียงไพ่ย้ายไปข้างตัวละครเราแล้ว) · กว้างไม่เกินขอบซ้ายของไพ่ในมือ (.gx-dock left 49vh) */
.chx[data-mode='table'] {
  --chx-w: min(21vw, 420px);
  /* สูงให้มากที่สุดโดยขอบบนยังอยู่ใต้แถวไพ่เกิดของคนฝั่งซ้าย (ก้นแถว ~62% ของความสูงจอทุกขนาด) — เจ้าของสั่งขยาย 0.34.1 */
  --chx-h: 34vh;
  --chx-left: 1.5vh;
  --chx-bottom: 1.5vh;
  font-size: max(10px, 1.9vh);
}
.chx.min {
  height: auto;
}
.chx.min .chx-body {
  display: none;
}

/* แถบบน: แท็บ + ปุ่มพับ */
.chx-top {
  display: flex;
  align-items: center;
  gap: 0.5vh;
  padding: 0.6vh 0.6vh 0.4vh;
  border-bottom: 0.15vh solid #e9c27a88;
}
.chx-tabs {
  display: flex;
  flex: 1;
  gap: 0.5vh;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.chx-tabs::-webkit-scrollbar {
  display: none;
}
.chx-tab,
.chx-fold {
  position: relative;
  flex: none;
  max-width: 14em;
  padding: 0.3vh 1.1vh;
  border: 0.15vh solid #e9c27a;
  border-radius: 99px;
  background: #fffdf8;
  color: var(--chx-ink);
  font: inherit;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.chx-tab.on {
  border-color: #b8862e;
  background: linear-gradient(180deg, #ffe9a8, #f2c25c);
  color: #3a1d06;
}
.chx-tab.lock {
  opacity: 0.5;
}
.chx-plus {
  padding: 0.3vh 0.9vh;
}
.chx-fold {
  padding: 0.3vh 0.8vh;
  background: none;
  border-color: transparent;
}
.chx-dot {
  display: inline-block;
  min-width: 1.4em;
  margin-left: 0.4em;
  padding: 0 0.3em;
  border-radius: 99px;
  background: #e2483c;
  color: #fff;
  font-style: normal;
  font-size: 0.8em;
  line-height: 1.4em;
  text-align: center;
}

/* รายการข้อความ */
.chx-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}
.chx-list {
  flex: 1;
  min-height: 0;
  padding: 0.6vh 1vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.chx-m {
  margin: 0.25vh 0;
  word-break: break-word;
  cursor: pointer;
}
.chx-m b {
  color: #8a4b12;
}
.chx-m.mine {
  cursor: default;
}
.chx-m.mine b {
  color: #2f6b9a;
}
.chx-rep {
  display: block;
  margin-top: 0.3vh;
  padding: 0.2vh 1vh;
  border: 0.15vh solid #e2483c;
  border-radius: 99px;
  background: #fff1ef;
  color: #b3261e;
  font: inherit;
  font-size: 0.9em;
  cursor: pointer;
}
.chx-empty {
  margin: 0.6vh 0;
  color: #7a6a5a;
  font-weight: 600;
}
.chx-friend {
  display: block;
  width: 100%;
  margin: 0.4vh 0;
  padding: 0.5vh 1vh;
  border: 0.15vh solid #e9c27a;
  border-radius: 1vh;
  background: #fffdf8;
  color: var(--chx-ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.chx-friend small {
  color: #7a6a5a;
}

/* กระซิบ: ปุ่มโหลดข้อความเก่ากว่า + ข้อความเก่าจากฐานข้อมูลจางลงเล็กน้อย */
.chx-older {
  display: block;
  margin: 0.2vh auto 0.6vh;
  padding: 0.2vh 1.2vh;
  border: 0.15vh solid #e9c27a;
  border-radius: 99px;
  background: #fffdf8cc;
  color: var(--chx-ink);
  font: inherit;
  font-size: 0.9em;
  cursor: pointer;
}
.chx-m.old {
  opacity: 0.85;
}

/* ข้อตกลงก่อนเริ่มแชท (บัญชีที่ยังไม่เคยยอมรับฉบับนี้) */
.chx-terms {
  margin: 0.4vh 0 0.8vh;
  padding: 0.6vh 1vh;
  border: 0.15vh solid #e9c27a;
  border-radius: 1vh;
  background: #fffdf5;
}
.chx-terms p {
  margin: 0 0 0.6vh;
  font-weight: 500;
}
.chx-terms a {
  color: #b8862b;
}
.chx-agree {
  padding: 0.4vh 1.4vh;
  border: 0;
  border-radius: 99px;
  background: linear-gradient(180deg, #ffe9a8, #f2c25c);
  color: #3a1d06;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

/* ข้อความแจ้ง (ส่งไม่ได้ / รายงานแล้ว) */
.chx-note {
  display: none;
  padding: 0.3vh 1vh;
  background: #fff1ef;
  color: #b3261e;
  font-size: 0.9em;
}
.chx-note.on {
  display: block;
}

/* ช่องพิมพ์ */
.chx-form {
  display: flex;
  gap: 0.5vh;
  margin: 0;
  padding: 0.5vh 0.6vh 0.6vh;
  border-top: 0.15vh solid #e9c27a88;
}
.chx-in {
  flex: 1;
  min-width: 0;
  padding: 0.5vh 1vh;
  border: 0.15vh solid #e9c27a;
  border-radius: 99px;
  background: #ffffff80; /* ช่องพิมพ์ทึบ 50% (เจ้าของสั่ง) */
  color: var(--chx-ink);
  font: inherit;
  font-weight: 600;
}
.chx-in:disabled {
  background: #f3ece080;
}
.chx-send {
  flex: none;
  width: 4.4vh;
  min-width: 26px;
  border: 0;
  border-radius: 99px;
  background: linear-gradient(180deg, #ffe9a8, #f2c25c);
  color: #3a1d06;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
.chx-send:disabled {
  opacity: 0.45;
  cursor: default;
}

/* อีโมติคอนรูป (Chat/chat-emoji.js): ในข้อความ · ข้อความที่มีแต่รูป (ใหญ่แบบสติกเกอร์) · ปุ่ม 😊 · แผงเลือก · บอกวิธีปลดชุดที่ล็อก
   แผงอยู่ในลำดับปกติเหนือช่องพิมพ์ — รายการข้อความหดลงให้เอง ไม่ทับโต๊ะ */
.chx-emo {
  width: 1.6em;
  height: 1.6em;
  vertical-align: -0.45em;
}
.chx-m.big .chx-emo {
  width: 3.4em;
  height: 3.4em;
  vertical-align: middle;
}
.chx-emo-btn {
  flex: none;
  width: 4.4vh;
  min-width: 26px;
  padding: 0;
  border: 0.15vh solid #e9c27a;
  border-radius: 99px;
  background: #ffffff80;
  font-size: 1.1em;
  line-height: 1;
  cursor: pointer;
}
.chx-emo-btn.on {
  background: linear-gradient(180deg, #ffe9a8, #f2c25c);
}
.chx-emo-btn:disabled {
  opacity: 0.45;
  cursor: default;
}
.chx-emo-panel {
  display: none;
  flex: none;
  max-height: 62%;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-top: 0.15vh solid #e9c27a88;
  background: #fffaf0e6; /* แผงเลือกทึบกว่ากล่องแชท ให้เห็นรูปชัด */
  text-shadow: none;
}
.chx-emo-panel.on {
  display: block;
}
.chx-emo-tabs {
  display: flex;
  gap: 0.4vh;
  padding: 0.4vh 0.6vh 0;
}
.chx-emo-tab {
  position: relative;
  flex: none;
  padding: 0.2vh 0.8vh;
  border: 0.15vh solid transparent;
  border-radius: 1vh 1vh 0 0;
  background: transparent;
  cursor: pointer;
}
.chx-emo-tab.on {
  border-color: #e9c27a;
  background: #fff;
}
.chx-emo-ti {
  display: block;
  width: 3vh;
  height: 3vh;
  min-width: 20px;
  min-height: 20px;
}
.chx-emo-lock {
  position: absolute;
  right: -0.2vh;
  bottom: -0.2vh;
  font-size: 0.7em;
  font-style: normal;
}
.chx-emo-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 5.4vh)); /* ช่องเล็กพอให้ยังเห็นข้อความแชทด้านบน */
  justify-content: space-between;
  gap: 0.3vh;
  padding: 0.5vh 0.6vh;
}
.chx-emo-cell {
  aspect-ratio: 1;
  padding: 0.2vh;
  border: 0;
  border-radius: 1vh;
  background: transparent;
  cursor: pointer;
}
.chx-emo-cell:hover,
.chx-emo-cell:focus-visible {
  background: #ffe9a866;
}
.chx-emo-cell.locked {
  opacity: 0.4;
  filter: grayscale(0.7);
}
.chx-emo-img {
  display: block;
  width: 100%;
  height: 100%;
}
/* สติกเกอร์ตัวละคร: ในข้อความใหญ่กว่าอีโมติคอน (รูปมีตัวละครครึ่งตัว) · ในแผงเรียง 6 ช่องต่อแถว แยกหัวข้อตามตัวละคร */
.chx-emo.chx-st {
  width: 3.6em;
  height: 3.6em;
  vertical-align: middle;
}
.chx-m.big .chx-emo.chx-st {
  width: 5.4em;
  height: 5.4em;
}
.chx-st-head {
  margin: 0.4vh 0.8vh 0;
  color: #8a4b12;
  font-size: 0.85em;
  font-weight: 800;
}
.chx-emo-grid.chx-st-grid {
  grid-template-columns: repeat(6, minmax(0, 7.6vh));
}
.chx-emo-unlock {
  margin: 0;
  padding: 0.3vh 0.8vh 0.6vh;
  color: #8a4b12;
  font-size: 0.9em;
  font-weight: 700;
}

/* จอเตี้ย (มือถือแนวนอนเล็ก): โต๊ะเล่นเหลือที่น้อย ช่องแชทเตี้ยลง */
@media (max-height: 420px) {
  .chx[data-mode='table'] {
    --chx-h: 34vh; /* ขอบบนต้องอยู่ใต้ไพ่เกิดของคนฝั่งซ้าย (ก้นแถว ~62% ของความสูงจอ) */
    --chx-bottom: 1.5vh;
  }
}

/* หน้าต่างดูแชทย้อนหลังของแอดมิน (Admin/admin-chat.js) — อยู่ไฟล์นี้เพราะเป็นของระบบแชท */
.st-modal.ad-chat-modal .ad-chat-box {
  display: block;
  width: min(92vw, 720px);
  max-height: 86vh;
}
.ad-chat-list {
  max-height: 64vh;
  overflow-y: auto;
  text-align: left;
}
.ad-chat-row {
  padding: 0.6vh 0;
  border-bottom: 1px solid #0001;
  word-break: break-word;
}
.ad-chat-room {
  margin-left: 0.5em;
  padding: 0 0.6em !important;
  font-size: 0.9em !important;
}
