:root {
  --bg: #09111f;
  --bg-soft: #0f1728;
  --panel: rgba(17, 26, 43, 0.82);
  --panel-strong: #101a2d;
  --line: rgba(143, 163, 191, 0.14);
  --text: #e7effb;
  --muted: #8fa3bf;
  --cyan: #16c6ff;
  --cyan-soft: rgba(22, 198, 255, 0.14);
  --violet: #7c7cff;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 22px;
  --radius-sm: 14px;
  --shadow: 0 22px 60px rgba(1, 8, 20, 0.36);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background:
    radial-gradient(circle at top right, rgba(22,198,255,.18), transparent 26%),
    radial-gradient(circle at bottom left, rgba(124,124,255,.12), transparent 24%),
    linear-gradient(180deg, #07101d 0%, #0a1323 100%);
  color: var(--text);
}

a { color: inherit; text-decoration: none; }
button, input { font: inherit; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(7, 12, 24, 0.72);
  backdrop-filter: blur(18px);
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #07101d;
  background: linear-gradient(135deg, #5ee4ff 0%, #16c6ff 55%, #5f7cff 100%);
  box-shadow: 0 12px 30px rgba(22,198,255,.25);
}

.brand-name { font-size: 1.15rem; font-weight: 800; }
.brand-sub { color: var(--muted); font-size: .9rem; }

.side-nav {
  display: grid;
  gap: 10px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  color: var(--muted);
  transition: .2s ease;
}

.nav-item:hover,
.nav-item.active {
  color: var(--text);
  background: linear-gradient(180deg, rgba(22,198,255,.12), rgba(124,124,255,.08));
  border: 1px solid rgba(22,198,255,.16);
}

.sidebar-footer {
  margin-top: auto;
  padding: 18px;
  border-radius: 18px;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--line);
}
.sidebar-footer p {
  color: var(--muted);
  margin: 12px 0 0;
  font-size: .92rem;
  line-height: 1.5;
}

.main-area {
  padding: 26px;
  display: grid;
  gap: 24px;
}

.glass-card,
.panel,
.page-head {
  background: linear-gradient(180deg, rgba(17,26,43,.92), rgba(12,20,34,.86));
  border: 1px solid rgba(143,163,191,.12);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.topbar {
  padding: 18px 22px;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
}

.topbar h1,
.page-head h2,
.panel h2 { margin: 4px 0 0; }
.topbar h1 { font-size: clamp(1.45rem, 2vw, 2rem); }
.eyebrow {
  margin: 0;
  color: var(--cyan);
  letter-spacing: .08em;
  text-transform: uppercase;
  font-size: .76rem;
  font-weight: 700;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.search-box {
  min-width: min(360px, 60vw);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 16px;
  color: var(--muted);
}
.search-box input {
  border: 0;
  outline: 0;
  background: transparent;
  width: 100%;
  color: var(--text);
}
.search-box input::placeholder { color: #73859f; }

.icon-btn,
.meta-chip {
  border: 1px solid rgba(255,255,255,.1);
  background: rgba(255,255,255,.04);
  color: var(--text);
  border-radius: 14px;
  padding: 11px 14px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 16px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
}
.user-chip small { display: block; color: var(--muted); }
.avatar {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, rgba(22,198,255,.9), rgba(124,124,255,.9));
  color: #09111f;
  font-weight: 800;
}

.kpi-grid {
  display: grid;
  gap: 18px;
}
.four-up { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.six-up { grid-template-columns: repeat(6, minmax(0, 1fr)); }

.kpi-card {
  padding: 22px;
  min-height: 136px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.card-label {
  color: var(--muted);
  font-size: .9rem;
}
.kpi-value {
  font-size: clamp(1.8rem, 2.1vw, 2.6rem);
  font-weight: 800;
  letter-spacing: -0.03em;
}
.kpi-value small {
  font-size: .45em;
  color: var(--muted);
}
.kpi-trend {
  margin: 0;
  font-size: .88rem;
}
.positive { color: #70f0a5; }
.negative { color: #ff8a8a; }
.neutral { color: var(--muted); }
.alert-accent { border-color: rgba(239,68,68,.22); }

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.75fr) minmax(320px, .75fr);
  gap: 20px;
  align-items: start;
}
.content-column,
.side-column { display: grid; gap: 20px; }

.panel,
.page-head {
  padding: 22px;
}
.panel-head {
  margin-bottom: 18px;
}
.panel-head.split {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
}
.panel-head h2 {
  font-size: 1.2rem;
}
.text-link {
  color: var(--cyan);
  font-weight: 600;
}

.status-pill,
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 700;
  font-size: .86rem;
}
.status-pill.success,
.status-chip.success,
.status-chip.ok {
  background: rgba(34,197,94,.14);
  color: #7bf0a7;
}
.status-chip.warning {
  background: rgba(245,158,11,.14);
  color: #ffcb6d;
}
.status-chip.danger,
.status-chip.critical {
  background: rgba(239,68,68,.14);
  color: #ff8e8e;
}
.status-chip.info {
  background: rgba(22,198,255,.12);
  color: #75dfff;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.broker-panel .broker-metrics,
.compact-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.broker-metrics div {
  padding: 16px;
  border-radius: 16px;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.06);
}
.broker-metrics span {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
  font-size: .84rem;
}
.broker-metrics strong {
  font-size: 1.03rem;
  word-break: break-word;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}
th, td {
  text-align: left;
  padding: 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
th {
  color: var(--muted);
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}
td {
  font-size: .94rem;
}
td span {
  display: block;
  color: var(--muted);
  margin-top: 4px;
  font-size: .83rem;
}

.lower-grid,
.detail-grid-bottom {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
}

.line-chart {
  position: relative;
  height: 280px;
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255,255,255,.025), rgba(255,255,255,.01));
  border: 1px solid rgba(255,255,255,.06);
  padding: 18px 16px 34px;
}
.tall-chart { height: 320px; }
.chart-grid {
  position: absolute;
  inset: 0 0 28px 0;
  background:
    linear-gradient(rgba(255,255,255,.045) 1px, transparent 1px) 0 0 / 100% 25%,
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px) 0 0 / 14.28% 100%;
  opacity: .6;
}
.line-chart svg {
  position: absolute;
  inset: 14px 12px 28px 12px;
  width: calc(100% - 24px);
  height: calc(100% - 42px);
}
.chart-line {
  fill: none;
  stroke: var(--cyan);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 10px rgba(22,198,255,.3));
}
.chart-line.alt {
  stroke: var(--violet);
  stroke-width: 3.5;
}
.chart-area {
  fill: url(#lineFillHome);
}
.chart-axis {
  position: absolute;
  inset: auto 14px 10px 14px;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: .76rem;
}

.bar-chart {
  height: 280px;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  align-items: end;
  gap: 14px;
  padding: 12px 4px 8px;
}
.bar-set {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  height: 100%;
  justify-content: end;
}
.bar-set i {
  display: block;
  width: 100%;
  min-width: 28px;
  border-radius: 16px 16px 8px 8px;
  background: linear-gradient(180deg, #31d6ff, #1b8fff 70%, #7c7cff);
  box-shadow: 0 16px 30px rgba(22,198,255,.18);
}
.bar-set span {
  color: var(--muted);
  font-size: .78rem;
}

.energy-flow {
  min-height: 280px;
  display: grid;
  place-items: center;
  gap: 12px;
  align-content: center;
}
.flow-node {
  min-width: 120px;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  text-align: center;
}
.flow-node span {
  display: block;
  color: var(--muted);
  margin-bottom: 6px;
}
.flow-node strong { font-size: 1.05rem; }
.flow-node.highlighted {
  background: linear-gradient(180deg, rgba(22,198,255,.16), rgba(22,198,255,.08));
  border-color: rgba(22,198,255,.22);
}
.flow-node.secondary {
  opacity: .95;
}
.flow-arrow {
  color: var(--cyan);
  font-size: 1.35rem;
  font-weight: 800;
}
.stacked-flow {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  min-height: 250px;
}

.alert-list {
  display: grid;
  gap: 14px;
}
.alert-item {
  border-radius: 18px;
  padding: 16px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.03);
}
.alert-item.critical { border-left: 4px solid var(--red); }
.alert-item.warning { border-left: 4px solid var(--amber); }
.alert-item.info { border-left: 4px solid var(--cyan); }
.alert-item p {
  margin: 10px 0 0;
  color: var(--text);
  line-height: 1.45;
}
.alert-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: .84rem;
}

.donut-chart {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background:
    radial-gradient(circle closest-side, var(--panel-strong) 64%, transparent 65%),
    conic-gradient(var(--green) 0 72%, var(--amber) 72% 88%, var(--red) 88% 100%);
  display: grid;
  place-items: center;
  margin: 0 auto 18px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06);
}
.donut-chart.uptime {
  background:
    radial-gradient(circle closest-side, var(--panel-strong) 64%, transparent 65%),
    conic-gradient(var(--cyan) 0 99.3%, rgba(255,255,255,.08) 99.3% 100%);
}
.donut-center {
  text-align: center;
}
.donut-center strong {
  display: block;
  font-size: 1.9rem;
}
.donut-center span { color: var(--muted); }
.legend-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 10px;
}
.legend-dot.green { background: var(--green); }
.legend-dot.amber { background: var(--amber); }
.legend-dot.red { background: var(--red); }

