/* ==========================================================================
   MihirSoft BD - Responsive / mobile styles
   Loaded after app.css + dashboard.css so these rules win.
   Breakpoints: drawer <= 1023px, stacking/tables <= 767px.
   ========================================================================== */

/* ---------- 1. Mobile navigation drawer (<= lg) ---------- */
#sidebarOverlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 55;
  background: rgba(2, 6, 16, 0.65);
  backdrop-filter: blur(2px);
}
body.nav-open { overflow: hidden; }

@media (max-width: 1023.98px) {
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 60;
    height: 100%;
    height: 100dvh;
    width: 248px !important;
    transform: translateX(-110%);
    transition: transform 0.25s ease;
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.45);
  }
  #sidebar.open { transform: translateX(0); }
  /* Desktop icon-only collapse must not fight the drawer on mobile */
  #sidebar.collapsed { width: 248px !important; }
  #sidebar.collapsed .nav-label,
  #sidebar.collapsed .nav-num,
  #sidebar.collapsed .submenu-toggle,
  #sidebar.collapsed .brand-text,
  #sidebar.collapsed .brand-sub { display: initial !important; }
  /* Submenus keep their own open/closed state on mobile: only neutralize
     the desktop collapsed "display:none", never force them open. */
  #sidebar.collapsed .nav-sub:not(.hidden) { display: block !important; }
  #sidebar.collapsed .nav-link { justify-content: flex-start; }

  /* Hide the desktop collapse button inside the drawer on mobile */
  #sidebarCollapse { display: none; }

  /* Touch-friendly nav targets */
  #sidebar .nav-link { min-height: 44px; }
  #sidebar .nav-sub a { padding-top: 0.6rem; padding-bottom: 0.6rem; }
}

@media (min-width: 1024px) {
  #mobileMenuBtn { display: none !important; }
  #sidebarOverlay { display: none !important; }
}

/* ---------- 2. Grid stacking on phones (<= md) ----------
   Only grids with NO responsive variant (no sm:/md:/lg:/xl: in the
   class list) are forced to a single column, so e.g. the KPI row that
   already uses "grid-cols-2 md:grid-cols-3" keeps its 2-column phone
   layout. */
@media (max-width: 767.98px) {
  main .grid-cols-2:not([class*="sm:"]):not([class*="md:"]):not([class*="lg:"]):not([class*="xl:"]),
  main .grid-cols-3:not([class*="sm:"]):not([class*="md:"]):not([class*="lg:"]):not([class*="xl:"]),
  main .grid-cols-4:not([class*="sm:"]):not([class*="md:"]):not([class*="lg:"]):not([class*="xl:"]),
  main .grid-cols-5:not([class*="sm:"]):not([class*="md:"]):not([class*="lg:"]):not([class*="xl:"]),
  main .grid-cols-6:not([class*="sm:"]):not([class*="md:"]):not([class*="lg:"]):not([class*="xl:"]),
  main .grid-cols-12:not([class*="sm:"]):not([class*="md:"]):not([class*="lg:"]):not([class*="xl:"]) {
    grid-template-columns: 1fr !important;
  }
  main [class*="col-span-"]:not([class*="sm:"]):not([class*="md:"]):not([class*="lg:"]):not([class*="xl:"]) {
    grid-column: 1 / -1 !important;
  }

  /* ---------- 3. Scrollable tables ---------- */
  main table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  main table thead,
  main table tbody {
    display: table;
    width: 100%;
    min-width: 560px;
  }
  main table th,
  main table td { white-space: nowrap; }

  /* ---------- 4. Tighter page padding ---------- */
  main { padding: 0.75rem !important; }
  main .p-6 { padding: 1rem !important; }
  main .p-5 { padding: 1rem !important; }
  main .gap-5 { gap: 0.75rem !important; }

  /* Long code/config blocks scroll instead of breaking layout */
  main pre { max-width: 100%; overflow-x: auto; }

  /* Page headers: let title + actions wrap instead of squeezing */
  main .flex.justify-between { flex-wrap: wrap; row-gap: 0.5rem; }

  /* Form inputs: comfortable tap size, no iOS auto-zoom */
  main input, main select, main textarea { font-size: 16px !important; }
  main button, main .btn { min-height: 40px; }
}

/* ---------- 5. Topbar on small screens ---------- */
@media (max-width: 767.98px) {
  header { padding-left: 0.75rem !important; padding-right: 0.75rem !important; }
  #globalSearch { font-size: 16px; } /* stop iOS zoom-on-focus */
}

/* ---------- 6. Small tablets: soften wide fixed grids ---------- */
@media (min-width: 768px) and (max-width: 1023.98px) {
  main .grid-cols-5:not([class*="md:"]):not([class*="lg:"]):not([class*="xl:"]) {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }
  main .grid-cols-3:not([class*="md:"]):not([class*="lg:"]):not([class*="xl:"]) {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

/* ---------- 7. Print: hide nav chrome ---------- */
@media print {
  #sidebar, header, #sidebarOverlay, #mobileMenuBtn { display: none !important; }
}
