:root {
  --bg: #0b0f17;
  --bg-soft: #121826;
  --card: #161d2e;
  --card-2: #1c2438;
  --line: #26304a;
  --text: #e8edf7;
  --muted: #8b96b0;
  --accent: #38e1c6;
  --accent-2: #4c8dff;
  --warn: #ffb020;
  --danger: #ff5d6c;
  --ok: #3ddc84;
  --radius: 16px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 50% -10%, #16203a 0%, var(--bg) 55%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
#app { max-width: 560px; margin: 0 auto; min-height: 100%; padding-bottom: 32px; }

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 12px) 14px 12px;
  background: rgba(11, 15, 23, 0.82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topTitle { font-size: 17px; font-weight: 600; }
.topbar-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 38px; height: 38px; flex: 0 0 auto;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--text);
  font-size: 20px; line-height: 1; cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn:active { transform: scale(0.94); }

.view { padding: 16px 14px; }

/* 通用卡片 */
.card {
  background: linear-gradient(180deg, var(--card) 0%, var(--bg-soft) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.card h4 { margin: 0 0 12px; font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: 0.5px; }

/* 设备列表 */
.device-card { display: flex; align-items: center; gap: 14px; cursor: pointer; }
.device-card:active { transform: scale(0.99); }
.dev-icon {
  width: 46px; height: 46px; border-radius: 13px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 22px;
  background: var(--card-2); border: 1px solid var(--line);
}
.dev-main { flex: 1; min-width: 0; }
.dev-name { font-weight: 600; font-size: 16px; }
.dev-id { font-size: 12px; color: var(--muted); font-family: ui-monospace, monospace; }
.dev-summary { font-size: 12px; color: var(--muted); margin-top: 4px; }
.dev-right { text-align: right; flex: 0 0 auto; }
.dev-soc { font-size: 20px; font-weight: 700; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.badge.online { color: var(--ok); border-color: rgba(61, 220, 132, 0.4); }
.badge.online .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.badge.offline { color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty .big { font-size: 46px; margin-bottom: 12px; }

/* 仪表盘 */
.gauge-wrap { display: flex; align-items: center; gap: 18px; }
.gauge { position: relative; width: 132px; height: 132px; flex: 0 0 auto; }
.gauge svg { transform: rotate(-90deg); }
.gauge .center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.gauge .soc { font-size: 32px; font-weight: 800; }
.gauge .soc small { font-size: 15px; font-weight: 600; }
.gauge .label { font-size: 12px; color: var(--muted); }
.gauge-side { flex: 1; display: grid; gap: 10px; }

.metric { background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.metric .k { font-size: 12px; color: var(--muted); }
.metric .v { font-size: 20px; font-weight: 700; }
.metric .v small { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 3px; }
.metric .v.pos { color: var(--ok); }
.metric .v.neg { color: var(--accent-2); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

/* 电芯电压条 */
.cells { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding-top: 8px; }
.cell-bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.cell-bar .bar { width: 100%; border-radius: 4px 4px 2px 2px; background: linear-gradient(180deg, var(--accent), var(--accent-2)); min-height: 3px; transition: height 0.4s; }
.cell-bar.max .bar { background: linear-gradient(180deg, var(--warn), #ff8a00); }
.cell-bar.min .bar { background: linear-gradient(180deg, var(--danger), #c0392b); }
.cell-bar .idx { font-size: 9px; color: var(--muted); }
.cell-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 10px; }
.cell-meta b { color: var(--text); }

/* 状态/保护 */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font-size: 12px; padding: 6px 11px; border-radius: 10px; background: var(--card-2); border: 1px solid var(--line); color: var(--muted); }
.chip.on { color: var(--ok); border-color: rgba(61, 220, 132, 0.4); }
.chip.alert { color: var(--danger); border-color: rgba(255, 93, 108, 0.5); background: rgba(255, 93, 108, 0.08); }
.chip.warn { color: var(--warn); border-color: rgba(255, 176, 32, 0.4); }

.alarm-item { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.alarm-item:last-child { border-bottom: 0; }
.alarm-item .dot { background: var(--danger); }
.alarm-item.warn .dot { background: var(--warn); }
.alarm-item.info .dot { background: var(--muted); }

/* 历史曲线 */
.chart { width: 100%; height: 140px; }
.chart-legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }

/* 控制 */
.ctrl-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); }
.ctrl-row:last-child { border-bottom: 0; }
.switch { width: 50px; height: 28px; border-radius: 999px; background: var(--card-2); border: 1px solid var(--line); position: relative; cursor: pointer; transition: 0.2s; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%; background: var(--muted); transition: 0.2s; }
.switch.on { background: rgba(61, 220, 132, 0.25); border-color: var(--ok); }
.switch.on::after { left: 24px; background: var(--ok); }
.note { font-size: 12px; color: var(--muted); margin-top: 10px; }

/* 设置 */
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 12px; border-radius: 12px;
  background: var(--card-2); border: 1px solid var(--line); color: var(--text); font-size: 15px;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent-2); }

.btn { padding: 12px 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--card-2); color: var(--text); font-size: 15px; cursor: pointer; }
.btn.primary { background: linear-gradient(135deg, var(--accent-2), var(--accent)); border: none; color: #04121a; font-weight: 700; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: rgba(255, 93, 108, 0.4); }
.btn:active { transform: scale(0.97); }
.btn.block { width: 100%; }

/* 弹窗 */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px); }
.modal-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 22px; box-shadow: var(--shadow); }
.modal-card h3 { margin: 0 0 6px; }
.modal-hint { font-size: 13px; color: var(--muted); margin: 0 0 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%); z-index: 60; background: var(--card-2); border: 1px solid var(--line); color: var(--text); padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14px; max-width: 90%; text-align: center; }

/* 控制按钮组 */
.ctrl-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ctrl-btns .btn { padding: 14px 8px; font-weight: 600; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn.danger:not(:disabled):active { background: rgba(255, 93, 108, 0.12); }

.section-title { font-size: 13px; color: var(--muted); margin: 4px 2px 10px; font-weight: 600; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, monospace; }

/* 指标异常 */
.metric.alert { border-color: rgba(255, 93, 108, 0.5); background: rgba(255, 93, 108, 0.06); }
.metric.alert .v { color: var(--danger); }

/* 告警行 */
.alarm-item { align-items: flex-start; }
.alarm-time { flex: 0 0 auto; font-size: 11px; color: var(--muted); font-family: ui-monospace, monospace; padding-top: 1px; }
.alarm-text { flex: 1; min-width: 0; }