:root {
    --bg: #f4f5f2;
    --card: #ffffff;
    --text: #1d211c;
    --muted: #5d665a;
    --line: #dde1d9;
    --accent: #2f6b3a;
    --warn: #b3261e;
    --cold: #1f5fae;
    --on: #1aa34a;
    color-scheme: light;
}
* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .75rem 1rem; background: var(--accent); color: #fff; }
.brand { font-weight: 600; }
.logout { display: flex; align-items: center; gap: .75rem; margin: 0; }
.logout button { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.6); padding: .3rem .7rem; }
main { max-width: 1100px; margin: 0 auto; padding: 1rem; }
h1 { font-size: 1.35rem; margin: 1.25rem 0 .75rem; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem; }
.narrow { max-width: 380px; margin: 2rem auto; }
p.secret code { display: block; margin: .4rem 0; font-size: 1.15rem; letter-spacing: .04em; word-break: break-all; }
/* Cards in one row stretch to the same height; on a phone (one per row) each is as tall as its content */
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.sensor .temp { font-size: 2rem; font-weight: 600; margin: .25rem 0; }
/* Change over the last hour, shown small beside the big temperature. Colour is a thermometer hue
   (blue cooling, orange warming), not an alarm signal, so it never reads like a threshold warning. */
.sensor .temp .trend { font-size: .9rem; font-weight: 600; white-space: nowrap; vertical-align: middle; margin-left: .35rem; }
.sensor .temp .trend.down { color: var(--cold); }
.sensor .temp .trend.up { color: #c2410c; }
.sensor .temp .trend.flat { color: var(--muted); }
.sensor .hum { margin: 0 0 .5rem; color: var(--muted); }
.sensor .meta { font-size: .85rem; color: var(--muted); margin: 0; }
.sensor.out .temp { color: var(--warn); }
/* Same 1px border as other cards plus a ring, so a stale card is not bigger than the rest */
.sensor.stale { border-color: var(--warn); box-shadow: 0 0 0 1px var(--warn); }
/* Alarm power button (editors) or status icon (viewers) in the corner of a sensor card.
   A grid so the phone layout (one line: name · temperature · power) is just a different area map. */
.sensor-head { display: grid; grid-template-columns: 1fr auto;
    grid-template-areas: "name power" "temp temp"; column-gap: .5rem; align-items: start; }
.sensor-head h2 { grid-area: name; margin: 0; }
.sensor-head .power-form, .sensor-head > .power { grid-area: power; }
.sensor-head .temp { grid-area: temp; }
/* Limits on one line, last measurement on the next (desktop); the short time is for the phone row. */
.sensor .meta .limits, .sensor .meta .last { display: block; }
.sensor .meta .last .short { display: none; }
.power-form { margin: 0; flex-shrink: 0; }
.power { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; width: 2.25rem; height: 2.25rem;
    padding: 0; border: 2px solid currentColor; border-radius: 50%; background: #fff; }
.power svg { width: 1.15rem; height: 1.15rem; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
/* On: solid bright green with a white symbol and a soft glow. Off: grey outline. */
.power.is-on { color: #fff; background: var(--on); border-color: var(--on); box-shadow: 0 0 0 3px rgba(26, 163, 74, .25); }
.power.is-off { color: #8a9087; }
button.power:hover, button.power:focus-visible { background: var(--bg); }
button.power.is-on:hover, button.power.is-on:focus-visible { background: #148a3c; border-color: #148a3c; }
.warn, .error { color: var(--warn); font-weight: 600; }
label { display: block; margin: 0 0 .9rem; font-size: .9rem; color: var(--muted); }
input, select, textarea { display: block; width: 100%; margin-top: .25rem; padding: .55rem .6rem; font: inherit; color: var(--text); background: #fff; border: 1px solid var(--line); border-radius: 6px; }
input[type=checkbox] { display: inline-block; width: auto; margin: 0 .4rem 0 0; }
textarea { min-height: 5rem; }
button { font: inherit; padding: .55rem 1rem; border: 0; border-radius: 6px; background: var(--accent); color: #fff; cursor: pointer; }
table { width: 100%; border-collapse: collapse; background: var(--card); font-size: .9rem; display: block; overflow-x: auto; }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
tr.inactive td { color: var(--muted); }

/* Navigation, messages, forms and charts (dashboard and admin panel) */
.brand { color: #fff; text-decoration: none; }
a { color: var(--accent); }
/* The card title and the footer link both open the sensor's history; both must look like links
   without hovering (phones), so: link colour, a soft underline that firms up on hover */
.sensor h2 a { color: var(--accent); text-decoration: underline; text-decoration-color: rgba(47, 107, 58, .35);
    text-decoration-thickness: 1px; text-underline-offset: .2em; }
.sensor h2 a:hover, .sensor h2 a:focus-visible { text-decoration-color: currentColor; }
/* A column, so the footer link sits at the bottom of every card in a row of equal-height cards */
.sensor { display: flex; flex-direction: column; }
.sensor .more { margin: auto 0 0; padding-top: .75rem; }
.sensor .more a { display: block; padding: .65rem 0 .25rem; border-top: 1px solid var(--line); font-size: .9rem; font-weight: 600;
    text-decoration: none; }
.sensor .more a:hover, .sensor .more a:focus-visible { text-decoration: underline; text-underline-offset: .2em; }
.tabs { display: flex; gap: .25rem; overflow-x: auto; padding: .4rem 1rem; background: #e8ece5; border-bottom: 1px solid var(--line); }
.tabs a { padding: .35rem .75rem; border-radius: 6px; text-decoration: none; color: var(--text); white-space: nowrap; }
.tabs a.current { background: var(--accent); color: #fff; }
.flash { margin: 0 0 1rem; padding: .6rem .8rem; border-radius: 6px; background: #e3f1e5; border: 1px solid #b9d8bd; }
.flash.error { background: #fbe9e7; border-color: #f0bdb8; }
.hint { font-size: .8rem; font-weight: 400; color: var(--cold); margin-left: .35rem; }
.alarm { margin-top: .6rem; padding: .5rem .6rem; border-radius: 6px; background: #fbe9e7; border: 1px solid #f0bdb8; font-size: .9rem; }
form.inline { display: inline; margin: 0 0 0 .5rem; }
button.small { padding: .25rem .6rem; font-size: .85rem; }
button.secondary { background: #fff; color: var(--text); border: 1px solid var(--line); }
button.danger { background: var(--warn); }
details.remove { margin: .4rem 0 1rem 1rem; font-size: .9rem; }
details.remove summary { color: var(--warn); cursor: pointer; }
details.remove form { margin-top: .5rem; }
td .cellform details.remove { margin: 0; }
td .cellform details.remove form { display: grid; gap: .4rem; }
.card + .card, .card + h2, .card + h1, section.card { margin-top: 1rem; }
/* In the sensor grid the gap does the spacing; the rule above pushed every card after the first down 1rem */
.grid > .card { margin-top: 0; }
.filter { display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: end; }
.filter label, .rules label { margin: 0; }
.filter .pager { display: flex; gap: 1rem; width: 100%; }
.rules { display: grid; gap: .9rem; grid-template-columns: 1fr; }
.rules .check, label.check { color: var(--text); }
.chart { position: relative; height: 280px; }
.chart.small { height: 160px; }
.meta { color: var(--muted); font-size: .9rem; }
.stack { display: grid; gap: 1rem; grid-template-columns: 1fr; }
.formgrid { display: grid; gap: .75rem; grid-template-columns: 1fr; align-items: end; }
.formgrid label { margin: 0; }
.formgrid .wide { grid-column: 1 / -1; }
.ok { color: var(--accent); font-weight: 600; }
.pagination { display: flex; gap: 1rem; margin: 1rem 0; }
code, .mono { font-family: ui-monospace, Consolas, monospace; font-size: .85em; }
td form { margin: 0; display: inline; }
td .cellform { display: grid; gap: .4rem; min-width: 14rem; }
@media (min-width: 640px) {
    .rules { grid-template-columns: repeat(2, 1fr) auto; align-items: end; }
    .rules .check { grid-column: 1 / -1; }
    .formgrid { grid-template-columns: repeat(2, 1fr); }
    .chart { height: 340px; }
}
@media (min-width: 960px) {
    .formgrid.three { grid-template-columns: repeat(3, 1fr); }
}
/* Phones: pack the sensor grid into compact rows so several greenhouses fit on one screen.
   Each card becomes one line (name · temperature+trend · power) plus a condensed meta line.
   Humidity, smoke and the history link drop off here; they stay on the sensor's own page. */
@media (max-width: 560px) {
    main { padding: .6rem; }
    .grid { gap: .5rem; }
    .sensor.card { padding: .5rem .7rem; border-radius: 8px; }
    .sensor-head { grid-template-columns: 1fr auto auto; grid-template-areas: "name temp power";
        align-items: center; column-gap: .5rem; }
    .sensor-head h2 { font-size: 1rem; min-width: 0; }
    .sensor .temp { font-size: 1.3rem; margin: 0; text-align: right; white-space: nowrap; }
    .sensor .temp .trend { font-size: .72rem; margin-left: .25rem; }
    .power { width: 1.9rem; height: 1.9rem; }
    .power svg { width: .95rem; height: .95rem; }
    .power.is-on { box-shadow: 0 0 0 2px rgba(26, 163, 74, .25); }
    .sensor .hum { display: none; }
    .sensor .more { display: none; }
    .warn { font-size: .78rem; margin: .1rem 0 0; }
    .sensor .meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .45rem; margin-top: .15rem; font-size: .78rem; }
    .sensor .meta .limits, .sensor .meta .last { display: inline; }
    .sensor .meta .last .full { display: none; }
    .sensor .meta .last .short { display: inline; }
    .sensor .meta .last::before { content: "·"; margin-right: .45rem; color: var(--muted); }
    .sensor .alarm { margin-top: .4rem; padding: .35rem .5rem; font-size: .8rem; }
}
