:root {
  color-scheme: dark;
  --bg: #07090d;
  --panel: #151821;
  --panel-soft: #1b1f2a;
  --line: #2b3140;
  --text: #edf1f7;
  --muted: #949cae;
  --solar: #f1c84b;
  --home: #8ea0ff;
  --powerwall: #45d88b;
  --grid: #c7cbd4;
  --vehicle: #ef6656;
  --focus: #5bb7ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 18% 0%, rgba(91, 183, 255, 0.1), transparent 32rem),
    linear-gradient(180deg, #10131b 0%, var(--bg) 42rem);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
a {
  font: inherit;
}

.app-shell {
  width: min(1500px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 30px;
}

.topbar,
.brand,
.nav-actions {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 20px;
  min-height: 72px;
}

.brand {
  gap: 13px;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: url("/assets/energyoptimizer-icon.png") center / cover no-repeat;
  border: 1px solid rgba(255, 255, 255, 0.14);
  flex: 0 0 auto;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 23px;
  line-height: 1.05;
  font-weight: 680;
}

.brand p,
.panel-head p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.nav-actions {
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-button,
.primary-button,
.link-button {
  min-height: 42px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}

.icon-button,
.link-button {
  background: rgba(255, 255, 255, 0.04);
}

.primary-button {
  background: rgba(91, 183, 255, 0.16);
  border-color: rgba(91, 183, 255, 0.42);
}

.icon-button:hover,
.primary-button:hover,
.link-button:hover {
  border-color: rgba(255, 255, 255, 0.34);
  background: rgba(255, 255, 255, 0.08);
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.metric,
.panel {
  border: 1px solid var(--line);
  background: rgba(20, 24, 33, 0.86);
  border-radius: 8px;
}

.metric {
  min-height: 94px;
  padding: 13px 15px;
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 5px;
  font-size: 28px;
  line-height: 1.05;
  font-weight: 620;
}

.metric.solar strong,
.solar-node strong {
  color: var(--solar);
}

.metric.home strong,
.home-node strong {
  color: var(--home);
}

.metric.powerwall strong,
.battery-node strong {
  color: var(--powerwall);
}

.metric.grid strong,
.grid-node strong {
  color: var(--grid);
}

.status {
  margin: 14px 0;
  border: 1px solid rgba(239, 102, 86, 0.38);
  border-radius: 8px;
  padding: 12px 14px;
  background: rgba(239, 102, 86, 0.09);
  color: #ffd4ce;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 12px;
  margin-top: 16px;
}

.panel {
  min-height: 260px;
  padding: 14px;
  background: linear-gradient(180deg, rgba(24, 28, 38, 0.94), rgba(10, 12, 17, 0.96));
  overflow: hidden;
}

.panel-head {
  min-height: 52px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

h2 {
  font-size: 18px;
  line-height: 1.15;
  font-weight: 680;
}

.badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.flow-panel {
  min-height: 470px;
}

.flow-map {
  position: relative;
  height: 360px;
  margin-top: 10px;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 42px 42px;
}

.flow-node {
  position: absolute;
  z-index: 2;
  width: 138px;
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(12, 15, 21, 0.94);
}

.flow-node span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.flow-node strong {
  display: block;
  margin-top: 5px;
  font-size: 22px;
}

.solar-node {
  left: 4%;
  top: 34px;
}

.home-node {
  left: calc(50% - 69px);
  top: 142px;
}

.battery-node {
  left: 4%;
  bottom: 30px;
}

.grid-node {
  right: 4%;
  bottom: 30px;
}

.vehicle-node {
  right: 4%;
  top: 34px;
}

.vehicle-node strong {
  color: var(--vehicle);
}

.flow-line {
  position: absolute;
  z-index: 1;
  height: 4px;
  border-radius: 999px;
  opacity: 0.18;
  transform-origin: center;
}

.flow-line.active {
  opacity: 0.86;
  box-shadow: 0 0 18px currentColor;
}

.solar-line {
  left: 22%;
  top: 110px;
  width: 34%;
  color: var(--solar);
  background: currentColor;
  transform: rotate(23deg);
}

.battery-line {
  left: 22%;
  bottom: 106px;
  width: 34%;
  color: var(--powerwall);
  background: currentColor;
  transform: rotate(-22deg);
}

.grid-line {
  right: 22%;
  bottom: 106px;
  width: 34%;
  color: var(--grid);
  background: currentColor;
  transform: rotate(22deg);
}

.vehicle-line {
  right: 22%;
  top: 110px;
  width: 34%;
  color: var(--vehicle);
  background: currentColor;
  transform: rotate(-23deg);
}

.status-list,
.event-list {
  margin-top: 10px;
}

.status-list {
  display: grid;
  gap: 10px;
}

.status-list div,
.event-item,
.signal-grid div {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
}

.status-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
}

dt,
dd {
  margin: 0;
}

dt {
  color: var(--muted);
}

dd {
  text-align: right;
}

.events-panel {
  min-height: 300px;
}

.event-list {
  display: grid;
  gap: 8px;
}

.event-item {
  padding: 11px 12px;
}

.event-item strong,
.event-item small {
  display: block;
}

.event-item small {
  margin-top: 4px;
  color: var(--muted);
}

.derived-panel {
  min-height: 300px;
}

.signal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.signal-grid div {
  min-height: 84px;
  padding: 12px;
}

.signal-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.signal-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 20px;
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .nav-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .summary-strip,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .flow-panel {
    min-height: 580px;
  }

  .flow-map {
    height: 470px;
  }

  .solar-node,
  .battery-node {
    left: 0;
  }

  .vehicle-node,
  .grid-node {
    right: 0;
  }

  .home-node {
    left: calc(50% - 69px);
    top: 200px;
  }

  .solar-line,
  .battery-line,
  .grid-line,
  .vehicle-line {
    width: 28%;
  }
}
