/*
 * Site Toolkit: Elementor extras, styled file upload field of Elementor Pro forms.
 * Pro's own <input type="file"> stays in the page, visually hidden but focusable (keyboard and screen readers); the
 * <label class="stk-upload__btn"> is the button. Colours, radius and font size are CSS variables (defaults = the look of the
 * theme code this replaces): --stk-upload-color, --stk-upload-bg, --stk-upload-hover, --stk-upload-hover-color,
 * --stk-upload-ring, --stk-upload-error, --stk-upload-radius, --stk-upload-size, --stk-upload-padding, --stk-upload-mt,
 * --stk-upload-mb, --stk-upload-weight, --stk-upload-icon.
 *
 * Contrast check (WCAG 2.2 AA, text needs 4.5:1, focus ring 3:1):
 *   default  #1F2C43 on #FFFFFF             = 14.6:1
 *   hover    #FFFFFF on #C8202B (default)   =  5.7:1
 *   the owner's red #F4343F as hover background: #1F2C43 on it is only 3.6:1 and white 3.9:1, so it passes with black
 *   text (5.4:1); the settings page output picks such a text colour automatically (--stk-upload-hover-color).
 *   #F4343F is kept for the focus ring (against white 3.9:1, as a non-text indicator it needs 3:1).
 *   error #B32D2E on white = 6.3:1 (change --stk-upload-error on dark backgrounds).
 */

/* Before the script runs (button printed by the server) and after (class added by the script). */
.elementor-field-group:has(> .stk-upload__btn) {
	position: relative;
}

.elementor-field-group:has(> .stk-upload__btn) > input[type="file"] {
	position: absolute !important;
	width: 1px !important;
	height: 1px !important;
	margin: -1px !important;
	padding: 0 !important;
	border: 0 !important;
	overflow: hidden !important;
	clip: rect(0 0 0 0) !important;
	clip-path: inset(50%) !important;
	white-space: nowrap !important;
}

.elementor-field-group.stk-upload {
	position: relative;
}

.elementor-field-group.stk-upload > input[type="file"] {
	position: absolute !important;
	width: 1px !important;
	height: 1px !important;
	margin: -1px !important;
	padding: 0 !important;
	border: 0 !important;
	overflow: hidden !important;
	clip: rect(0 0 0 0) !important;
	clip-path: inset(50%) !important;
	white-space: nowrap !important;
}

