:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #edf5f2;
  --text: #17211f;
  --muted: #697673;
  --line: #dce4e1;
  --green: #178f63;
  --amber: #e0a128;
  --blue: #2f78c4;
  --red: #cf5c47;
  --shadow: 0 12px 35px rgba(29, 44, 40, 0.08);
}

* {
  box-sizing: border-box;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px clamp(16px, 4vw, 44px);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.eyebrow,
.panel-heading span,
.metric span,
.flow-item span,
.totals-grid span {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.7rem, 3vw, 2.45rem);
}

h2 {
  font-size: 1.08rem;
}

main {
  width: min(1220px, calc(100% - 32px));
  margin: 24px auto 48px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 132px;
  justify-content: center;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 700;
}

.status-pill.connected {
  color: var(--green);
}

.status-pill.offline {
  color: var(--red);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.metric,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric {
  min-height: 132px;
  padding: 18px;
  display: grid;
  align-content: space-between;
}

.metric.primary {
  background: #e9f7ef;
  border-color: #c7e9d5;
}

.metric strong {
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1;
}

.metric small {
  color: var(--muted);
  font-weight: 800;
}

.live-layout {
  display: grid;
  grid-template-columns: 1.35fr 0.9fr;
  gap: 16px;
  margin-top: 16px;
}

.panel {
  padding: 18px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.flow-grid,
.totals-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.flow-item,
.totals-grid div {
  min-height: 88px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  display: grid;
  align-content: space-between;
}

.flow-item strong,
.totals-grid strong {
  font-size: 1.25rem;
}

.flow-item small {
  color: var(--muted);
  font-weight: 700;
}

.history-panel {
  margin-top: 16px;
}

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

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

.kv-grid div {
  min-height: 70px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  display: grid;
  align-content: space-between;
}

.kv-grid strong {
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}

.energy-table {
  display: grid;
  gap: 8px;
  overflow-x: auto;
}

.energy-row {
  display: grid;
  grid-template-columns: minmax(92px, 1.2fr) repeat(4, minmax(72px, 1fr));
  gap: 8px;
  min-width: 480px;
  align-items: center;
}

.energy-row > * {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.energy-row.header > * {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.history-heading {
  align-items: flex-start;
}

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

select,
input,
button {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 700;
}

select,
input {
  padding: 0 11px;
}

button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  cursor: pointer;
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}

button svg {
  width: 16px;
  height: 16px;
}

.chart-box {
  position: relative;
  height: 380px;
}

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

  .overview-grid,
  .live-layout,
  .flow-grid,
  .details-grid,
  .kv-grid,
  .totals-grid {
    grid-template-columns: 1fr;
  }

  .filters {
    width: 100%;
    justify-content: stretch;
  }

  .filters select,
  .filters input,
  .filters button {
    flex: 1 1 145px;
  }
}
