/* Torb Hai dashboard — โทนครีม+เส้นวาดมือ ให้ตรงกับ public-site (rebrand 9 ก.ค. 2026) */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@400;500;600;700;800&display=swap');
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #FAF8F2;
  --card: #ffffff;
  --ink: #0a0a0a;
  --muted: #6b5847;
  --line: #ececea;
  --chip: #f1f1ef;
  --accent: #e2574c;
  --accent-text: #c8483f;
  --green: #1a7f37;
  --red: #c03535;
  --amber-bg: #fdf3d7;
  --amber-ink: #7a5a00;
  --radius: 20px;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Georgia, 'Noto Serif Thai', serif;
}
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Noto Sans Thai', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.55;
}
a { color: inherit; }
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 20px 24px 80px; }

/* ---------- header ---------- */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 0 18px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; cursor: pointer; }
.brand .dot {
  width: 28px; height: 28px; border-radius: 9px; background: var(--ink); color: #fff;
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
}
.header-actions { display: flex; gap: 10px; align-items: center; }

.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 8px 16px; font-weight: 550;
  transition: background .15s;
}
.btn:hover { background: var(--chip); }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #333; }
.btn.danger { color: var(--red); border-color: #f0d9d9; }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn.icon { width: 38px; height: 38px; padding: 0; display: grid; place-items: center; font-size: 17px; }

/* ---------- stat cards ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--card); border-radius: var(--radius); padding: 18px 22px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 1px solid var(--line);
}
.stat .label { display: flex; align-items: center; gap: 10px; color: #555; font-weight: 500; }
.stat .label .ic {
  width: 34px; height: 34px; border-radius: 11px; background: var(--chip);
  display: grid; place-items: center; font-size: 15px;
}
.stat .num { font-size: 34px; font-weight: 650; letter-spacing: -1px; }

/* ---------- dry-run banner ---------- */
.banner {
  background: var(--amber-bg); color: var(--amber-ink);
  border-radius: 14px; padding: 10px 16px; margin-bottom: 16px;
  display: flex; align-items: center; gap: 10px; font-size: 14px;
}
.banner b { font-weight: 650; }
.banner .btn { margin-left: auto; background: transparent; border-color: #e5d39a; color: var(--amber-ink); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.tab {
  border: 1px solid var(--line); background: var(--card); color: #444;
  border-radius: 999px; padding: 7px 16px; font-weight: 500; font-size: 14px;
}
.tab.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---------- cards & tables ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 24px; margin-bottom: 16px;
}
.card h2 { font-size: 24px; font-weight: 650; letter-spacing: -.3px; }
.card .sub { color: var(--muted); font-size: 14px; margin-top: 2px; margin-bottom: 4px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 12.5px;
  padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td .name { font-weight: 600; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; white-space: nowrap; }
.link-btn {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 4px 11px; font-size: 12.5px; color: #444;
}
.link-btn:hover { background: var(--chip); }
.link-btn.danger { color: var(--red); }

.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  background: var(--chip); border-radius: 999px; padding: 3px 10px;
  font-size: 12.5px; color: #333; white-space: nowrap;
}
.chip.dark { background: var(--ink); color: #fff; }

.badge { border-radius: 999px; padding: 2px 9px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge.sent { background: #e3f2e6; color: var(--green); }
.badge.dry_run { background: var(--chip); color: #666; }
.badge.error, .badge.skipped_no_token { background: #fbe4e4; color: var(--red); }
.badge.dm { background: #e8e8ff; color: #3b3bb3; }

.platform-ic { font-size: 13px; color: #555; display: inline-flex; align-items: center; gap: 4px; margin-right: 8px; }
.pmark {
  display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 6px;
  background: var(--ink); color: #fff; font-size: 10.5px; font-weight: 700;
}

/* ---------- toggle switch ---------- */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; border-radius: 999px; background: #d9d9d5; transition: .18s;
}
.switch .slider::before {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; top: 3px; left: 3px; transition: .18s; box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.switch input:checked + .slider { background: var(--ink); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* ---------- forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: #555; font-weight: 550; margin-bottom: 5px; }
.field .hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=password], input[type=search], textarea, select {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; background: #fff; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: #bbb; }
textarea { min-height: 92px; resize: vertical; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input[type=search] { max-width: 280px; }
.fchip {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 6px 14px; font-size: 13px; color: #444;
}
.fchip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.mini-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.mini-stat { background: var(--chip); border-radius: 14px; padding: 12px 16px; }
.mini-stat .k { font-size: 12.5px; color: var(--muted); }
.mini-stat .v { font-size: 22px; font-weight: 650; }

/* ---------- rule editor ---------- */
.editor-head { display: flex; align-items: center; gap: 14px; margin: 4px 0 18px; }
.editor-head h1 { font-size: 30px; font-weight: 650; letter-spacing: -.5px; }
.editor-head .sub { color: var(--muted); font-size: 14px; }
.back-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line);
  background: #fff; display: grid; place-items: center; font-size: 16px; flex: none;
}
.section-title { font-size: 19px; font-weight: 650; letter-spacing: -.2px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }

.pf-card { border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-top: 12px; }
.pf-head { display: flex; align-items: center; gap: 10px; }
.pf-head .grow { flex: 1; }
.pf-head .pf-name { font-weight: 600; }
.pf-head .pf-sub { font-size: 12.5px; color: var(--muted); }
.pf-body { margin-top: 12px; }
.posts-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px; margin-top: 10px; max-height: 340px; overflow-y: auto;
}
.post-card {
  position: relative; border: 2px solid var(--line); border-radius: 12px; overflow: hidden;
  cursor: pointer; background: #fff; text-align: left; padding: 0;
}
.post-card.selected { border-color: var(--ink); }
.post-card img { width: 100%; height: 90px; object-fit: cover; display: block; background: var(--chip); }
.post-card .noimg { width: 100%; height: 90px; background: var(--chip); display: grid; place-items: center; color: var(--muted); font-size: 20px; }
.post-card .cap { padding: 7px 9px; font-size: 12px; color: #444; height: 3.1em; overflow: hidden; }
.reel-badge {
  position: absolute; top: 6px; left: 6px; z-index: 1;
  background: rgba(0,0,0,.72); color: #fff; font-size: 10.5px; font-weight: 700;
  padding: 3px 7px; border-radius: 999px; letter-spacing: .01em;
}

.trigger-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  border: 1px solid var(--line); border-radius: 14px; padding: 13px 16px; margin-top: 10px;
}
.trigger-row .t-name { font-weight: 550; }
.trigger-row .t-sub { font-size: 12.5px; color: var(--muted); }

.radio-row {
  display: flex; align-items: flex-start; gap: 10px; border: 1px solid var(--line);
  border-radius: 14px; padding: 13px 16px; margin-top: 10px; cursor: pointer;
}
.radio-row input { margin-top: 4px; accent-color: var(--ink); }
.radio-row.selected { border-color: var(--ink); }

.pf-select { display: flex; gap: 8px; margin-top: 8px; }
.pf-chip {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 7px 15px; font-size: 13.5px; display: inline-flex; align-items: center; gap: 7px;
}
.pf-chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.editor-footer { display: flex; gap: 10px; justify-content: flex-end; align-items: center; margin-top: 4px; }
.editor-footer .spacer { flex: 1; }

/* ---------- import steps ---------- */
.step { display: flex; gap: 14px; margin-top: 18px; }
.step .n {
  width: 28px; height: 28px; border-radius: 50%; background: var(--ink); color: #fff;
  display: grid; place-items: center; font-size: 13px; font-weight: 650; flex: none;
}
.step .body { flex: 1; min-width: 0; }
.step .t { font-weight: 600; }
.step .d { color: var(--muted); font-size: 13.5px; }
pre.code {
  background: #191919; color: #e8e8e4; border-radius: 14px; padding: 14px 16px;
  font-size: 12px; line-height: 1.5; overflow-x: auto; margin-top: 10px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.code-wrap { position: relative; }
.code-wrap .copy {
  position: absolute; top: 10px; right: 10px; background: #333; color: #fff;
  border: 0; border-radius: 999px; padding: 4px 12px; font-size: 12px;
}
.dropzone {
  border: 2px dashed #d5d5d0; border-radius: 16px; padding: 32px; text-align: center;
  color: var(--muted); margin-top: 10px; cursor: pointer; transition: .15s;
}
.dropzone.drag { border-color: var(--ink); color: var(--ink); background: var(--chip); }

/* ---------- modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(20,20,20,.35);
  display: grid; place-items: center; z-index: 50; padding: 20px;
}
.modal {
  background: #fff; border-radius: var(--radius); padding: 26px;
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
}
.modal h3 { font-size: 20px; font-weight: 650; margin-bottom: 4px; }
.modal .sub { color: var(--muted); font-size: 13.5px; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; border-radius: 999px; padding: 10px 20px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 99;
  max-width: 90vw;
}
#toast.show { opacity: 1; }

.empty { text-align: center; color: var(--muted); padding: 36px 10px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- Easy Builder ---------- */
.ez-wrap { display: grid; grid-template-columns: 1fr 300px; gap: 24px; align-items: start; }
.ez-steps { min-width: 0; }
.ez-steps .card { margin-bottom: 0; }
.ez-steps > .card { margin-bottom: 18px; }

.ez-step { display: flex; gap: 14px; margin-bottom: 18px; }
.ez-step .grow { flex: 1; min-width: 0; }
.ez-badge-col { display: flex; flex-direction: column; align-items: center; padding-top: 20px; }
.ez-badge {
  background: #fff; border: 1.5px solid var(--ink); color: var(--ink);
  border-radius: 999px; font-size: 12.5px; font-weight: 650; padding: 4px 12px; white-space: nowrap;
}
.ez-badge.dark { background: var(--ink); color: #fff; }
.ez-line { flex: 1; width: 1.5px; background: #ddd; margin-top: 8px; min-height: 30px; }

.ez-preview { position: sticky; top: 20px; }
.ez-phone {
  background: var(--ink); border-radius: 38px; padding: 12px 10px 14px; position: relative;
  box-shadow: 0 12px 30px rgba(0,0,0,.14);
}
.ez-notch {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  width: 84px; height: 20px; background: var(--ink); border-radius: 0 0 14px 14px; z-index: 2;
}
.ez-screen {
  background: #fff; border-radius: 28px; min-height: 430px; padding: 34px 14px 18px;
  font-size: 12.5px; overflow: hidden;
}
.ezp-head {
  text-align: center; font-weight: 650; font-size: 12px; color: #555;
  border-bottom: 1px solid #f0f0f0; padding-bottom: 8px; margin-bottom: 12px;
}
.ezp-label {
  font-size: 10.5px; font-weight: 650; color: #999; text-transform: uppercase;
  letter-spacing: .4px; margin: 6px 0;
}
.ezp-empty { text-align: center; color: var(--muted); padding: 60px 8px; line-height: 1.7; }
.ezp-post { display: flex; align-items: center; gap: 7px; margin-bottom: 10px; opacity: .5; }
.ezp-postbar { height: 8px; border-radius: 4px; background: #e8e8e8; flex: 1; }
.ezp-avatar {
  width: 24px; height: 24px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
}
.ezp-avatar.u { background: #e4e4e4; }
.ezp-avatar.b { background: var(--ink); color: #fff; }
.ezp-comment { display: flex; gap: 7px; margin-bottom: 8px; }
.ezp-comment.ezp-reply { margin-left: 22px; }
.ezp-name { font-weight: 650; font-size: 11px; margin-bottom: 1px; }
.ezp-text { color: #333; word-break: break-word; white-space: pre-wrap; }
.ezp-skip { color: #bbb; font-size: 11px; text-align: center; margin: 8px 0; }
.ezp-bubble {
  border-radius: 16px; padding: 8px 12px; max-width: 85%; margin-bottom: 8px;
  word-break: break-word; white-space: pre-wrap; line-height: 1.5;
}
.ezp-bubble.user { background: #f0f0f0; color: #222; border-bottom-left-radius: 5px; }
.ezp-bubble.page { background: var(--ink); color: #fff; margin-left: auto; border-bottom-right-radius: 5px; }
.ez-preview-note { text-align: center; color: var(--muted); font-size: 12px; margin-top: 10px; }

@media (max-width: 900px) {
  .ez-wrap { grid-template-columns: 1fr; }
  .ez-preview { position: static; max-width: 320px; margin: 0 auto; }
}

@media (max-width: 760px) {
  .stats { grid-template-columns: 1fr; }
  .mini-stats { grid-template-columns: repeat(2, 1fr); }
  .card { padding: 18px; }
  .ez-badge-col { display: none; }
}

/* ================= Flow Builder ================= */
.fb-top {
  display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.fb-top .name-input {
  font-size: 17px; font-weight: 650; border: 1px solid transparent; background: transparent;
  border-radius: 10px; padding: 6px 10px; min-width: 200px;
}
.fb-top .name-input:hover, .fb-top .name-input:focus { border-color: var(--line); background: var(--card); outline: none; }
.fb-badge {
  font-size: 12px; font-weight: 700; padding: 4px 12px; border-radius: 999px;
}
.fb-badge.draft { background: #f0f0ee; color: var(--muted); }
.fb-badge.live { background: #e5f6ea; color: var(--green); }
.fb-top .spacer { flex: 1; }
.fb-saved { font-size: 12.5px; color: var(--muted); }

.fb-wrap { display: grid; grid-template-columns: 1fr 320px; gap: 14px; align-items: start; }
.fb-canvas {
  position: relative; height: calc(100vh - 240px); min-height: 480px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; cursor: grab;
  background-image: radial-gradient(#e8e8e5 1.2px, transparent 1.2px);
  background-size: 22px 22px;
}
.fb-canvas.panning { cursor: grabbing; }
.fb-world { position: absolute; top: 0; left: 0; width: 0; height: 0; }
.fb-edges { position: absolute; top: 0; left: 0; overflow: visible; pointer-events: none; }
.fb-edges path { pointer-events: stroke; cursor: pointer; }
.fb-edges .edge { fill: none; stroke: #c9c9c4; stroke-width: 2.5; }
.fb-edges .edge:hover { stroke: var(--red); }
.fb-edges .edge-temp { fill: none; stroke: #999; stroke-width: 2.5; stroke-dasharray: 6 5; }
.fb-edges .edge-label { font-size: 10.5px; font-weight: 700; fill: var(--muted); pointer-events: none; }

.fb-node {
  position: absolute; width: 220px; background: var(--card); border: 1.5px solid var(--line);
  border-radius: 14px; box-shadow: 0 4px 14px -6px rgba(0,0,0,.12); user-select: none;
}
.fb-node.selected { border-color: var(--ink); box-shadow: 0 6px 20px -6px rgba(0,0,0,.25); }
.fb-node .head {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px; cursor: move;
  font-weight: 650; font-size: 13.5px; border-bottom: 1px solid var(--line);
}
.fb-node .head .ic {
  width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center; font-size: 12px; flex: none;
}
.fb-node.n-trigger .head .ic { background: #e8f0fe; }
.fb-node.n-message .head .ic { background: #e5f6ea; }
.fb-node.n-condition .head .ic { background: #fdf3d7; }
.fb-node.n-delay .head .ic { background: #f3e8fd; }
.fb-node.n-randomizer .head .ic { background: #fde8ec; }
.fb-node .body { padding: 9px 12px; font-size: 12.5px; color: var(--muted); min-height: 34px; word-break: break-word; }
.fb-node .body b { color: var(--ink); }

.fb-port {
  position: absolute; right: -8px; width: 15px; height: 15px; border-radius: 50%;
  background: var(--ink); border: 2.5px solid var(--card); cursor: crosshair; z-index: 2;
}
.fb-port:hover { transform: scale(1.25); }
.fb-port-label {
  position: absolute; right: 10px; font-size: 9.5px; font-weight: 700; color: var(--muted);
  transform: translateY(-1px); pointer-events: none;
}

.fb-toolbar {
  position: absolute; top: 12px; left: 12px; z-index: 5; display: flex; flex-direction: column; gap: 6px;
}
.fb-toolbar button {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px;
  padding: 7px 12px; font-size: 12.5px; font-weight: 600; text-align: left;
  box-shadow: 0 2px 8px -4px rgba(0,0,0,.15);
}
.fb-toolbar button:hover { background: var(--chip); }

.fb-panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; position: sticky; top: 16px; max-height: calc(100vh - 240px); overflow-y: auto;
}
.fb-panel h3 { font-size: 15px; margin-bottom: 4px; }
.fb-panel .hint { font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.fb-panel label { display: block; font-size: 12.5px; font-weight: 650; margin: 12px 0 5px; }
.fb-panel input[type=text], .fb-panel input[type=number], .fb-panel textarea, .fb-panel select {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 13.5px;
  background: var(--bg);
}
.fb-panel textarea { min-height: 84px; resize: vertical; }
.fb-panel .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fb-panel .chk { display: flex; align-items: center; gap: 7px; font-size: 13px; margin: 6px 0; font-weight: 500; }
.fb-panel .del-node { margin-top: 16px; width: 100%; }

.fb-empty-panel { color: var(--muted); font-size: 13px; text-align: center; padding: 30px 8px; }

.flow-runs { font-size: 12px; color: var(--muted); }

@media (max-width: 900px) {
  .fb-wrap { grid-template-columns: 1fr; }
  .fb-panel { position: static; max-height: none; }
}

/* ================= App shell (sidebar แบบ ManyChat) ================= */
.shell { display: flex; min-height: 100dvh; }
.side {
  width: 216px; flex: none; background: var(--card); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100dvh;
}
.side-brand {
  display: flex; align-items: center; gap: 9px; font-weight: 750; font-size: 16px;
  padding: 18px 18px 14px; cursor: pointer; text-decoration: none; color: inherit;
}
.side-logo { width: 30px; height: 28px; object-fit: contain; flex: none; }
.side-brand-name { font-family: var(--serif); font-style: italic; font-weight: 500; font-size: 20px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; flex: 1; }
.side-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 12px;
  font-size: 14px; font-weight: 550; color: #55554f; cursor: pointer; text-decoration: none;
  border: none; background: none; width: 100%; text-align: left; transition: background .15s, color .15s;
  min-height: 44px;
}
.side-item svg { width: 19px; height: 19px; flex: none; }
.side-item:hover { background: var(--chip); color: var(--ink); }
.side-item.active { background: var(--ink); color: #fff; font-weight: 650; }
.side-item:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.side-bottom { padding: 10px; border-top: 1px solid var(--line); }
.side-logout { color: var(--muted); font: inherit; font-size: 14px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 28px 10px; position: sticky; top: 0; z-index: 30;
  background: rgba(244,244,242,.9); backdrop-filter: blur(8px);
}
.page-title { font-size: 22px; font-weight: 750; letter-spacing: -.2px; }
.main .wrap { max-width: 1160px; width: 100%; }

/* ---------- หน้า Home ---------- */
.home-hello { font-size: 30px; font-weight: 800; letter-spacing: -.4px; margin: 8px 0 4px; }
.home-sub { color: var(--muted); font-size: 14.5px; margin-bottom: 22px; display: flex; gap: 18px; flex-wrap: wrap; }
.home-sub b { color: var(--ink); }
.home-section-head {
  display: flex; align-items: center; justify-content: space-between; margin: 26px 0 12px;
}
.home-section-head h2 { font-size: 19px; font-weight: 750; }
.tpl-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.tpl-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; cursor: pointer; text-align: left; font: inherit;
  display: flex; flex-direction: column; gap: 24px; min-height: 120px;
  transition: transform .18s ease, box-shadow .18s ease;
}
.tpl-card:hover { transform: translateY(-3px); box-shadow: 0 16px 32px -20px rgba(0,0,0,.25); }
.tpl-card .tpl-name { font-weight: 700; font-size: 15.5px; }
.tpl-card .tpl-foot { display: flex; align-items: center; justify-content: space-between; }
.tpl-card .tpl-kind { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.tpl-card .tpl-badge {
  font-size: 10.5px; font-weight: 800; letter-spacing: .05em; color: #7a4a00;
  background: #fdeccf; padding: 4px 9px; border-radius: 6px;
}
.next-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.next-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px;
}
.next-card .next-kicker { color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
.next-card .next-title { font-weight: 700; font-size: 15px; margin-bottom: 12px; }

/* ---------- sub-tabs (pills รอง ในหน้า Automation/Contacts) ---------- */
.subtabs { display: flex; gap: 8px; margin: 4px 0 16px; flex-wrap: wrap; }
.subtab {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 7px 16px; font-size: 13.5px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.subtab:hover { background: var(--chip); color: var(--ink); }
.subtab.active { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---------- Live Chat placeholder ---------- */
.soon-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 48px 32px; text-align: center;
}
.soon-card .soon-ic { font-size: 40px; margin-bottom: 14px; }
.soon-card h2 { font-size: 20px; margin-bottom: 8px; }
.soon-card p { color: var(--muted); font-size: 14.5px; max-width: 440px; margin: 0 auto 18px; }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .side {
    width: 100%; height: auto; position: static; flex-direction: row; align-items: center;
    border-right: none; border-bottom: 1px solid var(--line); padding: 4px 8px;
  }
  .side-brand { padding: 10px; }
  .side-brand-name { display: none; }
  .side-nav { flex-direction: row; overflow-x: auto; padding: 6px 4px; }
  .side-item { padding: 9px 11px; white-space: nowrap; }
  .side-item span { font-size: 12.5px; }
  .side-bottom { border-top: none; padding: 0 4px; }
  .side-logout span { display: none; }
  .topbar { padding: 12px 16px 8px; }
  .tpl-grid, .next-grid { grid-template-columns: 1fr; }
}

/* ================= Live Chat inbox ================= */
.chat-wrap {
  display: grid; grid-template-columns: 300px 1fr; gap: 0;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; height: calc(100dvh - 170px); min-height: 420px;
}
.chat-threads { border-right: 1px solid var(--line); overflow-y: auto; }
.chat-threads-head { padding: 14px 16px; font-weight: 700; font-size: 15px; border-bottom: 1px solid var(--line); }
.thread-item {
  display: flex; gap: 10px; align-items: center; width: 100%; text-align: left;
  padding: 12px 14px; border: none; background: none; font: inherit; cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.thread-item:hover { background: var(--chip); }
.thread-item.active { background: var(--chip); }
.thread-av {
  width: 38px; height: 38px; border-radius: 50%; flex: none; background: #e4e4e0;
  display: grid; place-items: center; font-weight: 700; font-size: 15px; color: #666;
}
.thread-info { min-width: 0; flex: 1; }
.thread-name { font-weight: 650; font-size: 13.5px; display: flex; align-items: center; gap: 6px; }
.thread-name .pmark { width: 16px; height: 16px; font-size: 8.5px; border-radius: 5px; }
.thread-last { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.thread-time { color: var(--muted); font-size: 11px; }
.thread-unread {
  background: var(--ink); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 5px;
}
.chat-pane { display: flex; flex-direction: column; min-width: 0; }
.chat-pane-head {
  padding: 13px 18px; border-bottom: 1px solid var(--line);
  font-weight: 700; font-size: 14.5px; display: flex; align-items: center; gap: 8px;
}
.chat-msgs { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.chat-bubble {
  max-width: 68%; padding: 9px 14px; border-radius: 16px; font-size: 14px; line-height: 1.5;
  word-break: break-word; white-space: pre-wrap;
}
.chat-bubble.in { background: var(--chip); align-self: flex-start; border-bottom-left-radius: 5px; }
.chat-bubble.out { background: var(--ink); color: #fff; align-self: flex-end; border-bottom-right-radius: 5px; }
.chat-bubble .chat-meta { display: block; font-size: 10.5px; opacity: .6; margin-top: 4px; }
.chat-empty { flex: 1; display: grid; place-items: center; color: var(--muted); font-size: 14px; text-align: center; padding: 30px; }
.chat-composer { display: flex; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); }
.chat-composer input {
  flex: 1; border: 1px solid var(--line); border-radius: 999px; padding: 10px 16px; font: inherit; background: var(--bg);
}
.chat-composer input:focus { outline: 2px solid var(--ink); outline-offset: -1px; }

@media (max-width: 900px) {
  .chat-wrap { grid-template-columns: 1fr; height: auto; }
  .chat-threads { max-height: 280px; border-right: none; border-bottom: 1px solid var(--line); }
  .chat-pane { min-height: 400px; }
}
