/* ============================================================
   BuiGia CRM — app.css
   File CSS DUY NHẤT cho toàn bộ ứng dụng.
   Gồm 3 phần:
     A. Design tokens   (biến CSS — màu, font, spacing, radius, shadow...)
     B. Base & layout   (reset, sidebar, topbar, page shell, drawer...)
     C. Components      (button, input, card, table, kanban, form, ...)
     D. Bổ sung         (state, login, skeleton, toast, dropzone, ...)
   ============================================================ */


/* ============================================================
   A. DESIGN TOKENS
   ============================================================ */
:root {
  /* --- Brand: BuiGia flame --- */
  --brand:        #E94B1F;
  --brand-600:    #D43F18;
  --brand-700:    #B23311;
  --brand-soft:   #FFF1EA;
  --brand-tint:   #FFE5D6;

  /* --- Surfaces (warm-cool neutrals, slightly cooler/cleaner than warm beige) --- */
  --bg-0: #F7F7F4;
  --bg-1: #FFFFFF;
  --bg-2: #F1F1ED;
  --bg-3: #E9E9E3;

  --border-1:      #EDECE6;
  --border-2:      #DDDBD3;
  --border-strong: #B7B5AB;

  /* --- Foregrounds --- */
  --fg-0: #18181B;
  --fg-1: #2A2A2E;
  --fg-2: #525158;
  --fg-3: #78767A;
  --fg-4: #A8A6AA;
  --fg-5: #CCCAC8;

  /* --- Semantic --- */
  --success:      #15803D;
  --success-bg:   #DCFCE7;
  --success-tint: #F0FDF4;
  --warn:         #B45309;
  --warn-bg:      #FEF3C7;
  --warn-tint:    #FFFBEB;
  --danger:       #B91C1C;
  --danger-bg:    #FEE2E2;
  --danger-tint:  #FEF2F2;
  --info:         #1D4ED8;
  --info-bg:      #DBEAFE;
  --info-tint:    #EFF6FF;
  --violet:       #6D28D9;
  --violet-bg:    #EDE9FE;
  --teal:         #0F766E;
  --teal-bg:      #CCFBF1;

  /* --- Pipeline stage colors --- */
  --stage-cold:   #94A3B8;   /* Chưa liên lạc       */
  --stage-follow: #2563EB;   /* Đang theo dõi       */
  --stage-warm:   #D97706;   /* Ít tiềm năng        */
  --stage-hot:    #DC2626;   /* Tiềm năng cao       */
  --stage-won:    #15803D;   /* Khách hàng          */
  --stage-lost:   #6B7280;   /* Thất bại            */

  /* --- Typography --- */
  --font-sans:    "Inter", "Plus Jakarta Sans", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono:    "JetBrains Mono", "SF Mono", ui-monospace, Menlo, monospace;
  --font-display: "Plus Jakarta Sans", "Inter", "SF Pro Display", system-ui, sans-serif;

  --text-2xs: 10px;
  --text-xs:  11px;
  --text-sm:  12px;
  --text-base:13px;
  --text-md:  14px;
  --text-lg:  16px;
  --text-xl:  18px;
  --text-2xl: 22px;
  --text-3xl: 28px;
  --text-4xl: 36px;

  --lh-tight:  1.15;
  --lh-snug:   1.3;
  --lh-normal: 1.5;

  --track-tight:  -0.01em;
  --track-normal:  0;
  --track-wide:    0.04em;

  /* --- Spacing (base 4px) --- */
  --space-0:  0;
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-7:  32px;
  --space-8:  40px;
  --space-9:  56px;
  --space-10: 72px;

  /* --- Radii --- */
  --radius-sm:   4px;
  --radius-md:   6px;
  --radius-lg:   10px;
  --radius-xl:   14px;
  --radius-pill: 999px;

  /* --- Heights / widths --- */
  --h-topbar:       52px;
  --h-rail:         52px;
  --h-button:       32px;
  --h-button-lg:    38px;
  --h-input:        34px;
  --h-row:          40px;
  --h-row-compact:  34px;
  --h-row-header:   32px;
  --w-sidebar:      220px;
  --w-subsidebar:   224px;
  --w-drawer:       520px;
  --w-drawer-wide:  720px;
  --w-content-max:  1680px;

  /* --- Shadows --- */
  --shadow-card:   0 1px 2px rgba(20, 18, 14, 0.04), 0 0 0 1px var(--border-1);
  --shadow-pop:    0 12px 32px -8px rgba(20, 18, 14, 0.16), 0 2px 6px rgba(20, 18, 14, 0.06);
  --shadow-drawer: -12px 0 32px -8px rgba(20, 18, 14, 0.12);
  --shadow-focus:  0 0 0 3px rgba(233, 75, 31, 0.18);
  --shadow-inset:  inset 0 1px 1px rgba(20, 18, 14, 0.04);

  /* --- Motion --- */
  --dur-fast: 120ms;
  --dur-base: 180ms;
  --dur-slow: 280ms;
  --ease-out: cubic-bezier(0.2, 0, 0, 1);
}


/* ============================================================
   A2. DARK THEME  — kích hoạt khi <html data-theme="dark">
   Chỉ override token MÀU; mọi component đã dùng var() nên tự đổi theo.
   ============================================================ */
[data-theme="dark"] {
  color-scheme: dark;

  /* Surfaces (tối dần: nền trang → card → nổi) */
  --bg-0: #15161A;
  --bg-1: #1C1D22;
  --bg-2: #232429;
  --bg-3: #2C2D33;

  --border-1:      #2A2B31;
  --border-2:      #383942;
  --border-strong: #54555E;

  /* Foregrounds (đảo: fg-0 = sáng nhất) */
  --fg-0: #F3F3F5;
  --fg-1: #E3E3E7;
  --fg-2: #ADACB4;
  --fg-3: #86858E;
  --fg-4: #66656E;
  --fg-5: #494951;

  /* Brand giữ nguyên hue, làm tối lớp nền mềm */
  --brand-soft:   #3A2218;
  --brand-tint:   #4A2A1D;

  /* Semantic: chữ sáng hơn + nền tối hơn để đủ tương phản trên nền tối */
  --success: #4ADE80; --success-bg: #14331F; --success-tint: #16241B;
  --warn:    #FBBF24; --warn-bg:    #382C12; --warn-tint:    #2A2310;
  --danger:  #F87171; --danger-bg:  #3A1B1B; --danger-tint:  #2A1616;
  --info:    #60A5FA; --info-bg:    #16243C; --info-tint:    #131D2B;
  --violet:  #A78BFA; --violet-bg:  #2A1F47;
  --teal:    #2DD4BF; --teal-bg:    #103632;

  --shadow-card:   0 1px 2px rgba(0,0,0,0.30), 0 0 0 1px var(--border-1);
  --shadow-pop:    0 12px 32px -8px rgba(0,0,0,0.55), 0 2px 6px rgba(0,0,0,0.40);
  --shadow-drawer: -12px 0 32px -8px rgba(0,0,0,0.50);
  --shadow-inset:  inset 0 1px 1px rgba(0,0,0,0.25);
}
/* Tooltip dùng --fg-0 làm NỀN (tối ở light, sẽ lật sáng ở dark) → cố định lại */
[data-theme="dark"] .rail-tip,
[data-theme="dark"] .chart-tip { background: var(--bg-3); color: var(--fg-0); border: 1px solid var(--border-2); }
/* Vài nền trắng hardcode khác */
[data-theme="dark"] .drawer .drawer-iframe { background: var(--bg-1); }
[data-theme="dark"] .calendar-day.weekend:not(.other) { background: var(--bg-2); }

/* Inline validation — ô lỗi + thông báo dưới ô */
.input.is-invalid,
.select.is-invalid,
textarea.input.is-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-bg);
}
.field-error {
  display: flex; align-items: center; gap: 4px;
  margin-top: 4px;
  color: var(--danger);
  font-size: 11px; font-weight: 500;
}
.field-error::before { content: "⚠"; font-size: 11px; }
.form-error-summary {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; margin-bottom: 4px;
  background: var(--danger-tint);
  border: 1px solid var(--danger-bg);
  border-radius: var(--radius-md);
  color: var(--danger);
  font-size: 13px; font-weight: 500;
}

/* Trình xem chứng từ chi phí (drawer bills.php) */
.bill-list { display: flex; flex-direction: column; gap: 16px; }
.bill-item { border: 1px solid var(--border-1); border-radius: var(--radius-md); overflow: hidden; }
.bill-item-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--bg-2); font-size: 12px; font-weight: 600; }
.bill-item-head .bill-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bill-preview { display: block; max-width: 100%; height: auto; background: var(--bg-2); }
.bill-preview-pdf { display: block; width: 100%; height: 68vh; border: 0; background: var(--bg-1); }


/* ============================================================
   B. BASE & LAYOUT
   ============================================================ */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--fg-1);
  background: var(--bg-0);
  line-height: var(--lh-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01", "cv02", "cv03", "cv04";
  letter-spacing: -0.005em;
}

h1, h2, h3, h4, .page-title, .card-title, .sidebar-brand-name {
  font-family: var(--font-display);
  letter-spacing: -0.018em;
}
.page-title { font-weight: 700; }
.sidebar-brand-name { font-weight: 800; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: transparent; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
/* Link trong bảng/card: subtle nhưng có dấu hiệu rõ hơn khi hover */
.tbl tbody a:not(.btn):not(.iconbtn):not(.chip):not(.tab),
.card-body a:not(.btn):not(.iconbtn):not(.chip):not(.tab):not(.status-tab):not(.nav-item) {
  color: var(--brand-700);
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  transition: text-decoration-color 120ms ease, color 100ms ease;
}
.tbl tbody a:not(.btn):not(.iconbtn):not(.chip):not(.tab):hover,
.card-body a:not(.btn):not(.iconbtn):not(.chip):not(.tab):not(.status-tab):not(.nav-item):hover {
  color: var(--brand);
  text-decoration-color: var(--brand);
}

.mono, .num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* Row click-to-navigate (highlight khi hover, cursor pointer) */
tr.row-clickable { transition: background 100ms ease; }
tr.row-clickable:hover {
  background: var(--bg-2);
}
tr.row-clickable:hover a:first-of-type {
  color: var(--brand-700);
}

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 999px; border: 2px solid var(--bg-0); }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }
::-webkit-scrollbar-track { background: transparent; }

/* App grid: sidebar + main, hoặc sidebar + sub-sidebar + main */
.app {
  display: grid;
  grid-template-columns: var(--w-sidebar) 1fr;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-0);
}
.app.has-sub      { grid-template-columns: var(--w-sidebar) var(--w-subsidebar) 1fr; }
.app.collapsed    { grid-template-columns: 56px 1fr; }
.app.collapsed.has-sub { grid-template-columns: 56px var(--w-subsidebar) 1fr; }

.main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}
.content {
  flex: 1;
  overflow: auto;
  background: var(--bg-0);
}


/* ============================================================
   SIDEBAR (menu chính, trái)
   ============================================================ */
.sidebar {
  background: var(--bg-1);
  border-right: 1px solid var(--border-1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-brand {
  height: var(--h-topbar);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-1);
}
.sidebar-brand-logo {
  width: 28px; height: 28px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #FF7B3D 0%, #E94B1F 60%, #B23311 100%);
  display: grid; place-items: center;
  color: white;
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(233, 75, 31, 0.25);
}
.sidebar-brand-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--fg-0);
}
.sidebar-brand-sub {
  font-size: 10px;
  color: var(--fg-3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: -1px;
}

.sidebar-user {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border-1);
}
.user-name { font-weight: 600; font-size: 13px; color: var(--fg-0); line-height: 1.2; }
.user-mail { font-size: 11px; color: var(--fg-3); line-height: 1.2; margin-top: 1px; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 8px; }

.nav-group-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-4);
  padding: 12px 12px 6px;
  font-weight: 600;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  color: var(--fg-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  position: relative;
  user-select: none;
}
.nav-item:hover  { background: var(--bg-2); color: var(--fg-0); }
.nav-item.active {
  background: var(--brand-soft);
  color: var(--brand-700);
  font-weight: 600;
}
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -8px; top: 6px; bottom: 6px;
  width: 3px;
  background: var(--brand);
  border-radius: 0 3px 3px 0;
}
.nav-item .nav-icon    { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item .nav-badge {
  margin-left: auto;
  background: var(--bg-3);
  color: var(--fg-2);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
}
.nav-item.active .nav-badge { background: var(--brand-tint); color: var(--brand-700); }
.nav-item .nav-chevron { margin-left: auto; width: 14px; height: 14px; opacity: 0.5; }

.nav-children {
  display: flex; flex-direction: column;
  padding-left: 28px;
  gap: 1px;
  margin-top: 2px;
}
.nav-child {
  font-size: 12px;
  height: 28px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  border-radius: var(--radius-sm);
  color: var(--fg-2);
  cursor: pointer;
}
.nav-child:hover  { background: var(--bg-2); color: var(--fg-0); }
.nav-child.active { color: var(--brand-700); font-weight: 600; }
.nav-child .dot   { width: 4px; height: 4px; border-radius: 999px; background: var(--fg-4); margin-right: 8px; }
.nav-child.active .dot { background: var(--brand); }

/* Sidebar trạng thái collapsed */
.app.collapsed .sidebar-brand-name,
.app.collapsed .sidebar-brand-sub,
.app.collapsed .user-name,
.app.collapsed .user-mail,
.app.collapsed .nav-item span:not(.nav-badge):not(.nav-icon),
.app.collapsed .nav-group-label,
.app.collapsed .nav-children { display: none; }
.app.collapsed .sidebar-brand { justify-content: center; padding: 0; }
.app.collapsed .sidebar-user  { justify-content: center; padding: 12px 0; }
.app.collapsed .nav-item      { justify-content: center; padding: 0; }
.app.collapsed .nav-item .nav-chevron { display: none; }
.app.collapsed .nav-item .nav-badge {
  position: absolute; top: 2px; right: 2px;
  margin: 0; padding: 0;
  min-width: 14px; height: 14px;
  font-size: 9px;
  display: grid; place-items: center;
}


/* ============================================================
   SUB-SIDEBAR (chi tiết doanh nghiệp)
   ============================================================ */
.subsidebar {
  background: var(--bg-1);
  border-right: 1px solid var(--border-1);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.subsidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-1);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.subsidebar-eyebrow {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--brand); font-weight: 600;
}
.subsidebar-title {
  font-size: 14px; font-weight: 700; color: var(--fg-0);
  line-height: 1.3;
}
.subsidebar-meta {
  font-size: 11px; color: var(--fg-3); font-family: var(--font-mono);
}
.subsidebar-nav { flex: 1; overflow-y: auto; padding: 8px; }


