:root {
  /* ธีมขาว - ทอง - ดำ */
  --ink: #14130F;
  --ink-soft: #2B2924;
  --ink-mute: #7A736A;
  --leaf: #C9A227;        /* ทอง */
  --leaf-dark: #A8871A;
  --deep: #1A1814;        /* ดำ */
  --paper: #F6F4EF;
  --line: #E2DCD0;
  --gold-line: #E3C766;
}

* { box-sizing: border-box; }

/* กันหน้าจอกระตุกตอนสลับเมนู: มีแถบเลื่อนค้างไว้เสมอ ความกว้างจึงคงที่ */
html {
  scrollbar-gutter: stable;
  overflow-y: scroll;
}

/* แถบเมนูด้านซ้าย - เขียวพาสเทล */
.sidebar {
  background: linear-gradient(170deg, #E8FAEE 0%, #CFEEDB 55%, #BFE6CF 100%);
  border-right: 1px solid #AEDCC0;
  color: #1E3A2B;
  /* เคลื่อนไหวเฉพาะการเลื่อนเข้าออกบนมือถือ ไม่ขยับความกว้างเวลาสลับเมนู */
  transition: transform .25s ease;
}
.sidebar select option { color: #1E3A2B; }

/* พื้นที่เนื้อหาสูงคงที่ ไม่ยุบตามความยาวของแต่ละหน้า */
.main-area {
  min-height: 100vh;
  min-height: 100dvh;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans Thai", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.app-loading {
  display: grid;
  place-items: center;
  min-height: 100vh;
  color: var(--ink-mute);
  letter-spacing: .01em;
}

/* ---------- หน้าเข้าสู่ระบบ ---------- */
.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 12% -10%, rgba(201,162,39,.22), transparent 60%),
    linear-gradient(160deg, #1F1B14 0%, #0E0D0A 70%);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 20px;
  padding: 36px 32px 28px;
  box-shadow: 0 24px 60px -24px rgba(3, 30, 22, .55);
}

.auth-brand { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 26px; }
.auth-brand h1 { margin: 0 0 4px; font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
.auth-brand p { margin: 0; font-size: 14px; line-height: 1.55; color: var(--ink-mute); }

.brand-logo {
  width: 56px; height: 56px; flex: 0 0 56px;
  filter: drop-shadow(0 4px 10px rgba(20,19,15,.22));
}

.logo-dot {
  width: 38px; height: 38px; flex: 0 0 38px; margin-top: 2px;
  border-radius: 13px 13px 13px 4px;
  background: linear-gradient(140deg, #E3C766 0%, #C9A227 55%, #9A7A15 100%);
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.18);
}

.auth-form { display: grid; gap: 16px; }
.auth-form label { display: grid; gap: 6px; font-size: 14px; font-weight: 500; }
.auth-form input {
  width: 100%; padding: 11px 13px; font-size: 15px; font-family: inherit;
  border: 1px solid var(--line); border-radius: 11px; background: #FAFBFA;
}
.auth-form input:focus { outline: 2px solid var(--gold-line); outline-offset: 1px; border-color: transparent; }
.auth-form button {
  margin-top: 4px; padding: 12px; font-size: 15px; font-weight: 700; font-family: inherit;
  color: #221B05; background: linear-gradient(160deg,#E3C766,#C9A227); border: 0; border-radius: 11px; cursor: pointer;
}
.auth-form button:hover { filter: brightness(1.04); }

.auth-error {
  margin-bottom: 18px; padding: 11px 14px; border-radius: 11px;
  background: #FDECEC; color: #A32020; font-size: 14px;
}
.auth-foot { margin: 22px 0 0; text-align: center; font-size: 12px; color: #9AA8A1; }

/* ---------- โครงห้องแชท ---------- */
.chat-shell {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
  height: calc(100dvh - 150px);
  min-height: 420px;
}
.chat-pane {
  flex-direction: column;
  min-height: 0;
  background: #fff;
  border: 1px solid #E4EAE6;
  border-radius: 18px;
  overflow: hidden;
}
/* แท็บเล็ตขึ้นไป: รายการ + บทสนทนา (พับได้ทั้งซ้ายและขวา) */
@media (min-width: 1024px) {
  .chat-shell { grid-template-columns: 320px minmax(0, 1fr); }
  .chat-shell.with-info { grid-template-columns: 320px minmax(0, 1fr) 300px; }
  .chat-shell.no-list { grid-template-columns: minmax(0, 1fr); }
  .chat-shell.no-list.with-info { grid-template-columns: minmax(0, 1fr) 300px; }
}
@media (min-width: 1280px) {
  .chat-shell { grid-template-columns: 340px minmax(0, 1fr); }
  .chat-shell.with-info { grid-template-columns: 340px minmax(0, 1fr) 320px; }
}
/* มือถือ: เต็มจอ ไม่มีระยะขอบซ้ายขวา */
@media (max-width: 1023px) {
  .chat-shell {
    height: calc(100dvh - 118px);
    margin: 0 -16px;
    gap: 0;
  }
  .chat-pane { border-radius: 0; border-left: 0; border-right: 0; }
  .chat-composer { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  /* แผงข้อมูลลูกค้าบนมือถือแสดงทับเต็มจอ */
  .chat-info {
    position: fixed;
    inset: 0;
    z-index: 45;
    border-radius: 0;
  }
  .chat-shell.no-list { grid-template-columns: 1fr; }
}
/* iPad แนวตั้ง: ให้รายการแคบลงเล็กน้อย */
@media (min-width: 768px) and (max-width: 1023px) {
  .chat-shell { grid-template-columns: 1fr; }
}

/* ---------- แชท ---------- */
.bubble { max-width: min(68ch, 100%); padding: 9px 13px; border-radius: 16px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; font-size: 15px; }
.bubble-in  { background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.bubble-out { background: linear-gradient(160deg,#D8B23C,#C9A227); color: #221B05; border-bottom-right-radius: 5px; }
.bubble-bot { background: #FAF2DC; color: #4A3A08; border: 1px solid #EEDFAE; border-bottom-right-radius: 5px; }
.bubble-sys { background: transparent; border: 1px dashed var(--line); color: var(--ink-mute); font-size: 12.5px; max-width: 100%; text-align: center; }

.thread { background-image: radial-gradient(rgba(26,24,20,.06) 1px, transparent 1px); background-size: 18px 18px; }
.thread::-webkit-scrollbar, .scroll-y::-webkit-scrollbar { width: 8px; }
.thread::-webkit-scrollbar-thumb, .scroll-y::-webkit-scrollbar-thumb { background: #D9D2C4; border-radius: 8px; }

.avatar { border-radius: 14px; object-fit: cover; background: linear-gradient(150deg,#2B2924,#14130F); color: var(--gold-line); display: grid; place-items: center; font-weight: 600; }
.pin-strip { background: linear-gradient(90deg, rgba(201,162,39,.16), transparent); }
/* แถบชิปเหนือช่องพิมพ์: เลื่อนได้และเห็นแถบเลื่อนบาง ๆ เมื่อมีรายการเยอะ */
.chip-row {
  scrollbar-width: thin;
  scrollbar-color: #E3C766 transparent;
  overscroll-behavior-x: contain;
}
.chip-row::-webkit-scrollbar { height: 6px; }
.chip-row::-webkit-scrollbar-track { background: #F4F1EA; border-radius: 6px; }
.chip-row::-webkit-scrollbar-thumb { background: #E3C766; border-radius: 6px; }
.chip-row::-webkit-scrollbar-thumb:hover { background: #C9A227; }

/* แถวปุ่มจัดการห้องแชท เลื่อนได้แต่ซ่อนแถบเลื่อนไว้ */
.chip-row-plain { scrollbar-width: none; }
.chip-row-plain::-webkit-scrollbar { display: none; }
.thread { scroll-behavior: smooth; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
textarea { font-size: 16px; } /* กัน iOS ซูมอัตโนมัติตอนพิมพ์ */
@media (min-width: 1024px) { textarea { font-size: 15px; } }

/* ---------- ทั่วไป ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  padding: 11px 18px; border-radius: 12px; color: #fff; background: var(--ink);
  font-size: 14px; z-index: 60; box-shadow: 0 12px 30px -12px rgba(0,0,0,.5);
}
.toast-error { background: #A32020; }

textarea, input, select, button { font-family: inherit; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
