@font-face {
  font-family: 'Space Grotesk';
  src: url('fonts/space-grotesk-latin.woff2') format('woff2');
  font-weight: 300 800;
  font-display: swap;
}

:root {
  --bg: #070D16;
  --panel: rgba(15, 26, 41, 0.66);
  --panel-solid: #0F1A29;
  --edge: rgba(126, 166, 224, 0.14);
  --edge-hi: rgba(126, 166, 224, 0.32);
  --ink: #EAF1FA;
  --ink-2: #9FB0C3;
  --ink-3: #5E7188;
  /* Chart-Serien (validiert, dark) */
  --c-pv: #BD821A;
  --c-haus: #24A592;
  --c-netz: #587FC8;
  /* helle Akzente */
  --a-pv: #FFB020;
  --a-haus: #2FD6C3;
  --a-netz: #8FB0E8;
  --radius: 18px;
  --display: 'Space Grotesk', -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background:
    radial-gradient(900px 500px at 18% -10%, rgba(255, 176, 32, 0.07), transparent 60%),
    radial-gradient(1100px 600px at 85% -20%, rgba(47, 214, 195, 0.06), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  min-height: 100vh;
}

.bg-grid {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    linear-gradient(rgba(126,166,224,0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(126,166,224,0.045) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse 90% 70% at 50% 0%, black 30%, transparent 100%);
}

.hidden { display: none !important; }
.muted { color: var(--ink-2); }
.small { font-size: 0.78rem; }
.center { text-align: center; }
.amber-t { color: var(--a-pv); }
.teal-t { color: var(--a-haus); }

.glass {
  background: var(--panel);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.05) inset,
    0 20px 50px -30px rgba(0,0,0,0.8);
}

/* ---------- Login ---------- */
.login { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 10; }
.login-card { padding: 2.6rem 2.2rem; width: min(350px, 90vw); text-align: center; display: flex; flex-direction: column; gap: 0.85rem; }
.login-logo { font-size: 3rem; color: var(--a-pv); text-shadow: 0 0 34px rgba(255,176,32,.55); }
.login-card h1 { font-family: var(--display); font-size: 1.3rem; letter-spacing: 0.14em; text-transform: uppercase; }
.login-card input { background: rgba(7,13,22,0.8); border: 1px solid var(--edge); border-radius: 10px; padding: 0.75rem 0.95rem; color: var(--ink); font-size: 1rem; }
.login-card input:focus { outline: none; border-color: var(--a-pv); box-shadow: 0 0 0 3px rgba(255,176,32,0.15); }
.login-card button { background: linear-gradient(180deg, #FFC24D, #F5A00E); color: #1A1204; border: 0; border-radius: 10px; padding: 0.75rem; font-size: 1rem; font-weight: 700; cursor: pointer; font-family: var(--display); letter-spacing: 0.04em; }
.login-error { color: #FF7A6B; min-height: 1.2em; font-size: 0.85rem; }

/* ---------- Layout ---------- */
.app { max-width: 1120px; margin: 0 auto; padding: 0.9rem 1rem 2rem; }

header {
  position: sticky; top: 0.6rem; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.55rem 1.1rem; margin-bottom: 1rem; flex-wrap: wrap;
}
.brand { font-family: var(--display); font-weight: 700; letter-spacing: 0.2em; font-size: 0.92rem; }
.brand-sun { color: var(--a-pv); text-shadow: 0 0 16px rgba(255,176,32,.6); }
.brand-thin { font-weight: 300; color: var(--ink-2); }
nav { display: flex; gap: 0.35rem; }
.tab { background: transparent; color: var(--ink-2); border: 1px solid transparent; padding: 0.42rem 1.05rem; border-radius: 999px; cursor: pointer; font-size: 0.88rem; font-family: var(--display); letter-spacing: 0.03em; }
.tab.active { background: rgba(126,166,224,0.1); border-color: var(--edge-hi); color: var(--ink); }
.header-right { display: flex; gap: 0.8rem; align-items: center; }
.clock { color: var(--ink-3); font-variant-numeric: tabular-nums; font-size: 0.85rem; font-family: var(--display); }
.sync-badge { color: var(--a-pv); font-size: 0.75rem; letter-spacing: 0.1em; animation: pulse 1.6s infinite; }
@media (max-width: 980px) {
  .clock { display: none; }
  .tab { padding: 0.4rem 0.7rem; font-size: 0.82rem; }
  .brand-thin { display: none; }
}
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--a-haus); box-shadow: 0 0 10px var(--a-haus); animation: pulse 2.4s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

.view { display: flex; flex-direction: column; gap: 1rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.col { display: flex; flex-direction: column; gap: 1rem; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }

.panel { padding: 1.25rem 1.4rem; }
.panel h2 { font-family: var(--display); font-size: 0.8rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-2); margin-bottom: 0.9rem; font-weight: 500; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.info { cursor: help; color: var(--ink-3); }

/* ---------- Hero ---------- */
.hero { padding: 0; overflow: hidden; }
.hero-stage { position: relative; }
.hero-img { width: 100%; display: block; }
.hero-flows { position: absolute; inset: 0; width: 100%; height: 100%; }
.hflow { fill: none; stroke-width: 4; stroke-linecap: round; stroke-dasharray: 2 18; opacity: 0; filter: url(#fglow); }
.hflow.on { opacity: 0.95; animation: hdash 1.1s linear infinite; }
.hf-pv { stroke: var(--a-pv); }
.hf-haus { stroke: var(--a-haus); }
.hf-netz { stroke: var(--a-netz); }
@keyframes hdash { to { stroke-dashoffset: -40; } }

.chip {
  position: absolute; display: flex; flex-direction: column; align-items: center; gap: 0.05rem;
  background: rgba(7, 13, 22, 0.72); backdrop-filter: blur(8px);
  border: 1px solid var(--edge-hi); border-radius: 12px; padding: 0.4rem 0.85rem;
  font-family: var(--display);
}
.chip-label { font-size: 0.62rem; letter-spacing: 0.2em; color: var(--ink-2); }
.chip-val { font-size: clamp(0.95rem, 2.2vw, 1.35rem); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chip-pv   { left: 6%; top: 9%; border-color: rgba(255,176,32,0.55); box-shadow: 0 0 24px -6px rgba(255,176,32,0.5); }
.chip-pv .chip-val { color: var(--a-pv); }
.chip-haus { left: 56%; top: 82%; transform: translateX(-50%); border-color: rgba(47,214,195,0.5); box-shadow: 0 0 24px -6px rgba(47,214,195,0.45); }
.chip-haus .chip-val { color: var(--a-haus); }
.chip-netz { right: 4%; top: 14%; border-color: rgba(143,176,232,0.5); box-shadow: 0 0 24px -6px rgba(143,176,232,0.45); }
.chip-netz .chip-val { color: var(--a-netz); }

.hero-badge {
  position: absolute; top: 4.5%; right: 4%;
  font-family: var(--display); font-size: 0.72rem; letter-spacing: 0.12em;
  color: var(--a-haus); background: rgba(7,13,22,0.72); border: 1px solid rgba(47,214,195,0.4);
  border-radius: 999px; padding: 0.3rem 0.75rem;
}
.hero-badge span { color: var(--ink-3); }

/* ---------- Überschuss-Ampel ---------- */
.ampel { display: flex; align-items: center; gap: 1rem; padding: 0.85rem 1.2rem; }
.ampel-dot { width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0; background: var(--ink-3); }
.ampel.gruen .ampel-dot { background: #34D97B; box-shadow: 0 0 18px #34D97B; animation: pulse 2s infinite; }
.ampel.gelb .ampel-dot { background: var(--a-pv); box-shadow: 0 0 16px rgba(255,176,32,0.8); }
.ampel.grau .ampel-dot { background: var(--ink-3); }
.ampel-text { flex: 1; min-width: 0; }
.ampel-title { font-family: var(--display); font-weight: 700; font-size: 0.98rem; }
.ampel.gruen { border-color: rgba(52,217,123,0.45); }
.ampel.gruen .ampel-title { color: #7BEBAA; }
.ampel-sub { font-size: 0.78rem; }
.ampel-kw { font-family: var(--display); font-weight: 700; font-variant-numeric: tabular-nums; color: #7BEBAA; white-space: nowrap; }

/* Bewertungs-Badges */
.rating { font-size: 0.68rem; font-family: var(--display); letter-spacing: 0.04em; border-radius: 6px; padding: 0.08rem 0.4rem; margin-left: 0.35rem; vertical-align: 1px; }
.rating.r-top { color: #7BEBAA; border: 1px solid rgba(52,217,123,0.4); }
.rating.r-gut { color: var(--a-haus); border: 1px solid rgba(47,214,195,0.4); }
.rating.r-ok { color: var(--a-pv); border: 1px solid rgba(255,176,32,0.4); }
.rating.r-neutral { color: var(--ink-2); border: 1px solid var(--edge-hi); }

/* ---------- KPI ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.kpi-row-5 { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 760px) { .kpi-row, .kpi-row-5 { grid-template-columns: repeat(2, 1fr); } }
.kpi { padding: 1rem 1rem 0.85rem; text-align: center; position: relative; overflow: hidden; }
.kpi::after { content: ''; position: absolute; left: 20%; right: 20%; top: 0; height: 1px; background: linear-gradient(90deg, transparent, var(--edge-hi), transparent); }
.kpi-label { font-family: var(--display); font-size: 0.68rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-2); }
.kpi-value { font-family: var(--display); font-size: clamp(1.7rem, 3.4vw, 2.3rem); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.3; }
.kpi-value.sm { font-size: clamp(1.3rem, 2.6vw, 1.7rem); }
.kpi-unit { font-size: 0.72rem; color: var(--ink-3); }
.kpi-pv .kpi-value { color: var(--a-pv); text-shadow: 0 0 28px rgba(255,176,32,.3); }
.kpi-haus .kpi-value { color: var(--a-haus); }
.kpi-netz .kpi-value { color: var(--a-netz); }
.kpi-spar .kpi-value { background: linear-gradient(120deg, var(--a-haus), #9BE8B7); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- Amortisation ---------- */
.seg { display: inline-flex; background: rgba(7,13,22,0.7); border: 1px solid var(--edge); border-radius: 999px; padding: 3px; }
.seg button { background: transparent; border: 0; color: var(--ink-2); padding: 0.35rem 0.95rem; border-radius: 999px; cursor: pointer; font-size: 0.85rem; font-family: var(--display); }
.seg button.active { background: rgba(126,166,224,0.14); color: var(--ink); }
.seg-sm button { padding: 0.22rem 0.75rem; font-size: 0.78rem; }

.amort-bar-wrap { margin: 1.1rem 0 0.4rem; }
.amort-bar { position: relative; height: 22px; border-radius: 999px; background: rgba(7,13,22,0.75); border: 1px solid var(--edge); overflow: hidden; }
.amort-fill {
  height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, #B97F16, var(--a-pv) 60%, #FFD37A);
  box-shadow: 0 0 24px rgba(255,176,32,0.45);
  transition: width 1.2s cubic-bezier(.2,.8,.2,1);
  position: relative;
}
.amort-fill::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent 40%, rgba(255,255,255,0.35) 50%, transparent 60%);
  background-size: 200% 100%; animation: shine 3.2s linear infinite;
}
@keyframes shine { to { background-position: -200% 0; } }
.amort-marker { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink-2); opacity: 0; }
.amort-scale { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--ink-3); margin-top: 0.35rem; font-variant-numeric: tabular-nums; }
.amort-facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: 1rem; }
@media (max-width: 760px) { .amort-facts { grid-template-columns: 1fr; gap: 0.6rem; } }
.fact-label { font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3); font-family: var(--display); }
.fact-val { font-family: var(--display); font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.fact-val.teal { color: var(--a-haus); }
.fact-val.amber { color: var(--a-pv); }

/* ---------- Gespart ---------- */
.spar-table { width: 100%; border-collapse: collapse; font-size: 0.98rem; }
.spar-table td { padding: 0.55rem 0; border-bottom: 1px solid rgba(126,166,224,0.09); }
.spar-table td:last-child { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--a-haus); font-family: var(--display); }
.spar-total td { border-bottom: 0; font-size: 1.18rem; }
.tarif-hinweis { margin-top: 0.8rem; font-size: 0.78rem; color: #FFC966; background: rgba(255,176,32,.07); border: 1px solid rgba(255,176,32,.22); border-radius: 10px; padding: 0.5rem 0.7rem; }
#tarifInfo { margin-top: 0.6rem; }

/* ---------- Meter (LED-Segmente) ---------- */
.meter-row { margin-bottom: 1.1rem; }
.meter-head { display: flex; justify-content: space-between; font-size: 0.88rem; margin-bottom: 0.4rem; }
.meter-val { font-family: var(--display); font-weight: 700; font-variant-numeric: tabular-nums; color: var(--a-haus); }
.meter { display: grid; grid-template-columns: repeat(24, 1fr); gap: 3px; height: 16px; }
.meter i { border-radius: 2.5px; background: rgba(126,166,224,0.12); }
.meter i.on { background: var(--a-haus); box-shadow: 0 0 8px rgba(47,214,195,0.55); }
.meter.amber i.on { background: var(--a-pv); box-shadow: 0 0 8px rgba(255,176,32,0.55); }

/* ---------- Parteien ---------- */
.partei-list { display: flex; flex-direction: column; gap: 0.55rem; }
.partei-row { display: grid; grid-template-columns: 1.1fr 2fr auto; gap: 0.7rem; align-items: center; font-size: 0.88rem; }
.partei-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.partei-name .common-tag { color: var(--ink-3); font-size: 0.74em; }
.partei-bar-bg { background: rgba(7,13,22,0.75); border: 1px solid rgba(126,166,224,0.08); border-radius: 5px; height: 14px; overflow: hidden; }
.partei-bar { background: linear-gradient(90deg, #1B8A7A, var(--a-haus)); height: 100%; border-radius: 4px; min-width: 2px; transition: width .6s ease; box-shadow: 0 0 10px rgba(47,214,195,0.35); }
.partei-val { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; text-align: right; min-width: 5.4em; font-family: var(--display); }

/* ---------- Historie ---------- */
.hist-controls { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.date-nav { display: flex; align-items: center; gap: 0.6rem; }
.date-nav button { background: rgba(7,13,22,0.7); border: 1px solid var(--edge); color: var(--ink); width: 32px; height: 32px; border-radius: 9px; cursor: pointer; font-size: 1.1rem; }
.date-nav button:hover { border-color: var(--edge-hi); }
.date-nav span { min-width: 11.5em; text-align: center; font-variant-numeric: tabular-nums; font-family: var(--display); }
.chart-wrap { position: relative; height: 330px; }
@media (max-width: 760px) { .chart-wrap { height: 240px; } }

/* ---------- Ranking / Rekorde ---------- */
.ranking-list { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }
.ranking-list li { display: grid; grid-template-columns: 2.2em 1fr auto; gap: 0.6rem; align-items: center; background: rgba(7,13,22,0.55); border: 1px solid var(--edge); border-radius: 12px; padding: 0.6rem 0.9rem; }
.ranking-list .medal { font-size: 1.2rem; text-align: center; }
.ranking-list .kwh { font-variant-numeric: tabular-nums; color: var(--ink-2); font-family: var(--display); }
.ranking-list li:first-child { border-color: rgba(255,176,32,0.5); background: rgba(255,176,32,.06); box-shadow: 0 0 30px -12px rgba(255,176,32,0.5); }

.rekord-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
@media (max-width: 760px) { .rekord-grid { grid-template-columns: repeat(2, 1fr); } }
.rekord { background: rgba(7,13,22,0.55); border: 1px solid var(--edge); border-radius: 12px; padding: 0.85rem; text-align: center; }
.rekord .r-icon { font-size: 1.3rem; }
.rekord .r-val { font-family: var(--display); font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: 0.15rem 0; }
.rekord .r-label { font-size: 0.72rem; color: var(--ink-2); }
.rekord .r-date { font-size: 0.7rem; color: var(--ink-3); }

.big-num { font-family: var(--display); font-size: 2.7rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: 0.4rem 0; }
.big-num.teal { color: var(--a-haus); text-shadow: 0 0 30px rgba(47,214,195,0.35); }
.big-num.amber { color: var(--a-pv); text-shadow: 0 0 30px rgba(255,176,32,0.35); }
.co2-eq { display: flex; justify-content: center; gap: 2.2rem; margin-top: 0.9rem; }
.co2-eq div { display: flex; flex-direction: column; }
.co2-eq span:first-child { font-family: var(--display); font-weight: 700; font-size: 1.15rem; font-variant-numeric: tabular-nums; }

/* ---------- Abrechnung ---------- */
.table-scroll { overflow-x: auto; }
.abr-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; min-width: 560px; }
.abr-table th { text-align: right; font-family: var(--display); font-size: 0.68rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3); padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--edge); }
.abr-table th:first-child { text-align: left; }
.abr-table td { padding: 0.5rem 0.6rem; text-align: right; font-variant-numeric: tabular-nums; border-bottom: 1px solid rgba(126,166,224,0.07); }
.abr-table td:first-child { text-align: left; }
.abr-table td:nth-child(5) { font-weight: 700; font-family: var(--display); }
.abr-status { color: var(--ink-3); font-size: 0.78rem; }
.row-investor { background: rgba(255,176,32,0.05); }
.row-investor .abr-status { color: var(--a-pv); }
.investor-tag { color: var(--a-pv); border: 1px solid rgba(255,176,32,0.35); border-radius: 6px; padding: 0.05rem 0.35rem; }
.topf-table .topf-zwischen td { color: var(--a-haus); }
.btn-ghost { background: rgba(7,13,22,0.7); border: 1px solid var(--edge); color: var(--ink-2); border-radius: 9px; padding: 0.5rem 0.9rem; cursor: pointer; font-size: 0.85rem; }
.btn-ghost:hover { border-color: var(--edge-hi); color: var(--ink); }

/* Amortisation Cash/Natura-Split */
.amort-split { margin-top: 1rem; }
.split-bar { display: flex; height: 8px; border-radius: 999px; overflow: hidden; background: rgba(7,13,22,0.7); border: 1px solid var(--edge); }
.split-cash { background: var(--a-haus); }
.split-natura { background: var(--a-pv); }
.amort-split p { margin-top: 0.4rem; }

/* ---------- Jürg ---------- */
.tab-juerg { color: var(--a-pv); }
.juerg-panel { text-align: center; }
.juerg-stage { display: flex; align-items: center; gap: 1.6rem; justify-content: center; flex-wrap: wrap; padding: 1rem 0; }
.juerg-avatar-wrap { position: relative; flex-shrink: 0; }
.juerg-avatar {
  width: 190px; height: 190px; border-radius: 50%; object-fit: cover; display: block;
  border: 2px solid rgba(255,176,32,0.5);
  box-shadow: 0 0 40px -8px rgba(255,176,32,0.45);
}
.talking .juerg-avatar { animation: bob 0.55s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-4px) rotate(-1.2deg); } }
.juerg-waves { position: absolute; bottom: -6px; left: 50%; transform: translateX(-50%); display: flex; gap: 4px; align-items: flex-end; height: 22px; opacity: 0; transition: opacity .25s; }
.talking .juerg-waves { opacity: 1; }
.juerg-waves i { width: 5px; border-radius: 3px; background: var(--a-pv); height: 6px; }
.talking .juerg-waves i { animation: eq 0.7s ease-in-out infinite; }
.juerg-waves i:nth-child(2) { animation-delay: 0.1s; }
.juerg-waves i:nth-child(3) { animation-delay: 0.2s; }
.juerg-waves i:nth-child(4) { animation-delay: 0.3s; }
.juerg-waves i:nth-child(5) { animation-delay: 0.4s; }
@keyframes eq { 50% { height: 20px; } }
.bubble {
  position: relative; max-width: 520px; text-align: left;
  background: rgba(7,13,22,0.75); border: 1px solid var(--edge-hi);
  border-radius: 16px; padding: 1.1rem 1.3rem; font-size: 1.02rem; line-height: 1.55;
}
.bubble::before {
  content: ''; position: absolute; left: -9px; top: 50%; transform: translateY(-50%) rotate(45deg);
  width: 16px; height: 16px; background: rgba(7,13,22,0.75);
  border-left: 1px solid var(--edge-hi); border-bottom: 1px solid var(--edge-hi);
}
@media (max-width: 760px) {
  .juerg-stage { flex-direction: column; }
  .bubble::before { left: 50%; top: -9px; transform: translateX(-50%) rotate(135deg); }
}
.juerg-controls { display: flex; gap: 0.7rem; justify-content: center; margin-top: 1rem; flex-wrap: wrap; }
.btn-play {
  background: linear-gradient(180deg, #FFC24D, #F5A00E); color: #1A1204; border: 0;
  border-radius: 999px; padding: 0.65rem 1.5rem; font-size: 1rem; font-weight: 700;
  cursor: pointer; font-family: var(--display);
  box-shadow: 0 0 28px -8px rgba(255,176,32,0.7);
}
.btn-play:active { transform: scale(0.97); }
.juerg-fussnote { margin-top: 1.1rem; }

footer { text-align: center; padding-top: 1.6rem; }
