:root {
	--wachapp-windows-titlebar-height: 46px;
	--wachapp-windows-device-safe-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
	--wachapp-windows-safe-top-space: calc(var(--wachapp-windows-titlebar-height) + max(0px, var(--wachapp-windows-device-safe-top)));
}

.wachapp-windows-titlebar {
	display: none;
}

html.wachapp-windows-titlebar-active {
	/*
	 * Das bestehende globale Safe-Area-System bleibt die einzige Quelle für
	 * alle Komponenten. Windows erweitert dessen oberen Wert lediglich um die
	 * eigene Titelleiste. Dadurch funktionieren auch dynamisch erzeugte und
	 * fixierte Elemente ohne Windows-spezifische Einzelregeln.
	 */
	--safe-top: var(--wachapp-windows-safe-top-space);
	--safe-top-space: var(--wachapp-windows-safe-top-space);
	--wa-sticky-nav-offset: var(--wachapp-windows-safe-top-space);
	scroll-padding-top: calc(var(--wachapp-windows-safe-top-space) + .75rem);
}

html.wachapp-windows-titlebar-active::before {
	position: fixed;
	top: 0;
	right: 0;
	left: 0;
	z-index: 2147482999;
	height: var(--wachapp-windows-titlebar-height);
	border-bottom: 1px solid rgba(255, 255, 255, .09);
	background: #101114;
	box-shadow: 0 1px 0 rgba(0, 0, 0, .55);
	content: "";
	pointer-events: none;
}

html.wachapp-windows-titlebar-active body {
	box-sizing: border-box;
	min-height: 100vh !important;
	/*
	 * Nicht nur die sichtbare Titelleiste, sondern die vollständige
	 * Windows-Safe-Area bildet den Inhaltsursprung.
	 */
	padding-top: var(--wachapp-windows-safe-top-space) !important;
}

html.wachapp-windows-titlebar-active .sticky-top {
	top: var(--wachapp-windows-safe-top-space);
}

/*
 * Arena-Benachrichtigungen verwenden historisch den nativen env()-Wert
 * direkt. WebView2 liefert dafür 0px, obwohl die eigene Windows-Titelleiste
 * den oberen Viewportbereich belegt. Der Windows-Adapter übernimmt deshalb
 * zentral die Positionierung, ohne die Arena-, Web-, PWA- oder Android-Styles
 * verändern zu müssen.
 *
 * Unterhalb von 576px bleibt die vorhandene mobile Bottom-Position erhalten.
 */
@media (min-width: 576px) {
	html.wachapp-windows-titlebar-active .toast-arena-container {
		top: calc(var(--wachapp-windows-safe-top-space) + 1rem);
	}
}

/*
 * Bootstrap-Offcanvas verwendet im bestehenden Theme die älteren globalen
 * Aliasvariablen --sat und --sat-max. Die Aliase werden ausschließlich im
 * Viewport-Overlay gesetzt, damit normale Inhalts-Header nicht doppelt nach
 * unten verschoben werden.
 */
html.wachapp-windows-titlebar-active .offcanvas {
	--sat: var(--wachapp-windows-safe-top-space);
	--sat-max: var(--wachapp-windows-safe-top-space);
}

html.wachapp-windows-titlebar-active .wachapp-windows-titlebar {
	position: fixed;
	top: 0;
	right: 0;
	left: 0;
	z-index: 2147483000;
	display: flex !important;
	align-items: stretch;
	height: var(--wachapp-windows-titlebar-height);
	border-bottom: 1px solid rgba(255, 255, 255, .09);
	background: #101114;
	box-shadow: 0 1px 0 rgba(0, 0, 0, .55);
	color: #eef0f3;
	font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
	font-size: .875rem;
	line-height: 1;
	user-select: none;
	-webkit-user-select: none;
}

.wachapp-windows-titlebar__navigation,
.wachapp-windows-titlebar__actions {
	display: flex;
	align-items: stretch;
	flex: 0 0 auto;
}

.wachapp-windows-titlebar__drag-region {
	min-width: 1rem;
	flex: 0 1 1rem;
	cursor: default;
	touch-action: none;
}


/* ######## Update 04: native KnowListic-Tabs ######## */
.wachapp-windows-titlebar__tabs.d-none {
	display: none !important;
}

.wachapp-windows-titlebar__tabs {
	display: flex;
	align-items: center;
	min-width: 0;
	max-width: none;
	width: auto;
	height: 100%;
	padding: 0 .25rem;
	overflow-x: auto;
	overflow-y: hidden;
	flex: 1 1 auto;
	scrollbar-width: none;
	overscroll-behavior-x: contain;
}

.wachapp-windows-titlebar__tabs::-webkit-scrollbar {
	display: none;
}