.elementor-field-group > .stk-upload__btn,
.stk-upload__btn {
	display: inline-block;
	box-sizing: border-box;
	margin: var(--stk-upload-mt, 0) 0 var(--stk-upload-mb, 0);
	margin-inline-end: 15px;
	/* !important: Pro's "Label spacing" (body .elementor-labels-above .elementor-field-group > label) sets padding on every label. */
	padding: var(--stk-upload-padding, 0.525rem 1.05rem) !important;
	border: 1px solid transparent; /* forced-colors mode draws it, so the button keeps its shape */
	border-radius: var(--stk-upload-radius, 4px);
	background: var(--stk-upload-bg, #fff);
	color: var(--stk-upload-color, #1f2c43);
	font-size: var(--stk-upload-size, 0.8em);
	font-weight: var(--stk-upload-weight, 800);
	line-height: 1.4;
	text-align: center;
	cursor: pointer;
	user-select: none;
	transition: background-color 0.2s ease;
}

.stk-upload__btn.is-drag,
.stk-upload > input[type="file"]:focus-visible + .stk-upload__btn,
.elementor-field-group > input[type="file"]:focus-visible + .stk-upload__btn {
	background: var(--stk-upload-hover, #c8202b);
	color: var(--stk-upload-hover-color, #fff);
}

@media (hover: hover) {
	.stk-upload__btn:hover {
		background: var(--stk-upload-hover, #c8202b);
		color: var(--stk-upload-hover-color, #fff);
	}
}

.stk-upload > input[type="file"]:focus-visible + .stk-upload__btn,
.elementor-field-group > input[type="file"]:focus-visible + .stk-upload__btn {
	outline: 2px solid var(--stk-upload-ring, #f4343f);
	outline-offset: 2px;
}

.stk-upload__btn.is-drag {
	outline: 2px dashed currentcolor;
	outline-offset: 2px;
}

.stk-upload__icon {
	display: inline-block;
	margin-inline-start: 0.6em;
	vertical-align: -0.125em;
	color: var(--stk-upload-icon, inherit);
}

/* On the hover / focus / drag background the icon takes the readable text colour, like the label. */
.stk-upload__btn.is-drag .stk-upload__icon,
.stk-upload > input[type="file"]:focus-visible + .stk-upload__btn .stk-upload__icon,
.elementor-field-group > input[type="file"]:focus-visible + .stk-upload__btn .stk-upload__icon {
	color: inherit;
}

@media (hover: hover) {
	.stk-upload__btn:hover .stk-upload__icon {
		color: inherit;
	}
}

.stk-upload__panel {
	flex: 0 0 100%;
	box-sizing: border-box;
	width: 100%;
	max-width: 100%;
	margin-top: 0.6em;
	font-size: 0.875em;
	line-height: 1.4;
	text-align: start;
}

.stk-upload [hidden] {
	display: none !important;
}

.stk-upload__count {
	margin: 0 0 0.25em;
	font-weight: 600;
}

.stk-upload__list {
	margin: 0;
	padding: 0;
	list-style: none;
}

.stk-upload__item {
	display: flex;
	flex-wrap: wrap;
	gap: 0.15em 0.6em;
	align-items: center;
	margin: 0;
	padding: 0.15em 0;
}

.stk-upload__name {
	flex: 0 1 auto;
	min-width: 0;
	overflow-wrap: anywhere;
}

.stk-upload__size {
	opacity: 0.75;
	white-space: nowrap;
}

.elementor-field-group.stk-upload button.stk-upload__remove,
.elementor-field-group.stk-upload button.stk-upload__clear {
	all: unset;
	box-sizing: border-box;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 24px;
	min-height: 24px;
	border-radius: 3px;
	color: inherit;
	font: inherit;
	cursor: pointer;
}

.elementor-field-group.stk-upload button.stk-upload__remove {
	padding: 0 0.4em;
	font-size: 1.25em;
	line-height: 1.2;
}

.elementor-field-group.stk-upload button.stk-upload__clear {
	margin-top: 0.35em;
	padding: 0 0.25em;
	text-decoration: underline;
}

@media (hover: hover) {
	.elementor-field-group.stk-upload button.stk-upload__remove:hover,
	.elementor-field-group.stk-upload button.stk-upload__clear:hover {
		background: rgba(128, 128, 128, 0.2);
	}
}

.elementor-field-group.stk-upload button.stk-upload__remove:focus-visible,
.elementor-field-group.stk-upload button.stk-upload__clear:focus-visible {
	outline: 2px solid currentcolor;
	outline-offset: 2px;
}

.stk-upload__errors {
	margin: 0.35em 0 0;
}

.stk-upload__error {
	margin: 0.15em 0 0;
	color: var(--stk-upload-error, #b32d2e);
	font-weight: 600;
}

.stk-upload__sr {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	border: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
}

/*
 * Tiles (the default look, built after waterboy.ee): a link-style button and the chosen files as small tiles with a
 * thumbnail (images) or a document icon with the extension, a round remove button on the corner and the name cut to the
 * tile width. Colours come from the text colour of the form (currentColor), so the same look works on light and dark
 * forms; settings (the CSS variables) still win where they are set.
 */
.elementor-field-group > .stk-upload__btn.stk-upload__btn--tiles {
	margin-top: var(--stk-upload-mt, 10px);
	padding: var(--stk-upload-padding, 1px) !important;
	border-radius: var(--stk-upload-radius, 0);
	background: var(--stk-upload-bg, transparent);
	color: var(--stk-upload-color, inherit);
	font-weight: var(--stk-upload-weight, 500);
	text-underline-offset: 3px;
	transition: opacity 0.15s ease;
}

.stk-upload__btn--tiles .stk-upload__icon {
	color: var(--stk-upload-icon, var(--e-global-color-accent, currentcolor));
}

.stk-upload__btn--tiles.is-drag,
.elementor-field-group > input[type="file"]:focus-visible + .stk-upload__btn--tiles {
	background: var(--stk-upload-hover, transparent);
	color: var(--stk-upload-hover-color, var(--stk-upload-color, inherit));
	text-decoration: underline;
}

@media (hover: hover) {
	.elementor-field-group > .stk-upload__btn.stk-upload__btn--tiles:hover {
		background: var(--stk-upload-hover, transparent);
		color: var(--stk-upload-hover-color, var(--stk-upload-color, inherit));
		text-decoration: none;
		opacity: 0.5;
	}

	.stk-upload__btn--tiles:hover .stk-upload__icon {
		color: var(--stk-upload-icon, var(--e-global-color-accent, currentcolor));
	}
}

.stk-upload__btn--tiles.is-drag .stk-upload__icon,
.elementor-field-group > input[type="file"]:focus-visible + .stk-upload__btn--tiles .stk-upload__icon {
	color: var(--stk-upload-icon, var(--e-global-color-accent, currentcolor));
}

.stk-upload--tiles .stk-upload__panel {
	margin-top: 14px;
}

/* The count stays for screen readers; "Clear all" is not part of this look (each tile has its own remove button). */
.stk-upload--tiles .stk-upload__count {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	border: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
}

.elementor-field-group.stk-upload--tiles button.stk-upload__clear {
	display: none;
}

.stk-upload--tiles .stk-upload__list {
	display: flex;
	flex-wrap: wrap;
	gap: 22px;
	padding: 6px 6px 0 0;
}

.stk-upload--tiles .stk-upload__list[hidden] {
	display: none !important;
}

.stk-upload--tiles .stk-upload__item {
	display: flex;
	flex-direction: column;
	gap: 4px;
	width: 59px;
	padding: 0;
}

.stk-upload--tiles .stk-upload__thumb {
	position: relative;
	display: flex;
	flex-direction: column;
	gap: 4px;
	align-items: center;
	justify-content: center;
	width: 59px;
	height: 59px;
	border-radius: 4px;
	background: color-mix(in srgb, currentcolor 10%, transparent);
	box-shadow: inset 0 0 0 1px color-mix(in srgb, currentcolor 16%, transparent);
}

/* Themes size every img (height:auto, max-width): the thumbnail is forced to cover its square, centred. */
.stk-upload--tiles .stk-upload__thumb .stk-upload__img {
	display: block;
	width: 100% !important;
	height: 100% !important;
	max-width: none !important;
	margin: 0 !important;
	border-radius: 4px;
	object-fit: cover;
	object-position: center;
}

.stk-upload--tiles .stk-upload__doc {
	width: 20px;
	height: 20px;
	opacity: 0.85;
}

.stk-upload--tiles .stk-upload__ext {
	max-width: 50px;
	overflow: hidden;
	font-size: 9px;
	font-weight: 600;
	letter-spacing: 0.04em;
	line-height: 1;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.stk-upload--tiles .stk-upload__name {
	display: block;
	max-width: 59px;
	overflow: hidden;
	font-size: 11px;
	line-height: 1.3;
	opacity: 0.8;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.elementor-field-group.stk-upload--tiles button.stk-upload__remove {
	position: absolute;
	top: -6px;
	right: -6px;
	width: 18px;
	min-width: 0;
	height: 18px;
	min-height: 0;
	padding: 0;
	border-radius: 50%;
	background: #fff;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
	color: #131a2b;
	line-height: 1;
}

/* A 28 px target around the 18 px circle (WCAG 2.2 target size). */
.elementor-field-group.stk-upload--tiles button.stk-upload__remove::after {
	content: "";
	position: absolute;
	inset: -5px;
}

.elementor-field-group.stk-upload--tiles button.stk-upload__remove svg {
	display: block;
	width: 8px;
	height: 8px;
}

@media (hover: hover) {
	.elementor-field-group.stk-upload--tiles button.stk-upload__remove:hover {
		background: #fff;
		transform: scale(1.08);
	}
}

@media (prefers-reduced-motion: reduce) {
	.stk-upload__btn {
		transition: none;
	}
}

@media (forced-colors: active) {
	.stk-upload__btn {
		border: 1px solid ButtonText;
		background: ButtonFace;
		color: ButtonText;
	}

	.stk-upload__btn:hover,
	.stk-upload__btn.is-drag {
		background: Highlight;
		color: HighlightText;
	}
}
