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

/* ── Design tokens — light ────────────────────────────────────────── */
:root {
  --bg:            #F3F6FB;
  --surface:       #FFFFFF;
  --surface2:      #EBF0F8;
  --border:        #CDD6E5;
  --text:          #18243C;
  --text-muted:    #5E6E88;
  --text-faint:    #8A9BB8;

  --accent:        #C07810;
  --accent-dim:    rgba(192, 120, 16, 0.10);

  --online:        #1A7840;
  --online-bg:     rgba(26, 120, 64, 0.09);
  --offline:       #AF2B2B;
  --offline-bg:    rgba(175, 43, 43, 0.09);
  --warn:          #9A5500;
  --warn-bg:       rgba(154, 85, 0, 0.09);

  --header-bg:     #18243C;
  --header-text:   #E0EAF8;
  --header-muted:  #7A90B0;

  --shadow-sm:     0 1px 3px rgba(18, 36, 60, .07), 0 1px 6px rgba(18, 36, 60, .04);
  --radius:        6px;
}

/* ── Dark theme ───────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:           #0A1018;
    --surface:      #0F1825;
    --surface2:     #0D1520;
    --border:       #1B2840;
    --text:         #C5D4EA;
    --text-muted:   #5E7090;
    --text-faint:   #344A66;
    --header-bg:    #060D18;
    --shadow-sm:    0 1px 3px rgba(0,0,0,.30), 0 1px 6px rgba(0,0,0,.20);
  }
}

:root[data-theme="dark"] {
  --bg:           #0A1018;
  --surface:      #0F1825;
  --surface2:     #0D1520;
  --border:       #1B2840;
  --text:         #C5D4EA;
  --text-muted:   #5E7090;
  --text-faint:   #344A66;
  --header-bg:    #060D18;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.30), 0 1px 6px rgba(0,0,0,.20);
}

/* ── Base ─────────────────────────────────────────────────────────── */
body {
  font-family: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ───────────────────────────────────────────────────────── */
.header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 52px;
  border-bottom: 1px solid rgba(255,255,255,.04);
}

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

.header-icon {
  width: 34px;
  height: 34px;
  background: var(--accent);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.header-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--header-text);
  letter-spacing: .1px;
}

.header-meta {
  font-size: 11.5px;
  color: var(--header-muted);
  letter-spacing: .15px;
}

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

.weather-badge {
  font-size: 12px;
  color: var(--header-muted);
}

.badge-online {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(26,120,64,.20);
  color: #4CD47A;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: .15px;
}

.badge-online::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4CD47A;
  animation: pulse 2.2s infinite;
  flex-shrink: 0;
}

@keyframes pulse { 0%,100% { opacity:1 } 50% { opacity:.3 } }

.theme-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,.14);
  color: var(--header-muted);
  border-radius: 5px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: border-color .15s, color .15s;
}

.theme-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.theme-btn-icon svg {
  display: block;
  width: 13px;
  height: 13px;
}

/* ── Tab bar ──────────────────────────────────────────────────────── */
.tabs-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  overflow-x: auto;
  white-space: nowrap;
  display: flex;
}

.tabs-bar::-webkit-scrollbar { height: 2px; }
.tabs-bar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 1px; }

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 16px;
  height: 44px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: transparent;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
  letter-spacing: .1px;
}

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

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Layout ───────────────────────────────────────────────────────── */
.page {
  padding: 20px 24px;
  max-width: 1400px;
  margin: 0 auto;
}

/* ── KPI grid ─────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid transparent;
  border-radius: var(--radius);
  padding: 13px 15px 15px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.kpi-card.accent { border-left-color: var(--accent); }
.kpi-card.green  { border-left-color: var(--online); }
.kpi-card.warn   { border-left-color: var(--warn); }
.kpi-card.red    { border-left-color: var(--offline); }

.kpi-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.kpi-icon {
  width: 26px;
  height: 26px;
  border-radius: 5px;
  background: var(--surface2);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.kpi-icon svg { width: 14px; height: 14px; }

.kpi-card.accent .kpi-icon { background: var(--accent-dim); color: var(--accent); }
.kpi-card.green  .kpi-icon { background: var(--online-bg);  color: var(--online); }
.kpi-card.warn   .kpi-icon { background: var(--warn-bg);    color: var(--warn); }
.kpi-card.red    .kpi-icon { background: var(--offline-bg); color: var(--offline); }

.kpi-label {
  font-size: 10.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .55px;
  font-weight: 600;
  line-height: 1.2;
}

.kpi-value {
  font-size: 26px;
  font-weight: 500;
  font-family: 'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;
  color: var(--text);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.5px;
}

.kpi-unit {
  font-size: 12px;
  font-weight: 400;
  font-family: 'IBM Plex Sans', inherit;
  color: var(--text-muted);
  letter-spacing: 0;
  margin-left: 3px;
}

/* ── Cards ────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
  overflow: hidden;
}

.card-header {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-header-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.card-header-sub {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 2px;
}

.card-body { padding: 16px 18px; }

/* ── Chart grid ───────────────────────────────────────────────────── */
.chart-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

