/* ==========================================================================
   merge.css — Merge Images editor: image list · canvas preview · settings
   Only loaded on /tools/image/merge-images (see data/tools.js → tool.css).
   ========================================================================== */

.merge {
  display: grid;
  grid-template-columns: minmax(0, 300px) minmax(0, 1fr) minmax(0, 330px);
  align-items: start;
  gap: var(--space-5);
}

/* The two rails scroll with the page until the header stops them. */
.merge__images,
.merge__settings {
  position: sticky;
  top: calc(var(--header-h) + var(--space-6));
  max-height: calc(100vh - var(--header-h) - var(--space-10));
}
.merge__images .panel__body,
.merge__settings .panel__body {
  overflow-y: auto;
}

.merge__head-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* --- Dropzone (compact variant of the shared .dropzone) ------------------- */
.dropzone--compact {
  min-height: 132px;
  padding: var(--space-5);
  gap: 3px;
}
.dropzone--compact .dropzone__icon {
  width: 36px;
  height: 36px;
  margin-bottom: var(--space-1);
}
.dropzone--compact .dropzone__title { font-size: var(--text-sm); }

/* --- Image list ----------------------------------------------------------- */
.img-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  list-style: none;
}
.img-list:empty { display: none; }

.img-item {
  display: grid;
  grid-template-columns: auto 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.02);
  transition: border-color var(--t), background-color var(--t), opacity var(--t);
}
.img-item:hover { border-color: var(--border-strong); }
.img-item.is-dragging { opacity: 0.4; }
.img-item.is-over { border-color: var(--primary); background: var(--primary-soft); }

.img-item__grip {
  display: grid;
  place-items: center;
  color: var(--text-subtle);
  cursor: grab;
  touch-action: none;
}
.img-item__grip:active { cursor: grabbing; }
.img-item__grip .icon { width: 16px; height: 16px; }

.img-item__thumb {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  object-fit: cover;
  background: var(--surface-3);
}

.img-item__body { min-width: 0; }
.img-item__name {
  display: block;
  font-size: var(--text-sm);
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.img-item__meta {
  display: block;
  color: var(--text-subtle);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.img-item__actions { display: flex; gap: 2px; }
.img-item__btn {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-subtle);
  cursor: pointer;
  transition: background-color var(--t-fast), color var(--t-fast);
}
.img-item__btn:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.img-item__btn:disabled { opacity: 0.3; pointer-events: none; }
.img-item__btn--danger:hover { background: var(--danger-soft); color: var(--danger); }
.img-item__btn .icon { width: 14px; height: 14px; }

/* --- Canvas stage --------------------------------------------------------- */
.merge__stage {
  align-items: center;
  justify-content: center;
  min-height: 460px;
}

.canvas-wrap {
  display: grid;
  place-items: center;
  width: 100%;
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  /* checkerboard, so a transparent background is readable */
  background-color: rgba(255, 255, 255, 0.02);
  background-image:
    linear-gradient(45deg, rgba(255, 255, 255, 0.05) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.05) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.05) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.05) 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
}
.canvas-wrap canvas {
  display: block;
  max-width: 100%;
  max-height: 62vh;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

/* --- Segmented control ---------------------------------------------------- */
.seg {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.02);
}
.seg__item input { position: absolute; opacity: 0; width: 0; height: 0; }
.seg__item span {
  display: block;
  padding: 7px 10px;
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 550;
  text-align: center;
  cursor: pointer;
  transition: background-color var(--t-fast), color var(--t-fast);
}
.seg__item:hover span { color: var(--text); }
.seg__item input:checked + span {
  background: var(--primary-soft);
  color: #93b8ff;
}
.seg__item input:focus-visible + span { box-shadow: var(--ring); }

/* --- Colour field --------------------------------------------------------- */
.color-field {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: var(--space-2);
}
.input--color {
  padding: 4px;
  height: 40px;
  cursor: pointer;
}
.input--color::-webkit-color-swatch-wrapper { padding: 0; }
.input--color::-webkit-color-swatch { border: 0; border-radius: var(--radius-xs); }
.input--color::-moz-color-swatch { border: 0; border-radius: var(--radius-xs); }

.rule { border: 0; border-top: 1px solid var(--border); }

/* --- Responsive ----------------------------------------------------------- */
@media (max-width: 1280px) {
  /* Preview goes full width on top, the two rails share the row beneath it. */
  .merge { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .merge__preview { grid-column: 1 / -1; grid-row: 1; }
  .merge__images { grid-row: 2; }
  .merge__settings { grid-row: 2; }
  .merge__images,
  .merge__settings { position: static; max-height: none; }
}

@media (max-width: 820px) {
  .merge { grid-template-columns: minmax(0, 1fr); }
  .merge__preview { grid-row: auto; }
  .merge__images,
  .merge__settings { grid-row: auto; }
  .merge__stage { min-height: 300px; }
  .canvas-wrap canvas { max-height: 46vh; }
}

@media (max-width: 480px) {
  .seg { grid-template-columns: minmax(0, 1fr); }
  .img-item { grid-template-columns: auto 36px minmax(0, 1fr); }
  .img-item__thumb { width: 36px; height: 36px; }
  .img-item__actions { grid-column: 2 / -1; justify-content: flex-end; }
}
