/* ==========================================================================
   CPL CENTRAL WEBADMIN - 5-THEME UNIFIED DESIGN SYSTEM
   Chuẩn hóa giao diện công nghiệp dược phẩm / thực phẩm (GMP & Cleanroom)
   Học hỏi và kế thừa từ CPL-NFC-V2 & App_Portal Central Admin
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. THEME DEFINITIONS (5 UNIFIED THEMES)
   -------------------------------------------------------------------------- */

/* 1.1. DARK THEME (Mặc định - Cleanroom Dark Mode) */
:root,
[data-theme="dark"] {
  --bg-app: #030712;
  --bg-card: rgba(15, 23, 42, 0.85);
  --bg-card-hover: rgba(30, 41, 59, 0.92);
  --bg-card-solid: #0d1527;
  --bg-sidebar: #070c18;
  --bg-sidebar-text: #f8fafc;
  --bg-header: rgba(7, 12, 24, 0.85);
  --bg-input: #1e293b;
  --bg-input-focus: #0f172a;
  --bg-btn: #1e293b;
  --bg-btn-hover: #334155;
  --bg-btn-pressed: #0f172a;
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-on-accent: #030712;
  --text-nav-section: #cbd5e1; /* Xám sáng đậm trên nền tối */
  
  --border-default: rgba(255, 255, 255, 0.08);
  --border-strong: #334155;
  --border-active: #38bdf8;
  
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
  --accent-subtle: rgba(56, 189, 248, 0.15);
  --accent-gradient: linear-gradient(135deg, #38bdf8, #0284c7);
  
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.15);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.15);
  --danger: #f43f5e;
  --danger-bg: rgba(244, 63, 94, 0.15);
  --danger-border: rgba(244, 63, 94, 0.4);
  --purple: #a855f7;

  --bg-table: rgba(15, 23, 42, 0.65);
  --bg-table-header: rgba(30, 41, 59, 0.95);
  --bg-table-row-alt: rgba(255, 255, 255, 0.02);
  
  --bg-led: #064e3b;
  --led-glow: rgba(52, 211, 153, 0.35);
  --led-color: #34d399;
  --bg-meter: rgba(0, 0, 0, 0.5);

  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--border-default);
  --shadow-glow: 0 0 25px rgba(56, 189, 248, 0.25);
  --body-pattern: radial-gradient(circle at 10% 20%, rgba(56, 189, 248, 0.05) 0%, transparent 40%),
                  radial-gradient(circle at 90% 80%, rgba(245, 158, 11, 0.03) 0%, transparent 40%);

  --ink: var(--text-primary);
  --ink-muted: var(--text-secondary);
  --bg: var(--bg-app);
  --surface: var(--bg-card-solid);
  --border: var(--border-default);
  --warn-bg: var(--warning-bg);
}

/* 1.2. NFC CORPORATE (Chuẩn Nhận Diện Thương Hiệu NFC Navy) */
[data-theme="nfc-corporate"] {
  --bg-app: #f4f6f9;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-card-solid: #ffffff;
  --bg-sidebar: #1f4e79;
  --bg-sidebar-text: #ffffff;
  --bg-header: rgba(255, 255, 255, 0.94);
  --bg-input: #ffffff;
  --bg-input-focus: #f8fafc;
  --bg-btn: #ffffff;
  --bg-btn-hover: #eef2f6;
  --bg-btn-pressed: #e2e7ee;
  
  --text-primary: #1f2937;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --text-on-accent: #ffffff;
  --text-nav-section: #ffffff; /* Trắng đậm nổi bật trên sidebar xanh Navy */
  
  --border-default: #e2e7ee;
  --border-strong: #c3cbd4;
  --border-active: #1f4e79;
  
  --accent: #1f4e79;
  --accent-hover: #163a5a;
  --accent-subtle: rgba(31, 78, 121, 0.12);
  --accent-gradient: linear-gradient(135deg, #1f4e79, #163a5a);
  
  --success: #2e8b57;
  --success-bg: rgba(46, 139, 87, 0.14);
  --warning: #d68910;
  --warning-bg: rgba(214, 137, 16, 0.14);
  --danger: #c0392b;
  --danger-bg: rgba(192, 57, 43, 0.14);
  --danger-border: rgba(192, 57, 43, 0.35);
  --purple: #7c3aed;

  --bg-table: #ffffff;
  --bg-table-header: #e9eef3;
  --bg-table-row-alt: rgba(31, 41, 55, 0.025);
  
  --bg-led: #0e2233;
  --led-glow: rgba(124, 255, 178, 0.25);
  --led-color: #7cffb2;
  --bg-meter: #f0f4f8;

  --shadow-card: 0 4px 16px -2px rgba(31, 41, 55, 0.08), 0 0 0 1px var(--border-default);
  --shadow-glow: 0 0 20px rgba(31, 78, 121, 0.2);
  --body-pattern: radial-gradient(circle at 10% 20%, rgba(31, 78, 121, 0.04) 0%, transparent 40%),
                  radial-gradient(circle at 90% 80%, rgba(46, 139, 87, 0.04) 0%, transparent 40%);

  --ink: var(--text-primary);
  --ink-muted: var(--text-secondary);
  --bg: var(--bg-app);
  --surface: var(--bg-card-solid);
  --border: var(--border-default);
  --warn-bg: var(--warning-bg);
}

/* 1.3. PREMIUM LIGHT (Sáng Sang Trọng) */
[data-theme="premium-light"] {
  --bg-app: #e2e8f0;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-card-solid: #ffffff;
  --bg-sidebar: #f1f5f9;
  --bg-sidebar-text: #0f172a;
  --bg-header: rgba(241, 245, 249, 0.94);
  --bg-input: #ffffff;
  --bg-input-focus: #ffffff;
  --bg-btn: #ffffff;
  --bg-btn-hover: #f1f5f9;
  --bg-btn-pressed: #e2e8f0;
  
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --text-on-accent: #ffffff;
  --text-nav-section: #0f172a; /* Xám đen đậm rõ nét */
  
  --border-default: rgba(15, 23, 42, 0.09);
  --border-strong: #cbd5e1;
  --border-active: #0284c7;
  
  --accent: #0284c7;
  --accent-hover: #0369a1;
  --accent-subtle: rgba(2, 132, 199, 0.12);
  --accent-gradient: linear-gradient(135deg, #0284c7, #0369a1);
  
  --success: #059669;
  --success-bg: rgba(5, 150, 105, 0.12);
  --warning: #d97706;
  --warning-bg: rgba(217, 119, 6, 0.12);
  --danger: #dc2626;
  --danger-bg: rgba(220, 38, 38, 0.12);
  --danger-border: rgba(220, 38, 38, 0.35);
  --purple: #7c3aed;

  --bg-table: #ffffff;
  --bg-table-header: #f1f5f9;
  --bg-table-row-alt: rgba(15, 23, 42, 0.025);
  
  --bg-led: #d1fae5;
  --led-glow: rgba(5, 150, 105, 0.2);
  --led-color: #065f46;
  --bg-meter: #f8fafc;

  --shadow-card: 0 4px 16px -2px rgba(15, 23, 42, 0.06), 0 0 0 1px var(--border-default);
  --shadow-glow: 0 0 20px rgba(2, 132, 199, 0.2);
  --body-pattern: radial-gradient(circle at 10% 20%, rgba(2, 132, 199, 0.04) 0%, transparent 40%),
                  radial-gradient(circle at 90% 80%, rgba(5, 150, 105, 0.04) 0%, transparent 40%);

  --ink: var(--text-primary);
  --ink-muted: var(--text-secondary);
  --bg: var(--bg-app);
  --surface: var(--bg-card-solid);
  --border: var(--border-default);
  --warn-bg: var(--warning-bg);
}

/* 1.4. WARM PAPER (Sáng Ấm CPL) */
[data-theme="warm-paper"] {
  --bg-app: #faf9f5;
  --bg-card: #ffffff;
  --bg-card-hover: #faf9f5;
  --bg-card-solid: #ffffff;
  --bg-sidebar: #f1efe8;
  --bg-sidebar-text: #3d3d3a;
  --bg-header: rgba(241, 239, 232, 0.94);
  --bg-input: #ffffff;
  --bg-input-focus: #ffffff;
  --bg-btn: #ffffff;
  --bg-btn-hover: #faf9f5;
  --bg-btn-pressed: #e6e4dc;
  
  --text-primary: #1c1917;
  --text-secondary: #44403c;
  --text-muted: #78716c;
  --text-on-accent: #ffffff;
  --text-nav-section: #1c1917; /* Xám đen đậm ấm */
  
  --border-default: rgba(61, 61, 58, 0.12);
  --border-strong: #d5d3cb;
  --border-active: #185fa5;
  
  --accent: #185fa5;
  --accent-hover: #124a80;
  --accent-subtle: rgba(24, 95, 165, 0.12);
  --accent-gradient: linear-gradient(135deg, #185fa5, #0f4577);
  
  --success: #0f6e56;
  --success-bg: rgba(15, 110, 86, 0.12);
  --warning: #854f0b;
  --warning-bg: rgba(133, 79, 11, 0.12);
  --danger: #a32d2d;
  --danger-bg: rgba(163, 45, 45, 0.12);
  --danger-border: rgba(163, 45, 45, 0.35);
  --purple: #6d28d9;

  --bg-table: #ffffff;
  --bg-table-header: #f1efe8;
  --bg-table-row-alt: rgba(61, 61, 58, 0.03);
  
  --bg-led: #ecfdf5;
  --led-glow: rgba(15, 110, 86, 0.15);
  --led-color: #065f46;
  --bg-meter: #f7f6f0;

  --shadow-card: 0 4px 16px -2px rgba(61, 61, 58, 0.08), 0 0 0 1px var(--border-default);
  --shadow-glow: 0 0 20px rgba(24, 95, 165, 0.15);
  --body-pattern: none;

  --ink: var(--text-primary);
  --ink-muted: var(--text-secondary);
  --bg: var(--bg-app);
  --surface: var(--bg-card-solid);
  --border: var(--border-default);
  --warn-bg: var(--warning-bg);
}

/* 1.5. INDUSTRIAL STEEL (Thép Công Nghiệp) */
[data-theme="industrial-steel"] {
  --bg-app: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #243447;
  --bg-card-solid: #1e293b;
  --bg-sidebar: #243447;
  --bg-sidebar-text: #f8fafc;
  --bg-header: rgba(36, 52, 71, 0.92);
  --bg-input: #1e293b;
  --bg-input-focus: #16202e;
  --bg-btn: #334155;
  --bg-btn-hover: #475569;
  --bg-btn-pressed: #16202e;
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-on-accent: #0f172a;
  --text-nav-section: #e2e8f0; /* Xám bạc sáng đậm */
  
  --border-default: #475569;
  --border-strong: #64748b;
  --border-active: #38bdf8;
  
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
  --accent-subtle: rgba(56, 189, 248, 0.18);
  --accent-gradient: linear-gradient(135deg, #38bdf8, #0284c7);
  
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.2);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.2);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.2);
  --danger-border: rgba(239, 68, 68, 0.4);
  --purple: #8b5cf6;

  --bg-table: rgba(36, 52, 71, 0.55);
  --bg-table-header: #243447;
  --bg-table-row-alt: rgba(255, 255, 255, 0.03);
  
  --bg-led: #0b1626;
  --led-glow: rgba(16, 185, 129, 0.3);
  --led-color: #10b981;
  --bg-meter: #16202e;

  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--border-default);
  --shadow-glow: 0 0 25px rgba(56, 189, 248, 0.25);
  --body-pattern: none;

  --ink: var(--text-primary);
  --ink-muted: var(--text-secondary);
  --bg: var(--bg-app);
  --surface: var(--bg-card-solid);
  --border: var(--border-default);
  --warn-bg: var(--warning-bg);
}

