/* Solar Fleet Dashboard — Dark Theme */

:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-card: #1c2128;
    --border: #30363d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #484f58;
    --accent: #f0883e;
    --accent-glow: rgba(240, 136, 62, 0.15);
    --green: #3fb950;
    --yellow: #d29922;
    --red: #f85149;
    --blue: #58a6ff;
}

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

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

/* ── Header ─────────────────────────────────────────── */

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

header h1 {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-primary);
}

.site-name {
    font-size: 0.85rem;
    color: var(--accent);
    background: var(--accent-glow);
    padding: 4px 12px;
    border-radius: 12px;
    font-weight: 500;
}

nav {
    display: flex;
    gap: 4px;
    background: var(--bg-primary);
    padding: 3px;
    border-radius: 8px;
}

.nav-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

.nav-btn:hover {
    color: var(--text-primary);
}

.nav-btn.active {
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.update-time {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background 0.3s;
}

.status-dot.ok { background: var(--green); box-shadow: 0 0 8px rgba(63,185,80,0.5); }
.status-dot.warn { background: var(--yellow); box-shadow: 0 0 8px rgba(210,153,34,0.5); }
.status-dot.error { background: var(--red); box-shadow: 0 0 8px rgba(248,81,73,0.5); }
.status-dot.offline { background: var(--text-muted); }

/* ── Pages ──────────────────────────────────────────── */

.page {
    display: none;
    padding: 24px;
    max-width: 1400px;
    margin: 0 auto;
}

.page.active {
    display: block;
}

/* ── KPI Cards ──────────────────────────────────────── */

.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    text-align: center;
    transition: border-color 0.2s;
}

.kpi-card:hover {
    border-color: var(--accent);
}

.kpi-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.1;
}

.kpi-unit {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ── Chart ──────────────────────────────────────────── */

.chart-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.chart-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.range-buttons {
    display: flex;
    gap: 4px;
    background: var(--bg-primary);
    padding: 3px;
    border-radius: 6px;
}

.range-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.2s;
}

.range-btn:hover {
    color: var(--text-primary);
}

.range-btn.active {
    background: var(--bg-card);
    color: var(--accent);
}

#powerChart {
    max-height: 350px;
}

/* ── Status Bar ─────────────────────────────────────── */

.status-bar {
    display: flex;
    gap: 32px;
    padding: 16px 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.status-item {
    display: flex;
    gap: 8px;
    align-items: center;
}

.status-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.status-value {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ── Inverter Grid ──────────────────────────────────── */

.inverter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
}

.inv-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

.inv-card:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
}

.inv-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--text-muted);
    transition: background 0.3s;
}

.inv-card.status-ok::before { background: var(--green); }
.inv-card.status-standby::before { background: var(--blue); }
.inv-card.status-warn::before { background: var(--yellow); }
.inv-card.status-error::before { background: var(--red); }
.inv-card.status-fault::before { background: var(--red); }
.inv-card.status-offline::before { background: var(--text-muted); }

.inv-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.inv-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.inv-status {
    font-size: 0.7rem;
    padding: 3px 8px;
    border-radius: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.inv-status.ok { background: rgba(63,185,80,0.15); color: var(--green); }
.inv-status.standby { background: rgba(88,166,255,0.15); color: var(--blue); }
.inv-status.warn { background: rgba(210,153,34,0.15); color: var(--yellow); }
.inv-status.error { background: rgba(248,81,73,0.15); color: var(--red); }
.inv-status.fault { background: rgba(248,81,73,0.15); color: var(--red); }
.inv-status.offline { background: rgba(72,79,88,0.15); color: var(--text-muted); }

.inv-metrics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.inv-metric {
    display: flex;
    flex-direction: column;
}

.inv-metric-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.inv-metric-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.inv-metric-value.power {
    color: var(--accent);
}

/* ── Responsive ─────────────────────────────────────── */

@media (max-width: 768px) {
    header {
        flex-direction: column;
        gap: 12px;
        padding: 12px 16px;
    }

    .page {
        padding: 16px;
    }

    .kpi-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .kpi-value {
        font-size: 1.6rem;
    }

    .status-bar {
        flex-wrap: wrap;
        gap: 16px;
    }

    .inverter-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 8px;
    }

    .inv-card {
        padding: 12px;
    }
}

@media (max-width: 480px) {
    .kpi-row {
        grid-template-columns: 1fr 1fr;
    }
}
