:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: rgba(255, 255, 255, .07);
  --text: #e8ebf2;
  --muted: #8a93a6;
  --brand: #4d6bfe;
  --brand-2: #6d5cf6;
  --user: #2b3a6b;
  --ok: #5ad19a;
  --warn: #f5b955;
  --err: #ff7a7a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  display: flex; flex-direction: column;
  overflow: hidden;
}

/* 顶栏 */
header {
  flex: none;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: rgba(15, 17, 21, .92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.brand .dot {
  width: 26px; height: 26px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
}
.brand .name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand .state { width: 6px; height: 6px; border-radius: 50%; background: #4a5162; flex: none; }
.brand .state.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.icon-btn {
  flex: none; width: 34px; height: 34px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.icon-btn:active { background: var(--panel-2); }

/* 消息区 */
main {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 14px 14px 10px;
  display: flex; flex-direction: column; gap: 12px;
}
.row { display: flex; flex-direction: column; max-width: 100%; }
.row.user { align-items: flex-end; }
.row.ai { align-items: flex-start; }
.bubble {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: 16px;
  font-size: 15px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word;
}
.row.user .bubble { background: var(--user); border-bottom-right-radius: 6px; }
.row.ai .bubble { background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.bubble :where(code) {
  background: #101319; border: 1px solid var(--line); border-radius: 6px;
  padding: 1px 5px; font-size: 13px;
}
.bubble pre {
  background: #0d1015; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px; overflow-x: auto; font-size: 12.5px; margin: 6px 0;
}

/* 工具卡片 */
.tool {
  align-self: flex-start; max-width: 90%;
  display: flex; align-items: center; gap: 8px;
  padding: 7px 11px; border-radius: 11px;
  background: #12151b; border: 1px solid var(--line);
  font-size: 12.5px; color: var(--muted);
}
.tool .sp { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); flex: none; }
.tool.done .sp { background: var(--ok); }
.tool.fail .sp { background: var(--err); }
.tool .tname { color: #b9c3d6; font-family: ui-monospace, Menlo, monospace; }
.tool .tprev { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 审批卡 */
.approval {
  align-self: stretch;
  border: 1px solid rgba(245, 185, 85, .45);
  background: rgba(245, 185, 85, .07);
  border-radius: 14px; padding: 12px;
}
.approval .title { color: var(--warn); font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.approval .code {
  background: #0d1015; border: 1px solid var(--line); border-radius: 9px;
  padding: 9px; font-size: 12px; font-family: ui-monospace, Menlo, monospace;
  color: #c7d0e0; white-space: pre-wrap; word-break: break-all; max-height: 120px; overflow: auto;
  margin-bottom: 9px;
}
.approval .acts { display: flex; gap: 8px; }
.approval button {
  flex: 1; border: 0; border-radius: 10px; padding: 9px; font-size: 13.5px; font-weight: 600;
}
.approval .allow { background: var(--warn); color: #201802; }
.approval .deny { background: #2a2f3c; color: #cfd6e4; }

/* 输入区 */
.composer-wrap {
  flex: none;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(15, 17, 21, .96);
  border-top: 1px solid var(--line);
}
.chips { display: flex; gap: 6px; padding: 0 2px 8px; overflow-x: auto; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--panel);
  color: var(--muted); border-radius: 999px; padding: 5px 11px; font-size: 12px;
}
.chip.on { border-color: rgba(77, 107, 254, .6); background: rgba(77, 107, 254, .15); color: #b9c6ff; }
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 8px 8px 8px 14px;
}
.composer:focus-within { border-color: rgba(77, 107, 254, .55); }
#input {
  flex: 1; border: 0; outline: none; resize: none; background: transparent;
  color: var(--text); font-size: 15px; line-height: 1.45;
  max-height: 132px; min-height: 22px; padding: 5px 0;
  font-family: inherit;
}
#input::placeholder { color: #5f6779; }
#send {
  flex: none; width: 38px; height: 38px; border-radius: 13px; border: 0;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; font-size: 17px;
}
#send:disabled { opacity: .4; }

/* 抽屉 */
.mask {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 20;
  opacity: 0; pointer-events: none; transition: opacity .18s;
}
.mask.on { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: 82%; max-width: 320px;
  background: #12151b; border-right: 1px solid var(--line); z-index: 21;
  transform: translateX(-102%); transition: transform .2s ease;
  display: flex; flex-direction: column;
  padding: calc(14px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
}
.drawer.on { transform: translateX(0); }
.drawer h2 { font-size: 15px; margin: 4px 6px 12px; display: flex; align-items: center; justify-content: space-between; }
.drawer h2 button {
  border: 1px solid var(--line); background: var(--panel); color: #cfd6e4;
  border-radius: 9px; padding: 6px 10px; font-size: 12px;
}
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.conv {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 10px; border-radius: 10px; font-size: 13.5px; color: #cfd6e4;
}
.conv.on { background: rgba(77, 107, 254, .14); color: #c9d3ff; }
.conv .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .del { color: #6b7284; font-size: 15px; padding: 2px 4px; }
.drawer .foot { padding-top: 10px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }

/* 技能面板 */
.skill-panel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 22;
  background: #12151b; border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  max-height: 70vh; display: flex; flex-direction: column;
  transform: translateY(102%); transition: transform .22s ease;
  padding-bottom: env(safe-area-inset-bottom);
}
.skill-panel.on { transform: translateY(0); }
.skill-panel .hd { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 8px; font-size: 15px; font-weight: 600; }
.skill-panel .hd button { border: 0; background: none; color: var(--muted); font-size: 14px; }
.skill-list { overflow-y: auto; padding: 4px 10px 14px; }
.skill-item { padding: 10px 10px; border-radius: 11px; }
.skill-item.on { background: rgba(77, 107, 254, .13); }
.skill-item .n { font-size: 13.5px; color: #d7deec; font-family: ui-monospace, Menlo, monospace; }
.skill-item .d { font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.45; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 30px 0; }
