:root {
  --bg: #0b1220;
  --panel: #121a2b;
  --panel2: #162033;
  --line: #243149;
  --text: #e8eefc;
  --muted: #8b9bb8;
  --green: #3dffa8;
  --blue: #4da3ff;
  --orange: #ffb020;
  --red: #ff5d6c;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif; }
button, textarea { font: inherit; }

.app {
  display: grid;
  grid-template-columns: 320px 1fr 380px;
  height: 100vh;
  gap: 10px;
  padding: 10px;
}

.col { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.card {
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  min-height: 0;
}
.flex1 { flex: 1; display: flex; flex-direction: column; }
.card-h {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; color: var(--muted); margin-bottom: 8px;
}
.tag.live {
  background: rgba(61,255,168,.12); color: var(--green);
  border: 1px solid rgba(61,255,168,.35);
  border-radius: 999px; padding: 2px 8px; font-size: 11px;
}
.muted { color: var(--muted); font-size: 12px; }

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 2px; }
.logo {
  width: 34px; height: 34px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #7dffc5, #1a6bff 60%, #0b1220);
  box-shadow: 0 0 18px rgba(61,255,168,.35);
}
.title { font-weight: 700; }
.sub { font-size: 11px; color: var(--muted); }
.icon-btn {
  margin-left: auto; background: transparent; border: 1px solid var(--line);
  color: var(--text); border-radius: 8px; width: 34px; height: 34px; cursor: pointer;
}
.wx-login-btn {
  margin-left: auto;
  margin-right: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid rgba(7,193,96,.45);
  background: rgba(7,193,96,.12);
  color: #07c160;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.wx-login-btn:hover { background: rgba(7,193,96,.22); }
.wx-login-btn.logged {
  border-color: rgba(61,255,168,.4);
  background: rgba(61,255,168,.1);
  color: var(--green);
}
.wx-ico {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: #07c160;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}
.wx-card { width: min(360px, 92vw); text-align: center; }

/* 华为云风格登录卡 */
.hw-login-card {
  position: relative;
  width: min(720px, 94vw);
  background: #fff;
  color: #1a1a1a;
  border-radius: 4px;
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
  padding: 28px 32px 24px;
}
.hw-close {
  position: absolute;
  right: 12px;
  top: 8px;
  border: none;
  background: transparent;
  font-size: 22px;
  color: #999;
  cursor: pointer;
  line-height: 1;
}
.hw-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 18px;
  padding-right: 24px;
}
.hw-head h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  color: #1a1a1a;
}
.hw-link {
  border: none;
  background: none;
  color: #0a59f7;
  cursor: pointer;
  font-size: 14px;
  text-decoration: none;
  padding: 0;
}
.hw-link.muted { color: #8a8a8a; font-size: 13px; }
.hw-body {
  display: grid;
  grid-template-columns: 240px 1px 1fr;
  gap: 0 28px;
  min-height: 320px;
}
.hw-split { background: #e8e8e8; }
.hw-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.hw-qr-box {
  position: relative;
  width: 180px;
  height: 180px;
  border: 1px solid #e5e5e5;
  display: grid;
  place-items: center;
  background: #fafafa;
}
.hw-qr-box img {
  width: 168px;
  height: 168px;
  object-fit: contain;
}
.hw-qr-mask {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,.85);
  display: grid;
  place-items: center;
  color: #0a59f7;
  cursor: pointer;
  font-size: 14px;
}
.hw-qr-label {
  margin-top: 10px;
  font-size: 13px;
  color: #666;
}
.hw-divider {
  width: 100%;
  margin: 18px 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #999;
  font-size: 12px;
}
.hw-divider::before, .hw-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #e8e8e8;
}
.hw-third {
  display: flex;
  gap: 28px;
  justify-content: center;
}
.hw-third-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  display: grid;
  gap: 6px;
  justify-items: center;
  color: #666;
  font-size: 12px;
  padding: 0;
}
.hw-third-btn .ico {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}
.hw-third-btn .ico.wx { background: #07c160; }
.hw-third-btn .ico.ali { background: #1677ff; }
.hw-right { padding-top: 4px; }
.hw-form-tabs {
  display: flex;
  gap: 28px;
  margin-bottom: 18px;
  border-bottom: 1px solid #eee;
}
.hw-ftab {
  border: none;
  background: none;
  padding: 0 0 10px;
  cursor: pointer;
  font-size: 15px;
  color: #666;
  position: relative;
}
.hw-ftab.active {
  color: #1a1a1a;
  font-weight: 600;
}
.hw-ftab.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: #1a1a1a;
}
.hw-field {
  margin-bottom: 14px;
  border: 1px solid #dcdcdc;
  border-radius: 2px;
  background: #fff;
  display: flex;
  align-items: center;
}
.hw-field input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 12px 14px;
  font-size: 14px;
  color: #1a1a1a;
  outline: none;
  width: 100%;
}
.hw-phone .hw-cc {
  padding: 0 10px 0 14px;
  color: #333;
  font-size: 14px;
  border-right: 1px solid #eee;
  white-space: nowrap;
}
.hw-code .hw-getcode {
  border: none;
  background: none;
  color: #0a59f7;
  padding: 0 14px;
  cursor: pointer;
  white-space: nowrap;
  font-size: 13px;
}
.hw-tip {
  margin: -4px 0 12px;
  font-size: 12px;
  color: #999;
}
.hw-submit {
  width: 100%;
  border: none;
  background: #c7000b;
  color: #fff;
  font-size: 16px;
  padding: 12px;
  border-radius: 2px;
  cursor: pointer;
  margin-top: 6px;
}
.hw-submit:hover { background: #a80009; }
.hw-submit:disabled { opacity: .6; cursor: default; }
.hw-foot {
  display: flex;
  justify-content: space-between;
  margin-top: 14px;
}
.hw-login-card .status-line {
  color: #c7000b;
  font-size: 13px;
  margin-top: 10px;
  text-align: left;
  min-height: 18px;
}
#btnWxLogout.hidden { display: none !important; }

@media (max-width: 720px) {
  .hw-body {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  .hw-split { display: none; }
}
.wx-qr-wrap {
  margin: 12px auto;
  width: 220px;
  height: 220px;
  background: #fff;
  border-radius: 12px;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.wx-qr-wrap img { width: 220px; height: 220px; display: block; }
.brand .icon-btn { margin-left: 0; }

.sphere-wrap { display: grid; place-items: center; }
.metrics-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 6px;
}
.metrics-row div {
  background: rgba(255,255,255,.03); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 4px; text-align: center;
}
.metrics-row b { display: block; font-size: 16px; color: var(--green); }
.metrics-row span { font-size: 10px; color: var(--muted); }

.log {
  flex: 1; overflow: auto; font-size: 12px; line-height: 1.45;
  background: rgba(0,0,0,.18); border-radius: 10px; padding: 8px;
  border: 1px solid var(--line);
}
.log .item { padding: 6px 4px; border-bottom: 1px dashed rgba(255,255,255,.06); }
.log .t { color: var(--muted); margin-right: 6px; }

.hands-card {
  min-height: 200px;
  max-height: 320px;
}
.hands-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}
.hands-metrics div {
  background: rgba(0,0,0,.22);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 4px;
  text-align: center;
}
.hands-metrics b {
  display: block;
  font-size: 14px;
  color: var(--green);
  font-variant-numeric: tabular-nums;
}
.hands-metrics span {
  font-size: 10px;
  color: var(--muted);
}
.hands-device-live {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
  line-height: 1.4;
}
.hands-device-live .on { color: var(--green); }
.hands-device-live .off { color: #ffb020; }
.hands-log {
  min-height: 90px;
  max-height: 140px;
}
.badge.warn { background: rgba(255,176,32,.15); color: #ffb020; }
.badge.tx { background: rgba(77,163,255,.15); color: var(--blue); }
.badge.rx { background: rgba(61,255,168,.15); color: var(--green); }
.badge {
  display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 999px; margin-left: 6px;
}
.badge.ok { background: rgba(61,255,168,.15); color: var(--green); }
.badge.err { background: rgba(255,93,108,.15); color: var(--red); }
.badge.info { background: rgba(77,163,255,.15); color: var(--blue); }

.row-btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.row-btns button, .composer button, .modal-card button {
  background: #1a2438; color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; cursor: pointer;
}
.row-btns button:hover, .composer button:hover { border-color: var(--blue); }
button.primary { background: #2457ff; border-color: #2457ff; font-weight: 600; }

.center {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  overflow: hidden;
  min-height: 0;
}
.chat {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 14px;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(36,87,255,.08), transparent 50%),
    #0d1422;
}
/* 消息少时贴在输入框上方（像微信），多时可向上滚动 */
.chat::before {
  content: "";
  flex: 1 0 auto;
}
.msg-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 100%;
}
.msg-row.user {
  flex-direction: row-reverse;
  align-self: stretch;
}
.msg-row.assistant {
  flex-direction: row;
  align-self: stretch;
}
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  user-select: none;
}
.avatar.user {
  background: linear-gradient(135deg, #4da3ff, #2457ff);
}
.avatar.assistant {
  background: radial-gradient(circle at 30% 30%, #7dffc5, #1a6bff 65%, #0b1220);
  box-shadow: 0 0 10px rgba(61,255,168,.25);
}
.msg-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: min(72%, 520px);
  min-width: 0;
}
.msg-row.user .msg-main { align-items: flex-end; }
.msg-row.assistant .msg-main { align-items: flex-start; }
.who {
  font-size: 11px;
  color: var(--muted);
  padding: 0 2px;
}
.bubble {
  padding: 10px 12px;
  border-radius: 8px;
  line-height: 1.55;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  position: relative;
}
.bubble.user {
  background: #95ec69;
  color: #111;
  border-radius: 8px 2px 8px 8px;
}
.bubble.assistant {
  background: #182338;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 2px 8px 8px 8px;
}
.bubble.pending {
  opacity: 0.85;
  color: var(--muted);
  font-style: italic;
}
.bubble.error {
  border-color: var(--red);
  color: #ffb4bc;
}

.composer {
  border-top: 1px solid var(--line);
  padding: 10px 12px 12px;
  background: var(--panel2);
}
.video-box {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 8px;
  background: rgba(36,87,255,.08);
}
.video-box input {
  flex: 1;
  background: #0e1626;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}
.hint { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.input-row { display: flex; gap: 8px; }
textarea {
  flex: 1; resize: none; background: #0e1626; color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px;
}

.topbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  font-size: 12px; color: var(--muted); padding: 4px 2px;
}
.topbar b { color: var(--text); }
.dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 8px var(--green); display: inline-block;
}
.sep { opacity: .4; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: grid; place-items: center; z-index: 20;
}
.modal.hidden { display: none !important; }
.agents-box {
  flex: 1;
  overflow: auto;
  font-size: 12px;
  line-height: 1.45;
  background: rgba(0,0,0,.18);
  border-radius: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  max-height: 180px;
}
.agent-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px dashed rgba(255,255,255,.06);
}
.agent-row.clickable {
  cursor: pointer;
  border-radius: 6px;
  padding: 6px 6px;
  margin: 0 -4px;
}
.agent-row.clickable:hover {
  background: rgba(77,163,255,.12);
}
.agent-row .on { color: var(--green); }
.agent-row .off { color: var(--orange); }
.agent-row .install-hint {
  font-size: 10px;
  color: var(--blue);
  margin-left: 6px;
}

.modal-card {
  width: min(760px, 94vw);
  max-height: 86vh;
  overflow: auto;
  background: linear-gradient(180deg, #141c2e, #101827);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 18px 14px;
  box-shadow: 0 18px 50px rgba(0,0,0,.45);
}
.modal-card pre {
  background: #0a101c; padding: 10px; border-radius: 8px; overflow: auto; font-size: 12px;
}
.settings-card h3 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 700;
}
.settings-card h4 {
  margin: 0 0 6px;
  font-size: 14px;
  color: #c9d6ef;
}
.settings-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}
.settings-block {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,.06);
}
.settings-block:first-of-type {
  border-top: 0;
  margin-top: 4px;
  padding-top: 0;
}
.status-line {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}
.hands-pair-box {
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(0,0,0,.25);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 8px;
  font-size: 12px;
  white-space: pre-wrap;
  color: #d7e0ff;
}
.hands-steps {
  margin: 10px 0 0;
  padding-left: 18px;
  line-height: 1.6;
}
.hands-steps code {
  font-size: 11px;
  color: #9ec1ff;
}
.hands-device-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
}
.hands-device-list li {
  font-size: 12px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,.05);
}
.hands-device-list .on { color: #3dffa8; }
.hands-device-list .off { color: var(--muted); }
.btn-link {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 12px;
}
.btn-link:hover { border-color: var(--blue); }
.btn-link.primary-link {
  background: rgba(70, 120, 255, .2);
  border-color: rgba(70, 120, 255, .45);
}
.form-grid {
  display: grid;
  gap: 12px;
  margin: 10px 0 12px;
}
.form-grid label,
.agent-ai-detail label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.form-grid input,
.agent-ai-detail input,
.agent-ai-detail select,
.agent-ai-detail textarea,
.coord-item input {
  background: #0e1626;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  width: 100%;
}
.form-grid input:focus,
.agent-ai-detail input:focus,
.agent-ai-detail select:focus,
.agent-ai-detail textarea:focus,
.coord-item input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(77,163,255,.15);
}
.form-2 {
  display: grid;
  grid-template-columns: 1.4fr 0.6fr;
  gap: 10px;
}
.coord-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  margin: 10px 0 12px;
  padding: 10px 12px;
  background: rgba(0,0,0,.18);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.coord-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.coord-item input {
  width: 64px;
  padding: 6px 8px;
}
.coord-check {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  grid-template-columns: none !important;
}
.auth-tabs {
  display: flex;
  gap: 8px;
  margin: 8px 0 12px;
}
.auth-tab {
  flex: 1;
  border: 1px solid rgba(255,255,255,.1);
  background: transparent;
  color: #8b9bb8;
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
}
.auth-tab.active {
  color: #e8eefc;
  border-color: #4da3ff;
  background: rgba(77,163,255,.12);
}
.workflow-status {
  padding: 10px 12px;
  margin-bottom: 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #a8b6d0;
  font-size: 13px;
  line-height: 1.5;
}
.workflow-status b {
  color: #e8eefc;
}
.form-grid-simple {
  grid-template-columns: 1fr !important;
}
.advanced-keys {
  margin: 10px 0 4px;
  color: #8b9bb8;
  font-size: 13px;
}
.advanced-keys summary {
  cursor: pointer;
  user-select: none;
  margin-bottom: 8px;
}
.advanced-keys .form-grid {
  margin-top: 6px;
}
.hidden {
  display: none !important;
}
.role-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px 28px;
  padding: 8px 4px 4px;
  max-height: none;
  overflow: visible;
}
.role-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
  transition: opacity .15s;
  white-space: nowrap;
}
.role-row:hover {
  border-color: transparent;
  background: transparent;
  opacity: 0.88;
}
.role-row.active .role-name {
  color: var(--blue);
}
.role-row .role-name {
  flex: none;
  font-weight: 500;
  color: var(--text);
  font-size: 14px;
}
.role-row .role-meta {
  display: none;
}
.role-row input.role-enable {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: #fff;
  cursor: pointer;
  flex-shrink: 0;
}
.role-badge {
  font-size: 13px;
  font-weight: 500;
  min-width: 0;
  text-align: left;
}
.role-badge.todo { color: var(--orange); }
.role-badge.ok { color: var(--green); }
.role-badge.off { color: #6b7a94; }
.role-editor {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid rgba(77,163,255,.35);
  border-radius: 12px;
  background: rgba(36,87,255,.08);
}
.role-editor.hidden { display: none; }
.role-editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.linkish {
  background: transparent !important;
  border: none !important;
  color: var(--blue) !important;
  padding: 0 !important;
  cursor: pointer;
}
.agent-ai-detail {
  display: grid;
  gap: 10px;
}
.agent-ai-detail textarea { min-height: 72px; resize: vertical; }
.modules-block summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

#customRoleModal {
  z-index: 40;
  background: rgba(0,0,0,.65);
}
.prompt-card {
  width: min(440px, 92vw);
  background: #2b2b2b;
  border: 1px solid #3d3d3d;
  border-radius: 10px;
  padding: 16px 18px 14px;
  box-shadow: 0 16px 40px rgba(0,0,0,.5);
  color: #eee;
}
.prompt-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  color: #f0f0f0;
}
.prompt-label {
  display: grid;
  gap: 8px;
  font-size: 13px;
  color: #ddd;
  margin-bottom: 12px;
}
.prompt-label input,
.prompt-grid input,
.prompt-grid select,
.prompt-grid textarea {
  width: 100%;
  background: #1e1e1e;
  color: #fff;
  border: 1px solid #5a9fd4;
  border-radius: 4px;
  padding: 8px 10px;
  font: inherit;
}
.prompt-grid {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}
.prompt-grid label {
  display: grid;
  gap: 5px;
  font-size: 12px;
  color: #aaa;
}
.prompt-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.prompt-actions button {
  min-width: 72px;
  border-radius: 6px;
  padding: 7px 14px;
}
.prompt-actions .primary {
  background: #8ab4f8;
  border-color: #8ab4f8;
  color: #1a1a1a;
}
.prompt-actions button:not(.primary) {
  background: #3a3a3a;
  border: 1px solid #8ab4f8;
  color: #8ab4f8;
}

@media (max-width: 1100px) {
  .app { grid-template-columns: 1fr; height: auto; }
  .col { min-height: 60vh; }
  .form-2 { grid-template-columns: 1fr; }
}
