/*
 * admin/css/pages/library.css — Library (pages/library.js) and the library
 * widgets it shares with Themes / Edit theme (ui/theme-library.js,
 * ui/test-image-library.js). The widgets load this sheet themselves
 * (ensureStylesheet), so their dialogs are styled on any page.
 *
 * Every colour is a token (css/tokens.css). Shapes follow spec §6: tiles and
 * cards 20px. Pills (the kit .pill-group) and buttons come from base.css.
 */

/* ── Theme presets ──────────────────────────────────────────────────────── */
.lib-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.lib-card-error {
  margin: 0;
}

/* ★ Default: the star in the warning ink when the preset is a default. */
.lib-default[aria-pressed="true"] {
  border-color: color-mix(in srgb, var(--warning) 40%, transparent);
  color: var(--warning);
}

/* ── Save to library dialog ─────────────────────────────────────────────── */
.lib-save-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.lib-save-error {
  margin: 0;
  white-space: pre-line;
}

/* ── Test images ────────────────────────────────────────────────────────── */
.til {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.til-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.til-note {
  margin: 0;
  padding: 10px 14px;
  border-radius: var(--radius-btn);
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  color: var(--danger);
  font-size: 13px;
  white-space: pre-line;
}

.til-progress {
  height: 3px;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--surface-hi);
}

.til-progress-bar {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width .3s var(--ease);
}

/* The grid is the drop zone; dragging files over it shows the label. */
.til-drop {
  position: relative;
  min-height: 160px;
  border-radius: var(--radius-card);
  outline: 2px dashed transparent;
  outline-offset: -2px;
  transition: outline-color var(--dur) var(--ease-ui), background var(--dur) var(--ease-ui);
}

.til-drop.is-drag-over {
  outline-color: var(--accent);
  background: var(--surface);
}

.til-drop-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: inherit;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease-ui);
}

.til-drop.is-drag-over .til-drop-label {
  opacity: 1;
}

.til-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

[data-til-mode="pick"] .til-grid {
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
}

.til-grid > .admin-empty-state,
.til-grid > .admin-loading {
  grid-column: 1 / -1;
}

.til-tile {
  position: relative;
  min-width: 0;
}

.til-tile-hit {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--surface-hi);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.til-tile-hit:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.til-tile-img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--surface);
}

.til-tile-name {
  overflow: hidden;
  padding: 7px 10px 8px;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-dim);
}

/* Pick mode: "Select" over the image on hover / keyboard focus. */
.til-tile-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transition: opacity var(--dur) var(--ease-ui);
}

.til-tile-hit:hover .til-tile-overlay,
.til-tile-hit:focus-visible .til-tile-overlay {
  opacity: 1;
}

.til-trash {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-btn);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  color: var(--text);
  cursor: pointer;
  transition: background var(--dur) var(--ease-ui), color var(--dur) var(--ease-ui);
}

/* 44px target around the 28px button. */
.til-trash::before {
  content: '';
  position: absolute;
  inset: -8px;
}

.til-trash .icon {
  width: 16px;
  height: 16px;
  stroke-width: 1.5;
}

.til-trash:hover {
  background: var(--bg);
  color: var(--danger);
}

.til-trash:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.til-trash:disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* Inline "Delete this image?" under the trash button. */
.til-del-pop {
  position: absolute;
  top: 40px;
  right: 6px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--bg);
  box-shadow: var(--popover-shadow);
  white-space: nowrap;
}

.til-del-msg {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.til-del-btns {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.til-del-btn {
  min-height: 32px;
  padding: 0 12px;
  font-size: 12px;
}

/* ── Image viewer dialog ────────────────────────────────────────────────── */
.til-viewer {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.til-viewer-img {
  display: block;
  max-width: 100%;
  max-height: 60vh;
  margin: 0 auto;
  border-radius: var(--radius-md);
  object-fit: contain;
}

.til-viewer-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  margin: 0;
  font-size: 13px;
}

.til-viewer-meta dt {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.til-viewer-meta dd {
  margin: 2px 0 0;
  color: var(--text);
}

@media (max-width: 600px) {
  .til-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  .til-progress-bar,
  .til-drop,
  .til-drop-label,
  .til-tile-overlay {
    transition: none;
  }
}
