*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  border: var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 0.75rem 1rem;
  border-radius: var(--r-control);
  cursor: pointer;
  font-weight: 600;
  transition: background-color 120ms, color 120ms, border-color 120ms;
}
button:hover {
  background: var(--surface);
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--sun);
  outline-offset: 2px;
}
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary,
button.primary,
.btn-charge {
  background: var(--sun);
  color: var(--bg);
  border-color: var(--sun);
}
.btn-primary:hover:not(:disabled),
button.primary:hover:not(:disabled),
.btn-charge:hover:not(:disabled) {
  background: var(--sun-hi);
  border-color: var(--sun-hi);
}

.btn-on {
  background: var(--energy);
  color: var(--bg);
  border-color: var(--energy);
}
.btn-on:hover:not(:disabled) {
  background: var(--energy-hi);
  border-color: var(--energy-hi);
}

.btn-off,
button.danger {
  background: var(--alert);
  color: var(--bg);
  border-color: var(--alert);
}
.btn-off:hover:not(:disabled),
button.danger:hover:not(:disabled) {
  background: var(--alert-hi);
  border-color: var(--alert-hi);
}

.btn-ghost,
.btn-neutral,
button.ghost {
  background: transparent;
  color: var(--text);
  border: var(--border);
}
.btn-ghost:hover:not(:disabled),
.btn-neutral:hover:not(:disabled),
button.ghost:hover:not(:disabled) {
  background: var(--surface-2);
}

button.icon {
  border-radius: var(--r-control);
  padding: 0.3rem 0.55rem;
  background: transparent;
}

.card {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--r-card);
  padding: var(--sp-5);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}

.section-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
  margin: 0;
  line-height: 1.35;
}

.live-value {
  font-family: var(--font-num);
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.live-value.power { color: var(--sun); }
.live-value.ok,
.live-value.energy { color: var(--energy); }
.live-value.low { color: var(--alert); }
.live-value.mid { color: var(--v-mid); }
.live-value.temp { color: var(--info); }
.live-value.price { color: var(--energy); }

.app-header,
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
}

.app-title {
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin: 0;
}

.app-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0.1rem 0 0;
}

.pill-group,
.view-toggle {
  display: flex;
  gap: var(--sp-1);
  background: var(--surface-2);
  border: var(--border);
  border-radius: var(--r-pill);
  padding: var(--sp-1);
}

.view-toggle button.view-chip,
.view-toggle a.view-chip {
  flex: 0 0 auto;
  min-width: 0;
  padding: 0.4rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
  background: transparent;
  color: var(--text-muted);
  border: 0;
  border-radius: var(--r-pill);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  transition: background-color 120ms, color 120ms;
}
.view-toggle button.view-chip.active,
.view-toggle a.view-chip.active {
  background: var(--sun-soft);
  color: var(--sun);
}

.status-chip-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0.28rem 0.62rem;
  border-radius: var(--r-pill);
  border: var(--border);
  background: var(--surface-2);
  font-size: 12px;
  line-height: 1.2;
}
.status-chip .status-chip-label,
.status-chip .status-chip-value {
  display: inline;
  margin: 0;
  font-size: inherit;
}
.status-chip .status-chip-label { color: var(--text-dim); }
.status-chip .status-chip-value {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}
.status-chip.on {
  background: var(--energy-soft);
  border-color: var(--energy);
}
.status-chip.on .status-chip-value { color: var(--energy); }
.status-chip.off {
  background: var(--surface-2);
  color: var(--text-dim);
}
.status-chip.info {
  background: var(--info-soft);
  border-color: var(--info);
  color: var(--info);
}
.status-chip .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--info);
  flex: 0 0 auto;
}

.chart-tip {
  position: absolute;
  display: none;
  pointer-events: none;
  z-index: 3;
  background: var(--surface-2);
  border: var(--border);
  border-radius: var(--r-control);
  padding: 0.28rem 0.45rem;
  font-family: var(--font-num);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  white-space: nowrap;
}
.chart-tip.show { display: block; }

.toast {
  position: fixed;
  right: var(--sp-4);
  bottom: var(--sp-4);
  background: var(--surface-2);
  border: var(--border);
  padding: 0.7rem 0.9rem;
  border-radius: var(--r-control);
  max-width: 22rem;
  z-index: 30;
}

.hidden { display: none !important; }

input, select, textarea {
  background: var(--surface-2);
  border: var(--border);
  border-radius: var(--r-control);
  padding: 0.55rem 0.7rem;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--sun);
  outline-offset: 2px;
}

.muted { color: var(--text-muted); }
.form-error,
#message.error { color: var(--alert); }
#message.ok { color: var(--energy); }
#message.warn { color: var(--sun); }
