/* =========================================================
   FINAL RESPONSIVE FIXES
   Load this file AFTER stylesheet.css
   ========================================================= */

/* Prevent accidental horizontal scrolling */
html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

/* Make images and tables safer on small screens */
img {
  max-width: 100%;
}

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* General containers */
.container,
.container-fluid {
  max-width: 100%;
}

/* Navbar mobile fix */
@media (max-width: 991.98px) {
  .navbar.navbar-dark .container-fluid {
    flex-wrap: wrap;
  }

  .navbar-collapse {
    width: 100%;
  }

  .navbar.navbar-dark .navbar-nav.mr-auto,
  .navbar.navbar-dark .navbar-nav.ml-lg-3 {
    width: 100%;
    align-items: stretch;
    gap: 8px;
    margin: 10px 0 0 !important;
    flex-wrap: wrap;
  }

  .navbar.navbar-dark .navbar-nav .nav-item,
  .navbar.navbar-dark .navbar-nav .nav-link {
    width: 100%;
  }

  .navbar.navbar-dark .navbar-nav.mr-auto .nav-link {
    margin-left: 0 !important;
    justify-content: flex-start;
  }

  .navbar.navbar-dark .nav-item.dropdown > .dropdown-toggle {
    width: 100%;
    max-width: none;
    justify-content: flex-start;
  }

  .dropdown-menu {
    width: 100%;
    max-width: 100%;
  }

  #displayUsername {
    max-width: 180px;
  }
}

/* Sidebar and working panel mobile fix */
@media (max-width: 991.98px) {
  .wrapper {
    display: block;
  }

  .wrapper .sidebar,
  .sidebar {
    position: static !important;
    width: auto !important;
    height: auto !important;
    margin: 12px;
    border-radius: 18px;
  }

  .wrapper .working-panel,
  .working-panel,
  .sidebar.collapsed ~ .working-panel,
  .wrapper.sidebar-collapsed .working-panel {
    width: auto !important;
    margin: 12px !important;
    padding: 16px !important;
  }

  .wrapper + footer,
  .wrapper.sidebar-collapsed + footer,
  footer {
    width: auto !important;
    margin: 20px 12px !important;
  }
}

@media (max-width: 575.98px) {
  .wrapper .sidebar .nav-bar {
    grid-template-columns: 1fr !important;
  }

  .sidebar .nav-bar li a,
  .wrapper .sidebar .nav-bar li a {
    justify-content: flex-start;
  }
}

/* Account/profile responsive fix */
@media (max-width: 991.98px) {
  .profile-card {
    max-width: 100%;
    margin: 0 auto 20px !important;
  }

  .profile-section,
  .category-section,
  .brand-section,
  .manageAccount-section,
  .product-section {
    width: 100%;
    margin: 0 auto;
    padding: 16px;
  }
}

/* Login/register responsive fix */
@media (max-width: 991.98px) {
  .loginform {
    max-width: 90% !important;
    width: 90% !important;
  }
}

@media (max-width: 575.98px) {
  .loginform {
    max-width: 100% !important;
    width: calc(100% - 24px) !important;
    padding: 18px !important;
  }

  .loginform img {
    width: 120px;
    height: 120px;
  }
}

/* Cart responsive fix */
@media (max-width: 767.98px) {
  .cart-item-card {
    display: grid !important;
    grid-template-columns: 34px 80px 1fr;
    align-items: start;
    gap: 12px;
    padding: 14px;
  }

  .cart-select-cell,
  .cart-image-cell {
    margin-right: 0;
  }

  .cart-image-cell,
  .cart-item-img {
    width: 80px;
    height: 80px;
  }

  .cart-item-card > .mx-4 {
    grid-column: 2 / 4;
    margin: 8px 0 0 !important;
  }

  .cart-item-card > .text-end {
    grid-column: 1 / 4;
    width: 100%;
    min-width: 0 !important;
    text-align: left !important;
  }

  .quantity-pill-container {
    width: 130px;
  }

  .order-summary-card {
    position: static;
    margin-top: 20px;
  }
}

