/* ============================================
   TRAILX — Facet Filter (汽车配件多维筛选)
   Extends the sidebar block / toolbar visual language in main.css
   ============================================ */

/* ====== FORM ROOT ====== */
.facet-form { display: block; }

/* ====== ACTIVE FILTER CHIPS ====== */
.facet-active {
  background: var(--white);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.facet-active[hidden] { display: none; }
.facet-active-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.facet-active-label {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-light);
}
.facet-clear-all {
  font-size: 12px;
  font-weight: 700;
  color: var(--brand);
  border-bottom: 1px dashed currentColor;
  cursor: pointer;
}
.facet-clear-all:hover { color: var(--accent-dark); }

.facet-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.facet-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--gray-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  line-height: 1.3;
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition);
}
.facet-chip:hover {
  border-color: var(--accent);
  background: rgba(255, 106, 0, 0.08);
}
.facet-chip .chip-group {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-light);
}
.facet-chip .chip-value { font-weight: 600; }
.facet-chip .chip-x {
  width: 12px;
  height: 12px;
  color: var(--text-light);
  flex-shrink: 0;
}
.facet-chip:hover .chip-x { color: var(--dark); }

/* 归档上下文 chip：不可就地取消，点击离开该归档 */
.facet-chip--locked {
  background: rgba(21, 23, 28, 0.07);
  border-color: rgba(21, 23, 28, 0.22);
  cursor: pointer;
}
.facet-chip--locked .chip-group { color: var(--brand); }
.facet-chip--locked:hover {
  background: rgba(21, 23, 28, 0.12);
  border-color: var(--brand);
}

/* ====== CONTEXT LINKS (taxonomy archives) ====== */
.facet-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.facet-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--white);
  font-size: 12.5px;
  line-height: 1.3;
  color: var(--text-primary);
  text-decoration: none;
  transition: var(--transition);
}
.facet-link:hover {
  border-color: var(--accent);
  background: rgba(255, 106, 0, 0.08);
  color: var(--dark);
}
.facet-link.is-active {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--white);
  font-weight: 700;
}
.facet-link .f-count {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-light);
}
.facet-link.is-active .f-count { color: rgba(255, 255, 255, 0.72); }
.facet-link[data-back] {
  font-weight: 700;
  color: var(--brand);
  background: var(--gray-bg);
  width: 100%;
  justify-content: flex-start;
}
.facet-link[data-back]:hover { color: var(--accent-dark); }

/* ====== BLOCK ====== */
.facet-block .facet-body { padding: 12px 16px 14px; }

/* ====== OPTION LIST ====== */
.facet-options {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.facet-option {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  font-size: 13.5px;
  color: var(--text-primary);
}
.facet-option:hover { background: rgba(21, 23, 28, 0.05); }
.facet-option input[type="checkbox"],
.facet-option input[type="radio"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  cursor: pointer;
}
.facet-option .facet-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.facet-option .f-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-light);
  background: var(--gray-bg);
  border-radius: var(--radius);
  padding: 2px 8px;
  min-width: 26px;
  text-align: center;
  flex-shrink: 0;
}
.facet-option:has(input:checked) {
  background: rgba(255, 106, 0, 0.12);
}
.facet-option:has(input:checked) .facet-name { font-weight: 700; color: var(--brand); }
.facet-option:has(input:checked) .f-count {
  background: var(--accent);
  color: var(--dark);
}

/* 折叠：超出 limit 的选项默认隐藏 */
.facet-option.is-extra { display: none; }
.facet-block.is-expanded .facet-option.is-extra { display: flex; }

/* 命中数为 0：弱化但仍可点（多选 OR 场景下仍有意义） */
.facet-option.is-zero { opacity: 0.45; }
.facet-option.is-zero:hover { opacity: 0.75; }

/* 搜索过滤隐藏 */
.facet-option.is-filtered-out,
.facet-family.is-filtered-out { display: none !important; }

/* ====== SHOW MORE ====== */
.facet-more {
  display: inline-block;
  margin-top: 8px;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--brand);
  cursor: pointer;
  border-bottom: 1px dashed currentColor;
}
.facet-more:hover { color: var(--accent-dark); }

/* ====== SEARCH BOX (Model) ====== */
.facet-search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--gray-bg);
  transition: var(--transition);
}
.facet-search:focus-within {
  border-color: var(--accent);
  background: var(--white);
}
.facet-search .icon {
  width: 15px;
  height: 15px;
  color: var(--text-light);
  flex-shrink: 0;
}
.facet-search-input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 9px 0;
  font: inherit;
  font-size: 13px;
  color: var(--text-primary);
}

