:root {
    color-scheme: light;
    --bg: #f4f9fc;
    --bg-deep: #e9f2f7;
    --panel: rgba(255, 255, 255, .88);
    --panel-solid: #ffffff;
    --line: rgba(34, 82, 108, .13);
    --line-strong: rgba(34, 82, 108, .22);
    --text: #173247;
    --muted: #6b8293;
    --green: #1da968;
    --cyan: #119cb8;
    --blue: #4674d8;
    --amber: #efa51c;
    --orange: #f0783c;
    --red: #dd5261;
    --radius: 24px;
    --shadow: 0 24px 60px rgba(38, 83, 105, .11);
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg-deep); }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background:
        radial-gradient(circle at 75% -10%, rgba(56, 178, 211, .16), transparent 34rem),
        linear-gradient(165deg, #f8fcfe 0%, #f0f7fa 58%, #eaf3f7 100%);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
    overflow-x: hidden;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

.ambient {
    position: fixed;
    z-index: -1;
    width: 30rem;
    height: 30rem;
    border-radius: 50%;
    filter: blur(100px);
    opacity: .11;
    pointer-events: none;
}

.ambient-one { top: 8rem; left: -18rem; background: var(--cyan); }
.ambient-two { right: -18rem; bottom: 10rem; background: var(--amber); }

.topbar {
    height: 82px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 max(24px, calc((100vw - 1440px) / 2));
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, .82);
    backdrop-filter: blur(18px);
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text);
    text-decoration: none;
}

.brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    color: #ffffff;
    background: linear-gradient(145deg, #34c881, #15985a);
    box-shadow: 0 9px 24px rgba(29, 169, 104, .2);
}

.brand-mark svg { width: 23px; fill: currentColor; }
.brand > span:last-child { display: grid; line-height: 1.05; }
.brand b { font-size: 1.08rem; letter-spacing: .01em; }
.brand small { margin-top: 5px; color: var(--muted); font-size: .75rem; }

.topbar-status { display: flex; align-items: center; gap: 18px; }
.sync-text { color: var(--muted); font-size: .83rem; }

.status-pill, .mini-badge, .controller-state {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 34px;
    padding: 0 13px;
    border: 1px solid rgba(50, 229, 142, .22);
    border-radius: 999px;
    color: #167a4c;
    background: rgba(29, 169, 104, .1);
    font-size: .78rem;
    font-weight: 700;
}

.status-pill i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--amber);
    box-shadow: 0 0 0 5px rgba(255, 189, 63, .09);
}

.status-pill.online i { background: var(--green); box-shadow: 0 0 0 5px rgba(50, 229, 142, .09); }
.status-pill.offline { color: #ffacb4; border-color: rgba(255, 100, 112, .22); background: rgba(255, 100, 112, .08); }
.status-pill.offline i { background: var(--red); box-shadow: 0 0 0 5px rgba(255, 100, 112, .08); }

main { width: min(1440px, calc(100% - 48px)); margin: 0 auto; padding: 54px 0 72px; }
section + section { margin-top: 34px; }

.section-heading, .chart-toolbar {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 24px;
}

.section-heading.compact { margin-bottom: 18px; }
.eyebrow { margin: 0 0 5px; color: var(--cyan); font-size: .74rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(2rem, 4vw, 3.45rem); line-height: 1.02; letter-spacing: -.055em; }
h2 { margin-bottom: 0; font-size: clamp(1.5rem, 2.6vw, 2.15rem); line-height: 1.1; letter-spacing: -.035em; }
h3 { margin: 3px 0 0; font-size: 1.08rem; letter-spacing: -.015em; }
#clock { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .95rem; }

.energy-stage {
    min-height: 270px;
    padding: 36px clamp(22px, 4vw, 54px);
    display: grid;
    grid-template-columns: minmax(135px, 1fr) minmax(55px, .52fr) minmax(135px, 1fr) minmax(55px, .52fr) minmax(135px, 1fr) minmax(55px, .52fr) minmax(135px, 1fr);
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 30px;
    background:
        linear-gradient(140deg, rgba(255, 255, 255, .96), rgba(241, 249, 252, .94)),
        radial-gradient(circle at 50% 0, rgba(17, 156, 184, .08), transparent 45%);
    box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.025);
    overflow: hidden;
    position: relative;
}

.energy-stage::before {
    content: "";
    position: absolute;
    inset: 0;
    opacity: .14;
    background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
    background-size: 42px 42px;
    mask-image: linear-gradient(to bottom, black, transparent 82%);
    pointer-events: none;
}

