:root {
  --bg: #14161d;
  --panel: #0f1116;
  --card: #1b1e28;
  --card2: #171a23;
  --border: #262b38;
  --text: #d7dbe4;
  --dim: #8b93a5;
  --accent: #6f7bff;
  --accent-soft: rgba(111, 123, 255, 0.14);
  --green: #3fbf7f;
  --red: #e5605c;
  --orange: #e6a23c;
  --mono: Consolas, "JetBrains Mono", "Courier New", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body, #app { height: 100%; }

body {
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  overflow: hidden;
}

#app { display: flex; }

button { font-family: inherit; }

/* ---------- 侧边栏 ---------- */
#sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px 10px;
  gap: 12px;
}

.side-header { display: flex; align-items: center; gap: 10px; padding: 2px 6px; }

.logo-mini {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #6f7bff, #9b6fff);
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  display: flex; align-items: center; justify-content: center;
}

.app-name { font-weight: 600; letter-spacing: 0.3px; }

.btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  font-size: 13.5px;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { border-color: #3a4152; background: #20242f; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #5f6cf0; }
.btn.primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--card); }
.btn.danger { background: transparent; border-color: rgba(229, 96, 92, 0.5); color: var(--red); }
.btn.danger:hover { background: rgba(229, 96, 92, 0.1); }
.btn.block { width: 100%; }

#sessionList { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }

.session-item {
  display: flex; align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--dim);
  font-size: 13px;
}
.session-item:hover { background: var(--card2); color: var(--text); }
.session-item.active { background: var(--accent-soft); color: var(--text); }
.s-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s-del {
  border: none; background: none; color: var(--dim);
  cursor: pointer; font-size: 12px; padding: 2px 4px; border-radius: 4px;
  visibility: hidden;
}
.session-item:hover .s-del { visibility: visible; }
.s-del:hover { color: var(--red); background: rgba(229, 96, 92, 0.12); }

.side-footer { display: flex; flex-direction: column; gap: 8px; }
.ver { text-align: center; color: #565d6d; font-size: 11px; }

/* ---------- 主区域 ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 17, 22, 0.6);
}

#workspaceBox {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer;
  padding: 5px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  color: var(--dim);
  font-size: 13px;
  max-width: 55%;
  overflow: hidden;
}
#workspaceBox:hover { border-color: var(--border); background: var(--card2); color: var(--text); }
#workspacePath { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; }
.ws-icon { min-width: 18px; }

.top-right { display: flex; align-items: center; gap: 10px; }

.badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--dim);
}
.badge.ok { color: var(--green); border-color: rgba(63, 191, 127, 0.4); }
.badge.none { color: var(--orange); border-color: rgba(230, 162, 60, 0.4); }

/* ---------- 聊天区 ---------- */
#chatScroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; }

#chatList {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 20px 10px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

#welcome {
  max-width: 720px;
  margin: 0 auto;
  padding: 60px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
}

.w-logo {
  width: 64px; height: 64px;
  border-radius: 18px;
  background: linear-gradient(135deg, #6f7bff, #9b6fff);
  color: #fff; font-size: 34px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 32px rgba(111, 123, 255, 0.35);
}

#welcome h1 { font-size: 26px; font-weight: 600; }
.w-sub { color: var(--dim); line-height: 1.6; }

.w-steps { display: flex; gap: 12px; margin-top: 14px; width: 100%; }
.w-step {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  display: flex; flex-direction: column; gap: 6px;
  transition: border-color 0.15s, transform 0.15s;
}
.w-step:hover { border-color: var(--accent); transform: translateY(-2px); }
.w-step b { font-size: 13.5px; }
.w-step span { color: var(--dim); font-size: 12px; }

.w-examples { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }
.chip {
  border: 1px solid var(--border);
  background: var(--card2);
  color: var(--dim);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12.5px;
  cursor: pointer;
}
.chip:hover { color: var(--text); border-color: var(--accent); }

/* ---------- 消息 ---------- */
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  background: #2a3153;
  border: 1px solid #39415f;
  border-radius: 14px 14px 4px 14px;
  padding: 10px 14px;
  max-width: 78%;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
}

