:root {
  --bg: #f6f7f9;
  --surface: #ffffff;

  --text: #111827;
  --muted: rgba(17, 24, 39, 0.45);
  --muted2: rgba(17, 24, 39, 0.35);
  --border: rgba(17, 24, 39, 0.08);
  --border-strong: rgba(17, 24, 39, 0.10);

  --primary: rgba(31, 60, 255, 0.95);
  --primary-soft: rgba(31, 60, 255, 0.10);

  --good: #10b981;
  --warn: #f59e0b;
  --bad: #ef4444;

  --radius: 16px;

  /* iOS safe area insets */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --tabs-h: 78px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; }

.skip-link {
  position: absolute;
  top: 0; left: 0;
  transform: translateY(-110%);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  padding: 10px 12px;
  border-radius: 10px;
  z-index: 9999;
}
.skip-link:focus { transform: translateY(12px); }

/* Shell */
.app-shell {
  height: 100%;
  display: grid;
  grid-template-rows: 1fr calc(var(--tabs-h) + var(--safe-bottom));
}

/* Main content */
.main {
  overflow: auto;
  padding: calc(8px + var(--safe-top)) 14px 14px 14px;
}

.view { min-height: 100%; }

/* Card baseline */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: none; /* screenshot: sehr clean */
}

/* Tabs */
.tabs {
  position: sticky;
  bottom: 0;
  z-index: 20;
  background: var(--surface);
  border-top: 1px solid var(--border-strong);
  padding-bottom: var(--safe-bottom);
  height: calc(var(--tabs-h) + var(--safe-bottom));
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--muted);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.tab__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: currentColor;
}
.tab__icon svg { display: block; }

.tab.is-active {
  color: var(--primary);
}

.tab__label { line-height: 1; }

/* Skeleton */
.view-skeleton { display: grid; gap: 12px; }
.skeleton-card {
  height: 110px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, #eee 25%, #f6f6f6 37%, #eee 63%);
  background-size: 400% 100%;
  animation: shimmer 1.1s infinite;
  border: 1px solid var(--border);
}
@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton-card { animation: none; }
}

/* ========== Dashboard styles ========== */

.dash { padding-bottom: 14px; }

/* Header row: "Home E4" */
.dash-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin: 2px 0 10px 0;
}

.dash-home {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.dash-home__title {
  font-size: 16px;
  font-weight: 650;
  color: var(--text);
}

.dash-home__chev {
  color: rgba(17, 24, 39, 0.55);
  font-size: 14px;
  transform: translateY(1px);
}

/* Segmented control: Aktuell / Heute */
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: rgba(17, 24, 39, 0.04);
  border: 1px solid rgba(17, 24, 39, 0.06);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 12px;
}

.seg__btn {
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 10px 12px;
  font-weight: 650;
  font-size: 13px;
  color: rgba(17, 24, 39, 0.30);
  cursor: pointer;
}

.seg__btn.is-active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 10px 22px rgba(17, 24, 39, 0.10);
}

/* Flow card: container */
.dash-card { padding: 14px; }

.flow {
  position: relative;
  height: 260px;
  border-radius: 18px;
  background: rgba(17, 24, 39, 0.02);
  border: 1px solid rgba(17, 24, 39, 0.06);
  overflow: hidden;
}

/* center junction */
.flow-center {
  position: absolute;
  left: 50%; top: 50%;
  width: 18px; height: 18px;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: 999px;
  border: 1px solid rgba(17, 24, 39, 0.10);
  box-shadow: 0 8px 18px rgba(17, 24, 39, 0.06);
}

/* nodes */
.flow-node {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 110px;
  height: 110px;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  display: grid;
  place-content: center;
  text-align: center;
  color: #fff;
  box-shadow: 0 14px 30px rgba(17, 24, 39, 0.14);
}

.flow-node__label {
  font-size: 12px;
  opacity: 0.92;
  margin-bottom: 2px;
}

.flow-node__value {
  font-size: 28px;
  font-weight: 780;
  line-height: 1.05;
}

.flow-node__unit {
  font-size: 12px;
  opacity: 0.92;
  margin-top: 2px;
}

