/* ---------------------------------------------------------------
   Browse view — filter drawer + active-chip strip
   Rules:
   - Each filter row is ONE LINE: [label][controls...].  Labels never
     stack above controls except in the single "Century of birth" row.
   - Chip groups never break: chips inside a group stay together on a
     single line.  Drawer column width is sized to make that fit.
   - Section titles are LEFT-aligned at the section's left edge.
   --------------------------------------------------------------- */

/* ============================================================
   Filter toggle bar (sits next to the Search button)
   ============================================================ */
.browse-filter-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
}
.browse-filter-bar:has(.btn-filter-clear:not(.hidden)),
.browse-filter-bar:has(.active-chip) {
  margin-top: 10px;
}

.btn-filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  min-height: 36px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-primary);
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.btn-filter-toggle:hover {
  background: var(--bg-hover-soft);
  border-color: var(--border-strong);
}
.btn-filter-toggle.open {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
}
.btn-filter-toggle .filter-icon { font-size: 14px; line-height: 1; }
.btn-filter-toggle .filter-count {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  background: var(--accent);
  color: var(--text-on-accent);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  line-height: 18px;
}
.btn-filter-toggle.open .filter-count {
  background: var(--text-on-accent);
  color: var(--accent);
}

.btn-filter-clear {
  padding: 6px 10px;
  min-height: 36px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}
.btn-filter-clear:hover { color: var(--text-primary); }

/* ============================================================
   Active filter chips (shown above results)
   ============================================================ */
.active-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
  min-width: 0;
}
.active-chips:empty { display: none; }

.active-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 4px 3px 10px;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.3;
  color: var(--text-primary);
}
.active-chip .ac-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0;
}
.active-chip .ac-remove:hover {
  background: var(--bg-hover-soft);
  color: var(--text-primary);
}

/* ============================================================
   Drawer — column min sized so the widest chip row
   ("Records | Has a photo | Has sources | Famous Kin")
   fits on one line without wrapping.
   ============================================================ */
.filter-drawer {
  margin-top: 10px;
  padding: 14px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 16px 24px;
}

.filter-section h4 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  text-align: left;
}

/* ============================================================
   Filter rows — ONE LINE: [label][controls].  Labels never stack.
   ============================================================ */
.filter-row {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 14px;
  min-width: 0;
}
.filter-row > label:first-child {
  flex: 0 0 100px;
  color: var(--text-secondary);
  font-size: 13px;
}
.filter-row .dash { color: var(--text-muted); flex: 0 0 auto; }

.filter-row input[type="number"],
.filter-row input[type="text"],
.filter-row select {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 5px;
  padding: 4px 8px;
  font: inherit;
  min-width: 0;
}
.filter-row input[type="number"] { width: 80px; flex: 0 0 auto; }
.filter-row input[type="text"]   { width: 180px; flex: 0 1 180px; }
.filter-row select               { flex: 0 1 220px; max-width: 220px; }
.filter-row input:focus,
.filter-row select:focus {
  outline: none;
  border-color: var(--accent);
}

/* The ONE exception: Century of birth stacks (21 chips wrap to multiple
   rows underneath a centered label). */
.filter-row-stacked {
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  flex-wrap: nowrap;
}
.filter-row-stacked > label:first-child {
  flex: 0 0 auto;
}
.filter-row-stacked .chip-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-content: flex-start;
  max-width: 100%;
}

/* ============================================================
   Chip groups (segmented controls) — NEVER wrap internally.
   The exception is the Century stacked row above.
   ============================================================ */
.chip-group {
  display: inline-flex;
  flex-wrap: nowrap;
  gap: 4px;
  min-width: 0;
}
.chip-group .chip {
  padding: 5px 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-secondary);
  border-radius: 14px;
  font: inherit;
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.chip-group .chip:hover {
  background: var(--bg-hover-soft);
  color: var(--text-primary);
}
.chip-group .chip.active {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
}

/* ============================================================
   Result count line
   ============================================================ */
.browse-result-count {
  margin: 12px 0 4px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ============================================================
   Narrow viewports — tighten padding and let inputs shrink so
   the one-line layout survives.  Labels and chip groups still
   stay on a single line; the row just gets denser.
   ============================================================ */
@media (max-width: 720px) {
  .filter-drawer {
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 14px;
  }
  .filter-row > label:first-child { flex-basis: 90px; }
  .filter-row input[type="number"] { width: 70px; }
  .filter-row input[type="text"]   { flex: 1 1 0; min-width: 0; }
  .filter-row select               { flex: 1 1 0; max-width: none; }
}

@media (max-width: 440px) {
  .filter-row > label:first-child { flex-basis: 80px; font-size: 12px; }
  .filter-row { font-size: 13px; gap: 6px; }
  .chip-group .chip { padding: 4px 7px; font-size: 11px; }
}
