:root {
  --bg: #F4F8F9;
  --surface: #FFFFFF;
  --primary: #2C7A7B;
  --primary-dark: #1F5C5D;
  --primary-tint: #E4F1F1;
  --text: #1B2B2E;
  --text-secondary: #5C6E71;
  --text-muted: #93A3A5;
  --border: #E1E8EA;
  --danger: #C64444;
  --danger-tint: #FCEBEB;
  --success: #2F9E5B;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 12px rgba(27, 43, 46, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
}
button { font-family: inherit; }
a { color: var(--primary); }

/* ---------------- 顶部栏 ---------------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: .7rem;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .brand-icon {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
}
.topbar .brand-text { font-weight: 700; font-size: 1.05rem; }
.topbar .brand-sub { font-size: .78rem; color: var(--text-muted); }

/* ---------------- 步骤条 ---------------- */
.steps {
  display: flex; justify-content: center; gap: 0;
  max-width: 640px; margin: 1.1rem auto 0; padding: 0 1rem;
}
.step {
  flex: 1; text-align: center; position: relative; font-size: .78rem; color: var(--text-muted);
}
.step .dot {
  width: 22px; height: 22px; border-radius: 50%; background: var(--surface); border: 2px solid var(--border);
  margin: 0 auto .35rem; display: flex; align-items: center; justify-content: center; font-size: .72rem; color: var(--text-muted);
  transition: all .25s ease;
}
.step::before {
  content: ''; position: absolute; top: 10px; left: -50%; width: 100%; height: 2px; background: var(--border); z-index: -1;
}
.step:first-child::before { display: none; }
.step.active .dot, .step.done .dot { background: var(--primary); border-color: var(--primary); color: #fff; }
.step.active { color: var(--primary); font-weight: 600; }
.step.done::before { background: var(--primary); }

/* ---------------- 容器 ---------------- */
.page {
  max-width: 640px; margin: 0 auto; padding: 1.5rem 1rem 6.5rem;
}
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.5rem; box-shadow: var(--shadow);
}

/* ---------------- 紧急提示 ---------------- */
.urgent-banner {
  background: var(--danger-tint); border: 1px solid #F3C6C6; color: var(--danger);
  border-radius: var(--radius-sm); padding: 1rem 1.1rem; margin-bottom: 1rem;
  display: flex; gap: .7rem; align-items: flex-start; font-size: .92rem; line-height: 1.6;
}
.urgent-banner .icon { font-size: 1.3rem; flex-shrink: 0; }
.urgent-banner strong { display: block; margin-bottom: .2rem; }

/* ---------------- 免责声明 ---------------- */
.disclaimer {
  font-size: .76rem; color: var(--text-muted); text-align: center; margin-top: 1.2rem; line-height: 1.7;
}

