/* ============================================================
   Image Rename Tool — gallery.css
   Step 2: toolbar (sort / remove) + draggable card list, each
   showing old→new name live preview, checkbox, drag handle.
   A LIST layout (not a grid) is used here on purpose — filenames
   need horizontal room to show "old → new" side by side, which
   a square thumbnail grid (like the format-converter tool) can't
   give without truncating both names into unreadable slivers.
   ============================================================ */


/* ══════════════════════════════════════════
   1. TOOLBAR
   ══════════════════════════════════════════ */
.ir-image-rename-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.ir-image-rename-toolbar__spacer {
  flex: 1 1 auto;
  min-width: 0;
}

.ir-image-rename-toolbar__count {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ir-ink-soft);
  white-space: nowrap;
}

.ir-image-rename-toolbar__menu {
  display: flex;
  gap: 6px;
}

.ir-image-rename-toolbar__iconbtn {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 12px;
  border-radius: 9999px;
  border: 1.5px solid var(--ir-line);
  background: #fff;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ir-ink-soft);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.ir-image-rename-toolbar__iconbtn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.ir-image-rename-toolbar__iconbtn span {
  display: none;
}

.ir-image-rename-toolbar__iconbtn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ir-image-rename-toolbar__iconbtn:not(:disabled):hover {
  border-color: var(--ir-line-strong);
  color: var(--ir-ink);
}

.ir-image-rename-toolbar__iconbtn--danger:not(:disabled):hover {
  border-color: var(--ir-error);
  color: var(--ir-error);
  background: #fdf1ef;
}

/* Subtler than --danger: outline + icon/text go red on hover, but no
   filled background. "Remove selected" is also destructive and should
   hint at that, without competing visually with "Remove all", which
   is the fully-alarming, irreversible action. */
.ir-image-rename-toolbar__iconbtn--danger-outline:not(:disabled):hover {
  border-color: var(--ir-error);
  color: var(--ir-error);
}


/* ══════════════════════════════════════════
   2. SORT PICKER — same custom-dropdown pattern as the
      format picker in controls.css, just more compact
      to sit comfortably in a toolbar row.
   ══════════════════════════════════════════ */
.ir-image-rename-sortpicker {
  position: relative;
}

.ir-image-rename-sortpicker__trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 14px;
  border-radius: 9999px;
  border: 1.5px solid var(--ir-line);
  background: #fff;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ir-ink);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ir-image-rename-sortpicker__icon {
  width: 15px;
  height: 15px;
  color: var(--ir-ink-soft);
  flex-shrink: 0;
}

.ir-image-rename-sortpicker__trigger:hover {
  border-color: var(--ir-line-strong);
}

.ir-image-rename-sortpicker__trigger:focus-visible {
  outline: none;
  border-color: var(--ir-brand);
  box-shadow: 0 0 0 4px var(--ir-brand-soft);
}

.ir-image-rename-sortpicker__chevron {
  width: 16px;
  height: 16px;
  color: var(--ir-ink-soft);
  flex-shrink: 0;
  transition: transform 0.18s ease;
}

.ir-image-rename-sortpicker__trigger[aria-expanded="true"] .ir-image-rename-sortpicker__chevron {
  transform: rotate(180deg);
}

.ir-image-rename-sortpicker__menu {
  /* fixed + positioned by JS so it always opens inside the visible
     screen (see createDropdown in main.js) */
  position: fixed;
  left: 0;
  top: 0;
  z-index: 80;
  min-width: 190px;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--ir-line);
  box-shadow: 0 16px 40px rgba(0,0,0,0.14), 0 4px 12px rgba(0,0,0,0.08);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  animation: irMenuIn 0.15s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.ir-image-rename-sortpicker__menu.is-up {
  animation-name: irMenuInUp;
}

.ir-image-rename-sortpicker__menu[hidden] {
  display: none;
}

