@use 'theme';
@use 'upsell';

$toolbar-block-size: 136px;
$wpcontent-inline-start-indent: 20px;

#wpbody {
	padding-block-start: $toolbar-block-size;
}

.code-snippets-toolbar {
	color: #2c3337;
	background: #fff;
	font-family: 'SF Pro', sans-serif;
	margin-inline-start: -$wpcontent-inline-start-indent - 2;
	position: absolute;
	inline-size: calc(100% + $wpcontent-inline-start-indent);
	block-size: $toolbar-block-size;
	inset-block-start: 0;
	display: flex;
	flex-direction: column;

	ul, li {
		margin: 0;
		padding: 0;
		list-style: none;
	}
}

.code-snippets-toolbar-upper {
	justify-content: space-between;
	block-size: 76px;
	box-sizing: border-box;
	padding-block: 16px;
	padding-inline: 24px;
	border-block-end: 1px solid rgb(195 196 199 / 50%);
	display: flex;
	align-items: center;

	.logo {
		display: flex;
		align-items: center;
		gap: 8px;

		img {
			block-size: 42px;
		}

		div {
			font-size: 18px;
			font-weight: 700;
		}
	}

	h1 {
		font-size: 18px;
		font-weight: 700;
		line-height: 1.5;
	}

	ul {
		display: flex;
		gap: 22px;
		align-items: center;
	}

	a {
		color: inherit;
		text-decoration: none;
	}

	@media (width <= 480px) {
		padding-inline: 10px;

		.logo img {
			block-size: 34px;
		}

		.logo div {
			display: none;
		}

		.toolbar-upgrade-item .button {
			padding-inline: 10px;
		}
	}
}

.code-snippets-toolbar-lower {
	border-block-end: 1px solid #e2e2e4;
	block-size: 60px;
	box-sizing: border-box;

	nav,
	ul {
		block-size: 100%;
	}

	ul {
		display: flex;
		align-items: stretch;
	}

	li {
		display: flex;
	}

	// Items fill the 60px band; the active tab is indicated by accent colour on
	// its icon and label, with no underline.
	li a {
		display: flex;
		margin: 0;
		block-size: 100%;
		padding-block: 0;
		padding-inline: 24px;
		color: #2c3337;
		gap: 12px;
		align-items: center;
		font-size: 16px;
		font-weight: 600;
		letter-spacing: -0.16px;
		text-decoration: none;
		box-sizing: border-box;
		cursor: pointer;

		svg {
			inline-size: 26px;
			block-size: 26px;
		}

		&.active-link, &:hover, &:focus, &:active {
			color: theme.$accent;
			z-index: 1;
		}
	}

	li:not(.toolbar-end-item) + li.toolbar-end-item {
		margin-inline-start: auto;
	}

	// Narrow widths: centre each item's label directly beneath its icon and
	// shrink the type so the nav still fits on one row. The pro chip becomes a
	// small badge pinned to the item's top corner, out of the flow so it never
	// shifts the icon off-centre from its label. Below 782px the row scrolls
	// sideways (see the mobile block below) rather than wrapping.
	@media (width <= 1140px) {
		li a {
			position: relative;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			gap: 4px;
			padding-inline: 14px;
			font-size: 13px;
			text-align: center;

			.pro-chip {
				position: absolute;
				inset-block-start: 7px;
				inset-inline-end: 4px;
				padding-block: 1px;
				padding-inline: 5px;
				font-size: 8px;
				line-height: normal;
			}
		}
	}

	// On narrow screens Settings remains available through the WordPress submenu.
	// The remaining primary destinations fill the toolbar evenly rather than
	// becoming a second horizontally-scrolling navigation row.
	@media (width <= 782px) {
		li.toolbar-end-item {
			display: none;
		}

		li:not(.toolbar-end-item) {
			flex: 1 1 0;
			min-inline-size: 0;
		}

		li:not(.toolbar-end-item) + li.toolbar-end-item {
			margin-inline-start: 0;
		}

		li a {
			inline-size: 100%;
			padding-inline: 8px;
			white-space: normal;
		}
	}
}

.code-snippets-toolbar-upper li a.active-link,
.code-snippets-toolbar-upper li a:hover,
.code-snippets-toolbar-upper li a:focus,
.code-snippets-toolbar-upper li a:active {
	color: theme.$accent;
}

.code-snippets-toolbar-lower .pro-chip,
.nav-tab .pro-chip,
.snippet-type-link .pro-chip {
	color: theme.$accent;
	background: #eff5f9;
	border: 1px solid rgb(34 113 177 / 10%);
	text-transform: uppercase;
	border-radius: 999px;
	display: flex;
	justify-content: center;
	align-items: center;
	box-sizing: border-box;
	padding: 5px 12px;
	font-weight: 700;
	line-height: 1;
}


.code-snippets-toolbar-lower .pro-chip {
	font-size: 12px;
}

.nav-tab .pro-chip,
.snippet-type-link .pro-chip {
	font-size: 10px;
}

.code-snippets-return-link {
	float: inline-end;
}

.code-snippets-toolbar-upper .toolbar-more-item {
	display: none;
}

.code-snippets-toolbar-upper .toolbar-more-menu {
	position: relative;

	.dashicons, .dashicons::before {
		inline-size: 16px;
		block-size: 16px;
		font-size: 16px;
	}
}

.code-snippets-toolbar-upper .toolbar-more-menu summary {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	cursor: pointer;
}

.code-snippets-toolbar-upper .toolbar-more-menu ul {
	position: absolute;
	inset-block-start: calc(100% + 8px);
	inset-inline-end: 0;
	z-index: 2;
	display: grid;
	min-inline-size: 180px;
	block-size: auto;
	margin: 0;
	padding: 8px;
	background: #fff;
	border: 1px solid theme.$control-border;
	box-shadow: 0 3px 8px rgb(0 0 0 / 15%);
}

.code-snippets-toolbar-upper .toolbar-more-menu li {
	margin: 0;
}

// The upper and lower toolbars are distinct navigation trees; keep this rule
// after the lower-toolbar link state rules so the compact menu owns its hover state.
// stylelint-disable-next-line no-descending-specificity
.code-snippets-toolbar-upper .toolbar-more-menu a {
	display: block;
	padding: 8px;
	white-space: nowrap;
}

.code-snippets-toolbar-upper .toolbar-more-menu a:hover,
.code-snippets-toolbar-upper .toolbar-more-menu a:focus {
	background: #f6f7f7;
}

@media (width <= 960px) {
	.code-snippets-toolbar-upper {
		gap: 12px;
		padding-inline: 16px;
	}

	.code-snippets-toolbar-upper .logo {
		flex: 0 1 auto;
		min-inline-size: 0;
	}

	.code-snippets-toolbar-upper nav {
		margin-inline-start: auto;
	}

	.code-snippets-toolbar-upper > nav > ul {
		gap: 8px;
	}

	.code-snippets-toolbar-upper > nav > ul > li:not(.toolbar-upgrade-item, .toolbar-more-item) {
		display: none;
	}

	.code-snippets-toolbar-upper .toolbar-more-item {
		display: flex;
	}

	.code-snippets-toolbar-upper .toolbar-more-menu summary {
		padding: 8px;
		white-space: nowrap;
	}

	.code-snippets-toolbar-upper .toolbar-upgrade-item .button {
		display: block;
		max-inline-size: 180px;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
}

@media (width <= 640px) {
	.code-snippets-toolbar-upper .logo div {
		display: none;
	}
}