/* ============================================================
   TOPBAR (search + bell + user menu)
   ============================================================ */
.topbar {
  height: var(--h-topbar);
  background: var(--bg-1);
  border-bottom: 1px solid var(--border-1);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  flex-shrink: 0;
}
.iconbtn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: var(--radius-md);
  color: var(--fg-2);
  position: relative;
}
.iconbtn:hover { background: var(--bg-2); color: var(--fg-0); }
.topbar-right .iconbtn[title]:hover::after {
  content: attr(title);
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--fg-0);
  color: white;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.3;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  z-index: 200;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(20, 18, 14, 0.18);
  animation: tipFade 120ms ease-out;
}
.topbar-right .iconbtn[title]:hover::before {
  content: '';
  position: absolute;
  top: calc(100% + 3px);
  right: 12px;
  border: 5px solid transparent;
  border-bottom-color: var(--fg-0);
  z-index: 200;
  pointer-events: none;
}
@keyframes tipFade {
  from { opacity: 0; transform: translateY(-2px); }
  to   { opacity: 1; transform: translateY(0); }
}
.iconbtn .badge {
  position: absolute;
  top: 4px; right: 4px;
  background: var(--brand);
  color: white;
  font-size: 9px;
  font-weight: 700;
  min-width: 14px; height: 14px;
  border-radius: 999px;
  display: grid; place-items: center;
  padding: 0 3px;
}
.search-bar {
  flex: 1;
  max-width: 480px;
  height: 34px;
  background: var(--bg-2);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px;
  color: var(--fg-3);
}
.search-bar:focus-within {
  background: var(--bg-1);
  border-color: var(--border-2);
  box-shadow: var(--shadow-focus);
  color: var(--fg-1);
}
.search-bar input {
  flex: 1; background: transparent; border: 0; outline: none;
  color: var(--fg-0);
}
.search-bar kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 5px;
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  color: var(--fg-3);
}
.topbar-spacer { flex: 1; }
.topbar-right  { display: flex; align-items: center; gap: 4px; }


/* ============================================================
   PAGE WRAPPER + HEADER
   ============================================================ */
.page      { padding: 14px 18px 36px; max-width: var(--w-content-max); margin: 0 auto; }
.page-wide { padding: 14px 18px 36px; }
@media (min-width: 1600px) {
  .page, .page-wide { padding: 16px 28px 40px; }
}

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
}
.page-title-row { display: flex; align-items: center; gap: 10px; }
.page-title {
  font-size: 20px; font-weight: 700; color: var(--fg-0);
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.page-sub  { font-size: 12px; color: var(--fg-3); margin-top: 4px; }
.crumbs    {
  font-size: 11px; color: var(--fg-3);
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 6px;
}
.crumbs a:hover { color: var(--brand); }
.page-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }


/* ============================================================
   C. COMPONENTS
   ============================================================ */

/* --- Card --- */
.card {
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(20, 18, 14, 0.025);
  transition: box-shadow 160ms var(--ease-out);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-1);
}
.card-title  { font-size: 13px; font-weight: 600; color: var(--fg-0); display: flex; align-items: center; gap: 8px; letter-spacing: -0.01em; }
.card-title .ico, .card-title i[data-lucide] { width: 16px; height: 16px; color: var(--brand); }
.card-body   { padding: 12px 14px; }
.card-body.flush { padding: 0; }
.card + .card-foot, .card-foot { padding: 10px 14px; }

/* --- Button --- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: var(--h-button);
  padding: 0 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-md);
  color: var(--fg-1);
  background: var(--bg-1);
  border: 1px solid var(--border-2);
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 80ms ease;
}
.btn:hover         { background: var(--bg-2); border-color: var(--border-strong); color: var(--fg-0); }
.btn:active        { transform: translateY(0.5px); }
.btn:focus-visible { outline: 0; box-shadow: var(--shadow-focus); }
.btn .ico, .btn i[data-lucide] { width: 14px; height: 14px; }
.btn.primary       { background: var(--fg-0); color: white; border-color: var(--fg-0); }
.btn.primary:hover { background: var(--fg-1); border-color: var(--fg-1); }
.btn.brand         {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-600) 100%);
  color: white; border-color: var(--brand-600);
  box-shadow: 0 1px 2px rgba(178, 51, 17, 0.18);
}
.btn.brand:hover   {
  background: linear-gradient(135deg, var(--brand-600) 0%, var(--brand-700) 100%);
  border-color: var(--brand-700);
  box-shadow: 0 2px 6px rgba(178, 51, 17, 0.28);
}
.btn.ghost         { background: transparent; border-color: transparent; color: var(--fg-2); }
.btn.ghost:hover   { background: var(--bg-2); color: var(--fg-0); }
.btn.danger        { color: var(--danger); border-color: var(--border-2); }
.btn.danger:hover  { background: var(--danger-bg); border-color: var(--danger); }
.btn.success       { background: var(--success); color: white; border-color: var(--success); }
.btn.sm            { height: 26px; padding: 0 8px; font-size: 11px; gap: 4px; }
.btn.sm .ico, .btn.sm i[data-lucide] { width: 12px; height: 12px; }
.btn.lg            { height: 38px; padding: 0 16px; font-size: 13px; }
.btn[disabled], .btn.disabled {
  opacity: 0.5; cursor: not-allowed; pointer-events: none;
}

/* --- Inputs --- */
.field          { display: flex; flex-direction: column; gap: 6px; }
.field label,
.field-label    { font-size: 11px; font-weight: 600; color: var(--fg-2); letter-spacing: 0.01em; }
.field .hint    { font-size: 11px; color: var(--fg-3); margin-top: -2px; }
.field .error   { font-size: 11px; color: var(--danger); margin-top: 2px; }
.field.req label::after { content: " *"; color: var(--danger); }

.input, .select, .textarea {
  height: var(--h-input);
  padding: 0 10px;
  background: var(--bg-1);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--fg-0);
  outline: none;
  width: 100%;
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}
.input:hover:not(:focus):not([disabled]) { border-color: var(--border-strong); }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--brand);
  box-shadow: var(--shadow-focus);
}
.input.error, .select.error, .textarea.error {
  border-color: var(--danger);
}
.input.error:focus, .select.error:focus, .textarea.error:focus {
  box-shadow: 0 0 0 3px rgba(185, 28, 28, 0.18);
}
.textarea       { height: auto; padding: 8px 10px; resize: vertical; min-height: 70px; }
.input::placeholder, .textarea::placeholder { color: var(--fg-4); }
.input[disabled], .select[disabled], .textarea[disabled] {
  background: var(--bg-2); color: var(--fg-3); cursor: not-allowed;
}

/* Checkbox / radio chuẩn */
.checkbox, .radio {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--fg-1); cursor: pointer;
}
.checkbox input[type="checkbox"],
.radio input[type="radio"] {
  width: 14px; height: 14px;
  accent-color: var(--brand);
}

/* Toggle switch */
.toggle {
  position: relative; display: inline-block; width: 32px; height: 18px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--bg-3);
  transition: var(--dur-fast) var(--ease-out);
  border-radius: 999px;
}
.toggle .slider::before {
  content: "";
  position: absolute; height: 14px; width: 14px;
  left: 2px; top: 2px;
  background: white; border-radius: 999px;
  transition: var(--dur-fast) var(--ease-out);
}
.toggle input:checked + .slider          { background: var(--brand); }
.toggle input:checked + .slider::before  { transform: translateX(14px); }

/* --- Chips / badges --- */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  height: 20px;
  padding: 0 8px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  background: var(--bg-2);
  color: var(--fg-2);
  white-space: nowrap;
}
.chip.dot::before { content: ""; width: 6px; height: 6px; border-radius: 999px; background: currentColor; }
.chip.success    { background: var(--success-bg);  color: var(--success); }
.chip.warn       { background: var(--warn-bg);     color: var(--warn); }
.chip.danger     { background: var(--danger-bg);   color: var(--danger); }
.chip.info       { background: var(--info-bg);     color: var(--info); }
.chip.brand      { background: var(--brand-soft);  color: var(--brand-700); }
.chip.violet     { background: var(--violet-bg);   color: var(--violet); }
.chip.teal       { background: var(--teal-bg);     color: var(--teal); }
.chip.outline    { background: transparent; border: 1px solid var(--border-2); color: var(--fg-2); }
.chip.lg         { height: 24px; font-size: 12px; padding: 0 10px; }

/* Stage chip — mapping theo pipeline */
.stage-cold   { background: #E2E8F0; color: var(--stage-cold); }
.stage-follow { background: #DBEAFE; color: var(--stage-follow); }
.stage-warm   { background: #FED7AA; color: var(--stage-warm); }
.stage-hot    { background: #FECACA; color: var(--stage-hot); }
.stage-won    { background: var(--success-bg); color: var(--stage-won); }
.stage-lost   { background: var(--bg-3); color: var(--stage-lost); }

/* --- Avatar --- */
.avatar {
  width: 32px; height: 32px;
  border-radius: 999px;
  background: var(--bg-3);
  display: grid; place-items: center;
  color: var(--fg-1);
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
}
.avatar.sm  { width: 24px; height: 24px; font-size: 10px; }
.avatar.lg  { width: 40px; height: 40px; font-size: 14px; }
.avatar.xl  { width: 56px; height: 56px; font-size: 18px; }
.avatar .av-svg { width: 100%; height: 100%; }

.avstack { display: inline-flex; }
.avstack .avatar { margin-left: -8px; border: 2px solid var(--bg-1); }
.avstack .avatar:first-child { margin-left: 0; }
.avstack .more {
  width: 24px; height: 24px; border-radius: 999px;
  background: var(--bg-2); color: var(--fg-2);
  font-size: 10px; font-weight: 600;
  display: grid; place-items: center;
  margin-left: -8px;
  border: 2px solid var(--bg-1);
}


/* --- Table --- */
.tbl {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
.tbl thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--bg-1);
  height: var(--h-row-header);
  padding: 0 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border-1);
  white-space: nowrap;
  user-select: none;
}
.tbl thead th.sortable        { cursor: pointer; }
.tbl thead th.sortable:hover  { color: var(--fg-1); }
.tbl thead th .sort-ico       { margin-left: 4px; opacity: 0.5; }
.tbl thead th.sorted .sort-ico { opacity: 1; color: var(--brand); }

.tbl tbody td {
  height: var(--h-row);
  padding: 0 12px;
  border-bottom: 1px solid var(--border-1);
  color: var(--fg-1);
  vertical-align: middle;
}
.tbl tbody tr           { transition: background var(--dur-fast) var(--ease-out); }
.tbl tbody tr:hover     { background: var(--bg-2); }
/* Pointer cursor CHỈ hiện trên row thực sự click được */
.tbl tbody tr.row-clickable,
.tbl tbody tr[data-href],
.tbl tbody tr[data-report-popup] { cursor: pointer; }
.tbl tbody tr.selected  { background: var(--brand-soft); }
.tbl .num, .tbl .right  { text-align: right; }
.tbl .center            { text-align: center; }
.tbl .ck                { width: 30px; }
.tbl tbody tr:last-child td { border-bottom: none; }

.tbl-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-1);
  background: var(--bg-1);
  flex-wrap: wrap;
}
.tbl-toolbar .grow { flex: 1; }

/* Pagination */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  border-top: 1px solid var(--border-1);
  background: var(--bg-1);
  font-size: 12px; color: var(--fg-3);
}
.pagination .pages { display: flex; align-items: center; gap: 4px; }
.pagination .pg-btn {
  min-width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px;
  font-family: var(--font-mono);
  border-radius: var(--radius-md);
  color: var(--fg-2);
  border: 1px solid transparent;
}
.pagination .pg-btn:hover         { background: var(--bg-2); color: var(--fg-0); }
.pagination .pg-btn.active        { background: var(--brand-soft); color: var(--brand-700); border-color: var(--brand-tint); }
.pagination .pg-btn[disabled]     { color: var(--fg-4); cursor: not-allowed; }

/* Bulk-actions banner */
.bulkbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px;
  background: var(--brand-soft);
  border-bottom: 1px solid var(--brand-tint);
  color: var(--brand-700);
  font-size: 12px;
  font-weight: 600;
}
.bulkbar .actions { display: flex; gap: 6px; margin-left: auto; }


/* --- Tabs --- */
.tabs {
  display: flex; gap: 2px;
  border-bottom: 1px solid var(--border-1);
}
.tab {
  height: 34px;
  padding: 0 12px;
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-2);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color 120ms ease, border-bottom-color 120ms ease;
}
.tab:hover  { color: var(--fg-0); }
.tab.active { color: var(--brand-700); border-bottom-color: var(--brand); font-weight: 600; }
.tab .count {
  background: var(--bg-2);
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  color: var(--fg-3);
  font-weight: 600;
}
.tab.active .count { background: var(--brand-tint); color: var(--brand-700); }

/* Segmented control */
.seg {
  display: inline-flex;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-md);
  padding: 2px;
  background: var(--bg-1);
  height: 30px;
}
.seg-btn {
  padding: 0 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-2);
  border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; gap: 4px;
}
.seg-btn:hover  { color: var(--fg-0); }
.seg-btn.active { background: var(--bg-3); color: var(--fg-0); }
.seg-btn .ico   { width: 12px; height: 12px; }


