/* 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-inline-end: 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-inline-start: 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); }
#detail-btn.on { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.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-inline-start: 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-inline-start: 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: end; font-weight: 550; overflow-wrap: anywhere; }
.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;
  font-variant-numeric: tabular-nums; min-width: 5.3em; }   /* room for "59 s ago": "9 s" → "10 s" must not shift or re-wrap the row */
.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; }
/* minmax(0, …): a select is as wide as its longest option and would otherwise widen the page on a phone. */
label.field, div.field.picker { display: grid; grid-template-columns: minmax(140px, 230px) minmax(0, 1fr); gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
label.field > *, div.field.picker > * { min-width: 0; }
label.field:last-of-type { border-bottom: 0; }
label.field > span:first-child, div.field.picker > span:first-child { color: var(--muted); }
div.field.picker > .row { flex-wrap: wrap; gap: 4px 14px; }
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: start; 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; inset-inline-end: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
#toast div { background: var(--panel); border: 1px solid var(--line); border-inline-start: 4px solid var(--accent); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); max-width: 380px; }
#toast div.bad { border-inline-start-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-inline-start: 4px; letter-spacing: 0; }
.kpi .what { font-size: 13px; color: var(--muted); min-height: 19px; white-space: pre-line; }
.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. Solar on top, grid left, home right, battery below; the wires run from the middle to
   the edges under the nodes, so the nodes may be any height. */
.d-top { align-items: stretch; }
.pf { container: pf / inline-size; padding: 14px; display: flex; flex-direction: column; }
.pf-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; min-height: 26px; }
.pf-head h2 { margin: 0; display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); font-weight: 600; }
.pf-head .spacer { flex: 1; }
.pf-head .live { width: 8px; height: 8px; border-radius: 50%; 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; }
.pf-ss { font-size: 12px; font-weight: 700; color: var(--battery); border: 1px solid color-mix(in srgb, var(--battery) 45%, var(--line));
  background: color-mix(in srgb, var(--battery) 12%, var(--panel)); border-radius: 999px; padding: 2px 9px; }
/* nodes are circles of one size with the icon and the number inside; the battery's ring fills with its charge and its
   % and time left sit under it. --top is the room above solar, --edge the room under the battery for its caption, --w
   the length of each wire and --hy the hub's height, so all four wires are the same length; --gx is where the grid
   and home circles' centres sit. */
.pf-dia { --d: 94px; --top: 4px; --edge: 44px; --w: 56px; --hy: calc(var(--top) + var(--d) + var(--w)); --gx: max(21%, calc(var(--d) / 2 + 6px));
  position: relative; height: calc(var(--hy) + var(--w) + var(--d) + var(--edge)); margin: 6px 0 auto; direction: ltr; }
.pf-node { position: absolute; z-index: 2; width: var(--d); translate: -50% 0; display: flex; flex-direction: column; align-items: center; gap: 2px;
  text-align: center; color: var(--text); text-decoration: none; }
.pf-node[data-k=pv] { left: 50%; top: var(--top); }
.pf-node[data-k=bat] { left: 50%; top: calc(var(--hy) + var(--w)); }
.pf-node[data-k=grid] { left: var(--gx); top: calc(var(--hy) - var(--d) / 2); }
.pf-node[data-k=load] { left: calc(100% - var(--gx)); top: calc(var(--hy) - var(--d) / 2); }
.pf-c { position: relative; width: var(--d); height: var(--d); border-radius: 50%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; box-sizing: border-box;
  background: color-mix(in srgb, var(--c) 12%, var(--panel)); border: 2px solid color-mix(in srgb, var(--c) 55%, var(--line)); transition: border-color .2s, transform .15s, background .2s; }
.pf-node:hover .pf-c { border-color: var(--c); background: color-mix(in srgb, var(--c) 18%, var(--panel)); }
.pf-node:active .pf-c { transform: scale(.97); }
.pf-node:focus-visible { outline: none; }
.pf-node:focus-visible .pf-c { outline: 2px solid var(--c); outline-offset: 3px; }
/* the battery: a faint track with the charge drawn over it as an arc */
.pf-node[data-k=bat] .pf-c { border-color: transparent; }
.pf-node[data-k=bat] .pf-c::before { content: ""; position: absolute; inset: -2px; border-radius: 50%;
  background: conic-gradient(var(--c) calc(var(--soc, 0) * 1%), color-mix(in srgb, var(--c) 20%, var(--line)) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3.5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3.5px)); transition: --soc .4s; }
