@use '../scss/_variables' as *;

.adpresso-token-select {
	position: relative;
	font-size: 1.3em;

	// --- Control (Input + Chips Wrapper) ---
	&__control {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		gap: 0.5em;
		padding: 0.5em 1em;
		min-height: 4em;
		border: 0.12em solid $color-text-grey;
		border-radius: 0.4em;
		cursor: text;
		transition: border-color 0.2s ease, box-shadow 0.2s ease;
		background-color: $color-white;

		&.adpresso-color-inactive {
			background-color: $color-white;
		}

		&:hover {
			border-color: $color-text-active;
		}
	}

	&.is-open .adpresso-token-select__control {
		border-color: $color-primary;
		box-shadow: 0 0 0 1px $color-primary;
	}

	// --- Chip / Token ---
	&__token {
		display: inline-flex;
		align-items: center;
		background-color: $color-primary;
		border-radius: $radius-md;
		gap: $space-2;
		padding: $space-1 $space-3;
		font-weight: 500;
		color: $color-white;
	}

	&__remove {
		background-color: rgba($color-white, 0.2);
		border: none;
		color: $color-white;
		border-radius: 50%;
		cursor: pointer;
		font-size: 0.8em;
		line-height: 1;
		padding: 0;
		margin-left: 0.4em;
		width: 1.5em;
		height: 1.5em;
		display: flex;
		align-items: center;
		justify-content: center;

		&:hover {
			background-color: rgba($color-white, 0.4);
		}
	}

	// --- Input Field ---
	&__input {
		flex: 1;
		min-width: 60px;
		border: none !important;
		box-shadow: none !important;
		padding: 4px 0 !important;
		margin: 2px 0 !important;
		background: transparent;
		font-size: inherit;
		line-height: inherit;

		&:focus {
			outline: none;
		}
	}

	// --- Single Value ---
	&__single-value {
		flex: 1;
		color: $color-text;
		margin-left: 2px;
	}

	&__clear {
		float: right;
		background: none;
		border: none;
		color: $color-text-grey;
		cursor: pointer;
		font-size: 18px;
		&:hover {
			color: $color-text-active;
		}
	}

	// --- Dropdown Menu ---
	&__menu {
		position: absolute;
		top: 100%;
		left: 0;
		width: 100%;
		max-height: 500px;
		overflow-y: auto;
		background: $color-white;
		border: 1px solid $color-border;
		border-top: none;
		border-radius: 0 0 4px 4px;
		box-shadow: 0 4px 6px rgba(0,0,0,0.1);
		z-index: 1000;
		margin: 0;
		list-style: none;
	}

	&__option {
		padding: 8px 12px;
		cursor: pointer;

		&:hover {
			background-color: $color-divider;
			color: $color-primary;
		}
	}

	&__group {
		padding: 0;
	}

	&__group-label {
		padding: 8px 12px;
		font-weight: 600;
		color: $color-text-active;
		font-size: 12px;
		text-transform: uppercase;
		background-color: $color-divider;
		border-bottom: 1px solid $color-divider;
		border-top: 1px solid $color-divider;
	}

	&__group:first-child &__group-label {
		border-top: none;
	}

	&__group-options {
		list-style: none;
		margin: 0;
		padding: 0;
	}

	.is-loading, .is-empty {
		padding: 12px;
		text-align: center;
		color: $color-text-grey;
		font-style: italic;
	}
}

.adpresso-token-select__popover-content {
	.adpresso-token-select {
		&__menu {
			position: relative;
			min-width: 300px;
		}
	}
}
