:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --line: #e3e2dd;
  --text: #1f1f1d;
  --muted: #6b6a65;
  --faint: #97968f;
  --accent: #185fa5;
  --accent-soft: #e6f1fb;
  --warn: #a32d2d;
  --ok: #0f6e56;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
}

button:hover { border-color: var(--muted); }
button[disabled] { opacity: .5; cursor: default; }

/* ---------- 登录 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  z-index: 10;
}

.overlay[hidden] { display: none; }

.card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
}

.card h1 { margin: 0 0 4px; font-size: 17px; font-weight: 500; }
.card .hint { margin: 0 0 16px; color: var(--muted); font-size: 13px; }

.card input {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 10px;
}

.card button {
  width: 100%;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}

.card .err { color: var(--warn); font-size: 13px; margin: 12px 0 0; }
.card .hint.gap { margin-top: 14px; }

/* ---------- 主界面 ---------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 900px;
  margin: 0 auto;
}

#app[hidden] { display: none; }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.bar-left { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.bar-right { display: flex; gap: 6px; }

.ghost { padding: 6px 10px; font-size: 13px; }
.ghost.warn { color: var(--warn); border-color: var(--warn); }
.ghost[hidden] { display: none; }

.model-select {
  padding: 6px 8px;
  font-size: 13px;
  border: 1px solid var(--border, #e2e2e2);
  border-radius: 6px;
  background: var(--card, #fff);
  color: var(--text, #222);
  cursor: pointer;
  max-width: 180px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--faint);
  flex: none;
}

.dot.busy { background: #ba7517; }
.dot.live { background: var(--ok); }
.dot.dead { background: var(--warn); }

.status {
  padding: 6px 14px;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.log {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  border-radius: 12px;
  padding: 10px 12px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
  font-size: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.msg.user { background: var(--accent-soft); border-color: #b5d4f4; }
.msg.assistant { background: var(--surface); }
.msg.err { background: #fcebeb; border-color: #f7c1c1; color: #501313; }
.msg.sys { background: transparent; border-style: dashed; color: var(--muted); font-size: 12px; }

/* 助手气泡内部：思考块 / 工具卡 / 正文 依次排列，彼此留白 */
.msg.assistant > * + * { margin-top: 8px; }
.msg.assistant > .tool { white-space: normal; }

.tool {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
}

.tool > summary {
  cursor: pointer;
  padding: 9px 12px;
  font-size: 13px;
  font-family: var(--mono);
  color: var(--accent);
  list-style: none;
}

.tool > summary::-webkit-details-marker { display: none; }
.tool[data-state="error"] > summary { color: var(--warn); }

.tool-body { border-top: 1px solid var(--line); }
.tool-body[hidden] { display: none; }

.tool-label {
  padding: 8px 12px 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .05em;
  color: var(--faint);
}

.tool-label[hidden], .tool pre[hidden] { display: none; }

.tool pre {
  margin: 0;
  padding: 4px 12px 10px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 340px;
  overflow: auto;
  background: var(--bg);
}

.thinking {
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--muted);
  white-space: pre-wrap;
}

.composer {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.composer textarea {
  flex: 1;
  resize: none;
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
  max-height: 160px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}

.composer textarea:focus { outline: none; border-color: var(--accent); }

.composer button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
  align-self: flex-end;
}

/* ---------- 顶部导航用链接（与 button 同款外观） ---------- */
a.ghost {
  display: inline-block;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  text-decoration: none;
  line-height: 1.35;
}
a.ghost:hover { border-color: var(--muted); }

/* ---------- 微信扫码页 ---------- */
.page { max-width: 520px; margin: 0 auto; padding: 18px 16px 40px; }
.page h2 { font-size: 17px; font-weight: 600; margin: 0 0 6px; }
.page p.lead { font-size: 13px; color: var(--muted); margin: 0 0 18px; line-height: 1.7; }
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 14px;
}
.qrbox { text-align: center; }
.qrbox img {
  width: 260px; height: 260px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px;
}
.qrbox .ph {
  width: 260px; height: 260px; margin: 0 auto;
  display: flex; align-items: center; justify-content: center;
  border: 1px dashed var(--line); border-radius: 10px;
  color: var(--faint); font-size: 13px;
}
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; border: 1px solid var(--line); color: var(--muted);
}
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.bad { color: var(--warn); border-color: var(--warn); }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.kv { font-size: 13px; color: var(--muted); line-height: 1.9; word-break: break-all; }
.kv b { color: var(--text); font-weight: 500; }
ol.steps { font-size: 13px; color: var(--muted); line-height: 1.9; padding-left: 18px; margin: 0; }
ol.steps b { color: var(--text); font-weight: 500; }

/* 注意：bridge 下发的是 style-src 'self'，页面里**不能**写内联 style（会被浏览器丢掉），
   间距、字号一律走下面这些类。 */
.panel h2.small { font-size: 15px; }
.qrbox .lead { margin: 14px 0 0; }
.lead.gap { margin: 14px 0 0; }
.lead.sample {
  margin: 12px 0 0;
  padding: 10px 12px;
  background: var(--accent-soft);
  border: 1px solid #b5d4f4;
  border-radius: 10px;
  color: var(--text);
}
.lead.sample[hidden] { display: none; }
.kv.kv-gap { margin-top: 12px; }

/* ---------- 主动问候面板 ---------- */
.fields { display: flex; flex-direction: column; gap: 10px; }
.field {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--muted);
}
.field input[type="time"],
.field input[type="number"] {
  font: inherit;
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
.field input[type="number"] { width: 68px; }
.field input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}
.field .tilde { color: var(--faint); }

