:root {
  --bg: #0b1412;
  --surface: #121e1a;
  --surface-2: #17261f;
  --line: rgba(255, 255, 255, 0.09);
  --text: #e8f0ea;
  --muted: #8ba79b;
  --accent: #35d07f;
  --warn: #f2b441;
  --danger: #f2604a;
  --cool: #4fc3f7;
  --radius: 14px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f2f5f3;
  --surface: #ffffff;
  --surface-2: #f7faf8;
  --line: rgba(16, 32, 26, 0.12);
  --text: #14211c;
  --muted: #5f7a6f;
  --accent: #16875a;
  --warn: #b8791a;
  --danger: #c0392b;
  --cool: #1c7fb8;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}
.app { max-width: 560px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 18%, transparent); font-size: 18px;
}
.title { font-size: 17px; font-weight: 600; }
.subtitle { font-size: 12px; color: var(--muted); margin-top: 1px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); font-size: 15px; cursor: pointer;
}
.icon-btn:hover { color: var(--text); }
.app-link {
  font-size: 12px; color: var(--muted); padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--line); text-decoration: none; white-space: nowrap;
}
.app-link:hover { color: var(--text); border-color: var(--muted); }
@media (max-width: 400px) { .app-link { display: none; } }
.conn {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px;
  color: var(--accent); padding: 5px 9px; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .dot { animation: none; } }
main { flex: 1; padding: 14px 16px 90px; }
.view { display: block; }
.view[hidden] { display: none; }
h2.section-title { font-size: 13px; font-weight: 600; color: var(--muted); margin: 18px 0 10px; letter-spacing: .4px; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.stat-value small { font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 2px; }
.house-list { display: flex; flex-direction: column; gap: 10px; }
.house {
  width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px; display: flex; flex-direction: column; gap: 10px;
}
.house:active { background: var(--surface-2); }
.house-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.house-name { font-size: 14px; font-weight: 600; }
.tag {
  font-size: 11px; padding: 3px 9px; border-radius: 999px; white-space: nowrap;
  background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent);
}
.tag[data-state="warn"] { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.tag[data-state="alarm"] { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.house-body { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }
.big-temp { font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.8px; }
.big-temp small { font-size: 14px; color: var(--muted); font-weight: 400; }
.mini-metrics { display: flex; gap: 16px; font-size: 11px; color: var(--muted); }
.mini-metrics b { display: block; font-size: 14px; color: var(--text); font-weight: 500; font-variant-numeric: tabular-nums; margin-top: 2px; }
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 2px 12px; }
.detail-name { font-size: 18px; font-weight: 600; }
.detail-note { font-size: 12px; color: var(--muted); margin-top: 2px; }
.chart-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px;
}
#chart { display: block; width: 100%; height: auto; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.metric {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 11px;
}
.metric-label { font-size: 11px; color: var(--muted); }
.metric-value { font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 4px; }
.metric-value small { font-size: 12px; color: var(--muted); font-weight: 400; }
.device-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.device {
  font: inherit; color: inherit; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px;
  display: flex; align-items: center; gap: 10px;
}
.device-dot {
  width: 10px; height: 10px; border-radius: 50%; flex: none;
  background: var(--muted); box-shadow: 0 0 0 4px color-mix(in srgb, var(--muted) 18%, transparent);
}
.device[data-on="true"] .device-dot {
  background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}
.device-name { font-size: 13.5px; font-weight: 500; }
.device-state { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.device[data-on="true"] .device-state { color: var(--accent); }
.alert-list { display: flex; flex-direction: column; gap: 10px; }
.alert {
  background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--warn); border-radius: 12px; padding: 11px 12px;
}
.alert[data-level="danger"] { border-left-color: var(--danger); }
.alert[data-level="info"] { border-left-color: var(--cool); }
.alert-top { display: flex; justify-content: space-between; gap: 10px; font-size: 11.5px; color: var(--muted); }
.alert-text { font-size: 13.5px; margin-top: 5px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 12px; }

/* 告警横幅与闪屏 */
.alarm-banner {
  position: sticky; top: 52px; z-index: 30;
  margin: 0 16px 8px;
  background: var(--danger); color: #fff;
  border-radius: 12px; padding: 12px 14px;
  font-size: 14px; line-height: 1.5;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.alarm-banner b { display: block; font-size: 15px; margin-bottom: 4px; }
.alarm-banner button {
  margin-top: 8px; font: inherit; font-size: 12px;
  background: rgba(255, 255, 255, .22); color: #fff;
  border: 0; border-radius: 8px; padding: 5px 12px;
}
.alarm-flash {
  position: fixed; inset: 0; pointer-events: none; z-index: 9999;
  background: var(--danger); opacity: 0;
}
.alarm-flash.on { animation: alarm-flash .55s ease-in-out 6; }
@keyframes alarm-flash { 0%, 100% { opacity: 0; } 50% { opacity: .30; } }
@media (prefers-reduced-motion: reduce) { .alarm-flash.on { animation: none; opacity: .18; } }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1 1 0; max-width: 140px;
  background: none; border: 0; font: inherit; cursor: pointer;
  color: var(--muted); padding: 9px 4px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px;
}
.tab-icon { font-size: 17px; line-height: 1; }
.tab.is-active { color: var(--accent); }
@media (min-width: 620px) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .device-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