/* Colors tuned towards screenshot */
.flow-node--pv   { background: #f6c23e; }
.flow-node--grid { background: #9ca3af; }
.flow-node--bat  { background: #1f3cff; }
.flow-node--load { background: #f59e0b; }

/* pipes */
.pipe { position: absolute; border-radius: 999px; }
.pipe--v { width: 10px; left: 50%; transform: translateX(-50%); }
.pipe--h { height: 10px; top: 50%; transform: translateY(-50%); }

.pipe--top    { top: 28px; height: calc(50% - 28px); background: rgba(246, 194, 62, 0.28); }
.pipe--bottom { top: 50%;  height: calc(50% - 28px); background: rgba(245, 158, 11, 0.28); }

.pipe--left  { left: 28px; width: calc(50% - 28px); background: rgba(156, 163, 175, 0.28); }
.pipe--right { left: 50%;  width: calc(50% - 28px); background: rgba(31, 60, 255, 0.18); }

/* Section titles like screenshot */
.dash-section-title {
  font-size: 13px;
  font-weight: 650;
  color: rgba(17, 24, 39, 0.55);
  margin: 12px 0 8px 2px;
}

/* KPI grid (2 columns) */
.dash-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.dash-kpi__head { display: flex; align-items: center; justify-content: space-between; }
.dash-kpi__title { font-size: 13px; font-weight: 700; color: var(--primary); }

.dash-kpi__big { font-size: 34px; font-weight: 820; margin-top: 8px; }
.dash-kpi__unit { font-size: 18px; font-weight: 750; margin-left: 2px; }

.dash-kpi__sub { font-size: 12px; color: rgba(17, 24, 39, 0.45); margin-top: 2px; }

.dash-kpi__foot { display: flex; justify-content: space-between; margin-top: 14px; }
.dash-kpi__muted { font-size: 12px; color: rgba(17, 24, 39, 0.35); }

.progress {
  margin-top: 10px;
  height: 8px;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.10);
  overflow: hidden;
}
.progress__bar {
  height: 100%;
  border-radius: 999px;
  background: rgba(31, 60, 255, 0.65);
}

.dash-kpi__status { margin-top: 10px; }
.dash-kpi__status-val { font-size: 13px; font-weight: 700; color: rgba(17, 24, 39, 0.70); }

/* PowerPilot: optional horizontal carousel */
.pp {
  position: relative;
}

.pp-scroller {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 86%;
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 6px;
}
.pp-scroller::-webkit-scrollbar { display: none; }

.pp-card {
  scroll-snap-align: start;
}

.pp-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.pp-icon {
  width: 28px;
  height: 28px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 900;
  flex: 0 0 auto;
}
.pp-card__title {
  font-weight: 750;
  color: var(--primary);
  margin-right: auto;
}
.pp-card__right { display: flex; align-items: center; gap: 8px; }
.pp-lock { color: rgba(17, 24, 39, 0.45); font-size: 12px; font-weight: 700; }
.pp-lock__ic { font-size: 14px; opacity: 0.7; }

.pp-card__big {
  margin-top: 14px;
  font-size: 20px;
  font-weight: 820;
}

.pp-card__meta { margin-top: 14px; }
.pp-card__label { font-size: 12px; color: rgba(17, 24, 39, 0.35); }
.pp-card__value { font-size: 13px; font-weight: 700; color: rgba(17, 24, 39, 0.70); }

.pp-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 10px 0 2px 0;
}
.dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.18);
}
.dot.is-active { background: var(--primary); }

/* Tariff card */
.tariff__head { display: flex; align-items: center; gap: 10px; }
.tariff__icon {
  width: 28px; height: 28px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 900;
}
.tariff__title { font-weight: 780; color: var(--primary); }

