/* 摊掌柜 · 移动端样式（桌面宽度下居中呈现手机竖屏布局） */
:root {
  --primary: #ff6a00;
  --primary-2: #ff8f3c;
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #26221d;
  --sub: #8b857b;
  --line: #ece8df;
  --in: #0a9d58;
  --out: #e0342b;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(60, 50, 30, .06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: #e7e2d8;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 15px;
}
#app {
  max-width: 480px; margin: 0 auto; min-height: 100dvh;
  background: var(--bg); position: relative;
  box-shadow: 0 0 30px rgba(0, 0, 0, .10);
}
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }
.hidden { display: none !important; }

/* ---------- 页面骨架 ---------- */
.page { display: none; min-height: 100dvh; padding-bottom: 86px; }
.page.active { display: block; }
#page-chat.active { display: flex; flex-direction: column; height: 100dvh; padding-bottom: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; position: sticky; top: 0; z-index: 5;
  background: linear-gradient(135deg, var(--primary-2), var(--primary)); color: #fff;
}
.topbar.plain {
  background: var(--card); color: var(--ink);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 17px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo {
  width: 38px; height: 38px; border-radius: 12px; background: rgba(255, 255, 255, .22);
  display: flex; align-items: center; justify-content: center; font-size: 21px;
}
.brand h1 { font-size: 17px; margin: 0; }
.brand p { margin: 1px 0 0; font-size: 11px; opacity: .9; }
.icon-btn {
  background: rgba(255, 255, 255, .2); border: none; color: #fff;
  width: 36px; height: 36px; border-radius: 12px; font-size: 18px;
}

/* ---------- 聊天页 ---------- */
.chat-scroll { flex: 1; overflow-y: auto; padding: 14px 12px 8px; }
.hero { text-align: center; padding: 22px 18px 4px; }
.hero-logo { font-size: 46px; }
.hero h2 { margin: 8px 0 6px; font-size: 20px; }
.hero p { margin: 0; color: var(--sub); font-size: 13px; line-height: 1.7; }

.no-key-card {
  margin: 14px 4px 0; background: #fff7e8; border: 1px solid #ffe2ad;
  border-radius: 12px; padding: 12px 14px; font-size: 13px; color: #8a6116;
}
.no-key-card p { margin: 4px 0 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 16px 4px 8px; }
.chip {
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 13px; font-size: 13px; color: var(--ink); box-shadow: var(--shadow);
}
.chip:active { background: #fff3e6; border-color: #ffd2ab; }

.msg { margin: 10px 0; animation: pop .18s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }
.msg .bubble {
  max-width: 86%; padding: 10px 14px; border-radius: 16px; line-height: 1.6;
  font-size: 15px; white-space: pre-wrap; word-break: break-word;
}
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  background: linear-gradient(135deg, var(--primary-2), var(--primary));
  color: #fff; border-bottom-right-radius: 4px;
}
.msg.ai .bubble {
  background: var(--card); box-shadow: var(--shadow); border-bottom-left-radius: 4px;
}
.msg.ai .bubble.error { background: #fff1f0; color: var(--out); }

.typing { display: inline-flex; gap: 5px; padding: 12px 16px; background: var(--card);
  border-radius: 16px; border-bottom-left-radius: 4px; box-shadow: var(--shadow); }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: #cbbfae; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }

.op-card {
  margin-top: 8px; max-width: 86%; background: var(--card); border-radius: 14px;
  padding: 11px 14px; box-shadow: var(--shadow); border-left: 4px solid #e8e2d6;
}
.op-card.fail { border-left-color: var(--out); background: #fff6f5; }
.op-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.op-title { font-weight: 700; font-size: 14px; }
.op-amount { font-weight: 800; font-size: 17px; white-space: nowrap; }
.op-amount.in { color: var(--in); }
.op-amount.out { color: var(--out); }
.op-line { font-size: 13px; color: var(--sub); margin-top: 4px; }
.op-extra {
  margin-top: 8px; font-size: 12px; color: #9a6b1f; background: #fff7e8;
  border-radius: 8px; padding: 6px 9px;
}

.composer { padding: 8px 12px calc(10px + 66px + env(safe-area-inset-bottom, 0px)); background: var(--bg); }
.rec-hint {
  text-align: center; font-size: 12px; color: var(--out);
  background: #fff1f0; border-radius: 999px; padding: 6px; margin-bottom: 8px;
}
.composer-row { display: flex; gap: 8px; align-items: center; }
.mic-btn {
  width: 46px; height: 46px; flex: none; border-radius: 50%; border: 1px solid var(--line);
  background: var(--card); font-size: 20px; box-shadow: var(--shadow);
}
.mic-btn.rec { background: var(--out); border-color: var(--out); animation: pulse 1.1s infinite; }
.mic-btn.busy { opacity: .55; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(224,52,43,.35); } 55% { box-shadow: 0 0 0 12px rgba(224,52,43,0); } }
#chat-input {
  flex: 1; height: 46px; border: 1px solid var(--line); border-radius: 14px;
  padding: 0 14px; font-size: 15px; background: var(--card); outline: none;
}
#chat-input:focus { border-color: var(--primary-2); }
.send-btn {
  height: 46px; padding: 0 18px; border: none; border-radius: 14px; color: #fff;
  background: linear-gradient(135deg, var(--primary-2), var(--primary));
  font-size: 15px; font-weight: 600; box-shadow: 0 4px 12px rgba(255, 106, 0, .3);
}

/* ---------- 通用列表页 ---------- */
.summary-card { margin: 12px 16px 0; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px 14px; }
.scope-toggle { display: flex; background: #f1ede4; border-radius: 999px; padding: 3px; }
.scope-toggle button {
  flex: 1; border: none; background: transparent; border-radius: 999px;
  padding: 6px 0; font-size: 13px; color: var(--sub);
}
.scope-toggle button.active { background: #fff; color: var(--primary); font-weight: 700; box-shadow: var(--shadow); }
.sum-row { display: flex; margin-top: 12px; }
.sum { flex: 1; text-align: center; }
.sum label { display: block; font-size: 12px; color: var(--sub); margin-bottom: 3px; }
.sum b { font-size: 20px; font-weight: 800; }
.sum b.in { color: var(--in); }
.sum b.out { color: var(--out); }

.seg { display: flex; gap: 6px; padding: 12px 16px 6px; overflow-x: auto; }
.seg button {
  flex: none; border: 1px solid var(--line); background: var(--card); color: var(--sub);
  border-radius: 999px; padding: 7px 14px; font-size: 13px;
}
.seg button.active { background: #fff3e6; border-color: #ffc79b; color: var(--primary); font-weight: 700; }

.search-row { padding: 12px 16px 4px; }
.search-row input {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; font-size: 15px; background: var(--card); outline: none;
}
.search-row input:focus { border-color: var(--primary-2); }

.list { padding: 6px 16px 12px; }
.day-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12px; color: var(--sub); padding: 10px 2px 6px;
}
.row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: 14px; box-shadow: var(--shadow);
  padding: 12px 14px; margin-bottom: 10px;
}
.row:active { background: #fdf9f2; }
.row-icon {
  width: 40px; height: 40px; flex: none; border-radius: 12px; background: #f6f1e7;
  display: flex; align-items: center; justify-content: center; font-size: 19px;
}
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-title .tag {
  font-style: normal; font-size: 10px; color: var(--sub); background: #f1ede4;
  border-radius: 4px; padding: 1px 5px; margin-left: 6px; vertical-align: 1px;
}
.row-title .tag.low { color: var(--out); background: #ffe9e7; }
.row-sub { font-size: 12px; color: var(--sub); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-amt { font-size: 16px; font-weight: 800; white-space: nowrap; }
.row-amt.in { color: var(--in); }
.row-amt.out { color: var(--out); }
.row-amt small { font-size: 11px; color: var(--sub); font-weight: 400; margin-left: 2px; }
.chev { color: #c9c2b4; font-size: 20px; }

.empty { text-align: center; color: var(--sub); font-size: 13px; padding: 46px 0; }
.empty-ico { font-size: 40px; margin-bottom: 10px; }

.todo-row .check {
  width: 26px; height: 26px; flex: none; border-radius: 50%;
  border: 2px solid #d8d2c4; background: #fff; color: #fff; font-size: 14px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.todo-row .check.checked { background: var(--in); border-color: var(--in); }
.todo-row.done .row-title { text-decoration: line-through; color: var(--sub); }
.todo-row.done { opacity: .75; }
.overdue { color: var(--out); font-weight: 700; }

.fab {
  position: fixed; z-index: 20; width: 56px; height: 56px; border-radius: 50%;
  border: none; color: #fff; font-size: 26px; line-height: 1;
  background: linear-gradient(135deg, var(--primary-2), var(--primary));
  box-shadow: 0 6px 18px rgba(255, 106, 0, .45);
  bottom: calc(86px + env(safe-area-inset-bottom, 0px));
  left: 50%; margin-left: calc(min(240px, 50vw) - 72px);
}
.fab:active { transform: scale(.94); }

/* ---------- 底部导航 ---------- */
#tabbar {
  position: fixed; z-index: 30; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px; display: flex;
  background: rgba(255, 255, 255, .96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
#tabbar .tab {
  flex: 1; background: none; border: none; padding: 8px 0 9px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; color: var(--sub);
}
#tabbar .tab span { font-size: 21px; line-height: 1.15; filter: grayscale(1) opacity(.6); }
#tabbar .tab.active { color: var(--primary); font-weight: 700; }
#tabbar .tab.active span { filter: none; }

/* ---------- 弹层 ---------- */
#modal-root .mask {
  position: fixed; inset: 0; z-index: 60; background: rgba(30, 25, 15, .5);
  display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal-card {
  background: var(--card); width: 100%; max-width: 480px; max-height: 88dvh;
  overflow-y: auto; border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  animation: slideup .2s ease;
}
@keyframes slideup { from { transform: translateY(40px); opacity: .6; } }
.modal-card h3 { margin: 0 0 4px; font-size: 17px; }
.modal-card label { display: block; font-size: 12px; color: var(--sub); margin: 11px 0 0; }
.modal-card input, .modal-card select {
  width: 100%; margin-top: 5px; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: #fbfaf7; font-size: 15px; outline: none; color: var(--ink);
}
.modal-card input:focus, .modal-card select:focus { border-color: var(--primary-2); background: #fff; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.btn { flex: 1; border: none; border-radius: 12px; padding: 13px; font-size: 15px; font-weight: 600; }
.btn.primary { background: linear-gradient(135deg, var(--primary-2), var(--primary)); color: #fff; }
.btn.danger { background: #fff1f0; color: var(--out); }
.btn.ghost { background: #f1ede4; color: var(--sub); }
.btn.small { width: auto; flex: none; padding: 8px 16px; font-size: 13px; }
.set-sec { border: 1px solid var(--line); border-radius: 14px; padding: 12px 12px 14px; margin-top: 12px; }
.set-sec h4 { margin: 0; font-size: 14px; }
.tip { font-size: 12px; color: var(--sub); line-height: 1.7; margin: 12px 0 0; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; z-index: 99; top: 18px; left: 50%; transform: translateX(-50%) translateY(-8px);
  background: rgba(30, 25, 15, .9); color: #fff; font-size: 13px;
  padding: 10px 18px; border-radius: 999px; opacity: 0; pointer-events: none;
  transition: all .22s ease; max-width: 86vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 访问密码锁屏 ---------- */
#lock-screen {
  position: fixed; inset: 0; z-index: 200; background: linear-gradient(160deg, #fff3e6, var(--bg));
  display: flex; align-items: center; justify-content: center;
}
#lock-screen.hidden { display: none; }
.lock-card { text-align: center; padding: 0 44px; }
.lock-ico { font-size: 52px; }
.lock-card h2 { margin: 10px 0 4px; font-size: 20px; }
.lock-card p { margin: 0 0 18px; color: var(--sub); font-size: 13px; }
#lock-pass {
  width: 100%; height: 48px; border: 1px solid var(--line); border-radius: 12px;
  padding: 0 16px; font-size: 17px; text-align: center; letter-spacing: 4px;
  background: var(--card); outline: none; margin-bottom: 12px;
}
#lock-pass:focus { border-color: var(--primary-2); }
#lock-btn { width: 100%; }
