/*
 * Portable image-editor presentation layer.
 * Copy this file with image-editor.js when reusing the editor in another project.
 * Existing MOONARROW names remain aliases; new projects should prefer image-editor-*.
 */

:root {
  --image-editor-accent: var(--store-accent, #2f6fed);
  --image-editor-accent-dark: #243fc1;
  --image-editor-ink: #174f9d;
  --image-editor-line: #c9dcf7;
  --image-editor-muted: #52606d;
}

.product-image-editor,
.image-editor {
  background: #f5f8ff;
  border: 1px solid #cdddf7;
  display: grid;
  gap: 0.75rem;
  margin: 1rem 0;
  padding: 1rem;
}

.product-image-editor-heading,
.image-editor-heading {
  align-items: start;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
}

.product-image-editor-heading .eyebrow,
.image-editor-heading .eyebrow {
  margin: 0 0 0.3rem;
}

.product-image-editor-heading h2,
.image-editor-heading h2 {
  margin: 0;
}

.product-image-editor-count,
.product-image-editor-status,
.product-image-editor-error,
.image-editor-count,
.image-editor-status {
  color: var(--image-editor-muted);
  font-size: 0.86rem;
  margin: 0;
}

.product-image-editor-error {
  color: #b42318;
  font-weight: 700;
}

.product-image-editor-error:empty {
  display: none;
}

.product-image-editor-count,
.image-editor-count {
  font-weight: 700;
  text-align: right;
}

.site-file-input,
.image-editor-file-input {
  background: #fff;
  border: 1px solid var(--image-editor-line);
  border-radius: 10px;
  color: var(--image-editor-muted);
  font: inherit;
  min-height: 44px;
  padding: 0.3rem 0.45rem;
  width: 100%;
}

.site-file-input::file-selector-button,
.image-editor-file-input::file-selector-button,
.site-file-input::-webkit-file-upload-button,
.image-editor-file-input::-webkit-file-upload-button {
  background: linear-gradient(135deg, var(--image-editor-accent), #3157e8);
  border: 1px solid transparent;
  border-radius: 7px;
  box-shadow: 0 5px 12px rgba(28, 86, 181, 0.2);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 800;
  margin-right: 0.65rem;
  min-height: 32px;
  padding: 0.35rem 0.65rem;
}

.site-file-input:hover::file-selector-button,
.site-file-input:focus-visible::file-selector-button,
.image-editor-file-input:hover::file-selector-button,
.image-editor-file-input:focus-visible::file-selector-button,
.site-file-input:hover::-webkit-file-upload-button,
.site-file-input:focus-visible::-webkit-file-upload-button,
.image-editor-file-input:hover::-webkit-file-upload-button,
.image-editor-file-input:focus-visible::-webkit-file-upload-button {
  background: linear-gradient(135deg, #075ed0, var(--image-editor-accent-dark));
}

.site-file-input:focus-visible,
.image-editor-file-input:focus-visible {
  border-color: var(--image-editor-accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.2);
  outline: 0;
}

.image-editor-save-button,
.image-editor-crop-dialog-actions .btn-primary {
  background: linear-gradient(135deg, var(--image-editor-accent), #3157e8);
  border: 1px solid transparent;
  border-radius: 9px;
  box-shadow: 0 9px 20px rgba(28, 86, 181, 0.24);
  color: #fff;
  font-weight: 800;
  min-height: 40px;
  padding: 0.45rem 0.9rem;
}

.image-editor-save-button:hover,
.image-editor-save-button:focus-visible,
.image-editor-crop-dialog-actions .btn-primary:hover,
.image-editor-crop-dialog-actions .btn-primary:focus-visible {
  background: linear-gradient(135deg, #075ed0, var(--image-editor-accent-dark));
  border-color: transparent;
  color: #fff;
  transform: translateY(-1px);
}

.image-editor-crop-dialog-actions .btn-secondary {
  background: #fff;
  border: 1px solid #b9cbe4;
  border-radius: 9px;
  color: var(--image-editor-ink);
  font-weight: 800;
  min-height: 40px;
  padding: 0.45rem 0.9rem;
}

.image-editor-crop-dialog-actions .btn-secondary:hover,
.image-editor-crop-dialog-actions .btn-secondary:focus-visible {
  background: #eef5ff;
  border-color: var(--image-editor-accent);
  color: var(--image-editor-ink);
}

.product-image-grid,
.image-editor-grid {
  display: grid;
  gap: 0.9rem;
  grid-template-columns: repeat(auto-fill, minmax(210px, 240px));
  justify-content: start;
}

.product-image-card,
.product-image-empty-state,
.image-editor-card,
.image-editor-empty-state {
  aspect-ratio: 1 / 1;
  box-sizing: border-box;
  min-width: 0;
}

.product-image-card,
.image-editor-card {
  background: #fff;
  border: 1px solid #cdd8ea;
  margin: 0;
  overflow: hidden;
  position: relative;
  transform-origin: center;
  transition: transform 0.32s cubic-bezier(.22, .85, .25, 1), opacity 0.2s ease, box-shadow 0.32s ease;
  user-select: none;
  will-change: transform;
}

.product-image-card.is-main-image,
.image-editor-card.is-main-image {
  border: 2px solid var(--image-editor-accent);
}

.product-image-card.is-new-image,
.image-editor-card.is-new-image {
  outline: 2px solid var(--image-editor-accent);
  outline-offset: -2px;
}

.product-image-card img,
.image-editor-card img {
  display: block;
  height: 100%;
  object-fit: contain;
  padding: 0.55rem;
  pointer-events: none;
  width: 100%;
  -webkit-user-drag: none;
}

/* Home images reuse the product editor card and sort interaction. The image
   uses cover so the saved crop position is visible, and no padding so the
   crop positioned by image-editor.js does not expose the card background. */
.product-image-card.home-image-card img {
  object-fit: cover;
  padding: 0;
  transform-origin: center;
}

.product-image-card figcaption,
.image-editor-card figcaption {
  background: rgba(8, 20, 40, 0.9);
  bottom: 0;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  left: 0;
  letter-spacing: 0.04em;
  margin: 0;
  padding: 0.45rem 0.6rem;
  position: absolute;
  right: 0;
}

.product-image-drag-handle,
.product-image-remove-button,
.image-editor-drag-handle,
.image-editor-remove-button {
  align-items: center;
  border-radius: 999px;
  box-sizing: border-box;
  cursor: pointer;
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  line-height: 1;
  padding: 0;
  position: absolute;
  top: 0.5rem;
  transition: background 0.16s ease, transform 0.16s ease;
  z-index: 3;
}

.product-image-drag-handle::before,
.product-image-remove-button::before,
.image-editor-drag-handle::before,
.image-editor-remove-button::before {
  content: "";
  position: absolute;
  inset: -0.5rem;
}

.product-image-drag-handle,
.image-editor-drag-handle {
  background: rgba(8, 20, 40, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.88);
  color: #fff;
  cursor: grab;
  font-size: 0.88rem;
  height: 2rem;
  right: 0.5rem;
  touch-action: none;
  width: 2rem;
}

.product-image-remove-button,
.image-editor-remove-button {
  background: #b42318;
  border: 1px solid #fff;
  color: #fff;
  font-size: 1rem;
  height: 2rem;
  left: 0.5rem;
  width: 2rem;
}

.product-image-drag-handle:hover,
.product-image-drag-handle:focus-visible,
.image-editor-drag-handle:hover,
.image-editor-drag-handle:focus-visible {
  background: var(--image-editor-accent);
  transform: scale(1.06);
}

.product-image-remove-button:hover,
.product-image-remove-button:focus-visible,
.image-editor-remove-button:hover,
.image-editor-remove-button:focus-visible {
  background: #8d221b;
  transform: scale(1.08);
}

.product-image-grid.is-image-reordering .product-image-card,
.image-editor-grid.is-image-reordering .image-editor-card {
  transition: none;
}

.product-image-grid.is-image-reordering .product-image-drag-handle,
.product-image-drag-handle:active,
.image-editor-grid.is-image-reordering .image-editor-drag-handle,
.image-editor-drag-handle:active {
  cursor: grabbing;
}

.product-image-card.is-image-dragging,
.image-editor-card.is-image-dragging {
  box-shadow: 0 20px 38px rgba(8, 20, 40, 0.24);
  opacity: 0.82;
  transform: scale(1.035) rotate(0.45deg);
  z-index: 2;
}

.product-image-card.is-image-settling,
.image-editor-card.is-image-settling {
  animation: image-editor-settle 0.42s cubic-bezier(.2, .9, .2, 1);
}

.product-image-card.is-image-arriving,
.image-editor-card.is-image-arriving {
  animation: image-editor-arrive 0.4s cubic-bezier(.2, .85, .25, 1) both;
}

@keyframes image-editor-settle {
  0% { transform: scale(1.035) rotate(0.45deg); }
  58% { transform: scale(0.985) rotate(-0.12deg); }
  100% { transform: scale(1) rotate(0); }
}

@keyframes image-editor-arrive {
  0% { opacity: 0; transform: translateY(14px) scale(0.94); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes image-editor-drop-target-arrive {
  from { opacity: 0.45; transform: scale(0.965); }
  to { opacity: 1; transform: scale(1); }
}

.product-image-empty-state,
.image-editor-empty-state {
  align-items: center;
  background: #fff;
  border: 1px dashed #97b5e4;
  color: #627185;
  display: flex;
  justify-content: center;
  max-width: 240px;
  padding: 1rem;
  text-align: center;
}

body.is-product-image-reordering,
body.is-product-image-reordering *,
body.is-image-editor-reordering,
body.is-image-editor-reordering * {
  cursor: grabbing !important;
  overscroll-behavior: none;
  user-select: none !important;
  -webkit-user-select: none !important;
}

body.is-product-image-reordering,
body.is-image-editor-reordering {
  touch-action: none;
}

[data-product-image-sort-list] > .is-image-drag-source,
[data-image-editor-sort-list] > .is-image-drag-source {
  display: none !important;
}

.product-image-drop-placeholder,
.image-editor-drop-placeholder {
  align-items: center;
  background: linear-gradient(135deg, rgba(47, 111, 237, 0.14), rgba(47, 111, 237, 0.035)), #f4f7fc;
  border: 2px dashed var(--image-editor-accent);
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.66);
  box-sizing: border-box;
  color: var(--image-editor-ink);
  display: flex;
  justify-content: center;
  margin: 0;
  min-width: 0;
  overflow: hidden;
  position: relative;
  width: 100%;
}

.product-image-drop-placeholder::before,
.image-editor-drop-placeholder::before {
  border: 1px solid rgba(47, 111, 237, 0.25);
  border-radius: 999px;
  content: "";
  height: 64px;
  position: absolute;
  width: 64px;
}

.product-image-drop-placeholder__label,
.image-editor-drop-placeholder__label {
  background: rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(20, 63, 126, 0.12);
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.4;
  max-width: calc(100% - 24px);
  padding: 0.48rem 0.68rem;
  position: relative;
  text-align: center;
  z-index: 1;
}

.product-image-drop-placeholder.is-image-drop-target,
.image-editor-drop-placeholder.is-image-drop-target {
  animation: image-editor-drop-target-arrive 160ms cubic-bezier(.22, .85, .25, 1);
}

.product-image-drag-ghost,
.image-editor-drag-ghost {
  box-shadow: 0 20px 44px rgba(8, 20, 40, 0.3) !important;
  contain: layout paint;
  left: 0 !important;
  margin: 0 !important;
  opacity: 0.94 !important;
  pointer-events: none !important;
  position: fixed !important;
  top: 0 !important;
  transition: none !important;
  will-change: transform;
  z-index: 10000 !important;
}

.product-image-drag-ghost,
.image-editor-drag-ghost {
  animation: none !important;
}

.product-image-drag-ghost input,
.product-image-drag-ghost button,
.product-image-drag-ghost select,
.product-image-drag-ghost textarea,
.image-editor-drag-ghost input,
.image-editor-drag-ghost button,
.image-editor-drag-ghost select,
.image-editor-drag-ghost textarea {
  pointer-events: none !important;
}

.image-editor-crop-dialog {
  background: transparent;
  border: 0;
  max-height: calc(100dvh - 1rem);
  max-width: min(680px, calc(100vw - 2rem));
  overflow: hidden;
  padding: 0;
  width: 100%;
}

.image-editor-crop-dialog::backdrop {
  background: rgba(8, 20, 40, 0.66);
}

.image-editor-crop-dialog-content {
  background: #fff;
  border: 1px solid #cdd8ea;
  border-radius: 14px;
  box-shadow: 0 26px 70px rgba(8, 20, 40, 0.32);
  box-sizing: border-box;
  display: grid;
  gap: 0.9rem;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  height: min(800px, calc(100dvh - 1rem));
  max-height: calc(100dvh - 1rem);
  overflow: hidden;
  padding: 1rem;
}

.image-editor-crop-dialog-heading {
  align-items: flex-start;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
}

.image-editor-crop-dialog-heading h2,
.image-editor-crop-dialog-heading p {
  margin: 0;
}

.image-editor-crop-dialog-heading p {
  color: var(--image-editor-muted);
  font-size: 0.88rem;
  line-height: 1.55;
  margin-top: 0.28rem;
}

.image-editor-crop-close {
  align-items: center;
  background: transparent;
  border: 0;
  color: var(--image-editor-muted);
  cursor: pointer;
  display: inline-flex;
  font-size: 1.7rem;
  height: 2rem;
  justify-content: center;
  line-height: 1;
  padding: 0;
  width: 2rem;
}

.image-editor-crop-close:hover,
.image-editor-crop-close:focus-visible {
  color: #0c55ba;
}

.image-editor-crop-button,
.home-image-crop-button {
  background: rgba(8, 20, 40, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.88);
  bottom: 0.42rem;
  color: #fff;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  min-height: 1.7rem;
  padding: 0.25rem 0.48rem;
  position: absolute;
  right: 0.45rem;
  transition: background 0.16s ease, transform 0.16s ease;
  z-index: 4;
}

.image-editor-crop-button:hover,
.image-editor-crop-button:focus-visible,
.home-image-crop-button:hover,
.home-image-crop-button:focus-visible {
  background: var(--image-editor-accent);
  color: #fff;
  transform: translateY(-1px);
}

.image-editor-crop-frame {
  align-self: center;
  aspect-ratio: 1 / 1;
  background: #111827;
  block-size: 100%;
  border: 1px solid #9fb8dc;
  inline-size: auto;
  justify-self: center;
  margin: 0;
  max-height: 100%;
  max-width: 100%;
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: contain;
  position: relative;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.image-editor-crop-frame[data-dragging="true"],
.image-editor-crop-frame:active {
  cursor: grabbing;
}

.image-editor-crop-frame img {
  display: block;
  height: auto;
  max-width: none;
  object-fit: fill;
  pointer-events: none;
  position: absolute;
  user-select: none;
  width: auto;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
}

.image-editor-crop-grid {
  background: linear-gradient(to right, transparent 33.1%, rgba(255, 255, 255, 0.72) 33.33%, transparent 33.58%, transparent 66.43%, rgba(255, 255, 255, 0.72) 66.66%, transparent 66.91%), linear-gradient(to bottom, transparent 33.1%, rgba(255, 255, 255, 0.72) 33.33%, transparent 33.58%, transparent 66.43%, rgba(255, 255, 255, 0.72) 66.66%, transparent 66.91%);
  inset: 0;
  pointer-events: none;
  position: absolute;
}

.image-editor-crop-controls {
  display: grid;
  gap: 0.35rem;
}

.image-editor-crop-controls input[type="range"] {
  width: 100%;
}

.image-editor-crop-controls input[type="range"]:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.image-editor-crop-axis-hint {
  background: #f4f7fc;
  border-left: 3px solid var(--image-editor-accent);
  color: var(--image-editor-muted);
  font-size: 0.82rem;
  line-height: 1.5;
  margin: 0.35rem 0 0;
  padding: 0.45rem 0.6rem;
}

.image-editor-crop-zoom-row {
  align-items: center;
  display: grid;
  gap: 0.5rem;
  grid-template-columns: auto minmax(0, 1fr) auto minmax(3.5rem, auto);
}

.image-editor-crop-zoom-row button {
  align-items: center;
  background: #f4f7fc;
  border: 1px solid #b9cbe4;
  border-radius: 999px;
  color: var(--image-editor-ink);
  cursor: pointer;
  display: inline-flex;
  font-size: 1.1rem;
  font-weight: 800;
  height: 2rem;
  justify-content: center;
  line-height: 1;
  padding: 0;
  width: 2rem;
}

.image-editor-crop-zoom-row output {
  color: #475569;
  font-variant-numeric: tabular-nums;
  min-width: 3.5rem;
  text-align: right;
}

.image-editor-crop-dialog-actions {
  align-self: end;
  display: flex;
  gap: 0.65rem;
  justify-content: flex-end;
}

@media (max-width: 767.98px) {
  .product-image-grid,
  .image-editor-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .product-image-empty-state,
  .image-editor-empty-state {
    max-width: none;
  }
}

@media (max-width: 479.98px) {
  .image-editor-crop-dialog {
    max-width: calc(100vw - 1rem);
  }

  .image-editor-crop-dialog-content {
    border-radius: 10px;
    padding: 0.8rem;
  }

  .image-editor-crop-dialog-actions .btn {
    flex: 1 1 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .product-image-card,
  .product-image-card.is-image-settling,
  .product-image-card.is-image-arriving,
  .product-image-drop-placeholder.is-image-drop-target,
  .image-editor-card,
  .image-editor-card.is-image-settling,
  .image-editor-card.is-image-arriving,
  .image-editor-drop-placeholder.is-image-drop-target {
    animation: none;
    transition: none;
  }
}

/* Compact image-management chrome; crop canvas remains unchanged for precision. */
.image-editor,
.home-image-editor,
.product-image-editor {
  margin-block: 0.75rem;
  padding: 0.75rem;
}

.image-editor-heading,
.home-image-editor-heading,
.product-image-editor-heading {
  gap: 0.5rem;
}

.product-image-grid,
.image-editor-grid {
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fill, minmax(10rem, 12.5rem));
  grid-auto-rows: auto;
  align-items: start;
}

@media (max-width: 767.98px) {
  .product-image-grid,
  .image-editor-grid {
    gap: 0.5rem;
    grid-auto-rows: auto;
  }
}

/* Issue #86 / TIN-299: homepage previews and crop tools share the live Hero ratio. */
.home-image-editor .product-image-grid {
  grid-template-columns: repeat(auto-fill, minmax(17rem, 22rem));
  grid-auto-rows: auto;
}

.home-image-editor .product-image-card,
.home-image-editor .product-image-empty-state {
  aspect-ratio: var(--moonarrow-hero-media-ratio, 1 / 1);
}

.image-editor-crop-dialog--hero {
  max-width: min(960px, calc(100vw - 2rem));
}

.image-editor-crop-dialog--hero .image-editor-crop-dialog-content {
  grid-template-columns: minmax(0, 1fr) minmax(15rem, 18rem);
  grid-template-rows: auto auto auto;
  height: auto;
  overflow: auto;
}

.image-editor-crop-dialog--hero .image-editor-crop-dialog-heading {
  grid-column: 1 / -1;
}

.image-editor-crop-dialog--hero .image-editor-crop-frame {
  grid-column: 1;
  grid-row: 2;
  width: 100%;
  height: auto;
  inline-size: 100%;
  block-size: auto;
  max-height: none;
  aspect-ratio: var(--moonarrow-hero-media-ratio, 1 / 1);
}

.image-editor-crop-dialog--hero .image-editor-crop-controls {
  grid-column: 2;
  grid-row: 2;
  align-content: start;
}

.image-editor-crop-dialog--hero .image-editor-crop-dialog-actions {
  grid-column: 1 / -1;
  grid-row: 3;
}

@media (max-width: 767.98px) {
  .image-editor-crop-dialog--hero {
    max-width: calc(100vw - 1rem);
  }

  .image-editor-crop-dialog--hero .image-editor-crop-dialog-content {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto;
  }

  .image-editor-crop-dialog--hero .image-editor-crop-frame,
  .image-editor-crop-dialog--hero .image-editor-crop-controls,
  .image-editor-crop-dialog--hero .image-editor-crop-dialog-actions {
    grid-column: 1;
  }

  .image-editor-crop-dialog--hero .image-editor-crop-frame {
    grid-row: 2;
  }

  .image-editor-crop-dialog--hero .image-editor-crop-controls {
    grid-row: 3;
  }

  .image-editor-crop-dialog--hero .image-editor-crop-dialog-actions {
    grid-row: 4;
  }

  .home-image-editor .product-image-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-auto-rows: auto;
  }
}
