/* Solar Dashboard - Dark Theme */

/* CSS Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* CSS Variables */
:root {
    --bg-primary: #0a0a0a;
    --bg-card: #141414;
    --bg-card-hover: #1a1a1a;
    --border-subtle: #222;
    --text-primary: #fff;
    --text-secondary: #888;

    /* Gauge accent colors */
    --yellow: #facc15;
    --cyan: #22d3ee;
    --green: #22c55e;
    --red: #f87171;
    --blue: #60a5fa;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    line-height: 1.5;
    min-height: 100vh;
}

/* Dashboard Layout */
.dashboard {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

.dashboard-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.title-group {
    display: flex;
    align-items: baseline;
    gap: 1rem;
}

.dashboard-title {
    font-size: 1.5rem;
    font-weight: 600;
}

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

.live-dot {
    width: 8px;
    height: 8px;
    background: var(--green);
    border-radius: 50%;
    display: inline-block;
    animation: pulse 2s infinite;
}

.live-dot.stale {
    background: var(--red);
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.2); }
}

/* Power Flow Animation */
.power-flow {
    --flow-speed: 2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding: 1.5rem 2rem;
}

.flow-source,
.flow-target {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    min-width: 80px;
}

.flow-icon {
    font-size: 2rem;
}

.flow-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
}

.flow-value {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--yellow);
}

.flow-target .flow-value {
    color: var(--green);
}

.flow-line-container {
    flex: 1;
    max-width: 300px;
    height: 4px;
    position: relative;
}

.flow-line {
    width: 100%;
    height: 100%;
    background: var(--border-subtle);
    border-radius: 2px;
    position: relative;
    overflow: hidden;
}

.flow-particle {
    position: absolute;
    width: 20px;
    height: 100%;
    background: linear-gradient(90deg, transparent, var(--yellow), transparent);
    border-radius: 2px;
    opacity: 0;
    animation: flowParticle var(--flow-speed) linear infinite;
}

.flow-particle:nth-child(2) {
    animation-delay: calc(var(--flow-speed) / 3);
}

.flow-particle:nth-child(3) {
    animation-delay: calc(var(--flow-speed) / 3 * 2);
}

.power-flow:not(.active) .flow-particle {
    animation: none;
    opacity: 0;
}

@keyframes flowParticle {
    0% {
        left: -20px;
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    90% {
        opacity: 1;
    }
    100% {
        left: 100%;
        opacity: 0;
    }
}

/* Controller Buttons */
.controller-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.controller-btn {
    padding: 0.5rem 1.25rem;
    border-radius: 9999px;
    border: 1px solid var(--border-subtle);
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.controller-btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--text-secondary);
}

.controller-btn.active {
    background: var(--cyan);
    border-color: var(--cyan);
    color: var(--bg-primary);
}

/* Main Content Grid */
.main-content {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

/* Card Component */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 1.25rem;
}

/* Line Chart */
.chart-card {
    min-height: 400px;
    display: flex;
    flex-direction: column;
}

.chart-card canvas {
    width: 100% !important;
    height: 0 !important;
    flex: 1 1 350px;
}

/* Range Buttons */
.range-buttons {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-subtle);
}

.range-btn {
    padding: 0.375rem 1rem;
    border-radius: 9999px;
    border: 1px solid var(--border-subtle);
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.range-btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--text-secondary);
}

.range-btn.active {
    background: var(--yellow);
    border-color: var(--yellow);
    color: var(--bg-primary);
}

/* Gauges Grid */
.gauges-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.gauge-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
}

.gauge-label {
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.gauge-wrapper {
    position: relative;
    width: 100%;
    max-width: 120px;
    aspect-ratio: 2 / 1;
}

.gauge-wrapper canvas {
    width: 100% !important;
    height: auto !important;
}

.gauge-value {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.25rem;
    font-weight: 700;
    text-align: center;
    white-space: nowrap;
}

/* Gauge color accents */
.gauge-card[data-color="yellow"] { border-top: 2px solid var(--yellow); }
.gauge-card[data-color="cyan"] { border-top: 2px solid var(--cyan); }
.gauge-card[data-color="green"] { border-top: 2px solid var(--green); }
.gauge-card[data-color="red"] { border-top: 2px solid var(--red); }
.gauge-card[data-color="blue"] { border-top: 2px solid var(--blue); }

.gauge-card[data-color="yellow"] .gauge-value { color: var(--yellow); }
.gauge-card[data-color="cyan"] .gauge-value { color: var(--cyan); }
.gauge-card[data-color="green"] .gauge-value { color: var(--green); }
.gauge-card[data-color="red"] .gauge-value { color: var(--red); }
.gauge-card[data-color="blue"] .gauge-value { color: var(--blue); }

/* Energy Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    border-left: 3px solid var(--cyan);
}

.stat-icon {
    font-size: 1.5rem;
    opacity: 0.8;
}

.stat-content {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 700;
}

.stat-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

/* Responsive Layout */
@media (max-width: 900px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .gauges-grid {
        order: -1;
        grid-template-columns: repeat(3, 1fr);
    }

    .chart-card {
        min-height: 300px;
    }

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

@media (max-width: 600px) {
    .dashboard {
        padding: 1rem;
    }

    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .title-group {
        flex-direction: column;
        gap: 0.25rem;
    }

    .power-flow {
        padding: 1rem;
    }

    .flow-icon {
        font-size: 1.5rem;
    }

    .flow-value {
        font-size: 1rem;
    }

    .flow-line-container {
        max-width: 120px;
    }

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

    .gauge-wrapper {
        max-width: 100px;
    }

    .gauge-value {
        font-size: 1rem;
    }
}