.page-footer {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-size: .82rem;
  padding-bottom: 8px;
}

.plant-head-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
}
.muted-line { margin: 8px 0 0; color: var(--muted); }
.plant-head-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.detail-grid-top {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(360px, .95fr);
  gap: 20px;
}
.chart-legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: .84rem;
}
.legend-line {
  width: 24px;
  height: 3px;
  display: inline-block;
  margin-right: 6px;
  border-radius: 999px;
  vertical-align: middle;
}
.legend-line.cyan { background: var(--cyan); }
.legend-line.violet { background: var(--violet); }
.code-block {
  margin-top: 16px;
  border-radius: 18px;
  padding: 16px;
  background: #0a1220;
  border: 1px solid rgba(22,198,255,.12);
  overflow: auto;
}
.code-block pre {
  margin: 0;
  color: #9be5ff;
  font-size: .83rem;
  line-height: 1.6;
}
.compact-table table { min-width: 680px; }

@media (max-width: 1440px) {
  .four-up { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .six-up { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dashboard-grid,
  .detail-grid-top { grid-template-columns: 1fr; }
  .lower-grid,
  .detail-grid-bottom { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .side-nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .topbar,
  .plant-head-card,
  .panel-head.split,
  .page-footer {
    flex-direction: column;
    align-items: flex-start;
  }
  .search-box { min-width: 100%; }
  .broker-panel .broker-metrics,
  .compact-metrics,
  .lower-grid,
  .detail-grid-bottom,
  .stacked-flow {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .main-area { padding: 16px; }
  .sidebar { padding: 18px 16px; }
  .side-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .four-up,
  .six-up { grid-template-columns: 1fr; }
  .topbar,
  .panel,
  .page-head,
  .kpi-card { padding: 18px; }
  .bar-chart { gap: 10px; }
  .page-footer { font-size: .75rem; }
}


/* Dynamic mock telemetry additions */
.panel.live { box-shadow: 0 0 0 1px rgba(22,198,255,.14), var(--shadow); }
.status-pill.live-pulse, .status-chip.live-pulse { position: relative; }
.status-pill.live-pulse::after, .status-chip.live-pulse::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 0 currentColor;
  animation: pulseDot 1.8s infinite;
}
@keyframes pulseDot {
  0% { box-shadow: 0 0 0 0 rgba(34,197,94,.5); }
  70% { box-shadow: 0 0 0 10px rgba(34,197,94,0); }
  100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}
.chart-shell { position: relative; }
.chart-tooltip {
  position: absolute;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 14px));
  background: rgba(6,12,24,.94);
  color: var(--text);
  border: 1px solid rgba(22,198,255,.18);
  border-radius: 12px;
  padding: 8px 10px;
  min-width: 120px;
  box-shadow: 0 16px 40px rgba(0,0,0,.35);
  font-size: .78rem;
  opacity: 0;
  transition: opacity .15s ease;
  z-index: 4;
}
.chart-tooltip.visible { opacity: 1; }
.chart-tooltip strong { display: block; margin-bottom: 3px; color: #fff; }
.chart-overlay {
  position: absolute;
  inset: 14px 12px 28px 12px;
  z-index: 3;
  cursor: crosshair;
}
.chart-focus-line {
  position: absolute;
  top: 14px;
  bottom: 28px;
  width: 1px;
  background: linear-gradient(180deg, rgba(22,198,255,.75), rgba(22,198,255,.1));
  opacity: 0;
  z-index: 2;
}
.chart-focus-line.visible { opacity: 1; }
.bar-set { position: relative; }
.bar-set.active i { filter: brightness(1.2); }
.bar-set.active::after {
  content: attr(data-value);
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(6,12,24,.94);
  border: 1px solid rgba(22,198,255,.18);
  font-size: .74rem;
  white-space: nowrap;
}
.table-wrap tbody tr { transition: background .15s ease; }
.table-wrap tbody tr:hover { background: rgba(255,255,255,.03); }
.flash-update { animation: flashUpdate .8s ease; }
@keyframes flashUpdate {
  0% { box-shadow: 0 0 0 0 rgba(22,198,255,.28); }
  100% { box-shadow: 0 0 0 16px rgba(22,198,255,0); }
}
.mqtt-stream {
  margin-top: 16px;
  display: grid;
  gap: 10px;
}
.stream-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: .82rem;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.06);
}
.stream-line b { color: var(--text); }
.small-note { color: var(--muted); font-size: .78rem; }
@media (max-width: 720px) {
  .chart-tooltip { display: none; }
}


.empty-state,
.loading-state,
.error-state {
  display: grid;
  place-items: center;
  min-height: 180px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed rgba(143,163,191,.18);
  border-radius: 18px;
  background: rgba(255,255,255,.02);
  padding: 20px;
}
.small-empty { min-height: 110px; }
.error-state { color: #ffb3b3; border-color: rgba(239,68,68,.28); }
.hint-box {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(22,198,255,.06);
  border: 1px solid rgba(22,198,255,.12);
  color: var(--muted);
  font-size: .88rem;
  line-height: 1.5;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.link-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.token-note {
  color: var(--muted);
  font-size: .8rem;
}
