:root {
  --bg: #f1f5f9; --card: #ffffff; --text: #0f172a; --muted: #64748b; --border: #e2e8f0;
  --accent: #1d4ed8; --accent-2: #3b82f6; --accent-bg: #dbeafe; --accent-text: #1e3a8a;
  --ok: #15803d; --ok-bg: #dcfce7; --warn: #b45309; --warn-bg: #fef3c7; --err: #b91c1c; --err-bg: #fee2e2;
  --off: #cbd5e1; --lamp: #f59e0b; --lamp-bg: #fef3c7; --radius: 14px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --card: #131c2e; --text: #e2e8f0; --muted: #94a3b8; --border: #1f2a40;
    --accent: #60a5fa; --accent-2: #3b82f6; --accent-bg: #1e3a8a; --accent-text: #dbeafe;
    --ok: #4ade80; --ok-bg: #14532d; --warn: #fbbf24; --warn-bg: #713f12; --err: #f87171; --err-bg: #7f1d1d;
    --off: #334155; --lamp-bg: #78350f; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1220; --card: #131c2e; --text: #e2e8f0; --muted: #94a3b8; --border: #1f2a40;
  --accent: #60a5fa; --accent-2: #3b82f6; --accent-bg: #1e3a8a; --accent-text: #dbeafe;
  --ok: #4ade80; --ok-bg: #14532d; --warn: #fbbf24; --warn-bg: #713f12; --err: #f87171; --err-bg: #7f1d1d;
  --off: #334155; --lamp-bg: #78350f; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 22px; margin: 0; font-weight: 600; }
h2 { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 22px 0 8px; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

/* Kopfzeile */
.top { position: sticky; top: 0; z-index: 10; background: var(--bg); padding: 14px 0 10px; }
.top .wrap { display: flex; align-items: center; gap: 12px; }
.top .grow { flex: 1; min-width: 0; }
.top .sub { color: var(--muted); font-size: 13px; }
.iconbtn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--border); background: var(--card);
  color: var(--text); display: inline-flex; align-items: center; justify-content: center; font-size: 20px; cursor: pointer; }

/* Navigation: unten am Handy, oben am PC */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--card); border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.nav a { flex: 1; text-align: center; color: var(--muted); font-size: 11px; padding: 4px 0; border-radius: 10px; }
.nav a i { display: block; font-size: 23px; line-height: 1.2; }
.nav a.aktiv { color: var(--accent); }
@media (min-width: 900px) {
  body { padding-bottom: 24px; padding-left: 210px; }
  .nav { top: 0; bottom: 0; right: auto; width: 210px; flex-direction: column; justify-content: flex-start;
    border-top: 0; border-right: 1px solid var(--border); padding: 20px 12px; gap: 4px; }
  .nav::before { content: "Power"; font-weight: 700; font-size: 20px; padding: 0 12px 16px; color: var(--accent); }
  .nav a { flex: 0; display: flex; align-items: center; gap: 12px; font-size: 15px; padding: 10px 12px; text-align: left; }
  .nav a i { display: inline; font-size: 21px; }
  .nav a.aktiv { background: var(--accent-bg); color: var(--accent-text); }
}

