/* ──────────────────────────────────────────────────────────────────
 * Mobile responsiveness overlay for the Mise design system.
 *
 * Each page has its own embedded <style> block; this stylesheet is
 * linked AFTER it so media-query overrides win on source order alone
 * (no !important needed). Loaded by every Mise *.html.
 *
 * Pattern: hide-on-mobile classes, hamburger drawer for the sidebar,
 * collapse multi-column grids to single column, full-bleed drawers.
 * ────────────────────────────────────────────────────────────────── */

/* ── Hamburger button (shown only on mobile) ──────────────────── */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--hair);
  color: var(--ink);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(11,27,38,.1);
}
.mobile-menu-btn svg { width: 18px; height: 18px; }
.mobile-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11,27,38,.45);
  z-index: 90;
}

/* ── Tablet: ≤ 1024px ─────────────────────────────────────────── */
@media (max-width: 1024px) {
  /* `1fr` defaults to minmax(min-content, 1fr); minmax(0, 1fr) lets
     the content column shrink below its widest child's min-content,
     which is the only thing that prevents page-level horizontal
     scroll when an interior grid is wider than the viewport. */
  .shell { min-width: 0 !important; grid-template-columns: var(--sidebar-w, 240px) minmax(0, 1fr) !important; }

  /* Collapse 2x2 / three-col grids */
  .grid-2x2 { grid-template-columns: 1fr !important; }
  .two-col { grid-template-columns: 1fr !important; }
  .kpis { grid-template-columns: repeat(2, 1fr) !important; }
  .sum-strip { grid-template-columns: repeat(2, 1fr) !important; }

  /* Store detail header card has a 240px right rail — let it stack. */
  .head-card { grid-template-columns: 1fr !important; }
  .hc-right { min-width: 0 !important; border-left: 0 !important; padding-left: 0 !important; padding-top: 16px !important; border-top: 1px solid var(--hair) !important; text-align: left !important; }
}

/* ── Mobile: ≤ 768px ──────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Belt-and-suspenders against any rogue child that still wants
     more width than the viewport (e.g. a horizontal-scrolling tabs
     strip whose parent doesn't have overflow constraints). The page
     itself never scrolls horizontally on mobile. */
  html, body { overflow-x: hidden !important; max-width: 100vw !important; }

  /* Surface the hamburger, hide its desktop counterpart */
  .mobile-menu-btn { display: inline-flex; }

  /* Single-column shell — sidebar slides over content. minmax(0, 1fr)
     so the content column can shrink below its min-content width. */
  .shell { grid-template-columns: minmax(0, 1fr) !important; }
  .sidebar {
    position: fixed !important;
    top: 0; left: 0;
    height: 100vh !important;
    width: 280px !important;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 4px 0 24px rgba(11,27,38,.20);
  }
  body.mobile-menu-open .sidebar { transform: translateX(0); }
  body.mobile-menu-open .mobile-sidebar-backdrop { display: block; }

  /* Topbar: drop search, condense */
  .topbar {
    grid-template-columns: 1fr auto !important;
    padding: 0 14px 0 60px !important; /* leave room for hamburger */
    gap: 12px !important;
  }
  .topbar .search { display: none; }
  .crumb { font-size: 16px !important; }
  .crumb .sub { display: none; }

  /* Reduce content padding everywhere */
  .main { padding: 14px !important; max-width: 100% !important; }
  .al-main { padding: 14px !important; }
  .set-pane { padding: 18px 14px !important; max-width: 100% !important; }

  /* KPIs / summary strips: single column */
  .kpis { grid-template-columns: 1fr !important; gap: 10px !important; }
  .sum-strip { grid-template-columns: 1fr !important; gap: 10px !important; }
  .sum-card { padding: 10px 12px !important; }

  /* Filters: wrap chips, hide view-toggle */
  .filters, .filter-bar-wrap { padding: 10px 14px !important; }
  .filter-chips, .filter-pills { flex-wrap: wrap !important; gap: 6px !important; }
  .view-toggle { display: none !important; }

  /* Tables that don't fit on mobile get a horizontal scroll container.
     Specific pages (stores, settings, documents) override this with
     card-style row collapses where it makes sense. */
  .table-wrap, .docs-card, .set-table {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Drawers: full-screen overlay */
  .al-shell { grid-template-columns: 1fr !important; }
  .al-drawer, .drawer {
    position: fixed !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 110;
    border-left: 0 !important;
  }

  /* Source panel on /ask: slides over chat */
  .body-grid { grid-template-columns: 1fr !important; }
  .source-panel {
    position: fixed !important;
    inset: 0 !important;
    z-index: 110;
    width: 100% !important;
  }

  /* Card heads can be cramped — let actions wrap */
  .card-head { flex-wrap: wrap !important; }

  /* Settings nav becomes top tabs */
  .set-main { grid-template-columns: 1fr !important; }
  .set-nav {
    position: relative !important;
    height: auto !important;
    border-right: 0 !important;
    border-bottom: 1px solid var(--hair) !important;
    padding: 12px 14px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    white-space: nowrap !important;
  }
  .set-group { display: inline-block !important; vertical-align: top; margin-right: 18px !important; margin-bottom: 0 !important; }

  /* Reports two-column main */
  .rep-main { grid-template-columns: 1fr !important; }

  /* Status banner */
  .status-card, .sc-title { font-size: 16px !important; }
  .status-card { flex-direction: column !important; align-items: flex-start !important; gap: 10px; }

  /* Map (stores): more height, less width chrome */
  .map-wrap { height: calc(100vh - 200px) !important; min-height: 360px !important; }
}

/* ── Tiny phones: ≤ 480px ─────────────────────────────────────── */
@media (max-width: 480px) {
  .topbar .top-right > *:not(.icon-btn):not(.mobile-menu-btn) { display: none !important; }
}