.wachapp-windows-tab {
	display: flex;
	align-items: center;
	flex: 1 1 0;
	min-width: 4.75rem;
	max-width: 15rem;
	height: 34px;
	margin: 6px 2px;
	border: 1px solid transparent;
	border-radius: .5rem;
	background: rgba(255, 255, 255, .045);
	color: #b9bec7;
	transition: background-color .12s ease, border-color .12s ease, color .12s ease;
}

.wachapp-windows-tab:hover {
	background: rgba(255, 255, 255, .08);
	color: #f7f8fa;
}

.wachapp-windows-tab.is-active {
	border-color: rgba(255, 255, 255, .1);
	background: rgba(255, 255, 255, .13);
	color: #fff;
}

.wachapp-windows-tab__activate {
	display: flex;
	align-items: center;
	min-width: 0;
	height: 100%;
	padding: 0 .35rem 0 .65rem;
	border: 0;
	background: transparent;
	color: inherit;
	font: inherit;
	text-align: left;
	cursor: default;
	flex: 1 1 auto;
}

.wachapp-windows-tab__activate:focus-visible,
.wachapp-windows-tab__close:focus-visible {
	outline: 0;
	box-shadow: inset 0 0 0 2px rgba(94, 168, 255, .9);
}

.wachapp-windows-tab__icon {
	margin-right: .42rem;
	font-size: .82rem;
	opacity: .78;
	flex: 0 0 auto;
}

.wachapp-windows-tab__title {
	display: block;
	min-width: 0;
	overflow: hidden;
	font-size: .79rem;
	font-weight: 500;
	line-height: 1;
	white-space: nowrap;
	text-overflow: ellipsis;
}

.wachapp-windows-tab__close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	min-width: 28px;
	height: 28px;
	margin-right: 2px;
	padding: 0;
	border: 0;
	border-radius: .4rem;
	background: transparent;
	color: currentColor;
	font-size: .72rem;
	cursor: default;
	opacity: .66;
}

.wachapp-windows-tab__close:hover {
	background: rgba(255, 255, 255, .12);
	opacity: 1;
}

.wachapp-windows-tab.is-primary .wachapp-windows-tab__activate {
	padding-right: .65rem;
}

.wachapp-windows-titlebar__button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 43px;
	min-width: 43px;
	height: 100%;
	padding: 0;
	border: 0;
	border-radius: 0;
	background: transparent;
	box-shadow: none;
	color: #d9dde3;
	font: inherit;
	font-size: 1.02rem;
	line-height: 1;
	text-decoration: none;
	cursor: default;
	transition: background-color .12s ease, color .12s ease, opacity .12s ease;
}

.wachapp-windows-titlebar__button:hover,
.wachapp-windows-titlebar__button:focus-visible,
.wachapp-windows-titlebar__button[aria-expanded="true"] {
	outline: 0;
	background: rgba(255, 255, 255, .09);
	color: #fff;
}

.wachapp-windows-titlebar__button:focus-visible {
	box-shadow: inset 0 0 0 2px rgba(94, 168, 255, .9);
}

.wachapp-windows-titlebar__button:disabled,
.wachapp-windows-titlebar__button[aria-disabled="true"] {
	opacity: .32;
	background: transparent;
	color: #aeb4bd;
}

.wachapp-windows-titlebar__connection {
	width: 46px;
	min-width: 46px;
	color: #aeb4bd;
	cursor: default;
}

.wachapp-windows-titlebar__connection:hover {
	background: transparent;
}

.wachapp-windows-titlebar__connection[data-quality="good"] {
	color: #4ade80;
}

.wachapp-windows-titlebar__connection[data-quality="slow"] {
	color: #facc15;
}

.wachapp-windows-titlebar__connection[data-quality="poor"],
.wachapp-windows-titlebar__connection[data-quality="offline"] {
	color: #fb7185;
}

.wachapp-windows-titlebar__avatar-button {
	width: 48px;
	min-width: 48px;
}

.wachapp-windows-titlebar__avatar-button img,
.wachapp-windows-titlebar__profile-head img {
	display: block;
	border: 1px solid rgba(255, 255, 255, .24);
	border-radius: 50%;
	background: #252932;
	object-fit: cover;
}

.wachapp-windows-titlebar__profile-menu {
	z-index: 2147483100;
	width: min(19rem, calc(100vw - 1rem));
	margin-top: .3rem !important;
	border-color: rgba(255, 255, 255, .11);
	border-radius: .85rem;
	box-shadow: 0 1.1rem 2.8rem rgba(0, 0, 0, .42);
}

.wachapp-windows-titlebar__profile-head {
	display: flex;
	align-items: center;
	gap: .75rem;
	min-width: 0;
}

