:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1c1f24;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2f6fed;
  --accent-soft: #e8f0ff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --zalo: #0068ff;
  --whatsapp: #1fa855;
  --facebook: #1877f2;
  --email: #ea580c;
  --web: #7c3aed;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 2px 8px rgba(0, 0, 0, 0.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --panel: #1a1d23;
    --text: #e8eaed;
    --muted: #9aa0a8;
    --line: #2b2f37;
    --accent: #5b8cff;
    --accent-soft: #1d2a45;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 24px; margin: 0; }
h2 { font-size: 16px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* Thanh bên */
.sidebar {
  width: 230px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { font-weight: 700; font-size: 17px; padding: 4px 10px 18px; display: flex; align-items: center; gap: 8px; }
.dot-logo { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a {
  color: var(--text);
  padding: 9px 12px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
nav a:hover { background: var(--bg); }
nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.pill { margin-left: auto; background: var(--accent); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 7px; }
.pill:empty { display: none; }
.side-foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 10px; border-top: 1px solid var(--line); }

main { flex: 1; padding: 24px 28px 60px; max-width: 1200px; min-width: 0; }
.view { display: none; }
.view.active { display: block; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.actions, .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }

/* Nút & ô nhập */
.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; margin-top: 10px; }
.btn.sm { padding: 3px 9px; font-size: 13px; }
.btn:disabled { opacity: 0.6; cursor: wait; }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.search { max-width: 340px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 20px;
  padding: 5px 13px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Thẻ kênh */
.channel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 12px; margin-bottom: 16px; }
.ch-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; cursor: pointer; box-shadow: var(--shadow); }
.ch-card:hover { border-color: var(--accent); }
.ch-name { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.ch-num { font-size: 26px; font-weight: 700; }
.ch-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sdot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.sdot.s-on { background: var(--ok); }
.sdot.s-error { background: var(--danger); }
.sdot.s-qr, .sdot.s-connecting { background: var(--warn); }

.badge { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 6px; color: #fff; display: inline-block; }
.badge.zalo { background: var(--zalo); }
.badge.whatsapp { background: var(--whatsapp); }
.badge.facebook { background: var(--facebook); }
.badge.email { background: var(--email); }
.badge.web { background: var(--web); }
.badge.fanpage { background: #0b5bd3; }
.badge.instagram { background: #d62976; }
.badge.zalooa { background: #0047b3; }
.section-title { margin: 28px 0 12px; font-size: 18px; }
.steps summary { cursor: pointer; font-size: 13px; color: var(--accent); margin: 6px 0; }
.steps ol { padding-left: 20px; margin: 6px 0 10px; }
.steps li { margin-bottom: 6px; }
code { font-size: 12px; background: var(--bg); border: 1px solid var(--line); padding: 1px 5px; border-radius: 5px; word-break: break-word; }
.toggles { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 2px; }
.toggles label { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.toggles input { width: auto; }

/* Tóm tắt */
.digest { white-space: pre-wrap; font-size: 14.5px; }
.older summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-top: 12px; }
.older .digest { border-top: 1px dashed var(--line); padding-top: 10px; margin-top: 10px; }

/* Danh sách tin */
.msg-list, .task-list, .plain-list { list-style: none; margin: 0; padding: 0; }
.msg {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.msg.important { border-left: 3px solid var(--warn); }
.msg-top { display: flex; align-items: center; gap: 8px; font-size: 13px; flex-wrap: wrap; }
.msg-thread { font-weight: 600; }
.msg-time { margin-left: auto; color: var(--muted); font-size: 12px; }
.msg-text { margin-top: 4px; white-space: pre-wrap; word-break: break-word; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.msg-text.open { -webkit-line-clamp: unset; }
.msg-actions { display: flex; gap: 4px; margin-top: 6px; }
.icon-btn { border: none; background: none; cursor: pointer; color: var(--muted); font-size: 13px; padding: 2px 6px; border-radius: 6px; }
.icon-btn:hover { background: var(--bg); color: var(--text); }
.compact .msg { padding: 8px 10px; }
.compact .msg-text { -webkit-line-clamp: 2; }
.empty { color: var(--muted); font-size: 14px; padding: 12px 4px; }

/* Việc */
.task-form { display: grid; grid-template-columns: 1fr 210px 150px auto; gap: 8px; margin-bottom: 14px; }
.task {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.task input[type="checkbox"] { width: 18px; height: 18px; margin-top: 2px; flex: none; cursor: pointer; }
.task-body { flex: 1; min-width: 0; }
.task-title { font-weight: 500; }
.task.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-meta { font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; margin-top: 2px; }
.task-note { font-size: 13px; color: var(--muted); white-space: pre-wrap; margin-top: 4px; }
.overdue { color: var(--danger); font-weight: 600; }
.prio-cao { color: var(--danger); }
.task-actions { display: flex; gap: 2px; flex: none; }
.compact .task-actions, .compact .task-note { display: none; }
@media (max-width: 900px) {
  .task { flex-wrap: wrap; }
  .task-actions { width: 100%; justify-content: flex-end; }
}

/* Trò chuyện */
.chat-box { display: flex; flex-direction: column; height: calc(100vh - 140px); min-height: 420px; }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px; }
.bubble { max-width: 80%; padding: 9px 13px; border-radius: 14px; white-space: pre-wrap; word-break: break-word; }
.bubble.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: var(--bg); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.typing { color: var(--muted); font-style: italic; }
.suggest { margin: 10px 0 8px; }
.chat-form { display: flex; gap: 8px; }

/* Kết nối */
.connect-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.span-all { grid-column: 1 / -1; }
.qr { width: 240px; height: 240px; display: block; margin: 8px auto; background: #fff; padding: 8px; border-radius: 10px; image-rendering: pixelated; }
.note { font-size: 12px; color: var(--muted); background: var(--bg); padding: 8px 10px; border-radius: 8px; margin-bottom: 0; }
.state { font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.form-grid.four { grid-template-columns: 2fr 1fr 1fr 1fr; }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }
.plain-list li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.plain-list li:last-child { border-bottom: none; }
.plain-list .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* Cài đặt */
.settings { display: flex; flex-direction: column; gap: 12px; max-width: 760px; }
.settings h2 { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.settings h2:first-child { border-top: none; margin-top: 0; padding-top: 0; }
.settings label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 500; }
.settings label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.settings label.check input { width: auto; }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #1c1f24;
  color: #fff;
  padding: 11px 16px;
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  max-width: 380px;
  z-index: 50;
  white-space: pre-wrap;
}

@media (max-width: 1000px) {
  .connect-grid { grid-template-columns: 1fr; }
  .form-grid.four { grid-template-columns: 1fr 1fr; }
  .span3 { grid-column: span 2; }
}
@media (max-width: 720px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; padding: 10px; }
  .brand { padding-bottom: 8px; }
  nav { flex-direction: row; overflow-x: auto; }
  nav a span { display: none; }
  .side-foot { display: none; }
  main { padding: 16px; }
  .two-col { grid-template-columns: 1fr; }
  .task-form { grid-template-columns: 1fr; }
  .form-grid, .form-grid.four { grid-template-columns: 1fr; }
  .span2, .span3 { grid-column: auto; }
}

/* Nút xem mật khẩu */
.pw-wrap { position: relative; display: block; width: 100%; }
.pw-wrap > input { width: 100%; padding-right: 42px; box-sizing: border-box; }
.pw-eye {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: none; border: 0; cursor: pointer; font-size: 17px; line-height: 1;
  padding: 6px 8px; border-radius: 6px; opacity: .7;
}
.pw-eye:hover, .pw-eye:focus-visible { opacity: 1; background: var(--accent-soft); }
