/* =====================================================
   Responsive Hardening
   Targets the most common viewport-failure patterns and
   is loaded LAST so it wins ties in the cascade.
   ===================================================== */

/* ---------- 1. Global overflow guards ---------- */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}

*, *::before, *::after { min-width: 0; }

img, picture, video, canvas, svg, iframe, object, embed {
  max-width: 100%;
  height: auto;
}

iframe { display: block; }

/* Long content that often blows out narrow viewports */
.hero h1, .hero p,
h1, h2, h3, h4, h5, h6,
p, li, td, th, dd, dt,
.card, .card-body,
.product-name, .product-title,
.breadcrumb, .breadcrumb-item,
.footer-links a,
.merchant-name, .merchant-card,
.category-horizontal-name,
.home-product-name {
  overflow-wrap: break-word;
  word-wrap: break-word;
}

/* URLs / emails / hashes need stricter wrapping */
.long-text, .url, .email, code, kbd, pre, samp, .hash {
  word-break: break-word;
}

/* Generic table guard: any frontend table that wasn't pre-wrapped
   gets a horizontal scroller so it never blows out the viewport.
   Excludes tables already inside a responsive wrapper or marked .no-responsive. */
main table:not(.no-responsive):not(.pdp-comparison-table) {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Bootstrap container max-width override conflict guard.
   modern-frontend.css sets .container { max-width:1680px !important }
   which removes Bootstrap's responsive container behavior. We at
   least make sure padding shrinks at small widths so content fits. */
@media (max-width: 575.98px) {
  .container,
  .container-fluid,
  .container-sm,
  .container-md,
  .container-lg,
  .container-xl,
  .container-xxl {
    padding-left: 14px;
    padding-right: 14px;
  }
}

/* ---------- 2. Header & menu ---------- */
@media (max-width: 1024px) {
  .header-nav { display: none !important; }
  .mobile-menu-toggle { display: flex !important; }
}

@media (max-width: 575.98px) {
  .header-inner {
    flex-wrap: wrap;
    height: auto;
    min-height: 56px;
    padding: 10px 0;
    gap: 10px;
  }
  .header-search {
    position: static;
    flex: 0 0 100%;
    width: 100%;
    max-width: none;
    padding: 0;
  }
  .header-search-box input {
    font-size: 16px;
    min-height: 44px;
  }
  .logo img { height: 32px !important; }
  .logo-text { font-size: 1rem; }
}

/* ---------- 3. Hero / search box ---------- */
.hero {
  padding: clamp(2rem, 6vw + 1rem, 5rem) 0;
}
.hero h1 {
  font-size: clamp(1.5rem, 3.5vw + 0.5rem, 3rem);
  line-height: 1.2;
}
.hero p {
  font-size: clamp(0.95rem, 0.6vw + 0.85rem, 1.25rem);
}

.search-box {
  width: 100%;
  max-width: 720px;
  margin-left: auto;
  margin-right: auto;
}

.search-box input,
.search-box input[type="text"],
.search-box input[type="search"] {
  font-size: 16px; /* Prevent iOS auto-zoom */
  min-height: 44px;
}

.search-box-submit {
  min-height: 44px;
  min-width: 44px;
}

@media (max-width: 480px) {
  .search-box .hide-mobile { display: none !important; }
  .search-box-submit { padding: 0 12px; }
  .popular-searches { font-size: 0.8125rem; gap: 6px; flex-wrap: wrap; }
  .popular-searches a { padding: 4px 8px; }
}

/* ---------- 4. Bootstrap rows: tighter gutters on small viewports only ---------- */
@media (max-width: 575.98px) {
  .row {
    --bs-gutter-x: 1rem;
  }
}

/* Section padding compresses gracefully on mobile */
.section,
section.section {
  padding-top: clamp(2rem, 4vw + 1rem, 4rem);
  padding-bottom: clamp(2rem, 4vw + 1rem, 4rem);
}

/* ---------- 5. Homepage categories grid ---------- */
.categories-grid-container .row > [class*="col-"] {
  margin-bottom: 0.5rem;
}

@media (max-width: 575.98px) {
  .categories-grid-container .row {
    margin-left: -8px;
    margin-right: -8px;
    row-gap: 0.75rem;
    gap: 0 !important;
  }

  .categories-grid-container .row > .col-6,
  .brands-grid-container .row > .col-6 {
    flex: 0 0 50% !important;
    max-width: 50% !important;
    width: 50% !important;
    padding-left: 8px;
    padding-right: 8px;
  }
}

/* ---------- 6. Brands / merchants horizontal lists ---------- */
.brands-grid-container .row > [class*="col-"] {
  flex: 0 0 auto;
  max-width: 100%;
}

@media (max-width: 575.98px) {
  .brands-grid-container .row { row-gap: 0.5rem; }
  .how-it-works-grid-container .row { row-gap: 0.75rem; }
}

/* ---------- 7. Footer grid ---------- */
.footer-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 32px;
}

