/*
  Kế hoạch thiết kế

  Ai dùng: nhân viên Chăm sóc khách hàng và Lễ tân, ngồi máy tính tại quầy, đôi lúc dùng điện thoại.
  Việc chính: trả lời tin nhắn của khách. Điều cần thấy đầu tiên: ai đang chờ, chờ bao lâu, ai phụ trách.

  Màu
    giấy      nền trang, hơi ấm để mắt đỡ mỏi khi trực cả ca
    mặt       nền của vùng nội dung
    mực       chữ chính;  mực nhạt: chữ phụ
    cổ vịt    màu hành động duy nhất (nút chính, mục đang chọn, tin của nhân viên)
    đỏ, cam, xanh   chỉ dùng cho trạng thái: quá hạn, đang chờ, đã xong (luôn kèm chữ)
    vàng ghi chú    nền của ghi chú nội bộ, để không lẫn với tin gửi khách

  Chữ: một phông hệ thống hiển thị tốt tiếng Việt; phân cấp bằng độ đậm và màu, số dùng chữ số đều.

  Bố cục: ba cột gồm danh sách việc, cuộc trò chuyện, hồ sơ khách; màn hẹp thu về một cột và đi từng bước.
*/

:root {
  --giay: #F4F2EC;
  --mat: #FFFFFF;
  --muc: #1B2428;
  --muc-nhat: #55626A;
  --ke: #DAD6CC;
  --co-vit: #0D6660;
  --co-vit-dam: #0A524D;
  --tren-co-vit: #FFFFFF;
  --co-vit-nen: #DCEFEC;
  --do: #B3261E;
  --do-nen: #FCE9E7;
  --cam: #8F5200;
  --cam-nen: #FDF0D9;
  --xanh: #1C7447;
  --xanh-nen: #E3F3EA;
  --ghi-chu: #FFF3C4;
  --bong: 0 1px 2px rgba(27, 36, 40, .08), 0 8px 24px rgba(27, 36, 40, .10);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --giay: #12171A;
    --mat: #1B2226;
    --muc: #E7ECEE;
    --muc-nhat: #A2AEB5;
    --ke: #2F393F;
    --co-vit: #56C6BC;
    --co-vit-dam: #7AD6CD;
    --tren-co-vit: #06201E;
    --co-vit-nen: #173B38;
    --do: #FF8A80;
    --do-nen: #3D1C1A;
    --cam: #F2B45A;
    --cam-nen: #3A2A10;
    --xanh: #6FD49C;
    --xanh-nen: #15331F;
    --ghi-chu: #3B3312;
    --bong: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--giay);
  color: var(--muc);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 22px; line-height: 1.3; }
h2 { font-size: 17px; line-height: 1.35; }
h3 { font-size: 15px; }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible { outline: 3px solid var(--co-vit); outline-offset: 2px; }

.nhat { color: var(--muc-nhat); }
.so { font-variant-numeric: tabular-nums; }
.boot { padding: 48px 16px; text-align: center; color: var(--muc-nhat); }

/* ---------- nút ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 8px 16px;
  border: 1px solid var(--ke); border-radius: 8px;
  background: var(--mat); color: var(--muc);
  font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--muc-nhat); }
.btn[disabled] { opacity: .6; cursor: default; }
.btn-chinh { background: var(--co-vit); border-color: var(--co-vit); color: var(--tren-co-vit); }
.btn-chinh:hover { background: var(--co-vit-dam); border-color: var(--co-vit-dam); }
.btn-nguy { color: var(--do); border-color: var(--do); background: transparent; }
.btn-chu { border-color: transparent; background: transparent; color: var(--co-vit); padding-left: 8px; padding-right: 8px; }
.btn-chu:hover { border-color: transparent; text-decoration: underline; }

/* ---------- ô nhập ---------- */

.o { display: grid; gap: 4px; }
.o label, .o .nhan { font-weight: 600; font-size: 14px; }
.o .goi-y { font-size: 14px; color: var(--muc-nhat); }
input[type="text"], input[type="password"], input[type="search"], input[type="tel"], input[type="number"], select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px;
  border: 1px solid var(--ke); border-radius: 8px;
  background: var(--mat); color: var(--muc);
}
textarea { resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--muc-nhat); }
.loi-o { color: var(--do); font-size: 14px; font-weight: 600; }
.da-luu { color: var(--xanh); font-size: 14px; font-weight: 600; }

