/* =========================================================
   CRM VNPT Bà Rịa — Design tokens & components
   Hệ màu đã duyệt ở wireframe Phase 1: xanh VNPT + trắng,
   enterprise, mật độ dữ liệu cao, không gradient màu mè.
   ========================================================= */
:root {
  --primary-900: #003A66;
  --primary-800: #004C85;
  --primary-700: #005A9E;
  --primary-600: #0066B3;
  --primary-500: #1B7DC4;
  --primary-100: #D6E9F7;
  --primary-50:  #EBF4FB;

  --bg: #F6F8FA;
  --surface: #FFFFFF;
  --border: #DDE3EA;
  --border-strong: #C4CDD6;
  --text: #0F172A;
  --text-2: #3E4C5E;
  /* Trước là #8494A7 — độ tương phản chỉ 3,3:1 trên nền trắng, đọc rất mệt.
     Nay 5,4:1, đạt chuẩn WCAG AA cho chữ thường. */
  --text-3: #5D6D80;
  --text-muted: #8494A7;   /* chỉ dùng cho ô trống "—", không dùng cho chữ đọc */

  --green: #0E7A4E;  --green-bg: #E3F3EC;
  --amber: #9A6700;  --amber-bg: #FFF3D6;
  --red:   #B42318;  --red-bg:   #FBEAE9;

  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.08);
  --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 13px; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.45; }
