/* ============================================================
   TEAMHUB — APP LAYOUT & COMPONENTS
   ============================================================
   Port nguyên văn từ app.css của CRM (mục 1–12), bổ sung mục 13
   riêng cho TeamHub (trang đăng nhập / đổi mật khẩu).
   Style riêng: sidebar, layout, bảng, form, badge trạng thái.
   Màu sắc LUÔN dùng biến từ brand.css (--brand-primary, ...).
   ============================================================ */

/* ============================================================
   1. LAYOUT — SIDEBAR + MAIN
   ============================================================ */
body {
  background-color: var(--color-bg-alt);
  color: var(--color-text);
  min-height: 100vh;
}

.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.app-sidebar {
  width: 240px;
  flex-shrink: 0;
  background-color: #ffffff;
  border-right: 1px solid var(--color-border-light);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 1030;
  transition: transform 0.25s ease;
}

.app-sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--color-border-light);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--brand-primary);
  text-decoration: none;
}

.app-sidebar__brand:hover {
  color: var(--brand-primary-dark);
}

.app-sidebar__brand i {
  font-size: 1.5rem;
}

.app-sidebar__nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
  /* Ẩn thanh trượt sidebar (09/11, Papa yêu cầu) — vẫn cuộn được bằng
     lăn chuột / phím / cảm ứng, chỉ không hiện thanh trượt nữa. */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge cũ */
}

/* Chrome / Edge / Safari: ẩn thanh trượt sidebar */
.app-sidebar__nav::-webkit-scrollbar {
  display: none;
}

.app-sidebar__nav .nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  margin-bottom: 2px;
  border-radius: 8px;
  color: var(--color-text);
  font-weight: 500;
  font-size: 0.93rem;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.app-sidebar__nav .nav-link i {
  font-size: 1.1rem;
  width: 20px;
  text-align: center;
  color: var(--color-text-muted);
  transition: color 0.15s ease;
}

.app-sidebar__nav .nav-link:hover {
  background-color: var(--brand-primary-bg);
  color: var(--brand-primary-dark);
}

.app-sidebar__nav .nav-link:hover i {
  color: var(--brand-primary);
}

.app-sidebar__nav .nav-link.active {
  background-color: var(--brand-primary);
  color: #ffffff;
}

.app-sidebar__nav .nav-link.active i {
  color: #ffffff;
}

.app-sidebar__nav .nav-link.disabled {
  color: var(--color-text-light);
  pointer-events: none;
  opacity: 0.6;
}

/* v0.3.3: badge số tin chưa đọc ở sidebar (pill nhỏ, nền cam, chữ trắng).
   Ẩn khi = 0 bằng thuộc tính hidden — cần rule [hidden] riêng vì
   display: inline-flex của author CSS thắng style mặc định của [hidden].
   Link đang active (nền cam) thì badge đổi thành nền trắng, chữ cam để
   vẫn nhìn rõ. */
.app-sidebar__nav .nav-badge {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background-color: #F85922;
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
}

.app-sidebar__nav .nav-badge[hidden] {
  display: none;
}

.app-sidebar__nav .nav-link.active .nav-badge {
  background-color: #ffffff;
  color: #F85922;
}

.app-sidebar__divider {
  height: 1px;
  background-color: var(--color-border-light);
  margin: 10px 12px;
}

.app-sidebar__section-label {
  padding: 6px 14px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-light);
}

/* ---------- Main ---------- */
.app-main {
  flex: 1;
  margin-left: 240px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ---------- Topbar ---------- */
.app-topbar {
  background-color: #ffffff; /* Đổi sang trắng */
  color: var(--color-text);  /* Chữ màu tối */
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 1020;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.app-topbar__title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0;
}

.app-topbar__breadcrumb {
  font-size: 0.83rem;
  margin: 0;
  padding: 0;
  background: none;
}

.app-topbar__breadcrumb .breadcrumb-item + .breadcrumb-item::before {
  color: rgba(0, 0, 0, 0.4);
}

.app-topbar__breadcrumb a {
  color: var(--brand-navbar-text);
  text-decoration: none;
  opacity: 0.75;
}

.app-topbar__breadcrumb a:hover {
  opacity: 1;
  text-decoration: underline;
}

.app-topbar__user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 600;
}

