:root {
  --ink: #12211C;
  --ink-soft: #2C3D36;
  --ink-mute: #64796F;
  --leaf: #06C755;
  --leaf-dark: #04A445;
  --deep: #0B4A3C;
  --paper: #F1F4F2;
  --line: #DCE4DF;
}

* { box-sizing: border-box; }

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(6,199,85,.16), transparent 60%),
    linear-gradient(160deg, #0B4A3C 0%, #12211C 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); }

.logo-dot {
  width: 38px; height: 38px; flex: 0 0 38px; margin-top: 2px;
  border-radius: 13px 13px 13px 4px;
  background: var(--leaf);
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.12);
}

.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(--leaf); outline-offset: 1px; border-color: transparent; }
.auth-form button {
  margin-top: 4px; padding: 12px; font-size: 15px; font-weight: 600; font-family: inherit;
  color: #fff; background: var(--deep); border: 0; border-radius: 11px; cursor: pointer;
}
.auth-form button:hover { background: #0a3d32; }

.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); }
}
/* จอกว้าง: เพิ่มแผงข้อมูลลูกค้า */
@media (min-width: 1280px) {
  .chat-shell { grid-template-columns: 330px minmax(0, 1fr) 300px; }
}
/* มือถือ: เต็มจอ ไม่มีระยะขอบซ้ายขวา */
@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;
  }
}
/* 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: var(--leaf); color: #05240F; border-bottom-right-radius: 5px; }
.bubble-bot { background: #E7F8ED; color: #0B3B22; 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(11,74,60,.07) 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: #C9D5CE; border-radius: 8px; }

.avatar { border-radius: 14px; object-fit: cover; background: var(--deep); color: #fff; display: grid; place-items: center; font-weight: 600; }
.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; }
}
