:root {
  --bg: #0f1419;
  --panel: #1a2029;
  --panel-2: #232b36;
  --text: #e6edf3;
  --muted: #8b97a7;
  --accent: #4f9cff;
  --on: #51cf66;
  --off: #4a5566;
  --border: #2c3440;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

h1 { font-size: 1.2rem; margin: 0; }
h2 { font-size: 1rem; margin: 0; }
.muted { color: var(--muted); font-size: 0.85rem; }

/* ---- Login ---- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: var(--panel);
  padding: 2rem;
  border-radius: 12px;
  box-shadow: var(--shadow);
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  border: 1px solid var(--border);
}
.login-card h1 { text-align: center; font-size: 1.6rem; }
.login-card .subtitle { text-align: center; color: var(--muted); margin: -0.5rem 0 0.5rem; }
.login-card label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; color: var(--muted); }
.login-card input {
  padding: 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 1rem;
}
button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
}
button.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); font-weight: 500; }
.error { color: #ff6b6b; font-size: 0.85rem; margin: 0; text-align: center; }

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 0.6rem; }
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--off); box-shadow: 0 0 0 0 transparent;
}
.dot.online { background: var(--on); box-shadow: 0 0 8px var(--on); }

/* ---- Summary ---- */
.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  padding: 1.25rem;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
}
.stat-label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 1.8rem; font-weight: 700; margin-top: 0.25rem; }

main { padding: 0 1.25rem 2rem; }

/* ---- Channel cards ---- */
.channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--off);
  border-radius: 12px;
  padding: 1rem;
  transition: border-color 0.2s;
}
.card.on { border-left-color: var(--on); }
.card-head { display: flex; align-items: center; gap: 0.5rem; }
.card-head .name {
  flex: 1;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
  min-width: 0;
}
.card-head .name:hover { border-color: var(--border); }
.card-head .name:focus { border-color: var(--accent); background: var(--panel-2); outline: none; }

.readout { display: flex; align-items: baseline; gap: 1rem; margin: 0.75rem 0; }
.metric { display: flex; align-items: baseline; gap: 0.2rem; }
.metric .m-value { font-size: 1.6rem; font-weight: 700; }
.metric.small .m-value { font-size: 1rem; color: var(--muted); font-weight: 600; }
.metric .m-unit { color: var(--muted); font-size: 0.8rem; }

.card-foot { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.8rem; }
.card-state { margin-top: 0.5rem; font-size: 0.75rem; letter-spacing: 0.03em; }
.card-state.want-on { color: var(--on); }
.card-state.want-off { color: var(--muted); }

/* ---- Switch ---- */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--off); border-radius: 24px; transition: 0.2s;
}
.slider::before {
  content: ''; position: absolute; height: 18px; width: 18px;
  left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: 0.2s;
}
.switch input:checked + .slider { background: var(--on); }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* ---- Graph ---- */
.graph-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}
.graph-controls { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.graph-controls .spacer { flex: 1; }
.graph-controls label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.75rem; color: var(--muted); }
.graph-controls select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  font-size: 0.9rem;
}
#history-chart { height: 340px; max-height: 340px; }
