.library-tools-host { position: relative; }
.history-panel.library-tools-host { grid-template-rows: auto minmax(0, 1fr); }
.library-tools {
  flex: 0 0 auto;
  padding: 0 0 14px;
  border-bottom: 1px solid var(--line, #d9dfe7);
  margin-bottom: 16px;
}
.library-tools-row, .library-tools-actions { display: flex; align-items: center; gap: 8px; }
.library-tools-row { flex-wrap: wrap; }
.library-search-wrap { position: relative; flex: 1 1 220px; min-width: 0; }
.library-search { display: block; }
.library-search-input {
  display: block;
  width: 100%;
  min-height: 38px;
  box-sizing: border-box;
  padding: 8px 62px 8px 12px;
  border: 1px solid var(--line, #d9dfe7);
  border-radius: 10px;
  background: var(--surface, #fff);
  color: var(--text, #24272c);
  font: inherit;
  font-size: calc(13px + var(--app-font-increase, 1pt));
}
.library-search-input::-webkit-search-cancel-button { appearance: none; }
.library-search-clear {
  position: absolute;
  inset-inline-end: 10px;
  top: 50%;
  transform: translateY(-50%);
  padding: 4px;
  border: 0;
  background: transparent;
  color: var(--muted, #626b78);
  font: inherit;
  font-size: calc(12px + var(--app-font-increase, 1pt));
  cursor: pointer;
}
.library-search-clear[hidden] { display: none; }
.library-action {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--line, #d9dfe7);
  border-radius: 10px;
  background: var(--surface, #fff);
  color: var(--text, #24272c);
  font: inherit;
  font-size: calc(12px + var(--app-font-increase, 1pt));
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.library-action:disabled { opacity: .5; cursor: default; }
.library-action:active:not(:disabled) { background: var(--surface-hover, #edf3fa); }
.library-action:focus-visible, .library-search-input:focus-visible, .library-search-clear:focus-visible {
  outline: 2px solid var(--accent, #007aff);
  outline-offset: 2px;
}
.library-tools-status { display: block; margin-top: 10px; color: var(--text, #24272c); font-size: calc(12px + var(--app-font-increase, 1pt)); }
.library-tools-note { margin: 5px 0 0; color: var(--muted, #626b78); font-size: calc(12px + var(--app-font-increase, 1pt)); line-height: 1.55; }
.library-compare:not([open]) { display: none; }
.library-compare[open] {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  min-height: 0;
  margin: 0;
  padding: 20px;
  overflow: auto;
  border: 1px solid var(--line, #d9dfe7);
  border-radius: 16px;
  background: var(--composer-card-solid, #fff);
  color: var(--text, #24272c);
  box-shadow: 0 8px 28px #1725340d;
}
.library-compare-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex: 0 0 auto; }
.library-compare-title { margin: 0; font-size: calc(16px + var(--app-font-increase, 1pt)); line-height: 1.4; }
.library-compare-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; flex: 1 1 auto; min-height: 0; }
.library-compare-grid[data-count="3"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.library-compare-grid[data-count="4"] { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.library-compare-item { display: flex; flex-direction: column; min-width: 0; min-height: 0; margin: 0; }
.library-compare-image { display: block; width: 100%; height: 0; min-height: 140px; flex: 1 1 auto; object-fit: contain; border-radius: 10px; background: var(--bg, #edf2f7); }
.library-compare-caption { padding-top: 10px; font-size: calc(12px + var(--app-font-increase, 1pt)); line-height: 1.5; overflow-wrap: anywhere; }
.library-compare-caption strong { font-weight: 600; }
.library-compare-caption p { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; margin: 4px 0 0; color: var(--muted, #626b78); }
.gallery-batch-heading { grid-column: 1 / -1; display: flex; align-items: baseline; gap: 8px; margin: 12px 0 0; font-size: calc(12px + var(--app-font-increase, 1pt)); font-weight: 600; color: var(--muted, #626b78); }
.gallery-lock-badge { position: absolute; inset-inline-end: 8px; top: 8px; z-index: 2; padding: 4px 7px; border-radius: 7px; background: #fffffff0; color: #323b49; font-size: calc(11px + var(--app-font-increase, 1pt)); font-weight: 600; pointer-events: none; }
@media (hover: hover) and (pointer: fine) {
  .library-action:hover:not(:disabled) { background: var(--surface-hover, #edf3fa); }
}
@media (max-width: 900px) {
  .library-compare-grid[data-count="3"], .library-compare-grid[data-count="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .library-compare-grid[data-count="3"] .library-compare-image, .library-compare-grid[data-count="4"] .library-compare-image { min-height: 160px; }
}
@media (max-width: 520px) {
  .library-tools-actions { width: 100%; }
  .library-action { flex: 1 1 auto; }
  .library-compare[open] { padding: 12px; }
  .library-compare-grid { gap: 8px; }
  .library-compare-caption { font-size: calc(11px + var(--app-font-increase, 1pt)); }
}

.library-compare-control { display: flex; align-items: center; flex: 0 0 auto; }
.library-compare-toggle { display: grid; place-items: center; width: 44px; height: 44px; padding: 10px; border-radius: 12px; }
.library-compare-toggle svg { width: 22px; height: 22px; }
.library-compare-toggle:not(:disabled) { color: var(--accent); border-color: var(--accent-line); }
.library-compare-grid { grid-auto-rows: minmax(240px, 1fr); }
.history-header .history-copy h2 { white-space: nowrap; }
