/* ==========================================================================
   PPG COLOR MANAGER - NEXT-GEN AUTOMOTIVE HIGH-TECH DESIGN SYSTEM (V83)
   Design Language: Automotive Precision & Bodyshop Ergonomics
   Standards: WCAG 2.1 AAA / 60-30-10 Rule / Touch Ergonomics 44px+
   ========================================================================== */

:root {
  /* 60% DOMINANT SURFACE (Nền Slate Tinh Tế) */
  --surface-ground: #F8FAFC;
  --surface-ground-rgb: 248, 250, 252;
  
  /* 30% SECONDARY STRUCTURE (Thẻ Kính Mờ & Đường Khung) */
  --surface-card: #FFFFFF;
  --surface-card-subtle: rgba(255, 255, 255, 0.92);
  --surface-border: #E2E8F0;
  --surface-border-subtle: rgba(226, 232, 240, 0.85);
  --surface-hover: #F1F5F9;
  --text-primary: #0F172A;     /* Contrast 15.8:1 trên nền trắng */
  --text-secondary: #334155;   /* Contrast 8.2:1 trên nền trắng */
  --text-muted: #64748B;       /* Contrast 4.68:1 trên nền trắng */
  
  /* 10% AUTOMOTIVE ACCENT COLORS (Màu Kỹ Thuật Ô Tô Chuẩn) */
  --accent-ppg-blue: #0284C7;
  --accent-ppg-blue-dark: #0369A1;
  --accent-ppg-cyan: #06B6D4;
  
  --paint-solid: #10B981;      /* Xanh ngọc Solid */
  --paint-solid-bg: #ECFDF5;
  --paint-metallic: #F59E0B;   /* Hổ phách Metallic */
  --paint-metallic-bg: #FFFBEB;
  --paint-pearl: #8B5CF6;      /* Tím phong lan Camay */
  --paint-pearl-bg: #F5F3FF;
  
  --solvent-blue: #2563EB;     /* Gốc dầu Nexa P */
  --water-cyan: #0891B2;       /* Gốc nước EHP T */
  
  /* CÔNG THÁI HỌC VÙNG CHẠM CẢM ỨNG XƯỞNG SƠN */
  --touch-target-min: 44px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  
  /* PHÔNG CHỮ */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
}

/* ÁP DỤNG CƠ BẢN TOÀN CỤC & CHỐNG TRÀN LỀ VIEWPORT */
html, body {
  font-family: var(--font-sans);
  background-color: var(--surface-ground);
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
  overflow-x: hidden !important;
  max-width: 100vw !important;
  width: 100% !important;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

*, *::before, *::after {
  box-sizing: border-box;
}

/* HIỆU ỨNG THẺ KÍNH MỜ GLASSMORPHISM ĐẲNG CẤP */
.glass-panel {
  background: var(--surface-card-subtle);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--surface-border-subtle);
  box-shadow: 0 4px 20px -2px rgba(15, 23, 42, 0.05), 0 2px 6px -1px rgba(15, 23, 42, 0.02);
}

/* NÂNG CẤP THANH HEADER CHÍNH */
header.bg-blue-600 {
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 50%, #0369a1 100%) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12) !important;
  box-shadow: 0 4px 20px -2px rgba(15, 23, 42, 0.25) !important;
}

#appHeaderTitle {
  font-weight: 800 !important;
  letter-spacing: -0.02em;
  background: linear-gradient(to right, #ffffff, #bae6fd);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* NÂNG CẤP THANH TABS NAVIGATION */
#navTabs {
  padding: 6px 4px !important;
  gap: 6px !important;
}

.tab-btn {
  border-radius: var(--radius-md) !important;
  border-bottom: none !important;
  padding: 8px 14px !important;
  font-size: 13px !important;
  font-weight: 600 !important;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

.tab-btn:hover {
  background-color: var(--surface-hover) !important;
  color: #0f172a !important;
}

.tab-btn.active {
  background: linear-gradient(135deg, #2563eb, #0284c7) !important;
  color: #ffffff !important;
  box-shadow: 0 4px 12px -2px rgba(37, 99, 235, 0.35) !important;
}

.tab-btn.active i {
  color: #ffffff !important;
}

/* NÂNG CẤP KHUNG BỘ LỌC THỐNG KÊ (FILTER BAR) */
#dashboardTab .animate__fadeInDown {
  background: #ffffff !important;
  border: 1px solid var(--surface-border) !important;
  border-radius: var(--radius-xl) !important;
  box-shadow: 0 4px 20px -2px rgba(15, 23, 42, 0.04) !important;
  padding: 16px 20px !important;
}

#dashboardTab select {
  height: 40px !important;
  border-radius: var(--radius-md) !important;
  border: 1px solid #cbd5e1 !important;
  background-color: #f8fafc !important;
  font-size: 13px !important;
  font-weight: 500 !important;
  color: #1e293b !important;
  transition: border-color 0.15s, box-shadow 0.15s !important;
}

