/* ================================================================
   SGI Inventory — Mobile Responsive Overrides
   Loaded after inline styles; layers responsive rules on top.
   Breakpoints: tablet ≤1024px, phone ≤768px, tiny ≤400px
   ================================================================ */

/* ── Hamburger button (hidden on desktop, shown on mobile) ─────── */
.mobile-menu-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  padding: 8px;
  flex-shrink: 0;
}
.mobile-menu-btn span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}
.mobile-menu-btn.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.mobile-menu-btn.open span:nth-child(2) { opacity: 0; }
.mobile-menu-btn.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Mobile nav drawer (hidden on desktop) ─────────────────────── */
.mobile-nav {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
}
.mobile-nav-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}
.mobile-nav-drawer {
  position: absolute;
  top: 0;
  right: 0;
  width: 260px;
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}
.mobile-nav.open { display: block; }
.mobile-nav.open .mobile-nav-drawer { transform: translateX(0); }

.mobile-nav-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.mobile-nav-logo {
  width: 32px;
  height: 32px;
  background: var(--red);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-head);
  font-weight: 900;
  font-size: 0.85rem;
  color: #fff;
  flex-shrink: 0;
}
.mobile-nav-title {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.mobile-nav-links {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0;
  flex: 1;
}
.mobile-nav-links a {
  font-family: var(--font-head);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.15s, color 0.15s;
  min-height: 48px;
}
.mobile-nav-links a:hover,
.mobile-nav-links a.active { background: var(--surface-2); color: var(--text); }
.mobile-nav-links a.active { border-left: 3px solid var(--red); }
.mobile-nav-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.mobile-nav-footer form { margin: 0; }
.mobile-nav-footer button,
.mobile-nav-footer .btn {
  width: 100%;
  justify-content: center;
  min-height: 44px;
}

/* ── Tablet breakpoint (≤1024px) ───────────────────────────────── */
@media (max-width: 1024px) {
  .header-inner { padding: 0 1.25rem; }
  .page  { padding: 1.5rem 1.25rem 3rem; }
  .hero  { padding: 2.5rem 1.25rem 2rem; }
  .main  { padding: 0 1.25rem 3rem; }
  .stats-bar { padding: 0 1.25rem 2rem; }

  /* Stats: 2-column on tablet */
  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  /* Cards: max 2 wide on tablet */
  .cards-3 { grid-template-columns: repeat(2, 1fr); }
  .cards-4 { grid-template-columns: repeat(2, 1fr); }
}

/* ── Phone breakpoint (≤768px) ─────────────────────────────────── */
@media (max-width: 768px) {

  /* ── Header ────────────────────────────────────────────────── */
  .header-inner {
    padding: 0 1rem;
    height: 56px;
    gap: 0.75rem;
  }
  .header-nav   { display: none; }        /* replaced by mobile drawer */
  .logo-text span { display: none; }     /* hide subtitle "Inventory System" */
  .user-chip    { display: none; }       /* hide username chip */
  .breadcrumb   { display: none; }       /* hide breadcrumb */
  .mobile-menu-btn { display: flex; }    /* show hamburger */

  /* Shrink global search to fill remaining space */
  .gs-wrap {
    width: auto !important;
    flex: 1;
    min-width: 0;
    max-width: 220px;
  }

  /* Tighten action buttons */
  .header-actions { gap: 0.4rem; }
  .btn-admin { font-size: 0.7rem; padding: 0.35rem 0.65rem; }

  /* ── Page containers ───────────────────────────────────────── */
  .page      { padding: 1.25rem 1rem 3rem; }
  .hero      { padding: 2rem 1rem 1.5rem; }
  .main      { padding: 0 1rem 3rem; }
  .stats-bar { padding: 0 1rem 1.5rem; }

  /* ── Stats grid: 2-column ──────────────────────────────────── */
  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  /* ── Module cards ───────────────────────────────────────────── */
  .cards-2 { grid-template-columns: 1fr; }
  .cards-3 { grid-template-columns: 1fr; }
  .cards-4 { grid-template-columns: repeat(2, 1fr); }

  /* ── Filters bar ────────────────────────────────────────────── */
  .filters {
    flex-direction: column;
    gap: 0.5rem;
  }
  .filters input,
  .filters select,
  .filters .filter-input,
  .filters .filter-sel,
  .filters .search-input { width: 100% !important; }
  .filters .btn,
  .filters .filter-btn { width: 100%; justify-content: center; }

  /* ── Table — horizontal scroll ──────────────────────────────── */
  .table-panel { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .data-table,
  .inv-table,
  .cat-table,
  .lines-table,
  .lines        { display: block; overflow-x: auto; white-space: nowrap; width: 100%; }
  .data-table th,  .data-table td,
  .inv-table th,   .inv-table td,
  .cat-table th,   .cat-table td,
  .lines-table th, .lines-table td,
  .lines th,       .lines td { white-space: nowrap; }

  /* Touch-target row height for tappable tables (≥44px including padding) */
  .data-table td,
  .inv-table td,
  .cat-table td { padding: 0.85rem 0.6rem; line-height: 1.3; }

  /* ── Status tabs — horizontal scroll ───────────────────────── */
  .status-tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .stab { min-width: 72px; padding: 0.6rem 0.75rem; flex-shrink: 0; }

  /* ── Detail / side-panel grids ──────────────────────────────── */
  .detail-grid,
  .page-grid,
  .two-col { grid-template-columns: 1fr !important; }

  /* ── Forms: stack fields single-column ──────────────────────── */
  .form-row   { flex-direction: column !important; }
  .form-grid,
  .fg-2,
  .fg-3       { grid-template-columns: 1fr !important; }

  /* Prevent iOS auto-zoom on input focus */
  input[type="text"],
  input[type="number"],
  input[type="email"],
  input[type="date"],
  input[type="search"],
  input[type="tel"],
  select,
  textarea    { font-size: 16px !important; }

  /* ── Touch targets: minimum 44px ────────────────────────────── */
  .btn, .hbtn, .stab, .act-btn, .filter-btn { min-height: 44px; }
  button { min-height: 44px; }

  /* ── Typography ─────────────────────────────────────────────── */
  .page-head h1 { font-size: 1.8rem; }
  .hero h1      { font-size: clamp(2rem, 8vw, 3rem) !important; }

  /* ── Mobile-only: clear hamburger button below test banner ──── */
  /* TestBannerMiddleware injects a 36px fixed banner at top:0 with
     z-index:99999, which sits in front of the hamburger at top:12.
     Push the hamburger down so it's fully tappable on mobile. */
  .mobile-hamburger { top: 48px !important; }

  /* ── Mobile-only: tap-to-open sidebar flyouts ───────────────── */
  /* Sidebar flyouts are hover-triggered on desktop (see layout.css);
     on touch we add `.tap-open` via sidebar.js. When set, the flyout
     drops in-line below its icon (position:static) so it lives inside
     the 60px drawer without overflowing the viewport edge. */
  #sidebar .nav-group.tap-open > .nav-flyout {
    display: block;
    position: static;
    width: auto;
    min-width: 0;
    border: none;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    box-shadow: none;
    padding: 0.25rem 0;
    background: var(--surface-2);
  }
  #sidebar .nav-group.tap-open > .nav-flyout .nav-flyout-item {
    padding: 0.7rem 0.75rem;
    min-height: 44px;
    white-space: normal;
  }
  /* Hide the flyout title on mobile — the icon already indicates the group. */
  #sidebar .nav-group.tap-open > .nav-flyout .nav-flyout-title { display: none; }
}

/* ── Very small phones (≤400px) ────────────────────────────────── */
@media (max-width: 400px) {
  .logo-text    { display: none; }       /* show only the SGI emblem */
  .gs-wrap      { display: none; }       /* hide search (access via filters) */
  .cards-4      { grid-template-columns: 1fr; }
  .header-inner { padding: 0 0.75rem; }
}
