:root {
  --bg: #f2f3f5;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #8a8f99;
  --line: #eceef1;
  --brand: #2fbf8f;
  --brand-soft: #e6f7f1;
  --warn: #efaa17;
  --danger: #e8463a;
  --radius: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

/* 顶部栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(180deg, #ffd94a 0%, #ffe98a 100%);
  padding: 14px 16px 12px;
}
.topbar .title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  font-weight: 600;
}
.topbar .sub {
  margin-top: 2px;
  font-size: 12px;
  color: rgba(0, 0, 0, 0.55);
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9aa0a6;
}
.dot.online { background: #1dc981; box-shadow: 0 0 0 3px rgba(29, 201, 129, 0.18); }

main { padding: 12px; }

/* 卡片 */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 4px 14px;
  margin-bottom: 12px;
}
.card h2 {
  margin: 0;
  padding: 14px 0 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.5px;
}

/* 行 */
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  border-top: 1px solid var(--line);
  padding: 8px 0;
}
.row:first-of-type { border-top: none; }
.row .label { font-size: 15px; }
.row .hint { font-size: 12px; color: var(--muted); }
.row.pending .label { color: var(--warn); }

/* 开关下方的状态反馈 */
.switch-text { flex: 1; min-width: 0; }
.switch-state {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}
.switch-state.on { color: #0a6b4f; }
.switch-state.pending { color: var(--warn); }

/* 手动 / 自动 分段按钮 */
.seg {
  display: flex;
  background: #f2f3f5;
  border-radius: 999px;
  padding: 3px;
  flex: 0 0 auto;
}
.seg-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-family: inherit;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.seg-btn.active {
  background: #fff;
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* 开 / 关 按键 */
.btn-group {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}
.fan-btn {
  min-width: 52px;
  border: 1px solid var(--brand);
  background: #fff;
  color: #0a6b4f;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.fan-btn.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
.fan-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background: #f5f6f7;
  color: var(--muted);
  border-color: var(--line);
}

/* 开关 */
.switch {
  position: relative;
  width: 48px;
  height: 28px;
  flex: 0 0 auto;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.switch .track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #d9dde3;
  transition: background 0.18s;
  pointer-events: none;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.18s;
}
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:disabled + .track { opacity: 0.6; }

/* 动作按钮 */
.action-btn {
  border: 1px solid var(--brand);
  background: var(--brand-soft);
  color: #0a6b4f;
  border-radius: 999px;
  padding: 7px 20px;
  font-size: 14px;
  font-family: inherit;
}
.action-btn:active { transform: scale(0.97); }
.action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* 滑杆行 */
.slider-row {
  display: block;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.slider-row:first-of-type { border-top: none; }
.slider-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.slider-head .val {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: #0a6b4f;
}
input[type="range"] {
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: #e3e6ea;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -8px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--brand);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}
input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: #e3e6ea;
}
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--brand);
}

/* 传感器数值 */
.sensor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
  padding-bottom: 6px;
}
.sensor {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.sensor:nth-child(-n+2) { border-top: none; }
.sensor .name { color: var(--muted); font-size: 14px; }
.sensor .value {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: #0a6b4f;
}

/* 告警列表 */
.event-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 0;
  border-top: 1px solid var(--line);
}
.event-item:first-child { border-top: none; }

.event-level {
  flex: 0 0 auto;
  margin-top: 1px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #f1f3f5;
  color: var(--muted);
}
.event-level.alarm,
.event-level.error { background: #fdecea; color: var(--danger); }
.event-level.warn { background: #fdf5e3; color: #b57c05; }
.event-level.info { background: var(--brand-soft); color: #0a6b4f; }

.event-body { flex: 1; min-width: 0; }
.event-msg { font-size: 14px; word-break: break-all; }
.event-time {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* 提示条 */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  background: rgba(26, 26, 26, 0.9);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

/* 顶部退出按钮 */
.topbar .logout {
  position: absolute;
  right: 14px;
  top: 14px;
  border: none;
  background: rgba(0, 0, 0, 0.08);
  color: #4a3b00;
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 13px;
  font-family: inherit;
}

/* ============ 登录页 ============ */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #ffe98a 0%, #fff7dd 38%, #f2f3f5 100%);
  padding: 24px 16px;
}

.auth-wrap {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: 16px;
  padding: 26px 22px 20px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.08);
}

.auth-logo {
  width: 62px;
  height: 62px;
  display: block;
  margin: 0 auto 6px;
}

.auth-title {
  margin: 0 0 20px;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
}

.tabs {
  display: flex;
  background: #f2f3f5;
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 18px;
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 9px 0;
  border-radius: 999px;
  font-size: 14px;
  color: var(--muted);
  font-family: inherit;
  cursor: pointer;
}

.tab.active {
  background: #fff;
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-form.hidden { display: none; }

.field { display: block; }

.field > span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  font-size: 15px;
  font-family: inherit;
  background: #fafbfc;
  color: var(--text);
  outline: none;
}

.field input:focus {
  border-color: var(--brand);
  background: #fff;
}

.field-row {
  display: flex;
  gap: 8px;
}

.field-row input { flex: 1; }

/* 保存密码勾选 */
.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  margin-top: -4px;
}
.check-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--brand);
  margin: 0;
}

.btn-primary {
  height: 46px;
  border: none;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  margin-top: 4px;
  cursor: pointer;
}

.btn-primary:disabled { opacity: 0.6; }

.btn-ghost {
  flex: 0 0 auto;
  height: 44px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--brand);
  background: var(--brand-soft);
  color: #0a6b4f;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

.btn-ghost:disabled { opacity: 0.6; }