/* Kacheln oben */
.kacheln { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 700px) { .kacheln { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kachel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.kachel .l { color: var(--muted); font-size: 12px; }
.kachel .v { font-size: 22px; font-weight: 650; line-height: 1.25; }
.kachel .e { color: var(--muted); font-size: 12px; }
.kachel.blau { background: var(--accent-bg); border-color: transparent; }
.kachel.blau .l, .kachel.blau .e, .kachel.blau .v { color: var(--accent-text); }

/* Gerätekarten */
.raster { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
@media (min-width: 640px) { .raster { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1200px) { .raster { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.karte { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px;
  display: flex; align-items: center; gap: 12px; min-height: 64px; }
.karte .ic { width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0; background: var(--bg); color: var(--muted); transition: background .2s, color .2s; }
.karte.an .ic { background: var(--accent-bg); color: var(--accent-text); }
.karte.an.lampe .ic { background: var(--lamp-bg); color: var(--lamp); }
.karte.sensor .ic { background: var(--ok-bg); color: var(--ok); }
.karte .txt { flex: 1; min-width: 0; }
.karte .txt a { color: var(--text); display: block; }
.karte .n { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.karte .s { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.karte .s b { color: var(--text); font-weight: 600; }
.karte.offline { opacity: .55; }
.karte.offline .s::after { content: " · offline"; color: var(--err); }
.karte input[type=range] { width: 100%; margin: 6px 0 0; }
.karte.kind { margin-left: 18px; }

/* Raum-/Gruppenkopf, einklappbar */
.gruppe { margin-top: 14px; }
.gkopf { display: flex; align-items: center; gap: 8px; padding: 8px 4px; cursor: pointer; user-select: none;
  border-radius: 10px; min-height: 44px; }
.gkopf:hover { background: var(--card); }
.gkopf:focus-visible { outline: 2px solid var(--accent-2); }
.gkopf .pfeil { font-size: 18px; color: var(--muted); transition: transform .2s; }
.gkopf .gname { flex: 1; min-width: 0; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase;
  letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gkopf .ginfo { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.gwatt { background: var(--accent-bg); color: var(--accent-text); font-weight: 650; font-size: 13px; padding: 2px 10px;
  border-radius: 999px; font-variant-numeric: tabular-nums; }
.gan { color: var(--muted); font-size: 12px; }
.gruppe.zu .pfeil { transform: rotate(-90deg); }
.gruppe.zu .raster { display: none; }
.gruppe.leer { display: none; }
.sortieren .gruppe.leer { display: block; }
.gruppe.leer .raster { min-height: 56px; border: 2px dashed var(--border); border-radius: var(--radius); }

/* Sortiermodus (Drag and Drop) */
.griff { display: none; color: var(--muted); font-size: 22px; cursor: grab; touch-action: none; padding: 6px 2px;
  margin: -6px 0; flex-shrink: 0; }
.sortieren .griff { display: inline-flex; align-items: center; }
.sortieren .karte .sw, .sortieren .karte input[type=range] { pointer-events: none; opacity: .5; }
.sortieren .gkopf { cursor: default; }
.sortieren .gruppe .raster { min-height: 56px; }
.sortieren .gkopf .pfeil { visibility: hidden; }
.sortier-hinweis { display: none; position: sticky; top: 68px; z-index: 9; margin: 12px 0 0; padding: 8px 12px;
  background: var(--accent-bg); color: var(--accent-text); border-radius: 12px; align-items: center; gap: 10px; font-size: 14px; }
.sortier-hinweis .grow { flex: 1; }
.sortieren .sortier-hinweis { display: flex; }
.geist { opacity: .35; }
.gewaehlt { box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.iconbtn.aktiv { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }

/* Geräteliste */
.modelle { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 12px; margin-top: 12px; }
@media (min-width: 900px) { .modelle { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.modell-kopf { display: flex; align-items: center; gap: 14px; }
.produkt { width: 76px; height: 76px; flex-shrink: 0; border-radius: 14px; background: #f1f5f9; display: flex;
  align-items: center; justify-content: center; overflow: hidden; padding: 6px; }
.produkt svg { width: 100%; height: 100%; }
.produkt img { width: 100%; height: 100%; object-fit: contain; }
.modell-name { font-size: 18px; font-weight: 700; }
.stueck { text-align: center; flex-shrink: 0; min-width: 56px; }
.stueck span { display: block; font-size: 30px; font-weight: 750; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }
.stueck small { color: var(--muted); font-size: 11px; }
.punkt { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; background: var(--err); }
.punkt.ok { background: #22c55e; }

/* Schalter */
.sw { position: relative; width: 50px; height: 30px; flex-shrink: 0; border-radius: 15px; background: var(--off); border: 0;
  cursor: pointer; transition: background .2s; padding: 0; }
.sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.sw.an { background: var(--accent-2); }
.lampe .sw.an { background: var(--lamp); }
.sw.an::after { transform: translateX(20px); }
.sw.wartet { opacity: .6; }
.sw.gross { width: 64px; height: 38px; border-radius: 19px; }
.sw.gross::after { width: 32px; height: 32px; }
.sw.gross.an::after { transform: translateX(26px); }

/* Boxen, Formulare */
.box { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.box h3 { margin: 0 0 10px; font-size: 16px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=time], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; min-height: 44px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-2); outline-offset: -1px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600;
  min-height: 44px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--card);
  color: var(--text); cursor: pointer; }
.btn.primaer { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.klein { min-height: 34px; padding: 4px 12px; font-size: 13px; }
.btn.gefahr { color: var(--err); }
.btn.voll { width: 100%; }
.zeile { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.zeile > .grow { flex: 1; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--card); color: var(--muted); border-radius: 999px; padding: 6px 14px;
  font-size: 13px; cursor: pointer; font: inherit; font-size: 13px; }
.chip.aktiv { background: var(--accent-bg); border-color: transparent; color: var(--accent-text); font-weight: 600; }
.tage { display: flex; gap: 4px; flex-wrap: wrap; }
.tage label { margin: 0; }
.tage input { display: none; }
.tage span { display: inline-flex; width: 38px; height: 38px; align-items: center; justify-content: center; border-radius: 50%;
  border: 1px solid var(--border); color: var(--muted); font-size: 13px; cursor: pointer; }
.tage input:checked + span { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.liste { list-style: none; margin: 0; padding: 0; }
.liste li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.liste li:last-child { border-bottom: 0; }
.liste .grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.klein { font-size: 12.5px; }
.flash { border-radius: 10px; padding: 10px 14px; margin: 0 0 12px; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.error { background: var(--err-bg); color: var(--err); }
.flash.info { background: var(--accent-bg); color: var(--accent-text); }
.hinweis { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 10px 14px; margin: 12px 0; }
.badge { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.err { background: var(--err-bg); color: var(--err); }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t td, table.t th { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: left; }
table.t th { color: var(--muted); font-weight: 500; font-size: 12px; }
table.t .r { text-align: right; white-space: nowrap; }
.anteil { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.anteil div { height: 100%; background: var(--accent-2); border-radius: 3px; }

/* Diagramm */
.chart { width: 100%; height: 190px; display: block; }
.chart text { fill: var(--muted); font-size: 10px; }
.chart .gl { stroke: var(--border); stroke-width: 1; }
.chart .bar { fill: var(--accent-2); opacity: .85; }
.chart .bar.hl { opacity: 1; fill: var(--accent); }
.chart .line { fill: none; stroke: var(--accent-2); stroke-width: 2; }
.chart .area { fill: var(--accent-2); opacity: .15; }
.chart-kopf { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }

/* Lampenfarben */
.farben { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.farben button { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--border); cursor: pointer; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 20px); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: 90vw; }

/* Anmeldeseiten */
.login { max-width: 380px; margin: 9vh auto 0; padding: 0 16px; }
.login .logo { width: 64px; height: 64px; margin: 0 auto 12px; display: block; }
.login h1 { text-align: center; margin-bottom: 18px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; margin: 12px 0; }
.check input { width: 20px; height: 20px; }
