:root {
  --bg: #ffffff;
  --bg-soft: #f7f8f9;
  --bg-chat: #fbfbfb;
  --ink: #0c0d0e;
  --ink-2: #52575d;
  --ink-3: #9aa0a6;
  --line: #e6e8ea;
  --line-2: #d3d6d9;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, .07);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, .07);
  --warn: #ea580c;
  --warn-soft: rgba(234, 88, 12, .08);
  --ok: #16a34a;
  --ok-soft: rgba(22, 163, 74, .07);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

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

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15.5px;
  line-height: 1.7;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 顶栏 ---------- */
.bar {
  flex: 0 0 auto;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.bar-in {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 20px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand b { font-size: 15px; font-weight: 620; letter-spacing: -.01em; white-space: nowrap; }
.brand i {
  font-style: normal;
  font-size: 12px;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pulse {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(22,163,74,.14);
  animation: breathe 2.6s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 3px rgba(22,163,74,.14); }
  50% { box-shadow: 0 0 0 6px rgba(22,163,74,.05); }
}
.reset {
  font-size: 13px;
  font-family: inherit;
  color: var(--ink-2);
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .18s, color .18s;
}
.reset:hover { border-color: var(--line-2); color: var(--ink); }
@media (max-width: 560px) { .brand i { display: none; } }

/* ---------- 对话区 ---------- */
.chat {
  flex: 1 1 auto;
  overflow-y: auto;
  background: var(--bg-chat);
  padding: 26px 0 20px;
  scroll-behavior: smooth;
}
.chat > * { max-width: 720px; margin-left: auto; margin-right: auto; padding-left: 20px; padding-right: 20px; }

/* 欢迎页 */
.welcome { padding-top: 20px; padding-bottom: 30px; }
.welcome h1 {
  font-size: clamp(24px, 4.2vw, 32px);
  font-weight: 650;
  letter-spacing: -.026em;
  margin-bottom: 10px;
}
.welcome > p {
  font-size: 15px;
  color: var(--ink-2);
  max-width: 34em;
  margin-bottom: 26px;
}
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 28px; }
.quick button {
  font-size: 13.5px;
  font-family: inherit;
  color: var(--ink-2);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 100px;
  padding: 8px 15px;
  cursor: pointer;
  transition: border-color .18s, color .18s, background .18s, transform .18s;
}
.quick button:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
.quick button:active { transform: scale(.97); }
.tips {
  font-size: 12.5px;
  color: var(--ink-3);
  background: var(--danger-soft);
  border-left: 2px solid rgba(220,38,38,.35);
  border-radius: 0 6px 6px 0;
  padding: 10px 14px;
  max-width: 40em;
}

/* 消息 */
.msg { display: flex; gap: 11px; margin-bottom: 20px; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  background: var(--ink);
  color: #fff;
  border-radius: 14px 14px 4px 14px;
  padding: 11px 16px;
  max-width: min(78%, 520px);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
}
.avatar {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  margin-top: 2px;
}
.msg.ai .body { flex: 1 1 auto; min-width: 0; }
.msg.ai .bubble {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px 14px 14px 14px;
  padding: 12px 16px;
  max-width: min(88%, 600px);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
  line-height: 1.75;
}

/* 风险徽章 */
.risk {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 10px;
  font-size: 12.5px;
  font-weight: 500;
  border-radius: 6px;
  padding: 6px 12px;
}
.risk::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.risk[data-r="emergency"] { color: var(--danger); background: var(--danger-soft); }
.risk[data-r="urgent"]    { color: var(--warn);   background: var(--warn-soft); }
.risk[data-r="routine"]   { color: var(--accent); background: var(--accent-soft); }
.risk[data-r="self-care"] { color: var(--ok);      background: var(--ok-soft); }

/* 科室卡片 */
.dept {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 13px;
  color: var(--ink-2);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 12px;
}
.dept b { color: var(--ink); font-weight: 600; }

/* 危险信号 */
.flags {
  margin-top: 10px;
  border: 1px solid rgba(220,38,38,.22);
  background: var(--danger-soft);
  border-radius: 8px;
  padding: 11px 14px;
}
.flags-t {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--danger);
  margin-bottom: 5px;
}
.flags ul { list-style: none; }
.flags li {
  font-size: 13px;
  color: #a02020;
  padding-left: 13px;
  position: relative;
  line-height: 1.7;
}
.flags li::before {
  content: "·";
  position: absolute;
  left: 3px;
  font-weight: 700;
}

/* 追问 */
.follow { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 7px; }
.follow button {
  font-size: 13px;
  font-family: inherit;
  color: var(--ink-2);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 100px;
  padding: 6px 13px;
  cursor: pointer;
  text-align: left;
  transition: border-color .18s, color .18s, background .18s;
}
.follow button:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* 打字指示 */
.dots { display: inline-flex; gap: 5px; padding: 14px 16px; }
.dots span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--line-2);
  animation: blink 1.3s ease-in-out infinite;
}
.dots span:nth-child(2) { animation-delay: .18s; }
.dots span:nth-child(3) { animation-delay: .36s; }
@keyframes blink {
  0%, 80%, 100% { opacity: .3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

/* ---------- 输入区 ---------- */
.composer {
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  background: var(--bg);
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
}
.composer-in {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 8px 8px 14px;
  background: var(--bg);
  transition: border-color .18s, box-shadow .18s;
}
.composer-in:focus-within {
  border-color: var(--line-2);
  box-shadow: 0 0 0 3px rgba(37,99,235,.06);
}
#input {
  flex: 1 1 auto;
  border: 0;
  outline: 0;
  resize: none;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: none;
  max-height: 132px;
  padding: 4px 0;
}
#input::placeholder { color: var(--ink-3); }
#send {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  border: 0;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .18s, opacity .18s;
}
#send:hover { background: #23262a; }
#send:disabled { opacity: .35; cursor: not-allowed; }
.hint {
  max-width: 720px;
  margin: 8px auto 0;
  font-size: 11.5px;
  color: var(--ink-3);
  text-align: center;
}

