:root {
  --bg: #f6f7fb; --panel: #fff; --line: #e6e8ef; --text: #1d2030; --muted: #6b7085;
  --brand: #4f46e5; --brand-soft: #eef0ff; --ai: #7c3aed; --ai-soft: #f3edff;
  --agent: #2563eb; --ok: #16a34a; --warn: #d97706; --bad: #dc2626;
  --messenger: #0a7cff; --line-green: #06c755; --radius: 12px;
  --shadow: 0 1px 2px rgba(20,22,40,.06), 0 4px 16px rgba(20,22,40,.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Thai", sans-serif; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
h1 { font-size: 20px; margin: 0 0 4px; } h2 { font-size: 16px; margin: 0 0 10px; } h3 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }

.btn { border: 1px solid var(--line); background: var(--panel); padding: 8px 14px; border-radius: 9px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #cfd3e0; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.ai { background: var(--ai-soft); border-color: #e2d6ff; color: var(--ai); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password], input[type=number], input[type=date], input:not([type]), select, textarea {
  width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 8px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { resize: vertical; min-height: 70px; }
label.f { display: block; } label.f > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 99px; font-size: 11px; font-weight: 600; background: #eef0f5; color: var(--muted); }
.badge.messenger { background: #e6f1ff; color: var(--messenger); }
.badge.line { background: #e3f9ec; color: #059142; }
.badge.test { background: #fff4e0; color: var(--warn); }
.badge.human { background: #fde8e8; color: var(--bad); }
.badge.ai { background: var(--ai-soft); color: var(--ai); }
.badge.promotion { background: #fff1e6; color: #c2410c; } .badge.service { background: #e7f6ff; color: #0369a1; } .badge.product { background: #eef0ff; color: var(--brand); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }

/* switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch i { width: 36px; height: 20px; border-radius: 99px; background: #cfd3e0; position: relative; transition: .15s; }
.switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .15s; }
.switch input:checked + i { background: var(--ai); }
.switch input:checked + i::after { left: 18px; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; height: 100vh; height: 100dvh; }
.nav { background: #151735; color: #c9cbe6; display: flex; flex-direction: column; padding: 14px 10px; gap: 2px; }
.nav .logo { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 700; font-size: 16px; padding: 4px 8px 14px; }
.nav .logo img { width: 26px; }
.nav a { color: inherit; text-decoration: none; padding: 9px 10px; border-radius: 8px; display: flex; gap: 10px; align-items: center; }
.nav a:hover { background: #22244a; }
.nav a.on { background: #2d2f63; color: #fff; }
.nav .count { margin-left: auto; background: var(--bad); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 6px; }
.nav .me { margin-top: auto; padding: 10px; font-size: 12px; border-top: 1px solid #2a2c55; }
.nav .me button { background: none; border: 0; color: #9fa2d0; cursor: pointer; padding: 0; text-decoration: underline; }
.main { overflow: auto; min-width: 0; }
.page { padding: 22px; max-width: 1100px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }

/* inbox */
.inbox { display: grid; grid-template-columns: 330px 1fr; height: 100%; }
.convlist { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.convlist .filters { display: flex; gap: 4px; padding: 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.convlist .filters button { border: 0; background: none; padding: 5px 10px; border-radius: 99px; cursor: pointer; color: var(--muted); }
.convlist .filters button.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.convs { overflow: auto; flex: 1; }
.conv { padding: 11px 12px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid; grid-template-columns: 38px 1fr; gap: 10px; }
.conv:hover { background: #fafbff; } .conv.on { background: var(--brand-soft); }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; background: #9aa0b8; }
.avatar.messenger { background: var(--messenger); } .avatar.line { background: var(--line-green); } .avatar.test { background: var(--warn); }
.conv .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .preview { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.conv .unread { background: var(--brand); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 6px; }
.chat { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.chat-head { padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.msgs { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 72%; display: flex; flex-direction: column; }
.msg .bubble { padding: 9px 12px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 3px; display: flex; gap: 8px; align-items: center; }
.msg.in { align-self: flex-start; } .msg.in .bubble { background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg.agent .bubble { background: var(--agent); color: #fff; border-bottom-right-radius: 4px; }
.msg.ai .bubble { background: var(--ai); color: #fff; border-bottom-right-radius: 4px; }
.msg.system { align-self: center; max-width: 90%; } .msg.system .bubble { background: #eef0f5; color: var(--muted); font-size: 12px; border-radius: 8px; }
.msg .err { color: var(--bad); font-size: 11px; }
.msg .teach { opacity: 0; border: 0; background: none; color: var(--ai); cursor: pointer; font-size: 11px; padding: 0; }
.msg:hover .teach { opacity: 1; }
.typing { font-size: 12px; color: var(--ai); padding: 0 16px 6px; min-height: 18px; }
.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 10px 12px; }
.composer textarea { min-height: 44px; max-height: 180px; }
.empty { display: grid; place-items: center; height: 100%; color: var(--muted); text-align: center; padding: 30px; }
.back { display: none; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(135deg, #eef0ff, #f8f3ff); }
.login .card { width: 100%; max-width: 380px; padding: 28px; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15,17,40,.4); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; padding: 20px; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 9px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--brand); border-color: var(--brand); font-weight: 600; }

.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat b { display: block; font-size: 22px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.bar { height: 8px; background: #eef0f5; border-radius: 99px; overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; background: var(--ok); }
.provider { border: 2px solid var(--line); border-radius: 12px; padding: 12px; cursor: pointer; flex: 1; min-width: 160px; }
.provider.on { border-color: var(--brand); background: var(--brand-soft); }
.copy { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: #f2f3f8; padding: 6px 8px; border-radius: 6px; word-break: break-all; }
pre.prompt { white-space: pre-wrap; background: #f7f7fb; border: 1px solid var(--line); padding: 12px; border-radius: 8px; font-size: 12px; max-height: 60vh; overflow: auto; }

/* phone mock for test chat */
.phone { max-width: 420px; height: 620px; border: 1px solid var(--line); border-radius: 24px; display: flex; flex-direction: column; overflow: hidden; background: #f0f2f7; box-shadow: var(--shadow); }
.phone .msg.in { align-self: flex-end; align-items: flex-end; } .phone .msg.in .bubble { background: var(--line-green); color: #fff; border: 0; }
.phone .msg.out { align-self: flex-start; align-items: flex-start; } .phone .msg.out .bubble { background: #fff; color: var(--text); border: 1px solid var(--line); }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 99; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
#toast div { background: #1d2030; color: #fff; padding: 9px 16px; border-radius: 9px; box-shadow: var(--shadow); }
#toast div.bad { background: var(--bad); }

@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .nav { order: 2; flex-direction: row; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); overflow-x: auto; gap: 0; }
  .nav .logo, .nav .me, .nav .label { display: none; }
  .nav a { flex-direction: column; gap: 0; font-size: 20px; padding: 6px 12px; position: relative; }
  .nav .count { position: absolute; top: 2px; right: 4px; }
  .main { order: 1; }
  .page { padding: 16px; }
  .inbox { grid-template-columns: 1fr; }
  .inbox.open .convlist { display: none; } .inbox:not(.open) .chat { display: none; }
  .back { display: inline-block; }
  .msg { max-width: 86%; }
  .grid2 { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}
.nav a.acct { display: none; }
@media (max-width: 800px) { .nav a.acct { display: flex; } }

/* pictures */
.msg img.pic { max-width: 240px; max-height: 260px; border-radius: 14px; border: 1px solid var(--line); display: block; margin-top: 4px; object-fit: cover; background: #fff; }
.thumb { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; border: 1px solid var(--line); display: block; }
.thumb.noimg, .noimg { display: grid; place-items: center; background: #f2f3f8; color: var(--muted); width: 48px; height: 48px; border-radius: 8px; flex: none; }
.attach { display: flex; align-items: flex-start; gap: 6px; margin-bottom: 8px; }
.attach img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.prodpick { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px; cursor: pointer; }
.prodpick:hover { border-color: var(--brand); background: var(--brand-soft); }
.prodpick img { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; flex: none; }

/* account labels */
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; flex: none; }
.dot.pick { width: 22px; height: 22px; cursor: pointer; border: 3px solid transparent; }
input[name=color]:checked + .dot.pick { border-color: #fff; box-shadow: 0 0 0 2px var(--text); }
.acct-badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: 99px; font-size: 11px; font-weight: 600; background: #f2f3f8; color: var(--text); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-badge .dot { width: 8px; height: 8px; }
.convlist .accsel { padding: 8px 10px 0; }

/* broadcasts */
.msg.broadcast { align-self: flex-end; align-items: flex-end; }
.msg.broadcast .bubble { background: #fff4e0; color: #7c4a03; border: 1px solid #fde1b0; border-bottom-right-radius: 4px; }
.btn.fb { background: #1877f2; border-color: #1877f2; color: #fff; }

/* booking slots */
.slots { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.slot { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 10px; cursor: pointer; font-variant-numeric: tabular-nums; }
.slot:hover { border-color: var(--brand); }
.slot.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.tabs .count { background: var(--warn); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 6px; margin-left: 4px; }

/* review photos */
.revgroup { display: flex; gap: 8px; align-items: center; width: 100%; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.revgroup:hover { background: #f5f6fb; } .revgroup.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.revgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.revcard { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 6px; display: flex; flex-direction: column; gap: 6px; position: relative; }
.revcard img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; display: block; background: #f2f3f8; }
.revcard input:not([type=checkbox]) { font-size: 12px; padding: 5px 7px; }
.revgrid.pick .revcard { cursor: pointer; } .revgrid.pick .revcard.on { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
/* saved replies */
.composer { position: relative; }
.attach { flex-wrap: wrap; }
.att { position: relative; display: inline-flex; align-items: flex-start; gap: 2px; }
.convlist .accsel { display: flex; flex-direction: column; gap: 6px; }
.slashpop { position: absolute; left: 12px; right: 12px; bottom: 100%; margin-bottom: 4px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 280px; overflow: auto; z-index: 5; }
.slashpop button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; cursor: pointer; font: inherit; border-bottom: 1px solid var(--line); }
.slashpop button .small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slashpop button.on, .slashpop button:hover { background: var(--brand-soft); }
.saved-preview { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
.savedgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.savedcard { display: flex; flex-direction: column; gap: 8px; }
.saved-text { white-space: pre-wrap; font-size: 14px; max-height: 9.5em; overflow: hidden; }
.saved-pics { display: flex; flex-wrap: wrap; gap: 6px; }
.saved-pics img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
/* who is on a chat */
.badge.live { background: #fff4d6; color: #8a5a00; }
.presence { color: #8a5a00; font-weight: 500; }
/* booking calendar */
.page.wide { max-width: 1400px; }
.badge.new { background: #e6f7ec; color: #11743a; }
.calbar { margin-bottom: 8px; gap: 6px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 6px 12px; cursor: pointer; font: inherit; }
.seg button.on { background: var(--brand); color: #fff; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; margin-bottom: 8px; color: var(--muted); }
.lgi { white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; }
.lg.short { background: repeating-linear-gradient(45deg, #fff, #fff 3px, #e9e9ef 3px, #e9e9ef 6px); }
.lg { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; border: 1px solid var(--line); }
.lg.free, .c.free { background: #fff; }
.lg.booked, .c.booked { background: #e7e9ff; }
.lg.new, .c.booked.new { background: #dff5e6; }
.lg.busy, .c.busy { background: #eceef2; }
.lg.closed, .c.closed, .c.past { background: #f7f7f9; }
.c.short { background: repeating-linear-gradient(45deg, #fff, #fff 4px, #f3f3f7 4px, #f3f3f7 8px); cursor: pointer; }
.calwrap { overflow: auto; max-height: calc(100vh - 260px); border: 1px solid var(--line); border-radius: 12px; background: #fff; }
table.cal { border-collapse: separate; border-spacing: 0; width: 100%; table-layout: fixed; min-width: 100%; }
table.cal th, table.cal td { border-bottom: 1px solid #f0f0f4; border-left: 1px solid #f0f0f4; padding: 0; }
table.cal thead th { position: sticky; top: 0; background: #fff; z-index: 2; padding: 6px 4px; font-size: 13px; text-align: center; border-bottom: 1px solid var(--line); }
table.cal thead th.today { color: var(--brand); }
table.cal .tcol { width: 56px; position: sticky; left: 0; background: #fff; z-index: 1; font-size: 12px; color: var(--muted); font-weight: 500; text-align: right; padding-right: 6px; vertical-align: top; }
table.cal thead .tcol { z-index: 3; }
table.cal tr.hour td, table.cal tr.hour th { border-top: 1px solid #e3e4ea; }
.c { height: 38px; font-size: 12px; line-height: 1.35; vertical-align: top; overflow: hidden; }
.c.free { cursor: pointer; color: transparent; text-align: center; }
.c.free:hover { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.c.booked { cursor: pointer; border-left: 3px solid var(--brand) !important; padding: 2px 5px !important; }
.c.booked.new { border-left-color: #1d9b54 !important; }
.c.booked b, .c.booked span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c.booked span { color: var(--muted); }
.c.booked.cont { border-top-color: transparent; }
.c.booked.hl { filter: brightness(0.95); }
.c.busy { color: var(--muted); padding: 2px 5px !important; white-space: nowrap; text-overflow: ellipsis; }
.c.busy.cont { border-top-color: transparent; }
.allday { font-size: 11px; font-weight: 400; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.automsg { display: flex; flex-direction: column; gap: 8px; padding: 12px; }
.automsg.off { opacity: .6; }
table.cal.week { min-width: 760px; }
@media (max-width: 760px) { .calwrap { max-height: calc(100vh - 230px); } }
/* tags */
.tags { display: inline-flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; vertical-align: middle; }
.tag { --tc: #6366f1; display: inline-flex; align-items: center; gap: 2px; font-size: 11.5px; font-weight: 600; line-height: 1; padding: 3px 7px; border-radius: 999px;
  color: var(--tc); background: color-mix(in srgb, var(--tc) 13%, #fff); border: 1px solid color-mix(in srgb, var(--tc) 30%, #fff); white-space: nowrap; }
.tag button { border: 0; background: none; color: inherit; cursor: pointer; padding: 0 0 0 3px; font-size: 13px; line-height: 1; opacity: .7; }
.tag button:hover { opacity: 1; }
.tag.add { --tc: #64748b; cursor: pointer; border-style: dashed; background: #fff; font: inherit; font-size: 11.5px; font-weight: 600; }
.iconbtn { border: 0; background: none; cursor: pointer; padding: 0 2px; font-size: 13px; opacity: .55; }
.iconbtn:hover { opacity: 1; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
/* master AI switch */
.aimaster { margin: 8px 10px 0; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.aimaster.on { background: var(--ai-soft); border-color: #ddd0fb; }
.aimaster.off { background: #fff4e5; border-color: #f5c98b; }
.aimaster .small { color: var(--muted); }
.chat-head > .grow { flex: 1 1 240px; min-width: 200px; }
.chat-head .tags { display: flex; margin-top: 4px; }
