:root {
  --bg: #f2f3f5;
  --card: #ffffff;
  --line: #e5e6eb;
  --text: #1d2129;
  --muted: #86909c;
  --primary: #4688fa;
  --green: #1b7a00;
  --red: #ff4759;
  --orange: #ff8547;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.view { min-height: 100vh; }
.hidden { display: none !important; }

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

/* 登录 */
.login-card {
  width: 320px;
  margin: 12vh auto 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card h1 { font-size: 20px; margin: 0; }
.muted { color: var(--muted); font-size: 13px; }

input {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  font-size: 14px;
  outline: none;
}
input:focus { border-color: var(--primary); }

button {
  height: 38px;
  border: none;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}
button:hover { filter: brightness(0.95); }
button.ghost {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}

.msg { font-size: 13px; min-height: 18px; color: var(--red); }

/* 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
}
.toolbar #search { flex: 1; max-width: 360px; }

/* 表格 */
table {
  width: calc(100% - 48px);
  margin: 0 24px;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  font-size: 14px;
}
th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
th { background: #fafbfc; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }
td button { height: 30px; padding: 0 14px; font-size: 13px; }

.tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
}
.tag.pending { background: #fff7e8; color: var(--orange); }
.tag.activated { background: #e8ffea; color: var(--green); }
/* 远程管控停用(一键停用生效中) */
.tag.disabled { background: #ffeaea; color: var(--red); }

/* 详情 */
.detail {
  margin: 16px 24px 32px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
}
.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.detail h2 { margin: 0 0 12px; font-size: 18px; }
.detail h3 { margin: 18px 0 8px; font-size: 15px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 14px; }
.kv .k { color: var(--muted); }
pre {
  background: #f7f8fa;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  overflow: auto;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-all;
}
textarea {
  width: 100%;
  min-height: 140px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  font-family: monospace;
  font-size: 13px;
  resize: vertical;
}
.logs { font-size: 13px; }
.logs div { padding: 6px 0; border-bottom: 1px dashed var(--line); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  background: #1d2129;
  color: #fff;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 14px;
}

/* 忘记密码向导弹窗 */
.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  height: auto;
  padding: 0;
  font-size: 13px;
  text-decoration: underline;
  align-self: center;
}
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(29, 33, 41, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 10vh 16px 16px;
  overflow: auto;
  z-index: 50;
}
.modal-card {
  width: 560px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-card h2 { margin: 0; font-size: 18px; }
.modal-card h3 { margin: 4px 0 0; font-size: 14px; }
.modal-card p { margin: 0; line-height: 1.6; }

/* ===== 应用骨架: 左侧导航 + 右侧路由内容 ===== */
.app-body { display: flex; min-height: 100vh; }
.sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--line);
  padding: 16px 0;
}
.sidebar .brand {
  padding: 0 20px 16px;
  font-weight: 700;
  font-size: 15px;
}
.nav-item {
  display: block;
  padding: 10px 20px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: #f7f8fa; }
.nav-item.active {
  color: var(--primary);
  border-left-color: var(--primary);
  background: #f0f5ff;
}
.content { flex: 1; min-width: 0; }

/* ===== 顶部加载条(请求进行中显示) ===== */
.loading-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 100%;
  background: linear-gradient(90deg, var(--primary), #9cc0ff);
  animation: loading-slide 1.2s linear infinite;
  z-index: 100;
}
@keyframes loading-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ===== 配置可视化编辑器 ===== */
.modal-wide { width: 780px; max-width: 100%; }
.cfg-dev { font-size: 13px; font-weight: normal; }

.cfg-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.cfg-tabs .cfg-tab { height: 30px; padding: 0 16px; font-size: 13px; background: var(--bg); color: var(--muted); }
.cfg-tabs .cfg-tab.active { background: var(--primary); color: #fff; }

.cfg-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px 12px;
  margin-bottom: 10px;
}
.cfg-section h4 {
  margin: 2px 0 10px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.cfg-section .muted { font-size: 12px; }
.cfg-sub { font-size: 13px; color: var(--muted); margin: 8px 0 6px; }
.cfg-section > .f-add { height: 30px; padding: 0 14px; font-size: 13px; }

.cfg-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.cfg-row input[type="text"] { height: 32px; flex: 1; min-width: 120px; }
.cfg-row select { height: 32px; border: 1px solid var(--line); border-radius: 6px; background: #fff; font-size: 13px; }
.cfg-row .f-del { height: 30px; padding: 0 12px; font-size: 13px; }
label.check {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}
input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

.cfg-errors {
  color: var(--red);
  font-size: 13px;
  white-space: pre-wrap;
  min-height: 0;
  margin: 4px 0;
}

.cfg-tpl { border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 10px; }
.cfg-tpl-line { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.cfg-tpl-line select { height: 32px; border: 1px solid var(--line); border-radius: 6px; background: #fff; font-size: 13px; max-width: 240px; }
.cfg-tpl-line input[type="text"] { height: 32px; flex: 1; }
.cfg-tpl-line button { height: 32px; padding: 0 14px; font-size: 13px; }
.cfg-tpl-json { margin: 2px 0 6px; }

/* 分区内独立模板栏(每个配置块各一条, 载入/保存只作用于该块) */
.cfg-sec-tpl {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  padding: 6px 8px;
  margin-bottom: 10px;
  background: var(--bg);
  border-radius: 6px;
}
.cfg-sec-tpl .cfg-tpl-tag { font-size: 12px; color: var(--muted); white-space: nowrap; }
.cfg-sec-tpl select { height: 28px; border: 1px solid var(--line); border-radius: 6px; background: #fff; font-size: 12px; max-width: 200px; }
.cfg-sec-tpl input[type="text"] { height: 28px; flex: 1; min-width: 140px; font-size: 12px; }
.cfg-sec-tpl button { height: 28px; padding: 0 12px; font-size: 12px; }

.cfg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* 功能开关目录勾选区 */
.cfg-feat-group { margin-bottom: 10px; }
.cfg-feat-title { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.cfg-feat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 2px 16px; }
.cfg-feat-item { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 3px 0; cursor: pointer; }
.cfg-feat-item .cfg-feat-key { font-size: 11px; color: var(--muted); font-family: monospace; }

/* ===== 在线状态徽标(MQTT) ===== */
.tag.online { background: #e8ffea; color: var(--green); }
.tag.offline { background: #f2f3f5; color: var(--muted); }

/* ===== 设备列表备注列(点击弹窗编辑) ===== */
.td-remark { max-width: 200px; }
.remark-cell {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
  color: var(--primary);
  cursor: pointer;
}
.remark-cell:hover { text-decoration: underline; }
.remark-cell.empty { color: var(--muted); }
.rmk-input { width: 100%; }

/* ===== 手机适配(窄屏): 侧栏折叠为顶部横条, 宽表格横向滚动 ===== */
@media (max-width: 720px) {
  .app-body { flex-direction: column; }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 0;
    display: flex;
    align-items: center;
    overflow-x: auto;
  }
  .sidebar .brand { padding: 14px; white-space: nowrap; font-size: 14px; }
  #nav-list { display: flex; }
  .nav-item {
    padding: 12px 14px;
    border-left: none;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
  }
  .nav-item.active { border-left-color: transparent; border-bottom-color: var(--primary); }
  .topbar { padding: 10px 14px; }
  .toolbar { padding: 12px 14px; flex-wrap: wrap; }
  table { width: calc(100% - 28px); margin: 0 14px; display: block; overflow-x: auto; }
  .detail { margin: 12px 14px 24px; padding: 14px; }
  .kv { grid-template-columns: 96px 1fr; }
  .login-card { width: calc(100% - 32px); margin-top: 8vh; }
  .modal-card { padding: 16px; }
  .cfg-feat-grid { grid-template-columns: 1fr; }
}
