.wp3dconf-custom-image-upload {
	display: flex;
	flex-direction: column;
	gap: 8px;
	width: 100%;
}

/*
 * The `hidden` HTML attribute alone isn't reliable here - this runs on
 * arbitrary customer themes, and any theme rule targeting `input` (a
 * CSS reset, a page-builder's form styling, etc.) has enough specificity
 * to override the attribute's default `display: none` and make the raw
 * OS file-picker control show through. Hidden visually rather than with
 * `display: none` so it stays focusable/clickable via its `<label>`.
 */
.wp3dconf-custom-image-upload-input {
	position: absolute !important;
	width: 1px !important;
	height: 1px !important;
	padding: 0 !important;
	margin: -1px !important;
	overflow: hidden !important;
	clip: rect(0, 0, 0, 0) !important;
	white-space: nowrap !important;
	border: 0 !important;
	opacity: 0 !important;
}

.wp3dconf-custom-image-upload-trigger {
	display: flex;
	align-items: center;
	gap: 12px;
	width: 100%;
	box-sizing: border-box;
	padding: 14px 16px;
	background: var(--wp3dconf-bg-item, #F0F3F0);
	border: 1.5px dashed var(--wp3dconf-border-dark, #CDD4CD);
	border-radius: 8px;
	cursor: pointer;
	transition: border-color 0.15s ease, background-color 0.15s ease;
}

.wp3dconf-custom-image-upload-trigger:hover,
.wp3dconf-custom-image-upload-trigger:focus-within,
.wp3dconf-custom-image-upload-trigger.is-dragover {
	border-color: var(--wp3dconf-primary, #5DBF56);
	background: var(--wp3dconf-control-title-bg, #EEF5EE);
}

.wp3dconf-custom-image-upload-actions-row {
	display: none;
	align-items: center;
	align-self: flex-start;
	gap: 12px;
}

.wp3dconf-custom-image-upload[data-has-image='true'] .wp3dconf-custom-image-upload-actions-row {
	display: flex;
}

.wp3dconf-custom-image-upload-replace,
.wp3dconf-custom-image-upload-remove {
	font-size: 12px;
	color: var(--wp3dconf-primary, #5DBF56);
	cursor: pointer;
}

.wp3dconf-custom-image-upload-remove {
	margin: 0;
	padding: 0;
	font-family: inherit;
	background: none;
	border: 0;
	box-shadow: none;
	text-decoration: underline;
}

.wp3dconf-custom-image-upload-replace:hover,
.wp3dconf-custom-image-upload-replace:focus-visible,
.wp3dconf-custom-image-upload-remove:hover,
.wp3dconf-custom-image-upload-remove:focus-visible {
	opacity: 0.8;
}

.wp3dconf-custom-image-upload-thumb {
	display: none;
	flex-shrink: 0;
	width: 40px;
	height: 40px;
	border-radius: 6px;
	background-color: rgba(0, 0, 0, 0.06);
	background-size: cover;
	background-position: center;
}

.wp3dconf-custom-image-upload-thumb[style*='background-image'] {
	display: inline-block;
}

.wp3dconf-custom-image-upload-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	width: 36px;
	height: 36px;
	border-radius: 50%;
	background: var(--wp3dconf-white, #FFFFFF);
	color: var(--wp3dconf-primary, #5DBF56);
	font-size: 18px;
}

.wp3dconf-custom-image-upload-text {
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
}

.wp3dconf-custom-image-upload-label {
	font-weight: 600;
	font-size: 14px;
	color: var(--wp3dconf-text-dark, #1A2B1A);
}

.wp3dconf-custom-image-upload-hint {
	font-size: 12px;
	color: var(--wp3dconf-text-muted, #6B7A6B);
}

.wp3dconf-custom-image-upload-notice {
	margin: 0;
	font-size: 12px;
	color: var(--wp3dconf-text-muted, #6B7A6B);
}

.wp3dconf-custom-image-upload-popup {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: flex;
	align-items: center;
	justify-content: center;
}

.wp3dconf-custom-image-upload-popup[hidden] {
	display: none;
}

.wp3dconf-layer-type-custom-image-upload {
	width: 100%;
}

.wp3dconf-custom-image-upload-close {
	position: absolute;
	top: 10px;
	right: 10px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	margin: 0;
	padding: 0;
	font-family: inherit;
	font-size: 24px;
	line-height: 1;
	color: var(--wp3dconf-text-dark, #1A2B1A);
	background: transparent;
	border: 0;
	border-radius: 50%;
	box-shadow: none;
	cursor: pointer;
}

.wp3dconf-custom-image-upload-close:hover,
.wp3dconf-custom-image-upload-close:focus-visible {
	background: var(--wp3dconf-bg-item, #F0F3F0);
}

.wp3dconf-custom-image-upload-popup-backdrop {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.6);
}

.wp3dconf-custom-image-upload-popup-inner {
	position: relative;
	background: #fff;
	border-radius: 8px;
	padding: 20px;
	display: flex;
	flex-direction: column;
	gap: 16px;
	max-width: calc(100vw - 32px);
	max-height: calc(100vh - 32px);
	overflow: auto;
	box-sizing: border-box;
}

/* Left: preview. Right: controls. Stacks on narrow screens. */
.wp3dconf-custom-image-upload-columns {
	display: grid;
	grid-template-columns: minmax(0, 400px) minmax(240px, 300px);
	gap: 24px;
	align-items: start;
}

.wp3dconf-custom-image-upload-preview-col,
.wp3dconf-custom-image-upload-controls-col {
	display: flex;
	flex-direction: column;
	gap: 16px;
	min-width: 0;
}

@media (max-width: 720px) {
	.wp3dconf-custom-image-upload-columns {
		grid-template-columns: minmax(0, 1fr);
	}
}

.wp3dconf-custom-image-upload-popup-title {
	margin: 0;
	padding-right: 40px;
}

.wp3dconf-custom-image-upload-canvas-wrap {
	display: flex;
	justify-content: center;
}

.wp3dconf-custom-image-upload-canvas {
	max-width: 100%;
	height: auto;
	touch-action: none;
	cursor: grab;
	border: 1px solid rgba(0, 0, 0, 0.1);
}

.wp3dconf-custom-image-upload-canvas:active {
	cursor: grabbing;
}

.wp3dconf-custom-image-upload-error {
	margin: 0;
	padding: 8px 12px;
	border-radius: 4px;
	background: #fdecea;
	color: #611a15;
	font-size: 13px;
}

.wp3dconf-custom-image-upload-error[hidden] {
	display: none;
}

.wp3dconf-custom-image-upload-controls {
	display: flex;
	flex-direction: column;
	gap: 16px;
}

.wp3dconf-custom-image-upload-control {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.wp3dconf-custom-image-upload-control > label,
.wp3dconf-custom-image-upload-control-label {
	font-size: 13px;
	font-weight: 600;
}

.wp3dconf-custom-image-upload-control-row {
	display: flex;
	align-items: center;
	gap: 12px;
}

.wp3dconf-custom-image-upload-controls input[type='range'] {
	flex: 1;
	min-width: 0;
}

.wp3dconf-custom-image-upload-number {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	flex-shrink: 0;
	font-size: 13px;
}

.wp3dconf-custom-image-upload-controls input[type='number'] {
	box-sizing: border-box;
	width: 72px;
	height: 32px;
	margin: 0;
	padding: 0 6px;
	font-size: 13px;
	text-align: right;
	border: 1px solid var(--wp3dconf-border-dark, #CDD4CD);
	border-radius: 4px;
}

.wp3dconf-custom-image-upload-align {
	display: flex;
	gap: 6px;
}

/*
 * Sizing and colour are stated rather than inherited: a bare <button>
 * picks up whatever a customer theme applies to buttons.
 */
.wp3dconf-custom-image-upload-align-btn {
	flex: 1;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	height: 36px;
	margin: 0;
	padding: 0;
	font-family: inherit;
	font-size: 18px;
	line-height: 1;
	color: var(--wp3dconf-text-dark, #1A2B1A);
	background: var(--wp3dconf-bg-item, #F0F3F0);
	border: 1px solid var(--wp3dconf-border-dark, #CDD4CD);
	border-radius: 6px;
	box-shadow: none;
	cursor: pointer;
	transition: border-color 0.15s ease, background-color 0.15s ease;
}

.wp3dconf-custom-image-upload-align-btn:hover,
.wp3dconf-custom-image-upload-align-btn:focus-visible {
	border-color: var(--wp3dconf-primary, #5DBF56);
}

.wp3dconf-custom-image-upload-align-btn[aria-pressed='true'] {
	color: var(--wp3dconf-white, #FFFFFF);
	background: var(--wp3dconf-primary, #5DBF56);
	border-color: var(--wp3dconf-primary, #5DBF56);
}

.wp3dconf-custom-image-upload-actions {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
	margin-top: 16px;
}

.wp3dconf-custom-image-upload-actions button {
	border-radius: 8px;
}

/*
 * Advisory, not a failure - amber rather than the error banner's red, so a
 * shopper who has simply zoomed past the edge isn't told something broke.
 */
.wp3dconf-custom-image-upload-warning {
	margin: 0;
	padding: 8px 12px;
	border-radius: 4px;
	background: #fff8e1;
	color: #6b4e00;
	font-size: 13px;
}

.wp3dconf-custom-image-upload-warning[hidden] {
	display: none;
}

/*
 * Auto-fit sits in the same row as Cancel/Apply but is a tertiary action -
 * pushed to the far left, away from the two the shopper is choosing
 * between, so it reads as a reset rather than a third way out of the popup.
 */
.wp3dconf-custom-image-upload-autofit {
	margin-right: auto;
}

/*
 * Help toggle and its panel.
 *
 * Visibility is Alpine's (`x-show`, see templates/layer/layer-custom-image-upload.php),
 * so nothing here sets `display` on the panel. The template carries the
 * initial inline `display: none`; adding a `display` rule for the closed
 * state would fight `x-show`, which restores an element by clearing the
 * inline value and would then fall through to whatever CSS said.
 *
 * The wrapper exists so the panel sits directly under its button in normal
 * flow. It is not a positioning context for an absolutely positioned
 * popover: the control is a flex column, and an absolutely positioned child
 * of a flex container takes its static position from the container's content
 * box rather than its place in source order, which put an earlier version of
 * this panel over the upload trigger.
 */
.wp3dconf-custom-image-upload-help-wrap {
	display: flex;
	flex-direction: column;
	gap: 8px;
	align-items: flex-start;
	width: 100%;
}

.wp3dconf-custom-image-upload-help {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	box-shadow: none;
	/*
	 * Typography is stated rather than inherited. A bare <button> picks up
	 * whatever a customer theme applies to buttons - heading-sized type, a
	 * background, letter-spacing - and this is a quiet secondary control.
	 */
	font-family: inherit;
	font-size: 12px;
	font-weight: 400;
	line-height: 1.4;
	text-transform: none;
	color: var(--wp3dconf-primary, #5DBF56);
	border-bottom: 1px solid;
	cursor: pointer;
}

.wp3dconf-custom-image-upload-help:hover,
.wp3dconf-custom-image-upload-help:focus-visible {
	opacity: 0.8;
}

/*
 * Keep the glyph beside the label; a theme setting `span { display: block }`
 * would otherwise stack them.
 */
.wp3dconf-custom-image-upload-help > span {
	display: inline-block;
	font-size: inherit;
	line-height: 1;
}

.wp3dconf-custom-image-upload-guide {
	box-sizing: border-box;
	width: 100%;
	padding: 12px;
	border: 1px solid var(--wp3dconf-border-dark, #CDD4CD);
	border-radius: 8px;
	background: var(--wp3dconf-bg-item, #F0F3F0);
	font-size: 13px;
	line-height: 1.5;
}

.wp3dconf-custom-image-upload-guide-preview {
	margin: 0 0 10px;
}

/*
 * The checkerboard lives here, not in the image's pixels. Drawing it onto
 * the canvas baked it into the PNG, so a shopper who saved the preview as a
 * starting template got a grey grid printed through their file and none of
 * the transparency it was there to demonstrate.
 *
 * The image itself is rendered at the print zone's own resolution (see
 * buildZonePreview()); this only scales it down for the panel.
 */
.wp3dconf-custom-image-upload-guide-image {
	display: block;
	width: 160px;
	max-width: 100%;
	height: auto;
	border: 1.5px dashed var(--wp3dconf-border-dark, #CDD4CD);
	border-radius: 4px;
	background-color: #ffffff;
	background-image:
		linear-gradient(45deg, #e0e0e0 25%, transparent 25%),
		linear-gradient(-45deg, #e0e0e0 25%, transparent 25%),
		linear-gradient(45deg, transparent 75%, #e0e0e0 75%),
		linear-gradient(-45deg, transparent 75%, #e0e0e0 75%);
	background-size: 16px 16px;
	background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.wp3dconf-custom-image-upload-guide-caption {
	margin: 6px 0 0;
	font-size: 12px;
	opacity: 0.75;
}

.wp3dconf-custom-image-upload-guide-notes {
	/* Line breaks arrive as <br> from nl2br() in the template, so no
	   white-space: pre-line here - the two together would double-space. */
	margin: 0;
}

.wp3dconf-custom-image-upload-guide-size {
	margin: 8px 0 0;
	font-size: 12px;
	opacity: 0.75;
}

/*
 * `style` is not on the kses allowlist for <p> (only <div> carries it), so
 * these two can't be hidden inline the way the preview container is. They
 * are empty until the script fills them - the notes with fallback advice,
 * the size line once the model has been measured - and :empty collapses
 * them until then, with no attribute to be stripped.
 */
.wp3dconf-custom-image-upload-guide-notes:empty,
.wp3dconf-custom-image-upload-guide-size:empty {
	display: none;
}
