:root {
  --bg: #f4f2ee;
  --card: #ffffff;
  --ink: #1d1f22;
  --muted: #6b6f76;
  --line: #dedad3;
  --accent: #b4441e;      /* Temperatur */
  --rh: #2f6f8f;          /* Luftfeuchte */
  --heat: rgba(214, 120, 40, .18);
  --ok: #2d7a46;
  --warn: #a35c00;
  --err: #a32020;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a; --card: #212326; --ink: #ecebe8; --muted: #9a9ea5; --line: #34373b;
    --accent: #ef7a4c; --rh: #6fb3d6; --heat: rgba(239, 140, 60, .16);
    --ok: #5fbf7d; --warn: #e3a44a; --err: #ef6b6b;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
header { display: flex; align-items: center; gap: 1rem; padding: .7rem 1.2rem; border-bottom: 1px solid var(--line); background: var(--card); flex-wrap: wrap; }
.brand { font-weight: 650; color: inherit; text-decoration: none; margin-right: auto; }
nav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
nav a { color: inherit; }
.who { color: var(--muted); }
main { max-width: 1100px; margin: 0 auto; padding: 1.2rem; }
h1 { font-size: 1.4rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.6rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1.2rem 0 .5rem; }
a { color: var(--rh); }
.muted { color: var(--muted); font-weight: normal; }
.narrow { max-width: 380px; margin: 3rem auto; }
.stack { display: grid; gap: .8rem; }
.row { display: flex; gap: .8rem; align-items: end; }
.row.between { justify-content: space-between; align-items: center; flex-wrap: wrap; }
.row.wrap { flex-wrap: wrap; }
label { display: grid; gap: .25rem; font-size: .9rem; color: var(--muted); }
label.check { display: flex; align-items: center; gap: .4rem; }
input[type=text], input[type=email], input[type=password] {
  font: inherit; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); min-width: 0;
}
button { font: inherit; padding: .5rem .9rem; border-radius: 6px; border: 1px solid var(--ink); background: var(--ink); color: var(--card); cursor: pointer; }
button.small { padding: .2rem .55rem; font-size: .85rem; background: transparent; color: var(--ink); border-color: var(--line); }
button.danger { color: var(--err); }
button.link { background: none; border: 0; color: inherit; text-decoration: underline; padding: 0; }
form.inline { display: inline; }
.msg { padding: .6rem .8rem; border-radius: 6px; border: 1px solid var(--line); background: var(--card); }
.msg.err { border-color: var(--err); color: var(--err); }
.msg.info { border-left: 4px solid var(--rh); }
.invite { display: flex; gap: .5rem; }
.invite input { flex: 1; font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }

table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; }
td.actions { white-space: nowrap; }
tr.st-pending td { background: color-mix(in srgb, var(--warn) 10%, transparent); }
code { font-size: .85rem; }

/* Gerätekarten */
#devices { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.dev { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.1rem; cursor: pointer; }
.dev.sel { outline: 2px solid var(--ink); outline-offset: -1px; }
.dev .top { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.dev .name { font-weight: 600; }
.dot { display: inline-block; width: .55rem; height: .55rem; border-radius: 50%; margin-right: .35rem; background: var(--muted); }
.dot.on { background: var(--ok); }
.dot.off { background: var(--err); }
.vals { display: flex; gap: 1.6rem; margin: .7rem 0 .5rem; align-items: baseline; flex-wrap: wrap; }
.big { font-size: 2.4rem; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.02em; color: var(--accent); }
.mid { font-size: 1.3rem; font-variant-numeric: tabular-nums; color: var(--rh); }
.unit { font-size: .55em; font-weight: 500; margin-left: .1em; }
.state { display: flex; gap: .5rem; flex-wrap: wrap; }
.pill { font-size: .8rem; padding: .15rem .55rem; border-radius: 999px; border: 1px solid var(--line); }
.pill.heat { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.pill.boost { background: var(--ink); color: var(--card); border-color: var(--ink); }
.dev .foot { margin-top: .6rem; font-size: .8rem; color: var(--muted); }

/* Verlauf */
#history { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 0 1.1rem 1rem; margin-top: 1.4rem; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { background: transparent; color: var(--ink); border: 0; border-radius: 0; padding: .3rem .7rem; font-size: .85rem; }
.seg button.on { background: var(--ink); color: var(--card); }
.legend { display: flex; gap: 1rem; font-size: .85rem; margin: .3rem 0 .4rem; flex-wrap: wrap; align-items: center; }
.lg::before { content: ""; display: inline-block; width: 1rem; height: .2rem; margin-right: .35rem; vertical-align: middle; }
.lg.temp::before { background: var(--accent); }
.lg.rh::before { background: var(--rh); }
.lg.heat::before { background: var(--heat); height: .7rem; border: 1px solid var(--accent); }
.chart { width: 100%; height: 300px; position: relative; }
.chart svg { width: 100%; height: 100%; display: block; }
.chart .empty { position: absolute; top: 40%; width: 100%; text-align: center; margin: 0; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 4; }
.chart .lbl { fill: var(--muted); font-size: 11px; }
.chart .l-temp { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart .l-rh { fill: none; stroke: var(--rh); stroke-width: 1.5; stroke-dasharray: 4 3; }
.chart .heat { fill: var(--heat); }
.chart .cursor { stroke: var(--muted); stroke-width: 1; }
.tip { position: absolute; pointer-events: none; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: .35rem .5rem; font-size: .8rem; white-space: nowrap; box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.events { list-style: none; padding: 0; margin: 0; font-size: .9rem; max-height: 260px; overflow: auto; }
.events li { padding: .3rem 0; border-bottom: 1px solid var(--line); display: flex; gap: .8rem; }
.events time { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 8.5rem; }

/* Fernsteuerung und Grenzwerte */
.badge { display: inline-block; font-size: .75rem; padding: .05rem .45rem; border-radius: 4px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.ok { border-color: var(--ok); color: var(--ok); }
.badge.warn { border-color: var(--warn); color: var(--warn); }
.badge.err { border-color: var(--err); color: var(--err); }
.ctl { margin-top: .7rem; padding-top: .6rem; border-top: 1px solid var(--line); font-size: .85rem; display: grid; gap: .35rem; }
.ctl-btns { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .15rem; }
.ctl-btns a { font-size: .85rem; margin-left: auto; }
button:disabled { opacity: .5; cursor: wait; }
.cfg { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 0 1.1rem 1rem; margin-top: 1.4rem; }
.cfg-form { display: grid; gap: .8rem; }
.cfg-form fieldset { border: 1px solid var(--line); border-radius: 8px; display: flex; gap: .8rem; flex-wrap: wrap; padding: .5rem .8rem .8rem; margin: 0; }
.cfg-form legend { font-size: .85rem; font-weight: 600; padding: 0 .3rem; }
.cfg-form input { width: 7rem; }
p.small { font-size: .85rem; }
.events li.ev-on span:first-of-type { color: var(--accent); }
.events li.ev-op { font-weight: 600; }
.chart .mk line { stroke-width: 1; stroke-dasharray: 3 3; }
.chart .mk path { stroke-width: 1.5; }
.chart .mk.start line, .chart .mk.start path { stroke: var(--accent); fill: var(--accent); }
.chart .mk.stop line, .chart .mk.stop path { stroke: var(--ink); fill: var(--card); }
.chart .mk.remote line, .chart .mk.remote path { stroke: var(--rh); fill: var(--rh); }
.lg.mk::before { width: 0; height: 0; background: none; border-left: .35rem solid transparent; border-right: .35rem solid transparent; border-top: .55rem solid var(--accent); }
