:root {
  --bg: #fdf6ff;
  --card: #fff;
  --ink: #3a2a4a;
  --accent: #b46bd6;
  --muted: #9a8eaa;
  --radius: 18px;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
header {
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #eee;
  gap: 12px;
}
header a {
  color: var(--accent);
  text-decoration: none;
}
main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 96px;
}
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
  box-shadow: 0 2px 10px rgba(180, 107, 214, 0.13);
}
.card h2 {
  margin: 0 0 8px;
  font-size: 18px;
}
.row {
  display: flex;
  gap: 12px;
  align-items: center;
}
.cute {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  object-fit: cover;
  background: #eee;
  flex-shrink: 0;
}
input,
button {
  font: inherit;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #e2d6ec;
  width: 100%;
}
button {
  background: var(--accent);
  color: #fff;
  border: 0;
  cursor: pointer;
  font-weight: 600;
}
button.secondary {
  background: #fff;
  color: var(--accent);
}
button:disabled {
  opacity: 0.6;
}
/* Device info card: text block flexes, Action pill pinned to the right edge. */
.dev-info {
  flex: 1;
  min-width: 0;
}
.action-pill {
  width: auto; /* beat the global button{width:100%} */
  flex-shrink: 0;
  white-space: nowrap;
  border-radius: 999px;
  padding: 10px 18px;
  box-shadow: 0 4px 12px rgba(180, 107, 214, 0.35);
}
.action-pill:active {
  transform: scale(0.96);
}
/* Action modal: centered dialog for the remote actions (capture / play
   audio). Mask click, × and Esc all close it. */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
}
.modal[hidden] {
  display: none;
}
.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(58, 42, 74, 0.35);
  backdrop-filter: blur(2px);
  animation: fade-in 0.15s ease-out;
}
.modal-card {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 340px);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(58, 42, 74, 0.25);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: pop-in 0.18s ease-out;
  /* 动作越来越多（摇杆/头部动作/投递模式），小屏放不下 —— 卡片限高内部滚动 */
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* 吸顶：卡片内滚时 × 不被卷走。负 margin 抵消卡片 padding，铺满整宽 */
  position: sticky;
  top: -20px;
  z-index: 1;
  margin: -20px -20px 0;
  padding: 20px 0 8px;
  background: var(--card);
}
.modal-head h3 {
  margin: 0;
  font-size: 18px;
}
.modal-x {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  background: #f4ecfa;
  color: var(--ink);
  font-size: 18px;
  line-height: 1;
}
/* Tappable action row (Capture): white tile with icon circle + description. */
.modal-action {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  background: #fff;
  color: var(--ink); /* beat the global button{color:#fff} */
  border: 1px solid #eee2f6;
  border-radius: 14px;
  padding: 12px;
  width: 100%;
}
.modal-action:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 14px rgba(180, 107, 214, 0.18);
}
.modal-action:active {
  transform: scale(0.98);
}
.ma-ic {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: #f4ecfa;
  font-size: 20px;
  flex-shrink: 0;
}
.ma-tx {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}
.ma-go {
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}
.modal-box {
  background: #faf3ff;
  border: 1px solid #f0e4f9;
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.modal-box-head {
  font-size: 14px;
}
.modal-box select {
  font: inherit;
  padding: 10px 12px;
  padding-right: 34px;
  border-radius: 10px;
  border: 1px solid #e2d6ec;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%239a8eaa' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center / 10px;
  appearance: none;
}
.modal-hint {
  margin: 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}
/* Joystick pad (device Move control): hold & drag the knob, release to stop. */
.joy-pad {
  position: relative;
  width: 150px;
  height: 150px;
  margin: 4px auto;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #fff 0%, #f3e8fb 75%);
  border: 2px solid #e2d6ec;
  touch-action: none; /* keep pointer events on the pad (no scroll on touch) */
  user-select: none;
  cursor: grab;
}
.joy-pad.dragging {
  cursor: grabbing;
}
.joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 3px 10px rgba(122, 74, 153, 0.45);
  pointer-events: none; /* the pad receives every pointer event */
  transition: transform 0.15s;
}
.joy-pad.dragging .joy-knob {
  transition: none;
}
.joy-arrow {
  position: absolute;
  color: #c9b8dd;
  font-size: 11px;
  pointer-events: none;
}
.joy-n { top: 6px; left: 50%; transform: translateX(-50%); }
.joy-e { right: 6px; top: 50%; transform: translateY(-50%); }
.joy-s { bottom: 6px; left: 50%; transform: translateX(-50%); }
.joy-w { left: 6px; top: 50%; transform: translateY(-50%); }
@keyframes fade-in {
  from {
    opacity: 0;
  }
}
@keyframes pop-in {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.92);
  }
}
.muted {
  color: var(--muted);
  font-size: 13px;
}
.badge {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f0e6f7;
  color: var(--accent);
}
.badge.pending {
  background: #fff3cd;
  color: #8a6d00;
}
/* Device-status dot (device detail): chatting/idle green（在线）/ offline gray */
.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.dot.chatting { background: #2e9e5b; }
.dot.idle { background: #2e9e5b; }
.dot.offline { background: #9aa0a6; }
.fab {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  font-size: 28px;
}
dialog {
  border-radius: var(--radius);
  border: 1px solid #e2d6ec;
  padding: 20px;
  max-width: 90vw;
}
.bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  margin: 6px 0;
}
.bubble.user {
  background: #f3e8fb;
  margin-left: auto;
}
.bubble.assistant {
  background: #fff;
  border: 1px solid #eee;
  margin-right: auto;
}
.live-sep {
  text-align: center;
  font-size: 12px;
  color: #999;
  margin: 10px 0;
}
.vision img {
  width: 100%;
  border-radius: 12px;
  display: block;
}
a.card {
  text-decoration: none;
  color: inherit;
}

/* Knowledge base MCP toggle switch */
.switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 30px;
  flex-shrink: 0;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  padding: 0;
  margin: 0;
  border: 0;
}
.switch .slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #d9d1e2;
  border-radius: 999px;
  transition: background 0.2s;
}
.switch .slider::before {
  content: '';
  position: absolute;
  height: 24px;
  width: 24px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
.switch input:checked + .slider {
  background: var(--accent);
}
.switch input:checked + .slider::before {
  transform: translateX(22px);
}

/* Knowledge doc binding dropdown (device detail): check = bind, uncheck = unbind */
.doc-dd {
  position: relative;
  margin-left: auto;
  flex-shrink: 0;
}
.doc-dd summary {
  list-style: none;
  cursor: pointer;
  width: auto;
  background: #fff;
  color: var(--accent);
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid #e2d6ec;
}
.doc-dd summary::-webkit-details-marker {
  display: none;
}
.doc-dd-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 10;
  background: #fff;
  border: 1px solid #e2d6ec;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(58, 42, 74, 0.18);
  padding: 8px;
  min-width: 230px;
  max-height: 280px;
  overflow-y: auto;
}
.doc-dd-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.doc-dd-panel label:hover {
  background: #f7f0fb;
}
.doc-dd-panel label span:first-of-type {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-dd-panel input[type='checkbox'] {
  width: auto;
  margin: 0;
  flex-shrink: 0;
}
.doc-dd-panel .dd-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 6px 8px;
}

