:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #eef2f5;
  --text: #17212b;
  --muted: #697684;
  --border: #d7dee6;
  --primary: #176b87;
  --primary-strong: #0f4f64;
  --ok: #1f8a5b;
  --warn: #c94c28;
  --backup: #8a5a12;
  --shadow: 0 12px 28px rgba(28, 43, 57, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.login-box {
  display: grid;
  gap: 16px;
  width: min(420px, 100%);
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-brand {
  margin-bottom: 8px;
  color: var(--text);
}

.login-box label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
}

.login-box input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}

.login-error {
  padding: 10px 12px;
  border: 1px solid #f2b39f;
  border-radius: 8px;
  background: #fff1ec;
  color: #7f270e;
  font-weight: 700;
}

button,
a {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #18242f;
  color: #ffffff;
  padding: 24px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 34px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #d8ebf0;
  color: #17313d;
  font-weight: 800;
}

.brand span:last-child {
  display: block;
  color: #b5c1ca;
  font-size: 13px;
  margin-top: 2px;
}

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

.nav-item {
  color: #cfdae1;
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 8px;
}

.nav-item:hover,
.nav-item.is-active {
  background: #263746;
  color: #ffffff;
}

.main-content {
  padding: 28px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
}

h2 {
  margin-bottom: 3px;
  font-size: 18px;
}

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

.system-state {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-weight: 700;
}

.state-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ok);
}

.system-state.is-fault .state-dot {
  background: var(--warn);
}

.system-state.is-warning .state-dot {
  background: var(--warn);
}

.system-state.is-backup .state-dot {
  background: var(--backup);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(620px, 1fr) 360px;
  gap: 22px;
  align-items: start;
}

.network-panel,
.message-card,
.logs-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.network-panel,
.logs-panel {
  padding: 20px;
}

.meter-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.meter-strip div {
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f9fbfc;
}

.meter-strip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.meter-strip strong {
  display: block;
  margin-top: 6px;
  font-size: 18px;
}

.panel-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.panel-header.compact {
  padding: 18px 18px 0;
}

.secondary-button,
.action-button,
.icon-button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}

.secondary-button {
  padding: 10px 13px;
}

.secondary-button:hover,
.icon-button:hover,
.action-button:hover {
  border-color: var(--primary);
  color: var(--primary-strong);
}

.network-diagram {
  position: relative;
  display: block;
  min-height: 330px;
  overflow: hidden;
  padding: 20px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.node {
  z-index: 2;
  position: absolute;
  display: grid;
  gap: 5px;
  align-content: center;
  width: 120px;
  min-height: 78px;
  padding: 13px;
  border: 2px solid #b8c7d2;
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  box-shadow: 0 8px 18px rgba(28, 43, 57, 0.08);
}

.node span {
  color: var(--muted);
  font-size: 13px;
}

.node strong {
  font-size: 15px;
}

.node:hover {
  border-color: var(--primary);
}

.node.is-failed {
  border-color: var(--warn);
  background: #fff1ec;
  animation: alertFlash 0.8s infinite;
}

.source {
  left: 24px;
  top: 38px;
}

.transformer {
  left: 24px;
  bottom: 44px;
}

.grid {
  right: 24px;
  top: 38px;
}

.ups {
  display: none;
}

.battery {
  left: calc(50% - 60px);
  bottom: 44px;
}

.inverter {
  right: 24px;
  bottom: 44px;
}

.line {
  position: absolute;
  border-radius: 999px;
  background: #a8b7c2;
  overflow: hidden;
}

.line::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.95), transparent);
  animation: flow 1.2s linear infinite;
}

.line.horizontal {
  height: 8px;
}

.line.vertical {
  width: 8px;
}

.line.active {
  background: var(--ok);
}

.line.backup {
  background: var(--backup);
}

.line.hidden {
  display: none;
}

.line.is-off {
  background: #c6cfd8;
}

.line.is-off::after {
  animation: none;
  background: transparent;
}

[data-line="feed-grid"] {
  left: 144px;
  right: 144px;
  top: 76px;
  width: auto;
}

[data-line="feed-transformer"] {
  left: 80px;
  top: 124px;
  width: 8px;
  height: 94px;
}

[data-line="transformer-battery"] {
  left: 144px;
  top: 264px;
  width: calc(50% - 204px);
}

[data-line="battery-inverter"] {
  left: calc(50% + 64px);
  right: 144px;
  top: 264px;
  height: 8px;
  width: auto;
}

[data-line="inverter-grid"] {
  right: 80px;
  top: 124px;
  width: 8px;
  height: 94px;
  transform: none;
}

.message-panel {
  display: grid;
  gap: 16px;
}

.warning-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: #fff1ec;
  border: 1px solid #f2b39f;
  border-radius: 8px;
  color: #7f270e;
  animation: alertFlash 0.8s infinite;
}

.warning-banner[hidden] {
  display: none;
}

.warning-banner span {
  display: block;
}

.warning-pulse {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--warn);
}

.message-list,
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.message-list {
  padding: 0 18px 18px;
}

.message-list li,
.history-list li {
  display: grid;
  gap: 4px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.message-list li:last-child,
.history-list li:last-child {
  border-bottom: 0;
}

.message-time {
  color: var(--muted);
  font-size: 12px;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.action-button {
  min-height: 52px;
  background: #ffffff;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
}

.modal {
  width: min(520px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 70px rgba(16, 32, 44, 0.28);
}

.modal::backdrop {
  background: rgba(10, 18, 25, 0.45);
}

.modal-header,
.modal-body,
.modal-actions,
.history-list {
  padding: 18px;
}

.modal-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.modal-body dl {
  display: grid;
  gap: 14px;
  margin: 0;
}

.modal-body div {
  display: grid;
  gap: 5px;
}

dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

dd {
  margin: 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  border-top: 1px solid var(--border);
}

.log-table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
}

.log-table th,
.log-table td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.log-table th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.status-pill {
  display: inline-flex;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.status-pill.ok {
  background: #e7f5ee;
  color: #136640;
}

.status-pill.info {
  background: #e9f3f7;
  color: #0f4f64;
}

.status-pill.warning,
.status-pill.critical {
  background: #fff1ec;
  color: #8a2f13;
}

@keyframes flow {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(100%);
  }
}

@keyframes alertFlash {
  0%,
  100% {
    box-shadow: 0 0 0 rgba(201, 76, 40, 0);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(201, 76, 40, 0.18);
  }
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    padding: 16px 20px;
  }

  .brand {
    margin-bottom: 0;
  }

  .nav-list {
    grid-auto-flow: column;
    align-items: center;
  }

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

  .meter-strip {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .main-content {
    padding: 18px;
  }

  .page-header,
  .panel-header,
  .sidebar {
    align-items: stretch;
    flex-direction: column;
  }

  .dashboard-grid {
    gap: 16px;
  }

  .network-diagram {
    justify-content: start;
    min-width: 600px;
  }
}
