/* ============================================================
   MOBILE RESPONSIVE — Chống Thấm Uy Việt
   v3.0 — Fixed Sidebar Click, Bottom Nav, Sub-sections
   ============================================================ */

/* ===== UTILITY ===== */
.desktop-only { display: flex !important; }
.mobile-only  { display: none !important; }

/* ===== BOTTOM NAV ===== */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 200;
  height: 62px;
  background: rgba(8,8,20,0.97);
  backdrop-filter: blur(24px) saturate(1.6);
  -webkit-backdrop-filter: blur(24px) saturate(1.6);
  border-top: 1px solid rgba(255,255,255,0.08);
  padding: 0;
  align-items: stretch;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.5);
  /* Scroll ngang nếu không đủ chỗ */
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.mobile-bottom-nav::-webkit-scrollbar { display: none; }

.mobile-nav-item {
  flex: 0 0 auto;
  min-width: 64px;
  width: calc(100% / 5);  /* 5 items equally */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 4px 8px;
  color: rgba(255,255,255,0.38);
  font-size: 0.5rem;
  font-weight: 600;
  letter-spacing: 0.2px;
  cursor: pointer;
  border: none;
  background: transparent;
  transition: all 0.22s ease;
  text-transform: uppercase;
  position: relative;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.mobile-nav-item i {
  font-size: 1.1rem;
  display: block;
  transition: transform 0.22s, filter 0.22s;
  line-height: 1;
}
.mobile-nav-item span {
  font-size: 0.48rem;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.mobile-nav-item.active { color: #3b82f6; }
.mobile-nav-item.active::before {
  content: '';
  position: absolute;
  top: 0; left: 20%; right: 20%;
  height: 2.5px;
  background: linear-gradient(90deg, #3b82f6, #8b5cf6);
  border-radius: 0 0 4px 4px;
}
.mobile-nav-item.active i {
  transform: translateY(-2px) scale(1.15);
  filter: drop-shadow(0 0 6px rgba(59,130,246,0.75));
}
[data-theme="dark"] .mobile-nav-item.active { color: #00f0ff; }
[data-theme="dark"] .mobile-nav-item.active::before {
  background: linear-gradient(90deg, #00f0ff, #0affdb);
}
[data-theme="dark"] .mobile-nav-item.active i {
  filter: drop-shadow(0 0 6px rgba(0,240,255,0.75));
}

/* ===== HEADER MOBILE STYLES ===== */
.header-mobile-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}
.mobile-user-avatar i { font-size: 1.2rem; color: var(--accent-blue); }

/* Mobile Quick Menu */
.mobile-quick-menu {
  position: fixed;
  top: 58px; right: 8px;
  z-index: 9001;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 14px;
  padding: 8px;
  flex-direction: column;
  gap: 2px;
  min-width: 175px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.4);
  transform: scale(0.9) translateY(-10px);
  opacity: 0;
  transition: all 0.2s cubic-bezier(0.23,1,0.32,1);
  pointer-events: none;
}
.mobile-quick-menu.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}
.mqm-overlay {
  position: fixed; inset: 0; z-index: 9000;
  background: rgba(0,0,0,0.25);
}
.mqm-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 13px; border-radius: 10px;
  font-size: 0.84rem; font-weight: 500;
  color: var(--text-primary); cursor: pointer;
  transition: background 0.15s;
}
.mqm-item:hover { background: var(--bg-hover); }
.mqm-item i { width: 16px; text-align: center; color: var(--text-secondary); font-size: 0.85rem; }
.mqm-item.danger { color: var(--accent-red); }
.mqm-item.danger i { color: var(--accent-red); }
[data-theme="dark"] .mobile-quick-menu { background: rgba(10,22,40,0.98); border-color: rgba(0,240,255,0.12); }
[data-theme="dark"] .mqm-item { color: #c8e6ff; }
[data-theme="dark"] .mqm-item:hover { background: rgba(0,240,255,0.06); }
[data-theme="dark"] .mqm-item i { color: rgba(0,240,255,0.45); }

/* ===== MOBILE SCROLL-TO-TOP ===== */
.mobile-scroll-top {
  position: fixed; bottom: 74px; right: 14px; z-index: 480;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent-blue); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem;
  box-shadow: 0 4px 14px rgba(59,130,246,0.4);
  cursor: pointer; border: none;
  opacity: 0; transform: translateY(10px) scale(0.8);
  transition: all 0.3s cubic-bezier(0.23,1,0.32,1);
  pointer-events: none;
}
.mobile-scroll-top.visible {
  opacity: 1; transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ===== PWA BANNER ===== */
.pwa-install-prompt {
  position: fixed; bottom: 70px; left: 12px; right: 12px;
  z-index: 490;
  background: rgba(17,24,39,0.95);
  border: 1px solid rgba(59,130,246,0.2);
  border-radius: 16px; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  backdrop-filter: blur(20px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  animation: slideUpPrompt 0.4s cubic-bezier(0.23,1,0.32,1);
}
@keyframes slideUpPrompt {
  from { opacity:0; transform:translateY(20px); }
  to   { opacity:1; transform:translateY(0); }
}
.pwa-install-content { display:flex; align-items:center; gap:10px; }
.pwa-install-title { font-size:0.82rem; font-weight:700; color:#f1f5f9; }
.pwa-install-sub { font-size:0.68rem; color:rgba(255,255,255,0.45); margin-top:1px; }
.offline-banner {
  position:fixed; top:58px; left:0; right:0; z-index:9999;
  background:linear-gradient(135deg,#f59e0b,#d97706);
  color:#fff; padding:8px 16px;
  display:flex; align-items:center; justify-content:center;
  gap:8px; font-size:0.8rem; font-weight:600;
}

/* ===== MOBILE DATA CARDS ===== */
.dt-desktop { display: block; }
.dt-mobile  { display: none; }

/* Mobile card list — enhanced */
.mobile-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 16px;
  padding: 15px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
  overflow: hidden;
  position: relative;
}
.mobile-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent-blue);
  border-radius: 3px 0 0 3px;
  opacity: 0;
  transition: opacity 0.2s;
}
.mobile-card:active { transform: scale(0.985); }
.mobile-card:hover {
  border-color: var(--accent-blue);
  box-shadow: 0 4px 20px rgba(59,130,246,0.12);
}
.mobile-card:hover::before { opacity: 1; }

.mc-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.mc-primary { flex: 1; font-size: 0.9rem; min-width: 0; }
.mc-status { flex-shrink: 0; }

.mc-body {
  border-top: 1px solid var(--border-primary);
  padding-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}
.mc-info-row { display: flex; flex-direction: column; gap: 2px; }
.mc-info-label {
  font-size: 0.63rem;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.mc-info-val { font-size: 0.83rem; color: var(--text-secondary); }

.mc-actions {
  display: flex;
  gap: 8px;
  border-top: 1px solid var(--border-primary);
  padding-top: 10px;
  margin-top: 10px;
}
.mc-actions .btn {
  flex: 1;
  min-width: 0;
  justify-content: center;
  font-size: 0.76rem;
  padding: 8px 10px;
}

/* Dark theme card */
[data-theme="dark"] .mobile-card {
  background: rgba(10,22,40,0.6);
  border-color: rgba(0,240,255,0.08);
}
[data-theme="dark"] .mobile-card:hover {
  border-color: rgba(0,240,255,0.35);
  box-shadow: 0 4px 24px rgba(0,240,255,0.08);
}
[data-theme="dark"] .mobile-card::before { background: #00f0ff; }
[data-theme="dark"] .mc-body { border-color: rgba(0,240,255,0.06); }
[data-theme="dark"] .mc-actions { border-color: rgba(0,240,255,0.06); }

/* ===== SIDEBAR MOBILE ===== */
/* Đảm bảo sidebar overlay có z-index cao, sidebar items clickable */
#sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 399 !important;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(2px);
  cursor: pointer;
}

/* ===== GLOBAL MOBILE (@media 768) ===== */
@media (max-width: 768px) {
  /* Utility */
  .desktop-only { display: none !important; }
  .mobile-only  { display: flex !important; }
  .mobile-hidden { display: none !important; }
  .mobile-full  { width: 100% !important; }
  .mobile-stack { flex-direction: column !important; }
  
  /* Touch targets min 44px */
  .btn, .header-btn, .tab-btn, .mobile-nav-item { min-height: 44px; }

  /* iOS zoom fix */
  input, select, textarea,
  .form-input, .form-select, .form-textarea,
  .nl-input, .nl-select, .nl-textarea { font-size: 16px !important; }

  /* ---------- SHOW BOTTOM NAV ---------- */
  .mobile-bottom-nav { display: flex; }

  /* ---------- APP LAYOUT ---------- */
  /* 🔑 FIX: Sidebar z-index cao hơn header để overlay không block click */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.23,1,0.32,1);
    z-index: 400 !important;   /* TĂNG từ 100 lên 400 */
    top: 0; bottom: 0; left: 0; width: 280px !important;
    position: fixed;
    overflow-y: auto;
    overflow-x: hidden;
    /* Đảm bảo tất cả items clickable */
    pointer-events: auto;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 6px 0 40px rgba(0,0,0,0.6);
    pointer-events: auto;
  }
  /* Sidebar nav items đảm bảo clickable */
  .sidebar .sidebar-item,
  .sidebar .sidebar-item * {
    pointer-events: auto;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
  /* Sidebar nav dễ scroll */
  .sidebar-nav {
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    max-height: calc(100vh - 140px);
  }

  .main-area { margin-left: 0 !important; width: 100%; }

  /* 🔑 FIX: Header z-index thấp hơn sidebar */
  .header {
    left: 0 !important;
    height: 56px;
    padding: 0 12px;
    z-index: 300;   /* THẤP hơn sidebar 400 */
  }
  .page-content {
    padding: 14px 12px 86px;
    padding-top: calc(56px + 14px);
    overflow-x: hidden;
    max-width: 100vw;
  }

  /* ---------- HEADER — FORCE HIDE SEARCH BAR ---------- */
  .header-search,
  .header-search.desktop-only,
  div.header-search { display: none !important; }
  .header-left { gap: 8px; min-width: 0; flex: 1; }
  .header-right { gap: 4px; flex-shrink: 0; }
  .header-btn { width: 40px; height: 40px; padding: 0; flex-shrink: 0; }
  /* Mobile title grows to fill space */
  .header-mobile-title { flex: 1; }
  
  /* ---------- PAGE HEADER ---------- */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 14px;
  }
  .page-header > div:first-child { min-width: 0; }
  .page-header h1 { font-size: 1.15rem; }
  .page-header p, .page-header-subtitle { font-size: 0.78rem; }
  .page-header-actions {
    width: 100%;
    display: flex;
    gap: 8px;
    align-items: center;
  }
  /* View toggle 50% + primary button 50% */
  .view-toggle { flex: 1; display: flex; gap: 4px; }
  .view-toggle-btn {
    flex: 1;
    padding: 0 8px;
    min-width: 0;
    min-height: 40px;
    justify-content: center;
  }
  .view-toggle-btn span { display: none; }
  .view-toggle-btn i { font-size: 0.95rem; margin: 0; }
  .page-header-actions > .btn:not(.view-toggle-btn) {
    flex-shrink: 0;
    font-size: 0.8rem;
    padding: 0 14px;
    min-height: 40px;
  }

  /* ---------- KPI GRID ---------- */
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
  .kpi-card { padding: 14px 12px; border-radius: 12px; }
  .kpi-card-value { font-size: 1.35rem; }
  .kpi-card-label { font-size: 0.7rem; }
  .kpi-card-icon { width: 34px; height: 34px; font-size: 0.85rem; }
  .kpi-card-sparkline, .kpi-card-trend { display: none; }

  /* ---------- SWITCH TABLE → CARD ON MOBILE ---------- */
  .dt-desktop { display: none !important; }
  .dt-mobile  { display: block !important; }
  .data-table-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 0;
  }
  .data-table-header h3 { font-size: 0.95rem; }
  .data-table-actions { width: 100%; }
  .data-table-search { flex: 1; min-width: unset; }
  .data-table-search input { font-size: 16px !important; }
  .data-table-footer { padding: 8px 0; font-size: 0.75rem; }

  /* ---------- DASHBOARD CC — COMPACT ---------- */
  .cc-dashboard {
    grid-template-columns: 1fr !important;
    gap: 10px; padding: 10px; min-height: auto;
  }
  .cc-status-bar {
    overflow-x: auto; overflow-y: hidden; flex-wrap: nowrap;
    gap: 12px; padding: 8px 12px; font-size: 0.62rem;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .cc-status-bar::-webkit-scrollbar { display: none; }
  .cc-status-item, .cc-status-divider { flex-shrink: 0; }
  .cc-clock { font-size: 0.7rem; }
  .cc-gauge-grid { grid-template-columns: 1fr 1fr !important; gap: 8px; }
  .cc-gauge-card { padding: 12px 8px; }
  .cc-gauge-svg { width: 80px; height: 80px; }
  .cc-gauge-value { font-size: 1.05rem; }
  .cc-gauge-label { font-size: 0.54rem; }
  .cc-radar-container { max-width: 160px; margin: 0 auto; }
  .cc-terminal { max-height: 160px; font-size: 0.62rem; padding: 8px; }
  .cc-panel-header { padding: 9px 12px 8px; }
  .cc-panel-title { font-size: 0.62rem; }
  .cc-panel-body { padding: 10px; }
  .cc-threat-level { font-size: 1.3rem; }
  .cc-revenue-container { flex-direction: column; }
  .cc-revenue-stats { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px; }
  .cc-revenue-stat { flex: 1; min-width: 65px; text-align: center; }
  .cc-revenue-stat-value { font-size: 0.95rem; }
  .cc-ai-card { padding: 10px; margin-bottom: 8px; }
  .cc-ai-title { font-size: 0.74rem; }
  .cc-ai-desc { font-size: 0.67rem; }
  .cc-anomaly-item { padding: 8px 10px; }
  .cc-anomaly-title { font-size: 0.75rem; }
  .cc-anomaly-desc { font-size: 0.66rem; }

  /* ---------- AI CHATBOT — ABOVE BOTTOM NAV ---------- */
  .chatbot-fab {
    bottom: 78px !important;
    right: 14px !important;
    width: 48px !important;
    height: 48px !important;
    font-size: 1.05rem !important;
    z-index: 450 !important;
  }
  .chatbot-fab.panel-open {
    opacity: 0 !important;
    pointer-events: none !important;
  }
  .chatbot-panel {
    width: calc(100vw - 20px) !important;
    max-width: 390px !important;
    right: 10px !important;
    left: 10px !important;
    bottom: 136px !important;
    max-height: calc(100vh - 210px) !important;
    border-radius: 20px !important;
    z-index: 449 !important;
  }
  .chatbot-messages { max-height: 42vh; }
  .chatbot-suggestions { flex-wrap: wrap; gap: 6px; }
  .chatbot-suggestions button { padding: 6px 10px; font-size: 0.72rem; }

  /* ---------- TOAST NOTIFICATIONS ---------- */
  .toast-container {
    right: 10px; left: 10px;
    bottom: 74px;
    z-index: 600;
  }
  .toast { min-width: unset; width: 100%; }

  /* ---------- NOTIFICATION DROPDOWN ---------- */
  .notification-dropdown {
    width: calc(100vw - 20px);
    right: -40px;
    max-height: 65vh;
  }

  /* ---------- MODAL (bottom sheet) ---------- */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%; width: 100%;
    border-radius: 20px 20px 0 0;
    max-height: 92vh;
    overflow-y: auto;
    overflow-x: hidden;
  }
  .modal::before {
    content: '';
    display: block;
    width: 40px; height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
    margin: 12px auto -4px;
    flex-shrink: 0;
  }
  .modal-header { padding: 14px 18px 12px; }
  .modal-header h2 { font-size: 1rem; }
  .modal-body { padding: 14px 18px; overflow-x: hidden; }
  .modal-footer { padding: 12px 18px; gap: 8px; }
  .modal .grid-2 { grid-template-columns: 1fr; gap: 0; }
  .modal-footer .btn { flex: 1; justify-content: center; }

  /* Tables inside modal: scroll horizontally */
  .modal-body table,
  .modal-body .data-table { 
    display: block; width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    font-size: 0.78rem;
  }
  .modal-body table::-webkit-scrollbar { display: none; }
  .modal-body table th, .modal-body table td { white-space: nowrap; padding: 7px 8px; }

  /* Plan comparison: 3-col → 1-col on mobile */
  [style*="grid-template-columns:repeat(3,1fr)"],
  [style*="grid-template-columns: repeat(3,1fr)"],
  [style*="grid-template-columns:repeat(3, 1fr)"] {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  /* Estimator result inside modal */
  #est-result, #est-compare { 
    overflow-x: hidden; 
    font-size: 0.82rem;
  }

  /* ---------- GLASS CARDS ---------- */
  .glass-card { border-radius: 14px; }
  .glass-card-header { padding: 12px 14px; }
  .glass-card-header h3 { font-size: 0.88rem; }
  .glass-card-body { padding: 12px 14px; }

  /* ---------- GRID COLLAPSE ---------- */
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr !important; gap: 10px; }
  .dashboard-grid { grid-template-columns: 1fr; gap: 12px; }
  .workflow-detail-grid { grid-template-columns: 1fr; gap: 12px; }
  [style*="grid-template-columns:1fr 320px"],
  [style*="grid-template-columns: 1fr 320px"] { grid-template-columns: 1fr !important; }
  [style*="grid-template-columns:repeat(4,1fr)"],
  [style*="grid-template-columns: repeat(4,1fr)"] { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }

  /* ---------- TABS (SCROLL NGANG) ---------- */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
    /* Đảm bảo tabs không bị ẩn */
    display: flex !important;
    gap: 4px;
    padding-bottom: 2px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab-btn {
    white-space: nowrap;
    flex: 0 0 auto;
    padding: 9px 14px;
    font-size: 0.8rem;
    min-height: 40px;
  }

  /* ---------- WORKFLOW STEPPER ---------- */
  .workflow-stepper {
    flex-direction: column; overflow-x: unset;
    padding: 10px; gap: 2px;
  }
  .workflow-step {
    display: flex; flex-direction: row;
    align-items: center; gap: 10px;
    text-align: left; min-width: unset; flex: unset;
    padding: 8px 10px;
  }
  .workflow-step-circle { margin: 0; flex-shrink: 0; width: 34px; height: 34px; font-size: 0.78rem; }
  .workflow-step-connector { display: none; }
  .workflow-step-label { font-size: 0.7rem; }

  /* ---------- PROJECT DETAIL ---------- */
  .project-detail-header { flex-direction: column; gap: 10px; margin-bottom: 12px; }
  .project-detail-title { flex-wrap: wrap; gap: 8px; }
  .project-detail-title h1 { font-size: 1.05rem; }

  /* ---------- KANBAN ---------- */
  .kanban-board {
    flex-direction: row;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 10px;
    padding-bottom: 8px;
    scrollbar-width: none;
  }
  .kanban-board::-webkit-scrollbar { display: none; }
  .kanban-column {
    min-width: 260px;
    flex: 0 0 260px;
  }
  .kanban-column-header { padding: 10px 12px; }

  /* ---------- CALENDAR ---------- */
  .cal-day { min-height: 44px; }
  .cal-weekdays div { font-size: 0.6rem; padding: 3px; }
  .cal-event { font-size: 0.52rem; padding: 1px 3px; }

  /* ---------- FINANCE PAGE ---------- */
  .chart-container canvas { max-height: 200px; }
  .finance-stats-grid { grid-template-columns: 1fr 1fr !important; gap: 8px; }
  .finance-summary-grid { grid-template-columns: 1fr 1fr !important; gap: 8px; }
  /* Tabs tài chính cuộn ngang */
  .finance-tabs,
  [class*="finance"] .tabs { overflow-x: auto; flex-wrap: nowrap; }
  /* Finance tab buttons row — scroll ngang */
  .finance-tab-bar {
    overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap !important;
    width: 100%;
    display: flex;
  }
  .finance-tab-bar::-webkit-scrollbar { display: none; }
  .finance-tab-bar .btn { flex: 0 0 auto; white-space: nowrap; font-size: 0.74rem; padding: 7px 12px; }
  /* Receipt cards: stack vertical */
  [style*="grid-template-columns:1fr 1fr"][style*="gap:16px"] {
    grid-template-columns: 1fr !important;
  }
  /* Debt aging 4 kpi → 2x2 */
  [style*="grid-template-columns:repeat(4,1fr)"],
  [style*="grid-template-columns: repeat(4,1fr)"],
  [style*="grid-template-columns:repeat(4, 1fr)"] {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }
  /* P&L table scroll */
  .glass-card-body .analytics-table,
  .glass-card-body .data-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .glass-card-body .analytics-table::-webkit-scrollbar,
  .glass-card-body .data-table::-webkit-scrollbar { display: none; }

  /* ---------- TASKS ---------- */
  .task-filters {
    overflow-x: auto; flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
    display: flex; gap: 6px; padding-bottom: 2px;
  }
  .task-filters::-webkit-scrollbar { display: none; }
  .task-filter-btn { white-space: nowrap; flex-shrink: 0; min-height: 36px; }
  .task-card { padding: 12px 14px; border-radius: 12px; }

  /* ---------- EMPLOYEES ---------- */
  .employee-card { padding: 14px; }
  .employee-avatar { width: 44px; height: 44px; font-size: 1.1rem; }
  /* Employee grid: 1 cột trên mobile */
  .employee-grid,
  [class*="employee"] .grid-3,
  [class*="employee"] .grid-4 {
    grid-template-columns: 1fr !important;
  }

  /* ---------- INVENTORY ---------- */
  .inventory-detail-grid { grid-template-columns: 1fr !important; }
  .stock-badge { font-size: 0.68rem; padding: 3px 8px; }
  /* Inventory filters cuộn ngang */
  .inventory-filters {
    overflow-x: auto; flex-wrap: nowrap;
    display: flex; gap: 6px;
  }

  /* ---------- QUOTATIONS ---------- */
  .quotation-line-items { overflow-x: auto; }
  .quotation-line-items table { min-width: 400px; }
  .quotation-total-bar { flex-direction: column; gap: 6px; }
  /* Quotation templates: scroll ngang */
  .quotation-template-grid {
    display: flex !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 8px;
    flex-wrap: nowrap !important;
    padding-bottom: 4px;
  }
  .quotation-template-grid::-webkit-scrollbar { display: none; }
  /* Template cards: fixed width khi scroll ngang */
  .quotation-template-card {
    flex: 0 0 130px !important;
    min-width: 130px !important;
  }
  /* Quote item row: stack vertical on mobile */
  .quote-item-row {
    grid-template-columns: 1fr auto !important;
    gap: 6px !important;
  }
  .quote-item-row input:nth-child(1) { grid-column: 1 / -1; }
  .quote-item-row input:nth-child(2) { grid-column: 1; }
  .quote-item-row input:nth-child(3) { grid-column: 1; }
  .quote-item-row input:nth-child(4) { grid-column: 1; }
  .quote-item-row button { grid-column: 2; grid-row: 2 / 5; align-self: center; }

  /* ---------- WARRANTY ---------- */
  .warranty-timeline { padding-left: 28px; }
  .warranty-step { padding: 10px 12px; border-radius: 10px; }

  /* ---------- REPORTS ---------- */
  .reports-grid { grid-template-columns: 1fr !important; }
  .report-chart-wrapper { max-height: 220px; }
  /* Report tabs cuộn ngang */
  .report-tabs { overflow-x: auto; flex-wrap: nowrap; }

  /* ---------- SETTINGS ---------- */
  .settings-grid { grid-template-columns: 1fr !important; }
  .settings-section { padding: 14px; border-radius: 14px; }
  .settings-toggle { transform: scale(1.15); }

  /* ---------- AI PAGES ---------- */
  .ai-command-grid { grid-template-columns: 1fr !important; }
  .ai-alert-item { padding: 10px 12px; }
  .ai-alert-title { font-size: 0.78rem; }
  .ai-alert-desc { font-size: 0.68rem; }
  .ai-analytics-grid { grid-template-columns: 1fr !important; }
  .ai-chart-card { border-radius: 14px; }
  .maintenance-card { padding: 12px 14px; }

  /* ---------- AI ANALYTICS — filter tabs ---------- */
  .ai-analytics-tabs,
  [class*="ai"] .tabs {
    overflow-x: auto; flex-wrap: nowrap;
    scrollbar-width: none;
    display: flex;
  }
  [class*="ai"] .tabs::-webkit-scrollbar { display: none; }

  /* AI Analytics specific tabs */
  .analytics-tabs {
    overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap !important;
    display: flex;
    gap: 6px;
    padding-bottom: 4px;
  }
  .analytics-tabs::-webkit-scrollbar { display: none; }
  .analytics-tab {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 8px 14px;
    font-size: 0.76rem;
  }

  /* NBA grid: 2 cột trên mobile */
  .analytics-nba-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px;
  }
  .nba-card { padding: 12px 10px; }
  .nba-title { font-size: 0.8rem; }
  .nba-desc { font-size: 0.68rem; }
  .nba-footer { flex-direction: column; gap: 3px; }

  /* Analytics KPI row */
  .analytics-kpi-row {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px;
  }
  .analytics-kpi { padding: 12px 10px; gap: 10px; }
  .analytics-kpi-value { font-size: 1rem; }
  .analytics-kpi-label { font-size: 0.65rem; }
  .analytics-kpi-icon { width: 32px; height: 32px; font-size: 0.85rem; flex-shrink: 0; }

  /* Analytics chart: shorter on mobile */
  .analytics-chart-card .glass-card-body { height: 200px !important; }
  #analytics-cashflow-canvas { max-height: 200px; }

  /* Analytics table scroll */
  .analytics-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    font-size: 0.75rem;
  }
  .analytics-table::-webkit-scrollbar { display: none; }
  .analytics-table th, .analytics-table td { white-space: nowrap; padding: 8px 10px; }

  /* Efficiency grid: 1 col */
  .efficiency-grid { grid-template-columns: 1fr !important; gap: 10px; }
  .efficiency-card { padding: 14px; }
  .efficiency-stats { gap: 8px; }
  .efficiency-recommendation { font-size: 0.73rem; }

  /* ROI bars */
  .roi-bars { gap: 10px; }
  .roi-bar-stats { flex-wrap: wrap; gap: 4px 10px; font-size: 0.65rem; }

  /* Section label */
  .section-label { font-size: 0.65rem; padding: 6px 10px; letter-spacing: 0.5px; }

  /* ---------- SUPPLIERS PAGE ---------- */
  .supplier-detail-grid { grid-template-columns: 1fr !important; }

  /* ---------- DASHBOARD — Active Projects List ---------- */
  .cc-project-item { padding: 10px 12px; }
  .cc-project-name { font-size: 0.8rem; }
  .cc-project-progress { height: 5px; border-radius: 3px; }

  /* ---------- LOGIN PAGE ---------- */
  .login-page {
    padding: 32px 14px 20px;
    align-items: flex-start;
    justify-content: center;
  }
  .login-card { width: 100%; max-width: 100%; padding: 26px 18px; border-radius: 20px; }
  .login-logo i { font-size: 2.2rem; }
  .login-logo h1 { font-size: 1rem; letter-spacing: 1px; }
  .login-logo p { font-size: 0.78rem; }
  .login-logo { margin-bottom: 22px; }
  /* Login roles grid: 2 cột nhỏ hơn */
  .login-roles { grid-template-columns: 1fr 1fr; gap: 6px; }
  .login-role-btn { padding: 10px 8px; }
  .login-role-btn i { font-size: 1.1rem; }
  .login-role-btn span { font-size: 0.7rem; }

  /* ---------- EMPTY STATE ---------- */
  .empty-state { padding: 32px 12px; }
  .empty-state i { font-size: 2rem; }

  /* ---------- PERFORMANCE ---------- */
  .fx-film-grain { opacity: 0.3; }
  #cursor-ribbon-canvas { display: none; }

  /* ---------- CUSTOMERS PAGE sub-sections ---------- */
  .customer-detail-grid { grid-template-columns: 1fr !important; }
  .customer-tabs { overflow-x: auto; flex-wrap: nowrap; }
  /* NPS, portal sections */
  [class*="nps"] .grid-2,
  [class*="portal"] .grid-2 { grid-template-columns: 1fr !important; }

  /* ---------- ACTIVITY LOG ---------- */
  .activity-log { max-height: 360px; }
  .activity-item { padding: 10px 12px; }
}

