/* 小盒子遥控器 — 蓝灰 · 微信间距 · 无气泡回复 */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
  --bg: #EEF1F5;
  --bg-top: #F7F9FB;
  --card: #FFFFFF;
  --ink: #1C2733;
  --ink2: #7A8699;
  --ink3: #A8B2BE;
  --line: #DCE3EB;
  --accent: #3D6B99;
  --accent-soft: #E7EEF6;
  --bubble: #D9E2EC;
  --ok: #2F9E6E;
  --warn: #C9922E;
}
html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  /* 输入法弹出时由 JS 写入真实可视高度，避免输入框被键盘压住 */
  --app-h: 100dvh;
}
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "MiSans", "PingFang SC", -apple-system, "Microsoft YaHei", sans-serif;
  font-size: 17px;
  line-height: 1.55;
  overscroll-behavior: none;
  position: fixed;
  inset: 0;
  width: 100%;
}
#app {
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.hidden { display: none !important; }

/* ---------- 登录 ---------- */
.login {
  min-height: 100%;
  display: grid; place-items: center;
  padding: 24px;
  background: linear-gradient(165deg, #E7EDF4 0%, #EEF1F5 45%, #E8EDF3 100%);
}
.login-card {
  width: min(340px, 92vw);
  background: var(--card);
  border-radius: 22px;
  padding: 36px 28px 28px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(28, 39, 51, 0.10);
}
.login-logo img { width: 72px; height: 72px; border-radius: 18px; }
.login-card h1 { font-size: 22px; font-weight: 600; margin-top: 16px; letter-spacing: 0.06em; }
.login-sub { color: var(--ink2); font-size: 13px; margin-top: 6px; }
#login-form { margin-top: 24px; display: grid; gap: 12px; }
#login-pwd {
  width: 100%; height: 48px; border: 1px solid var(--line); border-radius: 14px;
  padding: 0 16px; font-size: 17px; background: var(--bg-top); outline: none;
}
#login-pwd:focus { border-color: var(--accent); }
.btn-primary {
  height: 48px; border: 0; border-radius: 14px; background: var(--accent);
  color: #fff; font-size: 16px; font-weight: 500;
}
.btn-primary:active { opacity: 0.88; }
.login-err { color: #B3543F; font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---------- 主框架 ---------- */
.main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}
.topbar {
  flex: none;
  padding: calc(env(safe-area-inset-top) + 10px) 8px 10px;
  background: var(--bg-top);
  display: flex; align-items: center; gap: 4px;
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 5;
}
.icon-btn {
  width: 42px; height: 42px; border: 0; background: transparent;
  color: var(--ink); border-radius: 12px; display: grid; place-items: center;
}
.icon-btn:active { background: var(--accent-soft); }
.top-title { flex: 1; text-align: center; }
.top-name { font-size: 16px; font-weight: 600; }
.top-status, .drawer-status {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--ink2); margin-top: 1px;
}
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ink3); }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }

/* ---------- 聊天区 ---------- */
.chat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.messages { padding: 14px 20px 20px; max-width: 720px; margin: 0 auto; }
.msg { margin-bottom: 10px; }
.msg-time { text-align: center; font-size: 11px; color: var(--ink3); margin: 14px 0; }

/* 用户：浅气泡 */
.msg-user { display: flex; justify-content: flex-end; }
.msg-user .bubble {
  background: var(--bubble);
  color: var(--ink);
  border-radius: 18px;
  padding: 10px 14px;
  max-width: 78%;
  font-size: 17px;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}

/* 小盒子：无气泡，直接铺 */
.msg-bot { padding: 2px 0 4px; }
.msg-bot .text {
  font-size: 17px; line-height: 1.55; color: var(--ink);
  white-space: pre-wrap; word-break: break-word;
}
.msg-bot .meta { font-size: 12px; color: var(--ink3); margin-top: 6px; }