/* ---------------- 基本信息表单 ---------------- */
.form-group { margin-bottom: 1.1rem; }
.form-group label { display: block; font-size: .86rem; font-weight: 600; color: var(--text-secondary); margin-bottom: .4rem; }
.form-group input, .form-group select {
  width: 100%; padding: .8rem .9rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 1rem; background: var(--bg); color: var(--text); outline: none; transition: border-color .2s;
}
.form-group input:focus, .form-group select:focus { border-color: var(--primary); background: var(--surface); }
.form-row { display: flex; gap: .8rem; }
.form-row .form-group { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .85rem 1.5rem; border-radius: var(--radius-sm); border: none; cursor: pointer;
  font-size: .98rem; font-weight: 600; transition: transform .15s ease, opacity .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; width: 100%; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-outline { background: transparent; color: var(--primary); border: 1px solid var(--primary); }

/* ---------------- 聊天区 ---------------- */
.chat-log { display: flex; flex-direction: column; gap: .9rem; margin-bottom: 1rem; }
.msg { display: flex; gap: .6rem; max-width: 88%; }
.msg.assistant { align-self: flex-start; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg .avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: .8rem; font-weight: 700;
}
.msg.assistant .avatar { background: var(--primary-tint); color: var(--primary-dark); }
.msg.user .avatar { background: var(--primary); color: #fff; }
.msg .bubble {
  padding: .75rem 1rem; border-radius: 14px; font-size: .95rem; line-height: 1.65; white-space: pre-wrap;
}
.msg.assistant .bubble { background: var(--surface); border: 1px solid var(--border); border-top-left-radius: 4px; }
.msg.user .bubble { background: var(--primary); color: #fff; border-top-right-radius: 4px; }
.msg.typing .bubble { color: var(--text-muted); font-style: italic; }

.chat-input-bar {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--border);
  padding: .8rem 1rem calc(.8rem + env(safe-area-inset-bottom));
}
.chat-input-inner { max-width: 640px; margin: 0 auto; display: flex; gap: .6rem; align-items: flex-end; }
.chat-input-inner textarea {
  flex: 1; resize: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .7rem .9rem; font-size: .96rem; font-family: inherit; max-height: 96px; outline: none;
}
.chat-input-inner textarea:focus { border-color: var(--primary); }
.chat-input-inner button {
  width: 46px; height: 46px; border-radius: 50%; border: none; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; font-size: 1.1rem;
}
.chat-input-inner button:disabled { opacity: .45; cursor: not-allowed; }

/* ---------------- 导诊结果卡片 ---------------- */
.result-card {
  background: var(--primary-tint); border: 1px solid #CDE6E6; border-radius: var(--radius);
  padding: 1.3rem; text-align: center; margin: 1rem 0;
}
.result-card .dept { font-size: 1.35rem; font-weight: 800; color: var(--primary-dark); margin: .3rem 0; }
.result-card .reason { color: var(--text-secondary); font-size: .9rem; margin-bottom: 1rem; }
.result-actions { display: flex; gap: .7rem; flex-wrap: wrap; justify-content: center; }
.result-actions .btn { flex: 1; min-width: 140px; }

/* ---------------- 报告 ---------------- */
.report-section { margin-bottom: 1.2rem; }
.report-section h4 {
  font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; color: var(--primary-dark);
  margin-bottom: .4rem; display: flex; align-items: center; gap: .4rem;
}
.report-section p { font-size: .95rem; color: var(--text); white-space: pre-wrap; }
.report-section p.empty { color: var(--text-muted); font-style: italic; }
.report-meta { display: flex; flex-wrap: wrap; gap: .6rem 1.6rem; font-size: .88rem; color: var(--text-secondary); margin-bottom: 1.4rem; }
.report-meta b { color: var(--text); }

/* ---------------- 医生工作站 ---------------- */
.doctor-layout { display: flex; min-height: 100vh; }
.doctor-sidebar { width: 300px; background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; flex-shrink: 0; }
.doctor-main { flex: 1; padding: 1.8rem 2.2rem; overflow-y: auto; max-width: 760px; }
.report-item {
  padding: .95rem 1.2rem; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .15s;
}
.report-item:hover, .report-item.active { background: var(--primary-tint); }
.report-item .name { font-weight: 700; font-size: .92rem; }
.report-item .meta { font-size: .78rem; color: var(--text-muted); margin-top: .2rem; }
.report-item .urgent-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); margin-right: .4rem; }
.empty-state { text-align: center; color: var(--text-muted); padding: 3rem 1rem; font-size: .92rem; }

@media (max-width: 720px) {
  .doctor-layout { flex-direction: column; }
  .doctor-sidebar { width: 100%; max-height: 240px; }
  .doctor-main { padding: 1.2rem; }
}

/* ================================================================
   智能体风格增强：顶栏在线状态 / 会话标题 / 打字光标 / 快捷回复 / 预约凭证卡
   ================================================================ */
.topbar { justify-content: space-between; }
.topbar .brand-left { display: flex; align-items: center; gap: .7rem; }
.topbar .brand-icon {
  position: relative;
  background: linear-gradient(135deg, var(--primary), #45A0A1);
}
.topbar .brand-icon .pulse {
  position: absolute; bottom: -1px; right: -1px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--success); border: 2px solid var(--surface);
}
.topbar .brand-icon .pulse::after {
  content: ''; position: absolute; inset: 0; border-radius: 50%; background: var(--success);
  animation: pulse-ring 1.8s infinite;
}
@keyframes pulse-ring { 0% { opacity: .7; transform: scale(1); } 100% { opacity: 0; transform: scale(2.4); } }
.topbar .online-badge {
  font-size: .74rem; color: var(--success); background: #EAF9EF; border: 1px solid #CFEED9;
  padding: .25rem .7rem; border-radius: 20px; display: flex; align-items: center; gap: .35rem; font-weight: 600;
}

