:root {
  color-scheme: light;
  /* โทนน้ำตาล-ทองของแบรนด์ P1 (ชุดเดียวกับ P1 Admin Helper) */
  --bg: #f7f4ed;
  --surface: #ffffff;
  --surface-2: #fbf8f1;
  --border: #e9e0cc;
  --text: #1a1a1a;
  --text-muted: #6f6450;
  --brand: #5c4326;
  --brand-strong: #4a3520;
  --brand-soft: #fff8e1;
  --brand-text: #ffffff;
  --accent: #d4a23a;
  --accent-strong: #b88828;
  --accent-ring: rgba(212, 162, 58, 0.22);
  --header-bg: linear-gradient(135deg, #5c4326 0%, #7a5a33 100%);
  --danger: #d92d20;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bubble-in: #ffffff;
  --bubble-out: #5c4326;
  --bubble-out-text: #ffffff;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.06);
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Thai", "Sarabun", "Helvetica Neue", Arial, sans-serif;
}

/* โหมดมืด (ค่าเริ่มต้น) — theme.js ตั้ง data-theme ที่ <html> ตามที่แต่ละคนเลือกไว้ */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101215;
  --surface: #181b1f;
  --surface-2: #1f2328;
  --border: #2b3036;
  --text: #e8eaed;
  --text-muted: #b3a88f;
  --brand: #d4a23a;
  --brand-strong: #e6be63;
  --brand-soft: #2c2314;
  --brand-text: #1a1206;
  --accent-ring: rgba(212, 162, 58, 0.3);
  --header-bg: linear-gradient(135deg, #3d2c18 0%, #5c4326 100%);
  --bubble-out: #7a5a33;
  --warn: #f0a640;
  --warn-soft: #3a2c08;
  --bubble-in: #23272c;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

/* .drawer ตั้ง display: flex ไว้ ซึ่งชนะ [hidden] ของเบราว์เซอร์ — บังคับให้ hidden ชนะเสมอ */
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

button, input, select, textarea { font: inherit; color: inherit; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--brand); }

/* ---------- generic controls ---------- */
.button {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  background: transparent;
  transition: background 120ms ease, border-color 120ms ease, opacity 120ms ease;
  white-space: nowrap;
}
.button:disabled { opacity: 0.55; cursor: not-allowed; }
.button--primary { background: var(--brand); color: var(--brand-text); font-weight: 600; }
.button--primary:hover:not(:disabled) { background: var(--brand-strong); }
.button--ghost { border-color: var(--border); background: var(--surface); }
.button--ghost:hover:not(:disabled) { background: var(--surface-2); }
.button--block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field__label { font-size: 13px; color: var(--text-muted); }
.field__input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  width: 100%;
}
.field__input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

.pill { border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 600; }
.pill--muted { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.pill--ok { background: var(--brand-soft); color: var(--brand-strong); box-shadow: inset 0 0 0 1px rgba(212, 162, 58, 0.45); }
.pill--warn { background: var(--warn-soft); color: var(--warn); }
.pill--down { background: #fee4e2; color: var(--danger); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login__card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--accent);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login__brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: 0.2px; }
.login__dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); display: inline-block; }
.login__title { margin: 14px 0 4px; font-size: 22px; }
.login__hint { margin: 0 0 20px; color: var(--text-muted); font-size: 14px; }
.login__error { color: var(--danger); font-size: 13px; margin: 0 0 12px; }