#dashboardTab select:focus {
  border-color: #0284c7 !important;
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15) !important;
  outline: none !important;
}

/* NÂNG CẤP 8 THẺ THỐNG KÊ METRIC CARDS (AUTOMOTIVE STYLE) */
/* 1. Thẻ Tổng công thức */
.stat-card.bg-gradient-to-br.from-blue-500.to-blue-700 {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 60%, #0284c7 100%) !important;
  border-radius: var(--radius-xl) !important;
  box-shadow: 0 8px 25px -4px rgba(37, 99, 235, 0.35) !important;
  position: relative;
  overflow: hidden;
}

#totalFormulas {
  font-family: var(--font-mono) !important;
  font-weight: 800 !important;
  font-size: 2.25rem !important;
  letter-spacing: -0.03em !important;
}

/* 2. Thẻ Solid */
.stat-card.bg-gradient-to-br.from-green-500.to-green-700 {
  background: #ffffff !important;
  border: 1px solid #a7f3d0 !important;
  border-radius: var(--radius-xl) !important;
  box-shadow: 0 4px 18px -2px rgba(16, 185, 129, 0.12) !important;
}
.stat-card.bg-gradient-to-br.from-green-500.to-green-700 p.text-green-100 {
  color: #065f46 !important;
  font-weight: 700 !important;
  text-transform: uppercase;
  font-size: 11px !important;
  letter-spacing: 0.05em;
}
#solidCount {
  color: #059669 !important;
  font-family: var(--font-mono) !important;
  font-weight: 800 !important;
}

/* 3. Thẻ Metallic */
.stat-card.bg-gradient-to-br.from-yellow-500.to-orange-600 {
  background: #ffffff !important;
  border: 1px solid #fde68a !important;
  border-radius: var(--radius-xl) !important;
  box-shadow: 0 4px 18px -2px rgba(245, 158, 11, 0.12) !important;
}
.stat-card.bg-gradient-to-br.from-yellow-500.to-orange-600 p.text-yellow-100 {
  color: #92400e !important;
  font-weight: 700 !important;
  text-transform: uppercase;
  font-size: 11px !important;
  letter-spacing: 0.05em;
}
#metallicCount {
  color: #d97706 !important;
  font-family: var(--font-mono) !important;
  font-weight: 800 !important;
}

/* 4. Thẻ Camay / Pearl */
.stat-card.bg-gradient-to-br.from-purple-500.to-pink-600 {
  background: #ffffff !important;
  border: 1px solid #ddd6fe !important;
  border-radius: var(--radius-xl) !important;
  box-shadow: 0 4px 18px -2px rgba(139, 92, 246, 0.12) !important;
}
.stat-card.bg-gradient-to-br.from-purple-500.to-pink-600 p.text-purple-100 {
  color: #5b21b6 !important;
  font-weight: 700 !important;
  text-transform: uppercase;
  font-size: 11px !important;
  letter-spacing: 0.05em;
}
#pearlCount {
  color: #7c3aed !important;
  font-family: var(--font-mono) !important;
  font-weight: 800 !important;
}

/* SỬA TRIỆT ĐỂ LỖI ICON TRẮNG TRÊN NỀN TRẮNG (F15 - WCAG 2.1 AAA) */
.stat-card.bg-gradient-to-br.from-green-500.to-teal-600 .rounded-full {
  background-color: #ecfdf5 !important;
}
.stat-card.bg-gradient-to-br.from-green-500.to-teal-600 i {
  color: #059669 !important;
}

.stat-card.bg-gradient-to-br.from-yellow-500.to-orange-600 .rounded-full {
  background-color: #fffbeb !important;
}
.stat-card.bg-gradient-to-br.from-yellow-500.to-orange-600 i {
  color: #d97706 !important;
}

.stat-card.bg-gradient-to-br.from-purple-500.to-pink-600 .rounded-full {
  background-color: #f5f3ff !important;
}
.stat-card.bg-gradient-to-br.from-purple-500.to-pink-600 i {
  color: #7c3aed !important;
}

/* 5, 6, 7, 8. Các thẻ thống kê phụ */
.stat-card.bg-white {
  border-radius: var(--radius-lg) !important;
  border: 1px solid var(--surface-border) !important;
  box-shadow: 0 3px 12px -1px rgba(15, 23, 42, 0.04) !important;
  transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card.bg-white:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px -2px rgba(15, 23, 42, 0.08) !important;
}

#gocDauCount, #gocNuocCount, #thisWeekCount, #thisMonthCount {
  font-family: var(--font-mono) !important;
  font-weight: 700 !important;
}

