:root {
  --blue: #1E40AF;
  --blue2: #2563EB;
  --bg: #F5F7FA;
  --card: #FFFFFF;
  --text: #1F2937;
  --muted: #6B7280;
  --border: #E3E8EF;
  --green: #16A34A;
  --red: #DC2626;
  --orange: #F59E0B;
  --accent: #EFF6FF;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

input, select, textarea, button {
  font-family: inherit;
  font-size: 16px; /* 防止 iOS 聚焦自动放大 */
}

/* ═══ 通用 ═══ */
.hidden { display: none !important; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 20px;
  border: none;
  border-radius: var(--radius);
  background: var(--blue2);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  width: 100%;
  cursor: pointer;
  transition: opacity .15s;
}
.btn:active { opacity: .75; }
.btn:disabled { opacity: .45; }
.btn.ghost {
  background: var(--card);
  color: var(--blue2);
  border: 1px solid var(--border);
}
.btn.danger { background: var(--red); }
.btn.small-btn { min-height: 40px; font-size: 15px; width: auto; padding: 0 16px; }

.field { margin-bottom: 11px; }
.field label {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 5px;
  font-weight: 500;
}
.field input, .field select {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  outline: none;
}
.field input:focus, .field select:focus {
  border-color: var(--blue2);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .05);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(31, 41, 55, .94);
  color: #fff;
  padding: 11px 20px;
  border-radius: 22px;
  font-size: 15px;
  max-width: 86vw;
  z-index: 999;
  opacity: 0;
  transition: opacity .2s, bottom .2s;
  pointer-events: none;
}
.toast.show { opacity: 1; bottom: calc(100px + var(--safe-bottom)); }

/* ═══ 登录页 ═══ */
#login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 22px calc(24px + var(--safe-bottom));
  background: linear-gradient(160deg, #1E40AF 0%, #2563EB 55%, #3B82F6 100%);
}
#login-page .brand {
  text-align: center;
  color: #fff;
  margin-bottom: 28px;
}
#login-page .brand h1 {
  font-size: 26px;
  margin: 0 0 8px;
  letter-spacing: 1px;
  font-weight: 700;
}
#login-page .brand p {
  margin: 0;
  font-size: 15px;
  opacity: .82;
}
#login-page .login-card {
  background: #fff;
  border-radius: 18px;
  padding: 24px 20px;
  box-shadow: 0 10px 40px rgba(15, 23, 42, .18);
}
#login-page .btn { margin-top: 8px; }
#login-page .foot {
  text-align: center;
  color: rgba(255, 255, 255, .75);
  font-size: 13px;
  margin-top: 22px;
  line-height: 1.7;
}

/* ═══ 主框架 ═══ */
#app { min-height: 100vh;
  min-height: 100dvh; }

main {
  /* 顶栏去掉后，全面屏要自己留出状态栏高度，否则内容顶到刘海下面 */
  padding: calc(12px + env(safe-area-inset-top, 0px)) 14px calc(80px + var(--safe-bottom));
  max-width: 720px;
  margin: 0 auto;
}

/* ═══ 底部 tab ═══ */
nav.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 60;
  display: flex;
  background: rgba(255, 255, 255, .97);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
nav.tabbar button {
  flex: 1;
  border: none;
  background: none;
  padding: 9px 0 10px;
  color: var(--muted);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}
nav.tabbar button .ico { font-size: 21px; line-height: 1; }
nav.tabbar button.active { color: var(--blue2); font-weight: 600; }

/* ═══ 门店 chips ═══ */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 10px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 7px 15px;
  border-radius: 20px;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  white-space: nowrap;
}
.chip.active {
  background: var(--blue2);
  border-color: var(--blue2);
  color: #fff;
  font-weight: 600;
}

