:root {
    --bg: #0f1117;
    --bg2: #1a1d2e;
    --bg3: #22263a;
    --border: #2e3250;
    --text: #e8eaf6;
    --text2: #9095b8;
    --solar: #f59e0b;
    --battery: #10b981;
    --grid-import: #ef4444;
    --grid-export: #22c55e;
    --home: #6366f1;
    --ups: #8b5cf6;
    --enphase: #06b6d4;
    --deye: #f97316;
    --green: #22c55e;
    --red: #ef4444;
    --yellow: #f59e0b;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    min-height: 100vh;
}

.header {
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}
.header h1 { font-size: 18px; font-weight: 700; letter-spacing: 0.5px; }
.header h1 span { color: var(--solar); }
.status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text2); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); animation: pulse 2s infinite; }
.status-dot.error { background: var(--red); animation: none; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

.tabs {
    display: flex;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
    padding: 10px 20px;
    cursor: pointer;
    white-space: nowrap;
    color: var(--text2);
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    font-weight: 500;
    font-size: 13px;
}
.tab.active { color: var(--text); border-bottom-color: var(--solar); }
.tab:hover:not(.active) { color: var(--text); background: var(--bg3); }

.page { display: none; padding: 16px; max-width: 1240px; margin: 0 auto; }
.page.active { display: block; }

.flow-wrap {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 18px;
}
.flow-title { font-size: 13px; color: var(--text2); margin-bottom: 12px; text-transform: uppercase; letter-spacing: 1px; }
svg.flow { width: 100%; height: auto; display: block; max-height: 400px; }
.flow-line { fill: none; stroke-width: 3; stroke-linecap: round; opacity: 0.16; }
.flow-line.active { opacity: 0.9; animation: dash 1.5s linear infinite; stroke-dasharray: 10 8; }
@keyframes dash { to { stroke-dashoffset: -36; } }

.gauges {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}
.gauge-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 14px;
    text-align: center;
    min-width: 0;
}
.gauge-card .g-label { font-size: 11px; color: var(--text2); margin-top: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.gauge-card .g-sub { font-size: 11px; color: var(--text2); }
svg.gauge { width: 100%; height: auto; display: block; min-height: 180px; }

.totals {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}
.total-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 14px;
    text-align: center;
    min-width: 0;
}
.total-card .t-icon { font-size: 20px; margin-bottom: 6px; }
.total-card .t-label { font-size: 11px; color: var(--text2); }
.total-card .t-value { font-size: 26px; font-weight: 700; margin-top: 6px; line-height: 1.1; word-break: break-word; }

.financials {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}
.fin-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 14px;
    text-align: center;
    min-width: 0;
}
.fin-card .f-label { font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; }
.fin-card .f-value { font-size: 24px; font-weight: 800; margin-top: 4px; }
.fin-card.positive .f-value { color: var(--green); }
.fin-card.negative .f-value { color: var(--red); }
.fin-card.neutral .f-value { color: var(--solar); }
.fin-card .f-sub { font-size: 11px; color: var(--text2); margin-top: 2px; }

.section-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text2);
    margin: 16px 0 10px;
}

.solar-arrays {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.array-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    text-align: center;
    min-width: 0;
}
.array-card .a-name { font-size: 12px; color: var(--text2); margin-bottom: 6px; }
.array-card .a-value { font-size: 22px; font-weight: 700; color: var(--solar); }
.array-card .a-unit { font-size: 11px; color: var(--text2); }
.array-card .a-pct { font-size: 13px; margin-top: 4px; }
.array-card .a-peak { font-size: 11px; color: var(--text2); margin-top: 6px; }
.pct-bar-wrap { background: var(--bg3); border-radius: 4px; height: 6px; margin: 8px 0 4px; overflow: hidden; }
.pct-bar { height: 100%; border-radius: 4px; background: var(--solar); transition: width 0.5s; }

.phase-bars { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.phase-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    text-align: center;
}
.phase-card .p-label { font-size: 11px; color: var(--text2); }
.phase-card .p-value { font-size: 18px; font-weight: 700; margin-top: 4px; }
.phase-card .p-value.importing { color: var(--red); }
.phase-card .p-value.exporting { color: var(--green); }

@media (max-width: 980px) {
    .page { max-width: 980px; }
    .financials { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    svg.flow { max-height: 360px; }
}

@media (max-width: 760px) {
    .gauges, .totals, .solar-arrays, .phase-bars, .financials {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
    .header h1 { font-size: 15px; }
    .flow-wrap { padding: 16px; }
    svg.flow { max-height: none; }
}

@media (max-width: 520px) {
    .gauges, .totals, .solar-arrays, .phase-bars, .financials {
        grid-template-columns: 1fr !important;
    }
}

.refresh-bar {
    height: 2px;
    background: var(--solar);
    position: fixed;
    bottom: 0;
    left: 0;
    transition: width linear;
}
