/* Collection controls share the current workspace palette, including dark mode. */
#collection .toolbar {
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-card);
  background: var(--bg-surface);
}
#collection .toolbar .search-wrap { flex: 1 1 220px; max-width: none; min-height: 44px; }
#collection .toolbar-controls { flex: 1 1 auto; width: auto; gap: 8px; flex-wrap: wrap; }
#collection .collection-select { position: relative; flex: 1 1 160px; min-width: 0; }
#collection .collection-select > select[hidden] { display: none !important; }
#collection .collection-select-trigger {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--control-line);
  border-radius: var(--radius-control);
  background: var(--bg-card);
  color: var(--ink);
  font: inherit;
  font-size: .8rem;
  font-weight: 500;
  text-align: start;
  transition: background .18s, border-color .18s, box-shadow .18s;
}
#collection .collection-select-trigger > svg { color: var(--accent-color); }
#collection .collection-select svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#collection .collection-select-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#collection .collection-select-chevron { display: flex; color: var(--muted); transition: rotate .18s; }
#collection .collection-select-trigger:hover { background: var(--soft); border-color: var(--accent-color); }
#collection .collection-select-trigger[aria-expanded=true] { background: var(--tint); border-color: var(--accent-color); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-color) 10%, transparent); }
#collection .collection-select-trigger[aria-expanded=true] .collection-select-chevron { rotate: 180deg; }
#collection .collection-select[data-filtered=true] .collection-select-trigger { border-color: var(--accent-color); background: var(--soft); }
#collection .collection-select-menu, #collection .backup-menu > div {
  position: absolute;
  inset-block-start: calc(100% + 8px);
  inset-inline-start: 0;
  width: max(100%, 270px);
  max-width: calc(100vw - 64px);
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--bg-card);
  color: var(--ink);
  box-shadow: var(--shadow-panel);
  z-index: 60;
  animation: collection-menu-in .16s var(--ease-out);
}
#collection .collection-select-menu[hidden] { display: none; }
#collection .collection-select-heading { padding: 7px 10px 9px; color: var(--muted); font-size: .65rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; }
#collection .collection-select-options { max-height: min(340px, 45dvh); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
#collection .collection-select-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 46px;
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
}
#collection .collection-select-option > span { min-width: 0; }
#collection .collection-option-name { display: block; font-size: .82rem; font-weight: 500; overflow-wrap: anywhere; }
#collection .collection-select-option small { display: block; margin-top: 2px; color: var(--muted); font-size: .7rem; line-height: 1.45; }
#collection .collection-select-option > svg { color: var(--accent-color); visibility: hidden; }
#collection .collection-select-option[aria-selected=true] { background: var(--tint); }
#collection .collection-select-option[aria-selected=true] > svg { visibility: visible; }
#collection .collection-select-option:hover, #collection .collection-select-option.is-active { background: var(--soft); box-shadow: inset 0 0 0 1px var(--line); }
#collection .collection-select-option[aria-disabled=true] { opacity: .5; cursor: not-allowed; }
#collection .toolbar #refresh { min-height: 44px; margin: 0; font-size: .78rem; gap: 7px; }
#collection .backup-menu { flex: 0 0 44px; margin: 0; }
#collection .backup-menu summary { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border-radius: var(--radius-control); background: var(--bg-card); color: var(--muted); border-color: var(--control-line); cursor: pointer; letter-spacing: 2px; }
#collection .backup-menu summary:hover, #collection .backup-menu[open] summary { background: var(--tint); border-color: var(--accent-color); color: var(--ink); }
#collection .backup-menu > div { inset-inline-start: auto; inset-inline-end: 0; width: 230px; }
#collection .backup-menu button { min-height: 42px; padding: 10px 12px; border-radius: 8px; color: var(--ink); font-size: .8rem; }
#collection .backup-menu button:hover { background: var(--soft); }
#collection .backup-menu #new-library { margin-top: 5px; border-top: 1px solid var(--line); border-radius: 0 0 8px 8px; color: var(--red); }
@keyframes collection-menu-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
@media (max-width: 760px) {
  #collection .toolbar .search-wrap { flex-basis: 100%; }
  #collection .toolbar-controls { display: grid; grid-template-columns: minmax(0, 1fr) 44px; width: 100%; gap: 8px; }
  #collection .collection-select { grid-column: 1 / -1; }
  #collection .collection-select-menu { width: 100%; max-width: none; }
  #collection .toolbar #refresh { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  #collection .collection-select-menu, #collection .backup-menu > div { animation: none; }
  #collection .collection-select-trigger, #collection .collection-select-chevron { transition: none; }
}
html[data-motion=off] #collection :is(.collection-select-menu, .backup-menu > div) { animation: none; }
