/* The app shell: rail, bars, drawer, banners, shortcuts. Owner: W2b. */

/* The unread counters are hidden at zero; `stream.js` toggles `hidden`. */
[data-badge][hidden] {
	display: none !important;
}

@scope ([data-c="app-shell"]) to ([data-c]) {
	:scope {
		--topbar-h: 52px;
		display: block;
		min-height: 100dvh;
	}

	.side {
		display: none;
	}

	.right {
		display: none;
	}

	#main {
		min-height: 100dvh;
		padding-bottom: 72px;
	}

	@media (min-width: 760px) {
		:scope {
			--topbar-h: 0px;
			display: grid;
			grid-template-columns: 260px minmax(0, 640px);
			justify-content: center;
		}

		:scope.wide {
			grid-template-columns: 260px minmax(0, 960px);
		}

		.side {
			display: block;
		}

		#main {
			border-inline: 1px solid var(--line);
			padding-bottom: 0;
		}
	}

	@media (min-width: 1100px) {
		:scope.rail {
			grid-template-columns: 260px minmax(0, 640px) 320px;
		}

		.right {
			display: block;
			position: sticky;
			top: 0;
			align-self: start;
			height: 100dvh;
			overflow-y: auto;
			overscroll-behavior: contain;
			scrollbar-width: none;
		}
	}
}

@scope ([data-c="top-bar"]) to ([data-c]) {
	:scope {
		position: sticky;
		top: 0;
		z-index: 10;
		display: flex;
		align-items: center;
		gap: var(--s3);
		height: 52px;
		padding: 0 var(--s4);
		background: var(--paper);
		border-bottom: 1px solid var(--line);
	}

	.avatar {
		display: inline-flex;
		padding: 0;
		background: transparent;
		border: 0;
		min-width: 44px;
		min-height: 44px;
		align-items: center;
	}

	.brand {
		text-decoration: none;
	}

	@media (min-width: 760px) {
		:scope:not(.demo) {
			display: none;
		}
	}
}

@scope ([data-c="bottom-bar"]) to ([data-c]) {
	:scope {
		position: fixed;
		inset: auto 0 0 0;
		z-index: 20;
		display: flex;
		justify-content: space-around;
		align-items: center;
		padding: var(--s1) var(--s2) calc(var(--s1) + env(safe-area-inset-bottom));
		background: var(--paper);
		border-top: 1px solid var(--line);
		transition: transform var(--dur-fast) var(--ease);
	}

	:scope.hidden {
		transform: translateY(100%);
	}

	a,
	.compose {
		position: relative;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		min-width: 48px;
		min-height: 48px;
		color: var(--ink-dim);
		text-decoration: none;
	}

	a.current {
		color: var(--ink);
	}

	.compose {
		background: var(--ink);
		color: var(--paper-on-ink);
		border: 0;
		border-radius: var(--r-ctl);
	}

	.badge {
		position: absolute;
		top: 4px;
		right: 0;
	}

	@media (min-width: 760px) {
		:scope:not(.demo) {
			display: none;
		}
	}
}

@scope ([data-c="rail-nav"]) to ([data-c]) {
	:scope {
		position: sticky;
		top: 0;
		display: flex;
		flex-direction: column;
		gap: var(--s4);
		height: 100dvh;
		padding: var(--s4) var(--s3);
	}

	.brand {
		padding: var(--s2) var(--s3);
		text-decoration: none;
	}

	nav {
		display: flex;
		flex-direction: column;
		gap: var(--s1);
	}

	nav a {
		display: flex;
		align-items: center;
		gap: var(--s3);
		min-height: 48px;
		padding: 0 var(--s3);
		border: 1px solid transparent;
		border-radius: var(--r-ctl);
		color: var(--ink-dim);
		font-size: var(--t-lg);
		text-decoration: none;
		transition:
			color var(--dur-fast) ease,
			border-color var(--dur-fast) ease;
	}

	nav a:hover {
		color: var(--ink);
	}

	nav a.current {
		color: var(--ink);
		border-color: var(--line-hot);
	}

	.chip {
		margin-top: auto;
	}
}

@scope ([data-c="account-menu"]) to ([data-c]) {
	:scope {
		display: block;
	}
}

/* The trigger and the panel belong to the popover; its content is the account menu's. */
[data-c='account-menu'] .trigger {
	width: 100%;
	min-height: 0;
	padding: 0;
	gap: 0;
	border-color: transparent;
	text-align: left;
}

[data-c='account-menu'] .trigger:hover,
[data-c='account-menu'] .trigger:has(+ .panel:popover-open) {
	border-color: var(--line-hot);
}

[data-c='account-menu'] .panel {
	width: 300px;
	padding: var(--s2);
}

[data-c='account-menu'] .account {
	display: flex;
	align-items: center;
	gap: var(--s3);
	width: 100%;
	padding: var(--s2);
	text-align: left;
}

[data-c='account-menu'] .who {
	flex: 1;
	display: flex;
	flex-direction: column;
	min-width: 0;
}

