/* ========== 主题变量 ========== */
:root {
  --bg: #0a0e17;
  --panel: #121a29;
  --panel-2: #182236;
  --border: #1f2b42;
  --text: #e6ecf7;
  --muted: #8b96ad;
  --blue: #3b82f6;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 14px;
}

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

html { scrollbar-color: #2a3752 transparent; }

body {
  background:
    radial-gradient(1100px 500px at 85% -10%, rgba(59, 130, 246, 0.08), transparent 60%),
    radial-gradient(900px 420px at 0% 0%, rgba(34, 197, 94, 0.05), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  min-height: 100vh;
}

/* ========== 顶栏 ========== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 26px;
  background: rgba(10, 14, 23, 0.82);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

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

.brand-logo { color: var(--blue); flex: none; }

.brand-name { font-size: 17px; font-weight: 700; letter-spacing: 0.5px; }

.env-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--green);
  border: 1px solid rgba(34, 197, 94, 0.4);
  background: rgba(34, 197, 94, 0.1);
  border-radius: 6px;
  padding: 1px 7px;
  letter-spacing: 1px;
}

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

.search {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 12px;
  color: var(--muted);
  transition: border-color 0.2s;
}
.search:focus-within { border-color: var(--blue); color: var(--blue); }

.search input {
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13px;
  width: 210px;
}
.search input::placeholder { color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.btn:hover { border-color: var(--blue); background: var(--panel-2); }
.btn:active { transform: translateY(1px); }
.btn.spin svg { animation: spin 0.6s linear; }
@keyframes spin { to { transform: rotate(360deg); } }

.live-indicator {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
}

/* ========== 布局 ========== */
.layout {
  max-width: 1380px;
  margin: 0 auto;
  padding: 22px 26px 30px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: linear-gradient(180deg, #141d30, #111826);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.card-head h2, .section-head h2 { font-size: 15px; font-weight: 700; }

.card-sub { font-size: 12px; color: var(--muted); }

/* ========== KPI ========== */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.kpi {
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(180deg, #141d30, #111826);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.kpi-icon {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  font-size: 21px;
  border-radius: 12px;
  flex: none;
}
.kpi-blue  { background: rgba(59, 130, 246, 0.13); }
.kpi-green { background: rgba(34, 197, 94, 0.13); }
.kpi-amber { background: rgba(245, 158, 11, 0.13); }
.kpi-red   { background: rgba(239, 68, 68, 0.13); }

.kpi-num { font-size: 26px; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; }
.kpi-label { font-size: 12px; color: var(--muted); }

/* ========== 图表区 ========== */
.charts {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}

.chart-body { height: 230px; position: relative; }
.chart-body canvas { width: 100%; height: 100%; display: block; }

.donut-wrap {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  padding-top: 6px;
}

.donut { width: 158px; height: 158px; flex: none; }
.donut-num { fill: var(--text); font-size: 26px; font-weight: 800; }
.donut-label { fill: var(--muted); font-size: 11px; }

.donut-legend { display: flex; flex-direction: column; gap: 10px; flex: 1; min-width: 130px; }

.legend-item { display: flex; align-items: center; gap: 9px; font-size: 13px; }

.legend-dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }

.legend-item .legend-name { color: var(--text); }
.legend-item .legend-val { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.legend-item .legend-pct { color: var(--muted); font-size: 12px; width: 42px; text-align: right; }

/* ========== 设备列表 ========== */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.count {
  display: inline-block;
  min-width: 22px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--blue);
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: 999px;
  padding: 0 7px;
  margin-left: 4px;
  vertical-align: 2px;
}

.chips { display: flex; gap: 8px; flex-wrap: wrap; }

.chip {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.18s;
}
.chip:hover { color: var(--text); border-color: #2c3c5e; }
.chip.active { color: var(--blue); border-color: rgba(59, 130, 246, 0.55); background: rgba(59, 130, 246, 0.12); font-weight: 600; }

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 14px;
}

.device-card {
  background: linear-gradient(180deg, #141d30, #111826);
  border: 1px solid var(--border);
  border-left: 3px solid transparent;
  border-radius: 12px;
  padding: 14px 15px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.device-card:hover {
  transform: translateY(-2px);
  border-color: #2c3c5e;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
}
.st-online  { border-left-color: var(--green); }
.st-warning { border-left-color: var(--amber); }
.st-offline { border-left-color: var(--red); }

.device-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.device-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-icon { font-size: 16px; flex: none; }

.badge {
  flex: none;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 9px;
  border: 1px solid;
}
.badge-online  { color: var(--green); background: rgba(34, 197, 94, 0.1);  border-color: rgba(34, 197, 94, 0.4); }
.badge-warning { color: var(--amber); background: rgba(245, 158, 11, 0.1); border-color: rgba(245, 158, 11, 0.4); }
.badge-offline { color: var(--red);   background: rgba(239, 68, 68, 0.1);  border-color: rgba(239, 68, 68, 0.4); }

.device-meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; }

.device-metrics { display: flex; flex-direction: column; gap: 6px; margin-top: 2px; }

.metric { display: grid; grid-template-columns: 34px 1fr 48px; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); }

.metric-bar {
  height: 6px;
  border-radius: 999px;
  background: #1c2740;
  overflow: hidden;
}
.metric-bar i { display: block; height: 100%; border-radius: 999px; transition: width 0.5s ease; }

.metric-val { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }

.spark-wrap { height: 30px; margin-top: 2px; }
.spark { width: 100%; height: 100%; display: block; }

.device-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11.5px;
  color: var(--muted);
  border-top: 1px dashed var(--border);
  padding-top: 9px;
}
.uptime { color: var(--text); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ========== 事件列表 ========== */
.event-list {
  list-style: none;
  max-height: 250px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-right: 4px;
}
.event-list::-webkit-scrollbar { width: 6px; }
.event-list::-webkit-scrollbar-thumb { background: #2a3752; border-radius: 3px; }

.ev { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; font-size: 12.5px; }
.ev:hover { background: rgba(255, 255, 255, 0.03); }

.ev-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.ev-info  .ev-dot { background: var(--green); }
.ev-warn  .ev-dot { background: var(--amber); }
.ev-error .ev-dot { background: var(--red); }

.ev-time { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.ev-msg { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-error .ev-msg { color: #fca5a5; }
.ev-warn .ev-msg { color: #fcd34d; }
.ev-empty { color: var(--muted); text-align: center; padding: 20px 0; }

/* ========== 页脚 ========== */
.footer { text-align: center; color: var(--muted); font-size: 12px; padding-top: 4px; }

/* ========== 响应式 ========== */
@media (max-width: 1080px) {
  .charts { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .layout { padding: 16px 14px 24px; }
  .topbar { padding: 10px 14px; }
  .search input { width: 150px; }
}

@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr; }
  .topbar-actions { width: 100%; }
  .search { flex: 1; }
  .search input { width: 100%; }
}
