:root {
  --red: #c41a1a;
  --red-deep: #8b1010;
  --red-soft: #f8e6e6;
  --gold: #d4af37;
  --gold-bright: #f3d27a;
  --ink: #3b1d1d;
  --paper: #fff8f0;
  --card: #fffdf9;
  --muted: #8a6a6a;
  --line: #f0d4c4;
  --ok: #2f7d4a;
  --shadow: 0 12px 32px rgba(139, 16, 16, 0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 12% 8%, rgba(243, 210, 122, 0.28), transparent 28%),
    radial-gradient(circle at 90% 0%, rgba(196, 26, 26, 0.18), transparent 32%),
    linear-gradient(180deg, #fff4ea 0%, var(--paper) 40%, #ffe9dc 100%);
  color: var(--ink);
  font-family: "Songti SC", "Noto Serif SC", "Source Han Serif SC", "PingFang SC", serif;
}

button, a, input, select, textarea { touch-action: manipulation; }

#app { max-width: 1180px; margin: 0 auto; padding: 24px 20px 48px; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.seal {
  width: 56px;
  height: 56px;
  border: 3px solid var(--red);
  color: var(--red);
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 700;
  transform: rotate(-8deg);
  background: #fff;
  box-shadow: 2px 2px 0 var(--gold);
}

.brand h1 {
  font-size: 28px;
  letter-spacing: 4px;
  color: var(--red-deep);
}

.brand p { color: var(--muted); font-size: 13px; margin-top: 4px; letter-spacing: 2px; }

.nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  background: rgba(255, 253, 249, 0.86);
  padding: 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
}

.nav button {
  border: 0;
  background: transparent;
  color: var(--red-deep);
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
}

.nav button.active {
  background: linear-gradient(180deg, var(--red) 0%, var(--red-deep) 100%);
  color: #fff8e7;
  box-shadow: 0 6px 16px rgba(196, 26, 26, 0.28);
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.grid-4, .grid-2 { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); margin-bottom: 16px; }
.grid-2 { grid-template-columns: 1.2fr 0.8fr; gap: 16px; }

.stat {
  padding: 18px;
  border-radius: 16px;
  background: linear-gradient(160deg, #fff 0%, #fff4ea 100%);
  border: 1px solid var(--line);
}

.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; margin-top: 8px; color: var(--red-deep); font-weight: 700; }
.stat .hint { font-size: 12px; color: var(--gold); margin-top: 6px; }
.stat.clickable { cursor: pointer; }
.stat.clickable:active { transform: translateY(1px); }

.nav button.ghost-nav { color: var(--muted); }
.logout-mobile { display: none; margin-left: auto; }
.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
}
.item-row .item-meta { margin-top: 0; flex: 1; min-width: 0; }
.item-row .item-actions { margin-top: 0; flex-shrink: 0; }

.login-page {
  min-height: calc(100dvh - 48px);
  display: grid;
  place-items: center;
  padding: 24px 12px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--gold);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow);
}
.login-card .brand { margin-bottom: 18px; }
.captcha-row {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 10px;
  align-items: end;
}
.captcha-img {
  width: 120px;
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--line);
  cursor: pointer;
  object-fit: cover;
  background: #fff8f0;
}
.login-actions { justify-content: stretch; margin-top: 18px; }
.login-actions .btn { width: 100%; min-height: 44px; }
.login-hint { margin-top: 12px; font-size: 12px; }

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  align-items: center;
}

.filters { display: flex; gap: 8px; flex-wrap: wrap; }

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

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

textarea { width: 100%; min-height: 72px; resize: vertical; }

.btn {
  border: 0;
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  background: linear-gradient(180deg, var(--red) 0%, var(--red-deep) 100%);
  color: #fff8e7;
}

.btn.ghost {
  background: #fff;
  color: var(--red);
  border: 1px solid var(--red);
}

.btn.gold {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: var(--red-deep);
}

