:root {
  --teal: #0f9d9d;
  --teal-d: #0b7c7c;
  --bg: #f4f7f8;
  --card: #ffffff;
  --ink: #1f2d2d;
  --muted: #8a9a9a;
  --line: #e6edee;
  --danger: #e5484d;
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.topbar {
  background: linear-gradient(135deg, var(--teal), #14b8b0);
  color: #fff;
  padding: 22px 18px 18px;
}
.topbar h1 { margin: 0; font-size: 22px; font-weight: 700; }
.topbar .sub { margin: 4px 0 0; font-size: 13px; opacity: 0.9; }

.banner {
  margin: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  background: #fff4e5;
  color: #9a5b00;
  font-size: 13px;
  border: 1px solid #ffd8a8;
}

.card {
  background: var(--card);
  margin: 12px;
  padding: 16px;
  border-radius: 14px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.04);
}
.card-title {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 700;
  color: var(--teal-d);
  border-left: 4px solid var(--teal);
  padding-left: 8px;
}

/* 一句话录入 */
.sentence { background: #f0f9f9; border: 1px solid #d4efef; border-radius: 12px; padding: 10px; margin-bottom: 14px; }
.sentence-row { display: flex; gap: 8px; align-items: flex-start; }
.sentence-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.echo { font-size: 13px; color: var(--teal-d); flex: 1; }

.mic-btn {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--teal);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
}
.mic-btn.recording { background: var(--danger); animation: pulse 1s infinite; }
.mic-btn:disabled { background: #b9c6c6; cursor: not-allowed; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.12); } }
.rec-box { display: flex; align-items: center; gap: 10px; margin-top: 10px; padding: 10px 12px; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.wave { display: flex; align-items: flex-end; gap: 2px; height: 40px; flex: 1; overflow: hidden; }
.wbar { width: 3px; min-height: 4px; background: var(--teal); border-radius: 2px; height: 4px; transition: height 0.08s linear; }
.rec-status { font-size: 13px; color: var(--teal-d); white-space: nowrap; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--teal); border-radius: 50%; animation: spin 0.7s linear infinite; flex: 0 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 表单 */
.form-row { margin-bottom: 12px; }
.lbl { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.inp, .ta {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15px;
  background: #fafcfc;
  color: var(--ink);
  outline: none;
}
.inp:focus, .ta:focus { border-color: var(--teal); background: #fff; }
.ta { resize: vertical; font-family: inherit; }

/* 风险 chips */
.risk-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.risk-chip {
  position: relative;
  padding: 8px 26px 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}
.risk-chip.on { color: #fff; border-color: transparent; font-weight: 600; }
.chip-del {
  position: absolute; top: 50%; right: 7px; transform: translateY(-50%);
  width: 16px; height: 16px; line-height: 14px; text-align: center;
  border-radius: 50%; color: #aaa; font-size: 15px; cursor: pointer;
}
.chip-del:hover { color: #fff; background: #e5484d; }
.risk-chip.on .chip-del { color: rgba(255,255,255,.85); }
.risk-chip.on .chip-del:hover { color: #fff; background: rgba(0,0,0,.28); }
.add-chip {
  border-style: dashed; color: var(--muted); padding: 8px 14px;
}
.add-chip:hover { border-color: var(--teal); color: var(--teal); }

/* 按钮 */
.actions { display: flex; gap: 10px; }
.btn-primary {
  flex: 1;
  background: var(--teal);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 13px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:active { background: var(--teal-d); }
.btn-ghost {
  background: #eef3f3;
  color: var(--teal-d);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px 16px;
  font-size: 15px;
  cursor: pointer;
}
.btn-warn {
  background: #fdecec; color: var(--danger);
  border: 1px solid #f7c5c5; border-radius: 8px;
  padding: 7px 12px; font-size: 13px; cursor: pointer;
}
.btn-edit {
  background: #e8f5f5; color: var(--teal-d);
  border: 1px solid #c8e7e7; border-radius: 8px;
  padding: 7px 12px; font-size: 13px; cursor: pointer;
}

/* 统计卡 */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.stat {
  background: #f6fafa;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
}
.stat .num { font-size: 22px; font-weight: 700; }
.stat .cap { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.all .num { color: var(--teal); }
.stat.total { grid-column: span 3; background: var(--teal); border-color: var(--teal); }
.stat.total .num, .stat.total .cap { color: #fff; }

/* 患者列表 */
.patient-list { display: flex; flex-direction: column; gap: 10px; }
.prow {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.pinfo { min-width: 0; }
.pbed { font-weight: 700; color: var(--teal-d); margin-right: 6px; }
.pname { font-weight: 600; }
.ptags { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 5px; }
.ptag { font-size: 11px; color: #fff; padding: 2px 8px; border-radius: 999px; }
.pnote { font-size: 12px; color: var(--muted); margin-top: 6px; }
.pops { display: flex; flex-direction: column; gap: 6px; flex: 0 0 auto; }
.empty { text-align: center; color: var(--muted); padding: 24px 0; font-size: 14px; }

/* 弹层 */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none !important; }
.modal-mask { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }
.modal-panel {
  position: relative;
  width: 100%;
  max-width: 560px;
  background: #fff;
  border-radius: 16px 16px 0 0;
  max-height: 80vh;
  overflow: auto;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; }
.modal-title { font-size: 16px; font-weight: 700; color: var(--teal-d); }
.modal-close { border: none; background: none; font-size: 24px; color: var(--muted); cursor: pointer; line-height: 1; }
.modal-body { padding: 8px 16px 24px; }
.drow { padding: 12px 0; border-bottom: 1px solid var(--line); }
.drow:last-child { border-bottom: none; }
.dname { font-weight: 700; font-size: 15px; }
.dmeta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.dnote { font-size: 13px; margin-top: 6px; color: #444; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 16px; }
.foot .beian { color: var(--muted); text-decoration: none; }
.foot .beian:hover { color: #666; text-decoration: underline; }

/* ===== 登录 / 初始化遮罩 ===== */
.login-modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f9d9d, #14b8b0);
  padding: 20px;
}
.login-modal[hidden] { display: none !important; }
.login-card {
  width: 100%; max-width: 360px;
  background: #fff; border-radius: 16px; padding: 28px 24px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.18);
}
.login-title { margin: 0 0 18px; font-size: 19px; font-weight: 700; color: var(--teal-d); text-align: center; }
.login-sub { font-size: 13px; color: var(--muted); margin: 0 0 12px; text-align: center; }
.login-form .inp { margin-bottom: 12px; }
.login-form .btn-primary { width: 100%; margin-top: 4px; }
.login-err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 16px; text-align: center; }

/* ===== 顶栏（用户 / 病区 / 管理） ===== */
.topbar-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.topbar-titles { min-width: 0; flex: 1; min-width: 0; }
.topbar-user { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.me-wrap { position: relative; }
.me-box {
  font-size: 15px; color: #fff; background: rgba(255,255,255,0.18);
  padding: 6px 14px; border-radius: 999px; white-space: nowrap;
  cursor: pointer; user-select: none; font-weight: 600;
}
.me-box:hover { background: rgba(255,255,255,0.3); }
.me-box::after { content: ' ▾'; font-size: 13px; opacity: 0.85; }
.me-menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 60;
  min-width: 132px; background: #fff; border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.18); overflow: hidden;
  display: flex; flex-direction: column;
}
.me-menu[hidden] { display: none; }
.me-menu-item {
  text-align: left; background: none; border: none; cursor: pointer;
  padding: 13px 16px; font-size: 16px; color: var(--ink); white-space: nowrap;
}
.me-menu-item + .me-menu-item { border-top: 1px solid var(--line); }
.me-menu-item:hover { background: #f0f9f9; color: var(--teal-d); }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.ward-select {
  font-size: 15px; padding: 6px 10px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.5);
  background: rgba(255,255,255,0.95); color: var(--ink); max-width: 120px;
}
.btn-mini {
  font-size: 15px; padding: 6px 14px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.55);
  background: rgba(255,255,255,0.15); color: #fff; cursor: pointer; white-space: nowrap; font-weight: 600;
}
.btn-mini:hover { background: rgba(255,255,255,0.28); }

/* 手机端顶栏适配 */
@media (max-width: 600px) {
  .topbar { padding: 14px 12px 12px; }
  .topbar h1 { font-size: 19px; }
  .topbar .sub { display: none; }
  .topbar-user { flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
  .me-box { font-size: 14px; padding: 6px 12px; }
  .btn-mini { font-size: 14px; padding: 6px 12px; }
  .ward-select { font-size: 14px; padding: 5px 9px; max-width: 108px; }
}

/* 患者列表：病区分组标签（全部视图） */
.pward {
  display: inline-block; font-size: 11px; color: #fff; background: #0f9d9d;
  padding: 1px 8px; border-radius: 999px; margin-right: 6px; vertical-align: middle;
}

/* ===== 管理弹层 ===== */
.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tab {
  flex: 1; padding: 10px; border: 1px solid var(--line); background: #f6fafa;
  border-radius: 10px; font-size: 14px; cursor: pointer; color: var(--muted);
}
.tab.on { background: var(--teal); color: #fff; border-color: var(--teal); font-weight: 600; }
.add-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.add-row .inp { flex: 1; min-width: 120px; margin-bottom: 0; }
.add-row .btn-mini { background: var(--teal); border-color: var(--teal); }
.add-row.user-form .inp { flex: 1 1 120px; }
.pw-form { flex-direction: column; }
.pw-form .inp { flex: 1 1 auto; width: 100%; }
.pw-form .btn-mini { align-self: flex-end; }
.mgmt-list { display: flex; flex-direction: column; gap: 8px; }
.mgmt-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 14px;
}
.mgmt-row .btn-warn { flex: 0 0 auto; }