/* 思考流（实时） */
.live-think {
  font-size: 13px; line-height: 1.55; color: var(--ink3);
  white-space: pre-wrap; word-break: break-word;
  border-left: 2px solid var(--line); padding: 2px 0 2px 10px; margin: 2px 0 8px;
}
.live-text {
  font-size: 17px; line-height: 1.55; color: var(--ink);
  white-space: pre-wrap; word-break: break-word; opacity: 0.92;
}
.live-hint {
  font-size: 11px; color: var(--ink3); margin-top: 8px;
  animation: breathe 1.4s ease-in-out infinite;
}

/* 桌面端式：工具细条 + Markdown */
.tool-row {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 7px 0; border-top: 1px solid var(--line); cursor: pointer;
}
.tool-chip {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center;
}
.tool-chip.on { animation: breathe 1.2s ease-in-out infinite; }
.tool-main { flex: 1; min-width: 0; }
.tool-name { font-size: 13.5px; color: var(--ink); display: flex; align-items: center; gap: 6px; }
.tool-name .tool-run { font-size: 11px; color: var(--accent); }
.tool-name .chev { font-style: normal; color: var(--ink3); font-size: 11px; margin-left: auto; }
.tool-detail {
  font-size: 11.5px; color: var(--ink2); margin-top: 4px;
  word-break: break-all; line-height: 1.5;
}
.think-block { margin: 2px 0 8px; }
.think-label { font-size: 12px; color: var(--ink3); margin-bottom: 2px; }
.md-p { margin: 0 0 2px; }
.md-h { font-weight: 600; margin: 8px 0 4px; }
.md-li { padding-left: 1.1em; position: relative; margin: 1px 0; }
.md-li::before { content: "·"; position: absolute; left: 0.35em; color: var(--ink3); }
.md-gap { height: 8px; }
.text code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.86em; background: var(--accent-soft);
  padding: 1px 5px; border-radius: 6px;
}