/* ====== TREE (Model families) ====== */
.facet-options--tree { gap: 4px; }
.facet-family { border-top: 1px dashed var(--border); padding-top: 6px; }
.facet-family:first-child { border-top: 0; padding-top: 0; }
.facet-family-head {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-light);
  padding: 8px 8px 4px;
}
.facet-family-head .facet-name { white-space: normal; }
.facet-family-head:hover { background: transparent; }
.facet-family-body {
  padding-left: 10px;
  border-left: 2px solid var(--border);
  margin-left: 14px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-height: 260px;
  overflow-y: auto;
}
.facet-option--child { font-size: 13px; padding: 6px 8px; }

.facet-empty-note {
  font-size: 12px;
  color: var(--text-light);
  text-align: center;
  padding: 10px 0 2px;
}
.facet-empty-note[hidden] { display: none; }

/* ====== TABS (Assembly) ====== */
.facet-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.facet-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--white);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  user-select: none;
}
.facet-tab input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}
.facet-tab:hover { border-color: var(--accent); color: var(--dark); }
.facet-tab .f-count {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-light);
}
.facet-tab.is-active {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--white);
}
.facet-tab.is-active .f-count { color: rgba(255, 255, 255, 0.7); }
.facet-tab.is-zero:not(.is-active) { opacity: 0.5; }
.facet-tab:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ====== CATEGORY GROUP TITLE ====== */
.facet-subtitle {
  font-size: 11.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--brand);
  padding: 10px 8px 4px;
  border-top: 1px dashed var(--border);
  margin-top: 6px;
}
.facet-subtitle:first-child { border-top: 0; margin-top: 0; padding-top: 0; }

/* ====== APPLY (no-JS fallback) ====== */
.facet-apply { width: 100%; justify-content: center; }

/* ====== RESULTS AREA ====== */
.facet-results {
  position: relative;
  min-height: 180px;
  transition: opacity 0.2s ease;
}
.facet-results.is-loading {
  opacity: 0.5;
  pointer-events: none;
}
.facet-results.is-loading::after {
  content: "";
  position: absolute;
  top: 80px;
  left: 50%;
  width: 34px;
  height: 34px;
  margin-left: -17px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: facetSpin 0.7s linear infinite;
}
@keyframes facetSpin { to { transform: rotate(360deg); } }

.product-grid--empty { display: block; }
.product-grid--empty .no-results { display: block; }

/* ====== LOAD MORE ====== */
.facet-load-more-wrap,
.facet-load-more-wrap-holder {
  display: flex;
  justify-content: center;
  margin-top: 32px;
}
.facet-load-more {
  min-width: 220px;
  justify-content: center;
}
.facet-load-more[disabled] { opacity: 0.6; cursor: default; }

/* ====== TOOLBAR COUNT ====== */
#facetCount strong { color: var(--dark); }

/* ====== TOP PROGRESS BAR (busy indicator) ====== */
html.facet-busy::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 100%;
  z-index: 9999;
  background: linear-gradient(90deg, var(--accent), var(--brand-light), var(--accent));
  background-size: 200% 100%;
  animation: facetProgress 1.1s linear infinite;
}
@keyframes facetProgress {
  from { background-position: 0 0; }
  to { background-position: -200% 0; }
}

