// Base form field styling
@mixin form-control {
	box-shadow: inset 2px 1px 2px 0 rgba($color-black, .08), inset -2px 0px 2px 0 rgba($color-black, .08);
	font-size: 16px;
	line-height: 19px;
	margin: 0 0 15px;
	padding: 15px;
	position: relative;

	&:focus {
		border: 1px solid $color-charcoal2;
		box-shadow: none;
	}
}

.form-control {
	@include form-control;
}

// Standard inputs
.input-group {
	border: 1px solid $color-charcoal1;
	border-radius: 4px;
	margin-bottom: 15px;

	& > * {
		&:first-child {
			border-radius: 3px 0 0 3px;
			box-shadow: inset 2px 1px 2px 0 rgba($color-black, .08);
		}

		&:last-child {
			border-radius: 0 3px 3px 0;
			box-shadow: inset -2px 1px 2px 0 rgba($color-black, .08);
		}
	}

	.form-control {
		border: 0;
	}

	&-addon {
		background-color: $color-white;
		border: 0;
		color: $color-charcoal1;
		font-size: 20px;
	}

	&:focus-within {
		border: 1px solid $color-charcoal2;

		* {
			box-shadow: none;
		}
	}

	&--inline-btn {
		border: 0;

		&:focus-within {
			border: 0;
		}

		.form-control {
			border-width: 1px 0 1px 1px;
			border-color: $color-charcoal1;
			border-style: solid;

			&:focus {
				border-color: $color-charcoal2;
			}
		}

		.input-group-btn {
			.btn {
				border-radius: 0 4px 4px 0;
				margin: 0;
				padding-left: 15px;
				padding-right: 15px;
			}
		}
	}
}

.radio {
	margin-top: 0;

	&.form-control {
		box-shadow: none;
		height: auto;
		min-height: 48px;
		padding: 0;
	}

	label {
		line-height: 21px;
		padding: 15px 15px 15px 40px;
		width: 100%;

		input {
			&[type='radio'] {
				left: 15px;
				position: absolute;
				top: 10px;
				opacity: 0;

				+ span {
					background-color: $color-white;
					border: 1px solid $color-charcoal1;
					border-radius: 15px;
					box-shadow: inset 0 1px 3px 0 rgba($color-black, .1);
					display: block;
					height: 20px;
					left: 13px;
					position: absolute;
					top: 16px;
					width: 20px;
					z-index: 2;

					&::after {
						background: $color-white;
						border-radius: 9px;
						content: '';
						display: block;
						height: 10px;
						left: 4px;
						opacity: 0;
						position: absolute;
						top: 4px;
						transition: opacity $trans-time $trans-func;
						width: 10px;
						z-index: 3;
					}
				}

				&:checked {
					+ span {
						background-color: $color-blue5;
						border: 1px solid $color-blue5;

						&::after {
							opacity: 1;
						}
					}
				}
			}
		}
	}
}

.radio-colored {
	input {
		position: absolute;
		visibility: hidden;

		&:checked {
			~ span {
				border: 1px solid transparent;

				&::before {
					background: $color-blue8;
				}
			}

			~ label {
				@include font-primary-bold;
				background-color: $color-blue5;
				border-color: $color-blue5;
				box-shadow: inset 0 0 5px 0 rgba($color-black, .25);
				color: $color-white;
			}
		}
	}

	label {
		background-color: $color-charcoal1;
		border: 1px solid $color-ivory6;
		border-radius: 5px;
		cursor: pointer;
		display: block;
		font-size: 16px;
		font-weight: 500;
		line-height: 30px;
		margin: 10px auto;
		padding: 10px 25px 10px 60px;
		position: relative;
		transition: all .15s linear;
		white-space: nowrap;

		&:hover {
			background-color: $color-ivory7;
			color: $color-white;
		}
	}

	span {
		background-color: $color-white;
		border: 1px solid $color-charcoal2;
		border-radius: 100%;
		cursor: pointer;
		display: block;
		height: 16px;
		pointer-events: none;
		position: absolute;
		transform: translate(28px, -44px);
		transition: border $trans-func $trans-time;
		width: 16px;

		&::before {
			border-radius: 100%;
			content: '';
			display: block;
			height: 12px;
			margin: auto;
			position: absolute;
			transform: translate(1px, 1px);
			transition: background $trans-func $trans-time;
			width: 12px;
		}
	}
}

