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

/* --- Root Variables (Light Theme) --- */
:root {
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    
    --bg-main: #f8fafc; /* Very Light Gray */
    --bg-header: #ffffff;
    --bg-card: #ffffff;
    
    --border-color: #e2e8f0; /* Light Gray Border */
    
    --text-primary: #1e293b; /* Dark Blue-Gray */
    --text-secondary: #64748b; /* Medium Gray */
    
    --color-r: #e53e3e;
    --color-y: #f6ad55;
    --color-b: #3182ce;
    
    --color-green: #38a169;
    --color-yellow: #f59e0b;
    --color-purple: #8b5cf6;
    --color-blue: #3b82f6;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --transition: all 0.2s ease-in-out;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-main);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.dashboard-wrapper {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* --- Header --- */
.dashboard-header {
    background: var(--bg-header);
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.datetime {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-weight: 600;
    flex-shrink: 0;
}
.datetime span:first-child {
    font-size: 1.1rem;
    color: var(--text-primary);
    white-space: nowrap;
}
.datetime span:last-child {
    font-size: 0.875rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: #e6fef2;
    color: var(--color-green);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 600;
    flex-shrink: 0;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--color-green);
    animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.back-btn {
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 600;
    padding: 0.5rem 1rem;
    background-color: var(--bg-main);
    border-radius: 8px;
    transition: var(--transition);
    text-decoration: none;
    border: 1px solid var(--border-color);
    flex-shrink: 0;
    white-space: nowrap;
}
.back-btn:hover {
    color: var(--text-primary);
    background-color: #f0f2f5;
}

/* --- Main Content Grid --- */
.dashboard-grid {
    flex: 1;
    padding: 1.5rem;
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 1.5rem;
    align-items: start;
}

.card {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Row 1: 3 Gauges */
.gauge-card { grid-column: span 4; }

/* Row 2: Chart (FULL WIDTH) */
.chart-card { grid-column: span 12; }

/* Row 3: Voltage Grid + Details */
.voltage-grid-card { grid-column: span 7; }
.details-card { grid-column: span 5; }

/* Row 4: Power Gauges + Info + Freq */
.power-gauges-card { grid-column: span 4; }
.voltage-info-card { grid-column: span 4; }
.freq-card { grid-column: span 4; }

/* Row 5: Summaries */
.summary-card { grid-column: span 4; }

/* --- Gauge Cards (R, Y, B) --- */
.gauge-card .card-title { margin-bottom: 0; }
.gauge-circle {
    position: relative;
    width: 100%;
    max-width: 200px;
    height: auto;
    margin: 0 auto;
}
.gauge-circle svg { width: 100%; height: 100%; }
.gauge-bg {
    fill: none;
    stroke: #eef2f9;
    stroke-width: 14;
}
.gauge-progress {
    fill: none;
    stroke-width: 14;
    stroke-linecap: round;
    stroke-dasharray: 565.48;
    stroke-dashoffset: 0;
    transform: rotate(-90deg);
    transform-origin: 50% 50%;
    transition: stroke-dashoffset 0.5s ease;
}
.gauge-circle.r-phase .gauge-progress { stroke: var(--color-r); }
.gauge-circle.y-phase .gauge-progress { stroke: var(--color-y); }
.gauge-circle.b-phase .gauge-progress { stroke: var(--color-b); }
.gauge-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
.gauge-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* --- Chart Card --- */
.chart-container {
    height: 350px;
    position: relative;
}

/* --- Power Gauges Card --- */
.power-gauges-wrapper {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding-top: 1rem;
    flex: 1;
}
.circular-gauge {
    position: relative;
    width: 100px;
    height: 100px;
    text-align: center;
}
.circular-gauge svg { width: 100%; height: 100%; }
.gauge-ring {
    fill: none;
    stroke: #eef2f9;
    stroke-width: 10;
}
.gauge-fill {
    fill: none;
    stroke-width: 10;
    stroke-linecap: round;
    stroke-dasharray: 283;
    stroke-dashoffset: 283;
    transform: rotate(-90deg);
    transform-origin: 50% 50%;
    transition: stroke-dashoffset 0.5s ease;
}

.circular-gauge.r-power .gauge-fill { stroke: var(--color-r); }
.circular-gauge.y-power .gauge-fill { stroke: var(--color-y); }
.circular-gauge.b-power .gauge-fill { stroke: var(--color-b); }

.gauge-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
.gauge-center .gauge-value { font-size: 1.25rem; font-weight: 700; }
.gauge-unit { font-size: 0.8rem; color: var(--text-secondary); }

/* --- Voltage Grid Card --- */
.voltage-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}
.voltage-card {
    background-color: var(--bg-main);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    text-align: center;
}
.voltage-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}
.voltage-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* --- Details Card --- */
.details-card {
    flex: 1;
}
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    height: 100%;
}
.metric-box {
    background-color: var(--bg-main);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.metric-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}
