/*
 * Hamid Fathi — Global Mobile Responsive Layer
 * هدف: هر بخش در موبایل فضای کافی داشته باشد؛
 * موارد چندستونه فقط وقتی واقعاً جا دارند کنار هم بمانند.
 */

html, body { max-width:100%; overflow-x:hidden; }
*, *::before, *::after { min-width:0; }

@media (max-width: 767px) {
  .container { width: min(100% - 24px, 1180px); }

  /* Header */
  .header-main {
    grid-template-columns: minmax(0,1fr) auto !important;
    gap: 10px !important;
    padding: 12px 0 !important;
  }
  .search { grid-column: 1 / -1 !important; grid-row: 2 !important; }
  .header-actions { gap: 7px !important; }
  .main-nav { overflow-x:auto; overflow-y:hidden; -webkit-overflow-scrolling:touch; }
  .main-nav ul { justify-content:flex-start !important; gap:18px !important; white-space:nowrap; }
  .main-nav a { padding:9px 0; }

  /* Homepage sections */
  .section { padding:18px 0 38px; }
  .section-head {
    align-items:flex-start !important;
    flex-direction:column !important;
    gap:8px !important;
  }
  .section-head .text-link { align-self:flex-start; }
  .hero { margin:18px 0 34px; }
  .hero-box { min-height:420px; border-radius:22px; }
  .hero-content { max-width:none; padding:28px 22px; }
  .hero h1 { font-size:clamp(30px,9vw,40px); }
  .hero p { max-width:none; }

  .category-grid { grid-template-columns:repeat(2,minmax(0,1fr)) !important; }
  .product-grid { grid-template-columns:repeat(2,minmax(0,1fr)) !important; }
  .brand-row { grid-template-columns:repeat(2,minmax(0,1fr)) !important; }
  .benefits {
    grid-template-columns:1fr !important;
    gap:10px !important;
  }
  .benefit { padding:17px 18px; }
  .promo {
    display:flex !important;
    flex-direction:column !important;
    align-items:stretch !important;
    padding:24px 20px !important;
    gap:14px !important;
  }
  .promo .btn { width:100%; margin-top:2px; }
  .footer-grid { grid-template-columns:1fr !important; gap:24px !important; }

  /* Internal page builder */
  .bl-pb-row { flex-direction:column !important; margin-inline:0 !important; }
  .bl-pb-col {
    width:100% !important;
    padding-inline:0 !important;
  }
  .bl-pb-col-in { width:100%; }
  .bl-pb-widget { width:100%; }

  /* Generic builder widgets: prevent horizontal overflow */
  .bl-ib-side { flex-wrap:wrap; }
  .bl-w-image img, .bl-w-imagebox img { max-width:100%; height:auto; }
  .bl-tab-nav { overflow-x:auto; flex-wrap:nowrap; padding-bottom:4px; }
  .bl-tab-btn { flex:none; }
  .bl-w-testi { padding:20px; }

  /* WooCommerce global grids */
  body.woocommerce .bl-grid ul.products,
  body.woocommerce ul.products {
    grid-template-columns:repeat(2,minmax(0,1fr)) !important;
    gap:12px !important;
  }

  /* Shop */
  .bl-shop-head { padding:22px 18px 24px !important; border-radius:22px !important; }
  .bl-toolbar {
    flex-direction:column !important;
    align-items:stretch !important;
  }
  .bl-toolbar .woocommerce-result-count,
  .bl-toolbar .woocommerce-ordering {
    width:100% !important;
  }
  .bl-toolbar .woocommerce-ordering select { width:100% !important; }

  /* Product page */
  .bl-pd-stage {
    grid-template-columns:1fr !important;
    gap:26px !important;
    padding:26px 18px 32px !important;
    border-radius:26px !important;
  }
  .bl-pd-media {
    order:1 !important;
    width:min(100%,360px) !important;
    margin-inline:auto;
  }
  .bl-pd-summary { order:2 !important; width:100%; }
  .bl-story { grid-template-columns:1fr !important; }
  .bl-story-art { margin-inline:auto; max-width:100%; }
  .bl-more.bl-more-row { grid-template-columns:1fr !important; }
  body.single-product div.product.bl-pd .bl-pd-summary .single_add_to_cart_button {
    min-width:0;
  }

  /* Cart / checkout / account: columns become stacked */
  .bl-cart,
  .bl-checkout,
  .bl-account-grid,
  .bl-account-layout,
  .bl-account-main,
  .bl-co-grid {
    grid-template-columns:1fr !important;
  }

  /* Any Woo two-column form becomes one column */
  body.woocommerce-checkout :is(
    .woocommerce-billing-fields__field-wrapper,
    .woocommerce-shipping-fields__field-wrapper
  ) {
    grid-template-columns:1fr !important;
  }

  /* Account navigation should not squeeze content */
  .woocommerce-account .woocommerce-MyAccount-navigation {
    width:100% !important;
    float:none !important;
    margin-bottom:18px;
  }
  .woocommerce-account .woocommerce-MyAccount-content {
    width:100% !important;
    float:none !important;
  }

  /* Tables: preserve usability without breaking the page */
  .woocommerce table.shop_table,
  .woocommerce table.woocommerce-orders-table {
    width:100% !important;
  }
  .woocommerce table.shop_table_responsive thead { display:none; }
  .woocommerce table.shop_table_responsive tr {
    display:block;
    padding:12px 0;
    border-bottom:1px solid var(--line);
  }
  .woocommerce table.shop_table_responsive td {
    display:flex !important;
    align-items:center;
    justify-content:space-between;
    gap:12px;
    text-align:end !important;
    width:100% !important;
    border:0 !important;
  }
  .woocommerce table.shop_table_responsive td::before {
    float:none !important;
    flex:0 0 auto;
    margin-inline-end:auto;
  }

  /* Blog */
  .bl-sub { grid-template-columns:1fr !important; padding:24px 18px !important; }
  .bl-sub-fields { flex-direction:column; }
  .bl-sub-fields input,
  .bl-sub-fields .btn { width:100%; flex:0 0 auto; }
}

