/* SolarHub – "Sunrise" theme. One colour per energy flow everywhere: solar amber, grid violet,
   battery green, home sky blue. Dark by default (wall screens), light on request or by system setting. */
:root {
  --bg: #0a0f16; --bg-glow: #13202f; --panel: #111923; --panel-2: #17212d; --panel-3: #1d2937; --line: #223042;
  --text: #e9eff6; --muted: #8798ad; --faint: #5d6e84;
  --accent: #fbbf24; --accent-ink: #1a1203; --link: #7cc4fa;
  --pv: #fbbf24; --grid: #a78bfa; --battery: #34d399; --load: #38bdf8; --bad: #f87171; --warn: #fb923c; --ok: #34d399;
  --radius: 16px; --radius-sm: 10px; --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 8px 28px rgba(0,0,0,.28);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f5f9; --bg-glow: #fff7e6; --panel: #ffffff; --panel-2: #f4f6fa; --panel-3: #eaeef4; --line: #e2e7ef;
    --text: #101828; --muted: #5b6b80; --faint: #98a2b3; --accent: #f59e0b; --accent-ink: #ffffff; --link: #0b6bcb;
    --pv: #e8930c; --grid: #7c3aed; --battery: #059669; --load: #0284c7; --bad: #dc2626; --warn: #ea580c; --ok: #059669;
    --shadow: 0 1px 2px rgba(16,24,40,.04), 0 6px 20px rgba(16,24,40,.06);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f3f5f9; --bg-glow: #fff7e6; --panel: #ffffff; --panel-2: #f4f6fa; --panel-3: #eaeef4; --line: #e2e7ef;
  --text: #101828; --muted: #5b6b80; --faint: #98a2b3; --accent: #f59e0b; --accent-ink: #ffffff; --link: #0b6bcb;
  --pv: #e8930c; --grid: #7c3aed; --battery: #059669; --load: #0284c7; --bad: #dc2626; --warn: #ea580c; --ok: #059669;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 6px 20px rgba(16,24,40,.06);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
body { background: radial-gradient(1200px 600px at 70% -10%, var(--bg-glow), transparent 60%), var(--bg); background-attachment: fixed; min-height: 100vh; }
a { color: var(--link); text-decoration: none; }
h1 { font-size: 24px; margin: 0 0 18px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; letter-spacing: -.005em; }
h3 { font-size: 12px; margin: 18px 0 8px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .06em; }
.num, .stat .value, .kv td:last-child { font-variant-numeric: tabular-nums; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }

/* ---- shell & navigation */
#shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
#nav { background: color-mix(in srgb, var(--panel) 88%, transparent); backdrop-filter: blur(10px); border-right: 1px solid var(--line);
  padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; z-index: 20; }
.brand { color: var(--text); display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 17px; padding: 2px 10px 20px; letter-spacing: -.01em; }
.brand img { width: 32px; height: 32px; }
#nav ul { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; }
#nav li a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 10px; color: var(--muted); font-weight: 500; margin-bottom: 2px; }
#nav li a:hover { background: var(--panel-2); color: var(--text); }
#nav li a.active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--text); }
#nav li a.active svg.i { color: var(--accent); }
#nav li a .badge { margin-left: auto; }
.nav-sep { height: 1px; background: var(--line); margin: 10px 8px; }
.nav-foot { display: flex; align-items: center; gap: 8px; padding: 10px 6px 0; border-top: 1px solid var(--line); }
#nav-toggle { display: none; }
.conn { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; padding: 6px; flex: 1; }
.conn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 25%, transparent); }
.conn.ok::before { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--ok) 0%, transparent); } }
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  font-size: 11px; font-weight: 700; background: var(--bad); color: #fff; }
main { padding: 26px 28px 28px; max-width: 1480px; width: 100%; min-width: 0; }

