:root {
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* 暗色默认配色 */
  --bg-body: #090c10;
  --bg-card: rgba(18, 24, 34, 0.75);
  --bg-card-hover: rgba(26, 34, 48, 0.85);
  --bg-card-solid: #121822;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(59, 130, 246, 0.35);

  --text-main: #f0f6fc;
  --text-muted: #8b949e;
  --text-dim: #545d68;

  --accent-temp: #f59e0b;
  --accent-humid: #06b6d4;
  --accent-blue: #3b82f6;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --accent-purple: #8b5cf6;

  --glow-1: rgba(6, 182, 212, 0.12);
  --glow-2: rgba(139, 92, 246, 0.12);
  --shadow-card: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
}

[data-theme="light"] {
  --bg-body: #f4f6fa;
  --bg-card: rgba(255, 255, 255, 0.9);
  --bg-card-hover: #ffffff;
  --bg-card-solid: #ffffff;
  --border-subtle: rgba(15, 23, 42, 0.08);
  --border-highlight: rgba(37, 99, 235, 0.3);

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-dim: #94a3b8;

  --glow-1: rgba(37, 99, 235, 0.06);
  --glow-2: rgba(6, 182, 212, 0.06);
  --shadow-card: 0 8px 20px rgba(0, 0, 0, 0.04);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.mono {
  font-family: var(--font-mono);
}

/* 背景光晕装饰 */
.ambient-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(140px);
  z-index: -1;
  pointer-events: none;
}
.glow-1 {
  width: 550px;
  height: 550px;
  background: var(--glow-1);
  top: -120px;
  right: -100px;
}
.glow-2 {
  width: 500px;
  height: 500px;
  background: var(--glow-2);
  bottom: 5%;
  left: -120px;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

/* 顶部导航 */
.topbar {
  position: sticky;
  top: 0;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  background: rgba(9, 12, 16, 0.8);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 100;
  transition: background-color 0.3s ease;
}

[data-theme="light"] .topbar {
  background: rgba(244, 246, 250, 0.85);
}

.topbar-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 74px;
}

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

.brand-pulse {
  width: 12px;
  height: 12px;
  background-color: var(--accent-green);
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulse-ring 2s infinite;
}

@keyframes pulse-ring {
  0% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.brand-info h1 {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-info .sub {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
}

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

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
}

.indicator-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent-green);
}

.action-btn, .icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.action-btn {
  padding: 8px 16px;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 600;
}

.icon-btn {
  width: 40px;
  height: 40px;
}

.action-btn:hover, .icon-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-highlight);
  transform: translateY(-1px);
}

.action-btn svg, .icon-btn svg {
  width: 18px;
  height: 18px;
}

.sun-icon { display: none; }
.moon-icon { display: block; }

[data-theme="light"] .sun-icon { display: block; }
[data-theme="light"] .moon-icon { display: none; }

/* 主看板布局 */
.dashboard-main {
  padding: 32px 24px 60px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* 指标卡片网格 */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 22px;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: all 0.2s ease;
}

.metric-card:hover {
  border-color: var(--border-highlight);
  transform: translateY(-2px);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.card-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
}

.badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-temp { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.badge-humid { background: rgba(6, 182, 212, 0.15); color: #22d3ee; }
.badge-shield { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.badge-cloud { background: rgba(139, 92, 246, 0.15); color: #a78bfa; }

.metric-body {
  margin: 8px 0 16px;
}

.metric-value {
  font-size: 2.6rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.03em;
  font-family: var(--font-mono);
}

.metric-value .unit {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-left: 4px;
}

.state-text {
  font-size: 1.7rem;
  display: flex;
  align-items: center;
  gap: 12px;
}

.pulse-circle {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent-blue);
}

.metric-trend {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 8px;
}

.card-foot {
  font-size: 0.78rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border-subtle);
  padding-top: 10px;
}

/* 系统运行统计 */
.system-stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.85rem;
}

.stat-row {
  display: flex;
  justify-content: space-between;
}

.stat-label {
  color: var(--text-muted);
}

.stat-val {
  font-weight: 500;
}

.highlight {
  color: var(--accent-green);
}

/* 面板通用样式 */
.dashboard-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 18px;
  padding: 24px;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-card);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.panel-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.panel-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* 多防区卡片 (浴室 Bathroom / 卧室 Bedroom / 玄关 Entrance) */
.nodes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.node-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: all 0.2s ease;
}

.node-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-highlight);
  transform: translateY(-2px);
}

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

.node-icon {
  font-size: 1.6rem;
}

.node-names {
  flex-grow: 1;
}

.node-names h4 {
  font-size: 1rem;
  font-weight: 700;
}

.node-id {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.node-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  border-top: 1px dashed var(--border-subtle);
  padding-top: 10px;
}

.node-event {
  color: var(--text-main);
  font-weight: 500;
}

.node-time {
  font-size: 0.76rem;
  color: var(--text-muted);
}

/* 图表区 */
.chart-legend-box {
  display: flex;
  gap: 16px;
  font-size: 0.85rem;
  font-weight: 500;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot-temp { background-color: var(--accent-temp); }
.dot-humid { background-color: var(--accent-humid); }

.chart-wrapper {
  position: relative;
  height: 300px;
  width: 100%;
}

/* 筛选按钮 */
.filter-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.08);
}

.filter-btn.active {
  background: var(--accent-blue);
  color: #fff;
  border-color: var(--accent-blue);
}

/* 表格样式 */
.table-tag {
  font-size: 0.78rem;
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.05);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

.table-container {
  overflow-x: auto;
}

.events-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.events-table th {
  padding: 12px 16px;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.82rem;
  text-transform: uppercase;
}

.events-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.events-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

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

/* 状态药丸标签 */
.node-pill, .event-pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
}

.pill-alarm {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.pill-motion {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.pill-arm {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.pill-disarm {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.pill-online {
  background: rgba(139, 92, 246, 0.15);
  color: #c084fc;
  border: 1px solid rgba(139, 92, 246, 0.3);
}

.pill-offline {
  background: rgba(100, 116, 139, 0.15);
  color: #94a3b8;
  border: 1px solid rgba(100, 116, 139, 0.3);
}

/* 页脚 */
.footer {
  border-top: 1px solid var(--border-subtle);
  padding: 30px 0;
  margin-top: 20px;
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.footer-content code {
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 6px;
  border-radius: 4px;
}

/* 旋转动画 */
.rotating {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@media (max-width: 768px) {
  .topbar-content {
    flex-direction: column;
    height: auto;
    padding: 16px 0;
    gap: 12px;
  }
  .brand-info h1 {
    font-size: 1.15rem;
  }
  .status-indicator {
    display: none;
  }
  .metric-value {
    font-size: 2.1rem;
  }
}
