/* ==========================================================
   科室住院预约登记 —— 统一视觉规范（浅色 / 医疗蓝 / 移动优先）
   与既有量表类页面保持一致：卡片式、12px 圆角、主色 #0b63c5
   ========================================================== */

:root {
  --c-primary: #0b63c5;
  --c-primary-dark: #0a54a8;
  --c-primary-soft: #eef4fc;
  --c-bg: #f4f6f8;
  --c-card: #ffffff;
  --c-text: #1f2328;
  --c-text-2: #5b6570;
  --c-text-3: #8a939d;
  --c-border: #e3e8ee;
  --c-border-strong: #cfd7e0;
  --c-success: #1a7f37;
  --c-success-soft: #e8f5ec;
  --c-danger: #c0392b;
  --c-danger-soft: #fdecea;
  --c-warn: #b26a00;
  --c-warn-soft: #fdf3e3;
  --radius: 12px;
  --radius-sm: 9px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .16);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--c-bg);
  color: var(--c-text);
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 18px; font-weight: 600; }
h2 { font-size: 16px; font-weight: 600; }

.hidden { display: none !important; }

/* ---------------- 视图容器 ---------------- */
.view { max-width: 760px; margin: 0 auto; padding-bottom: calc(96px + var(--safe-bottom)); }

