:root {
  --bg: #eceff4;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --line: #d6dde6;
  --line-strong: #b9c4d1;
  --text: #16202b;
  --muted: #5d6b7a;
  --accent: #1f6feb;
  --accent-soft: #e7f0fe;
  --listen: #c2410c;
  --listen-soft: #fdeee4;
  --ok: #15803d;
  --warn: #b42318;
  --radius: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.view[hidden] { display: none !important; }

/* ---------- home ---------- */
.home-view {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: #f4f6f9;
}
.home-top {
  padding: 16px 18px;
  background: var(--text);
  color: #fff;
}
.home-brand { display: flex; align-items: baseline; gap: 10px; max-width: 980px; margin: 0 auto; width: 100%; }
.home-brand strong { font-size: 17px; font-weight: 600; }
.home-brand span { color: #9fb3c8; font-size: 12px; }
.home-main {
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 42px 18px 28px;
  flex: 1;
}
.home-heading { margin-bottom: 22px; }
.home-heading h1 { margin: 0 0 6px; font-size: 26px; font-weight: 650; letter-spacing: 0; }
.home-heading p { margin: 0; color: var(--muted); font-size: 14px; }
.home-choices { display: grid; grid-template-columns: 1fr; gap: 14px; }
.home-choice {
  display: flex; align-items: center; gap: 14px;
  width: 100%; min-height: 104px; padding: 17px 18px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font-family: inherit; text-align: left; cursor: pointer;
  box-shadow: 0 2px 8px rgba(16, 32, 48, .05);
}
.home-choice:hover { border-color: #9fb9df; background: #fbfdff; }
.home-choice:active { transform: translateY(1px); }
.home-choice-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 54px; height: 54px; flex: none; border-radius: 8px;
  background: var(--accent-soft); color: var(--accent);
}
.home-choice-icon svg { width: 27px; height: 27px; }
.home-choice-body { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.home-choice-body strong { font-size: 19px; font-weight: 650; }
.home-choice-body span { color: var(--muted); font-size: 13px; line-height: 1.5; }
.home-choice-arrow { color: #9aa9b8; flex: none; }
.home-choice-arrow svg { width: 20px; height: 20px; }
.home-foot { margin-top: 22px; padding-top: 15px; border-top: 1px solid var(--line); color: #7c8997; font-size: 12px; }

.home-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; flex: none; padding: 0;
  border: 1px solid #35465a; border-radius: var(--radius);
  background: #223142; color: #e6edf5; cursor: pointer;
}
.home-btn:hover { background: #2c3d52; }
.home-btn:active { transform: translateY(1px); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 14px;
  background: var(--text);
  color: #fff;
}
.brand { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.brand .home-btn { align-self: center; margin-right: 2px; }
.brand strong { font-size: 16px; font-weight: 600; white-space: nowrap; }
.tag { font-size: 12px; color: #9fb3c8; white-space: nowrap; }
.ver { font-size: 11px; color: #7c8ea3; white-space: nowrap; border: 1px solid #35465a; border-radius: 4px; padding: 0 5px; }
.actions { display: flex; align-items: center; gap: 6px; }
.savestate { font-size: 12px; color: #8fa3b8; margin-right: 4px; white-space: nowrap; }
.savestate.on { color: #7ee2b8; }

.btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 10px; border: 1px solid #35465a; border-radius: var(--radius);
  background: #223142; color: #e6edf5; font-size: 13px; font-family: inherit;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #2c3d52; }
.btn:active { transform: translateY(1px); }
.btn.danger { border-color: #6b3030; color: #ffd9d5; background: #3a2323; }
.btn.danger:hover { background: #4a2b2b; }
.btn.primary { border-color: #1b5ac0; background: #1f6feb; color: #fff; font-weight: 600; }
.btn.primary:hover { background: #2a7bf5; }
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 2px;
  border-radius: 999px; background: #35465a; color: #dbe6f2;
  font-size: 11px; line-height: 18px; text-align: center;
}

/* ---------- voice bar ---------- */
.voicebar {
  position: sticky; top: 46px; z-index: 25;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 3px rgba(16, 32, 48, .06);
}
.voice-main { display: flex; gap: 10px; align-items: center; flex: 1 1 320px; min-width: 0; }
.voice-side { flex: 1 1 300px; min-width: 0; }

.mic {
  display: inline-flex; align-items: center; justify-content: center;
  width: 52px; height: 52px; flex: none;
  border: 1px solid var(--line-strong); border-radius: 50%;
  background: var(--surface-2); color: var(--text); cursor: pointer;
}
.mic:hover { background: #eaeff5; }
.mic .ico-stop { display: none; }
.mic[aria-pressed="true"] {
  background: var(--listen-soft); border-color: var(--listen); color: var(--listen);
}
.mic[aria-pressed="true"] .ico-mic { display: none; }
.mic[aria-pressed="true"] .ico-stop { display: block; }
.mic.pulse { animation: pulse 1.6s ease-out infinite; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(194, 65, 12, .35); }
  70%  { box-shadow: 0 0 0 10px rgba(194, 65, 12, 0); }
  100% { box-shadow: 0 0 0 0 rgba(194, 65, 12, 0); }
}

.voice-text { min-width: 0; flex: 1; }
.voice-status { font-size: 13px; color: var(--muted); }
.voice-status.listening { color: var(--listen); font-weight: 600; }
.voice-now { font-size: 14px; font-weight: 600; margin-top: 1px; }
.voice-now span { color: var(--accent); }
.voice-heard {
  font-size: 13px; color: var(--muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 19px;
}
.voice-heard b { color: var(--text); font-weight: 600; }
.voice-debug {
  font-size: 11px; color: #8794a3; margin-top: 3px; min-height: 15px;
  font-family: ui-monospace, Consolas, "Courier New", monospace;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.sim input {
  width: 100%; padding: 7px 10px; font-family: inherit; font-size: 13px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
.sim input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.toggle {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 5px;
  font-size: 12px; color: var(--muted); cursor: pointer; user-select: none;
}
.toggle input { width: 15px; height: 15px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.hint { font-size: 12px; color: var(--muted); margin-top: 5px; line-height: 1.7; }
.hint code {
  padding: 1px 5px; border: 1px solid var(--line); border-radius: 4px;
  background: var(--surface-2); font-family: inherit; font-size: 12px; color: #35465a;
}

/* ---------- form ---------- */
.form { padding: 14px; max-width: 1180px; margin: 0 auto; }

.section {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 14px; overflow: hidden;
}
.section > h2 {
  margin: 0; padding: 9px 12px; font-size: 14px; font-weight: 600;
  background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.section-note { padding: 7px 12px; font-size: 12px; color: var(--muted); background: #fbfcfd; border-bottom: 1px solid var(--line); }
.batchbar {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 7px 12px; background: #fbfcfd; border-bottom: 1px solid var(--line);
}
.chip.batch {
  background: var(--accent-soft); border-color: #b9d3fb; color: #17509f; font-weight: 600;
  min-height: 34px; padding: 6px 14px;
}
.chip.batch:hover { background: #d9e8fd; }
.subsection > h3 {
  margin: 0; padding: 7px 12px; font-size: 13px; font-weight: 600;
  color: var(--muted); border-bottom: 1px solid var(--line); background: #fbfcfd;
}

.row {
  display: grid; grid-template-columns: minmax(190px, 240px) 1fr;
  gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row-label { font-size: 13px; padding-top: 6px; color: var(--text); }
.row.active { background: #f2f7ff; box-shadow: inset 3px 0 0 var(--accent); }
.row-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }

.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field-label { font-size: 11px; color: var(--muted); }
.field input[type="text"], .field input[type="number"], .field input[type="date"], .field textarea {
  width: 100%; padding: 6px 8px; font-family: inherit; font-size: 14px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text); min-width: 0;
}
.field textarea { resize: vertical; min-height: 38px; }
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field.active input, .field.active textarea { border-color: var(--accent); background: #fbfdff; }
.field.hidden { display: none; }
.field-locked input {
  background: var(--surface-2); color: var(--muted);
  border-color: var(--line); pointer-events: none;
}

.chooser { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  padding: 5px 11px; border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--surface); font-size: 13px; font-family: inherit; color: var(--text);
  cursor: pointer; white-space: nowrap;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.chip[aria-pressed="true"][data-tone="warn"] { background: var(--warn); border-color: var(--warn); }
.chip[aria-pressed="true"][data-tone="ok"] { background: var(--ok); border-color: var(--ok); }

.unit { font-size: 11px; color: var(--muted); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 14px);
  padding: 9px 16px; border-radius: var(--radius); background: #16202b; color: #fff;
  font-size: 13px; opacity: 0; pointer-events: none; transition: .18s ease;
  max-width: 90vw; text-align: center; z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- records modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(12, 20, 28, .55);
}
.modal[hidden] { display: none; }
.modal-card {
  width: 100%; max-width: 560px; max-height: 82vh;
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .3); overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.record-list { overflow-y: auto; padding: 8px; }
.record-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px; margin-bottom: 8px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
}
.record-item:last-child { margin-bottom: 0; }
.record-main { flex: 1; min-width: 0; cursor: pointer; }
.record-title {
  font-size: 14px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.record-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.record-empty { padding: 30px 12px; text-align: center; color: var(--muted); font-size: 13px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; flex: none; padding: 0;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: #b42318; cursor: pointer;
}
.icon-btn:hover { background: #fdf3f2; }

/* ---------- 拍照识别 ---------- */
.input-row { display: flex; gap: 6px; align-items: stretch; }
.input-row input { flex: 1; min-width: 0; }
.cam-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; flex: none; padding: 0;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text); cursor: pointer;
}
.cam-btn:hover { background: #eaeff5; }
.cam-btn:active { transform: translateY(1px); }

.ocr-body { padding: 10px 12px; overflow-y: auto; }
.ocr-preview {
  display: block; width: 100%; max-height: 40vh; object-fit: contain;
  background: #0d1620; border-radius: var(--radius);
}
.ocr-status { font-size: 13px; color: var(--muted); margin: 8px 0 6px; min-height: 19px; }
.ocr-text {
  width: 100%; padding: 8px 10px; font-size: 16px; letter-spacing: 1px;
  font-family: ui-monospace, Consolas, "Courier New", monospace;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
.ocr-text:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.ocr-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }
.ocr-actions .btn { min-height: 38px; padding: 8px 16px; font-size: 14px; }

/* ---------- ai diagnosis ---------- */
.diagnosis-main { padding: 14px; max-width: 980px; margin: 0 auto; }
.diag-voicebar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.diag-voicebar .voice-text { min-width: 0; }
.diag-voicebar #diagNext { margin-left: auto; flex: none; }
.diag-fields { display: grid; gap: 12px; padding: 12px; }
.diag-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.diag-field .field-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.diag-field input, .diag-field textarea {
  width: 100%; padding: 8px 9px; font-family: inherit; font-size: 15px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text); min-width: 0;
}
.diag-field textarea { resize: vertical; min-height: 76px; line-height: 1.5; }
.diag-field input:focus, .diag-field textarea:focus {
  outline: 2px solid var(--accent-soft); border-color: var(--accent);
}
.diag-field.active input, .diag-field.active textarea { border-color: var(--accent); background: #fbfdff; }
.diag-actions { display: flex; gap: 8px; padding: 0 12px 12px; }
.diag-submit { min-height: 40px; padding: 8px 18px; font-size: 14px; }
.diag-loading {
  display: flex; align-items: center; gap: 8px;
  margin: 0 12px 12px; padding: 10px 12px;
  border: 1px solid #c9d9f1; border-radius: var(--radius);
  background: #f3f7fe; color: #244a7d; font-size: 13px;
}
.spinner {
  width: 16px; height: 16px; flex: none; border-radius: 50%;
  border: 2px solid #b8cdf0; border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.diag-error {
  margin: 0 12px 12px; padding: 10px 12px;
  border: 1px solid #e4b4ae; border-radius: var(--radius);
  background: #fff5f3; color: #9f2d21; font-size: 13px; white-space: pre-wrap;
}
.diag-result-section { margin-top: 14px; }
.diag-result-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 12px; background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.diag-result-head h2 { margin: 0; font-size: 14px; font-weight: 600; }
.diag-result-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.diag-result-body { padding: 12px; }
.diag-summary {
  padding: 11px 12px; margin-bottom: 14px;
  border-left: 3px solid var(--accent); background: #f4f8fe;
  font-size: 15px; font-weight: 600; color: #173f73;
}
.diag-block { margin-bottom: 17px; }
.diag-block:last-child { margin-bottom: 0; }
.diag-block h3 {
  margin: 0 0 7px; padding-bottom: 5px; font-size: 14px; font-weight: 650;
  border-bottom: 1px solid var(--line); color: var(--text);
}
.diag-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.diag-item {
  padding: 9px 10px; border: 1px solid var(--line); border-radius: var(--radius);
  background: #fcfdfe; font-size: 13px;
}
.diag-item-title { display: flex; align-items: flex-start; gap: 7px; font-weight: 650; color: var(--text); }
.diag-item-title .num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; flex: none; border-radius: 50%;
  background: #e7eef8; color: #355a86; font-size: 11px;
}
.diag-item p { margin: 4px 0 0 27px; color: #465565; line-height: 1.55; }
.diag-item p b { color: var(--text); font-weight: 600; }
.diag-likelihood {
  display: inline-block; margin-left: 6px; padding: 0 6px;
  border-radius: 999px; background: #fdeee4; color: #9a4b14;
  font-size: 11px; font-weight: 600; line-height: 19px;
}
.diag-measure {
  display: grid; grid-template-columns: minmax(110px, 1fr) minmax(110px, 1fr) 1.6fr;
  gap: 8px; padding: 8px 9px; border-bottom: 1px solid var(--line); font-size: 13px;
}
.diag-measure:first-child { border-top: 1px solid var(--line); }
.diag-measure strong { font-weight: 600; }
.diag-raw { margin: 0; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: #f8fafc; font-family: inherit; font-size: 13px; white-space: pre-wrap; line-height: 1.6; overflow-wrap: anywhere; }
.diag-disclaimer {
  padding: 9px 12px; border-top: 1px solid var(--line);
  background: #fbfcfd; color: var(--muted); font-size: 12px; line-height: 1.55;
}
.diag-note-section .diag-note-body { padding: 10px 12px; }
.diag-note-text {
  margin: 0; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius);
  background: #fbfcfd; font-family: inherit; font-size: 13px; line-height: 1.6;
  white-space: pre-wrap; overflow-wrap: anywhere; max-height: 38vh; overflow-y: auto;
}
.diag-note-tools { display: flex; justify-content: flex-end; margin-top: 8px; }

@media (min-width: 720px) {
  .home-choices { grid-template-columns: 1fr 1fr; }
}

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  .form { padding: 10px; }
  .diagnosis-main { padding: 10px; }
  .home-main { padding: 28px 12px 20px; }
  .home-heading h1 { font-size: 23px; }
  .home-choice { min-height: 94px; padding: 14px; }
  .home-choice-body strong { font-size: 17px; }
  .diag-voicebar { flex-wrap: wrap; }
  .diag-voicebar #diagNext { margin-left: 0; }
  .diag-measure { grid-template-columns: 1fr 1fr; }
  .diag-measure .diag-measure-note { grid-column: 1 / -1; }
  .row { grid-template-columns: 1fr; gap: 6px; padding: 9px 10px; }
  .row-label { padding-top: 0; font-weight: 600; }
  .row-fields { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
  .voicebar { top: 46px; padding: 9px 10px; }
  .mic { width: 48px; height: 48px; }
  .topbar { padding: 8px 10px; }
  .savestate { display: none; }
}

@media print {
  .topbar, .voicebar, .toast { display: none !important; }
  html, body { background: #fff; font-size: 12px; }
  .form { padding: 0; max-width: none; }
  .section { break-inside: avoid; border-color: #999; margin-bottom: 8px; }
  .row { break-inside: avoid; padding: 5px 8px; }
  .field input, .field textarea {
    border: 0; border-bottom: 1px solid #ccc; border-radius: 0; padding: 2px 0;
  }
  .chip { border: 0; padding: 2px 0; }
  .chip[aria-pressed="true"] { background: none; color: #000; font-weight: 700; }
  .chip[aria-pressed="true"]::before { content: "☑ "; }
  .chip[aria-pressed="false"]::before { content: "☐ "; }
}
