/* ==========================================================================================
   energia.css - przepływ energii w rozwiniętej karcie Energia / licznika energii (js/smartdom_energia.js,
   definicje: przeplywEnergii w definicje/definicjeEkranow.js). Język kart "Stan systemu": neutralne kafle
   rgba(128,128,128,.14-.16), obwódka var(--sd-ramka), bez kolorowych pasków i pomarańczowych teł. Kolor węzła (--en-kolor)
   tylko na ikonie, blasku i kropkach. Blask jak żarówka w css/karty.css (drop-shadow, siła = --en-moc 0-1).
   Rozmiary schematu w --en-u (1/100 szerokości schematu, ustawiane z js) - ikony i napisy rosną razem z kartą.
   Zgodne z WebView Chrome 92 (bez :has(), bez container queries).
   ========================================================================================== */
.en-widzet {
    display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; justify-content: center;
    padding: 4px 0 2px; box-sizing: border-box;
    --en-wyl: var(--sd-swiatlo-wyl, #8a8a8a);
}
.en-kol-schemat { flex: 1 1 300px; min-width: 0; max-width: 480px; }
.en-kol-dane { flex: 1 1 260px; min-width: 0; max-width: 620px; display: flex; flex-direction: column; gap: 8px; }

/* ---------- schemat ---------- */
.en-schemat {
    --en-u: 3.4px;
    position: relative; width: 100%; height: 0; padding-top: 94%; /* wysokość ustawiana z js wg widocznych węzłów */
    -webkit-user-select: none; user-select: none;
}
.en-linie { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.en-tor { fill: none; stroke: rgba(128, 128, 128, 0.35); stroke-width: 0.7; stroke-linecap: round; transition: stroke 0.3s, stroke-opacity 0.3s; }
.en-linia.aktywna .en-tor { stroke: var(--en-kolor); stroke-opacity: 0.35; }
.en-kropki {
    fill: none; stroke: var(--en-kolor); stroke-width: 1.7; stroke-linecap: round;
    stroke-dasharray: 0 5; /* odstęp = OKRES w js */
    opacity: 0; transition: opacity 0.3s;
    animation: en-plyn var(--en-czas, 1.5s) linear infinite;
    animation-play-state: paused;
}
.en-linia.aktywna .en-kropki { opacity: 1; animation-play-state: running; }
.en-linia.wstecz .en-kropki { animation-direction: reverse; }
@keyframes en-plyn { from { stroke-dashoffset: 5; } to { stroke-dashoffset: 0; } }
.en-strzalka { fill: var(--en-kolor); display: none; }
.en-linia.wstecz .en-strzalka { transform: rotate(180deg); }
.en-rozdzielnia { fill: rgba(128, 128, 128, 0.55); }

/* węzeł: kółko z ikoną; tekst nad (górny rząd) albo pod kółkiem */
.en-wezel {
    position: absolute; z-index: 1; width: calc(var(--en-u) * 12); height: calc(var(--en-u) * 12);
    transform: translate(-50%, -50%); margin: 0; padding: 0; box-sizing: border-box;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%; border: 1px solid var(--sd-ramka, rgba(128, 128, 128, 0.35));
    background: rgba(128, 128, 128, 0.16); color: inherit; font: inherit; cursor: pointer;
    -webkit-tap-highlight-color: transparent; transition: transform 0.1s;
}
.en-wezel:active { transform: translate(-50%, -50%) scale(0.95); }
.en-wezel:focus-visible { outline: 2px solid var(--sd-akcent, #00ccff); outline-offset: 2px; }
.en-ikona { font-size: calc(var(--en-u) * 5.4); line-height: 1; color: var(--en-wyl); transition: color 0.3s, filter 0.3s; }
i.en-ikona { display: inline-block; }
.en-wezel.aktywny .en-ikona {
    color: var(--en-kolor);
    filter: drop-shadow(0 0 calc(2px + 8px * var(--en-moc, 0)) var(--en-kolor));
}
.en-tekst {
    position: absolute; left: 50%; transform: translateX(-50%); width: calc(var(--en-u) * 29);
    display: flex; flex-direction: column; align-items: center; text-align: center; line-height: 1.2; pointer-events: none;
}
.en-rzad-gora .en-tekst { bottom: calc(100% + 2px); flex-direction: column-reverse; }
.en-rzad-srodek .en-tekst, .en-rzad-dol .en-tekst { top: calc(100% + 2px); }
.en-wartosc {
    font-weight: 700; font-size: clamp(15px, calc(var(--en-u) * 5), 22px); white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.en-etykieta {
    max-width: 100%; font-size: clamp(12px, calc(var(--en-u) * 3.6), 14px); opacity: 0.8;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.en-wezel:not(.aktywny) .en-wartosc { opacity: 0.75; }

/* magazyn: rysunek baterii z poziomem; ładowanie bez znanego poziomu - wypełnianie w pętli */
.en-bateria { width: calc(var(--en-u) * 6.6); height: auto; overflow: visible; }
.en-bat-obrys { fill: none; stroke: currentColor; stroke-width: 1.5; }
.en-bat-biegun { fill: currentColor; }
.en-bat-wypelnienie {
    fill: currentColor; opacity: 0.45; transform-box: fill-box; transform-origin: left center;
    transform: scaleX(var(--en-poziom, 0.5)); transition: transform 0.6s;
}
.en-wezel.en-znany-poziom .en-bat-wypelnienie, .en-wezel.aktywny .en-bat-wypelnienie { opacity: 0.9; }
.en-wezel.en-laduje .en-bat-wypelnienie { animation: en-laduj 2.2s ease-in-out infinite; }
@keyframes en-laduj { 0% { transform: scaleX(0.12); } 85%, 100% { transform: scaleX(1); } }

/* odbiornik z obracaniem (np. wentylator pompy ciepła) */
.en-wezel.aktywny .en-obrot { animation: en-obrot var(--en-czas-obrotu, 2s) linear infinite; }
@keyframes en-obrot { to { transform: rotate(360deg); } }

.en-brak { padding: 12px; font-size: 14px; opacity: 0.8; text-align: center; }

/* ---------- podsumowanie: stan i koszt (kafle neutralne) ---------- */
.en-podsumowanie { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.en-podsumowanie.en-jeden { grid-template-columns: minmax(0, 1fr); }
.en-kafel {
    display: flex; align-items: center; gap: 10px; min-height: 52px; margin: 0; padding: 8px 12px; box-sizing: border-box; min-width: 0;
    border: 0; border-radius: var(--sd-promien-pola, 8px); background: var(--karta-tlo-wiersza, rgba(128, 128, 128, 0.14));
    color: inherit; font: inherit; font-size: 14px; text-align: left; line-height: 1.25;
}
.en-kafel > i:first-child { flex: 0 0 auto; width: 24px; text-align: center; font-size: 18px; color: var(--en-kolor, var(--sd-akcent, #00ccff)); }
.en-status.en-darmowa > i:first-child { filter: drop-shadow(0 0 5px var(--en-kolor)); }
.en-kafel-tekst { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; overflow-wrap: anywhere; }
.en-kafel-tekst b { font-size: 15px; }
.en-kafel-etyk { font-size: 12px; opacity: 0.8; }
.en-kafel-wartosc { font-size: 17px; font-variant-numeric: tabular-nums; }
.en-koszt { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.en-koszt > i:first-child { color: var(--sd-akcent, #00ccff); }
.en-koszt:focus-visible { outline: 2px solid var(--sd-akcent, #00ccff); outline-offset: 2px; }
.en-kafel-strzalka { flex: 0 0 auto; opacity: 0.5; font-size: 13px; }

/* ---------- dziś / wczoraj (kWh) ---------- */
.en-dzienne {
    padding: 10px 12px; border-radius: var(--sd-promien-pola, 8px); background: var(--karta-tlo-wiersza, rgba(128, 128, 128, 0.14));
    display: flex; flex-direction: column; gap: 10px;
}
.en-dzienne-naglowek { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; font-weight: 600; opacity: 0.9; }
.en-legenda { display: flex; gap: 10px; font-weight: 400; font-size: 12px; opacity: 0.85; }
.en-leg::before { content: ""; display: inline-block; width: 14px; border-radius: 3px; margin-right: 5px; vertical-align: middle; background: currentColor; }
.en-leg-dzis::before { height: 7px; }
.en-leg-wczoraj::before { height: 4px; opacity: 0.45; }
.en-wiersz { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 8px; row-gap: 4px; align-items: baseline; }
.en-wiersz-nazwa { font-size: 14px; min-width: 0; overflow-wrap: anywhere; }
.en-wiersz-wartosci { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.en-w-dzis { font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.en-w-wczoraj { font-size: 12px; opacity: 0.75; white-space: nowrap; }
.en-paski { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 2px; }
.en-pasek {
    display: block; height: 7px; border-radius: 4px; background: var(--en-kolor);
    transform-origin: left center; transform: scaleX(var(--en-skala, 0)); transition: transform 0.5s ease-out;
}
.en-pasek-wczoraj { height: 4px; opacity: 0.45; }

/* ---------- wstrzymanie (poza ekranem, aplikacja w tle) i ograniczony ruch ---------- */
.en-widzet.en-pauza .en-kropki, .en-widzet.en-pauza .en-obrot, .en-widzet.en-pauza .en-bat-wypelnienie { animation-play-state: paused !important; }
@media (prefers-reduced-motion: reduce) {
    .en-kropki { display: none; }
    .en-linia.aktywna .en-strzalka { display: inline; }
    .en-wezel.aktywny .en-obrot, .en-wezel.en-laduje .en-bat-wypelnienie { animation: none; }
    .en-pasek, .en-ikona, .en-bat-wypelnienie { transition: none; }
}

/* motyw jasny: mocniejszy tor i rozdzielnia */
body.light-mode .en-tor { stroke: rgba(90, 90, 90, 0.35); }
body.light-mode .en-rozdzielnia { fill: rgba(90, 90, 90, 0.55); }

/* ---------- prognoza PV (js/smartdom_prognoza_pv.js) - pełna szerokość karty pod przepływem ---------- */
.en-prognoza {
    flex: 1 1 100%; width: 100%; min-width: 0; box-sizing: border-box; padding: 10px 12px;
    border-radius: var(--sd-promien-pola, 8px); background: var(--karta-tlo-wiersza, rgba(128, 128, 128, 0.14));
    display: flex; flex-direction: column; gap: 8px;
}
.en-prog-naglowek { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.en-prog-tytul { font-size: 13px; font-weight: 600; opacity: 0.9; }
.en-prog-tytul i { color: var(--sd-swiatlo-kolor, #f5b301); margin-right: 4px; }
.en-prog-zrodlo, .en-prog-kal { font-size: 12px; opacity: 0.7; }
.en-prog-info { font-size: 13px; opacity: 0.85; }
.en-prog-kafle { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.en-prog-kafel { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.en-prog-et { font-size: 12px; opacity: 0.75; }
.en-prog-w { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.en-prog-opis { font-size: 11px; opacity: 0.7; }
.en-prog-wykres { width: 100%; min-width: 0; overflow: hidden; }
.en-prog-wykres svg { display: block; }
.en-prog-siatka { stroke: currentColor; stroke-opacity: 0.12; stroke-width: 1; }
.en-prog-os, .en-prog-dzien { fill: currentColor; fill-opacity: 0.65; font-size: 10px; font-variant-numeric: tabular-nums; }
.en-prog-dzien { fill-opacity: 0.85; font-weight: 600; font-size: 11px; }
.en-prog-slupek { opacity: 0.85; }
.en-prog-slupek.en-prog-jutro { opacity: 0.45; }
.en-prog-linia { fill: none; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.en-prog-doba { stroke: currentColor; stroke-opacity: 0.3; stroke-width: 1; stroke-dasharray: 3 3; }
.en-prog-teraz { stroke: currentColor; stroke-opacity: 0.7; stroke-width: 1.2; }
.en-prog-legenda { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; font-size: 12px; }
.en-prog-leg::before { content: ""; display: inline-block; width: 14px; margin-right: 5px; vertical-align: middle; background: var(--en-prog-k, currentColor); }
.en-prog-leg-p::before { height: 8px; border-radius: 2px; opacity: 0.85; }
.en-prog-leg-r::before { height: 2.5px; border-radius: 2px; }