/* Worker Params 面板（device detail，照 admin simulate_chat 的 .sim-wp 移植） */
.wp-panel {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.wp-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.wp-grid label {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.wp-grid input,
.wp-grid select,
.wp-grid textarea {
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid #e4dcef;
  border-radius: 6px;
  font-family: inherit;
}
.wp-grid textarea {
  resize: vertical;
}
.wp-span {
  grid-column: 1 / -1;
}
/* Personality mix 滑条区（Figma KOKO 431:41537）：名称+Effect 说明 | 滑条 | 数值 */
.wp-mix {
  border: 1px solid #e4dcef;
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.wp-mix-row {
  display: grid;
  grid-template-columns: 1fr 120px 20px;
  align-items: center;
  gap: 8px;
}
.wp-mix-name {
  font-size: 13px;
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}
.wp-mix-name .muted {
  font-size: 11px;
}
.wp-mix-v {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}
.wp-preview {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--muted);
  background: #f8f5fc;
  border-radius: 6px;
  padding: 8px 10px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 140px;
  overflow-y: auto;
}

/* 硬件状态 chips（device detail 主卡片，get_status 回报解析） */
.hw-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  align-items: center;
}
.hw-chip {
  font-size: 12px;
  background: #f1eaf8;
  border-radius: 10px;
  padding: 2px 8px;
  white-space: nowrap;
}

/* Device status modal 解析视图 */
.st-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
  border-bottom: 1px dashed #eee7f4;
  font-size: 12px;
}
.st-k {
  color: var(--muted);
  flex-shrink: 0;
}
.st-v {
  text-align: right;
  word-break: break-all;
}
.st-raw {
  margin-top: 6px;
  font-size: 11px;
}
.st-raw pre {
  margin: 4px 0 0;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--muted);
}