.msg.assistant .md { line-height: 1.7; word-break: break-word; }
.msg.assistant .md p { margin: 6px 0; }
.msg.assistant .md h1, .msg.assistant .md h2, .msg.assistant .md h3 { margin: 14px 0 8px; }
.msg.assistant .md ul, .msg.assistant .md ol { padding-left: 22px; margin: 6px 0; }
.msg.assistant .md li { margin: 3px 0; }
.msg.assistant .md blockquote {
  border-left: 3px solid var(--border);
  color: var(--dim);
  padding-left: 12px;
  margin: 8px 0;
}
.msg.assistant .md a { color: var(--accent); }
.msg.assistant .md code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}
.msg.assistant .md pre {
  position: relative;
  background: #10131a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 10px 0;
  overflow-x: auto;
}
.msg.assistant .md pre code {
  background: none; border: none; padding: 0;
  font-size: 12.5px; line-height: 1.6;
  color: #cdd6e8;
}
.copy-btn {
  position: absolute; top: 6px; right: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--dim);
  font-size: 11px;
  border-radius: 5px;
  padding: 2px 8px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
pre:hover .copy-btn { opacity: 1; }

.streaming::after {
  content: "▍";
  color: var(--accent);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.msg.error {
  color: var(--red);
  background: rgba(229, 96, 92, 0.08);
  border: 1px solid rgba(229, 96, 92, 0.3);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.6;
}

/* ---------- 工具卡片 ---------- */
.tool-card {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  font-size: 12.5px;
}
.tool-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
}
.tool-head:hover { background: var(--card); }
.tool-status { font-weight: 700; width: 16px; text-align: center; }
.tool-status.run { color: var(--accent); animation: spin 1.2s linear infinite; display: inline-block; }
.tool-status.ok { color: var(--green); }
.tool-status.bad { color: var(--red); }
.tool-status.warn { color: var(--orange); }
@keyframes spin { to { transform: rotate(360deg); } }
.tool-name { font-family: var(--mono); color: #9aa6ff; }
.tool-arg {
  flex: 1;
  font-family: var(--mono);
  color: var(--dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12px;
}
.tool-toggle { color: var(--dim); font-size: 11px; }
.tool-body { border-top: 1px solid var(--border); }
.tool-body pre {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  padding: 10px 12px;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: #b6c0d4;
}

/* ---------- 确认卡片 ---------- */
.approval-card {
  border: 1px solid rgba(230, 162, 60, 0.45);
  border-left: 4px solid var(--orange);
  background: rgba(230, 162, 60, 0.07);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.ap-title { font-size: 13.5px; }
.ap-detail {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--orange);
  background: rgba(0, 0, 0, 0.25);
  border-radius: 6px;
  padding: 8px 10px;
  white-space: pre-wrap;
  word-break: break-all;
}
.ap-actions { display: flex; gap: 8px; }
.ap-decided { color: var(--green); font-size: 13px; }
.ap-decided.no { color: var(--red); }

/* ---------- 输入区 ---------- */
#composerWrap { padding: 10px 20px 14px; }
#composer {
  max-width: 860px;
  margin: 0 auto;
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
}
#composer:focus-within { border-color: var(--accent); }
#input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  max-height: 200px;
}
#input::placeholder { color: #565d6d; }
.hint {
  max-width: 860px;
  margin: 6px auto 0;
  text-align: center;
  color: #565d6d;
  font-size: 11.5px;
}

/* ---------- 设置弹窗 ---------- */
.mask {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  width: 480px;
  max-width: calc(100vw - 40px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}
.modal-title { font-size: 17px; font-weight: 600; }
.modal label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--dim); }
.modal input, .modal select {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13.5px;
  outline: none;
  font-family: inherit;
}
.modal input:focus, .modal select:focus { border-color: var(--accent); }
.modal .row { display: flex; gap: 8px; }
.modal .row input { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.modal-note { font-size: 11.5px; color: #565d6d; line-height: 1.6; }

.hidden { display: none !important; }

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #2a3040; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #39415a; }
::-webkit-scrollbar-track { background: transparent; }