.pf-c svg.i { width: 20px; height: 20px; stroke-width: 2.1; color: var(--c); flex: none; }
.pf-node[data-k=bat] .what { margin-top: 6px; }
.pf-node .val { font-size: 20px; font-weight: 750; letter-spacing: -.02em; line-height: 1; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pf-node .val { display: flex; flex-direction: column; align-items: center; }
/* the unit sits under the number */
.pf-node .val small { font-size: 11.5px; font-weight: 600; color: var(--muted); margin-top: 3px; letter-spacing: .02em; }
.pf-node :is(.what, .eta) { font-size: 11.5px; color: var(--muted); line-height: 1.3; white-space: nowrap; }
.pf-node .what { color: var(--text); font-weight: 600; }
.pf-node .what b { color: var(--c); }
.pf-node :is(.what, .eta):empty { display: none; }
.pf-node:is([data-k=grid], [data-k=load], [data-k=pv]) :is(.what, .eta) { position: absolute; top: calc(100% + 4px); left: 0; right: 0; }
.pf-node.quiet :is(.val, svg.i) { color: var(--muted); }
.pf-node.quiet .pf-c { border-color: var(--line); background: var(--panel-2); }
.pf.down .pf-node[data-k=grid], .pf.down .pf-wire[data-w=grid] { --c: var(--bad) !important; }
.pf.down .pf-node[data-k=grid] .val { color: var(--bad); }
.pf-hub { position: absolute; left: 50%; top: var(--hy); width: 18px; height: 18px; translate: -50% -50%; border-radius: 50%; z-index: 1;
  background: var(--panel); border: 2px solid var(--muted); box-shadow: inset 0 0 0 3px var(--panel), inset 0 0 0 9px var(--muted); }
/* a wire: a faint line when idle; with power, a lit line, dots running along it the way the power goes */
.pf-wire { position: absolute; display: block; --dot: 22px; --len: 3px; border-radius: 3px; overflow: visible;
  background: repeating-linear-gradient(var(--wdir, 180deg), color-mix(in srgb, var(--muted) 45%, transparent) 0 2px, transparent 2px 8px); }
/* each wire runs from the hub to the centre of its circle (the circle covers its end) */
.pf-wire[data-w=pv] { left: calc(50% - 1.5px); width: 3px; top: calc(var(--top) + var(--d) / 2); height: calc(var(--w) + var(--d) / 2); }
.pf-wire[data-w=bat] { left: calc(50% - 1.5px); width: 3px; top: var(--hy); height: calc(var(--w) + var(--d) / 2); }
.pf-wire[data-w=grid] { top: calc(var(--hy) - 1.5px); height: 3px; left: var(--gx); width: calc(50% - var(--gx)); --wdir: 90deg; }
.pf-wire[data-w=load] { top: calc(var(--hy) - 1.5px); height: 3px; left: 50%; width: calc(50% - var(--gx)); --wdir: 90deg; }
.pf-wire[data-flow="+"], .pf-wire[data-flow="-"] { background: var(--c); box-shadow: 0 0 0 5px color-mix(in srgb, var(--c) 15%, transparent); }
.pf-wire[data-w=pv], .pf-wire[data-w=bat] { clip-path: inset(0 -8px); --anim: pf-y; }
.pf-wire[data-w=grid], .pf-wire[data-w=load] { clip-path: inset(-8px 0); --anim: pf-x; }
.pf-wire::after { content: ""; position: absolute; opacity: 0; background-image: radial-gradient(circle, var(--c) 0 3.5px, transparent 4px); }
/* the dot strip is one dot longer than the wire and slides by exactly one dot: seamless, and the wire clips the rest */
.pf-wire:is([data-w=pv], [data-w=bat])::after { inset: calc(-1 * var(--dot)) -4px 0; background-size: 100% var(--dot); }
.pf-wire:is([data-w=grid], [data-w=load])::after { inset: -4px 0 -4px calc(-1 * var(--dot)); background-size: var(--dot) 100%; }
.pf-wire[data-flow="+"]::after, .pf-wire[data-flow="-"]::after { opacity: 1; will-change: transform; animation: var(--anim) var(--dur, 2s) linear infinite; }
.pf-wire[data-flow="-"]::after { animation-direction: reverse; }
@keyframes pf-y { to { transform: translateY(var(--dot)); } }
@keyframes pf-x { to { transform: translateX(var(--dot)); } }
.pf [hidden], .today [hidden] { display: none !important; }
/* wider flow card: bigger circles */
@container pf (min-width: 520px) {
  .pf-dia { --d: 130px; --top: 4px; --edge: 48px; --w: 80px; --gx: 23%; }
  .pf-node .val { font-size: 29px; }
  .pf-node .val small { font-size: 14px; }
  .pf-c svg.i { width: 26px; height: 26px; }
  .pf-node :is(.what, .eta) { font-size: 12.5px; }
}
/* today: four small tiles, two by two next to the flow, one row when there is the width */
.today { container: today / inline-size; display: flex; flex-direction: column; }
.today .card-head { margin-bottom: 10px; }
.today-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; flex: 1; }
.td { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: 14px; color: var(--text); min-width: 0;
  background: var(--panel-2); border: 1px solid transparent; }
.td:hover { border-color: color-mix(in srgb, var(--c) 45%, var(--line)); }
.td .l { font-size: 12px; font-weight: 700; color: var(--c); }
.td .v { font-size: 24px; font-weight: 750; letter-spacing: -.02em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.td .v small { font-size: 12px; font-weight: 600; color: var(--muted); margin-inline-start: 3px; letter-spacing: 0; }
.td .s { font-size: 12px; color: var(--muted); }
.td .s b { color: var(--text); font-weight: 600; white-space: nowrap; }
.td .spark { height: 34px; margin: auto -4px 0; padding-top: 6px; }
.td .spark svg { width: 100%; height: 100%; display: block; overflow: visible; }
@container today (min-width: 640px) { .today-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 1180px) { .d-top .s7, .d-top .s5 { grid-column: 1 / -1; } }
/* phone: the totals become a strip of four under the flow, as in the app's design */
@media (max-width: 560px) {
  .today { background: none; border: 0; box-shadow: none; padding: 0; }
  .today .card-head { margin: 0 2px 6px; }
  .today .card-head h2 { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
  .today-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
  .td { padding: 9px 8px; background: var(--panel); border-color: var(--line); }
  .td .l { font-size: 11px; }
  .td .v { font-size: 15px; }
  .td .v small { font-size: 10.5px; margin-inline-start: 2px; }
  .td .s { font-size: 11px; line-height: 1.3; }
  .td .tm, .td .spark { display: none; }
  .pf { padding: 12px; }
}
@media (hover: none) { body { background-attachment: scroll; } }
@media (prefers-reduced-motion: reduce) { .pf-wire::after { display: none; } .pf-head .live { animation: none; } }

@media (prefers-reduced-motion: reduce) { .conn.ok::before { animation: none; } }

/* ---- 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: end; 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: start; 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-inline-start: 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: end; }
.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-inline-end: 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-inline-end: 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-inline-start: 4px; }
details.retry .row { margin-top: 6px; gap: 6px; }
label.inline { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); }
.sub { padding-block: 2px 10px; padding-inline: 12px 0; border-inline-start: 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; }
  /* No backdrop filter here: it would pin the tab bar below to the top bar instead of the window. */
  #nav { height: auto; position: sticky; flex-direction: row; align-items: center; padding: 10px 14px; border-inline-end: 0; border-bottom: 1px solid var(--line);
    backdrop-filter: none; background: var(--panel); }
  .brand { padding: 0; flex: 1; }
  /* The menu becomes a tab bar at the bottom of the screen, within reach of the thumb. */
  #nav ul#nav-links { position: fixed; inset: auto 0 0 0; display: flex; flex: none; overflow: visible; z-index: 30; margin: 0;
    background: color-mix(in srgb, var(--panel) 95%, transparent); backdrop-filter: blur(12px); border-top: 1px solid var(--line);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  #nav-links li { flex: 1; min-width: 0; }
  #nav-links .nav-sep { display: none; }
  #nav li a { flex-direction: column; gap: 2px; padding: 6px 2px; font-size: 10.5px; font-weight: 600; margin: 0; text-align: center; position: relative;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #nav li a svg.i { width: 22px; height: 22px; }
  #nav li a.active { background: none; color: var(--accent); }
  #nav li a .badge { position: absolute; top: 1px; inset-inline-start: calc(50% + 5px); margin: 0; min-width: 16px; height: 16px; font-size: 10px; padding: 0 4px; }
  .nav-foot { border-top: 0; padding: 0; order: 2; }
  .nav-foot .conn span { display: none; }
  main { padding: 16px 16px calc(84px + env(safe-area-inset-bottom)); }
  .save-bar { margin: 16px -16px -16px; padding: 12px 16px; bottom: calc(60px + env(safe-area-inset-bottom)); }
  #toast { bottom: calc(76px + env(safe-area-inset-bottom)); inset-inline: 12px; }
  #toast div { max-width: none; }
  .grid.wide { grid-template-columns: 1fr; }
  label.field, div.field.picker { grid-template-columns: minmax(0, 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: start; }
.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-inline-end: 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: end; white-space: nowrap; }
table.users td.actions button { padding: 5px 10px; font-size: 13px; margin-inline-start: 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-inline-end: 44px; }
.pw button { position: absolute; inset-inline-end: 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; inset-inline-end: 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; } }

