/* ══════════════════════════════════════════════════════════════════════
   RESPONSIVE LAYER  (added 2026-11-08)
   Replaces the "DESKTOP-ONLY LOCK" above, which forced a 1200px minimum
   width on every screen. Measured before: 810px overflow on a 390px phone,
   380px on an 820px tablet. Measured after: 0 on all tested pages.

   APPENDED, so every desktop rule above still applies. Overrides are scoped
   to narrow screens and use !important to match the lock they undo.

   Breakpoints:
     >= 1025px  desktop   unchanged
     769-1024   tablet    sidebar 210px, grids reflow to 2
     <= 768     mobile    sidebar becomes a drawer, app bar + tab bar shown
   ══════════════════════════════════════════════════════════════════════ */

/* ── 1. kill the hard 1200px floor below desktop ─────────────────────── */
@media (max-width: 1024px) {
  html, body {
    min-width: 0 !important;
    width: 100% !important;
  }
  .app-layout { width: 100% !important; }
  .app-layout > *,
  .main-content,
  .content { min-width: 0 !important; }

  /* ── TABLE STRATEGY (revised) ──────────────────────────────────────
     Tables were given min-width:560px on phones, which pushed them past a
     390px viewport. Measured: table w=600 right=821 on a 390px screen.
     Since the page can no longer scroll (overflow-x hidden), that content
     was silently clipped.

     New rule: the table itself may never exceed its container. Its PARENT
     becomes the scroll boundary, including for tables that were never
     wrapped in .table-wrap (3 of the 5 CEO tables). */
  .data-table {
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    table-layout: auto;
  }
  /* any block that directly contains a table becomes a scroll boundary */
  .card:has(table),
  .card-body:has(table),
  .table-wrap,
  .table-responsive {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    max-width: 100% !important;
  }
  /* tables that genuinely need many columns keep a floor ONLY inside a
     real scroll container, so nothing is clipped without a way to reach it */
  .table-wrap > table,
  .table-responsive > table { min-width: 520px; }
}

/* ── 2. TABLET  769px – 1024px ───────────────────────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
  html, body { min-width: 0 !important; }

  .sidebar {
    width: 210px !important;
    min-width: 210px !important;
    display: flex !important;
    transform: none !important;
  }
  .main-content {
    margin-left: 210px !important;
    width: auto !important;
    min-width: 0 !important;
    flex: 1 1 0% !important;
  }

  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .dashboard-grid,
  .stats-grid,
  .cards-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }

  .sales-layout { grid-template-columns: 1fr !important; }
  .sales-layout .cart-panel {
    position: static !important;
    max-height: none !important;
    top: auto !important;
  }

  .content { padding: 20px 18px 32px !important; }

  canvas, .chart-container, .chart-box { max-width: 100% !important; }

  .card-header {
    flex-wrap: wrap !important;
    gap: 10px !important;
  }
  .card-header .ch-right,
  .header-actions,
  .inv-search-row {
    flex-wrap: wrap !important;
    min-width: 0 !important;
    max-width: 100% !important;
    justify-content: flex-end !important;
  }
  .inv-search-row form,
  .inv-search-form { min-width: 0 !important; max-width: 100% !important; }
  .inv-search-form input { min-width: 0 !important; }

  /* ── header/topbar filter forms ───────────────────────────────────────
     /profits overflows 88px at tablet. Measured cause: a <form> in
     .topbar-right with inline display:flex and no wrap, holding a date
     input with INLINE width:150px. Inline styles beat stylesheet rules
     unless the property itself is marked !important. */
  .topbar-right form,
  .card-header form,
  .header-actions form {
    flex-wrap: wrap !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }
  .topbar-right form .form-input,
  .topbar-right form .form-select,
  .topbar-right form input,
  .card-header form .form-input,
  .card-header form .form-select,
  .card-header form input {
    width: auto !important;
    min-width: 0 !important;
    max-width: 100% !important;
    flex: 1 1 96px !important;
  }

  .topbar { gap: 10px !important; padding: 0 14px !important; }
  .topbar .topbar-right { gap: 10px !important; min-width: 0 !important; }
  .topbar-search input { width: 150px !important; }
  .user-pill { min-width: 0 !important; max-width: none !important; flex: 0 1 auto !important; }
  .user-pill > div { min-width: 0 !important; }
  .user-pill .up-name,
  .user-pill .up-role { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 130px; }
}

