/* ff-grid-12 */
/* ==========================================================================
   菲菲商店 v11 — 商品列表網格（Shop / 分類 / 品牌 全部共用）
   目的：不管外掛、舊快取、版型（flex / grid 母容器）怎麼排，
        手機上一律 2 欄、卡片至少 140px 寬，不會再變成一條細長條。
   全部規則加 !important，並且這份檔案同時用 <link> 載入 + 行內輸出兩次，
   任何一層被快取外掛吃掉，另一層還在。
   ========================================================================== */

/* ---------- 1. 容器：一定是一般區塊，不要被 flex / grid / float 影響 ---------- */
body.woocommerce .woocommerce-wrap,
body.woocommerce-page .woocommerce-wrap,
body.woocommerce .ff-content,
body.woocommerce-page .ff-content,
body.woocommerce .ff-shop-main,
body.woocommerce-page .ff-shop-main {
  display: block !important;
  float: none !important;
  clear: both !important;
  min-width: 0 !important;
  box-sizing: border-box !important;
}

/* ---------- 2. 工具列（結果數 + 排序）：自己一個區塊，獨佔整行 ---------- */
.ff-shop-toolbar,
body.woocommerce .ff-shop-toolbar,
body.woocommerce-page .ff-shop-toolbar {
  display: block !important;
  float: none !important;
  clear: both !important;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  margin: 0 0 18px !important;
  padding: 0 !important;
  overflow: visible !important;
  box-sizing: border-box !important;
}
.ff-shop-toolbar::after {
  content: "" !important;
  display: block !important;
  clear: both !important;
  height: 0 !important;
}

body.woocommerce .woocommerce-result-count,
body.woocommerce-page .woocommerce-result-count,
.woocommerce .woocommerce-result-count {
  float: none !important;
  display: block !important;
  width: 100% !important;
  margin: 2px 0 8px !important;
  font-size: 13px !important;
  line-height: 1.6 !important;
  color: #7b8494 !important;
}

body.woocommerce .woocommerce-ordering,
body.woocommerce-page .woocommerce-ordering,
.woocommerce .woocommerce-ordering {
  float: none !important;
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 0 4px !important;
  text-align: right;
  flex: 0 0 100% !important;
}

body.woocommerce .woocommerce-ordering select,
body.woocommerce-page .woocommerce-ordering select {
  display: inline-block !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* ---------- 3. 列表本體：Grid，寬度永遠吃滿，絕不當 flex 子項被壓窄 ---------- */
ul.products,
body.woocommerce ul.products,
body.woocommerce-page ul.products {
  display: grid !important;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)) !important;
  gap: 20px !important;
  margin: 0 0 28px !important;
  padding: 0 !important;
  list-style: none !important;
  float: none !important;
  clear: both !important;
  position: static !important;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  /* 母容器是 flex 時，這兩行是關鍵：不准縮、直接佔滿一整列 */
  flex: 0 0 100% !important;
  box-sizing: border-box !important;
  overflow: visible !important;
}

/* clearfix 假元素在 Grid 裡會各佔一格 → 第一格空白、商品掉到下一行 */
ul.products::before,
ul.products::after {
  content: none !important;
  display: none !important;
  clear: none !important;
}

/* ---------- 4. 卡片：撐滿格子、直的、不能有固定窄寬 ---------- */
ul.products li.product,
body.woocommerce ul.products li.product,
body.woocommerce-page ul.products li.product {
  float: none !important;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  position: relative !important;
  box-sizing: border-box !important;
  justify-self: stretch !important;
  align-self: stretch !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
}

/* ---------- 5. 圖片：撐滿卡片寬、固定高度、完整顯示 ---------- */
ul.products li.product a img,
ul.products li.product img,
.woocommerce ul.products li.product a img {
  width: 100% !important;
  max-width: 100% !important;
  height: 210px !important;
  object-fit: contain !important;
  object-position: center !important;
  margin: 0 auto !important;
  display: block !important;
  background: #fff !important;
}
ul.products li.product .ff-loop-img {
  display: block !important;
  width: 100% !important;
  box-sizing: border-box !important;
  padding: 10px !important;
}
ul.products li.product .ff-loop-body {
  width: 100% !important;
  min-width: 0 !important;
  box-sizing: border-box !important;
}

