/* Farben liegen auf den Daten, nicht auf dem Rahmen: PV (Bernstein), Batterie (Grün), Netz (Blau); alles andere neutral.
   Flächen sind flach (Rand statt Schatten), neutrale Dunkelstufen statt Marineblau. */
/* Standard ist dunkel (wie vor der Überarbeitung); hell folgt der Systemeinstellung oder der Wahl im Kopf (data-theme). */
:root {
  --ground: #0d0d0e;
  --surface: #151516;
  --raised: #1d1d1f;
  --border: #28292c;
  --control: #44464b;
  --text: #f4f4f5;
  --muted: #a9acb3;
  --pv: #f2b632;
  --bat: #45c28a;
  --grid: #5b9bf0;
  --home: #c9ccd2;
  --price: #f06595;
  --idle: #6b6e75;
  --negative: #e5566f;
  --positive: #3fc07a;
  --accent: #f4f4f5;
  --on-accent: #111317;
  --radius: 8px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --ground: #f6f7f8; --surface: #ffffff; --raised: #f3f4f6; --border: #e5e7eb; --control: #d1d5db;
    --text: #111317; --muted: #5f6672; --pv: #d99a06; --bat: #2f8f5f; --grid: #3b78d8; --home: #3d434d; --price: #c2255c;
    --idle: #9aa1ab; --negative: #c4242a; --positive: #247b50; --accent: #1d1f20; --on-accent: #ffffff;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --ground: #f6f7f8; --surface: #ffffff; --raised: #f3f4f6; --border: #e5e7eb; --control: #d1d5db;
  --text: #111317; --muted: #5f6672; --pv: #d99a06; --bat: #2f8f5f; --grid: #3b78d8; --home: #3d434d; --price: #c2255c;
  --idle: #9aa1ab; --negative: #c4242a; --positive: #247b50; --accent: #1d1f20; --on-accent: #ffffff;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  min-height: 100vh;
}
.num, svg text, time, td, th { font-variant-numeric: tabular-nums; }
h1, h2, h3, p { margin: 0; }

/* ---------- Kopf ---------- */
.top {
  display: flex; align-items: center; gap: 16px;
  max-width: 1280px; margin: 0 auto; padding: 16px 24px;
}
.brand { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.mark {
  width: 28px; height: 28px; flex: none; fill: none; stroke: var(--pv);
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.top h1 { font-size: 1.25rem; font-weight: 600; line-height: 1.2; white-space: nowrap; }
.scope { font-size: .8125rem; color: var(--muted); }
.fresh { display: flex; align-items: center; gap: 8px; font-size: .8125rem; color: var(--muted); text-align: right; }
.status::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--idle); margin-right: 6px; vertical-align: 0;
}
.status.ok { color: var(--text); }
.status.ok::before { background: var(--positive); }
.status.bad { color: var(--negative); }
.status.bad::before { background: var(--negative); }

