/* Design standard layout: the app shell (one navigation that is a tab bar on a phone and a
   sidebar from 761 px), the page, its header, sections, stacks, grids and stat cards. */

.app {
	min-block-size: 100dvh;
}

/* A focused field scrolls clear of the phone's tab bar. */
:root {
	scroll-padding-block-end: calc(var(--bar) + env(safe-area-inset-bottom) + var(--space-4));
}

.sidebar {
	position: fixed;
	inset-inline: 0;
	inset-block-end: 0;
	display: flex;
	z-index: 20;
	background: var(--bg-subtle);
	border-block-start: 1px solid var(--border);
	padding-block-end: env(safe-area-inset-bottom);
}

.brand {
	display: none;
	color: var(--text);
	text-decoration: none;
}

/* On a phone the sidebar is the tab bar: its footer links (settings, sign out) are the last tabs. */
.sidebar > nav {
	flex: 1;
	min-inline-size: 0;
}

.sidebar-footer {
	display: flex;
}

.sidebar-footer > :not(.nav-item) {
	display: none;
}

.logo {
	display: grid;
	place-items: center;
	inline-size: 24px;
	block-size: 24px;
	border-radius: var(--radius-sm);
	background: var(--ink);
	color: var(--on-ink);
}

.nav {
	display: flex;
	margin: 0;
	padding: 0;
	list-style: none;
}

.nav > li {
	display: flex;
	flex: 1;
	min-inline-size: 0;
}

.nav-item {
	display: flex;
	flex: 1;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: var(--space-1);
	min-inline-size: 0;
	min-block-size: var(--bar);
	padding: var(--space-1);
	border: 0;
	background: none;
	color: var(--text-secondary);
	font-size: var(--text-xs);
	font-weight: var(--weight-medium);
	text-decoration: none;
	white-space: nowrap;
	cursor: pointer;
}

.nav-item:hover {
	color: var(--text);
	text-decoration: none;
}

.nav-item[aria-current="page"] {
	color: var(--text);
}

.nav-item .icon {
	inline-size: 22px;
	block-size: 22px;
}

/* A label in the brand or a tab is a <span>: it ends with an ellipsis instead of spilling. */
.brand > span,
.nav-item > span {
	min-inline-size: 0;
	max-inline-size: 100%;
	overflow: hidden;
	text-overflow: ellipsis;
}

.main {
	min-inline-size: 0;
	padding-block-end: calc(var(--bar) + env(safe-area-inset-bottom));
}

.page {
	display: flex;
	flex-direction: column;
	gap: var(--space-4);
	inline-size: 100%;
	max-inline-size: var(--content);
	margin-inline: auto;
	padding: var(--space-4);
}

/* A page with no app shell (signing in): one narrow column. */
.page-narrow {
	max-inline-size: 420px;
	padding-block-start: var(--space-16);
}

.page-header {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-3);
}

.page-header > :first-child {
	min-inline-size: 0;
	margin-inline-end: auto;
}

/* A search box in the header takes its own full-width row on a phone. */
.page-header > .search {
	order: 3;
	inline-size: 100%;
}

.page-title {
	font-size: var(--text-xl);
	font-weight: var(--weight-semibold);
	line-height: 1.3;
}

.page-subtitle {
	color: var(--text-secondary);
	font-size: var(--text-sm);
}

.page-actions,
.row {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-2);
}

.section {
	display: flex;
	flex-direction: column;
	gap: var(--space-3);
}

.section-header {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: var(--space-3);
}

.section-title {
	font-size: var(--text-lg);
	font-weight: var(--weight-semibold);
}

.stack {
	display: flex;
	flex-direction: column;
	gap: var(--space-4);
}

.grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
	gap: var(--space-3);
}

.stats {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
	gap: var(--space-2);
}

.stat {
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
	min-inline-size: 0;
	padding: var(--space-3);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	background: var(--surface);
}

.stat-label {
	display: flex;
	align-items: center;
	gap: var(--space-1);
	min-inline-size: 0;
	color: var(--text-secondary);
	font-size: var(--text-sm);
	white-space: nowrap;
}

.stat-label > span {
	overflow: hidden;
	text-overflow: ellipsis;
}

.stat-value {
	font-size: var(--text-xl);
	font-weight: var(--weight-semibold);
	font-variant-numeric: tabular-nums;
	line-height: 1.2;
	white-space: nowrap;
}

.split {
	display: grid;
	gap: var(--space-4);
}

@media (min-width: 761px) {
	.app {
		display: grid;
		grid-template-columns: var(--sidebar) minmax(0, 1fr);
	}

	/* A page that hides the sidebar (signing in) is one column: .main never lands in the sidebar's. */
	.app:has(> .sidebar[hidden]) {
		grid-template-columns: minmax(0, 1fr);
	}

	.sidebar {
		position: sticky;
		inset-block-start: 0;
		display: flex;
		flex-direction: column;
		gap: var(--space-4);
		block-size: 100dvh;
		padding: var(--space-4) var(--space-3);
		border-block-start: 0;
		border-inline-end: 1px solid var(--border);
	}

	.brand {
		display: flex;
		align-items: center;
		gap: var(--space-3);
		padding: var(--space-1) var(--space-2);
		font-size: var(--text-lg);
		font-weight: var(--weight-semibold);
		white-space: nowrap;
	}

	.sidebar-footer {
		flex-direction: column;
		gap: var(--space-1);
		margin-block-start: auto;
	}

	.sidebar-footer > :not(.nav-item) {
		display: flex;
	}

	.nav {
		flex-direction: column;
		gap: var(--space-1);
	}

	.nav-item {
		flex-direction: row;
		justify-content: flex-start;
		gap: var(--space-3);
		min-block-size: var(--control);
		padding: var(--space-2);
		border-radius: var(--radius-sm);
		font-size: var(--text-md);
	}

	.nav-item .icon {
		inline-size: 18px;
		block-size: 18px;
	}

	.nav-item[aria-current="page"] {
		background: var(--surface-hover);
		box-shadow: inset 0 0 0 1px var(--border);
	}

	.main {
		padding-block-end: 0;
	}

	:root {
		scroll-padding-block-end: 0;
	}

	.page {
		gap: var(--space-5);
		padding: var(--space-6) var(--space-8);
	}

	.page-header > .search {
		order: 0;
		inline-size: 240px;
	}

	.stats {
		grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
		gap: var(--space-3);
	}

	.stat {
		padding: var(--space-4);
	}
}

@media (min-width: 1001px) {
	.split {
		grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
		align-items: start;
	}
}
