/* ═══════════════════════════════════════════════════════════
   RESPONSIVE.CSS — Sanraj Supplier Hub
   Mobile-First Breakpoint System
   Breakpoints: 320 | 480 | 768 | 1024 | 1440
   Decision: Tables → horizontal scroll with momentum (no card transform)
   ═══════════════════════════════════════════════════════════ */

/* ── 0. BASE OVERFLOW PROTECTION ── */
html {
  overflow-x: hidden;
  width: 100%;
}
body {
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

/* ── 1. APP SHELL — MOBILE FOUNDATION ── */

/* On mobile: the app uses full-width single column */
#app {
  display: none; /* JS shows it */
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

/* App body: sidebar + main. Mobile = 1 col */
.app-body {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
  position: relative;
}

/* ── 2. SIDEBAR DRAWER — MOBILE ── */

@media (max-width: 767px) {
  /* Sidebar becomes an off-canvas drawer */
  .sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    height: 100vh !important;
    width: 280px !important;
    min-width: unset !important;
    z-index: 1000 !important;
    transform: translateX(-100%) !important;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15) !important;
  }

  .sidebar.mobile-open {
    transform: translateX(0) !important;
  }

  /* Overlay backdrop */
  .sb-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
  }
  .sb-overlay.open {
    display: block;
    opacity: 1;
  }

  /* App body goes full width — sidebar is out of normal flow */
  .app-body {
    grid-template-columns: 1fr !important;
    height: calc(100vh - var(--header-h));
  }

  /* Main content: full width */
  .main-content {
    grid-column: 1 !important;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }
}

/* ── 3. TOPNAV — MOBILE LAYOUT ── */

@media (max-width: 767px) {
  .topnav {
    padding: 0 12px !important;
    gap: 8px !important;
    height: var(--header-h) !important;
    display: flex !important;
    align-items: center !important;
  }

  /* Show hamburger */
  .hamburger {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    font-size: 20px;
    padding: 0 !important;
    flex-shrink: 0;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.15s;
  }
  .hamburger:hover,
  .hamburger:active {
    background: rgba(0, 0, 0, 0.05);
  }

  /* Logo area: no fixed width, no border */
  .topnav-logo {
    flex: 1 !important;
    width: auto !important;
    min-width: 0 !important;
    border-right: none !important;
    padding: 0 8px !important;
    height: auto !important;
  }

  /* Hide "Growth Panel" label text on mobile */
  .topnav-logo > div > div[style*="Growth Panel"] {
    display: none !important;
  }

  /* Hide search center bar on mobile */
  .topnav-center {
    display: none !important;
  }

  /* Right icons: compact */
  .topnav-right {
    gap: 4px !important;
    padding: 0 !important;
    flex-shrink: 0;
  }

  /* Hide profile name text on mobile */
  .profile-name-sm {
    display: none !important;
  }

  /* Nav icon buttons: touch-friendly */
  .nav-icon-btn {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px;
    flex-shrink: 0;
  }

  /* Profile pill: compact */
  .profile-pill {
    padding: 5px !important;
    gap: 0 !important;
  }
}

/* ── 4. MAIN CONTENT & PAGE LAYOUT ── */

