:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f4f0e9;
  --ink: #1b1a17;
  --ink-2: #6e685f;
  --ink-3: #a8a095;
  --line: #e7e1d6;
  --line-soft: #f0ebe2;
  --accent: #c2410c;
  --accent-ink: #ffffff;
  --accent-soft: #fce7d5;
  --up: #b45309;
  --down: #0f766e;
  --ok: #4d7c0f;
  --danger: #b91c1c;
  --radius: 8px;
  --radius-sm: 5px;
  --font-display: 'Fraunces', Georgia, serif;
  --font-sans: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.app { height: 100vh; display: flex; flex-direction: column; }

/* ── topbar ── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 24px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 13px; }
.brand-glyph {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--ink); position: relative; flex-shrink: 0;
}
.brand-glyph::after {
  content: ''; position: absolute; inset: 8px;
  border-radius: 50%; background: var(--accent);
}
.brand-text h1 {
  font-family: var(--font-display); font-weight: 500; font-size: 19px;
  letter-spacing: -0.01em; line-height: 1.1;
}
.brand-text span {
  font-family: var(--font-mono); font-size: 10px; color: var(--ink-3);
  letter-spacing: 0.09em; text-transform: uppercase;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.counter { display: flex; flex-direction: column; align-items: flex-end; margin-right: 8px; line-height: 1; }
.counter b { font-family: var(--font-display); font-size: 19px; font-weight: 500; }
.counter span { font-size: 9.5px; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.07em; margin-top: 3px; }

/* ── buttons ── */
.btn {
  font-family: var(--font-sans); font-size: 12.5px; font-weight: 500;
  padding: 7px 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; transition: all .15s ease; white-space: nowrap;
}
.btn:hover { border-color: var(--ink); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-accent:hover { background: #a8370a; border-color: #a8370a; }

/* ── layout ── */
.layout {
  flex: 1; display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 460px;
  min-height: 0;
}
.col { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.col-logs { border-right: none; }
.col-head {
  display: flex; align-items: center; gap: 9px;
  padding: 17px 20px 13px;
  font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-3);
}

/* ── device list ── */
.devices { list-style: none; overflow-y: auto; padding: 0 12px 16px; flex: 1; }
.device {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius);
  cursor: pointer; position: relative; margin-bottom: 2px;
  transition: background .15s ease;
  animation: fade .25s ease;
}
.device:hover { background: var(--surface-2); }
.device.selected { background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.device.selected::before {
  content: ''; position: absolute; left: 0; top: 9px; bottom: 9px;
  width: 2px; border-radius: 2px; background: var(--accent);
}
.dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; background: var(--ink-3); }
.dot-ok { background: var(--ok); }
.dot-warn { background: var(--danger); }
.device-info { min-width: 0; flex: 1; }
.device-sn { font-family: var(--font-mono); font-size: 12.5px; font-weight: 500; }
.device-sub { display: flex; gap: 6px; align-items: center; margin-top: 2px; }
.type-tag { font-size: 9.5px; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.06em; }
.auto-flag {
  font-size: 9px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); padding: 1px 6px; border-radius: 3px;
  letter-spacing: 0.05em; text-transform: uppercase;
}
.warn-flag { font-family: var(--font-mono); font-size: 9.5px; color: var(--danger); }

/* ── panel ── */
.col-panel { overflow-y: auto; }
#panel-content { padding: 20px 26px 40px; }
.empty {
  display: flex; align-items: center; justify-content: center; height: 100%;
  color: var(--ink-3); font-size: 13px;
}
.empty[hidden] { display: none; } /* hidden 属性优先于 display:flex，选中设备后空状态正常收起 */
.summary {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px;
  background: var(--line); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; margin-bottom: 22px;
}
.summary-item { background: var(--surface); padding: 11px 14px; }
.summary-k { font-size: 9.5px; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.09em; }
.summary-v { font-family: var(--font-mono); font-size: 12.5px; margin-top: 3px; word-break: break-all; }

.tabs { display: flex; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.tab {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 9px 0; margin-right: 26px; cursor: pointer;
  font-family: var(--font-sans); font-size: 13px; font-weight: 500; color: var(--ink-2);
  transition: color .15s;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }
.tabpanel { display: none; }
.tabpanel.active { display: block; animation: fade .2s ease; }

.quick { display: flex; gap: 9px; margin-bottom: 16px; }
.chip {
  flex: 1; padding: 11px; border: 1px dashed var(--line); border-radius: var(--radius);
  background: transparent; cursor: pointer;
  font-family: var(--font-sans); font-size: 12.5px; color: var(--ink-2);
  transition: all .15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); border-style: solid; }