/* ---- layout */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); }
.g12 { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.s3 { grid-column: span 3; } .s4 { grid-column: span 4; } .s5 { grid-column: span 5; } .s6 { grid-column: span 6; }
.s7 { grid-column: span 7; } .s8 { grid-column: span 8; } .s12 { grid-column: 1 / -1; }
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid > .card + .card, .g12 > .card + .card, .stack > .card + .card { margin-top: 0; }
.grid + .card, .grid + .grid, .g12 + .g12, .g12 + .card, .card + .g12 { margin-top: 16px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card-head .spacer { flex: 1; }
.page-head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head .lead { color: var(--muted); font-size: 14px; margin-top: 4px; }

/* ---- small parts */
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 650; }
.stat .unit { font-size: 14px; color: var(--muted); font-weight: 400; margin-left: 3px; }
.mini-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 12px 16px; margin-top: 14px; }
.mini-stats > div { display: flex; flex-direction: column; min-width: 0; }
.mini-stats .label { color: var(--muted); font-size: 12px; }
.mini-stats .value { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-stats .unit { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 2px; }
.kv { width: 100%; border-collapse: collapse; }
.kv td { padding: 7px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.kv td:first-child { color: var(--muted); }
.kv td:last-child { text-align: right; font-weight: 550; }
.kv tr:last-child td { border-bottom: 0; }
.muted { color: var(--muted); }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 550;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); border-color: transparent; }
.pill.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); border-color: transparent; }
.pill.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); border-color: transparent; }
.pill.pv { color: var(--pv); background: color-mix(in srgb, var(--pv) 13%, transparent); border-color: transparent; }
.pill.grid { color: var(--grid); background: color-mix(in srgb, var(--grid) 13%, transparent); border-color: transparent; }
.pill.load { color: var(--load); background: color-mix(in srgb, var(--load) 13%, transparent); border-color: transparent; }
.fresh { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.fresh::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.fresh.stale::before { background: var(--warn); }
.fresh.off::before { background: var(--bad); }
.bar { height: 8px; border-radius: 999px; background: var(--panel-3); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: var(--c, var(--battery)); transition: width .8s ease; }
.soc-bar { height: 10px; border-radius: 6px; background: var(--panel-3); overflow: hidden; }
.soc-bar > div { height: 100%; background: var(--battery); }
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 5px 11px; border-radius: 7px; color: var(--muted); font-size: 13px; font-weight: 550; }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.18); }

