:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --line: #e3e8f0;
  --text: #10182a;
  --muted: #6b7891;
  --accent: #3b82f6;
  --accent-dark: #2563eb;
  --ok: #16a34a;
  --warn: #f59e0b;
  --bad: #dc2626;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 880px;
  margin: 0 auto;
  padding: 0 16px 28px;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 0 14px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: .2px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 4px rgba(107, 120, 145, .12);
  transition: background .2s, box-shadow .2s;
}
.dot.on  { background: var(--ok);   box-shadow: 0 0 0 4px rgba(22, 163, 74, .16); }
.dot.busy{ background: var(--warn); box-shadow: 0 0 0 4px rgba(245, 158, 11, .16); }

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

.devname {
  font-size: 13px;
  color: var(--muted);
  max-width: 230px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 按钮 ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  padding: 9px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s, opacity .15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #f7f9fc; border-color: #cfd8e6; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn.primary:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }

.btn.danger { color: var(--bad); border-color: #f3c4c4; }

/* ---------- 标签页 ---------- */
.tabs {
  display: flex;
  gap: 4px;
  margin: 14px 0 18px;
  background: #e9edf5;
  padding: 4px;
  border-radius: 12px;
  width: fit-content;
}

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  padding: 8px 20px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tab.active {
  background: #fff;
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(16, 24, 42, .1);
}

.panel { display: none; flex: 1; }
.panel.active { display: block; }

/* ---------- 电量主卡 ---------- */
.hero {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
  display: flex;
  align-items: center;
  gap: 26px;
  margin-bottom: 16px;
}

.battery {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.battery-body {
  width: 84px;
  height: 40px;
  border: 3px solid var(--text);
  border-radius: 7px;
  padding: 3px;
  display: flex;
  align-items: stretch;
  overflow: hidden;
}

.battery-fill {
  width: 0%;
  border-radius: 3px;
  background: linear-gradient(90deg, #22c55e, #4ade80);
  transition: width .4s ease, background .3s;
}

.battery-tip {
  width: 6px;
  height: 16px;
  background: var(--text);
  border-radius: 0 3px 3px 0;
  margin-left: 3px;
}

.hero-main { flex: 1; min-width: 0; }

.hero-value {
  font-size: 46px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
}
.hero-value small { font-size: 20px; font-weight: 600; color: var(--muted); margin-left: 3px; }

.hero-label { margin-top: 6px; color: var(--muted); font-size: 14px; }

/* ---------- 数据网格 ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 10px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 15px;
}

.card .k { font-size: 12.5px; color: var(--muted); }
.card .v {
  font-size: 22px;
  font-weight: 650;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}
.card .v.warn { color: var(--warn); }
.card .v.bad  { color: var(--bad); }

/* ---------- 表单 ---------- */
.form {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px 18px;
}

.form.compact {
  grid-template-columns: 1fr auto;
  align-items: end;
  margin-bottom: 14px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); }

input[type="number"], input[type="text"], select {
  font: inherit;
  font-size: 15px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfcfe;
  color: var(--text);
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, .14);
  background: #fff;
}

.hint {
  font-size: 13px;
  color: var(--muted);
  padding: 12px 2px 0;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 16px 0 0;
}

/* ---------- 日志 ---------- */
.log {
  background: #0f172a;
  color: #cbd5e1;
  font: 12.5px/1.55 "Cascadia Code", Consolas, "SF Mono", monospace;
  border-radius: 12px;
  padding: 14px 16px;
  height: 300px;
  overflow: auto;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
}
.log .tx { color: #7dd3fc; }
.log .rx { color: #86efac; }
.log .err { color: #fca5a5; }
.log .sys { color: #94a3b8; }

/* ---------- 提示条 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translate(-50%, 16px);
  background: #10182a;
  color: #fff;
  font-size: 14px;
  padding: 11px 20px;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: 88vw;
  text-align: center;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #b91c1c; }

/* ---------- 页脚 ---------- */
.foot {
  margin-top: 26px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  line-height: 1.7;
}

.mono { font-family: "Cascadia Code", Consolas, monospace; word-break: break-all; }

@media (max-width: 560px) {
  .hero { flex-direction: column; align-items: flex-start; gap: 16px; }
  .hero-value { font-size: 40px; }
  .topbar { flex-wrap: wrap; }
  .devname { max-width: 140px; }
  .tabs { width: 100%; }
  .tab { flex: 1; padding: 8px 10px; text-align: center; }
}
