/* Hütten-Dashboard · schlicht, hell/dunkel, Handy + PC */
:root {
  color-scheme: light;
  --bg: #f3f3f1; --surface: #fcfcfb; --surface-2: #f0efec; --border: #e3e2de; --border-2: #d3d2cd;
  --text: #0b0b0b; --text-2: #52514e; --muted: #7a7975;
  --accent: #2a78d6; --accent-ink: #1c5cab; --accent-soft: #e6f0fc;
  --s-bat: #2a78d6; --s-pv: #eb6834; --s-load: #1baf7a;
  --good: #0ca30c; --good-ink: #006300; --warn: #fab219; --warn-ink: #8a5a00; --crit: #d03b3b; --crit-ink: #b02a2a;
  --good-soft: #e7f6e7; --warn-soft: #fdf3dc; --crit-soft: #fbe9e9;
  /* Gerätefarben – geprüft für Nachbarn in fester Reihenfolge blau→orange→violett→pink→grau */
  --dev-blue: #2a78d6; --dev-orange: #eb6834; --dev-violet: #4a3aa7; --dev-magenta: #e87ba4; --dev-gray: #a3a29d;
  --r: 12px; --r-s: 8px;
  --shadow: 0 1px 2px rgb(0 0 0 / .04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #2c2c2a; --border-2: #3a3a37;
    --text: #f4f4f2; --text-2: #c3c2b7; --muted: #8f8e86;
    --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: #1b2a3d;
    --s-bat: #3987e5; --s-pv: #d95926; --s-load: #199e70;
    --good-ink: #5fd35f; --warn-ink: #fab219; --crit-ink: #f08a8a;
    --good-soft: #17271a; --warn-soft: #2d2510; --crit-soft: #321a1a;
    --dev-blue: #3987e5; --dev-orange: #d95926; --dev-violet: #9085e9; --dev-magenta: #d55181; --dev-gray: #6f6e69;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #2c2c2a; --border-2: #3a3a37;
  --text: #f4f4f2; --text-2: #c3c2b7; --muted: #8f8e86;
  --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: #1b2a3d;
  --s-bat: #3987e5; --s-pv: #d95926; --s-load: #199e70;
  --good-ink: #5fd35f; --warn-ink: #fab219; --crit-ink: #f08a8a;
  --good-soft: #17271a; --warn-soft: #2d2510; --crit-soft: #321a1a;
  --dev-blue: #3987e5; --dev-orange: #d95926; --dev-violet: #9085e9; --dev-magenta: #d55181; --dev-gray: #6f6e69;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 var(--font); color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent-ink); text-decoration: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.sec { color: var(--text-2); }

/* Symbole */
.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75;
     stroke-linecap: round; stroke-linejoin: round; }
.i-fill { fill: currentColor; stroke: none; }
.i-dots { stroke-width: 2.6; }
.i.sm { width: 16px; height: 16px; }

/* ---------- Grundgerüst ---------- */
.shell { min-height: 100vh; }
.side { display: none; }
main { padding: calc(12px + var(--safe-t)) 16px calc(84px + var(--safe-b)); max-width: 1600px; margin: 0 auto; }

.top { display: flex; align-items: center; gap: 12px; margin: 4px 0 16px; flex-wrap: wrap; }
.top h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; margin: 0; flex: 1 1 auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 99px;
        background: var(--surface); border: 1px solid var(--border); font-size: 13px; color: var(--text-2);
        white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.up, .dot.good { background: var(--good); }
.dot.slow, .dot.warn { background: var(--warn); }
.dot.down, .dot.crit { background: var(--crit); }
.dot.unknown { background: var(--border-2); }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex;
        background: var(--surface); border-top: 1px solid var(--border); padding-bottom: var(--safe-b); }
.tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 56px;
               padding: 8px 0 6px; border: 0; background: none; color: var(--muted); font-size: 11px; cursor: pointer; }
.tabs button[aria-current="page"] { color: var(--accent-ink); }
.tabs .i { width: 22px; height: 22px; }

.banner { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r);
          margin-bottom: 16px; border: 1px solid; font-size: 14px; }
.banner.crit { background: var(--crit-soft); border-color: var(--crit); color: var(--text); }
.banner.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--text); }
.banner.info { background: var(--accent-soft); border-color: var(--accent); }
.banner b { font-weight: 600; }
.banner .btn { margin-left: auto; }