/* --------------------------------------------------------------------------
   2. CORE TYPOGRAPHY & RESET
   -------------------------------------------------------------------------- */
:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  line-height: 1.5;
  font-size: 14px;
  background-image: var(--body-pattern);
  background-attachment: fixed;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-app);
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* --------------------------------------------------------------------------
   3. SIDEBAR NAVIGATION (NẰM DƯỚI TOPBAR 62PX - STICKY FLEX SIBLING)
   -------------------------------------------------------------------------- */
.sidebar {
  width: 270px;
  min-width: 270px;
  flex-shrink: 0;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 62px;
  height: calc(100vh - 62px);
  z-index: 95;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: width 0.28s cubic-bezier(0.4, 0, 0.2, 1), min-width 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-x: hidden;
  overflow-y: auto;
}

.sidebar-header {
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border-default);
  transition: padding 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--accent-subtle);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.8px;
  padding: 4px 10px;
  border-radius: var(--radius-xl);
  white-space: nowrap;
}

[data-theme="nfc-corporate"] .brand-badge {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.35);
  color: #ffffff;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  background-color: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--success);
  animation: pulse-ring 1.8s infinite;
  display: inline-block;
}

.btn-sidebar-toggle {
  background: transparent;
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  padding: 0;
}

.btn-sidebar-toggle:hover {
  background: var(--accent-subtle);
  color: var(--text-primary);
  border-color: var(--border-active);
}

.btn-sidebar-toggle svg {
  width: 16px;
  height: 16px;
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="nfc-corporate"] .btn-sidebar-toggle {
  color: rgba(255, 255, 255, 0.85);
  border-color: rgba(255, 255, 255, 0.25);
}
[data-theme="nfc-corporate"] .btn-sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.4);
}

.brand-title {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

[data-theme="nfc-corporate"] .brand-title {
  color: #ffffff;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 2px;
}

[data-theme="nfc-corporate"] .brand-subtitle {
  color: rgba(255, 255, 255, 0.75);
}

/* Nav Menu */
.nav-menu {
  list-style: none;
  padding: 12px 10px 24px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* Mục 2: Tiêu đề nhóm Menu chữ to hơn và màu xám đen đậm */
.nav-section-title {
  font-size: 12.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-nav-section);
  padding: 16px 12px 8px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 13.5px;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
  border: 1px solid transparent;
  user-select: none;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  transition: var(--transition);
}

.nav-item:hover {
  background-color: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-default);
}

[data-theme="nfc-corporate"] .nav-item {
  color: rgba(255, 255, 255, 0.88);
}
[data-theme="nfc-corporate"] .nav-item:hover {
  background-color: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}

.nav-item.active {
  background: var(--accent-subtle);
  color: var(--accent);
  font-weight: 600;
  border-color: var(--border-active);
  box-shadow: 0 0 16px var(--accent-subtle);
}

[data-theme="nfc-corporate"] .nav-item.active {
  background-color: #ffffff;
  color: #1f4e79;
  border-color: #ffffff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.nav-item.active svg {
  color: var(--accent);
}
[data-theme="nfc-corporate"] .nav-item.active svg {
  color: #1f4e79;
}

.nav-pill {
  margin-left: auto;
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-xl);
  background: var(--bg-btn);
  color: var(--text-muted);
}

.nav-pill.live-pulse {
  background: rgba(16, 185, 129, 0.2);
  color: #10b981;
}

/* Nút Đăng xuất */
.nav-item-logout {
  color: var(--text-secondary);
  margin-top: 4px;
}
.nav-item-logout:hover {
  color: var(--danger) !important;
  background: var(--danger-bg) !important;
  border-color: var(--danger-border) !important;
}
.nav-item-logout:hover svg {
  color: var(--danger) !important;
}

/* --------------------------------------------------------------------------
   4. COLLAPSED SIDEBAR (RÚT GỌN CHUẨN CPL.ADMIN)
   -------------------------------------------------------------------------- */
body.sidebar-collapsed .sidebar {
  width: 72px;
  min-width: 72px;
}

body.sidebar-collapsed .main-wrapper {
  margin-left: 0;
}

body.sidebar-collapsed .sidebar-header {
  padding: 16px 8px 14px;
  text-align: center;
}

body.sidebar-collapsed .sidebar-header-top {
  flex-direction: column-reverse;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-bottom: 0;
}

body.sidebar-collapsed .brand-badge {
  padding: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  margin-bottom: 0;
  justify-content: center;
}

body.sidebar-collapsed .brand-badge-text {
  display: none;
}

body.sidebar-collapsed .btn-sidebar-toggle svg {
  transform: rotate(180deg);
}

body.sidebar-collapsed .brand-title,
body.sidebar-collapsed .brand-subtitle {
  display: none;
}

body.sidebar-collapsed .nav-menu {
  padding: 12px 8px;
  align-items: center;
}

body.sidebar-collapsed .nav-section-title {
  font-size: 0;
  height: 1px;
  width: 32px;
  padding: 0;
  margin: 10px auto;
  background: var(--border-default);
}

body.sidebar-collapsed .nav-item {
  width: 48px;
  height: 48px;
  padding: 0;
  justify-content: center;
  position: relative;
  margin: 2px auto;
  border-radius: var(--radius-md);
}

body.sidebar-collapsed .nav-item span,
body.sidebar-collapsed .nav-item .nav-pill {
  display: none;
}

body.sidebar-collapsed .nav-item svg {
  width: 20px;
  height: 20px;
  margin: 0;
}

body.sidebar-collapsed .nav-item.active {
  box-shadow: none;
  background: var(--accent-subtle);
  border-color: var(--border-active);
}

/* Tooltips nổi khi Sidebar thu gọn */
body.sidebar-collapsed .nav-item::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%) translateX(-6px);
  background: var(--bg-card-solid);
  color: var(--text-primary);
  padding: 7px 14px;
  border-radius: var(--radius-md);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--shadow-card), 0 8px 24px rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-strong);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease, visibility 0.18s;
  z-index: 9999;
}

body.sidebar-collapsed .nav-item::before {
  content: '';
  position: absolute;
  left: calc(100% + 6px);
  top: 50%;
  transform: translateY(-50%);
  border-width: 5px 6px 5px 0;
  border-style: solid;
  border-color: transparent var(--border-strong) transparent transparent;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease, visibility 0.18s;
  z-index: 9999;
}

body.sidebar-collapsed .nav-item:hover::after,
body.sidebar-collapsed .nav-item:hover::before {
  opacity: 1;
  visibility: visible;
  transform: translateY(-50%) translateX(0);
}

/* --------------------------------------------------------------------------
   5. APP MAIN LAYOUT & FULL-WIDTH TOPBAR (CHUẨN V5 & TỐI ƯU TOÀN DIỆN UI/UX)
   -------------------------------------------------------------------------- */
.app-main-layout {
  display: flex;
  flex-direction: row;
  flex: 1;
  width: 100%;
  min-height: calc(100vh - 62px);
  position: relative;
}

.main-wrapper {
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
  max-width: 100%;
  margin: 0 !important;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 62px);
  box-sizing: border-box;
}

body.sidebar-collapsed .main-wrapper {
  margin: 0 !important;
  width: auto;
}

/* ==========================================================================
   TOPBAR HEADER CHẠY NGANG 100% TRÊN ĐỈNH TRÌNH DUYỆT (CHUẨN V5)
   ========================================================================== */
.app-topbar,
.header {
  height: 62px;
  min-height: 62px;
  width: 100%;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background-color: var(--bg-header);
  border-bottom: 1px solid var(--border-default);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  gap: 16px;
}

[data-theme="nfc-corporate"] .app-topbar,
[data-theme="nfc-corporate"] .header {
  background: #153757;
  border-bottom-color: rgba(255, 255, 255, 0.16);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
}

/* Header Left: Hamburger Toggle + Logo NFC + Title CPL + Badge ZERO DEFECT + Company */
.topbar-brand,
.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.sidebar-toggle-btn,
.header-sidebar-toggle-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  padding: 0;
  flex-shrink: 0;
}

.sidebar-toggle-btn:hover,
.header-sidebar-toggle-btn:hover {
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: var(--border-active);
}

.sidebar-toggle-btn svg,
.header-sidebar-toggle-btn svg {
  width: 18px;
  height: 18px;
}

