/* Bo cuc chinh + cot trai: tai khoan, hoi thoai, nhan. (Tach tu styles.css - nap theo DUNG thu tu trong index.html) */

/* =====================================================================
   Bo cuc chinh
   ===================================================================== */
#app-screen { display: flex; height: 100vh; overflow: hidden; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 330px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  height: 100%; /* cot ben trai cuon rieng, doc lap voi khung chat ben phai */
  box-shadow: 2px 0 12px rgba(23, 32, 51, .03);
  position: relative; z-index: 2;
}

/* Khoi dau sidebar: nen gradient + hoa van mo, chua ten nguoi dung, o tim
   kiem va nut quan tri - diem nhan mau sac chinh cua ca giao dien. */
.sidebar-hero {
  position: relative; overflow: hidden; overflow: clip; flex-shrink: 0; /* clip: khong bi cuon ngang khi focus nut */
  background: var(--grad);
  color: #fff;
  padding-bottom: 14px;
}
.sidebar-hero::before, .sidebar-hero::after {
  content: ""; position: absolute; border-radius: 50%; pointer-events: none;
}
.sidebar-hero::before { width: 220px; height: 220px; right: -70px; top: -110px; background: radial-gradient(circle, rgba(255, 255, 255, .28), transparent 70%); }
.sidebar-hero::after { width: 180px; height: 180px; left: -60px; bottom: -110px; background: radial-gradient(circle, rgba(140, 220, 255, .35), transparent 70%); }
.sidebar-hero > * { position: relative; z-index: 1; }