/* ---------- Karten & Raster ---------- */
.grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow);
        padding: 16px; min-width: 0; }
.card-h { display: flex; align-items: center; gap: 8px; margin: -2px 0 12px; min-height: 28px; }
.card-h h2 { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 0; flex: 1; text-transform: none;
             letter-spacing: 0; }
.card-h .aside { font-size: 12px; color: var(--muted); }
.stale .card { opacity: .62; }

/* Energie-Hauptkarte */
.energy { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }
.soc { display: flex; align-items: center; gap: 18px; }
.ring { width: 132px; height: 132px; flex: none; position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { stroke: var(--surface-2); }
.ring .val { stroke: var(--s-bat); transition: stroke-dashoffset .15s; }
.ring .val.warn { stroke: var(--warn); } .ring .val.crit { stroke: var(--crit); }
.ring .lbl { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.hero { font-size: 44px; font-weight: 650; letter-spacing: -.02em; line-height: 1; }
.hero small { font-size: 18px; font-weight: 500; color: var(--muted); margin-left: 1px; }
.soc-meta { display: grid; gap: 4px; font-size: 14px; flex: 1; min-width: 0; }
.soc-meta .state { font-weight: 600; }

.flow { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; align-items: center; gap: 6px; }
.flow .node { padding: 10px 12px; border-radius: var(--r-s); background: var(--surface-2); min-width: 0; }
.flow .node .k { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.flow .node .v { font-size: 22px; font-weight: 600; margin-top: 2px; white-space: nowrap; }
.flow .node .v small { font-size: 13px; color: var(--muted); font-weight: 500; }
.flow .arrow { color: var(--muted); display: flex; }
.flow .arrow.rev { transform: scaleX(-1); }
.key { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.key.pv { background: var(--s-pv); } .key.bat { background: var(--s-bat); } .key.load { background: var(--s-load); }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.stat { background: var(--surface-2); border-radius: var(--r-s); padding: 8px 12px; min-width: 0; }
.stat .k { font-size: 12px; color: var(--text-2); }
.stat .v { font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .v small { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 2px; }

/* Segment-Umschalter */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: none; padding: 4px 10px; border-radius: 6px; font-size: 12px; color: var(--text-2);
              cursor: pointer; min-height: 28px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--border); }

/* Diagramm */
.chart { position: relative; height: 180px; }
.chart.tall { height: 220px; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .grid-l { stroke: var(--border); stroke-width: 1; }
.chart .zero { stroke: var(--border-2); }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .ln.pv { stroke: var(--s-pv); } .chart .ln.bat { stroke: var(--s-bat); } .chart .ln.load { stroke: var(--s-load); }
.chart .xh { stroke: var(--text-2); stroke-width: 1; }
.chart .mk { stroke: var(--surface); stroke-width: 2; }
.chart .mk.pv { fill: var(--s-pv); } .chart .mk.bat { fill: var(--s-bat); } .chart .mk.load { fill: var(--s-load); }
.chart .empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
                color: var(--muted); font-size: 13px; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border-2);
       border-radius: 8px; padding: 6px 9px; font-size: 12px; white-space: nowrap; z-index: 5;
       box-shadow: 0 4px 12px rgb(0 0 0 / .12); }
.tip .t { color: var(--muted); margin-bottom: 2px; }
.tip .r { display: flex; align-items: center; gap: 6px; }
.tip .r b { margin-left: auto; padding-left: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* Listen */
.rows { display: grid; }
.row { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 2px; border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }
.row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { font-size: 12px; color: var(--muted); white-space: nowrap; }
.row .ico { color: var(--text-2); display: flex; }
.row a.go { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 8px;
            color: var(--text-2); }
.row a.go:hover { background: var(--surface-2); color: var(--text); }
.row .name.two { display: flex; flex-direction: column; white-space: normal; }
.row .name.two .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .name.two .meta { overflow: hidden; text-overflow: ellipsis; }
.card-h { flex-wrap: wrap; }
.card-h .legend { order: 3; flex-basis: 100%; }
/* Gerätezuordnung: Farbbalken an der Zeile + Gruppenkopf mit Namen (Farbe nie allein) */
.dv-blue { --dv: var(--dev-blue); } .dv-orange { --dv: var(--dev-orange); } .dv-violet { --dv: var(--dev-violet); }
.dv-magenta { --dv: var(--dev-magenta); } .dv-gray { --dv: var(--dev-gray); }
.devgrp { border-left: 3px solid var(--dv); padding-left: 10px; margin: 0 0 10px; }
.devgrp:last-child { margin-bottom: 0; }
.devh + .row, .devh + .setting { border-top: 0; }
.devh { display: flex; align-items: baseline; gap: 8px; font-size: 12px; color: var(--muted); padding: 2px 0 2px; }
.devh b { color: var(--text-2); font-weight: 600; }
.devh .key { width: 9px; height: 9px; border-radius: 3px; background: var(--dv); align-self: center; }
.setting-grp { border-left: 3px solid var(--dv); padding-left: 12px; margin-top: 12px; }
.setting-grp:first-child { margin-top: 0; }
.setting-grp .setting:first-of-type { padding-top: 8px; }
.grp { font-size: 12px; color: var(--muted); margin: 14px 2px 2px; }
.grp:first-child { margin-top: 0; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--text-2); } .kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 8px;
        border-radius: 99px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good-ink); }
