/* =============================================
   DIGITALSTORE - Mobile-First Responsive CSS
   Covers: 320px → 768px → 1024px → 1280px+
   ============================================= */

/* =============================================
   RESET & BASE MOBILE
   ============================================= */
html { font-size: 15px; }

@media (max-width: 768px) {
  html { font-size: 14px; }
}

/* =============================================
   MOBILE NAVBAR
   ============================================= */
@media (max-width: 768px) {
  .navbar {
    padding: 0 1rem;
    height: 56px;
  }

  .nav-menu { display: none !important; }

  .nav-brand .brand-text { font-size: 1.2rem; }

  .nav-actions {
    gap: 0.5rem;
  }

  .nav-actions > a:not(.nav-cart),
  .nav-actions > .btn { display: none; }

  .nav-cart {
    width: 36px;
    height: 36px;
  }

  .nav-user > span { display: none; }

  .nav-user .dropdown-menu {
    right: -1rem;
    width: 220px;
  }
}

/* =============================================
   MOBILE BOTTOM NAVIGATION BAR
   ============================================= */
.mobile-bottom-nav {
  display: none;
}

@media (max-width: 768px) {
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 999;
    background: rgba(10, 10, 18, 0.95);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    height: 60px;
    align-items: stretch;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .mob-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: var(--text-xs);
    font-weight: 600;
    transition: var(--transition);
    position: relative;
    cursor: pointer;
    background: none;
    border: none;
  }

  .mob-nav-item .mob-icon {
    font-size: 1.25rem;
    line-height: 1;
  }

  .mob-nav-item.active {
    color: var(--accent-1);
  }

  .mob-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20%;
    right: 20%;
    height: 2px;
    background: var(--gradient-main);
    border-radius: 0 0 4px 4px;
  }

  .mob-nav-badge {
    position: absolute;
    top: 4px;
    right: calc(50% - 18px);
    width: 16px;
    height: 16px;
    background: var(--accent-3);
    color: white;
    border-radius: 50%;
    font-size: 0.55rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Push content above bottom nav */
  body { padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px)); }
  .footer { margin-bottom: 0; }
}

/* =============================================
   MOBILE SIDEBAR OVERLAY
   ============================================= */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 300;
    box-shadow: none;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 40px rgba(0, 0, 0, 0.6);
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 299;
    backdrop-filter: blur(3px);
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
  }

  .sidebar-overlay.show {
    opacity: 1;
    visibility: visible;
  }

  .main-content {
    margin-left: 0 !important;
  }

  .page-header,
  .page-content {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }

  /* Mobile admin top bar */
  .mobile-admin-topbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .mob-menu-btn {
    width: 36px;
    height: 36px;
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-secondary);
    flex-shrink: 0;
  }
}

@media (min-width: 769px) {
  .mobile-admin-topbar { display: none; }
}

/* =============================================
   GRIDS - Mobile-First
   ============================================= */

/* Default mobile: 1 column */
.grid-2,
.grid-3,
.grid-4 {
  display: grid;
  gap: 1rem;
}

.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: 1fr 1fr; }

/* Tablet: 2 columns */
@media (min-width: 576px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* Desktop: full columns */
@media (min-width: 1024px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
  .grid-2, .grid-3, .grid-4 { gap: 1.5rem; }
}

/* =============================================
   HERO SECTION - Mobile
   ============================================= */
@media (max-width: 768px) {
  .hero {
    grid-template-columns: 1fr !important;
    padding: 2rem 1rem 3rem;
    min-height: auto;
    padding-top: 80px;
  }

  .hero > div:last-child { display: none; } /* Hide hero card on mobile */

  .hero-title { font-size: clamp(2rem, 8vw, 2.8rem); letter-spacing: -0.5px; }
  .hero-desc { font-size: 0.9rem; }

  .hero-actions {
    flex-direction: column;
    gap: 0.75rem;
  }

  .hero-actions .btn { width: 100%; justify-content: center; }

  .hero-stats {
    gap: 1.5rem;
    margin-top: 2rem;
  }

  .stat-number { font-size: 1.6rem; }
}

/* =============================================
   PRODUCT CARDS - Mobile
   ============================================= */
@media (max-width: 576px) {
  .product-info { padding: 0.85rem; }
  .product-name { font-size: 0.85rem; }
  .price-current { font-size: 1rem; }
  .product-meta { gap: 0.5rem; font-size: 0.72rem; }
  .btn-add-cart { width: 30px; height: 30px; font-size: 0.9rem; }

  /* 2-col product grid on mobile */
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
  }
}

/* =============================================
   CATEGORY PILLS - Mobile Scroll
   ============================================= */