.app-topbar__user i {
  font-size: 1.3rem;
}

/* v0.3.3: nút chuông chuyển màu cam khi thông báo đang BẬT (class do
   app.js thêm/bỏ theo trạng thái subscribe/quyền). Đặt sau Bootstrap nên
   thắng được màu của .btn-outline-secondary ở cùng độ ưu tiên; thêm cả
   :hover/:focus-visible để màu cam giữ nguyên khi rê chuột. */
.bell-on {
  color: #F85922;
  border-color: #F85922;
}

.bell-on:hover,
.bell-on:focus-visible {
  color: #F85922;
  border-color: #F85922;
  background-color: rgba(248, 89, 34, 0.08);
}

.sound-on {
  color: #F85922;
  border-color: #F85922;
}

.sound-on:hover,
.sound-on:focus-visible {
  color: #F85922;
  border-color: #F85922;
  background-color: rgba(248, 89, 34, 0.08);
}

/* ---------- Banner bật thông báo đẩy (v0.3.6) ---------- */
.push-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1rem 24px 0;
  padding: 0.75rem 1rem;
  background-color: rgba(248, 89, 34, 0.08);
  border: 1px solid #F85922;
  border-radius: 0.5rem;
}

.push-banner > .bi-bell {
  font-size: 1.5rem;
  color: #F85922;
  flex-shrink: 0;
}

.push-banner__text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.push-banner__text span {
  font-size: 0.875rem;
  color: #6c757d;
}

.push-banner__enable {
  flex-shrink: 0;
  background-color: #F85922;
  border: 1px solid #F85922;
  color: #fff;
  border-radius: 0.375rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  cursor: pointer;
}

.push-banner__enable:hover {
  background-color: #e04e1c;
  border-color: #e04e1c;
}

.push-banner__later {
  flex-shrink: 0;
  background: none;
  border: none;
  color: #6c757d;
  font-size: 0.875rem;
  cursor: pointer;
  padding: 0.375rem 0.5rem;
}

.push-banner__later:hover {
  color: #343a40;
  text-decoration: underline;
}

@media (max-width: 576px) {
  .push-banner {
    flex-wrap: wrap;
  }
}

/* ---------- Content ---------- */
.app-content {
  flex: 1;
  padding: 24px;
}

/* ---------- Footer ---------- */
.app-footer {
  background-color: #ffffff; /* Đổi sang trắng */
  color: var(--color-text-muted); /* Chữ xám cho nhẹ nhàng */
  border-top: 1px solid var(--color-border-light); /* Thêm đường kẻ mỏng phân cách */
  padding: 12px 24px;
  font-size: 0.83rem;
  text-align: center;
}

/* ============================================================
   2. PAGE HEADER (tiêu đề trang + nút hành động)
   ============================================================ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0;
  color: var(--color-text-heading);
}

.page-header__subtitle {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin: 2px 0 0;
}

/* ============================================================
   3. CARD / PANEL
   ============================================================ */
.app-card {
  background-color: #ffffff;
  border: 1px solid var(--color-border-light);
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.app-card + .app-card {
  margin-top: 16px;
}

.app-card__title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--color-text-heading);
}

/* ============================================================
   4. TABLE
   ============================================================ */
.app-table {
  width: 100%;
  margin: 0;
  font-size: 0.9rem;
}

.app-table thead th {
  background-color: var(--color-bg-muted);
  color: var(--color-text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 10px 12px;
  border-bottom: 2px solid var(--color-border-light);
  white-space: nowrap;
}

.app-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border-light);
  vertical-align: middle;
}

