:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #e4e9f0;
  --line-strong: #cfd8e3;
  --text: #0d1726;
  --muted: #5b6b80;
  --dim: #5f6f84;
  --accent: #2563eb;
  --accent-2: #0891b2;
  --accent-soft: #eff4ff;
  --ok: #0f766e;
  --warn: #b45309;
  --crit: #dc2626;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 14px 34px -18px rgba(16, 24, 40, 0.22);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

html, body { height: 100%; }

body {
  margin: 0;
  padding: 0 clamp(16px, 3vw, 32px) 40px;
  background:
    radial-gradient(900px 420px at 12% -8%, rgba(37, 99, 235, 0.07), transparent 62%),
    radial-gradient(760px 360px at 96% 0%, rgba(8, 145, 178, 0.06), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
}

header, main, footer, #overview { max-width: 1360px; margin-inline: auto; }

main, #overview, .topbar { position: relative; z-index: 1; }

.bg-grid {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: radial-gradient(rgba(15, 23, 42, 0.055) 1px, transparent 1px);
  background-size: 24px 24px;
  -webkit-mask-image: radial-gradient(circle at 50% 0%, #000 0%, transparent 62%);
  mask-image: radial-gradient(circle at 50% 0%, #000 0%, transparent 62%);
}

/* ---------------- 顶栏 ---------------- */

.topbar {
  position: sticky;
  top: 8px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(16px) saturate(1.1);
  backdrop-filter: blur(16px) saturate(1.1);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.mark {
  width: 36px;
  height: 36px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(135deg, #2563eb 0%, #0e7490 100%);
  box-shadow: 0 7px 16px -6px rgba(37, 99, 235, 0.62), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.brand h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: 0.1px; }
.brand .sub { margin: 3px 0 0; font-size: 11px; color: var(--dim); font-family: var(--mono); }

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

.picker {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}
.picker select {
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 12.5px;
  font-family: var(--mono);
  padding: 2px 4px;
  cursor: pointer;
}
.picker select option { background: var(--surface); color: var(--text); }

.conn {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 6px 12px;
}
.conn .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dim); }
.conn[data-state="live"] { color: var(--ok); border-color: #bfe6de; background: #f0fdfa; }
.conn[data-state="live"] .dot { background: var(--ok); animation: breathe 2.4s ease-in-out infinite; }
.conn[data-state="down"] { color: var(--crit); border-color: #f3c4c4; background: #fff7f7; }
.conn[data-state="down"] .dot { background: var(--crit); }

.clock { font-family: var(--mono); font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------------- 主区 ---------------- */

main { display: grid; gap: 12px; padding-top: 16px; }

.kpis {
  display: grid;
  grid-template-columns: 1.25fr repeat(5, 1fr);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.kpi {
  padding: 16px 18px;
  border-left: 1px solid var(--line);
  min-width: 0;
  background: var(--surface);
}
.kpi:first-child { border-left: 0; }
.kpi .label { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.kpi .value {
  margin-top: 7px;
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.kpi .value.tick { animation: tick 0.18s var(--ease); }
.kpi .sub.down, .kpi .sub.bad { color: var(--warn); }
.kpi .value .unit { font-size: 11px; color: var(--muted); margin-left: 4px; font-weight: 500; }
.kpi .sub { margin-top: 6px; font-size: 10px; color: var(--dim); font-family: var(--mono); }
.kpi .value.na { color: var(--dim); }
.kpi .value[data-kpi="total_w"] { color: var(--accent); }

/* ---------------- 变压器温度 ---------------- */

.temp-panel { padding: 18px 20px; }
.temp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
}
.temp-tile {
  padding: 14px 16px;
  border-left: 1px solid var(--line);
  min-width: 0;
}
.temp-tile:first-child { border-left: 0; }
.temp-tile .label { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.temp-tile .value {
  margin-top: 7px;
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.temp-tile .value .unit { font-size: 11px; color: var(--muted); margin-left: 4px; font-weight: 500; }
.temp-tile .status { margin-top: 6px; font-size: 10.5px; color: var(--dim); }
.temp-tile.warn { background: #fffbeb; }
.temp-tile.warn .value { color: var(--warn); }
.temp-tile.trip { background: #fff5f5; }
.temp-tile.trip .value { color: var(--crit); }

/* ---------------- 面板 ---------------- */

.grid-main { display: grid; grid-template-columns: minmax(0, 1fr) 292px; gap: 12px; align-items: start; }
.grid-bottom { display: grid; grid-template-columns: 1.15fr 1fr; gap: 12px; align-items: start; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.panel-head h2 { margin: 0; font-size: 13.5px; font-weight: 650; letter-spacing: 0.1px; }
.muted { color: var(--dim); font-weight: 400; font-size: 11px; margin-left: 6px; }

.tabs {
  display: flex;
  gap: 3px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 9px;
}
.tabs button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.tabs button:hover { color: var(--text); }
.tabs button.active {
  background: var(--surface);
  border-color: var(--line);
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
}

.chart-wrap { position: relative; height: 260px; }
#chart, #station-chart { width: 100%; height: 100%; display: block; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: 10.5px; color: var(--muted); }
.legend .item { display: flex; align-items: center; gap: 6px; }
.legend .swatch { width: 12px; height: 3px; border-radius: 2px; }

/* ---------------- 图表提示 ---------------- */

.chart-tip {
  position: absolute;
  z-index: 6;
  min-width: 120px;
  padding: 8px 10px;
  border-radius: 9px;
  background: #0f172a;
  color: #fff;
  box-shadow: 0 14px 30px -14px rgba(15, 23, 42, 0.6);
  font: 10px var(--mono);
  pointer-events: none;
  white-space: nowrap;
}
.chart-tip[hidden] { display: none; }
.chart-tip-time { color: #94a3b8; font-size: 9px; letter-spacing: 0.04em; }
.chart-tip-row { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.chart-tip-row i { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.chart-tip-row span { color: #cbd5e1; }
.chart-tip-row b { margin-left: auto; font-weight: 600; color: #fff; }

/* ---------------- 详情抬头 / 右栏 ---------------- */

.kicker {
  font: 700 9px var(--mono);
  letter-spacing: 0.14em;
  color: var(--dim);
  text-transform: uppercase;
}

.device-head {
  display: flex;
  align-items: center;
  gap: 13px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 18px;
}
.device-head .mark { width: 42px; height: 42px; border-radius: 12px; }
.device-title { min-width: 0; }
.device-title .crumb { display: block; font: 9.5px var(--mono); color: var(--dim); margin-bottom: 4px; }
.device-title h2 { margin: 0; font-size: 18px; font-weight: 650; letter-spacing: -0.2px; }
.device-title .meta { display: block; margin-top: 3px; font-size: 10.5px; color: var(--dim); }
.head-right { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}
.pill i { width: 6px; height: 6px; border-radius: 50%; background: var(--dim); }
.pill.live { color: var(--ok); border-color: #bfe6de; background: #f0fdfa; }
.pill.live i { background: var(--ok); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.1); }
.pill.off { color: var(--dim); }

.btn {
  height: 30px;
  padding: 0 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 11.5px;
  cursor: pointer;
}
.btn:hover { border-color: var(--line-strong); color: var(--text); }
.btn.primary { border-color: #c7d9fb; background: var(--accent-soft); color: var(--accent); }

.detail-rail { display: grid; gap: 12px; align-content: start; }
.detail-rail .panel { padding: 16px; }

.ring-wrap { display: flex; align-items: center; gap: 14px; }
.ring { width: 86px; height: 86px; flex: none; }
#health-score { font: 600 18px var(--mono); fill: var(--text); }
.ring-sub { font: 8px var(--mono); fill: var(--dim); letter-spacing: 0.08em; }
.ring-copy b { display: block; font-size: 12.5px; }
.ring-copy span { display: block; margin-top: 4px; font-size: 10px; line-height: 1.55; color: var(--dim); }
.health-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid #f0f4f9;
  font-size: 10.5px;
  color: var(--muted);
}
.health-row:last-child { border-bottom: 0; padding-bottom: 0; }
.health-row b { font: 600 10.5px var(--mono); color: var(--text); }
.health-row b.ok { color: var(--ok); }
.health-row b.warn { color: var(--warn); }
.health-row b.crit { color: var(--crit); }
.health-legend { margin-top: 10px; font: 9px var(--mono); color: var(--dim); letter-spacing: 0.02em; }

.meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.meta-grid .k {
  display: block;
  font: 9px var(--mono);
  letter-spacing: 0.08em;
  color: var(--dim);
  text-transform: uppercase;
}
.meta-grid .v {
  display: block;
  margin-top: 4px;
  font: 600 11px var(--mono);
  color: var(--text);
  word-break: break-all;
}

.rename-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.rename-form label { font: 10px var(--mono); color: var(--dim); text-transform: uppercase; letter-spacing: 0.08em; }
.rename-form input {
  flex: 1 1 180px;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font: 12px var(--sans);
}
.rename-form button {
  padding: 8px 14px;
  border: 0;
  border-radius: 7px;
  background: var(--text);
  color: #fff;
  font: 600 11px var(--sans);
  cursor: pointer;
}
.rename-form button:disabled { opacity: 0.45; cursor: not-allowed; }
.rename-msg { flex: 1 0 100%; min-height: 14px; font: 10.5px var(--sans); color: var(--dim); }
.rename-msg.ok { color: var(--ok); }
.rename-msg.bad { color: #b91c1c; }

.profile-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.profile-form label { font: 10px var(--mono); color: var(--dim); text-transform: uppercase; letter-spacing: 0.08em; }
.profile-form select,
.profile-form input[type="text"] {
  flex: 1 1 150px;
  min-width: 0;
  padding: 8px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font: 12px var(--sans);
}
.profile-form input[type="text"] { min-width: 180px; }
.profile-form button {
  padding: 8px 14px;
  border: 0;
  border-radius: 7px;
  background: var(--text);
  color: #fff;
  font: 600 11px var(--sans);
  cursor: pointer;
}
.profile-form button:disabled { opacity: 0.45; cursor: not-allowed; }
.profile-msg { flex: 1 0 100%; min-height: 14px; font: 10.5px var(--sans); color: var(--dim); }
.profile-msg.ok { color: var(--ok); }
.profile-msg.bad { color: #b91c1c; }

/* ---------------- 待审批 ---------------- */

.pending-open .badge {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin-left: 4px;
  border-radius: 999px;
  background: #b91c1c;
  color: #fff;
  font: 600 10px var(--mono);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(780px, 100%);
  max-height: min(82vh, 720px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px -24px rgba(15, 23, 42, 0.55);
  padding: 18px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-head h2 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.modal-head h2 .badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #b91c1c;
  color: #fff;
  font: 600 10.5px var(--mono);
}
.modal-head .ghost { font-size: 20px; line-height: 1; padding: 2px 8px; }
.modal-sub { margin: 6px 0 14px; font-size: 11.5px; color: var(--muted); }
.pending-list { display: grid; gap: 10px; }
.pending-card {
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
  padding: 12px;
  display: grid;
  gap: 10px;
}
.pending-title { display: flex; align-items: center; gap: 8px; }
.pending-title b { font-size: 13px; }
.pending-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 6px; font-size: 10.5px; color: var(--muted); }
.pending-meta code { font-family: var(--mono); color: var(--text); }
.pending-actions { display: grid; grid-template-columns: minmax(130px, 1fr) minmax(150px, 1.4fr) auto auto; gap: 8px; align-items: end; }
.pending-actions label { display: grid; gap: 4px; font: 10px var(--mono); color: var(--dim); text-transform: uppercase; letter-spacing: 0.06em; }
.pending-actions select,
.pending-actions input {
  min-width: 0;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font: 12px var(--sans);
}
.pending-actions .pending-reason { grid-column: 1 / 4; }
.pending-actions .btn { padding: 8px 14px; }
.pending-msg { grid-column: 1 / -1; min-height: 14px; font: 10.5px var(--sans); color: var(--dim); }
.pending-msg.ok { color: var(--ok); }
.pending-msg.bad { color: #b91c1c; }

@media (max-width: 700px) {
  .pending-actions { grid-template-columns: 1fr 1fr; }
  .pending-actions .pending-reason { grid-column: 1 / -1; }
}

/* ---------------- 登录 / 用户 / 审计 ---------------- */

.user-chip { display: flex; align-items: center; gap: 8px; font-size: 11px; }
.user-chip .muted { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .ghost { padding: 5px 9px; font-size: 11px; }

.auth-card { width: min(380px, 100%); }
.auth-card h2 { margin: 0 0 4px; font-size: 18px; }
.auth-form { display: grid; gap: 12px; }
.auth-form label,
.user-create label { display: grid; gap: 5px; font: 10px var(--mono); color: var(--dim); text-transform: uppercase; letter-spacing: 0.08em; }
.auth-form input,
.user-create input,
.user-create select,
.user-actions select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font: 12px var(--sans);
}
.user-create select:disabled,
.user-actions select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: var(--surface-2);
}
.auth-form .btn { justify-content: center; padding: 10px 14px; }
.auth-msg { min-height: 16px; font: 11px var(--sans); color: var(--muted); }
.auth-msg.bad { color: #b91c1c; }

.user-create {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}
.user-create .btn { align-self: end; }
.user-create .user-msg { grid-column: 1 / -1; min-height: 14px; font: 10.5px var(--sans); }
.user-msg.ok { color: var(--ok); }
.user-msg.bad { color: #b91c1c; }

.user-list { display: grid; gap: 8px; }
.user-row { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 8px; }
.user-main { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; }
.user-main .muted { font-size: 10.5px; }
.role-tag { padding: 1px 7px; border-radius: 999px; background: #e8eef8; color: #1d4ed8; font: 600 9.5px var(--mono); }
.role-tag.admin { background: #fee2e2; color: #b91c1c; }
.role-tag.operator { background: #dcfce7; color: #15803d; }
.role-tag.viewer { background: #eef2f7; color: #475569; }
.user-actions { display: grid; grid-template-columns: 120px minmax(140px, 1fr) auto auto auto; gap: 6px; align-items: center; }
.user-actions .ghost { padding: 6px 9px; font-size: 10.5px; }
.user-row-msg { min-height: 13px; font: 10.5px var(--sans); color: var(--dim); }
.user-row-msg.ok { color: var(--ok); }
.user-row-msg.bad { color: #b91c1c; }

.audit-list { display: grid; gap: 8px; }
.audit-row { border-bottom: 1px solid var(--line); padding: 8px 2px; font-size: 11px; }
.audit-row:last-child { border-bottom: 0; }
.audit-row pre { margin: 5px 0 0; font: 10px var(--mono); color: var(--muted); white-space: pre-wrap; word-break: break-all; }

.alarm-center-card { width: min(1040px, 96vw); max-height: min(88vh, 840px); }
.alarm-filters {
  display: grid;
  grid-template-columns: repeat(6, minmax(110px, 1fr));
  gap: 10px;
  align-items: end;
  margin: 12px 0 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}
.alarm-filters label {
  display: grid;
  gap: 5px;
  font: 10px var(--mono);
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.alarm-filters select,
.alarm-filters input {
  width: 100%;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
}
.alarm-filters .btn { justify-content: center; white-space: nowrap; }
.alarm-history-list { max-height: 56vh; }
.alarm-history-list .alarm { align-items: start; }
.alarm-history-list .meta .status { color: var(--accent); }
.offline-banner {
  margin: 10px auto 0;
  max-width: 1400px;
  padding: 9px 14px;
  border: 1px solid #f0d49a;
  border-radius: 9px;
  background: #fff9e8;
  color: #8a6418;
  font-size: 12px;
}
.stations-card { width: min(760px, 96vw); }
.station-admin-list { display: grid; gap: 6px; }
.station-admin-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 8px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
}
.station-admin-row .devices {
  margin-top: 3px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  line-height: 1.5;
}
.station-admin-row .devices a {
  color: var(--accent);
  text-decoration: none;
}
.station-admin-row .devices a:hover { text-decoration: underline; }
.danger-zone {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid #f0c7c7;
  border-radius: 9px;
  background: #fff8f8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 11px;
  color: var(--muted);
}
.report-card { width: min(920px, 96vw); }
.report-filters { grid-template-columns: repeat(6, minmax(100px, 1fr)); }
.report-summary { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.report-summary .cell {
  flex: 1 1 140px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  background: var(--surface-2);
}
.report-summary .cell b { display: block; font: 16px var(--mono); margin-top: 3px; }
.report-table { overflow: auto; max-height: 52vh; border: 1px solid var(--line); border-radius: 9px; }
.report-table table { width: 100%; border-collapse: collapse; font-size: 12px; }
.report-table th,
.report-table td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; }
.report-table th { position: sticky; top: 0; background: var(--surface-2); font: 10px var(--mono); color: var(--dim); }
.report-table td.num { text-align: right; font-family: var(--mono); }
.report-table tr:last-child td { border-bottom: 0; }
@media (max-width: 700px) {
  .alarm-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .report-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .user-create { grid-template-columns: 1fr; }
  .user-actions { grid-template-columns: 1fr 1fr; }
  .user-chip .muted { max-width: 120px; }
}

/* ---------------- 三相 ---------------- */

.phase-body { display: grid; gap: 16px; }
.phase-group .phase-title { font-size: 10px; color: var(--dim); letter-spacing: 0.1em; margin-bottom: 9px; font-family: var(--mono); text-transform: uppercase; }
.phase-row { display: grid; grid-template-columns: 22px 1fr 76px; align-items: center; gap: 9px; margin-bottom: 8px; }
.phase-row .ph { font-family: var(--mono); font-size: 10.5px; color: var(--dim); }
.bar { height: 7px; border-radius: 4px; background: #edf1f7; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; border-radius: 4px; transition: width 0.3s ease; }
.track { display: block; height: 7px; border-radius: 4px; background: #edf1f7; overflow: hidden; }
.track .fill { display: block; height: 100%; width: 0; border-radius: 4px; transition: width 0.3s ease; }
.track .fill.voltage { background: linear-gradient(90deg, #2563eb, #0891b2); }
.track .fill.current { background: linear-gradient(90deg, #0d9488, #22c55e); }
.phase-row .val { font-family: var(--mono); font-size: 10.5px; text-align: right; font-variant-numeric: tabular-nums; }
.imbalance {
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px solid #f0f4f9;
  display: flex;
  justify-content: space-between;
  font-size: 10.5px;
  color: var(--muted);
}
.imbalance b { font-family: var(--mono); color: var(--text); font-weight: 600; }
.imbalance b.bad { color: var(--warn); }

/* ---------------- 告警与原始报文 ---------------- */

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 10.5px;
  font-family: var(--mono);
  background: #eef2f6;
  color: var(--muted);
  margin-left: 8px;
}
.badge.hot { background: #fdecec; color: var(--crit); }

.ghost {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: 8px;
  padding: 5px 11px;
  font-size: 11px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.ghost:hover { color: var(--text); border-color: var(--line-strong); }
/* 链接形式的 .ghost（如顶栏「大屏」入口）：去掉下划线并保持按钮盒模型 */
a.ghost { display: inline-flex; align-items: center; text-decoration: none; }

.alarm-list { display: grid; gap: 8px; max-height: 260px; overflow: auto; }
.alarm {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-left: 3px solid var(--warn);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--surface);
}
.alarm.critical { border-left-color: var(--crit); }
.alarm .msg { font-size: 12px; }
.alarm .meta { font-size: 10px; color: var(--dim); font-family: var(--mono); margin-top: 4px; }
.alarm .sev {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 9.5px;
  font-weight: 600;
  background: #fdf1e3;
  color: var(--warn);
}
.alarm .sev.critical { background: #fdecec; color: var(--crit); }
.alarm .ack {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--accent);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 10.5px;
  cursor: pointer;
  white-space: nowrap;
}
.alarm .ack:hover { background: var(--accent-soft); border-color: #c7d9fb; }
.empty { color: var(--dim); font-size: 12px; padding: 18px 4px; text-align: center; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 24px 12px;
  text-align: center;
}
.empty-state .ic {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--ok);
  background: #f0fdfa;
  border: 1px solid #bfe6de;
}
.empty-state b { font-size: 12px; }
.empty-state > span:last-child { max-width: 250px; font-size: 10.5px; line-height: 1.6; color: var(--dim); }

.raw-actions { display: flex; align-items: center; gap: 10px; }
.raw-teaser {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font: 10px var(--mono);
  color: var(--dim);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.raw-body { display: grid; gap: 12px; }
.raw-body[hidden] { display: none; }
.regs { display: grid; grid-template-columns: repeat(auto-fill, minmax(126px, 1fr)); gap: 6px; }
.reg {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
  background: var(--surface);
}
.reg b { display: block; color: var(--text); font-weight: 600; font-size: 11.5px; margin-top: 2px; }
.reg .dec { color: var(--accent); font-size: 10px; }

pre#raw-json {
  margin: 0;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 10.5px;
  line-height: 1.55;
  color: var(--muted);
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 20px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 10.5px;
  color: var(--dim);
}
footer code { font-family: var(--mono); color: var(--muted); }

/* ---------------- 多设备总览 ---------------- */

#overview { padding-top: 16px; }
#overview[hidden], #detail[hidden], #back-overview[hidden], #overview-count[hidden] { display: none; }
.picker[hidden] { display: none; }

.overview {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.summary {
  display: grid;
  grid-template-columns: 1.35fr repeat(5, 1fr);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.summary .cell {
  padding: 15px 16px 13px;
  border-left: 1px solid var(--line);
  min-width: 0;
}
.summary .cell:first-child { border-left: 0; }
.summary .label { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.summary .value {
  margin-top: 8px;
  font: 600 27px/1.05 var(--mono);
  letter-spacing: -0.6px;
  font-variant-numeric: tabular-nums;
}
.summary .value small { margin-left: 4px; font: 500 11px var(--sans); color: var(--muted); letter-spacing: 0; }
.summary .hero-cell .value { font-size: 31px; color: var(--accent); }
.summary .value.na { color: var(--dim); }
.summary .value.hot { color: var(--crit); }
.summary .delta { margin-top: 5px; font: 10.5px var(--mono); color: var(--ok); }
.summary .delta.down { color: var(--warn); }
.summary .foot { margin-top: 6px; font: 10px var(--mono); color: var(--dim); }
.summary .foot.bad { color: var(--warn); }

.station-trend-panel .chart-wrap { height: 240px; position: relative; }
.station-trend-panel .sub { display: block; margin-top: 4px; font-size: 10.5px; color: var(--dim); }
.station-trend-panel .sub.retry { color: var(--crit); cursor: pointer; }
.station-trend-panel .sub.retry:hover { text-decoration: underline; }

.chart-stats {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #f0f4f9;
}
.chart-stats div { min-width: 72px; }
.chart-stats .kicker {
  display: block;
  font: 700 9px var(--mono);
  letter-spacing: 0.12em;
  color: var(--dim);
  text-transform: uppercase;
}
.chart-stats b { display: block; margin-top: 4px; font: 600 13px var(--mono); }

.chips {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 9px;
  flex-wrap: wrap;
}
.chips button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 10.5px;
  padding: 4px 9px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.chips button:hover { color: var(--text); }
.chips button.on {
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
}
.chips .chip-sep { width: 1px; height: 16px; background: var(--line); margin: 0 2px; }

.dev-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }

.station-group {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 8px 2px 0;
  padding: 0 0 5px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.3px;
}
.station-group b { color: var(--text); font-size: 13px; font-weight: 650; }
.station-group span { margin-left: auto; color: var(--dim); font-size: 10.5px; }
.station-group[hidden] { display: none; }

.dev-card {
  display: grid;
  gap: 8px;
  padding: 14px 16px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 13px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  cursor: pointer;
  transition: border-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease, opacity 0.2s;
}
.dev-card:hover { border-color: #c7d7ee; transform: translateY(-2px); box-shadow: 0 16px 30px -22px rgba(15, 23, 42, 0.4); }
.dev-card.offline { opacity: 1; background: #fbfcfe; }
.dev-card.offline .dot,
.dev-card.offline .card-spark,
.dev-card.offline .imb { opacity: 0.45; }
.dev-card.offline .dev-power { color: var(--muted); }

.dev-card header { display: flex; align-items: center; gap: 8px; }
.dev-card .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); flex: none; box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.09); }
.dev-card.offline .dot { background: var(--dim); box-shadow: none; }
.dev-card .name { font-size: 12.5px; font-weight: 650; letter-spacing: 0.2px; }
.dev-card .dev-station {
  font: 9.5px var(--mono);
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.02em;
}
.dev-card .dev-ip {
  font: 9.5px var(--mono);
  color: #31527a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.02em;
}
.dev-card .dev-ip[hidden] { display: none; }

.dev-card .vals {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.dev-card .vals i { font-style: normal; font-size: 10px; color: var(--dim); margin-left: 2px; }

.card-chart { width: 100%; height: 120px; display: block; }

.dev-card footer {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 10.5px;
  color: var(--dim);
  min-height: 16px;
  margin: 0;
  padding: 0;
  border: 0;
}
.dev-card footer b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.dev-card footer b.bad { color: var(--warn); }

.dev-card { gap: 7px; padding: 12px 12px 10px; }
.dev-card .badge {
  margin-left: auto;
  min-width: 0;
  height: auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  font: 9.5px var(--mono);
  color: var(--ok);
}
.dev-card .badge.off { color: var(--dim); }
.dev-card .meter-badge {
  margin-left: 4px;
  padding: 1px 5px;
  border-radius: 999px;
  background: #fff4e5;
  border: 1px solid #fcd9a8;
  color: #b45309;
  font: 9px var(--sans);
  white-space: nowrap;
}
.dev-card .meter-badge[hidden] { display: none; }
.dev-card .name-conflict-badge {
  margin-left: 4px;
  padding: 1px 5px;
  border-radius: 999px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  font: 9px var(--sans);
  white-space: nowrap;
}
.dev-card .name-conflict-badge[hidden] { display: none; }
.dev-power { font: 600 21px/1 var(--mono); letter-spacing: -0.4px; font-variant-numeric: tabular-nums; }
.dev-power small { margin-left: 3px; font: 500 9.5px var(--sans); color: var(--dim); letter-spacing: 0; }
.dev-card .card-spark { width: 100%; height: 34px; display: block; margin: 6px 0 5px; }
.dev-foot { display: flex; justify-content: space-between; gap: 6px; font: 9.5px var(--mono); color: var(--dim); white-space: nowrap; }
.dev-card .imb { height: 3px; border-radius: 2px; background: #edf1f7; overflow: hidden; margin-top: 1px; }
.dev-card .imb i { display: block; height: 100%; width: 0; border-radius: 2px; background: linear-gradient(90deg, #2563eb, #0891b2); transition: width 0.3s ease; }

.alarm-badge {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  background: var(--warn);
}
.alarm-badge.critical { background: var(--crit); }

/* 路由提示（未知设备等） */
.route-notice {
  max-width: 1360px;
  margin: 10px auto 0;
  padding: 10px 14px;
  border: 1px solid #f3d8b5;
  background: #fffbeb;
  color: #92400e;
  border-radius: var(--radius-sm);
  font-size: 12px;
}
.route-notice[hidden] { display: none; }

/* ---------------- 动效 ---------------- */

@keyframes breathe {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes tick {
  0% { background: var(--accent-soft); }
  100% { background: transparent; }
}

main > section, #overview > * { animation: rise 0.42s var(--ease) both; }
main > section:nth-child(2), #overview > *:nth-child(2) { animation-delay: 0.04s; }
main > section:nth-child(3), #overview > *:nth-child(3) { animation-delay: 0.08s; }
main > section:nth-child(4) { animation-delay: 0.12s; }

/* ---------------- 响应式 ---------------- */

@media (max-width: 1180px) {
  .grid-main, .grid-bottom { grid-template-columns: 1fr; }
  .detail-rail { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-wrap { height: 240px; }
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .kpi:nth-child(4) { border-left: 0; }
  .kpi:nth-child(n + 4) { border-top: 1px solid var(--line); }
}

@media (max-width: 1020px) {
  .summary { grid-template-columns: repeat(3, 1fr); }
  .summary .cell:nth-child(4) { border-left: 0; }
  .summary .cell:nth-child(n + 4) { border-top: 1px solid var(--line); }
  .dev-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .topbar { gap: 12px; }
  .topbar-right { gap: 10px; }
}

@media (max-width: 700px) {
  .summary { grid-template-columns: repeat(2, 1fr); }
  .summary .cell:nth-child(3) { border-left: 0; }
  .summary .cell:nth-child(n + 3) { border-top: 1px solid var(--line); }
  .dev-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-rail { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .topbar {
    top: 0;
    border-radius: 0;
    margin-inline: calc(-1 * clamp(16px, 3vw, 32px));
    padding-inline: clamp(16px, 3vw, 32px);
    background: var(--surface);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .clock { display: none; }
  .brand .sub { display: none; }
  .topbar-right { width: 100%; }
  .picker { flex: 1; }
  .picker select { font-size: 16px; }
}

@media (max-width: 640px) {
  body { padding: 0 16px 24px; }
  .brand h1 { font-size: 15px; }
  .panel { padding: 14px 14px; }
  .chart-wrap { height: 220px; }
  .kpis {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
  }
  .kpi {
    background: var(--surface);
    border: 1px solid var(--line) !important;
    border-radius: 10px;
    padding: 12px;
  }
  .kpi .value { font-size: 21px; }
  .overview { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .clock { display: none; }
  .brand .sub { display: none; }
  .topbar-right { width: 100%; }
  .picker { flex: 1; }
  .picker select { font-size: 16px; }
  .dev-grid { grid-template-columns: 1fr; }
}

@media (pointer: coarse) {
  .tabs button, .ghost, .alarm .ack, .picker, .btn, .chips button, .dev-card { min-height: 44px; }
  .picker select { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
/* 摄像头实时监控板块 */
.camera-panel .panel-head { display: flex; align-items: center; justify-content: space-between; }
.camera-live { display: flex; align-items: center; gap: 6px; color: #f55; font-size: 13px; font-weight: 600; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #f55; animation: cam-pulse 1.2s ease-in-out infinite; }
@keyframes cam-pulse { 0%,100%{opacity:1} 50%{opacity:.3} }
.camera-viewport { position: relative; width: 100%; aspect-ratio: 16/9; background: #0a0e17; border-radius: 10px; overflow: hidden; border: 1px solid rgba(255,255,255,.08); }
.camera-placeholder { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; }
#camera-video { display: block; }
.camera-icon { font-size: 48px; opacity: .4; }
.camera-text { font-size: 18px; color: rgba(255,255,255,.35); letter-spacing: 2px; }
.camera-sub { font-size: 13px; color: rgba(255,255,255,.2); }
.camera-overlay { position: absolute; top: 12px; left: 16px; right: 16px; display: flex; justify-content: space-between; pointer-events: none; }
.camera-timestamp { font-family: 'Courier New', monospace; font-size: 13px; color: rgba(255,255,255,.6); background: rgba(0,0,0,.35); padding: 2px 8px; border-radius: 4px; }
.camera-label { font-size: 13px; color: rgba(255,255,255,.5); background: rgba(0,0,0,.35); padding: 2px 8px; border-radius: 4px; }
/* CCTV 监控效果 */
.cctv-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }
