/*
 * Family Dashboard – optimiert für iPad mit iOS 12 (Safari 12).
 * Bewusst verzichtet: Flexbox-gap, aspect-ratio, inset, :is(), clamp(). Abstände über margin.
 */
:root {
  --bg: #0f1216;
  --panel: #181d23;
  --panel-2: #20262e;
  --line: #2a313b;
  --text: #e8ecf1;
  --muted: #8b95a3;
  --accent: #4f9cf9;
  --sun: #f5b82e;
  --green: #4cc38a;
  --red: #ef5b5b;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
  overflow: hidden;
}

button { font: inherit; color: inherit; }

/* --- Kopfzeile --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 18px;
  padding-top: env(safe-area-inset-top);
}
.clock #time { font-size: 40px; font-weight: 200; letter-spacing: 1px; }
.clock .date { margin-left: 14px; font-size: 18px; color: var(--muted); }
.status { font-size: 12px; color: var(--muted); text-align: right; }
.status .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin: 0 4px 0 12px; background: var(--green); }
.status .dot.err { background: var(--red); }
.status .dot.off { background: var(--line); }

/* --- Raster: 3 Spalten im Querformat --- */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  grid-gap: 12px;
  height: calc(100% - 64px);
  padding: 0 12px 12px;
}
.stack { display: flex; flex-direction: column; min-height: 0; }
.stack > .panel + .panel { margin-top: 12px; }
.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel.grow { flex: 1; }
/* Energie nur so hoch wie nötig, die Rollos bekommen den restlichen Platz */
.stack > #panel-energy { flex: none; }
.stack > #panel-shutters { flex: 1; }
.stack > #panel-shutters .panel-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }
/* Linke Spalte: Termine und Steckdosen je zur Hälfte */
#col-left > .panel { flex: 1 1 0; }
.panel h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0;
  padding: 12px 14px 8px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}