/* ====== RESPONSIVE ====== */
@media (min-width: 769px) and (max-width: 1199px) {
  /* 平板下侧栏转为横向卡片流：筛选面板占整行，避免挤压 */
  .main-layout .sidebar #facetSidebar { flex: 1 1 100%; }
  .facet-form { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
  .facet-form > .facet-active { grid-column: 1 / -1; }
  .facet-block { margin-bottom: 0; }
  .facet-family-body { max-height: 200px; }
}

@media (max-width: 767px) {
  .facet-form { display: block; }
  .facet-block { margin-bottom: 16px; }
  .facet-option { padding: 9px 8px; }
  .facet-family-body { max-height: 230px; }
  .facet-tab { padding: 8px 12px; }
  .facet-results.is-loading::after { top: 60px; }
  .facet-load-more { width: 100%; min-width: 0; }
}

/* ====== DARK THEME SAFETY ======
   本主题为浅色主题；若前台开启了深色模式，通过 .is-dark 容器覆盖。 */
.is-dark .facet-active,
.is-dark .facet-block { background: var(--dark-2); border-color: rgba(255, 255, 255, 0.12); }
.is-dark .facet-option { color: rgba(255, 255, 255, 0.85); }
.is-dark .facet-option .f-count { background: rgba(255, 255, 255, 0.08); color: rgba(255, 255, 255, 0.6); }
.is-dark .facet-chip { background: rgba(255, 255, 255, 0.06); border-color: rgba(255, 255, 255, 0.12); color: rgba(255, 255, 255, 0.85); }
.is-dark .facet-search { background: rgba(255, 255, 255, 0.06); border-color: rgba(255, 255, 255, 0.12); }
.is-dark .facet-search-input { color: rgba(255, 255, 255, 0.9); }
.is-dark .facet-tab { background: transparent; border-color: rgba(255, 255, 255, 0.16); color: rgba(255, 255, 255, 0.75); }
.is-dark .facet-link { background: rgba(255, 255, 255, 0.06); border-color: rgba(255, 255, 255, 0.12); color: rgba(255, 255, 255, 0.85); }
.is-dark .facet-link.is-active { background: var(--accent); border-color: var(--accent); color: var(--dark); }
.is-dark .facet-link .f-count { background: rgba(255, 255, 255, 0.08); color: rgba(255, 255, 255, 0.6); }
.is-dark .facet-link.is-active .f-count { background: transparent; color: rgba(0, 0, 0, 0.55); }
.is-dark .facet-chip--locked { background: rgba(255, 255, 255, 0.06); border-color: rgba(255, 255, 255, 0.16); }
.is-dark .facet-chip--locked .chip-group { color: var(--accent); }

/* ============================================================
   FACET DETAIL POLISH — v1.9.1
   ============================================================ */

/* ---- Custom checkbox / radio inside the facet panel ---- */
.facet-option input[type="checkbox"],
.facet-option input[type="radio"] {
  -webkit-appearance: none;
  appearance: none;
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  margin: 0;
  position: relative;
  background: var(--white);
  border: 1.5px solid #C7CCD4;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}
.facet-option input[type="radio"] { border-radius: 50%; }

.facet-option:hover input[type="checkbox"],
.facet-option:hover input[type="radio"] { border-color: var(--accent-line); }

.facet-option input[type="checkbox"]:checked,
.facet-option input[type="radio"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.facet-option input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1.5px;
  width: 4px;
  height: 8px;
  border: solid var(--white);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.facet-option input[type="radio"]:checked {
  background: var(--white);
  border-width: 5px;
}

.facet-option input:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

/* Family head checkbox reads as a "select the whole family" switch */
.facet-family-head input[type="checkbox"] { width: 15px; height: 15px; }
.facet-family-head input[type="checkbox"]:checked::after {
  left: 4px;
  top: 1px;
  width: 4px;
  height: 7px;
}

/* Rows: a touch more air + a left accent rail when selected */
.facet-option { padding: 7px 9px; }
.facet-option:has(input:checked) {
  box-shadow: inset 3px 0 0 var(--accent);
}

/* ---- "Show more" as a real toggle control ---- */
.facet-more {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--white);
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--brand);
  cursor: pointer;
  transition: var(--transition);
}
.facet-more:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
}
.facet-more::after {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform 0.2s ease;
}
.facet-block.is-expanded .facet-more::after { transform: translateY(1px) rotate(-135deg); }

/* ---- Active context link keeps its hover affordance ---- */
.facet-link.is-active:hover {
  background: var(--dark);
  border-color: var(--dark);
  color: var(--white);
}

/* ---- "Clear all" behaves like a button, not a dangling underline ---- */
.facet-clear-all {
  border-bottom: 0;
  padding: 2px 0;
}
.facet-clear-all:hover { border-bottom: 1px solid currentColor; }

/* ---- Assembly tabs: crisper active state + a11y ring ---- */
.facet-tab { padding: 8px 13px; }
.facet-tab.is-active {
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25), 0 2px 8px -4px rgba(14, 16, 20, 0.5);
}
.facet-tab:focus-within { outline: none; box-shadow: var(--ring); }

/* ---- Search field: subtle inset + clear focus ---- */
.facet-search { padding: 0 11px; }
.facet-search:focus-within { background: var(--white); box-shadow: var(--ring); }

/* ---- Result spinner sits on the surface, not floating ---- */
.facet-results.is-loading { opacity: 0.55; }

/* ---- Restore intentional spacing the generic row rule would flatten ---- */
.facet-option.facet-family-head { padding: 10px 9px 5px; }
.facet-option.facet-option--child { padding: 7px 9px; }

/* ---- Mobile: comfortable tap targets (≥44px) ---- */
@media (max-width: 767px) {
  .facet-option { padding: 11px 9px; }
  .facet-option.facet-family-head { padding: 11px 9px 6px; }
  .facet-link,
  .facet-chip,
  .facet-more,
  .facet-tab { min-height: 36px; }
  .facet-active { padding: 12px; }
  .facet-block .facet-body { padding: 12px 14px 14px; }
}
