:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --ink: #1c1b18;
  --ink-2: #6b6862;
  --ink-3: #a09c94;
  --line: #e6e3dc;
  --line-soft: #efece5;
  --accent: #2c5a4e;
  --accent-soft: #eaf0ed;
  --expense: #a8452e;
  --income: #2f6b4f;
  --warn: #b07d1f;
  --warn-soft: #fbf3e2;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(28, 27, 24, 0.04), 0 8px 24px rgba(28, 27, 24, 0.06);
}

* { box-sizing: border-box; }

/* 全局隐藏工具类：卡片里按方向切换字段全靠它 */
.hidden { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 14px;
  transition: background 0.15s, border-color 0.15s;
}
button:hover { background: #faf9f6; border-color: #d8d4cb; }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button.primary:hover { background: #244b41; }
button.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
button.ghost:hover { background: var(--line-soft); color: var(--ink); }
button:disabled { opacity: 0.45; cursor: default; }

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------- 登录 ---------- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 36px 32px 28px;
  box-shadow: var(--shadow);
}
.login-card h1 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.login-card .sub {
  margin: 0 0 26px;
  color: var(--ink-3);
  font-size: 13px;
}
.login-card label {
  display: block;
  font-size: 12px;
  color: var(--ink-2);
  margin-bottom: 6px;
}
.login-card input {
  width: 100%;
  margin-bottom: 16px;
  padding: 10px 12px;
}
.login-card button { width: 100%; padding: 10px; margin-top: 6px; }
.login-error {
  color: var(--expense);
  font-size: 13px;
  min-height: 20px;
  margin-top: 12px;
}

/* ---------- 主界面 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(247, 246, 243, 0.86);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
  color: var(--accent);
}
.brand .dot { color: var(--ink-3); font-weight: 400; margin: 0 6px; }
.brand .who { color: var(--ink-3); font-size: 13px; font-weight: 400; }
.topbar .spacer { flex: 1; }

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 20px 120px;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat .k { font-size: 12px; color: var(--ink-3); margin-bottom: 4px; }
.stat .v { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.stat .v.expense { color: var(--expense); }
.stat .v.income { color: var(--income); }

/* 录入框 */
.composer {
  position: relative;
  margin-bottom: 8px;
}
.composer input {
  width: 100%;
  padding: 16px 18px;
  font-size: 17px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.composer input::placeholder { color: #b8b4ab; }
.composer .hint {
  font-size: 12px;
  color: var(--ink-3);
  margin: 8px 4px 0;
}
.composer .hint kbd {
  font-family: inherit;
  background: var(--line-soft);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
  color: var(--ink-2);
}

/* 解析卡片 */
.parse-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-top: 12px;
}
.parse-card.hidden { display: none; }
.parse-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 14px;
}
.parse-amount {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.parse-amount.expense { color: var(--expense); }
.parse-amount.income { color: var(--income); }
.parse-amount .cur { font-size: 16px; font-weight: 500; margin-right: 2px; }
.parse-tag {
  font-size: 12px;
  color: var(--warn);
  background: var(--warn-soft);
  border-radius: 999px;
  padding: 2px 9px;
}
.parse-fields {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px 14px;
  margin-bottom: 14px;
}
.field label {
  display: block;
  font-size: 11px;
  color: var(--ink-3);
  margin-bottom: 4px;
}
.field input, .field select { width: 100%; font-size: 14px; padding: 7px 9px; }
.field.low input, .field.low select {
  border-color: #e0c286;
  background: #fffdf7;
}
.parse-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* 标签页 */
.tabs {
  display: flex;
  gap: 4px;
  margin: 28px 0 16px;
  border-bottom: 1px solid var(--line);
}
.tab {
  border: none;
  background: none;
  padding: 9px 14px;
  color: var(--ink-3);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  border-radius: 0;
  font-size: 14px;
}
.tab:hover { background: none; color: var(--ink-2); border-color: transparent; }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }
.tab .badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  margin-left: 6px;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  border-radius: 9px;
  background: var(--warn-soft);
  color: var(--warn);
}

/* 流水列表 */
.day-group { margin-bottom: 22px; }
.day-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 0 4px 8px;
  font-size: 12px;
  color: var(--ink-3);
}
.day-head .sum { margin-left: auto; font-variant-numeric: tabular-nums; }

.txn {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 14px;
  margin-bottom: 6px;
  transition: border-color 0.15s;
}
.txn:hover { border-color: #d8d4cb; }
.txn .check { margin: 0; }
.txn .body { flex: 1; min-width: 0; }
.txn .title {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.txn .meta {
  font-size: 12px;
  color: var(--ink-3);
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 1px;
}
.txn .chip {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--line-soft);
  color: var(--ink-2);
}
.txn .chip.none { background: var(--warn-soft); color: var(--warn); }
.txn .amt {
  font-size: 15px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.txn .amt.expense { color: var(--expense); }
.txn .amt.income { color: var(--income); }
.txn .amt.transfer { color: var(--ink-2); }
.txn .acts { display: flex; gap: 2px; opacity: 0; transition: opacity 0.15s; }
.txn:hover .acts { opacity: 1; }
.txn .acts button { padding: 3px 8px; font-size: 12px; }

.empty {
  text-align: center;
  color: var(--ink-3);
  padding: 48px 20px;
  font-size: 14px;
}

/* 批量操作条 */
.bulkbar {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(140%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--ink);
  color: #fff;
  border-radius: 999px;
  padding: 9px 12px 9px 18px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.24);
  transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.2s;
  opacity: 0;
  pointer-events: none;
  z-index: 40;
}
.bulkbar.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}
.bulkbar span { font-size: 13px; }
.bulkbar select {
  border: none;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  padding: 6px 10px;
  font-size: 13px;
}
.bulkbar select option { color: var(--ink); }
.bulkbar button {
  background: #fff;
  color: var(--ink);
  border: none;
  padding: 6px 14px;
  font-size: 13px;
}

/* 分类 / 账户 管理 */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.panel h2 {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
}
.panel .desc { font-size: 12px; color: var(--ink-3); margin: 0 0 14px; }
.cat-group { margin-bottom: 14px; }
.cat-group h3 {
  font-size: 12px;
  color: var(--ink-3);
  font-weight: 400;
  margin: 0 0 8px;
}
.cat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line-soft);
}
.cat-row:last-child { border-bottom: none; }
.cat-row .name { flex: 1; font-size: 14px; }
.cat-row .alias-list {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}
.cat-row .alias {
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.cat-row .alias.learned { background: var(--line-soft); color: var(--ink-2); }
.cat-row .alias button {
  border: none;
  background: none;
  padding: 0;
  font-size: 12px;
  line-height: 1;
  color: var(--ink-3);
}
.addrow { display: flex; gap: 8px; margin-top: 12px; }
.addrow input { flex: 1; }
.addrow select { width: 90px; }

.acct-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
}
.acct-row:last-of-type { border-bottom: none; }
.acct-row > div:first-child { flex: 1; min-width: 0; }
.acct-row .name { font-size: 14px; }
.acct-row .kind { font-size: 11px; color: var(--ink-3); }
.acct-row .bal {
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  font-weight: 500;
}
.acct-row .bal.neg { color: var(--expense); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  padding: 9px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--expense); }

@media (max-width: 620px) {
  main { padding: 16px 14px 120px; }
  .stat-row { grid-template-columns: 1fr 1fr; }
  .stat:last-child { display: none; }
  .parse-fields { grid-template-columns: 1fr; }
  .topbar-inner { padding: 10px 14px; }
  .txn .acts { opacity: 1; }
}