@media (max-width: 560px) {
  .container { width:min(100% - 20px,1180px); }

  .header-main { grid-template-columns:minmax(0,1fr) auto !important; }
  .logo { font-size:20px; }

  .category-grid { grid-template-columns:1fr !important; }
  .category-card { min-height:170px; }

  /* Two products per row remain usable; content inside each card is stacked. */
  .product-grid,
  body.woocommerce .bl-grid ul.products,
  body.woocommerce ul.products {
    grid-template-columns:repeat(2,minmax(0,1fr)) !important;
    gap:9px !important;
  }

  .product-card { border-radius:16px; }
  .product-info { padding:9px 8px 11px; }
  .product-name { font-size:12.5px; }
  .product-card .price { font-size:13px; }

  .brand-row { grid-template-columns:1fr !important; }
  .brand { min-height:64px; }

  .hero-box { min-height:390px; }
  .hero-content { padding:24px 19px; }
  .hero h1 { font-size:32px; }

  /* Never allow action rows to overflow */
  .promo,
  .bl-wa-ty,
  .bl-pv-head,
  .bl-tm-by,
  .bl-post-author {
    max-width:100%;
  }
  .promo .btn,
  .bl-wa-btn,
  .bl-pv-head .button { width:100%; }

  .bl-wa-ty { flex-wrap:wrap; }
  .bl-wa-ty-body { flex:1 1 calc(100% - 54px); }
  .bl-wa-btn { margin-top:4px; }

  .bl-sticky { gap:8px; }
  .bl-sticky button { padding-inline:16px; }
}

@media (max-width: 380px) {
  .product-grid,
  body.woocommerce .bl-grid ul.products,
  body.woocommerce ul.products {
    grid-template-columns:1fr !important;
  }
  .product-thumb { aspect-ratio:1 / .95; }
  .header-actions .icon-btn { width:38px; height:38px; }
}