.sidebar-header {
  padding: 16px 12px 14px 16px; display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.sidebar-brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.sidebar-hero .brand-mark.sm {
  background: rgba(255, 255, 255, .2); border: 1px solid rgba(255, 255, 255, .35);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .3);
}
.sidebar-user { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.sidebar-user strong { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-hero .muted { color: rgba(255, 255, 255, .78); }
.sidebar-hero .icon-btn { color: rgba(255, 255, 255, .85); }
.sidebar-header-actions { display: flex; align-items: center; gap: 2px; }
#notify-toggle-btn .bell-off { display: none; }
#notify-toggle-btn.muted-notify .bell-on { display: none; }
#notify-toggle-btn.muted-notify .bell-off { display: inline; }
#notify-toggle-btn.muted-notify { color: rgba(255, 255, 255, .55); }
.sidebar-hero .icon-btn:hover { background: rgba(255, 255, 255, .18); color: #fff; }

/* O "Tim kiem" kieu kinh mo tren nen gradient */
.search-trigger {
  display: flex; align-items: center; gap: 9px; width: calc(100% - 32px);
  margin: 0 16px 10px; padding: 10px 13px;
  background: rgba(255, 255, 255, .16); border: 1px solid rgba(255, 255, 255, .28); border-radius: var(--radius);
  color: rgba(255, 255, 255, .9); font-size: 13px; text-align: left;
  backdrop-filter: blur(6px);
  transition: background .2s, border-color .2s, box-shadow .2s;
}
.search-trigger:hover { background: rgba(255, 255, 255, .26); border-color: rgba(255, 255, 255, .45); box-shadow: 0 6px 18px rgba(0, 30, 100, .18); }
.sidebar-search { cursor: text; padding-top: 0; padding-bottom: 0; }
.sidebar-search:focus-within { background: #fff; border-color: #fff; box-shadow: 0 8px 22px rgba(0, 30, 100, .22); color: var(--primary); }
.sidebar-search #sidebar-search-input {
  flex: 1; min-width: 0; border: none; background: transparent; outline: none; box-shadow: none;
  padding: 10px 0; color: #fff; font: inherit; font-size: 13px; border-radius: 0;
}
.sidebar-search input::placeholder { color: rgba(255, 255, 255, .82); }
.sidebar-search:focus-within #sidebar-search-input { color: var(--text); }
.sidebar-search:focus-within input::placeholder { color: var(--muted); }
.sidebar-search input::-webkit-search-cancel-button { display: none; }
.sidebar-search-clear {
  flex-shrink: 0; width: 22px; height: 22px; border-radius: 50%; border: none; cursor: pointer; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .25); color: #fff;
}
.sidebar-search:focus-within .sidebar-search-clear { background: var(--surface-2); color: var(--muted); }
.sidebar-search-clear:hover { background: var(--danger) !important; color: #fff !important; }

/* Ket qua tim kiem thay cho danh sach hoi thoai */
.search-section-title {
  display: flex; align-items: center; gap: 6px; margin: 10px 4px 4px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
}
.search-section-title span {
  font-size: 11px; padding: 0 7px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); letter-spacing: 0;
}
.search-note { padding: 6px 8px 10px; font-size: 12.5px; color: var(--muted); }
.search-results-view mark { background: rgba(255, 196, 0, .38); color: inherit; border-radius: 3px; padding: 0 1px; }
.search-snippet {
  font-size: 12.5px; color: var(--text-2); line-height: 1.4; margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* Nut cong cu quan tri (Nhan vien / Tu dong tra loi) */
.sidebar-tools { display: flex; gap: 8px; padding: 0 16px; }
.sidebar-tools:not(:has(.tool-btn:not(.hidden))) { display: none; }
.tool-btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px; border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, .28); background: rgba(255, 255, 255, .1);
  color: #fff; font-size: 12.5px; font-weight: 500;
  white-space: nowrap; min-width: 0;
  transition: background .2s, transform .2s var(--ease), box-shadow .2s;
}
.tool-btn svg { flex-shrink: 0; }
.tool-btn:hover { background: #fff; color: var(--primary); transform: translateY(-1px); box-shadow: 0 6px 16px rgba(0, 30, 100, .22); }

.sidebar-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto; /* chi phan danh sach tai khoan/hoi thoai cuon, header ben tren giu co dinh */
}
.sidebar-section { padding: 14px 8px 8px; }
.sidebar-section + .sidebar-section { border-top: 1px solid var(--border); }
.section-title {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); margin: 0 8px 8px; min-height: 26px;
}
.section-title > span { display: inline-flex; align-items: center; }
.section-title > span:first-child::before { /* vach mau nho truoc tieu de muc */
  content: ""; width: 4px; height: 14px; border-radius: 4px; background: var(--grad); margin-right: 8px;
}
.section-title .small-btn { text-transform: none; letter-spacing: 0; }
#add-account-btn {
  color: #fff; border: none; background: var(--grad); font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 104, 255, .28);
}
#add-account-btn:hover { filter: brightness(1.06); box-shadow: 0 6px 16px rgba(0, 104, 255, .36); }

/* Nut "Danh dau da doc het" canh tieu de Hoi thoai (xem app.js). */
#mark-all-read-btn { padding: 3px 8px; font-size: 11px; }

.account-list, .conversation-list, .staff-list { list-style: none; margin: 0; padding: 0; }
.account-list li, .conversation-list li, .staff-list li {
  position: relative;
  padding: 8px 10px; border-radius: var(--radius); cursor: pointer; font-size: 13px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  transition: background .2s, transform .2s var(--ease);
}
.account-list li:hover, .conversation-list li:hover { background: var(--bg-surface-elevated); }
.account-list li.active, .conversation-list li.active {
  background: var(--chat-selected-row);
}
/* Vach gradient ben trai cho muc dang chon */
.account-list li.active::before, .conversation-list li.active::before {
  content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0;
  background: var(--grad);
}

