/* Responsive top navigation: keep every primary control visible and inside its frame. */
.topbar {
	min-width: 0;
}

.brand {
	min-width: 0;
}

.brand > span:nth-child(2) {
	min-width: 0;
	white-space: nowrap;
}

.top-actions {
	min-width: 0;
	flex-wrap: wrap;
}

.top-actions button {
	flex: 0 0 auto;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* The header identifies the world; actions live in an always-reachable command dock. */
@media (min-width: 821px) {
	body {
		overflow: visible !important;
	}

	.topbar {
		position: sticky;
		top: 0;
		z-index: 80;
		display: grid;
		grid-template-columns: minmax(0, 1fr) auto;
		grid-template-areas: "brand actions" "signal signal";
		align-items: center;
		column-gap: 18px;
		row-gap: 10px;
		height: auto;
		min-height: 64px;
		padding-bottom: 12px;
		background: linear-gradient(180deg, rgba(8, 12, 19, .98) 0%, rgba(8, 12, 19, .92) 88%, transparent 100%);
	}

	.topbar .brand { grid-area: brand; }
	.topbar .signal { grid-area: signal; }

	.top-actions {
		grid-area: actions;
		position: sticky;
		top: 12px;
		display: flex;
		flex-direction: row;
		flex-wrap: nowrap;
		gap: 7px;
		align-items: center;
		justify-content: flex-end;
		width: max-content;
		max-width: 100%;
		padding: 6px;
		border: 1px solid #31505c;
		background: linear-gradient(180deg, rgba(16, 32, 43, .96), rgba(8, 14, 21, .96));
		box-shadow: 0 8px 22px rgba(0, 0, 0, .25), inset 0 2px 0 var(--cyan);
		pointer-events: auto;
	}

	.top-actions::before {
		content: "COMMAND";
		padding: 0 5px;
		border-right: 1px solid var(--line);
		border-bottom: 1px solid var(--line);
		color: var(--muted);
		font-size: 8px;
		letter-spacing: 1.4px;
		text-align: center;
	}

	.top-actions .save-state {
		order: 10;
		max-width: 84px;
		padding-left: 5px;
		border-left: 1px solid var(--line);
		border-top: 1px solid var(--line);
		font-size: 8px;
		line-height: 1.35;
		text-align: center;
		white-space: normal;
	}

	.top-actions button {
		width: 36px;
		min-width: 36px;
		min-height: 34px;
		padding: 7px 6px;
		background: #0b151e;
		border-color: #263f4b;
		font-size: 9px;
		pointer-events: auto;
	}

	.top-actions button:hover,
	.top-actions button:focus-visible {
		border-color: var(--cyan);
		box-shadow: 0 0 14px rgba(61, 229, 208, .16);
		outline: none;
	}

	.top-actions .workspace-launcher,
	.top-actions .district-launcher {
		width: 108px;
		min-width: 108px;
		height: auto;
		min-height: 34px;
		justify-content: flex-start;
	}

	.top-actions .workspace-launcher span:last-child,
	.top-actions .district-launcher span:last-child {
		display: inline;
		min-width: 0;
		white-space: nowrap;
	}

	.top-actions .login-btn { width: 88px; min-width: 88px; }

	.rightbar.workspace-drawer {
		right: 0 !important;
		left: auto !important;
	}
}

@media (min-width: 821px) {
	.workspace-drawer,
	.district.district-drawer {
		top: 112px !important;
	}

	.rightbar.workspace-drawer {
		left: auto !important;
		right: 0 !important;
	}
}

@media (min-width: 821px) and (max-width: 1100px) {
	.top-actions {
		gap: 5px;
	}

	.top-actions .workspace-launcher,
	.top-actions .district-launcher,
	.top-actions button {
		width: 36px;
		min-width: 36px;
		padding: 7px 4px;
		justify-content: center;
	}

	.top-actions .workspace-launcher span:last-child,
	.top-actions .district-launcher span:last-child,
	.top-actions .save-state {
		display: none;
	}

	.top-actions .login-btn {
		width: 36px !important;
		min-width: 36px !important;
		font-size: 0;
	}

	.top-actions .login-btn::after {
		content: "ID";
		font: 700 9px var(--mono);
	}
}

@media (max-width: 820px) {
	.topbar {
		padding-bottom: 58px;
	}

	.top-actions {
		position: fixed;
		left: 50%;
		bottom: 10px;
		z-index: 70;
		display: flex;
		align-items: center;
		justify-content: center;
		gap: 5px;
		width: max-content;
		max-width: calc(100vw - 20px);
		padding: 6px;
		border: 1px solid #31505c;
		background: rgba(8, 14, 21, .94);
		box-shadow: 0 10px 30px rgba(0, 0, 0, .45), inset 0 2px 0 var(--cyan);
		transform: translateX(-50%);
		backdrop-filter: blur(12px);
	}

	.top-actions .save-state {
		display: none;
	}

	.top-actions button,
	.top-actions .workspace-launcher,
	.top-actions .district-launcher {
		width: 34px;
		min-width: 34px;
		height: 34px;
		min-height: 34px;
		padding: 0 !important;
		justify-content: center;
		font-size: 0 !important;
	}

	.top-actions .workspace-launcher span:first-child,
	.top-actions .district-launcher span:first-child {
		display: inline !important;
		margin: 0;
		font-size: 16px;
	}

	.top-actions .audio-btn,
	.top-actions .help-btn,
	.top-actions .icon-btn,
	.top-actions .lang-btn {
		font-size: 16px !important;
	}

	.top-actions .login-btn {
		font-size: 0 !important;
	}

	.top-actions .login-btn::after {
		content: attr(data-auth-label);
		font: 700 10px var(--mono);
		color: currentColor;
	}
}

/* Desktop OPS drawer owns the right edge; mobile keeps its centered drawer rules above. */
@media (min-width: 821px) {
	.rightbar.workspace-drawer {
		left: auto !important;
		right: 0 !important;
	}

	.workspace-drawer,
	.district.district-drawer {
		top: 112px !important;
		z-index: 90 !important;
	}

	.workspace-drawer-close {
		position: sticky;
		top: 0;
		z-index: 100 !important;
	}

	body .layout > .sidebar.workspace-drawer,
	body .layout > .rightbar.workspace-drawer,
	body > .district.district-drawer,
	body .rightbar > .district.district-drawer {
		top: 132px !important;
		height: auto !important;
		max-height: calc(100vh - 148px) !important;
		bottom: 16px !important;
		overflow-y: auto !important;
	}
}

/* Keep the drawer close row as the only sticky header inside the scrolling panel. */
.workspace-drawer .panel-heading {
	position: static !important;
}

.decrypted-skills {
	margin-top: 12px;
	padding-top: 12px;
	border-top: 1px solid rgba(61, 229, 208, .18);
}

.decrypted-skills-heading {
	display: grid;
	gap: 3px;
	margin-bottom: 7px;
	color: var(--cyan);
	font-size: 10px;
}

.decrypted-skills-heading small {
	color: var(--muted);
	font-size: 9px;
}

.decrypted-skill-row {
	display: grid;
	grid-template-columns: 24px minmax(0, 1fr) auto;
	align-items: center;
	gap: 7px;
	margin: 5px 0;
	padding: 8px;
	border: 1px solid var(--line);
	background: #0b121b;
}

.decrypted-skill-row.active {
	border-color: #24524e;
	background: #10252b;
}

.decrypted-skill-icon {
	color: var(--pink);
	font-size: 16px;
	text-align: center;
}

.decrypted-skill-copy {
	display: grid;
	min-width: 0;
	gap: 3px;
}

.decrypted-skill-copy b,
.decrypted-skill-copy small {
	overflow-wrap: anywhere;
}

.decrypted-skill-copy b {
	font-size: 10px;
}

.decrypted-skill-copy small {
	color: var(--muted);
	font-size: 9px;
	line-height: 1.4;
}

.decrypted-skill-toggle {
	border: 1px solid #24524e;
	background: #10252b;
	color: var(--cyan);
	padding: 6px 7px;
	font: 9px var(--mono);
	white-space: nowrap;
	cursor: pointer;
}

.decrypted-skill-row.active .decrypted-skill-toggle {
	border-color: #604b2d;
	background: #2b2230;
	color: var(--amber);
}

.workspace-drawer-close {
	display: flex;
	align-items: center;
	justify-content: space-between;
	order: -10 !important;
	flex: 0 0 auto !important;
	align-self: stretch;
	box-sizing: border-box;
	position: sticky;
	top: 0;
	z-index: 8;
	width: 100%;
	margin: -18px 0 14px;
	padding: 9px 2px 8px;
	border: 0;
	border-bottom: 1px solid var(--line);
	background: #10202b;
	color: var(--muted);
	font: 9px var(--mono);
	letter-spacing: 1px;
	text-align: left;
	cursor: pointer;
}

/* Runner telemetry must sit above the sticky desktop header. */
.values-modal {
	z-index: 110 !important;
}

.values-modal .values-box {
	position: relative;
	z-index: 111;
	align-self: start;
	margin: 128px auto 20px;
	max-height: calc(100vh - 148px);
	overflow-y: auto;
}

.values-modal .close-btn {
	z-index: 120 !important;
	pointer-events: auto;
}

.workspace-drawer {
	display: flex !important;
	flex-direction: column !important;
	align-items: stretch;
}

.workspace-drawer::after {
	content: none !important;
}

.workspace-icon {
	display: block;
	width: 17px;
	height: 17px;
	flex: 0 0 17px;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.7;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.top-actions .workspace-launcher,
.top-actions .district-launcher {
	align-items: center;
}

.top-actions .workspace-launcher[aria-expanded="true"] .workspace-icon,
.top-actions .district-launcher[aria-expanded="true"] .workspace-icon {
	filter: drop-shadow(0 0 5px currentColor);
}

.workspace-drawer-close span:first-child {
	color: var(--pink);
	font-size: 18px;
	line-height: 12px;
}

.workspace-drawer-close:hover,
.workspace-drawer-close:focus-visible {
	color: var(--text);
	border-bottom-color: var(--cyan);
	outline: none;
}

@media (max-width: 820px) {
	.workspace-drawer-close {
		margin: -14px 0 14px;
	}
}

/* Drawer copy is instructional content, so never truncate it into an ellipsis. */
.workspace-drawer .market-item small,
.workspace-drawer .upgrade-item small,
.workspace-drawer .install-record small {
	white-space: normal !important;
	overflow: visible !important;
	text-overflow: clip !important;
	line-height: 1.45;
	word-break: break-word;
}

.workspace-drawer .market-item > span:nth-child(2),
.workspace-drawer .upgrade-item > span:nth-child(2) {
	min-width: 0;
	flex: 1 1 auto;
}

@media (max-width: 380px) {
	.top-actions {
		gap: 3px;
		padding: 5px;
	}

	.top-actions button,
	.top-actions .workspace-launcher,
	.top-actions .district-launcher {
		width: 31px;
		min-width: 31px;
		height: 31px;
		min-height: 31px;
	}
}

@media (max-width: 820px) {
	.topbar {
		display: grid;
		grid-template-columns: minmax(0, 1fr) auto;
		grid-template-areas: "brand actions" "signal signal";
		align-items: center;
		column-gap: 12px;
		row-gap: 8px;
		padding-bottom: 8px;
	}

	.brand { grid-area: brand; }
	.brand small,
	.signal,
	.save-state { display: none; }

	.top-actions {
		grid-area: actions;
		justify-content: flex-end;
		gap: 6px;
	}

	.top-actions button {
		min-width: 30px;
		min-height: 32px;
	}

	.workspace-launcher span:first-child,
	.district-launcher span:first-child {
		display: inline !important;
		margin: 0;
	}

	.audio-btn,
	.help-btn {
		width: 32px;
		height: 32px;
	}

	.lang-btn { padding: 7px 8px !important; }
	.login-btn { max-width: 94px; padding: 7px 9px !important; }
}

@media (max-width: 560px) {
	.topbar {
		grid-template-columns: minmax(0, 1fr);
		grid-template-areas: "brand" "actions";
		row-gap: 10px;
	}

	.top-actions {
		display: grid;
		grid-template-columns: repeat(4, minmax(0, 1fr));
		width: 100%;
		gap: 6px;
	}

	.top-actions button {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		gap: 3px;
		width: 100%;
		min-height: 38px;
		min-width: 0;
		padding-left: 3px !important;
		padding-right: 3px !important;
		font-size: 10px !important;
		line-height: 1.2;
		white-space: normal;
		overflow: visible;
		text-overflow: clip;
	}

	.workspace-launcher span,
	.district-launcher span { display: inline !important; }
	.login-btn {
		max-width: none;
		font-size: 9px !important;
		white-space: nowrap !important;
	}
}

@media (max-width: 360px) {
	.shell {
		padding-left: 10px;
		padding-right: 10px;
	}

	.brand {
		gap: 7px;
		font-size: 17px;
	}

	.brand-mark {
		padding-left: 4px;
		padding-right: 4px;
	}

	.top-actions { gap: 4px; }
	.top-actions button { font-size: 11px !important; }
}

/* Keep the compact dock above the legacy small-screen grid rules. */
@media (max-width: 820px) {
	.top-actions {
		display: flex !important;
		width: max-content !important;
		max-width: calc(100vw - 20px) !important;
		grid-template-columns: none !important;
	}

	.top-actions button,
	.top-actions .workspace-launcher,
	.top-actions .district-launcher {
		width: 34px !important;
		min-width: 34px !important;
		max-width: 34px !important;
		height: 34px !important;
		min-height: 34px !important;
		padding: 0 !important;
		font-size: 0 !important;
		white-space: nowrap !important;
	}

	.top-actions .workspace-launcher span:first-child,
	.top-actions .district-launcher span:first-child {
		display: inline !important;
		font-size: 16px !important;
	}

	.top-actions .audio-btn,
	.top-actions .help-btn,
	.top-actions .icon-btn,
	.top-actions .lang-btn {
		font-size: 16px !important;
	}

	.top-actions .login-btn::after {
		font-size: 9px !important;
	}
}

@media (max-width: 380px) {
	.top-actions button,
	.top-actions .workspace-launcher,
	.top-actions .district-launcher {
		width: 31px !important;
		min-width: 31px !important;
		max-width: 31px !important;
		height: 31px !important;
		min-height: 31px !important;
	}
}

/* The dock is the final navigation layer, so an opened drawer must win the transform cascade. */
.workspace-drawer.is-open,
.district.district-drawer.is-open {
	transform: translateX(0) !important;
}

/* Closed drawers must be completely absent, not merely shifted beyond the viewport. */
.workspace-drawer:not(.is-open),
.district.district-drawer:not(.is-open) {
	visibility: hidden !important;
	pointer-events: none !important;
}

.workspace-drawer.is-open,
.district.district-drawer.is-open {
	visibility: visible !important;
	pointer-events: auto !important;
}

/* Reserve a clear lane between the right-side drawer and the command dock. */
@media (min-width: 821px) {
	.rightbar.workspace-drawer,
	.rightbar > .district.district-drawer {
		left: auto !important;
		right: 130px !important;
		width: min(360px, calc(100vw - 152px)) !important;
	}

	.top-actions .workspace-launcher[aria-expanded="true"],
	.top-actions .district-launcher[aria-expanded="true"] {
		border-color: var(--cyan) !important;
		background: var(--cyan) !important;
		color: #071316 !important;
		box-shadow: 0 0 18px rgba(61, 229, 208, .38), inset 0 -3px 0 rgba(7, 19, 22, .22) !important;
	}

	.top-actions .workspace-launcher[aria-expanded="true"] span,
	.top-actions .district-launcher[aria-expanded="true"] span {
		color: inherit;
	}
}

/* The bottom dock owns the lower edge on touch screens; drawers stop above it. */
@media (max-width: 820px) {
	.workspace-drawer,
	.district.district-drawer,
	.rightbar > .district.district-drawer {
		left: 50% !important;
		right: auto !important;
		bottom: 66px !important;
		width: min(350px, calc(100vw - 18px)) !important;
	}

	.workspace-drawer.is-open,
	.district.district-drawer.is-open {
		transform: translateX(-50%) !important;
	}

	.layout > .sidebar.workspace-drawer,
	.layout > .rightbar.workspace-drawer,
	.rightbar > .district.district-drawer {
		left: 50% !important;
		right: auto !important;
		bottom: 66px !important;
		height: calc(100vh - 128px) !important;
		max-height: none !important;
		overflow-y: auto !important;
	}

	.layout > .sidebar.workspace-drawer.is-open,
	.layout > .rightbar.workspace-drawer.is-open,
	.rightbar > .district.district-drawer.is-open {
		transform: translateX(-50%) !important;
	}

	.top-actions .workspace-launcher[aria-expanded="true"],
	.top-actions .district-launcher[aria-expanded="true"] {
		border-color: var(--amber) !important;
		background: #2b2230 !important;
		color: var(--amber) !important;
		box-shadow: 0 0 14px rgba(255, 186, 92, .28), inset 0 -2px 0 rgba(255, 186, 92, .25) !important;
	}
}

@media (min-width: 821px) {
	.rightbar.workspace-drawer {
		left: auto !important;
		right: 0 !important;
	}
}
