/* Bảng điều khiển: người thuê + admin/CS */
.viz-root {
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-8: #e34948;
  --grid: #eef0f5;
}
body.console { background: #f4f5fa; }
.btn-danger { color: var(--danger); border-color: #fecaca !important; }
.shell { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; background: #0d1128; color: #c7cbe6; display: flex; flex-direction: column; padding: 20px 14px; overflow-y: auto; }
.sidebar .logo { color: #fff; padding: 0 8px 22px; }
.side-label { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: #6b7199; padding: 14px 12px 6px; }
.side-nav { display: grid; gap: 2px; }
.side-nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 11px; color: #c7cbe6; font-weight: 500; font-size: 14.5px; transition: background .15s, color .15s; }
.side-nav a .i { width: 22px; text-align: center; font-size: 16px; }
.side-nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.side-nav a.active { background: linear-gradient(135deg, rgba(91, 75, 255, .9), rgba(155, 92, 255, .9)); color: #fff; box-shadow: 0 8px 20px rgba(91, 75, 255, .35); }
.side-nav a .count { margin-left: auto; min-width: 22px; height: 20px; padding: 0 6px; border-radius: 10px; background: #ef4444; color: #fff; font-size: 11.5px; font-weight: 800; display: grid; place-items: center; }
.side-foot { margin-top: auto; padding: 14px 10px 0; }
.plan-card { background: linear-gradient(150deg, #1c2250, #141a3a); border: 1px solid rgba(255, 255, 255, .08); border-radius: 16px; padding: 16px; color: #fff; }
.plan-card small { color: #a3a9cc; }
.plan-card b { display: block; font-size: 17px; margin: 2px 0 10px; }
.meter { height: 7px; border-radius: 4px; background: rgba(255, 255, 255, .12); overflow: hidden; margin: 8px 0 12px; }
.meter i { display: block; height: 100%; background: linear-gradient(90deg, #22d3ee, #9b5cff); border-radius: 4px; }

.main { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 30; height: 66px; display: flex; align-items: center; gap: 14px; padding: 0 28px; background: rgba(244, 245, 250, .85); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 20px; margin: 0; }
.topbar .sp { flex: 1; }
.topbar .mob-menu { display: none; background: none; border: 0; font-size: 22px; cursor: pointer; }
.icon-btn { position: relative; width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: #fff; display: grid; place-items: center; cursor: pointer; font-size: 17px; flex: none; }
.icon-btn:hover { border-color: #c9cde0; }
.icon-btn .dot { position: absolute; top: 7px; right: 8px; width: 9px; height: 9px; border-radius: 50%; background: #ef4444; border: 2px solid #fff; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 5px 12px 5px 5px; border-radius: 999px; background: #fff; border: 1px solid var(--line); font-weight: 600; font-size: 14px; cursor: pointer; }
.user-chip .av { width: 30px; height: 30px; border-radius: 50%; background: var(--grad); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 800; overflow: hidden; }
.user-chip .av img { width: 100%; height: 100%; object-fit: cover; }
.content { padding: 26px 28px 60px; max-width: 1480px; }
.view { display: none; animation: pop .3s var(--ease); }
.view.active { display: block; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar .sp { flex: 1; }
.seg { display: inline-flex; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: none; padding: 7px 14px; border-radius: 9px; font-weight: 600; font-size: 13.5px; cursor: pointer; color: var(--muted); }
.seg button.active { background: var(--ink); color: #fff; }

.card { background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 22px; min-width: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-head h3 { font-size: 16.5px; margin: 0; }
.card-head p { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; }
.grid { display: grid; gap: 18px; }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-21 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.g-12 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.mt { margin-top: 18px; }

.kpi { position: relative; overflow: hidden; }
.kpi .lbl { color: var(--muted); font-size: 13.5px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.kpi .lbl .ic { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-size: 15px; background: var(--bg-2); }
.kpi .val { font-size: 30px; font-weight: 800; letter-spacing: -.03em; margin: 10px 0 4px; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: 13px; font-weight: 700; }
.kpi .delta.up { color: #047857; }
.kpi .delta.down { color: #b42318; }
.kpi .delta span { color: var(--muted); font-weight: 500; }
.kpi.hero { background: linear-gradient(150deg, #1c2250, #0d1128); color: #fff; border: 0; }
.kpi.hero .lbl { color: #a3a9cc; }
.kpi.hero .lbl .ic { background: rgba(255, 255, 255, .08); }
.kpi.hero .delta span { color: #a3a9cc; }
.kpi.hero .delta.up { color: #6ee7b7; }

.chart-box { position: relative; height: 290px; }
.chart-box.sm { height: 230px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }

.funnel { display: grid; gap: 10px; }
.fn-row { display: grid; grid-template-columns: 190px 1fr 110px; gap: 12px; align-items: center; font-size: 14px; }
.fn-bar { height: 34px; background: var(--bg-2); border-radius: 8px; overflow: hidden; }
.fn-bar i { display: block; height: 100%; background: #2a78d6; border-radius: 0 8px 8px 0; transition: width 1s var(--ease); }
.fn-row:nth-child(2) .fn-bar i { background: #4a8fe0; }
.fn-row:nth-child(3) .fn-bar i { background: #6aa6e9; }
.fn-row:nth-child(4) .fn-bar i { background: #1baf7a; }
.fn-val { text-align: right; font-variant-numeric: tabular-nums; }
.fn-val b { display: block; font-size: 16px; }
.fn-val small { color: var(--muted); }

.reasons { display: grid; gap: 12px; }
.reason { display: grid; grid-template-columns: minmax(0, 1fr) 54px; gap: 4px 12px; align-items: center; cursor: default; }
.reason .name { font-size: 14px; font-weight: 600; }
.reason .pct { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.reason .bar { grid-column: 1 / -1; height: 10px; border-radius: 5px; background: var(--bg-2); overflow: hidden; }
.reason .bar i { display: block; height: 100%; background: #2a78d6; border-radius: 0 5px 5px 0; }
.reason .tip { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); }

.heat { display: grid; grid-template-columns: 44px repeat(24, minmax(0, 1fr)); gap: 3px; font-size: 11px; color: var(--muted); }
.heat .c { aspect-ratio: 1; border-radius: 4px; background: #eef4fc; position: relative; }
.heat .c:hover { outline: 2px solid var(--ink); z-index: 1; }
.heat .h { text-align: center; }
.heat .d { display: flex; align-items: center; font-weight: 600; }
.heat-scale { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.heat-scale i { width: 18px; height: 10px; border-radius: 3px; }

.insights { display: grid; gap: 12px; }
.insight { display: flex; gap: 12px; padding: 14px; border-radius: 14px; background: var(--bg-2); }
.insight .ic { font-size: 22px; flex: none; }
.insight b { display: block; font-size: 14.5px; margin-bottom: 2px; }
.insight p { margin: 0; font-size: 13.5px; color: var(--muted); }
.insight.ai { background: linear-gradient(135deg, #efedff, #fdf2f8); }

.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 12px; border-bottom: 1px solid #f0f1f6; vertical-align: middle; }
.tbl tr:hover td { background: #fafbff; }
.tbl tr.click { cursor: pointer; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.who2 { display: flex; align-items: center; gap: 10px; }
.who2 .av { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 13px; color: #fff; flex: none; }
.who2 small { display: block; color: var(--muted); font-size: 12.5px; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.b-green { background: #dcfce7; color: #166534; } .b-red { background: #fee2e2; color: #991b1b; } .b-amber { background: #fef3c7; color: #92400e; }
.b-blue { background: #dbeafe; color: #1e40af; } .b-violet { background: #ede9fe; color: #5b21b6; } .b-gray { background: #f1f5f9; color: #475569; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.fld { display: grid; gap: 6px; font-weight: 600; font-size: 14px; color: var(--ink-2); }
.fld small { font-weight: 400; color: var(--muted); }
.console input:not([type=checkbox]):not([type=radio]):not([type=color]), .console textarea, .console select {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 10px 13px; font-size: 14.5px; font-weight: 400; background: #fff; outline: none; transition: border-color .15s, box-shadow .15s; resize: vertical;
}
.console input:focus, .console textarea:focus, .console select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(91, 75, 255, .12); }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: #cbd5e1; cursor: pointer; transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.save-bar { position: sticky; bottom: 16px; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--ink); color: #fff; padding: 12px 14px 12px 20px; border-radius: 16px; margin-top: 20px; box-shadow: var(--shadow-lg); }
.save-bar[hidden] { display: none; }

.empty { text-align: center; color: var(--muted); padding: 34px 20px; border: 1px dashed var(--line); border-radius: 16px; }

/* inbox */
.inbox { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 0; background: #fff; border: 1px solid var(--line); border-radius: 20px; overflow: hidden; height: calc(100vh - 160px); min-height: 520px; }
.inbox.with-side { grid-template-columns: 320px minmax(0, 1fr) 280px; }
.ib-list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.ib-filter { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.ib-items { overflow-y: auto; flex: 1; }
.ib-item { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid #f2f3f8; cursor: pointer; position: relative; }
.ib-item:hover { background: #fafbff; }
.ib-item.active { background: var(--brand-soft); }
.ib-item .av { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; flex: none; position: relative; }
.ib-item .av .chm { position: absolute; right: -3px; bottom: -3px; }
.ib-item .body { min-width: 0; flex: 1; }
.ib-item .top { display: flex; justify-content: space-between; gap: 8px; }
.ib-item .top b { font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ib-item .top small { color: var(--muted); font-size: 12px; white-space: nowrap; }
.ib-item .pv { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 2px 0 4px; }
.ib-item .unread { position: absolute; right: 12px; bottom: 14px; min-width: 20px; height: 20px; border-radius: 10px; background: var(--brand); color: #fff; font-size: 11px; font-weight: 800; display: grid; place-items: center; }
.ib-thread { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.ib-head { padding: 12px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ib-head b { font-size: 16px; }
.ib-msgs { flex: 1; overflow-y: auto; padding: 18px; background: #f7f8fc; display: flex; flex-direction: column; gap: 8px; }
.ib-msgs .msg { max-width: 72%; }
.ib-msgs .msg.mine { align-self: flex-end; background: var(--grad); color: #fff; border-bottom-right-radius: 6px; }
.ib-msgs .msg.theirs { align-self: flex-start; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .06); }
.ib-msgs .msg.fu { align-self: flex-end; background: #fff7ed; color: var(--ink); border: 1px dashed #fdba74; }
.ib-msgs .msg.st { align-self: flex-end; background: #ecfdf5; color: var(--ink); }
.ib-msgs .meta { font-size: 11px; opacity: .7; margin-top: 3px; display: block; }
.ib-msgs .att { display: inline-block; margin-top: 6px; font-size: 12.5px; background: rgba(255, 255, 255, .25); padding: 3px 8px; border-radius: 8px; }
.ib-compose { border-top: 1px solid var(--line); padding: 12px; display: grid; gap: 8px; }
.ib-compose .row { display: flex; gap: 8px; }
.ib-compose textarea { min-height: 44px; }
.tpl { display: flex; gap: 6px; flex-wrap: wrap; }
.tpl button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 10px; font-size: 12.5px; cursor: pointer; max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tpl button:hover { border-color: var(--brand); color: var(--brand); }
.ib-side { border-left: 1px solid var(--line); padding: 18px; overflow-y: auto; font-size: 14px; }
.ib-side h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 16px 0 8px; }
.kv { display: grid; gap: 6px; }
.kv div { display: flex; justify-content: space-between; gap: 8px; }
.kv span { color: var(--muted); }

/* bot builder */
.industry-grid.compact { grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); gap: 12px; }
.industry-grid.compact .industry { padding: 14px; }
.industry-grid.compact .industry .ic { width: 44px; height: 44px; font-size: 22px; }
.tone-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.tone { text-align: left; padding: 13px 15px; border: 1px solid var(--line); border-radius: 14px; background: #fff; cursor: pointer; }
.tone b { display: block; font-size: 14.5px; }
.tone span { color: var(--muted); font-size: 12.5px; }
.tone.selected { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 3px rgba(91, 75, 255, .15); }
.faq-item { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 10px; align-items: start; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg-2); }
.faq-item .kw { grid-column: 1 / 3; }
.upload-zone { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; padding: 26px; border: 2px dashed #c9c2ff; border-radius: 18px; background: #fbfaff; }
.upload-zone.drag { border-color: var(--brand); background: var(--brand-soft); }
.link { background: none; border: 0; padding: 0; color: var(--brand); font-weight: 600; cursor: pointer; text-decoration: underline; font-size: inherit; }
.attach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 14px; margin-top: 16px; }
.att { border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: #fff; }
.att-thumb { height: 110px; background: var(--bg-2); display: grid; place-items: center; font-size: 38px; position: relative; }
.att-thumb img { width: 100%; height: 100%; object-fit: cover; }
.att-thumb .badge { position: absolute; top: 8px; left: 8px; }
.att-thumb .icon-btn { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; }
.att-body { padding: 12px; display: grid; gap: 6px; }
.att-body .lbl { font-size: 12px; font-weight: 600; color: var(--muted); }
.builder { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 22px; align-items: start; }
.builder .preview { position: sticky; top: 86px; }
.builder .phone { width: 100%; }
.builder .phone-screen { height: calc(100vh - 220px); min-height: 460px; max-height: 660px; }
.builder .phone-top { padding-top: 40px; }
.ch-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.ch-card { display: flex; gap: 14px; align-items: center; padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: #fff; cursor: pointer; text-align: left; width: 100%; }
.ch-card:hover { border-color: var(--brand); box-shadow: var(--shadow); }
.ch-card b { display: block; font-size: 16px; }
.ch-card .status { font-size: 13px; color: var(--muted); }
.ch-card .status.on { color: var(--accent); font-weight: 600; }
.ch-card .go { margin-left: auto; font-size: 13px; font-weight: 600; color: var(--brand); white-space: nowrap; }
.rule { border: 1px solid var(--line); border-radius: 18px; padding: 18px; background: #fff; display: grid; gap: 12px; }
.rule.off { opacity: .65; }
.rule-head { display: flex; align-items: center; gap: 12px; }
.rule-head input.name { font-weight: 700; font-size: 15.5px; border-color: transparent !important; padding-left: 0 !important; box-shadow: none !important; }
.rule-grid { display: grid; grid-template-columns: 1.4fr .8fr 1fr; gap: 12px; }
.rule-stat { font-size: 13px; color: var(--muted); }
.vars { font-size: 12.5px; color: var(--muted); }
.vars code { background: var(--bg-2); padding: 1px 6px; border-radius: 6px; cursor: pointer; }

/* modal & drawer */
.modal { position: fixed; inset: 0; z-index: 100; background: rgba(13, 17, 40, .5); display: grid; place-items: center; padding: 16px; backdrop-filter: blur(3px); }
.modal[hidden] { display: none; }
.modal-card { position: relative; background: #fff; border-radius: 22px; width: min(600px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 28px; animation: pop .2s ease-out; }
.modal-card.wide { width: min(980px, 100%); }
.modal-x { position: absolute; top: 14px; right: 14px; width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--bg-2); font-size: 22px; cursor: pointer; }
.modal h3 { display: flex; align-items: center; gap: 12px; font-size: 20px; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { background: var(--bg-2) !important; font-size: 13px !important; }
.drop { position: absolute; right: 0; top: 48px; width: 360px; max-height: 460px; overflow-y: auto; background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); z-index: 40; padding: 8px; }
.drop[hidden] { display: none; }
.notif { padding: 10px 12px; border-radius: 12px; display: block; color: var(--ink); }
.notif:hover { background: var(--bg-2); }
.notif.unread { background: #f5f3ff; }
.notif b { display: block; font-size: 14px; }
.notif p { margin: 2px 0; font-size: 13px; color: var(--muted); }
.notif small { color: var(--muted); font-size: 12px; }

.pp-preview { transform: scale(.82); transform-origin: top center; }
.pp-preview .pp { animation: none; }

@media (max-width: 1280px) {
  .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .inbox.with-side { grid-template-columns: 300px minmax(0, 1fr); }
  .inbox.with-side .ib-side { display: none; }
}
@media (max-width: 1100px) {
  .builder { grid-template-columns: minmax(0, 1fr); }
  .builder .preview { position: static; }
  .g-21, .g-12, .g-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; z-index: 70; left: 0; top: 0; width: 270px; transform: translateX(-100%); transition: transform .3s var(--ease); }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .4); }
  .topbar { padding: 0 16px; }
  .topbar .mob-menu { display: block; }
  .user-chip span.nm { display: none; }
  .content { padding: 18px 16px 60px; }
  .inbox, .inbox.with-side { grid-template-columns: minmax(0, 1fr); height: auto; }
  .ib-list { max-height: 360px; border-right: 0; border-bottom: 1px solid var(--line); }
  .ib-msgs { min-height: 360px; }
  .ch-grid, .form-grid, .rule-grid { grid-template-columns: minmax(0, 1fr); }
  .faq-item { grid-template-columns: 1fr; }
  .faq-item .kw { grid-column: auto; }
  .fn-row { grid-template-columns: 110px 1fr 70px; font-size: 12.5px; }
  .heat { grid-template-columns: 30px repeat(24, minmax(0, 1fr)); gap: 2px; font-size: 9px; }
  .drop { width: min(340px, calc(100vw - 32px)); right: -60px; }
}
@media (max-width: 560px) {
  .g-4, .g-2 { grid-template-columns: minmax(0, 1fr); }
  #modeBadge { display: none !important; }
  .topbar { gap: 8px; }
  .topbar h1 { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .kpi .val { font-size: 26px; }
}

.side-nav a .count[hidden] { display: none; }
