/* Search and actions belong to the list toolbar, aligned with its cards. */
#gallery-discovery-search { width: 100%; margin-top: 18px; }
#links-section .gallery-search-form { margin: 0; padding: 0; border: 0; border-radius: 0; background: none; }
.gallery-search-main { display: flex; align-items: center; gap: 14px; }
.gallery-search-field { display: flex; align-items: center; flex: 1 1 340px; max-width: 520px; min-width: 0; padding: 4px; gap: 7px; border: 1px solid var(--site-edge, var(--line)); border-radius: 10px; background: var(--surface); box-shadow: 0 2px 6px color-mix(in srgb, var(--ink) 3%, transparent); transition: border-color .18s, box-shadow .18s; }
.gallery-search-field:focus-within { border-color: var(--site-accent, var(--green)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 11%, transparent); }
#links-section .gallery-search-input { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; padding-left: 8px; background: transparent; border: 0; outline: 0; color: var(--muted); }
.gallery-search-input > svg { width: 16px; height: 16px; flex-shrink: 0; }
#links-section .gallery-search-input input { flex: 1; min-width: 0; width: 100%; height: 34px; padding: 7px 0; border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 12px; outline: none; box-shadow: none; }
.gallery-search-input input::placeholder { color: var(--muted); opacity: .85; }
#links-section .gallery-search-submit { flex: 0 0 auto; height: 34px; padding: 8px 13px; border-radius: 7px; font-size: 11px; }
.gallery-search-controls { display: flex; align-items: center; gap: 10px; min-width: 0; }
#links-section .gallery-search-controls > .button { flex: 0 0 auto; height: 44px; padding: 10px 12px; border: 1px solid var(--site-edge, var(--line)); border-radius: 10px; background: color-mix(in srgb, var(--surface) 70%, var(--bg)); color: var(--muted); font-size: 11px; white-space: nowrap; }
.gallery-search-controls > .button svg { width: 15px; height: 15px; }
#links-section .gallery-filter-toggle:hover,
#links-section .gallery-filter-toggle[aria-expanded="true"] { border-color: color-mix(in srgb, var(--green) 35%, var(--line)); color: var(--green); background: color-mix(in srgb, var(--green) 7%, var(--surface)); }
.gallery-filter-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--green); }
.gallery-sort-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; white-space: nowrap; }
#links-section .gallery-sort-control select { min-width: 0; height: 44px; padding: 0 26px 0 11px; background: var(--surface); border: 1px solid var(--site-edge, var(--line)); border-radius: 10px; color: var(--ink); font: inherit; }
.gallery-search-panel { margin-top: 14px; padding: 22px; border: 1px solid var(--site-edge, var(--line)); border-radius: 10px; background: var(--site-soft-surface, var(--surface)); }
.gallery-search-panel[hidden] { display: none; }
.gallery-search-fields { display: grid; grid-template-columns: 1fr 1fr 1.3fr 1.3fr; gap: 16px; }
.gallery-search-fields > label { display: flex; flex-direction: column; gap: 8px; min-width: 0; font-size: 11px; color: var(--muted); }
.gallery-search-fields input, .gallery-search-fields select { width: 100%; min-width: 0; padding: 10px; border: 1px solid var(--site-edge, var(--line)); border-radius: 6px; background: var(--surface); color: var(--ink); font: inherit; font-size: 12px; }
.gallery-count-range { border: 0; padding: 0; margin: 0; min-width: 0; display: flex; align-items: center; gap: 7px; color: var(--muted); }
.gallery-count-range legend { font-size: 11px; padding: 0; margin-bottom: 8px; }
.gallery-search-help { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-top: 18px; }
.gallery-search-help small { font-size: 10px; line-height: 1.8; color: var(--muted); }
.gallery-filter-actions { display: flex; align-items: center; gap: 16px; flex-shrink: 0; }
.gallery-filter-actions .text-button { font-size: 11px; white-space: nowrap; }
.gallery-filter-actions .button { font-size: 11px; padding: 10px 14px; }
.gallery-results-row { display: flex; align-items: center; justify-content: space-between; gap: 12px 24px; padding: 14px 0 18px; }
#discovery-description { display: flex; align-items: center; gap: 7px; min-width: 0; margin: 0; color: var(--muted); font-size: 10px; line-height: 1.8; }
#discovery-description > svg { width: 14px; height: 14px; flex-shrink: 0; }
.gallery-search-status { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px 14px; min-width: 0; }
.gallery-search-status > span { display: flex; gap: 6px; flex-wrap: wrap; min-width: 0; }
.gallery-search-status > small { font-size: 10px; color: var(--muted); white-space: nowrap; }
.gallery-filter-chip { font-size: 10px; padding: 5px 9px; border-radius: 5px; background: var(--green-pale); color: var(--green); overflow-wrap: anywhere; }

