.image-editor {
	height: 100%;
	display: flex;
	flex-direction: column;
	/* The root carries data-color-scheme="dark": the editor chrome is always dark
	   so the image stays the focus, and Designsystemet components inside pick up
	   matching dark tokens. */
	background: var(--ds-color-neutral-background-default, #111);
	color: var(--ds-color-neutral-text-default, white);
}

.image-editor__topbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	padding: 0.5rem 1rem;
	background: var(--ds-color-neutral-background-tinted, rgba(0, 0, 0, 0.4));
	border-bottom: 1px solid var(--ds-color-neutral-border-subtle, rgba(255, 255, 255, 0.08));
}

.image-editor__canvas {
	flex: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	position: relative;
	overflow: hidden;
}

.image-editor__replay-overlay {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(0, 0, 0, 0.4);
	color: var(--ds-color-neutral-text-default, white);
	z-index: 10;
	border-radius: 4px;
}

.image-editor__done {
	position: absolute;
	bottom: 1rem;
	right: 1rem;
	z-index: 5;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.image-editor__img {
	max-width: 100%;
	max-height: calc(100dvh - 160px); /* fallback when not inside zoom-canvas */
	object-fit: contain;
	border-radius: 4px;
	box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
	pointer-events: none;
	user-select: none;
}

.image-editor__toolbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0.75rem 1rem;
	background: var(--ds-color-neutral-background-tinted, #1a1a1a);
	border-top: 1px solid var(--ds-color-neutral-border-subtle, rgba(255, 255, 255, 0.08));
}

.image-editor__toolbar-group {
	display: flex;
	gap: 0.5rem;
	align-items: center;
	flex-wrap: wrap;
}

.image-editor__topbar-divider {
	width: 1px;
	height: 1.5rem;
	background: var(--ds-color-neutral-border-subtle, rgba(255, 255, 255, 0.15));
	flex-shrink: 0;
}

.image-editor__zoom-level {
	font-size: 0.8125rem;
	color: var(--ds-color-neutral-text-subtle, rgba(255, 255, 255, 0.6));
	min-width: 3.25ch;
	text-align: center;
	font-variant-numeric: tabular-nums;
}

/* ── Zoom canvas ─────────────────────────────────────────────── */

.zoom-canvas-root {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	touch-action: none;
	cursor: grab;
	user-select: none;
	/* Named size container so descendants can use cqh/cqw units. */
	container-type: size;
	container-name: zoom-canvas;
}

.zoom-canvas-root:active {
	cursor: grabbing;
}

.zoom-canvas-inner {
	transform-origin: center;
	padding: 1rem;
}

/*
 * Size all editor content relative to the canvas container rather than the
 * viewport. cqh/cqw refer to zoom-canvas-root which has known dimensions
 * (position: absolute; inset: 0), bypassing the percentage-height chain problem.
 *
 * Subtract padding so the element fits within its visual parent:
 *   • 2rem  = zoom-canvas-inner top + bottom padding (1rem each)
 *   • 32px  = crop-root top + bottom padding (16px each)
 *   • 4rem  = zoom-canvas-inner + redact-root padding (2 × 2rem)
 */
@container zoom-canvas (min-height: 1px) {
	.image-editor__img {
		max-height: calc(100cqh - 2rem);
	}

	.crop-root {
		max-height: calc(100cqh - 2rem);
	}

	/* Canvas has an intrinsic aspect ratio from its width/height attrs,
	   so both max constraints scale it to fit like an <img>. */
	.crop-inner canvas {
		max-height: calc(100cqh - 2rem - 32px);
		width: auto;
	}

	.redact-image {
		max-height: calc(100cqh - 4rem);
	}
}

/* ── Crop plugin ─────────────────────────────────────────────── */

.crop-root {
	position: relative;
	width: 100%;
	max-width: 900px;
	max-height: calc(100dvh - 160px); /* fallback when not inside zoom-canvas */
	/* Handles at the image corners are 28px circles — reserve half their size as padding
	   so they're never clipped at the edges. */
	padding: 16px;
	box-sizing: border-box;
	background: var(--ds-color-neutral-background-default, #111);
	touch-action: none;
}

.crop-inner {
	position: relative;
	display: inline-block;
	line-height: 0; /* remove gap under canvas */
}

/* Transparent drawing surface for the rectangle crop mode. Sits above the canvas
   but below the corner handles (which are hidden while this mode is active). */
.crop-draw-surface {
	position: absolute;
	inset: 0;
	cursor: crosshair;
	touch-action: none;
	z-index: 8;
}

/* ── Redact plugin ───────────────────────────────────────────── */

.redact-root {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	padding: 1rem;
}

.redact-inner {
	position: relative;
	display: inline-block;
	line-height: 0;
}

.redact-image {
	max-width: 100%;
	max-height: calc(100dvh - 160px); /* fallback when not inside zoom-canvas */
	display: block;
	user-select: none;
}

.redact-svg {
	position: absolute;
	inset: 0;
	cursor: crosshair;
	touch-action: none;
}

/* ── Handle hit-area expansion ───────────────────────────────── */
/* Invisible ::before expands the touch target without affecting layout */

.drag-handle::before {
	content: "";
	position: absolute;
	inset: -12px; /* 28px visual → 52px hit area */
}

.edge-handle::before {
	content: "";
	position: absolute;
	/* Expand whichever dimension is thin (6px) to ≥44px hit area */
	inset: -19px;
}

.crop-loading {
	align-items: center;
	justify-content: center;
	gap: 0.75rem;
	padding: 0.75rem 1rem;
	color: var(--ds-color-neutral-text-subtle, rgba(255, 255, 255, 0.7));
	position: absolute;
	inset: auto 0 0 0;
	background: linear-gradient(0deg, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0));
}

.LayoutSmall-root {
	height: 100dvh;
	overflow: hidden;
}

.LayoutSmall-root {
	display: grid;
	grid-template-rows: auto 1fr;
}
