:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f0f3f6;
  --border: #dfe4ea;
  --text: #18202a;
  --muted: #5d6b7c;
  --accent: #0a8f66;
  --accent-strong: #077553;
  --accent-soft: #e2f5ee;
  --accent-ink: #ffffff;
  --danger: #c9303c;
  --danger-soft: #fdecee;
  --warn: #9a5b00;
  --warn-soft: #fff3d9;
  --info-soft: #e8f0fe;
  --info: #2457c5;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.06);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", "Leelawadee UI", "Noto Sans Thai", "Sarabun", "Thonburi", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "Noto Sans Thai", monospace;
  --brand-bot: #0d9488; /* รุ่น 43: สีคำว่า bot ในโลโก้ */
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand-bot: #2dd4bf;
    --bg: #0f1418;
    --surface: #182027;
    --surface-2: #212b34;
    --border: #2d3944;
    --text: #e8edf2;
    --muted: #9aa8b6;
    --accent: #2fc493;
    --accent-strong: #52d6aa;
    --accent-soft: #143629;
    --accent-ink: #06231a;
    --danger: #ff6b76;
    --danger-soft: #3a1a1e;
    --warn: #f2b84b;
    --warn-soft: #3a2c10;
    --info-soft: #17274a;
    --info: #8fb1ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.35; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
p { margin: 0; }
a { color: var(--accent-strong); }

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  cursor: pointer;
  font-weight: 550;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .field:focus-visible, .tab:focus-visible, .nav a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.small { min-height: 30px; padding: 2px 10px; font-size: 13px; border-radius: 7px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }

