:root {
  --nen: #f6f7f9;
  --the: #fff;
  --chu: #1c2430;
  --phu: #677285;
  --vien: #e2e6ec;
  --chinh: #0b6bcb;
  --chinh-dam: #0957a6;
  --xanh: #1e9e5a;
  --vang: #c98a00;
  --do: #d13b3b;
  --xam: #9aa3b2;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--chu);
  background: var(--nen);
}
* { box-sizing: border-box; }
body { margin: 0; }
.an { display: none !important; }
.phu { color: var(--phu); font-size: 14px; }
.loi { color: var(--do); font-size: 14px; min-height: 1em; margin: 4px 0; }
.giua { text-align: center; }
h1, h2, h3 { margin: 0 0 4px; }
h2 { font-size: 22px; }
code { background: #eef1f5; padding: 1px 4px; border-radius: 4px; font-size: 13px; }

button {
  font: inherit; font-size: 14px; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  border: 1px solid var(--vien); background: var(--the); color: var(--chu);
}
button:disabled { opacity: .5; cursor: default; }
button.chinh { background: var(--chinh); border-color: var(--chinh); color: #fff; font-weight: 600; }
button.chinh:hover:not(:disabled) { background: var(--chinh-dam); }
button.nhe:hover:not(:disabled) { background: #f0f3f7; }
button.nguy { color: var(--do); }

label { display: block; font-size: 14px; color: var(--phu); margin: 12px 0 0; }
input {
  display: block; width: 100%; margin-top: 4px; font: inherit; font-size: 15px; color: var(--chu);
  padding: 10px 12px; border: 1px solid var(--vien); border-radius: 8px; background: #fff;
}
input:focus { outline: 2px solid #b9d6f5; border-color: var(--chinh); }

.dang-nhap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.the { background: var(--the); border: 1px solid var(--vien); border-radius: 14px; padding: 28px; width: 100%; max-width: 380px; }
.the button[type=submit] { width: 100%; margin-top: 12px; padding: 11px; }

.dau {
  display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: var(--the);
  border-bottom: 1px solid var(--vien);
}
.dau strong { font-size: 18px; color: var(--chinh); white-space: nowrap; }
.dau button { white-space: nowrap; }
.gian { flex: 1; }

.khung { max-width: 1100px; margin: 0 auto; padding: 24px; }
.hang-tieu-de { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.canh-bao {
  background: #fff8e6; border: 1px solid #f1d58a; color: #6b4f00; border-radius: 10px;
  padding: 10px 14px; font-size: 14px; margin-bottom: 16px;
}
.trong { text-align: center; color: var(--phu); padding: 40px 0; }

.ds-nick { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.nick { background: var(--the); border: 1px solid var(--vien); border-radius: 12px; padding: 16px; }
.nick-dau { display: flex; align-items: center; gap: 10px; }
.nick-ten { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.nick-ten strong, .nick-ten span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cham { width: 10px; height: 10px; border-radius: 50%; background: var(--xam); flex: none; }
.nhan { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 99px; background: #eef1f5; color: var(--phu); white-space: nowrap; }
.nick[data-mau=xanh] .cham { background: var(--xanh); }
.nick[data-mau=xanh] .nhan { background: #e3f5eb; color: #157043; }
.nick[data-mau=vang] .cham { background: var(--vang); }
.nick[data-mau=vang] .nhan { background: #fff3d6; color: #805800; }
.nick[data-mau=do] .cham { background: var(--do); }
.nick[data-mau=do] .nhan { background: #fde7e7; color: #a12727; }
.ly-do { font-size: 13px; color: var(--phu); min-height: 1em; margin: 10px 0 0; }
.nick[data-mau=do] .ly-do { color: #a12727; }
.so-lieu { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.so-lieu div { background: #f6f8fa; border-radius: 8px; padding: 8px; min-width: 0; }
.so-lieu dt { font-size: 12px; color: var(--phu); }
.so-lieu dd { margin: 2px 0 0; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.hang-nut { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }
.hang-nut.trai { justify-content: flex-start; margin-top: 0; }
.hang-nut.trai button { padding: 6px 10px; font-size: 13px; }

dialog { border: none; border-radius: 14px; padding: 24px; width: min(440px, calc(100vw - 32px)); color: var(--chu); }
dialog::backdrop { background: rgba(20, 28, 40, .45); }
.qr-khung {
  width: 260px; height: 260px; margin: 16px auto 8px; display: grid; place-items: center;
  border: 1px solid var(--vien); border-radius: 12px; background: #fff;
}
.qr-khung img { width: 240px; height: 240px; image-rendering: pixelated; }
.qr-khung .xong { font-size: 48px; color: var(--xanh); }
.huong-dan { font-size: 14px; color: var(--phu); padding-left: 20px; margin: 12px 0 0; }
.huong-dan li { margin: 4px 0; }

@media (max-width: 600px) {
  .khung { padding: 16px; }
  .dau { padding: 10px 16px; }
  #ten-nguoi-dung { display: none; }
}

/* ---------- The trang ---------- */
.the-trang { display: flex; gap: 4px; margin-left: 12px; }
.the-trang button { border: none; background: none; color: var(--phu); font-weight: 600; padding: 8px 12px; }
.the-trang button.dang-chon { background: #e8f1fb; color: var(--chinh); }
.dem { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 99px; background: var(--do); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }

/* ---------- Hop thu ---------- */
#man-chinh { display: flex; flex-direction: column; height: 100vh; }
.dau { flex: none; }
#trang-nick, #trang-bo-nao { flex: 1; overflow-y: auto; width: 100%; }
.hop-thu { display: grid; grid-template-columns: 340px 1fr; flex: 1; min-height: 0; }
.cot-ds { border-right: 1px solid var(--vien); background: var(--the); display: flex; flex-direction: column; min-height: 0; }
.loc { padding: 12px; border-bottom: 1px solid var(--vien); display: grid; gap: 8px; }
.loc input, .loc select { margin: 0; padding: 8px 10px; font-size: 14px; }
select { font: inherit; color: var(--chu); border: 1px solid var(--vien); border-radius: 8px; background: #fff; width: 100%; }
.nut-loc { display: flex; gap: 6px; flex-wrap: wrap; }
.nut-loc button { padding: 4px 10px; font-size: 13px; border-radius: 99px; }
.nut-loc button.dang-chon { background: var(--chinh); border-color: var(--chinh); color: #fff; }
.ds-ht { overflow-y: auto; flex: 1; min-height: 0; }
.ht {
  display: flex; gap: 10px; width: 100%; text-align: left; border: none; border-bottom: 1px solid #f0f2f5;
  border-radius: 0; padding: 10px 12px; background: none; align-items: flex-start;
}
.ht:hover { background: #f6f8fa; }
.ht.dang-mo { background: #e8f1fb; }
.ht-anh {
  width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 700; color: #fff; background: #7b8aa3;
}
.ht-anh.nhom { border-radius: 10px; background: #4f7fbf; }
.ht-giua { flex: 1; min-width: 0; }
.ht-dong { display: flex; gap: 8px; align-items: baseline; }
.ht-ten { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.ht-gio { font-size: 12px; color: var(--phu); flex: none; }
.ht-xem { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--phu); }
.ht.chua-doc .ht-ten, .ht.chua-doc .ht-xem { color: var(--chu); font-weight: 700; }
.ht-nick { font-size: 11px; color: var(--phu); background: #eef1f5; border-radius: 4px; padding: 1px 6px; display: inline-block; margin-top: 3px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xem-them { margin: 10px auto; display: block; }

.cot-chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chua-chon { margin: auto; color: var(--phu); padding: 24px; text-align: center; }
.khung-chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.dau-chat { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--the); border-bottom: 1px solid var(--vien); }
.quay-lai { display: none; font-size: 20px; padding: 2px 10px; }
.ds-tin { flex: 1; overflow-y: auto; padding: 12px 16px; min-height: 0; }
.ngay { text-align: center; font-size: 12px; color: var(--phu); margin: 14px 0 6px; }
.tin { display: flex; flex-direction: column; align-items: flex-start; margin: 4px 0; }
.tin.minh { align-items: flex-end; }
.bong {
  max-width: min(70%, 560px); background: var(--the); border: 1px solid var(--vien); border-radius: 12px;
  padding: 7px 11px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.45;
}
.tin.minh .bong { background: #dcecfd; border-color: #c4dcf6; }
.tin-ten { font-size: 12px; color: var(--phu); margin: 6px 4px 2px; }
.tin-chan { font-size: 11px; color: var(--phu); margin: 2px 4px 0; }
.bong a { color: var(--chinh); }
.bong.dac-biet { color: var(--phu); font-style: italic; }
.form-gui { display: flex; gap: 8px; padding: 10px 16px 4px; background: var(--the); border-top: 1px solid var(--vien); align-items: flex-end; }
.form-gui textarea {
  flex: 1; font: inherit; font-size: 14px; color: var(--chu); resize: none; padding: 9px 11px;
  border: 1px solid var(--vien); border-radius: 8px; max-height: 160px;
}
.form-gui textarea:focus { outline: 2px solid #b9d6f5; border-color: var(--chinh); }
.loi-gui { padding: 0 16px 8px; margin: 0; background: var(--the); }

@media (max-width: 760px) {
  .dau { gap: 6px; padding: 8px 10px; }
  .dau strong { font-size: 16px; }
  .the-trang { margin-left: 0; }
  .the-trang button { padding: 6px 8px; }
  #nut-dang-xuat { padding: 6px 8px; }
  #ten-to-chuc { display: none; }
  .hop-thu { grid-template-columns: 1fr; }
  .hop-thu .cot-chat { display: none; }
  .hop-thu.dang-xem-chat .cot-ds { display: none; }
  .hop-thu.dang-xem-chat .cot-chat { display: flex; }
  .quay-lai { display: inline-block; }
  .bong { max-width: 85%; }
}

/* ---------- AI trong hop thu ---------- */
.ai-chat { display: flex; align-items: center; gap: 6px; flex: none; }
.ai-chat button { padding: 5px 10px; font-size: 13px; }
.nhan-ai { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 99px; background: #eef1f5; color: var(--phu); white-space: nowrap; }
.nhan-ai.bat { background: #e3f5eb; color: #157043; }
.nhan-ai.nhap { background: #e8f1fb; color: var(--chinh); }
.nhan-ai.nghi { background: #fff3d6; color: #805800; }
.bao-can-nguoi { background: #fde7e7; color: #a12727; font-size: 13px; padding: 8px 16px; border-bottom: 1px solid #f5c9c9; }
.ban-nhap { background: #f2f7fd; border-top: 1px solid #c4dcf6; padding: 10px 16px; }
.ban-nhap-dau { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; font-size: 13px; color: var(--chinh); }
.ban-nhap-chu { white-space: pre-wrap; font-size: 14px; margin: 6px 0 8px; overflow-wrap: anywhere; max-height: 120px; overflow-y: auto; }
.the-nho { font-size: 11px; font-weight: 700; border-radius: 4px; padding: 1px 6px; margin-left: 4px; flex: none; }
.the-nho.do { background: #fde7e7; color: #a12727; }
.the-nho.xanh { background: #e8f1fb; color: var(--chinh); }
.tin-chan .la-ai { color: #157043; font-weight: 600; }

/* ---------- Bo nao AI ---------- */
.hai-cot { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.the-khoi { background: var(--the); border: 1px solid var(--vien); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.the-khoi h3 { font-size: 16px; }
.the-khoi textarea {
  display: block; width: 100%; margin-top: 4px; font: inherit; font-size: 14px; color: var(--chu); resize: vertical;
  padding: 9px 11px; border: 1px solid var(--vien); border-radius: 8px; line-height: 1.45;
}
.the-khoi textarea:focus { outline: 2px solid #b9d6f5; border-color: var(--chinh); }
.the-khoi textarea:disabled, .the-khoi input:disabled, select:disabled { background: #f6f8fa; color: var(--phu); }
.bn-nick { display: grid; gap: 8px; margin: 10px 0; }
.bn-nick-dong { display: flex; align-items: center; gap: 10px; }
.bn-nick-dong span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bn-nick-dong select { width: auto; padding: 6px 8px; font-size: 14px; }
.goi-y { padding-left: 18px; margin: 8px 0 0; }
.goi-y li { margin: 3px 0; }
.thu-ai { position: sticky; top: 0; }
.thu-tin { min-height: 160px; max-height: 50vh; overflow-y: auto; background: var(--nen); border-radius: 10px; padding: 10px; margin: 10px 0; }
.thu-ai .form-gui { padding: 0; background: none; border: none; }
.khung.cuon { max-width: 1200px; }

@media (max-width: 900px) {
  .hai-cot { grid-template-columns: 1fr; }
  .thu-ai { position: static; }
}
@media (max-width: 600px) {
  .ai-chat .nhan-ai { display: none; }
}

/* ----- Ngan hang ----- */
.o-tong { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.o-so { background: var(--the); border: 1px solid var(--vien); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.o-so b { font-size: 20px; color: var(--xanh); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hai-cot.nh { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); align-items: start; }
.loc-gd { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.loc-gd select, .loc-gd input { width: auto; margin: 0; padding: 7px 10px; font-size: 14px; }
a.nut {
  display: inline-block; font-size: 14px; border-radius: 8px; padding: 7px 12px; border: 1px solid var(--vien);
  background: var(--the); color: var(--chu); text-decoration: none; cursor: pointer;
}
a.nut:hover { background: #f0f3f7; }
.gd-ds { border-top: 1px solid var(--vien); }
.gd { display: grid; grid-template-columns: 92px minmax(0, 1fr) auto; gap: 4px 12px; padding: 10px 2px; border-bottom: 1px solid var(--vien); font-size: 14px; }
.gd-gio { color: var(--phu); font-size: 13px; }
.gd-nd { min-width: 0; overflow-wrap: anywhere; }
.gd-tk { display: block; font-size: 12px; color: var(--phu); }
.gd-tien { font-weight: 700; text-align: right; white-space: nowrap; }
.gd-tien.vao { color: var(--xanh); }
.gd-tien.ra { color: var(--do); }
.gd-bao { display: block; font-size: 11px; font-weight: 400; color: var(--phu); }
.gd-bao.do { color: var(--do); }
.kn { border: 1px solid var(--vien); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.kn-dau { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; }
.duong-nhan { display: flex; gap: 6px; margin: 8px 0; }
.duong-nhan input { margin: 0; font-size: 12px; padding: 6px 8px; font-family: ui-monospace, Consolas, monospace; color: var(--phu); }
.cach-noi { margin-top: 12px; font-size: 14px; }
.cach-noi summary { cursor: pointer; color: var(--chinh); font-weight: 600; }
.chon-bao { border: none; padding: 0; margin: 12px 0 0; }
label.dong-chon { display: flex; align-items: center; gap: 8px; color: var(--chu); margin: 8px 0 0; }
label.dong-chon input { display: inline-block; width: 16px; height: 16px; margin: 0; flex: none; }
.bc-xem {
  white-space: pre-wrap; background: #f6f8fa; border: 1px solid var(--vien); border-radius: 10px; padding: 12px;
  font: 13px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; max-height: 360px; overflow: auto; margin: 10px 0;
}
@media (max-width: 900px) {
  .hai-cot.nh { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .o-tong { grid-template-columns: 1fr; }
  .gd { grid-template-columns: minmax(0, 1fr) auto; }
  .gd-gio { grid-column: 1 / -1; }
}
.the-khoi label select { display: block; margin-top: 4px; padding: 9px 10px; font-size: 15px; }
/* Man hep: hang the trang xuong dong rieng, vuot thi vuot ngang trong hang */
@media (max-width: 600px) {
  .dau { flex-wrap: wrap; row-gap: 6px; }
  .the-trang { order: 3; width: 100%; overflow-x: auto; scrollbar-width: none; }
  .the-trang button { flex: none; }
  #ten-nguoi-dung { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55vw; }
}

/* ----- Tong quan, Cai dat, chia khach ----- */
.o-tong.tq { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.o-so b.do { color: var(--do); }
.o-so b.xam { color: var(--phu); }
.tq-cho { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; border: none; border-bottom: 1px solid var(--vien); border-radius: 0; padding: 10px 2px; background: none; }
.tq-cho:hover { background: #f6f8fa; }
.tq-cho .ht-giua { flex: 1; min-width: 0; }
.tq-cho .ht-gio.lau { color: var(--do); font-weight: 700; }
.cuon-ngang { overflow-x: auto; }
table.bang { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
table.bang th { text-align: left; font-size: 12px; color: var(--phu); font-weight: 600; padding: 6px; border-bottom: 1px solid var(--vien); white-space: nowrap; }
table.bang td { padding: 8px 6px; border-bottom: 1px solid var(--vien); white-space: nowrap; }
table.bang td.do { color: var(--do); font-weight: 600; }
.nv { border: 1px solid var(--vien); border-radius: 10px; padding: 12px; margin-top: 10px; }
.nv.bi-khoa { background: #f6f8fa; }
.nv .kn-dau strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nv .hang-nut.trai { margin-top: 8px; }
.mk-noi-dung { width: 100%; font: 14px/1.5 ui-monospace, Consolas, monospace; padding: 10px; border: 1px solid var(--vien); border-radius: 8px; resize: none; margin-top: 10px; }
.nhan-phu-trach { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--phu); white-space: nowrap; margin: 0; }
.nhan-phu-trach.an { display: none; }
.chon-phu-trach { width: auto; max-width: 150px; padding: 6px 8px; font-size: 13px; }
.ht-nick .phu-trach { color: var(--chinh); }
@media (max-width: 600px) {
  .nhan-phu-trach span { display: none; }
  .chon-phu-trach { max-width: 105px; }
}

/* Thanh tren cung: 6 the trang, man vua thi xuong dong */
#ten-to-chuc, #ten-nguoi-dung { white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 1100px) {
  #ten-to-chuc { display: none; }
}
@media (max-width: 900px) {
  .dau { flex-wrap: wrap; row-gap: 6px; }
  .the-trang { order: 3; width: 100%; margin-left: 0; overflow-x: auto; scrollbar-width: none; }
  .the-trang button { flex: none; }
}