[data-theme="nfc-corporate"] .sidebar-toggle-btn,
[data-theme="nfc-corporate"] .header-sidebar-toggle-btn {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

[data-theme="nfc-corporate"] .sidebar-toggle-btn:hover,
[data-theme="nfc-corporate"] .header-sidebar-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.24);
  color: #ffffff;
  border-color: #ffffff;
}

.brand-logo,
.brand-logo-img {
  height: 36px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}

.brand-title-wrap,
.brand-text-wrap {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

.brand-title,
.brand-main-title {
  font-size: 15.5px;
  font-weight: 800;
  letter-spacing: -0.2px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  line-height: 1.2;
}

[data-theme="nfc-corporate"] .brand-title,
[data-theme="nfc-corporate"] .brand-main-title {
  color: #ffffff;
}

.brand-badge-zero,
.brand-tag-badge {
  font-size: 9.5px;
  font-weight: 800;
  padding: 1.5px 7px;
  border-radius: 4px;
  background: var(--accent-subtle);
  color: var(--accent);
  border: 1px solid var(--border-active);
  letter-spacing: 0.6px;
}

[data-theme="nfc-corporate"] .brand-badge-zero,
[data-theme="nfc-corporate"] .brand-tag-badge {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.45);
}

.brand-sub,
.brand-company-sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

[data-theme="nfc-corporate"] .brand-sub,
[data-theme="nfc-corporate"] .brand-company-sub {
  color: rgba(255, 255, 255, 0.78);
}

/* Header Right: Controls, Quick Switcher, Themes, Status, User Pill */
.topbar-right,
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* Quick User Switcher Wrap */
.quick-switcher-wrap {
  display: flex;
  align-items: center;
}

.quick-user-switcher {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  font-size: 11.5px;
  font-weight: 600;
  padding: 6px 10px;
  outline: none;
  cursor: pointer;
  transition: var(--transition);
  max-width: 220px;
}

.quick-user-switcher:focus,
.quick-user-switcher:hover {
  border-color: var(--border-active);
  box-shadow: 0 0 0 2px var(--accent-subtle);
}

[data-theme="nfc-corporate"] .quick-user-switcher {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

/* Bộ Chọn Theme Chuẩn V5 */
.theme-selector-wrap,
.theme-picker {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-card);
  padding: 5px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  transition: var(--transition);
}

.theme-selector-wrap:hover,
.theme-picker:hover {
  border-color: var(--border-strong);
}

[data-theme="nfc-corporate"] .theme-selector-wrap,
[data-theme="nfc-corporate"] .theme-picker {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
}

.theme-icon,
.theme-picker label {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
}

[data-theme="nfc-corporate"] .theme-icon,
[data-theme="nfc-corporate"] .theme-picker label {
  color: rgba(255, 255, 255, 0.85);
}

.theme-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

[data-theme="nfc-corporate"] .theme-label {
  color: rgba(255, 255, 255, 0.85);
}

.theme-select,
.form-control-theme {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 11.5px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  padding: 2px 4px;
}

[data-theme="nfc-corporate"] .theme-select,
[data-theme="nfc-corporate"] .form-control-theme {
  color: #ffffff;
}

.theme-select option,
.form-control-theme option {
  background: var(--bg-card-solid);
  color: var(--text-primary);
}

/* Nút Mở Nhanh Popup AI Mai trên Topbar Header (Đồng bộ 5 Themes) */
.btn-header-ai-mai {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  outline: none;
  transition: var(--transition);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.btn-header-ai-mai:hover {
  border-color: var(--border-active);
  background: var(--bg-card-hover);
  color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--accent-subtle);
}

[data-theme="nfc-corporate"] .btn-header-ai-mai {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
  color: #ffffff;
}

[data-theme="nfc-corporate"] .btn-header-ai-mai:hover {
  background: rgba(255, 255, 255, 0.28);
  border-color: #ffffff;
  color: #ffffff;
}

.btn-header-ai-mai-icon {
  font-size: 13px;
  display: inline-block;
}

.btn-header-ai-mai-title {
  font-size: 12px;
  font-weight: 700;
}

.btn-header-ai-mai-kbd {
  font-size: 9.5px;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  color: var(--accent);
  padding: 1.5px 6px;
  border-radius: 999px;
  font-weight: 800;
  letter-spacing: 0.3px;
}

[data-theme="nfc-corporate"] .btn-header-ai-mai-kbd {
  background: rgba(0, 0, 0, 0.25);
  border-color: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

/* Chỉ báo trạng thái Capsule V5 */
.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  padding: 5px 12px;
  border-radius: var(--radius-xl);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

[data-theme="nfc-corporate"] .status-indicator {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

.dot-online {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--success);
  box-shadow: 0 0 8px var(--success);
  animation: pulse-ring 1.8s infinite;
}

/* User Pill Chuẩn V5 Tích Hợp Nút Đăng Xuất */
.user-pill,
.user-pill-header {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  padding: 3px 5px 3px 10px;
  border-radius: 24px;
  transition: var(--transition);
}

[data-theme="nfc-corporate"] .user-pill,
[data-theme="nfc-corporate"] .user-pill-header {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.28);
}

.user-avatar,
.user-avatar-header {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: var(--text-on-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 12px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.user-info,
.user-meta-header {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-name-line {
  display: flex;
  align-items: center;
  gap: 6px;
}

.user-name,
.user-name-header {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

[data-theme="nfc-corporate"] .user-name,
[data-theme="nfc-corporate"] .user-name-header {
  color: #ffffff;
}

.user-role,
.user-role-header {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
}

[data-theme="nfc-corporate"] .user-role,
[data-theme="nfc-corporate"] .user-role-header {
  color: rgba(255, 255, 255, 0.75);
}

/* Nút Đăng Xuất Tích Hợp trong User Pill */
.logout-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  margin-left: 4px;
  border-radius: 20px;
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger);
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.logout-btn:hover {
  background: var(--danger);
  color: #ffffff !important;
  border-color: var(--danger);
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.35);
}

.logout-btn svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

/* Role Badges */
.role-badge {
  font-size: 9px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-admin {
  background: rgba(56, 189, 248, 0.2);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.4);
}
.badge-director {
  background: rgba(168, 85, 247, 0.2);
  color: #a855f7;
  border: 1px solid rgba(168, 85, 247, 0.4);
}
.badge-checker {
  background: rgba(245, 158, 11, 0.2);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.4);
}
.badge-operator {
  background: rgba(16, 185, 129, 0.2);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.4);
}
.badge-store {
  background: rgba(99, 102, 241, 0.2);
  color: #818cf8;
  border: 1px solid rgba(99, 102, 241, 0.4);
}

/* Live Clock */
.live-clock {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-card);
  padding: 6px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
}

.clock-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--success);
  display: inline-block;
  animation: blinkDot 1s infinite alternate;
}

@keyframes blinkDot {
  from { opacity: 0.3; }
  to { opacity: 1; }
}

/* Notification Bell */
.notification-bell-container {
  position: relative;
}

.btn-bell {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: var(--transition);
}

.btn-bell:hover {
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: var(--border-active);
}

.bell-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 10px;
  border: 2px solid var(--bg-app);
}

.notification-popover {
  position: absolute;
  top: 48px;
  right: 0;
  width: 360px;
  max-width: 90vw;
  background: var(--bg-card-solid);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.4);
  z-index: 999;
  animation: popoverFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes popoverFadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.popover-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-default);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.popover-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-primary);
}

.popover-mark-all {
  font-size: 11.5px;
  color: var(--accent);
  cursor: pointer;
}
.popover-mark-all:hover {
  text-decoration: underline;
}

.popover-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-default);
  background: var(--bg-card);
}

.p-tab {
  flex: 1;
  text-align: center;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
}

.p-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--bg-card-solid);
}

.popover-body {
  max-height: 280px;
  overflow-y: auto;
  padding: 8px 0;
}

.notif-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-default);
  transition: var(--transition);
}
.notif-item:hover {
  background: var(--bg-card-hover);
}
.notif-item.unread {
  background: var(--accent-subtle);
}

.notif-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}
.notif-warn { background: var(--warning); }
.notif-danger { background: var(--danger); }
.notif-info { background: var(--accent); }

.notif-content {
  flex: 1;
}

.notif-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
}

.notif-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* Mục 8: Bố cục trang chi tiết co giãn sát theo khung trình duyệt */
.content-body {
  flex: 1 1 auto;
  min-width: 0;
  padding: clamp(14px, 1.8vw, 24px);
  width: 100%;
  max-width: 100%;
  margin: 0 !important;
  box-sizing: border-box;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --------------------------------------------------------------------------
   6. CARDS, KPI GRIDS & WORLD-CLASS MATRIX
   -------------------------------------------------------------------------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(8px);
  transition: var(--transition);
  margin-bottom: 20px;
  width: 100%;
}

.card:hover {
  border-color: var(--border-strong);
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.card-subtitle {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: -8px;
  margin-bottom: 16px;
}

/* KPI Grid */
.kpi-grid,
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
  width: 100%;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}

.kpi-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow-glow);
}

.kpi-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.kpi-title,
.kpi-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.kpi-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--accent-subtle);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.kpi-value {
  font-size: 26px;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.kpi-subtext {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.kpi-card.accent-orange .kpi-icon {
  background: var(--warning-bg);
  color: var(--warning);
}
.kpi-card.accent-green .kpi-icon {
  background: var(--success-bg);
  color: var(--success);
}
.kpi-card.accent-purple .kpi-icon {
  background: rgba(168, 85, 247, 0.15);
  color: var(--purple);
}

/* World-Class Food Manufacturing KPI Matrix */
.worldclass-kpi-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-card);
  width: 100%;
}

.worldclass-kpi-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}

.worldclass-badge {
  font-size: 10.5px;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  background: var(--accent-gradient);
  color: var(--text-on-accent);
  letter-spacing: 0.5px;
  margin-right: 8px;
}

.worldclass-kpi-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
}

