/* App frame: one stage of screens, an iOS tab bar on phones, a sidebar on wide screens. */

.app {
	position: relative;
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	grid-template-rows: minmax(0, 1fr);
	height: var(--app-height, 100dvh);
	overflow: hidden;
}
/* The banner holders are not grid items: their contents are positioned on the frame. */
.banner-slot,
.live-slot {
	display: contents;
}
.stage {
	position: relative;
	grid-row: 1;
	min-width: 0;
	overflow: hidden;
	background: var(--bg);
}
.screen {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	background: var(--bg);
}
.screen-scroll {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	overflow-x: hidden;
	overscroll-behavior-y: contain;
	-webkit-overflow-scrolling: touch;
	scroll-padding-top: calc(var(--navbar-height) + 8px);
}
.screen-body {
	width: 100%;
	max-width: var(--content-max);
	margin: 0 auto;
	padding: 4px max(var(--page-inset), var(--safe-right)) calc(32px + var(--tabbar-space, 0px) + var(--banner-space, 0px)) max(var(--page-inset), var(--safe-left));
}
.app[data-tabbar] {
	--tabbar-space: calc(var(--tabbar-height) + 12px + var(--safe-bottom));
}

/* Screen transitions: pushed screens come from the right, popped ones from the left. */
.screen.enter-push {
	animation: push-in var(--medium) var(--ease) both;
}
.screen.enter-pop {
	animation: pop-in var(--medium) var(--ease) both;
}
.screen.enter-fade {
	animation: fade-in var(--fast) ease-out both;
}
@keyframes push-in {
	from {
		transform: translateX(28%);
		opacity: 0;
	}
}
@keyframes pop-in {
	from {
		transform: translateX(-12%);
		opacity: 0;
	}
}
@keyframes fade-in {
	from {
		opacity: 0;
	}
}

/* Swipe back (js/ui/back-swipe.js): the screen follows the finger; the screen it came from lies
   underneath, a little to the left and a little darker, and comes forward as the top one leaves. */
.screen.swipe-top {
	z-index: 2;
	box-shadow:
		-0.5px 0 0 var(--line),
		-16px 0 36px rgba(0, 0, 0, 0.16);
	will-change: transform;
}
.screen.swipe-under {
	pointer-events: none;
	will-change: transform;
}
.screen.swipe-under::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 60;
	background: #000;
	opacity: var(--swipe-dim, 0);
	pointer-events: none;
}
.stage[data-swipe="settling"] .screen.swipe-top,
.stage[data-swipe="settling"] .screen.swipe-under {
	transition: transform var(--medium) var(--ease);
}
.stage[data-swipe="settling"] .screen.swipe-under::after {
	transition: opacity var(--medium) var(--ease);
}

/* ---- navigation bar ---------------------------------------------------------------------- */

