/* === ADGREEN SOLAR ERP PRO - GIAO DIEN DI DONG CHUYEN BIET (V20) === */
/* Mac dinh an toan bo thanh phan di dong tren May tinh (Desktop >= 861px) */
.mob-only,
.mob-bottom-nav,
.mob-drawer-backdrop,
.mob-header-actions,
.mob-account-sheet {
  display: none !important;
}

@media (max-width: 860px) {
  html, body {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
  }

  /* 1. BO CUC CHINH & NGAN KEO MENU TRUOT TRAI (DRAWER) */
  .layout {
    display: block !important;
    min-height: 100vh;
  }

  .sidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: 278px !important;
    max-width: 84vw !important;
    z-index: 9800 !important;
    transform: translateX(-106%);
    transition: transform 0.24s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex !important;
    flex-direction: column !important;
  }

  body.mob-drawer-open {
    overflow: hidden;
  }

  body.mob-drawer-open .sidebar {
    transform: translateX(0);
    box-shadow: 12px 0 42px rgba(0, 0, 0, 0.48);
  }

  body.mob-drawer-open .mob-drawer-backdrop {
    display: block !important;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.58);
    backdrop-filter: blur(2px);
    z-index: 9750;
  }

  /* Khoi phuc danh sach Menu doc sach dep ben trong Drawer */
  .sidebar .nav {
    display: flex !important;
    flex-direction: column !important;
    overflow-x: visible !important;
    gap: 3px !important;
    padding: 10px 12px calc(32px + env(safe-area-inset-bottom, 0px)) !important;
  }
  .sidebar .nav-section {
    display: block !important;
    padding: 10px 10px 4px !important;
  }
  .sidebar .nav-btn {
    width: 100% !important;
    white-space: normal !important;
    padding: 11px 13px !important;
    font-size: 13.5px !important;
    min-height: 42px;
  }

  /* Bo trang thai thu gon desktop khi mo tren mobile */
  body.sidebar-collapsed .sidebar {
    width: 278px !important;
  }
  body.sidebar-collapsed .sidebar .brand-meta,
  body.sidebar-collapsed .sidebar .nav-section {
    display: block !important;
  }
  body.sidebar-collapsed .sidebar .nav-btn {
    justify-content: flex-start !important;
    font-size: 13.5px !important;
  }

  /* 2. TOP HEADER SIEU GON 1 DONG (54px) */
  .topbar {
    padding: 6px 12px !important;
    height: 54px;
    min-height: 54px;
    flex-wrap: nowrap !important;
    gap: 8px !important;
    z-index: 900;
  }
  #btnSidebarToggle {
    padding: 6px 10px !important;
    font-size: 18px !important;
    min-height: 38px !important;
    min-width: 38px;
    justify-content: center;
  }
  #pageTitle {
    font-size: 14.5px !important;
    font-weight: 800 !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 56vw;
  }

  /* An cac nut thua cua Desktop tren thanh Topbar dien thoai */
  .topbar-right > *:not(.mob-header-actions) {
    display: none !important;
  }
  .mob-header-actions {
    display: inline-flex !important;
    align-items: center;
    gap: 6px;
  }
  .mob-icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-size: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
  }
  .mob-icon-btn-user {
    background: linear-gradient(135deg, #0d7a36, #10b981);
    color: #fff;
    border: none;
    font-weight: 800;
    font-size: 14px;
  }

  /* 3. KHUNG NOI DUNG CHINH (CHUA KHOANG AN TOAN CHO BOTTOM BAR) */
  .content {
    padding: 10px 10px calc(86px + env(safe-area-inset-bottom, 0px)) !important;
  }
  #bossDirectiveBar {
    padding: 8px 10px 0 !important;
  }
  .card {
    padding: 13px 12px !important;
    border-radius: 12px !important;
    margin-bottom: 12px !important;
  }
  .card h3 {
    font-size: 14px !important;
    flex-wrap: wrap;
    margin-bottom: 11px !important;
  }

  /* 4. LUOI KPI 2x2 GON DEP & FORM 1 COT */
  .grid-4,
  .hr-stat-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
    margin-bottom: 12px !important;
  }
  .kpi-card,
  .hr-stat-card {
    padding: 11px 12px !important;
    border-radius: 11px !important;
  }
  .kpi-title {
    font-size: 10.5px !important;
  }
  .kpi-val,
  .hr-stat-num {
    font-size: 20px !important;
    margin: 4px 0 2px !important;
  }
  .kpi-sub {
    font-size: 11.5px !important;
    line-height: 1.35;
  }
  .kpi-icon {
    width: 32px;
    height: 32px;
  }

  .grid-2,
  .grid-3,
  .form-row,
  .profile-grid,
  .smart-banner {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
  .smart-banner {
    padding: 14px !important;
  }

  /* 5. CHONG TU PHONG TO TREN IPHONE (iOS 16px) & NUT CHUAN NGON CAI */
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
  select,
  textarea {
    font-size: 16px !important;
    min-height: 42px;
    padding: 9px 11px !important;
    border-radius: 10px !important;
    width: 100% !important;
    max-width: 100% !important;
  }
  input[type="file"] {
    font-size: 13.5px !important;
    padding: 8px !important;
  }
  .btn {
    min-height: 40px;
    padding: 8px 13px;
    font-size: 13px;
    border-radius: 9px;
  }
  .btn-sm {
    min-height: 34px;
    padding: 6px 10px;
    font-size: 12px;
  }

  /* 6. THANH SUBTAB CUON NGANG MUOT */
  .hr-subtabs,
  .subtabs {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    gap: 6px !important;
    padding: 6px !important;
    margin-bottom: 10px !important;
    scrollbar-width: none;
  }
  .hr-subtabs::-webkit-scrollbar,
  .subtabs::-webkit-scrollbar {
    display: none;
  }
  .hr-tab-btn,
  .subtab-btn {
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    padding: 8px 12px !important;
    font-size: 12.5px !important;
  }

  /* 7. BANG DU LIEU & CHE DO THE DOC MOBILE (CARD TABLE) */
  .table-wrap {
    max-height: none !important;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
  }
  table {
    font-size: 12.5px;
  }
  th, td {
    padding: 8px 9px;
  }

  table.mob-card-table {
    border: none;
    display: block;
    width: 100%;
  }
  table.mob-card-table thead {
    display: none !important;
  }
  table.mob-card-table tbody {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
  }
  table.mob-card-table tbody tr {
    display: block;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 11px 12px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
  }
  table.mob-card-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    padding: 5px 0 !important;
    border-bottom: 1px dashed var(--border);
    max-width: 100% !important;
    white-space: normal !important;
    text-align: right;
  }
  table.mob-card-table tbody td:last-child {
    border-bottom: none;
    padding-top: 9px !important;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 6px;
  }
  table.mob-card-table tbody td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    text-align: left;
    flex-shrink: 0;
    padding-top: 2px;
  }
  table.mob-card-table tbody td[data-label=""]::before,
  table.mob-card-table tbody td.mob-full-cell::before {
    display: none;
  }
  table.mob-card-table tbody td.mob-full-cell {
    display: block;
    text-align: left;
  }

  /* 8. SO DO 32 MAY TREN DIEN THOAI: 2 COT GON DEP */
  .lm-flow {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  .lm-arrow {
    display: none !important;
  }
  .lm-node {
    width: 100% !important;
    padding: 9px 10px !important;
  }

  /* 9. MODAL DANG BOTTOM SHEET & CHONG DE NUT */
  .modal-overlay {
    padding: 8px !important;
    align-items: flex-end !important;
  }
  .modal-box {
    max-width: 100% !important;
    max-height: 92vh !important;
    border-radius: 18px 18px 10px 10px !important;
    padding: 16px 14px !important;
  }

  .ai-fab {
    bottom: calc(74px + env(safe-area-inset-bottom, 0px)) !important;
    right: 12px !important;
    padding: 9px 13px !important;
    font-size: 12px !important;
  }
  .ai-chat-panel {
    left: 8px !important;
    right: 8px !important;
    width: auto !important;
    bottom: calc(74px + env(safe-area-inset-bottom, 0px)) !important;
    height: 74vh !important;
  }
  .toast {
    bottom: calc(76px + env(safe-area-inset-bottom, 0px)) !important;
    left: 12px !important;
    right: 12px !important;
    text-align: center;
  }

  /* 10. THANH BOTTOM NAVIGATION BAR 4 NUT O DAY MAN HINH */
  .mob-bottom-nav {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9600;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 18px rgba(15, 23, 42, 0.08);
    padding: 4px 4px calc(5px + env(safe-area-inset-bottom, 0px));
  }
  body.dark-mode .mob-bottom-nav {
    background: rgba(15, 23, 42, 0.97);
    border-top-color: #1e293b;
  }
  .mob-bnav-btn {
    position: relative;
    background: transparent;
    border: none;
    color: var(--muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 5px 2px;
    border-radius: 10px;
    cursor: pointer;
    font-family: inherit;
    transition: color 0.15s, background 0.15s;
  }
  .mob-bnav-btn .mb-ic {
    font-size: 19px;
    line-height: 1.1;
  }
  .mob-bnav-btn .mb-lbl {
    font-size: 10.5px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }
  .mob-bnav-btn.active {
    color: var(--primary);
    background: var(--primary-soft);
  }
  .mob-bnav-badge {
    position: absolute;
    top: 2px;
    right: calc(50% - 22px);
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    padding: 1px 5px;
    border-radius: 999px;
    min-width: 17px;
    text-align: center;
    box-shadow: 0 2px 5px rgba(239, 68, 68, 0.45);
  }

  /* 11. MENU TAI KHOAN NHANH (BAM VAO AVATAR GOC PHAI) */
  .mob-account-sheet {
    display: flex !important;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.58);
    z-index: 9850;
    align-items: flex-end;
    justify-content: center;
    padding: 10px;
  }
  .mob-account-sheet.hidden {
    display: none !important;
  }
  .mob-sheet-card {
    background: var(--card);
    width: 100%;
    max-width: 460px;
    border-radius: 18px;
    padding: 16px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
}