/* ---------- 6. 標題：最多 2 行，長品名不會把卡片撐成長條 ---------- */
ul.products li.product .woocommerce-loop-product__title {
  display: -webkit-box !important;
  -webkit-box-orient: vertical !important;
  -webkit-line-clamp: 2 !important;
  overflow: hidden !important;
  width: 100% !important;
  font-size: 14px !important;
  line-height: 1.5 !important;
  padding: 0 !important;
  margin: 0 !important;
  word-break: break-word !important;
  overflow-wrap: anywhere !important;
}
/* 標題裡的 <a> 要維持 inline，否則 -webkit-line-clamp 不生效 */
ul.products li.product .woocommerce-loop-product__title a {
  display: inline !important;
  overflow: visible !important;
}

ul.products li.product .ff-loop-btn,
ul.products li.product .button {
  box-sizing: border-box !important;
  max-width: 100% !important;
}

/* ---------- 7. 平板：3 欄 ---------- */
@media (max-width: 1100px) {
  ul.products,
  body.woocommerce ul.products,
  body.woocommerce-page ul.products {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }
}

/* ---------- 8. 手機：2 欄、工具列上下堆疊、下拉框滿寬 ---------- */
@media (max-width: 760px), (max-device-width: 760px) {
  body.woocommerce .woocommerce-result-count,
  body.woocommerce-page .woocommerce-result-count {
    margin: 0 0 8px !important;
    font-size: 12.5px !important;
  }
  body.woocommerce .woocommerce-ordering,
  body.woocommerce-page .woocommerce-ordering {
    margin: 0 0 14px !important;
    text-align: left;
  }
  body.woocommerce .woocommerce-ordering select,
  body.woocommerce-page .woocommerce-ordering select {
    width: 100% !important;
    font-size: 15px !important;
    padding: 11px 12px !important;
  }
  ul.products,
  body.woocommerce ul.products,
  body.woocommerce-page ul.products {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 12px !important;
    margin-bottom: 22px !important;
  }
  ul.products li.product a img,
  ul.products li.product img,
  .woocommerce ul.products li.product a img { height: 148px !important; }
  ul.products li.product .ff-loop-img { padding: 8px !important; }
  ul.products li.product .ff-loop-body { padding: 10px 10px 12px !important; gap: 5px !important; }
  ul.products li.product .woocommerce-loop-product__title {
    font-size: 13.5px !important;
    line-height: 1.45 !important;
    min-height: 39px !important;
  }
  ul.products li.product .ff-loop-price { font-size: 15px !important; }
  ul.products li.product .ff-stars { font-size: 13px !important; letter-spacing: 1px !important; }
  ul.products li.product .ff-stock { font-size: 11.5px !important; }
  ul.products li.product .ff-loop-btn {
    font-size: 13px !important;
    padding: 9px 6px !important;
    border-radius: 7px !important;
  }
}

/* ---------- 9. 小手機 ---------- */
@media (max-width: 380px), (max-device-width: 380px) {
  ul.products,
  body.woocommerce ul.products,
  body.woocommerce-page ul.products {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }
  ul.products li.product a img,
  ul.products li.product img,
  .woocommerce ul.products li.product a img { height: 132px !important; }
  ul.products li.product .ff-loop-body { padding: 9px 8px 11px !important; }
  ul.products li.product .woocommerce-loop-product__title { font-size: 12.5px !important; }
}

/* ---------- 10. 極窄容器兜底：只有一欄也要佔滿（JS 修不到時的最後防線） ---------- */
@media (max-width: 300px) {
  ul.products,
  body.woocommerce ul.products,
  body.woocommerce-page ul.products {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}

/* ---------- 11. v12：子分類卡片、外掛迴圈、被側欄擠窄的版面 ---------- */
/* 子分類（li.product-category）也用同一套格子，不會各自變成細長條 */
ul.products li.product-category,
body.woocommerce ul.products li.product-category,
body.woocommerce-page ul.products li.product-category {
  float: none !important;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  box-sizing: border-box !important;
}
ul.products li.product-category img,
body.woocommerce ul.products li.product-category img {
  width: 100% !important;
  height: auto !important;
  max-height: 160px !important;
  object-fit: contain !important;
}

/* 常見內容容器：被當成 flex / grid 子項時不准縮成 0 或一小格 */
body.woocommerce .site-main,
body.woocommerce-page .site-main,
body.woocommerce #primary,
body.woocommerce-page #primary,
body.woocommerce .content-area,
body.woocommerce-page .content-area,
body.woocommerce .ff-content,
body.woocommerce-page .ff-content {
  min-width: 0 !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* 極窄容器：只剩 1 欄也要撐滿，不要留一條縫 */
@media (max-width: 760px) {
  body.woocommerce ul.products li.product .woocommerce-loop-product__title,
  body.woocommerce-page ul.products li.product .woocommerce-loop-product__title {
    word-break: break-word !important;
    overflow-wrap: anywhere !important;
  }
}
