:root {
  --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', 'Noto Sans Tamil', 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --bg: #f4f6f9; --panel: #ffffff; --line: #e6eaf0; --text: #0f1b2d; --muted: #64748b;
  --nav: #101c2e; --nav-text: #c4cedd; --nav-active: #24395a;
  --accent: #2563eb; --accent-soft: #e8f0fe; --accent-text: #ffffff;
  --bubble-in: #ffffff; --bubble-out: #dcf4e4; --bubble-out-text: #12351f;
  --ok: #15803d; --ok-soft: #e1f6e8; --warn: #b45309; --warn-soft: #fff2de; --bad: #b91c1c; --bad-soft: #fde8e7;
  --chip: #eef1f6; --shadow: 0 1px 2px rgba(15, 27, 45, .06), 0 1px 3px rgba(15, 27, 45, .04);
  --r: 12px; --r-sm: 8px; --h: 38px; --h-sm: 30px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1420; --panel: #141f30; --line: #25344a; --text: #e8eef7; --muted: #94a3b8;
    --nav: #091019; --nav-text: #b6c3d6; --nav-active: #1d3150;
    --accent: #5b9bff; --accent-soft: #182c4b; --accent-text: #0b1522;
    --bubble-in: #1e2b40; --bubble-out: #1c4730; --bubble-out-text: #e4f6ea;
    --ok: #4ade80; --ok-soft: #14351f; --warn: #fbbf24; --warn-soft: #3a2b0f; --bad: #fca5a5; --bad-soft: #3b1816;
    --chip: #1f2d43; --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 400 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
strong { font-weight: 600; }

#app { height: 100%; display: flex; flex-direction: column; }
.topbar { flex: none; height: 56px; background: var(--nav); color: var(--nav-text); display: flex; align-items: center; gap: 16px; padding: 0 16px; }
.brand { font-weight: 700; font-size: 15px; color: #fff; display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand i { width: 28px; height: 28px; border-radius: 9px; background: linear-gradient(135deg, #3b9cff, #6d5df0); display: inline-block; }
.tabs { display: flex; gap: 4px; }
.tab { height: 36px; display: inline-flex; align-items: center; padding: 0 16px; background: transparent; border: 0; border-radius: 9px; color: var(--nav-text); font-weight: 500; font-size: 14px; }
.tab:hover { background: rgba(255, 255, 255, .07); }
.tab.active { background: var(--nav-active); color: #fff; }
.spacer { flex: 1; }
.pill { height: 28px; display: inline-flex; align-items: center; padding: 0 12px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 0; white-space: nowrap; }
.pill.on { background: var(--ok-soft); color: var(--ok); }
.pill.off { background: var(--bad-soft); color: var(--bad); }
.pill.demo { background: #fde68a; color: #5b4300; }
/* Trạng thái Agent: chấm nhấp nháy + robot, không có chữ */
.pill.agent { gap: 8px; padding: 0 12px; cursor: pointer; }
.pill.agent svg { width: 18px; height: 18px; flex: none; }
.pill.agent .live { position: relative; width: 9px; height: 9px; border-radius: 50%; flex: none; background: currentColor; }
.pill.agent.on .live { background: #16a34a; }
.pill.agent.on .live::after { content: ''; position: absolute; inset: 0; border-radius: 50%; background: #16a34a; animation: agent-ping 1.6s ease-out infinite; }
.pill.agent.off .live { background: var(--bad); }
@keyframes agent-ping { 0% { transform: scale(1); opacity: .65; } 80%, 100% { transform: scale(2.8); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .pill.agent.on .live::after { animation: none; opacity: 0; } }
.ghost { height: 32px; padding: 0 14px; background: transparent; border: 1px solid rgba(255, 255, 255, .22); color: var(--nav-text); border-radius: 9px; font-weight: 500; font-size: 13px; }
.ghost:hover { background: rgba(255, 255, 255, .08); }
.banner { flex: none; background: #fde68a; color: #5b4300; padding: 6px 16px; font-size: 13px; font-weight: 500; text-align: center; }

.view { flex: 1; min-height: 0; }
.bottomnav { display: none; }

/* ---------- Nút, ô nhập, chip: cùng chiều cao, cân với chữ ---------- */
.btn { height: var(--h); display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 16px; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; font-weight: 600; font-size: 13.5px; line-height: 1; white-space: nowrap; color: var(--text); }
.btn:hover { background: var(--bg); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); background: var(--accent); }
.btn.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.btn.danger { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.btn.small { height: var(--h-sm); padding: 0 12px; font-size: 12.5px; border-radius: 8px; }
input[type=text], input[type=password], input[type=search], select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; width: 100%; height: var(--h); font-size: 14px; }
select { padding-right: 8px; }
textarea { height: auto; min-height: 72px; padding: 10px 12px; resize: vertical; }
input[type=file] { font-size: 13px; width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.chip { height: 22px; display: inline-flex; align-items: center; padding: 0 8px; background: var(--chip); border-radius: 6px; font-size: 11.5px; font-weight: 600; color: var(--muted); white-space: nowrap; line-height: 1; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.blue { background: var(--accent-soft); color: var(--accent); }
.avatar { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 15px; flex: none; }
.empty { color: var(--muted); padding: 28px 16px; text-align: center; }
.scroll { overflow: auto; flex: 1; min-height: 0; -webkit-overflow-scrolling: touch; }

/* ---------- Hội thoại: ba cột ---------- */
.inbox { display: grid; grid-template-columns: 360px minmax(0, 1fr) 340px; height: 100%; }
.col { background: var(--panel); border-right: 1px solid var(--line); min-height: 0; display: flex; flex-direction: column; min-width: 0; }
.col:last-child { border-right: 0; }
.col-head { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filters select:last-child { grid-column: 1 / -1; }
.count-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.only-small, .only-phone { display: none !important; }

.conv { display: grid; grid-template-columns: 42px 1fr; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); border-left: 3px solid transparent; cursor: pointer; }
.conv:hover { background: var(--bg); }
.conv.active { background: var(--accent-soft); }
.conv.attn { border-left-color: var(--warn); }
.conv .top { display: flex; justify-content: space-between; gap: 8px; }
.conv .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .time { color: var(--muted); font-size: 12px; flex: none; }
.conv .prev { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }

.chat-head { padding: 10px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-height: 62px; }
.chat-head h2 { margin: 0; font-size: 15.5px; font-weight: 600; line-height: 1.3; }
.chat-title { min-width: 0; flex: 1; }
.chat-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.messages { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; background: var(--bg); -webkit-overflow-scrolling: touch; }
.msg { max-width: 72%; padding: 9px 13px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; box-shadow: var(--shadow); line-height: 1.5; }
.msg.customer { align-self: flex-start; background: var(--bubble-in); border-bottom-left-radius: 5px; }
.msg.agent { align-self: flex-end; background: var(--bubble-out); color: var(--bubble-out-text); border-bottom-right-radius: 5px; }
.msg .meta { font-size: 11px; opacity: .6; margin-top: 3px; }
.sys { align-self: center; font-size: 12px; color: var(--muted); background: var(--chip); border-radius: 999px; padding: 3px 14px; text-align: center; }
.daysep { align-self: center; font-size: 11.5px; color: var(--muted); margin: 8px 0 2px; }
.chat-foot { padding: 9px 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }

.side-tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.side-tabs button { flex: 1; height: 44px; background: transparent; border: 0; font-weight: 600; font-size: 13.5px; color: var(--muted); border-bottom: 2px solid transparent; }
.side-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.side-close { display: none; }
.card { margin: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); }
.card h4 { margin: 0 0 10px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; }
.card.order { border-color: var(--warn); }
.card.order h4 { color: var(--warn); }
.kv { display: grid; grid-template-columns: 112px 1fr; gap: 5px 10px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.note { background: var(--warn-soft); border-radius: var(--r-sm); padding: 8px 12px; margin-top: 8px; }
.note small { color: var(--muted); display: block; margin-top: 2px; }
.turn { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.turn .t { color: var(--muted); font-size: 12px; }

/* ---------- Trang: đơn, thống kê, cài đặt ---------- */
.page { padding: 20px 24px 32px; overflow: auto; height: 100%; -webkit-overflow-scrolling: touch; }
.page h1 { font-size: 19px; font-weight: 700; margin: 0 0 16px; }
.page h3 { margin: 26px 0 10px; font-size: 14px; font-weight: 600; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.grid { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(176px, 1fr)); }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .v { font-size: 26px; font-weight: 700; line-height: 1.2; letter-spacing: -.3px; }
.kpi .l { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.kpi .s { color: var(--muted); font-size: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); }
.panel h3 { margin-top: 0; }
.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.note-text { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }
table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th { background: var(--bg); color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
.bar { display: grid; grid-template-columns: 150px 1fr 64px; gap: 10px; align-items: center; margin: 6px 0; }
.bar .track { background: var(--chip); border-radius: 6px; height: 12px; overflow: hidden; }
.bar .fill { background: var(--accent); height: 100%; border-radius: 6px; }
.bar .n { text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }
.sw { position: relative; display: inline-block; vertical-align: middle; width: 44px; height: 26px; flex: none; }
.sw input { opacity: 0; width: 0; height: 0; }
.sw span { position: absolute; inset: 0; background: var(--chip); border-radius: 999px; transition: .15s; cursor: pointer; border: 1px solid var(--line); }
.sw span::after { content: ""; position: absolute; width: 20px; height: 20px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.sw input:checked + span { background: var(--ok); border-color: var(--ok); }
.sw input:checked + span::after { transform: translateX(18px); }
.login { margin: 14vh auto; width: min(380px, 92vw); }
.login h1 { font-size: 21px; margin: 0 0 4px; }
.err { color: var(--bad); margin-top: 10px; min-height: 22px; font-size: 13px; }
.thumbs { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.thumbs figure { margin: 0; width: 120px; }
.thumbs img { width: 120px; height: 120px; object-fit: cover; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--chip); }
.thumbs figcaption { font-size: 12px; color: var(--muted); margin: 4px 0; }
.stack { display: grid; gap: 10px; max-width: 520px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

/* ---------- Máy tính bảng ---------- */
@media (max-width: 1100px) {
  .inbox { grid-template-columns: 320px minmax(0, 1fr); }
  .inbox .col:last-child { display: none; }
  .inbox.show-info .col:last-child { display: flex; position: fixed; inset: 0; z-index: 50; }
  .only-small { display: inline-flex !important; }
  .side-close { display: inline-flex; margin: 10px 12px 0; align-self: flex-start; }
}

/* ---------- Điện thoại ---------- */
@media (max-width: 760px) {
  body { font-size: 14.5px; }
  .topbar { height: 52px; padding: 0 12px; gap: 10px; }
  .tabs, .topbar .ghost { display: none; }
  /* Thanh trên không được rộng hơn màn hình (nếu tràn, cả trang bị lệch và điện thoại tự co phóng) */
  .topbar { overflow: hidden; min-width: 0; }
  .topbar > * { min-width: 0; }
  .brand { font-size: 14.5px; flex: 0 1 auto; }
  .brand b { overflow: hidden; text-overflow: ellipsis; }
  .pill { padding: 0 10px; flex: none; }
  .pill.demo:not(.ro) { display: none; } /* đã có dải vàng "dữ liệu mẫu" ngay bên dưới */
  .plink .pl-t { display: none; }
  .plink .pl-i { display: inline-flex; }
  .banner { font-size: 12px; padding: 5px 12px; }
  .only-phone { display: inline-flex !important; }
  .bottomnav { display: flex; flex: none; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .bottomnav button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: 58px; background: transparent; border: 0; color: var(--muted); font-size: 11px; font-weight: 600; }
  .bottomnav button.active { color: var(--accent); }
  .bottomnav svg { width: 22px; height: 22px; }
  .inbox { grid-template-columns: 1fr; }
  .inbox.has-sel .col:first-child { display: none; }
  .inbox:not(.has-sel) .col:nth-child(2) { display: none; }
  .filters.collapsed { display: none; }
  .col-head { padding: 10px; }
  .conv { padding: 12px; }
  .chat-head { padding: 8px 10px; min-height: 58px; }
  .chat-head .chips { display: none; }
  .chat-actions { flex: 1 1 100%; display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
  .chat-actions .btn { grid-column: span 2; width: 100%; height: 36px; padding: 0 6px; justify-content: center; }
  .chat-actions .act-main { grid-column: span 3; height: 44px; font-size: 15px; font-weight: 600; }
  .messages { padding: 12px 10px; }
  .msg { max-width: 88%; }
  .chat-foot { display: none; }
  .btn, input[type=text], input[type=password], input[type=search], select { height: 42px; }
  .btn.small { height: 34px; }
  .page { padding: 14px 12px 24px; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi { padding: 12px; }
  .kpi .v { font-size: 22px; }
  .two { grid-template-columns: 1fr; }
  .bar { grid-template-columns: 96px 1fr 52px; gap: 8px; }
  .kv { grid-template-columns: 100px 1fr; }
  /* bảng thành thẻ */
  table, thead, tbody, tr, td { display: block; width: 100%; }
  table { background: transparent; border: 0; }
  thead { display: none; }
  tr { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 10px; padding: 6px 12px; box-shadow: var(--shadow); }
  td { display: grid; grid-template-columns: 96px 1fr; gap: 8px; border-bottom: 1px dashed var(--line); padding: 8px 0; }
  td:last-child { border-bottom: 0; }
  td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 600; }
  td[data-label=""]::before, td:not([data-label])::before { content: none; }
  td:not([data-label]), td[data-label=""] { display: block; }
}

/* Bản dịch tiếng Việt cho quản lý và hộp dặn Agent */
.msg .vi { margin-top: 6px; padding-top: 6px; border-top: 1px dashed currentColor; border-top-color: color-mix(in srgb, currentColor 30%, transparent); font-size: 13px; opacity: .85; font-style: italic; }
.ask-pane { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.ask-pane .scroll { padding: 12px; }
.say { padding: 9px 12px; border-radius: 14px; margin: 0 0 8px; white-space: pre-wrap; word-wrap: break-word; line-height: 1.5; font-size: 14px; }
.say.mgr { background: var(--accent); color: #fff; margin-left: 24px; border-bottom-right-radius: 4px; }
.say.bot { background: var(--bubble-in); margin-right: 24px; border-bottom-left-radius: 4px; }
.draft { border: 1px dashed var(--line); border-radius: var(--r-sm); padding: 9px 12px; margin: 0 0 8px; font-size: 13.5px; }
.draft small { display: block; color: var(--muted); margin-bottom: 4px; }
.draft .vi2 { margin-top: 6px; font-style: italic; opacity: .85; }
.ask-foot { flex: none; border-top: 1px solid var(--line); padding: 10px 12px; background: var(--panel, transparent); }
.ask-foot textarea { min-height: 64px; }
.ask-foot .row { margin: 8px 0 0; }
.ask-hint { color: var(--muted); font-size: 12.5px; margin: 0 0 8px; }

.prodgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px 14px; }
.prodpick { display: flex; align-items: center; gap: 8px; font-size: 13.5px; min-height: 32px; }
.prodpick input { width: 16px; height: 16px; margin: 0; flex: none; }

/* ===== Logo Malak Agent: ảnh gốc giữ nguyên, hiệu ứng chỉ là lớp phủ (2.5 giây, lặp vô hạn) ===== */
.mlogo { position: relative; display: inline-block; width: var(--s, 64px); height: var(--s, 64px); flex: none; line-height: 0; }
.mlogo img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; user-select: none; -webkit-user-drag: none; }
.mlogo .glow { filter: blur(calc(var(--s, 64px) * .09)) saturate(1.3); opacity: .22; animation: mlg-glow 2.5s ease-in-out infinite; }
.mlogo .fx { position: absolute; left: -6%; top: -6%; width: 112%; height: 112%; pointer-events: none; overflow: visible; }
.mlogo .rimglow { fill: none; stroke: #b98cff; stroke-width: 70; opacity: 0; animation: mlg-rim 2.5s ease-in-out infinite; }
.mlogo .orb { fill: none; stroke-linecap: round; opacity: 0; }
.mlogo .orb.head { stroke: #fff; stroke-width: 15; stroke-dasharray: 1.4 98.6; animation: mlg-head 2.5s linear infinite; }
.mlogo .orb.halo { stroke: #d9b8ff; stroke-width: 34; stroke-dasharray: 1.6 98.4; animation: mlg-head 2.5s linear infinite; }
.mlogo .orb.tail1 { stroke: #e6d2ff; stroke-width: 10; stroke-dasharray: 7 93; animation: mlg-tail1 2.5s linear infinite; }
.mlogo .orb.tail2 { stroke: #b98cff; stroke-width: 7; stroke-dasharray: 16 84; animation: mlg-tail2 2.5s linear infinite; }
.mlogo .dot { fill: #8dffd2; opacity: 0; transform-box: fill-box; transform-origin: center; animation: mlg-dot 2.5s ease-in-out infinite; }
.mlogo .dot.d2 { animation-delay: .25s; }
.mlogo .dot.d3 { animation-delay: .5s; }
/* Nhịp: viền sáng lên; điểm sáng chạy một vòng quanh bong bóng; ba chấm xanh nhấp nháy lần lượt */
@keyframes mlg-glow { 0%, 100% { opacity: .2 } 25% { opacity: .5 } 55% { opacity: .34 } 75% { opacity: .5 } }
@keyframes mlg-rim { 0%, 100% { opacity: 0 } 15% { opacity: .22 } 40% { opacity: .1 } 75% { opacity: .2 } }
@keyframes mlg-head { 0%, 20% { stroke-dashoffset: 0; opacity: 0 } 26% { opacity: 1 } 78% { opacity: 1 } 84%, 100% { stroke-dashoffset: -100; opacity: 0 } }
@keyframes mlg-tail1 { 0%, 20% { stroke-dashoffset: 7; opacity: 0 } 26% { opacity: .85 } 78% { opacity: .85 } 84%, 100% { stroke-dashoffset: -93; opacity: 0 } }
@keyframes mlg-tail2 { 0%, 20% { stroke-dashoffset: 16; opacity: 0 } 26% { opacity: .5 } 78% { opacity: .5 } 84%, 100% { stroke-dashoffset: -84; opacity: 0 } }
@keyframes mlg-dot { 0%, 50% { opacity: 0; transform: scale(.9) } 58% { opacity: .85; transform: scale(1.12) } 68%, 100% { opacity: 0; transform: scale(.95) } }
@media (prefers-reduced-motion: reduce) {
  .mlogo .glow { animation: none; opacity: .28; }
  .mlogo .fx { display: none; }
}

.brand .mlogo { --s: 32px; }
.brand b { font-weight: 700; letter-spacing: .01em; }
.brand b span { color: #b98cff; }

/* ===== Màn hình đăng nhập ===== */
.lg { position: fixed; inset: 0; overflow: auto; display: grid; place-items: center; padding: 24px 16px; color: #e9e4ff;
  background: radial-gradient(1100px 700px at 15% 10%, #3a1a8f55, transparent 60%), radial-gradient(900px 700px at 90% 95%, #1b4fd855, transparent 60%), linear-gradient(160deg, #070419 0%, #0d0630 55%, #10073d 100%); }
.lg::before { content: ""; position: fixed; inset: -50%; z-index: 0; pointer-events: none;
  background-image: linear-gradient(#8b6cff14 1px, transparent 1px), linear-gradient(90deg, #8b6cff14 1px, transparent 1px); background-size: 56px 56px;
  transform: perspective(700px) rotateX(58deg); transform-origin: 50% 40%; animation: lg-grid 14s linear infinite;
  -webkit-mask-image: radial-gradient(closest-side, #000 15%, transparent 75%); mask-image: radial-gradient(closest-side, #000 15%, transparent 75%); }
@keyframes lg-grid { to { background-position: 0 56px, 56px 0; } }
.lg-orb { position: fixed; border-radius: 50%; filter: blur(70px); pointer-events: none; z-index: 0; animation: lg-float 9s ease-in-out infinite alternate; }
.lg-orb.a { width: 340px; height: 340px; background: #7c3aed55; left: -80px; top: 12%; }
.lg-orb.b { width: 300px; height: 300px; background: #2563eb44; right: -60px; bottom: 8%; animation-delay: -4s; }
@keyframes lg-float { to { transform: translate(40px, -30px) scale(1.12); } }
.lg-card { position: relative; z-index: 1; width: min(400px, 100%); text-align: center; padding: 30px 26px 22px; border-radius: 22px;
  background: linear-gradient(180deg, #ffffff12, #ffffff07); border: 1px solid #b98cff33; box-shadow: 0 30px 80px #0008, inset 0 1px 0 #ffffff1f; -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
.lg-card .mlogo { --s: 132px; margin: 4px 0 6px; }
.lg-card h1 { margin: 0; font-size: 30px; letter-spacing: .01em; color: #fff; }
.lg-card h1 span { background: linear-gradient(90deg, #c4a2ff, #7aa8ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lg-hello { height: 24px; margin: 8px 0 2px; color: #b9a8f5; font-size: 15px; transition: opacity .35s; }
.lg-sub { margin: 0 0 20px; color: #a99bdc; font-size: 11px; font-weight: 600; letter-spacing: .07em; text-wrap: balance; }
.lg-card input { height: 46px; background: #0a0526aa; border: 1px solid #8b6cff55; color: #fff; border-radius: 12px; text-align: left; padding: 0 16px; letter-spacing: .04em; }
.lg-card input::placeholder { color: #8d80c2; letter-spacing: normal; }
.lg-card input:focus { outline: none; border-color: #b98cff; box-shadow: 0 0 0 3px #8b5cf633; }
.lg-go { width: 100%; height: 46px; margin-top: 12px; border: 0; border-radius: 12px; font-weight: 700; font-size: 15px; color: #fff; cursor: pointer;
  background: linear-gradient(135deg, #8b5cf6, #4f46e5); box-shadow: 0 8px 24px #6d3df066; }
.lg-go:hover { filter: brightness(1.1); }
/* Vệt sáng lướt ngang nút đăng nhập */
.lg-go { position: relative; overflow: hidden; isolation: isolate; }
.lg-go::after { content: ''; position: absolute; top: -20%; bottom: -20%; left: 0; width: 38%; z-index: -1; pointer-events: none;
  background: linear-gradient(100deg, transparent 0%, #ffffff00 25%, #ffffff55 50%, #ffffff00 75%, transparent 100%); transform: translateX(-130%) skewX(-18deg); animation: lg-shine 3.2s ease-in-out infinite; }
@keyframes lg-shine { 0% { transform: translateX(-130%) skewX(-18deg); } 45%, 100% { transform: translateX(380%) skewX(-18deg); } }
.lg-card .err { color: #ff9d9d; }
.lg-status { margin-top: 14px; font-size: 12px; color: #8d80c2; display: flex; justify-content: center; align-items: center; gap: 8px; }
.lg-status i { width: 8px; height: 8px; border-radius: 50%; background: #34e5a0; box-shadow: 0 0 10px #34e5a0; animation: lg-blink 1.6s ease-in-out infinite; }
@keyframes lg-blink { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .lg::before, .lg-orb, .lg-status i, .lg-go::after { animation: none; } .lg-go::after { display: none; } }

/* Mạng lưới AI dưới khung đăng nhập */
.lg { display: flex; flex-direction: column; align-items: center; justify-content: safe center; gap: 14px; }
.lg-status { white-space: nowrap; }
.ainet { position: relative; z-index: 1; width: min(420px, 100%); height: auto; overflow: visible; flex: none; }
.ainet .ln { fill: none; stroke-linecap: round; }
.ainet .ln.glow { stroke: #9b6bff; stroke-width: 5; opacity: .35; animation: ai-glow 3.2s ease-in-out infinite; }
.ainet .ln.base { stroke: #8b6cff; stroke-width: 1; opacity: .5; }
.ainet .ln.flow { stroke: #d9c5ff; stroke-width: 1.6; stroke-dasharray: 3 14; animation: ai-flow 1.6s linear infinite; }
.ainet .ln.flow.f2 { animation-direction: reverse; animation-duration: 2s; }
.ainet .ln.flow.f3 { animation-duration: 2.4s; }
.ainet .spark { fill: #fff; filter: drop-shadow(0 0 4px #c4a2ff) drop-shadow(0 0 8px #8b5cf6); offset-rotate: 0deg; animation: ai-travel 3.2s ease-in-out infinite; }
.ainet .spark.s2 { animation-delay: -1.1s; animation-direction: alternate-reverse; }
.ainet .spark.s3 { animation-delay: -2.1s; animation-duration: 4s; }
.ainet .halo { fill: #8b5cf6; opacity: .14; animation: ai-halo 3s ease-in-out infinite; }
.ainet .halo.h2 { animation-delay: -1s; }
.ainet .halo.h3 { animation-delay: -2s; }
.ainet .node { fill: #140a3c; stroke: url(#ng); stroke-width: 1.4; }
.ainet .ico { fill: none; stroke: #d9c5ff; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.ainet .lab { fill: #b9a8f5; font-size: 10.5px; font-weight: 600; letter-spacing: .04em; }
@keyframes ai-flow { to { stroke-dashoffset: -34; } }
@keyframes ai-glow { 50% { opacity: .6; } }
@keyframes ai-halo { 50% { opacity: .32; transform: none; } }
@keyframes ai-travel { from { offset-distance: 0%; opacity: 0; } 10%, 90% { opacity: 1; } to { offset-distance: 100%; opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .ainet .ln, .ainet .spark, .ainet .halo { animation: none; } .ainet .spark { display: none; } }

/* Chọn khoảng ngày thống kê */
.range { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px 12px; }
.range .seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; background: var(--panel); }
.range .seg button { height: var(--h); padding: 0 12px; border: 0; background: transparent; color: var(--muted); font-weight: 600; cursor: pointer; }
.range .seg button + button { border-left: 1px solid var(--line); }
.range .seg button.active { background: var(--accent); color: var(--accent-text); }
.range .dates { display: flex; gap: 8px; align-items: center; }
.range .dates label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.range .dates input { width: 150px; }
@media (max-width: 760px) { .range { justify-content: flex-start; } .range .dates { width: 100%; } .range .dates label { flex: 1; } .range .dates input { width: 100%; } .range .seg { width: 100%; } .range .seg button { flex: 1; padding: 0 4px; } }

/* Ảnh khách gửi trong khung chat */
.msg a { display: block; line-height: 0; }
.chatimg { max-width: min(280px, 100%); max-height: 340px; border-radius: 10px; margin-top: 6px; display: block; cursor: zoom-in; background: var(--chip); }

.avatar { position: relative; overflow: hidden; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

/* Cờ ngôn ngữ */
.chip.flagchip { padding: 0 8px; }
.flag { width: 22px; height: 15px; display: block; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .18); }

/* Tên và ảnh đại diện khách trên từng nhóm tin */
.mrow { display: flex; gap: 8px; max-width: 78%; align-items: flex-end; }
.mrow.in { align-self: flex-start; }
.mrow.out { align-self: flex-end; }
.mrow .msg { max-width: 100%; }
.mrow .avatar { width: 30px; height: 30px; font-size: 12px; align-self: flex-start; margin-top: 18px; }
.avatar-gap { width: 30px; flex: none; }
.mcol { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.who { font-size: 12px; color: var(--muted); font-weight: 600; padding: 0 4px; margin-top: 4px; }
.mrow.out .who { text-align: right; }
@media (max-width: 760px) { .mrow { max-width: 92%; } }

/* ===== Tin chưa đọc, biểu tượng, huy hiệu ===== */
.avwrap { position: relative; flex: none; }
.udot { position: absolute; right: -2px; top: -2px; width: 14px; height: 14px; border-radius: 50%; background: #ff7a1a; border: 2px solid var(--panel); box-shadow: 0 0 0 0 #ff7a1a88; animation: udot 2s ease-out infinite; }
@keyframes udot { 70% { box-shadow: 0 0 0 7px #ff7a1a00; } 100% { box-shadow: 0 0 0 0 #ff7a1a00; } }
@media (prefers-reduced-motion: reduce) { .udot { animation: none; } }
.conv.unread .name { font-weight: 800; }
.conv.unread .prev { color: var(--text); font-weight: 600; }
.ficons { margin-left: auto; display: inline-flex; gap: 6px; align-items: center; }
.fi { width: 22px; height: 22px; border-radius: 7px; display: inline-grid; place-items: center; }
.fi svg { width: 14px; height: 14px; }
.fi.ph { background: var(--ok-soft); color: var(--ok); }
.fi.od { background: var(--warn-soft); color: var(--warn); }
.fi.hu { background: var(--bad-soft); color: var(--bad); }
.badge { display: inline-block; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 6px; border-radius: 9px; background: #ff7a1a; color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; vertical-align: middle; }
.badge[hidden] { display: none; }
.bottomnav button { position: relative; }
.bottomnav .badge { position: absolute; top: 3px; left: calc(50% + 6px); margin: 0; }

/* ===== Thanh chọn ngày thống kê ===== */
.rangebar { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 20px; margin-bottom: 16px; }
.rb-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.rb-range { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.rb-seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 12px; background: var(--chip); }
.rb-seg button { height: 34px; padding: 0 14px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 600; cursor: pointer; white-space: nowrap; }
.rb-seg button.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.rb-dates { display: flex; align-items: center; gap: 8px; }
.rb-arrow { font-style: normal; color: var(--muted); }
.rb-field { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 10px 0 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); cursor: pointer; }
.rb-field span { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.rb-field input { border: 0; background: transparent; height: auto; padding: 0; width: 128px; font: inherit; color: var(--text); outline: none; cursor: pointer; color-scheme: light dark; }
.rb-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
@media (max-width: 760px) {
  .rangebar { flex-direction: column; align-items: stretch; }
  .rb-range { flex-direction: column; align-items: stretch; }
  .rb-seg { width: 100%; }
  .rb-seg button { flex: 1; padding: 0 4px; height: 38px; }
  .rb-dates { width: 100%; }
  .rb-field { flex: 1; min-width: 0; height: 44px; }
  .rb-field input { width: 100%; min-width: 0; font-size: 16px; }
  .rb-arrow { display: none; }
}

/* ===== Điện thoại: không tự phóng to khi chạm hoặc nhập chữ ===== */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; touch-action: manipulation; }
button, a, input, select, textarea, label, .conv, .tab { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
/* Cỡ 16px thì điện thoại không tự phóng to. Phải chỉ rõ theo loại ô, vì quy tắc gốc (input[type=text]...) cụ thể hơn và sẽ đè mất. */
@media (max-width: 900px) { input[type=text], input[type=password], input[type=search], input[type=date], input[type=number], input[type=email], input, select, textarea, .lg-card input { font-size: 16px; } }
/* Link chính sách quyền riêng tư: dưới trang đăng nhập và trên thanh trên cùng (nút tròn "i" trên điện thoại) */
.lg-legal { display: block; margin-top: 10px; font-size: 12px; color: #8d80c2; text-decoration: none; }
.lg-legal:hover, .lg-legal:focus-visible { color: #c4a2ff; text-decoration: underline; }
.plink { color: var(--nav-text); font-size: 12.5px; opacity: .8; white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center; }
.plink:hover { opacity: 1; text-decoration: underline; }
.plink .pl-i { display: none; width: 24px; height: 24px; border: 1px solid rgba(255, 255, 255, .35); border-radius: 50%; align-items: center; justify-content: center; font: italic 700 13px Georgia, serif; }
@media (max-width: 1239px) { .plink .pl-t { display: none; } .plink .pl-i { display: inline-flex; } }
.tab, .ghost, .pill { white-space: nowrap; }
/* Thẻ bài quảng cáo ở đầu cuộc trò chuyện */
.adcard { align-self: center; width: min(420px, 100%); margin: 6px 0 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); overflow: hidden; }
.adcard-h { display: flex; gap: 8px; align-items: center; padding: 8px 12px; font-size: 12px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); background: var(--bg); }
.adcard-b { display: flex; gap: 12px; padding: 12px; align-items: flex-start; }
.adcard-b img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; display: block; background: var(--bg); }
.adcard-ph { flex: none; width: 96px; height: 96px; border-radius: 10px; display: grid; place-items: center; font-size: 28px; background: linear-gradient(135deg, #8b5cf633, #2563eb33); }
.adcard-t { min-width: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; }
.adcard-t b { font-size: 14px; overflow-wrap: anywhere; }
/* Tin nhắn thoại của khách */
.voice { display: flex; gap: 8px; align-items: flex-start; }
.voice-i { flex: none; width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; background: #8b5cf633; font-size: 13px; }
.voice b { font-weight: 600; }
/* Quy tắc chung của Agent */
.rule { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.rule:last-child { border-bottom: 0; }
.rule-t { flex: 1; min-width: 0; line-height: 1.45; }
.rule-t textarea { width: 100%; min-height: 54px; }
.rule-b { display: flex; flex-direction: column; gap: 6px; }
.rule-h { margin: 14px 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
@media (max-width: 760px) { .rule { flex-direction: column; } .rule-b { flex-direction: row; } }
.brand { cursor: pointer; border-radius: 10px; }
.brand:focus-visible { outline: 2px solid #b98cff; outline-offset: 3px; }
/* Điện thoại: thanh chọn ngày không tràn màn hình */
@media (max-width: 760px) {
  .rb-range, .rb-seg, .rb-dates { max-width: 100%; min-width: 0; }
  .rb-seg button { font-size: 13px; padding: 0 2px; }
  .rb-dates { flex-direction: column; align-items: stretch; gap: 8px; }
  .rb-field { width: 100%; box-sizing: border-box; }
  .rb-field input { flex: 1; }
}

/* Tab Bình luận */
.cbadge { background: var(--accent); }
.clist { display: flex; flex-direction: column; gap: 10px; }
.ccard { padding: 12px 14px; }
.ccard.unread { border-left: 3px solid #ff7a1a; }
.chead { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chead .time { margin-left: auto; color: var(--muted); font-size: 12px; }
.cquote { margin: 8px 0 4px; padding: 8px 12px; background: var(--chip); border-radius: var(--r-sm); font-size: 14px; overflow-wrap: anywhere; }
.clink { display: inline-block; margin: 2px 12px 2px 0; font-size: 12.5px; }
.cdraft { margin-top: 6px; display: grid; gap: 4px; }
.cdraft label { font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 4px; }
.cdraft textarea { min-height: 44px; font-size: 14px; }
.cdraft .vi { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.cerr { margin-top: 6px; color: var(--bad); background: var(--bad-soft); padding: 6px 10px; border-radius: var(--r-sm); font-size: 12.5px; }
