:root {
  --primary: #0f9d8a;
  --primary-dark: #0b7e70;
  --primary-light: #e2f5f1;
  --gold: #f4a71b;
  --red: #e5484d;
  --green: #2ba56b;
  --text: #1f2d2a;
  --text-2: #5f726d;
  --text-3: #93a5a0;
  --bg: #f3f6f5;
  --card: #ffffff;
  --line: #e5ecea;
  --shadow: 0 6px 20px rgba(18, 52, 46, 0.06);
  --radius: 16px;
  --tabbar-h: 64px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; border: none; background: none; cursor: pointer; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 15px; color: var(--text); }

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  position: relative;
}

/* header */
#app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: linear-gradient(135deg, var(--primary) 0%, #12b39d 100%);
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 16px) 18px 14px;
  box-shadow: 0 2px 12px rgba(11, 126, 112, .18);
}
.header-title { font-size: 20px; font-weight: 700; letter-spacing: .5px; }
.header-sub { font-size: 12px; opacity: .85; margin-top: 2px; }

/* main */
#page-root { padding: 14px 14px 20px; }

/* cards */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card-title {
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.card-title .more {
  font-size: 13px;
  font-weight: 500;
  color: var(--primary);
}
.section-title { font-size: 16px; font-weight: 700; margin: 4px 2px 10px; }

/* stat cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.stat-card {
  background: #fff;
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px;
}
.stat-card .label { font-size: 12px; color: var(--text-2); }
.stat-card .value {
  font-size: 20px;
  font-weight: 800;
  margin-top: 4px;
  white-space: nowrap;
}
.stat-card .hint { font-size: 11px; color: var(--text-3); margin-top: 4px; }
.stat-card.primary { background: linear-gradient(135deg, var(--primary), #12b39d); color: #fff; }
.stat-card.primary .label, .stat-card.primary .hint { color: rgba(255,255,255,.85); }
.stat-card.gold { background: linear-gradient(135deg, #f8b84a, #f4a71b); color: #fff; }
.stat-card.gold .label, .stat-card.gold .hint { color: rgba(255,255,255,.9); }
.stat-card.red { background: linear-gradient(135deg, #ef6b6e, #e5484d); color: #fff; }
.stat-card.red .label, .stat-card.red .hint { color: rgba(255,255,255,.9); }

/* quick actions */
.quick-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.quick-btn {
  background: #fff;
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 12px 4px 10px;
  text-align: center;
  color: var(--text);
}
.quick-btn .qi {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  margin: 0 auto 6px;
  border-radius: 14px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 20px;
  font-weight: 700;
}
.quick-btn .ql { font-size: 12px; color: var(--text-2); }

/* lists */
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.list-item:last-child { border-bottom: none; }
.list-icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  font-size: 17px;
  font-weight: 700;
}
.list-main { flex: 1; min-width: 0; }
.list-title { font-size: 15px; font-weight: 600; }
.list-desc { font-size: 12px; color: var(--text-3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-right { text-align: right; flex: none; }
.list-amount { font-size: 15px; font-weight: 700; }
.list-date { font-size: 11px; color: var(--text-3); margin-top: 2px; }

.empty {
  text-align: center;
  color: var(--text-3);
  padding: 28px 0 20px;
  font-size: 13px;
}
.empty .big { font-size: 34px; margin-bottom: 8px; }

/* ledger summary */
.ledger-summary {
  background: linear-gradient(135deg, #125d54, #0f9d8a);
  color: #fff;
  border-radius: var(--radius);
  padding: 18px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.ledger-summary .sum-row { display: flex; justify-content: space-between; gap: 10px; margin-top: 14px; }
.ledger-summary .sum-item { flex: 1; text-align: center; background: rgba(255,255,255,.1); border-radius: 12px; padding: 10px 4px; }
.ledger-summary .sum-item .sl { font-size: 11px; opacity: .8; }
.ledger-summary .sum-item .sv { font-size: 17px; font-weight: 800; margin-top: 3px; }
.ledger-summary .balance { font-size: 28px; font-weight: 800; }
.ledger-summary .balance-label { font-size: 12px; opacity: .8; }

.filter-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}
.chip {
  flex: none;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13px;
  color: var(--text-2);
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }

.amount-income { color: var(--green); }
.amount-expense { color: var(--red); }

/* buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--primary);
  color: #fff;
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  width: 100%;
}
.btn.secondary { background: #eef4f2; color: var(--primary-dark); }
.btn.danger { background: #fdecec; color: var(--red); }
.btn.gold { background: linear-gradient(135deg, #f8b84a, #f4a71b); color: #fff; }
.btn.small { width: auto; padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

.fab {
  position: fixed;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  right: max(18px, calc((100vw - 520px) / 2 + 18px));
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 26px;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(15, 157, 138, .35);
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* tabbar */
#tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 520px;
  margin: 0 auto;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 50;
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-3);
}
.tab-icon { font-size: 19px; line-height: 1; }
.tab-icon svg { width: 22px; height: 22px; }
.tab-label { font-size: 11px; }
.tab-btn.active { color: var(--primary); font-weight: 600; }
.tab-btn.active .tab-icon { transform: translateY(-1px); }

/* modal */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 31, 28, .45);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn .18s ease;
}
.modal-sheet {
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  animation: slideUp .22s ease;
}
.modal-title {
  font-size: 17px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-close { font-size: 20px; color: var(--text-3); padding: 4px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  background: #fafcfb;
  outline: none;
  transition: border .15s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); background: #fff; }
.field textarea { min-height: 72px; resize: vertical; }
.type-toggle { display: flex; background: #eef4f2; border-radius: 12px; padding: 4px; gap: 4px; }
.type-toggle button { flex: 1; padding: 9px; border-radius: 10px; font-size: 14px; color: var(--text-2); }
.type-toggle button.active-income { background: var(--green); color: #fff; font-weight: 600; }
.type-toggle button.active-expense { background: var(--red); color: #fff; font-weight: 600; }

/* knowledge */
.search-box { position: relative; margin-bottom: 12px; }
.search-box input {
  width: 100%;
  border: none;
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 12px 14px 12px 38px;
  outline: none;
}
.search-box .search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  font-size: 15px;
}
.cat-tabs { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 12px; -webkit-overflow-scrolling: touch; }

.article-card { padding: 0; overflow: hidden; }
.article-card .art-head { padding: 14px 16px 8px; }
.article-card .art-title { font-size: 15px; font-weight: 700; }
.article-card .art-meta { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.article-card .art-excerpt { padding: 0 16px 14px; font-size: 13px; color: var(--text-2); }

.article-body { font-size: 14px; color: var(--text); }
.article-body h3 { font-size: 15px; margin: 14px 0 6px; color: var(--primary-dark); }
.article-body p { margin-bottom: 8px; }
.article-body ul { padding-left: 18px; margin-bottom: 8px; }
.article-body li { margin-bottom: 4px; }
.tip-box {
  background: #fff8e8;
  border-left: 4px solid var(--gold);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 10px 0;
  font-size: 13px;
}

/* batch */
.batch-header { display: flex; align-items: center; gap: 12px; }
.batch-badge {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 800;
}
.batch-info { flex: 1; }
.batch-name { font-size: 16px; font-weight: 700; }
.batch-meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.batch-status {
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 600;
}
.batch-status.closed { background: #eef0ef; color: var(--text-3); }

.mini-stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 4px; }
.mini-stat { background: #f7faf9; border-radius: 12px; padding: 10px; text-align: center; }
.mini-stat .msv { font-size: 17px; font-weight: 800; color: var(--primary-dark); }
.mini-stat .msl { font-size: 11px; color: var(--text-3); margin-top: 2px; }

/* mine */
.profile-card { text-align: center; padding: 22px 16px; }
.avatar {
  width: 64px;
  height: 64px;
  margin: 0 auto 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #12b39d);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 800;
}
.profile-name { font-size: 17px; font-weight: 700; }
.profile-sub { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}
.menu-item:last-child { border-bottom: none; }
.menu-item .mi { color: var(--primary); font-size: 18px; width: 24px; text-align: center; }
.menu-item .chevron { margin-left: auto; color: var(--text-3); }

#toast-root {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: 90vw;
}
.toast {
  background: rgba(25, 45, 40, .92);
  color: #fff;
  font-size: 13px;
  border-radius: 999px;
  padding: 10px 18px;
  box-shadow: 0 6px 20px rgba(0,0,0,.15);
  animation: fadeIn .2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(30px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }

.text-primary { color: var(--primary); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-gold { color: var(--gold); }
.text-center { text-align: center; }
.mt-10 { margin-top: 10px; }
.mt-16 { margin-top: 16px; }
.muted { color: var(--text-3); font-size: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.fw-600 { font-weight: 600; }

/* dashboard chart */
.chart-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 4px 0 2px;
}
.chart-row canvas { flex: none; width: 140px; height: 140px; }
.chart-legend { flex: 1; min-width: 0; }
.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 0;
  font-size: 13px;
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}
.legend-name {
  flex: 1;
  min-width: 0;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.legend-value { font-weight: 600; }

/* progress */
.progress-block {
  margin-top: 12px;
  background: #f7faf9;
  border-radius: 12px;
  padding: 10px 12px;
}
.progress-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 6px;
}
.progress-track {
  height: 8px;
  border-radius: 999px;
  background: #e5ecea;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), #12b39d);
  transition: width .3s ease;
}

/* login */
body.logged-out #app-header,
body.logged-out #tabbar { display: none; }
body.logged-out #app { padding-bottom: 20px; }
.login-wrap {
  min-height: calc(100vh - 40px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 0;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 26px 20px 22px;
}
.login-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--primary), #12b39d);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(15, 157, 138, .3);
}
.login-card h2 {
  text-align: center;
  font-size: 20px;
  margin-bottom: 2px;
}

@media (min-width: 521px) {
  #tabbar, .fab { right: auto; left: 50%; transform: translateX(-50%); }
  .fab { transform: none; left: auto; }
}
