
// Limit resize in firefox, options are none, vertical, horizontal or both
textarea {
	resize: vertical;
}

form {
	margin: 0 auto;

	&:after {
		&:extend(.clear);
	}

	fieldset {
		border: 1px solid @colorDivider;
		margin: 1rem 0;
		padding: 1rem;
		border-radius: @radius;
		min-width: 0; // stop auto resize on Chrome
	}

	legend {
		padding: 0 .5rem;
		border: 1px solid @colorDivider;
		border-radius: @radius;
	}

	// Labels & validation
	label {
		display: block;
		position: relative;
		font-weight: 500;
		font-size: 1rem;
		color: @formTextDesc;
		top: 0;
		.transition();

		em {
			font-size: .85rem;
			font-style: normal;
			color: fadeout(@formValidatorReq, 13%);
		}

		&.validationError span:first-child {
			display: none;
		}

		&.focused {
			color: @colorPrimary;
		}
	}

	.description {
		clear: both;
		padding: .25rem 0 0 0;
		font-size: .85rem;
		color: @formTextDesc;
	}

	.validation {
		color: @formValidatorFailed;
		display: none;

		strong {
			font-weight: normal;
			display: block;
		}
	}

	.ok,
	.failed,
	.ajax {
		display: block;
	}

	// Form elements
	input[disabled] {
		cursor: not-allowed;
		opacity: .5;
	}

	input[type="text"],
	input[type="number"],
	input[type="email"],
	input[type="tel"],
	input[type="url"],
	input[type="password"],
	input[type="search"],
	select,
	textarea {
		outline: none;
		font-family: inherit;
		font-size: 1rem;
		width: 100%;
		padding: .5rem .25rem;
		border: 1px solid @colorDivider;
		color: @colorText;
		background-color: transparent;
		.transition();
		-webkit-appearance: none;
		border-radius: 0;

		&:focus {
			border: 1px solid @colorPrimary;
		}

		&.validationError {
			border-color: @formValidatorFailed;
		}
	}

	.selectControl select {
		padding-right: 2.5rem;
	}

	option {
		color: @colorText;
	}

	dt {
		position: relative;
	}

	input[type="file"] {
		font-size: 1rem;
		width: auto;
	}

	// Radio group
	.radiogroup {
		margin: 0;
		padding: 0;
		list-style: none;

		li {
			padding: .25rem 0;
			margin: 0;
		}

		input {
			margin-right: .5rem;
		}

		label {
			color: @colorText;
			font-size: 1rem;
		}
	}

	// Checklist
	.checklist {
		padding: .25rem;
		margin: 0;
		list-style: none;
		overflow: auto;
		border: 1px solid @colorDivider;
		border-radius: @radius;

		li {
			padding: .25rem;
			margin: 0;
			background-color: transparent;
			.transition();

			&.default {
				background-color: @checklistDefaultBg;
			}

			&.selected {
				background-color: @checklistSelectedBg;
			}

			&.default.selected {
				background-color: @checklistSelDefaultBg;
			}

			&:hover {
				background-color: @checklistHoverBg;

				&.default,
				&.default.selected {
					background-color: @checkListSelDefHoverBg;
				}
			}

			label {
				display: block;
				font-weight: normal;
				color: @colorText;
				font-size: 1rem;
				cursor: pointer;
			}
		}

		input {
			margin-right: .25rem;
		}
	}

	// Stacked Layout
	dd {
		&:last-child {
			margin-bottom: 0;
		}
	}

	.selectControl {
		position: relative;
		z-index: 1;
		cursor: pointer;

		select {
			cursor: pointer;
			z-index: 4;
			position: relative;
		}

		&:after {
			content: ' ';
			display: block;
			z-index: 2;
			width: 0;
			height: 0;
			border-style: solid;
			border-width: .5rem .5rem 0 .5rem;
			border-color: @colorPrimary transparent transparent transparent;
			position: absolute;
			top: 50%;
			right: 1rem;
			transform: translateY(-50%);
		}
	}
}