.pill.warn { background: var(--warn-soft); color: var(--warn-ink); }
.pill.crit { background: var(--crit-soft); color: var(--crit-ink); }
.pill.on { background: var(--accent-soft); color: var(--accent-ink); }

.meter { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--s-bat); border-radius: 3px; }
.meter i.warn { background: var(--warn); } .meter i.crit { background: var(--crit); }

/* Schalter */
.sw { position: relative; width: 46px; height: 28px; border-radius: 99px; border: 0; background: var(--border-2);
      cursor: pointer; flex: none; transition: background .15s; }
.sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
             background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / .25); transition: transform .15s; }
.sw[aria-checked="true"] { background: var(--accent); }
.sw[aria-checked="true"]::after { transform: translateX(18px); }
.sw:disabled { opacity: .5; cursor: default; }
.sw.busy { opacity: .6; }

/* Knöpfe & Eingaben */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 14px;
       border-radius: 10px; border: 1px solid var(--border-2); background: var(--surface); cursor: pointer;
       font-weight: 500; font-size: 14px; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--crit-ink); border-color: var(--crit); }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; min-height: 46px; }
.btn:disabled { opacity: .5; cursor: default; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.field { display: grid; gap: 4px; }
.field label { font-size: 13px; color: var(--text-2); }
.inp { min-height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border-2); background: var(--surface);
       width: 100%; }
.inp:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.setting { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; padding: 12px 0;
           border-top: 1px solid var(--border); }
.setting:first-child { border-top: 0; padding-top: 0; }
.setting .hint { font-size: 12px; color: var(--muted); }
.setting .ctl { display: flex; gap: 8px; align-items: center; }
.setting .ctl .inp { width: 110px; }
.setting .ctl .inp.sm { width: 76px; padding: 0 8px; }
@media (max-width: 520px) { .setting .ctl { flex-wrap: wrap; justify-content: flex-end; } }