.worldclass-status-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--success);
  background: var(--success-bg);
  padding: 3px 10px;
  border-radius: var(--radius-xl);
}

.worldclass-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}

.worldclass-card {
  background: var(--bg-card-solid);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  transition: var(--transition);
}

.worldclass-card:hover {
  border-color: var(--border-strong);
}

.wc-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.wc-label {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-secondary);
}

.wc-target {
  font-size: 10.5px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.wc-main-val {
  font-size: 22px;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--text-primary);
  margin-bottom: 8px;
}

.wc-progress-bar {
  height: 6px;
  background: var(--bg-input);
  border-radius: 4px;
  overflow: hidden;
}

.wc-progress-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--accent-gradient);
  transition: width 0.6s ease;
}

.wc-progress-fill.fill-green { background: var(--success); }
.wc-progress-fill.fill-orange { background: var(--warning); }
.wc-progress-fill.fill-purple { background: var(--purple); }

/* --------------------------------------------------------------------------
   7. 5-STATION RADAR CARDS & LED DISPLAYS
   -------------------------------------------------------------------------- */
.radar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
  width: 100%;
}

.radar-card {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-card);
  transition: var(--transition);
}

.radar-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.station-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.station-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-primary);
}

.station-status-pill {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-xl);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.status-online {
  background: var(--success-bg);
  color: var(--success);
}
.status-busy {
  background: var(--warning-bg);
  color: var(--warning);
}
.status-offline {
  background: var(--danger-bg);
  color: var(--danger);
}

.weight-meter {
  background: var(--bg-meter);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 10px;
  text-align: right;
}

.led-display {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 800;
  color: var(--led-color);
  text-shadow: 0 0 10px var(--led-glow);
  letter-spacing: 0.5px;
}

.meter-unit {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-left: 4px;
}

.station-meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-secondary);
  padding: 4px 0;
  border-top: 1px solid var(--border-default);
}

/* --------------------------------------------------------------------------
   8. DATA TABLES & MOBILE-FRIENDLY SCROLLING (MỤC 3)
   -------------------------------------------------------------------------- */
.table-wrap {
  background: var(--bg-table);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow-card);
  margin-bottom: 20px;
  width: 100%;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  text-align: left;
}

.data-table th {
  background: var(--bg-table-header);
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-default);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-default);
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table tbody tr:nth-child(even) {
  background: var(--bg-table-row-alt);
}

.data-table tbody tr:hover {
  background: var(--bg-card-hover);
}

.data-table tbody tr.row-selected {
  background: var(--accent-subtle) !important;
  border-left: 3px solid var(--accent);
}

.data-table tbody tr.row-warn {
  background: var(--warning-bg) !important;
}

.data-table th.num,
.data-table td.num {
  text-align: right;
  font-family: var(--font-mono);
}

.empty-row {
  text-align: center !important;
  padding: 36px 16px !important;
  color: var(--text-muted);
  font-style: italic;
}

/* --------------------------------------------------------------------------
   9. STATUS BADGES, CHIPS & BANNERS
   -------------------------------------------------------------------------- */
.status-badge,
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-xl);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.status-badge-hoat-dong,
.badge-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid var(--success);
}

.status-badge-cho-duyet,
.badge-warning {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid var(--warning);
}

.status-badge-tu-choi,
.badge-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  font-size: 12.5px;
}

.chip strong {
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.banner {
  padding: 12px 18px;
  border-radius: var(--radius-md);
  margin-bottom: 18px;
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.banner-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger-border);
}

.banner-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid var(--success);
}

.banner-warning {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid var(--warning);
}

/* --------------------------------------------------------------------------
   10. BUTTONS & FORMS
   -------------------------------------------------------------------------- */
.btn-primary {
  background: var(--accent-gradient);
  color: var(--text-on-accent);
  border: none;
  border-radius: var(--radius-md);
  padding: 9px 18px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 2px 8px var(--accent-subtle);
  min-height: 38px;
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.1);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px var(--accent-subtle);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: var(--bg-btn);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-btn-hover);
  border-color: var(--border-active);
}

.btn-secondary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius-md);
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  color: white;
}

.btn-small {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  min-height: 30px;
}

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
  width: 100%;
}

.toolbar-label {
  font-size: 13px;
  color: var(--text-secondary);
}

.form-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  width: 100%;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 200px;
}

.field-narrow { flex: 0 1 140px; }
.field-wide { flex: 2 1 280px; }

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

input[type="text"],
input[type="search"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
select,
textarea {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  transition: var(--transition);
  min-height: 38px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--border-active);
  box-shadow: 0 0 0 3px var(--accent-subtle);
  background: var(--bg-input-focus);
}

.field-error {
  color: var(--danger);
  font-size: 11.5px;
  font-weight: 600;
}

.suggest-wrap {
  position: relative;
}

.suggest-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card-solid);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  list-style: none;
}

.suggest-list li {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-default);
  font-size: 13px;
}

.suggest-list li:hover {
  background: var(--accent-subtle);
  color: var(--accent);
}

/* --------------------------------------------------------------------------
   11. MODAL DIALOGS
   -------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  animation: fadeIn 0.2s ease-out;
}

.modal-box {
  background: var(--bg-card-solid);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 540px;
  width: 100%;
  box-shadow: var(--shadow-card), 0 20px 40px rgba(0, 0, 0, 0.45);
  animation: modalScale 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalScale {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
}

/* --------------------------------------------------------------------------
   12. TOAST NOTIFICATIONS
   -------------------------------------------------------------------------- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card-solid);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  min-width: 280px;
  max-width: 420px;
  font-size: 13.5px;
  animation: slideInRight 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transition: opacity 0.28s ease, transform 0.28s ease;
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

.toast.success { border-left: 4px solid var(--success); }
.toast.warning { border-left: 4px solid var(--warning); }
.toast.danger { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--accent); }

.toast-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast.success .toast-icon { color: var(--success); }
.toast.warning .toast-icon { color: var(--warning); }
.toast.danger .toast-icon { color: var(--danger); }
.toast.info .toast-icon { color: var(--accent); }

.toast-message {
  flex: 1;
  line-height: 1.4;
}

.toast-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
}
.toast-close:hover {
  color: var(--text-primary);
}

/* --------------------------------------------------------------------------
   13. QUICK LAUNCHPAD (NAVIGATION TILES)
   -------------------------------------------------------------------------- */
.launchpad-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 14px;
  width: 100%;
}

.launchpad-tile {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 18px;
  text-decoration: none;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.launchpad-tile:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow-glow);
}

.tile-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--accent-subtle);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tile-content {
  flex: 1;
}

.tile-title {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.tile-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* --------------------------------------------------------------------------
   14. MOBILE BOTTOM NAVIGATION (THUMB ZONE - MỤC 4)
   -------------------------------------------------------------------------- */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  z-index: 1000;
  align-items: center;
  justify-content: space-around;
  padding: 0 4px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.25);
  background: rgba(15, 23, 42, 0.94);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

[data-theme="premium-light"] .mobile-bottom-nav,
[data-theme="warm-paper"] .mobile-bottom-nav,
[data-theme="nfc-corporate"] .mobile-bottom-nav {
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  flex: 1;
  height: 100%;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
  transition: var(--transition);
}

.mobile-nav-item svg {
  width: 20px;
  height: 20px;
}

.mobile-nav-item:hover,
.mobile-nav-item.active {
  color: var(--accent);
}

.mobile-icon-wrap {
  position: relative;
  display: inline-flex;
}

.mobile-badge {
  position: absolute;
  top: -4px;
  right: -8px;
  background: var(--success);
  color: white;
  font-size: 8px;
  font-weight: 800;
  padding: 1px 4px;
  border-radius: 8px;
}

/* Backdrop mờ khi mở Sidebar Drawer trên mobile */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1050;
}

.sidebar-backdrop.active {
  display: block;
}

/* Master-Detail Layout Co Giãn Sát Mép Trình Duyệt */
.master-detail-wrap {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  flex-wrap: wrap;
  width: 100%;
}

/* --------------------------------------------------------------------------
   15. RESPONSIVE BREAKPOINTS (MOBILE & TABLET FRIENDLY - MỤC 3, 4, 8)
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .brand-company-sub {
    display: none;
  }
}

@media (max-width: 768px) {
  .master-detail-wrap {
    flex-direction: column !important;
  }
  .master-detail-wrap > * {
    width: 100% !important;
    flex: 1 1 100% !important;
    min-width: 0 !important;
  }

  /* Sidebar thành Drawer trượt ra từ mép trái, nằm dưới topbar 56px */
  .sidebar {
    transform: translateX(-100%);
    position: fixed !important;
    top: 56px;
    bottom: 0;
    left: 0;
    height: calc(100vh - 56px);
    width: 280px !important;
    min-width: 280px !important;
    z-index: 1100;
    box-shadow: 0 0 35px rgba(0, 0, 0, 0.6);
  }

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

  .main-wrapper,
  .content-body {
    margin: 0 !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  .app-topbar,
  .header {
    padding: 0 10px;
    height: 56px;
    min-height: 56px;
  }

  .sidebar-toggle-btn,
  .header-sidebar-toggle-btn {
    display: inline-flex !important;
  }

  /* Ẩn bớt các nhãn phụ trên thanh header mobile để không bị tràn */
  .brand-sub,
  .brand-company-sub,
  .status-indicator,
  .logout-text,
  .theme-label {
    display: none !important;
  }

  /* Kích hoạt Mobile Bottom Nav */
  .mobile-bottom-nav {
    display: flex;
  }

  /* Đẩy padding bottom cho nội dung không bị che bởi Bottom Nav */
  .content-body {
    padding: 12px 10px 84px !important;
  }

  /* Table Mobile: Sticky cột đầu tiên */
  .data-table th:first-child,
  .data-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--bg-card-solid);
    box-shadow: 2px 0 6px rgba(0, 0, 0, 0.15);
  }

  .data-table th:first-child {
    background: var(--bg-table-header);
  }

  .data-table th,
  .data-table td {
    padding: 9px 11px;
    font-size: 12.5px;
  }

  /* Ergonomic touch targets: nút bấm tối thiểu 42px */
  .btn-primary,
  .btn-secondary,
  .btn-danger,
  input,
  select {
    min-height: 42px;
  }

  .quick-user-switcher {
    max-width: 130px;
    font-size: 11px;
    padding: 4px 6px;
  }

  .user-role,
  .user-role-header {
    display: none;
  }
}

