/* 
 * Twinkle Trimmings: Product Archives Module Styles 
 * Phase 5: Optimized & Refactored (Clean Architecture)
 */

/* ==========================================================================
   1. 全局变量与底层外壳 (防 Elementor 污染 & 防坍塌)
   ========================================================================== */
.tt-module-wrapper {
  /* 品牌视觉映射 */
  --tt-primary: var(--e-global-color-primary, #7f4c15);
  --tt-accent: var(--e-global-color-03899bb, #aa440f);
  --tt-light: var(--e-global-color-1f04b25, #fdf3d8);
  --tt-text: var(--e-global-color-text, #333333);

  font-family: inherit;

  /* 强制结构化与反坍塌机制 */
  display: block !important;
  height: auto !important;
  min-height: max-content !important;
  overflow: visible !important;

  /* 底部预留空间，防止与 Footer 重合 */
  padding-bottom: 60px;
  margin-bottom: 100px !important;
}

.tt-container {
  max-width: 1140px;
  margin: 0 auto;
  padding: 0;
  display: block !important;
  height: auto !important;
}

@media (max-width: 1199px) {
  .tt-container {
    padding: 0 30px;
  }
}

@media (max-width: 767px) {
  .tt-module-wrapper {
    padding-bottom: 60px;
  }
  .tt-container {
    padding: 0 20px;
    clear: both;
    overflow: hidden; /* 移动端触发 BFC 防坍塌 */
  }
}

/* ==========================================================================
   2. 通用组件：Banner (横幅)
   ========================================================================== */
.tt-category-banner {
  position: relative;
  width: 100%;
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  margin-bottom: 40px;
}
.tt-banner-tall {
  min-height: 45vh;
}
.tt-banner-normal {
  min-height: 25vh;
}

.tt-banner-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}
.tt-banner-content {
  position: relative;
  z-index: 2;
  color: #fff;
  padding: 20px;
  max-width: 700px;
}
.tt-banner-title {
  color: #fff !important;
  font-size: 2.5rem;
  margin-bottom: 10px;
}

/* =========================================================================
   3. 页面布局 A：一级分类导航页 (Tier 1 & Tier 2/3 Grid)
   ========================================================================= */
.tt-tier2-group-title {
  text-align: center;
  color: var(--tt-primary);
  font-size: 1.8rem;
  margin: 50px 0 30px;
}

.tt-tier3-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 30px;
  max-width: 800px;
  margin: 0 auto;
}

.tt-tier3-card {
  position: relative;
  aspect-ratio: 16/9;
  background-size: cover;
  background-position: center;
  border-radius: 4px;
  overflow: hidden;
}

.tt-tier3-card-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s;
}
.tt-tier3-card:hover .tt-tier3-card-overlay {
  background: rgba(0, 0, 0, 0.1);
}
.tt-tier3-card-title {
  color: #fff;
  font-size: 1.4rem;
  text-transform: uppercase;
  margin: 0;
}

/* 一级分类页特有的底部间距控制 */
.tt-tier2-group-title:last-of-type,
.tt-tier3-grid:last-child {
  margin-bottom: 80px;
}

/* 移动端特殊兜底：转换为 flex 以彻底解决空方块高度坍塌 Bug */
@media (max-width: 767px) {
  .tt-tier3-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 40px !important;
  }
  .tt-tier3-card {
    width: 100%;
    min-height: 200px; /* 强制锁底高度 */
    flex-shrink: 0;
  }
}

/* ==========================================================================
   4. 页面布局 B：高度定制化产品列表 (Customizer)
   ========================================================================== */
.tt-customizer-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 30px;
}
@media (min-width: 768px) {
  .tt-customizer-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.tt-customizer-card {
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  padding: 20px 30px;
  gap: 20px;
}

.tt-card-img {
  flex: 0 0 45%;
}
.tt-card-img img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
}
.tt-card-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

h3.tt-card-title {
  font-size: 1rem;
  margin: 0.25rem;
  color: var(--tt-accent);
}
.tt-card-desc p {
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

@media (min-width: 768px) {
  .tt-customizer-card {
    flex-direction: row;
  }
  .tt-card-info {
    justify-content: space-between;
  }
  .tt-card-img {
    flex: 0 0 40%;
  }
}

/* ==========================================================================
   5. 页面布局 C：常规归档页 (带侧边栏结构)
   ========================================================================== */
.tt-archive-layout {
  display: flex;
  flex-direction: column;
  gap: 40px;
}
@media (min-width: 992px) {
  .tt-archive-layout {
    flex-direction: row;
  }
}

/* 5.1 侧边栏菜单 */
.tt-sidebar {
  width: 100%;
}
@media (min-width: 992px) {
  .tt-sidebar {
    width: 260px;
    flex-shrink: 0;
  }
}

.tt-sidebar-title {
  background: var(--tt-primary);
  color: #fff;
  padding: 12px 15px;
  font-size: 1rem;
  font-weight: bold;
  margin-bottom: 2px;
}

.tt-sidebar-menu {
  list-style: none;
  padding: 0;
  margin: 0;
}
.tt-sidebar-menu li {
  margin-bottom: 1px;
}
.tt-sidebar-menu a {
  display: block;
  padding: 10px 15px;
  color: var(--tt-text);
  text-decoration: none;
  font-size: 0.95rem;
}
.tt-sidebar-menu a:hover,
.tt-sidebar-menu a.active {
  background: var(--tt-primary);
  color: #fff;
}

/* 5.2 主内容区 */
.tt-main-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   6. 交互组件：操作栏 (排序 + 搜索)
   ========================================================================== */
.tt-action-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 20px;
  margin-bottom: 30px;
  width: 100%;
}
@media (max-width: 767px) {
  .tt-action-bar {
    flex-direction: column;
    align-items: stretch;
  }
}