/* 提问卡 */
.q-card {
  background: var(--card); border-radius: 16px; padding: 14px;
  margin: 10px 0 6px; box-shadow: 0 6px 20px rgba(28,39,51,0.06);
}
.q-block + .q-block { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.q-header { font-size: 11px; color: var(--accent); letter-spacing: 0.08em; margin-bottom: 4px; }
.q-title { font-size: 16px; color: var(--ink); line-height: 1.5; margin-bottom: 10px; }
.q-opt {
  display: block; width: 100%; text-align: left;
  border: 1px solid var(--line); background: var(--bg-top);
  border-radius: 12px; padding: 11px 13px; margin-bottom: 8px;
  font-size: 14px; color: var(--ink); line-height: 1.45;
}
.q-opt b { display: block; font-weight: 600; }
.q-opt span { display: block; font-size: 12px; color: var(--ink2); margin-top: 2px; }
.q-opt:active { background: var(--accent-soft); border-color: var(--accent); }
.q-free { display: flex; gap: 8px; }
.q-free input {
  flex: 1; height: 40px; border: 1px solid var(--line); border-radius: 10px;
  padding: 0 12px; font-size: 14px; background: var(--bg-top); outline: none;
}
.q-free-send {
  border: 0; background: var(--accent); color: #fff; border-radius: 10px;
  padding: 0 16px; font-size: 14px;
}
.think-toggle {
  font-size: 12px; color: var(--ink3); background: none; border: 0;
  padding: 4px 0; margin: 2px 0 6px; display: inline-flex; align-items: center; gap: 4px;
}
.think-body {
  font-size: 13px; line-height: 1.5; color: var(--ink3);
  white-space: pre-wrap; word-break: break-word;
  border-left: 2px solid var(--line); padding: 2px 0 2px 10px; margin: 0 0 8px;
}

/* 任务卡 */
.task-card {
  background: var(--bg-top); border-radius: 14px; padding: 12px 14px;
  margin: 6px 0 10px; display: flex; gap: 12px; align-items: center;
}
.task-ico {
  width: 30px; height: 30px; border-radius: 9px; background: var(--accent-soft);
  display: grid; place-items: center; flex: none;
}
.task-ico svg { width: 15px; height: 15px; color: var(--accent); }
.task-body { flex: 1; min-width: 0; }
.task-title { font-size: 14px; color: var(--ink); }
.task-sub { font-size: 12px; color: var(--ink2); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-group-head { cursor: pointer; display: flex; align-items: center; gap: 6px; }
.tool-group-head .chev { font-style: normal; color: var(--ink3); font-size: 12px; }
.task-rows { margin-top: 8px; }
.task-row {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 12px; padding: 4px 0; color: var(--ink2);
  border-top: 1px solid var(--line);
}
.task-row span { color: var(--ink); flex: none; }
.task-row em {
  font-style: normal; text-align: right;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.task-bar { height: 3px; border-radius: 2px; background: var(--line); margin-top: 8px; overflow: hidden; }
.task-bar i { display: block; height: 100%; width: 35%; background: var(--accent); border-radius: 2px; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }

/* 思考中呼吸点 */
.typing { display: inline-flex; gap: 5px; padding: 6px 0 10px; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--ink3);
  animation: breathe 1.2s ease-in-out infinite;
}
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes breathe { 0%, 100% { opacity: 0.35; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-2px); } }

/* 空状态 */
.empty { text-align: center; color: var(--ink2); padding: 18vh 20px 0; }
.empty h2 { font-size: 19px; color: var(--ink); font-weight: 600; }
.empty p { font-size: 14px; margin-top: 10px; line-height: 1.8; }

/* ---------- 输入区 ---------- */
.dock {
  flex: none;
  position: relative;
  z-index: 6;
  padding: 6px 10px calc(env(safe-area-inset-bottom) + 8px);
  background: var(--bg-top);
  border-top: 1px solid var(--line);
}
.chips {
  display: flex; gap: 8px; margin: 0 2px 6px;
}
.seg {
  display: inline-flex; background: var(--bg); border-radius: 10px; padding: 3px;
}
.seg button {
  border: 0; background: none; padding: 6px 12px; border-radius: 8px;
  font-size: 12px; color: var(--ink2);
}
.seg button.on {
  background: var(--card); color: var(--accent); font-weight: 600;
  box-shadow: 0 1px 4px rgba(28, 39, 51, 0.08);
}
.img-preview {
  display: flex; gap: 8px; padding: 4px 2px 8px; overflow-x: auto;
}
.img-thumb {
  position: relative; flex: none;
}
.img-thumb img {
  width: 56px; height: 56px; object-fit: cover;
  border-radius: 10px; display: block;
}
.img-thumb button {
  position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px; border-radius: 50%;
  border: 0; background: var(--ink); color: #fff; font-size: 11px;
}
.dock-form {
  display: flex; align-items: flex-end; gap: 4px;
  max-width: 720px; margin: 0 auto;
}
.dock-form .icon-btn { flex: none; margin-bottom: 2px; }
#btn-mic.recording {
  color: #B3543F;
  background: #F6E7E2;
  border-radius: 50%;
}
#input {
  flex: 1; resize: none; border: 1px solid var(--line); background: var(--card);
  border-radius: 22px; padding: 11px 14px; font-size: 16px; line-height: 1.4;
  font-family: inherit; outline: none; max-height: 120px;
}
#input:focus { border-color: var(--accent); }
.send-btn {
  width: 42px; height: 42px; border: 0; border-radius: 50%;
  background: var(--accent); color: #fff; display: grid; place-items: center; flex: none;
  margin-bottom: 1px;
}
.send-btn:disabled { opacity: 0.45; }
.send-btn:active { transform: scale(0.95); }
.msg-img {
  max-width: 180px; border-radius: 12px; display: block; margin-bottom: 6px;
}

