:root {
  --bg: #faf7ef;
  --surface: rgba(255, 255, 255, .72);
  --line: rgba(62, 48, 24, .12);
  --line-2: rgba(62, 48, 24, .07);
  --text: #2b2620;
  --text-2: #6b6152;
  --dim: #9c9282;
  --temp: #d9772f;
  --temp-soft: #f0a35e;
  --hum: #5a82b5;
  --hum-soft: #8fb0da;
  --ok: #34a853;
  --warn: #d99b2b;
  --bad: #d9534f;
  --chart-grid: rgba(62, 48, 24, .08);
  --chart-tick: #9c9282;
  --point-border: #fffdf8;
  --tip-bg: rgba(255, 253, 248, .98);
  --tip-line: rgba(62, 48, 24, .12);
  --tip-title: #2b2620;
  --tip-body: #6b6152;
  --r: 18px;
  --shadow: 0 1px 2px rgba(80, 60, 30, .04), 0 14px 34px -20px rgba(80, 60, 30, .28);
}

* { box-sizing: border-box; }

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0 auto;
  max-width: 1180px;
  min-height: 100vh;
  background:
    radial-gradient(52% 42% at 14% 0%, rgba(240, 190, 120, .28), transparent 70%),
    radial-gradient(46% 38% at 88% 5%, rgba(226, 205, 160, .34), transparent 72%);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  padding: clamp(22px, 3.2vw, 44px) clamp(16px, 4vw, 56px) 64px;
  -webkit-font-smoothing: antialiased;
}

header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 26px;
}

.brand { display: flex; flex-direction: column; gap: 7px; }

h1 {
  font-size: clamp(21px, 2.6vw, 26px);
  font-weight: 620;
  letter-spacing: -.025em;
  margin: 0;
}

.stamp { margin: 0; color: var(--dim); font-size: 13px; font-variant-numeric: tabular-nums; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: fit-content;
  padding: 3px 10px 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, .7);
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 2px;
}

.pill i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--dim);
}

.pill.ok i { background: var(--ok); animation: pulse 2.4s infinite; }
.pill.warn i { background: var(--warn); }
.pill.bad i { background: var(--bad); }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(52, 168, 83, .45); }
  70% { box-shadow: 0 0 0 6px rgba(52, 168, 83, 0); }
  100% { box-shadow: 0 0 0 0 rgba(52, 168, 83, 0); }
}

.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  background: rgba(255, 255, 255, .7);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.seg button {
  border: 0;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 13px;
  padding: 7px 13px;
  border-radius: 9px;
  cursor: pointer;
  transition: color .16s, background .16s, box-shadow .16s;
  white-space: nowrap;
  flex: 0 0 auto;
}

.seg button:hover { color: var(--text); }

.seg button.on {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(80, 60, 30, .1);
}

.tools {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.tools > .seg { min-width: 0; }

.gear {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 255, 255, .75);
  color: var(--text-2);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: color .16s, background .16s;
}

