/* Narrowing the legal catalogue: the search field, the selects behind it, and
   the chips that say what is currently set. What those produce — the rows, the
   signals, the empty state — is styled in species-catalog.css. The two were one
   sheet until it passed the size limit, and this is the seam it split on. */

/* ---------- search and filters ---------- */
.catalog-search {
  display: grid; gap: var(--space-5);
  padding: 24px 26px;
  background: var(--surface-card);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-card);
}
.catalog-search-main { display: grid; gap: var(--space-2); }
.catalog-search-label { font-size: 13px; font-weight: 700; }
.catalog-search-row { display: flex; gap: var(--space-3); }
.species-suggest-field {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 11px;
  min-height: 52px; padding: 0 20px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-control);
}
.species-suggest-field > svg { flex: none; color: var(--text-muted); }
.species-suggest-field input[type="search"] {
  flex: 1; min-width: 0; min-height: 50px;
  padding: 0; border: 0; background: transparent; box-shadow: none; font-size: 15.5px;
}
.species-suggest-field:focus-within { border-color: var(--action-primary); }
.species-suggest-field input:focus-visible { outline: 0; }
.catalog-search-submit { flex: none; min-height: 52px; padding-inline: 26px; font-size: 15px; }
.catalog-search-hint { margin: 0; color: var(--text-secondary); font-size: 12.5px; }

.catalog-search-filters {
  display: flex; align-items: flex-end; flex-wrap: wrap; gap: var(--space-3);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border-subtle);
}
.catalog-filter { flex: 1 1 180px; min-width: 0; display: grid; gap: 6px; }
.catalog-filter > span { color: var(--text-secondary); font-size: 11.5px; font-weight: 700; }
.catalog-filter select {
  min-height: 48px; padding-block: 0;
  border-color: var(--border-subtle);
  font-size: 14px;
}

/* The rest of the vocabulary waits behind one disclosure. The selects stay
   inside the same GET form while closed, so the page still submits them. */
.catalog-more-filters { flex: none; }
.catalog-more-filters > summary {
  display: inline-flex; align-items: center;
  min-height: 48px; padding: 0 20px;
  background: var(--surface-warm);
  border-radius: var(--radius-control);
  font-size: 13.5px; font-weight: 600; cursor: pointer; list-style: none;
}
.catalog-more-filters > summary::-webkit-details-marker { display: none; }
.catalog-more-filters-body {
  display: flex; flex-wrap: wrap; gap: var(--space-3);
  width: 100%; margin-top: var(--space-3);
}
.catalog-more-filters-body .catalog-filter { flex: 1 1 200px; }

/* The selects live in a <dialog> so a phone can lift them into a bottom sheet.
   Everywhere else the dialog is not a box at all: `contents` hands its children
   straight to the form, which is why the rules above never mention it. The three
   parts that exist only for the sheet — the trigger, the head and the apply
   button — stay out of that layout. */
.catalog-filters-sheet { display: contents; }
.catalog-filters-open, .catalog-filters-head, .catalog-filters-apply { display: none; }

/* ---------- active filters ---------- */
.species-chips { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); }
.species-chips-label {
  margin-inline-end: 4px;
  color: var(--text-secondary);
  font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
}
.species-chip {
  display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: 36px; padding: 0 8px 0 14px;
  background: var(--surface-lilac); color: var(--text-primary);
  border-radius: var(--radius-control);
  font-size: 13px; font-weight: 600;
}
.species-chip:hover { background: color-mix(in srgb, var(--surface-lilac) 70%, var(--surface-card)); }
.species-chip-remove {
  display: grid; place-items: center;
  width: 22px; height: 22px; flex: none;
  background: var(--surface-card);
  border-radius: var(--radius-pill);
}
.species-chips-reset { margin-inline-start: 6px; font-size: 13px; font-weight: 600; }

