// ==========================================================================
// Per-link UTM Builder — redesigned card (matches the bl-* design system used
// on the Manage Links board). Rendered inside the shared react-modal opened
// from the link drawer. Pro replaces the component but reuses these classes,
// so keep the two in sync (betterlinks-pro/assets/scss/components/_utm-builder-pro.scss).
// ==========================================================================
$blu: var(--bl-m-accent, #2f6bff);
$blu-dark: var(--bl-m-accent-hover, #1f57e6);
$brd: var(--bl-m-border, #e6e8ee);
$ttl: var(--bl-m-text, #1a2233);
$mut: var(--bl-m-muted, #6b7280);
$foot-bg: var(--bl-m-surface-2, #f7f8fa);
$err: var(--bl-m-danger, #ef4444);

// Strip the react-modal's default chrome (20px padding, thin border, 4px radius)
// only for the modal instance that actually contains this card, and hide the
// legacy top-right close button — this card ships its own header + close.
.ReactModal__Content:has(.bl-utm) {
	padding: 0 !important;
	border: none !important;
	border-radius: 16px !important;
	overflow: visible !important;
	background: #fff !important;
	width: 520px !important;
	max-width: calc(100vw - 40px) !important;

	> .btl-close-modal {
		display: none !important;
	}
}

.bl-utm {
	* {
		box-sizing: border-box;
	}

	display: flex;
	flex-direction: column;
	max-height: calc(100vh - 80px);
	overflow: hidden;
	background: var(--bl-m-surface);
	border-radius: 16px;
	color: $ttl;
	font-family: inherit;
	text-align: left;

	// ---- Header ----------------------------------------------------------
	&__header {
		flex: none;
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: 12px;
		padding: 20px 22px;
		border-bottom: 1px solid $brd;
	}
	&__heading {
		display: flex;
		align-items: center;
		gap: 12px;

		.btl-tooltip {
			display: inline-flex;
			color: $mut;

			// The heading sits flush against the top of the modal, so the shared
			// tooltip's default upward position (bottom: 150%) overflows above the
			// modal and gets clipped. Flip it to drop BELOW the info icon instead,
			// and lift it above the modal chrome.
			.btl-tooltiptext {
				bottom: auto;
				top: calc(100% + 10px);
				z-index: 5;

				&::after {
					top: auto;
					bottom: 100%;
					border-color: transparent transparent #2961ff transparent;
				}
			}
		}
	}
	&__badge {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		width: 38px;
		height: 38px;
		border-radius: 10px;
		background: var(--bl-m-accent-soft);
		color: $blu;

		svg {
			display: block;
		}
	}
	&__title {
		margin: 0;
		font-size: 20px;
		font-weight: 700;
		line-height: 1.2;
		color: $ttl;
	}
	&__close {
		flex: none;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		width: 36px;
		height: 36px;
		padding: 0;
		border: 1px solid $brd;
		border-radius: 9px;
		background: var(--bl-m-input-bg);
		color: $mut;
		cursor: pointer;
		transition: all 0.15s ease;

		&:hover {
			color: $ttl;
			background: $foot-bg;
			border-color: var(--bl-m-muted);
		}
		svg {
			display: block;
		}
	}

	// ---- Body ------------------------------------------------------------
	&__body {
		flex: 1 1 auto;
		min-height: 0;
		overflow-y: auto;
		padding: 20px 22px;
		display: flex;
		flex-direction: column;
		gap: 16px;

		scrollbar-width: thin;
		scrollbar-color: var(--bl-m-scroll) transparent;
		&::-webkit-scrollbar {
			width: 6px;
		}
		&::-webkit-scrollbar-thumb {
			background: var(--bl-m-scroll);
			border-radius: 10px;
		}
	}

	&__field {
		display: flex;
		flex-direction: column;
		gap: 8px;

		> label {
			font-size: 14px;
			font-weight: 700;
			color: $ttl;
		}
	}

	&__input {
		width: 100%;
		height: 46px;
		padding: 0 14px;
		border: 1px solid $brd;
		border-radius: 10px;
		background: var(--bl-m-input-bg);
		font-size: 14px;
		font-weight: 500;
		color: $ttl;
		outline: none;
		transition: border-color 0.15s ease, box-shadow 0.15s ease;

		&::placeholder {
			color: var(--bl-m-placeholder);
			font-weight: 400;
		}
		&:focus {
			border-color: $blu;
			box-shadow: 0 0 0 3px var(--bl-m-accent-ring);
		}
		&.is-error {
			border-color: $err;
			box-shadow: 0 0 0 3px var(--bl-m-danger-ring);
		}
	}

	// Locked template picker (free) — looks like the Pro select, opens the
	// upgrade modal instead of a dropdown.
	&__locked-select {
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: 10px;
		width: 100%;
		height: 46px;
		padding: 0 14px;
		border: 1px solid $brd;
		border-radius: 10px;
		background: var(--bl-m-input-bg);
		font-size: 14px;
		font-weight: 500;
		color: $mut;
		cursor: pointer;
		transition: all 0.15s ease;

		&:hover {
			border-color: var(--bl-m-accent-border);
			color: $ttl;
		}
		img {
			flex: none;
			width: 16px;
			height: 16px;
		}
	}

	// Pro template select. Pro's UTMBuilderPro reuses this shared `.bl-utm`
	// design system, so the real `<select>` (+ custom caret + delete button)
	// must be styled here in the free plugin's always-loaded stylesheet — Pro's
	// own CSS may not be present on every page the UTM builder opens from.
	&__template-row {
		display: flex;
		align-items: center;
		gap: 10px;
	}
	&__select {
		position: relative;
		flex: 1;
		min-width: 0;
		display: flex;
		align-items: center;

		select {
			width: 100%;
			max-width: unset;
			height: 46px;
			margin: 0;
			padding: 0 40px 0 14px;
			border: 1px solid $brd;
			border-radius: 10px;
			background: var(--bl-m-input-bg);
			font-size: 14px;
			font-weight: 500;
			color: $ttl;
			line-height: 44px;
			cursor: pointer;
			outline: none;
			appearance: none;
			-webkit-appearance: none;
			-moz-appearance: none;

			&:focus {
				border-color: $blu;
				box-shadow: 0 0 0 3px var(--bl-m-accent-ring);
			}
		}
	}
	&__caret {
		position: absolute;
		right: 14px;
		top: 50%;
		transform: translateY(-50%);
		color: $mut;
		pointer-events: none;
	}
	&__template-delete {
		flex: none;

		button {
			display: inline-flex;
			align-items: center;
			justify-content: center;
			width: 44px;
			height: 46px;
			padding: 0;
			border: 1px solid $brd;
			border-radius: 10px;
			background: var(--bl-m-input-bg);
			color: $mut;
			cursor: pointer;
			transition: all 0.15s ease;

			&:hover {
				color: $err;
				border-color: var(--bl-m-danger-border);
				background: var(--bl-m-danger-soft);
			}
			.dashicons {
				font-size: 18px;
				width: 18px;
				height: 18px;
				line-height: 18px;
			}
		}
	}
	// Save-new-template row (Pro footer) — same input + inline buttons.
	&__template-save {
		display: flex;
		align-items: center;
		gap: 10px;
		flex: 1 1 auto;

		.bl-utm__input {
			flex: 1 1 auto;
			min-width: 160px;
		}
	}

	// ---- Footer ----------------------------------------------------------
	&__footer {
		flex: none;
		display: flex;
		flex-direction: column;
		gap: 10px;
		padding: 16px 22px;
		border-top: 1px solid $brd;
		background: $foot-bg;
		border-radius: 0 0 16px 16px;
	}
	&__actions {
		display: flex;
		align-items: center;
		flex-wrap: wrap;
		gap: 12px;
		justify-content: center;
	}

	&__btn {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		gap: 8px;
		height: 46px;
		padding: 0 20px;
		border: 1px solid transparent;
		border-radius: 10px;
		font-size: 14px;
		font-weight: 600;
		white-space: nowrap;
		cursor: pointer;
		transition: all 0.15s ease;

		svg {
			display: block;
		}
		img {
			width: 14px;
			height: 14px;
		}

		&--primary {
			background: $blu;
			border-color: $blu;
			color: #fff;
			box-shadow: 0 6px 16px var(--bl-m-accent-shadow);

			&:hover {
				background: $blu-dark;
				border-color: $blu-dark;
			}
		}
		&--ghost {
			background: var(--bl-m-input-bg);
			border-color: $brd;
			color: $ttl;

			&:hover {
				color: $blu;
				border-color: var(--bl-m-accent-border);
			}
		}
	}
}
