/* ═══ 设计令牌 ═══ 临床墨绿 + 纸面灰；红色只用于提醒，琥珀色只用于检查单 */
:root {
  --paper: #F1F4F2; --surface: #FFFFFF; --ink: #14221D; --muted: #586861; --faint: #8A9892;
  --line: #D6DED9; --line-soft: #E8EEEA;
  --brand: #0E6B5C; --brand-deep: #0A4E43; --brand-tint: #E1EFEB;
  --alert: #B3392B; --alert-tint: #FBE9E5;
  --amber: #8F5A0C; --amber-tint: #FAF1DC; --ok: #1E7A4B; --ok-tint: #DFF1E6;
  --font: "HarmonyOS Sans SC", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  --topbar: 52px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font: 15px/1.65 var(--font); background: var(--paper); color: var(--ink); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { line-height: 1.3; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; font-weight: 800; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 700; }
a { color: var(--brand); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.muted { color: var(--muted); }
.hint { font-size: 0.82rem; color: var(--muted); }
[hidden] { display: none !important; }

/* ── 顶栏 ── */
.topbar { height: var(--topbar); display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 800; color: var(--ink); text-decoration: none; }
.brand svg { width: 22px; height: 22px; }

.page { max-width: 1040px; margin: 0 auto; padding: 2.5rem 1.25rem 4rem; }
.page.wide { max-width: 1280px; }

/* ── 按钮与表单 ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; padding: 0.5rem 1rem;
  border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; transition: background 0.15s, border-color 0.15s; }
.btn:hover { background: var(--paper); border-color: var(--faint); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-deep); border-color: var(--brand-deep); }
.btn.danger { color: var(--alert); }
.btn.danger:hover { background: var(--alert-tint); border-color: var(--alert); }
.btn.quiet { border-color: transparent; background: transparent; }
.btn.quiet:hover { background: var(--line-soft); }
.btn.small { padding: 0.28rem 0.65rem; font-size: 0.85rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

input, select, textarea { font: inherit; color: inherit; width: 100%; padding: 0.5rem 0.65rem;
  border: 1px solid var(--line); border-radius: 6px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint); }
input[type=checkbox] { width: auto; accent-color: var(--brand); }
textarea { resize: vertical; min-height: 4.2rem; }
.field { display: grid; gap: 0.3rem; align-content: start; }
.field > span { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.field .hint { margin-top: 0.1rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.tag { display: inline-block; padding: 0.05rem 0.5rem; border-radius: 99px; font-size: 0.78rem; font-weight: 600;
  background: var(--line-soft); color: var(--muted); white-space: nowrap; }
.tag.easy, .tag.ok { background: var(--ok-tint); color: var(--ok); }
.tag.mid, .tag.warn { background: var(--amber-tint); color: var(--amber); }
.tag.hard, .tag.bad { background: var(--alert-tint); color: var(--alert); }
.tag.brand { background: var(--brand-tint); color: var(--brand-deep); }

.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 1rem); background: var(--ink); color: #fff;
  padding: 0.6rem 1.1rem; border-radius: 8px; font-size: 0.9rem; opacity: 0; pointer-events: none; transition: all 0.2s; z-index: 100; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--alert); }

/* ── 首页 ── */
.home { max-width: 960px; padding-top: clamp(1rem, 4vw, 3rem); }
.hero {
  overflow: hidden;
  padding: clamp(1.35rem, 4vw, 2.75rem);
  border-radius: 18px;
  background: var(--brand-deep);
  color: white;
}
.hero h1 { font-size: clamp(1.7rem, 5vw, 2.85rem); letter-spacing: -0.025em; }
.hero p { margin: 0.65rem 0 1.35rem; max-width: 34rem; color: #E1EFEB; }
.ecg {
  display: block;
  width: 100%;
  height: clamp(2.75rem, 6vw, 4.25rem);
  background-image: linear-gradient(to right, #ffffff12 1px, transparent 1px),
                    linear-gradient(to bottom, #ffffff12 1px, transparent 1px);
  background-size: 16px 16px;
}
.ecg path { fill: none; stroke: #95E5C8; stroke-width: 2; vector-effect: non-scaling-stroke;
  stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1; animation: trace 1.4s ease-out 1; }
@keyframes trace { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
.entries {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.entry {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: clamp(1.15rem, 3vw, 1.75rem);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
}
.entry .go {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 0.85rem;
  min-height: 44px;
  padding: 0.45rem 1.35rem;
  border: 1px solid var(--brand);
  border-radius: 999px;
  background: var(--brand);
  color: white;
  font-weight: 700;
}
.entry.teacher .go { color: var(--brand-deep); background: var(--surface); }
.entry:is(:hover, :focus-visible) { border-color: var(--brand); }
.entry:is(:hover, :focus-visible, :active) .go { background: var(--brand-deep); color: white; }
.home .banner { margin-top: 1rem; }
.banner { margin-top: 2.5rem; padding: 0.7rem 1rem; border-radius: 6px; background: var(--amber-tint); color: var(--amber); font-size: 0.9rem; }

/* ── 登录 ── */
.login { max-width: 25rem; margin: clamp(.5rem, 6vh, 4rem) auto; padding: clamp(1.1rem, 4vw, 2rem);
  display: grid; gap: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
.login .btn, .login input { min-height: 44px; border-radius: 9px; font-size: 1rem; }
.login .error-text:empty { display: none; }

/* ── 学生大厅 ── */
.identity { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; max-width: 460px; margin: 1.5rem 0 2rem; }
.resume { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.8rem 1rem;
  background: var(--brand-tint); border-radius: 8px; margin-bottom: 1.5rem; }
.student-lobby { display: flex; flex-direction: column; min-height: 100dvh; }
.student-lobby .page { flex: 1; width: 100%; padding-bottom: 1rem; }
.lobby-tabs { display: grid; grid-template-columns: 1fr 1fr; max-width: 24rem; gap: .25rem;
  background: var(--line-soft); border-radius: 12px; padding: .25rem; margin-bottom: 1rem; }
.lobby-tabs button { font: inherit; font-weight: 600; color: var(--muted); min-height: 44px;
  background: transparent; border: 0; border-radius: 9px; cursor: pointer; }
.lobby-tabs button[aria-selected="true"] { color: white; background: var(--brand); }
@media (max-width: 600px) {
  .student-lobby .page { padding: 1.25rem 1rem 1rem; }
  .student-lobby .page-head { align-items: center; margin-bottom: 1rem; }
  .lobby-tabs { max-width: none; }
}
.case-list { display: grid; min-inline-size: 0; border: 0; gap: .75rem; margin-top: .75rem; }
.case {
  display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: start; gap: .7rem;
  padding: 1rem; border: 1px solid var(--line); border-radius: 15px;
  background: var(--surface); overflow-wrap: anywhere; cursor: pointer;
}
.case input[type=radio] {
  appearance: none; width: 18px; height: 18px; padding: 0; margin-block-start: .25rem;
  border: 1.5px solid var(--faint); border-radius: 50%; background: var(--surface);
}
.case input[type=radio]:checked { border: 5px solid var(--brand); }
.case:has(input:checked) { border-color: var(--brand); background: #edf7f1; box-shadow: inset 0 0 0 1px var(--brand); }
.case:has(input:focus-visible) { outline: 2px solid var(--brand); outline-offset: 2px; }
.case-dock { position: sticky; bottom: 0; z-index: 10; background: var(--surface); border-top: 1px solid var(--line); }
.case-dock-inner { max-width: 1040px; margin: auto; display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .65rem 1.25rem calc(.65rem + env(safe-area-inset-bottom)); }
.case-dock small, .case-dock strong { display: block; }
.case-dock small { color: var(--muted); font-size: .8rem; }
.case-dock strong { font-size: 1.05rem; overflow-wrap: anywhere; }
.case-dock .btn { flex: none; min-height: 44px; padding-inline: 1.5rem; border-radius: 999px; }
.case-head { display: flex; align-items: baseline; gap: 0.75rem; flex-wrap: wrap; }
.patient-heading { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: .75rem; }
.patient-heading strong { font-size: 1.125rem; line-height: 1.4; }
.patient-meta { display: flex; flex-wrap: wrap; gap: 0 .75rem; margin-block-start: .25rem;
  color: var(--muted); font-size: .875rem; line-height: 1.5; font-variant-numeric: tabular-nums; }
.case .chief { display: block; margin-block-start: .625rem; line-height: 1.6; }
.empty { padding: 3rem 0; text-align: center; color: var(--faint); }

/* ── 问诊页 ── */
body.app-consult { height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
.consult { flex: 1; min-height: 0; display: grid; grid-template-columns: 240px minmax(0, 1fr) 300px; gap: 1rem; padding: 1rem; max-width: 1400px; width: 100%; margin: 0 auto; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.bedside { padding: 1.1rem; display: flex; flex-direction: column; gap: 1rem; overflow-y: auto; }
.bedside .back { font-size: 0.85rem; color: var(--muted); text-decoration: none; }
.bedside .back:hover { color: var(--ink); }
.bedside h1 { font-size: 1.4rem; }
.bedside .who-line { color: var(--muted); margin-top: 0.15rem; }
.chief-box { border-left: 3px solid var(--brand); padding: 0.1rem 0 0.1rem 0.75rem; }
.chief-box small { display: block; color: var(--faint); font-size: 0.78rem; font-weight: 600; }
.stats { display: grid; gap: 0.5rem; padding-top: 0.9rem; border-top: 1px solid var(--line-soft); }
.stats div { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.9rem; }
.stats b { color: var(--ink); font-variant-numeric: tabular-nums; }
.bedside .actions { margin-top: auto; display: grid; gap: 0.5rem; }
.only-narrow, .progress-toggle { display: none; }

.chat { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.transcript { flex: 1; overflow-y: auto; padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; scroll-behavior: smooth; }
.turn { display: flex; flex: none; align-items: flex-start; gap: .5rem; inline-size: fit-content;
  max-width: min(92%, 38rem); animation: rise 0.2s ease-out; }
.turn.doctor { align-self: flex-end; }
.turn .who { font-size: 0.75rem; color: var(--faint); font-weight: 600; }
.turn.doctor .who { text-align: right; }
.bubble { padding: 0.6rem 0.9rem; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.turn.doctor .bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 3px; }
.turn.patient .bubble { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 3px; }
.turn.typing .bubble { display: flex; gap: 4px; padding: 0.85rem 0.9rem; }
.turn.typing .bubble i { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); animation: blink 1.1s infinite; }
.turn.typing .bubble i:nth-child(2) { animation-delay: 0.18s; }
.turn.typing .bubble i:nth-child(3) { animation-delay: 0.36s; }
.chat .transcript { padding: clamp(.75rem, 2vw, 1.25rem); }
.turn.patient { align-self: flex-start; }
.turn-avatar { flex: none; inline-size: 36px; block-size: 36px; border-radius: 50%;
  background: var(--brand-tint) url("/static/assets/chat-avatars.webp") no-repeat;
  background-size: 600% 600%; }
.turn-message { min-inline-size: 0; display: grid; justify-items: start; gap: .2rem; }
.doctor .turn-message { justify-items: end; }
.turn-message .who { color: var(--muted); line-height: 1.4; overflow-wrap: anywhere; }
.turn-message .bubble { max-inline-size: 100%; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.report { align-self: stretch; background: #FFFDF6; border: 1px solid #E6DDBF; border-left: 3px solid var(--amber); border-radius: 6px; padding: 0.65rem 0.9rem; animation: rise 0.2s ease-out; }
.report-head { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.25rem; flex-wrap: wrap; }
.report-head b { font-weight: 700; }
.report p { white-space: pre-wrap; }
.note { align-self: center; font-size: 0.82rem; color: var(--muted); background: var(--line-soft); padding: 0.2rem 0.8rem; border-radius: 99px; text-align: center; }
.notice { margin: 0 1rem 0.6rem; padding: 0.55rem 0.9rem; border-radius: 6px; background: var(--alert-tint); color: var(--alert); font-size: 0.9rem; }
.notice.done { background: var(--ok-tint); color: var(--ok); }
.composer { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 0.6rem; padding: 0.8rem 1rem; border-top: 1px solid var(--line); }
.composer .voice-btn { min-height: 44px; min-width: 44px; align-self: end; padding-inline: .55rem; }
.composer .voice-btn[aria-pressed="true"] { background: var(--brand-tint); color: var(--brand-deep); }
.composer textarea { min-height: 0; resize: none; }

.orders { position: static; width: auto; max-width: none; min-height: 0; max-height: none; margin: 0;
  padding: 0; color: var(--ink); box-shadow: none; overflow: hidden; }
.orders[open] { display: flex; flex-direction: column; }
.orders:not([open]) { display: none; }
.orders-head { display: flex; justify-content: space-between; align-items: center; padding: 0.9rem 1rem 0.5rem; }
.cat-tabs { display: flex; gap: 0.25rem; padding: 0 0.75rem; flex-wrap: wrap; border-bottom: 1px solid var(--line-soft); }
.cat-tabs button { border: 0; background: none; font: inherit; font-size: 0.88rem; color: var(--muted); padding: 0.45rem 0.5rem; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.cat-tabs button.on { color: var(--brand-deep); font-weight: 700; border-bottom-color: var(--brand); }
.exam-list { flex: 1; overflow-y: auto; padding: 0.4rem 0.5rem; }
.exam { display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem; border-radius: 6px; cursor: pointer; }
.exam:hover { background: var(--paper); }
.exam.done { color: var(--faint); cursor: default; }
.exam.done:hover { background: none; }
.exam .tag { margin-left: auto; }
.orders-foot { padding: 0.8rem 1rem; border-top: 1px solid var(--line); display: grid; gap: 0.4rem; }

/* ── 弹窗 ── */
dialog { border: 0; border-radius: 12px; padding: 0; width: calc(100% - 2rem); max-width: 560px; box-shadow: 0 24px 70px rgba(20, 34, 29, 0.3); color: var(--ink); }
dialog::backdrop { background: rgba(20, 34, 29, 0.45); }
.dialog-body { padding: 1.4rem 1.5rem; display: grid; gap: 1rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }
.pre { white-space: pre-wrap; font: 0.85rem/1.7 var(--font); background: var(--paper); padding: 0.9rem; border-radius: 6px; max-height: 55vh; overflow: auto; }

/* ── 教师后台 ── */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.tabs { display: flex; gap: 1.5rem; border-bottom: 1px solid var(--line); margin-bottom: 1.5rem; }
.tabs button { border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); padding: 0.6rem 0; cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--brand-deep); border-bottom-color: var(--brand); }
.tab-pane { display: none; }
.tab-pane.on { display: block; }
.toolbar { display: flex; gap: 0.75rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar select { width: auto; }

.case-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .55rem; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.case-create-actions, .case-file-actions { display: flex; align-items: center; gap: .4rem; }
.case-toolbar .btn { min-height: 44px; border-radius: 9px; }
.case-create-actions .btn:not(.primary) { color: var(--brand-deep); background: var(--brand-tint); border-color: transparent; }
.case-create-actions .btn:not(.primary):hover { border-color: var(--brand); }
.case-file-actions .btn { color: var(--muted); font-size: .875rem; background: transparent; border-color: transparent; }
.case-file-actions .btn:hover { color: var(--brand-deep); background: var(--paper); }
.case-pool { display: flex; align-items: center; flex-wrap: wrap; column-gap: .5rem; margin: .65rem .25rem 1rem; }
@media (max-width: 600px) {
  .case-toolbar { display: grid; gap: .4rem; }
  .case-create-actions, .case-file-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .case-file-actions { border-top: 1px solid var(--line-soft); padding-top: .25rem; }
  .case-toolbar .btn { padding-inline: .35rem; }
}
#case-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 28rem), 1fr)); gap: .875rem; }
.admin-case { display: flex; flex-direction: column; justify-content: space-between; gap: .85rem;
  padding: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow-wrap: anywhere; }
.admin-case .case-head { gap: .3rem .6rem; }
.admin-case .case-complaint { margin: .6rem 0 .25rem; }
.admin-case .hint { color: var(--muted); }
.admin-case .answer { font-size: .88rem; color: var(--ok); margin-top: .25rem; }
.admin-case .answer.missing { color: var(--amber); }
.admin-case .row-actions { justify-content: flex-start; border-top: 1px solid var(--line-soft); padding-top: .7rem; }
.admin-case .btn { border-radius: 8px; }
.row-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: flex-end; }

table.data { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
table.data th { text-align: left; font-size: 0.82rem; color: var(--muted); background: var(--paper); padding: 0.6rem 0.9rem; }
table.data td { padding: 0.65rem 0.9rem; border-top: 1px solid var(--line-soft); vertical-align: middle; }
.table-wrap { overflow-x: auto; }

.editor { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 0.5rem 1.5rem 1.5rem; margin-bottom: 1.5rem; }
.editor .sec { padding: 1.25rem 0; border-top: 1px solid var(--line-soft); display: grid; gap: 1rem; }
.editor .sec:first-of-type { border-top: 0; }
.editor .sec > h3 small { font-weight: 400; color: var(--faint); margin-left: 0.5rem; font-size: 0.82rem; }
.fact-row { display: grid; grid-template-columns: 110px 96px minmax(0, 1fr) minmax(0, 1fr) auto; gap: 0.4rem; align-items: center; margin-bottom: 0.4rem; }
.exam-row { display: grid; grid-template-columns: 200px minmax(0, 1fr) auto auto auto; gap: 0.4rem; align-items: center; margin-bottom: 0.4rem; }
.exam-row .ex-auto { grid-column: 1 / -1; justify-self: start; }
.exam-row label { display: flex; align-items: center; gap: 0.3rem; font-size: 0.85rem; white-space: nowrap; color: var(--muted); }
.answer-box { background: var(--amber-tint); border-radius: 8px; padding: 0.9rem 1rem; }
.error-text { color: var(--alert); font-size: 0.9rem; }

#case-dialog { margin: auto; max-width: 54rem; border-radius: 16px; overflow: hidden; }
#editor { display: flex; flex-direction: column; max-height: min(90dvh, 60rem); padding: 0; margin: 0; border: 0; }
.case-dialog-head, .case-dialog-foot { flex: none; padding: .85rem 1.25rem; }
.case-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; border-bottom: 1px solid var(--line); }
.case-dialog-head h2 { min-width: 0; overflow-wrap: anywhere; }
.case-dialog-head button { flex: none; }
.case-dialog-fields { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-inline: 1.25rem; }
.case-dialog-fields input, .case-dialog-fields select, .case-dialog-fields .field { min-width: 0; }
.exam-feedback { grid-column: 1 / -1; color: var(--muted); }
.case-dialog-foot { border-top: 1px solid var(--line); }
.case-dialog-foot .error-text { margin-bottom: .5rem; max-height: 4.5rem; overflow-y: auto; }
#editor .dialog-actions button, .case-dialog-head button { min-height: 44px; }
@media (max-width: 600px) {
  #case-dialog { width: 100%; max-height: 100dvh; margin: auto 0 0; border-radius: 18px 18px 0 0; }
  #editor { max-height: calc(100dvh - .5rem); }
  .case-dialog-head, .case-dialog-foot, .case-dialog-fields { padding-inline: 1rem; }
  .case-dialog-foot { padding-bottom: calc(.75rem + env(safe-area-inset-bottom)); }
  #editor .grid, #editor .exam-row, #editor .fact-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #editor .field:only-child, #editor .ex-id { grid-column: 1 / -1; }
  #editor input, #editor select { font-size: 1rem; }
  #save-case { flex: 1; }
}
#gen-dialog { margin: auto; max-width: 32rem; border-radius: 16px; overflow: hidden; }
#gen-form { display: flex; flex-direction: column; max-height: calc(100dvh - 2rem); }
.gen-head { padding: 1rem 1.25rem .75rem; border-bottom: 1px solid var(--line-soft); }
.gen-head p { color: var(--muted); font-size: .875rem; margin-top: .2rem; }
.gen-fields { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 1rem 1.25rem;
  display: flex; flex-direction: column; gap: 1rem; }
.gen-fields .hint { color: var(--muted); }
#g-disease { display: block; margin-block: .3rem; }
.gen-picks summary { display: list-item; width: fit-content; padding-block: .5rem; color: var(--brand);
  font-weight: 600; cursor: pointer; }
.gen-settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
#gen-form .dialog-actions { padding: .75rem 1.25rem; border-top: 1px solid var(--line); }
#gen-form .dialog-actions .btn { min-height: 44px; border-radius: 9px; }
#gen-form .chip { min-height: 36px; }
#gen-form input, #gen-form select, #gen-form textarea { font-size: 1rem; }
#g-result { white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 600px) {
  #gen-dialog { width: 100%; max-width: none; max-height: 100dvh; margin: auto 0 0; border-radius: 18px 18px 0 0; }
  #gen-form { max-height: calc(100dvh - .5rem); }
  #gen-form .dialog-actions { padding-bottom: calc(.75rem + env(safe-area-inset-bottom)); }
  #g-submit { flex: 1; }
}
.chips { display: flex; flex-wrap: wrap; gap: 0.3rem; max-height: 7.5rem; overflow-y: auto; margin-top: 0.4rem; padding: 0.1rem; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--muted); font: inherit; font-size: 0.82rem; padding: 0.15rem 0.6rem; border-radius: 99px; cursor: pointer; }
.chip:hover { border-color: var(--brand); color: var(--brand-deep); }
.chip.on { background: var(--brand-tint); border-color: var(--brand); color: var(--brand-deep); }

/* ── 评阅页 ── */
.review { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 2rem; align-items: start; }
.review .transcript { padding: 1.25rem; max-height: none; overflow: visible; background: var(--paper); border-radius: 10px; border: 1px solid var(--line); }
.turn .meta { font-size: 0.72rem; color: var(--muted); overflow-wrap: anywhere; }
.turn.doctor .meta { text-align: end; }
.report .meta { margin-left: auto; font-size: 0.75rem; color: var(--faint); }
.side { position: sticky; top: calc(var(--topbar) + 1rem); display: grid; gap: 1.25rem; max-height: calc(100vh - var(--topbar) - 2rem); overflow-y: auto; padding-right: 0.25rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.1rem; display: grid; gap: 0.7rem; }
.card h3 { font-size: 0.95rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.3rem 0.9rem; font-size: 0.9rem; }
.kv dt { color: var(--muted); }
.kv dd { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.bar-row { display: grid; grid-template-columns: 4.5rem 1fr 3rem; gap: 0.6rem; align-items: center; font-size: 0.85rem; color: var(--muted); }
.bar { height: 6px; background: var(--line-soft); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--brand); }
.cov { display: grid; gap: 0.35rem; font-size: 0.88rem; }
.cov li { list-style: none; display: grid; grid-template-columns: auto 1fr; gap: 0.5rem; }
.cov .miss { color: var(--alert); }
.diag-pair { display: grid; gap: 0.6rem; font-size: 0.92rem; }
.diag-pair p { white-space: pre-wrap; }
.diag-pair small { display: block; color: var(--faint); font-size: 0.78rem; font-weight: 600; }

/* ── 响应式 ── */
@media (max-width: 1100px) {
  .consult { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); gap: 0.6rem; padding: 0.6rem; }
  .bedside { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0.6rem 1.2rem; padding: 0.7rem 0.9rem; overflow: visible; }
  .bedside .back, .chief-box small { display: none; }
  .bedside h1 { font-size: 1.1rem; }
  .chief-box { flex: 1 1 200px; }
  .stats { display: flex; gap: 1rem; padding: 0; border: 0; }
  .bedside .actions { margin: 0 0 0 auto; display: flex; }
  .only-narrow { display: inline-flex; }
  .orders { position: fixed; inset: auto 0 0; margin: 0 auto; width: min(100%, 34rem);
    height: min(82dvh, 38rem); border-radius: 16px 16px 0 0; }
  .orders-foot { padding-bottom: calc(.8rem + env(safe-area-inset-bottom)); }
  .orders-head .btn, .exam, #order-btn { min-height: 44px; }
  .cat-tabs { max-height: 25dvh; overflow-y: auto; }

}
/* 手机问诊页 */
@media (max-width: 640px) {
  body.app-consult { height: var(--chat-height, 100dvh); }
  .app-consult > .topbar { display: none; }
  .consult { padding: 0; gap: 0; grid-template-rows: fit-content(46%) minmax(0, 1fr); }
  .consult > .bedside, .consult > .chat { border: 0; border-radius: 0; }
  .consult > .bedside {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto;
    gap: .5rem; align-items: center; padding: .5rem .875rem .65rem;
    border-bottom: 1px solid var(--line); min-height: 0; overflow-y: auto;
  }
  .bedside .back { display: grid; place-items: center; width: 44px; min-height: 44px; border-radius: 50%; color: var(--brand); }
  .bedside .back span { display: none; }
  .bedside .back::before { content: ""; width: .65rem; height: .65rem; border: solid currentColor; border-width: 0 0 2px 2px; transform: rotate(45deg); }
  .patient-identity { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; column-gap: .6rem; overflow-wrap: anywhere; }
  .patient-identity::before { content: ""; grid-row: span 2; width: 36px; height: 36px; border-radius: 50%; background: var(--brand-tint) url("/static/assets/chat-avatars.webp") var(--patient-avatar, 0% 0%) / 600% 600% no-repeat; }
  .bedside .who-line { margin: 0; font-size: .8rem; line-height: 1.4; }
  .progress-toggle { display: inline-flex; align-items: center; gap: .45rem; min-height: 44px;
    background: transparent; color: var(--brand); font: inherit; font-size: .82rem; font-weight: 600; padding: 0 .3rem; border: 0; cursor: pointer; }
  .progress-toggle::after { content: ""; width: .42rem; height: .42rem; border: solid currentColor; border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); }
  .progress-toggle[aria-expanded="true"]::after { transform: rotate(225deg); }
  .bedside .chief-box { grid-column: 1 / -1; display: flex; align-items: baseline; gap: .65rem;
    padding: .45rem .75rem; background: var(--paper); border: 0; border-radius: .65rem; line-height: 1.5; overflow-wrap: anywhere; }
  .chief-box small { display: inline; flex: none; color: var(--muted); }
  .bedside .stats { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .4rem; padding: .15rem .75rem; }
  .bedside .stats div { display: grid; gap: .1rem; font-size: .78rem; }
  .bedside .stats b { font-size: .92rem; }
  .progress-toggle[aria-expanded="false"] ~ .stats { display: none; }
  .bedside .actions { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0; }
  .bedside .actions .btn { min-height: 44px; border-radius: .7rem; font-size: .88rem; padding: .35rem .6rem; }
  .bedside #open-diag { background: var(--brand-tint); border-color: var(--brand-tint); color: var(--brand-deep); }
  .chat { background: var(--paper); }
  .chat .transcript { min-height: 0; padding: 1rem .875rem; gap: .95rem; overscroll-behavior: contain; }
  .chat .waiting:only-child { margin-block: auto; background: transparent; }
  .chat .waiting:not(:only-child) { display: none; }
  .chat .composer { flex: none; align-items: end; gap: .5rem; padding: .55rem .75rem; background: var(--surface); }
  .chat .composer textarea { height: 44px; max-height: min(7rem, 22dvh); padding: .6rem .8rem; border-radius: .85rem; line-height: 1.4; font-size: 16px; }
  .chat #send { min-height: 44px; padding: .4rem 1.1rem; border-radius: .85rem; }
  .chat .notice { margin: 0; border-radius: 0; }
  .chat .notice.done ~ .composer { display: none; }
}
@media (min-width: 1101px) { #close-orders { display: none; } }
@media (max-width: 800px) {
  .entries, .identity, .review { grid-template-columns: 1fr; }
  .side { position: static; max-height: none; }
  .admin-case .btn { min-height: 44px; }
  .row-actions { justify-content: flex-start; }
  .fact-row, .exam-row { grid-template-columns: 1fr 1fr; }
  .fact-row input:nth-of-type(1), .fact-row input:nth-of-type(2), .exam-row input[type=text] { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

.visit-list { display: grid; gap: .45rem; margin: .75rem 0 2rem; }
.visit-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem;
  padding: .65rem .9rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); text-decoration: none; }
#student-accounts { display: grid; gap: .5rem; }
#student-accounts .visit-row { align-items: center; overflow-wrap: anywhere; }
#open-new-student, #new-student .btn { min-height: 44px; border-radius: 9px; }
.visit-list .visit-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center;
  padding-inline: clamp(1rem, 2.5vw, 1.4rem); color: var(--ink); }
.visit-info { display: grid; overflow-wrap: anywhere; }
.visit-info time { color: var(--muted); font-size: .875rem; font-variant-numeric: tabular-nums; }
.visit-list .visit-row b { color: var(--brand); }
.tabs { overflow-x: auto; }
.tabs button { flex: none; }

.record-filters { display: grid; gap: .65rem; margin-bottom: 1rem; }
.record-states { display: flex; flex-wrap: wrap; gap: .35rem; border: 0; min-width: 0; }
.record-states label { position: relative; cursor: pointer; }
.record-states input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.record-states label > span { display: flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: 44px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  padding: .35rem .85rem; font-size: .9rem; font-weight: 600; }
.record-states small { color: var(--muted); font-variant-numeric: tabular-nums; }
.record-states input:checked + span { background: var(--brand); border-color: var(--brand); color: white; }
.record-states input:checked + span small { color: inherit; }
.record-states input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.record-search { display: grid; grid-template-columns: minmax(0, 22rem) auto; gap: .5rem; justify-content: start; }
.record-search > * { min-width: 0; min-height: 44px; border-radius: 9px; }
#rec-reset { justify-self: start; color: var(--brand); }
.record-label { display: none; }
@media (max-width: 760px) {
  .admin-dashboard { padding: 1.25rem 1rem 3rem; }
  .admin-dashboard > .page-head { align-items: center; margin-bottom: 1rem; }
  .admin-dashboard .tabs { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: .2rem; padding: .25rem; margin-bottom: 1.25rem; border: 0; border-radius: 12px;
    background: var(--line-soft); overflow: visible; }
  .admin-dashboard .tabs button { margin: 0; border: 0; padding: .35rem .15rem;
    border-radius: 9px; min-height: 44px; font-size: .875rem; }
  .admin-dashboard .tabs button.on { background: var(--brand); color: white; }
  .record-states { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .record-states label > span { padding-inline: .15rem; gap: .25rem; flex-wrap: wrap; }
  .record-search { grid-template-columns: minmax(0, 1fr) auto; }
  #pane-records .table-wrap { overflow: visible; }
  #pane-records table { display: block; overflow: visible; border: 0; background: transparent; }
  #pane-records thead { display: none; }
  #rec-body { display: grid; gap: .75rem; }
  #rec-body tr { padding: .875rem 1rem; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
  #rec-body .record { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center;
    grid-template-areas: "student status" "case rounds" "time actions"; gap: .5rem .75rem; }
  #rec-body td { display: block; border: 0; padding: 0; min-width: 0; overflow-wrap: anywhere; }
  .record-label { display: inline; }
  .record-student { grid-area: student; }
  .record-student strong { font-size: 1.05rem; }
  .record-student .hint, .record-time, .record-rounds, .record-case .record-label { color: var(--muted); }
  .record-status { grid-area: status; justify-self: end; }
  .record-case { grid-area: case; }
  .record-rounds { grid-area: rounds; text-align: end; }
  .record-time { grid-area: time; font-size: .875rem; font-variant-numeric: tabular-nums; }
  #rec-body .record-actions { grid-area: actions; display: flex; flex-wrap: wrap; gap: .5rem; justify-content: end; }
  .record-actions .btn { min-height: 44px; padding-inline: .85rem; border-radius: 9px; white-space: nowrap; }
  .record-actions a { color: var(--brand-deep); background: var(--brand-tint); border-color: transparent; }
  #rec-body .record:has([data-bind]) { grid-template-areas: "student status" "case rounds" "time time" "actions actions"; }
  #rec-body .empty { padding-block: 1.5rem; }
}
@media (max-width: 374px) {
  .admin-dashboard .tabs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* 教师与学生的短表单共用弹窗结构 */
dialog.form-sheet { max-width: 32rem; max-height: none; margin: auto; border-radius: 16px; overflow: hidden; }
.form-sheet .dialog-body { max-height: calc(100dvh - 2rem); display: flex; flex-direction: column; gap: 0; padding: 0; }
.form-sheet .dialog-body > h2 { padding: 1rem 1.25rem .85rem; border-bottom: 1px solid var(--line-soft); }
.sheet-fields { min-height: 0; display: grid; align-content: start; gap: .9rem; padding: 1rem 1.25rem;
  overflow-y: auto; overscroll-behavior: contain; overflow-wrap: anywhere; }
.sheet-fields > *, .sheet-fields .field { min-inline-size: 0; }
.sheet-fields input, .sheet-fields select, .sheet-fields textarea { font-size: 1rem; }
.sheet-fields .pre { max-height: none; overflow: visible; }
.form-sheet .dialog-actions { padding: .75rem 1.25rem; border-top: 1px solid var(--line-soft); background: var(--surface); }
.form-sheet .dialog-actions .btn { min-height: 44px; border-radius: 9px; }
.term-types { min-width: 0; border: 0; display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: .3rem; }
.term-types legend { color: var(--muted); font-size: .85rem; font-weight: 600; margin-bottom: .35rem; }
.term-types label { position: relative; cursor: pointer; }
.term-types input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.term-types span { min-height: 44px; display: grid; place-items: center; font-weight: 600; border: 1px solid var(--line); border-radius: 9px; }
.term-types input:checked + span { color: white; background: var(--brand); border-color: var(--brand); }
.term-types input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.llm-advanced { border-top: 1px solid var(--line-soft); padding-block: .75rem; }
.llm-advanced summary, .import-help summary { min-height: 44px; align-content: center; font-weight: 600; color: var(--brand); cursor: pointer; }
#llm-form .field, .review > *, .side > * { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 760px) {
  dialog.form-sheet { width: 100%; max-width: none; margin: auto 0 0; border-radius: 16px 16px 0 0; }
  .form-sheet .dialog-body { max-height: calc(100dvh - .5rem); }
  .form-sheet .dialog-actions { padding-bottom: calc(.75rem + env(safe-area-inset-bottom)); }
  .form-sheet .dialog-actions .primary { flex: 1; }
  #llm-form { padding-inline: 1rem; border-radius: 14px; }
  #llm-form .row-actions .btn { min-height: 44px; }
  #llm-form .grid { grid-template-columns: minmax(0, 1fr); }
  #pane-terms table, #term-body { display: block; border: 0; background: transparent; }
  #pane-terms thead { display: none; }
  #term-body { display: grid; gap: .7rem; }
  #term-body tr { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: .3rem .75rem;
    padding: .85rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
  #term-body td { display: block; border: 0; padding: 0; overflow-wrap: anywhere; }
  .term-row td:nth-child(2) { grid-column: 1; font-weight: 700; }
  .term-row td:nth-child(3) { grid-column: 1 / -1; color: var(--muted); white-space: pre-wrap; }
  .term-row td:last-child { grid-column: 2; grid-row: 1 / 3; }
  .term-row .btn, .review .btn { min-height: 44px; }
  .side { padding: 0; gap: .85rem; }
  .review { gap: 1rem; }
  .review .transcript { padding: .75rem; }
}

.visit-item { display: flex; align-items: center; gap: .5rem; padding-inline-end: .65rem;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.visit-list .visit-item .visit-row { flex: 1; min-width: 0; border: 0; }
.visit-item .danger { flex: none; min-height: 44px; }
@media (max-width: 400px) {
  .visit-list .visit-item .visit-row { padding-inline: .65rem .25rem; gap: .35rem; }
}

.voice-bubble { inline-size: min(18rem, 100%); }
.voice-title { font-size: .85rem; font-weight: 600; }
.voice-bubble audio { display: block; inline-size: 100%; min-inline-size: 0; height: 38px; margin-block: .4rem; }
.voice-text { line-height: 1.5; }
.voice-bubble .row-actions { margin-top: .4rem; }