/* ---- controls */
button, .btn { display: inline-flex; align-items: center; gap: 7px; background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  padding: 7px 14px; border-radius: 10px; cursor: pointer; font: inherit; font-weight: 550; font-size: 14px; transition: border-color .15s, background .15s; }
button:hover, .btn:hover { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover { filter: brightness(1.06); }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: none; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); background: var(--panel-2); }
input, select, textarea { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; font: inherit; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 0; border-color: transparent; }
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
textarea { font-family: var(--mono); font-size: 13px; width: 100%; min-height: 120px; }
label.field { display: grid; grid-template-columns: minmax(140px, 230px) 1fr; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
label.field:last-of-type { border-bottom: 0; }
label.field > span:first-child { color: var(--muted); }
label.field > input[type="checkbox"] { justify-self: start; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--muted); padding: 9px 12px; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th { text-align: left; color: var(--muted); font-weight: 550; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px; border-bottom: 1px solid var(--line); }
table.list td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; font-variant-numeric: tabular-nums; }
table.list tr:last-child td { border-bottom: 0; }
.scroll-x { overflow-x: auto; }
pre.console { background: #070b10; color: #cfe3f2; padding: 12px; border-radius: 10px; font: 13px/1.45 var(--mono); max-height: 420px; overflow: auto; white-space: pre-wrap; margin: 0; }
#toast { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
#toast div { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); max-width: 380px; }
#toast div.bad { border-left-color: var(--bad); }

/* ---- dashboard: hero tiles */
.kpi { position: relative; overflow: hidden; padding: 16px 18px 14px; border-color: color-mix(in srgb, var(--c) 28%, var(--line));
  background: linear-gradient(160deg, color-mix(in srgb, var(--c) 13%, var(--panel)) 0%, var(--panel) 62%); }
.kpi .top { display: flex; align-items: center; gap: 8px; color: var(--c); font-size: 12px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
.kpi .top .ico { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; background: color-mix(in srgb, var(--c) 18%, transparent); }
.kpi .val { font-size: 38px; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; margin-top: 10px; font-variant-numeric: tabular-nums; }
.kpi .val small { font-size: 16px; font-weight: 600; color: var(--muted); margin-left: 4px; letter-spacing: 0; }
.kpi .what { font-size: 13px; color: var(--muted); min-height: 19px; }
.kpi .spark { height: 38px; margin: 8px -4px 2px; }
.kpi .spark svg { width: 100%; height: 100%; display: block; overflow: visible; }
.kpi .foot { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.kpi .foot b { color: var(--text); font-weight: 600; }
.kpi .foot { flex-wrap: wrap; } .kpi .foot span { white-space: nowrap; }

/* ---- dashboard: power flow */
.flow-card { display: flex; flex-direction: column; }
.flow { width: 100%; height: auto; display: block; max-height: 440px; }
.flow .wire { stroke: var(--line); stroke-width: 3; fill: none; stroke-linecap: round; }
.flow .flowing { fill: none; stroke-width: 5; stroke-linecap: round; stroke-dasharray: .1 18; animation: flow 1.6s linear infinite; filter: drop-shadow(0 0 4px currentColor); }
.flow .flowing.rev { animation-direction: reverse; }
@keyframes flow { to { stroke-dashoffset: -18.1; } }
.flow .node circle.bg { fill: var(--panel-2); stroke: color-mix(in srgb, var(--c) 55%, var(--line)); stroke-width: 2; }
.flow .node circle.glow { fill: color-mix(in srgb, var(--c) 14%, transparent); }
.flow .node .ring-bg { fill: none; stroke: var(--panel-3); stroke-width: 6; }
.flow .node .ring { fill: none; stroke: var(--c); stroke-width: 6; stroke-linecap: round; transition: stroke-dasharray .8s ease; }
.flow text { fill: var(--text); font-family: var(--font); }
.flow .v { font-size: 19px; font-weight: 750; font-variant-numeric: tabular-nums; }
.flow .l { fill: var(--muted); font-size: 11px; font-weight: 650; letter-spacing: .08em; }
.flow .s { fill: var(--muted); font-size: 11.5px; }
.flow .hub rect { fill: var(--panel-3); stroke: var(--line); }
.flow .ico path, .flow .ico rect, .flow .ico circle, .flow .ico line, .flow .ico polyline { stroke: var(--c); fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
@media (prefers-reduced-motion: reduce) { .flow .flowing, .conn.ok::before { animation: none; } }

/* ---- dashboard: today */
.ring-wrap { display: flex; align-items: center; gap: 16px; padding-bottom: 14px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.ring-wrap svg { width: 92px; height: 92px; flex: none; }
.ring-wrap .big { font-size: 26px; font-weight: 750; letter-spacing: -.01em; }
.ebars { display: grid; grid-template-columns: auto 1fr auto; gap: 10px 12px; align-items: center; font-size: 14px; }
.ebars .n { color: var(--muted); white-space: nowrap; }
.ebars .v { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ebars .v small { color: var(--muted); font-weight: 500; }

/* ---- device tiles */
.dev-list { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.dev { background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px; padding: 14px; min-width: 0; display: block; color: inherit; }
a.dev:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.dev .head { display: flex; align-items: center; gap: 10px; }
.dev .head .ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: color-mix(in srgb, var(--c, var(--accent)) 16%, transparent); color: var(--c, var(--accent)); flex: none; }
.dev .head .t { min-width: 0; flex: 1; }
.dev .head .t b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dev .head .t span { font-size: 12px; color: var(--muted); }
.dev .chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.dev .soc { display: flex; align-items: baseline; gap: 8px; margin-top: 10px; }
.dev .mini-stats { grid-template-columns: repeat(auto-fit, minmax(62px, 1fr)); gap: 10px; }
.dev .mini-stats .value { font-size: 15px; }
.dev .soc b { font-size: 26px; font-weight: 750; font-variant-numeric: tabular-nums; }

/* ---- events */
.events { display: flex; flex-direction: column; gap: 8px; }
.ev { display: grid; grid-template-columns: 4px 1fr auto; gap: 12px; padding: 10px 12px 10px 0; background: var(--panel-2); border-radius: 12px; align-items: start; }
.ev::before { content: ""; align-self: stretch; border-radius: 4px 0 0 4px; background: var(--lvl, var(--faint)); }
.ev.problem { --lvl: var(--bad); } .ev.warning { --lvl: var(--warn); } .ev.info { --lvl: var(--link); }
.ev .t { font-weight: 600; }
.ev .d { font-size: 13px; color: var(--muted); margin-top: 2px; }
.ev .when { font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ev .when b { display: block; color: var(--text); font-weight: 600; font-size: 13px; }
.ev.open .when b { color: var(--lvl); }
.day-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 14px 0 2px; }
.empty { text-align: center; color: var(--muted); padding: 22px 10px; font-size: 14px; }
.empty svg.i { width: 26px; height: 26px; display: block; margin: 0 auto 6px; color: var(--ok); }

/* ---- battery & inverter detail */
.md { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; align-items: start; }
.md .side { display: flex; flex-direction: column; gap: 10px; position: sticky; top: 16px; }
.pick { text-align: left; display: block; width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; color: inherit; font-weight: 400; box-shadow: var(--shadow); }
.pick.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
.pick .r1 { display: flex; align-items: center; gap: 8px; }
.pick .r1 b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick .r1 .pct { font-weight: 750; font-size: 18px; font-variant-numeric: tabular-nums; }
.pick .r2 { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.pick .r2 .bar { flex: 1; }
.chips-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; flex: 1; min-width: 0; }
.chipbox { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; min-width: 0; }
.chipbox .l { font-size: 11px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.chipbox .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; line-height: 1.25; }
.chipbox .v small { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 2px; }
.gauge { width: 112px; height: 112px; flex: none; }
.gauge text { fill: var(--text); font-family: var(--font); }
.detail-head { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.cmp th:not(:first-child), .cmp td:not(:first-child) { text-align: right; }
.cmp td.total { font-weight: 700; }
.cmp tr.grp td { padding-top: 16px; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; border-bottom: 0; }

/* battery cells: colour = distance from the average */
.cells { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.cell { border: 1px solid var(--line); border-radius: 10px; padding: 7px 9px; font-variant-numeric: tabular-nums; background: var(--panel-2); }
.cell .n { font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; }
.cell .v { font-weight: 700; font-size: 15px; }
.cell.hi { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 16%, var(--panel-2)); }
.cell.lo { border-color: var(--link); background: color-mix(in srgb, var(--link) 16%, var(--panel-2)); }
.cell.hi .n span:last-child { color: var(--warn); } .cell.lo .n span:last-child { color: var(--link); }
.cell.bal .n::after { content: "⇄"; color: var(--link); }
.legend-cells { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend-cells i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---- charts */
.chart { width: 100%; height: 280px; position: relative; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .axis text { fill: var(--faint); font-size: 11px; font-family: var(--font); }
.chart .axis line, .chart .gridline { stroke: var(--line); }
.chart .tip { position: absolute; pointer-events: none; background: color-mix(in srgb, var(--panel) 94%, transparent); backdrop-filter: blur(6px); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 11px; font-size: 12px; line-height: 1.6; white-space: nowrap; display: none; z-index: 2; box-shadow: var(--shadow); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; margin-top: 10px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ---- automation & configuration editors */
.rule { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 12px; background: var(--panel-2); }
.rule .cond, .rule .act, .card .act { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 6px 0; }
.rule select, .rule input, .card .act select, .card .act input { padding: 5px 8px; }
.rule input, .rule select { background: var(--panel); }
.rule.off { opacity: .6; }
.rule-head { display: flex; gap: 10px; align-items: center; }
.rule-title { flex: 1; min-width: 0; cursor: pointer; }
.rule .summary { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rule.open .summary { white-space: normal; }
.rule-body { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.rule h3 { margin: 14px 0 4px; }
.tag { font-size: 12px; font-weight: 650; padding: 3px 8px; border-radius: 6px; background: var(--panel); border: 1px solid var(--line); }
.chip { display: inline-flex; align-items: center; padding: 3px 10px; border: 1px solid var(--line); border-radius: 999px; font-size: 13px; cursor: pointer; user-select: none; }
.chip:has(input:checked) { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.chip input { display: none; }
.hold { display: inline-flex; gap: 4px; align-items: center; font-size: 13px; }
button.icon { padding: 4px 9px; }
details.retry { flex-basis: 100%; font-size: 13px; margin-left: 4px; }
details.retry .row { margin-top: 6px; gap: 6px; }
label.inline { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); }
.sub { padding: 2px 0 10px 12px; border-left: 2px solid var(--line); margin: 2px 0 6px; }
.small { font-size: 12px; }
code { font-family: var(--mono); font-size: 12px; background: var(--panel-3); padding: 1px 5px; border-radius: 5px; }
/* Pinned to the bottom of the window while scrolling; rests below the last card at the end of the page. */
.save-bar { position: sticky; bottom: 0; z-index: 5; margin: 16px -28px -28px; padding: 12px 28px;
  background: color-mix(in srgb, var(--panel) 90%, transparent); backdrop-filter: blur(8px); border-top: 1px solid var(--line); }
.login { max-width: 380px; margin: 12vh auto; }
[hidden] { display: none !important; }
.help { display: block; font-size: 12px; font-weight: 400; color: var(--muted); opacity: .85; margin-top: 2px; }
details > summary { cursor: pointer; }
details.card > summary { padding: 2px 0; }
details.card[open] > summary { margin-bottom: 8px; }
details.adv { margin-top: 8px; padding-top: 6px; border-top: 1px dashed var(--line); }
details.adv[open] > summary { margin-bottom: 4px; }

/* ---- responsive */
@media (max-width: 1180px) {
  .s3 { grid-column: span 6; } .s4, .s5, .s7, .s8 { grid-column: 1 / -1; } .s6 { grid-column: 1 / -1; }
}
@media (max-width: 960px) {
  .md { grid-template-columns: 1fr; }
  .md .side { position: static; flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .md .side .pick { min-width: 220px; }
}
@media (max-width: 860px) {
  #shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  #nav { height: auto; position: sticky; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 14px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0; flex: 1; }
  #nav-toggle { display: inline-flex; padding: 6px 10px; }
  #nav ul, #nav .nav-sep { display: none; flex-basis: 100%; }
  #nav.open ul { display: block; margin-top: 10px; }
  .nav-foot { border-top: 0; padding: 0; order: 2; }
  .nav-foot .conn span { display: none; }
  main { padding: 16px; }
  .save-bar { margin: 16px -16px -16px; padding: 12px 16px; }
  .grid.wide { grid-template-columns: 1fr; }
  label.field { grid-template-columns: 1fr; gap: 4px; }
  .s3 { grid-column: 1 / -1; }
  .kpi .val { font-size: 32px; }
}
@media (max-width: 560px) {
  .g12 { gap: 12px; }
  .kpis .s3 { grid-column: span 6; }
  .kpi { padding: 13px 14px 12px; }
  .kpi .val { font-size: 26px; }
  .kpi .spark { display: none; }
  .kpi .foot { flex-direction: column; gap: 0; font-size: 11.5px; }
  .kpi .foot span { white-space: normal; }
  .kpi .what { font-size: 12px; }
}
.grid.half { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.cols { columns: 3 320px; column-gap: 16px; }
.cols > .card { break-inside: avoid; margin: 0 0 16px; display: inline-block; width: 100%; }
.charts-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.charts-grid > .card { margin: 0; }
.charts-grid > .card.wide { grid-column: 1 / -1; }
.charts-grid .card-head { align-items: flex-start; }
@media (max-width: 1100px) { .charts-grid { grid-template-columns: 1fr; } }
input[type="date"] { padding: 5px 9px; }

/* ---- accounts: role-aware navigation */
body:not([data-role="admin"]) [data-admin] { display: none !important; }
.user-btn { display: flex; align-items: center; gap: 9px; padding: 5px 8px; min-width: 0; flex: 1; text-align: left; }
.user-btn .who { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.user-btn .who b { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-btn .who small { font-size: 11px; color: var(--muted); font-weight: 500; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center; flex: none; font-weight: 750; font-size: 13px;
  color: var(--accent-ink); background: linear-gradient(135deg, #fcd34d, #f59e0b); }
.avatar.sm { width: 26px; height: 26px; font-size: 12px; margin-right: 8px; vertical-align: middle; }
.nav-foot .conn { flex: none; padding: 6px; }
.nav-foot .conn::before { margin: 0; }
table.users td { vertical-align: middle; }
table.users td.actions { text-align: right; white-space: nowrap; }
table.users td.actions button { padding: 5px 10px; font-size: 13px; margin-left: 4px; }

/* ---- sign-in and first-time setup */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(380px, 1fr); }
.auth-brand { position: relative; overflow: hidden; display: flex; align-items: flex-end; padding: 56px;
  background: radial-gradient(900px 600px at 20% 10%, rgba(251,191,36,.28), transparent 60%),
              radial-gradient(700px 500px at 90% 100%, rgba(56,189,248,.18), transparent 60%), #0a111b; color: #e9eff6; }
.auth-brand .sun { position: absolute; width: 420px; height: 420px; right: -150px; top: -150px; border-radius: 50%;
  background: radial-gradient(circle, rgba(253,230,138,.9) 0%, rgba(251,191,36,.55) 30%, rgba(245,158,11,.18) 55%, transparent 70%);
  filter: blur(18px); opacity: .7; animation: glow 9s ease-in-out infinite alternate; }
.auth-brand::after { content: ""; position: absolute; inset: auto 0 0 0; height: 45%; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(56,189,248,.06) 0 1px, transparent 1px 28px); mask-image: linear-gradient(transparent, #000); }
@keyframes glow { to { transform: translate(-30px, 20px) scale(1.06); opacity: 1; } }
.auth-brand-in { position: relative; max-width: 520px; }
.auth-brand .logo { display: flex; align-items: center; gap: 12px; font-weight: 750; font-size: 20px; margin-bottom: 48px; }
.auth-brand .logo img { width: 44px; height: 44px; }
.auth-brand h1 { font-size: 46px; line-height: 1.08; letter-spacing: -.03em; margin: 0 0 28px; }
.auth-brand ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; color: #b9c6d6; }
.auth-brand li { display: flex; gap: 12px; align-items: center; }
.auth-brand li svg.i { color: #fbbf24; width: 22px; height: 22px; }
.auth-form { display: grid; place-items: center; padding: 32px 24px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h2 { font-size: 28px; margin: 0 0 6px; letter-spacing: -.02em; }
.auth-card > .muted { margin: 0 0 24px; }
.auth-card .step { display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); margin-bottom: 10px; }
.afield { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 13px; font-weight: 600; color: var(--muted); }
.afield input { padding: 11px 13px; font-size: 15px; width: 100%; }
.pw { position: relative; display: block; }
.pw input { padding-right: 44px; }
.pw button { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); padding: 6px 8px; }
button.wide { width: 100%; justify-content: center; padding: 12px; font-size: 15px; margin-top: 4px; }
.auth-error, .modal-error { color: var(--bad); font-size: 13px; min-height: 18px; margin: 2px 0 8px; }
.auth-foot { margin-top: 26px; font-size: 13px; color: var(--muted); }
.strength { height: 5px; border-radius: 999px; background: var(--panel-3); margin: -6px 0 16px; position: relative; }
.strength::before { content: ""; position: absolute; inset: 0 auto 0 0; width: var(--w, 0); background: var(--c, var(--bad)); border-radius: inherit; transition: width .3s; }
.strength::after { content: attr(data-t); position: absolute; right: 0; top: 8px; font-size: 11px; color: var(--muted); }
@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; }
  .auth-brand { padding: 28px 24px; min-height: 0; }
  .auth-brand .logo { margin-bottom: 18px; }
  .auth-brand h1 { font-size: 30px; margin-bottom: 0; }
  .auth-brand ul { display: none; }
  .auth-brand .sun { width: 300px; height: 300px; right: -90px; top: -120px; }
}

/* ---- dialogs */
#modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal-back { position: absolute; inset: 0; background: rgba(4, 8, 14, .6); backdrop-filter: blur(3px); animation: fade .15s ease; }
.modal { position: relative; width: 100%; max-width: 460px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 22px;
  box-shadow: 0 24px 60px rgba(0,0,0,.45); animation: pop .16s ease; max-height: calc(100vh - 32px); overflow: auto; }
.modal.wide { max-width: 560px; }
.modal h2 { font-size: 18px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.modal-body { color: var(--text); }
.modal-body p { margin: 0 0 10px; }
.modal-actions { margin-top: 14px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
button.danger-fill { background: var(--bad); border-color: var(--bad); color: #fff; }
ul.changes { margin: 0 0 12px; padding: 0; list-style: none; display: grid; gap: 6px; font-size: 14px; }
ul.changes li { background: var(--panel-2); border-radius: 10px; padding: 8px 11px; overflow-wrap: anywhere; }
ul.changes .bad, b.bad { color: var(--bad); }
.role-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.role-card { display: flex; flex-direction: column; gap: 4px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; background: var(--panel-2); }
.role-card:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.role-card input { display: none; }
.role-card span { font-size: 12.5px; color: var(--muted); }
@media (max-width: 520px) { .role-pick { grid-template-columns: 1fr; } }

/* ---- dashboard: all devices in one row, grouped by kind */
.dev-groups { display: grid; grid-template-columns: var(--split, 1fr 1fr); gap: 14px; }
.dev-group { --c: var(--pv); border: 1px solid color-mix(in srgb, var(--c) 28%, var(--line)); border-radius: 14px; padding: 10px;
  background: color-mix(in srgb, var(--c) 6%, var(--panel)); min-width: 0; }
.dev-group.bat { --c: var(--battery); }
.dev-group-h { display: flex; align-items: center; gap: 8px; color: var(--text); padding: 2px 4px 10px; font-size: 13px; }
.dev-group-h .ico { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; color: var(--c); background: color-mix(in srgb, var(--c) 18%, transparent); }
.dev-group-h b { text-transform: uppercase; letter-spacing: .07em; font-size: 12px; color: var(--c); }
.dev-group-h .count { font-size: 12px; font-weight: 700; color: var(--muted); }
.dev-group-h svg.i:last-child { color: var(--muted); width: 16px; height: 16px; }
.dev-group-h:hover svg.i:last-child { color: var(--c); }
.dev-row { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 8px; }
.devc { display: flex; flex-direction: column; gap: 7px; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; padding: 10px 11px; color: inherit; min-width: 0; }
.devc:hover { border-color: color-mix(in srgb, var(--c) 55%, var(--line)); }
.devc-h { display: flex; align-items: center; gap: 6px; min-width: 0; }
.devc-h b { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.devc-h .fresh { font-size: 11px; }
.devc-tags { display: flex; gap: 5px; flex-wrap: wrap; min-height: 21px; }
.devc-soc { display: flex; align-items: center; gap: 8px; min-height: 21px; }
.devc-soc b { font-size: 22px; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1; }
.devc-soc small { font-size: 12px; color: var(--muted); font-weight: 500; }
.devc .bar { height: 6px; }
.devc-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(54px, 1fr)); gap: 6px; }
.devc-stats > div { display: flex; flex-direction: column; min-width: 0; }
.devc-stats .label { font-size: 11px; color: var(--muted); }
.devc-stats .value { font-size: 14px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.devc-stats .value.neg { color: var(--warn); }
@media (max-width: 1180px) { .dev-groups { grid-template-columns: 1fr; } .dev-row { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); } }
.devc-stats.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.devc-stats .value { letter-spacing: -.01em; }
.fresh.dot { gap: 0; }
.devc-h .fresh.dot::before { width: 8px; height: 8px; }
.devc-stats .value small { font-size: 11px; font-weight: 500; color: var(--muted); margin-left: 2px; }
@media (max-width: 860px) { .user-btn { flex: none; } .user-btn .who { display: none; } .nav-foot { gap: 2px; } }
@media (max-width: 560px) { .dev-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } .devc-soc b { font-size: 19px; } .devc-stats .value { font-size: 13px; } }
@media (max-width: 560px) { .dev-group.inv .dev-row { grid-template-columns: 1fr; } }
.auth-note { display: flex; gap: 10px; align-items: flex-start; background: color-mix(in srgb, var(--accent) 12%, var(--panel-2));
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line)); border-radius: 12px; padding: 10px 12px; margin: -6px 0 18px; font-size: 14px; }
.auth-note svg.i { color: var(--accent); margin-top: 1px; }
.brand .pill { font-size: 10px; padding: 1px 7px; margin-left: 2px; }