/* ---------- phones ---------- */
@media (max-width: 899px) {
  .catalog-search { padding: 16px; border-radius: var(--radius-card); }
  .catalog-search-row { flex-wrap: wrap; }
  .catalog-search-submit { flex: 1 1 100%; }
  .catalog-search-filters { padding-top: var(--space-4); }
  .catalog-filter { flex: 1 1 100%; }
  .catalog-more-filters { width: 100%; }
  .catalog-more-filters > summary { justify-content: center; width: 100%; }

  /* ---------- the filter sheet ---------- */
  /* Only once catalog-filters.js has marked the form: the stack above is what a
     phone without it keeps, and it works. Everything below moves the selects
     into a compact search row while the filters open in a sheet. */
  .catalog-search.has-sheet {
    gap: 0; padding: 10px 12px;
    /* Opaque, not the design's frosted glass: a backdrop filter repaints
       everything behind the bar for the whole length of a 1287-row scroll. */
    background: var(--surface-card);
  }
  .has-sheet .catalog-search-main { gap: 0; }
  /* The field keeps its name while the row shows only the field and the count. */
  .has-sheet .catalog-search-label {
    position: absolute; width: 1px; height: 1px;
    clip-path: inset(50%); overflow: hidden; white-space: nowrap;
  }
  .has-sheet .catalog-search-hint, .has-sheet .catalog-search-submit { display: none; }
  .has-sheet .catalog-search-row { flex-wrap: nowrap; gap: var(--space-2); }
  .has-sheet .species-suggest-field { min-height: 46px; padding: 0 16px; }
  .has-sheet .species-suggest-field input[type="search"] { min-height: 44px; font-size: 14px; }
  .catalog-search.has-sheet .catalog-filters-open {
    flex: none;
    display: inline-flex; align-items: center;
    min-height: 46px; padding: 0 16px;
    background: var(--surface-card); color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-control);
    font-size: 13px; font-weight: 600;
  }

  .has-sheet .catalog-filters-sheet { display: none; }
  .has-sheet .catalog-filters-sheet[open] {
    display: block;
    position: fixed; inset: auto 0 0; z-index: 40;
    width: 100%; max-width: none;
    margin: 0; padding: 0; border: 0;
    background: var(--surface-card); color: var(--text-primary);
    border-radius: var(--radius-panel) var(--radius-panel) 0 0;
    overflow: hidden;
    animation: sheet-up .22s ease-out;
  }
  .has-sheet .catalog-filters-sheet::backdrop {
    background: color-mix(in srgb, var(--overlay-ink) 45%, transparent);
  }
  .has-sheet .catalog-search-filters {
    display: grid; gap: 7px;
    max-height: 78dvh; overflow-y: auto; overscroll-behavior: contain;
    padding: 10px 16px calc(14px + env(safe-area-inset-bottom));
    border-top: 0;
  }
  /* The grab handle is the shell's own (shell.css) and is styled nowhere else,
     so the head only has to place the line underneath it. */
  .has-sheet .catalog-filters-head { display: grid; gap: 10px; }
  .catalog-filters-headline {
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--space-3);
  }
  .catalog-filters-title { margin: 0; font-size: 15px; font-weight: 700; }
  .catalog-filters-reset { font-size: 12.5px; font-weight: 600; }

  /* A filter is one row: what it narrows on the left, what it is set to on the
     right. The select carries no chrome of its own — the row is the control. */
  .has-sheet .catalog-filter {
    flex: none;
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--space-3);
    min-height: 44px; padding: 0 14px;
    background: var(--surface-page);
    border-radius: var(--radius-media);
  }
  .has-sheet .catalog-filter > span {
    color: var(--text-primary); font-size: 13px; font-weight: 600;
  }
  .has-sheet .catalog-filter select {
    width: auto; max-width: 62%; min-height: 40px; padding-inline: 0 18px;
    background: transparent; border: 0;
    font-size: 13px; font-weight: 600; text-align: end;
  }
  /* An untouched dimension reads quieter than one that is narrowing the list. */
  .has-sheet .catalog-filter select:has(option[value=""]:checked) {
    color: var(--text-secondary); font-weight: 400;
  }
  .has-sheet .catalog-more-filters { width: auto; }
  .has-sheet .catalog-more-filters > summary { display: none; }
  .has-sheet .catalog-more-filters-body { display: grid; gap: 7px; margin-top: 0; }
  .has-sheet .catalog-filters-apply {
    display: grid; place-items: center;
    width: 100%; min-height: 48px; margin-top: 5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .has-sheet .catalog-filters-sheet[open] { animation: none; }
}