/* Item tai khoan Zalo: cham trang thai + ten + dong trang thai nho */
.account-item { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.account-item-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.account-item-label { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-item-status { font-size: 11.5px; color: var(--muted); }
.status-text-connected { color: var(--success); }
.status-text-pending { color: #c98a0c; }
.status-text-disconnected, .status-text-error { color: var(--danger); }
.account-list li.active .account-item-label { color: var(--primary); font-weight: 600; }
.account-del-btn { opacity: 0; transition: opacity .2s; }
.account-reconnect-btn {
  flex-shrink: 0; margin-left: 6px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid rgba(37, 99, 235, .35); background: rgba(37, 99, 235, .1);
  color: #2563eb; font-size: 11.5px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.account-reconnect-btn:hover { background: #2563eb; color: #fff; }
.account-reconnect-btn:disabled { opacity: .6; cursor: progress; }
.qr-relink-note {
  margin: 0 0 10px; padding: 8px 10px; border-radius: 8px; font-size: 13px;
  background: rgba(37, 99, 235, .08); color: inherit; line-height: 1.45;
}
.account-list li:hover .account-del-btn { opacity: 1; }

.status-dot { position: relative; width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.status-connected { background: var(--success); }
.status-connected::after { /* song lan toa cho tai khoan dang ket noi */
  content: ""; position: absolute; inset: 0; border-radius: 50%; background: var(--success);
  animation: status-ping 2s var(--ease) infinite;
}
@keyframes status-ping { 0% { transform: scale(1); opacity: .6; } 80%, 100% { transform: scale(2.6); opacity: 0; } }
.status-pending { background: var(--warning); box-shadow: 0 0 0 3px rgba(245, 165, 36, .2); }
.status-disconnected, .status-error { background: var(--danger); box-shadow: 0 0 0 3px rgba(229, 72, 77, .15); }
.status-all { background: var(--grad); box-shadow: 0 0 0 3px rgba(0, 104, 255, .15); }

/* Item hoi thoai: avatar + 2 dong (ten/gio, tai khoan · phu trach · tin hieu) */
.conversation-list li.conv-item {
  padding: 10px 12px; gap: 10px; justify-content: flex-start; margin-bottom: 0;
  min-height: 60px; box-sizing: border-box; align-items: center;
  border-radius: 0; border-bottom: 1px solid var(--ux-border);
}
.conversation-list li.conv-item:hover { background: var(--ux-hover); }
/* Hàng đang chọn theo V3.3.2: nền --ux-sel + vạch 3px bên trái (thay vạch gradient). */
.conversation-list li.conv-item.active,
.conversation-list li.conv-item.active:hover { background: var(--ux-sel); box-shadow: inset 3px 0 0 var(--ux-sel-bar); }
.conversation-list li.conv-item.active::before { display: none; }
.conversation-list li:hover { transform: none; }
.conversation-list li:focus-visible {
  outline: 2px solid var(--primary); outline-offset: -2px;
}
.conv-avatar-wrap { position: relative; flex-shrink: 0; }
.conv-avatar {
  width: 40px; height: 40px; border-radius: 50%; color: #fff; font-size: 15px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; text-transform: uppercase;
  box-shadow: none;
}
.conversation-list li.active .conv-avatar { box-shadow: none; }
.conv-group-mark {
  position: absolute; right: -3px; bottom: -3px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--surface);
  display: flex; align-items: center; justify-content: center; font-size: 9px;
  box-shadow: var(--shadow-sm);
}
.conv-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.conv-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.conv-name {
  flex: 1; min-width: 0; font-size: 13px; font-weight: 600; color: var(--ux-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-time { font-size: 11.5px; color: var(--ux-muted); flex-shrink: 0; }
.conv-account {
  flex: 0 1 auto; max-width: 38%; min-width: 0; font-size: 12px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-meta {
  display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1;
}
.conv-owner, .conv-status {
  font-size: 12px; color: var(--ux-text-2); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 110px;
}
.conv-owner.is-unassigned { color: var(--ux-muted); font-weight: 400; }
.conv-status.st-doing { color: var(--ux-text); font-weight: 600; }
.conv-status.st-done { color: var(--ux-muted); }

/* Unread = reading state only: dam title + badge. Time stays muted. */
.conversation-list li.unread .conv-name { font-weight: 700; }
.conversation-list li.unread .conv-account { color: var(--text-2); }

/* Tong so tin chua doc canh tieu de "Hoi thoai" o sidebar */
.unread-total {
  background: var(--grad-danger); color: #fff; font-size: 10.5px; font-weight: 700; letter-spacing: 0;
  border-radius: 999px; padding: 1px 7px; margin-left: 6px;
  box-shadow: 0 3px 8px rgba(229, 72, 77, .35);
}

/* So luong tin chua doc tren tung hoi thoai trong danh sach */
.unread-badge {
  background: var(--ux-primary); color: var(--ux-on-primary); font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 5px; flex-shrink: 0;
  box-shadow: none;
  animation: badge-pop .35s var(--ease);
}
@keyframes badge-pop { from { transform: scale(.4); } 60% { transform: scale(1.15); } to { transform: scale(1); } }

/* ---------- Phan loai / gan nhan (tags) ---------- */
.conv-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 8px 8px; }
#conv-filter-label {
  font-size: 12px; color: var(--primary); background: var(--primary-soft);
  padding: 3px 9px; border-radius: 999px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500;
}
.tag-filter-select {
  padding: 5px 8px; font-size: 12.5px; cursor: pointer; max-width: 160px; margin-left: auto;
}
/* Dropdown loc nhan: icon nhan ben trai + mui ten tu ve ben phai (an mui ten
   mac dinh cua trinh duyet), dang vien thuoc bo tron. */
.select-wrap {
  position: relative; display: inline-flex; align-items: center; margin-left: auto;
  color: var(--muted); transition: color .2s;
}
.select-wrap:hover, .select-wrap:focus-within { color: var(--primary); }
.select-wrap .tag-filter-select {
  appearance: none; -webkit-appearance: none; margin: 0;
  padding: 6px 30px 6px 31px; border-radius: 999px; max-width: 170px;
  font-size: 12.5px; font-weight: 500; color: var(--text-2);
  background: var(--surface-2); border-color: var(--border);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background .2s, border-color .2s, box-shadow .2s;
}
.select-wrap:hover .tag-filter-select { background: var(--primary-soft); border-color: var(--primary-soft-2); }
.select-wrap .select-icon { position: absolute; left: 11px; pointer-events: none; }
.select-wrap .select-chevron { position: absolute; right: 10px; pointer-events: none; transition: transform .2s var(--ease); }
.select-wrap:focus-within .select-chevron { transform: rotate(180deg); }

/* Cham mau nhan nho canh ten hoi thoai trong danh sach o sidebar */
.conv-tag-dots { display: inline-flex; gap: 3px; flex-shrink: 0; }
.conv-tag-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; box-shadow: 0 0 0 2px var(--chat-avatar-ring); }

/* Cac "chip" nhan hien duoi tieu de hoi thoai dang mo (chat-header) */
.chat-tags-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.chat-tags-row:empty { display: none; }
.chat-header-actions { display: flex; gap: 8px; flex-shrink: 0; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px;
  font-size: 11px; color: #fff; font-weight: 600;
  box-shadow: none;
}

/* Danh sach checkbox nhan trong modal "Phân loại hội thoại" */
.tag-assign-list { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow-y: auto; }
.tag-assign-list li {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; font-size: 13.5px; border-radius: var(--radius-sm);
  transition: background .2s;
}
.tag-assign-list li:hover { background: var(--surface-2); }
.tag-assign-list label { display: flex; align-items: center; gap: 10px; flex: 1; cursor: pointer; }
.tag-dot-lg { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 0 3px rgba(23, 32, 51, .06); }
.tag-delete-btn {
  background: none; border: none; color: var(--danger); font-size: 12px; padding: 3px 8px; border-radius: var(--radius-sm);
}
.tag-delete-btn:hover { background: var(--danger-soft); }

.tag-create-form { display: flex; gap: 8px; align-items: center; margin-top: 4px; padding-top: 14px; border-top: 1px solid var(--border); }
.tag-create-form input[type="text"], .tag-create-form input:not([type]) { flex: 1; min-width: 0; }
.tag-create-form input[type="color"] {
  width: 42px; height: 42px; padding: 3px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); cursor: pointer; flex-shrink: 0;
}
