:root {
	--header-h: 64px;
	--sidebar-expanded: 240px;
	--sidebar-collapsed: 65px;
	--mobile-sidebar-w: 260px;
	--app-main-bg-img: url("/images/blurry-nebula2.jpg");
	--app-main-bg-overlay: rgba(0, 0, 0, .1);
	/* Header stays CONSTANT (does not change with theme) */
	--header-bg: #0b2e4a;
	--header-fg: rgba(255, 255, 255, .95);
	--radius: 14px;
	--gap: 1rem;
	--font-sans: "Roboto", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
	--font-mono: "SUSE Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
	/* THEME-VARIABLES (default = dark) */
	--page-bg-1: #071b22;
	--sidebar-bg: #5f7891;
	--sidebar-link-icon-size: 25px;
	--sidebar-link-bg: rgba(255, 255, 255, 0.315);
	--sidebar-link-hover-bg: rgba(255, 255, 255, .18);
	--sidebar-link-fg: rgba(0, 0, 0, .85);
	/* Active state */
	--sidebar-active-bg: rgb(28, 39, 48);
	--sidebar-active-fg: #389FFF;
	--sidebar-active-ring: rgba(255, 255, 255, .22);
	--tab-bg: rgba(255, 255, 255, .12);
	--tab-border: rgba(255, 255, 255, .08);
	--tab-fg: rgba(255, 255, 255, .90);
	--tab-active-bg: rgba(0, 0, 0, .55);
	--tab-active-border: rgba(255, 255, 255, .10);
	--panel-radial: rgba(255, 255, 255, .05);
	--panel-from: rgba(0, 0, 0, 0.7);
	--panel-to: rgba(0, 0, 0, 0.5);
	--panel-border: rgba(255, 255, 255, .06);
	--panel-fg: rgba(255, 255, 255, .90);
	--panel-inset-shadow: rgba(0, 0, 0, .35);
	--tree-bg-color: rgba(25, 29, 34, 0.904);
	/* Buttons (header stays same; we keep button styling neutral) */
	--icon-btn-border: rgba(255, 255, 255, .14);
	--icon-btn-bg: rgba(0, 0, 0, .12);
	--icon-btn-bg-hover: rgba(0, 0, 0, .20);
	--icon-btn-fg: rgba(255, 255, 255, .95);
	--color-highlight: #389FFF;
	--color-highlight-text: #389FFF;
	--tree-bg: #0b1220;
	--tree-border: rgba(255,255,255,.10);
	--tree-text: #d9e7ff;
	--tree-muted: rgba(217,231,255,.65);
	--tree-hover: rgba(255,255,255,.06);
	--tree-active: rgba(84,151,254,.18);
	/* Ring */
	--ring-track: rgba(255,255,255,.14);
	--ring-size: 25px;
	--ring-thickness: 10px;
	/* Icons */
	--tree-icon: rgba(217,231,255,.75);
}

/* Light theme overrides (NAV + PANELS change; HEADER does NOT) */
html[data-bs-theme="light"] {
	--page-bg-1: #e9eff5;
	--sidebar-bg: #5f758b;
	--sidebar-link-bg: rgba(255, 255, 255, .55);
	--sidebar-link-hover-bg: rgba(255, 255, 255, .78);
	--sidebar-link-fg: rgba(0, 0, 0, .85);
	--app-main-bg-img: url("/images/blurry-nebula2-light.jpg");
	--app-main-bg-overlay: rgba(255, 255, 255, .1);
	--tab-bg: rgba(255, 255, 255, .70);
	--tab-border: rgba(0, 0, 0, .10);
	--tab-fg: rgba(0, 0, 0, .75);
	--tab-active-bg: rgba(255, 255, 255, .92);
	--tab-active-border: rgba(0, 0, 0, .14);
	--panel-radial: rgba(0, 0, 0, .05);
	--panel-from: #f5f8fb;
	--panel-to: #e4ebf2;
	--panel-border: rgba(0, 0, 0, .10);
	--panel-fg: rgba(0, 0, 0, .75);
	--panel-inset-shadow: rgba(255, 255, 255, .35);
	--tree-bg-color: rgb(140, 161, 185, 0.80);
	/* Keep header controls visually consistent even in light mode */
	--icon-btn-border: rgba(255, 255, 255, .14);
	--icon-btn-bg: rgba(0, 0, 0, .12);
	--icon-btn-bg-hover: rgba(0, 0, 0, .20);
	--icon-btn-fg: rgba(255, 255, 255, .95);
	--color-highlight: #669ccf;
	--color-highlight-text: #1a5995;
	--tree-bg: #f6f8ff;
	--tree-border: rgba(15, 23, 42, .12);
	--tree-text: #0f172a;
	--tree-muted: rgba(15, 23, 42, .62);
	--tree-hover: rgba(2, 6, 23, .045);
	--tree-active: rgba(84, 151, 254, .16);
	--ring-track: rgba(2, 6, 23, .16);
	--tree-icon: rgba(15, 23, 42, .70);
}