@keyframes irMenuIn {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes irMenuInUp {
  from { opacity: 0; transform: translateY(4px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.ir-image-rename-sortpicker__option {
  display: flex;
  align-items: center;
  height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ir-ink);
  cursor: pointer;
}

.ir-image-rename-sortpicker__option:hover {
  background: var(--ir-bg);
}

.ir-image-rename-sortpicker__option.is-selected {
  color: var(--ir-brand-dark);
  font-weight: 700;
  background: var(--ir-brand-soft);
}


/* ══════════════════════════════════════════
   3. DRAG-REORDER HINT
   ══════════════════════════════════════════ */
.ir-image-rename-hint {
  margin: 0 0 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ir-ink-soft);
  line-height: 1.5;
}


/* ══════════════════════════════════════════
   4. GALLERY — vertical list of cards
   ══════════════════════════════════════════ */
.ir-image-rename-gallery {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 4px;
}


/* ══════════════════════════════════════════
   5. CARD
   ══════════════════════════════════════════ */
.ir-image-rename-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 14px;
  background: #fff;
  border: 1.5px solid var(--ir-line);
  animation: irCardIn 0.22s ease both;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

@keyframes irCardIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Selection state ── */
.ir-image-rename-card.is-selected {
  border-color: var(--ir-brand);
  background: var(--ir-brand-soft);
}

/* ── Find & Replace match highlight (set from main.js) ── */
.ir-image-rename-card.is-match {
  border-color: #e3b341;
  background: #fffaf0;
}

.ir-image-rename-card.is-match.is-selected {
  border-color: var(--ir-brand);
}

/* ── Drag states ── */
.ir-image-rename-card.is-dragging {
  opacity: 0.4;
}

.ir-image-rename-card.is-dragover {
  border-color: var(--ir-brand);
  box-shadow: 0 0 0 3px var(--ir-brand-soft);
}

.ir-image-rename-card__drag {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 40px;
  border: none;
  background: none;
  color: var(--ir-line-strong);
  cursor: grab;
  touch-action: none;
}

.ir-image-rename-card__drag:active {
  cursor: grabbing;
}

.ir-image-rename-card__drag svg {
  width: 16px;
  height: 16px;
}

/* ── Checkbox (custom, matches brand rather than native styling) ── */
.ir-image-rename-card__select {
  flex-shrink: 0;
  position: relative;
  display: flex;
  cursor: pointer;
}

.ir-image-rename-card__checkbox {
  position: absolute;
  opacity: 0;
  width: 20px;
  height: 20px;
  margin: 0;
  cursor: pointer;
}

.ir-image-rename-card__checkmark {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 1.5px solid var(--ir-line-strong);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.ir-image-rename-card__checkmark::after {
  content: '';
  width: 10px;
  height: 6px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translateY(-1px);
  opacity: 0;
}

.ir-image-rename-card__checkbox:checked + .ir-image-rename-card__checkmark {
  background: var(--ir-brand);
  border-color: var(--ir-brand);
}

.ir-image-rename-card__checkbox:checked + .ir-image-rename-card__checkmark::after {
  opacity: 1;
}

.ir-image-rename-card__checkbox:focus-visible + .ir-image-rename-card__checkmark {
  outline: 2px solid var(--ir-brand);
  outline-offset: 2px;
}

/* ── Sequence index badge ── */
.ir-image-rename-card__index {
  flex-shrink: 0;
  min-width: 22px;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  color: var(--ir-ink-soft);
}

/* ── Thumbnail ── */
.ir-image-rename-card__thumbwrap {
  position: relative;
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 10px;
  overflow: hidden;
  background:
    linear-gradient(45deg, #e9e9ef 25%, transparent 25%) -6px 0/ 12px 12px,
    linear-gradient(-45deg, #e9e9ef 25%, transparent 25%) -6px 0/ 12px 12px,
    #fafafd;
}

.ir-image-rename-card__thumb {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Overlay on the thumbnail corner — always visible (not hover-only),
   since on mobile there's no hover state to rely on */
.ir-image-rename-card__remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(26,26,34,0.6);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(2px);
  transition: background 0.15s ease, transform 0.15s ease;
}

.ir-image-rename-card__remove svg {
  width: 10px;
  height: 10px;
}

.ir-image-rename-card__remove:active {
  transform: scale(0.9);
}

.ir-image-rename-card__remove:hover {
  background: var(--ir-error);
}

/* ── Names ── */
.ir-image-rename-card__names {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ir-image-rename-card__oldname {
  margin: 0;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ir-ink-soft);
  text-decoration: line-through;
  text-decoration-color: var(--ir-line-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ir-image-rename-card__newname-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.ir-image-rename-card__arrow {
  display: none; /* only shown on wider screens where both names fit side by side; see gallery.css desktop block */
  width: 13px;
  height: 13px;
  color: var(--ir-brand);
  flex-shrink: 0;
}

.ir-image-rename-card__newname {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ir-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  border-bottom: 1.5px dashed var(--ir-line-strong);
  padding-bottom: 1px;
}

.ir-image-rename-card__newname:hover {
  color: var(--ir-brand-dark);
  border-bottom-color: var(--ir-brand);
}

.ir-image-rename-card__lock {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  color: var(--ir-brand);
}

.ir-image-rename-card__lock svg {
  width: 13px;
  height: 13px;
}

.ir-image-rename-card__editinput {
  width: 100%;
  height: 30px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1.5px solid var(--ir-brand);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ir-ink);
  background: #fff;
}

.ir-image-rename-card__editinput:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ir-brand-soft);
}


/* ══════════════════════════════════════════
   6. "ADD MORE" — full-width tile at the end of the list
   ══════════════════════════════════════════ */
/* ══════════════════════════════════════════
   7. DESKTOP ENHANCEMENTS (≥768px)
   ══════════════════════════════════════════ */
@media (min-width: 768px) {
  .ir-image-rename-toolbar__iconbtn span {
    display: inline;
  }

  .ir-image-rename-card {
    padding: 10px 14px;
    gap: 14px;
  }

  .ir-image-rename-card__thumbwrap {
    width: 56px;
    height: 56px;
  }

  /* Enough room now to show old → new side by side, arrow included */
  .ir-image-rename-card__names {
    flex-direction: row;
    align-items: center;
    gap: 10px;
  }

  .ir-image-rename-card__oldname {
    flex: 0 1 auto;
    max-width: 34%;
  }

  .ir-image-rename-card__newname-wrap {
    flex: 1 1 auto;
  }

  .ir-image-rename-card__arrow {
    display: block;
  }

  .ir-image-rename-card__remove {
    width: 20px;
    height: 20px;
  }

  .ir-image-rename-card__remove:hover {
    transform: scale(1.08);
  }
}


/* ══════════════════════════════════════════
   8. ACCESSIBILITY
   ══════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  .ir-image-rename-card {
    animation: none;
  }
}