/* ---------- 抽屉 ---------- */
.scrim { position: fixed; inset: 0; background: rgba(28,39,51,0.32); z-index: 20; }
.drawer {
  position: fixed; left: 0; top: 0; width: 82vw; max-width: 320px;
  height: 100vh; height: 100lvh;
  background: var(--bg-top); z-index: 21; padding: calc(env(safe-area-inset-top) + 18px) 16px 16px;
  transform: translateX(-102%); transition: transform 0.22s ease;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-title { font-size: 20px; font-weight: 600; }
.drawer-status { margin-top: 3px; font-size: 12px; }
.drawer-new {
  margin: 16px 0 6px; height: 46px; border: 0; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent); font-size: 15px; font-weight: 600;
}
.drawer-label { font-size: 12px; color: var(--ink3); margin: 14px 4px 8px; }
.conv-list { overflow-y: auto; flex: 1; }
.conv-item {
  padding: 10px 10px; border-radius: 12px; cursor: pointer;
}
.conv-item:active, .conv-item.on { background: var(--accent-soft); }
.conv-item .t { font-size: 15px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .s { font-size: 11px; color: var(--ink3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-sep { height: 1px; background: var(--line); margin: 10px 0; }
.drawer-item {
  border: 0; background: none; text-align: left; font-size: 15px; color: var(--ink);
  padding: 13px 10px; border-radius: 12px;
}
.drawer-item:active { background: var(--accent-soft); }
.drawer-foot { font-size: 11px; color: var(--ink3); margin-top: 12px; text-align: center; }

/* ---------- 弹层 ---------- */
.sheet {
  position: fixed; inset: 0; background: rgba(28,39,51,0.32); z-index: 30;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-card {
  width: 100%; max-width: 720px; max-height: 82vh;
  background: var(--card); border-radius: 22px 22px 0 0;
  padding: 18px 20px calc(env(safe-area-inset-bottom) + 18px);
  display: flex; flex-direction: column;
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 17px; font-weight: 600; margin-bottom: 12px;
}
.sheet-body { overflow-y: auto; font-size: 15px; line-height: 1.7; }
.sheet-body .row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 13px 2px; border-bottom: 1px solid var(--line); gap: 12px;
}
.sheet-body .row:last-child { border-bottom: 0; }
.sheet-body .k { color: var(--ink); }
.sheet-body .v { color: var(--ink2); font-size: 13px; text-align: right; }
.sheet-body .hint { color: var(--ink3); font-size: 12px; margin-top: 10px; line-height: 1.7; }
.sec-title {
  font-size: 12px; color: var(--accent); letter-spacing: 0.08em;
  margin: 12px 0 4px; font-weight: 600;
}
.seg { display: inline-flex; background: var(--bg); border-radius: 10px; padding: 3px; }
.seg button {
  border: 0; background: none; padding: 7px 14px; border-radius: 8px;
  font-size: 13px; color: var(--ink2);
}
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 4px rgba(28,39,51,0.08); }
.switch { width: 46px; height: 27px; border-radius: 999px; background: var(--line); position: relative; border: 0; }
.switch i { position: absolute; top: 3px; left: 3px; width: 21px; height: 21px; border-radius: 50%; background: #fff; transition: left 0.15s; }
.switch.on { background: var(--ok); }
.switch.on i { left: 22px; }

/* ===== v2 精致化 ===== */
.md-table-wrap {
  overflow-x: auto; margin: 8px 0; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card);
  -webkit-overflow-scrolling: touch;
}
.md-table { border-collapse: collapse; width: 100%; font-size: 0.84em; }
.md-table th, .md-table td {
  border: 0; border-bottom: 1px solid var(--line);
  padding: 7px 10px; text-align: left; vertical-align: top;
  white-space: normal; min-width: 64px;
}
.md-table tr:last-child td { border-bottom: 0; }
.md-table th { background: var(--bg-top); color: var(--ink); font-weight: 600; }
.md-table td { color: var(--ink); }
.md-table tbody tr:nth-child(even) td { background: rgba(247, 249, 251, 0.7); }
.fabs {
  position: fixed; right: 12px; top: 34%;
  display: flex; flex-direction: column; gap: 10px;
  opacity: 0; pointer-events: none; transition: opacity 0.25s ease; z-index: 8;
}
.fabs.show { opacity: 1; pointer-events: auto; }
.fab {
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card);
  color: var(--ink2); font-size: 15px;
  box-shadow: 0 4px 14px rgba(28, 39, 51, 0.12);
}
.fab:active { transform: scale(0.92); }
.conv-search {
  width: 100%; height: 38px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--card);
  padding: 0 12px; font-size: 13px; color: var(--ink);
  outline: none; margin-bottom: 6px; font-family: inherit;
}
.conv-search:focus { border-color: var(--accent); }