.btn.tiny { padding: 4px 8px; font-size: 12px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); font-size: 14px; }
th { color: var(--muted); font-weight: 600; }
.amount { font-variant-numeric: tabular-nums; font-weight: 700; }
.give { color: var(--red); }
.receive { color: var(--ok); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--red-soft);
  color: var(--red-deep);
}

.badge.ok { background: #e7f6ec; color: var(--ok); }
.badge.warn { background: #fff1d6; color: #9a6b00; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; color: var(--muted); }

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(80, 16, 16, 0.35);
  display: grid;
  place-items: center;
  z-index: 80;
}

.modal {
  width: min(560px, 92vw);
  background: #fffdf9;
  border-radius: 18px;
  padding: 22px;
  border: 1px solid var(--gold);
  display: flex;
  flex-direction: column;
  max-height: min(88vh, 720px);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.modal-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-height: 0;
  padding-bottom: 8px;
}

.modal h3 { color: var(--red-deep); letter-spacing: 2px; margin: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-actions {
  flex-shrink: 0;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.chart { height: 320px; }
.muted { color: var(--muted); }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.mobile-list { display: none; }
.bottom-nav { display: none; }
.item-card {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.item-card:last-child { border-bottom: 0; }
.item-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.item-meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.item-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: nowrap; white-space: nowrap; }
.stats-filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

.toast {
  position: fixed;
  right: 20px;
  top: 20px;
  background: var(--red-deep);
  color: #fff8e7;
  padding: 10px 14px;
  border-radius: 10px;
  z-index: 30;
}

@media (max-width: 860px) {
  html { -webkit-text-size-adjust: 100%; }
  #app { padding: 12px 12px calc(76px + env(safe-area-inset-bottom)); }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .grid-2, .form-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 8px; margin-bottom: 12px; }
  .brand { gap: 10px; width: 100%; }
  .brand h1 { font-size: 20px; letter-spacing: 2px; }
  .brand p { font-size: 12px; }
  .seal { width: 44px; height: 44px; font-size: 22px; }
  .nav { display: none; }
  .logout-mobile { display: inline-flex; align-items: center; }
  .card { padding: 14px; border-radius: 14px; }
  .stat { padding: 12px; }
  .stat .value { font-size: 20px; }
  .toolbar { align-items: stretch; }
  .filters, .stats-filters { width: 100%; }
  .filters > *, .stats-filters > * { flex: 1 1 calc(50% - 8px); min-width: 0; }
  input, select, textarea {
    width: 100%;
    min-width: 0;
    font-size: 16px;
    min-height: 42px;
  }
  .btn { min-height: 42px; padding: 10px 14px; }
  .btn.tiny { min-height: 32px; padding: 4px 10px; font-size: 13px; }
  .item-row { flex-wrap: nowrap; }
  .item-row .item-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .captcha-row { grid-template-columns: 1fr 110px; }
  .desktop-table { display: none; }
  .mobile-list { display: block; }
  .chart { height: 240px; }
  .modal-mask {
    place-items: stretch;
    padding: 0;
    align-items: stretch;
  }
  .modal {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    padding: calc(12px + env(safe-area-inset-top)) 16px 0;
  }
  .modal-body {
    padding-bottom: 8px;
  }
  .modal-actions {
    flex-shrink: 0;
    margin: 0 -16px 0;
    padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
    background: #fffdf9;
    border-top: 1px solid var(--line);
  }
  .modal-actions .btn { flex: 1; min-height: 48px; }
  .toast {
    left: 12px;
    right: 12px;
    top: auto;
    bottom: calc(72px + env(safe-area-inset-bottom));
    z-index: 90;
  }
  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    background: rgba(255, 253, 249, 0.96);
    border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around;
  }
  .bottom-nav button {
    flex: 1;
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 8px 0;
    font-size: 12px;
    min-height: 48px;
  }
  .bottom-nav button.active { color: var(--red); font-weight: 700; }
}
