/* ==========================================================================
   CMG Nexus — B2B Customer Portal · Responsive + Nexus-alignment layer
   Additive, override-only. Loads AFTER customer-portal-pro.css.
   Goals: (1) match the main Nexus shell type (Rajdhani), (2) make the whole
   portal 100% usable on phone + tablet — real mobile nav drawer, dense grids,
   no iOS focus-zoom. Remove this one <link> to fully revert.
   Requires a hamburger toggle in the topbar (customer-portal.php).
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Rajdhani:wght@500;600;700&display=swap');

/* ========== 1. Nexus type layer — same face the app shell uses =========== */
body.portal-shell,
body.portal-auth-shell {
  font-family: 'Rajdhani', 'Segoe UI', system-ui, sans-serif;
  font-weight: 550;
}
body.portal-shell *:not(svg):not(path):not(g):not([class*="mono"]),
body.portal-auth-shell *:not(svg):not(path):not(g):not([class*="mono"]) {
  font-family: 'Rajdhani', 'Segoe UI', system-ui, sans-serif;
}
body.portal-shell :is(code, pre, kbd, samp, [class*="mono"]) {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}
/* Condensed face reads tall — hold the display weight on headings. */
body.portal-shell :is(h1, h2, .portal-hero h1, .pt-head h1, .pd-h, .portal-brand-name),
body.portal-auth-shell :is(h1, h2) {
  font-weight: 700;
  letter-spacing: .005em;
}

