:root {
  --page: #17191d;
  --surface-1: #22252a;
  --surface-2: #2a2e34;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --hairline: #2f3237;
  --baseline: #3c4046;
  --border: rgba(255, 255, 255, 0.10);
  /* Validated dark-mode categorical palette (solar, home, battery, grid) */
  --series-pv: #b18f1c;
  --series-load: #2a9d72;
  --series-bat: #6f83ec;
  --series-grid: #e05555;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 6px;
  max-width: 900px;
  margin: 0 auto;
}
.topbar h1 { font-size: 1.15rem; font-weight: 600; margin: 0; }

.topbar-right { display: flex; align-items: center; gap: 8px; }

.updated { color: var(--text-muted); font-size: 0.78rem; white-space: nowrap; }

.logout-btn {
  min-height: 33px;
  padding: 6px 12px;
  background: var(--surface-1);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.soc-chip {
  font-size: 0.9rem;
  color: var(--text-secondary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 8px 12px 32px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}

.banner {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  padding: 10px 12px;
}

/* Date navigation */
.date-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
}
.nav-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 0.9rem;
  cursor: pointer;
}
.nav-btn:disabled { opacity: 0.35; cursor: default; }
#date-input {
  flex: 1;
  height: 44px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font: inherit;
  font-size: 1rem;
  text-align: center;
  color-scheme: dark;
}

/* Chart */
.chart-wrap {
  position: relative;
  height: min(52vh, 460px);
  min-height: 300px;
}
.series-chips {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.chip {
  flex: 1 1 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
}
.chip:not(.active) { opacity: 0.45; }
.chip:not(.active) .dot { background: var(--text-muted) !important; }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex: 0 0 auto;
}
.dot-pv { background: var(--series-pv); }
.dot-load { background: var(--series-load); }
.dot-bat { background: var(--series-bat); }
.dot-grid { background: var(--series-grid); }

/* Stat cards */
.stat-card h2 {
  margin: 2px 0 10px;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  color: var(--text-primary);
}
.stat-card dl { margin: 0; }
.stat-card dl > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 2px;
  border-bottom: 1px solid var(--hairline);
}
.stat-card dl > div:last-child { border-bottom: none; }
.stat-card dt {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 0.95rem;
}
.stat-card dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.stat-card dd .unit { color: var(--text-muted); font-weight: 400; margin-left: 3px; }

/* Data table */
.table-card summary {
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.95rem;
  min-height: 28px;
}
.table-scroll { max-height: 340px; overflow: auto; margin-top: 10px; }
#data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
#data-table th, #data-table td {
  text-align: right;
  padding: 5px 8px;
  border-bottom: 1px solid var(--hairline);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#data-table th:first-child, #data-table td:first-child { text-align: left; }
#data-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-1);
  color: var(--text-muted);
  font-weight: 500;
}
#data-table td { color: var(--text-secondary); }

@media (min-width: 700px) {
  main {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .date-nav, .chart-card, .table-card, .banner { grid-column: 1 / -1; }
  .chart-wrap { height: min(56vh, 520px); }
}
