:root {
  color-scheme: light;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  --bg: #f4f6f3;
  --panel: #ffffff;
  --ink: #1f2522;
  --muted: #69716b;
  --line: #dfe5dc;
  --primary: #1e6d61;
  --primary-dark: #15564c;
  --accent: #b86435;
  --danger: #b42318;
  --ok: #157a5e;
  --pending: #9a650f;
  --shadow: 0 12px 32px rgba(31, 37, 34, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  padding-bottom: calc(78px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 10px 14px 12px;
  background: rgba(244, 246, 243, 0.94);
  backdrop-filter: blur(14px);
}

.brand-area {
  width: min(1040px, 100%);
  margin: 0 auto;
}

.banner-home-button {
  display: block;
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  text-align: left;
}

.hospital-banner {
  display: block;
  width: 100%;
  max-height: 76px;
  object-fit: contain;
  object-position: left center;
  border-radius: 8px;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 2px;
  font-size: 25px;
  line-height: 1.2;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
}

h3 {
  margin-bottom: 4px;
  font-size: 16px;
}

.user-line,
.form-hint,
.meta,
.subtle {
  color: var(--muted);
  font-size: 12px;
}

.top-actions {
  display: grid;
  justify-items: end;
  gap: 4px;
}

.sync-pill {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.sync-pill.ok {
  background: #e5f4ef;
  color: var(--ok);
}

.sync-pill.error {
  background: #fde8e5;
  color: var(--danger);
}

.main {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: 8px 14px 24px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.hero-card,
.stats-grid article,
.balance-card,
.record-card,
.member-card,
.mobile-form,
.filter-card,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.hero-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  margin-bottom: 14px;
}

.hero-card span,
.stats-grid span {
  color: var(--muted);
  font-size: 12px;
}

.hero-card strong {
  display: block;
  margin-top: 7px;
  font-size: 34px;
  line-height: 1;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.stats-grid article {
  min-height: 74px;
  padding: 13px;
}

.stats-grid strong {
  display: block;
  margin-top: 7px;
  font-size: 18px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 2px 10px;
}

.card-list {
  display: grid;
  gap: 10px;
}

.balance-card,
.record-card,
.member-card {
  padding: 14px;
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.person-name {
  font-size: 17px;
  font-weight: 850;
}

.balance-value {
  text-align: right;
  font-size: 20px;
  font-weight: 900;
}

.compact-balance-card {
  display: grid;
  gap: 12px;
}

.member-link {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
  font-size: 17px;
  font-weight: 850;
  text-align: left;
  text-decoration: underline;
  text-decoration-color: rgba(30, 109, 97, 0.28);
  text-underline-offset: 4px;
}

.balance-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 11px;
}

.pending-link,
.pending-text {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border-radius: 999px;
  padding: 0 10px;
  background: #fff1d6;
  color: var(--pending);
  font-size: 13px;
  font-weight: 850;
  text-decoration: none;
}

.small-text-button {
  font-size: 13px;
  white-space: nowrap;
}

.card-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.card-metrics div {
  border-radius: 8px;
  padding: 9px;
  background: #f7f8f5;
}

.card-metrics span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
}

.amount-add {
  color: var(--ok);
  font-weight: 850;
}

.amount-deduct {
  color: var(--danger);
  font-weight: 850;
}

.back-button {
  margin: 2px 0 10px;
}

.member-detail-hero {
  align-items: flex-start;
}

.detail-balance {
  text-align: right;
}

.detail-balance span {
  color: var(--muted);
  font-size: 12px;
}

.detail-balance strong {
  display: block;
  margin-top: 7px;
  font-size: 22px;
}

.detail-summary {
  margin-top: 12px;
}

.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-radius: 8px;
  padding: 12px;
  background: #f7f8f5;
}

.summary-row span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.summary-row strong {
  font-size: 20px;
}

.ledger-card h3 {
  margin-bottom: 4px;
}

.link-button {
  display: grid;
  place-items: center;
  text-decoration: none;
}

.mobile-form,
.filter-card {
  display: grid;
  gap: 13px;
  padding: 14px;
  margin-bottom: 14px;
}

.batch-form {
  max-width: none;
}

.period-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f7f8f5;
  color: var(--primary-dark);
  font-weight: 850;
}

.batch-toolbar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.batch-list {
  display: grid;
  gap: 10px;
}

.batch-row {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.batch-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.batch-row-head label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.batch-row-head input {
  width: 20px;
  min-height: 20px;
}

.batch-fields {
  display: grid;
  grid-template-columns: minmax(86px, 0.8fr) minmax(86px, 0.8fr) minmax(140px, 1.4fr);
  gap: 8px;
}

.link-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.link-card textarea {
  margin-top: 8px;
}

.qr-box {
  display: grid;
  place-items: center;
  min-height: 196px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
}

.qr-box img,
.qr-box canvas {
  width: 180px;
  height: 180px;
}

.compact-qr {
  min-height: 156px;
}

.compact-qr img,
.compact-qr canvas {
  width: 140px;
  height: 140px;
}

#confirmPasswordForm {
  display: grid;
  gap: 13px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.check-row input {
  width: 20px;
  min-height: 20px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.segmented label {
  display: block;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  place-items: center;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.segmented input:checked + span {
  border-color: var(--primary);
  background: #e5f4ef;
  color: var(--primary-dark);
  font-weight: 850;
}

.primary-button,
.secondary-button,
.danger-button,
.text-button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 850;
}

.primary-button {
  background: var(--primary);
  color: #fff;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.secondary-button {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.danger-button {
  background: #fff;
  color: var(--danger);
  border-color: #f0c7c2;
}

.text-button {
  min-height: 30px;
  padding: 0;
  background: transparent;
  color: var(--primary);
}

.wide-button {
  width: 100%;
}

.record-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 850;
}

.badge.confirmed {
  background: #e4f3ee;
  color: var(--ok);
}

.badge.waiting_member {
  background: #fff1d6;
  color: var(--pending);
}

.record-actions,
.member-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.record-actions.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.empty-state {
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 2px;
  padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
}

.bottom-nav.member-nav {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.nav-item {
  display: grid;
  place-items: center;
  gap: 3px;
  min-height: 54px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.nav-item span {
  font-size: 18px;
  line-height: 1;
}

.nav-item.active {
  background: #e5f4ef;
  color: var(--primary-dark);
}

@media (min-width: 760px) {
  .app-shell {
    padding-bottom: 0;
  }

  .topbar {
    padding: 14px 28px 16px;
  }

  .hospital-banner {
    max-height: 96px;
  }

  .title-row {
    margin-top: 10px;
  }

  .main {
    padding: 16px 28px 120px;
  }

  .bottom-nav {
    left: 50%;
    right: auto;
    bottom: 18px;
    width: min(720px, calc(100% - 36px));
    transform: translateX(-50%);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
  }

  .card-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-card {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .mobile-form {
    max-width: 680px;
    margin: 0 auto 14px;
  }

  .batch-form {
    max-width: 1040px;
  }
}

@media (max-width: 520px) {
  .topbar {
    padding: 8px 10px 10px;
  }

  .hospital-banner {
    max-height: 54px;
  }

  .title-row {
    gap: 8px;
    margin-top: 7px;
  }

  h1 {
    font-size: 21px;
  }

  .batch-fields {
    grid-template-columns: 1fr;
  }
}
