/* =========================================================
   环境监测仪表盘 · 深色科技风 + 轻玻璃拟态
   设计令牌集中在 :root，组件只引用令牌，便于整体换肤
   ========================================================= */

:root {
  --bg-0: #0b1220;
  --bg-1: #111a2c;
  --bg-2: #0f1a2e;

  --ink-1: #e6edf7;
  --ink-2: #93a4bd;
  --ink-3: #5d6e88;

  --sky: #38bdf8;
  --indigo: #818cf8;
  --cyan: #22d3ee;
  --rose: #fb7185;
  --amber: #fbbf24;
  --emerald: #34d399;
  --danger: #f87171;

  --glass: rgba(255, 255, 255, 0.045);
  --glass-strong: rgba(255, 255, 255, 0.07);
  --stroke: rgba(255, 255, 255, 0.09);
  --stroke-bright: rgba(255, 255, 255, 0.18);

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --shadow-soft: 0 18px 40px -24px rgba(2, 8, 20, 0.9);
  --shadow-lift: 0 28px 60px -30px rgba(2, 8, 20, 0.95);

  --font: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, -apple-system, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

html {
  background-color: var(--bg-0);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink-1);
  background: var(--bg-0) linear-gradient(160deg, var(--bg-0) 0%, var(--bg-1) 48%, var(--bg-2) 100%) no-repeat;
  background-size: 100% 100%;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ---------- 背景光晕 ---------- */
.aurora {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.aurora-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.32;
}

.aurora-cyan {
  width: 46vw;
  height: 46vw;
  top: -16vw;
  left: -10vw;
  background: radial-gradient(circle, rgba(34, 211, 238, 0.55), transparent 70%);
  animation: drift 18s var(--ease) infinite alternate;
}

.aurora-violet {
  width: 42vw;
  height: 42vw;
  right: -12vw;
  bottom: -18vw;
  background: radial-gradient(circle, rgba(129, 140, 248, 0.5), transparent 70%);
  animation: drift 22s var(--ease) infinite alternate-reverse;
}

.aurora-grid {
  position: absolute;
  inset: 0;
  background-image: linear-gradient(rgba(148, 163, 184, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.055) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: radial-gradient(ellipse at 50% 0%, #000 20%, transparent 78%);
}

@keyframes drift {
  from {
    transform: translate3d(0, 0, 0) scale(1);
  }
  to {
    transform: translate3d(4vw, 3vw, 0) scale(1.12);
  }
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 32px 6px;
  animation: fade-down 0.6s var(--ease) both;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  background: linear-gradient(150deg, rgba(56, 189, 248, 0.22), rgba(129, 140, 248, 0.12));
  border: 1px solid rgba(56, 189, 248, 0.28);
  box-shadow: 0 0 24px -8px rgba(56, 189, 248, 0.6);
  flex: 0 0 auto;
}

.brand-text h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.4px;
  line-height: 1.25;
}

.brand-text .sub {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--ink-3);
  letter-spacing: 0.6px;
}

.brand-text .sep {
  margin: 0 7px;
  color: rgba(148, 163, 184, 0.4);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: var(--glass);
  font-size: 12.5px;
  color: var(--ink-2);
  backdrop-filter: blur(12px);
  white-space: nowrap;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-3);
  box-shadow: 0 0 0 3px rgba(93, 110, 136, 0.16);
}

.status--online .status-dot {
  background: var(--emerald);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.16), 0 0 12px rgba(52, 211, 153, 0.7);
  animation: breathe 2.4s ease-in-out infinite;
}

.status--online {
  color: #a7f3d0;
  border-color: rgba(52, 211, 153, 0.26);
}

.status--cache .status-dot {
  background: var(--amber);
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.16), 0 0 12px rgba(251, 191, 36, 0.6);
}

.status--cache {
  color: #fde68a;
  border-color: rgba(251, 191, 36, 0.26);
}

.status--offline .status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.18);
}

.status--offline {
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.28);
}

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: 11px;
  border: 1px solid var(--stroke);
  background: rgba(9, 16, 28, 0.5);
  backdrop-filter: blur(12px);
}

.segmented button {
  border: 0;
  background: transparent;
  color: var(--ink-3);
  font: inherit;
  font-size: 12px;
  padding: 6px 13px;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.2s var(--ease), background 0.2s var(--ease);
}

