:root {
  --bg: #f4f6f8; --surface: #ffffff; --surface-2: #eef2f5; --ink: #0f1c24; --muted: #5d6b75; --line: #dfe5ea;
  --brand: #0e9384; --brand-ink: #ffffff; --on: #0e9384; --warn: #b7791f; --warn-bg: #fff4dd;
  --alarm: #d92d3a; --alarm-bg: #fde8ea; --ok: #1f8f4e; --radius: 14px; --shadow: 0 1px 2px rgba(15, 28, 36, .06), 0 4px 16px rgba(15, 28, 36, .05);
  --water: #0b63b6; --water-bg: #e3effa; --comfort: #0b7a6c; --comfort-bg: #e2efed;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1217; --surface: #121c23; --surface-2: #1a2730; --ink: #e6eef2; --muted: #8fa1ac; --line: #22323c;
    --brand: #2bb6a5; --on: #2bb6a5; --warn: #f0b44c; --warn-bg: #2d2412; --alarm: #ff5c69; --alarm-bg: #3a1419;
    --water: #62aef2; --water-bg: #122636; --comfort: #85bcb5; --comfort-bg: #042e29;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1217; --surface: #121c23; --surface-2: #1a2730; --ink: #e6eef2; --muted: #8fa1ac; --line: #22323c;
  --brand: #2bb6a5; --on: #2bb6a5; --warn: #f0b44c; --warn-bg: #2d2412; --alarm: #ff5c69; --alarm-bg: #3a1419;
  --water: #62aef2; --water-bg: #122636; --comfort: #85bcb5; --comfort-bg: #042e29;
  --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0; }
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 10px; padding: 8px 12px; cursor: pointer; font: inherit; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.light { background: #fff; color: #7a0f18; border-color: #fff; }
.btn.danger { color: var(--alarm); }
.btn.sel { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); padding: 28px; border-radius: var(--radius); box-shadow: var(--shadow); width: 100%; max-width: 360px; display: grid; gap: 12px; }
.login-card label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
input, select { font: inherit; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.err { color: var(--alarm); min-height: 1em; margin: 0; }
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.logo { color: var(--brand); }

.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 14px; position: sticky; top: 0; height: 100vh; }
.site-picker { width: 100%; }
nav { display: grid; gap: 2px; }
nav a { padding: 9px 10px; border-radius: 10px; color: var(--muted); cursor: pointer; text-decoration: none; }
nav a:hover { background: var(--surface-2); color: var(--ink); }
nav a.active { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.side-foot { margin-top: auto; display: grid; gap: 4px; }
main { padding: 20px 24px 40px; min-width: 0; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.top-right { display: flex; gap: 8px; }
.pill { padding: 4px 10px; border-radius: 99px; background: var(--surface-2); font-size: 12px; font-weight: 600; }
.pill.on { background: color-mix(in srgb, var(--brand) 18%, transparent); color: var(--brand); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.alarm { background: var(--alarm); color: #fff; }
.pill.dim { color: var(--muted); }

.alarm-banner { background: var(--alarm); color: #fff; border-radius: var(--radius); padding: 12px 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .85; } }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(12, 1fr); }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 16px; min-width: 0; }
.span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; } .span-6 { grid-column: span 6; } .span-7 { grid-column: span 7; } .span-8 { grid-column: span 8; } .span-12 { grid-column: span 12; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

.sec-state { font-size: 26px; font-weight: 700; text-transform: capitalize; margin: 4px 0 14px; }
.modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.modes .btn { padding: 12px 6px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface-2); cursor: pointer; display: grid; gap: 6px; text-align: left; color: var(--ink); font: inherit; }
.tile .k { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.tile.on { background: color-mix(in srgb, var(--on) 16%, var(--surface)); border-color: var(--on); }
.tile.off-line { opacity: .5; }
.tile .state { font-weight: 600; }
.room { margin-bottom: 18px; }
.room h3 { margin-bottom: 8px; }
/* R87 reading cards: a device's readings as meters (temperature, humidity, tank level, power) */
.rcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 12px; margin-top: 10px; }
.rcard { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 14px; display: grid; gap: 12px; min-width: 0; }
.rcard-head { display: flex; align-items: center; gap: 12px; min-width: 0; }
.rcard-icon { flex: none; width: 38px; height: 38px; border-radius: 12px; background: var(--comfort-bg); color: var(--comfort); display: grid; place-items: center; }
.rcard-icon.idle { background: var(--surface-2); color: var(--muted); }
.rcard-head .who { min-width: 0; }
.rcard-head .name { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rcard-head .sub { font-size: 12px; color: var(--muted); }
.rcard-head .age { margin-left: auto; font-size: 11px; color: var(--muted); text-align: right; white-space: nowrap; }
.meters { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.meter { background: var(--surface-2); border-radius: 14px; padding: 10px 8px 12px; display: grid; justify-items: center; gap: 4px; }
.meter .lbl { justify-self: start; padding-left: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.gauge { position: relative; width: 132px; height: 106px; }
.gauge svg { position: absolute; left: 0; top: 0; }
.gauge .num { position: absolute; left: 0; right: 0; top: 66px; height: 0; display: flex; align-items: center; justify-content: center; }
.gauge .num b { position: relative; font-size: 26px; line-height: 26px; letter-spacing: -.5px; }
.gauge .num i { position: absolute; left: 100%; top: 1px; padding-left: 2px; font-style: normal; font-size: 12px; line-height: 12px; font-weight: 600; letter-spacing: 0; color: var(--muted); }
.gauge .ends { position: absolute; left: 3px; right: 3px; bottom: -2px; display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: 4px; border-radius: 10px; padding: 3px 9px; font-size: 11px; font-weight: 700; }
.rcard .foot { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; color: var(--muted); }
.rcard .foot.stale span:first-child { color: var(--alarm); font-weight: 600; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); margin-right: 6px; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--alarm); }
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; width: 80px; display: inline-block; vertical-align: middle; }
.bar > i { display: block; height: 100%; background: var(--brand); }

.feed { list-style: none; padding: 0; margin: 0; max-height: 420px; overflow: auto; }
.feed li { padding: 8px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 64px 1fr; gap: 8px; }
.feed time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.feed li.alarm { color: var(--alarm); font-weight: 600; }
.feed li.warning { color: var(--warn); }

.tank { display: flex; gap: 20px; align-items: center; }
.tank-vessel { width: 110px; height: 150px; border: 3px solid var(--line); border-radius: 10px 10px 16px 16px; position: relative; overflow: hidden; background: var(--surface-2); }
.tank-water { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(#3fb2e8, #1678c2); transition: height .6s; }
.tank-pct { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; font-size: 22px; color: var(--ink); mix-blend-mode: difference; filter: invert(1); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; }

.nav-title { font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 10px 10px 4px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi span { font-size: 12px; color: var(--muted); font-weight: 600; }
.prio { display: inline-grid; place-items: center; width: 30px; height: 24px; border-radius: 8px; font-weight: 800; font-size: 12px; color: #fff; }
.p1 { background: var(--alarm); } .p2 { background: #e8590c; } .p3 { background: var(--warn); } .p4 { background: var(--muted); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 8px; font-size: 11px; font-weight: 700; background: var(--surface-2); color: var(--muted); margin-right: 4px; }
.tag.bank, .tag.high_value { background: var(--alarm-bg); color: var(--alarm); }
.tag.premium { background: color-mix(in srgb, var(--brand) 16%, transparent); color: var(--brand); }
.sla-late { color: var(--alarm); font-weight: 800; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.row-actions .btn { padding: 5px 9px; font-size: 12px; }
.inc-row { cursor: pointer; }
.inc-row.sel td { background: var(--surface-2); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 6px 0 6px 14px; border-left: 2px solid var(--line); font-size: 13px; }
.timeline time { color: var(--muted); font-size: 12px; margin-right: 6px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; align-items: end; }
.form-grid label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }

.toast { position: fixed; bottom: 20px; right: 20px; background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; max-width: 360px; }

@media (max-width: 960px) {
  .span-4, .span-5, .span-6, .span-7, .span-8 { grid-column: span 12; }
}
@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  nav { grid-auto-flow: column; overflow-x: auto; width: 100%; }
  nav a { white-space: nowrap; }
  .side-foot { flex-direction: row; display: flex; margin: 0; }
  main { padding: 16px; }
  .modes { grid-template-columns: repeat(2, 1fr); }
}
