/* ============================================================
   MOBILE OPTIMIZE - TỐI ƯU MOBILE CHO TOÀN BỘ UI CLIENT
   NGUYÊN TẮC: Chỉ áp dụng trong @media max-width
   Không làm thay đổi bất kỳ giao diện nào trên PC (min-width >= 992px)
   ============================================================ */

/* ============================================================
   1. LOGIN & REGISTER CARD - MÀN NHỎ
   ============================================================ */
@media (max-width: 576px) {
  /* Login card */
  .login-card {
    padding: 2rem 1.25rem !important;
    border-radius: 16px !important;
    margin: 0 !important;
    box-shadow: 0 10px 30px rgba(88, 47, 14, 0.08) !important;
  }

  .icon-box {
    width: 64px !important;
    height: 64px !important;
    margin-bottom: 1rem !important;
  }

  .brand-name {
    font-size: 18px !important;
  }

  /* Register card */
  .register-card {
    padding: 1.5rem 1.1rem !important;
    border-radius: 1.25rem !important;
  }
}

@media (max-width: 768px) and (min-width: 577px) {
  .login-card,
  .register-card {
    padding: 2rem 1.75rem !important;
  }
}

/* ============================================================
   2. MAIN CONTAINER - GIẢM PADDING TRÊN MOBILE
   ============================================================ */