.radio-with-check {
	display: block;
	margin-bottom: 15px;
	padding: 15px;
	position: relative;
	text-align: center;

	label {
		@include font-primary-regular;
		line-height: 19px;
		margin-bottom: 0;
		padding: 0 15px;
	}

	&:hover {
		input {
			+ .icon {
				+ span {
					border-color: $color-blue5;
				}
			}
		}
	}

	input {
		left: 0;
		opacity: 0;
		position: absolute;
		top: 0;

		+ .icon {
			color: $color-blue5;
			font-size: 16px;
			line-height: 16px;
			opacity: 0;
			position: absolute;
			right: 15px;
			top: 50%;
			transform: translateY(-50%);
			transition: opacity $trans-func $trans-time;

			+ span {
				border: 2px solid rgba($color-black, .1);
				border-radius: 4px;
				bottom: 0;
				display: block;
				left: 0;
				position: absolute;
				right: 0;
				top: 0;
				transition: border-color $trans-func $trans-time;
				z-index: 2;
			}
		}

		&:checked {
			+ .icon {
				opacity: 1;

				+ span {
					border-color: $color-blue5;
				}
			}
		}
	}
}

.radio-btn-group {
	border: 1px solid $color-charcoal1;
	border-radius: 3px;
	box-shadow: 0 2px 4px 0 rgba($color-black, .1);
	display: block;
	margin: 0;
	overflow: auto;

	&__btn {
		float: left;
		width: 20%;

		& + .radio-btn-group__btn {
			border-left: 1px solid $color-charcoal1;
		}
	}

	label {
		@include font-primary-regular;
		align-items: center;
		color: $color-charcoal3;
		cursor: pointer;
		display: flex;
		font-size: 14px;
		height: 70px;
		justify-content: center;
		margin: 0;
		padding: 20px 5px;
		position: relative;
		text-align: center;
		transition: all .15s linear;
		white-space: nowrap;
		width: 100%;

		&:hover {
			background-color: $color-ivory2;
			color: $color-charcoal5;
		}

		&:active {
			background-color: $color-blue6;
		}
	}

	input {
		position: absolute;
		visibility: hidden;

		& + span {
			position: absolute;
			top: 0;
			left: 0;
			height: 100%;
			width: 100%;
			z-index: -1;
			padding: 25% 0;

			&:hover {
				background-color: $color-ivory2;
			}
		}

		&:checked {
			& + span {
				background-color: $color-blue5;
				border: 1px solid $color-blue6;
				box-shadow: inset 0 2px 6px 0 rgba($color-black, .2);
				color: $color-white;
			}

			~ label {
				background-color: $color-blue5;
				border: 1px solid $color-blue6;
				box-shadow: inset 0 0 5px 0 rgba($color-black, .25);
				color: $color-white;
				font-weight: 700;
				line-height: 16px;

				&:hover {
					background-color: $color-blue5;
					box-shadow: inset 0 0 5px 0 rgba($color-black, .25);
					color: $color-white;
				}

				&:first-child {
					span {
						border-radius: 4px 0 0 4px;
					}
				}

				&:last-child {
					span {
						border-radius: 0 4px 4px 0;
					}
				}
			}
		}

		&:active {
			& + span {
				background-color: $color-blue6;
				border: 1px solid $color-blue6;
				box-shadow: inset 0 2px 6px 0 rgba($color-black, .2);
				color: $color-white;
			}
		}
	}
}

