:root {
  --bg: #f6f7f4; --card: #fff; --text: #1d2420; --muted: #6b746e; --line: #e3e7e1;
  --accent: #2f7d4f; --accent-soft: #e4f2e8;
  --ok: #2f7d4f; --ok-bg: #e4f2e8; --warn: #a15c00; --warn-bg: #fdf0dc;
  --bad: #b3261e; --bad-bg: #fbe5e3; --info: #2457a6; --info-bg: #e3ecfa; --grey-bg: #eef0ed;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141816; --card: #1d2320; --text: #e6ebe7; --muted: #95a09a; --line: #2c3430;
    --accent: #6cc28f; --accent-soft: #1f3a2a;
    --ok: #6cc28f; --ok-bg: #1f3a2a; --warn: #f0b45a; --warn-bg: #3d2f17;
    --bad: #f2867e; --bad-bg: #3f1f1d; --info: #8fb4f0; --info-bg: #1d2a40; --grey-bg: #262d29;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
.topbar { flex-wrap: wrap; row-gap: 6px; display: flex; align-items: center; gap: 24px; padding: 12px 20px; background: var(--card);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 18px; color: var(--text); }
nav { display: flex; gap: 4px; }
nav a { padding: 6px 12px; border-radius: 999px; color: var(--muted); }
nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.statusbar { padding: 8px 20px; font-size: 13px; color: var(--muted); display: flex; gap: 12px;
  flex-wrap: wrap; align-items: center; }
.statusbar .err { color: var(--bad); }
main { padding: 8px 20px 40px; max-width: 1200px; margin: 0 auto; }
h1 { font-size: 24px; margin: 8px 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); gap: 16px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); overflow: hidden; }
.card.pad { padding: 16px; }
a.card { color: inherit; display: block; transition: transform .1s; }
a.card:hover { transform: translateY(-2px); }
.card .photo { height: 140px; background: var(--grey-bg) center/cover no-repeat; display: flex;
  align-items: center; justify-content: center; font-size: 48px; }
.card .body { padding: 14px 16px 16px; }
.card .title { font-weight: 650; font-size: 17px; }
.metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 12px 0 8px; }
.metric { background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.metric .label { font-size: 12px; color: var(--muted); }
.metric .value { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.metric .value.na { color: var(--muted); font-weight: 400; font-size: 15px; }
.metrics.big { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.metrics.big .value { font-size: 24px; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.badge { font-size: 12px; padding: 3px 9px; border-radius: 999px; font-weight: 600; white-space: nowrap; }
.b-ok { background: var(--ok-bg); color: var(--ok); }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-bad { background: var(--bad-bg); color: var(--bad); }
.b-info { background: var(--info-bg); color: var(--info); }
.b-grey { background: var(--grey-bg); color: var(--muted); }
.add-card { display: flex; align-items: center; justify-content: center; min-height: 200px;
  border: 2px dashed var(--line); border-radius: var(--radius); color: var(--muted); font-weight: 600;
  background: transparent; cursor: pointer; font-size: 15px; }
.add-card:hover { border-color: var(--accent); color: var(--accent); }
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 7px 14px; border-radius: 10px; cursor: pointer; display: inline-block; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
form .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text); width: 100%; }
label.check { flex-direction: row; align-items: center; gap: 8px; align-self: end; padding-bottom: 10px; color: var(--text); }
label.check input { width: auto; flex: none; margin: 0; }
textarea { min-height: 80px; resize: vertical; }
.layout { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }
.stack > * + * { margin-top: 16px; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 12px; }
.chart h3 { margin: 0 0 4px; font-size: 14px; font-weight: 600; }
.chart .empty { height: 160px; display: flex; align-items: center; justify-content: center; color: var(--muted);
  font-size: 13px; background: var(--bg); border-radius: 10px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: space-between; margin-bottom: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.table-wrap { overflow-x: auto; }
code { word-break: break-all; font-size: 12px; background: var(--grey-bg); padding: 1px 5px; border-radius: 5px; }
.hero { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.hero .photo { width: 110px; height: 110px; border-radius: 14px; background: var(--grey-bg) center/cover no-repeat;
  display: flex; align-items: center; justify-content: center; font-size: 46px; flex: none; }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--info-bg); color: var(--info); font-size: 14px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; }
.u-legend { font-size: 12px; }
@media (max-width: 520px) { main { padding: 8px 12px 32px; } .topbar { gap: 8px 16px; padding: 10px 12px; } th, td { padding: 6px; } }
body.public [data-nav="sensors"], body.public [data-nav="settings"], body.public .edit { display: none; }
body.admin .local-only { display: none; }
.pending { display: none; position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow); }