.gear:hover { color: var(--text); background: #fff; }

.btn--sm {
  padding: 8px 14px;
  border-radius: 11px;
  box-shadow: var(--shadow);
}

.pick {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  padding: 8px 30px 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .75)
    url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%236b6152' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E")
    no-repeat right 9px center / 12px;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.pick:focus { border-color: rgba(62, 48, 24, .28); background-color: #fff; outline: none; }

.set {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 12px;
}

.set-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.pw {
  flex: 0 1 148px;
  min-width: 116px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, .75);
  outline: none;
}

.pw::placeholder { color: var(--dim); }
.pw:focus { border-color: rgba(62, 48, 24, .28); background: #fff; }

.num {
  width: 78px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, .75);
  outline: none;
}

.num::placeholder { color: var(--dim); }
.num:focus { border-color: rgba(62, 48, 24, .28); background: #fff; }

.unit { font-size: 12.5px; color: var(--dim); }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 8px 15px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .16s, color .16s, border-color .16s;
}

.btn:hover { background: var(--text); color: #fff; border-color: var(--text); }
.btn:disabled { opacity: .55; cursor: default; }
.btn:disabled:hover { background: #fff; color: var(--text); border-color: var(--line); }

.set-note {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.set-note.ok { color: var(--ok); }
.set-note.bad { color: var(--bad); }

.hero {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 22px 24px 24px;
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.stat-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }

.tag { color: var(--text-2); font-size: 13px; letter-spacing: .01em; display: inline-flex; align-items: center; gap: 8px; }

.tag::before {
  content: "";
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--dim);
}

.stat--temp .tag::before { background: var(--temp); }
.stat--hum .tag::before { background: var(--hum); }

.ico { width: 18px; height: 18px; opacity: .3; color: var(--text); }

.value {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-size: clamp(44px, 6.4vw, 58px);
  font-weight: 620;
  letter-spacing: -.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.value i { font-style: normal; font-size: .28em; font-weight: 400; color: var(--dim); letter-spacing: 0; margin-left: 2px; }

.stat--temp .value {
  background: linear-gradient(100deg, var(--temp), var(--temp-soft));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

.stat--hum .value {
  background: linear-gradient(100deg, var(--hum), var(--hum-soft));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

.meter {
  height: 3px;
  border-radius: 99px;
  background: var(--line-2);
  margin: 20px 0 12px;
  overflow: hidden;
}

.meter span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 99px;
  transition: width .6s cubic-bezier(.2, .8, .2, 1);
}

.stat--temp .meter span { background: linear-gradient(90deg, var(--temp), var(--temp-soft)); }
.stat--hum .meter span { background: linear-gradient(90deg, var(--hum), var(--hum-soft)); }

.foot { color: var(--dim); font-size: 12.5px; font-variant-numeric: tabular-nums; }

.mini {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 12px;
}

.cell {
  padding: 16px 22px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-left: 1px solid var(--line);
}

.cell:first-child { border-left: 0; }

.k { color: var(--dim); font-size: 12px; }

.v { font-size: 20px; font-weight: 590; letter-spacing: -.015em; font-variant-numeric: tabular-nums; }
.v b { font-weight: inherit; }
.v i { font-style: normal; font-size: 12px; font-weight: 400; color: var(--dim); margin-left: 3px; }

.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 12px; }

.box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 18px 22px 14px;
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

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

.box-head h2 { font-size: 13.5px; font-weight: 590; margin: 0; letter-spacing: -.005em; }

.hint { font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }

.canvas-wrap { position: relative; height: 210px; }

.hide { display: none; }

/* ---------- 三套固定布局：电脑 >1024 / 平板 641~1024 / 手机 ≤640 ---------- */

/* 电脑（默认）：标题在左、时间范围和设置按钮在右，内容最宽 1180 居中 */

/* 平板：标题独占一行，控件条铺满并靠右放设置按钮 */
@media (max-width: 1024px) {
  body { padding-left: 32px; padding-right: 32px; }
  header { align-items: flex-start; flex-direction: column; }
  .tools { width: 100%; align-items: center; }
  .tools > .seg { flex: 1; }
}

/* 手机：时间范围改成 4 列等宽网格，两行左右对齐；卡片单列、指标两列 */
@media (max-width: 640px) {
  body { padding: 22px 16px 56px; }
  #range { display: grid; grid-template-columns: repeat(4, 1fr); }
  #range button { padding: 7px 0; text-align: center; }
  .hero { grid-template-columns: 1fr; }
  .mini { grid-template-columns: repeat(2, 1fr); }
  .cell:nth-child(3) { border-left: 0; }
  .cell:nth-child(n+3) { border-top: 1px solid var(--line); }
  .charts { grid-template-columns: 1fr; }
  .value { font-size: 42px; }
  .pick { flex: 1 1 100%; }
}

/* ---------- 插座页专用 ---------- */

.hero { grid-template-columns: 320px 1fr; align-items: stretch; }

.switch-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  padding: 20px 22px 22px;
}

.card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.card-top .tag::before { background: var(--temp); }
.switch-row { display: flex; align-items: center; gap: 18px; }

.state { margin: 0; font-size: 14px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.state.ok { color: var(--ok); }
.state.bad { color: var(--bad); }

/* 开关：轨道 + 滑块，状态靠颜色区分，点击有过渡 */
.switch {
  --w: 76px;
  --h: 40px;
  position: relative;
  flex: 0 0 auto;
  width: var(--w);
  height: var(--h);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: calc(var(--h) / 2);
  background: rgba(156, 146, 130, .28);
  cursor: pointer;
  transition: background 180ms ease, border-color 180ms ease;
}

.switch .knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(var(--h) - 8px);
  height: calc(var(--h) - 8px);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(80, 60, 30, .18), 0 4px 10px -4px rgba(80, 60, 30, .3);
  transition: transform 200ms cubic-bezier(.34, 1.3, .5, 1);
}

.switch[aria-checked="true"] { background: var(--ok); border-color: rgba(52, 168, 83, .5); }
.switch[aria-checked="true"] .knob { transform: translateX(calc(var(--w) - var(--h))); }
.switch:disabled { opacity: .5; cursor: default; }
.switch:focus-visible { outline: 2px solid rgba(62, 48, 24, .35); outline-offset: 3px; }

/* 指令已发出、等板子回传期间轻微呼吸，避免看着像卡住 */
.switch.pending { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

.mini { margin-bottom: 0; }

.lbl { font-size: 12px; color: var(--text-2); }

.tm {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, .75);
  font-variant-numeric: tabular-nums;
}
.tm:focus { border-color: rgba(62, 48, 24, .28); background: #fff; outline: none; }

/* 平板：开关卡收窄 */
@media (max-width: 1024px) {
  .hero { grid-template-columns: 280px 1fr; }
}

/* 手机：开关在上、指标在下 */
@media (max-width: 640px) {
  .hero { grid-template-columns: 1fr; }
  .switch-card { padding: 16px; }
  .mini .cell:nth-child(3) { border-top: 1px solid var(--line); border-left: 0; }
  .set-row .tm, .set-row .pick { flex: 1 1 44%; }
}