@media (max-width: 768px) {
  .category-grid {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    gap: 0.5rem;
  }

  .category-grid::-webkit-scrollbar { display: none; }

  .category-pill {
    flex-shrink: 0;
    scroll-snap-align: start;
    font-size: 0.78rem;
    padding: 0.45rem 0.9rem;
  }
}

/* =============================================
   SECTION SPACING - Mobile
   ============================================= */
@media (max-width: 768px) {
  .section { padding: 2.5rem 0; }
  .container { padding: 0 1rem; }
  .section-title { font-size: clamp(1.4rem, 5vw, 2rem); letter-spacing: -0.5px; }
  .section-header { margin-bottom: 1.5rem; }
  .section-header .btn { font-size: 0.75rem; padding: 0.4rem 0.85rem; }
}

/* =============================================
   CARDS - Mobile
   ============================================= */
@media (max-width: 768px) {
  .card-body { padding: 1rem; }
  .card-header { padding: 0.85rem 1rem; flex-wrap: wrap; gap: 0.5rem; }
  .stat-card { padding: 1rem; }
  .stat-value { font-size: 1.5rem; }
}

/* =============================================
   FORMS - Mobile
   ============================================= */
@media (max-width: 768px) {
  .form-control {
    font-size: 16px; /* Prevent iOS zoom */
    padding: 0.7rem 0.9rem;
  }

  .btn-lg {
    padding: 0.8rem 1.5rem;
    font-size: 0.95rem;
  }
}

/* =============================================
   TABLE - Mobile Scroll
   ============================================= */
@media (max-width: 768px) {
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table { min-width: 600px; }

  /* Hide less important columns on mobile */
  .hide-mobile { display: none; }
}

/* =============================================
   PRODUCT DETAIL - Mobile
   ============================================= */
@media (max-width: 768px) {
  .product-detail-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem;
  }

  .purchase-card {
    position: fixed !important;
    bottom: 60px !important;
    left: 0;
    right: 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0 !important;
    padding: 1rem !important;
    z-index: 200;
    box-shadow: 0 -8px 40px rgba(0,0,0,0.5);
    border-left: none !important;
    border-right: none !important;
    border-bottom: none !important;
    max-height: 80vh;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .purchase-card.open {
    transform: translateY(0);
  }

  .purchase-card-toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    position: fixed;
    bottom: 60px;
    left: 0;
    right: 0;
    z-index: 201;
    background: var(--bg-card);
    border-top: 1px solid var(--border-accent);
    padding: 0.75rem 1rem;
  }

  .purchase-card-toggle .price { font-family: var(--font-body); font-size: 1.2rem; font-weight: 800; background: var(--gradient-text); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
}

@media (min-width: 769px) {
  .purchase-card-toggle { display: none; }
}

/* =============================================
   AUTH PAGES - Mobile
   ============================================= */
@media (max-width: 576px) {
  .auth-card { padding: 1.5rem; border-radius: var(--radius-lg); }
  .auth-container { padding: 1rem; }
}

/* =============================================
   FOOTER - Mobile
   ============================================= */
@media (max-width: 768px) {
  .footer-grid {
    grid-template-columns: 1fr !important;
    gap: 1.5rem;
  }

  .footer { padding: 2.5rem 0 1.5rem; }

  .footer-bottom {
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
  }
}

/* =============================================
   DASHBOARD PAGES - Mobile
   ============================================= */
@media (max-width: 768px) {
  /* Admin grid stats */
  .stat-row,
  .grid-4.stat-row { grid-template-columns: repeat(2, 1fr) !important; gap: 0.65rem; }

  /* User dashboard */
  .usr-grid { grid-template-columns: repeat(2, 1fr) !important; }

  /* Page headers */
  .page-title { font-size: 1.4rem; }
  .page-subtitle { font-size: 0.8rem; }
}

/* =============================================
   MODAL - Mobile Full Screen
   ============================================= */
@media (max-width: 576px) {
  .modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 95vh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0 !important;
    position: fixed;
    bottom: 0;
  }

  .modal-overlay {
    align-items: flex-end;
  }

  .modal-overlay.active .modal {
    transform: scale(1) translateY(0) !important;
  }
}

/* =============================================
   SEARCH - Mobile
   ============================================= */
@media (max-width: 768px) {
  .search-bar .form-control { width: 100%; }

  /* Products page sidebar → drawer */
  .products-layout {
    grid-template-columns: 1fr !important;
  }

  .filter-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 400;
    overflow-y: auto;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    padding: 1rem;
    padding-top: 4rem;
  }

  .filter-sidebar.open { transform: translateX(0); }

  .filter-toggle-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--text-secondary);
    margin-bottom: 1rem;
  }
}