html,
body {
	height: 100%;
}

body {
	font-family: var(--font-sans);
	background: radial-gradient(1200px 600px at 30% 20%, rgba(255, 255, 255, .04), transparent 55%), linear-gradient(180deg, rgba(0, 0, 0, .22), rgba(0, 0, 0, .22)), var(--page-bg-1);
	overflow: hidden;
}

.font-mono {
	font-family: var(--font-mono) !important;
}

code,
pre,
kbd,
samp {
	font-family: var(--font-mono);
}

.feature-disabled {
	opacity: .2 !important;
}

/* App shell */
.app-shell {
	height: 100vh;
	display: flex;
	flex-direction: column;
}

/* HEADER: fixed colors; does not change with theme */
.app-header {
	height: var(--header-h);
	background: var(--header-bg);
	color: var(--header-fg);
	border-bottom: 1px solid rgba(255, 255, 255, .06);
	position: relative;
	z-index: 2000;
}

	.app-header a {
		color: inherit;
	}

.app-body {
	flex: 1;
	min-height: 0;
	display: flex;
	position: relative;
	overflow: hidden;
}

/* Sidebar */
.app-sidebar {
	background: var(--sidebar-bg);
	width: var(--sidebar-expanded);
	transition: width .2s ease;
	display: flex;
	flex-direction: column;
	padding: .75rem .5rem;
	gap: .5rem;
	position: relative;
	z-index: 1600;
}

	.app-sidebar.collapsed {
		width: var(--sidebar-collapsed);
	}

/* Mobile: sidebar becomes overlay that can be fully hidden */
@media (max-width: 991.98px) {
	.app-sidebar {
		position: absolute;
		top: 0;
		bottom: 0;
		left: 0;
		z-index: 1600;
		width: var(--mobile-sidebar-w);
		transform: translateX(-100%);
		transition: transform .2s ease;
		box-shadow: 0 16px 48px rgba(0, 0, 0, .45);
	}

		.app-sidebar.collapsed {
			width: var(--mobile-sidebar-w);
		}

		/* ignore collapsed width on mobile */
		.app-sidebar.mobile-open {
			transform: translateX(0);
		}
}

/* Backdrop for mobile */
.sidebar-backdrop {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, .45);
	opacity: 0;
	pointer-events: none;
	transition: opacity .2s ease;
	z-index: 1500;
}

	.sidebar-backdrop.show {
		opacity: 1;
		pointer-events: auto;
	}

.nav-icon {
	width: 28px;
	height: 28px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}

.sidebar-link {
	border-radius: 12px;
	color: var(--sidebar-link-fg);
	background: var(--sidebar-link-bg);
	padding: .6rem .7rem;
	display: flex;
	align-items: center;
	gap: .7rem;
	text-decoration: none;
	transition: background .15s ease, transform .05s ease;
	user-select: none;
}

	.sidebar-link.active {
		background: var(--sidebar-active-bg);
		color: var(--sidebar-active-fg);
		box-shadow: 0 0 0 1px var(--sidebar-active-ring) inset;
	}

	.sidebar-link:hover {
		background: var(--sidebar-link-hover-bg);
	}

	.sidebar-link:active {
		transform: translateY(1px);
	}

	.sidebar-link i {
		font-size: var(--sidebar-link-icon-size);
	}

