:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --fill: #eef0f3;
  --fill-2: #e3e6ea;
  --text: #1d1d1f;
  --text-2: #4b4b50;
  --text-3: #6e6e73;
  --line: rgba(0, 0, 0, 0.09);
  --line-strong: rgba(0, 0, 0, 0.18);
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-soft: #e8f1fd;
  --green: #1d9f4b;
  --green-bg: #e8f7ee;
  --amber: #b26b00;
  --amber-bg: #fff3e0;
  --red: #d70015;
  --red-bg: #ffeceb;
  --blue: #0071e3;
  --blue-bg: #e8f1fd;
  --teal-50: #e7f7f4;
  --teal-100: #c7ece6;
  --teal-900: #0f5c52;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 12px 32px rgba(0, 0, 0, 0.07);
  --nav-h: 62px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --fs-h1: 32px;
  --fs-h2: 20px;
  --fs-h3: 17px;
  --fs-lg: 15px;
  --fs-md: 14px;
  --fs-sm: 13px;
  --fs-xs: 12px;
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-lg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { padding-bottom: calc(var(--nav-h) + max(var(--sp-2), var(--safe-bottom))); }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.bottomnav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 60;
  display: flex;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4) max(var(--sp-2), var(--safe-bottom));
  background: rgba(255, 255, 255, 0.82);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}
.bottomnav a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--text-3); padding: var(--sp-1) 22px; border-radius: 14px;
  font-size: var(--fs-xs); line-height: 1.2;
  transition: color 0.2s ease, background 0.2s ease;
}
.bottomnav a svg { width: 24px; height: 24px; }
.bottomnav a:hover { color: var(--text); background: rgba(0, 0, 0, 0.04); }
.bottomnav a.active { color: var(--accent); font-weight: 600; }

.app { max-width: 1000px; margin: 0 auto; padding: calc(var(--sp-6) + var(--safe-top)) var(--sp-5) var(--sp-5); }
.muted { color: var(--text-3); }

.page-head { margin-bottom: var(--sp-6); }
.page-head h1 { font-size: var(--fs-h1); font-weight: 600; letter-spacing: -0.022em; line-height: 1.2; margin: 0 0 var(--sp-3); }
.page-head p { margin: 0; color: var(--text-2); font-size: var(--fs-lg); max-width: 660px; }

.section-title { font-size: var(--fs-h2); font-weight: 600; letter-spacing: -0.01em; margin: var(--sp-7) 0 var(--sp-4); }

.grid { display: grid; gap: var(--sp-4); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
}
.card h3 { margin: 0 0 var(--sp-2); font-size: var(--fs-h3); font-weight: 600; letter-spacing: -0.01em; }
.card p { margin: var(--sp-2) 0; font-size: var(--fs-md); color: var(--text-2); }
.card.clickable { cursor: pointer; transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.25s, border-color 0.25s; }
.card.clickable:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--line-strong); }

.badge { display: inline-block; padding: 2px 10px; border-radius: 980px; font-size: var(--fs-xs); font-weight: 500; line-height: 1.7; }
.badge.teal, .badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.gray { background: var(--fill-2); color: var(--text-2); }

.subhead { font-size: var(--fs-sm); font-weight: 600; color: var(--text); margin-top: var(--sp-4); }

.chip-list { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-top: var(--sp-2); }
.chip { background: var(--fill); border-radius: 980px; padding: 5px 13px; font-size: var(--fs-sm); color: var(--text-2); }

.dialogue-head { padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--line); }
.dialogue-head h3 { margin: 0 0 var(--sp-1); font-size: var(--fs-h3); font-weight: 600; }
.dialogue-head p { margin: 0; font-size: var(--fs-sm); color: var(--text-3); }