/* --- KPI / Stat --- */
.kpi {
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 4px;
  position: relative;
  overflow: hidden;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.kpi:hover { border-color: var(--border-2); box-shadow: 0 2px 8px -4px rgba(20, 18, 14, 0.06); }
.kpi-label  { font-size: 11px; color: var(--fg-3); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.kpi-value  {
  font-size: 24px;
  font-weight: 700;
  color: var(--fg-0);
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.kpi-foot   { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--fg-3); margin-top: 2px; }
.kpi-delta.up   { color: var(--success); }
.kpi-delta.down { color: var(--danger); }
.kpi-icon {
  position: absolute; top: 14px; right: 14px;
  width: 28px; height: 28px;
  border-radius: var(--radius-md);
  display: grid; place-items: center;
  color: var(--brand);
  background: var(--brand-soft);
}
.kpi-strip {
  display: grid; gap: 10px;
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 12px;
}
.kpi-strip.cols-5 { grid-template-columns: repeat(5, 1fr); }
.kpi-strip.cols-6 { grid-template-columns: repeat(6, 1fr); }


/* --- Progress bar --- */
.bar { height: 6px; background: var(--bg-3); border-radius: 999px; overflow: hidden; }
.bar > div {
  height: 100%;
  background: var(--brand);
  border-radius: 999px;
  transition: width var(--dur-slow) var(--ease-out);
}
.bar.success > div { background: var(--success); }
.bar.warn    > div { background: var(--warn); }
.bar.danger  > div { background: var(--danger); }
.bar.info    > div { background: var(--info); }


/* --- Drawer --- */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 18, 14, 0.32);
  z-index: 60;
  animation: fade-in var(--dur-base) var(--ease-out);
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: var(--w-drawer);
  max-width: 90vw;
  background: var(--bg-1);
  box-shadow: var(--shadow-drawer);
  z-index: 61;
  display: flex; flex-direction: column;
  animation: slide-in var(--dur-base) var(--ease-out);
}
.drawer.wide { width: var(--w-drawer-wide); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-1);
}
.drawer-head h3 { font-size: 15px; font-weight: 700; color: var(--fg-0); margin: 0; }
.drawer-body    { flex: 1; overflow-y: auto; padding: 18px; }
.drawer-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border-1);
  background: var(--bg-1);
}
.drawer-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 16px 0 8px;
}

@keyframes slide-in { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Modal nhỏ (confirm dialog) — dùng cho confirm xóa, confirm chuyển KH */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20,18,14,0.32); z-index: 70; animation: fade-in var(--dur-base) var(--ease-out); }
.modal {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-1);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  z-index: 71;
  width: 440px; max-width: 90vw;
  display: flex; flex-direction: column;
  animation: slide-up var(--dur-base) var(--ease-out);
}
.modal-head { padding: 16px 18px 8px; }
.modal-head h3 { font-size: 15px; font-weight: 700; color: var(--fg-0); margin: 0; }
.modal-body { padding: 8px 18px 16px; font-size: 13px; color: var(--fg-1); }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border-1); display: flex; gap: 8px; justify-content: flex-end; }

/* Dropdown menu (more-actions ⋮) */
.menu {
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
  padding: 4px;
  min-width: 180px;
  z-index: 50;
}
.menu-item {
  display: flex; align-items: center; gap: 8px;
  height: 30px; padding: 0 8px;
  font-size: 12px; color: var(--fg-1);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.menu-item:hover         { background: var(--bg-2); }
.menu-item.danger        { color: var(--danger); }
.menu-item.danger:hover  { background: var(--danger-tint); }
.menu-divider            { height: 1px; background: var(--border-1); margin: 4px 0; }

/* Tooltip */
.tooltip {
  position: absolute;
  background: var(--fg-0); color: white;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  z-index: 80;
  pointer-events: none;
}


/* --- Kanban --- */
.kanban {
  display: flex; gap: 12px;
  overflow-x: auto;
  padding: 4px 4px 16px;
  min-height: 100%;
}
.kanban-col {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg-2);
  border-radius: var(--radius-lg);
  display: flex; flex-direction: column;
  padding: 10px;
  gap: 8px;
}
.kanban-col-head {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px;
}
.kanban-col-head .dot   { width: 8px; height: 8px; border-radius: 999px; }
.kanban-col-title       { font-size: 12px; font-weight: 700; color: var(--fg-0); }
.kanban-col-count       { font-size: 11px; color: var(--fg-3); font-family: var(--font-mono); }
.kanban-col-total       { font-size: 10px; color: var(--fg-3); font-family: var(--font-mono); margin-left: auto; }
.kanban-card {
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  padding: 10px;
  display: flex; flex-direction: column; gap: 6px;
  cursor: grab;
  transition: box-shadow var(--dur-fast) var(--ease-out),
              transform   var(--dur-fast) var(--ease-out);
}
.kanban-card:hover  { box-shadow: 0 2px 8px rgba(20,18,14,0.06); transform: translateY(-1px); }
.kanban-card.drag   { opacity: 0.5; cursor: grabbing; }
.kanban-card-title  { font-size: 12px; font-weight: 600; color: var(--fg-0); }
.kanban-card-sub    { font-size: 11px; color: var(--fg-3); }
.kanban-card-meta   { display: flex; align-items: center; justify-content: space-between; font-size: 10px; color: var(--fg-3); font-family: var(--font-mono); }


/* ============================================================
   D. UTILITIES, STATE, BỔ SUNG
   ============================================================ */

/* --- Layout helpers --- */
.row    { display: flex; align-items: center; gap: 8px; }
.col    { display: flex; flex-direction: column; gap: 8px; }
.gap-1  { gap: 4px;  } .gap-2  { gap: 8px;  } .gap-3 { gap: 12px; }
.gap-4  { gap: 16px; } .gap-5  { gap: 20px; } .gap-6 { gap: 24px; }
.mt-1   { margin-top: 4px;  } .mt-2 { margin-top: 8px;  } .mt-3 { margin-top: 12px; }
.mt-4   { margin-top: 16px; } .mt-5 { margin-top: 20px; } .mt-6 { margin-top: 24px; }
.fg-0   { color: var(--fg-0); } .fg-1 { color: var(--fg-1); } .fg-2 { color: var(--fg-2); }
.fg-3   { color: var(--fg-3); } .fg-4 { color: var(--fg-4); }
.tnum   { font-variant-numeric: tabular-nums; }
.muted  { color: var(--fg-3); }
.right  { text-align: right; }
.center { text-align: center; }
.grow   { flex: 1; }
.hidden { display: none; }
.divider { height: 1px; background: var(--border-1); margin: 8px 0; }

.t-up         { color: var(--success); }
.t-up::before { content: "▲ "; font-size: 8px; }
.t-down       { color: var(--danger); }
.t-down::before { content: "▼ "; font-size: 8px; }

.dot         { width: 8px; height: 8px; border-radius: 999px; display: inline-block; }
.dot.success { background: var(--success); }
.dot.warn    { background: var(--warn); }
.dot.danger  { background: var(--danger); }
.dot.info    { background: var(--info); }
.dot.brand   { background: var(--brand); }
.dot.muted   { background: var(--fg-4); }

.link        { color: var(--info); cursor: pointer; }
.link:hover  { text-decoration: underline; }
.link-brand  { color: var(--brand-700); cursor: pointer; font-weight: 600; }
.link-brand:hover { text-decoration: underline; }

kbd, code {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 5px;
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
}

/* --- Empty state --- */
.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--fg-3);
  font-size: 13px;
}
.empty .ico    { width: 32px; height: 32px; color: var(--fg-4); margin-bottom: 8px; }
.empty .title  { font-size: 14px; font-weight: 600; color: var(--fg-0); margin-bottom: 4px; }
.empty .cta    { margin-top: 12px; display: inline-flex; }

/* --- Loading skeleton --- */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-2) 0%,
    var(--bg-3) 50%,
    var(--bg-2) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
  border-radius: var(--radius-sm);
  display: inline-block;
}
.skeleton.line { height: 12px; width: 100%; }
.skeleton.line.sm { height: 10px; }
.skeleton.line.lg { height: 16px; }
.skeleton.circle { border-radius: 999px; width: 32px; height: 32px; }
.skeleton.row { height: 44px; width: 100%; border-radius: 0; }
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Spinner */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border-2);
  border-top-color: var(--brand);
  border-radius: 999px;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Callout / Alert --- */
.callout {
  display: flex; gap: 10px;
  padding: 10px 12px;
  background: var(--info-tint);
  border: 1px solid var(--info-bg);
  border-radius: var(--radius-md);
  font-size: 12px;
  color: var(--info);
}
.callout .ico    { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.callout.warn    { background: var(--warn-tint);    border-color: var(--warn-bg);    color: var(--warn); }
.callout.danger  { background: var(--danger-tint);  border-color: var(--danger-bg);  color: var(--danger); }
.callout.success { background: var(--success-tint); border-color: var(--success-bg); color: var(--success); }

/* Toast notifications (góc dưới phải) */
.toast-stack {
  position: fixed;
  right: 16px; bottom: 16px;
  display: flex; flex-direction: column-reverse; gap: 8px;
  z-index: 100;
}
.toast {
  background: var(--fg-0);
  color: white;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 12px;
  min-width: 240px;
  max-width: 360px;
  box-shadow: var(--shadow-pop);
  animation: slide-up var(--dur-base) var(--ease-out);
  display: flex; align-items: center; gap: 8px;
}
.toast.success { background: var(--success); }
.toast.warn    { background: var(--warn); }
.toast.danger  { background: var(--danger); }

/* Sparkline canvas */
.spark { width: 100%; height: 36px; }


/* ============================================================
   PAGES — bonus styles cho các trang đặc thù
   ============================================================ */

/* --- Login page --- */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--bg-0) 0%, var(--bg-2) 100%);
  padding: 20px;
}
.login-card {
  width: 420px; max-width: 100%;
  background: var(--bg-1);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  padding: 32px 28px;
  display: flex; flex-direction: column; gap: 16px;
}
.login-brand {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  margin-bottom: 8px;
}
.login-brand .logo {
  width: 56px; height: 56px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, #FF7B3D 0%, #E94B1F 60%, #B23311 100%);
  display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(233, 75, 31, 0.32);
}
.login-brand h1 { font-size: 18px; font-weight: 700; margin: 0; color: var(--fg-0); }
.login-brand .sub { font-size: 11px; color: var(--fg-3); letter-spacing: 0.08em; text-transform: uppercase; }
.login-foot { display: flex; align-items: center; justify-content: space-between; font-size: 11px; color: var(--fg-3); }

/* --- Detail page header (business header) --- */
.detail-header {
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 16px;
}
.detail-header .left  { display: flex; align-items: center; gap: 14px; flex: 1; min-width: 0; }
.detail-header .ttl   { font-size: 18px; font-weight: 700; color: var(--fg-0); line-height: 1.2; }
.detail-header .meta  { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; font-size: 12px; color: var(--fg-3); }
.detail-header .acts  { display: flex; align-items: center; gap: 6px; }

/* --- Activity timeline --- */
.timeline { display: flex; flex-direction: column; }
.timeline-item {
  display: flex; gap: 12px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border-1);
}
.timeline-item:last-child { border-bottom: none; }
.timeline-ico {
  width: 28px; height: 28px;
  border-radius: 999px;
  background: var(--bg-2);
  display: grid; place-items: center;
  color: var(--fg-2);
  flex-shrink: 0;
}
.timeline-ico.success { background: var(--success-bg); color: var(--success); }
.timeline-ico.warn    { background: var(--warn-bg); color: var(--warn); }
.timeline-ico.info    { background: var(--info-bg); color: var(--info); }
.timeline-body { flex: 1; font-size: 12px; }
.timeline-body .ttl  { color: var(--fg-1); font-weight: 500; }
.timeline-body .by   { color: var(--fg-3); }
.timeline-body .when { color: var(--fg-4); font-family: var(--font-mono); font-size: 11px; }

/* --- Comments (task / note) --- */
.comment {
  display: flex; gap: 10px;
  padding: 8px 0;
}
.comment-body {
  background: var(--bg-2);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  font-size: 12px;
  color: var(--fg-1);
}
.comment-head {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--fg-3);
  margin-bottom: 2px;
}
.comment-head strong { color: var(--fg-1); font-weight: 600; }

/* --- File dropzone --- */
.dropzone {
  border: 2px dashed var(--border-2);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
  background: var(--bg-2);
  color: var(--fg-3);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-700);
}
.dropzone .ico { width: 24px; height: 24px; margin-bottom: 8px; }

/* File list */
.file-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  background: var(--bg-1);
}
.file-row .ico { width: 18px; height: 18px; color: var(--fg-3); }
.file-row .name { font-size: 12px; color: var(--fg-1); flex: 1; }
.file-row .size { font-size: 11px; color: var(--fg-3); font-family: var(--font-mono); }

/* --- Map container (Leaflet) --- */
.map-shell {
  height: calc(100vh - 200px);
  min-height: 480px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-1);
  overflow: hidden;
}
.map-popup {
  font-family: var(--font-sans);
  font-size: 12px;
}

/* --- QR code card --- */
.qr-card {
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  padding: 16px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.qr-card img, .qr-card svg { width: 200px; height: 200px; }

/* --- Settings layout --- */
.settings-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 16px;
}
.settings-side {
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  padding: 8px;
  height: fit-content;
}
.settings-side .item {
  display: flex; align-items: center; gap: 8px;
  height: 30px; padding: 0 10px;
  font-size: 12px; color: var(--fg-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.settings-side .item:hover  { background: var(--bg-2); color: var(--fg-0); }
.settings-side .item.active { background: var(--brand-soft); color: var(--brand-700); font-weight: 600; }
.settings-side .group-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-4);
  padding: 10px 10px 4px;
  font-weight: 600;
}

/* --- Form section trong drawer --- */
.form-section {
  display: flex; flex-direction: column; gap: 12px;
}
.form-section + .form-section { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border-1); }
.form-section .section-title {
  font-size: 11px; font-weight: 600; color: var(--fg-3);
  text-transform: uppercase; letter-spacing: 0.04em;
  margin-bottom: 4px;
}