/* NÂNG CẤP KHUNG CHỨA BIỂU ĐỒ (CHARTS CONTAINER) */
.chart-container {
  border-radius: var(--radius-xl) !important;
  border: 1px solid var(--surface-border) !important;
  box-shadow: 0 4px 20px -2px rgba(15, 23, 42, 0.05) !important;
  background: #ffffff !important;
  padding: 20px !important;
}

.chart-container h3 {
  font-weight: 700 !important;
  font-size: 15px !important;
  color: #0f172a !important;
}

/* NÂNG CẤP MODAL XEM CÔNG THỨC CHI TIẾT (MIXING RECIPE MODAL) */
.modal-responsive-container,
#formulaModalContent,
.modal-content {
  width: 100%;
  max-width: 800px !important; /* Rule IV.5 */
  max-height: 92vh !important;
  border-radius: var(--radius-xl) !important;
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
  box-shadow: 0 25px 60px -15px rgba(15, 23, 42, 0.35) !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
}

/* FONT SỐ KỸ THUẬT CHO CÂN VÀ TỈ LỆ GRAM */
.font-numeric,
.tinter-weight,
.tinter-new-weight,
.tinter-cumulative,
#scalingWeight {
  font-family: var(--font-mono) !important;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* NÚT THAO TÁC CẢM ỨNG CHUẨN 44PX+ */
.touch-target {
  min-height: var(--touch-target-min);
  min-width: var(--touch-target-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ==========================================================================
   TỐI ƯU CÔNG THÁI HỌC TRÊN MOBILE (< 768px)
   ========================================================================== */
@media (max-width: 767px) {
  /* Ẩn widget lời chào dài dòng */
  #headerGreetingWidget {
    display: none !important;
  }

  /* Giảm khoảng đệm viền màn hình để mở rộng tối đa không gian xem số liệu */
  .container {
    padding-left: 8px !important;
    padding-right: 8px !important;
    max-width: 100vw !important;
  }

  /* Grid 8 thẻ chuyển sang 2 cột cân đối */
  #dashboardTab .grid-cols-4,
  #dashboardTab .grid-cols-5 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }

  /* Thẻ Tổng công thức chiếm full 2 cột */
  .stat-card.bg-gradient-to-br.from-blue-500.to-blue-700 {
    grid-column: span 2 / span 2 !important;
  }

  /* Modal vừa vặn màn hình điện thoại */
  .modal {
    padding: 6px !important;
  }
  
  #formulaModalContent,
  .modal-content {
    width: calc(100vw - 12px) !important;
    max-width: calc(100vw - 12px) !important;
    margin: 0 auto !important;
    padding: 12px !important;
    max-height: 96vh !important;
    border-radius: var(--radius-lg) !important;
  }
}


/* ========================================================
   CHART RESPONSIVE CONTAINER & WORKSHOP VISUAL BALANCE
   ======================================================== */
.chart-responsive-box {
  position: relative !important;
  width: 100% !important;
  height: 380px !important;
  min-height: 360px !important;
}

@media (min-width: 1024px) {
  .chart-responsive-box {
    height: 400px !important;
    min-height: 380px !important;
  }
}

/* ========================================================
   BOTTOM ACTION DOCK (CHO ĐIỆN THOẠI & TABLET)
   ======================================================== */



/* ========================================================
   BOTTOM ACTION DOCK (CHỈ CHO MOBILE / ĐIỆN THOẠI < 768px)
   TUYỆT ĐỐI ẨN TRÊN LAPTOP / PC / DESKTOP (>= 768px)
   ======================================================== */
#mobileBottomNav {
  display: none !important;
}

@media (max-width: 767px) {
  #mainScreen {
    padding-bottom: 72px !important;
  }
  #mobileBottomNav {
    display: flex !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    z-index: 40 !important;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08) !important;
  }
}

/* ========================================================
   MODAL SCROLL LOCK & MOBILE TOUCH ERGONOMICS (KHẮC PHỤC TRIỆT ĐỂ VUỐT CÔNG THỨC)
   ======================================================== */
body.modal-open {
  overflow: hidden !important;
  height: 100vh !important;
  touch-action: none !important;
}

.modal {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  height: 100% !important;
  z-index: 9999 !important;
  background-color: rgba(15, 23, 42, 0.75) !important;
  backdrop-filter: blur(4px) !important;
  -webkit-backdrop-filter: blur(4px) !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch !important;
  overscroll-behavior: contain !important;
  touch-action: pan-y !important;
  padding: 16px 8px !important;
}

.modal.active {
  display: block !important;
}

