/* ==========================================================================
   mbsmart – Design-Tokens & Basis-Komponenten
   Grundlage für die PWA. Keine externen Fonts/CDNs (läuft offline im LAN).
   ========================================================================== */

/* ---------- Tokens: Dunkel (Standard) ---------- */
:root {
  color-scheme: dark;

  /* Flächen */
  --bg: #090d12;
  --bg-glow: radial-gradient(1200px 600px at 10% -10%, #12301f55, transparent 60%),
             radial-gradient(900px 500px at 110% 10%, #1b2a4a55, transparent 60%);
  --surface: #11171f;
  --surface-2: #171f2a;
  --surface-3: #1f2935;
  --border: #243040;
  --border-strong: #33435a;

  /* Text */
  --text: #e9eef5;
  --text-2: #a7b3c3;
  --text-3: #6f7d90;
  --on-accent: #04130c;

  /* Marke / Aktion */
  --accent: #34e0a1;          /* Laden, Auto, primäre Aktion */
  --accent-strong: #1fc489;
  --accent-soft: #34e0a11f;

  /* Energie-Farben (immer gleiche Bedeutung) */
  --pv: #ffbd3f;              /* Sonne / PV */
  --pv-soft: #ffbd3f1f;
  --grid: #ff6b5e;            /* Netzbezug */
  --grid-soft: #ff6b5e1f;
  --feedin: #8fd16a;          /* Einspeisung */
  --battery: #8b93ff;         /* Hausspeicher */
  --battery-soft: #8b93ff1f;
  --home: #9fb0c4;            /* Hausverbrauch */
  --car: var(--accent);

  /* Status */
  --ok: #34e0a1;
  --warn: #ffbd3f;
  --danger: #ff5c5c;
  --danger-soft: #ff5c5c1c;
  --info: #5fb3ff;

  /* Typo */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI",
          Roboto, system-ui, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter",
          "Segoe UI", Roboto, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;

  --fs-xs: 12px;
  --fs-sm: 14px;
  --fs-md: 16px;
  --fs-lg: 20px;
  --fs-xl: 28px;
  --fs-2xl: 40px;
  --fs-3xl: 56px;

  /* Raster: 4 px */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px;

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-pill: 999px;

  --shadow: 0 1px 0 #ffffff08 inset, 0 10px 30px -12px #000a;
  --ring: 0 0 0 3px var(--accent-soft), 0 0 0 1px var(--accent);

  --ease: cubic-bezier(.2, .8, .2, 1);
  --dur: 180ms;
}

/* ---------- Tokens: Hell ---------- */
[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5f8;
  --bg-glow: radial-gradient(1200px 600px at 10% -10%, #c9f5e255, transparent 60%),
             radial-gradient(900px 500px at 110% 10%, #d7e3ff66, transparent 60%);
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --surface-3: #eceff4;
  --border: #e1e6ed;
  --border-strong: #cbd3de;
  --text: #0e1621;
  --text-2: #4a5768;
  --text-3: #7c8899;
  --accent: #0fb57b;
  --accent-strong: #0a9a68;
  --accent-soft: #0fb57b1f;
  --on-accent: #ffffff;
  --pv: #e59a00;
  --pv-soft: #e59a001f;
  --grid: #e5483b;
  --grid-soft: #e5483b1a;
  --feedin: #4f9e2a;
  --battery: #5b63e6;
  --battery-soft: #5b63e61a;
  --home: #64748b;
  --ok: #0fb57b;
  --warn: #d98a00;
  --danger: #dc3b3b;
  --danger-soft: #dc3b3b14;
  --shadow: 0 1px 2px #0e16210d, 0 8px 24px -12px #0e162126;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f3f5f8;
    --bg-glow: radial-gradient(1200px 600px at 10% -10%, #c9f5e255, transparent 60%),
               radial-gradient(900px 500px at 110% 10%, #d7e3ff66, transparent 60%);
    --surface: #ffffff; --surface-2: #f6f8fb; --surface-3: #eceff4;
    --border: #e1e6ed; --border-strong: #cbd3de;
    --text: #0e1621; --text-2: #4a5768; --text-3: #7c8899;
    --accent: #0fb57b; --accent-strong: #0a9a68; --accent-soft: #0fb57b1f; --on-accent: #fff;
    --pv: #e59a00; --pv-soft: #e59a001f; --grid: #e5483b; --grid-soft: #e5483b1a;
    --feedin: #4f9e2a; --battery: #5b63e6; --battery-soft: #5b63e61a; --home: #64748b;
    --ok: #0fb57b; --warn: #d98a00; --danger: #dc3b3b; --danger-soft: #dc3b3b14;
    --shadow: 0 1px 2px #0e16210d, 0 8px 24px -12px #0e162126;
  }
}

/* ---------- Basis ---------- */
/* Icons aus dem Sprite: Linienstil wird vom <svg> an <use> vererbt */
svg:has(> use) { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.45;
  color: var(--text);
  background: var(--bg-glow), var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; letter-spacing: -0.02em; }
h1 { font-size: var(--fs-xl); font-weight: 700; }
h2 { font-size: var(--fs-lg); font-weight: 650; }
h3 { font-size: var(--fs-md); font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.eyebrow {
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-3);
}
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-sm); }

/* Großer Messwert: Zahl + Einheit */
.metric { display: flex; align-items: baseline; gap: 4px; font-variant-numeric: tabular-nums; }
.metric b { font-family: var(--font-display); font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -0.03em; line-height: 1; }
.metric span { font-size: var(--fs-md); color: var(--text-2); font-weight: 500; }
.metric.sm b { font-size: var(--fs-xl); }
.metric.xl b { font-size: var(--fs-3xl); }

/* ---------- Karten ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); margin-bottom: var(--s-3); }
.card.glass { background: color-mix(in srgb, var(--surface) 82%, transparent); backdrop-filter: blur(18px); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 44px; padding: 0 var(--s-5);
  font: 600 var(--fs-md)/1 var(--font);
  border-radius: var(--r-md); border: 1px solid transparent;
  background: var(--surface-3); color: var(--text);
  cursor: pointer; transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--accent); color: var(--on-accent); box-shadow: 0 8px 24px -10px var(--accent); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-secondary { background: var(--surface-2); border-color: var(--border-strong); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { min-height: 34px; padding: 0 var(--s-3); font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn[disabled] { opacity: .45; pointer-events: none; }

/* ---------- Moduswahl (Segmented Control) ---------- */
.modes { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; padding: 6px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-lg); }
.mode {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: var(--s-3) var(--s-1); border-radius: var(--r-md); border: 0;
  background: transparent; color: var(--text-2); font: 600 var(--fs-xs)/1.1 var(--font);
  cursor: pointer; transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.mode svg { width: 22px; height: 22px; }
.mode[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.mode[aria-pressed="true"][data-mode="now"] svg, .mode[aria-pressed="true"][data-mode="auto"] svg { color: var(--accent); }
.mode[aria-pressed="true"][data-mode="pv"] svg,
.mode[aria-pressed="true"][data-mode="minpv"] svg { color: var(--pv); }
.mode[aria-pressed="true"][data-mode="off"] svg { color: var(--text-3); }

/* ---------- Status-Pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px; border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 600; white-space: nowrap;
  background: var(--surface-3); color: var(--text-2);
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.charging { background: var(--accent-soft); color: var(--accent); }
.pill.charging::before { animation: pulse 1.6s var(--ease) infinite; }
.pill.connected { background: #5fb3ff1f; color: var(--info); }
.pill.pv { background: var(--pv-soft); color: var(--pv); }
.pill.error { background: var(--danger-soft); color: var(--danger); }
.pill.plain::before { display: none; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 currentColor; } 50% { box-shadow: 0 0 0 5px transparent; } }

/* ---------- Formulare ---------- */
.field { display: grid; gap: 6px; }
.field label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
.input {
  width: 100%; min-height: 48px; padding: 0 var(--s-4);
  font: 500 var(--fs-md) var(--font); color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.input-group { position: relative; }
.input-group .suffix { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--text-3); font-size: var(--fs-sm); pointer-events: none; }
.hint { font-size: var(--fs-xs); color: var(--text-3); }

.otp { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.otp .input { text-align: center; padding: 0; font: 700 var(--fs-lg) var(--mono); }

/* Toggle */
.toggle { position: relative; width: 50px; height: 30px; flex: none; }
.toggle input { appearance: none; margin: 0; width: 100%; height: 100%; border-radius: var(--r-pill);
  background: var(--surface-3); border: 1px solid var(--border-strong); cursor: pointer; transition: background var(--dur) var(--ease); }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px #0004; transition: transform var(--dur) var(--ease); }
.toggle input:checked { background: var(--accent); border-color: var(--accent); }
.toggle input:checked::after { transform: translateX(20px); }

/* Slider (SoC) */
.range { -webkit-appearance: none; appearance: none; width: 100%; height: 8px; border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--c, var(--accent)) var(--v, 50%), var(--surface-3) var(--v, 50%)); }
.range::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; border: 0; box-shadow: 0 2px 8px #0006, 0 0 0 4px var(--c, var(--accent)); cursor: grab; }
.range::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 0;
  box-shadow: 0 2px 8px #0006, 0 0 0 4px var(--c, var(--accent)); }

/* ---------- SoC-Ring ---------- */
.ring { --size: 132px; --stroke: 11; position: relative; width: var(--size); height: var(--size); flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { stroke: var(--surface-3); }
.ring .value { stroke: var(--accent); stroke-linecap: round; transition: stroke-dasharray .6s var(--ease); filter: drop-shadow(0 0 6px var(--accent-soft)); }
.ring .limit { stroke: var(--text); stroke-linecap: round; opacity: .55; }
.ring .center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring .center b { font: 700 32px/1 var(--font-display); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.ring .center small { font-size: var(--fs-xs); color: var(--text-3); margin-top: 4px; }

/* ---------- Stat-Kacheln ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s-3); }
.stat { padding: var(--s-3) var(--s-4); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); }
.stat .label { font-size: var(--fs-xs); color: var(--text-3); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.stat .label i { width: 8px; height: 8px; border-radius: 3px; background: var(--c, var(--text-3)); }
.stat .metric b { font-size: var(--fs-lg); }
.stat .metric span { font-size: var(--fs-sm); }

/* ---------- Listen ---------- */
.list { display: grid; }
.row { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) 0; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .meta { font-size: var(--fs-sm); color: var(--text-3); }
.row .end { text-align: right; font-variant-numeric: tabular-nums; }
.avatar { width: 40px; height: 40px; border-radius: var(--r-sm); display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); flex: none; }
.avatar svg { width: 20px; height: 20px; }
.avatar.accent { background: var(--accent-soft); color: var(--accent); }
.avatar.pv { background: var(--pv-soft); color: var(--pv); }

/* Anteil-Balken (PV vs. Netz) */
.share { display: flex; height: 6px; border-radius: var(--r-pill); overflow: hidden; background: var(--surface-3); }
.share i { display: block; }

/* ---------- Tabelle (Desktop/Export-Vorschau) ---------- */
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.table th { text-align: left; font-size: var(--fs-xs); font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; padding: 10px 12px; border-bottom: 1px solid var(--border-strong); }
.table td { padding: 12px; border-bottom: 1px solid var(--border); }
.table td.r, .table th.r { text-align: right; }
.table tfoot td { font-weight: 700; border-bottom: 0; border-top: 1px solid var(--border-strong); }

/* ---------- Tab-Leiste (mobil) ---------- */
.tabbar {
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(20px) saturate(1.4);
  border-top: 1px solid var(--border);
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 0;
  font-size: 11px; font-weight: 600; color: var(--text-3); text-decoration: none; border-radius: var(--r-sm); }
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--accent); }

/* ---------- Hinweise / Toast ---------- */
.notice { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--border); font-size: var(--fs-sm); }
.notice svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.notice.warn { background: var(--pv-soft); border-color: transparent; color: var(--text); }
.notice.warn svg { color: var(--warn); }
.notice.error { background: var(--danger-soft); border-color: transparent; }
.notice.error svg { color: var(--danger); }

.toast { display: inline-flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: var(--r-pill);
  background: var(--text); color: var(--bg); font-size: var(--fs-sm); font-weight: 600; box-shadow: 0 12px 30px -10px #000a; }
.toast svg { width: 18px; height: 18px; color: var(--accent); }

/* ---------- Energiefluss ---------- */
.flow { position: relative; width: 100%; aspect-ratio: 1 / .9; }
.flow svg.lines { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.flow .line { fill: none; stroke: var(--surface-3); stroke-width: 2; }
.flow .stream { fill: none; stroke-width: 3; stroke-linecap: round; stroke-dasharray: 2 10; animation: flow 1s linear infinite; }
.flow .stream.slow { animation-duration: 1.8s; }
@keyframes flow { to { stroke-dashoffset: -12; } }
.flow .node { position: absolute; transform: translate(-50%, -32px); display: grid; justify-items: center; gap: 4px; text-align: center; }
.flow .bubble { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); border: 2px solid var(--c); color: var(--c);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--c) 10%, transparent), 0 10px 30px -10px var(--c); }
.flow .bubble svg { width: 28px; height: 28px; }
.flow .node.hub { transform: translate(-50%, -40px); }
.flow .node.hub .bubble { width: 80px; height: 80px; }
.flow .node b { font: 700 var(--fs-md)/1 var(--font-display); font-variant-numeric: tabular-nums; }
.flow .node small { font-size: 11px; color: var(--text-3); font-weight: 600; }

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