.app-table tbody tr:hover {
  background-color: var(--brand-primary-bg);
}

.app-table tbody tr:last-child td {
  border-bottom: none;
}

.app-table__empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--color-text-muted);
  font-style: italic;
}

/* ============================================================
   5. BUTTONS (bổ sung cho Bootstrap)
   ============================================================ */
.btn-brand {
  background-color: var(--brand-primary);
  border-color: var(--brand-primary);
  color: #ffffff;
  font-weight: 600;
}

.btn-brand:hover,
.btn-brand:focus {
  background-color: var(--brand-primary-dark);
  border-color: var(--brand-primary-dark);
  color: #ffffff;
}

.btn-brand:active {
  background-color: var(--brand-primary-darker) !important;
  border-color: var(--brand-primary-darker) !important;
}

.btn-outline-brand {
  background-color: transparent;
  border: 1px solid var(--brand-primary);
  color: var(--brand-primary);
  font-weight: 600;
}

.btn-outline-brand:hover,
.btn-outline-brand:focus {
  background-color: var(--brand-primary);
  border-color: var(--brand-primary);
  color: #ffffff;
}

/* ============================================================
   6. BADGES — Loại khách hàng
   ============================================================ */
.badge-type {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 50px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.badge-type--retail {
  background-color: #e3f2fd;
  color: #1565c0;
}

.badge-type--project {
  background-color: #f3e5f5;
  color: #6a1b9a;
}

.badge-type--reseller {
  background-color: #e8f5e9;
  color: #2e7d32;
}

.badge-type--dealer {
  background-color: #fff3e0;
  color: #e65100;
}

/* ============================================================
   7. BADGES — Trạng thái chung
   ============================================================ */
.badge-status {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 50px;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-status--active   { background-color: #e8f5e9; color: #2e7d32; }
.badge-status--inactive { background-color: #eceff1; color: #546e7a; }
.badge-status--warning  { background-color: #fff8e1; color: #f57c00; }
.badge-status--danger   { background-color: #ffebee; color: #c62828; }

/* ============================================================
   8. FORM
   ============================================================ */
.form-label {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--color-text-heading);
  margin-bottom: 6px;
}

.form-label .required {
  color: var(--color-danger);
  margin-left: 2px;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 0.2rem rgba(var(--brand-primary-rgb), 0.15);
}

.form-section {
  margin-bottom: 24px;
}

.form-section__title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-text-heading);
  padding-bottom: 8px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--color-border-light);
}

.form-actions {
  display: flex;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border-light);
}

/* ============================================================
   9. FILTER BAR (tìm kiếm + lọc)
   ============================================================ */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  padding: 16px 20px;
  background-color: #ffffff;
  border: 1px solid var(--color-border-light);
  border-radius: 10px;
  margin-bottom: 16px;
}

.filter-bar .form-control,
.filter-bar .form-select {
  max-width: 240px;
}

.filter-bar__spacer {
  flex: 1;
}

/* ============================================================
   10. PAGINATION (bổ sung Bootstrap)
   ============================================================ */
.app-pagination {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}

.app-pagination .page-link {
  color: var(--brand-primary);
  border-color: var(--color-border-light);
}

.app-pagination .page-item.active .page-link {
  background-color: var(--brand-primary);
  border-color: var(--brand-primary);
  color: #ffffff;
}

.app-pagination .page-item.disabled .page-link {
  color: var(--color-text-light);
}

/* ============================================================
   11. DETAIL VIEW (trang chi tiết)
   ============================================================ */
.detail-list {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 10px 16px;
  font-size: 0.9rem;
}

.detail-list dt {
  color: var(--color-text-muted);
  font-weight: 600;
}

.detail-list dd {
  margin: 0;
  color: var(--color-text);
}

/* ============================================================
   12. RESPONSIVE
   ============================================================ */
