/* ===== MOBILE RESPONSIVE STYLES ===== */

/* Cart Page Mobile */
@media (max-width: 768px) {
  .cart-grid {
    grid-template-columns: 1fr !important;
    gap: 1.5rem;
  }

  .cart-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .cart-item-img {
    width: 100%;
    height: 200px;
  }

  .cart-item-info {
    width: 100%;
  }

  .cart-summary {
    position: static;
    margin-top: 2rem;
  }
}

/* Product Detail Page Mobile */
@media (max-width: 768px) {
  .product-detail-grid {
    grid-template-columns: 1fr !important;
    gap: 2rem;
  }

  .detail-gallery {
    position: static;
  }

  .detail-main-img-wrap {
    height: 300px;
  }

  .detail-title {
    font-size: 1.75rem;
  }

  .detail-price {
    font-size: 2rem;
  }

  .quantity-selector {
    width: 100%;
    justify-content: center;
  }

  .btn-add-to-cart {
    width: 100%;
  }
}

/* Orders Page Mobile */
@media (max-width: 768px) {
  .orders-header h1 {
    font-size: 1.75rem;
  }

  .order-card {
    padding: 1.25rem;
  }

  .order-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .order-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .order-actions {
    width: 100%;
    flex-direction: column;
  }

  .order-actions button {
    width: 100%;
  }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
  /* Increase tap targets for touch devices */
  .btn,
  .filter-btn,
  .pagination button {
    min-height: 44px;
  }

  .product-card {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  /* Remove hover effects on touch devices */
  .product-card:hover {
    transform: none;
  }

  .btn-add:hover {
    transform: none;
  }
}

/* ===== GLOBAL CLIENT MOBILE LAYOUT (bổ sung) ===== */
@media (max-width: 1024px) {
  .container {
    max-width: 100%;
    padding: 0 1.25rem;
  }

  .grid-4 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  /* Ensure products container uses 3 columns on tablet */
  #products-container.grid-4 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .product-detail-grid {
    grid-template-columns: 1.1fr 1fr;
    gap: 2rem;
  }
}