.panel-body { padding: 0 14px 14px; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.empty, .muted { color: var(--muted); }
.empty { padding: 20px 0; text-align: center; }
.error { margin-top: 8px; font-size: 12px; color: var(--red); }

/* Hochformat: untereinander */
@media (orientation: portrait) {
  html, body { overflow: auto; }
  .grid { grid-template-columns: 1fr 1fr; height: auto; }
  #col-left { grid-column: 1 / 3; }
  #col-left > .panel { max-height: 40vh; }
  #panel-cameras { grid-column: 1 / 3; }
  .stack { grid-column: 1 / 3; }
}

/* --- Kalender --- */
.day { margin-bottom: 14px; }
.day-head { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.day-head.today { color: var(--accent); }
.event {
  display: flex;
  padding: 8px 10px;
  margin-bottom: 6px;
  background: var(--panel-2);
  border-radius: 10px;
  border-left: 4px solid var(--accent);
}
.event .t { width: 54px; flex-shrink: 0; font-size: 13px; color: var(--muted); padding-top: 1px; }
.event .t .allday { font-size: 11px; }
.event.past { opacity: .45; }
.event.running { background: rgba(79, 156, 249, .12); }
.event .live { display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 8px; font-size: 11px; font-weight: 600;
  color: #fff; background: var(--accent); vertical-align: 2px; }
/* "Jetzt"-Linie */
.now-line { position: relative; height: 0; margin: 10px 0 12px; border-top: 2px solid var(--red); }
.now-line:before { content: ''; position: absolute; left: -2px; top: -6px; width: 10px; height: 10px; border-radius: 50%; background: var(--red); }
.now-line span { position: absolute; right: 0; top: -9px; padding: 0 6px; font-size: 11px; font-weight: 600; color: var(--red); background: var(--panel); }
.past-note { font-size: 12px; color: var(--muted); margin: 0 0 6px; }
.event .t b { display: block; color: var(--text); font-weight: 600; font-size: 14px; }
.event .title { font-weight: 500; }
.event .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* --- Kameras --- */
.cams { display: flex; flex-wrap: wrap; margin: 0 -5px; }
.cam { width: 50%; padding: 0 5px 10px; }
.cam-frame {
  position: relative;
  padding-top: 56.25%; /* 16:9 ohne aspect-ratio */
  background: #000;
  border-radius: 10px;
  overflow: hidden;
}
.cam-frame img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
.cam-frame video.tile-live, .cam-frame img.tile-live {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; background: transparent;
  opacity: 0; -webkit-transition: opacity .4s; transition: opacity .4s;
}
.cam-frame .tile-live.ready { opacity: 1; }
.cam-label { z-index: 1; }
.cam-frame .placeholder {
  position: absolute; top: 50%; left: 0; right: 0;
  margin-top: -9px; text-align: center; font-size: 13px; color: var(--muted);
}
.cam-label {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 18px 8px 6px;
  font-size: 13px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .75));
}
.cam-label .src { float: right; font-size: 11px; opacity: .7; text-transform: uppercase; }
.cam-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.cam.offline .cam-frame { opacity: .45; }
/* Babycam nicht erreichbar: eingeklappt */
.cam.collapsed .cam-down { display: flex; flex-wrap: wrap; align-items: center; padding: 12px 14px; border-radius: 10px;
  background: var(--panel-2); font-size: 16px; }
.cam.collapsed .cam-down-ico { margin-right: 10px; font-size: 20px; }
.cam.collapsed .cam-down b { margin-right: 4px; }
.cam.collapsed .cam-down .muted { width: 100%; margin: 2px 0 0 30px; font-size: 12px; }

/* --- Energie --- */
.pv { display: flex; align-items: baseline; }
.pv .big { font-size: 34px; font-weight: 200; }
.pv .unit { font-size: 18px; color: var(--muted); margin-left: 4px; }
.pv .ico { font-size: 26px; margin-right: 10px; color: var(--sun); }
.yield { font-size: 13px; color: var(--muted); margin: 0 0 6px; }
/* Akku-Kennzahl: Hero-Zahl + Tagesverlauf. Polarität: rein = blau, raus = orange (validiert auf dunklem Grund). */
:root { --chg-in: #3987e5; --chg-out: #d95926; }
.kpi { margin: 2px 0 8px; padding: 8px 12px; background: var(--panel-2); border-radius: 10px; }
.kpi-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.kpi-value { font-size: 32px; font-weight: 300; line-height: 1.1; margin: 0 0 2px; }
.kpi-unit { font-size: 18px; color: var(--muted); margin-left: 3px; }
.kpi-chart { height: 60px; overflow: hidden; }
.kpi-chart svg { display: block; }
.battery-svg .grid { stroke: var(--line); stroke-width: 0.5; }
.battery-svg .tick { fill: var(--muted); font-size: 7px; }
.battery-svg .area { fill: var(--muted); fill-opacity: .12; }
.battery-svg .line { fill: none; stroke: var(--muted); stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.battery-svg .now { fill: var(--text); }
.battery-svg rect.in { fill: var(--chg-in); }
.battery-svg rect.out { fill: var(--chg-out); }
.kpi-foot { display: flex; justify-content: space-between; font-size: 12px; margin-top: 4px; }
.in { color: var(--chg-in); }
.out { color: var(--chg-out); }
.flows { display: flex; margin: 0 -4px; }
.flow { flex: 1; margin: 0 4px; padding: 6px; background: var(--panel-2); border-radius: 10px; text-align: center; }
.flow .v { font-size: 17px; font-weight: 500; }
.flow .l { font-size: 11px; color: var(--muted); margin-top: 2px; }
.pos { color: var(--green); }
.neg { color: var(--red); }

/* --- Rollos --- */
.h-actions .btn + .btn { margin-left: 8px; }
.shutter { display: flex; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.shutter:last-child { border-bottom: 0; }
.shutter .info { flex: 1; min-width: 0; }
.shutter .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shutter .room { font-size: 11px; color: var(--muted); }
.shutter .lvl { height: 4px; margin-top: 5px; border-radius: 2px; background: var(--panel-2); }
.shutter .lvl div { height: 100%; border-radius: 2px; background: var(--accent); }
.shutter .ctrl { flex-shrink: 0; margin-left: 10px; }
.shutter .ctrl .btn { width: 44px; height: 40px; padding: 0; margin-left: 4px; font-size: 16px; }
.shutter.unreach { opacity: .5; }
/* Kompakte Rollo-Kachel: eine Zeile je Raum */
.shutter.compact { padding: 6px 0; }
.shutter.compact .info { cursor: pointer; }
.shutter.compact .name { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Raumname links, Stand ("oben" / "unten" / "40 % unten") direkt daneben */
.shutter.compact .name-row { display: flex; align-items: baseline; min-width: 0; }
.shutter.compact .name-row .name { flex-shrink: 0; overflow: visible; }
.shutter.compact .name-row .pos { flex-shrink: 1; min-width: 0; margin-left: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Balken zeigt, wie weit die Rollos unten sind */
.shutter.compact .room { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shutter.compact .lvl { height: 3px; margin-top: 4px; }
.shutter.compact .ctrl .btn { width: 44px; height: 44px; min-height: 44px; padding: 0; font-size: 17px; margin-left: 5px; }

.btn {
  display: inline-block;
  min-height: 44px;
  padding: 10px 16px;
  font-size: 15px;
  border: 0;
  border-radius: 10px;
  background: var(--panel-2);
  cursor: pointer;
}
.btn:active { background: var(--line); }
a.btn, a.btn:visited { color: inherit; text-decoration: none; }
.btn.small { min-height: 34px; padding: 7px 12px; font-size: 13px; text-transform: none; letter-spacing: 0; }

/* iOS Safari löst click auf Nicht-Schaltflächen nur mit cursor:pointer aus */
.cam, .panel h2, .dim, .step-link { cursor: pointer; }

/* --- Bewegung: Kamera-Kachel hervorheben, Rest schmal zur Seite (nicht ausgeblendet) --- */
body.motion-mode .grid { grid-template-columns: 0.78fr 2.2fr 0.78fr; }
body.motion-mode #panel-calendar .h-actions, body.motion-mode .stack .h-actions { display: none; }
body.motion-mode #panel-calendar, body.motion-mode .stack { opacity: .55; }
body.motion-mode #panel-cameras { box-shadow: inset 0 0 0 2px var(--sun); }
body.motion-mode #panel-cameras h2 { color: var(--sun); }
.cams .cam:only-child { width: 100%; }
/* Dashboard: alle Kameras so groß wie die Babycam, untereinander */
#cameras .cams .cam { width: 100%; }
.cams .cam.motion-active { width: 100%; -webkit-order: -1; order: -1; }
.cam.motion-active .cam-frame { box-shadow: 0 0 0 3px var(--sun); }
.cam.motion-active .cam-label { font-size: 17px; }
.motion-badge {
  display: none; position: absolute; top: 10px; right: 10px; z-index: 2;
  padding: 4px 10px; border-radius: 12px; background: rgba(0, 0, 0, .65);
  color: var(--sun); font-size: 14px; font-weight: 600;
}
.cam.motion-active .motion-badge { display: block; }
.motion-badge .pulse {
  display: inline-block; width: 9px; height: 9px; margin-right: 7px; border-radius: 50%;
  background: var(--sun); -webkit-animation: pulse 1s infinite; animation: pulse 1s infinite;
}
@-webkit-keyframes pulse { 50% { opacity: .2; } }
@keyframes pulse { 50% { opacity: .2; } }
/* Schmale Seitenspalten: Texte kürzen statt umbrechen */
body.motion-mode .event .sub, body.motion-mode .shutter .room, body.motion-mode .yield { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Schmale Spalte: Raumname oben, Knöpfe darunter über die volle Breite */
body.motion-mode .shutter.compact { display: block; padding: 6px 0 8px; }
body.motion-mode .shutter.compact .room, body.motion-mode .shutter.compact .lvl { display: none; }
body.motion-mode .shutter.compact .name-row .pos { font-size: 12px; }
body.motion-mode .shutter.compact .ctrl { display: flex; margin: 4px 0 0; }
body.motion-mode .shutter.compact .ctrl .btn { flex: 1; width: auto; margin: 0 2px; }
@media (orientation: portrait) {
  body.motion-mode .grid { grid-template-columns: 1fr 1fr; }
  body.motion-mode #panel-cameras { -webkit-order: -1; order: -1; }
}

/* --- Babyphone --- */
#babyphone-toggle.on { background: var(--sun); color: #111; font-weight: 600; }
#babyphone-toggle.on .pulse { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: #111; -webkit-animation: pulse 1s infinite; animation: pulse 1s infinite; }
#babyphone-toggle.wait { background: var(--line); color: var(--sun); }
.babyphone-resume {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 35; padding: 18px; text-align: center;
  background: var(--sun); color: #111; font-size: 18px; font-weight: 600; cursor: pointer;
}

/* --- Energie: Dashboard-Kachel (animiert) --- */
.pv .sun { display: inline-block; -webkit-transition: color .6s, text-shadow .6s; transition: color .6s, text-shadow .6s; color: var(--muted); }
.pv .sun.producing { color: var(--sun); text-shadow: 0 0 14px rgba(245, 184, 46, .7); -webkit-animation: spin 24s linear infinite; animation: spin 24s linear infinite; }
@-webkit-keyframes spin { to { -webkit-transform: rotate(360deg); } }
@keyframes spin { to { transform: rotate(360deg); } }
.flow .v small { font-size: 12px; color: var(--muted); font-weight: 400; }
.flow .arrow { display: none; margin-right: 4px; font-size: 13px; }
.flow .arrow.in, .flow .arrow.out { display: inline-block; -webkit-animation: nudge 1.4s ease-in-out infinite; animation: nudge 1.4s ease-in-out infinite; }
.flow .arrow.in:before { content: '↓'; }
.flow .arrow.out:before { content: '↑'; }
.chev { display: inline-block; -webkit-animation: nudge 1.4s ease-in-out infinite; animation: nudge 1.4s ease-in-out infinite; }
@-webkit-keyframes nudge { 50% { -webkit-transform: translateY(-2px); opacity: .55; } }
@keyframes nudge { 50% { transform: translateY(-2px); opacity: .55; } }

/* --- Energie: Detailansicht --- */
.e-grid { display: flex; flex-wrap: wrap; margin: 0 -5px; }
.e-tile { padding: 0 5px 10px; }
.e-tile.w25 { width: 25%; } .e-tile.w16 { width: 16.6666%; } .e-tile.w33 { width: 33.3333%; } .e-tile.w50 { width: 50%; } .e-tile.w100 { width: 100%; }
/* Vier Kennzahlen als 2×2 neben dem Energiefluss */
.e-sub-grid { display: flex; flex-wrap: wrap; height: 100%; margin: 0 -5px -10px; }
.e-sub-grid .e-tile { padding-bottom: 10px; }
.e-sub-grid .e-big { font-size: 26px; margin: 0; }
.e-sub-grid .e-card { padding: 8px 10px; }
.e-legend { display: inline-block; float: right; }
.e-legend span { margin-left: 10px; font-size: 12px; }
.e-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.bvals { display: flex; justify-content: space-around; margin: 6px 0; font-size: 17px; }
.bstate-inline.in { color: var(--chg-in); } .bstate-inline.out { color: var(--chg-out); }
.e-card { height: 100%; padding: 10px 12px 12px; background: var(--panel); border-radius: 12px; overflow: hidden; }
.e-card.center { text-align: center; }
.e-title { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.e-card.center .e-title { text-align: left; }
.e-big { font-size: 34px; font-weight: 300; line-height: 1.15; margin: 4px 0; }
.e-big small { font-size: 16px; margin-left: 4px; color: var(--muted); }
.e-card.center .e-big { font-size: 34px; margin: 4px 0 2px; }
.e-sub { font-size: 12px; color: var(--muted); }
.e-phases { display: flex; justify-content: space-between; margin-top: 8px; }
.e-phases div { text-align: center; }
.e-phases b { display: block; font-size: 20px; font-weight: 400; }
.e-phases span { font-size: 12px; color: var(--muted); }
.spark { display: block; margin-top: 4px; }
.spark path { fill: none; stroke-width: 1.5; }
.echart { display: block; }
.echart .g { stroke: var(--line); stroke-width: 1; }
.echart .t, .gauge .t, .eflow .t { fill: var(--muted); font-size: 11px; }
.echart .t.v { fill: var(--text); }
.echart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; }
/* Aufbau-Animationen beim Öffnen */
.echart .ln.draw { stroke-dasharray: 3000; stroke-dashoffset: 3000; -webkit-animation: draw 1.4s ease-out forwards; animation: draw 1.4s ease-out forwards; }
.echart .area.draw { opacity: 0; -webkit-animation: fadein 1s .5s ease-out forwards; animation: fadein 1s .5s ease-out forwards; }
@-webkit-keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes draw { to { stroke-dashoffset: 0; } }
@-webkit-keyframes fadein { to { opacity: 1; } }
@keyframes fadein { to { opacity: 1; } }
.echart .bar.grow { -webkit-transform-origin: 50% 100%; transform-origin: 50% 100%; -webkit-transform-box: fill-box; transform-box: fill-box;
  -webkit-animation: grow .7s ease-out both; animation: grow .7s ease-out both; }
@-webkit-keyframes grow { from { -webkit-transform: scaleY(0); } to { -webkit-transform: scaleY(1); } }
@keyframes grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
/* Rundanzeigen */
.gauges { display: flex; align-items: center; justify-content: space-around; }
.e-tile.w50 .gauges .gauge { width: 44%; max-width: 170px; height: auto; }
/* Dashboard-Kachel: Energiefluss mit Akku-Tagesverlauf im Hintergrund */
.eflow-wrap { position: relative; }
.eflow.compact { max-height: 200px; }
/* Tagesverlauf als eigenes kleines Diagramm unter dem Energiefluss (nicht mehr im Hintergrund):
   Skalen im Rand neben der Zeichenfläche, damit nichts über den Linien liegt */
.soc-chart { position: relative; height: 92px; margin: 8px 0 2px; border-top: 1px solid var(--line); }
.soc-plot { position: absolute; left: 40px; right: 40px; top: 10px; bottom: 18px; }
.soc-plot svg { display: block; width: 100%; height: 100%; overflow: visible; }
.soc-plot .area { fill: #4cc38a; fill-opacity: .18; }
.soc-plot .line { fill: none; stroke: #4cc38a; stroke-width: 2; vector-effect: non-scaling-stroke; }
.soc-plot .grid { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.soc-plot .pline { fill: none; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.soc-plot .pline.pv { stroke: #f5b82e; }
.soc-plot .pline.house { stroke: #4f9cf9; stroke-opacity: .85; }
.soc-now { position: absolute; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; background: #4cc38a; }
.soc-y { position: absolute; left: -40px; width: 34px; white-space: nowrap; margin-top: -7px; text-align: right; font-size: 10px; line-height: 14px; color: var(--muted); }
.soc-y.right { left: auto; right: -40px; width: 36px; white-space: nowrap; text-align: left; }
.soc-x { position: absolute; bottom: -16px; margin-left: -10px; font-size: 10px; color: var(--muted); }
.e-legend-row { display: flex; flex-wrap: wrap; align-items: center; font-size: 11px; color: var(--muted); }
.e-legend-row b { color: #4cc38a; margin-right: 6px; }
.e-legend-row .soc-key:first-of-type { margin-left: 0; }
.soc-key { display: inline-block; width: 12px; height: 3px; margin: 0 4px 0 10px; border-radius: 2px; }
.soc-key.soc { background: #4cc38a; } .soc-key.pv { background: #f5b82e; } .soc-key.house { background: #4f9cf9; }
.e-foot { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: 4px; }
.e-foot .in { color: var(--chg-in); } .e-foot .out { color: var(--chg-out); }
.gauge .gtrack { fill: none; stroke: var(--panel-2); stroke-width: 12; stroke-linecap: round; }
.gauge .garc { fill: none; stroke-width: 12; stroke-linecap: round; -webkit-transition: stroke-dasharray .8s ease-out; transition: stroke-dasharray .8s ease-out; }
.gauge .gv { fill: var(--text); font-size: 19px; font-weight: 500; }
.bstate { font-size: 26px; font-weight: 300; color: var(--muted); }
.bstate.in { color: var(--chg-in); } .bstate.out { color: var(--chg-out); }
.btable { width: 100%; border-collapse: collapse; }
.btable th { font-size: 12px; color: var(--muted); font-weight: 400; text-align: left; padding: 4px 6px; }
.btable td { font-size: 20px; padding: 6px; background: var(--panel-2); border-right: 2px solid var(--panel); }
/* Energiefluss */
.flow-card { padding-bottom: 6px; }
.eflow { display: block; width: 100%; max-height: 200px; }
.eflow .ftrack { stroke: var(--panel-2); stroke-width: 6; stroke-linecap: round; }
.eflow .fline { fill: none; stroke-width: 5; stroke-linecap: round; stroke-dasharray: 3 11;
  -webkit-animation: flowdash 1.5s linear infinite; animation: flowdash 1.5s linear infinite; }
@-webkit-keyframes flowdash { to { stroke-dashoffset: -28; } }
@keyframes flowdash { to { stroke-dashoffset: -28; } }
.eflow .fnode { fill: var(--panel-2); stroke-width: 2.5; }
.eflow .fedge { font-size: 13px; font-weight: 600; paint-order: stroke; stroke: var(--panel); stroke-width: 3px; }
.eflow .farrow { -webkit-animation: fpulse 1.2s ease-in-out infinite; animation: fpulse 1.2s ease-in-out infinite; }
@-webkit-keyframes fpulse { 50% { opacity: .35; } }
@keyframes fpulse { 50% { opacity: .35; } }
.eflow .ficon { font-size: 24px; }
.eflow .fval { fill: var(--text); font-size: 17px; font-weight: 500; }
@media (orientation: portrait) {
  .e-tile.w25 { width: 50%; } .e-tile.w16 { width: 33.3333%; } .e-tile.w50, .e-tile.w33 { width: 100%; }
}

/* --- Detailansichten --- */
.detail { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 15; background: var(--bg); display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }
.detail-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; }
.detail-head h1 { margin: 0; font-size: 26px; font-weight: 300; }
.detail-body { flex: 1; min-height: 0; padding: 0 18px 24px; }
.stat-grid { display: flex; flex-wrap: wrap; margin: 0 -5px 8px; }
.stat { width: 25%; padding: 0 5px 10px; }
.stat-inner { padding: 10px 12px; background: var(--panel); border-radius: 10px; height: 100%; }
.stat .l { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 24px; font-weight: 300; margin-top: 2px; }
.stat .v small { font-size: 14px; color: var(--muted); margin-left: 3px; }
.stat .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.sm-grid { display: flex; flex-wrap: wrap; margin: 0 -5px; }
.sm { width: 50%; padding: 0 5px 10px; }
.sm-inner { padding: 10px 12px; background: var(--panel); border-radius: 10px; }
.sm-title { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.sm-title b { color: var(--text); font-weight: 500; }
.sm svg { display: block; }
.sm .area { fill: var(--muted); fill-opacity: .14; }
.sm .line { fill: none; stroke: var(--muted); stroke-width: 1.2; }
.sm .area.pv { fill: var(--sun); fill-opacity: .2; }
.sm .line.pv { stroke: var(--sun); }
.sm .grid { stroke: var(--line); stroke-width: .5; }
.sm .tick { fill: var(--muted); font-size: 9px; }
.sm rect.in { fill: var(--chg-in); }
.sm rect.out { fill: var(--chg-out); }
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 14px 0 8px; }
.days-table { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--panel); border-radius: 10px; overflow: hidden; }
.days-table th, .days-table td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.days-table th { color: var(--muted); font-weight: 500; font-size: 12px; }
.days-table th:first-child, .days-table td:first-child { text-align: left; }
.days-table tr:last-child td { border-bottom: 0; }
.bars { display: flex; align-items: flex-end; height: 110px; margin: 0 -3px 4px; }
.bar-col { flex: 1; margin: 0 3px; text-align: center; font-size: 11px; color: var(--muted); }
.bar-col .b { background: var(--sun); border-radius: 4px 4px 0 0; margin: 0 auto 4px; width: 70%; }
.bar-col .n { color: var(--text); font-size: 12px; }
.cal-cols { -webkit-column-count: 2; column-count: 2; -webkit-column-gap: 16px; column-gap: 16px; }
.cal-cols .day { -webkit-column-break-inside: avoid; break-inside: avoid; }
.cams.big .cam { width: 50%; }
.cams.big .cam-label { font-size: 16px; }
.all-shutters { display: flex; margin: 0 -5px 14px; }
.all-shutters .btn { flex: 1; margin: 0 5px; min-height: 52px; font-size: 16px; font-weight: 500; background: var(--panel); }
.detail-tools { display: flex; justify-content: space-between; align-items: center; margin: -4px 0 12px; font-size: 13px; }
/* Raumkarten: Breite nach Anzahl der Rollos (1 = ein Drittel, 2 = zwei Drittel, 3+ = ganze Breite) */
.room-grid { display: flex; flex-wrap: wrap; margin: 0 -6px; }
.room-card { padding: 0 6px 12px; }
.room-card.span-1 { width: 33.3333%; }
.room-card.span-2 { width: 66.6666%; }
.room-card.span-3 { width: 100%; }
.room-inner { height: 100%; background: var(--panel); border-radius: var(--radius); overflow: hidden; }
.room-head { display: flex; align-items: center; padding: 12px 14px 6px; }
.room-name { flex: 1; font-size: 19px; font-weight: 500; }
.room-state { font-size: 13px; color: var(--muted); margin-left: 8px; }
.room-head .move { min-width: 44px; min-height: 40px; margin: 0 6px 0 0; font-size: 15px; }
.room-head .move:last-child { margin: 0 0 0 8px; }
.room-head .move[disabled] { opacity: .25; }
.room-grid.reorder .room-inner { box-shadow: inset 0 0 0 2px var(--accent); }
.room-all { padding: 4px 14px 10px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }
.room-all .btn { color: var(--text); font-size: 15px; }
.room-shutters { display: flex; }
.shutter-row { flex: 1; min-width: 0; padding: 10px 14px 12px; }
.shutter-row + .shutter-row { border-left: 1px solid var(--line); }
.shutter-row.unreach { opacity: .5; }
.row-head { display: flex; justify-content: space-between; font-size: 15px; }
.row-head .muted { font-size: 13px; }
.shutter-row .lvl { height: 4px; margin: 6px 0 8px; border-radius: 2px; background: var(--panel-2); }
.shutter-row .lvl div { height: 100%; border-radius: 2px; background: var(--accent); }
.sbtns { display: flex; margin: 6px -3px 0; }
.sbtns .btn { flex: 1; min-width: 0; margin: 0 3px; padding: 10px 4px; }
.sbtns.presets .btn { font-size: 14px; }
.sbtns .btn.cur { background: var(--accent); color: #fff; }
.sbtns .btn.busy, .all-shutters .btn.busy { opacity: .5; }
.room-card.focus .room-name { color: var(--accent); }
@media (orientation: portrait) {
  .room-card.span-1 { width: 50%; }
  .room-card.span-2, .room-card.span-3 { width: 100%; }
}
/* Kalenderfarben */
.cal-colors { background: var(--panel); border-radius: var(--radius); padding: 4px 14px; }
.cal-color-row { display: flex; align-items: center; flex-wrap: wrap; padding: 10px 0; border-bottom: 1px solid var(--line); }
.cal-color-row:last-child { border-bottom: 0; }
.cal-color-name { width: 200px; font-size: 15px; }
.cal-color-name .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 8px; }
.swatches { display: flex; flex-wrap: wrap; align-items: center; }
.swatch { width: 40px; height: 40px; margin: 3px; border: 0; border-radius: 50%; cursor: pointer; }
.swatch.cur { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--text); }
.swatches .btn.small { margin-left: 8px; }
.totals { font-size: 13px; color: var(--muted); margin-top: 10px; }

/* --- Modal --- */
.modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, .85); z-index: 20; display: flex; align-items: center; justify-content: center; }
.modal-inner { width: 92%; max-width: 1100px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 20px; }
.modal-head .btn { margin-left: 8px; }
.modal-img-wrap { position: relative; min-height: 40vh; background: #000; border-radius: var(--radius); overflow: hidden; }
.modal-img-wrap img, .modal-img-wrap video { display: block; width: 100%; background: #000; }
/* Laden: letztes Standbild abgedunkelt im Hintergrund, Live erst einblenden, wenn es läuft */
.modal-img-wrap #modal-img, .modal-img-wrap video { position: relative; z-index: 1; -webkit-transition: opacity .5s; transition: opacity .5s; }
.modal-img-wrap .pending { opacity: 0; }
.modal-still { position: absolute; top: 0; left: 0; height: 100%; object-fit: cover; z-index: 0; opacity: 0;
  -webkit-filter: brightness(.45) blur(2px); filter: brightness(.45) blur(2px); -webkit-transition: opacity .5s; transition: opacity .5s; }
.modal-still.show { opacity: 1; }
.modal-still.plain { -webkit-filter: none; filter: none; }
.modal-loading.failed { justify-content: flex-end; padding-bottom: 14px; font-size: 14px; }
.modal-loading { position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 2; display: flex; flex-direction: column;
  align-items: center; justify-content: center; color: #fff; font-size: 16px; text-shadow: 0 1px 3px #000; }
.modal-loading .spinner { width: 54px; height: 54px; margin-bottom: 14px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, .25);
  border-top-color: var(--accent); -webkit-animation: spin 1s linear infinite; animation: spin 1s linear infinite; }
.modal-loading .loading-bar { position: relative; width: 50%; max-width: 280px; height: 4px; margin-top: 14px; border-radius: 2px;
  background: rgba(255, 255, 255, .2); overflow: hidden; }
.modal-loading .loading-bar i { position: absolute; top: 0; left: -40%; width: 40%; height: 100%; border-radius: 2px; background: var(--accent);
  -webkit-animation: slide 1.4s ease-in-out infinite; animation: slide 1.4s ease-in-out infinite; }
.modal-loading.failed .spinner, .modal-loading.failed .loading-bar { display: none; }
@-webkit-keyframes slide { 0% { left: -40%; } 100% { left: 100%; } }
@keyframes slide { 0% { left: -40%; } 100% { left: 100%; } }
#modal-info { margin-top: 8px; font-size: 13px; }

.dim { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: #000; opacity: .55; z-index: 25; }
.toast {
  position: fixed; left: 50%; bottom: 24px; width: 320px; margin-left: -160px;
  padding: 12px 16px; border-radius: 10px; background: var(--panel-2); text-align: center; z-index: 30;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
}
.topright { display: flex; align-items: center; }
.fresh { font-size: 12px; color: var(--muted); margin-right: 6px; white-space: nowrap; }
.fresh.stale { color: var(--sun); font-weight: 600; }
.topright .btn { margin-left: 14px; }

/* --- Anmeldung --- */
.login { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--bg); display: flex; align-items: center; justify-content: center; }
.login-box { width: 300px; text-align: center; }
.login-box h1 { font-weight: 200; font-size: 34px; margin: 0 0 24px; }
.login-box input {
  display: block; width: 100%; margin-bottom: 12px; padding: 12px 14px;
  font-size: 17px; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px; -webkit-appearance: none;
}
.btn.primary { width: 100%; padding: 12px; background: var(--accent); color: #fff; font-size: 17px; }
/* Zwei-Faktor */
.login-box { max-height: 100%; overflow-y: auto; }
#login-2fa { width: 360px; }
#login-2fa .btn { width: 100%; margin-top: 8px; }
.twofa-setup p { font-size: 14px; text-align: left; line-height: 1.4; }
.twofa-qr { background: #fff; border-radius: 12px; padding: 10px; width: 220px; height: 220px; margin: 8px auto; }
.twofa-qr svg { width: 200px; height: 200px; display: block; }
#twofa-secret { font-size: 13px; word-break: break-all; color: var(--text); }
#twofa-code { font-size: 26px; letter-spacing: 6px; text-align: center; }
/* Mein Konto */
.account-box { max-width: 420px; background: var(--panel); border-radius: var(--radius); padding: 16px; }
.account-box input { display: block; width: 100%; margin-bottom: 10px; padding: 11px 13px; font-size: 16px; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; -webkit-appearance: none; }
.account-box .btn + .btn { margin-left: 8px; }

.hidden { display: none !important; }

/* Sechs Kennzahlen in einer Reihe: etwas kleinere Zahlen */
.e-tile.w16 .e-card.center .e-big { font-size: 30px; }
.e-tile.w16 .e-sub { font-size: 11px; }

/* --- Steckdosen --- */
.plug { display: flex; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.plug:last-child { border-bottom: 0; }
.plug-text { flex: 1; min-width: 0; }
.plug-name { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plug-sub { font-size: 12px; color: var(--muted); }
.plug.offline .plug-name, .plug-card.offline .plug-name { color: var(--muted); }
.plug-switch { position: relative; width: 60px; height: 34px; margin: 5px 0 5px 10px; padding: 0; border: 0; border-radius: 17px;
  background: var(--line); -webkit-transition: background .2s; transition: background .2s; flex: none; }
.plug-switch .knob { position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%; background: #fff;
  -webkit-transition: -webkit-transform .2s; transition: transform .2s; }
.plug-switch.on { background: var(--green); }
.plug-switch.on .knob { -webkit-transform: translateX(26px); transform: translateX(26px); }
.plug-switch[disabled] { opacity: .35; }
.plug-switch.big { width: 72px; height: 40px; border-radius: 20px; }
.plug-switch.big .knob { width: 34px; height: 34px; }
.plug-switch.big.on .knob { -webkit-transform: translateX(32px); transform: translateX(32px); }
.plug-cards { display: flex; flex-wrap: wrap; margin: 0 -6px; }
.plug-card { width: 25%; padding: 0 6px 12px; }
.plug-card .plug-card-head { display: flex; align-items: flex-start; justify-content: space-between; }
.plug-card { box-sizing: border-box; }
.plug-card-head, .plug-big, .plug-card > .plug-sub { background: var(--panel); }
.plug-card-head { padding: 14px 14px 0; border-radius: var(--radius) var(--radius) 0 0; }
.plug-big { padding: 10px 14px 0; font-size: 30px; font-weight: 300; }
.plug-card > .plug-sub { padding: 2px 14px 14px; border-radius: 0 0 var(--radius) var(--radius); }
.plug-card.on .plug-big { color: var(--green); }
@media (orientation: portrait) { .plug-card { width: 50%; } }
@media (max-width: 600px) { .plug-card { width: 100%; } }

/* Schaltmodus der Steckdose */
.plug-mode { display: inline-block; margin-left: 4px; padding: 0 6px; border-radius: 8px; background: var(--panel-2); color: var(--muted); font-size: 11px; }
.plug-mode.sma { color: var(--sun); }

/* --- Handy: eine Spalte, Babyphone-Kamera zuerst --- */
@media (max-width: 600px) {
  html, body { overflow: auto; }
  .topbar { height: auto; min-height: 52px; padding: 6px 12px; padding-top: calc(6px + env(safe-area-inset-top)); flex-wrap: wrap; }
  .clock #time { font-size: 28px; }
  .clock .date { margin-left: 8px; font-size: 14px; }
  .status, .fresh { display: none; }
  .topright .btn { margin-left: 8px; }
  .grid, body.motion-mode .grid { display: -webkit-box; display: -webkit-flex; display: flex; -webkit-flex-direction: column; flex-direction: column;
    height: auto; padding: 0 8px 12px; }
  .grid > * { margin-bottom: 10px; }
  #panel-cameras { -webkit-order: -2; order: -2; }
  .grid > .stack { -webkit-order: -1; order: -1; }
  #col-left { -webkit-order: 0; order: 0; }
  #col-left > .panel { -webkit-flex: none; flex: none; max-height: none; }
  #panel-cameras .panel-body { padding-bottom: 4px; }
  #col-left > .panel + .panel { margin-top: 10px; }
  .stack > #panel-shutters .panel-body, .grid .scroll { overflow: visible; } /* nur Kacheln, Detailansichten scrollen weiter */
  body.motion-mode #panel-calendar, body.motion-mode .stack { opacity: 1; }
  /* Babyphone (lokale Kamera) zuerst und groß, weitere Kameras darunter */
  .cams .cam[data-id^="rtsp:"] { -webkit-order: -1; order: -1; width: 100%; }
  .cams .cam.motion-active { -webkit-order: -2; order: -2; }
  .panel h2 { padding: 10px 12px 6px; }
  .panel-body { padding: 0 12px 12px; }
  /* Detailansichten */
  .e-tile.w16, .e-tile.w25 { width: 50%; }
  .e-tile.w33, .e-tile.w50 { width: 100%; }
  .cams.big .cam { width: 100%; }
}

/* Push-Einstellungen im Konto */
#push-box .check-row { display: block; padding: 8px 0; font-size: 16px; }
#push-box .check-row input { width: 22px; height: 22px; vertical-align: middle; margin-right: 8px; }
#push-box .btn { margin: 8px 6px 0 0; }

/* Blink-Aufnahmen in der Kamera-Detailansicht */
.clips-title { margin-top: 18px; }
.clips { display: flex; flex-wrap: wrap; margin: 0 -5px; }
.clip { width: 25%; padding: 0 5px 12px; cursor: pointer; }
.clip-thumb { position: relative; padding-top: 56.25%; border-radius: 10px; overflow: hidden; background: var(--panel-2); }
.clip-thumb img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
.clip-play { position: absolute; top: 50%; left: 50%; margin: -18px 0 0 -14px; font-size: 30px; color: var(--muted); }
.clip-meta { margin-top: 5px; font-size: 13px; color: var(--muted); }
.clip-meta b { color: var(--text); font-weight: 500; }
@media (orientation: portrait) { .clip { width: 33.333%; } }
@media (max-width: 600px) { .clip { width: 50%; } }

/* Tooltips der Energie-Detailansicht (Kennzahlen und Diagramme) */
.chart-tip { position: fixed; z-index: 40; min-width: 180px; max-width: 300px; padding: 10px 12px; border-radius: 10px;
  background: rgba(17, 21, 27, .96); border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
  font-size: 13px; pointer-events: none; }
.chart-tip .tip-title { font-weight: 600; margin-bottom: 6px; }
.chart-tip table { width: 100%; border-collapse: collapse; }
.chart-tip td { padding: 2px 0; color: var(--muted); white-space: nowrap; }
.chart-tip td + td { padding-left: 14px; text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
.chart-tip i { display: inline-block; width: 9px; height: 9px; margin-right: 6px; border-radius: 2px; vertical-align: -1px; }
.chart { position: relative; }
.tip-mark { position: absolute; top: 0; bottom: 18px; pointer-events: none; }
.tip-mark.line { width: 1px; background: rgba(255, 255, 255, .45); }
.tip-mark.col { background: rgba(255, 255, 255, .07); border-radius: 4px; }
.e-card.has-tip { cursor: pointer; }
/* Auto-Ladung: Anteile PV / Akku / Netz */
.ev-share { margin: 8px 0 4px; }
.ev-share-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--line); }
.ev-share-bar span { display: block; height: 100%; }
.ev-share-bar span + span { border-left: 2px solid var(--panel); }
.ev-share-legend { margin-top: 5px; font-size: 12px; color: var(--muted); }
.ev-share-legend span { display: inline-block; margin-right: 12px; white-space: nowrap; }
.ev-share-legend b { color: var(--text); font-weight: 500; }
.ev-share-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
/* Ladeanzeige in Kacheln und Detailansichten */
.empty.loading { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 18px 0; color: var(--muted); }
.empty.loading .spinner { display: block; width: 26px; height: 26px; margin-bottom: 8px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .12);
  border-top-color: var(--accent); -webkit-animation: spin .9s linear infinite; animation: spin .9s linear infinite; }
.empty.loading span { -webkit-animation: loadpulse 1.6s ease-in-out infinite; animation: loadpulse 1.6s ease-in-out infinite; }
.empty.loading .loading-bar { position: relative; display: block; width: 120px; height: 3px; margin-top: 10px; border-radius: 2px;
  background: rgba(255, 255, 255, .08); overflow: hidden; }
.empty.loading .loading-bar i { position: absolute; top: 0; left: -40%; width: 40%; height: 100%; border-radius: 2px; background: var(--accent);
  -webkit-animation: slide 1.4s ease-in-out infinite; animation: slide 1.4s ease-in-out infinite; }
@-webkit-keyframes loadpulse { 50% { opacity: .45; } }
@keyframes loadpulse { 50% { opacity: .45; } }
.echart .hdot { stroke: var(--panel); stroke-width: 1.5; }
.cam.collapsed { cursor: default; }