/* ═══ 搜索区 ═══ */
.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.search-row input {
  flex: 1;
  min-height: 42px;
  padding: 0 12px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  background: #fff;
}
.search-row input:focus {
  border-color: var(--blue2);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.search-row select {
  flex: 0 0 108px;
  min-height: 42px;
  font-size: 15px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  outline: none;
}

/* ═══ 药品列表 ═══ */
.drug-item {
  background: #fff;
  border-radius: var(--radius);
  padding: 11px 13px;
  margin-bottom: 7px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  border: 1px solid transparent;
}
.drug-item:active { background: var(--accent); border-color: #BFDBFE; }
.drug-item .info { flex: 1; min-width: 0; }
.drug-item .name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.drug-item .meta {
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  flex-wrap: nowrap;      /* 只有一行，放不下就截断，不换行占高度 */
  align-items: baseline;
  gap: 9px;
  min-width: 0;
}
.drug-item .meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* 规格：不压缩，优先完整显示 */
.drug-item .meta .m-spec { flex: 0 0 auto; }
/* 厂家：占剩余空间，能显示多少显示多少，超出省略 */
.drug-item .meta .m-maker {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 11.5px;
  color: #9CA3AF;
}
.drug-item .right {
  text-align: right;
  flex: 0 0 auto;
}
.stock-badge {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 8px;
  background: #ECFDF5;
  color: var(--green);
}
.stock-badge.low { background: #FFFBEB; color: var(--orange); }
.stock-badge.zero { background: #FEF2F2; color: var(--red); }
.price { font-size: 13px; color: var(--muted); margin-top: 4px; }

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.8;
}
/* 卡片内的小空态，不要 48px 那么大的留白 */
.empty.small {
  padding: 18px 8px;
  font-size: 13px;
  line-height: 1.6;
}

/* ═══ 我的 ═══ */
.me-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
  font-size: 16px;
}
.me-row:last-child { border-bottom: none; }
.me-row .k { color: var(--muted); font-size: 15px; }
.me-row .v { font-weight: 500; }

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
}
.dot.ok { background: var(--green); }
.dot.bad { background: var(--red); }
.dot.wait { background: var(--orange); }

/* ═══ 已选药品 ═══ */
#picked-box {
  background: #fff;
  border: 1px solid #BFDBFE;
  border-radius: var(--radius);
  padding: 9px 11px;
  margin: 12px 0 10px;
}
.picked-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  color: var(--blue);
  font-weight: 600;
  margin-bottom: 6px;
}
.picked-head b { font-size: 15px; }
.picked-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px dashed var(--border);
}
.picked-item .pi-main { flex: 1; min-width: 0; }
.picked-item .pi-name {
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}
.pi-tag {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 6px;
  line-height: 1.6;
}
.pi-tag.zero { background: #FEF2F2; color: var(--red); }
.pi-tag.manual { background: #FFF7ED; color: #C2410C; }
.picked-item .pi-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.picked-item .pi-del {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  border: none;
  border-radius: 50%;
  background: #F3F4F6;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.picked-item .pi-del:active { background: #FEE2E2; color: var(--red); }

/* 已选过的药品，列表里淡化 */
.drug-item.picked { opacity: .5; }
.drug-item.picked:active { opacity: .5; }

/* ═══ 用户管理 ═══ */
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.card-title { font-size: 15px; font-weight: 600; }
.card-head .btn.small-btn { min-height: 34px; font-size: 14px; padding: 0 12px; }

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-top: 1px solid var(--border);
}
.user-row.off { opacity: .5; }
.user-row .u-main { flex: 1; min-width: 0; }
.user-row .u-name {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.user-row .u-me {
  font-size: 11px;
  font-weight: 500;
  color: var(--blue2);
  background: var(--accent);
  padding: 1px 6px;
  border-radius: 6px;
}
.user-row .u-sub {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 3px;
}
.user-row .u-role {
  padding: 1px 6px;
  border-radius: 6px;
  background: #F3F4F6;
  color: var(--muted);
  font-size: 12px;
}
.user-row .u-role.admin { background: #FEF3C7; color: #B45309; }
/* 管理员备注：只出现在管理员页面，长文本截断不撑破行 */
.user-row .u-note {
  font-size: 11px;
  font-weight: 500;
  color: #0369A1;
  background: #E0F2FE;
  padding: 1px 6px;
  border-radius: 6px;
  max-width: 132px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-row .u-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 12px;
}

.link-btn {
  border: none;
  background: none;
  padding: 4px 2px;
  color: var(--blue2);
  font-size: 14px;
  cursor: pointer;
}
.link-btn:active { opacity: .6; }
.link-btn.warn { color: var(--orange); }
.link-btn.ok { color: var(--green); }

.form-btns {
  display: flex;
  gap: 10px;
  margin-bottom: 4px;
}
.form-btns .btn { flex: 1; }

/* ═══ 签名与印章 ═══ */
.card-hint {
  font-size: 12px;
  color: var(--muted);
}

.sign-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.sign-row:last-child { border-bottom: none; }

.sign-preview {
  flex: 0 0 84px;
  height: 52px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: #FAFBFC;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.sign-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
/* 印章按方形缩略，红章一眼能认出来 */
.sign-preview.stamp { flex-basis: 60px; height: 60px; background: #FFF; }
.sign-preview.stamp img { max-width: 54px; max-height: 54px; }

.sign-empty {
  font-size: 12px;
  color: #AAB2BF;
}

.sign-mid {
  flex: 1;
  min-width: 0;
}
.sign-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.sign-person {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #FFF;
}
.sign-person:focus {
  outline: none;
  border-color: var(--blue2);
}

.sign-acts {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
.sign-acts .link-btn { font-size: 13px; }

.sign-tip {
  margin-top: 10px;
  padding: 10px 12px;
  background: #F8FAFC;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
}

/* ═══ 数量控制 ═══ */
.qty-ctrl {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.qty-ctrl .q-btn {
  width: 30px; height: 30px;
  border: none;
  background: #F8FAFC;
  color: var(--text);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.qty-ctrl .q-btn:active { background: var(--accent); color: var(--blue2); }
.qty-ctrl .q-val {
  min-width: 30px;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
}

/* ═══ 两列字段 ═══ */
.row2 { display: flex; gap: 10px; }
.row2 .field { flex: 1; }
.req { color: var(--red); }

/* ═══ 底部悬浮按钮 ═══ */
#page-rx { padding-bottom: 72px; }   /* 给底部「下一步」按钮留位 */

.fixed-cta {
  position: fixed;
  left: 14px; right: 14px;
  bottom: calc(64px + var(--safe-bottom));
  z-index: 55;
  max-width: 692px;
  margin: 0 auto;
  box-shadow: 0 6px 20px rgba(30, 64, 175, .28);
}

/* ═══ 全屏弹层 ═══ */
body.no-scroll { overflow: hidden; }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  animation: sheetIn .22s ease;
}
@keyframes sheetIn {
  from { transform: translateY(18px); opacity: .6; }
  to   { transform: translateY(0);    opacity: 1; }
}

.sheet-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.sheet-title { font-size: 17px; font-weight: 600; }
.sheet-x {
  width: 34px; height: 34px;
  border: none;
  border-radius: 50%;
  background: #F3F4F6;
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
}
.sheet-spacer { width: 34px; }

.sheet-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px 20px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.sheet-foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px calc(10px + var(--safe-bottom));
  background: #fff;
  border-top: 1px solid var(--border);
}
.sheet-foot .total-line {
  flex: 0 0 auto;
  font-size: 14px;
  color: var(--muted);
}
.sheet-foot .total-line b {
  font-size: 20px;
  color: var(--red);
  margin-left: 4px;
}
.sheet-foot .btn { flex: 1; }

/* ═══ 药品清单（表单内） ═══ */
.fx-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.fx-item:first-child { border-top: none; }
.fx-idx {
  flex: 0 0 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--blue2);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}
.fx-main { flex: 1; min-width: 0; }
.fx-name {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.fx-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fx-qty {
  flex: 0 0 auto;
  font-size: 15px;
  font-weight: 600;
  color: var(--blue2);
}

/* ═══ 处方图片 ═══ */
.img-body { padding-bottom: 24px; }
.rx-ok {
  background: #ECFDF5;
  border: 1px solid #A7F3D0;
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
}
.rx-ok-id {
  font-size: 15px;
  font-weight: 600;
  color: #047857;
}
.rx-ok-tip {
  font-size: 12.5px;
  color: #059669;
  margin-top: 3px;
}
#rx-img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .06);
}

/* ═══ 飞书存档 ═══ */
.archive-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  background: var(--bg, #f7f7f8);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  margin-bottom: 12px;
  line-height: 1.45;
}
.archive-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.archive-bar .link-btn { flex-shrink: 0; }

.arch-stats {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.arch-cell {
  flex: 1;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 4px;
  background: #fff;
}
.arch-n {
  font-size: 19px;
  font-weight: 700;
  color: var(--text, #1a1a1a);
  line-height: 1.2;
}
.arch-l {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
}
.arch-cell.ok .arch-n { color: var(--green); }
.arch-cell.bad .arch-n { color: var(--red); }
.arch-cell.wait .arch-n { color: var(--orange); }
.rx-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.rx-actions .btn { flex: 1; white-space: nowrap; padding: 0 8px; font-size: 15.5px; }

/* ═══ 患者联想下拉 ═══ */
.pat-hint {
  font-size: 12px;
  color: var(--blue2);
  margin-top: 5px;
}
.pat-sug {
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 6px 20px rgba(15, 23, 42, .10);
  overflow: hidden;
  max-height: 208px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;           /* 纵向滑动交给浏览器，别被脚本吃掉 */
  overscroll-behavior: contain;  /* 滑到底不带动整页 */
}
.pat-sug-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.pat-sug-item:last-child { border-bottom: none; }
.pat-sug-item:active { background: var(--accent); }
.pat-sug-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
}
.pat-sug-meta {
  font-size: 12.5px;
  color: var(--muted);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pat-sug-cnt {
  font-size: 11.5px;
  color: var(--blue);
  background: var(--accent);
  border-radius: 999px;
  padding: 2px 7px;
  white-space: nowrap;
}
.pat-sug-empty {
  padding: 10px 12px;
  font-size: 13px;
  color: var(--muted);
}

/* ═══ 患者卡片（折叠摘要） ═══ */
.pat-card { padding: 14px 16px 16px; }

.pat-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #F8FAFC;
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.pat-summary:active { background: var(--accent); }
.ps-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ps-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.ps-meta {
  font-size: 12.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ps-edit {
  flex: 0 0 auto;
  font-size: 13.5px;
  color: var(--blue2);
  padding-left: 4px;
}
/* 折叠后仍要醒目：缺身份证 / 缺监护人信息 */
.ps-warn {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--red);
  line-height: 1.35;
}
.pat-summary.has-warn {
  border-color: var(--red);
  background: #FEF2F2;
  box-shadow: inset 3px 0 0 var(--red);
}
.pat-summary.has-warn .ps-edit { color: var(--red); }
/* 字段名后面的小提示文字 */
.field label .hint {
  font-size: 11.5px;
  font-weight: 400;
  color: var(--muted);
  margin-left: 4px;
}
/* 一个手机号下的多位患者：标签选择 */
.pchips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 8px;
  padding: 8px 9px;
  background: var(--accent);
  border: 1px solid #DBEAFE;
  border-radius: 10px;
}
.pchips-tip {
  width: 100%;
  font-size: 11.5px;
  color: var(--blue);
}
.pchip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 5px 11px;
  border: 1px solid #BFDBFE;
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.25;
  cursor: pointer;
}
.pchip-name { font-weight: 600; }
.pchip-meta {
  font-size: 10.5px;
  color: var(--muted);
}
.pchip.on {
  background: var(--blue2);
  border-color: var(--blue2);
  color: #fff;
}
.pchip.on .pchip-meta { color: #DBEAFE; }
.pchip:active { opacity: .75; }
/* 新增成员：虚线框，和"选人"区分开 */
.pchip-add {
  border-style: dashed;
  border-color: #93C5FD;
  color: var(--blue2);
}
.pchip-add .pchip-meta { color: var(--muted); }

/* 改了老档案的身份证：当场红字提醒 */
.edit-warn {
  margin-top: 6px;
  padding: 7px 10px;
  background: #FEF2F2;
  border: 1px solid #FCA5A5;
  border-left: 3px solid var(--red);
  border-radius: 8px;
  color: var(--red);
  font-size: 12.5px;
  line-height: 1.45;
  word-break: break-all;
}

/* 性别：两个分段标签，比下拉少一次点击 */
.seg {
  display: flex;
  gap: 7px;
}
.seg-btn {
  flex: 1;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.seg-btn.on {
  background: var(--blue2);
  border-color: var(--blue2);
  color: #fff;
  font-weight: 600;
}
.seg-btn:active { opacity: .8; }

/* 确认页里那行只读患者信息 */
.pat-line {
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  word-break: break-all;
}

/* 卡片内嵌的小块（监护人） */
.sub-card {
  margin-top: 12px;
  padding: 12px;
  background: #F8FAFC;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.sub-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.sub-head .card-title { font-size: 14.5px; }

/* ═══ 未成年人开方提示 / 监护人 ═══ */
.warn-bar {
  margin-top: 8px;
  padding: 9px 11px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.55;
}
.warn-bar.danger {
  background: #FEF2F2;
  color: #B91C1C;
  border: 1px solid #FECACA;
  font-weight: 600;
}
.warn-bar.notice {
  background: #FFFBEB;
  color: #B45309;
  border: 1px solid #FDE68A;
}
.mini-tag {
  font-size: 11.5px;
  color: var(--orange);
  background: #FFFBEB;
  border: 1px solid #FDE68A;
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
}
#f-idcard.invalid { border-color: var(--red); background: #FEF2F2; }

/* 身份证校验没过（软校验放行态）：橙框提示，和 7 岁以下的红框区分开 */
#f-idcard.idc-bad,
#f-guardian-id.idc-bad { border-color: #F59E0B; background: #FFFBEB; }

/* 性别 label 右侧的小标签 */
.field label .mini-tag {
  margin-left: 6px;
  vertical-align: middle;
  display: inline-block;
}

/* 提示条里的行内操作按钮（如「改为女」） */
.wfix-btn {
  margin-left: 8px;
  padding: 3px 10px;
  border: 1px solid #F59E0B;
  border-radius: 999px;
  background: #fff;
  color: #B45309;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.wfix-btn:active { background: #FEF3C7; }

/* ═══ 阶段 4：历史处方 ═══ */
.his-bar {
  position: sticky;
  top: 0;
  z-index: 8;
  background: var(--bg);
  padding: 10px 14px 8px;
  border-bottom: 1px solid var(--border);
}
/* 历史页的来源切换（本机 / 云端）。原来复用 .seg，把患者表单里的性别分段
   也套上了灰底和内边距，这里单独用 #his-source，两者互不影响。 */
#his-source {
  display: flex;
  background: #E8EDF5;
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 9px;
}
#his-source button {
  flex: 1;
  min-height: 34px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
#his-source button.active {
  background: var(--card);
  color: var(--blue);
  box-shadow: 0 1px 4px rgba(15, 23, 42, .12);
}

.his-search { position: relative; margin-bottom: 9px; }
.his-search input {
  width: 100%;
  height: 42px;
  padding: 0 36px 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: 15px;
  -webkit-appearance: none;
  appearance: none;
}
.his-search input:focus { outline: none; border-color: var(--blue2); }
.his-q-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: #E5E9F0;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}
.chips { display: flex; gap: 7px; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  min-height: 32px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 13.5px;
  cursor: pointer;
}
.chip.active {
  background: var(--accent);
  border-color: var(--blue2);
  color: var(--blue);
  font-weight: 600;
}
.his-dates-custom {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}
.his-dates-custom input {
  flex: 1;
  min-width: 0;
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 13.5px;
}
.his-dates-custom .small-btn { flex: none; width: auto; min-height: 36px; padding: 0 14px; }
.his-filters { display: flex; gap: 8px; margin-top: 9px; }
.his-filters select {
  flex: 1;
  height: 38px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  -webkit-appearance: none;
  appearance: none;
}
.his-sum {
  margin-top: 9px;
  font-size: 12.5px;
  color: var(--muted);
}
.his-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 12px 14px 0;
}
.hs-cell {
  background: var(--card);
  border-radius: var(--radius);
  padding: 10px 6px;
  text-align: center;
  border: 1px solid var(--border);
}
.hs-cell b { display: block; font-size: 16px; color: var(--blue); }
.hs-cell span { font-size: 11.5px; color: var(--muted); }
.his-list { padding: 12px 14px 24px; }
.his-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 13px;
  margin-bottom: 9px;
  cursor: pointer;
}
.his-card:active { background: #F8FAFC; }
.his-l1 { display: flex; align-items: baseline; gap: 7px; }
.his-name { font-size: 16.5px; font-weight: 700; }
.his-sex { font-size: 12.5px; color: var(--muted); }
.his-amt { margin-left: auto; font-size: 15px; font-weight: 700; color: var(--blue); }
.his-l2 {
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0 6px;
}
.his-l3 {
  margin-top: 5px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.his-l4 {
  margin-top: 7px;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  color: var(--muted);
}
.his-tag {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.his-tag.ok { background: #ECFDF5; color: #047857; border-color: #A7F3D0; }
.his-tag.pending { background: #FFFBEB; color: #B45309; border-color: #FDE68A; }
.his-tag.fail { background: #FEF2F2; color: #B91C1C; border-color: #FECACA; }
.his-tag.partial { background: #FFF7ED; color: #C2410C; border-color: #FED7AA; }
.his-tag.cloud { background: #EFF6FF; color: var(--blue); border-color: #BFDBFE; }
.his-id { margin-left: auto; font-family: ui-monospace, Menlo, Consolas, monospace; }
.his-more { padding: 0 14px 28px; }
.his-empty {
  padding: 46px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}
.rx-ok-meta {
  margin-top: 5px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.6;
  white-space: pre-line;
}
.img-loading {
  padding: 40px 0;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ═══ 键盘弹出时让出空间 ═══
   底部 tabbar 和悬浮按钮都是 position:fixed，键盘一弹出来就贴着键盘顶边，
   把表单挤得只剩一两行。输入时临时收起它们，光标所在的字段就能露出来。 */
body.kb-open nav.tabbar,
body.kb-open .fixed-cta {
  display: none !important;
}
body.kb-open main { padding-bottom: 10px; }
body.kb-open #page-rx { padding-bottom: 10px; }

/* ═══ 电脑浏览器打开时的适配 ═══
   main 已经是 720px 居中，但底部导航（fixed 全宽）和全屏弹层（inset:0）
   会横跨整个显示器，按钮被拉得极开。统一收成 720 居中。手机上不生效。 */
@media (min-width: 760px) {
  nav.tabbar {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: 720px;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -2px 14px rgba(15, 23, 42, .06);
  }
  .sheet-head,
  .sheet-body,
  .sheet-foot {
    width: 720px;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
  }
  /* 弹层外层本身也要居中留白，否则内容贴着大屏左侧 */
  .sheet {
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
  }
}

/* ═══ 临床诊断：标签点选 ═══ */
.diag-hint {
  margin-left: 8px;
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 400;
}

.diag-picked {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
  min-height: 24px;
  align-items: center;
}
.diag-none { font-size: 12.5px; color: var(--muted); }

.dchip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px 4px 10px;
  border-radius: 999px;
  background: var(--accent);
  border: 1px solid #BFDBFE;
  color: var(--blue2);
  font-size: 13px;
  font-weight: 600;
}
.dchip-x {
  border: none;
  background: none;
  color: inherit;
  font-size: 12px;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
  opacity: .75;
}
.dchip-x:active { opacity: .4; }

.diag-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.diag-input-row input {
  flex: 1;
  min-width: 0;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  outline: none;
  font-size: 14px;
}
.diag-input-row input:focus {
  border-color: var(--blue2);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.diag-input-row .btn.small-btn { flex: 0 0 auto; min-height: 38px; padding: 0 14px; }

.diag-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 132px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
  padding: 8px;
  background: #F8FAFC;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.dtag {
  flex: 0 0 auto;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.1;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
.dtag:active { opacity: .7; }
.dtag.on {
  background: var(--blue2);
  border-color: var(--blue2);
  color: #fff;
  font-weight: 600;
}
.diag-empty { font-size: 12.5px; color: var(--muted); padding: 4px; }

/* ═══ 登录记录 / 设备管理 ═══ */
.sec-dev {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid var(--border);
}
.sec-dev:first-child { border-top: none; }
.sec-dev-main { flex: 1; min-width: 0; }
.sec-dev-name {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
}
.sec-on {
  margin-left: 6px;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--green);
  border: 1px solid #BBF7D0;
  background: #F0FDF4;
  border-radius: 999px;
  padding: 1px 7px;
}
.sec-dev-meta {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
  word-break: break-all;
}
.sec-dev-acts {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: flex-end;
}
.sec-log {
  padding: 8px 0;
  border-top: 1px solid var(--border);
}
.sec-log:first-child { border-top: none; }
.sec-log-line {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
}
.sec-log-user { font-weight: 600; }
.sec-log-dev { color: var(--muted); font-size: 12.5px; }
.sec-log-meta {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 3px;
}
.sec-tag {
  flex: 0 0 auto;
  font-size: 10.5px;
  border-radius: 4px;
  padding: 1px 6px;
}
.sec-tag.ok { color: var(--green); background: #F0FDF4; border: 1px solid #BBF7D0; }
.sec-tag.fail { color: var(--red); background: #FEF2F2; border: 1px solid #FCA5A5; }

/* ═══ 开方数量统计 ═══ */
.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid var(--border);
}
.stat-row:first-child { border-top: none; }
.stat-row.mine .stat-who { color: var(--blue, #1890FF); }
.stat-who {
  font-size: 14px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.stat-acct {
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
}
.stat-nums {
  display: flex;
  gap: 12px;
  flex: 0 0 auto;
}
.stat-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 34px;
}
.stat-cell b { font-size: 15px; font-weight: 700; line-height: 1.2; }
.stat-cell i {
  font-style: normal;
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 1px;
}

/* ═══ 门店选择 + 版本号 ═══ */
.store-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.store-row .chips {
  flex: 1 1 auto;
  min-width: 0;
}
.ver-tag {
  flex: 0 0 auto;
  font-size: 11px;
  line-height: 1;
  color: #9CA3AF;
  padding-top: 11px;
  white-space: nowrap;
  letter-spacing: 0.2px;
  user-select: none;
}

/* 环境标识（测试版 / 预发 等）
   只在设了 MOBILE_ENV_LABEL 的环境出现，正式环境这块 HTML 根本不会被替换出来 */
.env-badge {
  display: inline-block;
  vertical-align: middle;
  margin-left: 8px;
  padding: 2px 9px;
  border-radius: 999px;
  background: #FEF3C7;
  border: 1px solid #F59E0B;
  color: #B45309;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.6;
  letter-spacing: 0.5px;
  white-space: nowrap;
  user-select: none;
}
.store-row .env-badge {
  flex: 0 0 auto;
  margin: 8px 0 0 0;
}
#login-page .brand .env-badge {
  background: #F59E0B;
  border-color: #FBBF24;
  color: #fff;
  font-size: 12.5px;
  transform: translateY(-3px);
}