// Give form input fields an application style
.appFormStyle {
	form {
		input[type="text"],
		input[type="number"],
		input[type="email"],
		input[type="tel"],
		input[type="url"],
		input[type="password"],
		input[type="search"],
		select,
		textarea {
			padding: .5rem 0;
			border: none;
			border-bottom: 2px solid @colorDivider;

			&:focus {
				border: none;
				border-bottom: 2px solid @colorPrimary;
			}

			&.validationError {
				border: none;
				border-bottom: 2px solid @formValidatorFailed;
			}
		}
	}
}

.floatingLabels {
	label {
		.user-select();

		&.floatUp {
			color: @formTextDesc;
			position: absolute;
			top: .25rem;
			left: .25rem;
			font-size: .75rem;

			&.focused {
				color: @colorPrimary;
			}
		}

		&.floatDown {
			color: @formFloatLabel;
			position: absolute;
			top: 1rem;
			left: .25rem;
			cursor: text;

			&.focused {
				color: @colorPrimary;
			}
		}
	}

	form {
		input[type="text"],
		input[type="number"],
		input[type="email"],
		input[type="tel"],
		input[type="url"],
		input[type="password"],
		input[type="search"] {
			padding: 1.5rem .25rem .5rem .25rem;
		}

		textarea.hasFloatingLabel {
			margin-top: .5rem;
			padding: .5rem .25rem .5rem .25rem;
		}

		.selectControl {
			select {
				padding: 1.5rem 2.5rem .5rem .25rem;
				margin: 0;
				outline: none;
				border-radius: 0;
				-webkit-appearance: none;
				-moz-appearance: none;

				// Hide focus on Firefox
				&:-moz-focusring {
					color: transparent;
					text-shadow: 0 0 0 #000;
				}

				&:disabled {
					cursor: not-allowed;
				}

				&::-ms-expand {
					display: none;
				}
			}
		}
	}

	.floatTextarea {
		&.floatUp {
			left: 0;
			top: -.75rem;
		}
		&.floatDown {
			top: .75rem;
		}
	}

	&.appFormStyle,
	.appFormStyle {
		label {
			&.floatUp,
			&.floatDown {
				left: 0;
			}
		}

		textarea.hasFloatingLabel {
			padding-left: 0;
			padding-right: 0;
		}
		input[type="text"],
		input[type="number"],
		input[type="email"],
		input[type="tel"],
		input[type="url"],
		input[type="password"],
		input[type="search"],
		.selectControl select {
			padding: 1.5rem 0 .5rem 0;
		}

		.selectControl {
			select {
				padding-right: 2.5rem;
			}

			&:after {
				transform: none;
			}
		}
	}
}

// Submit buttons
form input[type="submit"],
form button, button { font-size: 1rem; }

// Horizontal Layout
.hform form,
form.hform {
	dt {
		float: left;
		clear: both;
		width: 28%;
		margin-right: 2%;

		label {
			text-align: right;
			padding: .4rem 0 .5rem 0;
			color: @colorText;
		}
	}
	dd {
		float: right;
		width: 70%;
	}
	.radiogroup {
		li:first-child {
			padding-top: 0;
		}
	}
	input[type="text"],
	input[type="number"],
	input[type="email"],
	input[type="tel"],
	input[type="url"],
	input[type="password"],
	input[type="search"],
	.selectControl select {
		padding: .5rem .25rem !important;
	}

	.selectControl select {
		padding-right: 2.5rem !important;
	}
}

// Submit button list layout
form {
	#submit-list {
		clear: both;

		dt {
			display: none;
		}
		dd {
			float: none;
			width: auto;
			display: inline;

			input, button {
				margin-left: 2px;
				margin-right: 2px;
			}
		}
	}
}

.hform {
	#submit-list {
		float: right;
		width: 70%;
	}
}

@media (max-width: (@breakpoint-s - 1)) {

	.hform #submit-list {
		float: none;
		width: 100%;
	}
	.hform form,
	form.hform {
		dt, dd {
			float: none;
			width: 100%;
		}

		dt label {
			text-align: left;
			font-size: .85rem;
			color: @formTextDesc;
		}

		.validation {
			width: auto;
			left: 40%;
			bottom: -.5rem;
		}
	}
}