.tariff__price {
  margin-top: 8px;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.tariff__price-big { font-size: 38px; font-weight: 860; }
.tariff__price-unit { font-size: 13px; color: rgba(17, 24, 39, 0.55); font-weight: 700; }
.tariff__sub { margin-top: 2px; font-size: 12px; color: rgba(17, 24, 39, 0.35); }

.spark { margin-top: 10px; }
.spark__axis {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: rgba(17, 24, 39, 0.30);
  margin-bottom: 6px;
}
.spark__svg { width: 100%; height: 64px; display: block; }

/* Small screens */
@media (max-width: 380px) {
  .flow { height: 248px; }
  .flow-node { width: 100px; height: 100px; }
  .pp-scroller { grid-auto-columns: 92%; }
}

/* Flow Animation in Energy Flower */
/* ===== FLOW FIX: circles must never clip ===== */
.flow {
  /* previously: overflow hidden — must be visible */
  overflow: visible;
  height: 300px; /* more room for 5 nodes */
  border-radius: 18px;
  position: relative;
}

/* Optional: soften inner canvas feel */
.flow::before {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 16px;
  border: 1px solid rgba(17,24,39,0.06);
  background: rgba(17,24,39,0.01);
  pointer-events: none;
}

/* Node sizing */
.flow-node { z-index: 2; }

.flow-node--small {
  width: 92px;
  height: 92px;
}
.flow-node--small .flow-node__value { font-size: 22px; }
.flow-node--small .flow-node__label { font-size: 11px; }
.flow-node--small .flow-node__unit  { font-size: 11px; }

/* Wallbox styling (distinct but consistent) */
.flow-node--wb {
  background: #22c55e; /* green-ish to separate consumption sink */
  box-shadow: 0 14px 30px rgba(17, 24, 39, 0.14);
}

/* Keep center above pipes */
.flow-center { z-index: 3; }

/* Pipes: base thickness + layered chevrons */
.pipe {
  z-index: 1;
  opacity: 1;
  filter: drop-shadow(0 10px 18px rgba(17,24,39,0.10));
}

/* Animated chevrons overlay */
.pipe::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 999px;
  opacity: 0.75;
  /* chevrons built by two gradients */
  background-image:
    linear-gradient(45deg, rgba(255,255,255,0) 45%, rgba(255,255,255,0.35) 46%, rgba(255,255,255,0.35) 54%, rgba(255,255,255,0) 55%),
    linear-gradient(-45deg, rgba(255,255,255,0) 45%, rgba(255,255,255,0.35) 46%, rgba(255,255,255,0.35) 54%, rgba(255,255,255,0) 55%);
  background-size: 26px 26px;
  background-repeat: repeat;
  animation: chevronsMove 1.1s linear infinite;
  pointer-events: none;
}

/* Direction control via data-dir */
.pipe[data-dir="left"]::after  { animation-direction: reverse; }
.pipe[data-dir="up"]::after    { animation-direction: reverse; }
.pipe[data-dir="diag-up"]::after { animation-direction: reverse; }

/* For vertical pipes, move pattern along Y; for horizontal along X */
.pipe--h::after { background-position: 0 0; }
.pipe--v::after { background-position: 0 0; }

/* We fake axis-specific motion by moving background diagonally,
   works well visually for both orientations and matches the screenshot style */
@keyframes chevronsMove {
  from { background-position: 0 0; }
  to   { background-position: 26px 26px; }
}

/* Diagonal pipe (center -> wallbox) */
.pipe--d {
  position: absolute;
  height: 10px;
  width: 120px;
  left: 56%;
  top: 56%;
  transform: translate(-50%, -50%) rotate(45deg);
  border-radius: 999px;
  background: rgba(34,197,94,0.22);
}
.pipe--d::after { opacity: 0.70; }

/* Position helper for diagonal wallbox pipe */
.pipe--wb {}

/* Fine-tune existing pipes to new geometry */
.pipe--top {
  top: 70px;
  height: calc(50% - 70px);
  background: rgba(246, 194, 62, 0.28);
}
.pipe--bottom {
  top: 50%;
  height: calc(50% - 70px);
  background: rgba(245, 158, 11, 0.28);
}
.pipe--left {
  left: 70px;
  width: calc(50% - 70px);
  background: rgba(156, 163, 175, 0.28);
}
.pipe--right {
  left: 50%;
  width: calc(50% - 70px);
  background: rgba(31, 60, 255, 0.18);
}

/* Reduce clutter: soften pipes on very small screens */
@media (max-width: 380px) {
  .flow { height: 290px; }
  .pipe--d { width: 105px; left: 57%; top: 57%; }
}