.fresh.dot { gap: 0; min-width: 0; }

@media (max-width: 860px) { .user-btn { flex: none; } .user-btn .who { display: none; } .nav-foot { gap: 2px; } }

.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-inline-start: 2px; }

/* ---- language picker (sign-in page, account dialog) */
.auth-form { position: relative; }
.auth-lang { position: absolute; top: 16px; inset-inline-end: 16px; }
.lang-select { width: auto; min-width: 130px; }
.modal .lang-select { width: 100%; }
/* AI assistant tokens: a new token / command to copy, on one line with its Copy button */
.modal .row input.grow { flex: 1; min-width: 0; font-family: var(--mono); font-size: 12px; padding: 9px 11px; }
.modal .row .grow + button { flex-shrink: 0; }
.modal p.bad { color: var(--bad); }
.modal .gap-top { margin-top: 14px; }
/* Right-to-left languages: numbers, charts and the power flow keep their left-to-right drawing. */
[dir="rtl"] .chart svg, [dir="rtl"] code, [dir="rtl"] pre.console { direction: ltr; }
[dir="rtl"] .i.flip, [dir="rtl"] a .i:last-child { transform: scaleX(-1); }
/* Numbers with units ("+4.49 kW", "3.6 kWh") stay in reading order inside right-to-left text. */
[dir="rtl"] :is(.kpi .val, .kpi .foot b, .value, .chipbox .v, .big, .pct, .kv td:last-child, table.list td, .stat .value, .ev .when b) {
  direction: ltr; unicode-bidi: isolate;
}
[dir="rtl"] :is(.kv td:last-child) { text-align: start; }
[dir="rtl"] .gauge { direction: ltr; }

/* eWeLink devices */
.ew-dev { border-top: 1px solid var(--line); padding: 14px 0; }
.ew-dev:first-child { border-top: 0; }
.ew-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.ew-head input { width: 190px; font-weight: 600; }
.ew-body { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px 24px; margin-top: 10px; }
.ew-sw { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; }
.ew-ch { display: inline-flex; align-items: center; gap: 8px; }
.ew-ch > span:first-child { font-size: 13px; color: var(--muted); min-width: 64px; }
.ew-key { display: grid; gap: 4px; }
.ew-key input { width: 230px; }
@media (max-width: 560px) { .ew-head input, .ew-key, .ew-key input { width: 100%; } }