/* ---------- Bedienelemente ---------- */
button {
  font: inherit; color: inherit; cursor: pointer;
  border: 1px solid var(--control); background: var(--surface);
  border-radius: 6px; padding: 0 14px; min-height: 36px;
}
button:hover:not(:disabled) { background: var(--raised); }
button:active:not(:disabled) { background: var(--border); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover:not(:disabled) { color: var(--text); }
.top .actions { display: flex; align-items: center; gap: 4px; }
select {
  font: inherit; font-size: .875rem; color: var(--text); background: var(--surface);
  border: 1px solid var(--control); border-radius: 6px; padding: 0 8px; min-height: 36px; cursor: pointer;
}
select:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
button:disabled { opacity: .35; cursor: default; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.link { border: 0; background: none; padding: 0; min-height: 0; text-decoration: underline; color: inherit; }

/* ---------- Aufbau ---------- */
.layout {
  display: grid; gap: 16px; padding: 0 24px 32px;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  max-width: 1280px; margin: 0 auto; align-items: start;
}
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.card h2, .card h3 { font-size: 1rem; font-weight: 600; }
.finding { margin-top: 4px; font-size: 1.0625rem; line-height: 1.35; min-height: 1.4em; }
.hint { margin-top: 8px; margin-bottom: 4px; font-size: .8125rem; color: var(--muted); min-height: 1.2em; }
.svgwrap { display: flex; justify-content: center; margin-top: 8px; }
.svgwrap svg { width: 100%; height: auto; max-width: 460px; display: block; }
.error-box {
  margin: 8px 0 0; padding: 10px 12px; border: 1px dashed var(--control); border-radius: 6px;
  font-size: .875rem; color: var(--muted);
}
.error-box button { display: block; margin-top: 4px; min-height: 0; border: 0; background: none; padding: 0; text-decoration: underline; color: var(--text); }

/* ---------- Tage ---------- */
.days-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; min-height: 44px; }
.days-head h2 { font-size: 1rem; font-weight: 600; }
.daynav { display: flex; align-items: center; gap: 8px; }
.daynav .nav { width: 44px; height: 44px; padding: 0; font-size: 1.4rem; line-height: 1; }
.daynav .nav.today { width: auto; padding: 0 12px; font-size: .875rem; }
.daynav .date { text-align: center; min-width: 9.5em; font-weight: 600; line-height: 1.25; }
.daynav .date.pickable { position: relative; }
.daynav .date-btn {
  display: block; width: 100%; min-height: 44px; margin: 0; padding: 2px 8px; font: inherit; line-height: inherit; text-align: center;
  color: inherit; background: transparent; border-color: transparent;
}
.daynav .date.pickable:hover .date-btn { background: var(--raised); }
.daynav .date-pick { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.picker {
  position: absolute; z-index: 30; top: calc(100% + 6px); left: 50%; transform: translateX(-50%); width: min(17rem, 88vw);
  padding: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  font-weight: 400;
}
.picker .pk-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.picker .pk-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; max-height: 15rem; overflow-y: auto; }
.picker .pk { min-height: 40px; padding: 0 6px; font-size: .9375rem; font-variant-numeric: tabular-nums; }
.picker .pk[aria-pressed="true"] { background: var(--raised); border-color: var(--text); font-weight: 600; }
.picker .pk:disabled { opacity: .35; }
.daynav .date small { display: block; font-weight: 400; color: var(--muted); font-size: .75rem; min-height: 1em; }
.days-cards { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }

.days-cards .wide { grid-column: 1 / -1; }
.note { margin-top: 10px; font-size: .8125rem; color: var(--muted); }
.fig { margin-top: 8px; display: flex; align-items: baseline; gap: 6px; }
.fig .big { font-size: 2rem; font-weight: 600; line-height: 1.1; letter-spacing: -.01em; }
.fig .unit { color: var(--muted); font-size: 1rem; }
.fig .big.none { color: var(--muted); }
.sub { margin-top: 2px; font-size: .875rem; color: var(--muted); min-height: 1.3em; }
.sub strong { color: var(--text); font-weight: 600; }

/* Verhältnisbalken: Anteile im echten Verhältnis, ohne Legende daneben (die Tabelle ist die Legende) */
.bar { display: flex; gap: 2px; height: 10px; margin: 16px 0 12px; background: var(--raised); border-radius: 2px; overflow: hidden; }
.bar span { display: block; min-width: 0; }
.s-pv { background: var(--pv); } .s-bat { background: var(--bat); }
.s-grid { background: var(--grid); } .s-home { background: var(--home); } .s-fix { background: var(--idle); }

table.rows { width: 100%; border-collapse: collapse; font-size: .875rem; }
.rows th { font-weight: 400; font-size: .75rem; color: var(--muted); text-align: right; padding: 0 0 6px; }
.rows th:first-child { text-align: left; }
.rows td { padding: 8px 0; border-top: 1px solid var(--border); text-align: right; }
.rows td:first-child { text-align: left; }
.rows .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 8px; vertical-align: -1px; }
.rows td.dash { color: var(--muted); }
.rows th:not(:first-child), .rows td:not(:first-child) { padding-left: 12px; white-space: nowrap; }

