/* ==========================================================
   归类页筛选
   主题图标横排 + 下拉筛选按钮行 + 结果行。手机（< 1024px）上图标行与
   按钮行各自横滑，下拉改成从底部弹出的面板。
   ========================================================== */

/* 带 display 的类（.card-grid 等）会盖过浏览器给 [hidden] 的 display:none。 */
.af[hidden],
.af [hidden] {
  display: none !important;
}

/* ---------- 主题图标横排 ---------- */

.af-themes {
  margin-bottom: var(--space-3);
}

.af-themes-list {
  display: flex;
  gap: 0.25rem;
  margin: 0;
  padding: 0 0 var(--space-1);
  list-style: none;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  /* flex 里的 min-width:auto 会让 overflow-x 失效，整条把页面撑出横向滚动。 */
  min-width: 0;
  max-width: 100%;
}

.af-themes-list::-webkit-scrollbar {
  display: none;
}

.af-themes-list > li {
  flex: 0 0 auto;
  scroll-snap-align: start;
}

.af-theme {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  width: 6.25rem;
  padding: 0.5rem 0.25rem;
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  text-wrap: balance;
  transition: var(--transition);
}

.af-theme:hover,
.af-theme:focus-visible {
  background: var(--color-mist);
  color: var(--color-accent-hover);
}

.af-theme-icon {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  background: var(--color-accent-soft);
  color: var(--color-accent);
}

.af-theme-icon svg {
  width: 1.5rem;
  height: 1.5rem;
}

.af-theme.is-current {
  color: var(--color-text);
}

.af-theme.is-current .af-theme-icon {
  background: var(--color-accent);
  color: var(--color-white);
}

/* ---------- 按钮行 ---------- */

.af {
  margin-bottom: var(--space-3);
}

.af-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.af-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.af-filter {
  position: relative;
}

.af-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--color-border-strong);
  border-radius: 999px;
  background: var(--color-white);
  color: var(--color-text);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.af-btn:hover {
  border-color: var(--color-accent);
}

.af-btn.is-active {
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
}

.af-btn.is-loading {
  cursor: progress;
  opacity: 0.7;
}

.af-btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.af-badge {
  display: inline-grid;
  place-items: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: var(--color-accent);
  color: var(--color-white);
  font-size: 0.7rem;
}

.af-side {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

.af-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

/* 屏幕阅读器专用文字是 absolute：要让它的包含块落在横滑容器里，才会被裁掉而不是撑宽页面。 */
.af-sort {
  position: relative;
}

.af-sort select {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-white);
  color: var(--color-text);
  font: inherit;
  font-size: 0.875rem;
}

/* ---------- 下拉 ---------- */

.af-panel {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  z-index: 50;
  min-width: 15rem;
  max-height: 60vh;
  overflow: auto;
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-white);
  box-shadow: var(--shadow-md);
}

.af-panel:focus {
  outline: none;
}

.af-panel-head {
  display: none;
  margin: 0 0 0.75rem;
  font-weight: 700;
}

.af-options {
  display: grid;
  gap: 0.4rem;
}

.af-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  white-space: nowrap;
  cursor: pointer;
}

/* 数量用次要文字色（白底 7.3:1）；为 0 的整行变灰，禁用的控件不要求对比度。 */
.af-n {
  color: var(--color-text-secondary);
  font-size: 0.85em;
}

.af-option.is-empty {
  color: var(--color-text-muted);
  cursor: default;
}

.af-option.is-empty .af-n {
  color: inherit;
}

.af-price {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.af-price label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--color-text-secondary);
}

.af-price input {
  width: 100%;
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius);
  font: inherit;
}

.af-panel-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: var(--space-2);
}

.af-clear,
.af-retry {
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-accent);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- 结果行 ---------- */

.af-results {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-top: var(--space-2);
}

.af-count {
  margin: 0;
  outline: none;
  font-weight: 700;
}

.af-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.af-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-mist);
  color: var(--color-text);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.af-chip-x {
  font-size: 1rem;
  line-height: 1;
}

.af-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

.af-empty {
  padding: var(--space-6) 0;
  text-align: center;
}

.af-grid {
  margin-top: var(--space-3);
}

.af-more {
  display: flex;
  justify-content: center;
  margin-top: var(--space-4);
}

/* 网址带着条件进来时，服务器的列表是没筛过的：清单到之前先淡化。 */
.af-server.is-stale {
  opacity: 0.45;
  pointer-events: none;
}

.af-backdrop {
  position: fixed;
  inset: 0;
  z-index: 390;
  background: rgb(15 62 84 / 40%);
}

html.af-locked {
  overflow: hidden;
}

/* ---------- 手机：两行横滑，下拉从底部弹出 ---------- */

@media (max-width: 1023px) {
  .af-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    min-width: 0;
    max-width: 100%;
    padding-bottom: 0.25rem;
  }

  .af-bar::-webkit-scrollbar {
    display: none;
  }

  .af-filters {
    flex-wrap: nowrap;
  }

  .af-side {
    margin-left: 0;
  }

  /* fixed 不受横滑容器 overflow 的裁切；要压过固定导航（z-index 100–300）。 */
  .af-panel {
    position: fixed;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 400;
    min-width: 0;
    max-height: 80vh;
    padding: var(--space-3) var(--space-2) calc(var(--space-2) + env(safe-area-inset-bottom));
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .af-panel-head {
    display: block;
  }
}

@media (prefers-reduced-motion: reduce) {
  .af-theme {
    transition: none;
  }
}
