:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --card: #ffffff;
  --line: #e3e8f0;
  --text: #1b2430;
  --muted: #6b7788;
  --accent: #2f6bff;
  --accent-soft: #eaf0ff;
  --green: #17a673;
  --red: #d64545;
  --amber: #b7791f;
  --shadow: 0 10px 30px rgba(21, 35, 60, .08);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.screen { min-height: 100vh; min-height: 100dvh; }
.center { display: flex; align-items: center; justify-content: center; padding: 24px; }
.card {
  width: min(460px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}
h1 { margin: 0 0 12px; font-size: 28px; letter-spacing: .5px; }
.muted { color: var(--muted); line-height: 1.7; font-size: 16px; margin: 8px 0; }
.small { font-size: 13px; }
.error { color: var(--red); min-height: 22px; font-size: 14px; margin: 10px 0 0; }
.code-input {
  width: 100%;
  margin: 18px 0 14px;
  padding: 16px 14px;
  font-size: 30px;
  letter-spacing: .5em;
  text-align: center;
  border: 2px solid var(--line);
  border-radius: 14px;
  outline: none;
}
.code-input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

button.primary {
  border: 0;
  background: var(--accent);
  color: #fff;
  border-radius: 12px;
  padding: 10px 16px;
}
button.primary:disabled { opacity: .45; cursor: default; }
button.big { width: 100%; padding: 15px 18px; font-size: 18px; font-weight: 600; }
button.ghost {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 13px;
}

.chat { height: 100vh; height: 100dvh; display: flex; flex-direction: column; max-width: 880px; margin: 0 auto; }
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, .88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-size: 20px; font-weight: 700; letter-spacing: 1px; }
.status-line { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #b7c0cd; }
.dot.online { background: var(--green); box-shadow: 0 0 8px rgba(23, 166, 115, .45); }
.dot.working { background: var(--amber); animation: pulse 1.2s infinite; }
.dot.offline { background: var(--red); }
@keyframes pulse { 50% { opacity: .35; } }
.chat-header .ghost { margin-left: auto; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 88%;
  padding: 11px 14px;
  border-radius: 15px;
  font-size: 16px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.assistant .bubble { background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.msg.user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
.msg.error .bubble { background: #fff2f2; border: 1px solid #ffd2d2; color: var(--red); }
.tool {
  align-self: flex-start;
  max-width: 92%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--muted);
}
.tool b { color: var(--text); }
.system { align-self: center; color: var(--muted); font-size: 12px; padding: 4px 8px; }

.composer-wrap {
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, .92);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
}
.working {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--amber);
  font-size: 13px;
  margin-bottom: 8px;
}
.composer { display: flex; gap: 8px; align-items: flex-end; }
#input {
  flex: 1;
  min-height: 46px;
  max-height: 160px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 13px;
  font: inherit;
  font-size: 16px;
  line-height: 1.5;
  outline: none;
  background: var(--card);
  color: var(--text);
}
#input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
#sendBtn { height: 46px; padding: 0 20px; border-radius: 14px; flex: none; font-weight: 600; }
.hint { display: flex; justify-content: space-between; gap: 10px; color: #98a2b3; font-size: 11px; margin-top: 7px; }
.usage { white-space: nowrap; }

.pair-page { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.pair-card {
  width: min(520px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}
.pair-card h1 { margin-bottom: 6px; }
.qr-wrap {
  margin: 18px auto 12px;
  width: 280px;
  height: 280px;
  max-width: 90vw;
  max-height: 90vw;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
  background: #fff;
}
.qr-wrap img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.pair-status { color: var(--muted); font-size: 16px; margin: 10px 0; }
.confirm-box { margin: 10px 0 4px; }
.confirm-code {
  font-size: 46px;
  font-weight: 700;
  letter-spacing: .28em;
  color: var(--accent);
  margin: 8px 0;
  font-variant-numeric: tabular-nums;
}
.success { color: var(--green); font-size: 20px; font-weight: 600; margin: 18px 0; }
.pair-actions { display: flex; gap: 10px; justify-content: center; margin: 18px 0 8px; flex-wrap: wrap; }
.pair-actions button { padding: 9px 14px; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(18, 26, 40, .55);
  backdrop-filter: blur(3px);
}
.modal-card {
  width: min(520px, 100%);
  max-height: 84vh;
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 20px 60px rgba(18, 26, 40, .25);
}
.modal-card h2 { margin: 0 0 8px; font-size: 20px; }
#permDetail {
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #f7f9fc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  font-size: 12px;
  color: var(--muted);
}
.perm-options { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.perm-options button { width: 100%; padding: 11px 14px; text-align: left; border-radius: 11px; }
.perm-options button.allow { border-color: #b7e4d0; background: #effaf5; color: #126b4a; }
.perm-options button.deny { border-color: #f2c9c9; background: #fff4f4; color: #a83232; }