/* 滚动条 */
.chat::-webkit-scrollbar { width: 8px; }
.chat::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.chat::-webkit-scrollbar-thumb:hover { background: var(--line-2); }

/* 错误 */
.err {
  margin: 0 auto 20px;
  max-width: 680px;
  font-size: 13px;
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid rgba(220,38,38,.2);
  border-radius: 8px;
  padding: 10px 14px;
}

/* ---------- 顶栏右侧 ---------- */
.bar-right { display: flex; align-items: center; gap: 8px; }
.balance {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-family: var(--mono);
  color: var(--ink-2);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 100px;
  padding: 5px 12px 5px 9px;
  cursor: pointer;
  transition: border-color .18s, color .18s, background .18s;
}
.balance:hover { border-color: var(--line-2); color: var(--ink); }
.balance i { font-style: normal; color: var(--ink-3); font-size: 11px; }
.bal-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ok);
}
.balance.low .bal-dot { background: var(--warn); }
.balance.empty .bal-dot { background: var(--danger); }
.balance.empty { color: var(--danger); border-color: rgba(220,38,38,.28); background: var(--danger-soft); }
@media (max-width: 520px) { .balance i { display: none; } }

/* ---------- 充值弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(12,13,14,.42);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  transition: opacity .2s;
}
.modal.open { display: flex; opacity: 1; }
.modal-card {
  width: 100%;
  max-width: 420px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 14px;
  box-shadow: 0 20px 60px -12px rgba(12,13,14,.28);
  transform: translateY(10px) scale(.98);
  transition: transform .22s;
}
.modal.open .modal-card { transform: none; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
}
.modal-head h3 { font-size: 16px; font-weight: 620; letter-spacing: -.01em; }
.modal-x {
  width: 28px; height: 28px;
  border: 0;
  background: none;
  font-size: 22px;
  line-height: 1;
  color: var(--ink-3);
  cursor: pointer;
  border-radius: 6px;
  transition: background .15s, color .15s;
}
.modal-x:hover { background: var(--bg-soft); color: var(--ink); }
.modal-body { padding: 18px 20px 22px; }

.bal-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.bal-row span { font-size: 13px; color: var(--ink-3); }
.bal-row b { font-family: var(--mono); font-size: 20px; font-weight: 620; letter-spacing: -.02em; }
.rate { font-size: 12px; color: var(--ink-3); margin: 9px 0 18px; }

.pay-steps { display: grid; gap: 14px; }
.step { display: flex; gap: 10px; font-size: 13.5px; color: var(--ink-2); line-height: 1.6; }
.step-n {
  flex-shrink: 0;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
  font-family: var(--mono);
}
.step-qr {
  display: flex;
  justify-content: center;
  padding: 4px 0;
}
.step-qr img {
  width: 168px;
  height: 168px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 6px;
}
.qr-fallback {
  display: none;
  width: 168px;
  height: 168px;
  border: 1px dashed var(--line-2);
  border-radius: 10px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  padding: 12px;
}
.qr-fallback b { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.qr-fallback small { font-size: 11px; color: var(--ink-3); line-height: 1.6; }
.qr-fallback code {
  font-family: var(--mono);
  background: var(--bg-soft);
  padding: 1px 4px;
  border-radius: 3px;
}

.redeem {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}
#codeInput {
  flex: 1 1 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 13px;
  font-family: var(--mono);
  font-size: 14px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink);
  outline: 0;
  background: var(--bg);
  transition: border-color .18s, box-shadow .18s;
}
#codeInput:focus {
  border-color: var(--line-2);
  box-shadow: 0 0 0 3px rgba(37,99,235,.06);
}
#redeemBtn {
  flex: 0 0 auto;
  font-size: 14px;
  font-family: inherit;
  color: #fff;
  background: var(--ink);
  border: 0;
  border-radius: 8px;
  padding: 0 20px;
  cursor: pointer;
  transition: background .18s, opacity .18s;
}
#redeemBtn:hover { background: #23262a; }
#redeemBtn:disabled { opacity: .4; cursor: not-allowed; }
.redeem-msg {
  margin-top: 9px;
  font-size: 12.5px;
  min-height: 18px;
  color: var(--ink-3);
}
.redeem-msg.ok { color: var(--ok); }
.redeem-msg.err { color: var(--danger); }

.ledger { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); }
.ledger-t { font-size: 12px; color: var(--ink-3); margin-bottom: 8px; }
.ledger ul { list-style: none; display: grid; gap: 6px; }
.ledger li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12.5px;
  color: var(--ink-2);
  font-family: var(--mono);
}
.ledger li em { font-style: normal; color: var(--ink-3); }
.ledger li b { font-weight: 600; }
.ledger li b.plus { color: var(--ok); }
.ledger li b.minus { color: var(--ink-3); }
