:root {
  --bg: #10141c;
  --bg2: #161b26;
  --panel: #1a2030;
  --line: #262e3f;
  --text: #e6ebf5;
  --muted: #8d9ab0;
  --accent: #35c9a1;
  --accent2: #4a9df8;
  --warn: #f0b44c;
  --bad: #ef6b6b;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 -apple-system, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

body {
  display: grid;
  grid-template-rows: 56px 1fr 30px;
  overflow: hidden;
}

/* ---------------- 顶栏 ---------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  background: linear-gradient(180deg, #18202e, #141a25);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand h1 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  letter-spacing: .5px;
  white-space: nowrap;
}

.brand .sub {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4a5568;
  flex: 0 0 auto;
  box-shadow: 0 0 0 3px rgba(74, 85, 104, .15);
}

.dot.on {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(53, 201, 161, .18);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .45; }
}

.pills { display: flex; gap: 8px; flex-wrap: wrap; }

.pill {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.pill.ok { color: var(--accent); border-color: rgba(53, 201, 161, .35); }
.pill.warn { color: var(--warn); border-color: rgba(240, 180, 76, .35); }
.pill.bad { color: var(--bad); border-color: rgba(239, 107, 107, .35); }

/* ---------------- 主体 ---------------- */

main {
  display: grid;
  grid-template-columns: 268px 1fr;
  gap: 12px;
  padding: 12px;
  min-height: 0;
  overflow: hidden;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  overflow-y: auto;
  min-height: 0;
}

.panel section { margin-bottom: 16px; }

.panel h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .8px;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.count { color: var(--muted); font-weight: 400; }

.hint {
  margin: 6px 0 0;
  color: #6f7c92;
  font-size: 11px;
  line-height: 1.5;
}

.empty { color: #5d6a80; font-size: 12px; padding: 4px 0; }

/* 下拉框（指数 / 波段） */

.picker {
  width: 100%;
  background: #131a26;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 5px 7px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}

.picker:disabled { opacity: .55; cursor: default; }
.picker:focus { outline: none; border-color: var(--accent); }

/* 当前公式，等宽小字，一眼能看出选的是哪个式子 */
.formula {
  margin-top: 6px;
  padding: 5px 7px;
  background: #131a26;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #9fb0c9;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 波段：变量名 + band 下拉 */

.band-rows { display: flex; flex-direction: column; gap: 5px; }

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

.band-row .var {
  flex: 0 0 50px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .2px;
  white-space: nowrap;
}

.band-row .picker { flex: 1 1 auto; min-width: 0; }

/* 输入与按钮 */

input[type="number"] {
  width: 100%;
  background: #131a26;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 4px 7px;
  font: inherit;
  font-variant-numeric: tabular-nums;
  outline: none;
}

input[type="number"]:focus { border-color: var(--accent2); }
input[type="number"]:disabled { opacity: .45; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #202b3c;
  color: var(--text);
  padding: 5px 10px;
}

button:hover { border-color: #37455c; }

button.mini { padding: 4px 9px; font-size: 12px; }

/* 保存类按钮：淡蓝边，和「暂停 / 清屏」这类画面操作区分开 */
button.save {
  border-color: rgba(74, 157, 248, .4);
  color: #cfe2ff;
}

button.save:hover {
  border-color: rgba(74, 157, 248, .8);
  background: #24344d;
}

button.save:disabled { opacity: .5; cursor: default; }

.tools .sep {
  width: 1px;
  height: 18px;
  background: var(--line);
  flex: 0 0 auto;
}

button.primary {
  width: 100%;
  padding: 8px;
  background: linear-gradient(180deg, #2fbf98, #26a583);
  border-color: #2fbf98;
  color: #06251d;
  font-weight: 700;
  letter-spacing: .5px;
}

button.primary:hover { filter: brightness(1.06); }

button.primary.dirty { animation: glow 1.4s infinite; }

@keyframes glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(53, 201, 161, .5); }
  50% { box-shadow: 0 0 0 5px rgba(53, 201, 161, 0); }
}

button.primary:disabled {
  background: #24303f;
  border-color: var(--line);
  color: var(--muted);
  cursor: not-allowed;
  animation: none;
}

.msg { margin: 8px 0 0; font-size: 11px; min-height: 14px; color: var(--muted); }
.msg.ok { color: var(--accent); }
.msg.err { color: var(--bad); }

/* 波段表 */

table.bands { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }

table.bands th {
  padding: 0 2px 4px;
  border-bottom: 1px solid #212a3a;
  font-size: 11px;
  font-weight: 400;
  color: #5d6a80;
  text-align: left;
}

table.bands th:last-child { text-align: right; }

table.bands td {
  padding: 4px 2px;
  border-bottom: 1px solid #212a3a;
  font-size: 12px;
}

table.bands td:first-child { color: var(--muted); }
table.bands td:last-child { text-align: right; color: var(--accent2); }

.calib { font-size: 12px; color: var(--muted); line-height: 1.7; }
.calib b { color: var(--text); font-weight: 600; }
.calib .ok { color: var(--accent); }
.calib .bad { color: var(--warn); }

/* ---------------- 右侧内容 ---------------- */

.content {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 10px;
  min-height: 0;
  min-width: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }

.tab {
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.tab .v { color: var(--text); font-weight: 600; margin-left: 6px; font-variant-numeric: tabular-nums; }
.tab:hover { border-color: #37455c; }

.tab.active {
  background: #1d2b33;
  border-color: rgba(53, 201, 161, .5);
  color: var(--accent);
}

.tools { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; }
.tools input[type="number"] { width: 66px; }

.check { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.check input { accent-color: var(--accent); margin: 0; }

.num { display: flex; align-items: center; gap: 5px; }

/* 热力图 */

.heatwrap {
  position: relative;
  background: #0b0f17;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 0;
}

#heat { display: block; width: 100%; height: 100%; }

.placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #4d5a70;
  font-size: 13px;
  pointer-events: none;
}

.placeholder.hide { display: none; }

.tip {
  position: absolute;
  pointer-events: none;
  background: rgba(10, 14, 22, .94);
  border: 1px solid #2c3850;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--text);
  white-space: nowrap;
  display: none;
  z-index: 5;
  font-variant-numeric: tabular-nums;
}

/* 图例 */

.legend { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); }

.legend .bar {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  border: 1px solid #2a3448;
}

.legNum { font-variant-numeric: tabular-nums; color: var(--text); min-width: 34px; text-align: center; }
.legNote { margin-left: 10px; color: #5d6a80; }

/* 统计卡片 */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
}

.card .k { font-size: 10px; color: var(--muted); letter-spacing: .6px; text-transform: uppercase; }
.card .v { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 1px; }
.card .v.dim { color: #55617a; font-weight: 400; }

/* 页脚 */

footer {
  display: flex;
  align-items: center;
  padding: 0 18px;
  border-top: 1px solid var(--line);
  background: #121821;
  color: #5d6a80;
  font-size: 11px;
}

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .panel { max-height: 240px; }
}

/* 保存后的轻提示：工具栏在右侧，侧栏那条提示太远，用户点了看不到反馈 */
.toast {
  position: fixed;
  left: 50%;
  bottom: 58px;
  transform: translateX(-50%) translateY(6px);
  padding: 8px 16px;
  border-radius: 8px;
  background: rgba(16, 22, 32, .96);
  border: 1px solid #33415a;
  color: var(--text);
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
  z-index: 30;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { border-color: rgba(239, 107, 107, .55); color: #ffd6d6; }
