.ha-powerflow {
	margin: 1.5em 0;
	font-family: inherit;
}

.ha-powerflow__title {
	margin: 0 0 1em;
	font-size: 1.5rem;
	line-height: 1.2;
}

.ha-powerflow__notice {
	margin: 0 0 1em;
	padding: 0.75em 1em;
	border-left: 3px solid #dba617;
	background: #fff8e5;
	color: #2c3338;
	font-size: 0.9em;
}

.ha-powerflow__grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
	gap: 1rem;
	margin: 0;
	padding: 0;
	list-style: none;
}

.ha-powerflow__card {
	display: flex;
	flex-direction: column;
	gap: 0.35em;
	padding: 1rem;
	border: 1px solid #dcdcde;
	border-radius: 8px;
	background: rgba( 255, 255, 255, var( --ha-powerflow-box-alpha, 1 ) );
	box-shadow: 0 1px 2px rgba( 0, 0, 0, 0.04 );
}

.ha-powerflow__card-header {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 0.4rem;
	margin: 0 0 0.35em;
}

.ha-powerflow__card-title {
	margin: 0;
	color: var( --ha-powerflow-title-colour, #1d2327 );
	font-size: var( --ha-powerflow-title-size, 18px );
	font-weight: 700;
	line-height: 1.2;
}

.ha-powerflow__card-lines {
	display: flex;
	flex-direction: column;
	gap: 0.35em;
	margin: 0;
	padding: 0;
	list-style: none;
}

.ha-powerflow__card-line {
	display: flex;
	flex-direction: column;
	align-items: stretch;
	gap: 0.15em;
}

.ha-powerflow__line-main {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 1em;
}

.ha-powerflow__line-label {
	font-weight: 600;
	letter-spacing: 0.03em;
	text-transform: uppercase;
}

.ha-powerflow__line-label--primary {
	color: var( --ha-powerflow-primary-colour, #1d2327 );
	font-size: var( --ha-powerflow-primary-size, 22px );
}

.ha-powerflow__line-label--secondary {
	color: var( --ha-powerflow-secondary-colour, #50575e );
	font-size: var( --ha-powerflow-secondary-size, 14px );
}

.ha-powerflow__line-value {
	font-weight: 700;
	line-height: 1.1;
	font-variant-numeric: tabular-nums;
}

.ha-powerflow__line-value--primary {
	color: var( --ha-powerflow-primary-colour, #1d2327 );
	font-size: var( --ha-powerflow-primary-size, 22px );
}

.ha-powerflow__line-value--secondary {
	color: var( --ha-powerflow-secondary-colour, #50575e );
	font-size: var( --ha-powerflow-secondary-size, 14px );
}

.ha-powerflow__error {
	align-self: flex-end;
	color: #8c8f94;
	font-size: 0.75rem;
}

@media ( max-width: 480px ) {
	.ha-powerflow__grid {
		grid-template-columns: 1fr;
	}
}

.ha-powerflow__overlay {
	position: relative;
	display: block;
	width: 100%;
	max-width: 100%;
	overflow: hidden;
	border-radius: 8px;
	line-height: 0;
}

.ha-powerflow__overlay--size-small {
	min-width: min( 100%, 360px );
}

.ha-powerflow__overlay-image {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: var( --ha-powerflow-object-fit, contain );
}

.ha-powerflow__overlay--ratio-auto .ha-powerflow__overlay-image {
	height: auto;
}

.ha-powerflow__overlay-svg {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	pointer-events: none;
	font-family: inherit;
	line-height: normal;
}

.ha-powerflow__powerflow-line {
	fill: none;
	stroke: var( --ha-powerflow-line-colour, var( --ha-powerflow-primary-colour, #1d2327 ) );
	stroke-width: 4;
	stroke-linecap: round;
	stroke-linejoin: round;
	opacity: var( --ha-powerflow-line-alpha, 0.45 );
}

.ha-powerflow__powerflow-flow {
	fill: none;
	color: var( --ha-powerflow-line-dash-colour, var( --ha-powerflow-primary-colour, #1d2327 ) );
	stroke: currentColor;
	stroke-width: 4;
	stroke-linecap: round;
	stroke-linejoin: round;
	stroke-dasharray: 20 80;
	filter: drop-shadow( 0 0 3px currentColor );
	animation: ha-powerflow-flow 2.4s linear infinite;
}

.ha-powerflow__powerflow-flow--reverse {
	animation-direction: reverse;
}

.ha-powerflow__powerflow-flow--very-slow {
	animation-duration: 8s;
	filter: drop-shadow( 0 0 2px currentColor );
}

.ha-powerflow__powerflow-flow--slow {
	animation-duration: 5s;
	filter: drop-shadow( 0 0 4px currentColor );
}

.ha-powerflow__powerflow-flow--medium {
	animation-duration: 3s;
	filter: drop-shadow( 0 0 5px currentColor ) drop-shadow( 0 0 2px currentColor );
}

.ha-powerflow__powerflow-flow--fast {
	animation-duration: 1.5s;
	filter: drop-shadow( 0 0 8px currentColor ) drop-shadow( 0 0 4px currentColor );
}

.ha-powerflow__powerflow-flow--very-fast {
	animation-duration: 0.75s;
	filter: drop-shadow( 0 0 12px currentColor ) drop-shadow( 0 0 6px currentColor );
}

@keyframes ha-powerflow-flow {
	from {
		stroke-dashoffset: 100;
	}

	to {
		stroke-dashoffset: 0;
	}
}

@media ( prefers-reduced-motion: reduce ) {
	.ha-powerflow__powerflow-flow {
		animation: none;
		stroke-dashoffset: 100;
	}
}

.ha-powerflow__overlay-pill {
	fill: rgba( 255, 255, 255, var( --ha-powerflow-box-alpha, 0.92 ) );
	stroke: rgba( 0, 0, 0, 0.14 );
	stroke-width: 1;
}

.ha-powerflow__overlay-label {
	fill: var( --ha-powerflow-title-colour, #1d2327 );
	font-size: var( --ha-powerflow-title-size, 18px );
	font-weight: 700;
	letter-spacing: 0.04em;
}

.ha-powerflow__overlay-line-label {
	font-weight: 700;
	letter-spacing: 0.04em;
}

.ha-powerflow__overlay-line-label--primary {
	fill: var( --ha-powerflow-primary-colour, #1d2327 );
	font-size: var( --ha-powerflow-primary-size, 22px );
}

.ha-powerflow__overlay-line-label--secondary {
	fill: var( --ha-powerflow-secondary-colour, #50575e );
	font-size: var( --ha-powerflow-secondary-size, 14px );
}

.ha-powerflow__overlay-value {
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}

.ha-powerflow__overlay-value--primary {
	fill: var( --ha-powerflow-primary-colour, #1d2327 );
	font-size: var( --ha-powerflow-primary-size, 22px );
}

.ha-powerflow__overlay-value--secondary {
	fill: var( --ha-powerflow-secondary-colour, #50575e );
	font-size: var( --ha-powerflow-secondary-size, 14px );
}

.ha-powerflow__sr-only {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect( 0, 0, 0, 0 );
	white-space: nowrap;
	border: 0;
}

.ha-powerflow__summary {
	display: grid;
	grid-template-columns: repeat( auto-fit, minmax( 150px, 1fr ) );
	gap: 0.65rem;
	margin: 0 0 1rem;
	padding: 0;
	list-style: none;
}

.ha-powerflow__summary-item {
	display: flex;
	flex-direction: column;
	gap: 0.15rem;
	padding: 0.7rem 0.9rem;
	border: 1px solid #dcdcde;
	border-left: 3px solid #646970;
	border-radius: 8px;
	background: rgba( 255, 255, 255, var( --ha-powerflow-box-alpha, 1 ) );
	box-shadow: 0 1px 2px rgba( 0, 0, 0, 0.04 );
}

.ha-powerflow__summary-item.is-good {
	border-left-color: #059669;
}

.ha-powerflow__summary-item.is-warn {
	border-left-color: #d97706;
}

.ha-powerflow__summary-item.is-info {
	border-left-color: #2563eb;
}

.ha-powerflow__summary-label {
	color: #646970;
	font-size: 0.72rem;
	font-weight: 700;
	letter-spacing: 0.04em;
	text-transform: uppercase;
}

.ha-powerflow__summary-value {
	color: var( --ha-powerflow-primary-colour, #1d2327 );
	font-size: 1.05rem;
	font-weight: 700;
	line-height: 1.2;
	font-variant-numeric: tabular-nums;
}

.ha-powerflow__summary-sub {
	color: var( --ha-powerflow-secondary-colour, #50575e );
	font-size: 0.76rem;
	line-height: 1.25;
}

.ha-powerflow__badge {
	display: inline-flex;
	align-items: center;
	padding: 0.16rem 0.5rem;
	border-radius: 999px;
	background: #f0f0f1;
	color: #3c434a;
	font-size: 0.7rem;
	font-weight: 700;
	line-height: 1.3;
	white-space: nowrap;
}

.ha-powerflow__badge--charging {
	background: #dcfce7;
	color: #166534;
}

.ha-powerflow__badge--discharging {
	background: #dbeafe;
	color: #1e40af;
}

.ha-powerflow__badge--idle {
	background: #f3f4f6;
	color: #4b5563;
}

.ha-powerflow__diagram-wrap {
	min-width: min( 100%, 480px );
	max-width: 100%;
}

.ha-powerflow__diagram {
	position: relative;
	width: 100%;
	aspect-ratio: 1000 / 640;
	min-height: 360px;
	border: 1px solid #dcdcde;
	border-radius: 12px;
	background: radial-gradient( circle at 50% 50%, rgba( 34, 113, 177, 0.05 ) 0%, rgba( 248, 250, 252, 0.9 ) 70% );
	overflow: hidden;
}

.ha-powerflow__diagram-svg {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	pointer-events: none;
}

.ha-powerflow__diagram-hub {
	fill: #ffffff;
	stroke: #cbd5e1;
	stroke-width: 2;
}

.ha-powerflow__diagram-hub.is-active {
	stroke: #2271b1;
	filter: drop-shadow( 0 0 6px rgba( 34, 113, 177, 0.25 ) );
}

.ha-powerflow__diagram-hub-core {
	fill: #f1f5f9;
}

.ha-powerflow__diagram-hub-badge {
	position: absolute;
	left: 50%;
	top: 50%;
	transform: translate( -50%, -50% );
	display: grid;
	place-items: center;
	width: 28px;
	height: 28px;
	color: #2271b1;
	pointer-events: none;
}

.ha-powerflow__diagram-hub-badge svg {
	width: 18px;
	height: 18px;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.ha-powerflow__diagram-node {
	position: absolute;
	transform: translate( -50%, -50% );
	width: clamp( 148px, 24%, 220px );
	padding: 0.65rem 0.8rem;
	border: 1px solid #dcdcde;
	border-top: 3px solid var( --ha-powerflow-node-accent, #2271b1 );
	border-radius: 10px;
	background: rgba( 255, 255, 255, var( --ha-powerflow-box-alpha, 0.94 ) );
	box-shadow: 0 4px 14px rgba( 15, 23, 42, 0.08 );
	backdrop-filter: blur( 4px );
}

.ha-powerflow__diagram-node--solar {
	left: 50%;
	top: 15%;
}

.ha-powerflow__diagram-node--grid {
	left: 16%;
	top: 50%;
}

.ha-powerflow__diagram-node--load {
	left: 84%;
	top: 50%;
}

.ha-powerflow__diagram-node--battery {
	left: 50%;
	top: 85%;
}

.ha-powerflow__diagram-node--ev {
	left: 84%;
	top: 15%;
}

.ha-powerflow__diagram-node-head {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.35rem 0.45rem;
	margin-bottom: 0.35rem;
}

.ha-powerflow__diagram-icon {
	display: grid;
	place-items: center;
	width: 1.55rem;
	height: 1.55rem;
	flex: 0 0 auto;
	border-radius: 6px;
	background: #f1f5f9;
	color: var( --ha-powerflow-node-accent, #2271b1 );
}

.ha-powerflow__diagram-icon svg {
	width: 0.95rem;
	height: 0.95rem;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.ha-powerflow__diagram-node-title {
	color: var( --ha-powerflow-title-colour, #1d2327 );
	font-size: calc( var( --ha-powerflow-title-size, 18px ) * 0.85 );
	font-weight: 700;
	line-height: 1.2;
}

.ha-powerflow__soc-bar {
	width: 100%;
	height: 5px;
	margin: 0.25rem 0 0.4rem;
	border-radius: 999px;
	background: #e2e8f0;
	overflow: hidden;
}

.ha-powerflow__soc-bar-fill {
	display: block;
	height: 100%;
	border-radius: 999px;
	background: var( --ha-powerflow-node-accent, #059669 );
	transition: width 0.3s ease;
}

.ha-powerflow__diagram-lines {
	display: flex;
	flex-direction: column;
	gap: 0.2rem;
	margin: 0;
	padding: 0;
	list-style: none;
}

.ha-powerflow__diagram-line-item {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 0.45rem;
}

.ha-powerflow__diagram-line-item--primary .ha-powerflow__diagram-line-label,
.ha-powerflow__diagram-line-item--primary .ha-powerflow__diagram-line-value {
	color: var( --ha-powerflow-primary-colour, #1d2327 );
	font-size: calc( var( --ha-powerflow-primary-size, 22px ) * 0.85 );
}

.ha-powerflow__diagram-line-item--secondary .ha-powerflow__diagram-line-label,
.ha-powerflow__diagram-line-item--secondary .ha-powerflow__diagram-line-value {
	color: var( --ha-powerflow-secondary-colour, #50575e );
	font-size: calc( var( --ha-powerflow-secondary-size, 14px ) * 0.9 );
}

.ha-powerflow__diagram-line-label {
	font-weight: 600;
	letter-spacing: 0.02em;
	text-transform: uppercase;
}

.ha-powerflow__diagram-line-value {
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}

.ha-powerflow__subloads {
	margin-top: 0.85rem;
	padding: 0.85rem 1rem;
	border: 1px solid #dcdcde;
	border-radius: 10px;
	background: rgba( 255, 255, 255, var( --ha-powerflow-box-alpha, 1 ) );
}

.ha-powerflow__subloads-title {
	display: block;
	margin-bottom: 0.55rem;
	color: #646970;
	font-size: 0.75rem;
	font-weight: 700;
	letter-spacing: 0.05em;
	text-transform: uppercase;
}

.ha-powerflow__subloads-list {
	display: grid;
	grid-template-columns: repeat( auto-fit, minmax( 170px, 1fr ) );
	gap: 0.65rem;
	margin: 0;
	padding: 0;
	list-style: none;
}

.ha-powerflow__subload {
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
	padding: 0.6rem 0.75rem;
	border: 1px solid #e2e8f0;
	border-radius: 8px;
	background: #f8fafc;
}

.ha-powerflow__subload-head {
	display: flex;
	align-items: center;
	gap: 0.45rem;
}

.ha-powerflow__subload-dot {
	width: 0.55rem;
	height: 0.55rem;
	border-radius: 50%;
	background: #cbd5e1;
	flex: 0 0 auto;
}

.ha-powerflow__subload.is-active .ha-powerflow__subload-dot {
	background: #059669;
	box-shadow: 0 0 0 3px rgba( 5, 150, 105, 0.2 );
}

.ha-powerflow__subload-title {
	color: var( --ha-powerflow-title-colour, #1d2327 );
	font-weight: 700;
	font-size: 0.92rem;
}

.ha-powerflow__subload-values {
	display: flex;
	flex-wrap: wrap;
	gap: 0.35rem 0.85rem;
	font-variant-numeric: tabular-nums;
}

.ha-powerflow__subload-label {
	color: var( --ha-powerflow-secondary-colour, #50575e );
	font-size: 0.75rem;
	text-transform: uppercase;
}

@media ( max-width: 640px ) {
	.ha-powerflow__diagram-wrap {
		min-width: 100%;
	}

	.ha-powerflow__diagram {
		display: grid;
		grid-template-columns: 1fr;
		gap: 0.75rem;
		padding: 0.75rem;
		aspect-ratio: auto;
		min-height: 0;
	}

	.ha-powerflow__diagram-svg,
	.ha-powerflow__diagram-hub-badge {
		display: none;
	}

	.ha-powerflow__diagram-node {
		position: static;
		transform: none;
		width: 100%;
	}
}

