:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --border: #e6e8ec;
  --text: #1a1d23;
  --text-dim: #6b7280;
  --accent: #2563eb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.view { height: 100vh; display: flex; flex-direction: column; }
.view[hidden] { display: none; }

/* ---------- 首页 ---------- */
#view-home { overflow-y: auto; }
.home-header {
  padding: 56px 24px 24px;
  text-align: center;
  max-width: 720px;
  margin: 0 auto;
}
.home-header h1 {
  margin: 0 0 16px;
  font-size: 28px;
  letter-spacing: -0.5px;
}
.disclaimer {
  font-size: 13px;
  color: var(--text-dim);
  background: #fff8e6;
  border: 1px solid #f5e2a8;
  border-radius: 10px;
  padding: 12px 16px;
  margin: 0 auto;
  max-width: 520px;
  line-height: 1.7;
}
.disclaimer strong { color: #b45309; }

.doctor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  max-width: 900px;
  margin: 0 auto;
  padding: 8px 24px 24px;
}
.doctor-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, border-color .15s;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.doctor-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(0,0,0,.08);
}
.doctor-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--card-color, var(--accent));
}
.doctor-emoji { font-size: 36px; display: block; margin-bottom: 12px; }
.doctor-name { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.doctor-dept {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 20px;
  color: #fff;
  background: var(--card-color, var(--accent));
  margin-bottom: 10px;
}
.doctor-intro { font-size: 13px; color: var(--text-dim); line-height: 1.6; }

.home-footer {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  padding: 20px 24px 40px;
}

/* ---------- 对话页 ---------- */
#view-chat { flex-direction: row; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px;
  overflow-y: auto;
}
.sidebar-head { margin-bottom: 12px; }

.session-list { list-style: none; padding: 0; margin: 12px 0 0; }
.session-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.session-item:hover { background: #f3f4f6; }
.session-item.active { background: #eef2ff; color: var(--accent); }
.session-item .title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-item .del {
  opacity: 0;
  border: none;
  background: none;
  color: #ef4444;
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
}
.session-item:hover .del { opacity: 1; }

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.chat-title { display: flex; align-items: center; gap: 10px; flex: 1; }
#chat-emoji { font-size: 22px; }
#chat-name { font-weight: 600; font-size: 15px; }
.chat-dept { font-size: 12px; color: var(--text-dim); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 12px;
  scroll-behavior: smooth;
}
.msg {
  max-width: 760px;
  margin: 0 auto 20px;
  display: flex;
  gap: 12px;
}
.msg-avatar {
  flex-shrink: 0;
  width: 32px; height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 16px;
  background: #eef2ff;
}
.msg-body {
  flex: 1;
  min-width: 0;
  font-size: 14.5px;
  line-height: 1.75;
  word-break: break-word;
}
.msg-body p { margin: 0 0 10px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body strong { color: #111827; }
.msg-body code {
  background: #f3f4f6;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 13px;
}
.msg-body ul { margin: 6px 0 10px; padding-left: 22px; }
.msg-body li { margin: 2px 0; }
.msg-body h2, .msg-body h3, .msg-body h4 {
  font-size: 15px;
  margin: 14px 0 6px;
  color: #111827;
}

.msg.user .msg-avatar { background: #dbeafe; }
.msg.user .msg-body {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
}

.msg.assistant .msg-body { padding: 0; }
.msg-error {
  color: #b91c1c;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  margin-top: 8px;
}

.typing::after {
  content: '▊';
  animation: blink 1s steps(2) infinite;
  color: var(--accent);
  font-weight: 300;
}
@keyframes blink { 50% { opacity: 0; } }

.composer {
  display: flex;
  gap: 10px;
  padding: 12px 20px 4px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  max-width: 100%;
}
.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  font-size: 14.5px;
  max-height: 160px;
  outline: none;
  transition: border-color .15s;
}
.composer textarea:focus { border-color: var(--accent); }
.composer textarea:disabled { background: #f9fafb; }
.composer-hint {
  font-size: 11px;
  color: var(--text-dim);
  padding: 4px 20px 10px;
  text-align: right;
  background: var(--panel);
}

/* ---------- 按钮 ---------- */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 20px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: #1d4ed8; }
.btn-primary:disabled { background: #93c5fd; cursor: not-allowed; }
.btn-primary.btn-block { width: 100%; }
.btn-ghost {
  background: none;
  border: none;
  color: var(--text-dim);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
}
.btn-ghost:hover { background: #f3f4f6; color: var(--text); }

/* ---------- 移动端 ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.overlay.show { opacity: 1; pointer-events: auto; }

@media (max-width: 720px) {
  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: 78vw;
    max-width: 300px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 2px 0 16px rgba(0,0,0,.12);
  }
  .sidebar.open { transform: translateX(0); }
  #btn-drawer { display: block; }
  .messages { padding: 16px 12px 8px; }
  .composer { padding: 10px 12px 4px; }
}
@media (min-width: 721px) {
  #btn-drawer { display: none; }
}
/* ---- clinic 首页分诊台手机适配 ---- */
@media (max-width: 720px) {
  .home-header { padding: 32px 16px 14px; }
  .home-header h1 { font-size: 23px; }
  .disclaimer { padding: 10px 14px; font-size: 12.5px; }
  .doctor-grid { padding: 4px 14px 16px; gap: 12px; }
  .doctor-card { padding: 18px 16px; }
  .doctor-emoji { font-size: 30px; margin-bottom: 8px; }
  .doctor-name { font-size: 17px; }
  .doctor-intro { font-size: 12.5px; }
  .home-footer { padding: 12px 16px 28px; }
}
@media (max-width: 360px) {
  .home-header h1 { font-size: 21px; }
  .disclaimer { font-size: 12px; }
}
