:root {
  --green: #2f9e6e;
  --green-d: #1f7d56;
  --green-mid: #2f9e6e;
  --teal: #16a6a0;
  --bg: #ffffff;            /* 页面背景：纯白（参照截图） */
  --card: #ffffff;
  --text: #1f2d28;
  --muted: #6b7d75;
  --user-bubble: #eceef0;       /* 提问者：灰底 */
  --user-bubble-text: #222222;  /* 提问者：黑字 */
  --border: #ececec;
  --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* 外层容器：透明，不再用白卡片（参照截图：白底无边框） */
.app {
  max-width: 760px;
  margin: 0 auto;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: transparent;
}

/* ---------- 顶栏（绿色 + 品牌 + 模式徽章 + 设置）---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: linear-gradient(135deg, #3aae80, #2f9e6e);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 44px; height: 44px; border-radius: 10px;
  display: block; object-fit: cover;
  background: #fff;
}
.brand-text { width: 132px; }
.brand-title { font-size: 19px; font-weight: 700; line-height: 1.2; text-align: justify; text-justify: inter-character; }
.brand-sub { font-size: 13px; opacity: 0.9; line-height: 1.2; margin-top: 2px; text-align: justify; text-justify: inter-character; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.badge {
  font-size: 13px; padding: 4px 12px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.18); color: #fff;
}
.badge-ai { background: #ffffff; color: var(--green-d); font-weight: 700; }
.badge-demo { background: rgba(255, 255, 255, 0.22); color: #fff; }
.icon-btn {
  border: none; background: rgba(255, 255, 255, 0.18); color: #fff;
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 16px;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.32); }

/* ---------- 聊天区 ---------- */
.chat {
  flex: 1; overflow-y: auto; padding: 18px 20px 12px;
  display: flex; flex-direction: column; gap: 18px;
  background: #ffffff;
}
.msg { display: flex; gap: 12px; max-width: 100%; width: 100%; }
.msg.bot { align-self: flex-start; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }

.bubble {
  flex: 1; padding: 4px 6px; line-height: 1.75;
  white-space: pre-wrap; word-break: break-word; font-size: 16px;
  background: transparent; border: none; border-radius: 0;
}
/* AI 回复：无气泡，直接排版 */
.msg.bot .bubble { background: transparent; border: none; padding: 2px 4px; }
/* 提问者：灰底黑字，靠右 */
.msg.user .bubble {
  background: var(--user-bubble); color: var(--user-bubble-text);
  text-align: right; padding: 12px 16px; border-radius: 16px;
  display: inline-block; width: auto; max-width: 78%;
}
.bubble em { color: var(--green-d); font-style: normal; font-weight: 600; }

/* ---------- Markdown 渲染（参照截图的版式）---------- */
/* 章节标题：绿色加粗，前置 ● 圆点 */
.bubble .md-h {
  display: block; font-weight: 700; color: var(--green-mid);
  line-height: 1.4; margin: 16px 0 0; letter-spacing: 0.2px;
  font-size: 1.08em;
}
.bubble .md-h::before {
  content: "● ";
  color: var(--green-mid);
  margin-right: 4px;
  font-size: 0.9em;
}
.bubble .md-h.md-h1 { font-size: 1.20em; }
.bubble .md-h.md-h2 { font-size: 1.14em; }
.bubble .md-h.md-h3,
.bubble .md-h.md-h4,
.bubble .md-h.md-h5,
.bubble .md-h.md-h6 { font-size: 1.06em; }

/* 关键词加粗 + 浅绿底高亮 */
.bubble .md-strong {
  font-weight: 700; color: #1f7d56;
  background: rgba(47, 158, 110, 0.16);
  padding: 1px 6px; border-radius: 4px;
  margin: 0 1px;
}

/* 列表：绿色 • + 缩进 */
.bubble .md-ul {
  list-style: none; margin: 8px 0 12px; padding-left: 0;
}
.bubble .md-ul li {
  position: relative; padding-left: 1.4em; margin: 6px 0; line-height: 1.75;
}
.bubble .md-ul li::before {
  content: "•";
  color: var(--green-mid);
  position: absolute; left: 0; top: 0;
  font-weight: 700; font-size: 1.1em;
}

/* 正在输入动画 */
.typing span {
  display: inline-block; width: 6px; height: 6px; margin: 0 2px;
  border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3 } 40% { opacity: 1 } }