.api-preview.has-gallery-cover { display: block; padding: 0; }
.api-preview.has-gallery-cover > .gallery-cover { height: 100%; width: 100%; }
.shelf-cover.has-gallery-cover { display: block; position: relative; width: 100%; cursor: pointer; }
.has-gallery-cover .cover-badge, .has-gallery-cover .cover-privacy, .has-gallery-cover .shelf-privacy, .has-gallery-cover .shelf-count { pointer-events: none; z-index: 3; }
.has-gallery-cover:focus-visible { outline: 3px solid var(--green); outline-offset: 3px; }
#links-scroll-sentinel { height: 1px; width: 100%; pointer-events: none; }
#links-load-state { margin-top: 18px; }

/* A stable cover ratio and responsive columns keep large and small screens balanced. */
#api-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 20px; align-items: stretch; }
#api-grid .api-card { display: flex; flex-direction: column; min-width: 0; }
#api-grid .api-preview { height: auto; aspect-ratio: 4 / 3; flex: 0 0 auto; }
#api-grid .api-body { display: flex; flex: 1; flex-direction: column; min-width: 0; padding: 13px 16px 14px; }
#api-grid .api-title-row h3 { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#api-grid .api-title-row > .icon-button, #api-grid .api-title-row > .api-label { flex-shrink: 0; }
#api-grid .api-body > p { display: block; height: 18px; min-height: 18px; line-height: 18px; margin: 5px 0 7px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#api-grid .api-meta { height: 18px; min-width: 0; flex-wrap: nowrap; gap: 8px; margin: 5px 0 12px; }
#api-grid .api-meta > span { flex-shrink: 0; white-space: nowrap; }
#api-grid .api-meta > .api-owner { flex: 0 1 auto; min-width: 0; max-width: 68px; margin-left: 0; }
#api-grid .api-meta > .api-tags { display: block; flex: 0 1 auto; min-width: 0; padding: 2px 5px; border-radius: 3px; background: var(--green-pale); color: var(--green); font-size: 9px; line-height: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#api-grid .api-actions { margin-top: auto; }

@media (max-width: 1100px) {
  .gallery-search-main { flex-wrap: wrap; gap: 12px; }
  .gallery-search-field { max-width: none; flex-basis: 100%; }
  .gallery-search-controls { flex-wrap: wrap; }
  .gallery-search-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .gallery-results-row { align-items: flex-start; }
}
@media (max-width: 650px) {
  #links-section .collection-nav { gap: 12px; padding-bottom: 14px; }
  #links-section .collection-nav .pill-tabs { flex: 1 1 100%; width: 100%; overflow-x: auto; scrollbar-width: thin; }
  #links-section .collection-nav > .button { margin-left: auto; }
  #gallery-discovery-search { margin-top: 14px; }
  .gallery-search-controls { width: 100%; gap: 8px; }
  #links-section .gallery-search-controls > .button { padding-inline: 10px; font-size: 10px; }
  .gallery-sort-control { flex: 1; gap: 6px; font-size: 10px; }
  #links-section .gallery-sort-control select { flex: 1; width: 0; padding-left: 8px; padding-right: 3px; }
  .gallery-search-panel { padding: 16px; }
  .gallery-search-fields { gap: 14px 10px; }
  .gallery-exclude, .gallery-count-range { grid-column: 1 / -1; }
  .gallery-search-help { flex-direction: column; align-items: stretch; }
  .gallery-filter-actions { justify-content: flex-end; }
  .gallery-results-row { flex-direction: column; gap: 6px; padding: 12px 0 16px; }
  .gallery-search-status { justify-content: flex-start; }
  #api-grid { gap: 18px; }
}
@media (max-width: 360px) {
  .gallery-search-controls { gap: 6px; }
  #links-section .gallery-search-controls > .button { padding-inline: 8px; gap: 5px; }
  .gallery-sort-control { font-size: 0; gap: 0; }
  #links-section .gallery-sort-control select { font-size: 10px; }
  #api-grid .api-meta { gap: 5px; }
  #api-grid .api-meta > span { gap: 3px; }
}
@media (prefers-reduced-motion: reduce) { .gallery-search-field { transition: none; } }