@media (max-width: 720px) { .chart-grid { grid-template-columns: 1fr; } }

.chart-wrap { position: relative; width: 100%; }
.chart-wrap canvas { width: 100% !important; max-height: 300px; }

/* ── Last updated ─────────────────────────────────────────────────── */
.last-updated {
  font-size: 11px;
  color: var(--text-faint);
  text-align: right;
  margin-top: -8px;
  margin-bottom: 4px;
}

/* ── Tables ───────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }

thead th {
  text-align: left;
  padding: 9px 16px;
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .55px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }

.table-loading {
  text-align: center;
  color: var(--text-muted);
  padding: 24px !important;
}

/* ── Badges ───────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .15px;
}

.badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}

.badge-on  { background: var(--online-bg);  color: var(--online); }
.badge-on::before  { background: var(--online); }
.badge-off { background: var(--offline-bg); color: var(--offline); }
.badge-off::before { background: var(--offline); }
.badge-warn{ background: var(--warn-bg);    color: var(--warn); }
.badge-warn::before{ background: var(--warn); }

/* ── Electrical detail ────────────────────────────────────────────── */
.elec-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

@media (max-width: 640px) { .elec-grid { grid-template-columns: 1fr; } }

.elec-title {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .55px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.gauge-bar-wrap { display: flex; align-items: center; gap: 8px; }
.gauge-bar { height: 4px; background: var(--border); border-radius: 2px; flex: 1; overflow: hidden; }
.gauge-fill { height: 100%; border-radius: 2px; background: var(--accent); transition: width .6s; }

.loading-text { font-size: 13px; color: var(--text-muted); }

/* ── Events ───────────────────────────────────────────────────────── */
.event-list { list-style: none; }

.event-item {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.event-item:last-child { border-bottom: none; }

.event-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
  flex-shrink: 0;
  margin-top: 5px;
}

.event-dot.info  { background: #2878C8; }
.event-dot.fault { background: var(--offline); }

.event-msg  { font-size: 13px; color: var(--text); line-height: 1.4; }
.event-meta { font-size: 11px; color: var(--text-muted); margin-top: 3px; }

.event-source {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
}

/* ── Empty state ──────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state svg {
  width: 36px;
  height: 36px;
  margin-bottom: 12px;
  opacity: .3;
  display: block;
  margin-inline: auto;
}

.empty-state-msg {
  font-size: 14px;
  font-weight: 500;
}

/* ── Skeleton ─────────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, var(--surface2) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}

@keyframes shimmer { 0% { background-position: 200%; } 100% { background-position: -200%; } }

/* ── Error banner ─────────────────────────────────────────────────── */
.error-banner {
  background: var(--offline-bg);
  border: 1px solid var(--offline);
  border-radius: var(--radius);
  padding: 12px 16px;
  color: var(--offline);
  font-size: 13px;
  margin-bottom: 16px;
  font-weight: 500;
}

/* ── Insights panel ───────────────────────────────────────────────── */
.insights-panel {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.insight-card {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 11px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}

.insight-card.positive { border-left: 3px solid var(--online); }
.insight-card.warning  { border-left: 3px solid var(--warn); }
.insight-card.info     { border-left: 3px solid #2878C8; }

.insight-icon {
  width: 28px;
  height: 28px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.insight-card.positive .insight-icon { background: var(--online-bg);  color: var(--online); }
.insight-card.warning  .insight-icon { background: var(--warn-bg);    color: var(--warn); }
.insight-card.info     .insight-icon { background: rgba(40,120,200,.09); color: #2878C8; }

.insight-icon svg { width: 14px; height: 14px; }

.insight-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .55px;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.insight-card.positive .insight-title { color: var(--online); }
.insight-card.warning  .insight-title { color: var(--warn); }
.insight-card.info     .insight-title { color: #2878C8; }

.insight-text {
  font-size: 12.5px;
  color: var(--text);
  line-height: 1.45;
}

/* ── Refresh indicator ────────────────────────────────────────────── */
.refresh-indicator {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  margin-left: 6px;
  opacity: 0;
  transition: opacity .3s;
  vertical-align: middle;
}

.refresh-indicator.active { opacity: 1; }

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 500px) {
  .header  { padding: 0 16px; }
  .tabs-bar { padding: 0 12px; }
  .tab-btn { padding: 0 12px; font-size: 12px; gap: 5px; height: 42px; }
  .page    { padding: 14px 16px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .kpi-value { font-size: 22px; }
  .card-header { padding: 11px 14px; }
  .card-body   { padding: 14px; }
}