@media (max-width: 767.98px) {
  .container {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  main[role="main"].container {
    padding-left: 10px !important;
    padding-right: 10px !important;
    margin-top: 0.5rem !important;
    margin-bottom: 1rem !important;
  }

  /* my-5 trên mobile quá nhiều khoảng cách */
  .my-5 {
    margin-top: 1.5rem !important;
    margin-bottom: 1.5rem !important;
  }

  .py-5 {
    padding-top: 2rem !important;
    padding-bottom: 2rem !important;
  }

  .mt-5 {
    margin-top: 1.5rem !important;
  }

  .mb-5 {
    margin-bottom: 1.5rem !important;
  }

  .pt-5 {
    padding-top: 2rem !important;
  }

  .pb-5 {
    padding-bottom: 2rem !important;
  }
}

/* ============================================================
   3. HEADER MOBILE - TỐI ƯU KHÔNG GIAN
   ============================================================ */
@media (max-width: 767.98px) {
  .main-header {
    padding: 6px 0 !important;
  }

  /* Col chứa logo canh giữa tốt hơn */
  .main-header .col-6 {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .main-logo {
    height: 38px !important;
  }

  /* Search bar mobile - full width, height rõ ràng hơn */
  .mobile-search-wrapper {
    padding: 6px 0 8px !important;
  }

  .mobile-search-wrapper .search-box-v2 {
    height: 40px !important;
    border-radius: 40px !important;
  }

  .mobile-search-wrapper .search-input-v2 {
    font-size: 13px !important;
    padding: 0 14px !important;
  }

  /* Icon user + cart thu gọn hơn */
  .icon-action-v2 {
    padding: 4px 6px !important;
    gap: 4px !important;
  }

  .icon-action-v2 i {
    font-size: 20px !important;
  }
}

@media (max-width: 380px) {
  .main-logo {
    height: 32px !important;
  }

  .icon-action-v2 i {
    font-size: 18px !important;
  }
}

/* ============================================================
   4. PRODUCT LIST / HOME PAGE - TỐI ƯU LƯỚI SẢN PHẨM
   ============================================================ */
@media (max-width: 767.98px) {
  /* Lưới 2 cột trên mobile - giảm gap */
  .row-cols-2.row-cols-md-3 {
    --bs-gutter-x: 8px;
    --bs-gutter-y: 8px;
  }

  /* Product card nhỏ gọn hơn */
  .product-card .product-body {
    padding: 8px 10px !important;
  }

  .product-title {
    font-size: 0.78rem !important;
    height: 2.4em !important;
  }

  .product-price {
    font-size: 0.85rem !important;
    margin: 5px 0 !important;
  }

  /* Button mua ngay / xem nhỏ hơn */
  .btn-product {
    font-size: 0.7rem !important;
    padding: 5px 8px !important;
    border-radius: 30px !important;
  }

  /* Danh mục nổi bật - item nhỏ hơn */
  .anic-category-wrapper {
    width: 110px !important;
  }

  .category-swipe-wrapper .anic-category-card > div:last-child {
    font-size: 10px !important;
    padding: 8px 4px !important;
    min-height: 40px !important;
  }

  /* Thanh tìm kiếm filter trên trang chủ */
  .search-btn-mobile {
    font-size: 12px !important;
    padding: 8px 10px !important;
  }
}

@media (max-width: 380px) {
  .anic-category-wrapper {
    width: 90px !important;
  }

  .category-swipe-wrapper .anic-category-card > div:last-child {
    font-size: 9px !important;
  }
}

/* ============================================================
   5. PRODUCT DETAIL - TỐI ƯU TRANG CHI TIẾT SẢN PHẨM
   ============================================================ */
@media (max-width: 767.98px) {
  /* Khung ảnh chính */
  .main-image-wrapper {
    height: 260px !important;
    border-radius: 12px !important;
  }

  /* Tiêu đề sản phẩm */
  .detail-title {
    font-size: 1.2rem !important;
    line-height: 1.35 !important;
  }

  /* Mô tả rút gọn hơn */
  .description-content {
    max-height: 200px !important;
  }

  /* Nút chức năng xếp dọc tốt hơn */
  .d-flex.flex-column.flex-sm-row.gap-2.mt-auto.pt-4.border-top {
    gap: 8px !important;
    padding-top: 16px !important;
  }

  /* Thumbnail nhỏ gọn hơn */
  .thumbnail-wrapper {
    width: 56px !important;
    height: 56px !important;
  }

  /* Margin container chi tiết */
  .container.mt-4.mt-md-5 {
    margin-top: 0.5rem !important;
  }

  /* Row padding */
  .row.bg-white.shadow-sm.rounded-4.p-3.p-md-4.mb-5 {
    padding: 12px !important;
    margin-bottom: 1.5rem !important;
  }

  /* Sản phẩm liên quan - title và giá nhỏ hơn */
  .related-title {
    font-size: 12px !important;
  }

  .related-price {
    font-size: 13px !important;
  }

  .related-img-wrapper {
    padding: 6px !important;
  }
}

@media (max-width: 380px) {
  .main-image-wrapper {
    height: 220px !important;
  }

  .detail-title {
    font-size: 1.05rem !important;
  }

  .thumbnail-wrapper {
    width: 48px !important;
    height: 48px !important;
  }
}

/* ============================================================
   6. GIỎ HÀNG - TỐI ƯU CART PAGE TRÊN MOBILE
   ============================================================ */
@media (max-width: 767.98px) {
  /* Title giỏ hàng nhỏ hơn */
  .cart-title {
    font-size: 1.4rem !important;
  }

  /* Cart item card thu gọn */
  .cart-item-card {
    padding: 12px 10px !important;
    border-radius: 12px !important;
  }

  /* Ảnh sản phẩm nhỏ hơn */
  .cart-item-img-wrapper {
    width: 75px !important;
    height: 75px !important;
    border-radius: 10px !important;
  }

  /* Tiêu đề item ngắn hơn */
  .cart-item-title {
    font-size: 13px !important;
  }

  /* Thành tiền */
  .cart-item-subtotal {
    font-size: 15px !important;
  }

  /* Summary card: không sticky trên mobile */
  .summary-card {
    position: static !important;
    padding: 16px !important;
    border-radius: 14px !important;
  }

  .summary-total-price {
    font-size: 20px !important;
  }

  .btn-checkout {
    padding: 14px 16px !important;
    font-size: 13px !important;
  }

  /* Toast - đưa xuống dưới trên mobile */
  .cart-toast {
    top: auto !important;
    bottom: 80px !important;
    right: 10px !important;
    left: 10px !important;
    font-size: 13px !important;
    padding: 12px 16px !important;
  }

  /* Control bar */
  .d-flex.align-items-center.justify-content-between.mb-3.px-3.py-2 {
    padding: 8px 10px !important;
  }

  /* Container py-5 giỏ hàng */
  .container.py-5 {
    padding-top: 1.25rem !important;
    padding-bottom: 1.25rem !important;
  }
}

@media (max-width: 380px) {
  .cart-item-img-wrapper {
    width: 60px !important;
    height: 60px !important;
  }

  .cart-item-title {
    font-size: 12px !important;
  }

  .cart-qty-input {
    width: 32px !important;
    font-size: 13px !important;
  }
}

/* ============================================================
   7. LỊCH SỬ MUA HÀNG - ORDER HISTORY
   ============================================================ */
@media (max-width: 767.98px) {
  /* Tiêu đề */
  .container[style*="max-width: 900px"] h2 {
    font-size: 1.2rem !important;
  }

  /* Accordion header - tránh vỡ layout */
  .accordion-button {
    padding: 10px 14px !important;
    font-size: 13px !important;
  }

  /* Badge trạng thái đơn hàng */
  .accordion-button .badge {
    font-size: 11px !important;
    padding: 4px 8px !important;
  }

  /* Mã đơn hàng */
  .accordion-button .text-danger.fs-5 {
    font-size: 1rem !important;
  }

  /* Bảng sản phẩm trong đơn - responsive */
  .accordion-body .table {
    font-size: 12px !important;
  }

  .accordion-body .table td,
  .accordion-body .table th {
    padding: 6px 8px !important;
  }

  /* Ảnh sản phẩm trong đơn hàng nhỏ hơn */
  .accordion-body img[style*="width: 60px"] {
    width: 44px !important;
    height: 44px !important;
  }

  /* Footer đơn hàng - xếp dọc */
  .accordion-body .d-flex.justify-content-between.align-items-center {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 10px !important;
  }

  .accordion-body .text-end {
    text-align: left !important;
  }

  /* Tổng tiền */
  .accordion-body h4.text-danger {
    font-size: 1.1rem !important;
  }
}

/* ============================================================
   8. CHECKOUT / ĐẶT HÀNG
   ============================================================ */
@media (max-width: 767.98px) {
  /* Tiêu đề trang checkout */
  .container.mt-5[style*="max-width: 900px"] h2,
  h2.text-center.text-primary {
    font-size: 1.2rem !important;
    margin-bottom: 1rem !important;
  }

  /* Đổi thứ tự: form điền thông tin lên trên, ảnh sản phẩm xuống dưới */
  .container.mt-5 .row {
    flex-direction: column-reverse;
  }

  /* Full width form trên mobile */
  .container.mt-5 .col-md-5,
  .container.mt-5 .col-md-7 {
    width: 100% !important;
  }

  /* Card ảnh sản phẩm thu gọn */
  .container.mt-5 .col-md-5 img {
    height: 120px !important;
  }

  /* Button đặt hàng to hơn */
  .container.mt-5 .btn-danger.fw-bold.px-4 {
    padding: 14px !important;
    font-size: 15px !important;
  }
}

/* ============================================================
   9. PROFILE - HỒ SƠ TÀI KHOẢN
   ============================================================ */
@media (max-width: 767.98px) {
  /* Card header nhỏ hơn */
  .card-header h4 {
    font-size: 1rem !important;
  }

  .card-body.p-4.p-md-5 {
    padding: 1rem !important;
  }

  /* Các cột form - full width trên mobile */
  .col-md-6.mb-3 {
    width: 100%;
  }

  /* Buttons */
  .d-flex.gap-2 .btn {
    font-size: 13px !important;
    padding: 10px 16px !important;
  }
}

/* ============================================================
   10. BREADCRUMB TRÊN MOBILE
   ============================================================ */
@media (max-width: 767.98px) {
  .breadcrumb {
    padding: 8px 12px !important;
    margin-bottom: 1rem !important;
    font-size: 12px !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
  }

  .breadcrumb .breadcrumb-item.active {
    max-width: 160px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block !important;
  }
}

/* ============================================================
   11. CARD (CHUNG) TRÊN MOBILE
   ============================================================ */
@media (max-width: 767.98px) {
  .card-body {
    padding: 14px !important;
  }

  .card-header {
    padding: 12px 14px !important;
  }

  /* Card shadow nhẹ hơn */
  .card.shadow-sm {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06) !important;
  }
}

/* ============================================================
   12. TABLE RESPONSIVE TRÊN MOBILE
   ============================================================ */
@media (max-width: 767.98px) {
  /* Mọi bảng trên mobile đều cuộn ngang */
  .accordion-body .table-responsive,
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .accordion-body table {
    min-width: 360px;
  }
}

/* ============================================================
    13. FOOTER MOBILE
    ============================================================ */
@media (max-width: 767.98px) {
  .footer-premium {
    padding: 30px 0 0 !important;
    text-align: left !important;
  }

  .footer-premium .row > div {
    margin-bottom: 0 !important;
  }

  .footer-premium h5 {
    font-size: 0.9rem !important;
  }

  .footer-premium a {
    font-size: 0.85rem !important;
  }

  /* Canh trái social icons */
  .footer-premium .d-flex.justify-content-center.justify-content-lg-start {
    justify-content: center !important;
  }
}

/* ============================================================
   14. OFFCANVAS MOBILE MENU - CẢI THIỆN
   ============================================================ */
@media (max-width: 991.98px) {
  .offcanvas {
    max-width: 80vw !important;
    width: 300px !important;
  }

  .offcanvas-title {
    font-size: 1rem !important;
  }

  .mobile-category-link {
    font-size: 14px !important;
  }

  .mobile-category-item .d-flex a {
    font-size: 14px !important;
  }

  .list-group-item {
    font-size: 14px !important;
    padding: 12px 16px !important;
  }
}

/* ============================================================
   15. MODAL TRÊN MOBILE
   ============================================================ */
@media (max-width: 576px) {
  .modal-dialog {
    margin: 8px !important;
  }

  .modal-body {
    padding: 16px !important;
  }

  .modal-header {
    padding: 14px 16px !important;
  }

  /* Modal liên hệ */
  #contactChoiceModal .btn {
    padding: 12px !important;
    font-size: 15px !important;
  }
}

