/**
 * MacroSpyder Master Responsive & Touch System CSS
 * Quy tắc giao diện mượt mà trên Mobile & Tablet (iOS / Android / iPad / Desktop)
 */

/* ── Global Touch & Scroll Enhancements ── */
body.drawer-open {
  overflow: hidden !important;
  touch-action: none;
}

.app-backdrop {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(11, 12, 15, 0.65);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.app-backdrop.active {
  display: block !important;
  opacity: 1 !important;
}

@media (min-width: 1025px) {
  .app-backdrop, #app-backdrop {
    display: none !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }
}

/* Nút Hamburger Menu Di động */
.mobile-menu-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--border-strong, rgba(255, 255, 255, 0.15));
  border-radius: 6px;
  width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  color: var(--text, #ffffff);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.15s ease;
}
.mobile-menu-btn svg {
  width: 20px;
  height: 20px;
}
.mobile-menu-btn:hover, .mobile-menu-btn:active {
  background: var(--hover, rgba(255, 255, 255, 0.1));
}

.pill svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* Nút Đóng Sidebar ✕ */
.sidebar-close-btn {
  display: none;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #9ca3af;
  font-size: 18px;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.sidebar-close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

/* ── Media Queries Tablet & Mobile (< 1024px) ── */
@media (max-width: 1024px) {
  /* Khung ứng dụng dạng 1 Cột Flexbox */
  .app, #app {
    display: flex !important;
    flex-direction: column !important;
    height: 100vh !important;
    height: 100dvh !important;
    width: 100vw !important;
    overflow-x: hidden !important;
    position: relative !important;
  }

  /* Topbar di động */
  .topbar {
    height: 50px !important;
    flex: 0 0 50px !important;
    padding: 0 12px !important;
    gap: 8px !important;
    width: 100% !important;
    position: relative !important;
    z-index: 1001 !important;
  }

  .breadcrumb {
    display: none !important;
  }

  .mobile-menu-btn {
    display: inline-flex !important;
  }

  /* Sidebar trái Off-canvas Drawer */
  .sidebar, aside.sidebar {
    position: fixed !important;
    top: 50px !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 280px !important;
    max-width: 85vw !important;
    z-index: 1000 !important;
    background: var(--surface, #111317) !important;
    border-right: 1px solid var(--border-strong, #2c2f37) !important;
    transform: translateX(-100%) !important;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.28s ease !important;
    box-shadow: none !important;
    height: calc(100vh - 50px) !important;
    height: calc(100dvh - 50px) !important;
  }

  .sidebar.open, aside.sidebar.open {
    transform: translateX(0) !important;
    box-shadow: 4px 0 25px rgba(0, 0, 0, 0.4) !important;
  }

  .sidebar .sidebar-close-btn {
    display: inline-flex !important;
  }

  /* Sidebar phải Off-canvas Drawer */
  .right, #right-sidebar, aside.right {
    position: fixed !important;
    top: 50px !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 320px !important;
    max-width: 90vw !important;
    z-index: 1000 !important;
    background: var(--surface, #111317) !important;
    border-left: 1px solid var(--border-strong, #2c2f37) !important;
    transform: translateX(100%) !important;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.28s ease !important;
    box-shadow: none !important;
    height: calc(100vh - 50px) !important;
    height: calc(100dvh - 50px) !important;
  }

  .right.mobile-open, #right-sidebar.mobile-open, aside.right.mobile-open {
    transform: translateX(0) !important;
    box-shadow: -4px 0 25px rgba(0, 0, 0, 0.4) !important;
  }

  .right-tabs {
    display: flex !important;
    height: 46px !important;
    border-bottom: 1px solid var(--border) !important;
    padding: 0 4px !important;
    background: var(--surface) !important;
  }

  .right-tabs button, .right-tabs .rs-tab {
    flex: 1 !important;
    font-size: 10px !important;
    padding: 0 2px !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    white-space: nowrap !important;
  }

  .right-tabs button span, .right-tabs .rs-tab span {
    display: inline-block !important;
  }

  .rs-panes, .rs-pane {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Main stage & content */
  .main-content, .stage, main, .main {
    flex: 1 !important;
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    overflow-x: hidden !important;
  }

  /* Toolbar cuộn ngang mượt (Single Row) */
  .toolbar, #chart-toolbar {
    width: 100% !important;
    display: flex;
    flex-direction: row !important;
    align-items: center !important;
    overflow-x: auto !important;
    white-space: nowrap !important;
    -webkit-overflow-scrolling: touch !important;
    padding: 6px 12px !important;
    gap: 10px !important;
    border-bottom: 1px solid var(--border) !important;
    scrollbar-width: none !important;
  }
  .toolbar::-webkit-scrollbar, #chart-toolbar::-webkit-scrollbar {
    display: none !important;
  }

  .app.no-toolbar .toolbar,
  .app.no-toolbar #chart-toolbar,
  #chart-toolbar[style*="display: none"],
  #chart-toolbar[style*="display:none"] {
    display: none !important;
  }

  .divider-v {
    display: none !important;
  }

  /* Lưới thống kê & Form */
  .cards, .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }

  .grid-2, .grid-layout {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  .form-grid {
    grid-template-columns: 1fr !important;
  }

  .form-grid .form-full {
    grid-column: span 1 !important;
  }
}

/* ── Media Queries Điện thoại (< 640px) ── */
@media (max-width: 640px) {
  .cards, .stats-grid {
    grid-template-columns: 1fr !important;
  }

  .pill .pill-text, .pill span:not(#themeIcon) {
    display: none !important;
  }

  .pill {
    padding: 0 !important;
    width: 34px !important;
    height: 34px !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
  }

  .topbar .user-name, .topbar .clock {
    display: none !important;
  }

  .topbar .logout-text {
    display: none !important;
  }

  .modal-box {
    width: 95% !important;
    padding: 18px 14px !important;
    max-height: 88vh !important;
  }

  .filter-form {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .filter-form input,
  .filter-form select,
  .filter-form button {
    width: 100% !important;
  }
}