.modal-content,
#formulaModalContent {
  position: relative !important;
  margin: 16px auto !important;
  width: 100% !important;
  max-width: 800px !important;
  background-color: #ffffff !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3) !important;
  overflow: visible !important;
  max-height: none !important;
  touch-action: pan-y !important;
}

@media (max-width: 767px) {
  .modal {
    padding: 8px 4px !important;
  }
  .modal-content,
  #formulaModalContent {
    margin: 8px auto !important;
    width: calc(100vw - 12px) !important;
    max-width: calc(100vw - 12px) !important;
    padding: 10px !important;
  }
}

.mobile-nav-btn {
  background: none !important;
  border: none !important;
  outline: none !important;
  cursor: pointer !important;
  padding: 4px 8px !important;
  -webkit-tap-highlight-color: transparent !important;
}

.mobile-nav-btn:active {
  transform: scale(0.95) !important;
}


/* ========================================================
   BOTTOM ACTION DOCK (MOBILE APP BAR CHUẨN XƯỞNG SƠN)
   TUYỆT ĐỐI ẨN TRÊN LAPTOP / PC (>= 768px)
   DÀN ĐỀU 5 NÚT 100% CHIỀU NGANG TRÊN MOBILE (< 768px)
   ======================================================== */
#mobileBottomNav {
  display: none !important;
}

@media (max-width: 767px) {
  #mainScreen {
    padding-bottom: 76px !important;
  }

  #mobileBottomNav {
    display: flex !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 64px !important;
    max-height: 64px !important;
    z-index: 50 !important;
    background: rgba(255, 255, 255, 0.98) !important;
    backdrop-filter: blur(16px) !important;
    -webkit-backdrop-filter: blur(16px) !important;
    border-top: 1px solid #e2e8f0 !important;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08) !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 0 4px !important;
    margin: 0 !important;
    box-sizing: border-box !important;
  }

  /* 4 nút danh mục chiếm đều tỷ lệ chiều ngang, không bị dính cục */
  .mobile-nav-btn {
    flex: 1 1 0 !important;
    height: 100% !important;
    min-width: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 3px !important;
    padding: 6px 2px !important;
    background: transparent !important;
    border: none !important;
    outline: none !important;
    cursor: pointer !important;
    -webkit-tap-highlight-color: transparent !important;
  }

  .mobile-nav-btn i {
    font-size: 19px !important;
    line-height: 1 !important;
    transition: transform 0.15s ease, color 0.15s ease !important;
  }

  .mobile-nav-btn span {
    font-size: 11px !important;
    font-weight: 700 !important;
    line-height: 1.1 !important;
    letter-spacing: -0.01em !important;
    white-space: nowrap !important;
  }

  .mobile-nav-btn:active {
    transform: scale(0.92) !important;
  }

  /* Nút trung tâm tạo nổi bật hình tròn dạng Floating Action Button */
  .mobile-nav-center-wrap {
    flex: 0 0 54px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    height: 100% !important;
  }

  .mobile-nav-center-btn {
    width: 46px !important;
    height: 46px !important;
    margin-top: -18px !important;
    border-radius: 50% !important;
    background: linear-gradient(135deg, #0284c7 0%, #06b6d4 100%) !important;
    color: #ffffff !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: 0 8px 16px -2px rgba(2, 132, 199, 0.45), 0 4px 6px -4px rgba(2, 132, 199, 0.3) !important;
    border: 3px solid #ffffff !important;
    cursor: pointer !important;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
    -webkit-tap-highlight-color: transparent !important;
  }

  .mobile-nav-center-btn:active {
    transform: scale(0.9) !important;
  }

  .mobile-nav-center-btn i {
    font-size: 18px !important;
  }

  /* Nút tìm kiếm biển số và nút lên đầu trang dịch lên trên để không che khuất chân trang (F14) */
  #scanLicensePlateBtn {
    bottom: 78px !important;
    right: 14px !important;
    z-index: 45 !important;
  }

  #backToTopBtn {
    bottom: 82px !important;
    right: 14px !important;
    z-index: 45 !important;
  }
}

.mobile-nav-btn i,
.mobile-nav-btn span {
  pointer-events: none !important;
}

/* ẨN CHÂN TRANG KHI ĐANG Ở MÀN HÌNH ĐĂNG NHẬP (F14) */
#mainScreen.hidden ~ #mobileBottomNav,
body:has(#mainScreen.hidden) #mobileBottomNav,
#loginScreen:not(.hidden) ~ #mobileBottomNav {
  display: none !important;
}

/* ÉP QUY TẮC CHIỀU RỘNG TỐI ĐA CHO TOÀN BỘ MODAL (RULE IV.5 & F13) */
.modal-content,
#formulaModalContent,
#formulaModal .modal-content {
  max-width: 800px !important;
  margin-left: auto !important;
  margin-right: auto !important;
}