.num { font-variant-numeric: tabular-nums; }
a { color: var(--primary-600); }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 228px; background: var(--primary-900); color: #fff; flex-shrink: 0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.logo { padding: 14px 16px; display: flex; align-items: center; gap: 11px; border-bottom: 1px solid rgba(255,255,255,.12); }
.logo img { flex-shrink: 0; }
.logo-mark { width: 32px; height: 32px; background: #fff; border-radius: 7px; display: flex; align-items: center; justify-content: center; color: var(--primary-600); font-weight: 800; font-size: 12px; }
.logo b { font-size: 13.5px; display: block; letter-spacing: .2px; }
.logo span { font-size: 10.5px; color: #9FC3E0; }
.nav { padding: 10px 10px 14px; flex: 1; overflow-y: auto; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.25) transparent; }
.nav-label { font-size: 10px; text-transform: uppercase; letter-spacing: .9px; color: #7FA8CB; padding: 14px 10px 5px; }
.nav a { display: flex; align-items: center; gap: 10px; color: #BDD5EA; padding: 8px 10px; border-radius: 7px; text-decoration: none; font-size: 12.5px; margin-bottom: 2px; }
.nav a svg { flex-shrink: 0; opacity: .72; }
.nav a .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav a.on { background: var(--primary-700); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 0 #6FBBEF; }
.nav a.on svg { opacity: 1; }
.nav a:hover:not(.on) { background: rgba(255,255,255,.08); color: #fff; }
.nav a:hover:not(.on) svg { opacity: .95; }
.nav a:focus-visible { outline: 2px solid #6FBBEF; outline-offset: -2px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 20px; height: 52px; display: flex; align-items: center; gap: 14px; position: sticky; top: 0; z-index: 20; }

/* ---------- Breadcrumb ---------- */
.crumbs { display: flex; align-items: center; gap: 1px; min-width: 0; font-size: 12.5px; }
.crumbs a { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); text-decoration: none; padding: 5px 9px; border-radius: 6px; white-space: nowrap; }
.crumbs a:hover { background: var(--primary-50); color: var(--primary-700); }
.crumbs .crumb-home svg { color: var(--text-3); }
.crumbs .crumb-home:hover svg { color: var(--primary-700); }
.crumbs .sep { color: var(--border-strong); flex-shrink: 0; }
.crumbs .grp { color: var(--text-3); padding: 5px 9px; white-space: nowrap; }
.crumbs .cur { color: var(--text); font-weight: 650; padding: 5px 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.content { padding: 18px 20px; flex: 1; }
.avatar { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.avatar .a { width: 30px; height: 30px; border-radius: 99px; background: var(--primary-100); color: var(--primary-700); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 11px; }
.avatar div b { font-size: 12px; display: block; }
.avatar div span { font-size: 10.5px; color: var(--text-3); }

/* ---------- Components ---------- */
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.page-head h2 { font-size: 17px; font-weight: 700; }
.page-head p { font-size: 12px; color: var(--text-3); }

.btn { border: 1px solid var(--border); background: var(--surface); padding: 7px 13px; border-radius: var(--radius-sm); font-size: 12.5px; font-weight: 500; cursor: pointer; font-family: inherit; display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); text-decoration: none; }
.btn.primary { background: var(--primary-600); border-color: var(--primary-600); color: #fff; }
.btn.primary:hover { background: var(--primary-700); }
.btn:focus-visible { outline: 2px solid var(--primary-500); outline-offset: 1px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.card-h h3 { font-size: 13px; font-weight: 600; }
.card-b { padding: 14px 16px; }

.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; display: inline-block; }
.b-green { background: var(--green-bg); color: var(--green); }
.b-amber { background: var(--amber-bg); color: var(--amber); }
.b-red   { background: var(--red-bg);   color: var(--red); }
.b-blue  { background: var(--primary-50); color: var(--primary-700); }
.b-gray  { background: #EEF1F4; color: var(--text-2); }

table.dt { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.dt th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-3); font-weight: 600; padding: 9px 12px; border-bottom: 1px solid var(--border); background: #FAFBFC; white-space: nowrap; }
.dt td { padding: 9px 12px; border-bottom: 1px solid #EEF1F4; vertical-align: middle; }
.dt tr:hover td { background: var(--primary-50); }
.dt .r { text-align: right; }
.dt .c { text-align: center; }

.field label { display: block; font-size: 11.5px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
.field label .req { color: var(--red); }
.field input, .field select, .field textarea { width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; font-size: 12.5px; font-family: inherit; background: #fff; color: var(--text); }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--primary-100); border-color: var(--primary-500); }
.hint { font-size: 11px; color: var(--text-3); margin-top: 4px; }

.alert { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 12.5px; margin-bottom: 14px; }
.alert.error { background: var(--red-bg); color: var(--red); border: 1px solid #F1C4C0; }
.alert.success { background: var(--green-bg); color: var(--green); border: 1px solid #BFE3D2; }
.alert.info { background: var(--primary-50); color: var(--primary-700); border: 1px solid var(--primary-100); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(180deg, var(--primary-900) 0%, var(--primary-800) 55%, var(--bg) 55.1%); padding: 20px; }
.login-card { width: 380px; background: var(--surface); border-radius: 12px; box-shadow: 0 20px 50px rgba(0,38,66,.35); overflow: hidden; }
.login-head { background: var(--primary-700); color: #fff; padding: 22px 26px; display: flex; align-items: center; gap: 12px; }
.login-body { padding: 26px; }
.login-foot { padding: 0 26px 22px; font-size: 11px; color: var(--text-3); text-align: center; }

/* ---------- Dòng thời gian (hồ sơ khách hàng) ----------
   Trục dọc + chấm mốc để nhìn ra ngay thứ tự trước/sau, thay cho danh sách
   phẳng. Màu chấm nói loại việc: xanh dương = CSKH, xanh lá = liên hệ… */
.tl { position: relative; padding-left: 28px; }
.tl::before { content: ''; position: absolute; left: 10px; top: 4px; bottom: 4px; width: 2px; background: var(--primary-100); border-radius: 2px; }
.tl-item { position: relative; padding-bottom: 15px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-dot { position: absolute; left: -28px; top: 1px; width: 22px; height: 22px; border-radius: 99px; background: var(--surface); border: 2px solid var(--primary-100); display: flex; align-items: center; justify-content: center; font-size: 11px; line-height: 1; }
.tl-dot.d-cskh { border-color: var(--primary-600); color: var(--primary-600); background: var(--primary-50); }
.tl-dot.d-green { border-color: var(--green); color: var(--green); background: var(--green-bg); }
.tl-dot.d-amber { border-color: var(--amber); color: var(--amber); background: var(--amber-bg); }
.tl-dot.d-gray { border-color: var(--border-strong); color: var(--text-3); }
.tl-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.tl-title { font-size: 13px; font-weight: 600; color: var(--text); }
.tl-time { font-size: 11.5px; color: var(--primary-600); font-weight: 600; margin-left: auto; white-space: nowrap; }
.tl-detail { font-size: 12.5px; color: var(--text-2); margin-top: 3px; }
.tl-who { font-size: 11.5px; color: var(--text-3); margin-top: 3px; }
.tl-day { font-size: 11px; font-weight: 700; color: var(--primary-700); text-transform: uppercase; letter-spacing: .4px; margin: 4px 0 8px; }

/* Phiếu CSKH đang mở — nổi bật ngay đầu dòng thời gian */
.care-open { border: 1px solid var(--primary-100); border-left: 3px solid var(--primary-600); background: var(--primary-50); border-radius: var(--radius-sm); padding: 9px 12px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.care-open + .care-open { margin-top: 7px; }
.care-open b { font-size: 12.5px; color: var(--primary-800); }
.care-open .due { font-size: 11.5px; color: var(--text-2); }
.care-open .due.late { color: var(--red); font-weight: 700; }

/* ---------- Autocomplete ---------- */
.ac-box { display: none; position: absolute; top: 100%; left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); box-shadow: 0 8px 20px rgba(15,23,42,.12); z-index: 50; max-height: 280px; overflow-y: auto; }
.ac-item { padding: 8px 12px; cursor: pointer; font-size: 12.5px; border-top: 1px solid #EEF1F4; }
.ac-item:first-child { border-top: 0; }
.ac-item b { display: block; font-weight: 600; }
.ac-item span { font-size: 11px; color: var(--text-3); }
.ac-item:hover, .ac-item.on { background: var(--primary-50); }
.ac-item.ac-free { color: var(--primary-600); font-weight: 600; }
.ac-empty { padding: 10px 12px; font-size: 12px; color: var(--text-3); }

/* ---------- Pagination ---------- */
.pager { display: flex; align-items: center; gap: 6px; padding: 11px 16px; font-size: 12px; color: var(--text-3); }
.pager .pg { margin-left: auto; display: flex; gap: 3px; }
.pager .pg a, .pager .pg span.cur { min-width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--border); background: #fff; border-radius: 5px; font-size: 12px; color: var(--text-2); text-decoration: none; padding: 0 6px; }
.pager .pg span.cur { background: var(--primary-600); border-color: var(--primary-600); color: #fff; font-weight: 600; }

@media (prefers-reduced-motion: no-preference) {
  .btn, .nav a { transition: background-color .12s ease; }

  /* View Transitions API (Chrome/Edge 126+): chuyển trang mượt kiểu SPA,
     không cần framework. Trình duyệt cũ tự bỏ qua - progressive enhancement. */
  @view-transition { navigation: auto; }
  ::view-transition-old(root), ::view-transition-new(root) { animation-duration: .14s; }
}

/* content-visibility: trình duyệt bỏ qua render phần ngoài màn hình -
   bảng dài 25-100 dòng cuộn nhẹ hẳn (Chrome/Edge/Firefox mới). */
.dt tbody tr { content-visibility: auto; contain-intrinsic-block-size: auto 44px; }

/* ---------- Responsive ----------
   View dùng inline grid-template-columns; dưới ngưỡng hẹp cho xuống 1 cột
   để bảng dữ liệu không bị bóp ngang (laptop 13", tablet ngang). */
@media (max-width: 1280px) {
  [style*="grid-template-columns:1"],
  [style*="grid-template-columns: 1"],
  [style*="grid-template-columns:2"],
  [style*="grid-template-columns: 2"] { grid-template-columns: 1fr !important; }
}
@media (max-width: 1024px) {
  [style*="repeat(6"], [style*="repeat(4"] { grid-template-columns: repeat(2, 1fr) !important; }
}
@media (max-width: 860px) {
  .sidebar { width: 60px; }
  .sidebar .logo { justify-content: center; padding: 14px 8px; }
  .sidebar .logo div, .nav-label { display: none; }
  .nav { padding: 8px 6px; }
  .nav a { justify-content: center; padding: 10px 0; }
  .nav a .t { display: none; }
  .nav a.on { box-shadow: inset 2px 0 0 0 #6FBBEF; }
  .crumbs .grp, .crumbs .crumb-home span { display: none; }
  [style*="repeat(6"], [style*="repeat(4"] { grid-template-columns: 1fr !important; }
}

/* ---- Modal / hộp thoại (thêm mới chuyên nghiệp) ---- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 42, .48);
  display: none; align-items: flex-start; justify-content: center;
  padding: 48px 16px; overflow-y: auto;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(15, 23, 42, .28);
  width: 100%; max-width: 560px; animation: modalIn .16s ease;
}
.modal.modal-lg { max-width: 820px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 15px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 14.5px; font-weight: 700; }
.modal-head .sub { font-size: 11.5px; color: var(--text-3); font-weight: 400; }
.modal-close { margin-left: auto; background: none; border: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--text-3); padding: 0 2px; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 13px 20px; border-top: 1px solid var(--border); background: var(--bg); border-radius: 0 0 var(--radius) var(--radius); }
.modal-grid { display: grid; gap: 13px; }
.modal-grid.cols-2 { grid-template-columns: 1fr 1fr; }
@keyframes modalIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
@media (max-width: 620px) { .modal-grid.cols-2 { grid-template-columns: 1fr; } }

/* ---- Chọn 1 trong nhiều (segmented, vd Loại khách) ---- */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.seg label { display: inline-flex; align-items: center; gap: 7px; padding: 8px 18px; margin: 0; font-size: 12.5px; font-weight: 500; color: var(--text-2); cursor: pointer; transition: background-color .12s, color .12s; }
.seg label + label { border-left: 1px solid var(--border); }
.seg input { position: absolute; opacity: 0; width: 0; height: 0; }
.seg label:has(input:checked), .seg label.is-on { background: var(--primary-600); color: #fff; }
.seg label:has(input:focus-visible) { outline: 2px solid var(--primary-500); outline-offset: -2px; }

/* ---- Chọn nhiều dạng chip (vd Tag phân loại) ---- */
.chip-check { display: inline-flex; align-items: center; gap: 6px; padding: 6px 13px; margin: 0; border: 1px solid var(--border); border-radius: 99px; font-size: 12px; font-weight: 500; color: var(--text-2); background: var(--surface); cursor: pointer; user-select: none; transition: background-color .12s, border-color .12s; }
.chip-check:hover { border-color: var(--border-strong); }
.chip-check input { position: absolute; opacity: 0; width: 0; height: 0; }
.chip-check::before { content: "+"; font-weight: 700; color: var(--text-3); }
.chip-check:has(input:checked), .chip-check.is-on { border-color: var(--primary-500); background: var(--primary-50); color: var(--primary-700); }
.chip-check:has(input:checked)::before, .chip-check.is-on::before { content: "✓"; color: var(--primary-600); }