.status-dot-small.blue {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-blue);
}

/* --- Small Info Cards --- */
.voltage-info-card, .freq-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    flex: 1;
}
.value-highlight {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}
.sub-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}
.frequency-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--color-blue);
    line-height: 1.2;
}

/* --- Summary Cards --- */
.summary-card {
    padding: 1.5rem;
    border-radius: 12px;
    text-align: center;
    color: white;
    box-shadow: var(--shadow-md);
    justify-content: center;
}
.summary-label {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.9;
    margin-bottom: 10px;
}
.summary-value {
    font-size: 2.25rem;
    font-weight: 800;
}
.summary-total {
    background: linear-gradient(135deg, var(--color-blue) 0%, #1d4ed8 100%);
}
.summary-pf {
    background: linear-gradient(135deg, var(--color-yellow) 0%, #d97706 100%);
}
.summary-freq {
    background: linear-gradient(135deg, var(--color-purple) 0%, #6d28d9 100%);
}

/* --- Responsive Styles --- */
@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: repeat(6, 1fr);
    }
    
    .gauge-card { grid-column: span 2; }
    .chart-card { grid-column: span 6; }
    
    .power-gauges-card { grid-column: span 6; }
    .voltage-grid-card { grid-column: span 6; }
    .details-card { grid-column: span 6; }
    .voltage-info-card { grid-column: span 3; }
    .freq-card { grid-column: span 3; }
    .summary-card { grid-column: span 2; }

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

@media (max-width: 768px) {
    .dashboard-wrapper {
        padding: 0;
    }
    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        border-radius: 0;
        position: static;
    }
    .header-right {
        width: 100%;
        flex-wrap: wrap;
        gap: 1rem;
    }
    .datetime { align-items: flex-start; }
    .back-btn { width: 100%; text-align: center; }

    .dashboard-grid {
        padding: 1rem;
        grid-template-columns: 1fr;
    }
    
    .card,
    .gauge-card,
    .chart-card,
    .power-gauges-card,
    .voltage-grid-card,
    .details-card,
    .voltage-info-card,
    .freq-card,
    .summary-card {
        grid-column: span 1 !important;
        height: auto;
    }
    
    .chart-container { height: 250px; }
    
    .gauge-container {
        display: flex;
        flex-direction: row;
        justify-content: space-around;
        gap: 1rem;
    }
    .gauge-circle {
        width: 100px;
        height: 100px;
    }
    .gauge-value {
        font-size: 1.25rem;
    }

    .voltage-grid { grid-template-columns: repeat(2, 1fr); }
    .metrics-grid { grid-template-columns: 1fr; }
    
    .power-gauges-wrapper {
        flex-direction: row;
        justify-content: space-around;
    }
    .circular-gauge { width: 80px; height: 80px; }
    .gauge-center .gauge-value { font-size: 1rem; }
}