/* Filter chips bar (multi-filter row) */
.filterbar {
  display: flex; flex-wrap: wrap; gap: 6px;
  align-items: center;
  padding: 6px 0;
}
.filterbar .clear {
  font-size: 11px; color: var(--fg-3);
  cursor: pointer; padding: 0 6px;
}
.filterbar .clear:hover { color: var(--danger); }

/* --- Donut/Bar mini chart wrapper --- */
.chart-shell {
  height: 220px;
  display: flex; align-items: center; justify-content: center;
}

/* --- Funnel chart --- */
.funnel        { display: flex; flex-direction: column; align-items: stretch; gap: 4px; }
.funnel-step   {
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-2);
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-1);
  text-align: center;
}

/* Vault banner (Kho bảo mật) */
.vault-banner {
  background: var(--danger-tint);
  border: 1px solid var(--danger-bg);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex; align-items: center; gap: 10px;
  color: var(--danger);
  font-size: 12px;
  margin-bottom: 12px;
}
.vault-banner .ico { width: 18px; height: 18px; flex-shrink: 0; }

/* Danger zone (settings/delete) */
.danger-zone {
  border: 1px solid var(--danger-bg);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  background: var(--danger-tint);
}
.danger-zone h3 { color: var(--danger); margin: 0 0 6px; font-size: 13px; }

/* Health score gauge (vòng tròn nhỏ) */
.gauge {
  width: 48px; height: 48px;
  position: relative;
  display: grid; place-items: center;
}
.gauge svg { transform: rotate(-90deg); }
.gauge .pct {
  position: absolute;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 11px;
  color: var(--fg-0);
}

/* Responsive — chỉ desktop, không tối ưu mobile (theo BRIEF) */
@media (max-width: 1199px) {
  .kpi-strip { grid-template-columns: repeat(2, 1fr); }
  .settings-shell { grid-template-columns: 180px 1fr; }
}
@media (max-width: 1023px) {
  .app { grid-template-columns: 56px 1fr; }
  .app.has-sub { grid-template-columns: 56px var(--w-subsidebar) 1fr; }
  .sidebar-brand-name, .sidebar-brand-sub, .user-name, .user-mail,
  .nav-item span:not(.nav-badge):not(.nav-icon), .nav-group-label, .nav-children { display: none; }
}

/* Print — tối thiểu để xuất PDF hiển thị OK */
@media print {
  .sidebar, .subsidebar, .topbar, .drawer, .drawer-backdrop, .iconbtn, .btn { display: none !important; }
  .app, .main, .content { display: block; height: auto; overflow: visible; }
  body { background: white; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}

/* ============================================================
   E. PHP THUẦN — BỔ SUNG CHO BuiGia CRM
   Dùng khi render HTML trực tiếp từ PHP 8.3, không React/Vite.
   Các class này không phá vỡ design system gốc.
   ============================================================ */

.admin-shell {
  display: grid;
  grid-template-columns: var(--w-sidebar) 1fr;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-0);
}
.admin-shell.has-sub { grid-template-columns: var(--w-sidebar) var(--w-subsidebar) 1fr; }
.admin-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.admin-content {
  flex: 1;
  overflow: auto;
  background: var(--bg-0);
}
.admin-shell > .sidebar,
.admin-shell > .subsidebar {
  height: 100vh;
  position: sticky;
  top: 0;
}

.flash-message,
.php-form-error,
.login-error {
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 12px;
  line-height: var(--lh-normal);
}
.flash-message { border: 1px solid var(--info-bg); background: var(--info-tint); color: var(--info); }
.flash-message.success { border-color: var(--success-bg); background: var(--success-tint); color: var(--success); }
.flash-message.warn { border-color: var(--warn-bg); background: var(--warn-tint); color: var(--warn); }
.flash-message.danger,
.php-form-error,
.login-error { border: 1px solid var(--danger-bg); background: var(--danger-tint); color: var(--danger); }

.action-bar,
.filter-form,
.table-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.action-bar { justify-content: space-between; margin-bottom: 12px; }
.filter-form {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-1);
  background: var(--bg-1);
}
.table-actions { justify-content: flex-end; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
}
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-3 { grid-column: span 3; }
.required::after { content: " *"; color: var(--danger); }
.csrf-debug-hidden { display: none !important; }

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
  gap: 16px;
}
.detail-list { display: grid; gap: 8px; }
.detail-row {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-1);
}
.detail-row:last-child { border-bottom: 0; }
.detail-row .label { color: var(--fg-3); font-size: 12px; }
.detail-row .value { color: var(--fg-0); font-weight: 500; }

.inline-form { display: inline; }
.delete-form { display: inline; }
.sort-link { display: inline-flex; align-items: center; gap: 4px; }
.sort-link.active { color: var(--brand-700); font-weight: 700; }

.user-menu { display: flex; align-items: center; gap: 8px; }
.quick-actions { display: flex; align-items: center; gap: 8px; }
.search-form { display: flex; align-items: center; gap: 8px; flex: 1; max-width: 520px; }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  display: inline-block;
  background: var(--fg-4);
}
.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--fg-4); }

.file-dropzone {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-2);
  min-height: 120px;
  display: grid;
  place-items: center;
  padding: 18px;
  color: var(--fg-3);
}
.file-dropzone.dragging {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand-700);
}

.audit-line {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-1);
  font-size: 12px;
}
.audit-line:last-child { border-bottom: 0; }
.audit-time { color: var(--fg-3); font-family: var(--font-mono); min-width: 120px; }

/* PHP server-rendered compatibility polish */
.brand-mark { text-decoration: none; color: inherit; }
.brand-mark span:last-child { display: grid; gap: 1px; }
.side-link { text-decoration: none; margin-bottom: 2px; }
.side-link span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-group { margin-bottom: 6px; }
.breadcrumbs { font-size: 11px; color: var(--fg-3); margin-bottom: 6px; }
.page-head h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--fg-0);
  line-height: 1.2;
  margin: 0;
}
.count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 8px;
  border-radius: var(--radius-pill);
  background: var(--brand-soft);
  color: var(--brand-700);
  font-size: 12px;
  vertical-align: middle;
}
.user-menu-wrap { position: relative; margin-left: auto; }
.user-menu-wrap .user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 30;
  display: none;
  min-width: 220px;
  padding: 8px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  background: var(--bg-1);
  box-shadow: var(--shadow-pop);
  flex-direction: column;
  align-items: stretch;
}
.user-menu-wrap .user-menu.open { display: flex; }
.user-menu-head {
  display: grid;
  gap: 2px;
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--border-1);
  margin-bottom: 4px;
}
.user-menu-head span { color: var(--fg-3); font-size: 11px; }
.user-menu a {
  padding: 8px 10px;
  border-radius: var(--radius-md);
  color: var(--fg-1);
  text-decoration: none;
  font-size: 13px;
}
.user-menu a:hover { background: var(--bg-2); color: var(--fg-0); }
.search-form.search-bar { max-width: 560px; }
.search-form.search-bar .input { background: transparent; border: 0; box-shadow: none; }
.quick-actions { margin-left: auto; }
.filter-form {
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  margin-bottom: 14px;
}
.card + .card,
form.card + .card,
.kpi-strip + .card,
.tabs + .card,
.tabs + form.card { margin-top: 10px; }
.card-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border-1);
}
.check-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 12px;
}
.check-grid label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 6px 8px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  background: var(--bg-2);
}
.inline-form { display: inline-flex; }
.table-actions .inline-form { vertical-align: middle; }
.audit-line {
  display: block;
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 8px;
}
.audit-line span { color: var(--fg-3); font-size: 11px; margin-left: 6px; }
.audit-line p { margin: 6px 0 0; color: var(--fg-1); }

.field.req label::after,
.field .required::after {
  content: " *";
  color: var(--danger);
}

.card-body:has(> .tbl) {
  overflow-x: auto;
}

.card-body > .tbl {
  min-width: 760px;
}

body.sidebar-collapsed .admin-shell {
  grid-template-columns: 56px 1fr;
}
body.sidebar-collapsed .sidebar-brand-name,
body.sidebar-collapsed .sidebar-brand-sub,
body.sidebar-collapsed .nav-group-label,
body.sidebar-collapsed .nav-item span {
  display: none;
}
body.sidebar-collapsed .sidebar-brand,
body.sidebar-collapsed .nav-item {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}
body.sidebar-collapsed .sidebar-brand-logo {
  margin: 0;
}

/* Tooltip nổi cho sidebar khi thu nhỏ (.sidebar có overflow:hidden nên tooltip CSS bị cắt → position:fixed) */
.rail-tip {
  position: fixed; transform: translateY(-50%);
  background: var(--fg-0); color: #fff;
  font-size: 11px; font-weight: 500; line-height: 1.3;
  padding: 5px 9px; border-radius: var(--radius-sm);
  white-space: nowrap; z-index: 1000; pointer-events: none;
  box-shadow: 0 4px 12px rgba(20, 18, 14, 0.18);
  opacity: 0; transition: opacity 100ms ease;
}
.rail-tip.show { opacity: 1; }

/* Tooltip biểu đồ (đi theo con trỏ) */
.chart-tip {
  position: fixed; z-index: 1000; pointer-events: none;
  background: var(--fg-0); color: #fff;
  font-size: 11px; font-weight: 600; line-height: 1.35;
  padding: 6px 9px; border-radius: var(--radius-sm);
  white-space: nowrap; max-width: 260px;
  box-shadow: 0 4px 14px rgba(20, 18, 14, 0.22);
  opacity: 0; transition: opacity 90ms ease; transform: translateY(-100%);
}
.chart-tip.show { opacity: 1; }
.chart-grouped-bar rect.gbar { cursor: pointer; transition: opacity 90ms ease; }
.chart-grouped-bar:hover rect.gbar { opacity: 0.55; }
.chart-grouped-bar rect.gbar:hover { opacity: 1; }

@media (max-width: 760px) {
  .topbar {
    min-height: var(--h-topbar);
    height: auto;
    align-items: stretch;
    flex-wrap: wrap;
    padding: 10px 12px;
  }
  .search-form.search-bar {
    order: 3;
    flex-basis: 100%;
    max-width: none;
  }
  .quick-actions {
    order: 4;
    width: 100%;
    margin-left: 0;
  }
  .quick-actions .btn {
    flex: 1;
    justify-content: center;
  }
  .user-menu-wrap {
    margin-left: 0;
  }
  .page {
    padding: 16px 12px 28px;
  }
  .page-head {
    align-items: flex-start;
    flex-direction: column;
  }
  .kpi-strip,
  .kpi-strip.cols-5,
  .kpi-strip.cols-6,
  .check-grid {
    grid-template-columns: 1fr;
  }

  /* Tiện ích: ẩn phần tử trên màn hình nhỏ (vd mục lục hướng dẫn) */
  .hide-mobile { display: none !important; }

  /* (a) Lưới an toàn: mọi bảng cuộn ngang trên mobile, không phá layout trang */
  .card-body { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* (b) Chế độ CARD cho bảng có class .cards-sm — mỗi dòng thành 1 thẻ dễ đọc */
  .tbl.cards-sm thead {
    position: absolute; width: 1px; height: 1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  .tbl.cards-sm tbody tr {
    display: block;
    background: var(--bg-1);
    border: 1px solid var(--border-1);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    padding: 10px 14px;
    margin-bottom: 10px;
  }
  .tbl.cards-sm tbody td {
    display: flex; align-items: baseline; gap: 12px;
    justify-content: space-between;
    height: auto; min-height: 0;
    padding: 5px 0;
    text-align: right;
    border-bottom: 1px dashed var(--border-1);
  }
  .tbl.cards-sm tbody tr td:last-child { border-bottom: none; }
  .tbl.cards-sm tbody td::before {
    content: attr(data-label);
    flex: 0 0 36%;
    text-align: left;
    color: var(--fg-3);
    font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.03em;
  }
  /* Ô không cần trên thẻ: checkbox; ô tiêu đề nổi như đầu thẻ */
  .tbl.cards-sm td.ck,
  .tbl.cards-sm td.col-stt { display: none; }
  .tbl.cards-sm td.cell-title {
    display: block; text-align: left;
    font-size: 15px; font-weight: 600;
    padding-bottom: 8px;
  }
  .tbl.cards-sm td.cell-title::before { display: none; }
  .tbl.cards-sm td.table-actions { justify-content: flex-start; }
  .tbl.cards-sm td.table-actions::before { display: none; }
}

@media (max-width: 1023px) {
  .admin-shell { grid-template-columns: 56px 1fr; }
  .admin-shell.has-sub { grid-template-columns: 56px var(--w-subsidebar) 1fr; }
  .form-grid,
  .form-grid.cols-3,
  .detail-grid { grid-template-columns: 1fr; }
  .form-grid .span-2,
  .form-grid .span-3 { grid-column: auto; }
}

/* === Sprint 21 — Kanban bổ sung === */
.kanban-col-body { display: flex; flex-direction: column; gap: 8px; min-height: 60px; padding: 4px 2px; flex: 1; }
.kanban-col-body.drop-target { background: rgba(0, 66, 171, 0.04); border-radius: var(--radius-md); outline: 1px dashed var(--brand); outline-offset: -2px; }
.kanban-card.dragging { opacity: 0.45; cursor: grabbing; }
.kanban-card-value { font-size: 12px; font-weight: 600; color: var(--success); font-variant-numeric: tabular-nums; }
.kanban-card-foot { font-size: 10px; color: var(--fg-3); border-top: 1px dashed var(--border-1); padding-top: 4px; }
.kanban-empty { font-size: 11px; color: var(--fg-4); text-align: center; padding: 12px 0; font-style: italic; }
.kanban-col-sub { font-size: 11px; color: var(--fg-3); font-family: var(--font-mono); margin-left: auto; }

/* === Sprint 21 — Trash chip === */
.chip.muted { background: var(--bg-2); color: var(--fg-3); border: 1px solid var(--border-1); }

/* === Sprint 22 — Priority highlight cho task kanban === */
.kanban-card.priority-urgent { border-left: 3px solid var(--danger); }
.kanban-card.priority-high   { border-left: 3px solid var(--warn); }

/* === Sprint 23 — Chart SVG vanilla === */
.chart-row { display: grid; grid-template-columns: minmax(260px, 1fr) 1fr; gap: 16px; align-items: start; }
.chart-wrap { background: var(--bg-1); border: 1px solid var(--border-1); border-radius: var(--radius-md); padding: 12px; }
.chart-empty { background: var(--bg-2); border: 1px dashed var(--border-1); border-radius: var(--radius-md); padding: 24px; text-align: center; color: var(--fg-3); font-size: 12px; }
.chart-donut { display: grid; grid-template-columns: 220px 1fr; gap: 14px; align-items: center; }
.chart-legend { display: flex; flex-direction: column; gap: 4px; }
.chart-legend-item { display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: 6px; font-size: 11px; }
.chart-swatch { width: 10px; height: 10px; border-radius: 2px; }
.chart-legend-label { color: var(--fg-1); }
.chart-legend-value { font-variant-numeric: tabular-nums; color: var(--fg-0); }
@media (max-width: 1023px) {
  .chart-row { grid-template-columns: 1fr; }
  .chart-donut { grid-template-columns: 1fr; justify-items: center; }
}

/* === Sprint 24 — OSM map pins === */
.biz-pin {
  background: var(--brand);
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
}
.biz-pin.pin-customer { background: var(--success); }
.biz-pin.pin-opportunity { background: var(--brand); }
.biz-pin span { line-height: 1; }

/* === Sprint 24 — Notification badge topbar === */
.notif-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--danger); color: #fff;
  border-radius: 999px; font-size: 10px; font-weight: 700;
  margin-left: 4px;
}
.notif-link { display: inline-flex; align-items: center; gap: 4px; color: var(--fg-1); }
.notif-link:hover { color: var(--brand); }

