:root {
  --bg: #f4f7f7;
  --panel: #ffffff;
  --ink: #14211f;
  --ink-2: #465954;
  --muted: #7c8f8a;
  --line: #e2eaea;
  --line-2: #eef3f3;
  --accent: #0e8f80;
  --accent-ink: #0a6d62;
  --accent-soft: #e7f5f2;
  --danger: #c8352b;
  --danger-soft: #fdecea;
  --user: #0e8f80;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 40, 36, .04), 0 8px 24px -12px rgba(16, 40, 36, .18);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---------- 顶栏 ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 11px;
  background: linear-gradient(145deg, #12a394, #0b7a6d);
  font-size: 19px;
  box-shadow: 0 2px 8px -2px rgba(14, 143, 128, .55);
}
.topbar h1 { margin: 0; font-size: 15.5px; font-weight: 650; letter-spacing: .2px; }
.sub { margin: 2px 0 0; font-size: 11.5px; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 8px; }

.badge {
  font-size: 11.5px;
  padding: 4px 9px;
  border-radius: 999px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-demo { background: #fff4e5; color: #9a5b00; }
.badge-live { background: var(--accent-soft); color: var(--accent-ink); }

.btn {
  font: inherit;
  font-size: 13px;
  border-radius: 9px;
  border: 1px solid transparent;
  padding: 7px 12px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .06s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { background: var(--line-2); color: var(--ink); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); }

/* ---------- 布局 ---------- */
.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 322px minmax(0, 1fr);
  min-height: 0;
}
.sidebar {
  overflow-y: auto;
  padding: 14px;
  border-right: 1px solid var(--line);
  background: #f9fbfb;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 650;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.hint { font-size: 10.5px; font-weight: 400; color: var(--muted); }

/* 就诊人切换 */
.member-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 9px;
}
.member-head h2 { margin: 0; }
.link-btn {
  font: inherit;
  font-size: 11.5px;
  color: var(--accent-ink);
  background: none;
  border: none;
  padding: 2px 4px;
  border-radius: 5px;
  cursor: pointer;
}
.link-btn:hover { background: var(--accent-soft); }

.member-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 1px 1px 8px;
  margin-bottom: 4px;
  scrollbar-width: none;
}
.member-bar::-webkit-scrollbar { display: none; }
.member-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font: inherit;
  font-size: 12px;
  padding: 3px 11px 3px 3px;
  border: 1px solid var(--line);
  background: #fbfdfd;
  color: var(--ink-2);
  border-radius: 999px;
  cursor: pointer;
  transition: all .15s;
  max-width: 132px;
}
.member-chip:hover { border-color: var(--accent); }
.member-chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 600;
  box-shadow: 0 1px 6px -2px rgba(14, 143, 128, .4);
}
.m-avatar {
  width: 21px; height: 21px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  flex: 0 0 auto;
}
.m-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-add { padding: 3px 10px; color: var(--muted); }
.m-plus { font-size: 14px; line-height: 1; }

.btn-danger {
  background: var(--danger-soft);
  color: #a4251d;
  border: 1px solid #f3c4bf;
}
.btn-danger:hover { background: #fbdad6; }
.spacer { flex: 1; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 11.5px; color: var(--ink-2); }
.form-grid .wide { grid-column: 1 / -1; }input, select, textarea {
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: #fbfdfd;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14, 143, 128, .12);
  background: #fff;
}
.save-tip { margin: 9px 0 0; font-size: 10.5px; color: var(--muted); }
.save-tip.saved { color: var(--accent-ink); }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  font: inherit;
  font-size: 12px;
  text-align: left;
  background: #fbfdfd;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 11px;
  color: var(--ink-2);
  cursor: pointer;
  transition: all .15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft); }
.chip-sm { font-size: 11.5px; padding: 4px 9px; }

.disclaimer {
  font-size: 11px;
  line-height: 1.65;
  color: var(--muted);
  margin: auto 0 0;
  padding: 6px 4px 2px;
}
.disclaimer strong { color: var(--ink-2); }

/* ---------- 主区 ---------- */
.main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--panel);
}
.redflag {
  margin: 12px 20px 0;
  padding: 12px 14px;
  background: var(--danger-soft);
  border: 1px solid #f6c6c1;
  border-left: 4px solid var(--danger);
  border-radius: 10px;
  color: #8f2019;
  font-size: 13.5px;
  line-height: 1.6;
  font-weight: 500;
  animation: flagIn .22s ease-out;
}
@keyframes flagIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.chat {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
}