.control-bar { display: flex; gap: var(--sp-3); align-items: flex-end; flex-wrap: wrap; margin-bottom: var(--sp-3); padding: var(--sp-4) var(--sp-5); }
.field { display: flex; flex-direction: column; gap: 5px; font-size: var(--fs-xs); color: var(--text-3); }
.field select {
  padding: 9px 14px; border: 1px solid var(--line); border-radius: 11px; font-family: inherit;
  font-size: var(--fs-md); color: var(--text); background: var(--fill); min-width: 158px;
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' fill='none' stroke='%236e6e73' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px;
}
.field select:focus { outline: none; box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.25); background: #fff; }
.control-status { margin-left: auto; align-self: center; }

.hint-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--sp-3) var(--sp-5); margin-bottom: var(--sp-4); font-size: var(--fs-sm); }
.hint-box summary { cursor: pointer; color: var(--text-2); font-weight: 500; }
.hint-box .chip-list { margin-top: var(--sp-3); }

.chat-window { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 360px; overflow: hidden; }
.chat-body { padding: var(--sp-5); flex: 1; display: flex; flex-direction: column; gap: var(--sp-3); min-height: 300px; max-height: 520px; overflow-y: auto; }
.msg { max-width: 78%; padding: 11px 15px; border-radius: 20px; font-size: var(--fs-lg); line-height: 1.6; white-space: pre-wrap; }
.msg.patient { align-self: flex-start; background: var(--fill); color: var(--text); border-bottom-left-radius: 6px; }
.msg.nurse { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 6px; }
.msg.system { align-self: center; background: var(--fill); color: var(--text-3); font-size: var(--fs-sm); max-width: 90%; border-radius: 980px; padding: 7px 14px; }

.chat-input { border-top: 1px solid var(--line); padding: var(--sp-4); display: flex; gap: var(--sp-3); align-items: flex-end; }
.chat-input textarea {
  flex: 1; resize: vertical; min-height: 58px; max-height: 170px; padding: 11px 14px;
  border: 1px solid var(--line); border-radius: 14px; font-family: inherit; font-size: var(--fs-lg); line-height: 1.6;
  background: var(--fill); color: var(--text);
}
.chat-input textarea:focus { outline: none; box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.25); background: #fff; }
.chat-actions { display: flex; flex-direction: column; gap: var(--sp-2); flex: none; }
.chat-actions .btn { width: 100%; }

