/* ---- Toast notification ---- */
.toast-wrap {
  position: fixed; top: 20px; right: 20px; z-index: 999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 8px;
  font-size: 13px; box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  display: flex; align-items: center; gap: 8px; min-width: 220px;
  animation: toast-in 0.2s ease;
}
.toast.toast-error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
.toast.toast-out { animation: toast-out 0.2s ease forwards; }
@keyframes toast-out { to { opacity: 0; transform: translateX(20px); } }

/* ---- Loading skeleton ---- */
.skeleton-bar {
  height: 14px; border-radius: 4px; width: 100%;
  background: linear-gradient(90deg, #EEF0F5 25%, #E4E7EE 37%, #EEF0F5 63%);
  background-size: 400% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
}
@keyframes skeleton-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}
.toolbar input, .toolbar select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.toolbar .search-input { width: 220px; }
.toolbar .grow { flex: 1; }
.toolbar.toolbar-sticky {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--card);
  padding: 6px 0;
}
/* Tab con dạng gạch chân (vd trang Hoa hồng NV: Báo cáo | Cấu hình) */
.subtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.subtab {
  background: none; border: none; border-bottom: 2px solid transparent; margin-bottom: -1px;
  padding: 8px 14px; font: inherit; font-size: 14px; font-weight: 600;
  color: var(--text-muted); cursor: pointer;
}
.subtab:hover { color: var(--ink); }
.subtab.active { color: var(--ink); border-bottom-color: var(--accent); }
.subtab-count { font-weight: 500; color: var(--text-muted); }
.checkbox-inline { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); }
.admin-toggle-box {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #F5F8FE;
  color: var(--text);
  font-size: 13px;
}
.perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  margin-top: 6px;
}
.perm-grid.disabled { opacity: 0.5; pointer-events: none; }
.perm-grid .perm-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #F9FAFC;
  font-size: 13px;
  color: var(--text);
}
.perm-grid .perm-item select { font-size: 13px; padding: 5px 6px; }