.msg { display: flex; gap: 11px; max-width: 780px; animation: msgIn .2s ease-out; }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.avatar {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  border-radius: 9px;
  display: grid; place-items: center;
  font-size: 14px;
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.msg.user .avatar { background: #e9efee; }
.bubble {
  font-size: 14px;
  line-height: 1.72;
  color: var(--ink);
  background: #f7fafa;
  border: 1px solid var(--line-2);
  border-radius: 13px;
  padding: 11px 14px;
  min-width: 0;
  overflow-wrap: anywhere;
}
.msg.user .bubble { background: var(--user); border-color: var(--user); color: #fff; }
.bubble p { margin: 0 0 9px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h3 {
  margin: 14px 0 6px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--accent-ink);
  display: flex;
  align-items: center;
  gap: 6px;
}
.bubble h3:first-child { margin-top: 0; }
.msg.user .bubble h3 { color: #fff; }
.bubble ul, .bubble ol { margin: 0 0 9px; padding-left: 20px; }
.bubble li { margin: 3px 0; }
.bubble strong { font-weight: 650; }
.msg.assistant .bubble strong { color: var(--accent-ink); }
.bubble code {
  background: #e9f1f0;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12.5px;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
.bubble pre {
  background: #f1f6f5;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 4px 0 10px;
}
.bubble pre code { background: none; padding: 0; font-size: 12.5px; line-height: 1.6; }
.bubble hr { border: none; border-top: 1px solid var(--line); margin: 12px 0; }
.bubble table { border-collapse: collapse; width: 100%; font-size: 13px; margin: 4px 0 10px; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; }
.bubble th { background: #f0f6f5; font-weight: 600; }

.bubble.error { background: var(--danger-soft); border-color: #f6c6c1; color: #8f2019; }

.typing { display: inline-flex; gap: 4px; padding: 3px 0; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* ---------- 输入区 ---------- */
.composer {
  flex: 0 0 auto;
  padding: 10px 20px 14px;
  border-top: 1px solid var(--line-2);
  background: linear-gradient(#fff, #fcfdfd);
}
.attach-bar {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px;
  margin-bottom: 8px;
  background: #f7fafa;
  border: 1px solid var(--line);
  border-radius: 10px;
  width: fit-content;
}
.attach-bar img { width: 42px; height: 42px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.attach-name { font-size: 12px; color: var(--ink-2); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-remove {
  border: none; background: transparent; cursor: pointer;
  color: var(--muted); font-size: 13px; padding: 2px 4px; border-radius: 5px;
}
.attach-remove:hover { background: var(--line); color: var(--ink); }

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 15px;
  padding: 7px 8px 7px 10px;
  transition: border-color .15s, box-shadow .15s;
}
.composer-row:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(14, 143, 128, .1); }
#input {
  flex: 1 1 auto;
  border: none;
  background: transparent;
  resize: none;
  padding: 5px 2px;
  max-height: 168px;
  line-height: 1.6;
  font-size: 14px;
}
#input:focus { box-shadow: none; background: transparent; }
.icon-btn {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--line-2); color: var(--accent-ink); }
.send-btn {
  flex: 0 0 auto;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.send-btn:hover:not(:disabled) { background: var(--accent-ink); }
.send-btn:disabled { opacity: .35; cursor: not-allowed; }
.composer-tip { margin: 8px 2px 0; font-size: 10.5px; color: var(--muted); }

/* ---------- 对话框 ---------- */
.dialog {
  border: none;
  padding: 0;
  border-radius: 16px;
  box-shadow: 0 24px 60px -20px rgba(10, 40, 36, .45);
  max-width: 560px;
  width: calc(100vw - 40px);
  color: var(--ink);
}
.dialog::backdrop { background: rgba(12, 30, 28, .38); backdrop-filter: blur(2px); }
.dialog-inner { padding: 20px 22px 18px; display: flex; flex-direction: column; gap: 11px; }
.dialog h2 { margin: 0; font-size: 16px; font-weight: 650; }
.dialog-desc { margin: 0 0 4px; font-size: 12px; line-height: 1.65; color: var(--muted); }
.dialog label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--ink-2); font-weight: 500; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.presets { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 11.5px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.summary-box {
  margin: 0;
  background: #f7fafa;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.75;
  white-space: pre-wrap;
  max-height: 44vh;
  overflow-y: auto;
  color: var(--ink);
}

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #cfdedb; border-radius: 999px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #a9c2bd; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 窄屏 ---------- */
.only-mobile { display: none; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; position: relative; }
  .only-mobile { display: inline-block; }

  .sidebar {
    position: absolute;
    inset: 0 0 auto 0;
    max-height: 74vh;
    z-index: 30;
    display: none;
    border-right: none;
    border-bottom: 1px solid var(--line);
    border-radius: 0 0 18px 18px;
    box-shadow: 0 18px 40px -18px rgba(10, 40, 36, .4);
    background: #f9fbfb;
  }
  .sidebar.open { display: flex; }

  .topbar { padding: 10px 12px; flex-wrap: wrap; }
  .topbar .sub { display: none; }
  .chat, .composer { padding-left: 12px; padding-right: 12px; }
  .redflag { margin-left: 12px; margin-right: 12px; }
  .msg { max-width: 100%; }
  .bubble { font-size: 13.5px; padding: 10px 12px; }
  .composer { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
  .composer-tip { font-size: 10px; }
}
