/* ChatHub — โครงหน้าและโทเค็นสี (mobile-first)
   สีหลักเขียวอมฟ้า ให้ต่างจาก hrhub (ฟ้า) และ conshubv2 (ส้ม) */
:root {
  --brand: #0d9488;
  --brand-d: #0f766e;
  --brand-l: #ccfbf1;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f1f5f9;
  --card: #ffffff;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --top-h: 52px;
  --bottom-h: 58px;
  --side-w: 208px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body { height: 100%; }
body.cx-body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Noto Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* ---------- แถบบน ---------- */
.cx-top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1030;
  height: calc(var(--top-h) + var(--safe-top)); padding-top: var(--safe-top);
  display: flex; align-items: center; gap: 12px; padding-inline: 14px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.cx-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--brand-d); text-decoration: none; }
.cx-brand img { border-radius: 8px; }
.cx-company { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.cx-top-right { margin-left: auto; }
.cx-userbtn { color: var(--ink); }

/* ---------- เมนูข้าง (เดสก์ท็อป) / เมนูล่าง (มือถือ) ---------- */
.cx-side { display: none; }
.cx-bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
  height: calc(var(--bottom-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none;       /* เมนูเยอะ → เลื่อนแนวนอนได้แทนที่จะบีบจนอ่านไม่ออก */
}
.cx-bottom::-webkit-scrollbar { display: none; }
.cx-bottom-item {
  flex: 1 0 auto; min-width: 62px; padding: 0 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  color: var(--muted); text-decoration: none; font-size: .7rem;
  white-space: nowrap;                            /* ชื่อเมนูบรรทัดเดียวเสมอ — ที่ไม่พอให้เมนูขยายตามความยาวชื่อแล้วเลื่อนแนวนอนแทน */
}
.cx-bottom-item i { font-size: 1.25rem; line-height: 1; }
.cx-bottom-item.active { color: var(--brand); font-weight: 600; }

/* ---------- เนื้อหา ---------- */
.cx-main {
  padding: calc(var(--top-h) + var(--safe-top) + 14px) 14px calc(var(--bottom-h) + var(--safe-bottom) + 14px);
  max-width: 1100px; margin: 0 auto;
}
body.cx-full .cx-main { padding: 0; max-width: none; margin: 0; }
body.cx-full .cx-main > .cx-pane { height: calc(100dvh - var(--top-h) - var(--safe-top) - var(--bottom-h) - var(--safe-bottom)); margin-top: calc(var(--top-h) + var(--safe-top)); }

@media (min-width: 992px) {
  .cx-bottom { display: none; }
  .cx-side {
    display: flex; flex-direction: column; gap: 2px;
    position: fixed; top: calc(var(--top-h) + var(--safe-top)); bottom: 0; left: 0; width: var(--side-w);
    padding: 12px 10px; background: var(--card); border-right: 1px solid var(--line); z-index: 1020;
  }
  .cx-side-item {
    display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px;
    color: var(--ink); text-decoration: none; font-size: .95rem; white-space: nowrap;
  }
  .cx-side-item i { font-size: 1.1rem; color: var(--muted); }
  .cx-side-item:hover { background: var(--bg); }
  .cx-side-item.active { background: var(--brand-l); color: var(--brand-d); font-weight: 600; }
  .cx-side-item.active i { color: var(--brand); }
  .cx-main { margin-left: var(--side-w); max-width: none; padding: calc(var(--top-h) + var(--safe-top) + 18px) 24px 24px; }
  body.cx-full .cx-main { margin-left: var(--side-w); padding: 0; }
  body.cx-full .cx-main > .cx-pane { height: calc(100dvh - var(--top-h) - var(--safe-top)); }
}

/* ---------- องค์ประกอบทั่วไป ---------- */
.cx-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.cx-card + .cx-card { margin-top: 12px; }
.cx-h1 { font-size: 1.25rem; font-weight: 700; margin: 0 0 12px; }
.cx-empty { text-align: center; color: var(--muted); padding: 40px 16px; }
/* ไอคอนตกแต่งหัวการ์ดเท่านั้น (ลูกตรง) — ห้ามครอบไอคอนในปุ่ม: เคยทำให้ไอคอนในปุ่ม .btn-brand เป็นสีเดียวกับพื้นปุ่มจนมองไม่เห็น */
.cx-empty > i { font-size: 2.6rem; color: var(--brand); opacity: .55; }
.btn-brand { background: var(--brand); border-color: var(--brand); color: #fff;
  transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease, transform .15s ease; }
.btn-brand:hover, .btn-brand:focus { background: var(--brand-d); border-color: var(--brand-d); color: #fff; }
.btn-outline-brand { border-color: var(--brand); color: var(--brand); }
.btn-outline-brand:hover { background: var(--brand); color: #fff; }
/* เอฟเฟกต์เล็กน้อยตอนชี้ปุ่ม: ยกขึ้นนิดเดียว + เงาโทนสีแบรนด์ + ไอคอนขยับ (เฉพาะอุปกรณ์ที่มีเมาส์ ไม่ค้างบนมือถือ) */
.btn-brand > i, .btn-outline-brand > i { display: inline-block; transition: transform .18s ease; }
@media (hover: hover) {
  .btn-brand:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(13, 148, 136, .30); }
  .btn-brand:hover > i, .btn-outline-brand:hover > i { transform: scale(1.15); }
}
.btn-brand:active { transform: none; box-shadow: none; }

/* ช่องค้นหาทรงแคปซูล + ไอคอนแว่นขยายในช่อง (ใช้ทั้งหน้ากล่องข้อความและหน้าลูกค้า — เดิมอยู่ใน inbox.css จึงหน้าลูกค้าไม่ได้สไตล์ ไอคอนไปติดขอบช่อง) */
.cx-search { position: relative; flex: 1; min-width: 150px; }
.cx-search i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: .9rem; pointer-events: none; }
.cx-search input { width: 100%; border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px 6px 38px; font-size: .9rem; background: #f8fafc; outline: none; }
.cx-search input:focus { border-color: var(--brand); background: #fff; }

/* ---------- Modal ทุกตัวใช้หลักการเดียวกัน ----------
   1) หัว modal อยู่ตำแหน่งเดิมเสมอ: modal เกาะขอบบน (ไม่จัดกึ่งกลางแนวตั้ง) — ความสูงเนื้อหาเปลี่ยน
      (เช่น สลับแท็บใน "เชื่อมต่อช่องทาง", ข้อความแจ้งเตือนโผล่) จะขยายลงด้านล่างเท่านั้น หัวไม่ขยับ
   2) เนื้อหายาวเกินจอ: เลื่อนเฉพาะ .modal-body หัวและปุ่มท้าย modal คงที่
   3) เขียน modal ใหม่ให้ใช้ class "modal-dialog modal-dialog-scrollable" เสมอ ห้ามใช้ modal-dialog-centered */
:root {
  --cx-modal-top: clamp(12px, 8vh, 72px);
  --cx-modal-bottom: 16px;
  --cx-modal-max-h: calc(100vh - var(--cx-modal-top) - var(--cx-modal-bottom));
}
@supports (height: 100dvh) { :root { --cx-modal-max-h: calc(100dvh - var(--cx-modal-top) - var(--cx-modal-bottom)); } }
.modal-dialog { margin-top: var(--cx-modal-top); margin-bottom: var(--cx-modal-bottom); }
.modal-dialog-scrollable { height: auto; }
.modal-dialog-scrollable .modal-content { max-height: var(--cx-modal-max-h); }
/* กันเผลอใส่ modal-dialog-centered ใน modal ใหม่ — บังคับให้เกาะขอบบนเหมือนกัน */
.modal-dialog-centered { min-height: 0; align-items: flex-start; }
@media (prefers-reduced-motion: reduce) {
  .btn-brand, .btn-brand > i, .btn-outline-brand > i { transition: none; }
  .btn-brand:hover, .btn-brand:hover > i, .btn-outline-brand:hover > i { transform: none; }
}

.cx-badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .72rem; font-weight: 600; white-space: nowrap; flex-shrink: 0; }   /* ป้ายสถานะบรรทัดเดียวเสมอ (บนมือถือไม่ให้ถูกบีบจนขึ้นบรรทัดใหม่) */
.cx-badge.ok   { background: #dcfce7; color: #166534; }
.cx-badge.warn { background: #fef3c7; color: #92400e; }
.cx-badge.bad  { background: #fee2e2; color: #991b1b; }
.cx-badge.mute { background: #e2e8f0; color: #475569; }

.cx-toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--bottom-h) + var(--safe-bottom) + 14px);
  z-index: 2000; background: #0f172a; color: #fff; padding: 9px 16px; border-radius: 10px; font-size: .9rem;
  max-width: 90vw; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.cx-toast.err { background: var(--bad); }
@media (min-width: 992px) { .cx-toast { bottom: 24px; } }

/* ---------- หน้าเข้าสู่ระบบ ---------- */
.cx-login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.cx-login-card { width: 100%; max-width: 380px; }
.cx-login-logo { display: block; margin: 0 auto 10px; border-radius: 18px; }

/* ---------- ตัวช่วย ---------- */
.text-brand { color: var(--brand) !important; }
.min-w-0 { min-width: 0; }

/* ---------- แท็ก / สี / รหัสผูกบัญชี ---------- */
.cx-tag { display: inline-block; padding: 1px 9px; border-radius: 999px; color: #fff; font-size: .72rem; font-weight: 600; line-height: 1.5; }
.cx-swatches { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.cx-swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; padding: 0; }
.cx-swatch.on { border-color: var(--ink); box-shadow: 0 0 0 2px #fff inset; }
.cx-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.8rem; letter-spacing: .3em; font-weight: 700; color: var(--brand-d); margin: 6px 0 10px; }

/* ปุ่มแท็บแบบ pills ใช้สีหลักของระบบ (ค่าเริ่มต้นของ Bootstrap เป็นสีน้ำเงิน) */
.nav-pills .nav-link { color: var(--brand-d); }
.nav-pills .nav-link.active, .nav-pills .show > .nav-link { background: var(--brand); color: #fff; }

/* ---------- คู่มือแบบ modal ใหญ่เกือบเต็มจอ (assets/js/app.js: cxManual) ---------- */
.cx-manual-dialog { --cx-modal-top: 2vh; --cx-modal-bottom: 2vh; width: 96vw; max-width: 1400px; margin-left: auto; margin-right: auto; }
.cx-manual-dialog .modal-content { height: 96vh; max-height: none; }
@supports (height: 100dvh) { .cx-manual-dialog .modal-content { height: 96dvh; } }
.cx-manual-dialog .modal-body { background: #f1f5f9; padding: 12px; }
.cx-manual-dialog .modal-header .btn-group .btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.cx-manual-body .cx-card { background: #fff; }
.cx-manual-body section.cx-card { scroll-margin-top: 8px; }