.card {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 15px; margin-bottom: 13px; background: var(--surface);
}
.card-title {
  font-size: 10.5px; font-weight: 600; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: 0.09em; margin-bottom: 11px;
}
.card-row { display: flex; gap: 9px; align-items: flex-end; }

.lbl { display: block; font-size: 11px; color: var(--ink-2); margin: 11px 0 5px; }
.lbl-inline { display: flex; flex-direction: column; font-size: 11px; color: var(--ink-2); gap: 5px; flex: 1; }
.input, .select {
  width: 100%; font-family: var(--font-sans); font-size: 13px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
}
.code {
  width: 100%; font-family: var(--font-mono); font-size: 12px; line-height: 1.55;
  padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--ink); resize: vertical;
}
.input:focus, .select:focus, .code:focus { outline: none; border-color: var(--ink); }
.card .btn { margin-top: 12px; }

.tpls { display: flex; gap: 6px; flex-wrap: wrap; }
.tpls button {
  font-family: var(--font-mono); font-size: 11px; padding: 4px 10px;
  border: 1px solid var(--line); border-radius: 4px; background: var(--surface-2);
  cursor: pointer; color: var(--ink-2); transition: all .15s;
}
.tpls button:hover { border-color: var(--accent); color: var(--accent); }

/* state / auto */
.muted-note { font-size: 12px; color: var(--ink-2); margin-bottom: 16px; line-height: 1.6; }
.fields { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.field-row { display: flex; align-items: center; gap: 11px; }
.field-row label { width: 130px; margin: 0; font-family: var(--font-mono); font-size: 12px; color: var(--accent); }
.field-row input { flex: 1; }
.auto-status { margin-bottom: 14px; display: flex; align-items: center; gap: 9px; font-size: 13px; }
.pill {
  font-size: 11px; padding: 2px 10px; border-radius: 20px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2);
}

