/* ════════════════════════════════════════════════════════════════════════════════ */
/* BILLZEN MOBILE RESPONSIVE CSS overrides */
/* ════════════════════════════════════════════════════════════════════════════════ */

/* Base hide for mobile elements on desktop */
#mob-overlay { display: none; }
#mob-bottom-nav { display: none; }

@media (max-width: 768px) {
  /* ── LAYOUT ── */
  #app { flex-direction: column; height: 100%; position: absolute; width: 100%; left: 0; top: 0; overflow: hidden; }
  
  /* ── MAIN AREA ── */
  #main { padding-bottom: 64px; flex: 1; overflow-y: auto; height: 100%; } /* Space for bottom nav */
  #content { padding: 14px; height: auto !important; }
  .g1-mob { grid-template-columns: 1fr !important; }
  
  /* ── TOPBAR ── */
  #mob-menu-btn { display: flex !important; }
  #topbar { padding: 0 14px; height: 56px; z-index: 10; flex-shrink: 0; }
  #topbar-date, #topbar-user, #topbar-avatar { display: none; } /* hide extra elements to save space */
  
  /* ── SIDEBAR SLIDE-OVER ── */
  #sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: -280px;
    width: 260px;
    height: 100%;
    z-index: 9999;
    background: #0f172a; /* Solid dark navy for sidebar */
    box-shadow: 10px 0 30px rgba(0,0,0,0.3);
    transition: left 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Navigation inside will scroll */
  }
  
  #sidebar.mob-open {
    left: 0;
  }

  .sb-nav {
    flex: 1;
    overflow-y: auto !important;
    padding-bottom: 20px;
    -webkit-overflow-scrolling: touch;
  }
  
  #mob-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 9998;
    display: none; /* toggled by JS inline */
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
  }
  
  /* Prevent background scrolling when sidebar open */
  body.mob-sidebar-open {
    overflow: hidden;
  }

  /* ── BOTTOM NAV ── */
  #mob-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 64px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 9000;
    justify-content: space-around;
    align-items: center;
    padding: 0 10px;
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -4px 12px rgba(0,0,0,0.03);
  }
  
  .mob-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    background: none;
    border: none;
    color: var(--text3);
    font-size: 10px;
    font-weight: 700;
    padding: 8px 0;
    border-radius: 8px;
    flex: 1;
  }
  
  .mob-nav-item.active, .mob-nav-item:active {
    color: var(--primary);
  }

  /* ── GENERAL GRID FIXES ── */
  .dashboard-grid, .g2, .g3, .g4 { 
    grid-template-columns: 1fr; 
    gap: 12px; 
  }
  
  /* Keep quick stats 2 wide on mobile if they are very small */
  .quick-stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  
  /* Tables horizontally scrollable */
  .tbl-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
  }
  
  table.tbl th, table.tbl td {
    padding: 10px 8px;
    font-size: 12px;
  }
  
  /* iOS Input Zoom Prevention Hack: Inputs must be at least 16px */
  input.inp, select.inp, textarea.inp {
    font-size: 16px;
    padding: 10px 12px; /* A bit larger touch target */
  }
  
  .page-title { font-size: 18px; line-height: 1.3; }
  .card { padding: 14px; border-radius: var(--r-md); }
  
  /* Modals full width */
  .modal-box {
    width: 100% !important;
    height: 95vh;
    height: 95svh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    margin-top: auto;
  }
  
  /* Hide the regular page buttons that might overlap the title */
  .page-header > div:nth-child(2) {
    width: 100%; 
    margin-top: 10px;
    justify-content: space-between;
  }

  /* POS / Billing Adjustments */
  #pos-wrap, #billing-wrap {
    grid-template-columns: 1fr !important;
    display: flex !important;
    flex-direction: column !important;
    height: auto !important;
    overflow: visible !important;
  }
  
  #billing-wrap.mob-layout {
    display: block !important;
    overflow: visible !important;
    height: auto !important;
    min-height: 100vh;
  }

  #pos-products, #product-panel {
    flex: none !important;
    height: 52vh !important; /* Limit products height */
    min-height: 380px;
    overflow-y: auto !important;
  }
  
  #cart-panel, #pos-cart {
    width: 100% !important;
    flex: none !important;
    height: auto !important;
    border-left: none;
    border-top: 2px solid var(--border);
    padding-bottom: 120px !important; /* Extra safety for bottom nav and submit button */
    overflow: visible !important;
  }

  /* Optimized Billing Cards for Mobile */
  .prod-card { padding: 10px !important; }
  .b-prod-name { font-size: 11.5px !important; }
  .b-prod-meta { font-size: 10px !important; margin-bottom: 5px !important; }
  .b-prod-price { font-size: 13.5px !important; }

  .branding-grid { grid-template-columns: 1fr; gap: 12px; }
}