/* ========== 2. Hamburger + drawer scaffolding (inert on desktop) ========= */
.portal-nav-cb { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.portal-nav-scrim { display: none; }
.portal-nav-burger {
  display: none;               /* shown only inside the touch breakpoint */
  width: 42px; height: 38px;
  flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer;
  border: 1px solid #dce7f0; border-radius: 10px; background: #eef4f9;
}
.portal-nav-burger span {
  display: block; width: 19px; height: 2px; margin: 2px 0;
  background: var(--pro-accent, #0f3d63); border-radius: 2px;
  transition: transform .2s ease, opacity .2s ease;
}

/* ========== 3. TOUCH LAYER — phones + tablet portrait (<=860px) ========== */
@media (max-width: 860px) {
  /* Keep the top bar a single row (base stylesheet stacks it into a column). */
  body.portal-shell .portal-topbar {
    flex-direction: row !important;
    align-items: center !important;
    height: 54px !important;
    padding: 0 14px !important;
    gap: 12px;
  }
  .portal-nav-burger { display: flex; }

  /* Nav → off-canvas right drawer (brand-dark, matches the app drawer). */
  body.portal-shell .portal-nav {
    position: fixed; top: 0; right: 0; z-index: 60;
    height: 100dvh; width: min(82vw, 320px);
    flex-direction: column; align-items: stretch; justify-content: flex-start;
    gap: 8px; padding: 68px 16px 24px;
    background: #0a2438;
    box-shadow: -24px 0 60px rgba(7, 24, 38, .40);
    transform: translateX(105%);
    transition: transform .26s cubic-bezier(.22, .61, .36, 1);
    overflow-y: auto;
  }
  .portal-nav-cb:checked ~ .portal-nav { transform: translateX(0); }
  .portal-nav-cb:checked ~ .portal-nav-scrim {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(6, 21, 33, .45);
  }

  /* Drawer links: full-width, generous tap targets, readable on dark. */
  body.portal-shell .portal-nav a,
  body.portal-shell .portal-nav button {
    width: 100%; min-height: 46px;
    justify-content: flex-start; text-align: left;
    padding: 0 14px !important; border-radius: 10px !important;
    font-size: 15px;
    color: #eaf2f8 !important;
    background: rgba(255, 255, 255, .06) !important;
    border: 1px solid rgba(255, 255, 255, .10) !important;
  }
  body.portal-shell .portal-nav a:hover,
  body.portal-shell .portal-nav button:hover {
    background: rgba(255, 255, 255, .14) !important;
    transform: none;
  }
  body.portal-shell .portal-nav form { width: 100%; margin-top: 4px; }
  body.portal-shell .portal-nav form button {
    background: rgba(220, 78, 78, .16) !important;
    border-color: rgba(220, 78, 78, .30) !important;
    color: #ffdada !important;
  }

  /* Burger morphs into a close (X) when the drawer is open. */
  .portal-nav-cb:checked ~ .portal-nav-burger span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  .portal-nav-cb:checked ~ .portal-nav-burger span:nth-child(2) { opacity: 0; }
  .portal-nav-cb:checked ~ .portal-nav-burger span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

  /* Hero: stack the title over the action row; actions fill the width. */
  body.portal-shell .portal-hero { flex-direction: column; align-items: stretch; gap: 12px; }
  body.portal-shell .portal-actions { flex-wrap: wrap; gap: 8px; }
  body.portal-shell .portal-actions > * {
    flex: 1 1 calc(50% - 4px);
    justify-content: center; text-align: center; min-height: 42px;
  }
  body.portal-shell .portal-actions > .portal-primary-action { flex-basis: 100%; }

  /* Metrics: two per row instead of the base one-per-row stack. */
  body.portal-shell .portal-metrics { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }

  /* Two-column content and form toolbars collapse to a single column. */
  body.portal-shell :is(.portal-grid, .portal-invoice-shell, .portal-quick-order, .portal-catalog-toolbar) {
    grid-template-columns: 1fr !important;
  }

  /* Sticky catalogue toolbar sits just under the 54px bar. */
  body.portal-shell .portal-catalog-toolbar { top: 58px !important; }

  /* Page side gutters. */
  body.portal-shell .portal-page { width: calc(100% - 24px) !important; }

  /* No iOS focus-zoom: every field ≥16px on touch. */
  body.portal-shell input, body.portal-shell select, body.portal-shell textarea,
  body.portal-auth-shell input, body.portal-auth-shell select, body.portal-auth-shell textarea {
    font-size: 16px !important;
  }

  /* Momentum scroll for the wide tables that scroll horizontally. */
  body.portal-shell .portal-table,
  body.portal-shell [style*="overflow-x"] { -webkit-overflow-scrolling: touch; }
}

/* ========== 4. PHONE (<=640px) — two-up product grids =================== */
@media (max-width: 640px) {
  body.portal-shell .portal-catalog { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
  body.portal-shell .portal-buy-again__list { grid-template-columns: repeat(2, 1fr) !important; }
  body.portal-shell .portal-item { padding: 10px; }
  body.portal-shell .portal-hero h1 { font-size: 20px; }
  /* Key/value detail pairs read denser two-up than the base one-per-row. */
  body.portal-shell .portal-detail-grid { grid-template-columns: repeat(2, 1fr) !important; }
  /* Supplier card: let the balance/button wrap under the identity cleanly. */
  body.portal-shell .portal-supplier-card { grid-template-columns: 42px minmax(0, 1fr); row-gap: 8px; }
  body.portal-shell .portal-supplier-balance { grid-column: 1 / -1; }
  body.portal-shell .portal-supplier-card > button { grid-column: 1 / -1; min-height: 42px; }
}

/* Narrow phones: every hero action full-width. */
@media (max-width: 400px) {
  body.portal-shell .portal-actions > * { flex-basis: 100%; }
}

/* ========== 5. TABLET PORTRAIT (641–860px) — three-up product grids ===== */
@media (min-width: 641px) and (max-width: 860px) {
  body.portal-shell .portal-catalog { grid-template-columns: repeat(3, 1fr) !important; }
  body.portal-shell .portal-buy-again__list { grid-template-columns: repeat(3, 1fr) !important; }
  body.portal-shell .portal-metrics { grid-template-columns: repeat(4, 1fr) !important; }
  body.portal-shell .portal-detail-grid { grid-template-columns: repeat(3, 1fr) !important; }
}

/* ========== 6. TABLET LANDSCAPE (861–1180px) — comfortable density ====== */
@media (min-width: 861px) and (max-width: 1180px) {
  body.portal-shell .portal-catalog { grid-template-columns: repeat(3, 1fr); }
}

/* Respect reduced-motion for the drawer + hover lifts. */
@media (prefers-reduced-motion: reduce) {
  body.portal-shell .portal-nav,
  body.portal-shell .portal-nav-burger span { transition: none !important; }
}
