:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --line: #e5e7eb;
  --ink: #111827;
  --muted: #6b7280;
  --brand: #e6584b;
  --brand-ink: #fff;
  --ok: #16a34a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

h1, h2, h3 { margin: 0 0 .6rem; }
h2 { font-size: 1rem; }
h3 { font-size: .95rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  padding: .5rem .8rem;
}
button.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
}
button.ghost { background: transparent; }
button.ghost.sm { padding: .25rem .5rem; font-size: .8rem; }
button.danger { color: var(--brand); }
button:disabled { opacity: .6; cursor: default; }

input, select {
  font: inherit;
  width: 100%;
  padding: .5rem .6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

label {
  display: block;
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: .6rem;
}
label input, label select { margin-top: .25rem; color: var(--ink); }

.hint { font-size: .8rem; color: var(--muted); }
.error { color: var(--brand); font-size: .85rem; margin: .4rem 0 0; }
.muted { color: var(--muted); }

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.auth-card { width: min(380px, 100%); }
.tabs { display: flex; gap: .5rem; margin-bottom: 1rem; }
.tab {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--line);
}
.tab.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.auth-card .primary { width: 100%; margin-top: .4rem; }

.topbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .7rem 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar .spacer { flex: 1; }
.who { color: var(--muted); font-size: .9rem; }

.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1rem;
  padding: 1rem;
  align-items: start;
}
.sidebar { display: flex; flex-direction: column; gap: 1rem; }
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
}

.claim { display: flex; gap: .5rem; margin-bottom: .5rem; }
.claim input { flex: 1; }
.claim button { white-space: nowrap; }

.sensor-list { list-style: none; margin: .5rem 0 0; padding: 0; }
.sensor-list li {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem 0;
  border-top: 1px solid var(--line);
}
.sensor-list li:first-child { border-top: 0; }
.sname { font-weight: 600; }
.badge {
  display: inline-block;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .05rem .45rem;
  margin-left: .35rem;
  color: var(--muted);
}
.smeta { font-size: .75rem; color: var(--muted); margin-top: .15rem; }
.row-actions { margin-left: auto; display: flex; gap: .25rem; }

.widget-form .fields {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .35rem;
}
.chk {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  margin: 0;
  color: var(--ink);
  font-size: .85rem;
}
.chk input { width: auto; }

.board-wrap { min-height: 60vh; }
.board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}
.empty {
  color: var(--muted);
  text-align: center;
  padding: 3rem 1rem;
}
.widget { display: flex; flex-direction: column; }
.widget-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .5rem;
}
.widget-head h3 { margin: 0; }
.widget-body { min-height: 60px; }
canvas.chart { width: 100%; height: 200px; display: block; cursor: grab; }

.chart-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  margin-bottom: .5rem;
  align-items: center;
}
.chart-toolbar .sm { padding: .2rem .5rem; font-size: .78rem; }
.live-btn { border: 1px solid var(--line); background: #fff; color: var(--muted); }
.live-btn.on { background: #fde8e6; border-color: var(--brand); color: var(--brand); }
.load-older { margin-top: .5rem; width: 100%; }

.events { max-height: 260px; overflow: auto; }
.event-row {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  padding: .35rem 0;
  border-top: 1px solid var(--line);
  font-size: .85rem;
}
.event-row:first-child { border-top: 0; }
.event-time { font-variant-numeric: tabular-nums; }
.event-detail { color: var(--muted); }

.value-box { display: flex; flex-wrap: wrap; gap: 1rem; align-items: baseline; }
.value-item { display: flex; flex-direction: column; }
.vk { font-size: .75rem; color: var(--muted); text-transform: capitalize; }
.vv { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.value-ts {
  width: 100%;
  font-size: .75rem;
  color: var(--muted);
  margin-top: .25rem;
}
