/* ============ Case History Buddy 全局样式 ============ */
:root {
  --primary: #1d4ed8;
  --primary-strong: #1e40af;
  --primary-soft: #eff6ff;
  --teal: #0f766e;
  --teal-soft: #f0fdfa;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --amber: #b45309;
  --amber-soft: #fffbeb;
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #94a3b8;
  --line: #e2e8f0;
  --bg: #f4f7fb;
  --card: #ffffff;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .05);
  --shadow-lg: 0 10px 32px rgba(15, 23, 42, .14);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; }
svg { display: block; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px;
  padding: 12px 26px;
  background: rgba(255, 255, 255, .86);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; cursor: pointer; user-select: none; }
.logo-mark {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, #2563eb, #0f766e);
  color: #fff; display: grid; place-items: center;
  box-shadow: 0 4px 10px rgba(29, 78, 216, .25);
}
.logo-mark svg { width: 21px; height: 21px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-title { font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.brand-sub { font-size: 11.5px; color: var(--ink-3); }
.nav { display: flex; gap: 4px; flex: 1; justify-content: center; }
.nav-btn {
  border: none; background: transparent; color: var(--ink-2);
  font-size: 14px; font-weight: 500; padding: 8px 16px; border-radius: 999px;
  cursor: pointer; transition: background .15s, color .15s;
}
.nav-btn:hover { background: #eef2f7; color: var(--ink); }
.nav-btn.active { background: var(--primary-soft); color: var(--primary); }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 9px 16px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 3px 8px rgba(29, 78, 216, .25); }
.btn-primary:hover { background: var(--primary-strong); transform: translateY(-1px); }
.btn-ghost { background: #fff; color: var(--ink-2); border-color: var(--line); }
.btn-ghost:hover { border-color: #cbd5e1; color: var(--ink); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: 5px 11px; font-size: 13px; border-radius: 8px; }
.btn-icon { padding: 6px 9px; background: transparent; border: none; color: var(--ink-3); border-radius: 8px; cursor: pointer; }
.btn-icon:hover { background: #eef2f7; color: var(--ink); }
.btn-icon.danger:hover { background: var(--danger-soft); color: var(--danger); }
.plus { font-size: 15px; font-weight: 700; }

/* ---------- 布局 ---------- */
.container { max-width: 1120px; margin: 0 auto; padding: 26px 26px 80px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-title { font-size: 21px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.page-title .sub { font-size: 13px; color: var(--ink-3); font-weight: 400; }
.back-link { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); font-size: 13.5px; font-weight: 500; cursor: pointer; background: none; border: none; padding: 4px 2px; }
.back-link:hover { color: var(--primary); }

/* ---------- 卡片 ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.section-title { font-size: 15.5px; font-weight: 600; margin: 0 0 4px; }
.section-sub { font-size: 13px; color: var(--ink-3); margin: 0 0 16px; }

/* ---------- 统计卡片 ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 26px; }
.stat-card { padding: 20px 22px; display: flex; align-items: center; gap: 16px; }
.stat-icon { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.stat-icon svg { width: 23px; height: 23px; }
.stat-icon.blue { background: var(--primary-soft); color: var(--primary); }
.stat-icon.teal { background: var(--teal-soft); color: var(--teal); }
.stat-icon.amber { background: var(--amber-soft); color: var(--amber); }
.stat-icon.gray { background: #f1f5f9; color: var(--ink-2); }
.stat-meta { min-width: 0; }
.stat-value { font-size: 26px; font-weight: 750; letter-spacing: -.3px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 13px; color: var(--ink-2); margin-top: 3px; }

/* ---------- 性别分布条 ---------- */
.dist-bar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; margin-top: 12px; background: #f1f5f9; }
.dist-legend { display: flex; gap: 16px; margin-top: 12px; font-size: 12.5px; color: var(--ink-2); }
.dist-legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.dist-legend b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------- 患者列表 ---------- */
.patient-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 16px; }
@media (max-width: 420px) { .patient-grid { grid-template-columns: 1fr; } }
.patient-card { padding: 16px 18px; cursor: pointer; transition: transform .15s, box-shadow .2s, border-color .15s; }
.patient-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: #bfdbfe; }
.pc-main { display: flex; align-items: flex-start; gap: 14px; }
.avatar {
  width: 46px; height: 46px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 17px; color: #fff;
}
.pc-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.pc-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.pc-name-wrap { min-width: 0; }
.pc-name { font-size: 16px; font-weight: 650; display: flex; align-items: center; gap: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc-sub { font-size: 12px; color: var(--ink-3); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc-badges { flex: none; display: flex; gap: 6px; flex-wrap: wrap; }
.pc-clinical { background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.pc-line { display: flex; gap: 10px; font-size: 13px; align-items: baseline; }
.pc-line .pc-label { width: 62px; flex: none; color: var(--ink-3); text-align: right; white-space: nowrap; }
.pc-line .pc-val { color: var(--ink); min-width: 0; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pc-line .pc-val.muted { color: var(--ink-3); }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink-2); background: #f8fafc; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; }
.chip.soft-blue { background: var(--primary-soft); border-color: #dbeafe; color: var(--primary); }
.chip.soft-teal { background: var(--teal-soft); border-color: #ccfbf1; color: var(--teal); }
.chip.soft-amber { background: var(--amber-soft); border-color: #fef3c7; color: var(--amber); }
.tag-type { display: inline-block; font-size: 11px; font-weight: 600; border-radius: 6px; padding: 2px 8px; }
.type-initial { background: #dbeafe; color: #1d4ed8; }
.type-followup { background: #e0e7ff; color: #4338ca; }
.type-emergency { background: #fee2e2; color: #b91c1c; }
.type-review { background: #ccfbf1; color: #0f766e; }
.type-other { background: #f1f5f9; color: #475569; }

.search-wrap { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.search-box { position: relative; }
.search-box svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--ink-3); }
.search-box input {
  width: 280px; max-width: 100%; border: 1px solid var(--line); background: #fff;
  border-radius: 999px; padding: 9px 16px 9px 36px; font-size: 14px; outline: none; transition: border .15s, box-shadow .15s;
}
.search-box input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.empty { text-align: center; color: var(--ink-3); padding: 60px 0; }
.empty svg { width: 60px; height: 60px; margin: 0 auto 14px; color: #cbd5e1; }
.empty p { margin: 4px 0; }
.empty .em-title { font-size: 16px; font-weight: 600; color: var(--ink-2); }

/* ---------- 详情页 ---------- */
.detail-grid { display: grid; grid-template-columns: 340px 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .detail-grid { grid-template-columns: 1fr; } }
.info-card { padding: 22px; position: sticky; top: 86px; }
.info-head { display: flex; align-items: center; gap: 13px; margin-bottom: 16px; }
.info-name { font-size: 18px; font-weight: 700; }
.info-meta { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }
.info-rows { display: flex; flex-direction: column; gap: 9px; }
.info-row { display: flex; gap: 10px; font-size: 13.5px; }
.info-row .k { width: 74px; flex: none; color: var(--ink-3); text-align: right; }
.info-row .v { color: var(--ink); word-break: break-word; white-space: pre-wrap; }
.info-row.key .v { font-weight: 600; color: var(--primary); }
.info-actions { display: flex; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.field-block { margin-top: 16px; border-top: 1px dashed var(--line); padding-top: 14px; }
.field-label { font-size: 12.5px; font-weight: 650; color: var(--ink-3); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 5px; }
.field-text { font-size: 13.5px; white-space: pre-wrap; }
.muted { color: var(--ink-3); }

/* ---------- 时间线 ---------- */
.timeline { display: flex; flex-direction: column; gap: 16px; }
.record { display: grid; grid-template-columns: 54px 1fr; gap: 16px; position: relative; }
.record:not(:last-child)::before { content: ""; position: absolute; left: 15px; top: 38px; bottom: -16px; width: 2px; background: #e2e8f0; }
.record-date { text-align: center; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.record-date .day { font-size: 19px; font-weight: 750; color: var(--ink); line-height: 1.15; }
.record-dot { width: 32px; height: 32px; margin: 0 auto; border-radius: 50%; background: #fff; border: 2px solid var(--primary); display: grid; place-items: center; color: var(--primary); margin-top: 2px; }
.record-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.record-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.record-title { font-weight: 650; font-size: 15px; margin-right: auto; }
.record-body { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 720px) { .record-body { grid-template-columns: 1fr; } }
.rf { min-width: 0; }
.rf .fl { font-size: 12px; color: var(--ink-3); margin-bottom: 3px; display: flex; align-items: center; gap: 5px; }
.rf .fv { font-size: 13.8px; white-space: pre-wrap; word-break: break-word; }
.fv.empty-val { color: #cbd5e1; font-style: italic; }
.record-actions { display: flex; gap: 4px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px;
  animation: fadeIn .16s ease; overflow-y: auto;
}
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.modal {
  background: #fff; border-radius: 16px; width: 560px; max-width: 100%;
  box-shadow: var(--shadow-lg); animation: popIn .18s ease; margin-bottom: 5vh;
}
.modal.wide { width: 700px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 24px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 17px; }
.modal-body { padding: 22px 24px; max-height: 66vh; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--line); background: #fafcff; border-radius: 0 0 16px 16px; }

/* ---------- 表单 ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.fg label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.fg label .req { color: var(--danger); }
.field, .field select, .field textarea, .field input {
  width: 100%; border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 12px; font-size: 14px; font-family: inherit; background: #fff; outline: none;
  transition: border .15s, box-shadow .15s; color: var(--ink);
}
.field:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
textarea.field { resize: vertical; min-height: 64px; line-height: 1.55; }
.field[readonly] { background: #f8fafc; color: var(--ink-2); }

/* ---------- Toast ---------- */
#toast-root { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--ink); color: #fff; font-size: 13.5px; padding: 10px 18px;
  border-radius: 999px; box-shadow: var(--shadow-lg); animation: popIn .2s ease;
  display: flex; align-items: center; gap: 8px; max-width: 90vw;
}
.toast.ok { background: #065f46; }
.toast.err { background: #991b1b; }

/* ---------- 其他 ---------- */
.loading { text-align: center; padding: 90px 0; color: var(--ink-3); }
.scroll-x { overflow-x: auto; }
.age-badge { font-size: 12px; color: var(--ink-3); font-weight: 400; }
.danger-zone-text { font-size: 13px; color: var(--ink-2); line-height: 1.6; }
.kbd-enter { color: var(--ink-3); }

/* ---------- 病程描述（老数据） ---------- */
.record-desc {
  margin-top: 4px; margin-bottom: 12px;
  padding: 10px 14px; background: var(--primary-soft);
  border: 1px solid #dbeafe; border-radius: 10px;
}
.record-desc .fl { color: var(--primary); font-size: 12px; font-weight: 650; margin-bottom: 4px; display: flex; align-items: center; gap: 5px; }
.record-desc .fv { font-size: 13.6px; white-space: pre-wrap; word-break: break-word; }

/* ---------- 病历图片（时间线内） ---------- */
.record-imgs { margin-top: 16px; border-top: 1px dashed var(--line); padding-top: 14px; }
.record-imgs > .fl { font-size: 12.5px; color: var(--ink-2); margin-bottom: 8px; display: flex; align-items: center; gap: 5px; }
.img-count { background: var(--primary-soft); color: var(--primary); font-size: 11px; border-radius: 999px; padding: 1px 8px; font-weight: 600; }
.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.img-thumb {
  padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  background: #fff; cursor: zoom-in; aspect-ratio: 1 / 1; width: 100%;
  transition: border-color .15s, transform .15s;
}
.img-thumb:hover { border-color: var(--primary); transform: translateY(-1px); box-shadow: var(--shadow); }
.img-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- 图片灯箱 ---------- */
.lightbox-backdrop {
  position: fixed; inset: 0; z-index: 60; background: rgba(10, 14, 22, .88);
  display: flex; align-items: center; justify-content: center; padding: 5vh 5vw;
}
.lb-stage { margin: 0; max-width: calc(100vw - 140px); max-height: 90vh; display: flex; flex-direction: column; align-items: center; }
.lb-stage img { max-width: 100%; max-height: calc(90vh - 42px); object-fit: contain; border-radius: 6px; box-shadow: var(--shadow-lg); }
.lb-stage figcaption { color: #cbd5e1; font-size: 13px; margin-top: 10px; text-align: center; }
.lb-btn {
  position: fixed; z-index: 61; background: rgba(255, 255, 255, .1);
  border: 1px solid rgba(255, 255, 255, .22); color: #fff; width: 46px; height: 46px;
  border-radius: 50%; font-size: 24px; line-height: 1; cursor: pointer;
  display: grid; place-items: center; transition: background .15s;
}
.lb-btn:hover { background: rgba(255, 255, 255, .25); }
.lb-close { top: 22px; right: 26px; }
.lb-prev { left: 26px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 26px; top: 50%; transform: translateY(-50%); }

/* ---------- M1.1 影像上传 / 整理 / 灯箱增强 ---------- */
.btn-xs { padding: 4px 10px; font-size: 12px; border-radius: 7px; gap: 5px; }
.record-imgs > .fl { justify-content: space-between; align-items: center; width: 100%; }
.fl-title { display: inline-flex; align-items: center; gap: 5px; }
.img-actions { display: inline-flex; align-items: center; gap: 6px; }
.att-input { display: none; }
.img-empty { margin: 6px 0 0; font-size: 12.5px; color: var(--ink-3); }
.record-file-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; }
.record-file-pick { position: relative; display: inline-flex; align-items: center; gap: 5px; cursor: pointer; overflow: hidden; }
.record-files-input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer; z-index: 1;
}
.record-file-hint { font-size: 12px; }
.record-files-preview { margin-top: 10px; }
.picked-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 10px; }
.pick-tile { position: relative; border: 1px solid var(--line); border-radius: 10px; padding: 6px; background: #fff; cursor: zoom-in; transition: border-color .15s, box-shadow .15s; }
.pick-tile:hover { border-color: #93c5fd; box-shadow: 0 3px 12px rgba(37, 99, 235, .12); }
.pick-tile .pick-name { transition: color .15s; }
.pick-tile:hover .pick-name { color: var(--primary); }
.pick-viewer {
  position: fixed; inset: 0; z-index: 1200; background: rgba(8, 12, 25, .92);
  display: grid; place-items: center;
}
.pick-view-stage { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.pick-view-stage img {
  max-width: min(92vw, 1100px); max-height: 80vh; object-fit: contain;
  border-radius: 10px; background: #000; box-shadow: 0 14px 44px rgba(0, 0, 0, .55);
}
.pick-view-stage figcaption { color: #cbd5e1; font-size: 13px; font-variant-numeric: tabular-nums; }
.pv-nav, .pv-close {
  position: fixed; z-index: 1201; border: none; border-radius: 50%;
  background: rgba(255, 255, 255, .14); color: #fff; cursor: pointer;
  display: grid; place-items: center; backdrop-filter: blur(4px);
  transition: background .15s;
}
.pv-nav:hover, .pv-close:hover { background: rgba(255, 255, 255, .3); }
.pv-nav { top: 50%; transform: translateY(-50%); width: 46px; height: 46px; font-size: 26px; padding-bottom: 3px; }
.pv-prev { left: 16px; }
.pv-next { right: 16px; }
.pv-close { top: 16px; right: 16px; width: 38px; height: 38px; font-size: 20px; }
.pick-thumb {
  position: relative; display: grid; place-items: center;
  aspect-ratio: 1 / 1; overflow: hidden; border-radius: 7px; background: #f1f5f9;
}
.pick-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pick-doc svg { width: 44%; height: 44%; color: #cbd5e1; }
.pick-ext {
  position: absolute; left: 50%; top: 55%; transform: translate(-50%, -50%);
  font-size: 10px; font-weight: 800; color: #64748b; letter-spacing: .3px; max-width: 80%;
  white-space: nowrap; overflow: hidden;
}
.pick-name {
  display: block; margin-top: 5px; font-size: 11px; color: var(--ink-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center;
}
.pick-x {
  position: absolute; top: 4px; right: 4px; z-index: 2;
  width: 18px; height: 18px; padding: 0; border: none; border-radius: 50%;
  background: rgba(15, 23, 42, .72); color: #fff; font-size: 13px; line-height: 1;
  cursor: pointer; display: grid; place-items: center;
}
.pick-x:hover { background: var(--danger); }

.att-tile { position: relative; }
.att-tile .tile-actions {
  position: absolute; top: 5px; right: 5px; display: flex; gap: 3px;
  opacity: 0; transition: opacity .12s;
}
.att-tile:hover .tile-actions { opacity: 1; }
.tile-btn {
  display: grid; place-items: center; width: 23px; height: 23px;
  background: rgba(15, 23, 42, .72); color: #fff; border: none; border-radius: 6px;
  cursor: pointer; padding: 0;
}
.tile-btn svg { width: 12px; height: 12px; }
.tile-btn:hover { background: var(--ink); }
.tile-btn.danger:hover { background: var(--danger); }

.pdf-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  aspect-ratio: 1 / 1; width: 100%; border: 1px dashed var(--line); border-radius: 8px;
  background: #f8fafc; color: var(--ink-2); padding: 8px; min-width: 0; text-decoration: none;
  transition: border-color .15s, color .15s;
}
.pdf-tile:hover { border-color: var(--primary); color: var(--primary); }
.pdf-tile .pdf-ic { color: #dc2626; }
.pdf-tile .pdf-ic svg { width: 32px; height: 32px; }
.pdf-name { font-size: 10.5px; max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: inherit; }

.manage-list { display: flex; flex-direction: column; gap: 10px; max-height: 52vh; overflow-y: auto; padding: 2px; }
.manage-row { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fff; }
.manage-thumb { width: 46px; height: 46px; flex: none; border-radius: 7px; overflow: hidden; border: 1px solid var(--line); background: #fff; }
.manage-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.manage-thumb .pdf-mini { display: grid; place-items: center; width: 100%; height: 100%; color: #dc2626; }
.manage-thumb .pdf-mini svg { width: 24px; height: 24px; }
.manage-name { flex: 1; min-width: 0; }
.manage-name .field { padding: 6px 10px; font-size: 13px; }
.manage-size { font-size: 11.5px; color: var(--ink-3); flex: none; width: 52px; text-align: right; font-variant-numeric: tabular-nums; }
.manage-btns { display: flex; gap: 2px; flex: none; }

.lb-scroll {
  max-width: calc(100vw - 130px); max-height: calc(90vh - 52px);
  overflow: auto; border-radius: 6px; box-shadow: var(--shadow-lg);
}
.lb-scroll img {
  max-width: 100%; max-height: calc(90vh - 52px); object-fit: contain; display: block;
  transition: transform .12s ease; transform-origin: center center;
}
.lb-tools { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 63; display: flex; gap: 8px; align-items: center; }
.lb-tool {
  min-width: 40px; height: 40px; padding: 0 10px;
  background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .25);
  color: #fff; border-radius: 11px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 2px; font-size: 15px;
  text-decoration: none; transition: background .15s;
}
.lb-tool:hover { background: rgba(255, 255, 255, .3); }
.lb-tool svg { width: 17px; height: 17px; }
.lb-scale-label { font-variant-numeric: tabular-nums; font-size: 12.5px; }

/* ---------- M1.2 患者库搜索 / 筛选 / 全文检索 ---------- */
.head-actions { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.search-tools { display: flex; gap: 10px; align-items: center; margin: 0 0 12px; }
.seg { display: inline-flex; flex: none; background: #eef1f6; border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg-btn { border: none; background: transparent; color: var(--ink-2); font-size: 13px; padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.seg-btn.active { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(15, 23, 42, .12); }
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 14px; }
.filter-sel { width: auto; padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.fdate { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.fdate input { padding: 5px 8px; font-size: 12.5px; border: 1px solid var(--line); border-radius: 8px; width: 142px; }
.fdate-sep { color: var(--ink-3); font-size: 12px; }
.result-panel { padding: 14px 18px; }
.search-group { padding: 14px 16px; cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.search-group:hover { border-color: var(--primary); box-shadow: 0 4px 14px rgba(37, 99, 235, .1); }
.sg-head { display: flex; align-items: center; gap: 10px; }
.sg-title { flex: 1; min-width: 0; }
.sg-more { font-size: 12.5px; color: var(--primary); white-space: nowrap; }
.sg-hits { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.hit-row { display: grid; grid-template-columns: auto auto 1fr; gap: 10px; align-items: baseline; }
.hit-date { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.hit-body { display: flex; flex-wrap: wrap; gap: 2px 14px; min-width: 0; font-size: 12.5px; color: var(--ink-2); }
.hit-d { color: var(--ink); }
.hit-type { min-width: 54px; text-align: center; }

/* ---------- M2.1 对话式录入助手 ---------- */
.chat-panel {
  display: flex; flex-direction: column;
  background: #fff; border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); overflow: hidden;
}
.chat-log {
  flex: 1; overflow-y: auto; padding: 20px 22px;
  display: flex; flex-direction: column; gap: 12px;
  height: min(560px, calc(100vh - 330px)); min-height: 360px;
  background: linear-gradient(180deg, #f8fafc, #eef3fb);
}
.msg-row { display: flex; flex-direction: column; max-width: 86%; }
.msg-row.user { align-self: flex-end; align-items: flex-end; }
.msg-row.assistant { align-self: flex-start; align-items: flex-start; }
.msg-row.proposal { align-self: stretch; max-width: 100%; }
.bubble {
  padding: 10px 14px; border-radius: 15px;
  font-size: 14px; line-height: 1.65; white-space: pre-wrap; word-break: break-word;
  max-width: 100%; box-shadow: 0 1px 2px rgba(15, 23, 42, .05);
}
.bubble.user {
  background: linear-gradient(135deg, #2563eb, #1d4ed8); color: #fff;
  border-bottom-right-radius: 5px;
}
.bubble.bot {
  background: #fff; border: 1px solid var(--line); color: var(--ink);
  border-bottom-left-radius: 5px;
}
.bubble.question { background: #fffbeb; border: 1px solid #fde68a; border-bottom-left-radius: 5px; }
.bubble.notice { background: #ecfdf5; border: 1px solid #a7f3d0; border-bottom-left-radius: 5px; }
.chat-meta { font-size: 11px; color: var(--ink-3); margin: 4px 6px 0; }
.chat-time { font-variant-numeric: tabular-nums; }
.chat-goto { margin-top: 8px; }
.welcome-suggest { display: flex; flex-wrap: wrap; gap: 8px; margin: 2px 0 6px; }
.suggest-chip {
  border: 1px solid var(--line); background: #fff; color: var(--ink-2);
  border-radius: 999px; padding: 6px 14px; font-size: 13px; cursor: pointer;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .05); transition: all .15s;
}
.suggest-chip:hover { border-color: var(--primary); color: var(--primary); background: #eff6ff; }
/* 复查计划卡（档案时间线顶部“下一步”） */
.record-next .record-card.next-set { border-top: 3px solid var(--teal); }
.record-next .record-date { color: var(--teal); }
.record-next .record-date .day { color: var(--teal); }
.record-next .record-card.next-missing { border: 1.5px dashed #eab308; background: var(--amber-soft); }
.record-next .record-card.next-missing .record-title { color: var(--amber); }
.record-next .record-title { display: inline-flex; align-items: center; gap: 6px; }
.review-missing-hint { font-size: 13.5px; color: var(--ink-2); margin: 2px 0 10px; }
.review-set-label { font-size: 12.5px; color: var(--amber); margin-bottom: 4px; }
.quick-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.quick-chips .suggest-chip { padding: 5px 12px; font-size: 12.5px; }
.chat-composer {
  display: flex; gap: 10px; align-items: flex-end;
  padding: 12px 14px; border-top: 1px solid var(--line); background: #fafcff;
}
.chat-composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; font-size: 14px; line-height: 1.5;
  font-family: inherit; outline: none; max-height: 160px; background: #fff;
}
.chat-composer textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.chat-send { flex: none; align-self: center; white-space: nowrap; }
.chat-tips { color: var(--ink-3); font-size: 12px; margin-top: 10px; line-height: 1.7; }

/* 提案卡片 */
.prop-shell { width: 100%; margin-top: 8px; }
.prop-card { border-left: 3px solid var(--primary); width: 100%; }
.prop-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.prop-head .chip { vertical-align: middle; }
.prop-patient { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; }
.prop-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-top: 14px; flex-wrap: wrap;
}
.prop-btns { display: inline-flex; gap: 8px; align-items: center; }
.prop-note { margin-top: 8px; font-size: 12px; color: var(--ink-3); line-height: 1.6; }
.prop-done { display: flex; align-items: center; gap: 10px; padding: 6px 2px; }
.pick-list { display: flex; flex-direction: column; gap: 8px; width: 100%; margin-top: 8px; }
.pick-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; cursor: pointer; text-align: left; font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}
.pick-item:hover { border-color: var(--primary); box-shadow: 0 3px 12px rgba(37, 99, 235, .12); }
.pick-item .avatar { flex: none; }
.pick-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pc-sub { font-size: 12px; color: var(--ink-3); }
.card.prop-card .field { font-size: 13.5px; }
.card.prop-card .fg label { font-size: 12.5px; }

/* =========================================================
   M2.4 移动优先 · 对话默认入口 · 拍照直传 · PWA 可安装
   ========================================================= */
/* ---- 对话内图片（桌面/移动共用） ---- */
.chat-panel { position: relative; }
.chat-add {
  flex: none; width: 38px; height: 38px; border-radius: 50%; align-self: flex-end;
  border: 1px solid var(--line); background: #fff; color: var(--primary);
  display: grid; place-items: center; cursor: pointer; padding: 0;
  transition: all .15s;
}
.chat-add:hover { border-color: var(--primary); background: var(--primary-soft); }
.chat-add svg { width: 19px; height: 19px; }
.chat-add:disabled { opacity: .45; cursor: not-allowed; }
.chat-pick-sheet {
  position: absolute; left: 12px; bottom: calc(100% - 14px);
  width: 208px; background: #fff; border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow-lg); padding: 6px; z-index: 12;
  animation: popIn .14s ease;
}
.chat-pick-sheet[hidden] { display: none; }
.cps-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: none; background: none; padding: 9px 11px; font-size: 14px;
  color: var(--ink); border-radius: 9px; cursor: pointer; text-align: left;
}
.cps-item:hover { background: var(--primary-soft); color: var(--primary); }
.cps-item svg { width: 18px; height: 18px; }
.cps-cancel {
  width: 100%; border: none; background: none; padding: 7px 11px;
  font-size: 13px; color: var(--ink-3); cursor: pointer; border-top: 1px solid #f1f5f9;
  border-radius: 0 0 9px 9px; margin-top: 2px;
}
.chat-pending {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px 12px; border-top: 1px solid var(--line); background: #fff;
}
.chat-pending[hidden] { display: none; }
.cpp-hint {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12.5px; color: var(--ink-2); font-weight: 600;
}
.cpp-grid { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.cpp-thumb {
  position: relative; width: 64px; height: 64px; flex: none;
  border-radius: 10px; overflow: hidden; border: 1px solid var(--line);
}
.cpp-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cpp-del {
  position: absolute; top: 3px; right: 3px; width: 19px; height: 19px;
  border-radius: 50%; padding: 0; border: none; cursor: pointer;
  background: rgba(15, 23, 42, .62); color: #fff;
  display: grid; place-items: center;
}
.cpp-del svg { width: 10px; height: 10px; }
.msg-imgs {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px; width: min(320px, 100%);
}
.chat-img {
  position: relative; width: 100%; aspect-ratio: 1 / 1; padding: 0;
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
  cursor: zoom-in; background: #fff; box-shadow: 0 1px 2px rgba(15, 23, 42, .05);
}
.chat-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat-img:hover { border-color: var(--primary); }
.pill.pending {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; color: var(--amber); background: var(--amber-soft);
  padding: 1px 8px; border-radius: 999px; font-weight: 600;
}
.chat-img-del {
  display: inline-flex; align-items: center; gap: 3px;
  border: none; background: none; font-size: 11px; color: var(--ink-3);
  cursor: pointer; padding: 1px 2px;
}
.chat-img-del:hover { color: var(--danger); }
.chat-img-del svg { width: 11px; height: 11px; }

/* ---- 底部导航（仅移动端显示） ---- */
#bottom-nav { display: none; }

/* ============================ 移动端 ≤ 768px ============================ */
@media (max-width: 768px) {
  .topbar {
    position: fixed; inset: 0 0 auto 0; z-index: 40;
    height: 54px; padding: 0 14px; gap: 10px;
  }
  .topbar .nav { display: none; }
  .topbar > .btn-primary { display: none; }
  .brand { flex: 1; }
  .brand-text { display: none; }

  .container { padding: 72px 14px 92px; } /* 顶栏固定占位 54 + 16 */
  .page-head { margin-bottom: 14px; gap: 10px; }
  .page-title { font-size: 18px; gap: 8px; flex-wrap: wrap; }
  .page-title .sub { font-size: 12px; }
  .head-actions .btn-sm { padding: 6px 10px; font-size: 12.5px; }
  .form-grid { grid-template-columns: 1fr; gap: 12px 0; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
  .stat-card { padding: 14px; gap: 10px; }
  .stat-icon { width: 36px; height: 36px; border-radius: 10px; }
  .stat-icon svg { width: 18px; height: 18px; }
  .stat-value { font-size: 20px; }
  .patient-grid { grid-template-columns: 1fr; gap: 12px; }
  .pc-main { gap: 10px; }
  .chat-tips { margin-top: 8px; font-size: 11.5px; }

  .modal-backdrop { padding: 12px 10px; align-items: center; }
  .modal, .modal.wide { width: 100%; margin-bottom: 0; border-radius: 14px; }
  .modal-head { padding: 14px 16px; }
  .modal-body { padding: 14px 16px; max-height: 72vh; }
  .modal-foot { padding: 12px 16px; }
  .prop-foot { align-items: stretch; }
  .prop-btns { width: 100%; justify-content: flex-end; }

  #toast-root { bottom: calc(76px + env(safe-area-inset-bottom)); }

  /* 聊天铺满可视区（对话=主场景） */
  body[data-view="chat"] { overflow: hidden; }
  body[data-view="chat"] .container {
    display: flex; flex-direction: column;
    margin-top: 54px;
    height: calc(100vh - 54px - 62px);
    height: calc(100dvh - 54px - 62px);
    padding: 0;
    max-width: none;
  }
  body[data-view="chat"] .page-head,
  body[data-view="chat"] .chat-tips { display: none; }
  body[data-view="chat"] .chat-panel {
    flex: 1; min-height: 0; display: flex; flex-direction: column;
    border-radius: 0; border-left: none; border-right: none;
  }
  body[data-view="chat"] .chat-log {
    flex: 1; min-height: 0; height: auto; padding: 16px 12px;
  }
  .chat-composer { padding: 9px 10px; gap: 8px; }
  .chat-composer textarea {
    font-size: 16px; padding: 9px 12px; border-radius: 12px; max-height: 120px;
  }
  .chat-send { padding: 9px 13px; }
  .send-text { display: none; }
  .chat-add { width: 38px; height: 38px; }

  /* 底部主导航 */
  #bottom-nav {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 42;
    height: calc(62px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(255, 255, 255, .96);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
  }
  .bn-btn {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; border: none; background: none; color: var(--ink-3);
    font-size: 11px; padding: 6px 2px 8px; cursor: pointer;
    transition: color .15s;
  }
  .bn-btn svg { width: 22px; height: 22px; }
  .bn-btn span.plus { font-size: 23px; line-height: 1; color: #fff; }
  .bn-btn.bn-new {
    flex: 0 0 auto; width: 52px; margin: 7px 10px; padding: 0;
    background: linear-gradient(135deg, #2563eb, #1d4ed8); color: #fff;
    border-radius: 15px; box-shadow: 0 6px 16px rgba(29, 78, 216, .35);
  }
  .bn-btn.bn-new span.plus { font-size: 24px; }
  .bn-btn.bn-new.active { color: #fff; }
  .bn-btn.active { color: var(--primary); font-weight: 600; }
  .bn-btn:active { opacity: .75; }
}

@media (max-width: 420px) {
  .msg-imgs { grid-template-columns: repeat(3, minmax(0, 1fr)); width: min(240px, 100%); }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}

