:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273449;
  --line: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #2563eb;
  --primary-h: #1d4ed8;
  --ok: #22c55e;
  --fail: #ef4444;
  --wait: #f59e0b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-size: 20px; font-weight: 700; }
.brand span { color: var(--primary); }

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: 999px; font-size: 14px; font-weight: 600;
}
.pill .dot { width: 10px; height: 10px; border-radius: 50%; }
.pill--off { background: #3f2532; color: #fca5a5; }
.pill--off .dot { background: var(--fail); }
.pill--wait { background: #3a2f16; color: #fcd34d; }
.pill--wait .dot { background: var(--wait); animation: blink 1s infinite; }
.pill--on { background: #14351f; color: #86efac; }
.pill--on .dot { background: var(--ok); }
@keyframes blink { 50% { opacity: .35; } }

.view { padding: 22px; max-width: 1150px; margin: 0 auto; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 20px;
}
.card.center { max-width: 460px; margin: 40px auto; text-align: center; }
.card h2, .card h3 { margin-top: 0; }

.grid { display: grid; grid-template-columns: 360px 1fr; gap: 20px; }
@media (max-width: 820px) { .grid { grid-template-columns: 1fr; } }

.muted { color: var(--muted); font-size: 14px; }
.lbl { display: block; margin: 12px 0 6px; font-size: 13px; color: var(--muted); }

input, textarea, select {
  width: 100%; padding: 10px 12px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  font-size: 14px; font-family: inherit;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); }

.btn {
  padding: 10px 16px; border: none; border-radius: 9px; cursor: pointer;
  font-size: 14px; font-weight: 600; color: #fff;
}
.btn--primary { background: var(--primary); }
.btn--primary:hover { background: var(--primary-h); }
.btn--ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn--danger { background: var(--fail); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.row { display: flex; gap: 10px; margin-top: 14px; }
.stack { display: flex; flex-direction: column; gap: 10px; }

.qrbox {
  width: 240px; height: 240px; margin: 18px auto;
  border: 2px dashed var(--line); border-radius: 12px;
  display: flex; align-items: center; justify-content: center; background: #fff;
}
.qrbox img { width: 100%; height: 100%; object-fit: contain; border-radius: 10px; }
.qr-placeholder { color: #64748b; font-size: 14px; }

.list-head { display: flex; justify-content: space-between; align-items: center; margin: 14px 0 8px; }
.chk { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.chk input, .clist input[type=checkbox] { width: auto; }

.clist { list-style: none; margin: 0; padding: 0; max-height: 380px; overflow-y: auto; }
.clist li {
  display: flex; align-items: center; gap: 10px; padding: 9px 8px;
  border-bottom: 1px solid var(--line);
}
.clist .ci-main { flex: 1; min-width: 0; }
.clist .ci-name { font-weight: 600; }
.clist .ci-sub { font-size: 12px; color: var(--muted); }
.clist .ci-tag {
  font-size: 11px; background: var(--panel-2); border: 1px solid var(--line);
  padding: 2px 7px; border-radius: 999px; color: var(--wait);
}
.clist .del { background: none; border: none; color: var(--fail); cursor: pointer; font-size: 16px; }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tab {
  background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 8px 4px; font-size: 15px; font-weight: 600; border-bottom: 2px solid transparent;
}
.tab--active { color: var(--text); border-bottom-color: var(--primary); }

.progress-wrap { margin-top: 16px; }
.progress { height: 12px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.progress__bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--ok)); transition: width .3s; }

.counters { display: flex; gap: 14px; margin: 10px 0; font-size: 13px; flex-wrap: wrap; }
.cnt b { font-size: 14px; }
.cnt--ok { color: var(--ok); }
.cnt--fail { color: var(--fail); }
.cnt--wait { color: var(--wait); }

.log {
  margin-top: 14px; background: #0b1220; border: 1px solid var(--line);
  border-radius: 9px; padding: 10px; font-family: ui-monospace, monospace;
  font-size: 12.5px; max-height: 260px; overflow-y: auto;
}
.log--sm { max-height: 130px; }
.log .l { padding: 3px 0; border-bottom: 1px solid #14203a; }
.log .l:last-child { border-bottom: none; }
.log .ok { color: var(--ok); }
.log .fail { color: var(--fail); }
.log .info { color: var(--muted); }
.log .wait { color: var(--wait); }

/* ---- head + badges ---- */
.card-head { display: flex; align-items: center; justify-content: space-between; }
.card-head h3 { margin: 0; }
.btn--sm { padding: 6px 10px; font-size: 12.5px; }
.ci-badge {
  font-size: 11px; background: #1b2f4a; border: 1px solid #2b4a72;
  color: #7fb2ff; padding: 2px 7px; border-radius: 999px;
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%; object-fit: cover;
  background: var(--panel-2); flex-shrink: 0;
}

/* ---- modal (Zalo-style) ---- */
.modal {
  position: fixed; inset: 0; background: rgba(2, 6, 23, .72);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal[hidden] { display: none; }            /* fix: cho phép ẩn bằng thuộc tính hidden */
.modal__box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  width: 100%; max-width: 480px; max-height: 88vh; display: flex; flex-direction: column;
  overflow: hidden; box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
.modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; background: var(--primary); color: #fff;
}
.modal__head h3 { margin: 0; font-size: 17px; }
.modal__x { background: none; border: none; color: #fff; font-size: 18px; cursor: pointer; opacity: .9; }
.modal__x:hover { opacity: 1; }

/* tabs trong modal */
.modal .tabs { margin: 0; padding: 0 18px; border-bottom: 1px solid var(--line); }
.import-tools { display: flex; gap: 8px; padding: 12px 18px 6px; }
.import-tools #importSearch {
  border-radius: 999px; background: var(--panel-2); padding-left: 14px;
}
.import-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 18px 8px; font-size: 13px;
}

/* danh sách chọn */
#importList { padding: 0 8px; margin: 0; list-style: none; overflow-y: auto; flex: 1; min-height: 200px; }
.clist--tall { max-height: 46vh; }
.irow {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px;
  border-radius: 10px; cursor: pointer; border-bottom: none;
}
.irow:hover { background: var(--panel-2); }
.irow.sel { background: #12233f; }
.irow .ci-main { flex: 1; min-width: 0; }
.irow .ci-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.irow .check {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  color: transparent; font-size: 13px; font-weight: 700; transition: all .12s;
}
.irow.sel .check { background: var(--primary); border-color: var(--primary); color: #fff; }

.modal__foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 18px; border-top: 1px solid var(--line); background: var(--panel);
}
.import-empty { padding: 24px; text-align: center; color: var(--muted); }