/* ---------------- 登录 ---------------- */
#view-login {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--c-card);
  border-radius: 16px; padding: 28px 22px; box-shadow: var(--shadow);
  text-align: center;
}
.login-logo {
  width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 14px;
  background: var(--c-primary); color: #fff; font-size: 30px; line-height: 56px; font-weight: 300;
}
.login-card h1 { margin-bottom: 4px; }
.login-sub { color: var(--c-text-2); font-size: 14px; margin-bottom: 20px; }
.login-tip { margin-top: 14px; font-size: 12px; color: var(--c-text-3); }

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(12px + var(--safe-top)) 14px 12px;
  background: var(--c-primary); color: #fff;
}
.topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar h1 { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.whoami {
  font-size: 13px; opacity: .95; max-width: 220px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sync-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #7ee2b8; flex: none;
  box-shadow: 0 0 0 3px rgba(126, 226, 184, .28);
}
.sync-dot.is-off { background: #ffd166; box-shadow: 0 0 0 3px rgba(255, 209, 102, .28); }
.sync-dot.is-down { background: #ff9f9f; box-shadow: 0 0 0 3px rgba(255, 159, 159, .28); }

/* ---------------- 菜单 ---------------- */
.menu {
  position: sticky; top: calc(52px + var(--safe-top)); z-index: 19;
  background: var(--c-card); border-bottom: 1px solid var(--c-border);
  box-shadow: var(--shadow);
}
.menu-item {
  display: block; width: 100%; text-align: left;
  padding: 13px 16px; border: none; border-bottom: 1px solid var(--c-border);
  background: var(--c-card); color: var(--c-text); font-size: 15px; cursor: pointer;
}
.menu-item:last-child { border-bottom: none; }
.menu-item:active { background: var(--c-primary-soft); }
.menu-item.danger { color: var(--c-danger); }

/* ---------------- 统计 ---------------- */
.stats { display: flex; gap: 10px; padding: 14px 14px 0; }
.stat {
  flex: 1; background: var(--c-card); border-radius: var(--radius);
  padding: 12px 8px; text-align: center; box-shadow: var(--shadow);
}
.stat b { display: block; font-size: 24px; font-weight: 650; color: var(--c-primary); line-height: 1.2; }
.stat span { font-size: 12px; color: var(--c-text-2); }

/* ---------------- 工具栏 ---------------- */
.toolbar { padding: 14px 14px 0; display: flex; flex-direction: column; gap: 8px; }
.toolbar-row { display: flex; gap: 8px; }
.toolbar-row > * { flex: 1; min-width: 0; }

.input {
  width: 100%; padding: 10px 12px; font-size: 16px; font-family: inherit;
  border: 1px solid var(--c-border-strong); border-radius: var(--radius-sm);
  background: var(--c-card); color: var(--c-text); outline: none;
}
.input:focus { border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(11, 99, 197, .12); }
select.input { appearance: none; background-image: none; }
textarea.input { resize: vertical; min-height: 56px; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--c-text-2); margin-bottom: 5px; }
.field-row { display: flex; gap: 10px; }
.field-row > .field { flex: 1; min-width: 0; }
.req { color: var(--c-danger); font-weight: 700; }

/* ---------------- 标签页 ---------------- */
.tabs {
  display: flex; gap: 6px; padding: 14px 14px 0;
  overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; padding: 8px 16px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--c-border-strong); background: var(--c-card);
  color: var(--c-text-2); font-size: 14px; font-family: inherit;
}
.tab.is-active { background: var(--c-primary); border-color: var(--c-primary); color: #fff; font-weight: 600; }

/* ---------------- 列表与卡片 ---------------- */
.list { padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--c-card); border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow); border: 1px solid transparent;
}
.item { position: relative; }
.item.is-emergency { border-left: 4px solid #d1242f; }
.item.is-urgent { border-left: 4px solid #d98324; }
.item.is-admitted { background: #f7f9fb; }

.item-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.item-name { font-size: 17px; font-weight: 600; }
.item-name .meta { font-size: 13px; font-weight: 400; color: var(--c-text-2); margin-left: 8px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.chip {
  font-size: 12px; padding: 2px 9px; border-radius: 999px;
  background: var(--c-primary-soft); color: var(--c-primary); border: 1px solid transparent;
}
.chip.ward { background: #eef7f0; color: var(--c-success); }
.chip.bed { background: #f3f0fb; color: #5b3fbf; }
.chip.date { background: #fff6e5; color: var(--c-warn); }
.chip.emergency { background: var(--c-danger-soft); color: var(--c-danger); font-weight: 600; }
.chip.urgent { background: var(--c-warn-soft); color: var(--c-warn); font-weight: 600; }

.kv { display: grid; grid-template-columns: 68px 1fr; gap: 3px 8px; font-size: 14px; }
.kv dt { color: var(--c-text-3); }
.kv dd { color: var(--c-text); word-break: break-all; }
.kv dd.mono { font-variant-numeric: tabular-nums; }

.phone-line { display: flex; align-items: center; gap: 8px; }
.link-btn {
  border: none; background: none; color: var(--c-primary); font-size: 13px;
  cursor: pointer; padding: 0; text-decoration: underline; font-family: inherit;
}
.item-foot {
  margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--c-border);
  font-size: 12px; color: var(--c-text-3); display: flex; flex-wrap: wrap; gap: 4px 12px;
}
.item-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.item-actions .btn { flex: 1 1 calc(50% - 4px); min-width: 104px; }

.empty { text-align: center; color: var(--c-text-3); padding: 40px 20px; font-size: 14px; }
.hint { font-size: 12px; color: var(--c-text-3); margin-top: 8px; }
.err { color: var(--c-danger); font-size: 13px; margin: 4px 0 8px; }
.ok { color: var(--c-success); font-size: 13px; margin: 8px 0; }

/* ---------------- 按钮 ---------------- */
.btn {
  padding: 10px 14px; border: none; border-radius: var(--radius-sm);
  font-size: 15px; font-family: inherit; font-weight: 500; cursor: pointer;
  background: var(--c-border); color: var(--c-text);
  transition: filter .15s ease;
}
.btn:active { filter: brightness(.94); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--c-primary); color: #fff; }
.btn-secondary { background: var(--c-primary-soft); color: var(--c-primary); border: 1px solid #cfe0f5; }
.btn-success { background: var(--c-success); color: #fff; }
.btn-danger { background: var(--c-danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--c-text-2); border: 1px solid var(--c-border-strong); }
.topbar .btn-ghost, #btn-back {
  color: #fff; border-color: rgba(255, 255, 255, .5); background: rgba(255, 255, 255, .14);
}
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-block { display: block; width: 100%; }

/* ---------------- 浮动按钮 ---------------- */
.fab {
  position: fixed; right: 18px; bottom: calc(24px + var(--safe-bottom)); z-index: 30;
  width: 56px; height: 56px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--c-primary); color: #fff; font-size: 30px; font-weight: 300; line-height: 1;
  box-shadow: 0 6px 20px rgba(11, 99, 197, .38);
}

/* ---------------- 弹窗 ---------------- */
.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.modal-mask { position: absolute; inset: 0; background: rgba(16, 24, 40, .45); }
.modal-panel {
  position: relative; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--c-card); border-radius: 16px 16px 0 0; padding: 16px;
  box-shadow: var(--shadow-lg); animation: slide-up .18s ease-out;
}
.modal-sm { max-width: 420px; }
@keyframes slide-up { from { transform: translateY(24px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--c-border);
}
.modal-close { border: none; background: none; font-size: 26px; line-height: 1; color: var(--c-text-3); cursor: pointer; }
.modal-body { margin-bottom: 8px; }
.modal-actions { display: flex; gap: 10px; margin-top: 12px; }
.modal-actions .btn { flex: 1; }

/* ---------------- 管理后台 ---------------- */
.admin-pane { padding: 12px 14px; display: flex; flex-direction: column; gap: 12px; }
.admin-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.admin-row .who { font-size: 15px; font-weight: 600; }
.admin-row .sub { font-size: 12px; color: var(--c-text-3); }
.role-tag { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--c-primary-soft); color: var(--c-primary); }
.role-tag.admin { background: var(--c-danger-soft); color: var(--c-danger); }
.role-tag.viewer { background: #f0f2f5; color: var(--c-text-2); }
.role-tag.disabled { background: #f0f2f5; color: var(--c-text-3); text-decoration: line-through; }

.log-item { padding: 10px 0; border-bottom: 1px solid var(--c-border); font-size: 13px; }
.log-item:last-child { border-bottom: none; }
.log-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.log-action { font-weight: 600; }
.log-meta { color: var(--c-text-3); font-size: 12px; }
.log-detail { color: var(--c-text-2); word-break: break-all; margin-top: 2px; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 5px; }
.badge.denied { background: var(--c-danger-soft); color: var(--c-danger); }
.badge.failure { background: var(--c-warn-soft); color: var(--c-warn); }
.badge.success { background: var(--c-success-soft); color: var(--c-success); }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(80px + var(--safe-bottom)); z-index: 90;
  max-width: 84vw; padding: 10px 18px; border-radius: 999px;
  background: rgba(24, 32, 44, .92); color: #fff; font-size: 14px; text-align: center;
  box-shadow: var(--shadow-lg);
}
.toast.is-error { background: rgba(192, 57, 43, .95); }

/* ---------------- 桌面端适配（27" 4K 显示器） ---------------- */
@media (min-width: 900px) {
  body { font-size: 16px; }
  .view { max-width: 860px; }
  .modal { align-items: center; }
  .modal-panel { border-radius: 16px; }
  .item-actions .btn { flex: 0 1 auto; min-width: 116px; }
  .fab { right: calc(50vw - 430px + 18px); }
}

@media print {
  .topbar, .menu, .toolbar, .tabs, .fab, .item-actions { display: none !important; }
}

/* ================= v2 新增 ================= */

/* 统计卡可点击 */
.stat-link { border: 0; background: transparent; font: inherit; color: inherit; cursor: pointer; }
.stat-link:active { transform: scale(.98); }

/* 病区待入院分布 */
.wardbar { display: flex; gap: 8px; overflow-x: auto; padding: 0 14px 10px; scrollbar-width: none; }
.wardbar::-webkit-scrollbar { display: none; }
.wardbar[hidden] { display: none; }
.ward-chip {
  flex: 0 0 auto; padding: 5px 10px; border-radius: 999px; font-size: 12px;
  border: 1px solid var(--c-border-strong); background: #fff; color: var(--c-text-2); cursor: pointer;
}
.ward-chip.is-active { background: var(--c-primary-soft); border-color: var(--c-primary); color: var(--c-primary); }

/* 筛选行内复选框 */
.check-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--c-text-2); white-space: nowrap; }

/* 列表头部 */
.list-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 14px 6px; }
.list-count { font-size: 12px; color: var(--c-text-3); }
.list-head-right { display: flex; gap: 8px; }

/* 加载更多 */
.load-more { margin: 10px 14px 0; width: calc(100% - 28px); }

/* 状态标签配色 */
.chip.status-wait { background: var(--c-primary-soft); color: var(--c-primary-dark); }
.chip.status-admitted { background: var(--c-success-soft); color: var(--c-success); }
.chip.status-cancelled { background: #f0f2f5; color: var(--c-text-3); }
.chip.status-deleted { background: var(--c-danger-soft); color: var(--c-danger); }
.chip.source { background: #f5f3ff; color: #5b21b6; }
.chip.overdue { background: var(--c-danger-soft); color: var(--c-danger); font-weight: 600; }
.chip.date.is-overdue { background: var(--c-danger-soft); color: var(--c-danger); }

.card.is-cancelled { opacity: .72; }

/* 批量选择 */
.item-name .pick { width: 18px; height: 18px; margin-right: 8px; accent-color: var(--c-primary); }
.list.is-selecting .item { border-color: var(--c-primary); }

/* 表单小字提示 */
.field-hint { font-size: 11px; color: var(--c-text-3); font-weight: 400; }
.check-line { flex-direction: row; align-items: center; gap: 8px; font-size: 13px; color: var(--c-text-2); }
.check-line input { width: 16px; height: 16px; accent-color: var(--c-danger); }

/* 卡片底部操作记录入口 */
.item-links { display: flex; justify-content: flex-end; padding-top: 6px; }
.item-links .link-btn { font-size: 12px; color: var(--c-text-3); }

/* 时间线 */
.timeline-item { padding: 10px 0; border-bottom: 1px dashed var(--c-border); }
.timeline-item:last-child { border-bottom: 0; }
.timeline-top { display: flex; align-items: center; gap: 8px; }
.timeline-action { font-weight: 600; font-size: 14px; }

/* 预格式文本（确认弹窗说明） */
.pre-wrap { white-space: pre-wrap; }

/* 打印：只输出列表 */
@media print {
  body { background: #fff; }
  body.printing .topbar, body.printing .stats, body.printing .wardbar, body.printing .toolbar,
  body.printing .tabs, body.printing .list-head, body.printing .fab, body.printing .item-actions,
  body.printing .item-links, body.printing .load-more, body.printing #menu, body.printing .toast { display: none !important; }
  body.printing .list { padding: 0; }
  body.printing .card.item { break-inside: avoid; box-shadow: none; border: 1px solid #ccc; margin-bottom: 8px; }
  body.printing .view { max-width: none; padding: 0; }
}