/* 左侧原生排序 */
.tt-sorting-wrapper .woocommerce-ordering {
  display: flex;
  align-items: center;
  margin: 0;
}
.tt-sorting-wrapper .woocommerce-ordering::before {
  content: "SORT BY";
  color: #999;
  font-size: 0.85rem;
  letter-spacing: 1px;
  white-space: nowrap;
  margin-right: 10px;
}
.tt-sorting-wrapper select {
  padding: 8px 30px 8px 10px;
  border: 1px solid #ddd;
  border-radius: 3px;
  background: #fff;
  outline: none;
  height: 38px;
}

/* 右侧搜索框 */
.tt-inline-search form {
  position: relative;
  display: flex;
  width: 260px;
}
@media (max-width: 767px) {
  .tt-inline-search form {
    width: 100%;
  }
}
.tt-inline-search input {
  width: 100%;
  height: 38px;
  padding: 8px 40px 8px 15px;
  border: 1px solid #ddd;
  border-radius: 3px;
  outline: none;
}
.tt-inline-search button {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none !important;
  color: #999;
  cursor: pointer;
  padding: 0 !important;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tt-inline-search button:hover,
.tt-inline-search button:focus {
  background-color: transparent !important;
  color: #555 !important;
}

/* ==========================================================================
   7. 核心业务：单品列表网格与卡片
   ========================================================================== */
.tt-product-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  width: 100%;
}
@media (max-width: 991px) {
  .tt-product-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.tt-prod-card {
  background: #fff;
  display: flex;
  flex-direction: column;
}

/* 强制图片比例防 Elementor 污染 */
.tt-prod-img-wrap {
  position: relative;
  aspect-ratio: 1/1;
  background: #000;
  overflow: hidden;
  margin-bottom: 15px;
}
.tt-module-wrapper .tt-prod-card img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  padding: 0 !important;
  margin: 0 !important;
  border: none !important;
}

/* 悬浮蒙版层 */
.tt-prod-hover-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s;
  padding: 15px;
  text-align: center;
}
.tt-prod-card:hover .tt-prod-hover-overlay {
  opacity: 1;
}

.tt-hover-title {
  font-size: 1rem;
  color: var(--tt-text);
  margin-bottom: 10px;
  font-weight: normal;
}

.tt-prod-materials-list {
  display: flex;
  gap: 8px;
  margin-bottom: 15px;
  justify-content: center;
}
.tt-module-wrapper img.tt-mat-icon {
  width: 24px !important;
  height: 24px !important;
}

.tt-btn-accent {
  background: var(--tt-accent);
  color: #fff !important;
  padding: 6px 18px;
  border-radius: 4px;
  font-size: 0.85rem;
  text-decoration: none;
  text-align: center;
  font-weight: 500;
}

/* 卡片底部文字信息区 */
.tt-prod-meta {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.tt-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.9rem;
}

.tt-sku,
.tt-size {
  color: var(--tt-text);
  font-weight: bold;
}
.tt-price-sale {
  color: var(--tt-text);
}
.tt-price-sale strong {
  color: var(--tt-accent);
  font-weight: bold;
}
.tt-price-regular {
  color: #aaa;
  text-decoration: line-through;
  font-size: 0.85rem;
}

/* ==========================================================================
   8. 交互组件：分页器
   ========================================================================== */
.tt-pagination {
  margin-top: 40px;
  text-align: center;
}
.tt-pagination ul {
  list-style: none;
  padding: 0;
  display: inline-flex;
  gap: 5px;
}
.tt-pagination li span,
.tt-pagination li a {
  padding: 8px 12px;
  border: 1px solid #ddd;
  text-decoration: none;
  color: var(--tt-text);
}
.tt-pagination li span.current {
  background: var(--tt-primary);
  color: #fff;
  border-color: var(--tt-primary);
}

/* ==========================================================================
   9. 页面布局 D：独立搜索结果页 (无侧边栏 4 列布局)
   ========================================================================== */
.tt-search-page-wrapper .tt-container {
  max-width: 1140px;
  margin-left: auto;
  margin-right: auto;
}

@media (min-width: 992px) {
  .tt-search-page-wrapper .tt-product-grid {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 15px;
  }
}
