:root {
  --green: #07C160;
  --green-dark: #06a050;
  --bg: #f2f3f5;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #8a8a8a;
  --line: #ececec;
  --danger: #e24b4a;
  --warn: #e8920c;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 6px 16px rgba(0,0,0,.04);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

/* 顶栏 */
.topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}
.topbar-title { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--green); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 17px;
}
.t1 { font-size: 16px; font-weight: 600; }
.t2 { font-size: 11px; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.month-total { font-size: 18px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.icon-btn {
  border: none; background: transparent; font-size: 24px; color: var(--muted);
  width: 36px; height: 36px; border-radius: 50%; cursor: pointer;
}
.icon-btn:active { background: var(--bg); }

/* 聊天列表 */
.chat-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px 12px 20px;
  -webkit-overflow-scrolling: touch;
}
.empty-state { text-align: center; color: var(--muted); margin-top: 30%; }
.es-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { margin: 4px 0; }
.es-sub { font-size: 13px; opacity: .8; }

.day-divider {
  text-align: center; margin: 16px 0 10px;
}
.day-divider span {
  background: rgba(0,0,0,.06); color: var(--muted);
  font-size: 11px; padding: 3px 10px; border-radius: 10px;
}

/* 气泡 */
.bubble {
  display: flex; gap: 10px; margin-bottom: 14px;
  align-items: flex-start;
}
.avatar {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, #07C160, #0aa85a);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600;
}
.bubble-body {
  background: var(--card); border-radius: 4px 14px 14px 14px;
  padding: 10px 12px; max-width: 78%;
  box-shadow: var(--shadow); cursor: pointer;
}
.bb-head { display: flex; align-items: baseline; gap: 8px; }
.bb-merchant { font-weight: 600; font-size: 14px; }
.bb-amount { color: var(--danger); font-weight: 600; font-size: 15px; font-variant-numeric: tabular-nums; }
.bb-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; align-items: center; }
.chip {
  font-size: 11px; padding: 2px 8px; border-radius: 8px;
  background: #eef7f1; color: var(--green-dark);
}
.chip.purpose { background: #f4f4f4; color: #555; }
.tag-unn {
  font-size: 11px; padding: 2px 8px; border-radius: 8px;
  background: #fdeaea; color: var(--danger); font-weight: 500;
}
.bb-time { font-size: 11px; color: var(--muted); margin-top: 6px; }

/* 输入栏 */
.inputbar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px calc(10px + var(--safe-b));
  background: var(--card);
  border-top: 1px solid var(--line);
}
.plus-btn {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%;
  border: none; background: var(--bg); color: #555; font-size: 22px;
  cursor: pointer; line-height: 1;
}
.plus-btn:active { background: #e6e6e6; }
.nl-input {
  flex: 1 1 auto; height: 38px; border: none; border-radius: 19px;
  background: var(--bg); padding: 0 16px; font-size: 15px; outline: none;
}
.send-btn {
  flex: 0 0 auto; height: 38px; padding: 0 18px; border: none; border-radius: 19px;
  background: var(--green); color: #fff; font-size: 15px; font-weight: 500; cursor: pointer;
}
.send-btn:active { background: var(--green-dark); }

/* 动作面板 / 菜单 */
.sheet-mask, .menu-mask, .modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 20; display: none;
  animation: fade .18s ease;
}
.sheet-mask.show, .menu-mask.show, .modal-mask.show { display: flex; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.sheet-mask { align-items: flex-end; justify-content: center; }
.sheet, .menu {
  background: var(--card); width: 100%; max-width: 480px;
}
.sheet {
  border-radius: 16px 16px 0 0; padding: 8px 0 calc(8px + var(--safe-b));
  animation: slideUp .22s ease;
}
@keyframes slideUp { from { transform: translateY(100%) } to { transform: translateY(0) } }
.sheet-item, .menu-item {
  display: block; width: 100%; text-align: left; border: none; background: transparent;
  padding: 16px 20px; font-size: 16px; color: var(--text); cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.sheet-item:active, .menu-item:active { background: var(--bg); }
.sheet-item.cancel { color: var(--muted); border-bottom: none; text-align: center; font-weight: 500; }
.menu-mask { align-items: flex-start; justify-content: flex-end; background: rgba(0,0,0,.25); }
.menu {
  margin-top: 56px; margin-right: 10px; border-radius: 12px; overflow: hidden;
  width: 180px; box-shadow: var(--shadow); padding: 4px 0;
  max-height: 75vh; overflow-y: auto;
  animation: pop .15s ease;
}
@keyframes pop { from { opacity: 0; transform: scale(.96) } to { opacity: 1; transform: scale(1) } }
.menu-item { border-bottom: 1px solid var(--line); padding: 13px 16px; font-size: 15px; }
.menu-item:last-child { border-bottom: none; }
.menu-item.danger { color: var(--danger); }
.close-btn { text-align: center; color: var(--muted); font-weight: 500; border-bottom: 2px solid var(--line) !important; }

/* 弹窗 */
.modal-mask { align-items: center; justify-content: center; padding: 20px; }
.modal {
  background: var(--card); border-radius: 16px; width: 100%; max-width: 420px;
  padding: 20px; max-height: 86vh; overflow-y: auto;
  animation: pop .18s ease;
}
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal .range { color: var(--muted); font-size: 12px; margin: 0 0 14px; }

/* 表单 */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; height: 42px; border: 1px solid var(--line); border-radius: 10px;
  padding: 0 12px; font-size: 15px; background: #fafafa; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--green); background: #fff; }
.row2 { display: flex; gap: 10px; }
.row2 .field { flex: 1; }
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-top: 1px solid var(--line);
}
.toggle-row span { font-size: 14px; }
.switch { position: relative; width: 44px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; background: #d8d8d8; border-radius: 13px; transition: .2s; cursor: pointer;
}
.slider:before {
  content: ""; position: absolute; width: 22px; height: 22px; left: 2px; top: 2px;
  background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider:before { transform: translateX(18px); }

.btn-primary {
  width: 100%; height: 46px; border: none; border-radius: 12px;
  background: var(--green); color: #fff; font-size: 16px; font-weight: 600; cursor: pointer;
  margin-top: 8px;
}
.btn-primary:active { background: var(--green-dark); }
.btn-ghost {
  width: 100%; height: 42px; border: 1px solid var(--line); border-radius: 12px;
  background: #fff; color: #555; font-size: 15px; cursor: pointer; margin-top: 8px;
}

/* 报告 */
.report h3 { font-size: 14px; margin: 18px 0 8px; color: #333; }
.summary { display: flex; gap: 10px; margin: 10px 0; }
.sum-item {
  flex: 1; background: var(--bg); border-radius: 12px; padding: 12px 10px; text-align: center;
}
.sum-item span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.sum-item b { font-size: 17px; }
.sum-item b.warn { color: var(--danger); }
.chart-wrap { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.legend { flex: 1; min-width: 160px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 3px 0; }
.legend-item .dot { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.legend-item b { margin-left: auto; }
.legend-item .muted { color: var(--muted); font-size: 12px; }
.tips { margin: 6px 0; padding-left: 18px; }
.tips li { font-size: 13px; padding: 3px 0; }
.savings { background: #fff8ec; color: #8a5a00; border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-top: 8px; }
.savings b { color: var(--warn); }
.savings.good { background: #eef7f1; color: var(--green-dark); }
.empty { color: var(--muted); font-size: 13px; }

/* 提示条 */
.toast {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%,-50%);
  background: rgba(0,0,0,.8); color: #fff; padding: 12px 20px; border-radius: 10px;
  font-size: 14px; z-index: 50; max-width: 80%; text-align: center;
  animation: fade .2s ease;
}
.ocr-status { color: var(--muted); font-size: 13px; text-align: center; padding: 20px; }
.spinner {
  width: 28px; height: 28px; border: 3px solid #ddd; border-top-color: var(--green);
  border-radius: 50%; margin: 0 auto 12px; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }

/* 账本筛选 + 预算条 */
.subbar {
  flex: 0 0 auto;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 8px 12px 10px;
  z-index: 4;
}
.filter-chips { display: flex; gap: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chip-btn {
  flex: 0 0 auto; border: 1px solid var(--line); background: #fafafa; color: var(--muted);
  font-size: 13px; padding: 5px 14px; border-radius: 14px; cursor: pointer; white-space: nowrap;
}
.chip-btn.active { background: var(--green); color: #fff; border-color: var(--green); }
.budget-bar { margin-top: 10px; cursor: pointer; }
.budget-label { font-size: 12px; color: var(--muted); margin-bottom: 5px; font-variant-numeric: tabular-nums; }
.budget-bar.over .budget-label { color: var(--danger); font-weight: 600; }
.budget-track { height: 6px; background: #eee; border-radius: 3px; overflow: hidden; }
.budget-fill { height: 100%; width: 0%; background: var(--green); border-radius: 3px; transition: width .3s ease; }
.budget-bar.over .budget-fill { background: var(--danger); }

/* 账户徽标 */
.chip.acc { color: #fff; }

/* 资产与余额 */
.networth {
  background: linear-gradient(135deg, #07C160, #0aa85a); color: #fff;
  border-radius: 14px; padding: 16px 18px; margin: 4px 0 6px;
}
.networth span { font-size: 13px; opacity: .9; }
.networth b { display: block; font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.nw-sub { display: flex; gap: 16px; margin-top: 8px; font-size: 12px; opacity: .92; }
.nw-sub .warn { color: #ffe08a; }
.assets h3 { font-size: 14px; margin: 18px 0 8px; color: #333; }
.acc-card {
  background: var(--bg); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px;
}
.acc-main { display: flex; align-items: center; justify-content: space-between; }
.acc-name { font-size: 15px; font-weight: 500; }
.acc-main b { font-size: 16px; font-variant-numeric: tabular-nums; }
.acc-main b.warn { color: var(--danger); }
.acc-repay { margin-top: 6px; }
.repay-tag { font-size: 11px; padding: 2px 8px; border-radius: 8px; background: #eef0f3; color: var(--muted); }
.repay-tag.near { background: #fdeaea; color: var(--danger); font-weight: 600; }
.acc-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.mini {
  border: 1px solid var(--line); background: #fff; color: #555; font-size: 13px;
  padding: 5px 14px; border-radius: 10px; cursor: pointer;
}
.mini.del { color: var(--danger); }
.mini:active { background: var(--bg); }

/* 账户分布（报告中） */
.acc-brk { display: flex; flex-direction: column; gap: 4px; }
.acc-brk-row { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 3px 0; }
.acc-brk-row .dot { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.acc-brk-row b { margin-left: auto; font-variant-numeric: tabular-nums; }
.acc-brk-row .muted { color: var(--muted); font-size: 12px; min-width: 34px; text-align: right; }

/* 桌面端布局优化：宽屏下居中成卡片，提升可读性与点击体验 */
@media (min-width: 640px) {
  body {
    display: flex; align-items: center; justify-content: center;
    background: #e9eaec;
  }
  #app {
    height: 100vh; max-width: 460px;
    box-shadow: 0 10px 50px rgba(0,0,0,.12);
    border-radius: 0;
  }
  .subbar, .topbar { max-width: 460px; }
  .modal { max-width: 420px; }
  .sheet, .menu { max-width: 460px; }
  /* 桌面端鼠标悬停反馈 */
  .chip-btn:hover { border-color: var(--green); color: var(--green); }
  .sheet-item:hover, .menu-item:hover { background: var(--bg); }
  .send-btn, .plus-btn, .btn-primary, .mini { cursor: pointer; }
}