.nav-text {
	font-weight: 600;
	letter-spacing: .02em;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.app-sidebar.collapsed .nav-text {
	display: none;
}

/* Main */
.app-main {
	flex: 1;
	min-width: 0;
	min-height: 0;
	overflow: auto;
	padding: 1rem;
	position: relative;
	/* required for overlay */
	background-image: linear-gradient(180deg, var(--app-main-bg-overlay), var(--app-main-bg-overlay)), var(--app-main-bg-img);
	background-size: cover;
	background-position: center;
	background-repeat: no-repeat;
	/* optional: keeps it from �jumping� while scrolling */
	background-attachment: fixed;
}

/* Panels (E/D/F/G all change because they share kv-panel) */
.kv-panel {
	background: radial-gradient(900px 500px at 50% 30%, var(--panel-radial), transparent 55%), linear-gradient(180deg, var(--panel-from), var(--panel-to));
	border: 1px solid var(--panel-border);
	border-radius: var(--radius);
	box-shadow: 0 10px 24px var(--panel-inset-shadow) inset;
	display: flex;
	padding: 15px;
	color: var(--panel-fg);
	text-decoration: none;
	
}
	.kv-panel a {
		color: inherit;
		text-decoration: none;
	}

	.kv-panel.ai {
		padding: 0;
	}

	.kv-panel h3,
	.kv-tree h3 {
		font-size: 1.3rem;
		font-weight: 400;
		margin: 0;
	}

.kv-tab {
	border-radius: 12px;
	background: var(--tab-bg);
	border: 1px solid var(--tab-border);
	color: var(--tab-fg);
	padding: 8px;
	position: relative;
	overflow: hidden;
	/* keeps the image clipped to the tab */
	height: 100% !important;
}

.kv-tree {
	border-radius: 12px;
	background: var(--tree-bg-color);
	border: 1px solid var(--tab-border);
	color: var(--tab-fg);
	padding: 15px;
	position: relative;
	overflow: hidden;
	/* keeps the image clipped to the tab */
	height: 100% !important;
}

.kv-tab.active {
	background: var(--tab-active-bg);
	border-color: var(--tab-active-border);
	box-shadow: 0 0 0 1px rgba(0, 0, 0, .18) inset;
}

	.kv-tab.active::after {
		content: "";
		position: absolute;
		top: 0;
		right: -20px;
		bottom: 0;
		width: 40%;
		background-image: url("/images/devices/bg-generator.png");
		background-repeat: no-repeat;
		background-position: right center;
		background-size: cover;
		opacity: 0.25;
		pointer-events: none;
		z-index: 0;
	}

.kv-panel-ai {
	background-color: #384B69;
	border-radius: 0 0 .5rem .5rem;
}

/* Layout helpers */
.kv-wrap {
	height: calc(100vh - var(--header-h) - 2rem);
	min-height: 520px;
	display: flex;
	flex-direction: column;
	gap: var(--gap);
}

.kv-stage {
	flex: 1;
	min-height: 0;
}

.tree {
	background: radial-gradient(900px 500px at 50% 30%, var(--panel-radial), transparent 55%), linear-gradient(180deg, var(--panel-from), var(--panel-to));
	border: 1px solid var(--panel-border);
	border-radius: var(--radius);
	box-shadow: 0 10px 24px var(--panel-inset-shadow) inset;
	display: flex;
	padding: 15px;
	color: var(--panel-fg);
}

.kv-e {
	flex: 1.05;
}

.kv-bottom-row {
	flex: 0.95;
	min-height: 0;
}

.k5-icon-tile {
	width: 35px;
	height: 35px;
	background: var(--color-highlight);
	border-radius: .5rem;
	margin-right: 10px;
	color: #000;
	align-items: center !important;
	justify-content: center !important;
	flex-shrink: 1 !important;
	display: inline-flex !important;
}

.fill {
	flex: 1;
	min-height: 0;
}

/* Brand */
.brand {
	display: flex;
	align-items: center;
	gap: .65rem;
	text-decoration: none;
}

.brand-title {
	font-weight: 700;
	letter-spacing: .02em;
	font-size: 1.6rem;
}

/* Header buttons */
.icon-btn {
	border: 1px solid var(--icon-btn-border);
	background: var(--icon-btn-bg);
	color: var(--icon-btn-fg);
	border-radius: 12px;
	width: 60px;
	height: 44px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: .4rem;
}

	.icon-btn:hover {
		background: var(--icon-btn-bg-hover);
	}

	.icon-btn i {
		font-size: 25px;
	}

@media (max-width: 576px) {
	.app-main {
		padding: .75rem;
	}

	.kv-wrap {
		height: auto;
		min-height: unset;
	}
}

.breadcrumbs {
	text-transform: uppercase;
	font-size: .9rem;
}

	.breadcrumbs a {
		color: var(--color-highlight-text);
		text-decoration: none;
		font-weight: 500;
	}

.device-title {
	padding-top: 5px;
	font-size: 1.5rem;
	font-weight: 500;
}

.device-sku {
	font-size: 0.9rem;
}

.remaining-life-value {
	color: var(--color-highlight-text);
	font-size: 1.4rem;
	font-weight: 400;
	line-height: 1.2rem;
}

.remaining-life-label {
	font-size: 0.8rem;
}

.reliability-score-label {
	font-size: 1rem;
	padding-top: 3px;
}


.maintenance-dual-stat {
	--kv-bg: rgba(51, 51, 51, .76);
	border-radius: 12px;
	min-height: 82px;
	display: flex;
}

.maintenance-pane {
	position: relative;
	flex: 1 1 0;
	padding: 0 22px;
	display: flex;
	align-items: center;
}

.maintenance-content {
	position: relative;
	z-index: 2;
}

.maintenance-value {
	color: var(--color-highlight-text);
	font-weight: 600;
	letter-spacing: .01em;
	margin-top: 0.2rem;
	line-height: 1;
	font-size: clamp(1.75rem, 2.2vw, 2.25rem);
}

.maintenance-label {
	margin-top: 0.2rem;
	color: #fff;
	font-size: 0.8rem;
	line-height: 1.1;
}

.maintenance-bg {
	position: absolute;
	inset: auto;
	width: 190px;
	height: 190px;
	transform: scale(.75);
	opacity: .38;
	z-index: 1;
	pointer-events: none;
}

	.maintenance-bg path {
		fill: #000;
	}

.maintenance-bg--left {
	left: -23px;
	top: -23px;
}

.maintenance-bg--right {
	right: -32px;
	top: -54px;
}

.telemetry-gauge {
	margin-top: 20px;
}

.telemetry-chart {
	width: 100%;
	height: 295px;
}


.tree-list {
	list-style: none;
	margin: 0;
	padding: .25rem;
}

.tree-branch {
	position: relative;
	margin-left: .55rem;
	padding-left: .85rem;
	border-left: 1px solid var(--tree-border);
}

.tree-item {
	margin: .15rem 0;
}

/* Shared row layout (used by <summary> and <a>) */
.tree-row {
	display: flex;
	align-items: center;
	gap: .6rem;
	padding: .55rem .65rem;
	border-radius: 10px;
	color: var(--tree-text);
	user-select: none;
}

	.tree-row:hover {
		background: var(--tree-hover);
	}

	.tree-row.active {
		background: var(--tree-active);
		outline: 1px solid rgba(84,151,254,.35);
	}

a.tree-row {
	text-decoration: none;
	cursor: pointer;
}

.tree-title {
	display: flex;
	align-items: center;
	gap: .5rem;
	min-width: 0;
}

.tree-label {
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	font-weight: 400;
	letter-spacing: .2px;
}

.tree-meta {
	margin-left: auto;
	display: flex;
	align-items: center;
	gap: .6rem;
	flex: 0 0 auto;
}

/* Expand/collapse (native <details>, no JS) */
details.tree-details > summary {
	list-style: none;
	cursor: pointer;
}

	details.tree-details > summary::-webkit-details-marker {
		display: none;
	}

.disclosure {
	width: 1.1rem;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	opacity: .9;
	flex: 0 0 auto;
	transition: transform .15s ease;
}

details.tree-details[open] .disclosure {
	transform: rotate(90deg);
}

/* Tree leading icons */
.tree-leading {
	width: 1.1rem;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	color: var(--tree-icon);
	opacity: .95;
	flex: 0 0 auto;
}

	.tree-leading i {
		font-size: 1.05rem;
		line-height: 1;
	}

/* Icon flags (shown via data attributes on the row) */
.flag {
	display: none;
	font-size: 1.25rem;
	line-height: 1;
	opacity: .95;
}

.tree-row[data-warning="true"] .flag.warning {
	display: inline-flex;
}

.tree-row[data-maintenance="true"] .flag.maintenance {
	display: inline-flex;
}

/* Score ring (no JS). Set --score: 0..99 on .score-ring */
.score-ring {
	--score: 0; /* 0..99 */
	--hue: calc(var(--score) * 1.2); /* 0=red, ~120=green at 99 */
	--ring-color: hsl(var(--hue) 92% 52%);
	width: var(--ring-size);
	height: var(--ring-size);
	border-radius: 999px;
	position: relative;
	display: inline-block;
	flex: 0 0 auto;
}

	.score-ring::before {
		content: "";
		position: absolute;
		inset: 0;
		border-radius: 999px;
		background: conic-gradient( var(--ring-color) calc(var(--score) * 1%), var(--ring-track) 0 );
		-webkit-mask: radial-gradient(farthest-side, transparent calc(50% - var(--ring-thickness)), #000 0);
		mask: radial-gradient(farthest-side, transparent calc(50% - var(--ring-thickness)), #000 0);
	}

/* Score text to the RIGHT of the ring */
.score-text {
	font-family: var(--font-mono);
	font-size: 1rem;
	font-weight: 700;
	color: rgba(217,231,255,.92);
	min-width: 2.2ch;
	text-align: right;
	opacity: .95;
}

:root[data-theme="light"] .score-text {
	color: rgba(15, 23, 42, .90);
}

.kv-devices {
	background: var(--k5-prediction-surface);
	border: 1px solid var(--k5-prediction-border);
	border-radius: .75rem;
	padding: .8rem;
	display: flex;
	flex-direction: column;
	justify-content: space-between;
}