/* ---------- shell ---------- */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap;
  padding: 10px 18px;
  background: var(--header-bg);
  color: #ffffff;
  border-bottom: 3px solid var(--accent);
}
.topbar .app-version { color: rgba(255, 255, 255, 0.75); }
/* ป้ายสถานะไม่ตกบรรทัดกลางคำ — ที่ไม่พอให้ทั้งกลุ่มขึ้นแถวใหม่แทน */
.topbar .pill { white-space: nowrap; }
.topbar .button--ghost { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.28); color: #ffffff; }
.topbar .button--ghost:hover:not(:disabled) { background: rgba(255, 255, 255, 0.16); border-color: var(--accent); }
.topbar .pill--muted { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.25); color: #ffffff; }
.topbar .pill--button:hover { background: rgba(255, 255, 255, 0.2); }
.topbar .pill--ok { background: rgba(212, 162, 58, 0.22); color: #ffd58a; }
.topbar__brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.app-version { font-size: 11px; font-weight: 500; color: var(--text-muted); letter-spacing: 0; white-space: nowrap; }
.update-banner {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 10px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 14px;
  max-width: calc(100vw - 32px);
}
/* แท็บธุรกิจบนแถบน้ำตาล (GoldenCow / P1) — แท็บที่เปิดอยู่เป็นสีครีม */
.business-tabs { display: flex; gap: 6px; }
.business-tab {
  font: inherit; font-size: 15px; font-weight: 700; display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 18px; border-radius: 10px; cursor: pointer; color: #ffffff;
  background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.28);
}
.business-tab:hover { background: rgba(255, 255, 255, 0.18); }
.business-tab[aria-selected="true"] { background: #fff8e1; color: #4a3520; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(212, 162, 58, 0.35); }
.business-tab .badge { font-size: 11px; }
.business-tab--add { border-style: dashed; font-weight: 600; color: rgba(255, 255, 255, 0.85); background: transparent; }
.setup-steps { margin: 0 0 14px; padding-left: 22px; display: flex; flex-direction: column; gap: 12px; line-height: 1.6; }
.setup-steps__code { margin: 8px 0; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; white-space: pre-wrap; }
.setup-steps code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 0 5px; font-size: 13px; }
/* ปุ่มเลือกโหมดสี (สว่าง / มืด) บนแถบด้านบน */
.theme-switch { display: inline-flex; border: 1px solid rgba(255, 255, 255, 0.28); border-radius: 10px; overflow: hidden; }
.theme-switch__option { font: inherit; font-size: 13px; padding: 7px 10px; border: 0; background: rgba(255, 255, 255, 0.06); color: #ffffff; cursor: pointer; white-space: nowrap; }
.theme-switch__option:hover { background: rgba(255, 255, 255, 0.16); }
.theme-switch__option[aria-pressed="true"] { background: #fff8e1; color: #4a3520; font-weight: 700; }
.topbar__status { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.topbar__actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.topbar__agent { font: inherit; color: #ffd58a; font-size: 14px; background: none; border: 1px dashed transparent; border-radius: 8px; padding: 4px 8px; cursor: pointer; white-space: nowrap; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.topbar__agent:hover, .topbar__agent:focus-visible { border-color: rgba(255, 213, 138, 0.6); }
.topbar__agent::after { content: ' ✎'; opacity: 0.7; }

/* รายการห้องกว้างตามจอ (ชื่อลูกค้า + ป้ายช่องทาง/เพจไม่โดนตัด) แต่ไม่เบียดห้องแชท */
.layout { flex: 1; display: grid; grid-template-columns: clamp(300px, 28vw, 420px) minmax(0, 1fr) minmax(280px, 330px); min-height: 0; }

/* ---------- sidebar ---------- */
.sidebar {
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar__search { padding: 12px 12px 8px; }
.tabs { display: flex; gap: 6px; padding: 0 12px 10px; }
.tab {
  flex: 1; border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 8px; padding: 6px 8px; font-size: 13px; cursor: pointer;
}
.tab.is-active { background: var(--brand-soft); border-color: var(--accent); color: var(--brand-strong); font-weight: 600; }

.conversations { list-style: none; margin: 0; padding: 0 8px 16px; overflow-y: auto; flex: 1; }
.conversation {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 10px;
  align-items: center; padding: 10px; border-radius: var(--radius); cursor: pointer;
}
.conversation:hover { background: var(--surface-2); }
.conversation.is-active { background: var(--brand-soft); box-shadow: inset 3px 0 0 var(--accent); }
.conversation__main { min-width: 0; }
.conversation__name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation__preview { color: var(--text-muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation__meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.conversation__time { font-size: 11px; color: var(--text-muted); }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); }
.avatar--lg { width: 48px; height: 48px; }
.empty { color: var(--text-muted); text-align: center; padding: 24px 12px; font-size: 14px; }

/* ---------- thread ---------- */
.thread { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.thread__placeholder { margin: auto; text-align: center; color: var(--text-muted); padding: 24px; }
.thread__placeholder h2 { color: var(--text); font-size: 18px; margin-bottom: 6px; }
.thread__body { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.thread__header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.thread__identity { min-width: 0; }
.thread__title { margin: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread__subtitle { margin: 0; font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread__controls { margin-left: auto; display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; justify-content: flex-end; }
.thread__controls .pill { white-space: nowrap; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track {
  width: 40px; height: 22px; border-radius: 999px; background: var(--border);
  position: relative; transition: background 140ms ease; display: inline-block;
}
.switch__thumb {
  position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: transform 140ms ease; box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.switch input:checked + .switch__track { background: var(--brand); }
.switch input:checked + .switch__track .switch__thumb { transform: translateX(18px); }

.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 4px; }
/* margin-top keeps short threads anchored to the composer, like a chat app. */
#message-list { display: flex; flex-direction: column; gap: 10px; margin-top: auto; }

.day { align-self: center; font-size: 12px; color: var(--text-muted); background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 2px 12px; margin: 8px 0; }

.msg { display: flex; flex-direction: column; max-width: min(72%, 560px); gap: 4px; }
.msg--inbound { align-self: flex-start; }
.msg--outbound { align-self: flex-end; align-items: flex-end; }
.msg--system { align-self: center; max-width: 80%; }
.msg__bubble {
  background: var(--bubble-in); border: 1px solid var(--border);
  border-radius: 16px; padding: 9px 13px; white-space: pre-wrap; word-break: break-word;
  box-shadow: var(--shadow);
}
.msg--outbound .msg__bubble { background: var(--bubble-out); color: var(--bubble-out-text); border-color: transparent; }
.msg--bot .msg__bubble { background: var(--surface-2); color: var(--text); border: 1px dashed var(--border); }
.msg--system .msg__bubble {
  background: transparent; border: none; box-shadow: none; color: var(--text-muted);
  font-size: 13px; text-align: center; padding: 2px 0;
}
.msg__meta { font-size: 11px; color: var(--text-muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.msg__author { padding: 1px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); border: 1px solid var(--accent); font-weight: 600; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg__image { max-width: 260px; border-radius: 12px; display: block; }
.msg__image-link { cursor: zoom-in; display: block; }

/* ── ตัวดูรูป (กดรูปในแชท) ── */
.lightbox {
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: #fff;
  overflow: hidden;
}
.lightbox[open] { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; }
.lightbox::backdrop { background: rgba(8, 10, 12, 0.88); }
.lightbox__img { max-width: calc(100vw - 140px); max-height: calc(100vh - 110px); object-fit: contain; border-radius: 8px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5); }
.lightbox__bar { display: flex; align-items: center; gap: 10px; }
.lightbox__count { font-size: 13px; opacity: 0.8; min-width: 3em; text-align: center; }
.lightbox__button {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border-radius: 999px;
  padding: 6px 14px;
  font: inherit;
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
}
.lightbox__button:hover { background: rgba(255, 255, 255, 0.18); }
.lightbox__nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}
.lightbox__nav:hover { background: rgba(255, 255, 255, 0.26); }
.lightbox__nav--prev { left: 16px; }
.lightbox__nav--next { right: 16px; }
@media (max-width: 600px) {
  .lightbox__img { max-width: 94vw; }
  .lightbox__nav--prev { left: 6px; }
  .lightbox__nav--next { right: 6px; }
}
.msg__file { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: inherit; }
.msg__status--failed { color: var(--danger); font-weight: 600; }
.msg__status--pending { opacity: 0.7; }

.composer { position: relative; display: flex; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface); align-items: flex-end; }
.composer__input { flex: 1; resize: none; max-height: 160px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; outline: none; }
.composer__input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.thread__body.is-dropping { outline: 3px dashed var(--accent); outline-offset: -8px; background: var(--brand-soft); }
.composer__error { color: var(--danger); font-size: 13px; padding: 0 18px 10px; margin: 0; }

/* ---------- modal ---------- */
.modal { width: min(680px, 94vw); border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); padding: 20px; box-shadow: var(--shadow); }
.modal--narrow { width: min(420px, 94vw); }
.modal--narrow .rule-form { border-top: 0; padding-top: 0; }
.modal--narrow h2 { margin: 0 0 8px; }
.who-names { display: flex; flex-direction: column; gap: 10px; max-height: 40vh; overflow-y: auto; margin-bottom: 12px; }
.who-names__title { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.who-names__chips { display: flex; flex-wrap: wrap; gap: 6px; }
.who-chip { font: inherit; display: inline-flex; flex-direction: column; align-items: flex-start; gap: 0; padding: 6px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; text-align: left; }
.who-chip small { font-size: 11px; color: var(--text-muted); }
.who-chip:hover { border-color: var(--accent); }
.who-chip[aria-pressed="true"] { background: var(--brand); color: var(--brand-text); border-color: var(--brand); }
.who-chip[aria-pressed="true"] small { color: inherit; opacity: 0.8; }
.who-chip[hidden], .who-names__group[hidden] { display: none; }
.modal::backdrop { background: rgba(12, 16, 20, 0.45); }
.modal__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal__head h2 { margin: 0; font-size: 18px; }
.modal__hint { color: var(--text-muted); font-size: 13px; }
.rules { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; max-height: 40vh; overflow-y: auto; }
.rule { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; background: var(--surface-2); display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start; }
.rule__title { font-weight: 600; }
.rule__meta { font-size: 12px; color: var(--text-muted); }
.rule__reply { font-size: 13px; margin-top: 4px; white-space: pre-wrap; }
.rule__actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
.rule__account { font: inherit; font-size: 12px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); max-width: 140px; }
.rule-form { border-top: 1px solid var(--border); padding-top: 14px; }
.rule-form h3 { margin: 0 0 12px; font-size: 15px; }
.rule-form__grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 12px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #1c2024; color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 14px; box-shadow: var(--shadow); z-index: 40;
}

@media (max-width: 1200px) {
  .layout { grid-template-columns: clamp(300px, 34vw, 400px) minmax(0, 1fr); }
  .assist { display: none; }
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .app.is-thread-open .sidebar { display: none; }
  .app:not(.is-thread-open) .sidebar { display: flex; }
  .app:not(.is-thread-open) .thread { display: none; }
  .topbar__actions .button--ghost { padding: 8px 10px; }
  /* จอแคบ: ปุ่มขึ้นแถวใหม่แทนการล้นออกข้าง และวันที่อัปเดตอยู่ใต้ชื่อ */
  .topbar { flex-wrap: wrap; gap: 8px 12px; }
  .topbar__brand { flex-wrap: wrap; row-gap: 0; }
  .topbar__brand .app-version { flex-basis: 100%; padding-left: 18px; }
  .topbar__actions { flex-wrap: wrap; justify-content: flex-end; }
  /* จอแคบ: แท็บธุรกิจเต็มแถวของตัวเอง กดง่าย */
  .business-tabs { flex-basis: 100%; }
  .business-tab { flex: 1; justify-content: center; }
}

/* ═══════════════ ส่วนช่วยงานแอดมิน (P1 Admin Helper) ═══════════════ */

.pill--button { border: 1px solid var(--border); cursor: pointer; font: inherit; font-size: 12px; font-weight: 600; }
.pill--button:hover { background: var(--surface-2); }
.pill--stage { background: var(--brand-soft); color: var(--brand-strong); }
.button--sm { padding: 4px 10px; font-size: 13px; }

.sidebar__filter {
  display: flex; align-items: center; gap: 8px;
  padding: 0 16px 10px; font-size: 13px; color: var(--text-muted); cursor: pointer;
}

/* ระดับความเร่งด่วนของห้องค้างตอบ — ไล่สีจากขาว → ส้ม → แดง */
.conversation { border-left: 3px solid transparent; }
.conversation--watch { border-left-color: #cbd5e1; }
.conversation--warning { border-left-color: #f59e0b; background: rgba(245, 158, 11, 0.07); }
.conversation--critical { border-left-color: var(--danger); background: rgba(217, 45, 32, 0.08); }
.conversation__wait { font-size: 11px; font-weight: 700; }
.conversation__wait--warning { color: var(--warn); }
.conversation__wait--critical { color: var(--danger); }
.conversation__stage { font-size: 11px; color: var(--text-muted); }

.assist {
  border-left: 1px solid var(--border); background: var(--surface);
  display: flex; flex-direction: column; min-height: 0;
}
.assist__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.assist__head h3 { margin: 0; font-size: 15px; }
.assist__body { overflow-y: auto; padding: 14px 16px 24px; display: flex; flex-direction: column; gap: 14px; }

.card { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; background: var(--surface-2); }
.card__title { font-size: 13px; font-weight: 700; margin: 0 0 8px; display: flex; align-items: center; gap: 6px; }
.card--critical { border-color: var(--danger); background: rgba(217, 45, 32, 0.07); }
.card--high { border-color: var(--warn); background: rgba(245, 158, 11, 0.08); }
.card--medium { border-color: var(--border); }
.card--low { opacity: 0.85; }

.stage-track { display: flex; gap: 4px; margin-bottom: 8px; }
.stage-dot {
  flex: 1; height: 6px; border-radius: 99px; background: var(--border);
}
.stage-dot--passed { background: var(--accent); }
.stage-dot--current { background: var(--brand-strong); box-shadow: 0 0 0 2px var(--brand-soft); }
.stage-meta { font-size: 12px; color: var(--text-muted); }

.script {
  display: block; width: 100%; text-align: left; margin-top: 6px;
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  padding: 8px 10px; font-size: 13px; cursor: pointer; white-space: pre-wrap;
}
.script:hover { border-color: var(--accent); background: var(--brand-soft); }

.warn-item { font-size: 13px; margin: 0 0 6px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border-radius: 999px; padding: 3px 10px; font-size: 12px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
}
.chip--on { color: #fff; border-color: transparent; }

.style-warnings {
  border-top: 1px solid var(--border); background: rgba(245, 158, 11, 0.1);
  padding: 8px 18px; font-size: 13px; display: flex; flex-direction: column; gap: 4px;
}
.style-warnings--critical { background: rgba(217, 45, 32, 0.12); }

.composer__tool { padding: 8px 12px; font-size: 18px; line-height: 1; }

/* ── แผงข้อมูลลูกค้า ── */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(12, 16, 20, 0.45); z-index: 30; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 92vw); z-index: 31;
  background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.drawer__head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.drawer__head h2 { margin: 0; font-size: 17px; }
.drawer__body { overflow-y: auto; padding: 16px 18px 28px; display: flex; flex-direction: column; gap: 16px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: 13px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; word-break: break-word; }

/* ── ตัวเลือกข้อความสำเร็จรูป ── */
.picker { display: flex; flex-direction: column; gap: 6px; max-height: 55vh; overflow-y: auto; margin-top: 12px; }
.picker__item {
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px;
  background: var(--surface-2); cursor: pointer; text-align: left;
}
.picker__item:hover { border-color: var(--accent); background: var(--brand-soft); }
.picker__name { font-weight: 600; font-size: 13px; }
.picker__content { font-size: 12px; color: var(--text-muted); white-space: pre-wrap; margin-top: 2px; max-height: 3.4em; overflow: hidden; }

/* ── ใบเสนอราคา ── */
.modal--wide { width: min(860px, 96vw); }
.checkbox { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; margin-right: 16px; }
.quote-flags { display: flex; flex-wrap: wrap; gap: 8px 0; margin-bottom: 12px; }
.quote-items { border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-bottom: 14px; }
.quote-items__head { display: flex; align-items: center; justify-content: space-between; font-weight: 600; font-size: 14px; margin-bottom: 10px; }
.quote-row { display: grid; grid-template-columns: 1fr 64px 112px 92px 84px 36px; gap: 6px 8px; margin-bottom: 8px; align-items: center; }
.quote-row input { width: 100%; }
.quote-row--labels { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.quote-row__hint { grid-column: 1 / -1; font-size: 12px; color: var(--text-muted); margin-top: -2px; }
.quote-row__hint:empty { display: none; }
.quote-row__hint.is-warning { color: var(--warn); }
.quote-bundle-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: -4px 0 12px; }
.quote-submit { display: flex; flex-wrap: wrap; gap: 8px; }
.quote-confirm { border: 1px solid var(--accent); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; background: var(--brand-soft); }
.quote-confirm h3 { margin: 0 0 8px; font-size: 15px; }
.quote-confirm__warnings { margin: 0 0 10px; padding-left: 18px; color: var(--warn); font-size: 13px; font-weight: 600; }
.quote-confirm__lines { margin: 0 0 10px; font: inherit; font-size: 13px; white-space: pre-wrap; }
.quote-confirm__totals { display: grid; grid-template-columns: auto auto; justify-content: start; gap: 2px 18px; margin: 0; font-size: 13px; }
.quote-confirm__totals dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.quote-confirm__totals .is-total { font-weight: 700; font-size: 15px; padding-top: 4px; }
.quote-result { border: 1px solid var(--accent); background: var(--brand-soft); border-radius: 12px; padding: 12px; margin-top: 14px; font-size: 14px; }
.quote-result p { margin: 0 0 8px; font-weight: 600; }
.doc-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.doc-actions a { text-decoration: none; color: inherit; }
.doc-actions:empty { display: none; }
.slip-stage { margin-top: 6px; }
.slip-stage__list { margin-top: 6px; display: grid; gap: 4px; }
.slip-stage__item { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 8px; }
.slip-stage__item span { overflow-wrap: anywhere; }
.result-card__ok { color: var(--brand-strong); font-weight: 600; font-size: 13px; }
.result-card .doc-actions a { display: inline-flex; margin-top: 0; word-break: normal; }
.quote-history { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 4px; }
.modal__section { border-top: 1px solid var(--border); margin-top: 18px; padding-top: 14px; }
.modal__section h3 { margin: 0 0 4px; font-size: 15px; }

@media (max-width: 720px) {
  .quote-row { grid-template-columns: 1fr 1fr; }
  .quote-row > input:first-child { grid-column: 1 / -1; }
  .quote-row--labels { display: none; }
}

/* ── P1Care / ตัวอย่างเอกสาร ── */
.doc-preview { width: 100%; height: 65vh; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.form-section { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; }
.form-section > h3 { margin: 0 0 10px; font-size: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 12px; }
.form-grid--wide { grid-template-columns: 1fr; }
.symptom-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.result-card {
  border: 1px solid var(--brand); background: var(--brand-soft);
  border-radius: 12px; padding: 12px; margin-top: 12px; font-size: 14px;
}
.result-card a { display: block; margin-top: 4px; word-break: break-all; }
.result-card__actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.job-row {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  background: var(--surface-2); margin-bottom: 8px;
}
.job-row__title { font-weight: 600; font-size: 13px; }
.job-row__meta { font-size: 12px; color: var(--text-muted); }
.job-row__status { font-size: 12px; font-weight: 600; }
.late-tax { display: grid; grid-template-columns: 2fr 1fr; gap: 0 8px; margin: 6px 0; }
.late-tax .field__hint { grid-column: 1 / -1; margin: 0 0 4px; font-size: 12px; color: var(--danger, #b91c1c); }
@media (max-width: 520px) { .late-tax { grid-template-columns: 1fr; } }
.doc-summary { margin: 4px 0; font-size: 13px; }

/* ── รายงานประจำวัน ── */
.report-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 8px; }
.field--inline { margin-bottom: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat {
  border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; background: var(--surface-2);
}
.stat__label { font-size: 12px; color: var(--text-muted); }
.stat__value { font-size: 20px; font-weight: 700; margin-top: 2px; }
.stat__hint { font-size: 11px; color: var(--text-muted); }
.stat--alert { border-color: var(--danger); background: rgba(217, 45, 32, 0.08); }
.report-section { margin-bottom: 18px; }
.report-section > h3 { margin: 0 0 8px; font-size: 15px; }
.report-row { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: var(--surface); }
.report-row__title { font-weight: 600; font-size: 14px; }
.report-row__meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.report-row__line { font-size: 13px; margin-top: 4px; }
.report-row__warn { font-size: 12px; color: var(--warn); margin-top: 3px; }

/* ── ช่องทาง (LINE / Messenger / คอมเมนต์เพจ) ── */
.channel-badge {
  display: inline-block;
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 700;
  vertical-align: 1px;
  color: #fff;
}
.channel-badge--line { background: #06c755; }
.channel-badge--messenger { background: #0084ff; }
.channel-badge--fb_comment { background: #1877f2; }
.account-badge {
  display: inline-block;
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 700;
  vertical-align: 1px;
  color: #fff;
  max-width: 9em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.channel-filter { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 8px; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
}
.chip.is-active { background: var(--brand-soft); color: var(--text); border-color: var(--accent); font-weight: 600; }
.line-import { margin-top: 8px; font-size: 13px; }
.line-import__summary { font-weight: 600; margin: 0 0 6px; }
.line-import__sample { margin: 6px 0; padding-left: 18px; color: var(--text-muted); }
.line-import__table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.line-import__table th, .line-import__table td { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.line-import__table th { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.line-import__warn { color: #b45309; margin: 4px 0; }
.shared-emails { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.shared-email { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) auto; gap: 8px; align-items: center; }
.shared-email [data-role="match"] { grid-column: 1 / -1; margin: 0 0 6px; }
.shared-email [data-role="match"].is-warning { color: var(--warn); }
@media (max-width: 560px) {
  .shared-email { grid-template-columns: minmax(0, 1fr) auto; }
  .shared-email [data-role="positions"] { grid-column: 1 / -1; grid-row: 2; }
}
.conversation__replied { display: inline-flex; flex-direction: column; align-items: center; max-width: 76px; padding: 3px 8px; border-radius: 10px; line-height: 1.25; font-size: 11px; }
.conversation__replied-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.settings-warning { margin: 0 0 12px; padding: 8px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 13px; }
.checkbox-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.setup-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.setup-checks { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.setup-check { display: grid; grid-template-columns: 22px 1fr; gap: 6px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); font-size: 13px; }
.setup-check__icon { font-weight: 700; text-align: center; }
.setup-check__title { font-weight: 600; }
.setup-check__detail { color: var(--text-muted); margin-top: 2px; word-break: break-word; }
.setup-check--ok .setup-check__icon { color: #16a34a; }
.setup-check--warn .setup-check__icon { color: #d97706; }
.setup-check--fail { border-color: rgba(220, 38, 38, 0.45); }
.setup-check--fail .setup-check__icon { color: #dc2626; }
.line-setup { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.line-setup__account { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.line-setup__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.thread__post { margin: 2px 0 0; font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread__post a { color: #1877f2; }
.composer__hint { font-size: 12px; color: var(--text-muted); padding: 6px 18px 0; margin: 0; }
.composer__hint--warn { color: var(--warn); }
.conversation__assignee { font-size: 11px; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation__assignee--me { color: var(--brand-strong); font-weight: 600; }
.msg__jump { margin-top: 6px; padding: 2px 10px; font-size: 12px; }

/* ── ปุ่มเข้าสู่ระบบด้วย Google ── */
.button--google {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  font-weight: 600; text-decoration: none; margin-bottom: 12px;
}
.button--google:hover { background: var(--surface-2); }
.button__icon {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: #4285f4; color: #fff; font-size: 13px; font-weight: 700;
}

/* ── คีย์ลัดข้อความสำเร็จรูป (/คีย์ ในช่องพิมพ์) ── */
.shortcut-popup { position: absolute; left: 12px; right: 12px; bottom: calc(100% + 6px); max-height: 320px; overflow-y: auto; background: var(--surface); border: 1px solid var(--accent); border-radius: 12px; box-shadow: var(--shadow); z-index: 30; padding: 4px; }
.shortcut-item { padding: 7px 10px; border-radius: 8px; cursor: pointer; }
.shortcut-item.is-active, .shortcut-item:hover { background: var(--brand-soft); }
.shortcut-item__head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.shortcut-item__name { font-weight: 600; font-size: 14px; }
.shortcut-item__meta { font-size: 12px; color: var(--text-muted); }
.shortcut-item__content { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.shortcut-item--more { font-size: 13px; color: var(--brand-strong); border-top: 1px solid var(--border); border-radius: 0 0 8px 8px; }
.shortcut-key { display: inline-block; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: var(--brand-soft); color: var(--brand-strong); border: 1px solid var(--accent); }
.composer-attachments { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 18px 0; font-size: 13px; color: var(--text-muted); }
.composer-attachments img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.category-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.template-thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.template-thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.template-images { margin: 6px 0 12px; display: grid; gap: 6px; }
.template-image { display: grid; gap: 4px; justify-items: center; }
.rule--editing { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-ring); }

/* ── แถบแท็กลูกค้าใต้หัวห้อง ── */
.tag-strip { position: relative; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 6px 18px; border-bottom: 1px solid var(--border); background: var(--surface); font-size: 13px; }
.tag-strip__label { font-size: 14px; }
.tag-strip__empty { color: var(--text-muted); font-size: 12px; }
.tag-strip__add { width: 26px; height: 26px; border-radius: 50%; border: 1px dashed var(--accent); background: transparent; color: var(--brand-strong); font-size: 16px; line-height: 1; cursor: pointer; }
.tag-pill { --tag: #b89b3f; display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--tag); background: color-mix(in srgb, var(--tag) 12%, transparent); border: 1px solid color-mix(in srgb, var(--tag) 35%, transparent); }
.tag-pill__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--tag); }
.tag-pill__remove { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 14px; line-height: 1; padding: 0 0 0 2px; }
.tag-pill--choice { cursor: pointer; }
.tag-pill--choice:hover { background: color-mix(in srgb, var(--tag) 24%, transparent); }
.tag-picker { position: absolute; top: calc(100% + 4px); left: 18px; z-index: 40; width: min(320px, calc(100vw - 36px)); background: var(--surface); border: 1px solid var(--accent); border-radius: 12px; box-shadow: var(--shadow); padding: 10px; display: grid; gap: 10px; }
.tag-picker__choices { display: flex; flex-wrap: wrap; gap: 6px; max-height: 180px; overflow-y: auto; }
.tag-picker__form { display: flex; gap: 6px; }
.tag-picker__form .field__input { flex: 1; }

/* ── งานติดตาม: กลุ่มตามความเร่งด่วน · ห้องที่ควรตาม · ห้ามติดตาม ── */
.followup-options { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin: 8px 0; font-size: 13px; }
.followup-options label { display: inline-flex; align-items: center; gap: 6px; }
.followup-group { margin: 14px 0 6px; font-size: 14px; }
.followup-card { border-left: 4px solid var(--border); }
.followup-card--emergency { border-left-color: var(--danger); }
.followup-card--high { border-left-color: #e8590c; }
.followup-card--medium { border-left-color: var(--warn); }
.followup-card--low { border-left-color: #2f9e44; }
.followup-card__main { display: grid; gap: 4px; min-width: 0; }
.followup-reason { font-size: 13px; font-weight: 600; color: var(--brand-strong); }
.followup-snooze { font-size: 12px; color: var(--text-muted); background: var(--surface-2); border-radius: 8px; padding: 4px 8px; margin-top: 4px; }
.followup-picker { margin-top: 6px; font-size: 13px; }
.followup-text { font-size: 13px; resize: vertical; }
.followup-room-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
@media (max-width: 720px) {
  .followup-card { grid-template-columns: 1fr; }
  .followup-card .rule__actions { justify-content: flex-start; }
  .followup-options { gap: 6px 12px; }
}

/* ── ร่างข้อความด้วย AI ── */
.composer__hint--ai { margin: 6px 18px 0; padding: 6px 10px; border-radius: 8px; background: var(--brand-soft); color: var(--brand-strong); font-size: 12px; }
#ai-draft:disabled { opacity: 0.7; cursor: progress; }
.report-bar--export { margin-top: 6px; gap: 8px; align-items: center; }
.report-score { font-weight: 600; color: var(--brand-strong); margin-top: 4px; font-size: 13px; }

/* ── ลิงก์นโยบายใต้ฟอร์มเข้าสู่ระบบ · ปุ่มลบข้อมูลลูกค้า ── */
.login__legal { margin: 16px 0 0; text-align: center; font-size: 12px; color: var(--text-muted); }
.login__legal a { color: var(--text-muted); }
.button--danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.button--danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }

/* ── ธุรกิจที่มีหลายเพจ: บอกเพจของห้อง + ตัวกรองตามเพจ ── */
/* ป้ายเพจ (P1 / RS / RY) ต่อจากป้ายช่องทาง — ไม่ตั้งป้ายใช้ชื่อเพจ ตัดให้สั้น */
.page-tag {
  display: inline-block;
  max-width: 9em;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--brand-strong);
  color: var(--brand-strong);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.5;
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.page-tags { margin-top: 12px; }
.page-tags__list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; margin: 6px 0; }
