:root {
  --energy-export: #ffb600;
  --energy-vpp: #6cff3b;
  --energy-island: #37d7ff;
  --energy-local: #ffd45a;
  --energy-charge: #8e9cff;
  --energy-storm: #ff7a1a;
  --energy-stale: #8b95a7;
}

.energy-heartbeat {
  position: absolute;
  z-index: 14;
  left: 18px;
  bottom: 30px;
  width: min(390px, calc(100% - 36px));
  padding: 12px 14px 11px;
  border: 1px solid rgba(0,32,92,.16);
  border-radius: 17px;
  background: rgba(255,255,255,.96);
  color: #17213a;
  box-shadow: 0 12px 34px rgba(0,22,63,.20);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  pointer-events: auto;
}
.energy-heartbeat-head {
  display: grid;
  grid-template-columns: 10px auto 1fr 27px;
  align-items: center;
  gap: 7px;
  min-width: 0;
}
.energy-heartbeat-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #14835a;
  box-shadow: 0 0 0 4px rgba(20,131,90,.13);
}
.energy-heartbeat-head strong {
  color: #00205c;
  font-family: "Oswald", sans-serif;
  font-size: 13px;
  line-height: 1;
  letter-spacing: .075em;
}
.energy-heartbeat-head [data-energy-age] {
  min-width: 0;
  overflow: hidden;
  color: #667188;
  font-size: 9.5px;
  font-weight: 650;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.energy-heartbeat-head button {
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(0,32,92,.14);
  border-radius: 50%;
  background: #f5f6fb;
  color: #00205c;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.energy-heartbeat-head button:hover { background: #fff; border-color: rgba(0,32,92,.3); }
.energy-heartbeat-head button.is-spinning { animation: energy-refresh-spin .8s linear infinite; }
@keyframes energy-refresh-spin { to { transform: rotate(360deg); } }
.energy-heartbeat-counts {
  margin-top: 8px;
  color: #38445d;
  font-size: 10.6px;
  font-weight: 700;
  line-height: 1.35;
}
.energy-heartbeat-power {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 5px;
}
.energy-heartbeat-power strong {
  color: #00205c;
  font-family: "Oswald", sans-serif;
  font-size: 23px;
  line-height: 1;
}
.energy-heartbeat-power span {
  color: #667188;
  font-size: 9.7px;
  font-weight: 650;
  line-height: 1.25;
}
.energy-heartbeat-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 13px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(0,32,92,.11);
  color: #5c667a;
  font-size: 9px;
  font-weight: 700;
}
.energy-heartbeat-legend span { display: inline-flex; align-items: center; gap: 5px; }
.energy-heartbeat-legend i { width: 8px; height: 8px; border-radius: 50%; box-shadow: 0 0 0 3px rgba(0,0,0,.04); }
.energy-heartbeat-legend .legend-export { background: var(--energy-export); }
.energy-heartbeat-legend .legend-vpp { background: var(--energy-vpp); }
.energy-heartbeat-legend .legend-island { background: var(--energy-island); }
.energy-heartbeat.mode-export { border-color: rgba(255,182,0,.55); }
.energy-heartbeat.mode-export .energy-heartbeat-dot { background: var(--energy-export); box-shadow: 0 0 0 4px rgba(255,182,0,.16), 0 0 16px rgba(255,182,0,.55); }
.energy-heartbeat.mode-vpp { border-color: rgba(108,255,59,.68); background: rgba(250,255,248,.97); }
.energy-heartbeat.mode-vpp .energy-heartbeat-dot { background: var(--energy-vpp); box-shadow: 0 0 0 4px rgba(108,255,59,.17), 0 0 18px rgba(108,255,59,.72); }
.energy-heartbeat.mode-island { border-color: rgba(55,215,255,.68); background: rgba(247,254,255,.97); }
.energy-heartbeat.mode-island .energy-heartbeat-dot { background: var(--energy-island); box-shadow: 0 0 0 4px rgba(55,215,255,.18), 0 0 18px rgba(55,215,255,.68); }
.energy-heartbeat.is-stale { border-color: rgba(139,149,167,.45); }
.energy-heartbeat.is-stale .energy-heartbeat-dot { background: var(--energy-stale); box-shadow: 0 0 0 4px rgba(139,149,167,.13); }
.energy-heartbeat.is-loading .energy-heartbeat-dot { animation: energy-dot-pulse 1.5s ease-in-out infinite; }
@keyframes energy-dot-pulse { 50% { opacity: .35; transform: scale(.82); } }

.live-energy-card {
  --card-accent: var(--energy-local);
  margin: 14px 0 0;
  padding: 13px 14px 14px;
  border: 1px solid rgba(0,32,92,.14);
  border-radius: 17px;
  background: linear-gradient(180deg,rgba(255,255,255,.99),rgba(247,248,252,.98));
  box-shadow: 0 8px 24px rgba(0,32,92,.09);
}
.live-energy-card[data-mode="export"] { --card-accent: var(--energy-export); border-color: rgba(255,182,0,.45); }
.live-energy-card[data-mode^="vpp"] { --card-accent: var(--energy-vpp); border-color: rgba(108,255,59,.55); background: linear-gradient(180deg,#fff,rgba(247,255,244,.98)); }
.live-energy-card[data-mode="island"] { --card-accent: var(--energy-island); border-color: rgba(55,215,255,.58); background: linear-gradient(180deg,#fff,rgba(244,253,255,.98)); }
.live-energy-card[data-mode="charging"] { --card-accent: var(--energy-charge); border-color: rgba(142,156,255,.45); }
.live-energy-card[data-mode="stale"] { --card-accent: var(--energy-stale); border-color: rgba(139,149,167,.42); }
.live-energy-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.live-energy-card-head > div { min-width: 0; }
.live-energy-card-head span:first-child {
  display: block;
  color: #667188;
  font-size: 8.7px;
  font-weight: 850;
  letter-spacing: .11em;
}
.live-energy-card-head strong {
  display: block;
  margin-top: 3px;
  color: #00205c;
  font-size: 12.2px;
  line-height: 1.28;
}
.live-energy-card-head strong::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--card-accent);
  box-shadow: 0 0 10px rgba(0,32,92,.20);
}
.live-energy-updated {
  flex: 0 0 auto;
  color: #788195;
  font-size: 8.8px;
  font-weight: 650;
  white-space: nowrap;
}
.energy-topology { margin-top: 12px; }
.energy-solar-stack {
  width: 92px;
  margin: 0 auto -1px;
  display: grid;
  justify-items: center;
}
.energy-main-flow {
  display: grid;
  grid-template-columns: minmax(70px,1fr) minmax(30px,.42fr) minmax(70px,1fr) minmax(30px,.42fr) minmax(70px,1fr);
  align-items: center;
  gap: 4px;
}
.energy-node {
  min-width: 0;
  padding: 8px 7px;
  border: 1px solid rgba(0,32,92,.13);
  border-radius: 11px;
  background: #fff;
  text-align: center;
  box-shadow: 0 3px 10px rgba(0,32,92,.055);
}
.energy-node span {
  display: block;
  color: #707a8e;
  font-size: 7.8px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.energy-node strong {
  display: block;
  margin-top: 3px;
  color: #00205c;
  font-family: "Oswald", sans-serif;
  font-size: 14px;
  line-height: 1.05;
  overflow-wrap: anywhere;
}
.energy-node small {
  display: block;
  margin-top: 3px;
  color: #788195;
  font-size: 7.7px;
  line-height: 1.2;
}
.energy-node-battery { border-color: rgba(255,182,0,.38); }
.live-energy-card[data-mode^="vpp"] .energy-node-battery { border-color: rgba(108,255,59,.55); }
.live-energy-card[data-mode="island"] .energy-node-battery { border-color: rgba(55,215,255,.58); }
.live-energy-card[data-mode="charging"] .energy-node-battery { border-color: rgba(142,156,255,.52); }
.live-energy-card[data-mode="stale"] .energy-node-battery { border-color: rgba(139,149,167,.45); }
.energy-node-site { border-color: rgba(0,32,92,.26); background: #f7f8fc; }
.energy-node-grid strong { font-size: 12px; }
.energy-link {
  --flow-color: #9aa3b5;
  --flow-weight: 2;
  position: relative;
  min-width: 0;
  height: 22px;
  opacity: .18;
}
.energy-link::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 2px;
  right: 2px;
  height: calc(var(--flow-weight) * 1px);
  min-height: 1.5px;
  border-radius: 999px;
  background: linear-gradient(90deg,transparent,var(--flow-color),transparent);
  transform: translateY(-50%);
}
.energy-link::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transform: translateY(-50%);
}
.energy-link i {
  position: absolute;
  top: 50%;
  left: 7%;
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 8px var(--flow-color);
  opacity: 0;
}
.energy-link.is-active { opacity: 1; }
.energy-link.is-active i { opacity: 1; animation: energy-flow-right 1.45s linear infinite; }
.energy-link.to-right::after { right: 0; border-left: 6px solid var(--flow-color); }
.energy-link.to-left::after { left: 0; border-right: 6px solid var(--flow-color); }
.energy-link.to-left i { animation-name: energy-flow-left; }
.energy-link.mode-local { --flow-color: var(--energy-local); }
.energy-link.mode-export { --flow-color: var(--energy-export); }
.energy-link.mode-vpp { --flow-color: var(--energy-vpp); }
.energy-link.mode-island { --flow-color: var(--energy-island); }
.energy-link.mode-charging { --flow-color: var(--energy-charge); }
.energy-link.mode-grid { --flow-color: #596cc7; }
.energy-link.mode-solar { --flow-color: #f0b83f; }
.energy-link.is-broken { opacity: .75; }
.energy-link.is-broken::before {
  height: 2px;
  background: repeating-linear-gradient(90deg,#8190a8 0 5px,transparent 5px 10px);
}
.energy-link.is-broken::after { content: "×"; right: calc(50% - 5px); border: 0; color: var(--energy-island); font-size: 16px; font-weight: 900; transform: translateY(-57%); }
.energy-link.is-broken i { display: none; }
@keyframes energy-flow-right { from { left: 7%; } to { left: 83%; } }
@keyframes energy-flow-left { from { left: 83%; } to { left: 7%; } }
.energy-solar-stack .energy-link {
  width: 22px;
  height: 25px;
}
.energy-solar-stack .energy-link::before {
  top: 2px;
  bottom: 2px;
  left: 50%;
  right: auto;
  width: calc(var(--flow-weight) * 1px);
  min-width: 1.5px;
  height: auto;
  background: linear-gradient(180deg,transparent,var(--flow-color),transparent);
  transform: translateX(-50%);
}
.energy-solar-stack .energy-link::after {
  top: auto;
  bottom: 0;
  left: 50%;
  border: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 6px solid var(--flow-color);
  transform: translateX(-50%);
}
.energy-solar-stack .energy-link i {
  top: 7%;
  left: 50%;
  margin: 0 0 0 -3px;
}
.energy-solar-stack .energy-link.is-active i { animation: energy-flow-down 1.45s linear infinite; }
@keyframes energy-flow-down { from { top: 7%; } to { top: 76%; } }
.live-energy-narrative {
  margin: 10px 0 0;
  color: #4b566d;
  font-size: 10.3px;
  line-height: 1.45;
}

@media (max-width: 980px) {
  .energy-heartbeat {
    left: 10px;
    right: 10px;
    bottom: 12px;
    width: auto;
    padding: 10px 12px 9px;
    border-radius: 15px;
  }
  .energy-heartbeat-counts { font-size: 9.8px; }
  .energy-heartbeat-power strong { font-size: 20px; }
  .energy-heartbeat-legend { display: none; }
  .energy-main-flow { grid-template-columns: minmax(62px,1fr) 25px minmax(62px,1fr) 25px minmax(62px,1fr); gap: 2px; }
  .energy-node { padding: 7px 4px; }
  .energy-node strong { font-size: 12.5px; }
}

@media (max-width: 520px) {
  .energy-heartbeat-head { grid-template-columns: 9px auto 1fr 25px; gap: 6px; }
  .energy-heartbeat-head strong { font-size: 11.5px; }
  .energy-heartbeat-head [data-energy-age] { font-size: 8.7px; }
  .energy-heartbeat-counts { white-space: normal; }
  .energy-heartbeat-power { margin-top: 3px; }
  .live-energy-card { padding: 11px 10px 12px; }
  .energy-main-flow { grid-template-columns: minmax(58px,1fr) 20px minmax(58px,1fr) 20px minmax(58px,1fr); }
  .energy-node span { font-size: 7px; }
  .energy-node strong { font-size: 11.7px; }
  .energy-node-grid strong { font-size: 10.4px; }
}

@media (prefers-reduced-motion: reduce) {
  .energy-heartbeat-head button.is-spinning,
  .energy-heartbeat.is-loading .energy-heartbeat-dot,
  .energy-link.is-active i { animation: none !important; }
  .energy-link.is-active i { left: 50%; }
}