.flow-node { display: grid; justify-items: center; text-align: center; position: relative; z-index: 2; --activity: .2; }
.flow-node strong { margin-top: 7px; font-size: clamp(1.35rem, 2.3vw, 2rem); letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.flow-node small { margin-top: 3px; color: var(--muted); font-size: .78rem; }
.node-label { color: #526d7e; font-size: .77rem; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }

.node-icon {
    width: 70px;
    height: 70px;
    display: grid;
    place-items: center;
    margin-bottom: 16px;
    border: 1px solid rgba(92, 140, 255, .24);
    border-radius: 22px;
    color: var(--blue);
    background: linear-gradient(145deg, rgba(70, 116, 216, .12), rgba(255, 255, 255, .9));
    box-shadow: inset 0 1px 0 rgba(255,255,255,.8), 0 14px 32px rgba(45,83,101,.1);
}
.node-icon svg { width: 32px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sun-icon { color: var(--amber); border-color: rgba(239, 165, 28, .28); background: linear-gradient(145deg, rgba(255, 196, 74, .18), rgba(255,255,255,.9)); }
.flow-load .node-icon { color: var(--cyan); border-color: rgba(17, 156, 184, .24); background: linear-gradient(145deg, rgba(17,156,184,.11), rgba(255,255,255,.9)); }

.flow-node .node-icon,
.battery-shell { transition: transform .35s ease, box-shadow .35s ease, border-color .35s ease; }
.flow-solar.active .sun-icon {
    border-color: rgba(239, 165, 28, .55);
    box-shadow: 0 0 34px rgba(239,165,28,.32);
    animation: sun-breathe var(--node-duration, 2.1s) ease-in-out infinite;
}
.flow-solar.active .sun-icon svg { animation: sun-turn var(--sun-duration, 12s) linear infinite; }
.flow-mppt.active .node-icon {
    border-color: rgba(70,116,216,.5);
    box-shadow: 0 0 28px rgba(70,116,216,.25);
    animation: controller-pulse 2.2s ease-in-out infinite;
}
.flow-load.active .node-icon {
    color: #f09b12;
    border-color: rgba(239,165,28,.48);
    background: radial-gradient(circle, rgba(255,221,117,.48), rgba(255,255,255,.92) 68%);
    box-shadow: 0 0 34px rgba(239,165,28,.32);
    animation: load-glow var(--node-duration, 1.6s) ease-in-out infinite;
}
.flow-load.active .node-icon svg { filter: drop-shadow(0 0 6px rgba(239,165,28,.45)); }

@keyframes sun-turn { to { transform: rotate(360deg); } }
@keyframes sun-breathe { 50% { transform: scale(1.08); } }
@keyframes controller-pulse { 50% { transform: translateY(-3px); } }
@keyframes load-glow { 50% { transform: scale(1.06); filter: brightness(1.08); } }

.battery-shell {
    width: 86px;
    height: 54px;
    margin: 8px 0 24px;
    padding: 5px;
    display: flex;
    align-items: end;
    border: 3px solid #71899a;
    border-radius: 13px;
    position: relative;
}
.battery-shell::after { content: ""; position: absolute; right: -9px; top: 16px; width: 7px; height: 18px; border-radius: 0 4px 4px 0; background: #71899a; }
.battery-shell i { display: block; width: 100%; height: 0%; border-radius: 6px; background: linear-gradient(90deg, #20d879, #58efaa); box-shadow: 0 0 22px rgba(50,229,142,.23); transition: height .7s ease, background .3s ease; position: relative; overflow: hidden; }
.battery-shell i::after { content: ""; position: absolute; inset: -80% -30%; background: linear-gradient(115deg, transparent 38%, rgba(255,255,255,.75) 50%, transparent 62%); transform: translateX(-60%); opacity: 0; }
.flow-battery.charging .battery-shell { border-color: #22a969; box-shadow: 0 0 28px rgba(29,169,104,.26); animation: battery-charge var(--node-duration, 1.8s) ease-in-out infinite; }
.flow-battery.charging .battery-shell i::after { opacity: .75; animation: battery-shine var(--shine-duration, 1.6s) linear infinite; }
.flow-battery.discharging .battery-shell { border-color: #ee9134; box-shadow: 0 0 24px rgba(240,120,60,.24); animation: battery-discharge var(--node-duration, 1.4s) ease-in-out infinite; }
.flow-battery.discharging .battery-shell i { background: linear-gradient(90deg, #f0a33a, #ffca66); }
.flow-battery.discharging .battery-shell i::after { opacity: .6; animation: battery-shine 2.1s linear infinite reverse; }
@keyframes battery-shine { to { transform: translateX(120%); } }
@keyframes battery-charge { 50% { transform: translateY(-2px) scale(1.025); } }
@keyframes battery-discharge { 50% { transform: scale(.97); } }

.flow-track { height: 2px; background: rgba(34, 82, 108, .14); position: relative; overflow: hidden; }
.flow-track span { position: absolute; inset: 0; background: repeating-linear-gradient(90deg, transparent 0 11px, var(--cyan) 11px 18px, transparent 18px 27px); animation: energy-flow var(--flow-duration, 1.25s) linear infinite; opacity: var(--flow-opacity, .8); }
.track-one span { background: repeating-linear-gradient(90deg, transparent 0 11px, var(--amber) 11px 18px, transparent 18px 27px); }
.flow-track.reverse span { animation-direction: reverse; }
.flow-track::after { content: ""; position: absolute; top: -4px; left: -12px; width: 10px; height: 10px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 5px var(--cyan), 0 0 13px var(--cyan); animation: energy-comet var(--comet-duration, 2s) linear infinite; opacity: var(--flow-opacity, .8); }
.track-one::after { background: var(--amber); box-shadow: 0 0 5px var(--amber), 0 0 14px var(--amber); }
.flow-track.reverse::after { animation-direction: reverse; }
.flow-track.inactive span, .flow-track.inactive::after, .energy-stage.paused .flow-track span, .energy-stage.paused .flow-track::after { animation-play-state: paused; opacity: .08; }
@keyframes energy-flow { to { transform: translateX(27px); } }
@keyframes energy-comet { to { left: calc(100% + 12px); } }

.kpi-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-top: 18px; }
.kpi-card, .chart-card, .device-card {
    border: 1px solid var(--line);
    background: var(--panel);
    box-shadow: inset 0 1px 0 rgba(255,255,255,.025);
    backdrop-filter: blur(10px);
}
.kpi-card { min-height: 174px; padding: 22px; border-radius: 21px; position: relative; overflow: hidden; }
.kpi-card::after { content: ""; position: absolute; top: -42px; right: -42px; width: 100px; height: 100px; border-radius: 50%; background: currentColor; filter: blur(48px); opacity: .11; }
.accent-green { color: var(--green); }.accent-blue { color: var(--blue); }.accent-cyan { color: var(--cyan); }.accent-amber { color: var(--amber); }.accent-orange { color: var(--orange); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; color: #4f6879; font-size: .88rem; font-weight: 650; }
.kpi-card strong { display: block; margin-top: 18px; color: var(--text); font-size: 2.25rem; line-height: 1; letter-spacing: -.05em; font-variant-numeric: tabular-nums; }
.kpi-card strong em { margin-left: 6px; color: currentColor; font-size: .96rem; font-style: normal; font-weight: 700; }
.kpi-card > small { display: block; margin-top: 13px; color: var(--muted); font-size: .77rem; }
.mini-badge { min-height: 25px; padding: 0 9px; font-size: .67rem; }
.spark-icon { font-size: 1.1rem; color: currentColor; }
.progress { height: 5px; margin-top: 17px; border-radius: 9px; background: rgba(34,82,108,.09); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0%; border-radius: inherit; background: linear-gradient(90deg, #1ccf77, #64f7b2); transition: width .7s ease; }

.chart-section { padding: 30px; border: 1px solid var(--line); border-radius: 28px; background: rgba(255,255,255,.52); }
.range-switch { display: flex; padding: 4px; gap: 3px; border: 1px solid var(--line); border-radius: 13px; background: rgba(226,239,245,.75); }
.range-switch button { min-height: 38px; padding: 0 15px; border: 0; border-radius: 9px; color: var(--muted); background: transparent; cursor: pointer; font-size: .82rem; font-weight: 700; }
.range-switch button:hover { color: var(--text); }
.range-switch button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.range-switch button.active { color: #fff; background: var(--blue); box-shadow: 0 5px 14px rgba(70,116,216,.2); }

.chart-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(330px, .8fr); gap: 16px; }
.chart-card { padding: 22px; border-radius: 21px; min-width: 0; }
.chart-card-head { min-height: 44px; display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.chart-kicker { color: var(--muted); font-size: .73rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; }
.legend { display: flex; flex-wrap: wrap; justify-content: end; gap: 14px; color: var(--muted); font-size: .74rem; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 3px; }
.legend-power { background: var(--cyan); }.legend-soc { background: var(--green); }
.controller-state { min-height: 28px; padding: 0 10px; }
.chart-wrap { height: 280px; margin-top: 18px; position: relative; }
.chart-wrap.small { height: 238px; }
.chart-wrap canvas { width: 100%; height: 100%; display: block; }
.chart-tooltip { position: absolute; display: none; pointer-events: none; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 10px; color: var(--text); background: rgba(4,12,19,.94); box-shadow: 0 12px 30px rgba(0,0,0,.3); font-size: .72rem; white-space: nowrap; transform: translate(-50%, calc(-100% - 10px)); }
.chart-stats, .detail-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.chart-stats span, .detail-list span { display: grid; padding: 12px 14px; border: 1px solid var(--line); border-radius: 13px; background: rgba(240,247,250,.72); }
.chart-stats small, .detail-list small { color: var(--muted); font-size: .68rem; }
.chart-stats b, .detail-list b { margin-top: 3px; font-size: .84rem; font-variant-numeric: tabular-nums; }

.device-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.device-card { min-height: 82px; padding: 18px 20px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; border-radius: 18px; }
.device-card div { display: grid; }
.device-card b { font-size: .92rem; }
.device-card small, .device-card > span:last-child { color: var(--muted); font-size: .75rem; }
.device-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 6px rgba(140,163,180,.06); }
.device-dot.online { background: var(--green); box-shadow: 0 0 0 6px rgba(50,229,142,.07); }
.device-dot.offline { background: var(--red); box-shadow: 0 0 0 6px rgba(255,100,112,.07); }

.error-toast { position: fixed; left: 50%; bottom: 24px; z-index: 50; transform: translate(-50%, 140%); opacity: 0; max-width: calc(100% - 32px); padding: 13px 17px; border: 1px solid rgba(255,100,112,.3); border-radius: 13px; color: #ffd8dc; background: rgba(75,15,23,.95); box-shadow: var(--shadow); transition: .3s ease; font-size: .85rem; }
.error-toast.visible { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 1050px) {
    .energy-stage { grid-template-columns: repeat(7, minmax(74px, 1fr)); padding-inline: 25px; }
    .flow-node small { display: none; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .chart-grid { grid-template-columns: 1fr; }
    .chart-wrap.small { height: 260px; }
}

@media (max-width: 760px) {
    .topbar { height: 72px; padding-inline: 18px; }
    .sync-text { display: none; }
    main { width: min(100% - 28px, 1440px); padding-top: 34px; }
    .section-heading, .chart-toolbar { align-items: start; flex-direction: column; }
    #clock { display: none; }
    .energy-stage { grid-template-columns: 1fr 1fr; gap: 0 12px; min-height: 0; padding: 22px 16px; }
    .flow-node { min-height: 168px; align-content: center; border-bottom: 1px solid var(--line); }
    .flow-node:nth-of-type(3), .flow-node:nth-of-type(4) { border-bottom: 0; }
    .flow-track { display: none; }
    .node-icon { width: 58px; height: 58px; margin-bottom: 12px; border-radius: 18px; }
    .battery-shell { margin-top: 0; margin-bottom: 18px; transform: scale(.86); }
    .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .kpi-card { min-height: 154px; padding: 18px; }
    .kpi-card strong { font-size: 1.8rem; }
    .chart-section { padding: 20px 14px; margin-inline: -2px; }
    .chart-toolbar { margin-bottom: 16px; }
    .range-switch { width: 100%; }
    .range-switch button { flex: 1; padding-inline: 8px; }
    .chart-card { padding: 18px 12px; }
    .chart-card-head { padding-inline: 5px; }
    .legend { gap: 8px; }
    .chart-wrap, .chart-wrap.small { height: 245px; }
    .chart-stats span, .detail-list span { padding: 10px 8px; }
    .device-grid { grid-template-columns: 1fr; }
}

@media (max-width: 460px) {
    .status-pill { padding: 0 10px; }
    h1 { font-size: 2.15rem; }
    .kpi-grid { grid-template-columns: 1fr; }
    .kpi-card { min-height: 143px; }
    .chart-card-head { flex-direction: column; }
    .legend { justify-content: start; }
    .chart-wrap { margin-top: 12px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
