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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container { max-width: 1400px; margin: 0 auto; }

header {
    background: white; padding: 20px 30px; border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1); margin-bottom: 25px;
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: 15px;
}
.header-left { display: flex; flex-direction: column; gap: 5px; }
h1 { color: #2d3748; font-size: 28px; font-weight: 600; margin: 0; }
.header-stats { display: flex; gap: 20px; font-size: 14px; color: #718096; flex-wrap: wrap; }
.stat-item { display: flex; align-items: center; gap: 5px; }
.stat-value { font-weight: 600; color: #2d3748; }
.status-container { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.status { display: flex; align-items: center; gap: 8px; color: #4a5568; font-size: 14px; }
.uptime { font-size: 12px; color: #a0aec0; text-align: right; }
.last-update { color: #718096; font-size: 13px; }

.status-dot { width: 10px; height: 10px; border-radius: 50%; transition: all 0.3s ease; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes flash { 0%, 50% { opacity: 1; transform: scale(1); } 100% { opacity: 0.3; transform: scale(1.5); } }
.status-dot.green { background: #48bb78; animation: pulse 2s infinite; }
.status-dot.red { background: #f56565 !important; animation: flash 1s infinite !important; box-shadow: 0 0 15px rgba(245,101,101,1) !important; width: 14px !important; height: 14px !important; }

.power-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; margin-bottom: 25px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; margin-bottom: 25px; }

.card { background: white; padding: 20px; border-radius: 12px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); transition: transform 0.2s, box-shadow 0.2s; }
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 12px rgba(0,0,0,0.15); }
.card-title { font-size: 18px; font-weight: 600; color: #718096; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 15px; display: flex; align-items: center; gap: 8px; }
.card-title svg { width: 20px; height: 20px; vertical-align: middle; }

.metrics-row { display: flex; justify-content: space-between; gap: 10px; -ms-overflow-style: none; scrollbar-width: none; }
.metrics-row::-webkit-scrollbar { display: none; }
.metric { flex: 1; text-align: center; min-width: 0; }
.metric-label { font-size: 20px; color: #a0aec0; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric-value { font-size: 24px; font-weight: 700; line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: inline; }
.metric-unit { font-size: 22px; font-weight: 500; color: #718096; margin-left: 2px; display: inline; }
.positive { color: #48bb78; }
.negative { color: #f56565; }
.neutral  { color: #4299e1; }
.zero     { color: #4299e1; }

.chart-card { background: white; padding: 25px; border-radius: 12px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); margin-bottom: 25px; }
.chart-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 15px; }
.chart-header h2 { font-size: 18px; font-weight: 600; color: #2d3748; margin: 0; }
.chart-container { position: relative; height: 300px; }
.time-selector { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.time-option { display: flex; align-items: center; gap: 5px; cursor: pointer; padding: 6px 10px; border-radius: 6px; transition: all 0.2s; background: #f7fafc; border: 1px solid #e2e8f0; font-size: 13px; }
.time-option:hover { background: #edf2f7; }
.time-option.selected { background: #4299e1; color: white; border-color: #4299e1; }
.time-option input { margin: 0; }
.data-info { font-size: 12px; color: #718096; text-align: right; margin-top: 10px; }

.tab-container { margin-bottom: 20px; }
.tabs { display: flex; background: white; border-radius: 12px; padding: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.tab { flex: 1; text-align: center; padding: 12px 16px; cursor: pointer; border-radius: 8px; transition: all 0.3s ease; font-weight: 500; color: #718096; }
.tab:hover { background: #f7fafc; }
.tab.active { background: #4299e1; color: white; box-shadow: 0 2px 4px rgba(66,153,225,0.3); }
.tab-content { display: none; }
.tab-content.active { display: block; }

.hs-button { padding: 12px 20px; border: none; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; transition: all 0.3s ease; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.hs-button:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.15); }
.hs-button:active { transform: translateY(0); }
.hs-button:disabled { opacity: 0.5; cursor: not-allowed; }
.hs-button svg { width: 16px; height: 16px; vertical-align: middle; margin-right: 8px; }
.hs-on { background: linear-gradient(135deg, #48bb78 0%, #38a169 100%); color: white; }
.hs-on:hover:not(:disabled) { background: linear-gradient(135deg, #38a169 0%, #2f855a 100%); }
.hs-off { background: linear-gradient(135deg, #718096 0%, #4a5568 100%); color: white; }
.hs-off:hover:not(:disabled) { background: linear-gradient(135deg, #4a5568 0%, #2d3748 100%); }

#hsStatus { font-size: 14px; text-align: center; font-weight: 500; }
#hsStatus.success { background: #c6f6d5; color: #22543d; }
#hsStatus.error   { background: #fed7d7; color: #c53030; display: block !important; }
#hsStatus.loading { background: #bee3f8; color: #2c5282; display: block !important; }

.error-message { background: #fed7d7; color: #c53030; padding: 15px; border-radius: 8px; margin-bottom: 20px; display: none; }
.loading { display: none; text-align: center; padding: 20px; color: #718096; }

@media (max-width: 768px) {
    body { padding: 10px; }
    h1 { font-size: 22px; }
    .header-stats { gap: 10px; }
    .stat-item { font-size: 12px; }
    
    /* ─── FIX: Make BOTH grids use same column width ─────────────────── */
    .power-grid,
    .grid {
        grid-template-columns: 1fr !important;
        gap: 15px;
    }
    
    /* ─── FIX: Force ALL cards to same max-width ─────────────────── */
    .power-grid .card,
    .grid .card {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }
    
    /* ─── Keep metrics as horizontal scroll (DON'T wrap) ─────────────────── */
    .metrics-row {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 5px;
        gap: 10px;
    }
    
    .metric {
        min-width: 80px;
        flex: 0 0 auto;
    }
    
    /* ─── Slightly smaller text for mobile ─────────────────── */
    .metric-value { font-size: 20px; }
    .metric-label { font-size: 16px; }
    .metric-unit  { font-size: 18px; }
    
    .chart-container { height: 250px; }
    .chart-header { flex-direction: column; align-items: flex-start; }
    .time-selector { width: 100%; justify-content: space-between; }
    .time-option { flex: 1; justify-content: center; text-align: center; padding: 8px 6px; font-size: 12px; }
    .status-container { align-items: flex-start; margin-top: 10px; }
    .card { padding: 15px; }
    .tabs { flex-direction: column; gap: 5px; }
    .tab { padding: 10px; }
    .hs-button { padding: 10px 15px; font-size: 13px; }
}

@media (max-width: 480px) {
    .metric-value { font-size: 18px; }
    .metric-label { font-size: 15px; }
    .metric-unit  { font-size: 16px; }
    .metrics-row  { gap: 5px; }
    .metric { min-width: 70px; }
}