@media (min-width: 769px) {
  .filter-toggle-btn { display: none; }
  .products-layout { display: grid; grid-template-columns: 240px 1fr; gap: 2rem; align-items: start; }
  .filter-sidebar { position: static; transform: none; width: auto; background: transparent; border: none; padding: 0; }
}

/* =============================================
   CART - Mobile
   ============================================= */
@media (max-width: 768px) {
  .cart-layout {
    grid-template-columns: 1fr !important;
  }

  .cart-summary-mobile {
    position: fixed;
    bottom: 60px;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border-accent);
    padding: 0.85rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 200;
  }
}

@media (min-width: 769px) {
  .cart-summary-mobile { display: none !important; }
}

/* =============================================
   CHAT - Mobile Full Screen
   ============================================= */
@media (max-width: 768px) {
  .chat-layout {
    grid-template-columns: 1fr !important;
  }

  .rooms-panel {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 500;
    width: 100% !important;
  }

  .rooms-panel.mobile-show { display: block; }
}

/* =============================================
   TOASTS - Mobile
   ============================================= */
@media (max-width: 576px) {
  .toast-container {
    bottom: calc(60px + 1rem);
    right: 0.75rem;
    left: 0.75rem;
  }

  .toast { min-width: auto; }
}

/* =============================================
   FLASH BANNER - Mobile
   ============================================= */
@media (max-width: 576px) {
  #flashBanner { padding: 0.4rem 2rem 0.4rem 0.5rem; font-size: 0.75rem; }
  #flashBanner a { flex-wrap: wrap; gap: 0.3rem; font-size: 0.75rem; }
}

/* =============================================
   PAGINATION - Mobile
   ============================================= */
@media (max-width: 576px) {
  .pagination { gap: 0.35rem; }
  .page-btn { width: 34px; height: 34px; font-size: 0.8rem; }
}

/* =============================================
   STATS ROW (admin) - Mobile
   ============================================= */
@media (max-width: 576px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); gap: 0.65rem; }
}

/* =============================================
   TOUCH OPTIMIZATIONS
   ============================================= */
@media (hover: none) {
  /* Remove hover states that don't work on touch */
  .product-card:hover { transform: none; }
  .btn:hover::before { opacity: 0; }

  /* Larger touch targets */
  .btn, .form-control, .sidebar-link, .mob-nav-item {
    min-height: 44px;
  }

  /* Active states instead of hover */
  .product-card:active { transform: scale(0.98); box-shadow: var(--shadow-glow); }
  .btn:active { transform: scale(0.97) !important; }
}

/* =============================================
   UTILITY CLASSES
   ============================================= */
.hide-mobile { }
.show-mobile { display: none; }

@media (max-width: 768px) {
  .hide-mobile { display: none !important; }
  .show-mobile { display: block !important; }
  .show-mobile-flex { display: flex !important; }
  .mobile-full { grid-column: 1 / -1; }
  .mobile-p-1 { padding: 0.5rem !important; }
  .mobile-text-sm { font-size: 0.8rem !important; }
}

/* =============================================
   PULL-TO-REFRESH INDICATOR
   ============================================= */
.ptr-indicator {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%) translateY(-60px);
  background: var(--accent-1);
  color: white;
  padding: 0.4rem 1rem;
  border-radius: 0 0 var(--radius-full) var(--radius-full);
  font-size: 0.8rem;
  font-weight: 700;
  z-index: 1000;
  transition: transform 0.3s ease;
}

/* =============================================
   SWIPEABLE CARDS
   ============================================= */
.swipe-container {
  overflow-x: auto;
  display: flex;
  gap: 0.75rem;
  padding-bottom: 0.75rem;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}

.swipe-container::-webkit-scrollbar { display: none; }

.swipe-card {
  flex-shrink: 0;
  scroll-snap-align: start;
}

@media (min-width: 769px) {
  .swipe-container {
    overflow-x: visible;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    flex-wrap: wrap;
  }
  .swipe-card { flex-shrink: 1; }
}

/* =============================================
   SUBSCRIPTION CARDS - Mobile
   ============================================= */
@media (max-width: 768px) {
  .plan-cards-grid {
    grid-template-columns: 1fr !important;
    max-width: 400px;
    margin: 0 auto;
  }
}

/* =============================================
   VENDOR STORE - Mobile
   ============================================= */
@media (max-width: 768px) {
  .vendor-store-header {
    flex-direction: column;
    text-align: center;
  }

  .vendor-store-header img {
    margin: 0 auto;
  }
}

/* =============================================
   SAFE AREA (iPhone notch)
   ============================================= */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .mobile-bottom-nav {
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(60px + env(safe-area-inset-bottom));
  }
}
