:root {
  --bg: #f4f6f8; --surface: #fff; --text: #1c2430; --muted: #6b7684; --line: #e2e6eb;
  --accent: #1463d8; --accent-text: #fff; --bot: #eef3fb; --agent: #e7f6ee; --customer: #fff;
  --warn: #b45309; --warn-bg: #fff4e5; --danger: #c62828; --hot: #d93025;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c; --surface: #1b2129; --text: #e6e9ee; --muted: #9aa4b2; --line: #2a323d;
    --accent: #4c8dff; --accent-text: #fff; --bot: #1d2a3d; --agent: #19342a; --customer: #232a33;
    --warn: #f0a050; --warn-bg: #3a2a14; --danger: #ff6b6b; --hot: #ff6b6b;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: inherit; }
main { max-width: 860px; margin: 0 auto; padding: 12px 16px 40px; }

.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; text-decoration: none; color: var(--accent); }
.topbar nav { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; font-size: 14px; }
.topbar nav a { text-decoration: none; color: var(--muted); }
.topbar form { margin: 0; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; }

.btn { font: inherit; font-size: 14px; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.ghost { color: var(--muted); }
.error { color: var(--danger); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px; }
.login { max-width: 360px; margin: 40px auto; display: grid; gap: 12px; }
.login h1 { margin: 0 0 4px; font-size: 20px; }
.login label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
input, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); width: 100%; }

.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 10px; }
.tabs a { white-space: nowrap; text-decoration: none; padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: 14px; }
.tabs a.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.count { color: var(--muted); font-weight: 400; }
.count.hot { color: var(--hot); font-weight: 700; }

.conv-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.conv + .conv { border-top: 1px solid var(--line); }
.conv a { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 8px; padding: 10px 14px; text-decoration: none; }
.conv.unread .who { font-weight: 700; }
.conv.unread .who::after { content: " ●"; color: var(--hot); }
.who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.when { color: var(--muted); font-size: 13px; }
.snippet { grid-column: 1 / -1; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tags { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; }
.tags > span { padding: 1px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.empty { padding: 24px; text-align: center; color: var(--muted); }

.chan { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 6px; align-self: center; }
.chan-messenger { background: #e8f0fe; color: #1a56c9; }
.chan-web { background: #ede7f6; color: #5e35b1; }
.tags .status-human { background: #fde8e8; color: var(--hot); font-weight: 600; }
.tags .status-bot { background: var(--bot); color: var(--accent); }
.tags .window, .tags .reason { background: var(--warn-bg); color: var(--warn); }
.tags .account { background: var(--agent); color: var(--text); }

.conv-page { display: grid; gap: 10px; }
.conv-head h1 { font-size: 19px; margin: 6px 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.back { font-size: 14px; color: var(--muted); text-decoration: none; }
.reason-box { margin: 8px 0 0; padding: 8px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--warn); font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.thread { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; height: min(60vh, 640px); overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 85%; }
.msg.customer { align-self: flex-start; }
.msg.bot, .msg.agent { align-self: flex-end; text-align: right; }
.bubble { display: inline-block; text-align: left; padding: 8px 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--customer); white-space: normal; overflow-wrap: anywhere; }
.msg.bot .bubble { background: var(--bot); border-color: transparent; }
.msg.agent .bubble { background: var(--agent); border-color: transparent; }
.meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.msg.system { align-self: center; font-size: 12px; color: var(--muted); background: var(--bg); padding: 2px 10px; border-radius: 999px; max-width: 100%; text-align: center; }
.att { font-size: 13px; }
.typing { margin: 0; font-size: 13px; color: var(--muted); }

.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: vertical; }
.note summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.note form { display: grid; gap: 8px; margin-top: 8px; }
.note .btn { justify-self: start; }
.flash { background: var(--agent); padding: 8px 12px; border-radius: 8px; margin: 0 0 10px; }
.chan-zalo { background: #e0f2fe; color: #0369a1; }