/* === Sprint 26 — Sub-sidebar cho chi tiết doanh nghiệp === */
.biz-detail-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 16px;
  align-items: start;
}
.biz-detail-content { min-width: 0; }
.sub-sidebar {
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  position: sticky;
  top: 16px;
  overflow: hidden;
}
.sub-sidebar-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-1);
}
.sub-sidebar-title { font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--fg-3); letter-spacing: 0.04em; }
.sub-sidebar-sub { font-size: 13px; color: var(--fg-1); margin-top: 2px; }
.sub-nav { display: flex; flex-direction: column; padding: 6px; gap: 1px; }
.sub-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  color: var(--fg-1);
  border-radius: var(--radius-sm);
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
}
.sub-nav-item:hover { background: var(--bg-2); color: var(--fg-0); }
.sub-nav-item.active {
  background: var(--brand-soft);
  color: var(--brand-700);
  font-weight: 600;
}
.sub-nav-icon { font-size: 14px; width: 18px; text-align: center; }
@media (max-width: 1023px) {
  .biz-detail-layout { grid-template-columns: 1fr; }
  .sub-sidebar { position: static; }
  .sub-nav { flex-direction: row; flex-wrap: wrap; }
}

/* === Sprint 26 — Drawer iframe polish === */
.drawer.wide { width: min(720px, 92vw); display: flex; flex-direction: column; }
.drawer .drawer-iframe { background: #fff; min-height: 100%; }
.drawer-title { font-size: 16px; font-weight: 700; }
.iconbtn {
  background: transparent; border: 0; cursor: pointer;
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--fg-1);
}
.iconbtn:hover { background: var(--bg-2); }

/* === Sprint 27 — Polish UI giống design BuiGia-CRM === */
/* Lucide icons baseline */
.sidebar-nav .nav-item i,
.topbar .iconbtn i,
.topbar .btn i,
.sub-nav-item i,
.btn i,
.iconbtn i { display: inline-flex; }
[data-lucide] { width: 16px; height: 16px; stroke-width: 1.6; }

/* Sidebar refresh */
.sidebar { display: flex; flex-direction: column; }
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-1);
  color: var(--fg-0);
}
.sidebar-brand-link {
  display: flex; align-items: center; gap: 10px;
  flex: 1; min-width: 0;
  text-decoration: none; color: inherit;
}
.sidebar-brand-text { flex: 1; min-width: 0; }
.sidebar-brand-logo {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: #fff;
  display: grid; place-items: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  overflow: hidden;
}
.sidebar-brand-logo svg { width: 22px; height: 22px; }
.sidebar-brand-logo img { width: 100%; height: 100%; object-fit: contain; }
.sidebar-brand-name {
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.01em;
  color: var(--fg-0);
}
.sidebar-brand-sub { font-size: 9px; color: var(--fg-3); letter-spacing: 0.10em; text-transform: uppercase; font-weight: 600; margin-top: 1px; }
.sidebar-collapse-btn {
  width: 28px; height: 28px;
  display: inline-grid; place-items: center;
  background: transparent;
  border: 1px solid var(--border-1);
  border-radius: 6px;
  color: var(--fg-3);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.sidebar-collapse-btn:hover { background: var(--bg-2); color: var(--fg-0); }
.sidebar-collapse-btn i { width: 14px; height: 14px; }

.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-1);
  position: relative;
}
.sidebar-user-meta { flex: 1; min-width: 0; }
.sidebar-user .user-name { font-size: 13px; font-weight: 600; color: var(--fg-0); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user .user-mail { font-size: 10px; color: var(--fg-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user .user-role { font-size: 10px; font-weight: 500; color: var(--fg-3); letter-spacing: 0.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-btn { width: 26px; height: 26px; }
.sidebar-user-btn i { width: 14px; height: 14px; }
.sidebar-user .user-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 8px;
  left: 8px;
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 50;
  display: none;
}
.sidebar-user .user-menu.open { display: block; }
.sidebar-user .user-menu-head {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-1);
  margin-bottom: 4px;
  display: flex; flex-direction: column;
}
.sidebar-user .user-menu-head strong { font-size: 13px; color: var(--fg-0); }
.sidebar-user .user-menu-head span { font-size: 11px; color: var(--fg-3); }
.sidebar-user .user-menu a {
  display: block; padding: 7px 10px;
  font-size: 12px; color: var(--fg-1);
  text-decoration: none;
  border-radius: var(--radius-sm);
}
.sidebar-user .user-menu a:hover { background: var(--bg-2); color: var(--fg-0); }

/* Sidebar collapsed - additional rules for new structure */
body.sidebar-collapsed .sidebar-brand-text,
body.sidebar-collapsed .sidebar-user-meta,
body.sidebar-collapsed .sidebar-user-btn,
body.sidebar-collapsed .user-role { display: none; }
/* Thu nhỏ: xếp dọc — GIỮ logo (về trang chủ) + GIỮ nút thu/mở (thành nút mở rộng) */
body.sidebar-collapsed .sidebar-brand { flex-direction: column; gap: 6px; padding: 8px 4px; justify-content: center; height: auto; min-height: var(--h-topbar); }
body.sidebar-collapsed .sidebar-brand-link { justify-content: center; flex: none; }
body.sidebar-collapsed .sidebar-brand-logo { width: 30px; height: 30px; }
body.sidebar-collapsed .sidebar-collapse-btn svg,
body.sidebar-collapsed .sidebar-collapse-btn i { transform: rotate(180deg); }
body.sidebar-collapsed .sidebar-user { justify-content: center; padding: 10px 6px; }

/* Nav items với badge */
.nav-icon { color: var(--fg-3); flex-shrink: 0; }
.nav-item.active .nav-icon { color: var(--brand-700); }
.nav-badge {
  margin-left: auto;
  background: var(--bg-2);
  color: var(--fg-3);
  font-size: 10px; font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  font-family: var(--font-mono);
}
.nav-item.active .nav-badge { background: var(--brand-tint); color: var(--brand-700); }
.nav-group-label {
  font-size: 10px; font-weight: 600; letter-spacing: 0.06em;
  color: var(--fg-4);
  padding: 12px 14px 6px;
}

/* Avatar sizes */
.avatar {
  width: 32px; height: 32px;
  border-radius: 999px;
  display: inline-grid; place-items: center;
  font-size: 11px; font-weight: 700;
  background: var(--bg-2); color: var(--fg-1);
  flex-shrink: 0;
}
.avatar.sm { width: 24px; height: 24px; font-size: 10px; }
.avatar.md { width: 32px; height: 32px; font-size: 11px; }
.avatar.lg { width: 40px; height: 40px; font-size: 14px; }
.avatar.xl { width: 52px; height: 52px; font-size: 18px; }

/* Topbar polish */
.topbar {
  display: flex; align-items: center; gap: 8px;
  height: 56px; padding: 0 16px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border-1);
}
.topbar-spacer { flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 4px; }
.topbar-divider { width: 1px; height: 20px; background: var(--border-1); margin: 0 4px; }

.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-2);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 6px 10px;
  width: 360px; max-width: 40vw;
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.search-bar:focus-within { background: var(--bg-1); border-color: var(--border-2); }
.search-bar i { color: var(--fg-3); }
.search-bar input { flex: 1; border: 0; background: transparent; outline: none; font-size: 13px; color: var(--fg-0); min-width: 0; }
.search-bar kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-3);
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: 4px;
  padding: 1px 5px;
}

.iconbtn {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  border: 0;
  background: transparent;
  display: inline-grid; place-items: center;
  color: var(--fg-1);
  cursor: pointer;
  position: relative;
  text-decoration: none;
}
.iconbtn:hover { background: var(--bg-2); color: var(--fg-0); }
.iconbtn .badge {
  position: absolute;
  top: 2px; right: 2px;
  min-width: 16px; height: 16px;
  padding: 0 4px;
  background: var(--danger); color: #fff;
  border-radius: 999px;
  font-size: 9px; font-weight: 700;
  display: grid; place-items: center;
  border: 1.5px solid var(--bg-1);
}

/* User menu dropdown */
.user-menu-wrap { position: relative; }
.user-menu {
  position: absolute; top: 100%; right: 0;
  width: 220px;
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 30px rgba(20,18,14,.12);
  display: none;
  flex-direction: column;
  padding: 6px;
  z-index: 100;
  margin-top: 6px;
}
.user-menu.open { display: flex; }
.user-menu-head { padding: 10px 12px; border-bottom: 1px solid var(--border-1); margin-bottom: 4px; }
.user-menu-head strong { display: block; font-size: 13px; color: var(--fg-0); }
.user-menu-head span { font-size: 11px; color: var(--fg-3); text-transform: uppercase; letter-spacing: 0.04em; }
.user-menu a {
  padding: 8px 12px;
  font-size: 13px;
  color: var(--fg-1);
  border-radius: var(--radius-sm);
  text-decoration: none;
}
.user-menu a:hover { background: var(--bg-2); color: var(--fg-0); }

/* Sub-sidebar polish: thêm header card với eyebrow + title */
.sub-sidebar-eyebrow {
  font-size: 10px; font-weight: 600; letter-spacing: 0.06em;
  color: var(--fg-3); text-transform: uppercase;
  margin-bottom: 4px;
}
.sub-sidebar-back {
  font-size: 11px; color: var(--fg-3);
  text-decoration: none;
  display: inline-flex; align-items: center; gap: 4px;
  margin-bottom: 8px;
}
.sub-sidebar-back:hover { color: var(--fg-0); }