/* ============================================================
   16. ALERT & THÔNG BÁO TRÊN MOBILE
   ============================================================ */
@media (max-width: 767.98px) {
  .alert {
    padding: 10px 14px !important;
    font-size: 13px !important;
    border-radius: 10px !important;
  }

  .alert.alert-info {
    font-size: 13px !important;
  }
}

/* ============================================================
   17. PAGINATION MOBILE
   ============================================================ */
@media (max-width: 576px) {
  .pagination {
    gap: 2px !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
  }

  .pagination .page-link {
    width: 32px !important;
    height: 32px !important;
    padding: 0 !important;
    font-size: 12px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
}

/* ============================================================
    19. CHECKOUT FROM CART - TỐI ƯU
    ============================================================ */
@media (max-width: 767.98px) {
  .container.mt-5.mb-5 .col-md-6 {
    width: 100% !important;
    padding: 0 !important;
  }

  .container.mt-5.mb-5 .col-md-6.shadow.p-4.rounded {
    padding: 1.25rem !important;
    border-radius: 12px !important;
  }

  .container.mt-5.mb-5 h2.text-primary {
    font-size: 1.15rem !important;
  }

  /* Alert info thu gọn */
  .container.mt-5.mb-5 .alert.alert-info {
    font-size: 13px !important;
    padding: 10px 12px !important;
  }

  /* Button xác nhận */
  .container.mt-5.mb-5 .btn.btn-danger.btn-lg {
    font-size: 15px !important;
    padding: 14px !important;
  }
}

/* ============================================================
   20. GENERAL UX - TOUCH TARGETS & ACCESSIBILITY
   ============================================================ */
@media (max-width: 767.98px) {
  /* Minimum touch target: 44x44px cho tất cả button và link */
  .btn:not(.btn-sm),
  button:not(.btn-sm):not(.cart-qty-btn) {
    min-height: 40px;
  }

  /* Checkbox lớn hơn để dễ tap */
  input[type="checkbox"] {
    min-width: 18px;
    min-height: 18px;
  }

  /* Input lớn hơn để dễ nhập */
  .form-control,
  .form-select {
    font-size: 16px !important; /* Ngăn iOS auto-zoom */
    min-height: 44px !important;
  }

  /* Ngăn iOS font scaling */
  textarea.form-control {
    font-size: 16px !important;
    min-height: auto !important;
  }

  /* Smooth scroll trên iOS */
  .offcanvas-body,
  .accordion-body,
  .cart-items-list {
    -webkit-overflow-scrolling: touch;
  }
}

/* ============================================================
   21. IMAGES - MOBILE SAFE
   ============================================================ */
@media (max-width: 767.98px) {
  img {
    max-width: 100%;
  }

  /* Ngăn ảnh tràn container */
  .card img,
  .product-image,
  .cart-item-img,
  .related-img-wrapper img {
    max-width: 100% !important;
    height: auto;
  }

  /* Ảnh trong mô tả sản phẩm */
  .description-wrapper img,
  .description-content img {
    max-width: 100% !important;
    height: auto !important;
  }
}

/* ============================================================
   22. SAFE AREA INSET - HỖ TRỢ IPHONE NOTCH
   ============================================================ */
@supports (padding: max(0px)) {
  @media (max-width: 767.98px) {
    .main-header {
      padding-left: max(12px, env(safe-area-inset-left)) !important;
      padding-right: max(12px, env(safe-area-inset-right)) !important;
    }

    .offcanvas.offcanvas-start {
      padding-left: env(safe-area-inset-left);
    }
  }
}