/* ── logs ── */
.filterbar { display: flex; gap: 5px; padding: 0 16px 13px; align-items: center; flex-wrap: wrap; }
.seg {
  font-family: var(--font-sans); font-size: 11px; padding: 4px 10px;
  border: 1px solid var(--line); border-radius: 4px; background: var(--surface);
  cursor: pointer; color: var(--ink-2); transition: all .15s;
}
.seg:hover { border-color: var(--ink-3); }
.seg.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.seg-up.active { background: var(--up); border-color: var(--up); color: #fff; }
.seg-down.active { background: var(--down); border-color: var(--down); color: #fff; }
.seg-toggle {
  font-family: var(--font-sans); font-size: 11px; padding: 4px 10px;
  border: 1px dashed var(--line); border-radius: 4px; background: transparent;
  cursor: pointer; color: var(--ink-3); transition: all .15s;
}
.seg-toggle.active { color: var(--accent); border-color: var(--accent); border-style: solid; }
.filter-spacer { flex: 1; }
.badge {
  font-family: var(--font-mono); font-size: 10.5px; padding: 1px 8px;
  border-radius: 10px; background: var(--surface-2); color: var(--ink-2);
}

.logs { list-style: none; overflow-y: auto; padding: 0 16px 16px; flex: 1; }
.log {
  display: flex; gap: 11px; padding: 9px 2px;
  border-bottom: 1px solid var(--line-soft);
  animation: logIn .25s ease-out;
}
@keyframes logIn { from { opacity: 0; transform: translateY(-4px); } }
.log-rail { width: 2px; border-radius: 2px; flex-shrink: 0; background: var(--ink-3); }
.log-up .log-rail { background: var(--up); }
.log-down .log-rail { background: var(--down); }
.log-main { min-width: 0; flex: 1; }
.log-head { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.log-time { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-3); }
.log-arrow { font-weight: 700; font-size: 12px; }
.log-up .log-arrow { color: var(--up); }
.log-down .log-arrow { color: var(--down); }
.log-type { font-family: var(--font-mono); font-size: 12px; font-weight: 500; }
.log-mid { font-family: var(--font-mono); font-size: 9.5px; color: var(--ink-3); }
.log-cmd {
  font-family: var(--font-mono); font-size: 10.5px; color: var(--down);
  background: rgba(15, 118, 110, 0.09); padding: 0 6px; border-radius: 3px;
}
.log-action { font-size: 11.5px; color: var(--ok); margin: 4px 0 0; font-style: italic; }
.log-payload {
  font-family: var(--font-mono); font-size: 10.5px; line-height: 1.55; color: var(--ink-2);
  background: var(--surface-2); padding: 8px 11px; border-radius: var(--radius-sm);
  overflow-x: auto; margin-top: 5px; white-space: pre;
}

/* ── dialog ── */
.dialog {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; background: var(--surface); color: var(--ink);
  min-width: 380px; box-shadow: 0 24px 60px rgba(27, 26, 23, 0.14);
  /* 全局 * { margin: 0 } 会覆盖 UA 给 dialog 的 margin:auto，导致 showModal 后贴角落；
     这里显式恢复，配合原生 left/right:0 + position:fixed 实现居中 */
  margin: auto;
}
.dialog::backdrop { background: rgba(27, 26, 23, 0.32); backdrop-filter: blur(3px); }
.dialog-title { font-family: var(--font-display); font-size: 18px; font-weight: 500; margin-bottom: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; }

/* ── toast ── */
#toast {
  position: fixed; bottom: 26px; left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--ink); color: var(--bg);
  padding: 9px 20px; border-radius: var(--radius-sm);
  font-size: 12.5px; opacity: 0; pointer-events: none;
  transition: all .2s ease; z-index: 100;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@keyframes fade { from { opacity: 0; } }

/* scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }

/* ── 发送子导航 + 字典表单 ── */
.subnav {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px;
  border-bottom: 1px solid var(--line-soft); padding-bottom: 12px;
}
.subnav button {
  font-family: var(--font-mono); font-size: 11.5px; padding: 5px 11px;
  border: 1px solid var(--line); border-radius: 4px; background: var(--surface);
  cursor: pointer; color: var(--ink-2); transition: all .15s;
}
.subnav button:hover { border-color: var(--ink-3); color: var(--ink); }
.subnav button.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.frow { display: grid; grid-template-columns: 150px minmax(0,1fr); align-items: center; gap: 11px; padding: 5px 0; }
.frow label { font-family: var(--font-mono); font-size: 12px; color: var(--accent); }
.frow .ctrl { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.frow .ctrl .input, .frow .ctrl .select, .frow .ctrl .code { font-size: 12.5px; padding: 6px 9px; }
.frow .ctrl .code { font-size: 11.5px; }
.frow .desc { font-size: 10.5px; color: var(--ink-3); line-height: 1.4; }
.frow .desc .unit { color: var(--ink-2); font-family: var(--font-mono); }
.frow select { width: 100%; }
.frow-bool { display: flex; align-items: center; gap: 8px; }
.frow-bool input { width: auto; }
.raw-toggle { display: flex; align-items: center; gap: 8px; margin: 4px 0 12px; font-size: 11.5px; color: var(--ink-2); cursor: pointer; }
.raw-toggle input { width: auto; }

/* ── 注册/拉取对话框 ── */
.dialog-wide { min-width: 460px; }
.check-row { display: flex; align-items: center; gap: 8px; margin: 14px 0 6px; font-size: 13px; }
.check-row input { width: auto; }
.warn-note { font-size: 11.5px; color: var(--danger); background: rgba(185,28,28,0.06); border-left: 2px solid var(--danger); padding: 7px 10px; border-radius: 0 4px 4px 0; margin: 6px 0 12px; line-height: 1.5; }
.checklist { list-style: none; max-height: 260px; overflow-y: auto; margin: 12px 0; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.checklist li { display: flex; align-items: center; gap: 9px; padding: 8px 11px; border-bottom: 1px solid var(--line-soft); font-size: 12.5px; }
.checklist li:last-child { border-bottom: none; }
.checklist input { width: auto; }
.checklist .cl-sn { font-family: var(--font-mono); }
.checklist .cl-type { font-size: 10px; color: var(--ink-3); text-transform: uppercase; }
.checklist .empty { height: auto; padding: 16px; justify-content: center; }

/* ── 登录页 ── */
.login-screen {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-screen[hidden] { display: none; } /* hidden 属性优先于 display:flex，登录成功后正常收起 */
.login-card {
  width: 300px; padding: 30px 28px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(27, 26, 23, 0.10);
}
.login-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 24px; }
.login-input { text-align: center; font-size: 14px; }
.login-btn { width: 100%; margin-top: 12px; }
.login-error { font-size: 12px; color: var(--danger); margin-top: 10px; text-align: center; }
