/* Keep image-cut geometry independent of the shared button interaction styles.
 * React owns each cut's inline left/top and its native pointer/keyboard events. */
.ds-image-tools .ds-grid-picture {
  overflow: hidden;
  border-radius: 4px;
  isolation: isolate;
}

/* Only the split dialog changes layout. Keep its title/actions outside the
 * scrollable controls so focus never scrolls the whole dialog past its header. */
.ds-image-tools:has(> .ds-grid-stage) {
  --ct-split-preview-height: min(48vh, 440px);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: clip;
}

.ds-image-tools:has(> .ds-grid-stage) > :is(header, footer) {
  flex: 0 0 auto;
}

.ds-image-tools:has(> .ds-grid-stage) > .ds-grid-stage {
  flex: 0 0 auto;
  align-items: center;
  min-height: 0;
}

.ds-image-tools:has(> .ds-grid-stage) > .ds-image-controls {
  flex: 0 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scroll-padding-block: 8px;
}

.ds-image-tools:has(> .ds-grid-stage) > .ds-image-tools-error {
  flex: 0 1 auto;
  min-height: 0;
  max-height: 72px;
  overflow: auto;
}

/* Let the image's intrinsic ratio determine the cut-overlay box. Overriding
 * only the old inline width would squeeze portrait or very wide previews. */
.ds-image-tools:has(> .ds-grid-stage) .ds-grid-picture {
  width: fit-content !important;
  height: auto;
  aspect-ratio: auto !important;
  max-width: 100%;
}

.ds-image-tools:has(> .ds-grid-stage) .ds-grid-picture > img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: var(--ct-split-preview-height);
  object-fit: contain;
}

@media (max-height: 800px) {
  .ds-image-tools:has(> .ds-grid-stage) {
    --ct-split-preview-height: clamp(100px, calc(100dvh - 460px), 320px);
  }

  .ds-image-tools:has(> .ds-grid-stage) > header {
    padding: 12px 20px;
  }

  .ds-image-tools:has(> .ds-grid-stage) > .ds-image-controls {
    padding: 12px 20px 8px;
  }

  .ds-image-tools:has(> .ds-grid-stage) > footer {
    padding: 12px 20px 14px;
  }

  .ds-image-tools:has(> .ds-grid-stage) .ds-image-custom-grid {
    flex-wrap: wrap;
    row-gap: 7px;
    margin-top: 10px;
  }

  .ds-image-tools:has(> .ds-grid-stage) .ds-image-split-options {
    margin-top: 10px;
  }

  .ds-image-tools:has(> .ds-grid-stage) .ds-image-controls p {
    margin: 8px 0 3px;
    line-height: 1.5;
  }
}

.ds-image-tools .ds-grid-picture > button.ds-grid-cut {
  box-sizing: border-box;
  display: block;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  transform: translate(-50%, -50%) !important;
  transition: background-color 120ms ease;
  touch-action: none;
}

.ds-image-tools .ds-grid-picture > button.ds-grid-cut.is-horizontal {
  left: 50%;
  width: 100%;
  height: 24px;
  cursor: row-resize;
}

.ds-image-tools .ds-grid-picture > button.ds-grid-cut.is-vertical {
  top: 50%;
  width: 24px;
  height: 100%;
  cursor: col-resize;
}

.ds-image-tools .ds-grid-picture > button.ds-grid-cut::before {
  box-sizing: border-box;
  pointer-events: none;
}

.ds-image-tools .ds-grid-picture > button.ds-grid-cut.is-horizontal::before {
  inset: 50% 0 auto;
  height: 1px;
  transform: translateY(-50%);
}

.ds-image-tools .ds-grid-picture > button.ds-grid-cut.is-vertical::before {
  inset: 0 auto 0 50%;
  width: 1px;
  transform: translateX(-50%);
}

.ds-image-tools .ds-grid-picture > button.ds-grid-cut > span {
  box-sizing: border-box;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.ds-image-tools .ds-grid-picture > button.ds-grid-cut.is-horizontal > span {
  width: 24px;
  height: 5px;
}

.ds-image-tools .ds-grid-picture > button.ds-grid-cut.is-vertical > span {
  width: 5px;
  height: 24px;
}

.ds-image-tools .ds-grid-picture > button.ds-grid-cut:is(:hover, :active) {
  background: #dce9ff12;
}

@media (prefers-reduced-motion: reduce) {
  .ds-image-tools .ds-grid-picture > button.ds-grid-cut {
    transition: none;
  }
}