[data-c='account-menu'] .trigger .who {
	max-width: 150px;
}

[data-c='account-menu'] .display {
	font-weight: 600;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

[data-c='account-menu'] .handle {
	color: var(--ink-dim);
	font-size: var(--t-sm);
	overflow: hidden;
	text-overflow: ellipsis;
}

[data-c='account-menu'] .list {
	display: flex;
	flex-direction: column;
}

[data-c='account-menu'] .row {
	display: flex;
	align-items: center;
	gap: var(--s3);
	width: 100%;
	min-height: 48px;
	padding: var(--s2) var(--s3);
	background: transparent;
	border: 0;
	border-radius: var(--r-ctl);
	color: var(--ink);
	text-align: left;
	text-decoration: none;
}

[data-c='account-menu'] .row:hover,
[data-c='account-menu'] .row:focus-visible {
	background: var(--surface-hover);
}

[data-c='account-menu'] .row:focus-visible {
	outline-offset: -2px;
}

[data-c='account-menu'] .danger {
	color: var(--danger);
}

[data-c='account-menu'] .plain {
	min-height: 40px;
}

[data-c='account-menu'] hr {
	margin: var(--s2) 0;
	border: 0;
	border-top: 1px solid var(--line);
}

@media (pointer: coarse) {
	[data-c='account-menu'] .row {
		min-height: 52px;
	}
}

@scope ([data-c="drawer"]) to ([data-c]) {
	:scope {
		margin: 0;
		padding: 0;
		height: 100dvh;
		max-height: none;
		width: min(320px, 86vw);
		background: var(--surface);
		color: var(--ink);
		border: 0;
		border-right: 1px solid var(--line-hot);
	}

	:scope::backdrop {
		background: var(--paper);
		opacity: 0.7;
	}

	.panel {
		display: flex;
		flex-direction: column;
		gap: var(--s4);
		min-height: 100%;
		padding: var(--s4);
	}

	.head {
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: var(--s2);
	}

	.me {
		display: flex;
		align-items: center;
		gap: var(--s3);
		min-width: 0;
		color: var(--ink);
		text-decoration: none;
	}

	.who {
		display: flex;
		flex-direction: column;
		min-width: 0;
	}

	.display {
		font-weight: 600;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.handle {
		color: var(--ink-dim);
		font-size: var(--t-sm);
		overflow: hidden;
		text-overflow: ellipsis;
	}

	nav {
		display: flex;
		flex-direction: column;
	}

	nav a {
		display: flex;
		align-items: center;
		gap: var(--s3);
		min-height: 48px;
		color: var(--ink);
		font-size: var(--t-lg);
		text-decoration: none;
	}

	h2 {
		font-size: var(--t-sm);
		font-family: var(--font-mono);
		letter-spacing: 0.2em;
		text-transform: uppercase;
		color: var(--ink-dim);
	}

	ul {
		list-style: none;
		display: flex;
		flex-direction: column;
	}

	li button {
		display: flex;
		align-items: center;
		gap: var(--s3);
		width: 100%;
		min-height: 48px;
		background: transparent;
		border: 0;
		text-align: left;
	}

	.foot {
		display: flex;
		flex-direction: column;
		gap: var(--s2);
		margin-top: auto;
	}
}

@scope ([data-c="announcement-banner"]) to ([data-c]) {
	:scope {
		display: flex;
		flex-direction: column;
	}

	.banner {
		position: relative;
		display: flex;
		align-items: center;
		gap: var(--s3);
		padding: var(--s2) var(--s2) var(--s2) var(--s4);
		background: var(--surface);
		border-bottom: 1px solid var(--line);
	}

	.stripe {
		position: absolute;
		inset: 0 auto 0 0;
		width: 6px;
		background: var(--ink);
		mask-size: calc(var(--cell) * 4);
		-webkit-mask-size: calc(var(--cell) * 4);
		image-rendering: pixelated;
	}

	.warning {
		border-bottom-color: var(--danger);
	}

	.warning .stripe {
		background: var(--danger);
	}

	.warning .icon {
		color: var(--danger);
	}

	.icon {
		display: inline-grid;
		flex: none;
	}

	p {
		flex: 1;
		min-width: 0;
		font-size: var(--t-sm);
		overflow-wrap: anywhere;
	}

	a {
		color: var(--ink);
		text-decoration: underline;
		white-space: nowrap;
	}

	@media (pointer: coarse) {
		a {
			display: inline-flex;
			align-items: center;
			min-height: 44px;
		}
	}
}

@scope ([data-c="shortcuts-dialog"]) to ([data-c]) {
	section + section {
		margin-top: var(--s4);
	}

	h3 {
		margin-bottom: var(--s2);
		font-size: var(--t-sm);
		font-family: var(--font-mono);
		letter-spacing: 0.2em;
		text-transform: uppercase;
		color: var(--ink-dim);
	}

	.item {
		display: flex;
		justify-content: space-between;
		gap: var(--s4);
		padding-block: var(--s1);
	}

	dt {
		display: flex;
		align-items: center;
		gap: var(--s1);
	}

	kbd {
		padding: 0 var(--s2);
		border: 1px solid var(--line-hot);
		border-radius: var(--r-ctl);
		font-family: var(--font-mono);
		font-size: var(--t-sm);
	}

	.join {
		color: var(--ink-dim);
		font-size: var(--t-sm);
	}
}

@scope ([data-c="page-bar"]) to ([data-c]) {
	:scope {
		background: var(--paper);
		border-bottom: 1px solid var(--line);
		padding: var(--s2) var(--s4) 0;
		z-index: 5;
		/* Stays under the shell's mobile top bar instead of sliding beneath it. */
		position: sticky;
		top: var(--topbar-h, 0px);
	}

	.row {
		display: flex;
		align-items: center;
		gap: var(--s3);
		min-height: 48px;
		padding-bottom: var(--s2);
	}

	.titles {
		flex: 1;
		min-width: 0;
	}

	h1,
	h2 {
		font-size: var(--t-xl);
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.sub {
		color: var(--ink-dim);
		font-size: var(--t-sm);
	}

	.actions {
		display: flex;
		gap: var(--s2);
		align-items: center;
	}
}

@scope ([data-c="right-rail"]) to ([data-c]) {
	:scope {
		display: flex;
		flex-direction: column;
		gap: var(--s4);
		padding: var(--s4) 0 var(--s5) var(--s4);
	}

	.search {
		position: sticky;
		top: 0;
		z-index: 1;
		display: flex;
		gap: var(--s2);
		padding-bottom: var(--s1);
		background: var(--paper);
	}

	.field {
		flex: 1;
		min-width: 0;
		display: flex;
		align-items: center;
		gap: var(--s2);
		padding-inline: var(--s3);
		border: 1px solid var(--line);
		border-radius: var(--r-ctl);
		transition: border-color var(--dur-fast) ease;
	}

	.field:hover {
		border-color: var(--line-hot);
	}

	.field:focus-within {
		border-color: var(--ink);
		box-shadow: inset 0 -2px 0 var(--ink);
	}

	input {
		flex: 1;
		min-width: 0;
		min-height: 42px;
		background: transparent;
		border: 0;
		outline: none;
		appearance: none;
	}

	input::placeholder {
		color: var(--ink-dim);
	}

	input::-webkit-search-cancel-button,
	input::-webkit-search-decoration {
		appearance: none;
		display: none;
	}

	.go {
		display: inline-grid;
		place-items: center;
		width: 42px;
		background: transparent;
		border: 1px solid var(--line);
		border-radius: var(--r-ctl);
		transition: border-color var(--dur-fast) ease;
	}

	.go:hover {
		border-color: var(--line-hot);
	}

	.card {
		border: 1px solid var(--line);
		border-radius: var(--r-card);
		overflow: hidden;
	}

	h2 {
		padding: var(--s4) var(--s4) var(--s2);
		font-size: var(--t-lg);
	}

	ul {
		list-style: none;
	}

	.trend {
		position: relative;
		overflow: hidden;
		display: grid;
		grid-template-columns: 24px 1fr;
		column-gap: var(--s3);
		padding: var(--s3) var(--s4);
		color: var(--ink);
		text-decoration: none;
	}

	.rank {
		grid-row: span 2;
		font-family: var(--font-mono);
		font-size: var(--t-sm);
		color: var(--ink-dim);
	}

	.label {
		font-weight: 600;
		overflow-wrap: anywhere;
	}

	.count {
		color: var(--ink-dim);
		font-size: var(--t-sm);
	}

	.person {
		display: flex;
		align-items: center;
		gap: var(--s3);
		padding: var(--s3) var(--s4);
	}

	.who {
		flex: 1;
		min-width: 0;
		display: flex;
		flex-direction: column;
		color: var(--ink);
		text-decoration: none;
	}

	.handle {
		color: var(--ink-dim);
		font-size: var(--t-sm);
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.more {
		display: flex;
		align-items: center;
		min-height: 44px;
		padding: 0 var(--s4);
		border-top: 1px solid var(--line);
		color: var(--ink);
		text-decoration: none;
	}

	.more:hover {
		background: var(--surface);
	}

	.foot {
		display: flex;
		flex-wrap: wrap;
		gap: var(--s1) var(--s3);
		padding: 0 var(--s2);
		font-size: var(--t-sm);
	}

	.foot a,
	.foot button {
		display: inline-flex;
		align-items: center;
		min-height: 28px;
		padding: 0;
		background: transparent;
		border: 0;
		color: var(--ink-dim);
		text-decoration: none;
	}

	.foot a:hover,
	.foot button:hover {
		color: var(--ink);
		text-decoration: underline;
	}

	@media (pointer: coarse) {
		.foot a,
		.foot button {
			min-height: 40px;
		}
	}
}