/* Contact/footer mobile fix */
@media (max-width: 575.98px) {
  .contact-page {
    margin-top: 88px !important;
  }

  .contact-form,
  .contact-form-copy,
  .contact-info-card {
    padding: 18px !important;
  }

  .general-info,
  .general-info-shop,
  .footer-main .general-info {
    grid-template-columns: 1fr !important;
    flex-direction: column !important;
    gap: 20px;
    padding: 22px !important;
  }

  .footer-shop,
  .footer-main {
    margin-left: 12px !important;
    margin-right: 12px !important;
  }
}

/* Notification dropdown mobile fix */
@media (max-width: 575.98px) {
  .notification-dropdown {
    width: min(92vw, 340px) !important;
    min-width: 0 !important;
    max-width: 92vw !important;
    right: 0 !important;
    left: auto !important;
  }

  .notification-dropdown-body {
    max-height: 360px;
  }
}

/* Modal mobile fix */
@media (max-width: 575.98px) {
  .modal-dialog {
    margin: 10px;
  }

  .modal-content {
    border-radius: 16px;
  }

  .modal-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .modal-footer .btn {
    width: 100%;
  }
}

/* Keep Bootstrap sticky-top working */
nav.navbar.sticky-top {
  position: sticky !important;
  top: 0 !important;
  z-index: 3000 !important;
}

/* Sidebar top only on desktop */
@media (min-width: 992px) {
  .wrapper .sidebar,
  .sidebar {
    top: 66px !important;
  }
}

/* ===============================
   DESKTOP SIDEBAR BEHAVIOR
   992px and above
================================ */
@media (min-width: 992px) {
  .toggle-btns {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .sidebar.collapsed .text-link {
    display: none !important;
  }
}

/* ===============================
   MOBILE SIDEBAR BEHAVIOR
   below 992px
================================ */
@media (max-width: 991.98px) {
  /* Hide the desktop sidebar collapse buttons on mobile */
  .toggle-btns {
    display: none !important;
  }

  /* Keep Bootstrap hamburger visible for navbar */
  .navbar-toggler {
    display: block;
  }

  /* Do not allow desktop collapsed sidebar to affect mobile */
  .sidebar,
  .sidebar.collapsed {
    width: auto !important;
    max-width: calc(100% - 24px) !important;
    margin-left: 12px !important;
    margin-right: 12px !important;
  }

  /* Always show sidebar text on mobile */
  .sidebar .text-link,
  .sidebar.collapsed .text-link {
    display: inline-block !important;
    opacity: 1 !important;
    visibility: visible !important;
  }

  /* Reset wrapper/content spacing on mobile */
  .wrapper,
  .wrapper.sidebar-collapsed {
    display: block;
  }

  .working-panel,
  .wrapper.sidebar-collapsed .working-panel {
    width: auto !important;
    max-width: calc(100% - 24px) !important;
    margin: 12px !important;
  }
}

/* Keep modals above sticky navbar and sidebar */
.modal {
  z-index: 20000 !important;
}

.modal-backdrop {
  z-index: 19990 !important;
}

/* Lower navbar only when modal is open */
body.modal-open .dashboard-navbar,
body.modal-open .navbar.sticky-top {
  z-index: 1000 !important;
}

/* Better height for large order details modal */
#orderDetailsModal .modal-dialog {
  max-width: 80%;
}

@media (max-width: 575.98px) {
  #orderDetailsModal .modal-dialog {
    width: auto !important;
    max-width: calc(100% - 20px) !important;
    margin: 10px auto !important;
  }

  #orderDetailsModal .modal-body {
    max-height: calc(100vh - 140px);
    overflow-y: auto;
  }
}

#orderDetailsModal .modal-body {
  max-height: calc(100vh - 200px);
  overflow-y: auto;
}

/* Checkout page mobile polish */
@media (max-width: 767.98px) {
  .checkout-stepper {
    margin-top: 18px !important;
    padding: 14px !important;
    border-radius: 18px !important;
    flex-direction: column !important;
    gap: 8px !important;
  }

  .checkout-stepper .step {
    width: 100% !important;
    margin: 0 !important;
    text-align: center !important;
  }

  .checkout-stepper i.fa-chevron-right {
    transform: rotate(90deg);
  }

  #checkoutform .form-group {
    flex: 0 0 100% !important;
    max-width: 100% !important;
  }

  .ui-card,
  .ui-card-gray {
    width: 100% !important;
    max-width: 100% !important;
    padding: 18px !important;
    margin-bottom: 18px !important;
  }

  .cartItems {
    max-width: 100% !important;
    overflow-x: hidden !important;
  }

  #placeOrder {
    width: 100% !important;
  }

  .footer-main {
    width: auto !important;
    max-width: calc(100% - 24px) !important;
    margin: 20px 12px !important;
  }

  .footer-main .general-info {
    flex-direction: column !important;
    gap: 18px !important;
    padding: 22px !important;
  }
}