@media (max-width: 991.98px) {
  .footer-grid { grid-template-columns: repeat(2, 1fr); gap: 24px; }
}

@media (max-width: 575.98px) {
  .footer-grid {
    grid-template-columns: 1fr 1fr;
    gap: 20px 24px;
  }
  .footer-brand {
    grid-column: 1 / -1;
    text-align: left;
  }
  .footer-bottom {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    text-align: left;
  }
  .footer-bottom-links {
    justify-content: flex-end;
  }
  .site-footer .container { padding-left: 16px; padding-right: 16px; }
}

/* Avoid mobile bottom-nav overlapping footer */
@media (max-width: 768px) {
  body { padding-bottom: 64px; }
  .site-footer { padding-bottom: 12px; }
}

/* ---------- 8. Touch targets (a11y / usability) ---------- */
@media (max-width: 768px) {
  a.btn,
  button,
  .btn,
  .header-nav-link,
  .mobile-nav-link,
  .pagination-btn,
  .pagination-num,
  .filter-toggle,
  .header-search-btn,
  .search-box-submit,
  input[type="submit"],
  input[type="button"] {
    min-height: 44px;
    line-height: 1.2;
  }
}

/* ---------- 9. Search results / category listing layout ---------- */
.srm-layout,
.search-page-chawkbazar .row,
.category-results-modern .row {
  flex-wrap: wrap;
}

@media (max-width: 991.98px) {
  .srm-sidebar,
  .filters-sidebar,
  .filters-column {
    width: 100%;
    max-width: 100%;
    flex: 0 0 100%;
    margin-bottom: 16px;
  }
}

/* Frontend product/result cards never overflow their column */
.product-card,
.srm-card,
.pricecompare-card,
.merchant-card,
.brand-card {
  max-width: 100%;
  overflow: hidden;
}

/* ---------- 10. Product detail page ---------- */
@media (max-width: 991.98px) {
  .pdp-hero-grid,
  .product-hero,
  .product-hero-grid {
    grid-template-columns: 1fr !important;
    display: grid;
    gap: 16px;
  }

  .pdp-image,
  .pdp-image-wrapper,
  .product-image,
  .product-image-wrapper {
    max-height: 60vh;
  }
}

.pdp-comparison-table-wrapper,
.comparison-table-wrapper,
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 575.98px) {
  .pdp-comparison-table { min-width: 640px; }
}

/* ---------- 11. Forms (contact, review, auth) ---------- */
@media (max-width: 575.98px) {
  .form-row,
  .row.form-row {
    flex-direction: column;
  }

  .form-row > [class*="col-"],
  .row.form-row > [class*="col-"] {
    width: 100%;
    max-width: 100%;
    flex: 0 0 100%;
  }

  input.form-control,
  select.form-control,
  textarea.form-control,
  .form-control {
    font-size: 16px; /* Prevent iOS zoom */
    min-height: 44px;
  }

  textarea.form-control {
    min-height: 120px;
  }
}

/* ---------- 12. Cards & generic containers ---------- */
.card,
.section-card,
.info-card {
  max-width: 100%;
}

@media (max-width: 575.98px) {
  .card-body,
  .section-card .body,
  .info-card .body {
    padding: 14px;
  }
}

/* ---------- 13. CMS / content pages (about, faq, terms, contact, blog) ---------- */
.cms-content,
.page-content,
article.post-content {
  max-width: 100%;
}

.cms-content img,
.page-content img,
article.post-content img {
  height: auto;
  max-width: 100%;
}

/* ---------- 14. iframe / embed wrappers ---------- */
.iframe-wrapper,
.embed-wrapper,
.video-wrapper,
.embed-responsive {
  position: relative;
  width: 100%;
  padding-top: 56.25%;
  overflow: hidden;
}

.iframe-wrapper > iframe,
.embed-wrapper > iframe,
.video-wrapper > iframe,
.video-wrapper > video,
.embed-responsive > iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* ---------- 15. Utility helpers ---------- */
.text-truncate-mobile {
  white-space: normal;
}
@media (max-width: 575.98px) {
  .text-truncate-mobile {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

.no-scroll-x { overflow-x: hidden; }

/* ---------- 16. iOS safe-area for sticky / fixed elements ---------- */
.site-header {
  padding-top: env(safe-area-inset-top, 0);
}

.mobile-nav,
.mobile-bottom-nav {
  padding-bottom: env(safe-area-inset-bottom, 0);
}