.checkbox {
	&.form-control {
		line-height: 15px;
		padding: 15px 10px 10px 15px;
	}

	label {
		display: inline-block;
		height: 100%;
		padding-left: 26px;
		position: relative;
		width: 100%;

		input {
			&[type='checkbox'] {
				background: transparent;
				border-color: $color-white;
				border-radius: 0;
				left: 16px;
				margin-top: 0;
				position: absolute;
				top: -2px;

				&::before {
					@include icon-fill;
					background: $color-white;
					border: 1px solid $color-charcoal1;
					border-radius: 2px;
					box-shadow: inset 0 1px 3px 0 rgba($color-black, .1);
					color: $color-white;
					content: '\e920';
					display: block;
					height: 20px;
					text-align: center;
					transition: color $trans-time $trans-func;
					width: 20px;
				}

				&:checked {
					&::before {
						background-color: $color-blue5;
						border-color: $color-blue6;
						color: $color-white;
						font-size: 18px;
					}
				}
			}
		}
	}

	&--no-border {
		&.checkbox {
			margin: 15px 0;

			label {
				line-height: 15px;
				padding-left: 35px;
				width: auto;

				input {
					&[type='checkbox'] {
						left: 25px;
						top: -2px;
					}
				}
			}
		}
	}
}

// Select
div {
	&.form-control {
		box-shadow: none;
		padding: 0;
	}
}

.select {
	@include form-control;
	& {
		appearance: none;
		background: transparent;
		box-shadow: none;
		border: 0;
		cursor: pointer;
		outline: none;
		padding-bottom: 13px;
		padding-top: 14px;
		margin: 0;
		position: relative;
		width: 100%;
	}

	option {
		background: $color-white;
		color: $color-charcoal5;
	}

	+ span {
		margin-top: -7px;
		position: absolute;
		right: 15px;
		top: 50%;
		pointer-events: none;
	}
}

.arrow-down {
	margin: 0;

	&::after {
		@include icon-basic;
		content: '\e905';
		position: absolute;
		right: 15px;
		top: 50%;
		transform: translate(0, -50%);
	}
}

.image-selector {
	display: inline-block;
	height: 87px;
	margin: 0 0 8px;
	width: 32.5%;

	&__group {
		display: flex;
		flex-wrap: wrap;
	}

	input {
		display: none;

		&:checked {
			~ .image-selector__border {
				border: 3px solid $color-blue5;
				border-radius: 8px;
				padding: 2px;
			}
		}
	}

	&__border {
		border: 3px solid $color-white;
		border-radius: 8px;
		display: inline-block;
		height: 100%;
		padding: 2px;
		width: 100%;

		&:hover {
			border: 3px solid $color-blue5;
		}
	}

	label {
		background-position: center 1px;
		background-size: cover;
		border-radius: 5px;
		box-shadow: 0 3px 4px 0 rgba($color-black, .2);
		cursor: pointer;
		height: 100%;
		line-height: 77px;
		text-align: center;
		width: 100%;

		span {
			@include font-primary-bold;
			color: $color-white;
			font-size: 18px;
		}
	}
}

// Error handling
.has-error {
	.input-group {
		* {
			box-shadow: none;
		}
	}

	.form-control {
		border: 1px solid $color-red5;
		color: $color-red5;
	}

	.form-error-message {
		display: block !important;
	}

	.radio-with-check {
		input {
			+ .icon {
				+ span {
					border: 2px solid $color-red5;
				}
			}
		}
	}

	.radio-btn-group {
		border: 1px solid $color-red5;

		& + .form-error-message {
			margin-top: 5px;
		}
	}

	.radio-colored {
		label {
			border: 1px solid $color-red5;

			& + .form-error-message {
				margin-top: 5px;
			}
		}
	}

	.image-selector {
		&__border {
			border: 3px solid $color-red5;
		}

		& + .form-error-message {
			margin-top: 5px;
		}
	}

	.input-group {
		border: 0;

		&:focus-within {
			border: 0;
		}

		&--inline-btn {
			.form-control {
				border-color: $color-red5;
			}
		}
	}
}

.form-error-message {
	color: $color-red5;
	font-size: 14px;
	display: none;
	margin: -10px 0 10px 2px;
}

@include breakpoint-phone {
	.image-selector {
		margin-bottom: 0;
		width: 31%;
	}
}
