/**
 * CoCLinks Platform — 3-Row Clean & Intuitive Category Filter
 * Row 1: Village Switcher (Left) + Open Sort Navigation (Right)
 * Row 2: Town Hall / Builder Hall Levels Rail
 * Row 3: Base Purpose & Defense Type Filter Chips
 */

/* Main 3-Row Filter Card */
.category-filter-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 16px);
  padding: 16px;
  margin-bottom: 32px;
  box-shadow: 0 2px 12px -2px rgba(15, 23, 42, 0.04), 0 1px 2px rgba(15, 23, 42, 0.02);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@media (min-width: 768px) {
  .category-filter-card {
    padding: 24px;
    margin-bottom: 40px;
    gap: 20px;
  }
}

/* ==========================================================================
   ROW 1: Header Bar — Village Switcher (Left) + Open Sort Pills (Right)
   ========================================================================== */
.cf-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

/* Village Mode Segmented Controller */
.cf-village-switcher {
  display: inline-flex;
  align-items: center;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
  flex-shrink: 0;
}

.cf-village-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 16px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  border-radius: 7px;
  text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  line-height: 16px;
  white-space: nowrap;
}

.cf-village-tab:hover {
  color: var(--text-primary);
  background: rgba(0, 0, 0, 0.03);
}

html.dark .cf-village-tab:hover {
  background: rgba(255, 255, 255, 0.05);
}

.cf-village-tab.active {
  background: var(--brand-blue);
  color: #ffffff !important;
  box-shadow: 0 1px 4px rgba(0, 102, 204, 0.25);
}

/* Open Sort Navigation */
.cf-sort-bar {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  min-width: 0;
}

.cf-sort-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex-shrink: 0;
}

.cf-sort-pills {
  display: inline-flex;
  align-items: center;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
}

.cf-sort-pills::-webkit-scrollbar {
  display: none;
}

.cf-sort-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: 7px;
  text-decoration: none;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  line-height: 16px;
  white-space: nowrap;
  flex-shrink: 0;
}

.cf-sort-pill:hover {
  color: var(--text-primary);
  background: rgba(0, 0, 0, 0.03);
}

html.dark .cf-sort-pill:hover {
  background: rgba(255, 255, 255, 0.05);
}

.cf-sort-pill.active {
  background: var(--bg-card);
  color: var(--brand-blue) !important;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

html.dark .cf-sort-pill.active {
  background: #1e222e;
  color: #2997ff !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

/* ==========================================================================
   ROW 2: Hall Levels Rail (TH3..TH18 / BH3..BH10)
   ========================================================================== */
.cf-row-levels {
  display: flex;
  align-items: center;
  min-width: 0;
}

.cf-levels-scroll {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 1px 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
  width: 100%;
}

.cf-levels-scroll::-webkit-scrollbar {
  display: none;
}

.cf-level-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 42px;
  line-height: 16px;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.cf-level-pill:hover {
  border-color: var(--brand-blue);
  color: var(--brand-blue);
  background: var(--bg-subtle);
  box-shadow: 0 1px 3px rgba(0, 102, 204, 0.1);
}

.cf-level-pill.active {
  background: var(--brand-blue);
  border-color: var(--brand-blue);
  color: #ffffff !important;
  font-weight: 700;
}

html.dark .cf-level-pill.active {
  box-shadow: 0 2px 6px rgba(41, 151, 255, 0.3);
}

/* ==========================================================================
   ROW 3: Subcategory / Purpose Filter Chips
   ========================================================================== */
.cf-row-chips {
  display: flex;
  align-items: center;
  min-width: 0;
}

.cf-chips-scroll {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 1px 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
  width: 100%;
}

.cf-chips-scroll::-webkit-scrollbar {
  display: none;
}

.cf-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  text-decoration: none;
  white-space: nowrap;
  line-height: 16px;
  flex-shrink: 0;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.cf-chip:hover {
  color: var(--text-primary);
  background: var(--border-subtle);
  border-color: var(--border);
}

/* Active Filter Pill (Soft Blue Tint) */
.cf-chip.active {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #0066cc !important;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 102, 204, 0.08);
}

html.dark .cf-chip {
  background: var(--bg-subtle);
  border-color: var(--border);
}

html.dark .cf-chip:hover {
  background: var(--border);
  color: var(--text-primary);
}

html.dark .cf-chip.active {
  background: rgba(41, 151, 255, 0.15);
  border-color: rgba(41, 151, 255, 0.4);
  color: #2997ff !important;
  box-shadow: 0 1px 4px rgba(41, 151, 255, 0.15);
}

/* ==========================================================================
   Responsive Adaptations
   ========================================================================== */
@media (max-width: 768px) {
  .category-filter-card {
    padding: 16px;
    gap: 16px;
    margin-bottom: 32px;
  }
  
  .cf-row-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding-bottom: 12px;
  }
  
  .cf-village-switcher {
    width: 100%;
    display: flex;
  }
  
  .cf-village-tab {
    flex: 1;
    text-align: center;
  }
  
  .cf-sort-bar {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }
  
  .cf-sort-pills {
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  
  .cf-levels-scroll,
  .cf-chips-scroll {
    gap: 6px;
  }
  
  .cf-level-pill,
  .cf-chip {
    padding: 5px 12px;
    font-size: 12px;
    border-radius: 7px;
  }
}