.wachapp-windows-titlebar__profile-head .min-w-0 {
	min-width: 0;
}

.wachapp-windows-titlebar__profile-menu .dropdown-item {
	display: flex;
	align-items: center;
	min-height: 2.45rem;
}

.wachapp-windows-titlebar__separator {
	align-self: center;
	width: 1px;
	height: 22px;
	margin: 0 2px;
	background: rgba(255, 255, 255, .12);
}

.wachapp-windows-titlebar__window-button {
	width: 46px;
	min-width: 46px;
	font-size: .9rem;
}

.wachapp-windows-titlebar__close {
	width: 48px;
	min-width: 48px;
}

.wachapp-windows-titlebar__close:hover,
.wachapp-windows-titlebar__close:focus-visible {
	background: #c42b1c;
	color: #fff;
}

html.wachapp-windows-window-maximized .wachapp-windows-titlebar {
	box-shadow: none;
}

@media (max-width: 1100px) {
	.wachapp-windows-titlebar__button {
		width: 40px;
		min-width: 40px;
	}

	.wachapp-windows-titlebar__connection,
	.wachapp-windows-titlebar__avatar-button,
	.wachapp-windows-titlebar__close {
		width: 46px;
		min-width: 46px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.wachapp-windows-titlebar__button {
		transition: none;
	}
}

/*
 * WordPress-Backend in der nativen Windows-App
 * --------------------------------------------
 * wp-admin besitzt eine eigene fixe Adminbar und ein fixes Adminmenü. Die
 * normale Frontend-Regel `body { padding-top: ... }` reicht dort nicht aus
 * und würde die WordPress-Geometrie sogar doppelt verschieben. Deshalb wird
 * die komplette Admin-Chrome gezielt unter die KnowListic-Titelleiste gelegt.
 */
html.wachapp-windows-titlebar-active body.wp-admin {
	padding-top: 0 !important;
}

html.wachapp-windows-titlebar-active.wp-toolbar {
	padding-top: calc(var(--wp-admin--admin-bar--height, 32px) + var(--wachapp-windows-safe-top-space)) !important;
}

html.wachapp-windows-titlebar-active body.wp-admin #wpadminbar {
	top: var(--wachapp-windows-safe-top-space) !important;
}

html.wachapp-windows-titlebar-active body.wp-admin #adminmenuback,
html.wachapp-windows-titlebar-active body.wp-admin #adminmenuwrap {
	top: calc(var(--wp-admin--admin-bar--height, 32px) + var(--wachapp-windows-safe-top-space)) !important;
}

html.wachapp-windows-titlebar-active body.wp-admin #wpwrap,
html.wachapp-windows-titlebar-active body.wp-admin #wpcontent,
html.wachapp-windows-titlebar-active body.wp-admin #wpbody,
html.wachapp-windows-titlebar-active body.wp-admin #wpbody-content {
	box-sizing: border-box;
}

/* Im Backend wird für den Avatar bewusst kein Bootstrap-Dropdown benötigt. */
body.wp-admin .wachapp-windows-titlebar__avatar-button img {
	width: 28px;
	height: 28px;
}

@media screen and (max-width: 782px) {
	html.wachapp-windows-titlebar-active.wp-toolbar {
		padding-top: calc(var(--wp-admin--admin-bar--height, 46px) + var(--wachapp-windows-safe-top-space)) !important;
	}

	html.wachapp-windows-titlebar-active body.wp-admin #adminmenuback,
	html.wachapp-windows-titlebar-active body.wp-admin #adminmenuwrap {
		top: calc(var(--wp-admin--admin-bar--height, 46px) + var(--wachapp-windows-safe-top-space)) !important;
	}
}


@media (max-width: 900px) {
	.wachapp-windows-titlebar__tabs {
		max-width: 44vw;
	}

	.wachapp-windows-tab {
		min-width: 6.25rem;
		max-width: 11rem;
	}
}


/* ######## Update 04 Phase 1.4: Profilmenü im aktiven Child-Tab ######## */
.wachapp-windows-tab-profile-overlay {
	position: fixed;
	inset: 0;
	z-index: 2147483600;
	pointer-events: auto;
}

.wachapp-windows-tab-profile-overlay__backdrop {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	padding: 0;
	border: 0;
	background: transparent;
	cursor: default;
}

.wachapp-windows-tab-profile-overlay__menu {
	position: fixed !important;
	top: 6px !important;
	right: 174px !important;
	left: auto !important;
	z-index: 2147483601 !important;
	display: block !important;
	margin: 0 !important;
	transform: none !important;
}

@media (max-width: 760px) {
	.wachapp-windows-tab-profile-overlay__menu {
		right: 12px !important;
	}
}