/* Business detail header với chip row + quick stats */
.biz-header {
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-xl);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(20, 18, 14, 0.025);
}
.biz-header-row { display: flex; align-items: flex-start; gap: 12px; }
.biz-avatar {
  width: 52px; height: 52px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--brand-soft) 0%, var(--brand-tint) 100%);
  border: 1px solid var(--border-1);
  display: grid; place-items: center;
  color: var(--brand-700);
  flex-shrink: 0;
}
.biz-chip-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.biz-meta-row {
  margin-top: 6px;
  font-size: 12px; color: var(--fg-3);
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.biz-meta-row > span { display: inline-flex; align-items: center; gap: 4px; }
.biz-meta-row i { width: 12px; height: 12px; }
.biz-quick-stats {
  margin-top: 14px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
}
.qstat {
  background: var(--bg-2);
  border-radius: var(--radius-md);
  padding: 8px 12px;
}
.qstat-label { font-size: 10px; color: var(--fg-3); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.qstat-value { font-size: 16px; font-weight: 700; color: var(--fg-0); font-family: var(--font-mono); margin-top: 2px; }

/* === Sprint 28 — Dashboard polish === */
.dashboard-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.dashboard-kpi-grid .kpi {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out), border-color var(--dur-fast);
}
.dashboard-kpi-grid .kpi:hover {
  transform: translateY(-2px);
  border-color: var(--border-2);
}
.dashboard-grid-2col {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
@media (max-width: 1023px) {
  .dashboard-grid-2col { grid-template-columns: 1fr; }
}

/* === Sprint 28 — Timeline (activity feed) === */
.timeline { display: flex; flex-direction: column; gap: 10px; }
.timeline-item {
  display: flex; gap: 10px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border-1);
}
.timeline-item:last-child { border-bottom: 0; }
.timeline-icon {
  width: 28px; height: 28px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.timeline-icon i { width: 14px; height: 14px; }
.timeline-body { flex: 1; min-width: 0; }
.timeline-row1 { font-size: 13px; }
.timeline-desc { font-size: 12px; color: var(--fg-2); margin-top: 2px; }
.timeline-meta { font-size: 10px; color: var(--fg-4); margin-top: 4px; font-family: var(--font-mono); }

/* card-head with link-brand */
.card-head .link-brand { font-size: 12px; }
.card-title i { width: 14px; height: 14px; vertical-align: -2px; margin-right: 4px; }

/* Sprint 28 — Ledger tab */
.ledger-table tr.ledger-invoice td:first-child { border-left: 3px solid var(--info); padding-left: 8px; }
.ledger-table tr.ledger-payment td:first-child { border-left: 3px solid var(--success); padding-left: 8px; }
.ledger-table tr.ledger-quote td:first-child { border-left: 3px solid var(--brand); padding-left: 8px; }
.ledger-table tr.ledger-contract td:first-child { border-left: 3px solid #a855f7; padding-left: 8px; }
.ledger-table tr.ledger-expense td:first-child { border-left: 3px solid var(--warn); padding-left: 8px; }

/* === Sprint 29 — seg-btn cho anchor + KPI position relative === */
a.seg-btn { text-decoration: none; height: 100%; }
.seg { height: 32px; align-items: stretch; }
.seg a.seg-btn, .seg button.seg-btn { display: inline-flex; align-items: center; }
.seg-btn i { width: 12px; height: 12px; }

.kpi { position: relative; min-height: 96px; padding-bottom: 18px; }
.kpi-foot { display: flex; align-items: center; gap: 8px; font-size: 11px; }
.kpi-delta.up { color: var(--success); }
.kpi-delta.down { color: var(--danger); }
.kpi-icon { width: 28px; height: 28px; border-radius: var(--radius-md); display: grid; place-items: center; position: absolute; top: 14px; right: 14px; }
.kpi-icon i { width: 14px; height: 14px; }

a.kpi { text-decoration: none; color: inherit; }
.tabs .tab { text-decoration: none; }

/* === Sprint 30 — admin-shell 3 cột khi has-sub === */
:root { --w-subsidebar: 232px; }
.admin-shell.has-sub {
  display: grid;
  grid-template-columns: 232px var(--w-subsidebar) 1fr;
  min-height: 100vh;
}
.admin-shell.has-sub .subsidebar {
  border-right: 1px solid var(--border-1);
  background: var(--bg-1);
  overflow-y: auto;
  height: 100vh;
  position: sticky;
  top: 0;
}
.subsidebar-header {
  padding: 16px 14px;
  border-bottom: 1px solid var(--border-1);
  display: flex; flex-direction: column; gap: 4px;
}
.subsidebar-back {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; color: var(--fg-3);
  text-decoration: none;
  margin-bottom: 6px;
  align-self: flex-start;
}
.subsidebar-back:hover { color: var(--brand); }
.subsidebar-eyebrow {
  font-size: 10px; font-weight: 600; letter-spacing: 0.06em;
  color: var(--fg-3); text-transform: uppercase;
}
.subsidebar-title { font-size: 15px; font-weight: 700; color: var(--fg-0); line-height: 1.3; }
.subsidebar-meta { font-size: 11px; color: var(--fg-3); margin-top: 2px; font-family: var(--font-mono); }
.subsidebar-nav { display: flex; flex-direction: column; padding: 8px 6px; gap: 1px; }
.subsidebar-nav .nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px; color: var(--fg-1);
  text-decoration: none; cursor: pointer;
}
.subsidebar-nav .nav-item:hover { background: var(--bg-2); color: var(--fg-0); }
.subsidebar-nav .nav-item.active {
  background: var(--brand-soft);
  color: var(--brand-700);
  font-weight: 600;
}
.subsidebar-nav .nav-item .nav-icon { color: var(--fg-3); }
.subsidebar-nav .nav-item.active .nav-icon { color: var(--brand-700); }
.subsidebar-nav .nav-item .nav-badge {
  margin-left: auto;
  background: var(--bg-2);
  color: var(--fg-3);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  font-family: var(--font-mono);
}
.subsidebar-nav .nav-item.active .nav-badge { background: var(--brand-tint); color: var(--brand-700); }

@media (max-width: 1023px) {
  .admin-shell.has-sub {
    grid-template-columns: 56px var(--w-subsidebar) 1fr;
  }
}
@media (max-width: 767px) {
  .admin-shell.has-sub {
    grid-template-columns: 1fr;
  }
  .admin-shell.has-sub .sidebar,
  .admin-shell.has-sub .subsidebar { display: none; }
}

/* Bỏ biz-detail-layout cũ vì sub-sidebar đã ra ngoài */
.biz-detail-layout {
  display: block;
}
.biz-detail-content { width: 100%; }

/* === Sprint 30 — Drawer fragment pattern === */
.drawer { display: flex; flex-direction: column; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border-1); }
.drawer-head h3 { margin: 0; font-size: 15px; font-weight: 700; color: var(--fg-0); }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px; }
.drawer-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border-1); background: var(--bg-1); }
.drawer-section-label { font-size: 11px; font-weight: 600; color: var(--fg-3); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px; margin-top: 4px; }
.drawer .callout { display: flex; gap: 10px; padding: 10px 12px; background: var(--brand-soft); color: var(--brand-700); border-radius: var(--radius-md); font-size: 12px; line-height: 1.5; }
.drawer .callout i { flex-shrink: 0; margin-top: 2px; color: var(--brand); }
.drawer .callout strong { color: var(--brand-700); }
.divider { height: 1px; background: var(--border-1); margin: 12px 0 8px; }
.col { display: flex; flex-direction: column; }
.col.gap-2 { gap: 8px; } .col.gap-3 { gap: 12px; } .col.gap-4 { gap: 16px; }
.row { display: flex; align-items: center; }
.row.gap-2 { gap: 8px; } .row.gap-3 { gap: 12px; }
.field label { font-size: 11px; color: var(--fg-2); margin-bottom: 4px; display: block; }
.field { display: flex; flex-direction: column; min-width: 0; }

/* === Sprint 32 — Sitemap === */
.sitemap-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}
.sitemap-items { display: flex; flex-direction: column; gap: 2px; }
.sitemap-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--fg-1);
  font-size: 13px;
}
.sitemap-item:hover { background: var(--bg-2); color: var(--brand-700); }
.sitemap-item i { color: var(--fg-3); width: 14px; height: 14px; }
.sitemap-item:hover i { color: var(--brand); }
.sitemap-count { margin-left: auto; font-size: 10px; font-family: var(--font-mono); color: var(--fg-3); background: var(--bg-2); padding: 1px 6px; border-radius: 999px; }

/* === Sprint 32 — Knowledge grid === */
.knowledge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.knowledge-card { text-decoration: none; color: inherit; transition: border-color var(--dur-fast), transform var(--dur-fast); }
.knowledge-card:hover { border-color: var(--brand); transform: translateY(-2px); }
.knowledge-card .card-body { padding: 14px; }
.article-body { line-height: 1.7; font-size: 14px; }
.article-body h1, .article-body h2, .article-body h3 { margin: 16px 0 8px; color: var(--fg-0); }
.article-body p { margin: 8px 0; }
.article-body ul { padding-left: 20px; margin: 8px 0; }
.article-body code { background: var(--bg-2); padding: 1px 6px; border-radius: 4px; font-family: var(--font-mono); font-size: 12px; }
.article-body a { color: var(--brand-700); }

/* === Sprint 33 — Tweaks panel === */
.tweaks-panel {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 280px;
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 40px rgba(0,0,0,.18);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.tweaks-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-1);
}
.tweaks-head strong { font-size: 13px; color: var(--fg-0); }
.tweaks-body { padding: 14px; }
.tweaks-colors {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-top: 6px;
}
.tweaks-color {
  appearance: none;
  border: 2px solid #fff;
  outline: 1px solid transparent;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
  transition: transform var(--dur-fast);
}
.tweaks-color:hover { transform: scale(1.1); outline-color: var(--border-2); }
.tweaks-body kbd { font-family: var(--font-mono); font-size: 10px; background: var(--bg-2); padding: 1px 5px; border-radius: 4px; border: 1px solid var(--border-1); }

/* === Sprint 34 — Bulk toolbar === */
.bulk-toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 14px;
  background: var(--brand-soft);
  border: 1px solid var(--brand);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--brand-700);
}
.bulk-toolbar .input.sm { height: 28px; padding: 0 8px; font-size: 12px; }
.bulk-toolbar .btn.sm { height: 28px; font-size: 11px; padding: 0 10px; }
.ck { width: 28px; text-align: center; }