@media (max-width: 640px) {
  .live-clock {
    display: none;
  }

  .theme-picker label span {
    display: none;
  }

  .kpi-grid,
  .radar-grid,
  .worldclass-grid {
    grid-template-columns: 1fr;
  }

  .launchpad-grid {
    grid-template-columns: 1fr;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar .field,
  .toolbar button {
    width: 100%;
  }

  .form-row {
    flex-direction: column;
  }
}

/* --------------------------------------------------------------------------
   16. PRESERVED PRINTING SYSTEM (BẢO LƯU 100% CHUẨN IN BM & TEM DECAL A4)
   -------------------------------------------------------------------------- */
@media print {
  @page {
    size: A4 landscape;
    margin: 8mm;
  }

  /* Ẩn tất cả các thành phần UI ngoài trừ vùng in */
  .no-print,
  .sidebar,
  .app-topbar,
  .header,
  .mobile-bottom-nav,
  .toast-container,
  .sidebar-backdrop,
  .ai-mai-fab,
  .copilot-fab,
  .ai-mai-popup-wrapper,
  .copilot-drawer,
  .copilot-backdrop,
  .ai-mai-mini-pill,
  [class*="copilot-"],
  [class*="ai-mai-"] {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
  }

  /* Reset layout cha để không làm co/đẩy vùng in */
  html, body, .app-shell, .app-main-layout, .content-body, .main-wrapper {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    color: #000 !important;
    width: 100% !important;
    height: auto !important;
    min-height: auto !important;
    overflow: visible !important;
    display: block !important;
    position: static !important;
  }

  body > *:not(.app-shell) {
    display: none !important;
  }

  .bm-preview-area {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    overflow: visible !important;
    display: block !important;
  }

  .bm-preview-area .bm-page {
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    min-height: auto !important;
    background: transparent !important;
    page-break-after: always !important;
    break-after: page !important;
  }

  .bm-preview-area .bm-page:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }

  .bm-content {
    width: 100% !important;
    max-width: 100% !important;
  }

  .print-area,
  .nhan-print-area,
  .kh-ngay-area,
  .nhan-dau-ra-in {
    display: block !important;
    overflow: visible !important;
  }

  body.in-nhan-tem .print-area,
  body.in-nhan-tem .bm-preview-area,
  body.in-nhan-tem .kh-ngay-area {
    display: none !important;
  }
}

:root {
  --tem-rong: 60mm;
  --tem-cao: 40mm;
}

/* Khi in tem nhãn nhiệt: body có class in-nhan-tem kích hoạt khổ tem 60x40mm */
@media print {
  body.in-nhan-tem {
    width: 60mm !important;
    height: 40mm !important;
    max-height: 40mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
  }

  body.in-nhan-tem .nhan-print-area {
    display: block !important;
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    width: 60mm !important;
    height: 40mm !important;
    max-height: 40mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
  }

  body.in-nhan-tem .print-area,
  body.in-nhan-tem .bm-preview-area,
  body.in-nhan-tem .kh-ngay-area {
    display: none !important;
  }
}

.nhan-print-area {
  display: block;
  overflow: hidden;
}

.nhan-grid {
  display: block;
  margin: 0;
  padding: 0;
}

.nhan-tem-page {
  width: var(--tem-rong, 60mm);
  height: var(--tem-cao, 40mm);
  max-height: var(--tem-cao, 40mm);
  page-break-after: always;
  break-after: page;
  page-break-inside: avoid;
  break-inside: avoid;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  overflow: hidden;
  margin: 0;
  padding: 0;
}

.nhan-tem-page:last-child {
  page-break-after: avoid;
  break-after: avoid;
}

.nhan-tem {
  width: 52mm;
  height: 26mm;
  max-width: 52mm;
  max-height: 26mm;
  box-sizing: border-box;
  border: 1px solid #000;
  border-radius: 1mm;
  margin: 0 auto;
  padding: 0.6mm 1.2mm;
  break-inside: avoid;
  page-break-inside: avoid;
  page-break-after: avoid;
  page-break-before: avoid;
  font-family: Arial, sans-serif;
  color: #000;
  background: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  position: relative;
}

/* Tem test chẩn đoán máy in */
.nhan-tem-test {
  border: 1.5px dashed #000;
  background: #fff;
}
.nhan-tem-test .test-crosshair-tl { position: absolute; top: 1mm; left: 1mm; font-size: 8pt; font-weight: bold; line-height: 1; }
.nhan-tem-test .test-crosshair-tr { position: absolute; top: 1mm; right: 1mm; font-size: 8pt; font-weight: bold; line-height: 1; }
.nhan-tem-test .test-crosshair-bl { position: absolute; bottom: 1mm; left: 1mm; font-size: 8pt; font-weight: bold; line-height: 1; }
.nhan-tem-test .test-crosshair-br { position: absolute; bottom: 1mm; right: 1mm; font-size: 8pt; font-weight: bold; line-height: 1; }
.nhan-tem-test .test-title { font-size: 8.5pt; font-weight: bold; text-align: center; margin-top: 1mm; }
.nhan-tem-test .test-desc { font-size: 6.5pt; text-align: center; color: #333; margin-top: 0.5mm; }
.nhan-tem-test .test-ruler { display: flex; justify-content: space-between; font-size: 6pt; border-bottom: 1px solid #000; margin: 1mm 2mm; padding-bottom: 0.5mm; }

.nhan-tem:not(:last-child) {
  page-break-after: always;
}

.nhan-tem .nhan-tem-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1.5mm;
  flex: 1;
}

.nhan-tem .nhan-ten {
  font-weight: 800;
  font-size: 7.5pt;
  line-height: 8.5pt;
  max-width: 36mm;
  word-break: break-word;
  color: #000;
}

.nhan-tem .nhan-ma {
  font-size: 6.5pt;
  line-height: 7.5pt;
  color: #222;
  margin-top: 0.2mm;
}

.nhan-tem .nhan-ma-pl {
  font-size: 9.75pt;
  line-height: 10.5pt;
  font-weight: 800;
  color: #000;
  margin-top: 0.3mm;
  margin-bottom: 0.3mm;
}

.nhan-tem .nhan-hsd {
  font-weight: 700;
  color: #8b0000;
  font-size: 6.5pt;
}

.nhan-tem .nhan-qr {
  width: 13.5mm;
  height: 13.5mm;
  flex-shrink: 0;
}

.nhan-tem .nhan-qr img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.nhan-tem-footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  border-top: 0.5px dashed #666;
  padding-top: 0.4mm;
  margin-top: 0.4mm;
}

.nhan-tem .nhan-kl {
  font-size: 10pt;
  font-weight: 900;
  line-height: 10pt;
  color: #000;
}

.nhan-tem .nhan-vitri {
  font-size: 6.5pt;
  font-weight: 700;
  color: #333;
}

/* Biểu mẫu cân A4/A5 */
/* Phiếu theo dõi cân phụ liệu (xem/in) — bố cục theo bản in của Cpl.Admin (Cpl.Printing.BieuMauCanRenderer): A4 NGANG 1122 × 793 px,
   lề 40 px, tiêu đề + logo ở giữa, QR 80 px bên phải, 4 ô thông tin, cột nhãn 160 px nền xám nhạt, viền 0,5 px. Nội dung chữ lấy từ
   BieuMauCanNoiDung (Cpl.Admin.Core), cùng nguồn với bản in WPF. */
.bm-preview-area {
  margin: 0 auto 30px;
  box-sizing: border-box;
  overflow-x: auto;
}