.auth-tip {
  min-height: 18px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.auth-tip.error { color: var(--danger); }

/* 登录页底部"安装到桌面"入口 */
.install-entry {
  text-align: center;
  margin-top: 10px;
  font-size: 13px;
}
.install-entry a {
  color: var(--muted);
  text-decoration: none;
}

/* ============ 安装引导页 ============ */
.install-wrap { text-align: left; }

.install-sub {
  margin: -10px 0 16px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
}

.install-btn {
  width: 100%;
  margin-bottom: 14px;
}

.install-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
  background: #fafbfc;
}

.steps {
  margin: 8px 0 0;
  padding-left: 20px;
  font-size: 13px;
  line-height: 1.9;
  color: var(--text);
}
.steps li { margin-bottom: 2px; }

.url-box {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.url-box span {
  flex: 1;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  word-break: break-all;
}

.install-tip {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

/* 忘记密码链接 */
.auth-links {
  display: flex;
  justify-content: flex-end;
  margin-top: -6px;
}
.link-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-family: inherit;
  padding: 4px 0;
  cursor: pointer;
}

/* ============ 通用 ============ */
.hidden { display: none !important; }

.topbar .back {
  border: none;
  background: transparent;
  color: #4a3b00;
  font-size: 24px;
  line-height: 1;
  padding: 0 6px 0 0;
  margin-left: -6px;
  cursor: pointer;
}

/* ============ 项目选择 ============ */
.projects {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding-bottom: 12px;
}

.project {
  border: 1px solid var(--line);
  background: #fafbfc;
  border-radius: 10px;
  padding: 14px 6px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  text-align: center;
  min-height: 56px;
  cursor: pointer;
}

.project.active {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: #0a6b4f;
  font-weight: 600;
}

/* ============ 设备列表 ============ */
.device-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-top: 1px solid var(--line);
  cursor: pointer;
}
.device-item:first-child { border-top: none; }

.device-main { flex: 1; min-width: 0; }
.device-name { font-size: 15px; }
.device-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.device-meta.on { color: #0a6b4f; }

.chev { color: #c4c8ce; font-size: 20px; }

/* 可点击的设备卡片 */
.device-item.clickable {
  border: 1px solid var(--line);
  background: #f8faf9;
  border-radius: 12px;
  padding: 14px 14px;
  margin-bottom: 10px;
  border-top: 1px solid var(--line);
  transition: background 0.15s, transform 0.1s;
}
.device-item.clickable:hover { background: #f1f6f3; }
.device-item.clickable:active {
  background: #e9f3ee;
  transform: scale(0.99);
}
.device-item.clickable .enter-btn {
  flex: 0 0 auto;
  background: var(--brand-soft);
  color: #0a6b4f;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.device-item.clickable .device-name {
  font-size: 16px;
  font-weight: 500;
}

.del-btn {
  border: 1px solid var(--danger);
  background: #fff;
  color: var(--danger);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

.list-actions {
  display: flex;
  gap: 10px;
  padding: 12px 0 14px;
  border-top: 1px solid var(--line);
}
.list-actions .btn-ghost { flex: 1; }

.btn-ghost.danger {
  border-color: var(--danger);
  background: #fff5f4;
  color: var(--danger);
}
.btn-ghost.active {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.empty {
  padding: 22px 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ============ 弹层（靠上显示） ============ */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 56px 16px 24px;
  overflow-y: auto;
  z-index: 60;
}

.modal {
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
}

.modal h3 { margin: 0; font-size: 16px; font-weight: 600; }

.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn-ghost { flex: 1; }
.modal-actions .btn-primary { flex: 1; margin-top: 0; }

/* ============ 状态徽标 ============ */
.badge {
  font-size: 12px;
  color: var(--muted);
  background: #f2f3f5;
  border-radius: 999px;
  padding: 3px 10px;
}
.badge.on { color: #0a6b4f; background: var(--brand-soft); }

/* ============ 顶部右侧按钮组（退出 + 齿轮） ============ */
.top-actions {
  position: absolute;
  right: 14px;
  top: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.top-actions .logout {
  position: static;
  right: auto;
  top: auto;
}
.top-actions .gear {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.10);
  color: #4a3b00;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.topbar.topbar-stacked {
  padding-bottom: 22px;
}

/* 后台管理页的标签页 */
main .tabs {
  margin-bottom: 12px;
}

/* 后台：行内操作按钮 */
.row-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 0 0 auto;
}
.mini-btn {
  border: 1px solid var(--brand);
  background: var(--brand-soft);
  color: #0a6b4f;
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.mini-btn.danger {
  border-color: var(--danger);
  background: #fff5f4;
  color: var(--danger);
}

/* 后台：设备详情 */
.detail-section {
  border-top: 1px solid var(--line);
  padding: 10px 0;
}
.detail-section:first-child {
  border-top: none;
  padding-top: 0;
}
.detail-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}
.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  font-size: 13px;
}
.detail-key {
  color: var(--muted);
  flex: 0 0 auto;
}
.detail-val {
  text-align: right;
  word-break: break-all;
}

/* 原始报文展示 */
.json-box {
  margin: 0;
  padding: 12px;
  background: #f6f8f7;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 240px;
  overflow: auto;
  color: var(--text);
}

/* 后台：实时报文 + 下发面板 */
.debug-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.msg-list {
  max-height: 180px;
  overflow-y: auto;
  background: #f6f8f7;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg-item {
  border-bottom: 1px dashed var(--line);
  padding-bottom: 6px;
}
.msg-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.msg-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
}
.msg-topic {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-time { flex: 0 0 auto; }

.msg-body {
  margin: 4px 0 0;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text);
}

.pub-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  background: #fafbfc;
  color: var(--text);
  resize: vertical;
}
.pub-input:focus {
  border-color: var(--brand);
  background: #fff;
  outline: none;
}