.profile-menu-wrap { position: relative; }
.profile-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 6px 6px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--border);
  cursor: pointer;
}
.profile-chip:hover { border-color: var(--accent); }
.profile-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: var(--ink); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
}
.profile-meta { text-align: left; line-height: 1.35; }
.profile-name { font-size: 13px; font-weight: 600; color: var(--ink); }
.profile-role {
  display: inline-block; margin-top: 2px; font-size: 11px; font-weight: 600;
  padding: 1px 8px; border-radius: 999px;
}
.profile-role.admin { background: #E6F7EE; color: #1a9f5c; }
.profile-role.staff { background: #F1F2F6; color: #6B7280; }
.profile-dropdown {
  display: none;
  position: absolute; top: calc(100% + 8px); right: 0;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(20,32,92,0.15);
  min-width: 190px; padding: 6px; z-index: 45;
}
.profile-dropdown.open { display: block; }
.profile-dropdown-item {
  display: block; width: 100%; text-align: left;
  padding: 9px 10px; border: none; background: none;
  font-size: 13px; color: var(--text); border-radius: 6px; cursor: pointer;
}
.profile-dropdown-item:hover { background: #F5F8FE; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
/* Bảng tự có vùng cuộn riêng, dòng tiêu đề cột đứng yên khi cuộn —
   giống cách diem-van-hoa đang làm, áp dụng cho các bảng danh sách chính. */
.table-scroll { overflow: auto; max-height: calc(100vh - 320px); }
.table-scroll table thead th { position: sticky; top: 0; z-index: 3; background: var(--card); }
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--ink); }
thead th.sortable .sort-arrow { display: inline-block; width: 10px; opacity: 0.5; }
thead th.sortable.sort-active { color: var(--ink); }
thead th.sortable.sort-active .sort-arrow { opacity: 1; }
tbody td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
tbody tr:hover { background: #FAFBFD; }
.muted { color: var(--text-muted); }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #EAF6FC;
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
}
.badge.warn { background: #FCEFEA; color: #C05621; }
.badge.off { background: #F1F2F6; color: #6B7280; }
tr.group-tier td { background: var(--ink); color: #fff; font-weight: 700; padding: 8px 10px; }
tr.group-market td { background: #E8EEFC; color: var(--ink); font-weight: 600; padding: 7px 10px 7px 26px; }
tr.group-product td { background: #F5F8FE; color: var(--ink); font-weight: 500; padding: 6px 10px 6px 42px; }
tr.group-product a { color: var(--accent); text-decoration: none; }
tr.group-product a:hover { text-decoration: underline; }
.row-actions { display: flex; gap: 6px; flex-wrap: nowrap; }
.empty-state { text-align: center; padding: 40px 0; color: var(--text-muted); }

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-muted);
}
.page-jump-input {
  width: 64px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}

/* ---------- Modal ---------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20,32,92,0.35);
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
}
.modal-box.small { max-width: 380px; }
.modal-box.wide { max-width: 1100px; }
.modal-box h3 { margin: 0 0 16px; color: var(--ink); }
/* Tiêu đề modal (luôn là phần tử con đầu tiên của .modal-box) đứng yên
   khi cuộn nội dung dài bên trong — bleed ra hết padding của .modal-box
   bằng margin âm, giống cách .topbar làm ở khung trang chính. */
.modal-box > h3 {
  position: sticky; top: -24px; z-index: 2;
  margin: -24px -24px 16px; padding: 24px 24px 0;
  background: #fff;
}
.modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
}
.modal-grid .full { grid-column: 1 / -1; }
/* Modal rộng (.modal-box.wide) dùng 3 cột cho đỡ trống — form Client */
.modal-box.wide .modal-grid { grid-template-columns: 1fr 1fr 1fr; }
/* Mỗi khu vực trong form đóng khung riêng, có nền phân biệt với modal
   (nền trắng) — dùng luôn --bg của trang (xám xanh nhạt) cho đồng bộ
   màu hệ thống thay vì bịa màu mới. */
.modal-section {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 14px;
}
.modal-section:last-of-type { margin-bottom: 0; }
/* Mỗi khu vực 1 màu nền khác nhau (pastel nhạt, pha từ màu thương hiệu
   --accent/--ink + amber trung tính) để phân biệt nhanh bằng mắt, viền
   giữ cùng tông cho đỡ chói. */
.modal-section--accent { background: #EAF6FC; border-color: #CDEBF8; }
.modal-section--ink { background: #EEF0FA; border-color: #D9DCF2; }
.modal-section--amber { background: #FFF8EC; border-color: #F5E3C0; }
/* Toàn bộ field trong khu "Thông tin bắt buộc" đều required — tô đỏ +
   đậm tên field (không phải input) để nhận ra ngay field nào bắt buộc. */
.modal-section--accent .field label:not(.checkbox-inline) {
  color: var(--danger); font-weight: 700;
}
.modal-section-title {
  margin: 0 0 10px; font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}
/* Hàng nút Lưu/Huỷ CUỐI CÙNG của modal đứng yên ở đáy khi cuộn, cùng lý
   do như tiêu đề — chỉ gắn class này cho đúng 1 hàng cuối mỗi modal (vài
   modal có nhiều .modal-actions rải rác giữa nội dung, kiểu "Tài khoản
   của tôi" có 3 hàng, không phải hàng nào cũng nên dính đáy). */
.modal-actions.sticky-footer {
  position: sticky; bottom: -24px; z-index: 2;
  padding: 12px 24px 24px; margin-left: -24px; margin-right: -24px; margin-bottom: -24px;
  background: #fff;
}
.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
}

.pick-list { max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; margin-top: 8px; }
.pick-list-float {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 30;
  max-height: 220px; overflow-y: auto; background: #fff;
  border: 1px solid var(--border); border-radius: 8px; margin-top: 4px;
  box-shadow: 0 8px 24px rgba(20,32,92,0.15);
}
.pick-item { padding: 8px 10px; cursor: pointer; font-size: 13px; border-bottom: 1px solid var(--border); }
.pick-item:last-child { border-bottom: none; }
.pick-item:hover { background: #EAF6FC; }
.pick-item .sub { color: var(--text-muted); font-size: 11px; }
.selected-client-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #EAF6FC;
  color: var(--ink);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
}
.selected-client-chip button {
  border: none; background: none; color: var(--danger); cursor: pointer; font-weight: 700;
}

@media (max-width: 720px) {
  .app-layout { flex-direction: column; }
  .sidebar {
    width: 100%; flex-direction: row; overflow-x: auto; overflow-y: visible; padding: 10px;
    flex-shrink: 0; height: auto;
  }
  .sidebar .brand { display: none; }
  .nav-spacer { display: none; }
  .modal-grid, .modal-box.wide .modal-grid { grid-template-columns: 1fr; }
  .global-header-row { padding: 12px 16px 0; }
  .topbar { padding: 16px 16px 10px; }
  .page-body { padding: 6px 16px 16px; }
}