/* Homepage hero mobile fix */
@media (max-width: 767.98px) {
  #home.home {
    position: relative;
    width: 100%;
    height: auto !important;

    min-height: calc(100vh - 68px);
    min-height: calc(100svh - 68px);

    padding: 60px 18px;

    justify-content: center;
    align-items: flex-start;

    background-size: cover !important;
    background-repeat: no-repeat !important;
    background-position: 68% center !important;

    overflow: hidden;
  }

  #home.home::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(
      90deg,
      rgba(15, 23, 42, 0.82),
      rgba(15, 23, 42, 0.45),
      rgba(15, 23, 42, 0.08)
    );
    z-index: 0;
  }

  #home .container-home {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 290px;
    margin: 0 !important;
    padding: 0 !important;
  }

  #home .container-home h5 {
    color: #ffffff !important;
    font-size: 0.85rem;
  }

  #home .container-home h1 {
    color: #ffffff !important;
    font-size: clamp(2rem, 9vw, 2.8rem) !important;
    line-height: 1.1;
  }

  #home .container-home h1 span {
    color: #fb774b !important;
  }

  #home .container-home p {
    max-width: 280px;
    color: rgba(255, 255, 255, 0.92) !important;
    font-size: 0.92rem;
    line-height: 1.5;
  }

  #home .container-home button {
    min-width: 140px;
    padding: 12px 18px;
  }
}

/* =========================================================
   SHOP PAGE MOBILE FILTERS
   ========================================================= */

.shop-filter-toggle {
  min-height: 46px;
  border-radius: 12px;
  background: #ffffff;
  font-weight: 700;
}

@media (max-width: 991.98px) {
  .shop-main > .container-fluid {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  .shop-filter-sidebar {
    width: 100%;
    max-width: 100%;
    margin-bottom: 16px;
    padding: 18px;

    border: 1px solid #e2e8f0;
    border-radius: 16px;

    background: #ffffff;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
  }

  .shop-filter-sidebar h5 {
    margin-top: 14px;
    font-size: 1rem;
    font-weight: 700;
  }

  .shop-filter-sidebar h5:first-child {
    margin-top: 0;
  }

  .shop-filter-sidebar ul {
    margin-bottom: 12px;
  }

  .shop-filter-sidebar .form-control {
    width: 100%;
    min-width: 0;
  }

  .shop-filter-sidebar #applyPriceFilter {
    min-height: 40px;
  }
}

/* Keep the filter sidebar permanently visible on desktop */
@media (min-width: 992px) {
  .shop-filter-sidebar.collapse {
    display: block !important;
  }
}

/* Shop sort controls on phones */
@media (max-width: 767.98px) {
  .shop-sort-bar {
    display: block !important;
    padding: 12px !important;
  }

  .shop-sort-bar > span {
    display: block;
    margin: 0 0 10px !important;
  }

  .shop-sort-buttons {
    display: flex;
    width: 100%;
    overflow-x: auto;
    padding-bottom: 5px;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .shop-sort-buttons .btn {
    flex: 0 0 auto;
    min-width: max-content;
  }
}

/* =========================================================
   HOMEPAGE PRODUCT AND BRAND RESPONSIVE FIX
   Keep this at the END of responsive-fixes.css
   ========================================================= */

/* Remove the Bootstrap ml-4 overflow from homepage sections */
#brands-section,
#latest-products-section {
  width: 100%;
  max-width: 100%;
  margin-left: 0 !important;
  padding-left: 15px !important;
  padding-right: 15px !important;
  overflow: hidden;
}

/* =========================================================
   DAILY PRODUCTS
   ========================================================= */

