/**
 * Sizing and focus fixes for the Select2 control inside a Gravity Forms field.
 *
 * Scoped to .gfds-post-select so nothing here touches the other Select2 controls
 * on the site.
 */

.gfds-post-select .select2-container {
	max-width: 100%;
}

/* Dropdown placement.
 *
 * The script attaches the dropdown to .ginput_container, so it is positioned
 * within this box rather than against the document. Select2 still writes inline
 * top/left from its own measurements, which is what goes wrong when the
 * control's geometry changes after the menu opens, so both are overridden
 * outright. The menu then sits directly beneath the control by construction and
 * cannot ride up over the input.
 *
 * Width is deliberately left to Select2's inline value rather than pinned to
 * 100% of this wrapper.
 *
 * This also makes Select2's --above flipping a no-op, which is deliberate: a
 * menu that opens upward over a multi select hides the tags the visitor has
 * already chosen.
 */
.gfds-post-select .ginput_container {
	position: relative;
	/* An overflow-clipped wrapper would cut the menu off now that it lives
	   inside it rather than on <body>. */
	overflow: visible;
}

.gfds-post-select .ginput_container .select2-dropdown {
	position: absolute !important;
	top: 100% !important;
	left: 0 !important;
	/* width: 100% !important; */
	z-index: 100000;
}

/* Keep a long result list from running off the bottom of the page. */
.gfds-post-select .select2-results > .select2-results__options {
	max-height: 15rem;
}

/* GF's own field styles set a min-height on selects that Select2 does not
   inherit, leaving the control noticeably shorter than sibling inputs. */
.gfds-post-select .select2-container--default .select2-selection--multiple {
	min-height: 2.5rem;
	padding: 0.15rem 0.25rem;
	border-color: #686e77;
	border-radius: 3px;
}

.gfds-post-select .select2-container--default.select2-container--focus .select2-selection--multiple,
.gfds-post-select .select2-container--default.select2-container--open .select2-selection--multiple {
	border-color: #204ce5;
	outline: 2px solid rgba( 32, 76, 229, 0.35 );
	outline-offset: 1px;
}

/* Long disease names should wrap inside their tag rather than force the
   control wider than the form. */
.gfds-post-select .select2-container--default .select2-selection--multiple .select2-selection__choice {
	max-width: 100%;
	white-space: normal;
	overflow-wrap: anywhere;
}

/* The field fails validation like any other GF field; match GF's error colour
   so the control does not look untouched when the rest of the field is red. */
.gfds-post-select.gfield_error .select2-container--default .select2-selection--multiple {
	border-color: #c02b0a;
}

/* ---------------------------------------------------------------------------
 * Defensive rules against theme styling.
 *
 * Select2 builds its control out of ordinary elements -- a <ul>, <li>s, an
 * <input> and, since 4.1, a real <button> for each tag's remove control. A
 * theme with opinions about those element types styles the whole control by
 * accident, and the result is not subtly off but unusable.
 *
 * The rules below re-assert only what Select2 needs to function, at a
 * specificity that beats element-level theme rules. !important is used
 * deliberately and only where a bare element selector in a theme would
 * otherwise win; each is a property Select2's own stylesheet also sets, so
 * nothing here invents an appearance of its own.
 * ------------------------------------------------------------------------- */

/* The remove button.
 *
 * The big one. It is positioned over the left edge of its tag, so a theme's
 * button background paints a block across the start of the disease name, and a
 * theme's button padding widens the tag until the inline search field has
 * nowhere left to sit. */
.gfds-post-select .select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
	background: none !important;
	background-color: transparent !important;
	border: none !important;
	border-right: 1px solid #aaa !important;
	border-radius: 4px 0 0 4px !important;
	box-shadow: none !important;
	color: #666 !important;
	font-size: 1em !important;
	font-weight: bold !important;
	line-height: 1.4 !important;
	letter-spacing: normal !important;
	text-transform: none !important;
	text-decoration: none !important;
	min-width: 0 !important;
	width: auto !important;
	min-height: 0 !important;
	height: auto !important;
	margin: 0 !important;
	padding: 0 5px !important;
	position: absolute !important;
	left: 0 !important;
	top: 0 !important;
	bottom: 0 !important;
	transform: none !important;
}

.gfds-post-select .select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover,
.gfds-post-select .select2-container--default .select2-selection--multiple .select2-selection__choice__remove:focus {
	background-color: #f1f1f1 !important;
	color: #222 !important;
}

/* The tag itself: keep room for the button, and keep the theme's list styling
   off a <li> that is not a list item in any meaningful sense. */
.gfds-post-select .select2-container--default .select2-selection--multiple .select2-selection__choice {
	background-color: #e4e4e4;
	border: 1px solid #aaa;
	border-radius: 4px;
	padding: 1px 6px 1px 24px !important;
	margin: 4px 0 0 5px;
	line-height: 1.4;
	font-size: 0.95rem;
	list-style: none;
	text-indent: 0;
}

.gfds-post-select .select2-container--default .select2-selection--multiple .select2-selection__choice__display {
	padding: 0 !important;
	color: inherit;
}

.gfds-post-select .select2-selection__rendered {
	list-style: none !important;
	margin: 0 !important;
	padding: 0 !important;
}

/* The typing area. Select2 sizes this inline as you type; a theme that forces
   a width, height or box model on inputs collapses it to a sliver. */
.gfds-post-select .select2-container .select2-search--inline .select2-search__field {
	background: transparent !important;
	border: none !important;
	box-shadow: none !important;
	outline: 0 !important;
	height: auto !important;
	min-height: 1.75rem !important;
	min-width: 8rem;
	max-width: 100%;
	margin: 2px 0 0 6px !important;
	padding: 0 !important;
	font-family: inherit;
	font-size: 1rem;
	line-height: 1.5;
}

/* The dropdown. A transparent panel over page content is unreadable, so the
   background is re-asserted rather than inherited. */
.gfds-post-select .ginput_container .select2-dropdown {
	background-color: #fff !important;
	border: 1px solid #aaa !important;
	border-radius: 0 0 4px 4px;
	box-shadow: 0 6px 16px rgba( 0, 0, 0, 0.15 );
}

/* Result rows: readable at the form's own text size, not whatever a theme
   applies to nested list items. */
.gfds-post-select .select2-results__options {
	list-style: none !important;
	margin: 0 !important;
	padding: 0 !important;
	background-color: transparent;
}

.gfds-post-select .select2-results__option {
	font-family: inherit;
	font-size: 1rem !important;
	line-height: 1.4;
	padding: 0.5rem 0.75rem !important;
	margin: 0 !important;
	color: #1a1a1a;
	text-indent: 0;
	list-style: none;
}

.gfds-post-select .select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
	background-color: #204ce5;
	color: #fff;
}

.gfds-post-select .select2-container--default .select2-results__option--selected {
	background-color: #e8ecf9;
	color: #1a1a1a;
}
