.toolbars-expand-to-two-lines() {
	flex-flow: column;

	#left-navigation {
		// Necessary to make the ::after pseudo-element full-width below the menu items.
		flex-wrap: wrap;

		// Add a border effect between the two lines of the toolbar. Not using an actual border on
		// #left-navigation because it has a negative margin so a border would overflow the layout.
		&::after {
			background-color: @border-color-subtle;
			content: '';
			height: 1px;
			// Account for negative horizontal margins on #left-navigation.
			width: calc( 100% - ( @spacing-horizontal-tabs * 2 ) );
			margin-left: @spacing-horizontal-tabs;
		}
	}

	// Align right nav to the start of the toolbar when on a separate line.
	#right-navigation .vector-menu-content-list {
		justify-content: flex-start;
	}

	// Push the bookmark to the right.
	// The bookmark is the only item in the "Views" nav that should be shown on the right. If the
	// bookmark isn't present on a page, the tools overflow menu and any gadgets in the toolbar will
	// still be aligned to the left.
	#ca-bookmark {
		margin-left: auto;
	}

	// Hide "view" link, unless the page is in edit mode.
	#ca-view {
		display: none;

		.ve-activated &,
		.action-edit & {
			display: block;
		}
	}
}

.vector-page-toolbar-container {
	display: flex;
	flex-flow: row;
	justify-content: space-between;
	font-size: @font-size-small;
	// Use box-shadow instead of border to allow border collapsing between titlebar and toolbar
	box-shadow: 0 1px @border-color-subtle;
	// Add bottom margin to account for box-shadow
	margin-bottom: 1px;

	// Between the mobile and desktop breakpoints, expand the toolbar to 2 lines if there is not
	// enough room for all items on one line.
	// Below `@max-width-breakpoint-mobile`, most items get collapsed into the tools menu.
	@media ( min-width: @max-width-breakpoint-mobile ) {
		@media ( max-width: @max-width-breakpoint-desktop ) {
			&--expand {
				.toolbars-expand-to-two-lines();
			}
		}
	}

	.cdx-button {
		// Override default button styles to match the styles of the tabs in the titlebar
		font-weight: normal;
		font-size: @font-size-small;
	}

	.mw-portlet-views {
		@media ( min-width: @min-width-breakpoint-page-tools-dropdown ) {
			&:not( .emptyPortlet ) {
				display: flex;
			}
		}
	}

	@media ( max-width: @min-width-breakpoint-page-tools-dropdown ) {
		.mw-portlet-views .vector-menu-item--collapsible {
			display: none;
		}
	}
}

// ID Selectors outside of .vector-page-toolbar-container to avoid over-specificity.
#right-navigation,
#left-navigation {
	// flex ensures all child elements align on one line.
	display: flex;
	align-items: center;
	margin: 0 -@spacing-horizontal-tabs;
}

// For language variants
#left-navigation > nav {
	display: flex;
}

#right-navigation {
	justify-content: flex-end;

	// Needed to ensure views push bookmark to right
	// between tablet and desktop breakpoint
	> nav:first-child {
		width: 100%;
	}

	// Any dropdowns inside the right navigation in modern Vector (e.g. "more" menu).
	// should be right-aligned to prevent horizontal scrolling.
	.vector-dropdown-content {
		.mixin-vector-dropdown-content-flip();
	}
}