.chon-nhieu { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.chon-nhieu label { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-weight: 400; font-size: 15px; }
.chon-nhieu input { width: 20px; height: 20px; }

/* ---------- khung ứng dụng ---------- */

#app { height: 100dvh; display: flex; flex-direction: column; }

.thanh-tren {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 16px; background: var(--mat); border-bottom: 1px solid var(--ke);
}
.ten-app { font-weight: 700; font-size: 16px; margin-right: 8px; white-space: nowrap; }
.dieu-huong { display: flex; gap: 4px; }
.dieu-huong button {
  min-height: 44px; padding: 8px 12px; border: 0; border-radius: 8px;
  background: transparent; font-weight: 600; color: var(--muc-nhat); cursor: pointer; white-space: nowrap;
}
.dieu-huong button[aria-current="page"] { background: var(--co-vit-nen); color: var(--muc); }
.dem {
  display: inline-block; min-width: 22px; margin-left: 6px; padding: 0 6px;
  border-radius: 11px; background: var(--do); color: #fff;
  font-size: 13px; font-weight: 700; line-height: 22px; text-align: center; font-variant-numeric: tabular-nums;
}
@media (prefers-color-scheme: dark) { .dem { color: #2A0B09; } }
.nguoi-dung { margin-left: auto; text-align: right; line-height: 1.3; min-width: 0; }
.nguoi-dung strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nguoi-dung span { font-size: 14px; color: var(--muc-nhat); }

.bao-mat-ket-noi {
  padding: 8px 16px; background: var(--cam-nen); color: var(--cam); font-weight: 600; text-align: center;
}

.chinh { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---------- đăng nhập ---------- */

.dang-nhap { flex: 1; display: grid; place-items: center; padding: 24px 16px; }
.dang-nhap form { width: 100%; max-width: 380px; display: grid; gap: 16px; }
.dang-nhap .don-vi { color: var(--muc-nhat); margin-top: 4px; }

/* ---------- màn trực tin nhắn ---------- */

.hop-thu {
  flex: 1; min-height: 0; display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr) 320px;
}
.cot { min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.cot-ds { border-right: 1px solid var(--ke); }
.cot-tro-chuyen { background: var(--mat); }
.cot-ho-so { border-left: 1px solid var(--ke); overflow-y: auto; padding: 16px; gap: 24px; }

.cong-cu-ds { padding: 12px 12px 8px; display: grid; gap: 8px; }
.the-loc { display: flex; gap: 4px; }
.the-loc button {
  flex: 1; min-height: 44px; padding: 6px 8px; border: 1px solid transparent; border-radius: 8px;
  background: transparent; font-weight: 600; color: var(--muc-nhat); cursor: pointer;
}
.the-loc button[aria-selected="true"] { background: var(--mat); border-color: var(--ke); color: var(--muc); }
.loc-hang { display: grid; grid-template-columns: 1fr; gap: 8px; }

.ds-cuon { flex: 1; overflow-y: auto; padding: 0 8px 16px; }
.nhom-tieu-de {
  display: flex; align-items: baseline; gap: 8px;
  margin: 16px 8px 4px; font-size: 14px; font-weight: 700; color: var(--muc-nhat);
}
.nhom-tieu-de.tre { color: var(--do); }
.nhom-tieu-de .so { font-weight: 600; }

.dong {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px;
  width: 100%; padding: 10px 8px; border: 0; border-radius: 8px;
  background: transparent; text-align: left; cursor: pointer;
}
.dong:hover { background: var(--mat); }
.dong[aria-current="true"] { background: var(--co-vit-nen); }
.dong .ten { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dong.cho .ten { font-weight: 700; }
.dong .gio { font-size: 14px; color: var(--muc-nhat); font-variant-numeric: tabular-nums; }
.dong .xem-truoc {
  grid-column: 1 / -1; color: var(--muc-nhat);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dong.cho .xem-truoc { color: var(--muc); }
.dong .phu { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 14px; color: var(--muc-nhat); }

.the {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 1px 8px; border-radius: 6px; border: 1px solid var(--ke);
  font-size: 13px; font-weight: 600; color: var(--muc); background: var(--mat); white-space: nowrap;
}
.the::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--muc-nhat); }
.the.facebook::before { background: #1877F2; border-radius: 50%; }
.the.zalo_oa::before { background: #0068FF; transform: rotate(45deg); }
.huy-hieu { padding: 1px 8px; border-radius: 6px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.huy-hieu.tre { background: var(--do-nen); color: var(--do); }
.huy-hieu.cho { background: var(--cam-nen); color: var(--cam); }
.huy-hieu.xong { background: var(--xanh-nen); color: var(--xanh); }

.trong { padding: 32px 16px; text-align: center; color: var(--muc-nhat); display: grid; gap: 12px; justify-items: center; }
.trong strong { color: var(--muc); font-size: 16px; }

/* ---------- cuộc trò chuyện ---------- */

.dau-tro-chuyen {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--ke);
}
.dau-tro-chuyen .ai { flex: 1 1 220px; min-width: 0; }
.dau-tro-chuyen .ai h2 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dau-tro-chuyen .ai p { font-size: 14px; color: var(--muc-nhat); }
.dau-tro-chuyen .viec { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.dau-tro-chuyen select { width: auto; max-width: 200px; font-weight: 600; }
.phu-trach { font-weight: 600; color: var(--muc); }
.nut-lui, .nut-ho-so { display: none; }

.tin-cuon { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.ngay { align-self: center; margin: 8px 0 4px; font-size: 14px; font-weight: 600; color: var(--muc-nhat); }
.tin { max-width: min(78%, 560px); display: grid; gap: 2px; }
.tin .bong {
  padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--giay); border: 1px solid var(--ke);
}
.tin .ghi { font-size: 13px; color: var(--muc-nhat); font-variant-numeric: tabular-nums; }
.tin.den { align-self: flex-start; }
.tin.di { align-self: flex-end; justify-items: end; }
.tin.di .bong { background: var(--co-vit-nen); border-color: transparent; }
.tin.di.loi .bong { background: var(--do-nen); }
.tin .bao-loi { color: var(--do); font-size: 14px; font-weight: 600; text-align: right; }
.tin.ghi-chu { align-self: stretch; max-width: none; }
.tin.ghi-chu .bong { background: var(--ghi-chu); border-color: transparent; border-radius: 8px; }
.tin.ghi-chu .ghi { font-weight: 600; color: var(--muc); }
.tin img { display: block; max-width: 240px; max-height: 240px; border-radius: 8px; margin-top: 4px; }
.he-thong { align-self: center; font-size: 14px; color: var(--muc-nhat); text-align: center; }

.soan { border-top: 1px solid var(--ke); padding: 12px 16px 16px; display: grid; gap: 8px; }
.soan .che-do { display: flex; gap: 4px; }
.soan .che-do button {
  min-height: 36px; padding: 4px 12px; border: 1px solid var(--ke); border-radius: 8px;
  background: transparent; font-weight: 600; color: var(--muc-nhat); cursor: pointer;
}
.soan .che-do button[aria-pressed="true"] { background: var(--co-vit-nen); border-color: transparent; color: var(--muc); }
.soan.ghi-chu textarea { background: var(--ghi-chu); }
.soan .hang-gui { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.soan .hang-gui select { width: auto; max-width: 260px; }
.luu-y { padding: 8px 12px; border-radius: 8px; background: var(--cam-nen); color: var(--cam); font-weight: 600; font-size: 14px; }
.luu-y.thuong { background: var(--giay); color: var(--muc-nhat); font-weight: 400; }
.thong-bao-phu-trach { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: space-between; }

/* ---------- hồ sơ khách ---------- */

.khoi { display: grid; gap: 12px; }
.khoi form { display: grid; gap: 12px; }
.nhan-chon { display: flex; flex-wrap: wrap; gap: 8px; }
.nhan-chon button {
  min-height: 36px; padding: 4px 12px; border: 1px solid var(--ke); border-radius: 18px;
  background: var(--mat); cursor: pointer;
}
.nhan-chon button[aria-pressed="true"] { background: var(--co-vit); border-color: var(--co-vit); color: var(--tren-co-vit); font-weight: 600; }
.thong-tin { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; font-size: 14px; }
.thong-tin dt { color: var(--muc-nhat); }
.thong-tin dd { margin: 0; font-weight: 600; }

/* ---------- cài đặt ---------- */

.cai-dat { flex: 1; overflow-y: auto; padding: 24px 16px 48px; }
.cai-dat-trong { max-width: 960px; margin: 0 auto; display: grid; gap: 24px; }
.the-cai-dat { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--ke); padding-bottom: 8px; }
.the-cai-dat button {
  min-height: 44px; padding: 8px 12px; border: 0; border-radius: 8px;
  background: transparent; font-weight: 600; color: var(--muc-nhat); cursor: pointer;
}
.the-cai-dat button[aria-selected="true"] { background: var(--co-vit-nen); color: var(--muc); }
.muc { display: grid; gap: 16px; }
.muc > p { max-width: 70ch; }
.bang-cuon { overflow-x: auto; background: var(--mat); border: 1px solid var(--ke); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--ke); }
th { font-size: 14px; color: var(--muc-nhat); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.viec { white-space: nowrap; text-align: right; }
td.viec .btn { min-height: 36px; padding: 4px 10px; }
.xac-nhan { display: grid; gap: 8px; padding: 12px; border-radius: 8px; background: var(--do-nen); }
.xac-nhan .hang, .hang-nut { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.bieu-mau {
  display: grid; gap: 12px; padding: 16px; max-width: 560px;
  background: var(--mat); border: 1px solid var(--ke); border-radius: 8px;
}
.kenh { display: grid; gap: 12px; padding: 16px; background: var(--mat); border: 1px solid var(--ke); border-radius: 8px; }
.kenh .dau { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: space-between; }
.kenh .luoi { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; align-items: start; }
td strong { white-space: nowrap; }
.ma { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; overflow-wrap: anywhere; }
.mau-tra-loi { display: grid; gap: 4px; padding: 12px 0; border-bottom: 1px solid var(--ke); }
.mau-tra-loi .dau { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.mau-tra-loi p { white-space: pre-wrap; color: var(--muc-nhat); }

/* ---------- thông báo nổi ---------- */

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20; display: grid; gap: 8px; width: min(92vw, 480px); pointer-events: none; }
#toast div { padding: 12px 16px; border-radius: 8px; background: var(--muc); color: var(--giay); font-weight: 600; box-shadow: var(--bong); }
#toast div.loi { background: var(--do); color: #fff; }
@media (prefers-color-scheme: dark) { #toast div.loi { color: #2A0B09; } }

/* ---------- màn vừa: ẩn cột hồ sơ, mở khi cần ---------- */

@media (max-width: 1100px) {
  .hop-thu { grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); }
  .cot-ho-so { display: none; border-left: 0; background: var(--giay); }
  .hop-thu[data-pane="ho-so"] .cot-tro-chuyen { display: none; }
  .hop-thu[data-pane="ho-so"] .cot-ho-so { display: flex; }
  .nut-ho-so { display: inline-flex; }
}

/* ---------- màn hẹp: một cột, đi từng bước ---------- */

@media (max-width: 760px) {
  .hop-thu { grid-template-columns: minmax(0, 1fr); }
  .cot-ds { border-right: 0; }
  .hop-thu[data-pane="ds"] .cot-tro-chuyen,
  .hop-thu[data-pane="tro-chuyen"] .cot-ds,
  .hop-thu[data-pane="ho-so"] .cot-ds { display: none; }
  .nut-lui { display: inline-flex; }
  .thanh-tren { padding: 6px 8px; gap: 4px; }
  .thanh-tren .btn { padding: 8px 10px; }
  .dieu-huong button { padding: 8px; }
  .ten-app { display: none; }
  .nguoi-dung span { display: none; }
  .tin { max-width: 88%; }
  .dau-tro-chuyen { padding: 8px 12px; }
  .tin-cuon { padding: 12px; }
  .soan { padding: 8px 12px 12px; }
  .cai-dat { padding: 16px 12px 48px; }
}

@media (prefers-reduced-motion: no-preference) {
  .tin.moi { animation: hien .18s ease-out; }
  @keyframes hien { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}