.segmented button:hover {
  color: var(--ink-1);
}

.segmented button.is-active {
  color: #03121f;
  background: linear-gradient(140deg, var(--sky), var(--cyan));
  font-weight: 600;
  box-shadow: 0 6px 16px -8px rgba(56, 189, 248, 0.9);
}

.refresh {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--stroke);
  background: var(--glass);
  color: var(--ink-2);
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: transform 0.25s var(--ease), border-color 0.25s var(--ease), color 0.25s var(--ease);
}

.refresh:hover {
  transform: translateY(-1px);
  border-color: rgba(56, 189, 248, 0.4);
  color: var(--sky);
}

.refresh-ring {
  position: absolute;
  inset: 0;
  transform: rotate(-90deg);
}

.ring-track,
.ring-progress {
  fill: none;
  stroke-width: 2;
}

.ring-track {
  stroke: rgba(148, 163, 184, 0.14);
}

.ring-progress {
  stroke: var(--sky);
  stroke-linecap: round;
  stroke-dasharray: 97.4;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.9s linear;
  filter: drop-shadow(0 0 4px rgba(56, 189, 248, 0.7));
}

.refresh.is-busy .refresh-icon {
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes breathe {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

/* ---------- 布局 ---------- */
.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 16px;
  flex: 1 1 auto;
  min-height: 0;
  padding: 10px 32px 18px;
}

/* ---------- 指标卡 ---------- */
.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.metric-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 18px 14px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--stroke);
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.022));
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px) saturate(1.15);
  overflow: hidden;
  transition: transform 0.35s var(--ease), box-shadow 0.35s var(--ease), border-color 0.35s var(--ease);
  animation: fade-up 0.7s var(--ease) both;
}

.metric-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent, var(--sky)), transparent);
  opacity: 0.9;
}

.metric-card:hover {
  transform: translateY(-4px);
  border-color: var(--stroke-bright);
  box-shadow: var(--shadow-lift);
}

.metric-head {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink-2);
  font-size: 12.5px;
  letter-spacing: 0.3px;
}

.metric-icon {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--accent);
}

.metric-body {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.metric-value {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.metric-number {
  font-size: 40px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #ffffff, color-mix(in srgb, var(--accent) 55%, #ffffff));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.metric-unit {
  font-size: 13px;
  color: var(--ink-3);
  font-weight: 500;
}

.metric-tail {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.metric-delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-3);
  background: rgba(148, 163, 184, 0.1);
  font-variant-numeric: tabular-nums;
}

.metric-delta.is-up {
  color: #fca5a5;
  background: rgba(251, 113, 133, 0.14);
}

.metric-delta.is-down {
  color: #7dd3fc;
  background: rgba(56, 189, 248, 0.14);
}

.metric-delta.is-flat {
  color: var(--ink-3);
}

.spark {
  width: 92px;
  height: 30px;
  display: block;
  overflow: visible;
}

.metric-foot {
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: 0.2px;
}

/* ---------- 图表面板 ---------- */
.panel {
  border-radius: var(--radius-lg);
  border: 1px solid var(--stroke);
  background: linear-gradient(170deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.018));
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px) saturate(1.1);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  animation: fade-up 0.7s var(--ease) 0.1s both;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px 10px;
  flex-wrap: wrap;
}

.panel-titles h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.panel-sub {
  margin: 4px 0 0;
  font-size: 11.5px;
  color: var(--ink-3);
  letter-spacing: 0.3px;
}

.legend {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.legend-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: rgba(9, 16, 28, 0.42);
  color: var(--ink-2);
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
  transition: color 0.22s var(--ease), border-color 0.22s var(--ease), opacity 0.22s var(--ease),
    transform 0.22s var(--ease);
}

.legend-pill:hover {
  transform: translateY(-1px);
  border-color: var(--stroke-bright);
  color: var(--ink-1);
}

.legend-pill.is-off {
  opacity: 0.4;
}

.legend-swatch {
  width: 16px;
  height: 0;
  border-top: 2px solid var(--accent);
  border-radius: 2px;
}

.legend-pill[data-dash="dashed"] .legend-swatch {
  border-top-style: dashed;
}

.legend-pill[data-dash="dotted"] .legend-swatch {
  border-top-style: dotted;
  border-top-width: 3px;
}

.chart-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  padding: 0 12px 12px;
}