/* Mitglieder-Einzelseite */
body.member .side, body.member .tabs { display: none !important; }
/* Mitglieder-Seite hat keine Seitenleiste → Konto-Knopf (Abmelden, Passwort, Design) immer zeigen */
body.member .top .only-m { display: inline-flex !important; }
body.member .shell { display: block; }
body.member main { max-width: 1120px; padding-bottom: calc(24px + var(--safe-b)); }
body.member .toasts { bottom: 24px; }
.mgrid { display: grid; gap: 16px; }
.card-h.sect { margin: 4px 2px 10px; }
.svcs { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
.svc { display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: var(--r); background: var(--surface);
       border: 1px solid var(--border); color: var(--text); box-shadow: var(--shadow); min-height: 84px; }
.svc:hover { border-color: var(--border-2); background: var(--surface-2); }
.svc-i { width: 44px; height: 44px; border-radius: 12px; background: var(--accent-soft); color: var(--accent-ink);
         display: flex; align-items: center; justify-content: center; flex: none; }
.svc-i .i { width: 24px; height: 24px; }
.svc-t { flex: 1; min-width: 0; display: grid; gap: 2px; }
.svc-t b { font-weight: 600; font-size: 16px; }
.svc-t .hint { font-size: 13px; color: var(--text-2); }
.svc-s { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.svc-go { color: var(--muted); }
.wx-now { display: flex; gap: 16px; align-items: center; margin-bottom: 12px; }
.i.wx-i { width: 44px; height: 44px; color: var(--text-2); }
.wx-days { display: grid; gap: 4px; margin: 0 0 10px; }
.wx-day { display: grid; grid-template-columns: 52px 22px 1fr auto; align-items: center; gap: 8px; font-size: 14px;
          padding: 6px 0; border-top: 1px solid var(--border); }
.wx-day .hint { font-size: 12px; color: var(--muted); }
.wx-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 8px 0; border-top: 1px solid var(--border); font-size: 14px; }
.wx-row .sec { display: flex; align-items: center; gap: 6px; }
.wx-row .hint { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.wx-row .hint:empty { display: none; }
#mb-wx > .hint { font-size: 11px; color: var(--muted); margin-top: 8px; }
@media (min-width: 720px) {
  .svcs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .svc { flex-direction: column; align-items: flex-start; min-height: 150px; position: relative; }
  .svc-go { position: absolute; top: 16px; right: 16px; }
}
.mgrid > .banner { order: 0; } #mb-sec-power { order: 1; } #mb-sec-links { order: 2; } #mb-sec-wx { order: 3; }
@media (min-width: 1000px) {
  .mgrid { grid-template-columns: minmax(0, 7fr) minmax(0, 4fr); align-items: start; }
  .mgrid > .banner, #mb-sec-links { grid-column: 1 / -1; }
  #mb-sec-wx { order: 2; } #mb-sec-links { order: 3; }
  .svcs { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.row .name.two .n.wrap { white-space: normal; }
.card > .hint { font-size: 12px; color: var(--muted); margin-top: 10px; }

/* Anträge & Badge */
.pend { margin-bottom: 8px; padding: 2px 12px 8px; border-radius: var(--r-s); background: var(--warn-soft); }
.pend .mem { border-top-color: var(--border-2); }
.pend-about { font-size: 13px; color: var(--text-2); font-style: italic; }
.badge { margin-left: 6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; background: var(--crit);
         color: #fff; font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.tabs .badge { position: absolute; margin: -6px 0 0 14px; }
.tabs button { position: relative; }
.login .signup { font-size: 14px; color: var(--text-2); text-align: center; }

/* Mitglieder */
.mem { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 10px 0; border-top: 1px solid var(--border); }
.rows > .mem:first-child { border-top: 0; }
.mem.off .mem-n b { color: var(--muted); }
.mem-t { flex: 1 1 260px; min-width: 0; display: grid; gap: 2px; }
.mem-n { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mem .hint, .form .hint { font-size: 12px; color: var(--muted); }
.mem .ctl { flex-wrap: wrap; }
.form { display: grid; gap: 12px; }
.linkbox { display: grid; gap: 8px; padding: 12px; margin-bottom: 12px; border-radius: var(--r-s); background: var(--accent-soft); }
.linkbox .hint { font-size: 12px; color: var(--text-2); }
.linkrow { display: flex; gap: 8px; }
.linkrow .inp { font: 12px ui-monospace, Consolas, monospace; }
select.inp { appearance: auto; }

/* Updates */
.upd { padding: 10px 0; border-top: 1px solid var(--border); }
.devh + .upd { border-top: 0; padding-top: 6px; }
.upd-h { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.upd-t { flex: 1 1 260px; display: grid; gap: 4px; min-width: 0; }
.upd .hint { font-size: 12px; color: var(--muted); }
.upd-imp { font-size: 13px; color: var(--text-2); }
.upd-imp b { color: var(--text); font-weight: 600; }
pre.log { margin: 8px 0 0; padding: 8px 10px; background: var(--surface-2); border-radius: 8px;
          font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
          white-space: pre-wrap; word-break: break-all; max-height: 220px; overflow: auto; color: var(--text-2); }
.upd-sub { border-top: 1px dashed var(--border); }
details.pk summary { cursor: pointer; font-size: 13px; color: var(--text-2); margin-top: 6px; }
table.log { width: 100%; border-collapse: collapse; font-size: 13px; }
table.log th { text-align: left; font-weight: 500; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.log td { padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.log td.t { white-space: nowrap; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* Relais */
.relays { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.relay { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--r-s);
         border: 1px solid var(--border); background: var(--surface); min-height: 56px; }
.relay .ico { width: 34px; height: 34px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
              background: var(--surface-2); color: var(--text-2); flex: none; }
.relay.on .ico { background: var(--accent-soft); color: var(--accent-ink); }
.relay .name { flex: 1; min-width: 0; }
.relay .name b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.relay .name span { font-size: 12px; color: var(--muted); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .sp { flex: 1; }

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login .box { width: 100%; max-width: 380px; display: grid; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; }
.brand .mark { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: #fff; display: flex;
               align-items: center; justify-content: center; }
.brand .mark .i { width: 18px; height: 18px; }
.login h1 { font-size: 24px; margin: 8px 0 0; letter-spacing: -.01em; }
.login p { margin: 0; color: var(--text-2); }
.err { color: var(--crit-ink); font-size: 14px; }
details.local summary { cursor: pointer; color: var(--text-2); font-size: 14px; padding: 6px 0; }
details.local form { display: grid; gap: 10px; margin-top: 8px; }

/* Dialog & Toast */
dialog { border: 1px solid var(--border-2); border-radius: 14px; background: var(--surface); color: var(--text);
         padding: 20px; width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog h3 { margin: 0 0 6px; font-size: 17px; }
dialog p { margin: 0 0 16px; color: var(--text-2); }
dialog .btns { justify-content: flex-end; }
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(76px + var(--safe-b)); z-index: 50;
          display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-size: 14px;
         box-shadow: 0 6px 20px rgb(0 0 0 / .2); }
.toast.bad { background: var(--crit); color: #fff; }

.relay.flat { border: 0; border-top: 1px solid var(--border); border-radius: 0; padding: 6px 2px; min-height: 52px; background: none; }
.relay.flat:first-child { border-top: 0; }
.top .only-m { order: -1; margin-left: auto; }
.top h1 { order: -2; }

/* ---------- Tablet ---------- */
@media (min-width: 720px) {
  main { padding-left: 24px; padding-right: 24px; }
  .grid { grid-template-columns: repeat(12, minmax(0, 1fr)); }
  .grid > * { grid-column: span 12; }
  .grid > .t6 { grid-column: span 6; }
  .row .name.two { flex-direction: row; align-items: center; gap: 12px; }
  .row .name.two .n { flex: 1; }
  .card-h .legend { order: 0; flex-basis: auto; margin-right: 8px; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- PC ---------- */
@media (min-width: 1200px) {
  .shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); }
  .side { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; padding: 20px 14px;
          border-right: 1px solid var(--border); background: var(--surface); }
  .side .brand { padding: 0 8px 18px; }
  .side nav { display: grid; gap: 2px; }
  .side nav button { display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 10px; border: 0;
                     background: none; border-radius: 8px; cursor: pointer; color: var(--text-2); font-size: 14px;
                     text-align: left; }
  .side nav button:hover { background: var(--surface-2); color: var(--text); }
  .side nav button[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
  .side nav kbd { margin-left: auto; font: 11px var(--font); color: var(--muted); }
  .side .user { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--border); display: grid; gap: 8px;
                font-size: 13px; }
  .side .user b { font-weight: 600; }
  .tabs, .only-m { display: none !important; }
  main { padding: 20px 28px 28px; }
  .toasts { bottom: 24px; }

  .grid > .d8 { grid-column: span 8; } .grid > .d4 { grid-column: span 4; }
  .grid > .d7 { grid-column: span 7; } .grid > .d5 { grid-column: span 5; }
  .grid > .d6 { grid-column: span 6; }
  .col { display: grid; gap: 16px; align-content: start; }
  .energy { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); }
  .energy .chart-wrap { grid-column: 1 / -1; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .scroll { scrollbar-width: thin; max-height: 340px; overflow: auto; margin-right: -8px; padding-right: 8px; }
}
@media (min-width: 1200px) and (max-height: 900px) { .chart { height: 150px; } .ring { width: 116px; height: 116px; } }

/* Wandmodus */
body.kiosk .side, body.kiosk .tabs, body.kiosk .ctl-only { display: none !important; }
body.kiosk .shell { display: block; }
body.kiosk main { padding-bottom: 24px; }
body.kiosk .hero { font-size: 64px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