@media (max-width: 768px) {
  html,
  body {
    overflow-x: hidden;
  }

  .container {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .navbar {
    height: auto;
    padding: 0.5rem 0;
  }

  .navbar .container.d-flex {
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: space-between;
  }

  .logo img {
    height: 64px !important;
  }

  /* Hiển thị thanh search trong navbar trên mobile, full width ở hàng riêng */
  .navbar .nav-search {
    display: flex !important;
    flex: 1 0 100%;
    order: 3;
    margin: 0.25rem 0 0.5rem;
    max-width: 100%;
  }

  /* Hero + products */
  .hero {
    padding: 3rem 0 2rem;
    text-align: center;
  }

  .hero .container.d-flex {
    flex-direction: column;
    gap: 2rem;
  }

  .hero-content {
    max-width: 100%;
  }

  /* Pagination: keep on one horizontal row on mobile (style.css sets .d-flex column) */
  #pagination.d-flex,
  #pagination {
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: center !important;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    gap: 0.5rem !important;
    padding: 0.25rem 0.25rem;
    max-width: 100%;
  }

  #pagination::-webkit-scrollbar {
    height: 0;
  }

  #pagination .btn {
    flex: 0 0 auto;
    min-width: 40px;
    height: 40px;
    padding: 0.6rem 0.9rem;
    font-size: 0.9rem;
    white-space: nowrap;
  }

  #pagination span {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  /* Force 2 columns on mobile */
  .grid.grid-4,
  .grid-4,
  #products-container.grid-4,
  #products-container.grid.grid-4 {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.75rem !important;
  }

  .product-card {
    padding: 0;
    border-radius: 12px;
    overflow: hidden;
  }

  .product-img-wrap {
    height: 180px;
    border-radius: 12px 12px 0 0;
  }

  .product-info {
    padding: 0.75rem;
  }

  .product-title {
    font-size: 0.9rem;
    line-height: 1.3;
    margin-bottom: 0.5rem;
    line-clamp: 2;
    -webkit-line-clamp: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .product-price {
    font-size: 1rem;
    font-weight: 700;
  }

  .product-card div[style*="font-size: 0.85rem"] {
    font-size: 0.75rem !important;
    margin-bottom: 0.4rem;
  }

  .btn-add-cart {
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
  }

  .card-badge {
    top: 0.5rem;
    left: 0.5rem;
    font-size: 0.7rem;
    padding: 0.25rem 0.6rem;
  }

    .card-badge.tag-sale {
    top: 0.5rem;
    left: 0.3rem !important;
  }
  .card-badge.tag-bestseller {
      top: 0.5rem;
      right: 0rem !important;
  }

  .btn-wishlist {
    top: 0.5rem;
    right: 0.5rem;
    width: 32px;
    height: 32px;
    font-size: 0.85rem;
  }

  .product-bottom {
    gap: 0.75rem;
    margin-top: 0.5rem;
  }

  .filter-bar-wrapper {
    justify-content: flex-start;
  }

  .filter-bar {
    width: 100%;
    overflow-x: auto;
  }

  /* Footer */
  .footer-grid {
    /* Mobile: 2 columns for "Khám phá" & "Hỗ trợ" */
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.5rem;
  }

  /* Make intro block (logo + description) full width */
  .footer-grid > div:first-child {
    grid-column: 1 / -1;
  }

  /* Make hotline block full width (last column in markup) */
  .footer-grid > div:last-child {
    grid-column: 1 / -1;
  }

  .footer-links li {
    margin-bottom: 0.6rem;
  }

  .footer {
    padding: 3rem 0 2rem;
  }

  /* Cart page */
  .cart-grid {
    grid-template-columns: 1fr !important;
    gap: 1.5rem;
  }

  .cart-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .cart-item-img {
    width: 100%;
    height: 200px;
  }

  .cart-item-info {
    width: 100%;
  }

  .cart-card[style*="position: sticky"],
  .cart-summary {
    position: static !important;
    margin-top: 1.5rem;
  }

  /* Product detail */
  .product-detail-grid {
    grid-template-columns: 1fr !important;
    gap: 2rem;
  }

  .detail-gallery {
    position: static;
  }

  .detail-main-img-wrap {
    height: auto;
    min-height: 250px;
    max-height: none;
    aspect-ratio: unset;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .detail-main-img {
    object-fit: contain;
    width: 100%;
    height: auto;
    max-width: 100%;
    max-height: 500px;
    display: block;
  }

  .detail-gallery {
    padding: 0.75rem;
  }

  .detail-title {
    font-size: 1.75rem;
  }

  .detail-price {
    font-size: 2rem;
  }

  .detail-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .quantity-wrapper {
    justify-content: center;
    width: 100%;
    margin-bottom: 0.75rem;
  }

  .btn-add-cart-lg {
    width: 100%;
  }

  /* Orders page (client) */
  .orders-header h1 {
    font-size: 1.75rem;
  }

  .order-card {
    padding: 1.25rem;
  }

  .order-header,
  .order-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .order-item {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 480px) {
  /* Keep 2 columns even on very small screens for better UX */
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.5rem !important;
  }

  #products-container.grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.5rem !important;
  }

  .hero-title {
    font-size: 1.75rem;
  }

  /* Pagination tighter on very small screens */
  #pagination {
    gap: 0.4rem !important;
  }

  #pagination .btn {
    min-width: 36px;
    height: 36px;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
  }
}

@media (max-width: 430px) {
  .grid-4,
  #products-container.grid-4 {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  .product-card {
    display: flex;
    flex-direction: column;
  }

  .product-info {
    padding: 10px !important;
  }

  .product-title {
    font-size: 0.85rem !important;
  }
}