.chat-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: .3rem; }
.chat-title-row h2 { margin: 0; }
.chat-title-row .agent-tag {
  font-size: .72rem; color: var(--primary-dark); background: var(--primary-tint);
  padding: .2rem .6rem; border-radius: 20px; font-weight: 600; white-space: nowrap;
}

/* 打字中：三个跳动的圆点，比"正在思考…"文字更有 AI 感 */
.msg.typing .bubble { display: flex; align-items: center; gap: 4px; padding: .9rem 1.1rem; }
.typing-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted);
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: .15s; }
.typing-dot:nth-child(3) { animation-delay: .3s; }
@keyframes typing-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* 打字机效果的闪烁光标 */
.type-cursor {
  display: inline-block; width: 2px; height: 1em; background: var(--primary); vertical-align: -0.15em;
  animation: cursor-blink .85s steps(1) infinite; margin-left: 1px;
}
@keyframes cursor-blink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

/* 快捷回复胶囊 */
.quick-replies { display: flex; flex-wrap: wrap; gap: .5rem; margin: .9rem 0 .2rem; }
.quick-chip {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-secondary);
  padding: .45rem 1rem; border-radius: 20px; font-size: .84rem; cursor: pointer; transition: all .15s ease;
  display: inline-flex; align-items: center; gap: .4rem;
}
.quick-chip:hover { border-color: var(--primary); color: var(--primary-dark); background: var(--primary-tint); }

/* ---------------- 预约凭证卡（挂号模拟结果） ---------------- */
.ticket-card {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  border-radius: var(--radius); padding: 1.4rem 1.5rem; color: #fff; margin: 1rem 0; position: relative; overflow: hidden;
}
.ticket-card::after {
  content: ''; position: absolute; right: -30px; top: -30px; width: 140px; height: 140px; border-radius: 50%;
  background: rgba(255,255,255,0.06);
}
.ticket-card .ticket-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1rem; }
.ticket-card .ticket-hospital { font-size: .8rem; opacity: .85; }
.ticket-card .ticket-no { font-family: 'SFMono-Regular', Consolas, monospace; font-size: .74rem; opacity: .75; }
.ticket-card .ticket-dept { font-size: 1.3rem; font-weight: 800; margin: .1rem 0 .6rem; }
.ticket-card .ticket-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; font-size: .88rem; }
.ticket-card .ticket-grid .label { opacity: .75; font-size: .74rem; margin-bottom: .1rem; }
.ticket-card .ticket-grid .value { font-weight: 700; }
.ticket-card .ticket-divider { border-top: 1px dashed rgba(255,255,255,0.3); margin: 1rem 0; position: relative; }
.ticket-card .demo-tag {
  position: absolute; top: 1.3rem; right: 1.5rem; font-size: .68rem; background: rgba(255,255,255,0.15);
  padding: .15rem .6rem; border-radius: 20px;
}

.ticket-extra { background: var(--surface); border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--radius) var(--radius); margin-top: -1rem; padding: 1.3rem 1.5rem 1.5rem; }
.ticket-extra h4 { font-size: .84rem; color: var(--primary-dark); margin: 0 0 .5rem; display: flex; align-items: center; gap: .4rem; }
.ticket-extra ul { margin: 0 0 1rem; padding-left: 1.2rem; font-size: .88rem; color: var(--text-secondary); line-height: 1.8; }
.ticket-extra ul:last-child { margin-bottom: 0; }

.booking-trigger-card {
  border: 1px dashed var(--primary); background: var(--primary-tint); border-radius: var(--radius);
  padding: 1.2rem; text-align: center; margin: 1rem 0;
}
.booking-trigger-card p { font-size: .88rem; color: var(--text-secondary); margin: .3rem 0 .9rem; }
