:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --good: #0ca30c;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --good: #0ca30c;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --good: #0ca30c;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--page);
  color: var(--text-primary);
}

#app {
  display: flex;
  height: 100vh;
}

.lang-toggle {
  position: fixed;
  top: 12px;
  right: 16px;
  z-index: 20;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  cursor: pointer;
}

.lang-toggle:hover {
  background: var(--page);
}

/* Sidebar / tree */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  padding: 16px 0 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.tree-list {
  flex: 1;
  overflow-y: auto;
}

.sidebar-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-user {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-link {
  font-family: inherit;
  font-size: 12px;
  color: var(--series-1);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.tree-root {
  padding: 0 16px 12px;
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tree-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree-group {
  margin-bottom: 4px;
}

.tree-group-name {
  padding: 10px 16px 4px 16px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.tree-sublist {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 16px 8px 40px;
  border: none;
  background: none;
  text-align: left;
  font-size: 13.5px;
  color: var(--text-primary);
  cursor: pointer;
  font-family: inherit;
}

.tree-item:hover {
  background: var(--page);
}

.tree-item.active {
  background: var(--page);
  box-shadow: inset 3px 0 0 var(--series-1);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-muted);
}

.status-dot.online {
  background: var(--good);
}

.tree-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meter-badge {
  font-size: 10px;
  color: var(--series-1);
  flex-shrink: 0;
}

/* Main panel */
.main {
  flex: 1;
  overflow-y: auto;
  padding: 28px 36px;
}

.empty-state {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 60px;
  text-align: center;
}

.panel-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 4px;
}

.panel-header h1 {
  font-size: 20px;
  margin: 0;
}

.panel-sub {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 20px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

/* Info card for non-meter devices */
.info-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  max-width: 480px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13.5px;
  border-bottom: 1px solid var(--grid);
}

.info-row:last-child {
  border-bottom: none;
}

.info-row .label {
  color: var(--text-secondary);
}

.info-row .value {
  color: var(--text-primary);
  font-weight: 500;
}

.info-note {
  margin-top: 16px;
  font-size: 12.5px;
  color: var(--text-muted);
}

/* Admin: user management */
.admin-user-list {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 20px;
  max-width: 480px;
  margin-bottom: 24px;
}

.admin-form {
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.admin-field label {
  font-size: 12.5px;
  color: var(--text-secondary);
}

.admin-field input,
.admin-field select {
  font-family: inherit;
  font-size: 13.5px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
}

.admin-section-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--grid);
}

.admin-error {
  color: #e34948;
  font-size: 12.5px;
}

.admin-success {
  color: var(--good);
  font-size: 12.5px;
}

/* Filter row */
.filter-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.filter-btn {
  font-family: inherit;
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
}

.filter-btn.active {
  background: var(--series-1);
  color: #fff;
  border-color: var(--series-1);
}

.period-group {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
  padding-left: 12px;
  border-left: 1px solid var(--grid);
  font-size: 12.5px;
  color: var(--text-muted);
}

.period-group.active {
  color: var(--text-secondary);
}

.period-input {
  font-family: inherit;
  font-size: 12px;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
}

.range-label {
  font-size: 12px;
  color: var(--text-muted);
  margin: -8px 0 16px;
}

.gap-notice {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  color: var(--text-muted);
  margin: -8px 0 16px;
}

.gap-notice:empty {
  display: none;
}

/* Stat tiles */
.stat-row {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 18px;
  min-width: 150px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: proportional-nums;
}

/* Charts grid */
.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

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

.chart-card-wide {
  grid-column: 1 / -1;
}

.chart-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 2px;
}

.legend {
  display: flex;
  gap: 14px;
  margin: 6px 0 4px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-secondary);
}

.legend-key {
  width: 12px;
  height: 2px;
  border-radius: 1px;
}

.chart-svg {
  width: 100%;
  height: 200px;
  overflow: visible;
}

.tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  display: none;
  z-index: 10;
  min-width: 140px;
}

.tooltip-time {
  color: var(--text-muted);
  font-size: 11px;
  margin-bottom: 4px;
}

.tooltip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: space-between;
}

.tooltip-key {
  width: 10px;
  height: 2px;
  border-radius: 1px;
  flex-shrink: 0;
}

.tooltip-name {
  color: var(--text-secondary);
  flex: 1;
}

.tooltip-value {
  color: var(--text-primary);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 860px) {
  .chart-grid {
    grid-template-columns: 1fr;
  }
}
