.device-monitor-page {
  --device-primary: #1677ff;
  --device-primary-hover: #0958d9;
  --device-text: #10213d;
  --device-muted: #526278;
  --device-soft: #7a889c;
  --device-border: #e2e8f0;
  --device-subtle: #f8fafc;
}

.device-monitor-page > .kpi-grid { gap: 16px; margin-bottom: 16px; }

.device-monitor-page > .kpi-grid .kpi-card {
  min-height: 128px;
  padding: 16px 20px;
  border-color: var(--device-border);
  border-radius: 8px;
  box-shadow: none;
}

.device-monitor-page > .kpi-grid .kpi-card::after { display: none; }

.device-monitor-page > .kpi-grid .kpi-top {
  color: var(--device-muted);
  font-size: 14px;
  line-height: 22px;
}

.device-monitor-page > .kpi-grid .kpi-icon {
  width: 32px;
  height: 32px;
  background: var(--device-subtle);
  border: 1px solid var(--device-border);
  border-radius: 6px;
}

.device-monitor-page > .kpi-grid .kpi-value { margin-top: 8px; }

.device-monitor-page > .kpi-grid .kpi-value strong {
  color: var(--device-text);
  font-size: 30px;
  line-height: 40px;
}

.device-monitor-page > .kpi-grid .kpi-value small {
  color: var(--device-muted);
  font-size: 13px;
  line-height: 20px;
}

.device-monitor-page > .kpi-grid .kpi-foot {
  margin-top: 4px;
  color: var(--device-soft);
  font-size: 12px;
  line-height: 18px;
}

.device-monitor-page > .panel {
  border-color: var(--device-border);
  border-radius: 8px;
  box-shadow: none;
}

.device-monitor-page > .panel + .panel { margin-top: 16px; }

.device-monitor-page > .panel > .panel-head {
  min-height: 52px;
  padding: 0 20px;
  border-bottom-color: var(--device-border);
}

.device-monitor-page > .panel > .panel-head h3 {
  color: var(--device-text);
  font-size: 16px;
  line-height: 24px;
  font-weight: 600;
}

.device-monitor-page > .panel > .panel-head h3::before { height: 16px; background: var(--device-primary); }

.device-monitor-page > .panel > .panel-head > span {
  color: var(--device-soft);
  font-size: 12px;
  line-height: 18px;
}

.device-monitor-page > .panel > .panel-body { padding: 20px; }

.device-visual-overview { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; }

.device-topology {
  position: relative;
  min-height: 426px;
  overflow: hidden;
  font-size: 12px;
  line-height: 18px;
  background:
    linear-gradient(#e8eef5 1px, transparent 1px),
    linear-gradient(90deg, #e8eef5 1px, transparent 1px),
    var(--device-subtle);
  background-size: 28px 28px;
  border: 1px solid var(--device-border);
  border-radius: 8px;
}

.device-distribution {
  min-width: 0;
  padding: 20px;
  background: #fff;
  border: 1px solid var(--device-border);
  border-radius: 8px;
}

.device-distribution > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 32px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--device-border);
}

.device-distribution > header b {
  color: var(--device-text);
  font-size: 14px;
  line-height: 22px;
  font-weight: 600;
}

.device-distribution > header span {
  color: var(--device-soft);
  font-size: 12px;
  line-height: 18px;
}

.device-distribution .donut-wrap { min-height: 240px; gap: 20px; }

.device-distribution .donut { width: 136px; height: 136px; }

.device-distribution .donut::after { width: 82px; height: 82px; }

.device-distribution .legend-list { min-width: 108px; }

.device-distribution .donut-center strong {
  color: var(--device-text);
  font-size: 24px;
  line-height: 32px;
}

.device-distribution .donut-center small,
.device-distribution .legend-item {
  font-size: 12px;
  line-height: 18px;
}

.distribution-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.distribution-summary div {
  min-width: 0;
  padding: 12px;
  background: var(--device-subtle);
  border: 1px solid var(--device-border);
  border-radius: 8px;
}

.distribution-summary small,
.distribution-summary strong { display: block; }

.distribution-summary small {
  color: var(--device-soft);
  font-size: 12px;
  line-height: 18px;
}

.distribution-summary strong {
  margin-top: 4px;
  color: var(--device-text);
  font-size: 16px;
  line-height: 24px;
}

.topology-connections {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 390px;
  pointer-events: none;
}