/* === Dashboard expansion === */
.dashboard-grid-3col {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
@media (max-width: 1023px) { .dashboard-grid-3col { grid-template-columns: 1fr; } }

.dashboard-task-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}
.task-tab {
  display: flex; flex-direction: column;
  padding: 12px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  color: inherit;
  text-decoration: none;
  transition: border-color var(--dur-fast), transform var(--dur-fast);
}
.task-tab:hover { border-color: var(--border-2); transform: translateY(-1px); }
.task-tab-label { font-size: 11px; color: var(--fg-3); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.task-tab-value { font-size: 22px; font-weight: 700; color: var(--fg-0); margin-top: 4px; font-family: var(--font-mono); }
.task-tab.danger { background: #fef2f2; border-color: #fecaca; }
.task-tab.danger .task-tab-value { color: #dc2626; }

.task-mini-list { display: flex; flex-direction: column; gap: 1px; }
.task-mini-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: inherit;
  font-size: 13px;
}
.task-mini-item:hover { background: var(--bg-2); }
.task-dot { width: 8px; height: 8px; border-radius: 999px; background: var(--fg-4); flex-shrink: 0; }
.task-dot.priority-high { background: #ef4444; }
.task-dot.priority-normal { background: #2563eb; }
.task-dot.priority-low { background: #94a3b8; }
.task-mini-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-mini-due { font-size: 11px; color: var(--fg-3); font-family: var(--font-mono); }
.task-mini-due.overdue { color: #dc2626; font-weight: 600; }

.reminder-list { display: flex; flex-direction: column; gap: 6px; }
.reminder-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: inherit;
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.reminder-item:hover { background: var(--bg-2); border-color: var(--border-2); }
.reminder-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: grid; place-items: center;
  background: rgba(245, 158, 11, 0.12);
  color: #d97706;
  flex-shrink: 0;
}
.reminder-icon i { width: 16px; height: 16px; }
.reminder-body { flex: 1; min-width: 0; }
.reminder-title { font-size: 13px; font-weight: 600; color: var(--fg-0); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reminder-meta { font-size: 11px; color: var(--fg-3); margin-top: 2px; }

.top-customer-list { display: flex; flex-direction: column; gap: 6px; }
.top-customer {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  text-decoration: none;
  color: inherit;
  transition: background var(--dur-fast);
}
.top-customer:hover { background: var(--bg-2); }
.top-customer .rank {
  font-family: var(--font-mono);
  font-size: 12px; font-weight: 700;
  color: var(--brand-700);
  background: var(--brand-soft);
  padding: 4px 8px;
  border-radius: 6px;
  flex-shrink: 0;
}
.top-customer-body { flex: 1; min-width: 0; }
.top-customer-name { font-size: 13px; font-weight: 600; color: var(--fg-0); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-customer-bar {
  width: 100%; height: 4px;
  background: var(--bg-3);
  border-radius: 999px;
  margin-top: 4px;
  overflow: hidden;
}
.top-customer-bar span { display: block; height: 100%; background: var(--brand); border-radius: inherit; }
.top-customer-value { font-family: var(--font-mono); font-size: 13px; font-weight: 600; color: var(--fg-0); flex-shrink: 0; }

/* Horizontal filter row - used across list pages */
.filter-row {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 8px 10px;
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  margin-bottom: 10px;
}
.filter-row .search-bar {
  flex: 1 1 220px;
  min-width: 200px;
  max-width: 360px;
  margin: 0;
  height: 32px;
}
.filter-row .search-bar input { font-size: 12px; height: 30px; }
.filter-row .input, .filter-row .select {
  height: 32px; padding: 0 8px; font-size: 12px;
  flex: 0 1 auto;
  min-width: 130px;
  max-width: 200px;
}
.filter-row .input[type="date"], .filter-row .input[type="month"] { min-width: 130px; width: 130px; }
.filter-row .filter-spacer { flex: 1 0 0; min-width: 12px; }
.filter-row label.chip,
.filter-row .filter-chk {
  height: 32px;
  font-size: 12px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.filter-row .filter-chk input { margin: 0; width: 14px; height: 14px; accent-color: var(--brand); }
.filter-row .btn { height: 32px; font-size: 12px; padding: 0 10px; }

/* File input — fix vertical alignment trên Chrome/Firefox */
input.input[type="file"] {
  padding: 0 0 0 10px;
  display: inline-flex;
  align-items: center;
  line-height: 1;
  cursor: pointer;
}
input.input[type="file"]::-webkit-file-upload-button,
input.input[type="file"]::file-selector-button {
  height: 28px;
  margin: 0 10px 0 -10px;
  padding: 0 12px;
  background: var(--bg-2);
  border: 0;
  border-right: 1px solid var(--border-2);
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-1);
  cursor: pointer;
  transition: background 120ms ease;
}
input.input[type="file"]:hover::-webkit-file-upload-button,
input.input[type="file"]:hover::file-selector-button {
  background: var(--bg-3);
  color: var(--fg-0);
}

/* Status tabs - horizontal */
.status-tabs {
  display: flex; align-items: center; gap: 4px;
  border-bottom: 1px solid var(--border-1);
  margin-bottom: 12px;
  overflow-x: auto;
}
.status-tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-bottom: 2px solid transparent;
  color: var(--fg-2);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.status-tab:hover { color: var(--fg-0); }
.status-tab.active { color: var(--brand-700); border-bottom-color: var(--brand); font-weight: 600; }
.status-tab .count {
  font-size: 11px;
  background: var(--bg-2);
  padding: 1px 7px;
  border-radius: 999px;
  font-family: var(--font-mono);
  color: var(--fg-3);
}
.status-tab.active .count { background: var(--brand-soft); color: var(--brand-700); }

/* KPI mini-grid (used on list pages) */
.kpi-mini-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}
.kpi-mini {
  padding: 10px 12px;
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}
.kpi-mini:hover { border-color: var(--border-2); box-shadow: 0 2px 8px -4px rgba(20, 18, 14, 0.08); }
.kpi-mini-label { font-size: 11px; color: var(--fg-3); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.kpi-mini-value { font-size: 18px; font-weight: 700; color: var(--fg-0); margin-top: 4px; font-family: var(--font-mono); }
.kpi-mini-sub { font-size: 11px; color: var(--fg-3); margin-top: 2px; }
.kpi-mini.warn .kpi-mini-value { color: #d97706; }
.kpi-mini.danger .kpi-mini-value { color: #dc2626; }
.kpi-mini.success .kpi-mini-value { color: #059669; }
.kpi-mini.info .kpi-mini-value { color: #2563eb; }

/* Notification drawer items */
.notif-list { display: flex; flex-direction: column; gap: 6px; }
.notif-item {
  display: flex; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border-1);
  border-left-width: 3px;
  border-radius: var(--radius-md);
  background: var(--bg-1);
  color: inherit;
  text-decoration: none;
  align-items: flex-start;
}
.notif-item:hover { background: var(--bg-2); }
.notif-item.notif-info { border-left-color: #2563eb; }
.notif-item.notif-warn { border-left-color: #f59e0b; }
.notif-item.notif-danger { border-left-color: #ef4444; }
.notif-item.notif-success { border-left-color: #10b981; }
.notif-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: grid; place-items: center;
  background: var(--bg-2);
  color: var(--fg-2);
  flex-shrink: 0;
}
.notif-item.notif-info .notif-icon { background: #2563eb22; color: #2563eb; }
.notif-item.notif-warn .notif-icon { background: #f59e0b22; color: #d97706; }
.notif-item.notif-danger .notif-icon { background: #ef444422; color: #dc2626; }
.notif-item.notif-success .notif-icon { background: #10b98122; color: #059669; }
.notif-icon i { width: 16px; height: 16px; }
.notif-body { flex: 1; min-width: 0; }
.notif-title { font-size: 13px; font-weight: 600; color: var(--fg-0); line-height: 1.3; }
.notif-desc { font-size: 12px; color: var(--fg-1); line-height: 1.4; margin-top: 2px; word-wrap: break-word; }
.notif-meta { font-size: 10px; color: var(--fg-3); margin-top: 4px; }

/* === Calendar view === */
.calendar-nav { display: inline-flex; align-items: center; gap: 6px; }
.calendar-grid {
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.calendar-head {
  display: grid; grid-template-columns: repeat(7, 1fr);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border-1);
}
.calendar-head-cell {
  padding: 8px 10px;
  font-size: 11px; font-weight: 600;
  color: var(--fg-3); text-transform: uppercase; letter-spacing: 0.04em;
  text-align: center;
}
.calendar-head-cell.weekend { color: var(--brand-700); }
.calendar-week {
  display: grid; grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--border-1);
}
.calendar-week:last-child { border-bottom: none; }
.calendar-day {
  min-height: 110px;
  padding: 6px 6px 8px;
  border-right: 1px solid var(--border-1);
  display: flex; flex-direction: column;
  gap: 4px;
  background: var(--bg-1);
  position: relative;
}
.calendar-day:last-child { border-right: none; }
.calendar-day.other { background: var(--bg-2); }
.calendar-day.other .calendar-day-num { color: var(--fg-4); }
.calendar-day.weekend:not(.other) { background: #fffaf7; }
.calendar-day.today { background: rgba(233, 75, 31, 0.06); }
.calendar-day.today .calendar-day-num {
  background: var(--brand);
  color: #fff;
  width: 22px; height: 22px;
  border-radius: 999px;
  display: inline-grid; place-items: center;
  font-weight: 700;
}
.calendar-day-head {
  display: flex; justify-content: space-between; align-items: center;
}
.calendar-day-num { font-size: 12px; font-weight: 600; color: var(--fg-1); }
.calendar-day-add {
  width: 18px; height: 18px;
  display: inline-grid; place-items: center;
  border-radius: 4px;
  color: var(--fg-4);
  text-decoration: none;
  opacity: 0;
  transition: opacity var(--dur-fast);
}
.calendar-day:hover .calendar-day-add { opacity: 1; }
.calendar-day-add:hover { background: var(--brand-soft); color: var(--brand-700); }
.calendar-day-add i { width: 12px; height: 12px; }
.calendar-day-tasks { display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.calendar-task {
  display: flex; align-items: center; gap: 4px;
  padding: 2px 6px;
  background: var(--bg-2);
  border-left: 3px solid var(--brand);
  border-radius: 3px;
  font-size: 11px;
  color: var(--fg-1);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  line-height: 1.3;
}
.calendar-task:hover { background: var(--bg-3); }
.calendar-task .calendar-task-title { overflow: hidden; text-overflow: ellipsis; }
.calendar-task .dot-urgent {
  width: 14px; height: 14px;
  background: #ef4444;
  color: #fff;
  border-radius: 999px;
  font-size: 9px; font-weight: 700;
  display: inline-grid; place-items: center;
  flex-shrink: 0;
}
.calendar-more {
  font-size: 11px; color: var(--brand-700);
  text-decoration: none;
  padding: 1px 4px;
}
.calendar-more:hover { text-decoration: underline; }

@media (max-width: 768px) {
  .calendar-day { min-height: 80px; padding: 4px 3px; }
  .calendar-day-num { font-size: 11px; }
  .calendar-task { font-size: 10px; padding: 1px 4px; }
  .calendar-head-cell { padding: 6px 4px; font-size: 10px; }
}

/* === Mobile polish === */
@media (max-width: 767px) {
  /* Sidebar: hide completely, push content to fullscreen */
  .admin-shell { grid-template-columns: 1fr !important; }
  .admin-shell.has-sub { grid-template-columns: 1fr !important; }
  /* Off-canvas drawer behaviour (slide-in + overlay + full menu labels)
     is consolidated in the dedicated block further below. */
  /* Topbar: more compact */
  .topbar { padding: 0 8px; gap: 4px; }
  .search-bar { width: 0; flex: 1; min-width: 0; }
  .search-bar kbd { display: none; }
  .topbar-divider { margin: 0 2px; }
  .topbar .btn.brand.sm { padding: 0 8px; }
  .topbar .btn.brand.sm span,
  .topbar .btn.brand.sm { font-size: 0; }
  .topbar .btn.brand.sm i { font-size: 16px; }
  /* Show mobile hamburger button */
  .mobile-menu-btn { display: inline-grid !important; }
  /* Page head: stack vertically */
  .page-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .page-head .action-bar { flex-wrap: wrap; gap: 6px; }
  .page-head .action-bar .btn { font-size: 12px; padding: 0 10px; height: 32px; }
  /* Tables: horizontal scroll */
  .card-body { overflow-x: auto; }
  .tbl { min-width: 600px; }
  /* KPI mini grid: 2 cols */
  .kpi-mini-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid-2col,
  .dashboard-grid-3col { grid-template-columns: 1fr; }
  /* Filter row: stack */
  .filter-row { padding: 8px; gap: 6px; }
  .filter-row .search-bar { width: 100%; flex: none; }
  .filter-row .input { font-size: 12px; }
  .filter-row .filter-spacer { display: none; }
  /* Status tabs: compact + scroll */
  .status-tabs { font-size: 12px; }
  .status-tab { padding: 6px 10px; font-size: 12px; }
  .status-tab .count { font-size: 10px; padding: 0 5px; }
  /* Kanban: stack columns */
  .kanban { display: flex; flex-direction: column; overflow-x: auto; }
  .kanban-col { min-width: 260px; }
  /* Hide rich crumbs */
  .crumbs { font-size: 11px; }
}
.mobile-menu-btn { display: none; }


/* ============================================================
   SPRINT v3 — Mobile overhaul (Banking, Bottom nav, Full-screen)
   ============================================================ */

/* Touch target & input zoom prevention on iOS */
@media (max-width: 767px) {
  /* Prevent iOS zoom on focus: input must be >= 16px */
  input.input, select.input, textarea.input,
  input[type="text"], input[type="email"], input[type="tel"],
  input[type="number"], input[type="password"], input[type="search"],
  input[type="date"], input[type="time"], input[type="datetime-local"],
  input[type="url"], textarea, select {
    font-size: 16px !important;
    min-height: 40px;
  }
  /* Touch targets: min 40px height for buttons / links in nav */
  .btn { min-height: 40px; padding: 0 14px; }
  .btn.xs { min-height: 32px; }
  .btn.sm { min-height: 36px; }
  .iconbtn { min-width: 40px; min-height: 40px; }
  .iconbtn.xs { min-width: 32px; min-height: 32px; }
  /* Better tap feedback */
  .btn:active, .iconbtn:active, .nav-item:active, .kanban-card:active { opacity: .7; }
}

/* Safe area for iPhone notch / Android gesture bar */
@supports (padding: max(0px)) {
  .admin-content { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  .sidebar { padding-bottom: env(safe-area-inset-bottom); }
}

/* Bottom navigation (mobile only) */
.bottom-nav {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 90;
  background: var(--bg-1);
  border-top: 1px solid var(--border-1);
  box-shadow: 0 -2px 12px rgba(20,18,14,0.06);
  padding: 4px 4px max(4px, env(safe-area-inset-bottom));
  justify-content: space-around;
  align-items: stretch;
}
.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  font-size: 10px;
  font-weight: 600;
  color: var(--fg-3);
  border-radius: var(--radius-md);
  text-decoration: none;
  min-height: 48px;
  position: relative;
}
.bottom-nav-item i {
  width: 20px; height: 20px;
  margin-bottom: 2px;
}
.bottom-nav-item.active {
  color: var(--brand);
}
.bottom-nav-item.active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 30%;
  right: 30%;
  height: 2px;
  background: var(--brand);
  border-radius: 0 0 2px 2px;
}
.bottom-nav-badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 18px);
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 14px;
  height: 14px;
  border-radius: 999px;
  padding: 0 4px;
  display: grid; place-items: center;
  line-height: 1;
}

@media (max-width: 767px) {
  .bottom-nav { display: flex; }
  /* Reserve space at bottom of content so bottom-nav doesn't overlap last items */
  .admin-content { padding-bottom: calc(72px + env(safe-area-inset-bottom)) !important; }
  .tweaks-panel { bottom: calc(72px + env(safe-area-inset-bottom)); }
}

/* ============================================================
   Sidebar drawer (mobile, <=767px)
   - Off-canvas: always position:fixed, slid off-screen to the left,
     so the slide-in animation actually plays (display:none can't animate).
   - z-index: overlay (1000) sits above bottom-nav (90); drawer (1001)
     above overlay. Clicking the overlay = click on <body> => JS closes it.
   - When open we RESTORE the full menu (icon + label + badge + group
     titles), overriding the <=1023px icon-rail rules that hide the text.
   ============================================================ */
@media (max-width: 767px) {
  /* NB: dùng `.admin-shell > .sidebar` để THẮNG rule `.admin-shell > .sidebar
     { position: sticky }` (cùng độ đặc hiệu nhưng rule này đứng sau). Nếu chỉ
     dùng `.sidebar` thì position:fixed bị sticky đè → sidebar vẫn chiếm 1 hàng
     trong grid và đẩy toàn bộ nội dung xuống dưới màn hình. */
  .admin-shell > .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: min(280px, 84vw);
    max-width: 84vw;
    z-index: 1001;
    display: flex !important;
    transform: translateX(-100%);
    transition: transform 220ms cubic-bezier(0.2, 0, 0, 1);
    will-change: transform;
    box-shadow: var(--shadow-pop);
  }
  body.sidebar-mobile-open .admin-shell > .sidebar { transform: translateX(0); }
  body.sidebar-mobile-open::after {
    content: "";
    position: fixed; inset: 0;
    background: rgba(20,18,14,0.45);
    z-index: 1000;
    animation: bn-fade-in 200ms ease;
  }
  body.sidebar-mobile-open { overflow: hidden; }

  /* Restore full menu text when the drawer is open */
  body.sidebar-mobile-open .sidebar .sidebar-brand-name,
  body.sidebar-mobile-open .sidebar .sidebar-brand-sub,
  body.sidebar-mobile-open .sidebar .sidebar-user-meta,
  body.sidebar-mobile-open .sidebar .user-name,
  body.sidebar-mobile-open .sidebar .user-mail,
  body.sidebar-mobile-open .sidebar .user-role,
  body.sidebar-mobile-open .sidebar .nav-group-label,
  body.sidebar-mobile-open .sidebar .nav-children { display: block; }
  body.sidebar-mobile-open .sidebar .nav-item span:not(.nav-icon) { display: inline; }
  body.sidebar-mobile-open .sidebar .nav-item .nav-badge { display: inline-flex; }
}
@keyframes bn-fade-in { from { opacity: 0 } to { opacity: 1 } }

/* Mobile responsive tables — convert to cards via data-label attrs */
@media (max-width: 640px) {
  /* Cancel the 600px scroll-width so stacked cards never overflow the page */
  .tbl.tbl-stack { min-width: 0; width: 100%; }
  .tbl.tbl-stack thead { display: none; }
  .tbl.tbl-stack tbody { display: block; }
  .tbl.tbl-stack tr {
    display: block;
    margin-bottom: 8px;
    border: 1px solid var(--border-1);
    border-radius: var(--radius-md);
    background: var(--bg-1);
    padding: 4px 0;
  }
  .tbl.tbl-stack td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px;
    border: 0;
    border-bottom: 1px dashed var(--border-1);
    text-align: right;
  }
  .tbl.tbl-stack td:last-child { border-bottom: 0; }
  .tbl.tbl-stack td::before {
    content: attr(data-label);
    font-size: 11px;
    color: var(--fg-3);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: left;
    flex-shrink: 0;
  }
  .tbl.tbl-stack td:empty::before { content: none; }
  /* Checkbox cell: keep on its own row, left aligned, no label */
  .tbl.tbl-stack td.ck { justify-content: flex-start; text-align: left; width: auto; }
  .tbl.tbl-stack td.ck::before { content: none; }
  /* Actions cell: wrap buttons full-width, no label */
  .tbl.tbl-stack td.table-actions { flex-wrap: wrap; justify-content: flex-start; text-align: left; }
  .tbl.tbl-stack td.table-actions::before { content: none; }
  .tbl.tbl-stack td.table-actions .btn,
  .tbl.tbl-stack td.table-actions form { flex: 1 1 auto; }
}

/* Page-head mobile polish */
@media (max-width: 767px) {
  .page { padding: 12px 10px 16px; }
  .page-title { font-size: 18px; }
  .page-sub { font-size: 11px; }
  .page-title-row { flex-wrap: wrap; gap: 6px; }
  .action-bar { width: 100%; }
  .action-bar .btn { flex: 1; min-width: 0; justify-content: center; }
  .crumbs { display: none; }
}

/* Filter row mobile — collapsible with toggle */
@media (max-width: 767px) {
  .filter-row {
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
  }
  .filter-row > * { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .filter-row .input, .filter-row select {
    width: 100%;
    font-size: 14px !important;
  }
  .filter-row .btn { flex: 1 1 calc(50% - 4px); }
  .filter-row .filter-spacer { display: none; }
}

/* Kanban — horizontal scroll with snap on mobile */
@media (max-width: 767px) {
  .kanban {
    display: flex !important;
    flex-direction: row !important;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    gap: 8px;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
  }
  .kanban-col {
    min-width: 80vw;
    max-width: 85vw;
    scroll-snap-align: start;
    flex-shrink: 0;
  }
  .kanban-card { padding: 10px 12px; }
  .kanban-card-title { font-size: 13px; }
}

/* Form grid mobile */
@media (max-width: 767px) {
  .form-grid {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }
  .form-grid .span-2, .form-grid .span-3 { grid-column: 1 / -1; }
  .form-actions {
    flex-direction: column-reverse;
    align-items: stretch;
    gap: 8px;
  }
  .form-actions .btn { width: 100%; justify-content: center; }
}

/* Cards / KPI mobile */
@media (max-width: 767px) {
  .card { border-radius: var(--radius-md); }
  .card-head { padding: 10px 12px; flex-wrap: wrap; gap: 6px; }
  .card-body { padding: 10px 12px; }
  .kpi { padding: 10px 12px; }
  .kpi-label { font-size: 10px; }
  .kpi-value { font-size: 18px; }
  .kpi-strip,
  .kpi-strip.cols-3,
  .kpi-strip.cols-4,
  .kpi-strip.cols-5,
  .kpi-strip.cols-6 {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }
}

/* Drawer full-screen on mobile */
@media (max-width: 767px) {
  .drawer, .drawer.wide {
    width: 100vw !important;
    max-width: 100vw;
  }
  .drawer-head { padding: 12px 14px; }
  .drawer-body { padding: 12px 14px; }
  .drawer-foot { padding: 10px 14px; flex-direction: column-reverse; gap: 6px; }
  .drawer-foot .btn { width: 100%; justify-content: center; }
}

/* Modal: full-screen on small mobile, dialog on tablet */
@media (max-width: 640px) {
  .modal-box {
    width: 100vw !important;
    max-height: 100vh !important;
    height: 100vh !important;
    border-radius: 0 !important;
    max-width: 100vw;
  }
}

/* Bank reconciliation page UI helpers */
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border-1); flex-wrap: wrap; }
.tabs .tab {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-3);
  border: 0;
  background: transparent;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.tabs .tab:hover { color: var(--fg-0); }
.tabs .tab.active {
  color: var(--brand-700);
  border-bottom-color: var(--brand);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: var(--radius-pill);
  background: var(--bg-2);
  color: var(--fg-2);
}
.badge.ok { background: var(--success-bg); color: var(--success); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.muted { background: var(--bg-2); color: var(--fg-3); }

.ta-right { text-align: right; }

/* Better mobile topbar */
@media (max-width: 767px) {
  .topbar {
    padding: 0 8px;
    min-height: 52px;
    gap: 6px;
  }
  .topbar-spacer { display: none; }
  .topbar .search-bar input { font-size: 14px; }
  .topbar-bell { position: relative; }
  .user-menu-wrap .avatar { width: 30px; height: 30px; font-size: 11px; }
  /* Hide some less-critical icons on mobile to save space */
  .topbar [href*="muctieu"], .topbar [href*="forecast"] { display: none; }
}

/* Pagination mobile */
@media (max-width: 767px) {
  .pagination {
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    font-size: 12px;
  }
  .pagination .pages {
    justify-content: center;
    flex-wrap: wrap;
  }
}

/* Sticky form footer on mobile (improves submit access) */
@media (max-width: 767px) {
  .card form > .form-actions:last-child {
    position: sticky;
    bottom: calc(72px + env(safe-area-inset-bottom));
    background: var(--bg-1);
    padding: 10px 12px;
    margin: 12px -12px -12px;
    border-top: 1px solid var(--border-1);
    z-index: 5;
  }
}

/* Avoid horizontal page overflow */
.admin-content, .admin-main { min-width: 0; }
@media (max-width: 767px) {
  html, body { overflow-x: hidden; }
  .admin-content { max-width: 100vw; }
  .card-body { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* Modal — base styles (in case page doesn't define) */
.modal { position: fixed; inset: 0; z-index: 9999; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal-overlay { position: absolute; inset: 0; background: rgba(20,18,14,0.45); }
.modal-box {
  position: relative;
  background: var(--bg-1);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  width: min(560px, 92vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
}
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--border-1); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-body { padding: 16px 18px; overflow-y: auto; flex: 1; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border-1); display: flex; justify-content: flex-end; gap: 8px; }

/* ============================================================
   F. POPUP SYSTEM (BG.modal / BG.toast / BG.confirm / BG.peek / BG.lightbox)
   ============================================================ */

/* --- Modal --- */
.bg-modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 18, 14, 0.42);
  backdrop-filter: blur(2px);
  animation: bgFadeIn 160ms ease-out;
}
.bg-modal-backdrop.out { animation: bgFadeOut 160ms ease-out forwards; }
.bg-modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-1);
  border-radius: var(--radius-xl);
  box-shadow: 0 24px 64px -16px rgba(20, 18, 14, 0.28), 0 4px 12px rgba(20, 18, 14, 0.08);
  display: flex; flex-direction: column;
  max-height: 88vh;
  width: min(560px, 92vw);
  overflow: hidden;
  animation: bgModalIn 180ms cubic-bezier(0.16, 1, 0.3, 1);
}
.bg-modal.out { animation: bgModalOut 140ms ease-in forwards; }
.bg-modal-sm   { width: min(420px, 92vw); }
.bg-modal-md   { width: min(560px, 92vw); }
.bg-modal-lg   { width: min(820px, 94vw); }
.bg-modal-xl   { width: min(1100px, 96vw); max-height: 92vh; }
.bg-modal-full { width: 96vw; height: 92vh; max-height: 92vh; }
.bg-modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-1);
  gap: 12px;
}
.bg-modal-title { font-size: 14px; font-weight: 700; color: var(--fg-0); letter-spacing: -0.01em; font-family: var(--font-display); }
.bg-modal-close { width: 28px; height: 28px; }
.bg-modal-body  { padding: 14px 16px; overflow-y: auto; flex: 1; min-height: 60px; }
.bg-modal-body.flush { padding: 0; }
.bg-modal-foot  {
  padding: 10px 16px;
  border-top: 1px solid var(--border-1);
  display: flex; justify-content: flex-end; align-items: center;
  gap: 8px;
  background: var(--bg-0);
}
.bg-modal-loading { padding: 32px; text-align: center; color: var(--fg-3); display: flex; align-items: center; justify-content: center; gap: 8px; }
.bg-modal-loading i { animation: bgSpin 800ms linear infinite; }
.bg-modal-error { padding: 20px; color: var(--danger); }

@keyframes bgFadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes bgFadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes bgModalIn {
  from { opacity: 0; transform: translate(-50%, -48%) scale(0.96); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@keyframes bgModalOut {
  from { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  to   { opacity: 0; transform: translate(-50%, -50%) scale(0.97); }
}
@keyframes bgSpin { to { transform: rotate(360deg); } }

/* --- Toast --- */
.bg-toast-wrap {
  position: fixed;
  top: 16px; right: 16px;
  display: flex; flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
  max-width: 380px;
}
.bg-toast {
  pointer-events: auto;
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-left: 3px solid var(--fg-2);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px -8px rgba(20, 18, 14, 0.18), 0 2px 6px rgba(20, 18, 14, 0.06);
  padding: 10px 12px;
  display: flex; align-items: flex-start; gap: 10px;
  font-size: 13px;
  color: var(--fg-1);
  transform: translateX(110%);
  transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1), opacity 200ms;
  opacity: 0;
}
.bg-toast.in  { transform: translateX(0); opacity: 1; }
.bg-toast.out { transform: translateX(110%); opacity: 0; }
.bg-toast-icon  { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.bg-toast-body  { flex: 1; min-width: 0; }
.bg-toast-title { font-weight: 600; color: var(--fg-0); margin-bottom: 2px; font-size: 13px; }
.bg-toast-msg   { font-size: 12px; line-height: 1.45; color: var(--fg-1); }
.bg-toast-close { width: 22px; height: 22px; opacity: 0.5; }
.bg-toast-close:hover { opacity: 1; }
.bg-toast-action {
  background: transparent;
  border: 1px solid var(--border-2);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  flex-shrink: 0;
  color: var(--fg-1);
  transition: background 120ms;
}
.bg-toast-action:hover { background: var(--bg-2); }
.bg-toast-success  { border-left-color: var(--success); }
.bg-toast-success .bg-toast-icon { color: var(--success); }
.bg-toast-info     { border-left-color: var(--info); }
.bg-toast-info .bg-toast-icon { color: var(--info); }
.bg-toast-warn     { border-left-color: var(--warn); }
.bg-toast-warn .bg-toast-icon { color: var(--warn); }
.bg-toast-danger   { border-left-color: var(--danger); }
.bg-toast-danger .bg-toast-icon { color: var(--danger); }

/* --- Confirm --- */
.bg-confirm { display: flex; gap: 14px; }
.bg-confirm-icon {
  width: 44px; height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  display: grid; place-items: center;
}
.bg-confirm-icon i { width: 22px; height: 22px; }
.bg-confirm-icon.info   { background: var(--info-bg);   color: var(--info); }
.bg-confirm-icon.danger { background: var(--danger-bg); color: var(--danger); }
.bg-confirm-msg { flex: 1; min-width: 0; font-size: 13px; line-height: 1.55; color: var(--fg-1); }
.bg-confirm-title { font-size: 14px; font-weight: 600; color: var(--fg-0); margin-bottom: 4px; }
.bg-confirm-token { margin-top: 10px; }
.bg-confirm-token label { font-size: 11px; color: var(--fg-3); display: block; margin-bottom: 4px; }
.bg-confirm-token code { background: var(--bg-2); padding: 1px 6px; border-radius: 4px; color: var(--danger); font-weight: 600; }

/* --- Peek --- */
.bg-peek {
  position: absolute;
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 32px -8px rgba(20, 18, 14, 0.18), 0 2px 6px rgba(20, 18, 14, 0.06);
  min-width: 280px;
  max-width: 360px;
  z-index: 700;
  font-size: 12px;
  color: var(--fg-1);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 140ms ease, transform 140ms ease;
  pointer-events: none;
}
.bg-peek.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.bg-peek-head { padding: 10px 12px 6px; border-bottom: 1px solid var(--border-1); }
.bg-peek-title { font-weight: 700; color: var(--fg-0); font-size: 13px; letter-spacing: -0.005em; }
.bg-peek-sub   { font-size: 11px; color: var(--fg-3); margin-top: 2px; }
.bg-peek-body  { padding: 8px 12px; }
.bg-peek-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bg-peek-stat  { padding: 6px 8px; background: var(--bg-2); border-radius: 6px; }
.bg-peek-stat-label { font-size: 10px; color: var(--fg-3); text-transform: uppercase; font-weight: 600; letter-spacing: 0.03em; }
.bg-peek-stat-value { font-size: 13px; font-weight: 700; color: var(--fg-0); font-family: var(--font-mono); margin-top: 2px; }
.bg-peek-foot  { padding: 6px 12px 10px; display: flex; gap: 6px; }
.bg-peek-loading { padding: 16px; text-align: center; color: var(--fg-3); font-style: italic; }
[data-peek] { cursor: help; border-bottom: 1px dotted transparent; transition: border-color 120ms ease; }
[data-peek]:hover { border-bottom-color: var(--fg-4); }

/* --- Lightbox --- */
.bg-lightbox-img { display: flex; align-items: center; justify-content: center; background: #111; padding: 0; min-height: 60vh; }
.bg-lightbox-img img { max-width: 100%; max-height: 80vh; object-fit: contain; }
.bg-lightbox-pdf { height: 80vh; background: #f1f1ed; }
.bg-lightbox-pdf iframe { width: 100%; height: 100%; border: 0; }
.bg-modal-xl .bg-modal-body, .bg-modal-lg .bg-modal-body { padding: 0; }

/* Print: ẩn các UI primitives */
@media print {
  .bg-modal-backdrop, .bg-modal, .bg-toast-wrap, .bg-peek { display: none !important; }
}

/* ============================================================
   Tùy biến MẬT ĐỘ hiển thị (theme_density) — class gắn vào <body>.
   normal = mặc định (không class). compact = gọn, comfortable = thoáng.
   ============================================================ */
body.density-compact .page { padding: 10px 14px 28px; }
body.density-compact .card-body { padding: 8px 10px; }
body.density-compact .tbl tbody td,
body.density-compact .tbl thead th { padding-top: 5px; padding-bottom: 5px; }
body.density-compact .kpi { padding: 12px 14px; }
body.density-compact .kpi-mini { padding: 8px 10px; }

body.density-comfortable .page { padding: 24px 28px 52px; }
body.density-comfortable .card-body { padding: 18px 22px; }
body.density-comfortable .tbl tbody td,
body.density-comfortable .tbl thead th { padding-top: 12px; padding-bottom: 12px; }
body.density-comfortable .kpi { padding: 22px 24px; }
body.density-comfortable .kpi-mini { padding: 16px 18px; }

/* Bố cục 2 cột trang Công nợ theo tuổi (donut hẹp trái + bảng phải), tự xếp dọc trên màn nhỏ */
.aging-cols { display: grid; grid-template-columns: minmax(0, 340px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .aging-cols { grid-template-columns: 1fr; } }