.chart {
  width: 100%;
  height: 100%;
  min-height: 260px;
}

.chart-stamp {
  position: absolute;
  right: 22px;
  bottom: 8px;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 11px;
  color: var(--ink-3);
  background: rgba(9, 16, 28, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(8px);
  pointer-events: none;
}

/* 骨架屏 */
.skeleton {
  position: absolute;
  inset: 12px 20px 34px;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  opacity: 1;
  transition: opacity 0.4s var(--ease);
}

.skeleton[hidden] {
  display: none;
}

.skeleton span {
  flex: 1;
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.12), rgba(129, 140, 248, 0.05));
  animation: shimmer 1.5s ease-in-out infinite;
}

.skeleton span:nth-child(1) {
  height: 42%;
}

.skeleton span:nth-child(2) {
  height: 68%;
  animation-delay: 0.1s;
}

.skeleton span:nth-child(3) {
  height: 54%;
  animation-delay: 0.2s;
}

.skeleton span:nth-child(4) {
  height: 78%;
  animation-delay: 0.3s;
}

.skeleton span:nth-child(5) {
  height: 60%;
  animation-delay: 0.4s;
}

@keyframes shimmer {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 0.75;
  }
}

/* ---------- 底栏 ---------- */
.footbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 4px;
  font-size: 11.5px;
  color: var(--ink-3);
  letter-spacing: 0.2px;
  flex-wrap: wrap;
}

.foot-item b {
  color: var(--ink-2);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.foot-sep {
  width: 1px;
  height: 11px;
  background: rgba(148, 163, 184, 0.22);
}

.foot-spacer {
  flex: 1;
}

.foot-muted {
  color: rgba(93, 110, 136, 0.85);
}

/* ---------- 错误横幅 ---------- */
.banner {
  position: fixed;
  left: 50%;
  top: 78px;
  transform: translateX(-50%);
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 12.5px;
  color: #fde68a;
  background: rgba(48, 32, 6, 0.82);
  border: 1px solid rgba(251, 191, 36, 0.35);
  box-shadow: 0 18px 40px -24px rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(14px);
  animation: fade-down 0.35s var(--ease) both;
}

.banner[hidden] {
  display: none;
}

.banner-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.8);
}

/* ---------- 动画 ---------- */
@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fade-down {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- 响应式 ---------- */
/* 矮屏（1366×768 笔记本、教室投影压缩后）压缩留白，避免图表被裁 */
@media (min-width: 1024px) and (max-height: 820px) {
  .topbar {
    padding: 12px 28px 2px;
  }

  .brand-text h1 {
    font-size: 19px;
  }

  .layout {
    gap: 12px;
    padding: 6px 28px 12px;
    min-height: 560px;
  }

  .metric-card {
    padding: 12px 16px 10px;
    gap: 6px;
  }

  .metric-number {
    font-size: 32px;
  }

  .panel-head {
    padding: 12px 18px 6px;
  }

  .chart {
    min-height: 200px;
  }

  .footbar {
    font-size: 11px;
  }
}

@media (max-width: 1023px) {
  .layout {
    height: auto;
    min-height: calc(100vh - 74px);
    grid-template-rows: auto auto auto;
    padding: 10px 20px 20px;
  }

  .chart,
  .chart-wrap {
    min-height: 360px;
  }

  .panel {
    min-height: 420px;
  }
}

@media (max-width: 767px) {
  .topbar {
    flex-wrap: wrap;
    padding: 16px 16px 4px;
    gap: 12px;
  }

  .brand-text h1 {
    font-size: 18px;
  }

  .topbar-actions {
    width: 100%;
    gap: 8px;
  }

  .status {
    height: 30px;
    padding: 0 11px;
    font-size: 11.5px;
  }

  .segmented {
    flex: 1;
    justify-content: center;
  }

  .segmented button {
    flex: 1;
    padding: 6px 0;
  }

  .metrics {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .metric-number {
    font-size: 32px;
  }

  .spark {
    width: 72px;
    height: 26px;
  }

  .layout {
    padding: 10px 14px 18px;
  }

  .chart {
    min-height: 300px;
  }

  .panel-head {
    padding: 14px 16px 6px;
  }

  .banner {
    top: 96px;
    width: calc(100% - 32px);
    justify-content: center;
  }

  .foot-spacer {
    display: none;
  }

  .foot-muted {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