/* Laden: Platzhalter in Größe der Werte, ohne Schimmer */
.skel { display: block; background: var(--raised); border-radius: 4px; animation: skel-pulse 1.1s ease-in-out infinite; }
@keyframes skel-pulse { 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } }
.skel.fig-s { width: 7.5rem; height: 2rem; margin-top: 8px; }
.skel.line-s { width: 11rem; height: .9rem; margin-top: 8px; }
.skel.bar-s { height: 10px; margin: 16px 0 12px; }
.skel.row-s { height: 2.5rem; margin-top: 2px; }

/* ---------- SVG ---------- */
svg text { fill: var(--text); font-family: inherit; text-anchor: middle; }
svg .node { fill: var(--raised); stroke: var(--control); stroke-width: 1.5; }
svg .rim-pv { stroke: var(--pv); stroke-width: 2; } svg .rim-bat { stroke: var(--bat); stroke-width: 2; }
svg .rim-grid { stroke: var(--grid); stroke-width: 2; } svg .rim-home { stroke: var(--home); stroke-width: 2; }
svg .ico { fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
svg .t-main { font-size: 17px; font-weight: 600; }
svg .t-label { font-size: 13px; fill: var(--muted); }
svg .t-label.long { font-size: 11.5px; }
svg .line { fill: none; stroke-linecap: round; }
svg .c-pv { stroke: var(--pv); } svg .c-bat { stroke: var(--bat); } svg .c-grid { stroke: var(--grid); }
svg .c-home { stroke: var(--home); } svg .c-idle { stroke: var(--control); }
svg .f-pv { fill: var(--pv); } svg .f-bat { fill: var(--bat); } svg .f-grid { fill: var(--grid); } svg .f-home { fill: var(--home); }
.stale svg { opacity: .45; }
.stale svg .line.flow { animation: none; }

/* Fließende Striche in Flussrichtung (Linie läuft von der Quelle zum Ziel) */
svg .line.flow { stroke-dasharray: 7 7; }
@media (prefers-reduced-motion: no-preference) {
  svg .line.flow { animation: flow 0.9s linear infinite; }
}
@keyframes flow { to { stroke-dashoffset: -14; } }

/* ---------- Tagesverlauf ---------- */
.chart-card { grid-column: 1 / -1; }
.chart-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chart-head h2 { flex: 1; min-width: 0; }
.chart-head button { min-height: 36px; }
.close { display: none; width: 44px; height: 44px; padding: 0; }
.close svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.chart-date { margin-left: 8px; font-size: .875rem; font-weight: 400; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 12px; font-size: .875rem; }
.chip[aria-pressed="true"] { background: var(--raised); border-color: var(--text); font-weight: 600; }
.chip[aria-pressed="false"] { color: var(--muted); border-style: dashed; background: transparent; }
.chip[aria-pressed="false"] .swatch { opacity: .3; }
/* Ausgeblendete Datenreihe im Verlauf: durchgestrichen */
#chart-legend .chip[aria-pressed="false"] { text-decoration: line-through; }
.ser-direktverbrauch { --c: var(--pv); }
.ser-batterieentladung, .ser-batterieladung { --c: var(--bat); }
.ser-netzbezug, .ser-netzeinspeisung { --c: var(--grid); }
.ser-pv_dc { --c: #e8590c; }
.ser-haus { --c: var(--text); }
.ser-zaehler_bezug { --c: #8b5cf6; }
.ser-soc { --c: var(--muted); }
.ser-preis_total, .ser-preis_energy { --c: var(--price); }
.swatch { display: inline-block; flex: none; width: 12px; height: 12px; border-radius: 2px; background: var(--c); }
.swatch.tint { opacity: .45; }
.swatch.line { width: 16px; height: 0; background: none; border-top: 2px solid var(--c); border-radius: 0; }
.swatch.dash { border-top-style: dashed; }
.chartwrap { position: relative; margin-top: 12px; }
#chart { min-height: 240px; }
.chartwrap svg { display: block; touch-action: pan-y; }
svg .grid { stroke: var(--border); stroke-width: 1; }
svg .ax { font-size: 12px; fill: var(--muted); }
svg .area { fill: var(--c); }
svg .area.tint { fill-opacity: .4; }
svg .ln { fill: none; stroke: var(--c); stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; }
svg .ln.dash { stroke-dasharray: 5 4; }
svg .avg { stroke: var(--price); stroke-width: 1.25; stroke-dasharray: 2 4; opacity: .9; }
svg .avg-t { fill: var(--price); font-weight: 600; }
svg .cross { stroke: var(--muted); stroke-width: 1; }
.skel.chart-s { height: 240px; width: 100%; }
.tip {
  position: absolute; z-index: 2; pointer-events: none; font-size: .8125rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .18);
}
.tip[hidden] { display: none; }
.tip-time { font-weight: 600; margin-bottom: 4px; }
.tip table { border-collapse: collapse; }
.tip td { padding: 1px 0; }
.tip td:first-child { padding-right: 16px; white-space: nowrap; }
.tip td:first-child .swatch { margin-right: 8px; vertical-align: -1px; }
.tip .num { text-align: right; }
.tip .swatch.line { vertical-align: middle; }

/* Vollbild: die Karte füllt das Fenster, das Diagramm bekommt die Resthöhe (chart.js), oben rechts schließt das Kreuz */
html.noscroll { overflow: hidden; }
.chart-card.full {
  position: fixed; inset: 0; z-index: 20; border: 0; border-radius: 0; overflow: auto;
  padding: calc(8px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 8px calc(16px + env(safe-area-inset-left));
}
.chart-card #chart-full { display: inline-flex; align-items: center; justify-content: center; }
.chart-card.full #chart-full { display: none; }
.chart-card.full .close { display: inline-flex; align-items: center; justify-content: center; }
.chart-card.full .legend { margin-top: 4px; gap: 6px; }
.chart-card.full .chip { min-height: 32px; padding: 0 8px; gap: 6px; font-size: .8125rem; }
.chart-card.full .chartwrap { margin-top: 4px; }
.chart-card.full #chart { min-height: 160px; }
.chart-card.full svg { touch-action: none; }

/* ---------- Einstellungen ---------- */
.subnav {
  display: flex; gap: 4px; max-width: 1280px; margin: 0 auto 12px; padding: 0 24px; overflow-x: auto;
}
.subnav a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border-radius: 6px;
  color: var(--muted); text-decoration: none; font-size: .9375rem; white-space: nowrap;
}
.subnav a:hover { color: var(--text); background: var(--raised); }
.subnav a[aria-current="page"] { color: var(--text); background: var(--raised); font-weight: 600; }
.subnav a:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.page-title { font-size: 1.125rem; font-weight: 600; margin: 4px 0 12px; }
.settings { max-width: 720px; margin: 0 auto; padding: 0 24px 96px; }
.set-card { margin-bottom: 16px; }
.field { margin-top: 18px; }
.field label { display: block; font-weight: 600; font-size: .9375rem; }
.field .inp { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.field input {
  font: inherit; color: var(--text); background: var(--ground); border: 1px solid var(--control);
  border-radius: 6px; padding: 0 12px; min-height: 44px; width: 100%; max-width: 16rem;
}
.field input:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.dir { color: var(--text); font-size: .9375rem; font-weight: 600; white-space: nowrap; }
.unit-s { color: var(--muted); font-size: .9375rem; white-space: nowrap; }
.field .hint { margin-top: 6px; }
.field-error { margin-top: 4px; font-size: .875rem; color: var(--negative); min-height: 0; }
.savebar {
  position: sticky; bottom: 0; display: flex; align-items: center; gap: 12px; padding: 12px 0;
  background: var(--ground);
}
button.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; font-weight: 600; min-height: 44px; padding: 0 20px; }
button.primary:hover:not(:disabled) { background: var(--accent); opacity: .88; }
.muted { color: var(--muted); font-size: .875rem; }
.muted.bad { color: var(--negative); }
@media (max-width: 640px) { .settings { padding: 0 16px 96px; } .subnav { padding: 0 12px; } }
.field select {
  font: inherit; color: var(--text); background: var(--ground); border: 1px solid var(--control);
  border-radius: 6px; padding: 0 12px; min-height: 44px; width: 100%; max-width: 16rem;
}

/* ---------- Amortisationsrechner ---------- */
.amort { max-width: 1000px; margin: 0 auto; padding: 0 24px 48px; }
.amort .card { margin-bottom: 16px; }
.status-line { color: var(--muted); font-size: .9375rem; min-height: 1.4em; margin-bottom: 8px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-top: 12px; }
.kpi-l { font-size: .8125rem; color: var(--muted); }
.kpi-v { font-size: 1.5rem; font-weight: 600; line-height: 1.2; margin-top: 2px; }
.kpi-s { font-size: .8125rem; color: var(--muted); margin-top: 2px; min-height: 1.2em; }
.calc-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 24px; }
.calc-grid .field { margin-top: 12px; }
.why { margin-top: 8px; padding: 10px 12px; border: 1px dashed var(--control); border-radius: 6px; font-size: .9375rem; }
.field input.missing { border-color: var(--negative); }
.note-c { color: var(--muted); font-size: .8125rem; white-space: nowrap; }
.legend-static { align-items: center; }
.chip.static { cursor: default; background: var(--raised); }
svg .dot { fill: var(--text); }
@media (max-width: 760px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .calc-grid { grid-template-columns: minmax(0, 1fr); } .amort { padding: 0 16px 48px; } }

/* ---------- Anmeldung ---------- */
body.login { display: grid; place-items: center; padding: 16px; }
.login-card { width: min(100%, 360px); display: grid; gap: 14px; justify-items: stretch; padding: 24px; }
.login-card img { justify-self: center; border-radius: 16px; }
.login-card h1 { text-align: center; font-size: 1.3rem; }
.login-card label { display: grid; gap: 6px; font-size: .9rem; color: var(--muted); }
.login-card input {
  font: inherit; color: var(--text); background: var(--ground);
  border: 1px solid var(--control); border-radius: 6px; padding: 12px; min-height: 44px;
}
.login-card button { background: var(--accent); border-color: transparent; color: var(--on-accent); min-height: 44px; font-weight: 600; }
.login-card button:hover:not(:disabled) { background: var(--accent); opacity: .88; }
.error { padding: 10px 12px; border-radius: 6px; background: rgba(196, 36, 42, .12); color: var(--negative); font-size: .9rem; }
.login-card .step { display: grid; gap: 14px; }
.login-card .step[hidden] { display: none; }
.login-card .lead { font-size: .9rem; color: var(--muted); line-height: 1.45; }
.login-card .small { font-size: .8125rem; color: var(--muted); }
.login-card a { color: var(--text); }
.login-card .check { display: flex; align-items: center; gap: 8px; }
.login-card .check input { min-height: 0; width: 18px; height: 18px; padding: 0; }

/* ---------- Konto und Benutzerverwaltung ---------- */
.qr { display: block; margin: 8px auto; padding: 8px; background: #fff; border-radius: 8px; width: 200px; height: 200px; }
.secret { display: inline-block; max-width: 100%; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--raised); font-size: .9375rem; letter-spacing: .04em; overflow-wrap: anywhere; user-select: all; }
.secret.big { font-size: 1.25rem; padding: 10px 14px; }
.codes { margin: 8px 0; padding: 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--raised); font-size: 1rem; line-height: 1.7; letter-spacing: .05em; user-select: all; white-space: pre-wrap; }
.lead { font-size: .9375rem; line-height: 1.45; }
.account .savebar { position: static; flex-wrap: wrap; padding: 12px 0 4px; background: none; }
.account .set-card p { margin-top: 8px; }
.account .field select { width: 100%; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: .9375rem; }
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--muted); }
.msg { margin: 0 0 12px; padding: 10px 12px; border-radius: 6px; background: rgba(63, 192, 122, .14); color: var(--text); font-size: .9rem; }
.msg.bad { background: rgba(196, 36, 42, .14); color: var(--negative); }
.secret-box { border-color: var(--pv); }
button.danger { color: var(--negative); border-color: var(--negative); }
.users { display: grid; gap: 12px; }
.user.off { opacity: .7; }
.user-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.user-name { overflow-wrap: anywhere; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge { padding: 2px 8px; border: 1px solid var(--border); border-radius: 999px; font-size: .75rem; color: var(--muted); }
.badge.ok { color: var(--positive); border-color: var(--positive); }
.badge.warn { color: var(--pv); border-color: var(--pv); }
.badge.bad { color: var(--negative); border-color: var(--negative); }
.badge.self { color: var(--text); border-color: var(--control); }
.user-role { margin-top: 8px; font-size: .875rem; color: var(--muted); }
.user-role select { margin-left: 6px; font: inherit; color: var(--text); background: var(--ground); border: 1px solid var(--control); border-radius: 6px; padding: 6px 8px; min-height: 36px; }
.user-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.tablewrap { overflow-x: auto; margin-top: 12px; }
#log-table td, #log-table th { padding: 6px 8px; text-align: left; white-space: nowrap; }
#log-table tr.fail td { color: var(--negative); }
details > summary { cursor: pointer; font-weight: 600; }

/* ---------- Tablet und Smartphone ---------- */
@media (max-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .top { padding: 12px 16px 8px; gap: 4px 8px; flex-wrap: wrap; }
  .top h1 { font-size: 1.125rem; }
  .brand { flex: 0 0 100%; }
  .fresh { flex: 1 1 0; text-align: left; padding-left: 40px; flex-wrap: wrap; gap: 0 8px; }
  .actions select, button.ghost { min-height: 44px; }
  .layout { padding: 0 16px 24px; }
  .card { padding: 16px; }
  .days-head { flex-direction: column; align-items: stretch; }
  .daynav { justify-content: space-between; }
  .daynav .date { flex: 1; }
  .days-cards { grid-template-columns: minmax(0, 1fr); }
  .chip { min-height: 44px; }
  button.ghost { min-height: 44px; }
}
@media (prefers-reduced-motion: no-preference) {
  button { transition: background-color .12s; }
}

/* ---------- Zeitraum (Tag, Monat, Jahr, Gesamt) ---------- */
[hidden] { display: none !important; }
.days-head { flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; min-height: 36px; padding: 0 14px; background: transparent; color: var(--muted); font-size: .875rem; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--raised); color: var(--text); font-weight: 600; }
.seg button:focus-visible { outline: 2px solid var(--text); outline-offset: -2px; }
.period-card { grid-column: 1 / -1; }
.period-card .legend { margin-top: 8px; }
.bars svg { width: 100%; height: auto; }
.bars .col.s-pv { fill: var(--pv); } .bars .col.s-bat { fill: var(--bat); }
.bars .col.s-grid { fill: var(--grid); } .bars .col.s-home { fill: var(--home); }
.bars .tick { font-size: 11px; fill: var(--muted); }
.bars .hit { fill: transparent; cursor: pointer; }
.bars .hit:hover { fill: var(--raised); opacity: .5; }
.readout { margin-top: 8px; min-height: 2.6em; font-size: .875rem; color: var(--muted); }
.readout strong { color: var(--text); }
@media (max-width: 640px) {
  .seg { width: 100%; }
  .seg button { flex: 1; min-height: 44px; padding: 0 4px; }
}

/* ---------- Batteriezustand ---------- */
#battery-card { grid-column: 1 / -1; }
.tiles { display: grid; gap: 12px; margin-top: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.tile { display: flex; flex-direction: column; gap: 2px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--raised); }
.tile .tl { font-size: .8125rem; color: var(--muted); }
.tile .tv { font-size: 1.5rem; font-weight: 600; line-height: 1.2; }
.tile .unit { font-size: .875rem; font-weight: 400; color: var(--muted); }
.tile .ts { font-size: .75rem; color: var(--muted); }

/* ---------- Vergleich mit Tibber (vorübergehend) ---------- */
.tablewrap { overflow-x: auto; }
.rows tr.sum td { border-top: 1px solid var(--control); font-weight: 600; }
.rows td small { color: var(--muted); font-weight: 400; }
.bars .swatch.s-pv { background: var(--pv); } .bars .swatch.s-grid { background: var(--grid); }
.legend-static .swatch.s-pv { background: var(--pv); } .legend-static .swatch.s-grid { background: var(--grid); }