/* ===== LANDING PAGE MOBILE ===== */
@media (max-width: 768px) {
  .nl-nav { padding: 0 12px; height: 56px; }
  .nl-nav-links, .nl-nav-actions { display: none !important; flex-direction: column; gap: 4px; }
  .nl-nav-links.open, .nl-nav-actions.open {
    display: flex !important;
    position: absolute; top: 56px; left: 0; right: 0;
    background: rgba(6,6,15,0.98); backdrop-filter: blur(24px);
    padding: 10px 12px; z-index: 1001;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    animation: slideDown 0.22s ease;
  }
  .nl-nav-hamburger {
    display: flex !important; align-items: center; justify-content: center;
    width: 40px; height: 40px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px; color: #fff; font-size: 1rem; cursor: pointer;
  }
  @keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  .nl-hero { padding: 76px 14px 16px; min-height: auto; }
  .nl-hero-content { grid-template-columns: 1fr; gap: 24px; text-align: center; }
  .nl-hero-visual { order: -1; }
  .nl-hero-badge { margin: 0 auto 16px; }
  .nl-hero-title { font-size: 1.85rem; line-height: 1.2; }
  .nl-title-highlight { font-size: 2rem; }
  .nl-hero-desc { font-size: 0.85rem; margin-bottom: 18px; }
  .nl-hero-cta { justify-content: center; flex-wrap: wrap; gap: 10px; }
  .nl-btn-lg { padding: 11px 20px; font-size: 0.86rem; }

  .nl-sphere-canvas { width: 140px; height: 140px; }
  .nl-dashboard-float { width: 100%; max-width: 280px; margin: 0 auto; }

  .nl-stats-bar { grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 20px; padding: 0; }
  .nl-stat { padding: 12px 8px; border-radius: 12px; }
  .nl-stat-num { font-size: 1.4rem; }
  .nl-stat-label { font-size: 0.65rem; }

  .nl-section { padding: 48px 12px 38px; }
  .nl-heading { font-size: 1.6rem; }
  .nl-subhead { font-size: 0.84rem; }

  .nl-bento { grid-template-columns: 1fr; gap: 10px; }
  .nl-bento-wide { grid-column: span 1; }
  .nl-bento-card { padding: 18px 14px; border-radius: 14px; }
  .nl-bento-icon { width: 40px; height: 40px; font-size: 0.9rem; }
  .nl-bento-card h3 { font-size: 0.92rem; }
  .nl-bento-card p { font-size: 0.78rem; }

  .nl-ai-grid { grid-template-columns: 1fr; gap: 10px; }
  .nl-ai-card { padding: 20px 14px; border-radius: 14px; }

  .nl-timeline { padding-left: 32px; }
  .nl-timeline-step { gap: 10px; padding: 8px; margin-bottom: 10px; }
  .nl-step-body h4 { font-size: 0.86rem; }
  .nl-step-body p { font-size: 0.74rem; }

  .nl-testimonial-card { padding: 20px 14px; }
  .nl-testimonial-card p { font-size: 0.86rem; }

  .nl-trust-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .nl-trust-card { padding: 18px 10px; }
  .nl-trust-big-num { font-size: 1.6rem; }
  .nl-trust-card h3 { font-size: 0.82rem; }
  .nl-trust-card p { font-size: 0.74rem; }

  .nl-contact-grid { grid-template-columns: 1fr; gap: 24px; }
  .nl-contact-form { padding: 18px 14px; border-radius: 14px; gap: 10px; }

  .nl-footer-body { padding: 24px 12px 80px; }
  .nl-footer-grid { grid-template-columns: 1fr; gap: 22px; }
  .nl-footer-bottom { flex-direction: column; gap: 6px; text-align: center; }
  #cursor-ribbon-canvas { display: none; }
}