/* ---------- 输入区（白底圆角浮卡）---------- */
.composer {
  padding: 8px 12px 14px;
  background: transparent;
  border-top: none;
}
.composer-inner {
  display: flex; gap: 10px; align-items: flex-end;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 8px 10px 8px 14px;
  box-shadow: var(--shadow-card);
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px;
  padding: 8px 4px;
  border: none; background: transparent;
  font-size: 16px; line-height: 1.5;
  font-family: inherit; outline: none;
}
.composer textarea::placeholder { color: #9aa7a1; }
.send-btn {
  flex: none;
  border: none; background: var(--green); color: #fff; font-weight: 600;
  height: 40px; padding: 0 22px;
  border-radius: 12px; cursor: pointer; font-size: 16px;
  transition: background 0.15s ease;
}
.send-btn:hover { background: var(--green-d); }
.send-btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(15, 30, 24, 0.45);
  display: grid; place-items: center; z-index: 50;
}
.modal.hidden { display: none; }
.modal-card {
  width: min(520px, 92vw); background: #fff; border-radius: 16px;
  padding: 22px; box-shadow: 0 10px 40px rgba(0,0,0,0.15);
  max-height: 90vh; overflow-y: auto;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 18px; font-weight: 700; margin-bottom: 8px;
}
.modal-head .icon-btn { background: #f0f2f1; color: var(--text); }
.modal-head .icon-btn:hover { background: #e2e7e4; }
.modal-tip { font-size: 14px; color: var(--muted); line-height: 1.6; margin: 0 0 14px; }
.modal-tip b { color: var(--green-d); }
.modal-card label {
  display: block; font-size: 14px; color: var(--muted); margin: 12px 0 6px;
}
.modal-card input[type="text"],
.modal-card input[type="password"],
.modal-card select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 15px; outline: none; font-family: inherit;
}
.modal-card input:focus, .modal-card select:focus { border-color: var(--green); }
.checkbox-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px !important; color: var(--text) !important; margin: 16px 0 6px !important;
}
.checkbox-row input { width: auto !important; }
.proxy-hint { font-size: 13px; color: var(--muted); line-height: 1.5; margin: 6px 0 0; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.primary-btn {
  flex: 1; border: none; background: var(--green); color: #fff; font-weight: 600;
  padding: 11px; border-radius: 10px; cursor: pointer; font-size: 15px;
}
.primary-btn:hover { background: var(--green-d); }
.ghost-btn {
  border: 1px solid var(--border); background: #fff; color: var(--muted);
  padding: 11px 14px; border-radius: 10px; cursor: pointer; font-size: 15px;
}
.ghost-btn:hover { border-color: var(--green); color: var(--green-d); }

/* ---------- 顶栏新按钮：新建 / 历史（替代原设置按钮）---------- */
.topbar-action {
  display: inline-flex; align-items: center; gap: 4px;
  border: none; background: rgba(255, 255, 255, 0.18); color: #fff;
  padding: 6px 10px; border-radius: 8px; cursor: pointer;
  font-size: 13px; font-weight: 600; line-height: 1;
  transition: background 0.15s ease;
}
.topbar-action:hover { background: rgba(255, 255, 255, 0.32); }
.topbar-action .ico { font-size: 16px; line-height: 1; font-weight: 700; }
.topbar-right .topbar-action { color: #fff; }

/* ---------- 历史对话抽屉（右侧滑入）---------- */
.drawer-mask {
  position: fixed; inset: 0; background: rgba(15, 30, 24, 0.32);
  z-index: 60; opacity: 0; pointer-events: none;
  transition: opacity 0.18s ease;
}
.drawer-mask:not(.hidden) { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; right: 0; top: 0; bottom: 0;
  width: min(360px, 88vw); background: #fff;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.10);
  transform: translateX(100%); transition: transform 0.22s ease;
  z-index: 61; display: flex; flex-direction: column;
}
.drawer:not(.hidden) { transform: translateX(0); }
.drawer-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
  font-size: 17px; font-weight: 700; color: var(--text);
}
.drawer-head .icon-btn { background: #f0f2f1; color: var(--text); }
.drawer-head .icon-btn:hover { background: #e2e7e4; }
.drawer-body { flex: 1; overflow-y: auto; padding: 4px 0 24px; }
.hist-group-title {
  font-size: 13px; color: var(--muted); font-weight: 600;
  padding: 14px 18px 6px;
}
.hist-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; cursor: pointer; border-bottom: 1px solid #f3f4f3;
  transition: background 0.12s ease;
}
.hist-item:hover { background: #f7faf8; }
.hist-item.active { background: rgba(47, 158, 110, 0.08); }
.hist-item.active .hist-title { color: var(--green-d); font-weight: 600; }
.hist-title {
  flex: 1; font-size: 15px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hist-meta { font-size: 12px; color: var(--muted); flex: none; }
.hist-del {
  border: none; background: transparent; color: var(--muted);
  font-size: 14px; padding: 2px 8px; border-radius: 4px; cursor: pointer;
  opacity: 0; transition: opacity 0.15s;
}
.hist-item:hover .hist-del { opacity: 1; }
.hist-del:hover { background: #ffe6e6; color: #d83a3a; }
.hist-empty {
  padding: 48px 24px; color: var(--muted); font-size: 14px; text-align: center;
}