/* ---------- ฟอร์ม ---------- */
.field {
  width: 100%;
  min-height: 38px;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
}
textarea.field { resize: vertical; line-height: 1.6; }
.field:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
textarea.prompt { min-height: 320px; font-size: 14.5px; }
.form-row { display: grid; gap: 6px; margin-bottom: 16px; align-content: start; }
.form-row > label, .label { font-weight: 600; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* ---------- โครงหน้า ---------- */
.shell { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 12px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; font-weight: 700; font-size: 16px; }
/* รุ่น 43: โลโก้ Studio Chatbot — เครื่องหมายเป็น SVG บนพื้นน้ำเงินเข้ม (คงสีเดิมทุกธีม) ชื่อระบบเป็น SVG สีตามข้อความ คำว่า bot ใช้ --brand-bot */
.brand-mark { width: 30px; height: 30px; border-radius: 7px; background: #0f172a; overflow: hidden; flex: none; }
.brand-mark svg { display: block; width: 100%; height: 100%; }
.brand-word { display: inline-flex; align-items: center; color: var(--text); min-width: 0; }
.brand-word svg { display: block; height: 17px; width: auto; }
.brand-word .bot { fill: var(--brand-bot); }
.login .brand-mark { width: 40px; height: 40px; border-radius: 9px; }
.login .brand-word svg { height: 22px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 12px; border-radius: 9px; color: var(--text); text-decoration: none; font-weight: 550;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--accent-soft); color: var(--accent-strong); }
.side-foot { margin-top: auto; padding: 8px 4px; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.me { padding: 0 10px 6px; min-width: 0; max-width: 100%; }
.me-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--danger); color: #fff;
  font-size: 12px; font-weight: 700; display: inline-grid; place-items: center;
}
.main { padding: 26px 30px 60px; min-width: 0; }
.page { max-width: 1040px; margin: 0 auto; }
.page.wide { max-width: 1240px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.cards .card + .card { margin-top: 0; }
.bot-card { display: block; text-decoration: none; color: inherit; transition: border-color 0.12s, transform 0.12s; }
.bot-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.bot-card .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.stats { display: flex; gap: 14px; margin-top: 12px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.stats b { color: var(--text); font-variant-numeric: tabular-nums; }

.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty h2 { color: var(--text); margin-bottom: 6px; }
.empty .btn { margin-top: 16px; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 1px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 650; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.chip.ok { background: var(--accent-soft); color: var(--accent-strong); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.err { background: var(--danger-soft); color: var(--danger); }
.chip.info { background: var(--info-soft); color: var(--info); }

.notice { padding: 10px 14px; border-radius: 10px; background: var(--info-soft); color: var(--text); font-size: 14px; }
.notice.warn { background: var(--warn-soft); }
.notice.err { background: var(--danger-soft); }
.notice.ok { background: var(--accent-soft); }

code, .code {
  font-family: var(--mono); font-size: 13px; background: var(--surface-2); padding: 1px 6px; border-radius: 6px;
  overflow-wrap: anywhere;
}

/* ---------- แท็บ ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab {
  padding: 9px 14px; border: 0; background: none; cursor: pointer; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-strong); border-bottom-color: var(--accent); }

.savebar {
  position: sticky; top: 0; z-index: 5; margin: -26px -30px 20px; padding: 12px 30px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.savebar .inner { max-width: 1040px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.crumb { display: flex; align-items: center; gap: 10px; min-width: 0; }
.crumb h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 19px; }
.dirty { color: var(--warn); font-size: 13px; font-weight: 600; }

/* ---------- รายการ ---------- */
.list { display: grid; gap: 10px; }
.item {
  display: flex; gap: 12px; align-items: flex-start; justify-content: space-between;
  padding: 14px 16px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface);
}
.item .body { min-width: 0; flex: 1; }
.item .snippet { color: var(--muted); font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }

.url-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.url-row .code { flex: 1; min-width: 200px; padding: 7px 10px; }
ol.steps { margin: 8px 0 0; padding-left: 22px; color: var(--muted); font-size: 14px; }
ol.steps li { margin-bottom: 3px; }

/* ---------- หน้าต่างลอย ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(10, 16, 22, 0.55); display: grid; place-items: center;
  padding: 16px; z-index: 50;
}
.modal {
  width: min(560px, 100%); max-height: calc(100vh - 32px); background: var(--surface); border-radius: 14px;
  border: 1px solid var(--border); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); display: flex; flex-direction: column;
}
.modal.wide { width: min(900px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 20px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }

/* ---------- คลังรูป ---------- */
.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; margin-top: 16px; }
.img-card { border: 1px solid var(--border); border-radius: 11px; overflow: hidden; background: var(--surface); display: flex; flex-direction: column; }
.img-card .thumb { position: relative; aspect-ratio: 4 / 3; overflow: hidden; background: var(--surface-2); }
.img-card .thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.img-card .badge {
  position: absolute; left: 8px; top: 8px; padding: 1px 8px; border-radius: 7px; font-family: var(--mono);
  font-size: 12.5px; font-weight: 700; background: rgba(12, 18, 24, 0.82); color: #fff;
}
.img-card .info { padding: 8px 10px 0; font-size: 12.5px; color: var(--muted); }
.img-card .name { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.img-card .row { display: flex; gap: 6px; padding: 10px; margin-top: auto; }
.img-card .row .btn { flex: 1; }
.img-card .desc-box { padding: 8px 10px 0; display: grid; gap: 6px; }
.img-card .desc { font-size: 13px; line-height: 1.45; resize: vertical; min-height: 96px; }
.img-card .desc-state { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.img-card .desc-state.warn { color: var(--warn); font-weight: 600; }
.img-card .desc-state.err { color: var(--danger); }
.img-card .desc-state.ok { color: var(--accent); }
.img-card .row.tight { padding: 0; margin-top: 0; }
.upload-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

/* ---------- แชต ---------- */
.chat { display: flex; flex-direction: column; gap: 10px; padding: 16px; overflow: auto; background: var(--surface-2); flex: 1; min-height: 240px; }
.msg { max-width: min(78%, 560px); display: flex; flex-direction: column; gap: 3px; }
.msg.user { align-self: flex-start; }
.msg.assistant, .msg.admin { align-self: flex-end; align-items: flex-end; }
.msg .who { font-size: 12px; color: var(--muted); }
.msg .who .free-tag { margin-left: 6px; padding: 1px 7px; border-radius: 999px; font-size: 11px; background: var(--accent-soft); color: var(--accent-strong); }
.free-hint { display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-variant-numeric: tabular-nums; background: var(--accent-soft); color: var(--accent-strong); }
.slip { margin-top: 4px; padding: 8px 11px; border-radius: 11px; font-size: 13px; max-width: 380px; border: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.slip.ok { background: var(--accent-soft); border-color: transparent; }
.slip.ok b { color: var(--accent-strong); }
.slip.fail { background: var(--danger-soft); border-color: transparent; }
.slip.fail b { color: var(--danger); }
.slip.pending { background: var(--warn-soft); border-color: transparent; }
.slip.pending b { color: var(--warn); }
.slip.none { border: 0; background: none; padding: 0; flex-direction: row; align-items: center; gap: 8px; }
.slip-facts { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.free-hint.soon { background: var(--warn-soft); color: var(--warn); }
.bubble { padding: 9px 13px; border-radius: 15px; background: var(--surface); border: 1px solid var(--border); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant .bubble { background: var(--accent-soft); border-color: transparent; }
.msg.admin .bubble { background: var(--info-soft); border-color: transparent; }
.msg .pics { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.msg .pics img { width: 132px; height: 132px; object-fit: cover; border-radius: 11px; border: 1px solid var(--border); background: var(--surface); }
.msg.user .pics { justify-content: flex-start; }
.msg .pics a { display: block; line-height: 0; border-radius: 11px; }
.msg .pics a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.attach-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--border); background: var(--surface); }
.attach-bar img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.attach-bar img.outgoing { width: 96px; height: 96px; object-fit: contain; background: var(--surface-2); }
.attach-bar .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; color: var(--muted); }
.msg .pics img.sticker { width: 112px; height: 112px; object-fit: contain; border: 0; border-radius: 0; background: none; }
/* วิดีโอ/เสียง/ไฟล์ที่ลูกค้าส่ง (ไฟล์อยู่ที่ LINE กดแล้วค่อยโหลด) */
.msg .pics .media { display: flex; flex-direction: column; gap: 6px; max-width: 320px; padding: 8px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface); line-height: 1.35; }
.msg .pics .media-thumb { position: relative; width: 240px; max-width: 100%; aspect-ratio: 16 / 10; border-radius: 10px; overflow: hidden; background: #1c2630; cursor: pointer; }
.msg .pics .media-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border: 0; border-radius: 0; background: none; }
.msg .pics .media-play { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, 0.92); color: #111; font-size: 22px; line-height: 52px; text-align: center; padding: 0 0 0 4px; cursor: pointer; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35); }
.msg .pics .media-play:hover { background: #fff; }
.msg .pics .media-play:disabled { opacity: 0.6; cursor: default; }
.msg .pics .media-audio .media-play { position: static; width: 34px; height: 34px; margin: 0; font-size: 15px; line-height: 34px; background: var(--accent); color: #fff; box-shadow: none; }
.msg .pics .media-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.msg .pics .media a.btn { text-decoration: none; line-height: 1.3; }
.msg .pics .media-label { flex: 1; min-width: 0; font-weight: 600; }
.msg .pics .media-player { display: block; width: 300px; max-width: 100%; border-radius: 10px; background: #000; }
.msg .pics audio.media-player { background: none; height: 40px; }
.msg .pics .media-file { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.msg .pics .media-file > div { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.msg .pics .media-icon { font-size: 24px; }
.msg .pics .media-note:empty { display: none; }
.btn.icon { min-width: 42px; padding: 4px 8px; font-size: 20px; line-height: 1; }
.picker { border-top: 1px solid var(--border); background: var(--surface); padding: 10px 14px; max-height: 250px; overflow: auto; }
.picker-group + .picker-group { margin-top: 8px; }
.picker-label { font-size: 12.5px; color: var(--muted); margin: 2px 0 4px; }
.emoji-grid { display: flex; flex-wrap: wrap; gap: 2px; }
.emoji { width: 38px; height: 38px; border: 0; border-radius: 8px; background: none; cursor: pointer; font-size: 22px; line-height: 1; padding: 0; }
.emoji:hover, .sticker-tile:hover, .pack-tab:hover { background: var(--surface-2); }
.emoji:focus-visible, .sticker-tile:focus-visible, .pack-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.pack-tabs { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 6px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.pack-tab { flex: none; width: 44px; height: 44px; padding: 4px; border: 0; border-radius: 9px; background: none; cursor: pointer; }
.pack-tab.active { background: var(--accent-soft); }
.pack-tab img { width: 100%; height: 100%; object-fit: contain; display: block; }
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 4px; }
.sticker-tile { aspect-ratio: 1 / 1; padding: 6px; border: 0; border-radius: 10px; background: none; cursor: pointer; }
.sticker-tile img { width: 100%; height: 100%; object-fit: contain; display: block; }
.meter { width: 100%; height: 10px; margin: 12px 0 6px; border: 0; border-radius: 999px; overflow: hidden; background: var(--surface-2); accent-color: var(--accent); }
.meter::-webkit-progress-bar { background: var(--surface-2); border-radius: 999px; }
.meter::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
.meter::-moz-progress-bar { background: var(--accent); border-radius: 999px; }
.sysnote { align-self: center; font-size: 12.5px; color: var(--muted); background: var(--surface); border: 1px dashed var(--border); padding: 3px 12px; border-radius: 999px; text-align: center; }
.sysnote.err { color: var(--danger); border-color: var(--danger); }
.reply-as + .composer, .reply-as + .picker[hidden] + .composer { border-top: 0; padding-top: 4px; }
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); background: var(--surface); align-items: flex-end; }
.composer textarea { min-height: 42px; max-height: 160px; }
.chat-box { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); height: min(620px, calc(100vh - 260px)); min-height: 380px; }

/* ---------- กล่องข้อความ ---------- */
.inbox { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 14px; height: calc(100vh - 150px); min-height: 440px; }
.conv-list { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: auto; }
.conv {
  display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer;
  text-decoration: none; color: inherit;
}
.conv:hover { background: var(--surface-2); }
.conv.active { background: var(--accent-soft); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--surface-2); flex: none; display: grid; place-items: center; font-weight: 700; color: var(--muted); overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.conv .body { min-width: 0; flex: 1; }
.conv .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.conv .name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .time { font-size: 12px; color: var(--muted); flex: none; }
.conv .last { color: var(--muted); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .chips { display: flex; gap: 6px; margin-top: 4px; }
.avatar-wrap { position: relative; flex: none; width: 40px; height: 40px; }
.oa-logo {
  flex: none; display: grid; place-items: center; overflow: hidden; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-strong); font-weight: 800;
}
.oa-logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.oa-logo.mini { position: absolute; right: -5px; bottom: -5px; width: 22px; height: 22px; font-size: 11px; border: 2px solid var(--surface); }
.oa-logo.big { width: 52px; height: 52px; font-size: 21px; border: 1px solid var(--border); }
.conv.active .oa-logo.mini { border-color: var(--accent-soft); }
.reply-as { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--border); background: var(--surface); }
.reply-as-text { min-width: 0; line-height: 1.35; }
.reply-as-name { font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-as-note { color: var(--warn); font-weight: 600; font-size: 13.5px; overflow-wrap: anywhere; }
.oa-head { display: flex; align-items: center; gap: 12px; min-width: 0; }
.pane { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; min-width: 0; }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.pane-foot-hint { padding: 0 14px 10px; font-size: 12.5px; color: var(--muted); background: var(--surface); }
.back-mobile { display: none; }

/* ---------- ตัวกรองเคส + ทีมงาน ---------- */
.conv-col { display: flex; flex-direction: column; gap: 10px; min-height: 0; min-width: 0; }
.conv-col .conv-list { flex: 1; min-height: 0; }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 11px; background: var(--surface-2); }
.seg-btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 34px; padding: 4px 8px;
  border: 0; border-radius: 8px; background: none; cursor: pointer; font-weight: 600; font-size: 14px; color: var(--muted);
}
.seg-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(16, 24, 40, 0.12); }
.seg-count { min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--danger); color: #fff; font-size: 12px; font-weight: 700; }
.seg-count.quiet { background: var(--border); color: var(--text); }
.chips-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0 4px; }
.perms { display: grid; gap: 4px; border: 1px solid var(--border); border-radius: 10px; padding: 6px; }
.perm { display: flex; gap: 10px; align-items: flex-start; padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.perm:hover { background: var(--surface-2); }
.perm input { width: 17px; height: 17px; margin-top: 4px; accent-color: var(--accent); flex: none; }
.perm span { display: grid; }
.perm:has(input:disabled) { opacity: 0.55; cursor: not-allowed; }

/* ---------- บันทึกระบบ ---------- */
.log { padding: 12px 16px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); }
.log .top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.log .text { margin-top: 4px; font-weight: 550; }
.log pre { margin: 8px 0 0; padding: 10px; background: var(--surface-2); border-radius: 8px; font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 220px; overflow: auto; }

/* ---------- เข้าสู่ระบบ ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: min(380px, 100%); padding: 28px; }
.login .brand { padding: 0 0 18px; }

/* ---------- แจ้งเตือน ---------- */
#toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 100; max-width: min(380px, calc(100vw - 36px)); }
.toast { padding: 11px 15px; border-radius: 10px; background: #18202a; color: #fff; box-shadow: var(--shadow); font-size: 14px; }
.toast.err { background: #b3232e; }
.toast.ok { background: #0a7a57; }

.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 40px; text-align: center; color: var(--muted); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; } /* แถบเมนูบนสูงเท่าเนื้อหาของมัน (ไม่ถูกยืดเมื่อหน้าสั้นกว่าจอ) */
  .side { position: sticky; top: 0; z-index: 10; height: auto; flex-direction: row; align-items: center; padding: 8px 10px; border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto; gap: 8px; }
  .brand { padding: 0 4px; }
  .brand span { display: none; }
  .nav { flex-direction: row; }
  .nav a { padding: 7px 10px; white-space: nowrap; font-size: 14px; }
  .side-foot { margin: 0 0 0 auto; padding: 0; flex-direction: row; align-items: center; flex: none; }
  .me { display: none; }
  .side-foot .btn { white-space: nowrap; }
  .main { padding: 18px 14px 50px; }
  .savebar { margin: -18px -14px 16px; padding: 10px 14px; top: 55px; }
  .grid-2 { grid-template-columns: 1fr; gap: 0; }
  .inbox { grid-template-columns: 1fr; height: auto; }
  .inbox.has-open .conv-col { display: none; }
  .inbox:not(.has-open) .pane { display: none; }
  .pane { height: calc(100vh - 170px); min-height: 420px; }
  .back-mobile { display: inline-flex; }
  .msg { max-width: 88%; }
}

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

/* ---------- แท็กและโน้ตลูกค้า ---------- */
.chip.tag { background: hsl(var(--tag-h) 70% 91%); color: hsl(var(--tag-h) 65% 26%); }
.tag-x { border: 0; background: none; cursor: pointer; padding: 0 0 0 2px; font-size: 14px; line-height: 1; color: inherit; opacity: 0.7; }
.tag-x:hover, .tag-x:focus-visible { opacity: 1; }
.conv .chips { flex-wrap: wrap; }
.tag-filter, .case-filter, .inbox-vip { min-height: 34px; padding: 4px 10px; font-size: 14px; }
.inbox-filters { display: flex; gap: 6px; }
.inbox-filters > select { flex: 1; min-width: 0; }
.inbox-filters > select[hidden] { display: none; }
.inbox-vip.active { border-color: var(--warn); color: var(--warn); font-weight: 600; }
.oa-pick { position: relative; }
.conv-col .inbox-team { margin-bottom: 8px; font-weight: 600; }
.conv-col .inbox-brand { margin-bottom: 8px; font-weight: 600; }
/* VIP (รุ่น 35): ป้ายระดับ เห็นเฉพาะคนที่มีสิทธิ์ */
.chip.vip { background: var(--warn-soft); color: var(--warn); font-weight: 700; }
.vip-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.vip-total { font-size: 13px; color: var(--muted); }
.vip-total b { color: var(--text); }
.same-list { display: grid; gap: 6px; }
.same-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); color: inherit; text-decoration: none; }
.same-row:hover { border-color: var(--accent); }
.same-row .name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tier-rows { display: grid; gap: 6px; }
.tier-row { display: grid; grid-template-columns: 56px minmax(0, 1fr) minmax(0, 1fr) auto; gap: 6px; align-items: center; }
.tier-row .lvl { font-weight: 700; color: var(--muted); }
.brand-item .stats { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.oa-current, .oa-row { display: flex; align-items: center; gap: 9px; width: 100%; padding: 8px 11px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: inherit; font: inherit; text-align: left; cursor: pointer; }
.oa-current:hover, .oa-row:hover { border-color: var(--accent); }
.oa-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.oa-counts { display: flex; gap: 5px; flex-shrink: 0; }
.oa-counts .chip { font-size: 11.5px; padding: 1px 7px; font-variant-numeric: tabular-nums; }
.oa-caret { color: var(--muted); font-size: 12px; }
.oa-menu { position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; right: 0; max-height: 360px; overflow: auto; padding: 5px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: 0 10px 30px rgb(0 0 0 / 0.16); display: flex; flex-direction: column; gap: 3px; }
.oa-row { border-color: transparent; padding: 7px 8px; }
.oa-row.active { background: var(--accent-soft); }
.inbox-search { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.list-info { padding: 0 4px; margin-top: -4px; }
.list-more { display: flex; justify-content: center; padding: 12px; }

.cust-bar { padding: 8px 16px; border-bottom: 1px solid var(--border); display: grid; gap: 8px; }
.cust-bar:empty { display: none; }
.cust-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tag-input { width: 190px; min-height: 30px; padding: 2px 9px; font-size: 13.5px; }
.note-view { background: var(--warn-soft); border-radius: 9px; padding: 8px 12px; }
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; max-height: 96px; overflow: auto; }
.note-edit { display: grid; gap: 8px; }

/* ---------- ข้อความสำเร็จรูป ---------- */
.quick-head { display: flex; gap: 8px; align-items: center; }
.quick-list { display: grid; gap: 4px; }
.quick-item { display: grid; gap: 2px; text-align: left; padding: 8px 10px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); cursor: pointer; }
.quick-item:hover { background: var(--surface-2); border-color: var(--accent); }
.quick-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.quick-item > span { color: var(--muted); font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; overflow-wrap: anywhere; }
.quick-form { box-shadow: none; }
.quick-form .label { margin-bottom: 10px; }

/* ---------- เลือก LINE OA ให้ทีมงาน ---------- */
.oa-logo.tiny { width: 24px; height: 24px; font-size: 11px; border: 1px solid var(--border); }
.oa-pick { align-items: center; }
.oa-pick input { margin-top: 0; }
.oa-cell { display: flex; align-items: center; gap: 8px; }

/* ---------- การแจ้งเตือนเคส ---------- */
#alerts { position: fixed; top: 10px; right: 16px; display: grid; gap: 6px; z-index: 101; max-width: min(420px, calc(100vw - 32px)); }
.toast.alert { background: #8a4b00; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; border-radius: 8px; font-size: 13px; line-height: 1.35; }
.toast.alert b { white-space: nowrap; }
.toast.alert .alert-body { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: 0.95; }
.toast.alert .alert-x { flex: none; width: 24px; height: 24px; border: 0; border-radius: 6px; background: rgba(255, 255, 255, 0.14); color: #fff; font-size: 16px; line-height: 1; cursor: pointer; padding: 0; }
.toast.alert .alert-x:hover { background: rgba(255, 255, 255, 0.28); }
.toast.alert:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.toast-hint { font-size: 12px; opacity: 0.85; }

/* ---------- แดชบอร์ด ---------- */
.dash-seg { min-width: 240px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat-tile.warn { border-color: var(--warn); background: var(--warn-soft); }
.stat-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 26px; font-weight: 750; line-height: 1.3; font-variant-numeric: tabular-nums; }
.bars { display: flex; align-items: stretch; gap: 4px; height: 190px; margin-top: 12px; }
.bar-col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.bar-set { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 2px; border-bottom: 1px solid var(--border); }
.bar { flex: 1; max-width: 16px; border-radius: 3px 3px 0 0; }
.bar.customer, .key.customer::before { background: var(--info); }
.bar.bot, .key.bot::before { background: var(--accent); }
.bar.admin, .key.admin::before { background: var(--warn); }
.bar-label { height: 16px; font-size: 11px; color: var(--muted); text-align: center; white-space: nowrap; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); }
.key::before { content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.table th { font-size: 12.5px; color: var(--muted); font-weight: 650; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr:last-child td { border-bottom: 0; }
@media (prefers-color-scheme: dark) {
  .chip.tag { background: hsl(var(--tag-h) 40% 22%); color: hsl(var(--tag-h) 75% 82%); }
  .toast.alert { background: #6e3d05; }
}

/* ---------- สาย และค่าใช้จ่าย ---------- */
.team-item .stats { margin-top: 8px; }
.field.price { width: 120px; min-height: 32px; padding: 3px 8px; text-align: right; }
.table td .field.price { display: inline-block; }
.seg-btn { white-space: nowrap; }
.dash-seg.wide { min-width: 340px; }
.list + .card { margin-top: 14px; }

/* ---------- แดชบอร์ดรายคน ---------- */
button.stat-tile { font: inherit; color: inherit; text-align: left; cursor: pointer; display: block; width: 100%; }
button.stat-tile:hover { border-color: var(--accent); }
button.stat-tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile-more { color: var(--accent-strong); font-weight: 600; margin-top: 2px; }
.person { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.legend-list { margin: 10px 0 0; padding-left: 18px; display: grid; gap: 2px; }

/* ประเภทเคส */
.chip.cat { background: var(--info-soft); color: var(--info); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.case-list { display: flex; flex-direction: column; gap: 8px; }
.case-row { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(0, 2fr) auto; gap: 8px; align-items: center; }
.case-pick { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.case-select { min-height: 30px; padding: 2px 8px; font-size: 13px; width: auto; max-width: 220px; }
.reason-name { display: flex; flex-direction: column; gap: 4px; min-width: 140px; }
.reason-bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.reason-bar > div { height: 100%; background: var(--info); border-radius: 3px; }
@media (max-width: 640px) {
  .case-row { grid-template-columns: 1fr auto; }
  .case-row .case-hint { grid-column: 1 / -1; grid-row: 2; }
}

/* สุขภาพของ LINE OA: โควตาข้อความ และสิทธิ์ตอบฟรี */
.oa-health { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.oa-health-row { border: 1px solid var(--border); border-radius: 10px; padding: 12px; min-width: 0; }
.oa-health-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.oa-health-head .label { margin: 0; }
.oa-health-row .hint { margin: 6px 0 0; }
.oa-health-row .notice { margin: 0 0 10px; font-size: 14px; }
.oa-health-row .notice > div + div { margin-top: 4px; }
.quota-text { font-size: 14px; }
.quota-bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.quota-bar > div { height: 100%; border-radius: 4px; background: var(--accent); }
.quota-bar.low > div { background: var(--warn); }
.quota-bar.out > div { background: var(--danger); }
@media (max-width: 760px) {
  .oa-health { grid-template-columns: 1fr; }
}

/* ข้อความที่เพิ่งกดส่ง (รอผล / ส่งไม่สำเร็จ) */
.msg.pending .bubble { opacity: 0.6; }
.msg.failed .bubble { background: var(--danger-soft); border-color: var(--danger); }
.msg.failed .who { color: var(--danger); font-weight: 600; }
.send-error { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; font-size: 13px; color: var(--danger); text-align: right; }
.send-error .actions { display: flex; gap: 6px; }

/* คีย์ลัดและรายการข้อความสำเร็จรูปที่ขึ้นเมื่อพิมพ์ / ในช่องตอบ */
.chip.quick-key { background: var(--accent-soft); color: var(--accent-strong); font-family: var(--mono); font-weight: 600; }
.shortcut-row { display: flex; align-items: center; gap: 8px; max-width: 320px; }
.shortcut-slash { font-family: var(--mono); font-size: 18px; font-weight: 700; color: var(--muted); }
.composer { position: relative; }
.slash-list { position: absolute; left: 12px; right: 12px; bottom: calc(100% + 4px); z-index: 5; display: grid; gap: 4px; max-height: 300px; overflow: auto; padding: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.slash-list[hidden] { display: none; }
.slash-item { display: grid; gap: 2px; text-align: left; padding: 8px 10px; border: 1px solid transparent; border-radius: 9px; background: none; cursor: pointer; font: inherit; color: inherit; }
.slash-item.active, .slash-item:hover { background: var(--accent-soft); border-color: var(--accent); }
.slash-item > span { color: var(--muted); font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; overflow-wrap: anywhere; }
.slash-tip { font-size: 12px; color: var(--muted); padding: 2px 4px 0; }
.slash-empty { padding: 6px 4px; }

/* แผงข้อความสำเร็จรูปแบบเต็มจอ (กดปุ่ม ⚡) */
.overlay.quick-overlay { display: flex; align-items: stretch; justify-items: stretch; padding: 28px; }
.quick-sheet { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--surface); border-radius: 16px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); overflow: hidden; }
.quick-sheet-head { display: flex; align-items: center; gap: 12px; padding: 18px 24px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.quick-sheet-head h2 { margin: 0; font-size: 20px; white-space: nowrap; }
.quick-sheet-oa { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.quick-search { flex: 1; min-width: 240px; min-height: 48px; padding: 8px 16px; font-size: 17px; border: 2px solid var(--accent); border-radius: 12px; }
.quick-grid { flex: 1; overflow: auto; padding: 20px 24px; display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); grid-auto-rows: max-content; gap: 14px; align-content: start; background: var(--bg); }
.quick-card { display: flex; flex-direction: column; gap: 8px; min-height: 120px; padding: 14px 16px; text-align: left; font: inherit; color: inherit; background: var(--surface); border: 1.5px solid var(--border); border-radius: 14px; cursor: pointer; }
.quick-card:hover { border-color: var(--accent); }
.quick-card.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.quick-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.quick-card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.quick-card-head b { font-size: 17px; overflow-wrap: anywhere; }
.quick-card-head .chip.quick-key { font-size: 15px; padding: 2px 10px; }
.quick-card-text { font-size: 15.5px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.quick-empty { grid-column: 1 / -1; }
.quick-sheet-foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 10px 24px; border-top: 1px solid var(--border); color: var(--muted); font-size: 14px; }
@media (max-width: 760px) {
  .overlay.quick-overlay { padding: 0; }
  .quick-sheet { border-radius: 0; }
  .quick-sheet-head { padding: 12px 14px; gap: 8px; }
  .quick-sheet-head h2 { font-size: 17px; }
  .quick-sheet-head h2 { flex: 1; }
  .quick-sheet-oa { order: 6; flex-basis: 100%; max-width: none; }
  .quick-search { order: 5; min-width: 100%; }
  .quick-grid { padding: 12px; grid-template-columns: 1fr; }
  .quick-sheet-foot { padding: 10px 14px; }
  .quick-sheet-keys { display: none; }
}

/* หน้าโปรโมชั่นและคูปอง */
.promo-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.promo-oa { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 220px; max-width: 420px; }
.offer-list { display: grid; gap: 12px; }
.offer-card { display: flex; gap: 16px; align-items: flex-start; margin: 0; }
.offer-card.dim { opacity: 0.72; }
.offer-thumb { flex: none; width: 168px; height: 112px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.offer-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.offer-body { flex: 1; min-width: 0; display: grid; gap: 6px; }
.offer-title { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.offer-title h2 { margin: 0; font-size: 17px; overflow-wrap: anywhere; }
.offer-when { margin: 0; }
.offer-detail { font-size: 14.5px; white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.offer-actions { margin-top: 4px; }
/* รุ่น 38: แยกส่วน "ทั้งแบรนด์" กับ "เฉพาะ OA นี้" */
.offer-group { margin-bottom: 18px; }
.offer-group-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 8px; }
.offer-group-head h2 { margin: 0; font-size: 16px; }
.offer-group-head .hint { margin: 0; }
#offer-group-brand .offer-card { border-left: 3px solid var(--accent); }
.offer-empty { padding: 18px; }
.offer-empty h2 { font-size: 15px; }
.offer-readonly { align-self: center; }
.field-static { margin: 0; padding: 8px 0; font-size: 14.5px; }
.grant-oa { color: var(--muted); font-size: 13px; }
.offer-image-box { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.offer-image-box img { max-width: 240px; max-height: 160px; border-radius: 10px; border: 1px solid var(--border); }
@media (max-width: 640px) {
  .offer-card { flex-direction: column; }
  .offer-thumb { width: 100%; height: 160px; }
}

/* ตอบกลับแบบอ้างถึงข้อความ (quote) */
.msg .who .quote-btn { margin-left: 8px; padding: 0 4px; border: 0; background: none; font: inherit; font-size: 12px; color: var(--muted); cursor: pointer; border-radius: 6px; }
.msg .who .quote-btn:hover, .msg .who .quote-btn:focus-visible { color: var(--accent-strong); background: var(--accent-soft); outline: none; }
.msg .quoted { display: flex; flex-direction: column; gap: 1px; max-width: 100%; padding: 5px 10px; border: 0; border-left: 3px solid var(--border-strong, var(--border)); border-radius: 8px; background: var(--surface-2); font: inherit; font-size: 12.5px; color: var(--muted); text-align: left; cursor: pointer; }
.msg .quoted b { font-size: 11.5px; color: var(--text); }
.msg .quoted span { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.flash .bubble, .msg.flash .pics img { outline: 2px solid var(--accent); outline-offset: 2px; transition: outline-color 0.3s; }
.quote-bar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-top: 1px solid var(--border); background: var(--surface); }
.quote-bar-text { flex: 1; min-width: 0; display: flex; flex-direction: column; padding-left: 10px; border-left: 3px solid var(--accent); font-size: 13px; }
.quote-bar-text b { font-size: 12px; color: var(--accent-strong); }
.quote-bar-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.quote-bar:not([hidden]) + .composer { border-top: 0; padding-top: 4px; }
/* ลากไฟล์รูปมาวางในแชต */
.pane.dropping { outline: 2px dashed var(--accent); outline-offset: -6px; }

/* ---------- ข้อมูลลูกค้า (เฉพาะเจ้าของระบบ) ---------- */
.link-btn { font: inherit; color: var(--accent-strong); background: none; border: 0; padding: 0; cursor: pointer; text-align: left; font-weight: 600; }
.link-btn:hover { text-decoration: underline; }
.link-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
button.stat-tile.picked { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.contact-filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.contact-filters .field { width: auto; min-width: 150px; flex: 0 1 190px; }
.contact-filters input[type='search'] { flex: 1 1 200px; }
.contact-table .group-row td { background: var(--surface-2); font-weight: 650; font-size: 13px; color: var(--muted); padding: 6px 10px; }
.contact-table td { vertical-align: top; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 12px; font-size: 14px; color: var(--muted); }
.contact-setting { display: flex; gap: 14px; align-items: flex-start; justify-content: space-between; padding: 12px 0; border-top: 1px solid var(--border); }
.contact-setting:first-of-type { border-top: 0; padding-top: 0; }
.contact-setting > div { flex: 1; min-width: 0; }
.contact-setting .btn { flex: none; }
.contact-phone { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }
.contact-phone > div:first-child { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.quote-src { margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 640px) {
  .contact-setting { flex-direction: column; }
}

/* ---------- เจ้าของระบบ: เลือกสายก่อนดูรายการ ---------- */
button.team-card { font: inherit; text-align: left; cursor: pointer; width: 100%; }
button.team-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.team-card h2 { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.team-search { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.team-search .field { flex: 1 1 280px; max-width: 460px; }
.team-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.team-bar .field { width: auto; min-width: 200px; max-width: 100%; }

/* ตัวแปรในข้อความสำเร็จรูป */
.quick-vars { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.quick-vars .hint { margin: 0; }

/* ประวัติเคส */
.case-history { font-size: 14px; }
.case-day { font-size: 12px; font-weight: 700; color: var(--muted); margin: 14px 0 6px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.case-day:first-child { margin-top: 4px; }
.case-event { display: grid; grid-template-columns: 46px 26px 1fr; gap: 8px; align-items: start; padding: 7px 0; }
.case-time { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; padding-top: 2px; }
.case-icon { font-size: 16px; line-height: 1.3; }
.case-text b { display: block; font-weight: 600; }
.case-text span { display: block; font-size: 13px; color: var(--muted); margin-top: 1px; }
.case-event.legacy .case-text b { font-weight: 500; }

/* ช่องข้อมูลลูกค้าที่ทีมตั้งเอง */
.cust-fields { gap: 6px; }
.cust-field { border: 1px solid var(--border); border-radius: 8px; padding: 2px 9px; font-size: 13.5px; background: var(--surface); max-width: 100%; overflow-wrap: anywhere; }
.cust-field-name { color: var(--muted); }
.field-hit { font-size: 13px; color: var(--muted); margin-top: 4px; overflow-wrap: anywhere; }
.field-hit mark { background: var(--warn-soft); color: var(--text); border-radius: 4px; padding: 0 4px; font-weight: 700; }
.cf-form { margin-top: 16px; }
.cf-item h3 { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* รูปและสลิปทั้งหมดของลูกค้ารายคน */
.gallery-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.gallery-sum { font-size: 14px; font-weight: 600; background: var(--accent-soft); color: var(--accent-strong); border-radius: 9px; padding: 6px 12px; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.gallery-grid .empty { grid-column: 1 / -1; }
.gallery-card { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); display: flex; flex-direction: column; min-width: 0; }
.gallery-pic { display: block; height: 190px; background: var(--surface-2); overflow: hidden; }
.gallery-pic img { width: 100%; height: 100%; object-fit: cover; object-position: top center; display: block; }
.gallery-pic.gone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 13.5px; text-align: center; padding: 10px; }
.gallery-info { padding: 9px 11px 10px; display: grid; gap: 4px; }
.gallery-line { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.gallery-amount { font-weight: 700; font-size: 14px; }
.gallery-more { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.gallery-jump { border: 0; background: none; padding: 0; margin-top: 2px; font: inherit; font-size: 13px; font-weight: 600; color: var(--accent-strong); cursor: pointer; text-align: left; }
.gallery-jump:hover { text-decoration: underline; }
.gallery-jump:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.gallery-old { font-size: 12.5px; }
.gallery-foot { margin: 14px 0 0; text-align: center; }
@media (max-width: 640px) {
  .gallery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .gallery-pic { height: 150px; }
  .cf-form .grid-2 { grid-template-columns: 1fr; }
}

/* Facebook เพจ (รุ่นทดลอง) */
.inbox-tabs { flex: none; align-self: center; }
.inbox-tabs a.seg-btn { text-decoration: none; padding: 4px 16px; min-width: 96px; }
.meta-steps { margin: 6px 0 0; padding-left: 22px; display: grid; gap: 6px; font-size: 14px; line-height: 1.6; }
#meta-app-card h2, #meta-connect-card h2 { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#meta-app-card .url-row .code { overflow-wrap: anywhere; }
@media (max-width: 640px) {
  #meta-app-card .grid-2 { grid-template-columns: 1fr; }
}
/* มีแท็บ LINE OA / Facebook (เจ้าของระบบที่เชื่อมเพจแล้ว): หัวหน้าไม่สูงขึ้น แท็บอยู่แถวเดียวกับชื่อหน้า จอแคบซ่อนคำอธิบายใต้ชื่อ */
.page-head:has(.inbox-tabs:not([hidden])) { flex-wrap: nowrap; align-items: center; }
.page-head:has(.inbox-tabs:not([hidden])) > div:first-child { min-width: 0; }
@media (max-width: 1100px) {
  .page-head:has(.inbox-tabs:not([hidden])) .sub { display: none; }
}
@media (max-width: 640px) {
  .inbox-tabs a.seg-btn { min-width: 0; padding: 4px 10px; }
}

/* ---------- หน้าแชต: ให้พื้นที่กับบทสนทนามากขึ้น ---------- */
/* ช่องพิมพ์ต้องอยู่ในจอเสมอ: บนจอเตี้ย แถบข้อมูลลูกค้าที่กางอยู่จะเลื่อนในตัวเองแทนการดันช่องพิมพ์ตกขอบ */
.pane .chat { min-height: 150px; }
.cust-bar { min-height: 0; overflow-y: auto; flex-shrink: 1; }
.pane-head, .reply-as, .composer, .pane-foot-hint { flex: none; }
/* แถบข้อมูลลูกค้าแบบย่อ: บรรทัดเดียว ส่วนที่ยาวเกินถูกตัดท้าย */
.cust-bar:has(.cust-compact) { padding: 6px 16px; overflow: hidden; }
.cust-compact { flex-wrap: nowrap; gap: 8px; min-width: 0; }
.cust-compact-items { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; }
.cust-compact-items > * { flex: none; }
.cust-mini { font-size: 13.5px; }
.cust-note-mini { flex: 0 1 auto !important; min-width: 96px; overflow: hidden; text-overflow: ellipsis; font-size: 13.5px; background: var(--warn-soft); border-radius: 7px; padding: 1px 8px; }
.chip.cat-none { border: 1px dashed var(--border); background: none; color: var(--muted); font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.chip.cat-none:hover { color: var(--text); border-color: var(--muted); }
.chip.cat-none:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.cust-compact #cust-toggle { flex: none; white-space: nowrap; }
.cust-collapse { margin-left: auto; }
/* แถบ "กำลังตอบในนาม": บรรทัดเดียว โลโก้เล็ก (ชี้ที่โน้ตเพื่ออ่านเต็ม) */
.reply-as { padding: 5px 14px; gap: 8px; }
.reply-as .oa-logo.big { width: 26px; height: 26px; font-size: 12px; }
.reply-as-text { display: flex; align-items: baseline; gap: 8px; min-width: 0; white-space: nowrap; overflow: hidden; line-height: 1.5; }
.reply-as-text .hint { flex: none; }
.reply-as-name { font-size: 14px; flex: 0 0 auto; max-width: 45%; }
.reply-as-note { font-size: 13px; flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; overflow-wrap: normal; }
/* ขยายแชต: ซ่อนรายการแชตด้านซ้ายและหัวข้อหน้า */
@media (min-width: 861px) {
  .inbox.chat-wide { grid-template-columns: minmax(0, 1fr); height: calc(100vh - 28px); }
  .inbox.chat-wide .conv-col { display: none; }
  .chat-wide-page .page-head { display: none; }
  .page.chat-wide-page { max-width: none; }
  .main:has(> .chat-wide-page) { padding: 14px 18px; }
}
@media (max-width: 860px) {
  .chat-wide-btn { display: none; } /* จอมือถือ แชตเต็มจออยู่แล้ว */
}
@media (max-width: 640px) {
  .reply-as-text { flex-wrap: wrap; white-space: normal; gap: 0 8px; }
  .reply-as-note { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; white-space: normal; overflow-wrap: anywhere; flex-basis: 100%; }
}

/* ข้อความสำเร็จรูป: รายการโปรดและใช้ล่าสุด */
.quick-card-wrap { position: relative; display: flex; min-width: 0; }
.quick-card-wrap .quick-card { flex: 1; min-width: 0; }
.quick-card-wrap .quick-card-head { padding-right: 34px; }
.quick-star { position: absolute; top: 8px; right: 8px; width: 34px; height: 34px; border: 0; border-radius: 9px; background: none; font-size: 21px; line-height: 1; color: var(--muted); cursor: pointer; }
.quick-star:hover { background: var(--surface-2); color: var(--warn); }
.quick-star:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.quick-card-wrap.fav .quick-star { color: #d97706; }
.quick-card-wrap.fav .quick-card { border-color: #f3c97a; }
.quick-card-wrap.fav .quick-card.active, .quick-card-wrap.fav .quick-card:hover { border-color: var(--accent); }
.chip.quick-recent { background: var(--info-soft); color: var(--info); font-size: 12px; }
.slash-fav { color: #d97706; }

/* รูปที่ตรวจแล้วไม่ใช่สลิป: เหลือลิงก์เล็ก ๆ ให้กดตรวจเอง */
.slip-quiet { border: 0; background: none; padding: 0; font: inherit; font-size: 12px; color: var(--muted); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.slip-quiet:hover { color: var(--text); }
.slip-quiet:disabled { opacity: 0.6; cursor: default; }
.slip.none.quiet { margin-top: 2px; line-height: 1.2; }
/* จอที่มีเมาส์: ซ่อนไว้จนกว่าจะชี้ที่ข้อความนั้น (หรือโฟกัสด้วยแป้นพิมพ์) · จอสัมผัสแสดงเป็นลิงก์เล็กตลอด */
@media (hover: hover) {
  .slip.none.quiet .slip-quiet { opacity: 0; transition: opacity 0.12s; }
  .msg:hover .slip.none.quiet .slip-quiet, .slip.none.quiet .slip-quiet:focus-visible, .slip.none.quiet .slip-quiet:disabled { opacity: 1; }
}

/* ---------- ดูรูปขยายในหน้าเดิม ---------- */
.overlay.img-viewer { display: flex; flex-direction: column; align-items: stretch; padding: 0; background: rgba(8, 12, 16, 0.9); z-index: 60; }
.img-viewer-bar { flex: none; display: flex; justify-content: flex-end; gap: 8px; padding: 10px 14px; }
.img-viewer-bar .btn { background: rgba(255, 255, 255, 0.94); color: #1b2430; border-color: transparent; text-decoration: none; }
.img-viewer-bar .btn:hover { background: #fff; }
.img-viewer-stage { flex: 1; min-height: 0; overflow: auto; display: flex; padding: 0 14px 14px; }
.img-viewer-pic { margin: auto; max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; background: #fff; cursor: zoom-in; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5); }
.img-viewer-stage.zoomed .img-viewer-pic { max-width: none; max-height: none; height: auto; cursor: zoom-out; }
.img-viewer-error { margin: auto; max-width: 420px; padding: 18px 20px; border-radius: 12px; background: var(--surface); color: var(--text); text-align: center; line-height: 1.6; }

/* ---------- แดชบอร์ด: เลือกช่วงวันที่เอง ---------- */
.dash-seg { min-width: 0; }
.dash-range { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 10px 14px; margin: -8px 0 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.dash-range-field { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.dash-range-field .field { width: auto; min-height: 34px; padding: 4px 8px; }
.dash-range .hint { flex-basis: 100%; }
.bars.dense { overflow-x: auto; padding-bottom: 4px; }
.bars.dense .bar-col { flex: 0 0 24px; }

/* ---------- แถบเตือนเคส (จอเล็ก: อยู่ใต้แถบเมนูด้านบน) ---------- */
@media (max-width: 860px) {
  #alerts { top: 58px; right: 10px; left: 10px; max-width: none; }
}

/* ---------- แชตที่ถูกทำเครื่องหมายสแปม ---------- */
.chip.spam { background: #3a3a3a; color: #fff; }
@media (prefers-color-scheme: dark) { .chip.spam { background: #5a5a5a; color: #fff; } }

/* ---------- สร้างรูปด้วย AI ---------- */
.img-layout { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.img-layout[hidden], .img-history[hidden] { display: none; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.grid-3 .form-row { margin-bottom: 0; }
.chips-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.pick { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); cursor: pointer; font: inherit; font-size: 13.5px; text-align: left; }
.pick b { font-size: 14px; }
.pick span { font-size: 12px; color: var(--muted); }
.pick.small { flex-direction: row; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px; font-weight: 600; }
.pick.small .pick-sub { font-weight: 500; }
.pick:hover { border-color: var(--accent); }
.pick.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); }
.pick.active span { color: var(--accent-strong); opacity: 0.85; }
.pick:disabled { opacity: 0.45; cursor: not-allowed; }
.pick:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.img-custom { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.img-custom .field { width: 110px; }
.img-examples { display: grid; gap: 6px; margin-top: 8px; }
.img-example { text-align: left; padding: 8px 12px; border: 1px dashed var(--border); border-radius: 10px; background: var(--surface-2); color: var(--text); cursor: pointer; font: inherit; font-size: 13.5px; }
.img-example:hover { border-color: var(--accent); background: var(--accent-soft); }
.img-refs { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 8px; }
.img-ref { position: relative; width: 84px; height: 84px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.img-ref img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-ref-x { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border: 0; border-radius: 50%; background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 15px; line-height: 1; cursor: pointer; }
.img-result { position: sticky; top: 14px; }
.img-stage { position: relative; width: 100%; max-height: 70vh; border-radius: 12px; overflow: hidden; background: var(--surface-2); display: flex; align-items: center; justify-content: center; cursor: zoom-in; }
.img-stage.failed { cursor: default; background: var(--danger-soft); }
.img-pic { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-wait { display: grid; justify-items: center; gap: 8px; padding: 24px; text-align: center; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.img-actions { margin-top: 12px; }
.img-prompt { margin: 12px 0 4px; font-size: 14px; white-space: pre-wrap; }
.img-ref-mode { margin: 2px 0 10px; }
.img-size-pick { margin: 2px 0 6px; }
.img-size-pick .pick.small span { font-size: 11.5px; }
.img-sent { margin: 6px 0 2px; font-size: 13px; }
.img-sent summary { cursor: pointer; color: var(--muted); }
.img-sent-text { margin: 6px 0 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); font: inherit; font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.img-meta { margin-top: 4px; }
.img-edit { margin-top: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); display: grid; gap: 10px; }
.img-edit[hidden] { display: none; }
.img-empty { display: grid; justify-items: center; gap: 6px; padding: 60px 20px; text-align: center; color: var(--muted); }
.img-empty-art { font-size: 44px; }
.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; align-items: start; }
.img-card { display: block; padding: 0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); text-align: left; cursor: pointer; font: inherit; color: inherit; box-shadow: var(--shadow); }
.img-card:hover, .img-card.active { border-color: var(--accent); }
.img-card.active { box-shadow: 0 0 0 2px var(--accent-soft); }
.img-thumb { width: 100%; aspect-ratio: 1 / 1; background: var(--surface-2); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.img-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-card-body { padding: 10px 12px 12px; display: grid; gap: 4px; }
.img-card-prompt { font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.img-card.failed .img-thumb { background: var(--danger-soft); }
@media (max-width: 960px) {
  .img-layout { grid-template-columns: 1fr; }
  .img-result { position: static; }
  .grid-3 { grid-template-columns: 1fr; }
}
.img-form .form-row > .btn { justify-self: start; }
.pick.ai { border-style: dashed; }
.pick.ai.active { border-style: solid; }
/* โหมดบรีฟ (รุ่น 41): สวิตช์ 2 โหมด บรีฟช่องเดียว ตัวหนังสือที่ระบบวางเอง และผลการตีความ */
.img-mode { margin-bottom: 14px; }
.img-mode .seg-btn { flex: 1; }
.img-brief-hint { margin: 6px 0 0; }
.img-note { margin: 6px 0 2px; padding: 8px 12px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 10px 10px 0; color: var(--text); }
.img-preview { display: grid; gap: 8px; margin-top: 10px; padding: 12px; border: 1px solid var(--accent); border-radius: 12px; background: var(--surface-2); }
.img-preview[hidden] { display: none; }
.img-preview textarea { font-size: 13px; }
.img-overlay-box { display: grid; gap: 8px; margin-top: 8px; padding: 10px 12px; border: 1px dashed var(--border); border-radius: 12px; }
.img-overlay-box[hidden] { display: none; }
.img-overlay-box .label-row { gap: 10px; flex-wrap: wrap; }
.img-overlay-box .label-row .label { margin: 0; min-width: 64px; }
.img-stage canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
/* ช่องกำหนดขนาดเอง (รุ่น 41.1): สลับ ใส่พิกเซล / ใส่สัดส่วน */
.img-custom-box { display: grid; gap: 8px; margin-top: 8px; }
.img-size-mode { display: inline-flex; width: auto; }
.img-size-mode .seg-btn { padding: 5px 12px; font-size: 13px; }
.img-ratio { display: grid; gap: 6px; }
.img-ratio .img-custom { margin-top: 0; }
.img-ratio .img-custom .field { width: 84px; }
.img-ratio[hidden], .img-custom[hidden] { display: none; }
.hint.err { color: var(--danger); }
/* ฟอนต์ไทยสำหรับวางตัวหนังสือทับรูป (โหลดเฉพาะตอนใช้) ดู public/fonts/LICENSE-Loma.txt */
@font-face { font-family: 'LAS Thai'; src: url('/fonts/Loma.otf') format('opentype'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'LAS Thai'; src: url('/fonts/Loma-Bold.otf') format('opentype'); font-weight: 700; font-display: swap; }

/* ---------- บรอดแคสต์ ---------- */
.bc-item .label-row { justify-content: flex-start; }
.bc-steps { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.bc-step { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 13.5px; }
.bc-step b { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; background: var(--border); color: var(--text); font-size: 12px; }
.bc-step.active { background: var(--accent-soft); color: var(--accent-strong); }
.bc-step.active b, .bc-step.done b { background: var(--accent); color: #fff; }
.bc-editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.bc-items { display: grid; gap: 12px; margin-bottom: 12px; }
.bc-items .card + .card { margin-top: 0; }
.bc-item-card { padding: 12px 14px; }
.bc-editor { display: grid; gap: 8px; margin-top: 8px; }
.bc-editor textarea.field { width: 100%; }
.bc-action { display: grid; grid-template-columns: minmax(0, 1fr) 150px minmax(0, 1.4fr); gap: 6px; flex: 1; }
.bc-areas { display: grid; gap: 4px; }
.bc-buttons { display: grid; gap: 6px; }
.bc-buttons .actions { flex-wrap: nowrap; }
.bc-card-editors { display: grid; gap: 10px; }
.bc-card-editor { padding: 12px; display: grid; gap: 8px; background: var(--surface-2); }
.bc-thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.bc-sticker-grid { max-height: 220px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; padding: 4px; }
.sticker-tile.active { outline: 2px solid var(--accent); background: var(--accent-soft); }
.bc-json { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.bc-preview { position: sticky; top: 0; padding: 14px; border-radius: 14px; background: #8cabd9; display: grid; gap: 10px; align-content: start; min-height: 200px; }
.bc-preview-head { font-size: 12.5px; color: #fff; font-weight: 600; opacity: 0.9; }
.bc-preview-item { display: grid; justify-items: start; }
.bc-bubble { max-width: 100%; padding: 8px 12px; border-radius: 14px; background: #fff; color: #222; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bc-bubble .hint { color: #777; }
.bc-pic, .bc-rich img { max-width: 100%; border-radius: 12px; display: block; }
.bc-sticker { width: 110px; height: 110px; object-fit: contain; }
.bc-rich { position: relative; width: 100%; }
.bc-rich-grid { position: absolute; inset: 0; display: grid; }
.bc-rich-grid span { display: flex; align-items: center; justify-content: center; border: 1px dashed rgba(255, 255, 255, 0.85); color: #fff; font-weight: 700; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }
.bc-rich.layout-2h .bc-rich-grid { grid-template-columns: 1fr 1fr; }
.bc-rich.layout-2v .bc-rich-grid { grid-template-rows: 1fr 1fr; }
.bc-rich.layout-3v .bc-rich-grid { grid-template-rows: 1fr 1fr 1fr; }
.bc-rich.layout-4 .bc-rich-grid { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.bc-cards { display: flex; gap: 8px; overflow-x: auto; max-width: 100%; padding-bottom: 4px; }
.bc-card { flex: 0 0 170px; display: grid; gap: 4px; padding: 0 0 10px; border-radius: 12px; background: #fff; color: #222; font-size: 13px; overflow: hidden; }
.bc-card img { width: 100%; aspect-ratio: 20 / 13; object-fit: cover; display: block; }
.bc-card b, .bc-card p, .bc-card .bc-price, .bc-card .bc-code { margin: 0 10px; }
.bc-card b { margin-top: 8px; }
.bc-card p { color: #666; font-size: 12.5px; white-space: pre-wrap; }
.bc-price { color: #1a7f4b; font-weight: 700; }
.bc-btn { margin: 4px 10px 0; padding: 6px; border-radius: 8px; background: #06c755; color: #fff; text-align: center; font-weight: 600; font-size: 12.5px; }
.bc-btn ~ .bc-btn { background: #eef1f4; color: #222; }
.bc-coupon { flex-basis: 220px; padding-top: 10px; }
.bc-code { padding: 8px 10px; border-radius: 8px; background: #f2f8f4; color: #1a7f4b; font-weight: 800; font-size: 18px; letter-spacing: 1px; }
.bc-report h3 { margin: 14px 0 6px; font-size: 15px; }
.bc-failures { margin: 0; padding-left: 20px; font-size: 14px; }
.bc-failures li { margin-bottom: 4px; }
.msg .who .free-tag.bc-tag { background: var(--info-soft); color: var(--info); }
@media (max-width: 860px) {
  .bc-editor-grid { grid-template-columns: 1fr; }
  .bc-preview { position: static; }
  .bc-action { grid-template-columns: 1fr; }
}
.log-oa { cursor: pointer; border: 0; font: inherit; font-size: 12px; }
.log-oa:hover { text-decoration: underline; }
.log-chat { text-decoration: none; }
.log-chat:hover { text-decoration: underline; }
#logs-oa { max-width: 240px; min-height: 36px; padding: 4px 10px; font-size: 14px; }

/* รุ่น 38: การ์ดแบรนด์แบบย่อ/กาง ค้นหา และตัวกรองแบรนด์ของรายการ LINE OA */
#brands h2 .hint { font-weight: 400; font-size: 13px; margin-left: 6px; }
#brands.collapsed { padding-top: 12px; padding-bottom: 12px; }
.oa-filter { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 0 0 12px; }
.oa-filter .field { width: auto; min-width: 220px; max-width: 100%; }

/* ---------- ธีมหน้าเว็บ (รุ่น 39) ---------- */
/* เลือกได้ที่มุมล่างของเมนูซ้าย จำไว้ในเบราว์เซอร์ของแต่ละคน · ค่าเริ่มต้น = Ivory Gold · Sunset Orange = ตัวเลือกที่ 3 · "คลาสสิก" = ธีมเดิมด้านบนทั้งหมด (รวมโหมดมืดตามระบบ)
   Ivory Gold และ Sunset Orange ซ้อนทับเฉพาะตัวแปรสีกับของตกแต่งไม่กี่จุด ไม่แตะโครงหน้า จึงไม่กระทบการทำงานของหน้าใด ๆ และเป็นธีมสว่างเสมอ (ไม่ตามโหมดมืดของระบบ)
   ห้ามทับสไตล์พื้นฐานของ .btn / .card / .toast / .field ใต้ html[data-theme] เพราะความจำเพาะจะไปชนะ .btn.danger:hover, .toast.err ฯลฯ ทับได้เฉพาะตัวแปรกับส่วนที่เป็นสีเน้น */
html[data-theme="ivory"] {
  --bg: #f5f1e9;
  --surface: #fffdf9;
  --surface-2: #f2ecdf;
  --border: #e4dac6;
  --border-strong: #cdbf9f;
  --text: #241d13;
  --muted: #7b7061;
  --accent: #a9863b;
  --accent-strong: #8a6a25;
  --accent-soft: #f4ead3;
  --accent-ink: #fff8e6;
  --danger: #b5343d;
  --danger-soft: #fbe9e8;
  --warn: #8a5a00;
  --warn-soft: #fbefd3;
  --info: #3f5c95;
  --info-soft: #e9eef8;
  --shadow: 0 1px 2px rgba(60, 40, 10, 0.06), 0 8px 24px rgba(60, 40, 10, 0.08);
  --radius: 14px;
  --gold: #a9863b;
  --gold-hi: #d9bd78;
  color-scheme: light;
}
html[data-theme="ivory"] body { background: radial-gradient(1000px 520px at 85% -10%, rgba(169, 134, 59, 0.12), transparent 60%), var(--bg); }
html[data-theme="ivory"] h1 { font-weight: 600; letter-spacing: 0.01em; }
html[data-theme="ivory"] h2 { font-weight: 600; }
html[data-theme="ivory"] .page-head h1::after { content: ''; display: block; width: 40px; height: 2px; margin-top: 7px; background: linear-gradient(90deg, var(--gold), transparent); border-radius: 2px; }
/* แถบเมนูซ้าย */
html[data-theme="ivory"] .side { background: linear-gradient(180deg, #fbf8f1, #f3eee3); }
html[data-theme="ivory"] .brand { letter-spacing: 0.01em; font-weight: 600; } /* 0.03em ทำให้ชื่อระบบตกเป็น 2 บรรทัดในเมนูกว้าง 226px */
html[data-theme="ivory"] .brand-mark { box-shadow: 0 4px 12px rgba(15, 23, 42, 0.22); }
html[data-theme="ivory"] .nav a { color: #5c5346; border-left: 2px solid transparent; border-radius: 0 10px 10px 0; }
html[data-theme="ivory"] .nav a:hover { color: var(--text); background: rgba(169, 134, 59, 0.07); }
html[data-theme="ivory"] .nav a.active { color: var(--accent-strong); background: linear-gradient(90deg, rgba(169, 134, 59, 0.18), transparent); border-left-color: var(--gold); }
html[data-theme="ivory"] .count { background: var(--gold); color: #fff8e6; }
/* ปุ่มหลัก ป้าย แท็บ */
html[data-theme="ivory"] .btn.primary { background: linear-gradient(135deg, #c9a85c, var(--gold) 60%, #8a6a25); border-color: transparent; color: #fff8e6; font-weight: 650; box-shadow: 0 4px 14px rgba(169, 134, 59, 0.28); }
html[data-theme="ivory"] .btn.primary:hover { background: linear-gradient(135deg, #d4b66c, #b59147 60%, #957330); border-color: transparent; }
html[data-theme="ivory"] .chip.ok { box-shadow: inset 0 0 0 1px rgba(169, 134, 59, 0.3); }
html[data-theme="ivory"] .tab.active { color: var(--accent-strong); border-bottom-color: var(--gold); }
html[data-theme="ivory"] .seg-btn.active { background: var(--surface); color: var(--accent-strong); box-shadow: inset 0 0 0 1px rgba(169, 134, 59, 0.35); }
html[data-theme="ivory"] .toast.ok { background: #8a6a25; }
html[data-theme="ivory"] .bot-card:hover { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(169, 134, 59, 0.25), var(--shadow); }
/* กล่องข้อความ */
html[data-theme="ivory"] .conv.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--gold); }
html[data-theme="ivory"] .chat { background: #f6f1e7; }
html[data-theme="ivory"] .msg.assistant .bubble { background: var(--accent-soft); border: 1px solid rgba(169, 134, 59, 0.22); }
/* หน้าเข้าสู่ระบบ */
html[data-theme="ivory"] .login { background: radial-gradient(900px 520px at 50% 0%, rgba(169, 134, 59, 0.2), transparent 60%), var(--bg); }
html[data-theme="ivory"] .login .card { border-color: #dfcfa6; box-shadow: 0 30px 70px rgba(60, 40, 10, 0.18); padding: 34px 30px; }
html[data-theme="ivory"] .login .brand { justify-content: center; font-size: 18px; letter-spacing: 0.06em; }
html[data-theme="ivory"] .login .brand-mark { width: 40px; height: 40px; }
/* กราฟแดชบอร์ด: แท่ง "แอดมิน" เป็นทองแดง จะได้ไม่กลืนกับแท่ง "บอท" สีทอง */
html[data-theme="ivory"] .bar.admin, html[data-theme="ivory"] .key.admin::before { background: #b86b3a; }
/* Sunset Orange (ตัวเลือกที่ 3): พื้นเทาอุ่น การ์ดขาวนวล ส้มสดเป็นสีเน้น ตัวหนังสือเข้ม · โครงเดียวกับ Ivory Gold (ตัวแปร + ของตกแต่งไม่กี่จุด) */
html[data-theme="sunset"] {
  --bg: #e6e1dc;
  --surface: #fbf9f7;
  --surface-2: #efebe7;
  --border: #d8d1ca;
  --border-strong: #c2b8ae;
  --text: #16130f;
  --muted: #6b625a;
  --accent: #f55200;
  --accent-strong: #c23f00;
  --accent-soft: #ffe7d6;
  --accent-ink: #ffffff;
  --danger: #c4302b;
  --danger-soft: #fde6e3;
  --warn: #9a5d00;
  --warn-soft: #fff0d2;
  --info: #2f5fa8;
  --info-soft: #e6eefb;
  --shadow: 0 1px 2px rgba(40, 20, 0, 0.06), 0 10px 28px rgba(40, 20, 0, 0.10);
  --radius: 14px;
  --sun: #ff5e0e;
  --sun-hi: #ff8c1a;
  --sun-deep: #d94600;
  --ink: #141a17;
  color-scheme: light;
}
html[data-theme="sunset"] body { background: radial-gradient(1100px 560px at 85% -12%, rgba(255, 94, 14, 0.16), transparent 60%), radial-gradient(700px 400px at -10% 100%, rgba(255, 140, 26, 0.10), transparent 60%), var(--bg); }
html[data-theme="sunset"] h1 { font-weight: 700; letter-spacing: -0.01em; }
html[data-theme="sunset"] h2 { font-weight: 650; }
html[data-theme="sunset"] .page-head h1::after { content: ''; display: block; width: 44px; height: 3px; margin-top: 7px; background: linear-gradient(90deg, var(--sun), var(--sun-hi) 70%, transparent); border-radius: 3px; }
/* แถบเมนูซ้าย */
html[data-theme="sunset"] .side { background: linear-gradient(180deg, #f3efeb, #e9e4df); }
html[data-theme="sunset"] .brand { font-weight: 700; letter-spacing: 0.01em; }
html[data-theme="sunset"] .brand-mark { box-shadow: 0 6px 16px rgba(15, 23, 42, 0.25); }
html[data-theme="sunset"] .nav a { color: #4d4540; border-left: 3px solid transparent; border-radius: 0 12px 12px 0; }
html[data-theme="sunset"] .nav a:hover { color: var(--text); background: rgba(255, 94, 14, 0.08); }
html[data-theme="sunset"] .nav a.active { color: var(--accent-strong); background: linear-gradient(90deg, rgba(255, 94, 14, 0.18), transparent); border-left-color: var(--sun); font-weight: 600; }
html[data-theme="sunset"] .count { background: var(--sun); color: #fff; }
/* ปุ่มหลัก ป้าย แท็บ */
html[data-theme="sunset"] .btn.primary { background: linear-gradient(135deg, #ff7a2e, var(--accent) 55%, var(--sun-deep)); border-color: transparent; color: #fff; font-weight: 650; box-shadow: 0 6px 16px rgba(245, 82, 0, 0.30); }
html[data-theme="sunset"] .btn.primary:hover { background: linear-gradient(135deg, #ff8a45, #ff5e0e 55%, #e04a00); border-color: transparent; }
html[data-theme="sunset"] .chip.ok { box-shadow: inset 0 0 0 1px rgba(245, 82, 0, 0.30); }
html[data-theme="sunset"] .tab.active { color: var(--accent-strong); border-bottom-color: var(--sun); }
html[data-theme="sunset"] .seg-btn.active { background: var(--surface); color: var(--accent-strong); box-shadow: inset 0 0 0 1px rgba(245, 82, 0, 0.40); }
html[data-theme="sunset"] .toast.ok { background: var(--sun-deep); }
html[data-theme="sunset"] .bot-card:hover { border-color: var(--sun); box-shadow: 0 0 0 1px rgba(255, 94, 14, 0.30), var(--shadow); }
/* กล่องข้อความ */
html[data-theme="sunset"] .conv.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--sun); }
html[data-theme="sunset"] .chat { background: #ece7e2; }
html[data-theme="sunset"] .msg.assistant .bubble { background: var(--accent-soft); border: 1px solid rgba(245, 82, 0, 0.22); }
/* หน้าเข้าสู่ระบบ */
html[data-theme="sunset"] .login { background: radial-gradient(900px 540px at 50% 0%, rgba(255, 94, 14, 0.26), transparent 60%), var(--bg); }
html[data-theme="sunset"] .login .card { border-color: #e4c9b5; border-top: 4px solid var(--sun); box-shadow: 0 30px 70px rgba(40, 20, 0, 0.18); padding: 32px 30px; }
html[data-theme="sunset"] .login .brand { justify-content: center; font-size: 18px; }
html[data-theme="sunset"] .login .brand-mark { width: 40px; height: 40px; }
/* กราฟแดชบอร์ด: แท่ง "แอดมิน" เป็นสีเข้ม จะได้ไม่กลืนกับแท่ง "บอท" สีส้ม */
html[data-theme="sunset"] .bar.admin, html[data-theme="sunset"] .key.admin::before { background: #2b2622; }
/* ตัวเลือกธีมที่มุมล่างของเมนูซ้าย */
.theme-pick { display: flex; align-items: center; gap: 6px; padding: 2px 10px 6px; font-size: 13px; color: var(--muted); max-width: 100%; }
.theme-pick select { width: auto; min-height: 30px; padding: 2px 8px; font-size: 13px; border-radius: 7px; }
@media (max-width: 860px) {
  .theme-pick { padding: 0; }
  .theme-pick span { display: none; }
}