/* ===== TABLET (769-1024) ===== */
@media (min-width: 769px) and (max-width: 1024px) {
  .nl-hero { padding: 90px 28px 24px; }
  .nl-hero-content { grid-template-columns: 1fr; text-align: center; gap: 36px; }
  .nl-hero-visual { order: -1; }
  .nl-hero-cta { justify-content: center; }
  .nl-hero-title { font-size: 2.5rem; }
  .nl-section { padding: 76px 28px; }
  .nl-bento { grid-template-columns: 1fr 1fr; }
  .nl-bento-wide { grid-column: span 2; }
  .nl-ai-grid { grid-template-columns: 1fr 1fr; }
  .nl-trust-grid { grid-template-columns: repeat(2, 1fr); }
  .nl-contact-grid { grid-template-columns: 1fr; }
  .nl-footer-grid { grid-template-columns: 1fr 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* ===== VERY SMALL (< 380px) ===== */
@media (max-width: 380px) {
  .nl-hero-title { font-size: 1.65rem; }
  .nl-title-highlight { font-size: 1.85rem; }
  .kpi-grid { grid-template-columns: 1fr; }
  .nl-trust-grid { grid-template-columns: 1fr; }
  /* Bottom nav: ẩn text, chỉ icon */
  .mobile-nav-item span { display: none; }
  .mobile-nav-item {
    padding: 4px 0;
    min-width: 52px;
    width: calc(100% / 5);
  }
  .mobile-nav-item i { font-size: 1.15rem; }
  .page-content { padding-left: 10px; padding-right: 10px; }
  .header-mobile-title { max-width: 110px; font-size: 0.82rem; }
}

/* ===== SAFE AREA — IPHONE NOTCH / DYNAMIC ISLAND ===== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .mobile-bottom-nav {
    height: calc(62px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
  }
  .page-content { padding-bottom: calc(86px + env(safe-area-inset-bottom)); }
  .chatbot-fab { bottom: calc(78px + env(safe-area-inset-bottom)) !important; }
  .chatbot-panel { bottom: calc(136px + env(safe-area-inset-bottom)) !important; }
  .toast-container { bottom: calc(74px + env(safe-area-inset-bottom)); }
  .mobile-scroll-top { bottom: calc(74px + env(safe-area-inset-bottom)); }
}

/* ===== MOBILE TOUCH POLISH ===== */
@media (max-width: 768px) {
  /* Active press state - gives tactile feeling */
  .btn:active,
  .kpi-card:active,
  .glass-card:active,
  .mobile-card:active,
  .sidebar-item:active,
  .mobile-nav-item:active {
    transform: scale(0.97) !important;
    transition: transform 0.1s ease !important;
  }

  /* Tap highlight color — consistent across app */
  a, button, [onclick], .btn, .kpi-card, .mobile-card, 
  .sidebar-item, .mobile-nav-item, .tab-btn, .task-filter-btn {
    -webkit-tap-highlight-color: rgba(59, 130, 246, 0.08);
  }

  /* Smooth sidebar slide with iOS-like physics */
  .sidebar {
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1) !important;
    will-change: transform;
  }

  /* Chatbot panel — full screen on very small phones */
  @media (max-height: 680px) {
    .chatbot-panel {
      max-height: calc(100vh - 150px) !important;
    }
    .chatbot-messages { max-height: 35vh; }
  }

  /* Sticky filter bars */
  .task-filters,
  .inventory-filters {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-primary);
    padding: 8px 0;
    margin: -8px 0 8px;
  }

  /* Better empty state on mobile */
  .empty-state {
    padding: 40px 16px;
    border-radius: 16px;
  }
  .empty-state i {
    font-size: 2.4rem;
    margin-bottom: 12px;
  }
  .empty-state p {
    font-size: 0.82rem;
    line-height: 1.5;
  }

  /* Notification dropdown full-width */
  .notification-dropdown {
    left: -30px;
  }

  /* Workflow stepper scrollable horizontal */
  .wf-steps-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 8px;
  }
  .wf-steps-scroll::-webkit-scrollbar { display: none; }

  /* Customer portal tab */
  .customer-portal-tabs,
  .customer-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
  }
  .customer-portal-tabs::-webkit-scrollbar,
  .customer-tabs::-webkit-scrollbar { display: none; }

  /* Reports grid */
  .reports-filter-bar {
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }
  .reports-filter-bar::-webkit-scrollbar { display: none; }

  /* AI Command page alert/anomaly list */
  .ai-anomaly-list,
  .ai-alerts-list { max-height: 320px; overflow-y: auto; -webkit-overflow-scrolling: touch; }

  /* Bottom sheet drag indicator enhancement */
  .modal::before {
    content: '';
    width: 40px;
    height: 4px;
    background: rgba(255,255,255,0.25) !important;
    border-radius: 3px;
    margin: 10px auto 6px;
    display: block;
    flex-shrink: 0;
  }

  /* Inline styles via attribute selectors — catch remaining inline grids */
  [style*="display:flex"][style*="gap:24px"]:not(.header):not(.sidebar-user),
  [style*="display: flex"][style*="gap: 24px"]:not(.header):not(.sidebar-user) {
    gap: 10px !important;
  }

  /* Data table in glass-card-body */
  .glass-card-body table {
    font-size: 0.8rem;
  }
  .glass-card-body table th { font-size: 0.66rem; }
}
