.chemical-space-catalog { margin: 0 0 24px; }
.chemical-space-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  scroll-margin-top: 1rem;
}
.chemical-space-filters label:not([hidden]) { display: grid; gap: 5px; font-size: .85rem; font-weight: 600; }
.chemical-space-search { flex: 2 1 260px; }
.chemical-space-filters label:not(.chemical-space-search) { flex: 1 1 150px; }
.chemical-space-filters :is(input, select) {
  box-sizing: border-box;
  min-height: 42px;
  width: 100%;
  padding: 8px 12px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--strong-rule);
  border-radius: 8px;
  font: inherit;
  font-weight: 400;
}
.chemical-space-results, .chemical-space-message { margin: 16px 0 12px; color: var(--muted); font-size: .88rem; }
.chemical-space-results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 175px), 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.chemical-space-entry { min-width: 0; }
.chemical-space-entry-button {
  display: grid;
  grid-template-rows: auto 1fr;
  width: 100%;
  height: 100%;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-align: left;
}
.chemical-space-entry-button:hover { border-color: var(--muted); }
.chemical-space-catalog :is(button, input, select, a):focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.chemical-space-picture {
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 8px;
  background: #fff;
  border-bottom: 1px solid var(--rule);
}
.chemical-space-picture img { display: block; width: 100%; height: auto; max-height: 144px; object-fit: contain; }
.chemical-space-entry-text { display: grid; align-content: start; gap: 3px; padding: 11px 12px; overflow-wrap: anywhere; }
.chemical-space-entry-text strong { font-size: .9rem; }
.chemical-space-entry-text :not(strong) { color: var(--muted); font-size: .78rem; }
.chemical-space-paging span { font-variant-numeric: tabular-nums; font-size: .86rem; }
.chemical-space-sources { margin: 18px 0 0; color: var(--muted); font-size: .86rem; }
.chemical-space-links { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.chemical-space-links a { color: var(--ink); text-decoration: underline; text-underline-offset: .18em; overflow-wrap: anywhere; }
.chemical-space-detail {
  box-sizing: border-box;
  width: min(600px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 16px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--strong-rule);
  border-radius: 14px;
}
.chemical-space-detail::backdrop { background: rgb(0 0 0 / .45); }
.chemical-space-detail-head { display: flex; align-items: start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.chemical-space-detail-head h3 { margin: 4px 0; overflow-wrap: anywhere; }
.chemical-space-detail .chemical-space-picture { border: 1px solid var(--rule); border-radius: 8px; }
.chemical-space-detail .chemical-space-picture img { max-height: 280px; }
.chemical-space-detail p { margin: 8px 0; color: var(--muted); font-size: .86rem; }
.chemical-space-detail dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 14px; font-size: .88rem; }
.chemical-space-detail dd { margin: 0; overflow-wrap: anywhere; }
.chemical-space-detail dt { color: var(--muted); }
@media (max-width: 570px) {
  .chemical-space-results-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .chemical-space-entry-text { padding: 8px; }
}
.chemical-space-library-links { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chemical-space-count { margin: 5px 0 0; color: var(--muted); font-size: .82rem; }
.candidate-table .candidate-library-structure { width: 112px; padding: 4px; border: 1px solid var(--rule); border-radius: 7px; }


.chemical-space-entry:has(.chemical-space-tick) { position: relative; }
.chemical-space-tick {
  position: absolute;
  inset-block-start: 7px;
  inset-inline-end: 7px;
  display: grid;
  place-items: center;
  inline-size: 40px;
  block-size: 40px;
  border-radius: 8px;
  background: #fff;
  color-scheme: light;
  cursor: pointer;
}
.chemical-space-tick input {
  inline-size: 17px;
  block-size: 17px;
  margin: 0;
  accent-color: #262626;
  cursor: pointer;
}
.chemical-space-tick:hover { background: #f1f1f1; }
.chemical-space-tick input:focus-visible { outline: 2px solid #292929; outline-offset: 2px; }
.chemical-space-entry.is-picked .chemical-space-entry-button {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}
.chemical-space-entry.is-picked .chemical-space-entry-text { background: var(--tint); }
.chemical-space-stock-action {
  position: fixed;
  inset-inline-end: max(24px, env(safe-area-inset-right));
  inset-block-end: max(24px, env(safe-area-inset-bottom));
  z-index: 10;
}
.chemical-space-stock-action .button {
  min-block-size: 42px;
  box-shadow: 0 4px 16px #0003;
}
.chemical-space-catalog.has-stock-selection { padding-block-end: 58px; }
@media (max-width: 600px) {
  .chemical-space-stock-action { inset-inline-end: max(12px, env(safe-area-inset-right)); }
}

.stock-selectable .candidate-table :is(th, td):first-child {
  min-width: 0;
  width: 3.25rem;
  padding-inline: 6px;
  text-align: center;
  white-space: nowrap;
}
.stock-pick {
  display: grid;
  place-items: center;
  inline-size: 40px;
  min-block-size: 36px;
  margin-inline: auto;
  cursor: pointer;
}
.stock-pick input {
  inline-size: 17px;
  block-size: 17px;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
}
.stock-selectable .candidate-table tr:has(.stock-pick input:checked) { background: var(--tint); }
.chemical-space-stock-action .stock-remove-button {
  background: #a32222;
  border-color: #a32222;
  color: #fff;
}
.chemical-space-stock-action .stock-remove-button:hover:not(:disabled) {
  background: #861c1c;
  border-color: #861c1c;
  color: #fff;
}
.chemical-space-stock-action .stock-remove-button:disabled { opacity: .72; }

.stock-view-toggle {
  display: flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--surface);
}
.stock-view-toggle .button {
  min-block-size: 34px;
  padding-inline: 11px;
  border-color: transparent;
  white-space: nowrap;
}
.stock-view-toggle button.button[aria-pressed=true] {
  color: var(--primary-ink);
  background: var(--primary);
}
.stock-card {
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--surface);
}
.stock-card.is-picked {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}
.stock-card.is-picked .stock-card-body { background: var(--tint); }
.stock-card-picture {
  position: relative;
  min-block-size: clamp(110px, 11vw, 148px);
}
.stock-card-picture > span { color: #666; font-size: .78rem; }
.stock-card-picture > img {
  position: absolute;
  max-width: calc(100% - 16px);
  max-height: calc(100% - 16px);
  opacity: 0;
}
.stock-card-picture > img.is-ready { opacity: 1; }
.stock-card-picture:has(img.is-ready) > span { visibility: hidden; }
.stock-card-body {
  display: flex;
  flex-direction: column;
}
.stock-card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
  padding: 0 10px 10px;
}
.stock-card-actions :is(select, .button) { min-height: 34px; font-size: .78rem; }
.stock-card-actions select { max-width: 100%; }
