/* ========================================
   PRODUCTS PAGE MOBILE v5.0
   Modern eMAG-inspired mobile layout
   Clean, slick, intuitive design
   ======================================== */

/* ========== TABLETS (max 1024px) ========== */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 280px;
  }

  .products-section {
    margin-right: 0; /* Sidebar collapsed by default, no margin needed */
    padding: 1rem;
  }

  /* When sidebar is expanded on tablet */
  body:has(.filters-sidebar.expanded) .products-section {
    margin-right: var(--sidebar-width, 280px);
  }
}

/* ========== MOBILE BREAKPOINT (max 900px) ========== */
@media (max-width: 900px) {
  .products-section {
    margin-right: 0 !important;
    /* navbar (60px) + category bar (52px) + small gap */
    margin-top: 120px !important;
    padding: 1rem;
    padding-bottom: 100px;
    overflow-x: hidden;
    background: var(--bg-secondary, #f5f5f5);
  }

  /* Products grid - 2 columns */
  .products-grid,
  #productsGrid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.75rem;
  }

  /* Grouped view - vertical stack of categories */
  .products-grid.grouped-view,
  #productsGrid.grouped-view {
    display: flex !important;
    flex-direction: column !important;
    gap: 1.5rem !important;
  }

  /* ===== CATEGORY SECTIONS - CLEAN DESIGN ===== */
  .category-section {
    background: var(--bg-card, #fff);
    border-radius: 16px;
    padding: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  }

  .category-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color, rgba(0,0,0,0.06));
  }

  .category-header i {
    font-size: 1.25rem;
    color: var(--bs-primary, #e02020);
    background: rgba(224, 32, 32, 0.1);
    padding: 0.5rem;
    border-radius: 10px;
    flex-shrink: 0;
  }

  .category-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    flex: 1;
  }

  .category-header .product-count {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg-secondary, #f5f5f5);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-weight: 500;
  }

  /* Hide slider nav buttons on mobile */
  .category-nav-buttons {
    display: none !important;
  }

  /* ===== PRODUCTS GRID INSIDE CATEGORY - 2 COLUMNS ===== */
  .category-products {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.75rem !important;
    overflow: visible !important;
    padding: 0 !important;
  }

  /* ===== PRODUCT CARDS - MODERN CLEAN DESIGN ===== */
  .product-card,
  .category-products .product-card {
    flex: unset !important;
    width: 100% !important;
    min-width: unset !important;
    max-width: 100% !important;
    background: var(--bg-card, #fff);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border-color, rgba(0,0,0,0.08));
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.2s ease;
  }

  .product-card:active {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }

  /* Image container - clean white background */
  .product-image-container,
  .category-products .product-card .product-image-container {
    height: 150px !important;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem;
    position: relative;
  }

  .product-image {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
  }

  /* Card body */
  .product-card-body,
  .category-products .product-card .product-card-body {
    padding: 0.875rem !important;
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 0.25rem;
  }

  /* Brand label */
  .product-brand {
    font-size: 0.65rem;
    color: var(--bs-primary, #e02020);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
  }

  /* Title - readable, 2 lines */
  .product-title,
  .category-products .product-card .product-title {
    font-size: 0.875rem !important;
    font-weight: 600;
    line-height: 1.35;
    color: var(--text-primary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 0.5rem;
    min-height: 2.4em;
  }

  /* Hide description on mobile */
  .product-description,
  .category-products .product-card .product-description {
    display: none !important;
  }

  /* Footer - price and button */
  .product-footer,
  .category-products .product-card .product-footer {
    margin-top: auto;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color, rgba(0,0,0,0.06));
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
  }

  /* Price - prominent and clear */
  .product-price,
  .category-products .product-card .product-price {
    font-size: 1.125rem !important;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    text-align: left !important;
  }

  /* Old price styling */
  .product-price span[style*="line-through"],
  .category-products .product-card .product-price span[style*="line-through"] {
    font-size: 0.8rem !important;
    color: var(--text-tertiary, #999) !important;
    font-weight: 400 !important;
    display: block;
    margin-bottom: 0.125rem;
  }

  /* Current price styling */
  .product-price span[style*="font-weight: 700"],
  .category-products .product-card .product-price span:last-child {
    font-size: 1.125rem !important;
    color: var(--bs-primary, #e02020) !important;
  }

  /* Button - compact, not full width */
  .product-btn,
  .category-products .product-card .product-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: auto !important;
    padding: 0.35rem 0.65rem !important;
    font-size: 0.65rem !important;
    font-weight: 500;
    border-radius: 5px;
    gap: 0.25rem;
    background: var(--bs-primary, #e02020);
    color: #fff !important;
    text-decoration: none !important;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: unset;
  }

  .product-btn:active {
    transform: scale(0.98);
    background: var(--accent-dark, #c01818);
  }

  .product-btn span {
    display: inline !important;
  }

  .product-btn i {
    font-size: 0.7rem;
  }

  /* View more button */
  .category-view-more {
    margin-top: 1rem;
    padding-top: 1rem;
  }

  .category-view-more-btn {
    width: 100%;
    justify-content: center;
    padding: 0.875rem 1rem;
    font-size: 0.9rem;
    border-radius: 10px;
  }

  /* ===== SIDEBAR AS BOTTOM SHEET ===== */
  .filters-sidebar {
    display: flex !important;
    flex-direction: column;
    position: fixed !important;
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto;
    max-height: 85vh;
    border-left: none !important;
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.2);
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1001;
  }

  .filters-sidebar.active {
    transform: translateY(0);
  }

  /* Hide the desktop toggle on mobile - use floating button instead */
  .sidebar-toggle {
    display: none !important;
  }

  .sidebar-handle {
    display: block !important;
    width: 48px;
    height: 5px;
    background: var(--text-tertiary, #ccc);
    border-radius: 3px;
    margin: 12px auto;
    opacity: 0.5;
  }

  .sidebar-header {
    padding: 0 1.25rem 1rem;
  }

  .sidebar-title {
    font-size: 1.125rem;
  }

  .sidebar-subtitle {
    display: none;
  }

  .page-type-switcher {
    margin-top: 0.75rem;
  }

  .page-type-btn {
    padding: 0.625rem 1rem;
    font-size: 0.8rem;
  }

  .sidebar-search {
    padding: 0.75rem 1.25rem;
  }

  .sidebar-search-input {
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    font-size: 0.875rem;
    border-radius: 12px;
  }

  .sidebar-content {
    flex: 1;
    max-height: calc(85vh - 220px);
    overflow-y: auto;
    padding: 1rem 1.25rem;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar-results {
    padding: 1rem 1.25rem;
  }
}

/* ========== MOBILE PHONES (max 768px) ========== */
@media (max-width: 768px) {
  .products-section {
    /* navbar (60px) + category bar (52px) + small gap */
    margin-top: 120px !important;
    padding: 0.75rem;
  }

  .products-grid,
  #productsGrid {
    gap: 0.625rem;
  }

  .category-section {
    padding: 0.875rem;
    border-radius: 14px;
  }

  .category-header h2 {
    font-size: 1rem;
  }

  .category-products {
    gap: 0.625rem !important;
  }

  .product-image-container,
  .category-products .product-card .product-image-container {
    height: 130px !important;
  }

  .product-card-body,
  .category-products .product-card .product-card-body {
    padding: 0.75rem !important;
  }

  .product-title,
  .category-products .product-card .product-title {
    font-size: 0.8rem !important;
  }

  .product-price,
  .category-products .product-card .product-price {
    font-size: 1rem !important;
  }

  .product-btn,
  .category-products .product-card .product-btn {
    padding: 0.35rem 0.6rem !important;
    font-size: 0.65rem !important;
    min-height: unset;
  }
}

/* ========== SMALL PHONES (max 576px) - Navbar is 56px ========== */
@media (max-width: 576px) {
  .products-section {
    /* navbar (56px) + category bar (48px) + small gap */
    margin-top: 112px !important;
  }
}

/* ========== SMALL PHONES (max 480px) ========== */
@media (max-width: 480px) {
  .products-section {
    /* navbar (56px) + category bar (46px) + small gap */
    margin-top: 110px !important;
    padding: 0.5rem;
  }

  .products-grid,
  #productsGrid,
  .category-products {
    gap: 0.5rem !important;
  }

  .category-section {
    padding: 0.75rem;
    border-radius: 12px;
  }

  .category-header {
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
  }

  .category-header i {
    font-size: 1rem;
    padding: 0.375rem;
  }

  .category-header h2 {
    font-size: 0.9rem;
  }

  .product-image-container,
  .category-products .product-card .product-image-container {
    height: 115px !important;
    padding: 0.5rem;
  }

  .product-card-body,
  .category-products .product-card .product-card-body {
    padding: 0.625rem !important;
  }

  .product-brand {
    font-size: 0.6rem;
  }

  .product-title,
  .category-products .product-card .product-title {
    font-size: 0.75rem !important;
    min-height: 2.2em;
  }

  .product-footer,
  .category-products .product-card .product-footer {
    gap: 0.5rem;
    padding-top: 0.5rem;
  }

  .product-price,
  .category-products .product-card .product-price {
    font-size: 0.9rem !important;
  }

  .product-btn,
  .category-products .product-card .product-btn {
    padding: 0.3rem 0.55rem !important;
    font-size: 0.6rem !important;
    min-height: unset;
    border-radius: 5px;
  }

  .product-btn i {
    font-size: 0.65rem;
  }

  .category-view-more-btn {
    padding: 0.75rem;
    font-size: 0.85rem;
  }
}

/* ========== VERY SMALL PHONES (max 360px) ========== */
@media (max-width: 360px) {
  .product-image-container,
  .category-products .product-card .product-image-container {
    height: 100px !important;
  }

  .product-title,
  .category-products .product-card .product-title {
    font-size: 0.7rem !important;
  }

  .product-price,
  .category-products .product-card .product-price {
    font-size: 0.85rem !important;
  }

  .product-btn,
  .category-products .product-card .product-btn {
    padding: 0.25rem 0.5rem !important;
    font-size: 0.55rem !important;
    min-height: unset;
  }
}

/* ========== MOBILE FILTER TOGGLE BUTTON ========== */
.mobile-filter-toggle {
  display: none;
}

@media (max-width: 900px) {
  .mobile-filter-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 60px;
    height: 60px;
    background: var(--bs-primary, #e02020);
    color: white;
    border: none;
    border-radius: 50%;
    box-shadow: 0 4px 20px rgba(224, 32, 32, 0.4);
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 1000;
    transition: all 0.25s ease;
  }

  .mobile-filter-toggle:active {
    transform: scale(0.95);
  }

  .mobile-filter-toggle.active {
    background: var(--text-primary);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  }

  .mobile-filter-toggle i {
    transition: transform 0.25s ease;
  }

  .mobile-filter-toggle.active i {
    transform: rotate(45deg);
  }

  .mobile-filter-toggle .filter-count {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    background: #fff;
    color: var(--bs-primary, #e02020);
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  }
}

@media (max-width: 480px) {
  .mobile-filter-toggle {
    width: 56px;
    height: 56px;
    bottom: 1.25rem;
    right: 1.25rem;
    font-size: 1.25rem;
  }
}

/* ========== BACKDROP OVERLAY ========== */
.sidebar-backdrop {
  display: none;
}

@media (max-width: 900px) {
  .sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
  }

  .sidebar-backdrop.active {
    display: block;
    opacity: 1;
    visibility: visible;
  }
}

/* ========== BODY SCROLL LOCK ========== */
@media (max-width: 900px) {
  body.sidebar-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
  }
}

/* ========== TOUCH OPTIMIZATIONS ========== */
@media (hover: none) and (pointer: coarse) {
  .filter-option,
  .page-type-btn,
  .subcategory-filter-btn,
  .mobile-filter-toggle {
    min-height: 44px;
  }

  .product-btn {
    min-height: unset;
  }

  .product-card:hover {
    transform: none;
    box-shadow: none;
  }
}

/* ========== SAFE AREA SUPPORT ========== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  @media (max-width: 900px) {
    .filters-sidebar {
      padding-bottom: env(safe-area-inset-bottom);
    }

    .mobile-filter-toggle {
      bottom: calc(1.5rem + env(safe-area-inset-bottom));
    }

    .products-section {
      padding-bottom: calc(100px + env(safe-area-inset-bottom));
    }
  }
}

/* ========== LANDSCAPE MODE ========== */
@media (max-width: 900px) and (orientation: landscape) {
  .filters-sidebar {
    max-height: 75vh;
  }

  .sidebar-content {
    max-height: calc(75vh - 180px);
  }

  /* 3 columns in landscape */
  .products-grid,
  #productsGrid,
  .category-products {
    grid-template-columns: repeat(3, 1fr) !important;
  }

  .product-image-container,
  .category-products .product-card .product-image-container {
    height: 100px !important;
  }
}

/* ========== NO RESULTS & LOADING ========== */
@media (max-width: 768px) {
  .no-results,
  #noResults {
    padding: 3rem 1.5rem;
    text-align: center;
  }

  .no-results i,
  #noResults i {
    font-size: 3rem;
    color: var(--text-tertiary);
    margin-bottom: 1rem;
  }

  .no-results h3,
  #noResults h3 {
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
  }

  .no-results p,
  #noResults p {
    font-size: 0.875rem;
    color: var(--text-secondary);
  }

  .loading-state {
    padding: 3rem 1.5rem;
  }

  .loading-state .spinner {
    width: 40px;
    height: 40px;
  }

  .loading-state p {
    font-size: 0.875rem;
  }
}

/* ========== DARK MODE ========== */
[data-theme="dark"] .sidebar-backdrop {
  background: rgba(0, 0, 0, 0.7);
}

[data-theme="dark"] .mobile-filter-toggle .filter-count {
  background: var(--bg-card);
}

[data-theme="dark"] .product-image-container {
  background: var(--bg-secondary);
}

[data-theme="dark"] .product-card {
  border-color: var(--border-primary);
}

[data-theme="dark"] .category-section {
  background: var(--bg-card);
}
