/* ══════════════════════════════════════════════════════════════════
   ZAITOON INVENTORY & RMS — MOBILE RESPONSIVE ENGINE
   ══════════════════════════════════════════════════════════════════ */

/* ── Base Touch & Viewport Protection ── */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
  -webkit-text-size-adjust: 100%;
}

/* ── Mobile Hamburger Button ── */
.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  margin-right: 12px;
  background: #f8fafc;
  color: #1a1a2e;
  border: 1.5px solid #cbd5e1;
  border-radius: 8px;
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.mobile-menu-btn:hover {
  background: #f1f5f9;
  border-color: #e94560;
  color: #e94560;
}
.mobile-menu-btn:active {
  background: #e2e8f0;
  transform: scale(0.96);
}

/* ── Mobile Sidebar Close Button ── */
.mobile-sidebar-close {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin-left: auto;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 18px;
  cursor: pointer;
  transition: background 0.15s;
}
.mobile-sidebar-close:hover,
.mobile-sidebar-close:active {
  background: #e94560;
}

/* ── Mobile Backdrop Overlay ── */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
body.sidebar-open .sidebar-backdrop {
  opacity: 1;
  pointer-events: auto;
}

/* ══════════════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINT: TABLETS & MOBILE (<= 991px)
   ══════════════════════════════════════════════════════════════════ */
@media (max-width: 991px) {
  /* Show mobile controls */
  .mobile-menu-btn {
    display: inline-flex !important;
  }
  .mobile-sidebar-close {
    display: inline-flex !important;
  }

  /* Sidebar Drawer */
  .sidebar {
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    width: 270px !important;
    max-width: 82vw !important;
    z-index: 999 !important;
    transform: translateX(-100%) !important;
    transition: transform 0.26s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-shadow: none !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  body.sidebar-open .sidebar {
    transform: translateX(0) !important;
    box-shadow: 6px 0 30px rgba(0, 0, 0, 0.4) !important;
  }
  body.sidebar-open {
    overflow: hidden !important;
  }

  /* Main container takes full width */
  .main {
    margin-left: 0 !important;
    width: 100% !important;
    min-height: 100vh !important;
  }

  /* Topbar adaptability */
  .topbar {
    padding: 10px 14px !important;
    position: sticky;
    top: 0;
    z-index: 50;
    gap: 8px;
    flex-wrap: wrap;
  }
  .topbar h2, .page-title {
    font-size: 16px !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100vw - 160px);
  }
  .topbar-right, .topbar-actions {
    gap: 8px !important;
    font-size: 12px !important;
  }
  #currentDate, .topbar-right > span:nth-child(2) {
    display: none !important; /* Hide date separator & date on mobile */
  }

  /* Stats Cards Grid */
  .stats-row, .summary-cards {
    padding: 12px 14px 0 !important;
    gap: 10px !important;
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
  }
  .stat-card {
    min-width: 0 !important;
    padding: 14px !important;
  }
  .stat-value {
    font-size: 20px !important;
  }
  .stat-label {
    font-size: 11px !important;
  }

  /* Toolbars */
  .toolbar {
    margin: 12px 14px 0 !important;
    padding: 12px 14px !important;
    gap: 10px !important;
    flex-direction: column !important;
    align-items: stretch !important;
  }
  .search-wrap {
    min-width: 100% !important;
    max-width: 100% !important;
  }
  .toolbar > * {
    max-width: 100% !important;
  }
  .toolbar label {
    margin-top: 4px;
  }

  /* Subtabs Bar - Horizontal Scroll on touch */
  .subtabs {
    padding: 10px 14px 0 !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    flex-wrap: nowrap !important;
    gap: 6px !important;
  }
  .subtab {
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    padding: 8px 14px !important;
    font-size: 12px !important;
  }

  /* Side navbars used in accounts.html & reports.html */
  .wrap {
    flex-direction: column !important;
    height: auto !important;
  }
  .side {
    width: 100% !important;
    min-height: auto !important;
    border-right: none !important;
    border-bottom: 1px solid #e2e8f0 !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    padding: 8px 12px !important;
    gap: 6px !important;
    background: #fff !important;
  }
  .side-item, .side-nav-item {
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    padding: 8px 14px !important;
    border-radius: 8px !important;
    border: 1px solid #e2e8f0 !important;
    font-size: 12.5px !important;
    border-left: 1px solid #e2e8f0 !important;
  }
  .content, .page-section, .section {
    padding: 12px 14px !important;
    width: 100% !important;
  }

  /* POS Terminal layout */
  .catalog {
    padding: 12px !important;
    max-height: 48vh !important;
    flex: none !important;
    width: 100% !important;
  }
  .cart-panel {
    min-width: 100% !important;
    border-left: none !important;
    border-top: 2px solid #e2e8f0 !important;
    flex: none !important;
  }
  .box-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)) !important;
    gap: 10px !important;
  }
  .item-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)) !important;
    gap: 8px !important;
  }
  .item-card {
    padding: 10px !important;
  }

  /* Tables & Horizontal Scroll Container */
  .table-wrap, .groups-table-wrap, .cat-block {
    margin: 10px 0 !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 10px !important;
  }
  table {
    min-width: 580px; /* Preserve readability with smooth horizontal swipe */
  }
  thead th, tbody td {
    padding: 8px 10px !important;
    font-size: 12px !important;
    white-space: nowrap;
  }
  table td:nth-child(2), table th:nth-child(2) {
    white-space: normal;
    min-width: 130px;
  }

  /* Modals */
  .modal {
    width: 95vw !important;
    max-width: 95vw !important;
    padding: 18px 16px !important;
    margin: 10px !important;
    border-radius: 12px !important;
    max-height: 92vh !important;
  }
  .form-row {
    flex-direction: column !important;
    gap: 10px !important;
  }
  .modal-actions {
    flex-direction: column-reverse !important;
    gap: 8px !important;
  }
  .modal-actions .btn {
    width: 100% !important;
    padding: 12px !important;
  }

  /* Buttons & touch target sizing */
  .btn {
    padding: 9px 14px !important;
    font-size: 13px !important;
    touch-action: manipulation;
  }
  .btn-sm {
    padding: 6px 10px !important;
  }
}

/* ══════════════════════════════════════════════════════════════════
   SMALL PHONES (<= 480px)
   ══════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .stats-row, .summary-cards {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
    padding: 10px 10px 0 !important;
  }
  .stat-card {
    padding: 10px 12px !important;
  }
  .stat-value {
    font-size: 18px !important;
  }
  .toolbar {
    margin: 10px 10px 0 !important;
    padding: 10px 12px !important;
  }
  .page-section, .section {
    padding: 10px !important;
  }
  .cat-header {
    padding: 10px 12px !important;
    font-size: 13px !important;
  }
  .box-card {
    padding: 12px 10px !important;
  }
}