/* ── 3. MOBILE  <= 768px ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  html, body {
    min-width: 0 !important;
    width: 100% !important;
    overflow-x: hidden !important;
  }

  .sidebar {
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    width: 82% !important;
    max-width: 320px !important;
    min-width: 0 !important;
    transform: translateX(-100%) !important;
    transition: transform .25s ease !important;
    z-index: 1200 !important;
    display: flex !important;
    box-shadow: 0 0 40px rgba(0,0,0,.34) !important;
  }
  body.mob-nav-open .sidebar { transform: translateX(0) !important; }

  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
    min-width: 0 !important;
    flex: 1 1 auto !important;
  }

  .content { padding: 14px 12px 90px !important; }

  .kpi-grid,
  .dashboard-grid,
  .stats-grid,
  .cards-grid,
  .form-grid,
  .filters,
  .report-grid { grid-template-columns: 1fr !important; }

  .sales-layout { grid-template-columns: 1fr !important; display: block !important; }
  .sales-layout .cart-panel {
    position: static !important;
    max-height: none !important;
    margin-top: 16px !important;
  }

  .card, .panel, .sidebar-card, .modal, .drawer {
    width: 100% !important;
    max-width: 100% !important;
  }

  .card-header { flex-wrap: wrap !important; gap: 10px !important; }
  .card-header .ch-right,
  .header-actions,
  .inv-search-row {
    flex-wrap: wrap !important;
    min-width: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    justify-content: flex-start !important;
  }
  .inv-search-row form,
  .inv-search-form { width: 100% !important; min-width: 0 !important; }
  .inv-search-form input { min-width: 0 !important; width: 100% !important; }

  canvas, .chart-container, .chart-box { max-width: 100% !important; height: auto !important; }

  /* chart bars: the label row was wider than its 143px container */
  .chart-bar { max-width: 100% !important; min-width: 0 !important; }
  .chart-bar > * { min-width: 0 !important; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  img { max-width: 100%; height: auto; }

  button, .btn, a.btn, input[type="submit"], select { min-height: 44px; }
  .btn-sm, button.small { min-height: 38px; }

  input, select, textarea, .form-control, .form-select, .form-input {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
  }

  td, th, .card, h1, h2, h3, p { overflow-wrap: anywhere; }

  .topbar { padding: 0 12px !important; min-height: 56px !important; gap: 8px !important; }
  .topbar .topbar-right { gap: 8px !important; min-width: 0 !important; }
  .topbar-search { display: none !important; }
  .user-pill { max-width: 130px !important; min-width: 0 !important; padding-right: 8px !important; }
  .user-pill > div:last-child,
  .user-pill .up-name { display: none !important; }

  /* style.css line 729 hides the phone chrome with !important:
       .mobile-appbar, .mobile-tabbar, .mobile-scrim, .mob-outlet-sheet
       { display: none !important; }
     On phones that must be undone. Only the PROPERTY that needs overriding is
     set here (display), with the same flex value mobile.css uses, so the
     element keeps its position:fixed / left:0 / right:0 from mobile.css.
     Do not add width or positioning here. */
  .mobile-appbar { display: flex !important; }
  .mobile-tabbar { display: flex !important; }
  .mobile-drawer-head { display: flex !important; }
}

/* ── 4. very small phones ────────────────────────────────────────────── */
@media (max-width: 390px) {
  .content { padding: 12px 10px 88px !important; }
  .kpi-grid { grid-template-columns: 1fr !important; }
  .btn { font-size: .84rem; padding: 10px 12px; }
  h1 { font-size: 1.18rem; } h2 { font-size: 1.05rem; }
  .mob-outlet-pill { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ── 5. LOGIN / AUTH PAGES ──────────────────────────────────────────────
   Measured on production at 390px: the showcase column was only 80px wide,
   its text had height 1206px and sat at y=-1629 (drawn far off-screen), and
   the capability row landed at y=2127 below the fold. The login panel
   itself was full-bleed at x=30 w=360, so the hero showed as a thin strip
   on the left behind it. Result: a broken, overlapping login page.

   Cause: the login layout's own responsive rules are inside the disabled
   "max-width: 1px" blocks in style.css (originally 920px and 720px). This
   block restores them with their real breakpoints. */

@media (max-width: 920px) {
  .investor-login .login-shell {
    grid-template-columns: minmax(0, 1.1fr) minmax(330px, .9fr) !important;
  }
  .investor-login .capability-row { grid-template-columns: 1fr !important; gap: 11px !important; }
  .investor-login .showcase-message h1 { font-size: 3rem !important; }
}

@media (max-width: 768px) {
  /* single column: hero becomes a full-bleed background, panel sits on top */
  .investor-login .login-shell {
    display: block !important;
    min-height: 100vh !important;
    position: relative !important;
    grid-template-columns: none !important;
  }
  .investor-login .login-showcase {
    position: fixed !important;
    inset: 0 !important;
    width: 100% !important;
    max-width: none !important;
    min-height: 100vh !important;
    z-index: 0 !important;
  }
  /* the hero's marketing copy is pointless behind a white panel: hide it */
  .investor-login .showcase-top,
  .investor-login .showcase-centre,
  .investor-login .showcase-bottom { display: none !important; }
  .investor-login .showcase-overlay {
    background: linear-gradient(145deg, rgba(2,54,32,.86), rgba(6,74,45,.72)) !important;
  }
  .investor-login .login-panel {
    position: relative !important;
    z-index: 1 !important;
    width: 100% !important;
    max-width: none !important;
    min-height: 100vh !important;
    padding: 28px 22px 24px !important;
    background: rgba(255,255,255,.96) !important;
  }
  .investor-login .login-panel-inner { margin: auto !important; width: 100% !important; max-width: 380px !important; }
  .investor-login .mobile-wordmark { display: block !important; }
  .investor-login .login-panel-footer { color: #627a6c !important; }
}

@media (max-width: 390px) {
  .investor-login .login-panel { padding-left: 18px !important; padding-right: 18px !important; }
}

/* ── 5. safety net ───────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .main-content > *,
  .content > * { max-width: 100%; }
  .topbar > * { min-width: 0; }
}