.navbar {
	position: relative;
	z-index: 5;
	flex-shrink: 0;
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
	align-items: center;
	gap: 8px;
	min-height: calc(var(--navbar-height) + var(--safe-top));
	padding: var(--safe-top) max(8px, var(--safe-right)) 0 max(8px, var(--safe-left));
	background: transparent;
	transition: background var(--fast), box-shadow var(--fast);
}
.navbar[data-scrolled],
.navbar[data-solid] {
	background: var(--bar);
	-webkit-backdrop-filter: saturate(180%) blur(20px);
	backdrop-filter: saturate(180%) blur(20px);
	box-shadow: 0 0.5px 0 var(--line);
}
.navbar-title {
	grid-column: 2;
	min-width: 0;
	max-width: min(60vw, 420px);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	font-size: var(--text-headline);
	font-weight: 600;
	text-align: center;
	opacity: 0;
	transform: translateY(4px);
	transition: opacity var(--fast), transform var(--fast);
}
.navbar[data-scrolled] .navbar-title,
.navbar[data-compact] .navbar-title {
	opacity: 1;
	transform: none;
}
.navbar-title small {
	display: block;
	font-size: var(--text-caption2);
	font-weight: 500;
	color: var(--muted);
}
.navbar-start,
.navbar-end {
	display: flex;
	align-items: center;
	gap: 6px;
	min-width: 0;
}
.navbar-start {
	grid-column: 1;
	justify-content: flex-start;
}
.navbar-end {
	grid-column: 3;
	justify-content: flex-end;
}
.nav-back {
	display: inline-flex;
	align-items: center;
	gap: 2px;
	min-height: var(--touch);
	max-width: 100%;
	padding: 0 8px 0 2px;
	color: var(--accent);
	font-size: var(--text-body);
	border-radius: 22px;
}
.nav-back .icon {
	width: 26px;
	height: 26px;
	stroke-width: 2.2;
}
.nav-back span {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
/* Telegram draws its own Back button in its header. */
[data-native-back] .nav-back {
	display: none;
}

/* Glass circle buttons, as in iOS 26 bars. */
.nav-button {
	display: inline-grid;
	place-items: center;
	min-width: 38px;
	height: 38px;
	padding: 0 10px;
	border-radius: 19px;
	color: var(--accent);
	background: var(--glass);
	box-shadow: inset 0 0 0 0.5px var(--glass-line), 0 1px 6px #0000000f;
	-webkit-backdrop-filter: blur(16px) saturate(170%);
	backdrop-filter: blur(16px) saturate(170%);
	font-size: var(--text-subheadline);
	font-weight: 600;
	transition: transform var(--fast) var(--ease), background var(--fast);
}
.nav-button:active {
	transform: scale(0.92);
}
.nav-button .icon {
	width: 21px;
	height: 21px;
	stroke-width: 2;
}
.nav-button[data-variant="primary"] {
	background: var(--fill);
	color: var(--on-accent);
	box-shadow: none;
}
.nav-button:disabled {
	opacity: 0.45;
}

.large-title {
	padding: 2px max(var(--page-inset), var(--safe-right)) 10px max(var(--page-inset), var(--safe-left));
	max-width: var(--content-max);
	margin: 0 auto;
	width: 100%;
}
.large-title h1 {
	font: 700 var(--text-large-title) / 1.2 var(--font-display);
	letter-spacing: -0.02em;
	overflow-wrap: anywhere;
}
.large-title p {
	margin-top: 4px;
	color: var(--muted);
	font-size: var(--text-subheadline);
}
.workspace-chip {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	margin-top: 4px;
	min-height: 32px;
	padding: 0 10px 0 12px;
	border-radius: 16px;
	background: var(--soft);
	color: var(--text);
	font-size: var(--text-footnote);
	font-weight: 600;
}
.workspace-chip .icon {
	width: 16px;
	height: 16px;
	color: var(--muted);
}

/* ---- tab bar (phones) -------------------------------------------------------------------- */

.tabbar {
	position: absolute;
	z-index: 20;
	left: 50%;
	bottom: calc(10px + var(--safe-bottom));
	display: grid;
	grid-auto-flow: column;
	grid-auto-columns: 1fr;
	gap: 2px;
	width: min(calc(100% - 2 * max(16px, var(--safe-left))), 440px);
	height: var(--tabbar-height);
	padding: 5px;
	border-radius: calc(var(--tabbar-height) / 2);
	transform: translateX(-50%);
	background: var(--glass);
	box-shadow: inset 0 0 0 0.5px var(--glass-line), var(--glass-shadow);
	-webkit-backdrop-filter: blur(24px) saturate(180%);
	backdrop-filter: blur(24px) saturate(180%);
	transition: transform var(--medium) var(--ease), opacity var(--medium);
}
.app:not([data-tabbar]) .tabbar {
	transform: translate(-50%, calc(100% + 40px));
	opacity: 0;
	pointer-events: none;
}
.tab {
	position: relative;
	display: grid;
	justify-items: center;
	align-content: center;
	gap: 1px;
	min-width: 0;
	border-radius: calc(var(--tabbar-height) / 2 - 5px);
	color: var(--text);
	font-size: var(--text-caption2);
	font-weight: 600;
	letter-spacing: 0.01em;
	transition: background var(--fast), color var(--fast), transform var(--fast) var(--ease);
}
.tab span:last-child {
	max-width: 100%;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	padding: 0 2px;
}
.tab .icon {
	width: 25px;
	height: 25px;
	stroke-width: 1.8;
}
.tab[aria-current="page"] {
	color: var(--accent);
	background: var(--soft);
}
.tab:active {
	transform: scale(0.94);
}
.tab:focus-visible {
	outline-offset: -3px;
}
.tab-icon {
	position: relative;
	display: grid;
}
.badge {
	display: inline-grid;
	place-items: center;
	min-width: 18px;
	height: 18px;
	padding: 0 5px;
	border-radius: 9px;
	background: var(--system-red);
	color: #fff;
	font-size: var(--text-caption2);
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	line-height: 1;
}
.tab .badge {
	position: absolute;
	top: -4px;
	right: -10px;
	box-shadow: 0 0 0 2px var(--bar-solid);
}

/* ---- sidebar (wide screens) -------------------------------------------------------------- */

.sidebar {
	display: none;
}

@media (min-width: 960px) {
	.app {
		grid-template-columns: 320px minmax(0, 1fr);
	}
	.tabbar {
		display: none;
	}
	.app[data-tabbar] {
		--tabbar-space: 0px;
	}
	.sidebar {
		grid-row: 1;
		display: flex;
		flex-direction: column;
		min-height: 0;
		background: var(--sidebar);
		border-right: 0.5px solid var(--line);
		padding-top: var(--safe-top);
	}
	.app[data-chrome="hidden"] {
		grid-template-columns: minmax(0, 1fr);
	}
	.app[data-chrome="hidden"] .sidebar {
		display: none;
	}
	/* Bar items line up with the content column instead of the window edges. */
	.navbar {
		padding-inline: max(16px, calc((100% - var(--content-max)) / 2));
	}
	.chat-screen .navbar {
		padding-inline: max(16px, calc((100% - var(--chat-max)) / 2));
	}
	/* Top-level screens and conversations have no Back on desktop: the sidebar is the way around. */
	.screen[data-top] .nav-back,
	.chat-screen .nav-back {
		display: none;
	}
}
.sidebar-head {
	display: grid;
	gap: 10px;
	padding: 14px 12px 8px;
}
.brand {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 2px 6px;
}
.brand-mark {
	display: grid;
	place-items: center;
	width: 30px;
	height: 30px;
	border-radius: 9px;
	background: linear-gradient(145deg, #3d8bff, #6a5cff 55%, #b85cff);
	color: #fff;
}
.brand-mark .icon {
	width: 18px;
	height: 18px;
	stroke-width: 2;
}
.brand strong {
	font-size: var(--text-headline);
	font-weight: 700;
	letter-spacing: -0.01em;
}
.brand small {
	display: block;
	color: var(--muted);
	font-size: var(--text-caption);
	font-weight: 500;
}
.workspace-switch {
	display: flex;
	align-items: center;
	gap: 10px;
	width: 100%;
	min-height: 44px;
	padding: 6px 10px;
	border-radius: 12px;
	background: var(--card);
	box-shadow: var(--shadow-card), inset 0 0 0 0.5px var(--line);
	text-align: start;
}
.workspace-switch:hover {
	background: color-mix(in srgb, var(--card) 92%, var(--text));
}
.workspace-switch .ws-text {
	flex: 1;
	min-width: 0;
}
.workspace-switch strong,
.workspace-switch small {
	display: block;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.workspace-switch strong {
	font-size: var(--text-subheadline);
	font-weight: 600;
}
.workspace-switch small {
	color: var(--muted);
	font-size: var(--text-caption);
}
.workspace-switch > .icon {
	width: 16px;
	height: 16px;
	color: var(--muted);
}
.ws-avatar {
	display: grid;
	place-items: center;
	width: 28px;
	height: 28px;
	flex-shrink: 0;
	border-radius: 8px;
	background: var(--tint-fill);
	color: var(--accent);
	font-size: var(--text-footnote);
	font-weight: 700;
}
.new-chat {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	min-height: 40px;
	border-radius: 12px;
	background: var(--fill);
	color: var(--on-accent);
	font-size: var(--text-subheadline);
	font-weight: 600;
}
.new-chat:hover {
	background: var(--fill-strong);
}
/* The sections and the chat list share one scroller: an unfolded group pushes the chats down
   instead of squeezing them out. */
.side-scroll {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
}
.side-nav {
	display: grid;
	gap: 1px;
	padding: 4px 12px 8px;
}
/* A group of sections: its heading folds it, as a sidebar section does on iPadOS. */
.side-group {
	display: grid;
	gap: 1px;
}
.side-group-head {
	display: flex;
	align-items: center;
	gap: 8px;
	min-height: 30px;
	margin-top: 6px;
	padding: 0 10px;
	border-radius: 8px;
	color: var(--muted);
	font-size: var(--text-caption);
	font-weight: 600;
	letter-spacing: 0.04em;
	text-align: start;
	text-transform: uppercase;
}
.side-group-head > span:first-child {
	flex: 1;
}
.side-group-head:hover {
	background: var(--press);
	color: var(--text);
}
.side-group-head .chev {
	width: 14px;
	height: 14px;
	transition: transform 0.2s var(--ease-out, ease);
}
.side-group[data-open] > .side-group-head .chev {
	transform: rotate(90deg);
}
.side-group-items {
	display: grid;
	gap: 1px;
}
.side-link .status-dot,
.side-group-head .status-dot {
	flex: none;
}
@media (prefers-reduced-motion: reduce) {
	.side-group-head .chev {
		transition: none;
	}
}
.side-link {
	display: flex;
	align-items: center;
	gap: 10px;
	min-height: 36px;
	padding: 0 10px;
	border-radius: 10px;
	color: var(--text);
	font-size: var(--text-subheadline);
	text-align: start;
}
.side-link .icon {
	width: 19px;
	height: 19px;
	color: var(--muted);
}
.side-link > span:not(.badge, .status-dot) {
	flex: 1;
}
.side-link:hover {
	background: var(--press);
}
.side-link[aria-current="page"] {
	background: var(--soft);
	font-weight: 600;
}
.side-link[aria-current="page"] .icon {
	color: var(--accent);
}
.side-section {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 10px 22px 4px;
	color: var(--muted);
	font-size: var(--text-caption);
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.04em;
}
.side-threads {
	padding: 0 12px 12px;
}
.side-foot {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 10px 22px calc(12px + var(--safe-bottom));
	border-top: 0.5px solid var(--line);
	color: var(--muted);
	font-size: var(--text-caption);
}
.side-foot strong {
	flex: 1;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	color: var(--text);
	font-weight: 600;
}

/* Connection state, shown quietly. */
.live-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--system-gray);
	flex-shrink: 0;
}
.live-dot[data-state="open"] {
	background: var(--system-green);
}
.live-dot[data-state="retrying"],
.live-dot[data-state="connecting"] {
	background: var(--system-orange);
}
.live-banner {
	position: absolute;
	z-index: 30;
	top: calc(var(--safe-top) + 6px);
	left: 50%;
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 6px 12px;
	border-radius: 16px;
	background: var(--glass);
	box-shadow: inset 0 0 0 0.5px var(--glass-line), var(--glass-shadow);
	-webkit-backdrop-filter: blur(20px) saturate(180%);
	backdrop-filter: blur(20px) saturate(180%);
	color: var(--text);
	font-size: var(--text-footnote);
	font-weight: 600;
	transform: translateX(-50%);
	animation: drop-in var(--medium) var(--ease) both;
}
.live-banner .icon {
	width: 16px;
	height: 16px;
	color: var(--system-orange);
}
@keyframes drop-in {
	from {
		transform: translate(-50%, -150%);
		opacity: 0;
	}
}

/* Reduced transparency or more contrast: solid bars. */
@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
	.navbar[data-scrolled],
	.navbar[data-solid],
	.tabbar,
	.nav-button,
	.live-banner {
		background: var(--bar-solid);
		-webkit-backdrop-filter: none;
		backdrop-filter: none;
	}
	.tabbar {
		box-shadow: 0 0 0 1px var(--line), var(--glass-shadow);
	}
}