#dailyProducts-container {
  display: flex !important;
  flex-wrap: wrap !important;
  align-items: stretch;
  justify-content: center;
  width: 100%;
  max-width: 100%;
  margin-right: 0 !important;
  margin-left: 0 !important;
}

/* Make every Bootstrap column hold an equal-height card */
#dailyProducts-container > [class*="col-"] {
  display: flex;
  min-width: 0;
  padding-right: 6px;
  padding-left: 6px;
}

/* Remove the fixed 250px width and margins */
#dailyProducts-container .dailyProductCard {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  height: 100%;
  margin: 0 !important;
  overflow: hidden;
}

/* Keep the card body inside its own column */
#dailyProducts-container .card-body {
  width: 100%;
  min-width: 0;
}

/* Responsive square product image */
#dailyProducts-container .card-img-top {
  display: block;
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important;
  aspect-ratio: 1 / 1;
  padding: 6px;
  object-fit: cover;
}

/* Prevent long product names and prices from pushing cards wider */
#dailyProducts-container .card-title,
#dailyProducts-container .product-name,
#dailyProducts-container span,
#dailyProducts-container small {
  max-width: 100%;
  overflow-wrap: anywhere;
}

/* Responsive Add to Cart button */
#dailyProducts-container .homepage-cart-btn {
  display: flex;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px 5px;
  white-space: normal;
  text-align: center;
}

/* =========================================================
   OWL PRODUCT AND BRAND CAROUSELS
   ========================================================= */

#brand-carousel,
#product-carousel,
#brand-carousel .owl-stage-outer,
#product-carousel .owl-stage-outer {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

/* Equal-height Owl cards */
#brand-carousel .owl-stage,
#product-carousel .owl-stage {
  display: flex;
}

#brand-carousel .owl-item,
#product-carousel .owl-item {
  display: flex;
  min-width: 0;
  height: auto;
}

/* Owl must control the item width—not the fixed 250px rule */
#brand-carousel .product-card,
#product-carousel .product-card {
  display: flex;
  flex-direction: column;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  height: 100%;
  margin: 0 !important;
  overflow: hidden;
}

/* Responsive image container */
#brand-carousel .product-img,
#product-carousel .product-img {
  display: flex;
  width: 100%;
  max-width: 100%;
  height: auto !important;
  aspect-ratio: 1 / 1;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 8px;
}

/* Override fixed 290px image height from stylesheet.css */
#brand-carousel .product-img img,
#product-carousel .product-img img {
  display: block;
  width: 100% !important;
  max-width: 100% !important;
  height: 100% !important;
}

/* Brand logos should not be cropped */
#brand-carousel .product-img img {
  object-fit: contain;
}

/* Product images can fill their square */
#product-carousel .product-img img {
  object-fit: cover;
}

/* Prevent names from increasing carousel width */
#brand-carousel .product-name,
#product-carousel .product-name,
#brand-carousel .product-details,
#product-carousel .product-details {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
}

/* =========================================================
   MOBILE
   ========================================================= */

@media (max-width: 575.98px) {
  #brands-section,
  #latest-products-section {
    padding-right: 10px !important;
    padding-left: 10px !important;
  }

  #dailyProducts-container {
    padding-right: 4px !important;
    padding-left: 4px !important;
  }

  #dailyProducts-container > [class*="col-"] {
    padding-right: 4px;
    padding-left: 4px;
    margin-bottom: 8px !important;
  }

  #dailyProducts-container .card-body {
    padding: 7px !important;
  }

  #dailyProducts-container .card-title {
    font-size: 0.78rem !important;
  }

  #dailyProducts-container .homepage-cart-btn {
    min-height: 35px;
    padding: 7px 3px;
    font-size: 0.72rem;
  }

  #dailyProducts-container .homepage-cart-btn i {
    font-size: 0.75rem;
  }

  #product-carousel .product-details,
  #brand-carousel .product-details {
    padding: 8px;
  }

  #product-carousel .product-name,
  #brand-carousel .product-name {
    font-size: 0.9rem;
  }
}

/* Use one Daily Product per row on extremely narrow phones */
@media (max-width: 359.98px) {
  #dailyProducts-container > [class*="col-"] {
    flex: 0 0 100% !important;
    max-width: 100% !important;
  }
}