@media (max-width: 767px) {
  .main-content {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden;
  }

  .page {
    padding: 16px !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }

  .pg-hdr {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 12px !important;
    margin-bottom: 16px !important;
  }

  .pg-hdr > div:last-child {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .pg-hdr > div:last-child button,
  .pg-hdr > div:last-child select {
    flex: 1;
    min-width: 120px;
  }

  .pg-title {
    font-size: clamp(16px, 4.5vw, 22px) !important;
  }
}

/* ── 5. STATS GRIDS — RESPONSIVE ── */

/* Mobile default: 1 column */
.stats-row,
.grid-4,
.pay-sum-grid {
  grid-template-columns: 1fr !important;
}

/* 480px+: 2 columns */
@media (min-width: 480px) {
  .stats-row,
  .grid-4,
  .pay-sum-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* 1024px+: 4 columns (desktop) */
@media (min-width: 1024px) {
  .stats-row,
  .grid-4,
  .pay-sum-grid {
    grid-template-columns: repeat(4, 1fr) !important;
  }
}

/* Stat cards: always full width of their grid cell */
.stat-card,
.pay-card {
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box;
  min-width: 0 !important;
}

/* ── 6. PAGE-SPECIFIC LAYOUTS ── */

/* Home layout: 2-col desktop → 1-col mobile */
.home-layout,
.grid-2-1 {
  grid-template-columns: 1fr !important;
}

@media (min-width: 1024px) {
  .home-layout {
    grid-template-columns: 1fr 300px !important;
  }
  .grid-2-1 {
    grid-template-columns: 2fr 1fr !important;
  }
}

/* Analytics / Growth 2fr 1fr panels */
@media (max-width: 767px) {
  /* Any inline grid-template-columns: 2fr 1fr */
  .home-main,
  .home-side {
    width: 100% !important;
    min-width: 0 !important;
  }
}

/* Three-column grids */
.three-col {
  grid-template-columns: 1fr !important;
}
@media (min-width: 480px) {
  .three-col {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}
@media (min-width: 1024px) {
  .three-col {
    grid-template-columns: repeat(3, 1fr) !important;
  }
}

/* Support grid */
.support-grid {
  grid-template-columns: 1fr !important;
}
@media (min-width: 768px) {
  .support-grid {
    grid-template-columns: 1fr 1fr !important;
  }
}

/* Form row (2 columns) */
.form-row,
.form-row-2 {
  grid-template-columns: 1fr !important;
}
@media (min-width: 768px) {
  .form-row,
  .form-row-2 {
    grid-template-columns: 1fr 1fr !important;
  }
}

/* Promo grid inside growth page */
.promo-grid {
  grid-template-columns: 1fr !important;
}
@media (min-width: 480px) {
  .promo-grid {
    grid-template-columns: 1fr 1fr !important;
  }
}

/* ── 7. CARDS — FULL WIDTH ON MOBILE ── */

@media (max-width: 767px) {
  .card {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    padding: 14px !important;
  }

  .insight-card {
    width: 100% !important;
    min-width: 0 !important;
  }
}

/* ── 8. TABLES — HORIZONTAL SCROLL WITH MOMENTUM ── */

/* Wrap all table containers for scrolling */
.tbl-wrap {
  width: 100% !important;
  overflow: hidden !important;
  box-sizing: border-box;
}

.tbl-scroll {
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch; /* iOS momentum scroll */
  scroll-snap-type: x proximity;
}

/* Ensure the table itself has a minimum width so columns don't squeeze */
.tbl-scroll table,
.tbl-wrap table {
  min-width: 560px;
}

/* Visual scroll hint: subtle fade on the right edge */
@media (max-width: 767px) {
  .tbl-wrap {
    position: relative;
  }

  /* Scroll indicator on orders/inventory tables */
  .tbl-scroll {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px; /* room for scrollbar */
  }

  /* Tabs: horizontal scroll, no wrap */
  .m-tabs {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap !important;
    flex-wrap: nowrap !important;
    padding-bottom: 0;
    scrollbar-width: none; /* Firefox */
  }
  .m-tabs::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
  }
  .m-tab {
    flex-shrink: 0 !important;
    white-space: nowrap;
    padding: 10px 14px !important;
  }
}

/* ── 9. FILTER BAR — MOBILE STACK ── */

@media (max-width: 767px) {
  .m-filters {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
    padding: 12px !important;
  }

  .m-filters > div[style*="width: 250px"],
  .m-filters > div[style*="position: relative; width"] {
    width: 100% !important;
    min-width: 0 !important;
  }

  .m-filters input[type="text"] {
    width: 100% !important;
    min-width: 0 !important;
  }

  .m-filters .m-select {
    width: 100% !important;
  }

  /* "flex: 1" spacer divs: collapse on mobile */
  .m-filters > div[style="flex:1"] {
    display: none !important;
  }
}

/* ── 10. DROPDOWNS — CONSTRAIN TO VIEWPORT ── */

@media (max-width: 767px) {
  .notif-box,
  .dropdown-notif {
    width: min(320px, calc(100vw - 24px)) !important;
    right: 0 !important;
    left: auto !important;
  }

  .profile-drop {
    width: min(220px, calc(100vw - 24px)) !important;
    right: 0 !important;
    left: auto !important;
  }
}

/* ── 11. MODALS — MOBILE SAFE ── */

@media (max-width: 767px) {
  .modal-bg {
    padding: 12px !important;
    align-items: flex-end !important; /* bottom sheet feel */
  }

  .modal {
    max-width: 100% !important;
    width: 100% !important;
    border-radius: 18px 18px 0 0 !important;
    max-height: 92vh !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    padding: 20px !important;
  }
}

/* ── 12. FORMS — MOBILE OPTIMIZED ── */

@media (max-width: 767px) {
  .form-input,
  .form-select,
  .m-select {
    font-size: 16px !important; /* Prevent iOS zoom on focus */
    min-height: 46px !important;
  }

  .btn,
  .btn-orange,
  .btn-green,
  .btn-outline,
  .btn-primary {
    min-height: 44px;
    font-size: 14px;
  }

  .nav-item {
    min-height: 44px !important;
  }
}

/* ── 13. UPLOAD WIZARD — MOBILE ── */

@media (max-width: 767px) {
  .upload-wizard {
    max-width: 100% !important;
    margin: 0 !important;
    width: 100% !important;
  }

  .wizard-step {
    padding: 16px !important;
    margin-bottom: 16px !important;
    border-radius: 12px !important;
  }

  .drag-drop-zone {
    padding: 24px 16px !important;
  }

  /* Stepper: compact on mobile */
  .v-stepper {
    padding: 0 4px !important;
    margin-bottom: 20px !important;
  }

  .v-step-lbl {
    font-size: 9px !important;
  }
}

/* ── 14. CATEGORY SELECTOR (MEESHO-STYLE) ── */

@media (max-width: 767px) {
  .meesho-cat-container {
    flex-direction: column !important;
    height: auto !important;
    max-height: none !important;
  }

  .meesho-cat-col {
    min-width: unset !important;
    width: 100% !important;
    border-right: none !important;
    border-bottom: 1px solid var(--border) !important;
    max-height: 180px !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .meesho-cat-col:last-child {
    border-bottom: none !important;
  }

  .cat-card-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    padding: 12px !important;
    gap: 10px !important;
  }

  .cat-card {
    padding: 12px 8px !important;
    min-height: 80px !important;
  }

  .cat-icon {
    width: 50px !important;
    height: 50px !important;
    line-height: 50px !important;
    font-size: 26px !important;
    margin-bottom: 8px !important;
  }

  .cat-name {
    font-size: 12px !important;
  }

  .cat-search-box {
    padding: 12px 16px !important;
    margin-bottom: 12px !important;
  }
}

/* ── 15. PROFILE / SETTINGS SPLIT LAYOUT ── */

@media (max-width: 767px) {
  .meesho-split-layout {
    grid-template-columns: 1fr !important;
    max-height: none !important;
    overflow: visible !important;
    gap: 16px !important;
  }

  .meesho-sidebar-menu {
    position: static !important;
    border-radius: 10px !important;
    padding: 8px 0 !important;
  }

  /* Horizontal tabs on mobile for the menu */
  .meesho-sidebar-menu {
    display: flex !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    gap: 0;
    white-space: nowrap;
    border-radius: 10px !important;
    padding: 8px !important;
    scrollbar-width: none;
    flex-direction: row !important;
  }
  .meesho-sidebar-menu::-webkit-scrollbar {
    display: none;
  }

  .meesho-menu-item {
    border-left: none !important;
    border-bottom: 3px solid transparent !important;
    padding: 10px 14px !important;
    flex-shrink: 0 !important;
    font-size: 12px !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 4px !important;
    border-radius: 8px !important;
  }

  .meesho-menu-item.active {
    border-left-color: transparent !important;
    border-bottom-color: var(--orange2) !important;
    background: #fff8f5 !important;
  }

  .meesho-menu-item svg {
    width: 18px !important;
    height: 18px !important;
  }

  .meesho-content-pane {
    max-height: none !important;
    overflow-y: visible !important;
    padding: 16px !important;
    border-radius: 10px !important;
  }
}

/* ── 16. HOME PAGE WELCOME BANNER ── */

@media (max-width: 767px) {
  /* Progress tracker steps: vertical on very small screens */
  #page-home > div:first-child {
    flex-direction: column !important;
    gap: 12px !important;
    align-items: flex-start !important;
  }

  #page-home > div:first-child > div:last-child {
    align-self: flex-end;
  }
}