.btn {
  border: 1px solid transparent; border-radius: 10px; min-height: 40px; padding: 0 18px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: var(--fs-md); font-weight: 500; cursor: pointer; font-family: inherit;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn:active { transform: translateY(0.5px); }
.btn.primary { background: #1d1d1f; color: #fff; }
.btn.primary:hover { background: #000000; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line-strong); }
.btn.ghost:hover { background: var(--fill); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.score-panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: var(--sp-6); margin-top: var(--sp-5); }
.score-head { display: flex; align-items: center; gap: var(--sp-4); flex-wrap: wrap; }
.score-total { display: flex; align-items: baseline; gap: var(--sp-2); }
.score-total b { font-size: 46px; font-weight: 600; letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.score-total span { font-size: var(--fs-sm); color: var(--text-3); }
.grade-pill { padding: 5px 16px; border-radius: 980px; font-weight: 600; font-size: var(--fs-md); }
.grade-pill.excellent { background: var(--green-bg); color: var(--green); }
.grade-pill.good { background: var(--blue-bg); color: var(--blue); }
.grade-pill.pass { background: var(--amber-bg); color: var(--amber); }
.grade-pill.improve { background: var(--red-bg); color: var(--red); }

.bar-row { margin: var(--sp-4) 0; }
.bar-top { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-1) var(--sp-3); flex-wrap: wrap; font-size: var(--fs-sm); margin-bottom: 6px; }
.bar-top > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.bar-top .val { color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-track { height: 7px; background: var(--fill-2); border-radius: 980px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 980px; background: var(--accent); transition: width 0.6s cubic-bezier(0.2, 0.8, 0.2, 1); }
.bar-fill.low { background: #ff9500; }
.bar-fill.bad { background: #ff3b30; }

.dim-feedback { font-size: var(--fs-sm); color: var(--text-2); padding: 2px 0 var(--sp-2); }
.dim-feedback .miss { color: var(--text-3); }
.dim-feedback .neg { color: var(--red); }

.callout { border-radius: 14px; padding: var(--sp-3) 18px; font-size: var(--fs-sm); margin-top: var(--sp-3); color: var(--text-2); }
.callout.good { background: var(--green-bg); color: #15633a; }
.callout.warn { background: var(--amber-bg); color: #8a5300; }
.callout.bad { background: var(--red-bg); color: #a50012; }
.callout ul { margin: var(--sp-2) 0 0; padding-left: 18px; }
.callout li { margin: 3px 0; }

.checklist { display: grid; gap: var(--sp-2); margin-top: var(--sp-2); }
.checklist .row { display: flex; align-items: flex-start; gap: var(--sp-3); font-size: var(--fs-md); color: var(--text-2); }
.checklist .mark { width: 18px; height: 18px; border-radius: 6px; display: grid; place-items: center; font-size: 11px; font-weight: 700; flex: none; margin-top: 2px; }
.checklist .mark.ok { background: var(--green-bg); color: var(--green); }
.checklist .mark.no { background: var(--fill-2); color: var(--text-3); }

.control-bar .field > span { font-weight: 500; }

.history-toolbar { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.history-list { display: grid; gap: var(--sp-3); }
.history-item { padding: 0; overflow: hidden; }
.history-item.open { border-color: var(--line-strong); }
.history-summary { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-4); padding: var(--sp-4) var(--sp-5); cursor: pointer; transition: background 0.2s ease; }
.history-summary:hover { background: var(--fill); }
.history-meta { min-width: 0; }
.history-summary h3 { margin: 0 0 2px; font-size: var(--fs-h3); }
.history-summary p { margin: 0; font-size: var(--fs-sm); }
.history-score { display: flex; align-items: center; gap: var(--sp-3); flex: none; }
.history-score .score-total b { font-size: 30px; }
.history-hint { padding: 0 var(--sp-5) var(--sp-4); font-size: var(--fs-xs); color: var(--text-3); }
.history-detail { border-top: 1px solid var(--line); padding: var(--sp-4) var(--sp-5) var(--sp-5); }
.history-chat { padding: 0; min-height: 0; max-height: 340px; gap: var(--sp-2); }
.history-detail .score-panel { box-shadow: none; border: none; padding: var(--sp-4) 0 0; margin-top: var(--sp-4); }
.history-detail pre.code { box-shadow: none; }

img, video, canvas, svg { max-width: 100%; }
.chip, .badge, .indicator-tags span, .callout { overflow-wrap: anywhere; }

@media (max-width: 1024px) {
  .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .grid.cols-2 { grid-template-columns: 1fr; }
  .case-layout { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  :root { --fs-h1: 27px; --fs-h2: 19px; }
  .app { padding: calc(var(--sp-5) + var(--safe-top)) var(--sp-4); }
  .control-bar { align-items: stretch; }
  .control-bar .field, .control-bar .field select { width: 100%; min-width: 0; }
  .control-bar .btn { flex: 1; }
  .chat-window { min-height: 0; }
  .chat-body { min-height: 240px; max-height: min(520px, 60vh); }
  .chat-input { flex-direction: column; align-items: stretch; }
  .chat-input textarea { width: 100%; }
  .chat-actions { flex-direction: row; }
  .chat-actions .btn { flex: 1; width: auto; }
  .msg { max-width: 88%; }
  .score-total b { font-size: 40px; }
  .bottomnav { gap: 0; padding-left: var(--sp-2); padding-right: var(--sp-2); }
  .bottomnav a { flex: 1; padding: var(--sp-1) var(--sp-2); }
}

@media (max-width: 560px) {
  :root { --fs-h1: 24px; }
  .history-summary { flex-direction: column; align-items: stretch; gap: var(--sp-3); }
  .history-score { justify-content: space-between; }
  .card { padding: var(--sp-4); }
  .score-panel { padding: var(--sp-4); }
  .score-head { gap: var(--sp-3); row-gap: var(--sp-2); }
  .score-total b { font-size: 36px; }
  .chat-body { padding: var(--sp-4); }
  .msg { max-width: 92%; }
}
