:root {
  --primary: #15616d;
  --primary-light: #2a8a99;
  --primary-soft: #e7f1f2;
  --bg: #f4f7f8;
  --card: #fff;
  --text: #1f2933;
  --muted: #6b7785;
  --border: #e2e8ea;
  --danger: #c0392b;
  --success: #2e7d52;
  --shadow: 0 6px 24px rgba(21, 97, 109, .1);
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", -apple-system, "Helvetica Neue", sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
.hidden { display: none !important; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: 18px 20px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  box-shadow: var(--shadow);
}
.topbar-inner { max-width: 760px; margin: 0 auto; }
.hospital { font-size: 15px; letter-spacing: .5px; opacity: .92; }
.title { margin-top: 2px; font-size: 20px; font-weight: 700; }
.sub { margin-top: 3px; font-size: 12px; opacity: .8; }
.tabs { display: flex; gap: 8px; margin-top: 12px; }
.tab {
  flex: 1;
  padding: 9px 0;
  border: 1px solid rgba(255, 255, 255, .25);
  border-radius: 10px;
  color: #fff;
  background: rgba(255, 255, 255, .16);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: .2s;
}
.tab.active { color: var(--primary); background: #fff; }
.tab:focus-visible, .btn:focus-visible, .purpose-opt:focus-visible { outline: 3px solid rgba(255, 255, 255, .8); outline-offset: 2px; }

.wrap { max-width: 760px; margin: 0 auto; padding: 18px 16px 60px; }
.card {
  margin-bottom: 18px;
  padding: 22px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 4px; color: var(--primary); font-size: 17px; }
.card .hint { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.success-title { color: var(--success) !important; }
.disclaimer-box {
  max-height: 46vh;
  overflow: auto;
  padding: 16px;
  border: 1px solid #cfe3e6;
  border-radius: 10px;
  color: #26343a;
  background: var(--primary-soft);
  font-size: 14.5px;
  line-height: 1.85;
}
.disclaimer-box p { margin: 0 0 10px; }
.checks { margin: 16px 0 4px; }
.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fbfdfd;
  font-size: 14px;
  cursor: pointer;
}
.check input { flex: none; width: 18px; height: 18px; margin-top: 3px; accent-color: var(--primary); }
.btn {
  display: inline-block;
  width: 100%;
  padding: 13px 18px;
  border: 0;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: .15s;
}
.btn-primary { color: #fff; background: var(--primary); }
.btn-primary:hover { background: #114e58; }
.btn-primary:disabled { background: #b6c7ca; cursor: not-allowed; }
.btn-ghost { border: 1px solid var(--primary); color: var(--primary); background: #fff; }
.btn-soft { color: var(--primary); background: var(--primary-soft); }
.btn-row { display: flex; gap: 10px; margin-top: 6px; }
.btn-row .btn { flex: 1; width: auto; }
.top-gap { margin-top: 16px; }

.field { display: block; margin: 0 0 15px; }
.purpose-field { padding: 0; border: 0; }
.lb { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 600; }
.req { margin-left: 2px; color: var(--danger); }
.opt { margin-left: 4px; color: var(--muted); font-size: 12px; font-weight: 400; }
input[type="text"], input[type="tel"], input[type="password"], input[type="search"], input[type="datetime-local"], select, textarea {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: 0;
  color: var(--text);
  background: #fff;
  font-size: 15px;
  transition: .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(21, 97, 109, .12); }
textarea { min-height: 64px; resize: vertical; }
.err { display: none; margin-top: 5px; color: var(--danger); font-size: 12.5px; }
.field.invalid .err { display: block; }
.field.invalid input, .field.invalid select { border-color: var(--danger); }
.purpose-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.purpose-opt {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 48px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: #fff;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: .15s;
}
.purpose-opt .dot { flex: none; width: 16px; height: 16px; border: 2px solid var(--border); border-radius: 50%; }
.purpose-opt.sel { border-color: var(--primary); background: var(--primary-soft); }
.purpose-opt.sel .dot { border-color: var(--primary); background: var(--primary); box-shadow: inset 0 0 0 3px #fff; }
.purpose-opt.other { padding-right: 6px; }
.purpose-opt.other input { padding: 0; border: 0; outline: 0; background: transparent; box-shadow: none; font-size: 14px; }
.meta-line { margin-top: 10px; color: var(--muted); font-size: 12.5px; text-align: center; }
.note-policy { margin-top: 14px; color: var(--muted); font-size: 12px; line-height: 1.7; }
.note-policy b { color: var(--primary); }

.notify-box {
  margin: 8px 0 18px;
  padding: 14px 16px;
  border: 1px solid #bfe3cd;
  border-left: 5px solid var(--success);
  border-radius: 10px;
  color: #234d39;
  background: linear-gradient(135deg, #eafaf0 0%, #e7f1f2 100%);
  font-size: 14px;
  line-height: 1.8;
}
.notify-box .nt { display: block; margin-bottom: 6px; color: var(--success); font-size: 13px; font-weight: 700; letter-spacing: .5px; }
.receipt { padding: 20px; border: 2px dashed var(--primary-light); border-radius: 12px; background: #fcfefe; }
.receipt .rno { color: var(--primary); font-size: 22px; font-weight: 700; letter-spacing: 1px; }
.receipt .rrow { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px dashed #dbe7e9; font-size: 14.5px; }
.receipt .rrow:last-child { border-bottom: 0; }
.receipt .k { color: var(--muted); }
.receipt .v { max-width: 62%; font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.tag, .mode-badge { display: inline-block; padding: 2px 8px; border-radius: 20px; color: var(--primary); background: var(--primary-soft); font-size: 12px; }
.mode-badge { margin-left: 8px; vertical-align: middle; }
.mode-badge.off { color: var(--danger); background: #fbeae8; }

.qr-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 6px 0 2px; }
.qr-wrap img { width: 200px; height: 200px; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.qr-fallback { padding: 0 10px; color: var(--muted); font-size: 13px; text-align: center; word-break: break-all; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.share-toolbar { margin-top: 6px; }
.toolbar input { flex: 1; min-width: 160px; }
.toolbar .btn { flex: none; width: auto; padding: 11px 14px; font-size: 14px; }
.token-bar { display: flex; gap: 8px; margin-bottom: 12px; }
.token-button { flex: none; width: auto; padding: 9px 16px; font-size: 14px; }
.stat { margin-bottom: 12px; color: var(--muted); font-size: 13px; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { color: var(--muted); background: #fafcfc; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.row-actions button { padding: 5px 9px; border: 1px solid var(--border); border-radius: 8px; color: var(--primary); background: #fff; font-size: 12.5px; cursor: pointer; }
.row-actions .del { border-color: #f0d4d0; color: var(--danger); }
.empty { padding: 36px 0; color: var(--muted); font-size: 14px; text-align: center; }

.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  z-index: 60;
  max-width: 88%;
  padding: 12px 20px;
  border-radius: 10px;
  color: #fff;
  background: #26343a;
  font-size: 14px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(20px);
  transition: .25s;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.overlay { position: fixed; inset: 0; z-index: 50; display: none; align-items: flex-start; justify-content: center; overflow: auto; padding: 24px 14px; background: rgba(15, 40, 45, .55); }
.overlay.show { display: flex; }
.overlay .panel { width: 100%; max-width: 640px; margin: auto 0; padding: 24px 22px; border-radius: 16px; background: #fff; }
.overlay h2 { margin-top: 0; color: var(--primary); }
.overlay .disclaimer-box { max-height: 50vh; }
.overlay-close { margin-top: 16px; }
.print-area { display: none; }
/* 独立管理工作台 */
.admin-page { min-height: 100vh; background: #eef3f4; }
.admin-header {
  padding: 20px 28px;
  color: #fff;
  background: #124f59;
  box-shadow: 0 2px 16px rgba(15, 56, 64, .15);
}
.admin-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  max-width: 1180px;
  margin: 0 auto;
}
.public-link {
  padding: 9px 14px;
  border: 1px solid rgba(255, 255, 255, .38);
  border-radius: 9px;
  color: #fff;
  font-size: 13px;
  text-decoration: none;
}
.public-link:hover { background: rgba(255, 255, 255, .1); }
.admin-wrap { max-width: 1180px; margin: 0 auto; padding: 30px 24px 64px; }
.login-card {
  width: 100%;
  max-width: 430px;
  margin: 8vh auto 0;
  padding: 36px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(21, 74, 83, .12);
}
.lock-mark {
  display: grid;
  width: 46px;
  height: 46px;
  margin-bottom: 20px;
  place-items: center;
  border-radius: 12px;
  color: #fff;
  background: var(--primary);
  font-weight: 700;
}
.login-card h1 { margin: 0; color: var(--text); font-size: 24px; line-height: 1.35; }
.login-card > p { margin: 8px 0 24px; color: var(--muted); font-size: 14px; }
.login-error { margin: -4px 0 12px; color: var(--danger); font-size: 13px; }
.security-note { margin-top: 18px; color: var(--muted); font-size: 12px; text-align: center; }
.default-password-note { margin-top: 16px; padding: 9px 11px; border-radius: 8px; color: #765313; background: #fff7e6; font-size: 12px; text-align: center; }
.dashboard-titlebar { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.dashboard-titlebar h1 { margin: 0; font-size: 25px; line-height: 1.3; }
.dashboard-titlebar p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.logout-button { padding: 8px 12px; border: 1px solid #cbd8da; border-radius: 8px; color: var(--muted); background: transparent; cursor: pointer; }
.logout-button:hover { color: var(--danger); border-color: #e3bcb6; background: #fff; }
.admin-account-actions { display: flex; gap: 8px; }
.password-button { padding: 8px 12px; border: 1px solid #b9ced1; border-radius: 8px; color: var(--primary); background: #fff; cursor: pointer; }
.password-button:hover { border-color: var(--primary); background: var(--primary-soft); }
.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 20px; }
.metric-card {
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: #fff;
  box-shadow: 0 3px 14px rgba(21, 97, 109, .06);
}
.metric-card span { display: block; color: var(--muted); font-size: 13px; }
.metric-card strong { display: block; margin: 3px 0 0; color: var(--primary); font-size: 30px; line-height: 1.3; }
.metric-card small { color: #8b979e; font-size: 11px; }
.admin-card {
  margin-bottom: 20px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 3px 14px rgba(21, 97, 109, .06);
}
.admin-section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.admin-section-head h2, .share-panel h2 { margin: 0; color: var(--text); font-size: 18px; }
.admin-section-head p, .share-panel p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.live-badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 20px; color: var(--success); background: #eaf6ef; font-size: 12px; white-space: nowrap; }
.live-badge i { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.admin-toolbar { display: flex; gap: 10px; margin-bottom: 10px; }
.search-box { position: relative; flex: 1; }
.search-box span { position: absolute; top: 8px; left: 13px; color: var(--muted); font-size: 22px; line-height: 1; }
.search-box input { padding-left: 39px; }
.compact-btn { width: auto; padding: 11px 16px; font-size: 14px; white-space: nowrap; }
.record-summary { margin: 12px 0; color: var(--muted); font-size: 12.5px; }
.admin-table td strong, .admin-table td small { display: block; }
.admin-table td strong { color: var(--text); font-size: 13px; font-weight: 600; white-space: nowrap; }
.admin-table td small { margin-top: 2px; color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.admin-table td { padding-top: 13px; padding-bottom: 13px; }
.admin-table .tag { white-space: nowrap; }
.table-scroll .empty { display: flex; flex-direction: column; gap: 4px; }
.table-scroll .empty b { color: var(--text); font-weight: 600; }
.table-scroll .empty span { font-size: 12px; }
.share-panel { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 28px; }
.copy-row { display: flex; gap: 8px; max-width: 650px; margin-top: 18px; }
.admin-qr { width: 150px; min-height: 150px; }
.admin-qr img { display: block; width: 150px; height: 150px; border: 1px solid var(--border); border-radius: 10px; }
.password-dialog { width: calc(100% - 28px); max-width: 460px; padding: 0; border: 0; border-radius: 16px; color: var(--text); box-shadow: 0 24px 70px rgba(15, 40, 45, .25); }
.password-dialog::backdrop { background: rgba(15, 40, 45, .55); backdrop-filter: blur(2px); }
.password-dialog form { padding: 26px; }
.dialog-heading h2 { margin: 0; color: var(--text); font-size: 20px; }
.dialog-heading p { margin: 5px 0 20px; color: var(--muted); font-size: 13px; }
.password-hint { display: block; margin-top: 5px; color: var(--muted); font-size: 11.5px; }
.dialog-actions { display: flex; gap: 10px; margin-top: 20px; }
.dialog-actions .btn { flex: 1; }

@media (max-width: 520px) {
  .purpose-grid { grid-template-columns: 1fr; }
  .topbar .title { font-size: 18px; }
  .card { padding: 20px 16px; }
  .token-bar { flex-direction: column; }
  .token-button { width: 100%; }
  th:nth-child(4), td:nth-child(4) { display: none; }
  .admin-header { padding: 17px 18px; }
  .admin-header-inner { align-items: flex-start; }
  .admin-header .public-link { padding: 7px 9px; font-size: 11px; }
  .admin-wrap { padding: 20px 14px 48px; }
  .login-card { margin-top: 3vh; padding: 28px 20px; }
  .metric-grid { grid-template-columns: 1fr; gap: 10px; }
  .metric-card { padding: 15px 18px; }
  .metric-card strong { font-size: 25px; }
  .admin-card { padding: 18px 14px; }
  .admin-toolbar { flex-wrap: wrap; }
  .search-box { flex-basis: 100%; }
  .compact-btn { flex: 1; }
  .share-panel { grid-template-columns: 1fr; }
  .admin-qr { justify-self: center; }
  .dashboard-titlebar { align-items: flex-start; }
  .admin-account-actions { flex-direction: column; }
}

@media print {
  body * { visibility: hidden; }
  #printArea, #printArea * { visibility: visible; }
  #printArea { position: absolute; top: 0; left: 0; display: block; width: 100%; padding: 20px; }
}
