:root {
  --bg: #0b1220;
  --panel: #121b2b;
  --panel-2: #182235;
  --panel-soft: rgba(255,255,255,0.03);
  --text: #e8eefc;
  --muted: #9fb0d1;
  --border: rgba(255,255,255,0.08);
  --shadow: 0 10px 30px rgba(0,0,0,0.25);
  --green: #35c759;
  --yellow: #ffb020;
  --red: #ff6b57;
  --blue: #4fc3f7;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: linear-gradient(180deg, #09101c 0%, #0d1626 100%);
  color: var(--text);
}

.page {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 20px 40px;
}

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

.topbar h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

.overview-grid {
  display: grid;
  grid-template-columns: 1.2fr 1.2fr 1.2fr 1.2fr;
  gap: 16px;
  align-items: start;
}

.card {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.energy-card { grid-column: 1; }
.forecast-card { grid-column: 2; }
.inverters-card { grid-column: 3; }
.today-card { grid-column: 4; }
.pv-eff-card { grid-column: 1 / span 3; }
.energy-history-card { grid-column: 1 / span 3; }
.mppt-history-card { grid-column: 1 / span 3; }
.balancing-history-card { grid-column: 1 / span 3; }
.thermal-card { grid-column: 4; }

.card-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 14px;
}

.energy-layout {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr;
  gap: 12px;
}

.energy-box {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  text-align: center;
}

.center-box { background: rgba(255,255,255,0.05); }

.label {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 8px;
}

.value {
  font-size: 42px;
  font-weight: 700;
  line-height: 1.1;
}

.unit {
  font-size: 14px;
  color: var(--muted);
  margin-top: 8px;
}

.status {
  margin-top: 12px;
  display: inline-block;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  background: rgba(255,255,255,0.08);
}

.status.charging { background: rgba(53,199,89,0.18); color: #7df0a0; }
.status.discharging { background: rgba(255,107,87,0.18); color: #ffb1a7; }
.status.idle { background: rgba(159,176,209,0.18); color: #d6def1; }

.battery-row {
  margin-top: 16px;
  display: flex;
  justify-content: space-between;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.battery-label { color: var(--muted); }
.battery-value { font-weight: 700; }

.banner {
  color: white;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 12px;
}

.rows { display: grid; gap: 0; }

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: 15px;
}

.row span { color: #d0d0d0; }
.row strong { color: white; }

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

.gauge-card {
  background: var(--panel-soft);
  border-radius: 16px;
  padding: 14px;
  text-align: center;
}

.gauge-name {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 10px;
}

.gauge-ring {
  position: relative;
  width: 210px;
  height: 210px;
  margin: 0 auto;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, #162033 0 58%, transparent 59% 100%),
    conic-gradient(#1f2a3d 0deg, #1f2a3d 360deg);
}

.gauge-fill {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, transparent 0 58%, transparent 59% 100%),
    conic-gradient(var(--green) 0deg, var(--green) 0deg, #1f2a3d 0deg 360deg);
}

.gauge-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 4px;
  pointer-events: none;
}

.gauge-value {
  font-size: 48px;
  font-weight: 700;
  line-height: 1;
}

.gauge-sub,
.gauge-temp {
  font-size: 14px;
  color: var(--muted);
}

.today-top-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.mini-stat {
  border-radius: 10px;
  padding: 10px 12px;
  text-align: center;
}

.mini-yellow { background: rgba(255,213,79,0.08); }
.mini-blue { background: rgba(79,195,247,0.08); }

.mini-label {
  font-size: 13px;
  color: #d0d0d0;
}

.mini-value {
  font-size: 20px;
  font-weight: 700;
  margin-top: 2px;
}

.balance-box {
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  padding: 10px 12px;
  margin-top: 12px;
}

.balance-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 15px;
}

.balance-track {
  height: 8px;
  background: rgba(255,255,255,0.08);
  border-radius: 999px;
  overflow: hidden;
}

.balance-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: var(--green);
}

.balance-fill.red { background: var(--red); }
.balance-fill.green { background: var(--green); }

.balance-kind {
  margin-top: 6px;
  font-size: 13px;
  color: #bdbdbd;
  text-align: right;
}

.subsection-title {
  margin-top: 14px;
  margin-bottom: 10px;
  font-size: 18px;
  font-weight: 700;
}

.battery-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.battery-card {
  background: #282828;
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 6px;
}

.battery-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  padding-bottom: 6px;
}

.battery-name {
  font-size: 17px;
  font-weight: 700;
}

.battery-soc {
  font-size: 16px;
  font-weight: 700;
}

.battery-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 15px;
}

.battery-meta,
.battery-cells {
  font-size: 14px;
  color: #d0d0d0;
  display: grid;
  gap: 4px;
}

.green { color: #81c784; }
.yellow { color: #ffb74d; }
.red { color: #ff8a65; }

@media (max-width: 1280px) {
  .overview-grid { grid-template-columns: 1fr 1fr; }
  .energy-card, .forecast-card, .inverters-card, .today-card { grid-column: auto; }
}

@media (max-width: 900px) {
  .overview-grid,
  .energy-layout,
  .gauge-grid,
  .today-top-grid,
  .battery-cards {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .gauge-ring {
    width: 180px;
    height: 180px;
  }

  .gauge-value {
    font-size: 38px;
  }
}
.chart-wrap {
  position: relative;
  width: 100%;
  height: 320px;
}

.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

.pv-eff-top {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.pv-eff-box {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
}

.pv-eff-value {
  margin-top: 4px;
  font-size: 24px;
  font-weight: 700;
}

.mppt-table {
  display: grid;
  gap: 0;
}

.mppt-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: 15px;
}

.mppt-row-label {
  color: #d0d0d0;
}

.mppt-row-value {
  font-weight: 700;
  color: #ffffff;
}

@media (max-width: 900px) {
  .pv-eff-top {
    grid-template-columns: 1fr;
  }
}

.thermal-box {
  background: rgba(255,255,255,0.04);
  border-radius: 12px;
  padding: 12px;
  margin-top: 10px;
}

.thermal-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 700;
}

.thermal-sub {
  margin-top: 8px;
  font-size: 14px;
  color: #cfd8dc;
}

#thermal_inv_status,
#thermal_bat_status {
  font-weight: 700;
}

.chart-wrap-small {
  height: 260px;
}