.topology-connections path {
  fill: none;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.topology-connections .source-line {
  stroke-width: 2.5;
  stroke-dasharray: 7 6;
  animation: topology-flow 3s linear infinite;
}

.topology-connections .grid-line { stroke: var(--device-primary); }
.topology-connections .solar-line { stroke: #10b981; }
.topology-connections .bus-line { stroke: url(#gridFlow); stroke-width: 5; }
.topology-connections .branch-line { stroke: #7ea8df; stroke-width: 2; }
.topology-connections .device-line { stroke: #b8c7d9; stroke-width: 1.5; stroke-dasharray: 3 4; }
.topology-connections .junction { fill: #fff; stroke: var(--device-primary); stroke-width: 3; vector-effect: non-scaling-stroke; }

@keyframes topology-flow { to { stroke-dashoffset: -26; } }

.topology-source {
  position: absolute;
  top: 16px;
  display: flex;
  align-items: center;
  width: 192px;
  min-height: 64px;
  gap: 10px;
  padding: 10px 12px;
  color: inherit;
  text-decoration: none;
  background: #fff;
  border: 1px solid var(--device-border);
  border-radius: 8px;
  box-shadow: none;
}

.source-grid { left: calc(23% - 96px); }
.source-solar { left: calc(77% - 96px); }
.source-solar:hover { border-color: #10b981; }

.topology-symbol {
  display: grid;
  flex: 0 0 36px;
  height: 36px;
  place-items: center;
  color: #fff;
  font-size: 13px;
  font-weight: 650;
  background: var(--device-primary);
  border-radius: 8px;
}

.source-solar .topology-symbol { background: #10b981; }
.topology-source div { display: grid; gap: 2px; }
.topology-source small { color: var(--device-soft); font-size: 12px; line-height: 18px; }
.topology-source strong { color: var(--device-text); font-size: 14px; line-height: 22px; }
.topology-source > em { margin-left: auto; color: var(--device-muted); font-size: 12px; line-height: 18px; font-style: normal; }

.topology-bus {
  position: absolute;
  top: 98px;
  left: 50%;
  z-index: 2;
  display: flex;
  align-items: center;
  min-width: 310px;
  gap: 14px;
  padding: 9px 16px;
  color: #fff;
  text-decoration: none;
  background: var(--device-primary);
  border: 1px solid #0958d9;
  border-radius: 8px;
  box-shadow: none;
  transform: translateX(-50%);
}

.topology-bus span { font-size: 12px; line-height: 18px; font-weight: 600; }
.topology-bus span i { display: inline-block; width: 7px; height: 7px; margin-right: 6px; background: #a7f3d0; border-radius: 50%; }
.topology-bus strong { font-family: Bahnschrift, "DIN Alternate", sans-serif; font-size: 18px; line-height: 24px; }
.topology-bus em { color: #e6f4ff; font-size: 12px; line-height: 18px; font-style: normal; }

.topology-feeder-grid,
.topology-device-grid {
  position: absolute;
  right: 3%;
  left: 3%;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.topology-feeder-grid { top: 158px; }
.topology-device-grid { top: 277px; }

.topology-feeder {
  min-width: 0;
  padding: 10px 12px;
  color: inherit;
  text-decoration: none;
  background: #fff;
  border: 1px solid var(--device-border);
  border-radius: 8px;
  box-shadow: none;
  transition: border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

.topology-feeder:hover,
.topology-feeder:focus-visible { background: #f8fbff; border-color: var(--device-primary); outline: none; box-shadow: 0 0 0 2px #e6f4ff; }
.topology-feeder header,
.topology-feeder footer { display: flex; align-items: center; }
.topology-feeder header { min-width: 0; gap: 6px; }
.topology-feeder header b { overflow: hidden; color: var(--device-text); font-size: 12px; line-height: 18px; text-overflow: ellipsis; white-space: nowrap; }
.topology-feeder header i { max-width: 44%; margin-left: auto; overflow: hidden; color: #b26a00; font-size: 12px; line-height: 18px; font-style: normal; text-overflow: ellipsis; white-space: nowrap; }
.topology-feeder header i.normal { color: #047857; }
.topology-breaker { flex: 0 0 10px; width: 10px; height: 14px; border: 2px solid var(--device-primary); border-radius: 2px; background: #e6f4ff; }
.topology-feeder > strong { display: block; margin-top: 6px; color: var(--device-text); font-family: Bahnschrift, "DIN Alternate", sans-serif; font-size: 18px; line-height: 24px; }
.topology-feeder footer { justify-content: space-between; gap: 6px; margin-top: 4px; color: var(--device-soft); font-size: 12px; line-height: 18px; }
.topology-feeder footer span,
.topology-feeder footer em { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topology-feeder footer em { color: var(--device-primary); font-style: normal; }

.topology-device-stack { display: grid; min-width: 0; gap: 6px; }
.topology-device { display: flex; min-width: 0; min-height: 28px; align-items: center; gap: 6px; padding: 5px 8px; background: #fff; border: 1px solid var(--device-border); border-radius: 6px; }
.topology-device i { flex: 0 0 7px; width: 7px; height: 7px; background: #10b981; border-radius: 50%; }
.topology-device b { overflow: hidden; color: var(--device-muted); font-size: 12px; line-height: 18px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.topology-device em { margin-left: auto; color: var(--device-text); font-size: 12px; line-height: 18px; font-style: normal; white-space: nowrap; }
.topology-device.warn i { background: #f59e0b; }
.topology-device.off i { background: #ef5261; }
.topology-device.more { justify-content: center; color: var(--device-soft); background: #f8fafc; border-style: dashed; }
.topology-device.more i { display: none; }
.topology-device.more b { color: var(--device-soft); }

.topology-legend { position: absolute; right: 16px; bottom: 10px; left: 16px; display: flex; align-items: center; gap: 16px; color: var(--device-soft); font-size: 12px; line-height: 18px; }
.topology-legend span { display: flex; align-items: center; gap: 6px; }
.topology-legend i { width: 7px; height: 7px; background: #10b981; border-radius: 50%; }
.topology-legend i.warn { background: #f59e0b; }
.topology-legend i.off { background: #ef5261; }
.topology-legend em { margin-left: auto; font-style: normal; }

@media (prefers-reduced-motion: reduce) {
  .topology-connections .source-line { animation: none; }
}

.monitor-group-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }

.monitor-group-card {
  display: block;
  min-width: 0;
  padding: 16px;
  color: inherit;
  text-decoration: none;
  background: #fff;
  border: 1px solid var(--device-border);
  border-radius: 8px;
  transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.monitor-group-card:hover,
.monitor-group-card:focus-visible {
  background: #f8fbff;
  border-color: var(--device-primary);
  box-shadow: 0 0 0 2px #e6f4ff;
  outline: none;
}

.monitor-group-card header,
.monitor-group-card footer,
.monitor-group-value {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.monitor-group-card header > div { min-width: 0; }

.monitor-group-card header b,
.monitor-group-card header small {
  display: block;
}

.monitor-group-card header b {
  color: var(--device-text);
  font-size: 14px;
  line-height: 22px;
  font-weight: 600;
}

.monitor-group-card header small {
  margin-top: 2px;
  color: var(--device-soft);
  font-size: 12px;
  line-height: 18px;
}

.monitor-group-card .badge {
  min-height: 24px;
  padding: 0 8px;
  font-size: 12px;
  line-height: 18px;
}

.monitor-group-value {
  justify-content: flex-start;
  gap: 6px;
  margin-top: 16px;
}

.monitor-group-value strong {
  color: var(--group-color);
  font-family: Bahnschrift, "DIN Alternate", sans-serif;
  font-size: 30px;
  line-height: 40px;
}

.monitor-group-value span {
  color: var(--device-muted);
  font-size: 13px;
  line-height: 20px;
}

.monitor-group-value em {
  margin-left: auto;
  color: var(--device-text);
  font-size: 14px;
  line-height: 22px;
  font-style: normal;
  font-weight: 600;
}

.monitor-group-progress {
  height: 5px;
  margin: 12px 0 10px;
  overflow: hidden;
  background: #edf2f7;
  border-radius: 5px;
}

.monitor-group-progress span {
  display: block;
  height: 100%;
  background: var(--group-color);
  border-radius: inherit;
}

.monitor-group-card footer {
  color: var(--device-soft);
  font-size: 12px;
  line-height: 18px;
}

.monitor-group-link {
  color: var(--device-primary);
  font-weight: 500;
}

@media (max-width: 1280px) {
  .device-visual-overview { grid-template-columns: minmax(0, 1fr); }
  .device-distribution {
    display: grid;
    grid-template-columns: minmax(160px, 0.7fr) minmax(320px, 1.3fr) minmax(240px, 0.8fr);
    align-items: center;
    gap: 20px;
  }

  .device-distribution > header {
    display: grid;
    justify-content: start;
    border-right: 1px solid var(--device-border);
    border-bottom: 0;
  }
  .device-distribution .donut-wrap { min-height: 180px; }
}

@media (max-width: 1180px) {
  .device-monitor-page > .kpi-grid.five { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .monitor-group-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1040px) {
  .device-topology { min-height: 500px; }
  .topology-feeder { padding-inline: 8px; }
  .topology-feeder header { display: grid; grid-template-columns: 8px minmax(0, 1fr); gap: 2px 4px; }
  .topology-feeder header i { grid-column: 2; max-width: none; margin-left: 0; }
  .topology-breaker { grid-row: 1 / span 2; flex-basis: 8px; width: 8px; }
  .topology-feeder footer { flex-wrap: wrap; }
  .topology-feeder footer span,
  .topology-feeder footer em { flex: 1 0 100%; }
  .topology-device-grid { top: 304px; }
  .topology-device:not(.more) { grid-template-columns: 7px minmax(0, 1fr); display: grid; }
  .topology-device:not(.more) em { grid-column: 2; margin-left: 0; text-align: right; }
  .device-distribution { grid-template-columns: minmax(0, 1fr); }
  .device-distribution > header {
    display: flex;
    justify-content: space-between;
    border-right: 0;
    border-bottom: 1px solid var(--device-border);
  }
  .device-monitor-page > .kpi-grid.five,
  .monitor-group-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