/* 紧凑化：更精致，去掉老年机感 */
.topbar { padding: calc(env(safe-area-inset-top) + 6px) 6px 6px; }
.top-name { font-size: 15px; }
.top-status { font-size: 10.5px; }
.icon-btn { width: 38px; height: 38px; }
.msg { margin-bottom: 8px; }
.msg-user .bubble { padding: 8px 12px; border-radius: 16px; font-size: 1em; max-width: 82%; }
.msg-bot .text { font-size: 1em; line-height: 1.6; }
.msg-bot .meta { font-size: 11px; margin-top: 4px; }
.think-body { font-size: 0.82em; line-height: 1.55; }
.think-toggle { font-size: 11.5px; padding: 2px 0; margin: 1px 0 4px; }
.tool-row { padding: 5px 0; }
.tool-chip { width: 22px; height: 22px; border-radius: 7px; }
.tool-name { font-size: 12.5px; }
.tool-detail { font-size: 11px; margin-top: 3px; }
.md-p { margin: 0 0 1px; line-height: 1.6; }
.md-h { font-size: 1.02em; margin: 6px 0 3px; }
.md-gap { height: 6px; }
.live-hint { font-size: 10.5px; margin-top: 6px; }
.q-card { padding: 12px; border-radius: 14px; }
.q-title { font-size: 1em; margin-bottom: 8px; }
.q-opt { padding: 9px 11px; font-size: 0.92em; border-radius: 11px; }
.seg button { padding: 5px 10px; font-size: 11.5px; }
.chips { margin-bottom: 5px; gap: 6px; }
.dock { padding: 5px 8px calc(env(safe-area-inset-bottom) + 6px); }
#input { padding: 10px 13px; font-size: 15px; border-radius: 20px; }
.send-btn { width: 38px; height: 38px; }
.conv-item { padding: 8px 10px; }
.conv-item .t { font-size: 14px; }
.conv-item .s { font-size: 10.5px; }
.drawer-title { font-size: 18px; }
.drawer-item { font-size: 14px; padding: 11px 10px; }
.empty h2 { font-size: 17px; }
.empty p { font-size: 13px; }
.sheet-body { font-size: 14px; }
.sheet-body .row { padding: 11px 2px; }
.sheet-body .k { font-size: 14px; }
.sheet-body .v { font-size: 12px; }

/* ===== v3 ===== */
.sec-card {
  background: var(--card); border-radius: 12px;
  border: 1px solid var(--line); padding: 2px 12px;
}
.sec-card .row:last-child { border-bottom: 0; }
.sheet-body .row .k {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0; flex: 1;
}
.sheet-body .row .v {
  white-space: nowrap; flex: none; max-width: 46%;
}
.pin { margin-right: 4px; font-size: 11px; }

.conv-item.press { background: var(--accent-soft); }

.q-actions { display: flex; gap: 8px; margin-top: 10px; }
.q-ghost {
  border: 1px solid var(--line); background: var(--bg-top); color: var(--ink2);
  border-radius: 10px; padding: 8px 12px; font-size: 12.5px;
}
.q-ghost.danger { color: #B3543F; border-color: #E8C9C0; }

.live-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; }
#btn-mic.busy { opacity: 0.5; }