/* Loads (load manager) */
.banner { display: flex; gap: 12px; align-items: flex-start; }
.banner > svg.i { flex: none; width: 22px; height: 22px; margin-top: 2px; }
.banner.warn { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); background: color-mix(in srgb, var(--warn) 8%, var(--panel)); }
.banner.warn > svg.i { color: var(--warn); }
#l-sum { margin: 0 2px 10px; }
.loads { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; margin-bottom: 14px; }
.loads.compact { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); margin: 0; }
.load { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; display: grid; gap: 10px; }
.loads.compact .load { background: var(--panel-2); }
.load.running { border-color: color-mix(in srgb, var(--pv) 55%, var(--line)); }
.load-h { display: flex; align-items: center; gap: 10px; }
.load-ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--panel-3); color: var(--muted); flex: none; }
.load.running .load-ic { background: color-mix(in srgb, var(--pv) 18%, transparent); color: var(--pv); }
.load-why { font-size: 13.5px; }
.load-why.bad { color: var(--bad); }
.load-bar { display: flex; height: 8px; border-radius: 99px; background: var(--panel-3); overflow: hidden; }
.load-bar i { display: block; height: 100%; }
.load-ctl { gap: 8px; flex-wrap: wrap; }
.boost-grp { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.boost-row { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.boost-b { padding: 4px 10px; font-size: 13px; background: var(--panel); }
.load-src { display: inline-flex; align-items: center; gap: 5px; margin-inline-start: 10px; white-space: nowrap; }
.load-src i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
@media (max-width: 560px) { .loads, .loads.compact { grid-template-columns: 1fr; } }

/* Totals: period presets and a from–to date range */
.t-period { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px 14px; }
.t-dates { gap: 10px; }
.t-dates input[type="date"] { width: auto; }
@media (max-width: 560px) { .t-period { justify-content: flex-start; } .t-dates label { flex: 1; } .t-dates input[type="date"] { width: 100%; } }

/* ---- simple and technical view */
body:not([data-detail="advanced"]) .adv-only { display: none !important; }
body[data-detail="advanced"] .simple-only { display: none !important; }
label.check-row { display: flex; gap: 10px; align-items: flex-start; margin: 4px 0 14px; cursor: pointer; }
label.check-row input { margin-top: 3px; flex: none; }

/* ---- tabs of the pages that share a menu entry */
.subnav { display: flex; gap: 4px; margin: -6px 0 18px; overflow-x: auto; overflow-y: hidden; touch-action: pan-x; overscroll-behavior: contain; scrollbar-width: none; border-bottom: 1px solid var(--line); }
.subnav::-webkit-scrollbar { display: none; }
.subnav a { padding: 8px 12px; color: var(--muted); font-weight: 600; font-size: 14px; border-bottom: 2px solid transparent; white-space: nowrap; }
.subnav a:hover { color: var(--text); }
.subnav a.on { color: var(--text); border-bottom-color: var(--accent); }

/* ---- home: needs attention, forecast on its own in the simple view */
.attention { border-color: color-mix(in srgb, var(--lvl, var(--warn)) 45%, var(--line)); background: color-mix(in srgb, var(--lvl, var(--warn)) 7%, var(--panel)); margin-bottom: 16px; }
.attention.problem { --lvl: var(--bad); } .attention.warning { --lvl: var(--warn); }
.attention .attn-ico { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; color: var(--lvl); background: color-mix(in srgb, var(--lvl) 16%, transparent); }
.attention + .g12 { margin-top: 0; }
.attention.storm-on .card-head { margin-bottom: 4px; } .attention.storm-on h2 { font-size: 16px; }

/* ---- inverters in the simple view */
.inv-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.inv-cards > .card { margin: 0; }
.inv-card-h { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.inv-card-h .ico { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; color: var(--pv); background: color-mix(in srgb, var(--pv) 15%, transparent); }
.inv-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.inv-stats > div { display: flex; flex-direction: column; border-top: 3px solid var(--c); padding-top: 6px; min-width: 0; }
.inv-stats .label { font-size: 12px; color: var(--muted); }
.inv-stats .value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.inv-stats .value small { font-size: 12px; color: var(--muted); font-weight: 500; margin-inline-start: 2px; }
.inv-say { margin: 12px 0 6px; font-size: 14px; }
.warn-text { color: var(--warn); }
@media (max-width: 560px) { .inv-cards { grid-template-columns: 1fr; } }

/* ---- batteries: time estimate */
p.eta { margin: -2px 0 10px; font-weight: 600; color: var(--battery); }

/* ---- grid status line */
.grid-status { display: flex; align-items: center; gap: 14px; --c: var(--muted); }
.grid-status.ok { --c: var(--ok); } .grid-status.bad { --c: var(--bad); } .grid-status.warn { --c: var(--warn); }
.grid-status .g-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 5px color-mix(in srgb, var(--c) 22%, transparent); flex: none; margin-inline-start: 4px; }
.grid-status b { font-size: 17px; }

/* ---- on/off switch */
.switch { position: relative; display: inline-flex; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch i { width: 42px; height: 24px; border-radius: 999px; background: var(--panel-3); border: 1px solid var(--line); position: relative; transition: background .15s; }
.switch i::after { content: ""; position: absolute; top: 2px; inset-inline-start: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s; }
.switch input:checked + i { background: var(--ok); border-color: var(--ok); }
.switch input:checked + i::after { transform: translateX(18px); }
[dir="rtl"] .switch input:checked + i::after { transform: translateX(-18px); }
.switch input:focus-visible + i { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }
.switch-row { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; }

/* ---- automations */
.sec-h { margin: 22px 0 10px; }
.sec-row { display: flex; align-items: center; gap: 12px; margin: 22px 0 10px; }
.sec-row .sec-h { margin: 0; }
.auto-list { display: grid; gap: 10px; }
.auto-list > .card { margin: 0; }
#a-log { margin-top: 22px; }
.auto-card { display: flex; align-items: flex-start; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px;
  cursor: pointer; box-shadow: var(--shadow); transition: border-color .15s; }
.auto-card:hover, .auto-card:focus-visible { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); outline: none; }
.auto-card.off { opacity: .62; }
.auto-ic { width: 36px; height: 36px; border-radius: 10px; flex: none; display: grid; place-items: center; color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.auto-main { flex: 1; min-width: 0; }
.auto-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.auto-say { font-size: 14px; margin-top: 3px; overflow-wrap: anywhere; }
.auto-meta { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.auto-card .switch { margin-top: 6px; }
.note { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 10px 12px; border-radius: 12px; margin: 10px 0; font-size: 13.5px;
  background: color-mix(in srgb, var(--link) 9%, var(--panel-2)); border: 1px solid color-mix(in srgb, var(--link) 30%, var(--line)); }
.note > svg.i { color: var(--link); }
.note > span { flex: 1; min-width: 200px; }
.note.warn { background: color-mix(in srgb, var(--warn) 9%, var(--panel-2)); border-color: color-mix(in srgb, var(--warn) 35%, var(--line)); }
.note.warn > svg.i { color: var(--warn); }
button.link-btn { background: none; border: 0; padding: 2px 0; color: var(--link); font-size: 13px; font-weight: 550; }

/* ---- the editing panel */
#drawer { position: fixed; inset: 0; z-index: 55; }
.drawer-back { position: absolute; inset: 0; background: rgba(4, 8, 14, .5); backdrop-filter: blur(2px); animation: fade .15s ease; }
.drawer { position: absolute; inset-block: 0; inset-inline-end: 0; width: min(640px, 100%); background: var(--panel); border-inline-start: 1px solid var(--line);
  display: flex; flex-direction: column; box-shadow: -20px 0 60px rgba(0,0,0,.35); animation: slide .18s ease; }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }
.drawer header, .drawer footer { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.drawer footer { border-bottom: 0; border-top: 1px solid var(--line); padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
.drawer header h2 { margin: 0; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 20px 24px; }
.dr-say { margin: -4px 0 8px; padding: 10px 12px; border-radius: 12px; background: var(--panel-2); font-size: 14px; overflow-wrap: anywhere; }
.dr-sec { margin-top: 18px; }
.dr-sec h3 { margin: 0 0 4px; }
.dr-sec > p { margin: 0 0 8px; }
.cond-row, .act-row { display: flex; gap: 10px; align-items: flex-start; padding: 10px; margin: 8px 0; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); }
.cond-main, .act-main { flex: 1; min-width: 0; display: grid; gap: 6px; }
.cond-line { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cond-row select, .cond-row input, .act-row select, .act-row input, .drawer .act select, .drawer .act input { padding: 5px 8px; background: var(--panel); }
.cond-row select.ctype { font-weight: 600; }
.chk { width: 26px; height: 26px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 13px; font-weight: 800; color: var(--muted); background: var(--panel-3); margin-top: 2px; }
.chk.yes { color: #fff; background: var(--ok); }
.chk.no { background: none; box-shadow: inset 0 0 0 2px var(--line); }
.act-row .tag { margin-top: 4px; }
select.add-sel { margin-top: 4px; }
.dr-adv { margin-top: 22px; padding-top: 12px; border-top: 1px dashed var(--line); }
.dr-adv > summary { color: var(--muted); font-weight: 600; }
.drawer .sub { margin-top: 10px; }
@media (max-width: 640px) {
  .drawer { width: 100%; border: 0; }
  .drawer header, .drawer footer, .drawer-body { padding-inline: 14px; }
  .cond-row, .act-row { padding: 8px; gap: 8px; }
}

/* ---- templates */
.tpl-grid { display: grid; gap: 8px; }
button.tpl, a.preset, button.preset { display: flex; gap: 12px; align-items: flex-start; text-align: start; width: 100%; padding: 12px; border-radius: 12px; font-weight: 400; color: var(--text); }
button.tpl b, .preset b { display: block; font-weight: 650; }
button.tpl small, .preset small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
button.tpl:disabled { opacity: .55; }
.modal .field { grid-template-columns: minmax(120px, 200px) 1fr; }

/* ---- power management */
.pm-pick { margin-bottom: 16px; flex-wrap: wrap; }
.presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
a.preset, button.preset { background: var(--panel-2); border: 1px solid var(--line); }
.preset.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.preset .pill { margin-inline-start: 4px; vertical-align: 1px; }
details.pm-all h3:first-of-type { margin-top: 8px; }
label.field.changed > span:first-child { color: var(--accent); font-weight: 600; }

/* ---- configuration: second row of tabs inside a group */
.cfg-sub { margin: -6px 0 16px; }

/* Sidebar foot: the account with the live-connection dot as a badge on the avatar, then two compact icon buttons. */
.nav-foot { gap: 2px; }
.user-btn .who { overflow: hidden; }
.nav-foot > button.ghost:not(.user-btn) { padding: 6px; flex: none; }
.nav-foot .user-btn { padding: 5px 6px; gap: 8px; }
.user-btn .who small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar-wrap { position: relative; display: inline-flex; flex: none; }
.avatar-wrap .conn { position: absolute; inset: auto -2px -2px auto; padding: 0; }
[dir="rtl"] .avatar-wrap .conn { inset: auto auto -2px -2px; }
.avatar-wrap .conn::before { width: 10px; height: 10px; box-shadow: 0 0 0 2px var(--panel); }
.avatar-wrap .conn.ok::before { animation: none; box-shadow: 0 0 0 2px var(--panel); }

/* Attention card: the title and the close button stay on one line on any phone; the link sits under the list. */
.attention .card-head { flex-wrap: nowrap; }
.attention .card-head h2 { min-width: 0; }
.attention [data-attn-hide] { flex: none; margin-inline-end: -6px; }
.attn-foot { display: flex; justify-content: flex-end; margin-top: 10px; }

.danger-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 20px; padding: 12px 0; border-top: 1px solid var(--line); }
.danger-row > div:first-child { flex: 1 1 280px; }
.danger-row input[type=number] { width: 80px; }
.table-scroll { overflow-x: auto; }

/* ---- Overview: where the power goes, battery bar, device line */
.kpi .what b { color: var(--text); font-weight: 600; }
.kpi .flowto { color: var(--c); font-weight: 700; margin-right: 2px; }
.kpi.quiet .val { color: var(--muted); }
.kpi .socbar { position: relative; height: 8px; border-radius: 4px; background: var(--panel-3); margin: 14px 0 12px; }
.kpi .socbar .socfill { position: absolute; inset: 0 auto 0 0; border-radius: 4px; background: var(--battery); transition: width .4s; }
.d-row .card { margin-bottom: 0; }
.devs { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.dev { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--panel-2); border: 1px solid transparent; border-radius: 12px; color: var(--text); min-width: 0; }
.dev:hover { border-color: color-mix(in srgb, var(--c) 45%, var(--line)); }
.dev .ico { width: 32px; height: 32px; flex: none; border-radius: 9px; display: grid; place-items: center; color: var(--c); background: color-mix(in srgb, var(--c) 18%, transparent); }
.dev .dv { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.dev .dv b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dev .dv span { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dev .fresh.dot::before { width: 8px; height: 8px; }
.dev.off { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
.dev.off .dv span { color: var(--bad); }
#d-devs-sum.bad { color: var(--bad); font-weight: 600; }

/* ---- inverters: cards on top, the picked one's readings below */
.i-head { margin: 22px 0 12px; }
body[data-detail="advanced"] .inv-cards .inv-card[data-i] { cursor: pointer; }
.inv-cards .inv-card.sel { border-color: color-mix(in srgb, var(--pv) 55%, var(--line)); box-shadow: 0 0 0 1px color-mix(in srgb, var(--pv) 35%, transparent), var(--shadow); }
body:not([data-detail="advanced"]) .inv-cards .inv-card.sel { border-color: var(--line); box-shadow: var(--shadow); }
#i-cmp-card { margin-top: 16px; }

/* ---- batteries: where the bank totals come from */
.b-source { margin: -4px 0 10px; }
.pick .r1 .pill { font-size: 10.5px; padding: 1px 7px; }
/* phones: the devices one under the other, full width, instead of a row that scrolls sideways */
@media (max-width: 560px) { .md .side { flex-direction: column; overflow: visible; padding-bottom: 0; } .md .side .pick { min-width: 0; } }

/* ---- energy totals table */
#t-table th.n, #t-table td.n { text-align: end; }
#t-table th small { display: block; text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 11px; }
#t-table td:first-child { white-space: nowrap; }
/* the day stays in view while the table scrolls sideways on a phone */
#t-table th:first-child, #t-table td:first-child { position: sticky; inset-inline-start: 0; background: var(--panel); z-index: 1; }
#t-table tr.sum td:first-child { background: var(--panel-2); }
#t-table tr.sum td { font-weight: 700; background: var(--panel-2); }
.t-note { margin: 0 0 10px; }

/* ---- grid: last 30 days, set-up cards */
#g-month .chips-row { margin: 4px 0 10px; }
.g-outs td.n { text-align: end; color: var(--muted); }
.g-volt-note { margin: 10px 0 0; }
.g-setup { display: flex; align-items: center; gap: 16px; }
.g-setup > div { flex: 1; min-width: 0; }
.g-setup p { margin: 4px 0 0; }
.g-setup .btn { flex: none; text-decoration: none; }
@media (max-width: 560px) { #grid-stats { grid-template-columns: 1fr 1fr; } }

/* remote */
.remote-state { gap: 8px; margin: 4px 0 10px; }
.remote-url { margin-bottom: 8px; }
.remote-url a { overflow-wrap: anywhere; font-weight: 550; }
.remote-log pre { overflow: auto; max-height: 220px; font-size: 11px; line-height: 1.5; padding: 8px; border-radius: 8px;
  background: color-mix(in srgb, currentColor 6%, transparent); white-space: pre; }
.remote-log summary { cursor: pointer; }
textarea[data-k="ca_pem"] { width: 100%; font: 11px/1.4 ui-monospace, monospace; }
/* setup wizard */
.wiz { max-width: 760px; }
.wiz-steps { display: flex; gap: 6px; list-style: none; padding: 0; margin: 0 0 14px; flex-wrap: wrap; }
.wiz-steps li { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--faint); padding: 5px 11px 5px 5px; border-radius: 999px; border: 1px solid var(--line); }
.wiz-steps li span { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; background: var(--panel-3); color: var(--muted); }
.wiz-steps li.on { color: var(--text); border-color: var(--accent); }
.wiz-steps li.on span { background: var(--accent); color: var(--accent-ink); }
.wiz-steps li.past { color: var(--muted); }
.wiz-steps li.past span { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.wiz-card { padding: 22px; }
.wiz-card h2 { font-size: 18px; }
.wiz-card h3.wiz-g { display: flex; align-items: center; gap: 6px; }
.wiz-card h3.wiz-g svg.i { width: 15px; height: 15px; }
.wiz-nav { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.wiz-langs { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; }
.wiz-langs .chip { padding: 8px 14px; font-size: 14px; background: var(--panel-2); }
.wiz-langs .chip.on { border-color: var(--accent); color: var(--text); background: color-mix(in srgb, var(--accent) 14%, var(--panel-2)); }
.wiz-links { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.wiz-links .btn { text-decoration: none; }
.wiz-find-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wiz-find-h h2 { margin: 0; }
.wiz-dev { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; margin-bottom: 8px; background: var(--panel-2); }
.wiz-dev.on { border-color: var(--accent); }
.wiz-dev p { margin: 8px 0 0; }
.wiz-dev-h { display: flex; align-items: center; gap: 10px; }
.wiz-dev-h input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.wiz-dot { width: 18px; flex: none; }
.wiz-dev-t { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.wiz-dev-t small { overflow-wrap: anywhere; }
.wiz-sample { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 10px 0 0 28px; }
.wiz-sample span { display: flex; flex-direction: column; }
.wiz-sample small { color: var(--muted); font-size: 11.5px; }
.wiz-alt { display: flex; align-items: center; gap: 8px; margin: 10px 0 0 28px; color: var(--muted); }
.wiz-spin { width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; display: inline-block; animation: wiz-spin .8s linear infinite; }
@keyframes wiz-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .wiz-spin { animation: none; } }
.wiz-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 4px 14px; margin-top: 14px; }
.wiz-done { text-align: center; padding: 18px 8px; }
.wiz-done > svg.i { width: 40px; height: 40px; color: var(--ok); }
@media (max-width: 560px) { .wiz-steps li { font-size: 0; padding: 4px; gap: 0; } .wiz-steps li.on { font-size: 13px; padding-right: 11px; gap: 7px; }
  .wiz-card { padding: 14px; } .wiz-dev { padding: 10px; } .wiz-dev-h { flex-wrap: wrap; row-gap: 6px; }
  .wiz-dev-t { flex-basis: calc(100% - 28px); } .wiz-dev-h .pill { margin-inline-start: 28px; }
  .wiz-sample, .wiz-alt { margin-left: 0; } }
.wiz-form .afield select { padding: 11px 13px; font-size: 15px; width: 100%; }
/* setup hotspot (hotspot.html) */
body.hotspot { display: grid; place-items: start center; padding: 24px 16px; min-height: 100vh; }
.hs { width: 100%; max-width: 420px; margin-top: 4vh; }
.hs h1 { font-size: 20px; margin: 8px 0; }
.hs .hs-logo { width: 40px; height: 40px; }
.hs select { width: 100%; padding: 11px 13px; font-size: 15px; }
/* installer */
.bulk-bar { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.bulk-bar input { margin-top: 3px; }
.bulk-bar:has(input:checked) { border-color: var(--accent); }
.bulk-result td { vertical-align: top; }
.bulk-result td div { margin: 2px 0; }
.bad-text { color: var(--bad); }
.rep-sum td:first-child { white-space: nowrap; }
.rep-checks select { min-width: 90px; }
#site-template .row { flex-wrap: wrap; }
/* planner */
.grid.wide.plan-grid { grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 1400px) { .grid.wide.plan-grid { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); } }
.plan-headline { margin: 2px 0 10px; font-weight: 550; }
.plan-chart { width: 100%; min-height: 230px; overflow: hidden; }
.plan-svg { display: block; }
.plan-axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.plan-axis.strong { fill: var(--text); font-weight: 600; }
.plan-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 6px 0 4px; font-size: 12px; color: var(--muted); }
.plan-legend span { display: inline-flex; align-items: center; gap: 6px; }
.plan-legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.plan-legend i.ln { height: 3px; border-radius: 2px; }
.plan-list { list-style: none; margin: 10px 0 6px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.plan-list li { display: flex; gap: 10px; align-items: baseline; line-height: 1.45; }
.plan-list li > i { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--c); transform: translateY(-1px); }
.pl-outages { margin-top: 12px; }
.pl-outages summary { cursor: pointer; color: var(--link); }
.pl-add { margin-top: 10px; align-items: end; }
.pl-add label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.pl-history td { font-size: 13px; }
table.tt input { width: 100%; min-width: 0; }
table.tt .tt-time { width: 64px; }
.tt-days { white-space: nowrap; font-size: 11px; }
.tt-days label { display: inline-flex; flex-direction: column; align-items: center; margin-inline-end: 2px; }
#tariff-tables table.tt td { padding: 6px 4px; }
@media (max-width: 560px) { #tariff-tables { overflow-x: auto; } .plan-axis { font-size: 10px; } }
/* insights */
.ins-bat h3, .ins-form h3 { font-size: 13px; color: var(--muted); font-weight: 600; margin: 18px 0 8px; }
.ins-tiles { margin: 6px 0 4px; }
.ins-verdict { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 6px; }
.ins-verdict li { position: relative; padding-left: 18px; }
.ins-verdict li::before { content: ""; position: absolute; left: 2px; top: .55em; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.ins-verdict li.ok::before { background: var(--ok); }
.ins-verdict li.warn::before { background: var(--warn); }
.ins-verdict li.bad::before { background: var(--bad); }
.ins-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.ins-test .row { margin: 8px 0; }
.ins-test table { margin-top: 10px; }
.ins-size { margin-top: 14px; }
.ins-row { margin: 10px 0; }
.ins-frame { width: 100%; height: 75vh; border: 0; border-radius: 10px; background: #fff; }
.ins-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px 16px; margin: 12px 0; }
.ins-form label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
.ins-form h3 { grid-column: 1 / -1; }
.ins-faults { margin-bottom: 16px; }
.ins-faults .ev .d b { font-weight: 600; }
/* smart loads (smartloads.js) */
.sl-bits { margin: 4px 0 2px; }
.sl-bits svg.i { width: 14px; height: 14px; vertical-align: -2px; }
#l-extra:empty { display: none; }
#l-extra { margin-top: 12px; }
.sl-gen ul, .sl-ev ul { margin: 6px 0 0; padding-left: 18px; }
.sl-tuya-row { border: 1px solid var(--line, rgba(127,127,127,.25)); border-radius: 10px; margin: 10px 0; padding: 4px 12px 8px; }
.sl-tuya-row legend { padding: 0 6px; font-weight: 600; }
.sl-tuya .banner { margin-top: 8px; }
.sl-check { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0; }
/* assistant */
#nav .nav-short { display: none; }
@media (max-width: 860px) { #nav .nav-long { display: none; } #nav .nav-short { display: inline; } }
@media (max-width: 420px) { #nav-links li a { font-size: 9.5px; letter-spacing: -.01em; } }   /* seven tabs on a small phone */
/* Tab bar labels in long languages ("Общ преглед", "Einstellungen"): up to two lines, hyphenated by the page's
   language, instead of one clipped line. */
@media (max-width: 860px) {
  /* A word a little wider than its tab ("Устройства") spills evenly into the gaps beside it instead of being cut. */
  #nav li a { white-space: normal; text-overflow: clip; line-height: 1.12; hyphens: auto; -webkit-hyphens: auto; overflow-wrap: normal;
    justify-content: flex-start; align-items: center; min-height: 50px; overflow: visible; }
  #nav li a span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
}
/* Rows of tabs (Settings sections, Alerts) never widen the page on a phone: they scroll sideways instead. */
.seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.seg::-webkit-scrollbar { display: none; }
.seg button { flex: none; white-space: nowrap; }
.as-chat { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.as-log { display: flex; flex-direction: column; gap: 16px; padding: 20px; min-height: 260px; max-height: min(62vh, 720px); overflow-y: auto; }
.as-off { padding: 32px 16px 20px; }
.as-log:empty { display: none; }
.as-off svg.i, .as-hello > svg.i { color: var(--accent); }
.as-hello { text-align: center; color: var(--muted); padding: 36px 10px 10px; margin: auto 0; }
.as-hello > svg.i { width: 30px; height: 30px; display: block; margin: 0 auto 8px; }
.as-hello b { color: var(--text); font-size: 17px; }
.as-suggest { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.as-suggest .chip { background: var(--panel-2); color: var(--text); font-weight: 500; padding: 7px 13px; }
.as-suggest .chip:hover { border-color: var(--accent); }
.as-msg { display: flex; gap: 10px; align-items: flex-start; max-width: 100%; }
.as-msg.me { justify-content: flex-end; }
.as-msg.me .as-bubble { background: color-mix(in srgb, var(--accent) 16%, var(--panel-2)); border-color: transparent; max-width: min(80%, 620px); white-space: pre-wrap; }
.as-avatar { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.as-avatar svg.i { width: 17px; height: 17px; }
.as-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; max-width: 720px; }
.as-bubble { background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; overflow-wrap: anywhere; }
.as-bubble p { margin: 0 0 8px; }
.as-bubble p:last-child, .as-bubble ul:last-child { margin-bottom: 0; }
.as-bubble ul, .as-bubble ol { margin: 0 0 10px; padding-inline-start: 20px; }
.as-bubble li { margin: 3px 0; }
.as-bubble ol:last-child, .as-bubble .as-table:last-child { margin-bottom: 0; }
.as-bubble h4 { margin: 12px 0 6px; font-size: 15px; }
.as-bubble h4:first-child { margin-top: 0; }
.as-bubble hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.as-table { overflow-x: auto; margin: 4px 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.as-table table { border-collapse: collapse; width: 100%; font-size: 14px; }
.as-table th, .as-table td { padding: 7px 12px; text-align: start; border-bottom: 1px solid var(--line); white-space: nowrap; }
.as-table th { font-weight: 600; color: var(--muted); font-size: 12.5px; background: var(--panel-2); }
.as-table tr:last-child td { border-bottom: 0; }
.as-table .num { text-align: end; font-variant-numeric: tabular-nums; }
.as-bubble code { font-family: var(--mono); font-size: 13px; background: var(--panel-3); padding: 1px 5px; border-radius: 5px; }
.as-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.as-tools .pill { color: var(--muted); background: var(--panel-2); }
.as-tools .pill svg.i { width: 13px; height: 13px; color: var(--ok); }
.as-tools .pill.bad { color: var(--bad); }
.as-spin { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--faint); border-top-color: var(--accent); animation: as-spin .8s linear infinite; }
@keyframes as-spin { to { transform: rotate(360deg); } }
.as-typing { display: flex; gap: 4px; padding: 12px 4px; }
.as-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: as-blink 1.2s infinite; }
.as-typing i:nth-child(2) { animation-delay: .2s; } .as-typing i:nth-child(3) { animation-delay: .4s; }
@keyframes as-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.as-error { color: var(--bad); font-size: 13px; }
.as-action { border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); background: color-mix(in srgb, var(--accent) 5%, var(--panel)); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.as-action.done { border-color: var(--line); background: var(--panel); }
.as-action-head { display: flex; align-items: center; gap: 8px; }
.as-action-head svg.i { color: var(--accent); }
.as-diff { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.as-diff .muted { min-width: 90px; }
.as-diff .old { text-decoration: line-through; color: var(--muted); }
.as-diff .new { font-weight: 700; }
.as-diff svg.i { width: 15px; height: 15px; color: var(--muted); }
.as-rule { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.as-rule ul { margin: 4px 0 0; padding-inline-start: 18px; }
.as-action-foot { gap: 8px; }
.as-action-foot .pill svg.i { width: 13px; height: 13px; }
.as-compose { display: flex; gap: 8px; align-items: flex-end; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--panel); }
.as-compose[hidden] { display: none; }
.as-compose textarea { flex: 1; min-height: 42px; max-height: 160px; resize: none; font: inherit; padding: 10px 12px; border-radius: 12px; }
.as-compose button { height: 42px; width: 46px; justify-content: center; border-radius: 12px; }
[dir="rtl"] .as-compose button svg.i { transform: scaleX(-1); }
[dir="rtl"] .as-compose button.as-mic svg.i { transform: none; }
.as-compose .as-mic.on { color: var(--bad); border-color: var(--bad); animation: as-listen 1.4s ease-in-out infinite; }
@keyframes as-listen { 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--bad) 22%, transparent); } }
@media (prefers-reduced-motion: reduce) { .as-compose .as-mic.on { animation: none; } }
.as-foot { display: flex; align-items: center; gap: 10px; padding: 8px 16px 12px; flex-wrap: wrap; border-top: 1px solid var(--line); }
.as-foot .switch-row { font-weight: 500; }
.as-foot .switch i { transform: scale(.8); }
.as-privacy { padding: 4px 16px 10px; font-size: 13px; color: var(--muted); }
.as-privacy summary { cursor: pointer; display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-weight: 550; }
.as-privacy summary svg.i { width: 15px; height: 15px; }
.as-privacy p { margin: 8px 0 0; max-width: 760px; }
.as-settings summary { cursor: pointer; list-style: none; }
.as-settings summary::-webkit-details-marker { display: none; }
.as-settings summary h2 { margin: 0; display: inline-flex; align-items: center; gap: 8px; }
.as-settings[open] summary { margin-bottom: 14px; }
.as-settings + .as-chat { margin-top: 16px; }
.as-form { display: flex; flex-direction: column; gap: 16px; max-width: 760px; }
.as-form .switch-row, .as-field { display: flex; justify-content: space-between; align-items: center; gap: 16px; font-weight: 400; flex-wrap: wrap; }
.as-field > span, .as-form .switch-row > span:first-child { flex: 1 1 300px; }
.as-field input[type="password"] { width: 220px; }
.as-field input[type="number"] { width: 110px; }
@media (max-width: 560px) {
  .as-log { padding: 14px; max-height: 65vh; }
  .as-rule { grid-template-columns: 1fr; }
  .as-avatar { display: none; }
  .as-field input[type="password"] { width: 100%; }
}

/* charts: range statistics and full screen */
.chart .range-box { position: absolute; left: 50px; bottom: 30px; z-index: 3; max-width: calc(100% - 60px); overflow-x: auto;
  background: color-mix(in srgb, var(--panel) 96%, transparent); backdrop-filter: blur(6px); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 20px rgb(0 0 0 / 0.18); }
.chart .range-box[hidden] { display: none; }
.chart .range-box .range-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.chart .range-box table { border-collapse: collapse; white-space: nowrap; }
.chart .range-box th { color: var(--faint); font-weight: 500; text-align: right; padding: 0 0 2px 12px; }
.chart .range-box td { text-align: right; padding: 1px 0 1px 12px; font-variant-numeric: tabular-nums; }
.chart .range-box td:first-child { text-align: left; padding-left: 0; }
.chart .range-box td i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.fs-btn { background: none; border: 0; padding: 2px 6px; margin-left: 6px; color: var(--faint); cursor: pointer; font-size: 15px; line-height: 1; }
.fs-btn:hover { color: inherit; }
.card:fullscreen { background: var(--bg); padding: 24px; overflow: auto; }
.card:fullscreen .chart { height: calc(100vh - 140px) !important; }

/* totals: compared with before */
.t-cmp-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 8px 28px; }
.t-cmp h3 { margin: 6px 0 4px; }
.t-cmp td.n .pill { margin-left: 4px; font-size: 11px; }
.t-cmp th small { display: block; font-weight: 400; color: var(--faint); }
