/* ==========================================================================
 * BizOne ERP - Mobile responsive (PWA)
 * File rieng, nap SAU style.css. Chi tac dong man hinh <= 768px.
 * Khong sua desktop: moi rule nam trong @media.
 * Font: stack ho tro day du tieng Viet (khong webfont trang tri).
 * ========================================================================== */

#bizone-mobile-menu-btn {
  display: none;
}

@media (max-width: 768px) {

  /* ---- Font chu tieng Viet an toan ---- */
  body,
  body button,
  body input,
  body select,
  body textarea {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
  }

  /* ---- Header: nut menu + goi dong ---- */
  #bizone-mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    margin-right: 0.5rem;
    background: var(--bg-subtle);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    flex: 0 0 auto;
  }

  .app-header {
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem;
  }

  .header-brand h1 {
    font-size: 1rem;
  }

  .header-brand p {
    display: none;
  }

  .header-actions {
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
  }

  .header-actions .btn {
    min-height: 44px;
    flex: 1 1 auto;
  }

  /* ---- Sidebar: off-canvas ---- */
  .app-wrapper {
    display: block;
    min-height: auto;
  }

  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100dvh;
    width: min(300px, 84vw);
    min-width: 0;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    z-index: 200;
    box-shadow: none;
  }

  .app-sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.45);
  }

  /* Nut < trong sidebar: hien tren mobile de dong menu truot (mo lai bang nut menu header) */
  .app-sidebar .sidebar-toggle-btn {
    display: flex;
  }

  #bizone-sidebar-scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 190;
  }

  #bizone-sidebar-scrim.visible {
    display: block;
  }

  .sidebar-nav-item {
    min-height: 48px;
  }

  /* ---- Main content ---- */
  .app-main {
    padding: 0.75rem;
    max-width: 100%;
  }

  .app-container {
    padding: 0.75rem;
  }

  /* ---- Grids -> 1 cot ---- */
  .kpi-grid,
  .grid-single-platform,
  .header-action-grid,
  .perm-matrix-grid {
    grid-template-columns: 1fr !important;
  }

  /* ---- Tables: cuon ngang muot ---- */
  .table-responsive {
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
  }

  .data-table {
    font-size: 0.8rem;
  }

  .data-table th,
  .data-table td {
    padding: 0.5rem 0.6rem;
    white-space: nowrap;
  }

  /* ---- Forms: full-width, touch target >= 44px ---- */
  .form-group {
    margin-bottom: 0.9rem;
  }

  input[type="text"],
  input[type="number"],
  input[type="date"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  select,
  textarea {
    width: 100% !important;
    min-height: 44px;
    font-size: 16px; /* chong iOS tu zoom khi focus */
  }

  button,
  .btn,
  input[type="submit"],
  input[type="button"] {
    min-height: 44px;
  }

  /* ---- Modals fit viewport ---- */
  .modal-overlay {
    padding: 0.75rem;
    align-items: flex-end;
  }

  .modal-content {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 92dvh;
    overflow-y: auto;
    margin: 0;
  }

  /* ---- Feedback module tren mobile ---- */
  .fb-page-head { flex-direction: column; align-items: stretch; }
  .fb-head-actions { flex-wrap: wrap; }
  .fb-head-actions .btn { flex: 1 1 auto; min-height: 44px; }
  #feedback-fab {
    bottom: calc(1rem + env(safe-area-inset-bottom)) !important;
    right: 1rem !important;
    width: 56px !important;
    height: 56px !important;
  }

  #feedback-dialog {
    width: calc(100vw - 1.5rem) !important;
    max-width: calc(100vw - 1.5rem) !important;
    max-height: 88dvh !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    right: auto !important;
  }

  /* ---- Tab panes / cards ---- */
  .tab-pane {
    padding: 0.5rem 0;
  }

  .card,
  .panel {
    border-radius: var(--radius-sm);
  }

  /* ---- Màn hình Tính giá: giữ nguyên 1 cột dọc 1-2-3-4 trên mobile ----
     (ghi đè vị trí cột/hàng của desktop) ---- */
  .pricing-steps-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  .pricing-step-1,
  .pricing-step-2,
  .pricing-step-3,
  .pricing-step-4 {
    grid-column: 1 / -1 !important;
    grid-row: auto !important;
  }

  /* Chong tran ngang tong the */
  .app-main,
  .tab-pane {
    overflow-x: hidden;
  }

  /* ---- Ma tran phan quyen (RBAC): cuon ngang tren mobile ---- */
  .perm-matrix-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin: 0 -0.25rem;
  }
  .perm-matrix-scroll .perm-table {
    min-width: 620px;
  }
  .perm-section-header {
    flex-wrap: wrap;
    gap: 0.3rem;
  }
}