/* ── 17. HOME PAGE: Progress tracker 3-step row ── */

@media (max-width: 479px) {
  /* The 3-step flex row in home page progress card */
  div[style*="display: flex; border-bottom: 1px solid"] {
    flex-direction: column !important;
  }
}

/* ── 18. STICKY VERIFY BAR ── */

@media (max-width: 767px) {
  .sticky-verify-bar {
    margin: -16px -16px 16px !important;
    padding: 10px 16px !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
}

/* ── 19. LEGAL MODAL ── */

@media (max-width: 767px) {
  .legal-overlay-modal {
    padding: 0 !important;
    align-items: flex-end !important;
  }

  .legal-modal-content {
    max-width: 100% !important;
    border-radius: 20px 20px 0 0 !important;
    max-height: 85vh !important;
  }
}

/* ── 20. TOAST — BOTTOM CENTER ON MOBILE ── */

@media (max-width: 767px) {
  #toast-container {
    bottom: 16px !important;
    right: 12px !important;
    left: 12px !important;
    align-items: stretch !important;
  }

  .toast {
    min-width: unset !important;
    max-width: 100% !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }
}

/* ── 21. OTP BOXES — MOBILE SCALE ── */

@media (max-width: 479px) {
  .otp-box {
    width: 44px !important;
    height: 52px !important;
    font-size: 1.2rem !important;
  }
  .otp-inputs {
    gap: 8px !important;
  }
}