@media (max-width: 991.98px) {
  .app-sidebar {
    transform: translateX(-100%);
  }

  .app-sidebar.is-open {
    transform: translateX(0);
  }

  .app-main {
    margin-left: 0;
  }

  .app-topbar__toggle {
    display: inline-flex !important;
  }
}

.app-topbar__toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--brand-navbar-text);
  padding: 0 8px 0 0;
}

/* Fix triệt để dropdown bị cắt trong table-responsive */
.table-responsive {
  overflow-x: auto;
  overflow-y: visible !important; /* Cho phép dropdown xổ ra ngoài */
}
.dropdown-menu.product-dropdown {
  box-shadow: 0 0.5rem 1rem rgba(0,0,0,.175) !important;
}
/* ============================================================
   13. TEAMHUB — trang đăng nhập / đổi mật khẩu
   ============================================================
   Theo mẫu login của CRM — CRM để <style> inline trong login.ejs,
   TeamHub đưa vào file riêng (sạch hơn, không inline style). */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 420px;
}

/* ============================================================
   14. TEAMHUB — chat GĐ2 (hội thoại 1-1 + phòng nhóm)
   ============================================================
   CRM không có chat nên mục này TeamHub tự viết, theo tokens
   brand (#F85922) + bảng màu chung. */
.chat-messages {
  max-height: 480px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 2px;
}

.chat-message {
  max-width: 75%;
  padding: 8px 12px;
  border-radius: 12px;
  background-color: var(--color-bg-muted);
  border: 1px solid var(--color-border-light);
  align-self: flex-start;
  word-break: break-word;
}

.chat-message--mine {
  align-self: flex-end;
  background-color: var(--brand-primary-lighter);
  border-color: var(--brand-primary-border);
}

.chat-message__sender {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 2px;
}

.chat-message--mine .chat-message__sender {
  color: var(--brand-primary-dark);
}

.chat-message__text {
  white-space: pre-wrap;
}

.chat-message__time {
  font-size: 11px;
  color: var(--color-text-light);
  margin-top: 4px;
  text-align: right;
}

/* ============================================================
   15. TEAMHUB — presence + typing + toast thông báo (v0.3.1)
   ============================================================ */

/* --- Chấm trạng thái online --- */
.presence {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--color-text-muted);
  margin-left: 6px;
  white-space: nowrap;
}

.presence-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background-color: #b0bec5; /* offline: xám */
  flex-shrink: 0;
}

.presence-dot--online {
  background-color: #2e7d32; /* online: xanh lá */
  box-shadow: 0 0 0 2px rgba(46, 125, 50, 0.18);
}

/* --- "Đang nhập..." + 3 chấm nhấp nháy --- */
.typing-indicator {
  font-size: 0.83rem;
  color: var(--color-text-muted);
  font-style: italic;
  padding: 6px 2px 0;
  min-height: 22px;
}

.typing-dots {
  display: inline-flex;
  gap: 3px;
  margin-left: 4px;
  vertical-align: middle;
}

.typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background-color: var(--color-text-muted);
  animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* --- Toast thông báo tin mới (kiểu Facebook, góc dưới phải) --- */
.toast-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 1050;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(340px, calc(100vw - 32px));
}

.chat-toast {
  position: relative;
  background-color: #ffffff;
  border: 1px solid var(--color-border-light);
  border-left: 4px solid var(--brand-primary);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
  padding: 12px 32px 12px 14px;
  cursor: pointer;
}

.chat-toast:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.chat-toast__sender {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--color-text-heading);
  margin-bottom: 2px;
}

.chat-toast__text {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.chat-toast__close {
  position: absolute;
  top: 4px;
  right: 8px;
  background: none;
  border: none;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--color-text-light);
  padding: 2px 4px;
  cursor: pointer;
}

.chat-toast__close:hover {
  color: var(--color-text);
}