.bm-preview-area .bm-page {
  width: 1120px;
  max-width: 100%;
  min-height: auto;
  padding: 16px 20px;
  margin: 0 auto 24px;
  border: 1px solid var(--border-strong, #cbd5e1);
  border-radius: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.bm-page {
  page-break-after: always;
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 11px;
  color: #000;
  background: #fff;
  padding: 5mm 6mm;
  box-sizing: border-box;
  position: relative;
}

.bm-page:last-child {
  page-break-after: auto;
}

.bm-content {
  width: 100%;
  max-width: 100%;
}

/* ==========================================================================
   BIEU MAU THEO DÕI CÂN PHỤ LIỆU - CHUẨN FORM PDF NHÀ MÁY
   ========================================================================== */
.bm-pdf-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  padding-bottom: 4px;
}

.bm-pdf-logo-col {
  flex: 0 0 auto;
}

.bm-pdf-logo {
  height: 48px;
  object-fit: contain;
  display: block;
}

.bm-pdf-title-col {
  flex: 1 1 auto;
  text-align: center;
  padding: 0 10px;
}

.bm-pdf-title {
  font-size: 16px;
  font-weight: 800;
  margin: 0 0 4px 0;
  color: #000;
  letter-spacing: 0.5px;
}

.bm-pdf-mact {
  font-size: 14px;
  font-weight: 700;
  color: #000;
}

.bm-pdf-meta-col {
  flex: 0 0 auto;
  font-size: 10.5px;
  line-height: 1.4;
  color: #000;
  text-align: left;
  padding: 0 10px;
}

.bm-pdf-meta-row {
  display: flex;
  gap: 4px;
}

.bm-pdf-meta-label {
  font-weight: 600;
}

.bm-pdf-qr-col {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.bm-pdf-qr {
  width: 95px;
  height: 95px;
  display: block;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

.bm-pdf-qr-code {
  font-size: 9.5px;
  font-weight: 700;
  color: #000;
  margin-top: 3px;
  letter-spacing: 0.3px;
}

/* BẢNG LƯỚI GRID */
.bm-grid-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
  font-size: 10px;
  color: #000;
  margin-bottom: 4px;
}

.bm-grid-table th,
.bm-grid-table td {
  border: 1px solid #000;
  padding: 3px 3px;
  color: #000;
  vertical-align: middle;
}

/* Headers */
.bm-grid-table thead th {
  background-color: #fff;
  font-weight: 600;
  text-align: center;
}

.bm-grid-table .col-stt {
  width: 32px;
  text-align: center;
  font-weight: 700;
}

.bm-grid-table .col-me-header {
  width: 48px;
  text-align: center;
  font-weight: 600;
  line-height: 1.1;
}

.bm-grid-table .col-so-me-highlight {
  color: #dc2626;
  font-weight: 800;
  font-size: 11px;
  text-align: center;
}

.bm-grid-table .col-thanhphan {
  font-weight: 700;
  text-align: center;
}

.bm-grid-table .col-pl-code {
  min-width: 52px;
  text-align: center;
  padding: 2px 2px;
}

.pl-code-label {
  font-size: 8px;
  font-weight: normal;
  color: #333;
}

.pl-code-val {
  font-size: 9.5px;
  font-weight: 700;
  white-space: nowrap;
}

.bm-grid-table .col-pl-kl {
  text-align: center;
  padding: 2px 2px;
}

.pl-kl-label {
  font-size: 8px;
  font-weight: normal;
  color: #333;
}

.pl-kl-val {
  font-size: 9.5px;
  font-weight: 700;
}

.bm-grid-table .col-lot {
  width: 45px;
  text-align: center;
  font-weight: 600;
}

.bm-grid-table .col-nguoi-can {
  width: 52px;
  text-align: center;
  font-weight: 600;
  line-height: 1.1;
}

.bm-grid-table .col-kh-header {
  text-align: center;
  font-size: 9px;
  font-weight: 600;
}

.bm-grid-table .col-kh-sub {
  width: 44px;
  font-size: 8px;
  text-align: center;
  line-height: 1.15;
  font-weight: normal;
}

.bm-grid-table .col-ky-ten {
  width: 50px;
  text-align: center;
  font-weight: 600;
  line-height: 1.1;
}

.bm-grid-table .col-sau-xay {
  width: 78px;
  text-align: center;
  background-color: #f0fdf4 !important;
  color: #166534 !important;
  font-weight: 700;
  font-size: 9px;
  line-height: 1.15;
}

.bm-grid-table .col-sau-xay-sub {
  background-color: #f0fdf4 !important;
  color: #166534 !important;
  font-weight: 700;
  font-size: 8.5px;
  text-align: center;
}

.bm-grid-table .cell-sau-xay {
  background-color: #f0fdf4;
  color: #166534;
  font-weight: 700;
  text-align: right;
  padding-right: 4px;
}

/* Các hàng đặc biệt */
.bm-grid-table .row-nsx td {
  height: 22px;
}

.bm-grid-table .cell-label-left {
  font-weight: 600;
  text-align: left;
  padding-left: 4px;
  white-space: nowrap;
}

.bm-grid-table .cell-label-bold {
  font-weight: 700;
  text-align: left;
  padding-left: 4px;
  white-space: nowrap;
}

.bm-grid-table .cell-unit {
  text-align: center;
  font-size: 9px;
}

.bm-grid-table .cell-val-bold {
  text-align: center;
  font-weight: 700;
  font-size: 9.5px;
}

.bm-grid-table .cell-stt {
  text-align: center;
  font-weight: 600;
}

.bm-grid-table .row-batch td {
  height: 24px;
  text-align: center;
}

.bm-grid-table .row-summary td {
  height: 22px;
}

.bm-sub-header-bar {
  display: flex;
  justify-content: flex-start;
  gap: 40px;
  font-size: 11px;
  font-weight: 500;
  margin-bottom: 8px;
  color: #000;
}

.col-pl-code-label-cell {
  background: #fff;
  text-align: left;
  padding: 3px 6px;
  font-weight: normal;
  width: 90px;
}

.cell-nsx-prompt {
  font-size: 8px;
  line-height: 1.35;
  color: #333;
  padding: 2px 2px;
  text-align: left;
}

.row-ghi-nhan-nsx td {
  padding: 2px 6px;
  font-size: 8.5px;
  font-style: italic;
  text-align: left;
  background-color: #fafafa;
}

.cell-total-col {
  width: 80px;
}

/* Legend chân bảng */
.bm-grid-legend-row {
  display: flex;
  gap: 25px;
  font-size: 10px;
  margin: 6px 0 4px 0;
  padding: 0 4px;
}

.bm-solo-instruction {
  font-size: 9.5px;
  line-height: 1.35;
  margin: 4px 0 16px 0;
  padding: 0 4px;
  color: #000;
}

.bm-signatures-section {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  font-size: 10.5px;
  margin-top: 14px;
  padding: 0 4px;
}

.sign-block {
  display: flex;
  flex-direction: column;
}

.bm-bottom-meta {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-top: 1px dashed #999;
  font-size: 9.5px;
  color: #555;
}

/* Hỗ trợ sắp xếp bảng */
th.sortable {
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}

th.sortable:hover {
  background-color: var(--primary-light, #e0f2fe) !important;
  color: var(--primary-accent, #0284c7) !important;
}

.sort-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 700;
  color: var(--primary-accent, #0284c7);
  background: var(--primary-light, #e0f2fe);
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 4px;
}

/* --------------------------------------------------------------------------
   17. TIEN DO MONITORING (A6) — BỐ CỤC DỌC & MA TRẬN MẺ CÂN N >= 15
   -------------------------------------------------------------------------- */
tr.row-selected td {
  background-color: var(--primary-light, #e0f2fe) !important;
  color: var(--primary, #153757) !important;
  font-weight: 600;
  border-top: 1px solid var(--primary-accent, #0284c7) !important;
  border-bottom: 1px solid var(--primary-accent, #0284c7) !important;
}

tr.row-selected td:first-child {
  border-left: 3.5px solid var(--primary-accent, #0284c7) !important;
}

.tien-do-master-card {
  width: 100%;
  margin-bottom: 20px;
}

.tien-do-master-table-wrap {
  max-height: 420px;
  overflow-y: auto;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.tien-do-master-table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--bg-card-alt, #f8fafc);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.tien-do-detail-card {
  width: 100%;
  margin-top: 20px;
  animation: fadeIn 0.2s ease-in-out;
}

/* Bảng ma trận mẻ cân hỗ trợ N >= 15 mẻ với 2 cột cố định (Sticky) */
.matrix-table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin: 14px 0;
}

.matrix-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

.matrix-table th,
.matrix-table td {
  padding: 10px 12px;
  white-space: nowrap;
  font-size: 13.5px;
}

/* Cố định cột 1: Mã PL */
.matrix-table .sticky-col-ma {
  position: sticky;
  left: 0;
  z-index: 2;
  background-color: var(--bg-card, #ffffff);
  min-width: 90px;
  font-weight: 700;
}

/* Cố định cột 2: Tên PL */
.matrix-table .sticky-col-ten {
  position: sticky;
  left: 90px;
  z-index: 2;
  background-color: var(--bg-card, #ffffff);
  min-width: 160px;
  box-shadow: 3px 0 6px -2px rgba(0, 0, 0, 0.1);
}

/* Khi thead sticky và cột cũng sticky */
.matrix-table thead .sticky-col-ma,
.matrix-table thead .sticky-col-ten {
  background-color: var(--bg-card-alt, #f1f5f9);
  z-index: 3;
}

/* Mini Progress Bar hiển thị tỷ lệ mẻ hoàn thành */
.mini-progress-container {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.mini-progress-bg {
  width: 65px;
  height: 6px;
  background-color: var(--border, #e2e8f0);
  border-radius: 9999px;
  overflow: hidden;
}

.mini-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #0284c7 0%, #10b981 100%);
  border-radius: 9999px;
}

/* Live scale weight badge */
.live-scale-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--primary-light, #e0f2fe);
  border: 1px solid rgba(2, 132, 199, 0.3);
  padding: 6px 14px;
  border-radius: var(--radius-md);
  color: var(--primary, #153757);
  font-size: 13.5px;
  font-weight: 600;
}

.live-scale-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #10b981;
  box-shadow: 0 0 8px #10b981;
}

/* ==========================================================================
   MOBILE TOPBAR & APPROVAL CARD ERGONOMICS (< 768px)
   ========================================================================== */
@media (max-width: 768px) {
  /* 1. Thu gọn và tối ưu Topbar */
  .app-topbar {
    padding: 0 10px !important;
    height: 52px !important;
  }
  .topbar-brand .brand-logo {
    height: 28px !important;
  }
  .topbar-brand .brand-sub,
  .topbar-brand .brand-badge-zero {
    display: none !important;
  }
  .topbar-brand .brand-title {
    font-size: 13.5px !important;
    line-height: 1.2 !important;
  }
  .topbar-right {
    gap: 6px !important;
  }
  .theme-selector-wrap {
    display: none !important; /* Ẩn bộ chọn theme trên mobile để giải phóng không gian */
  }
  .quick-switcher-wrap {
    max-width: 110px !important;
  }
  .quick-user-switcher {
    padding: 4px 6px !important;
    font-size: 11px !important;
    max-width: 110px !important;
  }
  .user-pill {
    padding: 2px !important;
    background: transparent !important;
    border: none !important;
  }
  .user-pill .user-info {
    display: none !important; /* Chỉ hiện Avatar tròn trên mobile */
  }
  .user-avatar {
    width: 32px !important;
    height: 32px !important;
    font-size: 12px !important;
  }

  /* 2. HangDoiDuyet Dual-Layout */
  .hang-doi-desktop {
    display: none !important;
  }
  .hang-doi-mobile {
    display: flex !important;
    flex-direction: column;
    gap: 12px;
    padding-bottom: 75px; /* Tránh bị Bottom Navigation che khuất */
  }
}

@media (min-width: 769px) {
  .hang-doi-mobile {
    display: none !important;
  }
  .hang-doi-desktop {
    display: block !important;
  }
}

/* Mobile Approval Card Design System */
.hang-doi-mobile {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mobile-filter-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 8px 2px;
  -webkit-overflow-scrolling: touch;
}
.mobile-filter-chips::-webkit-scrollbar {
  display: none;
}
.mobile-chip {
  background: var(--bg-card, #ffffff);
  border: 1px solid var(--border-default, #cbd5e1);
  color: var(--text-secondary, #475569);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s;
}
.mobile-chip.active {
  background: var(--primary, #0284c7);
  color: #ffffff !important;
  border-color: var(--primary, #0284c7);
  box-shadow: 0 2px 6px rgba(2, 132, 199, 0.3);
}

.mobile-approval-card {
  background: var(--bg-card, #ffffff);
  border: 1px solid var(--border-default, #e2e8f0);
  border-radius: 12px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.05);
  overflow: hidden;
  position: relative;
  transition: transform 0.15s, box-shadow 0.15s;
}
.mobile-approval-card:active {
  transform: scale(0.99);
}
.mobile-approval-card.urgent {
  border-left: 5px solid #ef4444;
}
.mobile-approval-card.warning {
  border-left: 5px solid #f59e0b;
}
.mobile-approval-card.normal {
  border-left: 5px solid #10b981;
}
.mobile-approval-card.card-deeplink {
  border: 2px solid #0284c7;
  border-left: 5px solid #0284c7;
  box-shadow: 0 0 14px rgba(2, 132, 199, 0.25);
}

.m-card-header {
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card-alt, #f8fafc);
  border-bottom: 1px solid var(--border-default, #f1f5f9);
}
.m-card-id-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
.badge-focus {
  background: #0284c7;
  color: #fff;
  font-size: 9.5px;
  font-weight: 800;
  padding: 2px 5px;
  border-radius: 4px;
}
.m-card-id {
  font-family: var(--font-mono, monospace);
  font-size: 13px;
  font-weight: 800;
  color: var(--accent, #0284c7);
}
.m-card-time {
  font-size: 11px;
  color: var(--text-muted, #64748b);
}
.m-card-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 6px;
}
.m-card-badge.urgent {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}
.m-card-badge.warning {
  background: #fefce8;
  color: #a16207;
  border: 1px solid #fef08a;
}
.m-card-badge.normal {
  background: #f0fdf4;
  color: #15803d;
  border: 1px solid #bbf7d0;
}

.m-card-body {
  padding: 12px 14px;
}
.m-card-product {
  margin-bottom: 8px;
}
.m-card-mact {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 800;
  color: var(--accent, #0284c7);
  background: rgba(2, 132, 199, 0.08);
  padding: 1px 6px;
  border-radius: 4px;
  margin-bottom: 3px;
}
.m-card-name {
  font-size: 15px;
  font-weight: 800;
  color: var(--text-primary, #0f172a);
  margin: 0;
  line-height: 1.3;
}

.m-card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--bg-card-alt, #f8fafc);
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-default, #e2e8f0);
}
.m-grid-cell .cell-label {
  display: block;
  font-size: 10px;
  color: var(--text-muted, #64748b);
  margin-bottom: 1px;
}
.m-grid-cell .cell-val {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary, #0f172a);
}

.m-card-alert {
  margin-top: 8px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.m-card-footer {
  padding: 8px 12px;
  background: var(--bg-card-alt, #f8fafc);
  border-top: 1px solid var(--border-default, #e2e8f0);
  display: flex;
  gap: 8px;
}
.m-btn-inspect {
  flex: 1;
  background: var(--bg-card, #ffffff);
  border: 1px solid var(--border-default, #cbd5e1);
  color: var(--text-primary, #334155);
  font-weight: 700;
  padding: 10px 0;
  border-radius: 8px;
  font-size: 12.5px;
  text-align: center;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.m-btn-approve {
  flex: 2;
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff !important;
  font-weight: 800;
  padding: 10px 0;
  border-radius: 8px;
  font-size: 13px;
  text-align: center;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 3px 8px rgba(16, 185, 129, 0.3);
  min-height: 44px;
}
.m-btn-disabled {
  flex: 2;
  background: #e2e8f0;
  color: #94a3b8;
  border: 1px solid #cbd5e1;
  font-weight: 600;
  padding: 10px 0;
  border-radius: 8px;
  font-size: 12px;
  cursor: not-allowed;
  min-height: 44px;
}
.mobile-empty-state {
  text-align: center;
  padding: 30px 16px;
  color: var(--text-muted);
}
.mobile-empty-state span {
  font-size: 36px;
  display: block;
  margin-bottom: 8px;
}

/* ==========================================================================
   KẾ HOẠCH CÂN THEO DÒNG & PREVIEW PANEL (CPL V6.4+)
   ========================================================================== */

/* 1. Layout Master-Detail Theo Chiều Dọc (Vertical Stacked Layout - CPL V6.4+) */
.plan-vertical-layout {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
}
.plan-vertical-section {
  width: 100%;
}
.plan-vertical-preview {
  width: 100%;
  animation: slideDownFade 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  margin-top: 6px;
}

@keyframes slideDownFade {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 2. Bảng Lưới Nhập Liệu Theo Dòng (Smart Data Grid - 100% Full Width) */
.grid-table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: 12px;
  overflow: visible;
  margin-bottom: 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}
.grid-plan-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.grid-plan-table th {
  background: var(--bg-table-header);
  color: var(--text-primary);
  font-weight: 700;
  padding: 12px 14px;
  border-bottom: 1.5px solid var(--border-strong);
  text-align: left;
  white-space: nowrap;
}
.grid-plan-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-default);
  vertical-align: middle;
}
.grid-plan-table tr {
  transition: background 0.15s ease;
  cursor: pointer;
}
.grid-plan-table tr:hover {
  background: rgba(56, 189, 248, 0.04);
}
.grid-plan-table tr.row-selected {
  background: rgba(56, 189, 248, 0.09) !important;
  box-shadow: inset 4px 0 0 var(--accent);
}
.grid-plan-table tr.row-invalid {
  background: rgba(244, 63, 94, 0.04);
}
.grid-plan-table td.num, .grid-plan-table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Ô nhập liệu inline trong dòng */
.inline-input-text {
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  border-radius: 6px;
  padding: 7px 11px;
  font-size: 13px;
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.inline-input-text:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
  outline: none;
  background: var(--bg-input-focus);
}
.inline-input-num {
  width: 85px;
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.inline-input-date {
  padding: 6px 10px;
  font-size: 12.5px;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
}

/* Autocomplete Suggestion trong lưới */
.inline-suggest-box {
  position: relative;
  width: 100%;
}
.inline-suggest-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1050;
  background: var(--bg-card-solid);
  border: 1.5px solid var(--accent);
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
  max-height: 220px;
  overflow-y: auto;
  list-style: none;
  padding: 4px;
  margin-top: 2px;
}
.inline-suggest-item {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  color: var(--text-primary);
  transition: background 0.15s ease;
}
.inline-suggest-item:hover {
  background: var(--accent-subtle);
  color: var(--accent);
}

/* 3. Bảng Xem Trước Chi Tiết Định Mức (Warm Paper Theme / Cleanroom - Trải Dài 100%) */
.preview-panel-container {
  background: #fffdf7;
  border: 1.5px solid #ebd9b3;
  border-radius: 14px;
  color: #2c251e;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}
[data-theme="dark"] .preview-panel-container {
  background: #0d1526;
  border: 1.5px solid #2d3b55;
  color: #f8fafc;
}
.preview-panel-header {
  padding: 14px 20px;
  background: #fdf5e2;
  border-bottom: 1.5px solid #ebd9b3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
[data-theme="dark"] .preview-panel-header {
  background: #19253d;
  border-bottom: 1.5px solid #2d3b55;
}
.preview-panel-title {
  display: flex;
  align-items: center;
  gap: 12px;
}
.preview-icon { font-size: 24px; line-height: 1; }
.preview-heading {
  font-size: 15px;
  font-weight: 800;
  color: #332a22;
  letter-spacing: -0.2px;
}
[data-theme="dark"] .preview-heading { color: #f8fafc; }
.preview-subheading {
  font-size: 12.5px;
  color: #64748b;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.preview-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.btn-scroll-top {
  background: rgba(56, 189, 248, 0.12);
  color: var(--accent);
  border: 1px solid rgba(56, 189, 248, 0.4);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.btn-scroll-top:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-close-preview {
  background: rgba(148, 163, 184, 0.15);
  border: 1px solid rgba(148, 163, 184, 0.3);
  font-size: 12px;
  font-weight: 700;
  color: #64748b;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 6px;
  transition: all 0.2s ease;
}
.btn-close-preview:hover {
  color: #f43f5e;
  background: rgba(244, 63, 94, 0.12);
  border-color: rgba(244, 63, 94, 0.4);
}

.preview-table-wrap {
  width: 100%;
  overflow-x: auto;
}
.preview-detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: #ffffff;
}
[data-theme="dark"] .preview-detail-table {
  background: #090e1a;
}
.preview-detail-table th {
  background: #fdf5e2;
  color: #4a3b2c;
  font-weight: 700;
  padding: 11px 16px;
  border-bottom: 1.5px solid #ebd9b3;
  white-space: nowrap;
}
[data-theme="dark"] .preview-detail-table th {
  background: #172138;
  color: #94a3b8;
  border-bottom: 1.5px solid #2d3b55;
}
.preview-detail-table td {
  padding: 10px 16px;
  border-bottom: 1px solid #f6eedb;
  color: #332a22;
  vertical-align: middle;
}
[data-theme="dark"] .preview-detail-table td {
  border-bottom: 1px solid #1a243a;
  color: #cbd5e1;
}
.preview-detail-table tr:hover td {
  background: rgba(245, 158, 11, 0.05);
}
[data-theme="dark"] .preview-detail-table tr:hover td {
  background: rgba(56, 189, 248, 0.04);
}
.preview-detail-table td.num, .preview-detail-table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Footer chi tiết dạng Card KPI trải rộng */
.preview-panel-footer-cards {
  padding: 14px 20px;
  background: #fdf5e2;
  border-top: 1.5px solid #ebd9b3;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
[data-theme="dark"] .preview-panel-footer-cards {
  background: #131c30;
  border-top: 1.5px solid #2d3b55;
}
.preview-footer-card {
  background: #ffffff;
  border: 1px solid #ebd9b3;
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
[data-theme="dark"] .preview-footer-card {
  background: #1a253c;
  border: 1px solid #2d3b55;
}
.preview-footer-label {
  font-size: 11.5px;
  color: #64748b;
  font-weight: 600;
}
.preview-footer-val {
  font-size: 14.5px;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.preview-footer-card.highlight-card {
  background: #fff8e6;
  border: 1.5px solid #f59e0b;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.15);
}
[data-theme="dark"] .preview-footer-card.highlight-card {
  background: rgba(245, 158, 11, 0.12);
  border: 1.5px solid #f59e0b;
}
.preview-footer-val.highlight-val {
  color: #d97706;
  font-size: 16px;
}
[data-theme="dark"] .preview-footer-val.highlight-val {
  color: #fbbf24;
}

/* 4. Modal Import File Excel / CSV */
.cpl-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 18, 0.75);
  backdrop-filter: blur(4px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}
.cpl-modal-dialog {
  background: var(--bg-card-solid);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  width: 100%;
  max-width: 680px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  overflow: hidden;
}
.cpl-modal-dialog.modal-lg { max-width: 840px; }
.cpl-modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.cpl-modal-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
}
.btn-close-modal {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.btn-close-modal:hover { color: var(--danger); background: var(--danger-bg); }

.cpl-modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.cpl-modal-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border-default);
  background: var(--bg-card);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.template-download-box {
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 10px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.upload-dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: 12px;
  padding: 30px 20px;
  text-align: center;
  background: rgba(255, 255, 255, 0.015);
  transition: all 0.2s ease;
  cursor: pointer;
}
.upload-dropzone:hover {
  border-color: var(--accent);
  background: var(--accent-subtle);
}
.upload-dropzone.disabled { opacity: 0.6; pointer-events: none; }
.input-file-hidden { display: none; }
.dropzone-label { cursor: pointer; display: block; }
.dropzone-icon { font-size: 38px; margin-bottom: 8px; }
.dropzone-text { font-size: 14px; color: var(--text-primary); }
.dropzone-text .link-browse { color: var(--accent); text-decoration: underline; font-weight: 700; }
.dropzone-hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

.processing-box {
  padding: 16px;
  text-align: center;
  color: var(--accent);
  font-weight: 600;
  font-size: 13.5px;
}
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.preview-import-table-wrap {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--border-default);
  border-radius: 8px;
}
.row-error { background: rgba(244, 63, 94, 0.08) !important; }
.btn-remove-row {
  background: none;
  border: none;
  color: var(--danger);
  font-weight: 700;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.btn-remove-row:hover { background: var(--danger-bg); }

/* 5. Giao Diện Mobile & Thumb-Zone Ergonomics (< 992px) */
.plan-mobile-container { display: none; }

@media (max-width: 992px) {
  .plan-desktop-container { display: none; }
  .plan-mobile-container { display: flex; flex-direction: column; gap: 12px; margin-bottom: 90px; }
  
  .mobile-plan-card {
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  }
  .mobile-plan-card.card-selected {
    border-color: var(--accent);
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.25);
  }
  .mobile-plan-card.card-invalid {
    border-left: 4px solid var(--danger);
  }
  .card-top-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
  }
  .card-formula-code {
    font-size: 16px;
    font-weight: 800;
    color: var(--text-primary);
  }
  .card-product-name {
    font-size: 13px;
    color: var(--accent);
    margin-top: 2px;
  }
  .card-body-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--bg-input);
    padding: 10px 12px;
    border-radius: 8px;
  }
  .card-batch-stepper {
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .btn-stepper {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid var(--border-strong);
    background: var(--bg-btn);
    color: var(--text-primary);
    font-weight: 800;
    font-size: 16px;
    display: grid;
    place-items: center;
    cursor: pointer;
  }
  .stepper-val {
    font-size: 15px;
    font-weight: 800;
    min-width: 28px;
    text-align: center;
  }
  .card-actions-row {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
  }

  /* Nút nổi Thêm Kế Hoạch (FAB) */
  .fab-add-plan {
    position: fixed;
    bottom: 84px;
    right: 20px;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: var(--success);
    color: #ffffff;
    border: none;
    font-size: 26px;
    font-weight: 900;
    display: grid;
    place-items: center;
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
    cursor: pointer;
    z-index: 1000;
    transition: transform 0.15s ease;
  }
  .fab-add-plan:active { transform: scale(0.92); }

  /* Thanh Sticky Bottom Bar - Ngón cái 1 chạm */
  .sticky-bottom-action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card-solid);
    border-top: 1px solid var(--border-default);
    padding: 12px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    z-index: 999;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
  }
  .sticky-summary {
    font-size: 12.5px;
    color: var(--text-muted);
  }
  .sticky-summary strong {
    font-size: 14px;
    color: var(--text-primary);
    display: block;
  }
  .btn-sticky-submit {
    flex: 1;
    max-width: 240px;
    background: var(--success);
    color: #ffffff;
    font-size: 14px;
    font-weight: 800;
    border: none;
    border-radius: 10px;
    padding: 12px 16px;
    cursor: pointer;
    text-align: center;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
  }
}

/* In kế hoạch cân trong ngày (bảng Tổ trưởng + thẻ giao việc công nhân) — luôn nền trắng chữ đen để in và xem giống nhau. */
.kh-ngay-area { background:#fff; color:#000; border:1px solid #cbd5e1; border-radius:8px; padding:16px; margin-top:12px; font-size:12px; }
.kh-ngay-area * { color:#000; }
.kh-ngay-trang { page-break-after: always; }
.kh-ngay-trang:last-child { page-break-after: auto; }
.kh-ngay-tieude { text-align:center; font-size:18px; margin:0; }
.kh-ngay-phu { text-align:center; margin:2px 0 10px; font-size:12px; }
.kh-ngay-meta { display:flex; justify-content:space-between; gap:12px; margin-bottom:6px; font-weight:600; }
.kh-ngay-bang { width:100%; border-collapse:collapse; font-size:12px; }
.kh-ngay-bang th, .kh-ngay-bang td { border:1px solid #000; padding:4px 6px; text-align:left; background:#fff; }
.kh-ngay-bang th { background:#e9edf5; font-size:11px; text-transform:uppercase; }
.kh-ngay-bang td.c { text-align:center; } .kh-ngay-bang td.n { text-align:right; font-variant-numeric:tabular-nums; }
.kh-ngay-o { display:inline-block; width:14px; height:14px; border:1.5px solid #000; vertical-align:middle; }
.kh-ngay-ky { display:flex; gap:16px; margin-top:28px; }
.kh-ngay-ky div { flex:1; border-top:1px solid #000; padding-top:3px; text-align:center; font-size:11px; }
.kh-ngay-chan { display:flex; justify-content:space-between; gap:12px; margin-top:10px; font-size:10px; }
.kh-ngay-trang-the { display:grid; grid-template-columns:1fr 1fr; gap:10mm; align-items:start; }
.kh-ngay-the { border:1px dashed #555; padding:8px 10px; page-break-inside:avoid; break-inside:avoid; }
.kh-ngay-the:nth-child(2n) { page-break-after:always; }
.kh-ngay-the-dau { display:flex; gap:10px; align-items:flex-start; margin-bottom:8px; }
.kh-ngay-the-dau .kh-ngay-bang { flex:1; }
.kh-ngay-qr { text-align:center; font-size:10px; }
.kh-ngay-qr img { width:90px; height:90px; display:block; margin:0 auto 2px; }

/* Nhãn đầu ra Trạm Chuẩn bị in lại: tem nhiệt 60x40 mm (6cm × 4cm / 24 cm²). Dùng trang có tên để chỉ trang này in khổ tem, các trang khác vẫn A4 ngang. */
@page nhan60x40mm { size: 60mm 40mm; margin: 0; }
.nhan-dau-ra-in { page: nhan60x40mm; background:#fff; color:#000; margin:0; padding:0; width:60mm; height:40mm; max-height:40mm; overflow:hidden; }
.nhan-dau-ra-in * { color:#000; box-sizing:border-box; }
.ndr-nhan { width:60mm; height:39.5mm; max-height:40mm; box-sizing:border-box; padding:2mm 2.5mm; display:flex; gap:2mm; background:#fff; border:1px solid #888; font-family:Arial,sans-serif; overflow:hidden; page-break-inside:avoid; break-inside:avoid; page-break-after:avoid; break-after:avoid; }
.ndr-trai { width:34mm; display:flex; flex-direction:column; justify-content:space-between; }
.ndr-ten { font-weight:800; font-size:8.5pt; line-height:10pt; word-break:break-word; }
.ndr-ma { font-size:6.5pt; line-height:8pt; }
.ndr-ma-pl { font-size:9.75pt; line-height:11pt; font-weight:800; color:#000; margin:0.3mm 0; }
.ndr-kl { font-weight:900; font-size:15pt; line-height:16pt; margin:1mm 0; }
.ndr-phai { flex:1; display:flex; flex-direction:column; align-items:center; justify-content:space-between; }
.ndr-phai img { width:22mm; height:22mm; }
.ndr-tram { font-weight:800; font-size:5.5pt; text-align:center; }
.ndr-inlai { background:#000; color:#fff !important; font-weight:900; font-size:6.5pt; padding:1px 3px; border-radius:2px; }
@media print {
  .nhan-dau-ra-in { margin:0 !important; padding:0 !important; width:60mm !important; height:40mm !important; max-height:40mm !important; overflow:hidden !important; page-break-after:avoid !important; break-after:avoid !important; }
  .nhan-dau-ra-in .ndr-nhan { border:none !important; height:39.5mm !important; max-height:40mm !important; page-break-after:avoid !important; break-after:avoid !important; }
  .nhan-dau-ra-in .ndr-inlai { color:#fff !important; -webkit-print-color-adjust:exact; print-color-adjust:exact; }
}