:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1f2328;
  --muted: #6b7280;
  --line: #e4e6eb;
  --brand: #2f6f4f;
  --brand-ink: #ffffff;
  --mine: #d9f2e3;
  --theirs: #ffffff;
  --danger: #b4443a;
  --ok: #2f8f5b;
  --bad: #c0493f;
  --warn: #b7791f;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink); background: var(--bg);
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; }

button {
  font: inherit; padding: 7px 14px; border: 1px solid var(--brand);
  background: var(--brand); color: var(--brand-ink);
  border-radius: 6px; cursor: pointer;
}
button:disabled { opacity: .45; cursor: default; }
button.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
button.ghost:hover:not(:disabled) { background: #eef0f3; }
button.small { padding: 3px 9px; font-size: 12px; }
button.danger { background: var(--danger); border-color: var(--danger); }
input {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 6px; background: #fff; color: var(--ink);
}
input:focus { outline: 2px solid var(--brand); outline-offset: -1px; }

/* 登录 */
.login { display: grid; place-items: center; height: 100vh; }
.login-card {
  display: flex; flex-direction: column; gap: 12px; width: 300px;
  padding: 28px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius);
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; text-align: center; }

/* 布局 */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; }
.spacer { flex: 1; }
.main { flex: 1; display: grid; grid-template-columns: 300px 240px 1fr; min-height: 0; }
.col { display: flex; flex-direction: column; border-right: 1px solid var(--line); min-height: 0; background: var(--panel); }
.col.chat { border-right: none; background: var(--bg); }
.col-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; font-weight: 600; border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.list { overflow-y: auto; flex: 1; }

/* 设备项 */
.device, .conv {
  padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.device:hover, .conv:hover { background: #f0f2f5; }
.device.active, .conv.active { background: #e6f0ea; border-left: 3px solid var(--brand); }
.device-top { display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #c2c6cc; flex: none; }
.dot.on { background: var(--ok); }
.device-name { font-weight: 500; }
.device-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.lights { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.light {
  font-size: 11px; padding: 1px 6px; border-radius: 4px;
  border: 1px solid var(--line); color: var(--muted);
}
.light.ok { color: var(--ok); border-color: #bfe3cd; background: #f0faf4; }
.light.bad { color: var(--bad); border-color: #eccac6; background: #fcf2f1; }
.light.warn { color: var(--warn); border-color: #ecdcb8; background: #fcf7ec; }

/* 会话项 */
.conv-top { display: flex; justify-content: space-between; align-items: baseline; }
.conv-peer { font-weight: 500; }
.conv-last { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  background: var(--danger); color: #fff; border-radius: 10px;
  font-size: 11px; padding: 0 6px; min-width: 18px; text-align: center;
}

/* 聊天 */
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.bubble-row { display: flex; }
.bubble-row.out { justify-content: flex-end; }
.bubble {
  max-width: 68%; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--theirs); white-space: pre-wrap; word-break: break-word;
}
.bubble-row.out .bubble { background: var(--mine); }
.meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.meta .st-ok { color: var(--ok); }
.meta .st-bad { color: var(--bad); }
.meta .st-warn { color: var(--warn); }
.send-bar { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--panel); }
.send-bar input { flex: 1; }

/* 弹窗 */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; z-index: 10; }
.modal-card { background: var(--panel); border-radius: var(--radius); width: 560px; max-width: 92vw; max-height: 86vh; overflow-y: auto; padding: 18px; }
.modal-card.small { width: 380px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-weight: 600; }
.admin-sec { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.admin-sec:first-of-type { border-top: none; margin-top: 0; padding-top: 0; }
.admin-sec h3 { margin: 0 0 10px; font-size: 15px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.row input { flex: 1; min-width: 100px; }
.chk { display: flex; align-items: center; gap: 4px; font-size: 13px; white-space: nowrap; }
.acc-list { display: flex; flex-direction: column; gap: 6px; }
.acc-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; }
.acc-row .spacer { flex: 1; }
.token { margin-top: 14px; padding: 16px; text-align: center; border: 1px dashed var(--brand); border-radius: 8px; }
.token .code { font-size: 28px; font-weight: 700; letter-spacing: 4px; font-family: ui-monospace, Menlo, monospace; }
