:root {
  --green: #2e7d5b;
  --green-dark: #1f5c43;
  --green-light: #e8f3ee;
  --ink: #22312a;
  --muted: #6b7d74;
  --bg: #f4f6f4;
  --card: #ffffff;
  --border: #dfe7e2;
  --user-bg: #d8ecff;
  --shadow: 0 1px 3px rgba(31, 60, 48, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1180px;
  margin: 0 auto;
  background: var(--bg);
}

/* 主体：侧栏 + 聊天 */
.body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* 顶部 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  display: block;
}
.brand-text h1 { margin: 0; font-size: 18px; color: var(--green-dark); }
.brand-text p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.topbar-controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.control { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.control select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  color: var(--ink);
}
.control-checkbox { cursor: pointer; user-select: none; }
.control-checkbox input { accent-color: var(--green); }

/* 主体 */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

/* 侧栏 */
.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 10px;
  overflow: hidden;
}
.user-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; background: var(--green-light);
  border-radius: 12px; border: 1px solid var(--border);
}
.user-avatar {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--green); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
  flex-shrink: 0; overflow: hidden; font-weight: 600;
}
.user-avatar img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.modal-brand-icon {
  width: 28px; height: 28px; border-radius: 6px; vertical-align: -6px; margin-right: 4px;
}
.user-info { min-width: 0; }
.user-name { font-size: 15px; font-weight: 600; color: var(--green-dark); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-sub { font-size: 11px; color: var(--muted); }

.btn-block { width: 100%; }
.about-entry { margin-top: 8px; }
.btn-user { background: var(--green-light); color: var(--green-dark); border: 1px solid var(--border); padding: 6px 14px; font-size: 13px; }
.btn-user:hover { background: var(--green); color: #fff; }

.history-title { font-size: 12px; color: var(--muted); font-weight: 600; padding: 0 4px; }
.history-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.history-empty { font-size: 12px; color: var(--muted); text-align: center; padding: 20px 8px; line-height: 1.6; }
.history-item {
  position: relative;
  padding: 9px 30px 9px 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.12s;
}
.history-item:hover { border-color: var(--green); background: var(--green-light); }
.history-item.active { border-color: var(--green); background: var(--green-light); }
.history-item .h-title { font-size: 13px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item .h-time { font-size: 11px; color: var(--muted); margin-top: 3px; }
.history-item .h-del {
  position: absolute; top: 8px; right: 6px;
  width: 20px; height: 20px; border: none; border-radius: 6px;
  background: transparent; color: var(--muted); font-size: 13px; cursor: pointer;
  display: none; align-items: center; justify-content: center;
}
.history-item:hover .h-del { display: flex; }
.history-item .h-del:hover { background: #fdecea; color: #b3261e; }

/* 登录框 */
.modal-narrow { width: min(400px, 92vw); }
.modal-about { width: min(520px, 94vw); max-height: 86vh; display: flex; flex-direction: column; }
.modal-about .about-body {
  overflow-y: auto;
  padding: 4px 2px 8px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
}
.about-hero {
  text-align: center;
  margin-bottom: 12px;
}
.about-hero img {
  width: 72px; height: 72px; border-radius: 16px; object-fit: cover;
}
.about-meta { margin-top: 4px; font-size: 12px; color: var(--muted); }
.about-tagline { margin-top: 8px; font-size: 13px; color: var(--green); font-weight: 600; }
.about-summary { margin-top: 10px; }
.about-highlights {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 14px 0 6px;
}
.about-hi {
  background: var(--green-light);
  border-radius: 10px;
  padding: 10px 6px;
  text-align: center;
}
.about-hi .v { display: block; font-size: 18px; font-weight: 700; color: var(--green-dark); }
.about-hi .l { display: block; margin-top: 2px; font-size: 11px; color: var(--muted); }
.about-bullets { margin: 12px 0 0; padding-left: 1.15em; }
.about-bullets li { margin: 6px 0; }
.about-mv { margin-top: 12px; font-size: 13px; color: var(--muted); }
.about-mv strong { color: var(--green-dark); }
.about-disclaimer {
  margin-top: 12px;
  padding: 10px 12px;
  background: #f7f4ec;
  border-radius: 8px;
  font-size: 12px;
  color: #7a6a45;
}
.about-welcome { margin-top: 14px; text-align: center; }
.about-link {
  border: none;
  background: transparent;
  color: var(--green);
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 0;
  font-family: inherit;
}
.about-link:hover { color: var(--green-dark); }
@media (max-width: 520px) {
  .about-highlights { grid-template-columns: repeat(2, 1fr); }
}
.login-row { margin: 6px 0 4px; }
.login-row label { font-size: 13px; font-weight: 600; display: block; margin-bottom: 6px; }
.login-row input {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 15px; font-family: inherit; outline: none;
}
.login-row input:focus { border-color: var(--green); }

/* 移动端菜单按钮 */
.mobile-menu-btn {
  display: none; background: none; border: none; font-size: 22px;
  color: var(--green-dark); cursor: pointer; padding: 0 6px;
}

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

/* 欢迎页 */
.welcome { text-align: center; padding: 40px 20px; }
.welcome-icon {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  object-fit: cover;
  display: block;
  margin: 0 auto;
}
.welcome h2 { color: var(--green-dark); margin: 12px 0 8px; font-size: 22px; }
.welcome p { color: var(--muted); max-width: 560px; margin: 0 auto 20px; line-height: 1.7; }
.examples { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-bottom: 24px; }
.example {
  padding: 8px 16px;
  border: 1px solid var(--green);
  color: var(--green-dark);
  background: var(--green-light);
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.example:hover { background: var(--green); color: #fff; }
.disclaimer { font-size: 12px; color: #b08a3e; background: #fbf3e2; border: 1px solid #f0e2c0; border-radius: 8px; padding: 10px 14px; display: inline-block; }

/* 消息 */
.message { display: flex; margin-bottom: 18px; gap: 10px; }
.message.user { flex-direction: row-reverse; }
.avatar {
  width: 36px; height: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
  background: var(--green-light);
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.message.user .avatar { background: var(--user-bg); }
.bubble {
  max-width: 76%;
  padding: 12px 16px;
  border-radius: 14px;
  line-height: 1.7;
  font-size: 15px;
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  word-break: break-word;
}
.message.ai .bubble { background: var(--card); border: 1px solid var(--border); border-top-left-radius: 4px; }
.message.user .bubble { background: var(--user-bg); border-top-right-radius: 4px; }
.bubble .backend-tag { display: block; font-size: 11px; color: var(--muted); margin-bottom: 6px; }

/* AI 气泡内的 Markdown 渲染 */
.bubble.md { white-space: normal; }
.bubble.md p { margin: 0 0 10px; }
.bubble.md p:last-child { margin-bottom: 0; }
.bubble.md h3, .bubble.md h4, .bubble.md h5 {
  margin: 14px 0 8px;
  color: var(--green-dark);
  line-height: 1.4;
}
.bubble.md h3 { font-size: 17px; }
.bubble.md h4 { font-size: 16px; }
.bubble.md h5 { font-size: 15px; }
.bubble.md h3:first-child, .bubble.md h4:first-child, .bubble.md h5:first-child { margin-top: 0; }
.bubble.md ul, .bubble.md ol { margin: 6px 0 12px; padding-left: 22px; }
.bubble.md li { margin: 4px 0; }
.bubble.md strong { color: var(--green-dark); font-weight: 600; }
.bubble.md em { font-style: italic; }
.bubble.md code {
  background: var(--green-light);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 13px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
}

/* 参考医案卡片 */
.cases {
  max-width: 76%;
  margin: -8px 0 18px 46px;
  padding: 10px 14px;
  background: #f7f4ec;
  border: 1px solid #e7dfca;
  border-radius: 10px;
  font-size: 12px;
  color: #7a6a45;
}
.cases summary { cursor: pointer; font-weight: 600; }
.cases .case-item { margin-top: 8px; padding-top: 8px; border-top: 1px dashed #e0d6bd; }
.cases .case-item .score { color: #a08b57; }

/* 健康管理咨询联系卡片 */
.contact-card {
  max-width: 76%;
  margin: -4px 0 18px 46px;
  padding: 14px 16px;
  background: var(--green-light);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--ink);
}
.contact-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--green-dark);
}
.contact-subtitle {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}
.contact-phone {
  display: inline-block;
  margin-top: 10px;
  color: var(--green-dark);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
}
.contact-phone:hover { text-decoration: underline; }
.contact-wechat { margin-top: 12px; }
.contact-wechat-label {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}
.contact-qr {
  display: block;
  width: 148px;
  height: 148px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.composer-area {
  background: var(--card);
  border-top: 1px solid var(--border);
}
.composer {
  display: flex;
  gap: 10px;
  padding: 10px 20px 14px;
  align-items: center;
}
.contact-entry { flex-shrink: 0; }
#contact-modal .contact-subtitle { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
#contact-modal .contact-phone { display: inline-block; margin-top: 4px; }
#contact-modal .contact-wechat { margin-top: 14px; }
#contact-modal .contact-qr { width: 160px; height: 160px; }

/* 快捷回复条 */
.quick-replies {
  display: flex;
  gap: 8px;
  padding: 10px 20px 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.quick-replies::-webkit-scrollbar { display: none; }
.quick-replies:empty { padding: 0; }
.qr-chip {
  flex-shrink: 0;
  padding: 6px 14px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.qr-chip:hover { border-color: var(--green); color: var(--green-dark); background: var(--green-light); }

/* 工具行 */
.tool-row {
  display: flex;
  gap: 8px;
  padding: 10px 20px 0;
  flex-wrap: wrap;
}
.tool-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.tool-btn:hover { border-color: var(--green); color: var(--green-dark); background: var(--green-light); }

/* 附件预览 */
.attachments {
  display: flex;
  gap: 10px;
  padding: 10px 20px 0;
  flex-wrap: wrap;
}
.attachments:empty { padding: 0; }
.attachment {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.attachment img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attachment .att-kind {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: rgba(31, 60, 48, 0.7);
  color: #fff; font-size: 11px; text-align: center; padding: 2px 0;
}
.attachment .att-remove {
  position: absolute; top: 2px; right: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(0,0,0,0.55); color: #fff;
  border: none; font-size: 12px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* 聊天中的图片消息 */
.bubble img.chat-photo {
  max-width: 220px;
  border-radius: 10px;
  display: block;
  margin-top: 6px;
  cursor: zoom-in;
}

/* 预问诊模态框 */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal-mask { position: absolute; inset: 0; background: rgba(20, 35, 28, 0.45); }
.modal-body {
  position: relative;
  width: min(680px, 92vw);
  max-height: 86vh;
  overflow-y: auto;
  background: var(--card);
  border-radius: 16px;
  padding: 20px 22px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.18);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; }
.modal-header h2 { margin: 0; font-size: 18px; color: var(--green-dark); }
.modal-close { background: none; border: none; font-size: 20px; color: var(--muted); cursor: pointer; }
.modal-tip { font-size: 12px; color: var(--muted); margin: 8px 0 14px; }

.intake-fields { display: flex; flex-direction: column; gap: 14px; }
.intake-field .field-label { font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 7px; }
.intake-field .field-label .multi-hint { font-weight: 400; color: var(--muted); font-size: 11px; }
.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 6px 13px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 999px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.12s;
  user-select: none;
}
.chip:hover { border-color: var(--green); }
.chip.selected { background: var(--green); border-color: var(--green); color: #fff; }

.intake-note-row { margin-top: 16px; }
.intake-note-row label { font-size: 13px; font-weight: 600; display: block; margin-bottom: 6px; }
.intake-note-row textarea {
  width: 100%; resize: vertical;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  font-family: inherit; font-size: 14px; outline: none;
}
.intake-note-row textarea:focus { border-color: var(--green); }

.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* 合规提示 */
.compliance-note {
  margin-top: 16px;
  padding: 12px 14px;
  background: #fbf3e2;
  border: 1px solid #f0e2c0;
  border-radius: 10px;
  font-size: 12px;
  color: #8a6d2f;
  line-height: 1.7;
}
.compliance-footer {
  padding: 6px 20px 10px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  border-top: 1px dashed var(--border);
}

#input {
  flex: 1;
  resize: none;
  max-height: 160px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.5;
  outline: none;
}
#input:focus { border-color: var(--green); }

.btn {
  padding: 12px 22px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--green-dark); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); padding: 6px 14px; font-size: 13px; }
.btn-ghost:hover { background: var(--green-light); color: var(--green-dark); }

/* 流式光标 */
.streaming::after {
  content: "▍";
  color: var(--green);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.error-banner {
  max-width: 76%;
  margin: 0 0 18px 46px;
  padding: 10px 14px;
  background: #fdecea;
  border: 1px solid #f5c6c0;
  color: #b3261e;
  border-radius: 10px;
  font-size: 13px;
}

/* 错误横幅内的一键重试按钮 */
.retry-btn {
  margin-left: 8px;
  padding: 4px 14px;
  border: 1px solid #b3261e;
  border-radius: 999px;
  background: #fff;
  color: #b3261e;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.retry-btn:hover { background: #b3261e; color: #fff; }

/* 急危重症提醒横幅（最醒目级别） */
.emergency-banner {
  max-width: 88%;
  margin: 0 0 18px 46px;
  padding: 14px 16px;
  background: #d32f2f;
  border: 2px solid #b71c1c;
  color: #fff;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.7;
  box-shadow: 0 4px 14px rgba(211, 47, 47, 0.35);
}
.emergency-banner .em-title { font-size: 15px; display: block; margin-bottom: 4px; }

/* 后端自动降级提示 */
.switch-banner {
  max-width: 76%;
  margin: 0 0 18px 46px;
  padding: 8px 14px;
  background: #e3f2fd;
  border: 1px solid #bbdefb;
  color: #1565c0;
  border-radius: 10px;
  font-size: 12px;
}

/* 照片仅存档提示 */
.photo-notice {
  align-self: center;
  font-size: 11px;
  color: var(--muted);
  cursor: help;
}

/* 医案相似度定性标签 */
.cases .case-item .sim-tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  margin-right: 6px;
}
.cases .case-item .sim-high { background: #e8f5e9; color: #2e7d32; }
.cases .case-item .sim-mid { background: #fff3e0; color: #e65100; }
.cases .case-item .sim-low { background: #f5f5f5; color: #757575; }

@media (max-width: 760px) {
  .bubble, .cases, .contact-card, .error-banner { max-width: 88%; }
  .brand-text p { display: none; }
  .mobile-menu-btn { display: block; }
  .sidebar {
    position: absolute; z-index: 50; top: 0; bottom: 0; left: 0;
    transform: translateX(-100%);
    transition: transform 0.2s;
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }
  .sidebar.open { transform: translateX(0); }
}