/* ── 22. AUTH PAGE — MOBILE ── */

@media (max-width: 479px) {
  #auth-page {
    padding: 16px !important;
    padding-top: 24px !important;
  }

  .auth-card,
  #auth-card-container {
    padding: 24px 16px !important;
    border-radius: 12px !important;
  }

  /* Full-width auth card below 480px */
  #auth-card-container {
    max-width: 100% !important;
  }

  /* Switcher section below auth card */
  div[style*="max-width: 420px"] {
    max-width: 100% !important;
  }
}

/* ── 23. INLINE GRID OVERRIDES (target anonymous inline grids) ── */

@media (max-width: 767px) {
  /* Business Insights 2-col grid inside dashboard card */
  div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Any 2fr 1fr analytics/growth grid */
  div[style*="grid-template-columns: 2fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Any explicit 260px sidebar grid (settings) */
  div[style*="grid-template-columns: 260px"] {
    grid-template-columns: 1fr !important;
  }
}

/* ── 24. SPECIFIC FIXED-WIDTH OVERRIDES ── */

@media (max-width: 767px) {
  /* Orders search input */
  #page-orders div[style*="width: 250px"],
  #page-inventory div[style*="width: 250px"] {
    width: 100% !important;
    min-width: 0 !important;
  }

  /* Growth panel label in topnav */
  div[style*="Growth Panel"] {
    display: none !important;
  }

  /* Page header action buttons: full width stack */
  .pg-hdr button {
    padding: 8px 14px !important;
    font-size: 12px !important;
    white-space: nowrap;
  }

  /* Bar chart: ensure it doesn't overflow */
  .bar-chart {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Grid-specific inline styles override */
  .stats-row[style*="grid-template-columns"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

@media (max-width: 374px) {
  .stats-row,
  .grid-4,
  .pay-sum-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ── 25. CATALOG GRID — RESPONSIVE ── */

@media (max-width: 767px) {
  .cat-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
    margin-top: 16px !important;
  }

  .cat-card {
    padding: 16px 12px !important;
    min-height: 80px !important;
  }
}

@media (max-width: 374px) {
  .cat-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ── 26. TABLET REFINEMENTS (768px – 1023px) ── */

@media (min-width: 768px) and (max-width: 1023px) {
  .stats-row,
  .grid-4 {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .home-layout {
    grid-template-columns: 1fr !important;
  }

  .page {
    padding: 20px !important;
  }

  /* Sidebar: show permanently on tablet */
  .sidebar {
    position: fixed !important;
    transform: translateX(0) !important;
  }

  .app-body {
    grid-template-columns: var(--sidebar-w) 1fr !important;
  }

  .hamburger {
    display: none !important;
  }
}

/* ── 27. DESKTOP (1024px+) ── */

@media (min-width: 1024px) {
  .app-body {
    grid-template-columns: var(--sidebar-w) 1fr;
  }

  .hamburger {
    display: none !important;
  }

  .sidebar {
    position: fixed !important;
    transform: translateX(0) !important;
  }

  /* Sidebar collapsed state */
  .app-body.sidebar-collapsed {
    grid-template-columns: var(--sidebar-w-collapsed) 1fr;
  }
}

/* ── 28. MISC UTILITY OVERRIDES ── */

/* Ensure no element can cause horizontal overflow */
* {
  max-width: 100%;
}

/* Exception: allow tables to be wider than parent (scroll handles it) */
table {
  max-width: none;
}

/* Images always responsive */
img {
  max-width: 100%;
  height: auto;
  object-fit: contain;
}

/* Prevent white-space: nowrap overflow on small elements */
@media (max-width: 479px) {
  .breadcrumb {
    flex-wrap: wrap !important;
    gap: 4px !important;
  }
}

/* ── 29. SCROLLBAR STYLING FOR HORIZONTAL TABLES ── */

/* Show thin scrollbar on table containers (UX signal) */
.tbl-scroll::-webkit-scrollbar {
  height: 4px;
}
.tbl-scroll::-webkit-scrollbar-track {
  background: var(--gray-100, #f3f4f6);
  border-radius: 4px;
}
.tbl-scroll::-webkit-scrollbar-thumb {
  background: var(--primary, #F5A623);
  border-radius: 4px;
}
