:root {
  --bg: #eef1f6;
  --card: #ffffff;
  --ink: #16233a;
  --ink-2: #5c6b85;
  --ink-3: #8d9ab0;
  --line: #e4e9f1;
  --brand: #2f5bd8;
  --brand-soft: #eaf0ff;
  --income: #d23b48;
  --expense: #1c9a6a;
  --warn: #c47a12;
  --danger: #c0392b;
  --radius: 16px;
  --shadow: 0 2px 14px rgba(22, 35, 58, .06);
  --safe-top: env(safe-area-inset-top, 0px);
  /* 只保留必要的系统手势区：iPhone 的 34px 若全量并入底栏，会变成
     「82px 宽栏 + 43px 下部留白」。封顶 12px 后栏仍是窄条，按钮底部
     距屏幕底 >= 17px，不会被 Home 指示条压住，内容也不会被栏遮住。 */
  --safe-bottom: min(env(safe-area-inset-bottom, 0px), 12px);
  /* v0.6.2：底栏「可见高度」单独成变量。安全区只作为系统手势区承接，
     不再并进可见栏高，否则 iPhone / 全面屏安卓上底栏会被撑到 82px。 */
  --tabbar-h: 40px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1422;
    --card: #162034;
    --ink: #eaf0fb;
    --ink-2: #a3b0c7;
    --ink-3: #74839d;
    --line: #26344c;
    --brand: #7ea2ff;
    --brand-soft: #1d2c4c;
    --income: #ff7a86;
    --expense: #5fd4a4;
    --warn: #e3ad58;
    --danger: #ff8a80;
    --shadow: 0 2px 14px rgba(0, 0, 0, .28);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* v0.7 布局骨架：文档本身不滚动，滚动只发生在 .main 里。
   底栏改为 flex 末项而不是 position:fixed —— iOS Safari 首次渲染时地址栏
   仍展开，fixed 元素会按「大 layout viewport」定位，看起来不在屏幕最底部，
   用户划一下地址栏收起才归位。flex 末项永远贴住容器底，与视口计算无关。 */
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei UI", "PingFang SC", "Hiragino Sans GB", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
input, textarea, select { min-width: 0; max-width: 100%; }
/* .field / .split-box 等作者样式带 display:block，会盖过 UA 的 [hidden]，
   必须显式收口，否则切换记账方式时旧控件仍占位。 */
[hidden] { display: none !important; }

.app {
  display: flex; flex-direction: column;
  height: 100dvh;                 /* 老浏览器回退 */
  height: var(--app-h, 100dvh);  /* JS 用 visualViewport 精确修正 iOS */
  max-width: 560px; margin: 0 auto;
  overflow: hidden;
}
/* 手机 <600px 不变；600–899px 只是适度放宽；≥768px 的平板走后面的
   专属侧栏 + 分栏布局，而不是把手机界面简单拉宽。 */
@media (min-width: 600px) and (max-width: 767px) { .app { max-width: 680px; } }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: calc(var(--safe-top) + 14px) 18px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.brand-mark {
  width: 20px; height: 20px; border-radius: 6px;
  background: linear-gradient(140deg, var(--brand), #7f6bf0);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.28);
}
.brand-tag {
  font-size: 11px; font-weight: 600; color: var(--brand);
  background: var(--brand-soft); padding: 2px 7px; border-radius: 20px;
}
.top-status {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--ink-2);
  padding: 6px 10px; border-radius: 20px; background: var(--card);
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; }
.dot-online { background: #24b47e; box-shadow: 0 0 0 3px rgba(36,180,126,.15); }
.dot-offline { background: var(--ink-3); }
.dot-pending { background: var(--warn); box-shadow: 0 0 0 3px rgba(196,122,18,.15); }
.dot-error { background: var(--danger); box-shadow: 0 0 0 3px rgba(192,57,43,.15); }

.offline-bar {
  margin: 10px 16px 0; padding: 9px 12px; border-radius: 10px;
  background: rgba(196,122,18,.12); color: var(--warn);
  font-size: 12.5px; text-align: center;
}

/* v0.7：内容区自己滚动，底栏是兄弟节点、永远贴在容器底部。
   不再给 fixed 底栏预留 padding，滚到底也不会空出一大截。 */
.main {
  flex: 1 1 auto; min-height: 0; min-width: 0;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain;
  padding: 14px 16px 18px;
}
.screen { display: none; min-width: 0; animation: fade .18s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-title { margin: 2px 2px 14px; }
.page-title h1 { margin: 0; font-size: 21px; font-weight: 750; letter-spacing: -.3px; }
.page-title p { margin: 2px 0 0; font-size: 12px; color: var(--ink-3); }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 20px 2px 10px; }
.section-head h2 { font-size: 15px; margin: 0; font-weight: 700; }
.link-btn { color: var(--brand); font-size: 13px; }
.counter { font-size: 12px; color: var(--ink-3); }

.hero { padding: 20px 18px; background: linear-gradient(150deg, var(--card), var(--brand-soft)); }
.hero-label { font-size: 12px; color: var(--ink-2); }
.hero-value { font-size: 34px; font-weight: 700; letter-spacing: -.5px; margin: 4px 0 16px; font-variant-numeric: tabular-nums; }
.hero-split { display: flex; align-items: center; gap: 18px; }
.hero-split > div { display: flex; flex-direction: column; gap: 2px; }
.hero-divider { width: 1px; height: 28px; background: var(--line); }
.hero-sub-label { font-size: 11px; color: var(--ink-3); }
.hero-sub { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; }
.hero-sub.income { color: var(--income); }
.hero-sub.expense { color: var(--expense); }

.list { padding: 4px 16px; }
.row {
  display: flex; align-items: center; gap: 8px;
  padding: 13px 0; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 14.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* 桌面端同步过来的「整笔备注」必须在手机上完整可见，不能挤进会截断的 row-sub。 */
.row-note { font-size: 11.5px; color: var(--ink-2); margin-top: 3px; line-height: 1.5; word-break: break-word; }
.row-sub { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; display: flex; gap: 8px; align-items: center; min-width: 0; overflow: hidden; white-space: nowrap; }
.row-sub > span { flex: none; }
.row-sub > span:not(.sync-flag) { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.row-amount { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-amount.income { color: var(--income); }
.row-amount.expense { color: var(--expense); }
.sync-flag { font-size: 10px; padding: 1px 6px; border-radius: 10px; white-space: nowrap; }
.sync-flag.cloud { color: var(--brand); background: var(--brand-soft); }
.sync-flag.local { color: var(--warn); background: rgba(196,122,18,.12); }
.row-del {
  flex: none; font-size: 11px; color: var(--ink-3);
  padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line);
}
.group-toggle { color: var(--brand); background: var(--brand-soft); }
.row-edit {
  flex: none; font-size: 11px; color: var(--brand);
  padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--brand-soft);
}
.group-detail { display: none; padding: 2px 0 10px 34px; }
.group-detail.open { display: block; }
.group-line {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 12px; color: var(--ink-2); padding: 5px 0;
  border-bottom: 1px dashed var(--line);
}
.group-line:last-child { border-bottom: 0; }
.group-line span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-line strong { font-variant-numeric: tabular-nums; flex: none; }
.empty { padding: 30px 8px; text-align: center; color: var(--ink-3); font-size: 13px; }

/* ---- 拆分明细：每一条都是独立小卡片，项目名 / 金额 / 分类放在同一条内 ---- */
.split-box { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 16px; }
.split-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.split-head .field-label { margin: 0; }
.split-sum { font-size: 12.5px; font-weight: 700; color: var(--brand); font-variant-numeric: tabular-nums; white-space: nowrap; }
.split-sum.bad { color: var(--danger); }
.split-lines { display: flex; flex-direction: column; gap: 8px; }
.split-line {
  display: flex; flex-direction: column; gap: 6px; min-width: 0;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px;
}
.split-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.split-line input, .split-line select {
  min-width: 0; box-sizing: border-box; height: 38px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 9px; padding: 0 9px;
  background: var(--bg); outline: none;
}
.split-line input:focus, .split-line select:focus { border-color: var(--brand); }
.split-name { flex: 1 1 auto; width: auto; }
.split-amt { flex: 0 0 96px; width: 96px; text-align: right; font-variant-numeric: tabular-nums; }
.split-cat {
  flex: 1 1 auto; width: auto; font-size: 14px; padding-right: 26px;
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
                    linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 15px) 17px, calc(100% - 10px) 17px;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
.split-del {
  flex: none; width: 30px; height: 30px; border-radius: 8px;
  color: var(--ink-3); border: 1px solid var(--line); font-size: 16px; line-height: 1;
}
.split-del:disabled { opacity: .35; }
.ghost-btn {
  width: 100%; margin-top: 10px; padding: 9px; border-radius: 9px;
  border: 1px dashed var(--line); color: var(--brand); font-size: 13px; font-weight: 600;
}
.inline-error { color: var(--danger); font-size: 12px; margin: 9px 0 0; line-height: 1.5; }

.hint strong { font-size: 13.5px; }
.hint p { margin: 6px 0 0; font-size: 12.5px; color: var(--ink-2); line-height: 1.6; }

.seg { display: flex; gap: 4px; background: var(--bg); border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.seg-btn { flex: 1; padding: 9px 0; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.seg-btn.active { background: var(--card); color: var(--brand); box-shadow: var(--shadow); }
.mode-seg { margin-bottom: 14px; }
.mode-seg .seg-btn { font-size: 13px; padding: 8px 0; }
.field { display: block; margin-bottom: 14px; min-width: 0; }
.field-label { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 6px; }
.field input, .field textarea, .field select {
  display: block;
  width: 100%; min-width: 0; max-width: 100%; box-sizing: border-box;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px; outline: none; resize: vertical;
  font-size: 16px; line-height: 1.35;
}
.field select {
  appearance: none; -webkit-appearance: none; height: 46px; padding-right: 32px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
                    linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 17px) 20px, calc(100% - 12px) 20px;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
/* 日期框：Safari / WebView 会给 type=date 一个比父容器更宽的内在尺寸，
   不显式压住就会顶出卡片。16px 同时避免 iOS 聚焦时自动放大页面。 */
.date-field { overflow: hidden; }
.date-field input[type="date"] {
  -webkit-appearance: none; appearance: none;
  height: 46px; padding: 10px 12px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; font-variant-numeric: tabular-nums;
}
.date-field input[type="date"]::-webkit-calendar-picker-indicator { opacity: .55; margin-left: 2px; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--brand); }
.amount-row { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; min-width: 0; }
.amount-row:focus-within { border-color: var(--brand); }
.amount-row .cny { color: var(--ink-3); font-size: 18px; flex: none; }
.amount-row input { flex: 1; width: 100%; min-width: 0; border: 0; background: none; padding: 11px 0; font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.amount-row input:focus { border: 0; }
.primary-btn, .secondary-btn, .danger-btn {
  width: 100%; padding: 13px; border-radius: 12px; font-weight: 650; font-size: 15px;
}
.primary-btn { background: var(--brand); color: #fff; }
.primary-btn:disabled { opacity: .55; }
.secondary-btn { background: var(--brand-soft); color: var(--brand); border: 1px solid var(--line); }
.danger-btn { background: transparent; color: var(--danger); border: 1px solid var(--line); margin-top: 10px; }
.save-hint { text-align: center; font-size: 12px; color: var(--ink-3); margin: 10px 0 0; }
.field-note { font-size: 11.5px; color: var(--ink-3); line-height: 1.7; margin: 10px 0 0; }
.search-card { padding: 10px 12px; }
.search-card input { width: 100%; border: 0; background: var(--bg); border-radius: 9px; padding: 9px 11px; outline: none; }

.sync-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.sync-title { font-size: 16px; font-weight: 700; }
.sync-sub { font-size: 12px; color: var(--ink-3); }
.stat-row { display: flex; gap: 8px; margin-bottom: 16px; }
.stat {
  flex: 1; min-width: 0; background: var(--bg); border-radius: 11px; padding: 10px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; overflow: hidden;
}
.stat-label { font-size: 10.5px; color: var(--ink-3); white-space: nowrap; }
.stat strong { font-size: 19px; font-variant-numeric: tabular-nums; max-width: 100%; }
.stat-unit { font-size: 10px; color: var(--ink-3); }
.stat-time { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync-msg { font-size: 12px; color: var(--ink-2); margin: 10px 0 0; min-height: 18px; overflow-wrap: anywhere; }
.config-card h2, .tools-card h2, .account-card h2 { font-size: 14px; margin: 0 0 14px; }

/* ---- v0.4 账号与设备 ---- */
.account-card .seg { margin-bottom: 14px; }
.account-card .seg-btn { font-size: 12.5px; }
.auth-pane { display: none; }
.auth-pane.active { display: block; }
.auth-msg { font-size: 12px; color: var(--danger); min-height: 17px; margin: 10px 0 0; line-height: 1.5; }
.auth-msg.ok { color: var(--brand); }
.alert {
  background: rgba(192,57,43,.10); border: 1px solid rgba(192,57,43,.32);
  color: var(--danger); border-radius: 10px; padding: 10px 12px;
  font-size: 12.5px; line-height: 1.6; margin-bottom: 14px;
}
.account-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.account-avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  background: var(--brand-soft); border: 1px solid var(--line); position: relative;
}
.account-avatar::after {
  content: ''; position: absolute; left: 13px; top: 9px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--brand); opacity: .75;
  box-shadow: 0 12px 0 3px var(--brand);
}
.account-name { font-size: 16px; font-weight: 700; }
.account-sub { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.btn-row { display: flex; gap: 8px; margin-top: 12px; }
.btn-row .secondary-btn { flex: 1; }
.device-list { margin-top: 12px; }
.device-row {
  display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
  padding: 9px 0; border-top: 1px solid var(--line); font-size: 12px;
}
.device-row span { color: var(--ink-3); font-size: 11px; }
.device-row strong { font-weight: 600; }
.device-row .current { color: var(--brand); }
.pw-change { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.pw-change summary { font-size: 13px; color: var(--brand); cursor: pointer; margin-bottom: 12px; }
.pw-change .secondary-btn { width: 100%; }
.diag-card > summary {
  font-size: 13px; font-weight: 650; color: var(--ink-2);
  list-style: none; cursor: pointer;
}
.diag-card > summary::-webkit-details-marker { display: none; }
.diag-card > summary::after { content: ' ▾'; color: var(--brand); }
.diag-card[open] > summary { margin-bottom: 10px; }
.tools-card .secondary-btn { margin-bottom: 2px; }

.tabbar {
  /* v0.7：从 fixed 改成 flex 末项，彻底规避 iOS Safari 地址栏展开时
     fixed 元素按大 layout viewport 定位、要划一下才贴底的问题。
     安全区只作为栏内底部留白，手机/平板明暗主题都用同一套变量。 */
  flex: 0 0 auto;
  position: relative; bottom: auto; left: auto; right: auto;
  width: 100%; max-width: none; margin: 0; z-index: 30;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 0 4px var(--safe-bottom);
  display: flex; align-items: stretch;
  background: var(--card);
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 18px rgba(22,35,58,.05);
}
.tab {
  flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0; font-size: 10px; line-height: 1.1; color: var(--ink-3);
  padding: 0 2px; white-space: nowrap; overflow: hidden;
}
.tab > span:last-child { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.tab.active { color: var(--brand); font-weight: 650; }
.tab-icon { width: 17px; height: 17px; border-radius: 5px; border: 2px solid currentColor; opacity: .85; position: relative; flex: none; }
.icon-home { border-radius: 3px; }
.icon-home::after { content: ''; position: absolute; left: 3px; right: 3px; bottom: 2px; height: 5px; border: 2px solid currentColor; border-top: 0; }
.icon-add::before, .icon-add::after { content: ''; position: absolute; background: currentColor; }
.icon-add::before { left: 7px; top: 3px; width: 2px; height: 9px; }
.icon-add::after { left: 3px; top: 7px; width: 9px; height: 2px; }
.icon-list { border-radius: 4px; }
.icon-list::after { content: ''; position: absolute; left: 3px; right: 3px; top: 4px; height: 2px; background: currentColor; box-shadow: 0 4px 0 currentColor; }
.icon-me { border: 0; opacity: .9; }
.icon-me::before {
  content: ''; position: absolute; left: 4px; top: 0; width: 8px; height: 8px;
  border-radius: 50%; border: 2px solid currentColor;
}
.icon-me::after {
  content: ''; position: absolute; left: 0; bottom: 0; width: 15px; height: 7px;
  border-radius: 8px 8px 3px 3px; border: 2px solid currentColor; border-bottom: 0;
}

/* 窄屏：收紧留白，保证四个页签文字与长数字都不被裁掉 */
@media (max-width: 360px) {
  .main { padding-left: 12px; padding-right: 12px; }
  .brand-tag { display: none; }
  .hero-value { font-size: 29px; }
  .card { padding: 14px; }
  .split-amt { flex-basis: 84px; width: 84px; }
  .row { gap: 6px; }
  .row-del, .row-edit { padding: 5px 6px; font-size: 10.5px; }
  .cat-row { grid-template-columns: 60px minmax(0,1fr) 70px 28px; gap: 6px; }
}

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px); transform: translate(-50%, 12px);
  background: rgba(20, 30, 48, .94); color: #fff; padding: 10px 18px; border-radius: 22px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: .22s ease; z-index: 50;
  max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ================= 多账本：账本切换条 / 记入提示 / 同步范围卡片 ================= */
.book-switch {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.book-switch::-webkit-scrollbar { display: none; }
.book-chip {
  flex: none; display: inline-flex; align-items: center; gap: 7px;
  min-height: 38px; padding: 7px 13px; border-radius: 20px;
  background: var(--card); border: 1px solid var(--line);
  color: var(--ink-2); font-size: 13px; white-space: nowrap;
  box-shadow: var(--shadow); transition: background .16s ease, color .16s ease;
}
.book-chip.active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 650; }
.book-chip.active .book-dot { box-shadow: 0 0 0 2px rgba(255, 255, 255, .7); }
.book-dot {
  width: 9px; height: 9px; border-radius: 50%; flex: none;
  display: inline-block; background: var(--brand);
}
.book-dot.all { background: linear-gradient(140deg, var(--brand), #7f6bf0); }
.hero-opening {
  margin-top: 13px; padding-top: 9px; border-top: 1px dashed var(--line);
  font-size: 11.5px; color: var(--ink-3);
}
.book-current {
  margin: 0 2px 12px; padding: 9px 12px; border-radius: 10px;
  background: var(--brand-soft); color: var(--brand);
  font-size: 12.5px; font-weight: 600;
}
.books-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.books-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
.books-note { margin: 0 0 10px; font-size: 12px; color: var(--ink-3); line-height: 1.6; }
.books-list { display: flex; flex-direction: column; }
.book-row {
  display: flex; align-items: center; gap: 10px; min-height: 48px;
  padding: 9px 4px; border-top: 1px solid var(--line); cursor: pointer;
}
.book-row:first-child { border-top: 0; }
.book-row input { width: 18px; height: 18px; accent-color: var(--brand); flex: none; }
.book-row-main { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.book-row-main strong { font-size: 13.5px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-row-main small { font-size: 11px; color: var(--ink-3); }

/* ---- 新建账本：中性占位、触控目标 ≥44px、明暗主题跟随变量 ---- */
.book-create { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.book-create > .secondary-btn { width: 100%; }
.book-create-form { margin-top: 12px; display: grid; gap: 12px; }
.book-create-form .field { display: flex; flex-direction: column; gap: 6px; }
.book-create-form input[type="color"] {
  width: 100%; height: 44px; padding: 4px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card);
}
.book-create-form .field-note { margin: 0; }

/* ---- 「记一笔」最近账目：手机在表单下方，平板并排右侧（只读） ---- */
.recent-card .section-head { margin-top: 0; }
.recent-list { display: flex; flex-direction: column; }
.recent-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 2px; border-top: 1px solid var(--line); min-width: 0;
}
.recent-row:first-child { border-top: 0; }
.recent-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.recent-dot.income { background: var(--income); }
.recent-dot.expense { background: var(--expense); }
.recent-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.recent-main strong { font-size: 13px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-main small { font-size: 11px; color: var(--ink-3); }
.recent-amount { flex: none; font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; }
.recent-amount.income { color: var(--income); }
.recent-amount.expense { color: var(--expense); }

/* ================= 中屏平板 768–899：独立版式，不是拉宽的手机 =============
   iPad 竖屏 / 安卓小平板：内容两列网格 + 横排底栏，仍保留底栏导航，
   ≥900 才切换成侧栏布局。 */
@media (min-width: 768px) and (max-width: 899px) {
  .app { max-width: 100%; }
  .topbar { padding-left: 24px; padding-right: 24px; }
  .main { padding: 18px 24px 24px; }
  .tabbar { --tabbar-h: 46px; padding-left: 12px; padding-right: 12px; }
  .tab { flex-direction: row; gap: 7px; font-size: 11.5px; }
  #screen-home.active, #screen-sync.active {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 16px; align-items: start;
  }
  #screen-home .page-title, #screen-sync .page-title,
  #screen-home #book-switch { grid-column: 1 / -1; }
  #screen-home .home-left, #screen-home .home-right { grid-column: auto; }
  #screen-home .home-right > .section-head { margin-top: 0; }
  #screen-sync > .card { min-width: 0; }
}

/* ================= 手机端细节：触控目标与表单排布 ================= */
.field input, .field select, .field textarea, .search-card input { min-height: 44px; }
.row-del { min-height: 36px; padding: 6px 10px; }
@media (min-width: 420px) {
  .form-card { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 12px; }
  .form-card > .seg, .form-card > .field, .form-card > .split-box,
  .form-card > .primary-btn, .form-card > .save-hint { grid-column: 1 / -1; }
  .form-card > .date-field, .form-card > #category-field { grid-column: auto; }
}

/* ================= 平板 ≥900px：专属双栏，不是把手机界面拉宽 =================
   左侧固定账本导航 + 页面导航，右侧内容区；底栏在平板上收起，导航走侧栏。 */
.sidebar { display: none; }
@media (min-width: 900px) {
  .app {
    max-width: 1180px;
    display: grid;
    grid-template-columns: 264px minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    background: var(--card);
    box-shadow: 0 0 0 1px var(--line);
  }
  .sidebar {
    display: flex; flex-direction: column;
    grid-column: 1; grid-row: 1 / -1;
    position: sticky; top: 0; height: 100%;
    min-height: 0;
    padding: 22px 16px; background: var(--bg);
    border-right: 1px solid var(--line);
  }
  .side-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 4px 6px 18px; border-bottom: 1px solid var(--line);
  }
  .side-brand .brand-mark { width: 30px; height: 30px; border-radius: 9px; }
  .side-brand strong { display: block; font-size: 16px; }
  .side-brand small { display: block; font-size: 11px; color: var(--ink-3); }
  .side-section { margin-top: 20px; min-height: 0; }
  .side-label { padding: 0 6px 8px; font-size: 11px; font-weight: 700; letter-spacing: .6px; color: var(--ink-3); }
  .side-books { display: flex; flex-direction: column; gap: 4px; max-height: 38vh; overflow-y: auto; }
  .side-book {
    display: flex; align-items: center; gap: 9px; width: 100%;
    padding: 9px 10px; border-radius: 10px; border: 1px solid transparent;
    text-align: left; color: var(--ink-2); font-size: 13px; min-height: 40px;
  }
  .side-book:hover { background: var(--card); }
  .side-book.active { background: var(--brand); color: #fff; font-weight: 650; }
  .side-book > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .side-nav { display: flex; flex-direction: column; gap: 3px; }
  .side-nav .side-nav-item {
    display: flex; flex-direction: row; align-items: center; justify-content: flex-start;
    gap: 10px; width: 100%; min-height: 42px; padding: 10px 12px;
    border-radius: 10px; text-align: left; font-size: 13.5px; color: var(--ink-2);
  }
  .side-nav .side-nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 650; }
  .side-foot {
    display: flex; align-items: center; gap: 8px; margin-top: auto;
    padding: 12px 8px 4px; border-top: 1px solid var(--line);
    font-size: 12px; color: var(--ink-2);
  }
  .topbar { grid-column: 2; grid-row: 1; }
  .offline-bar { grid-column: 2; grid-row: 2; margin: 10px 24px 0; }
  .main { grid-column: 2; grid-row: 3; padding: 20px 24px 30px; }
  .tabbar { display: none !important; }
  .toast { left: calc(50% + 132px) !important; bottom: 24px; }
  #screen-home.active {
    display: grid; grid-template-columns: minmax(250px, .8fr) minmax(0, 1.2fr);
    column-gap: 18px; align-items: start;
  }
  #screen-home #book-switch { grid-column: 1 / -1; }
  #screen-home .home-left { grid-column: 1; }
  #screen-home .home-right { grid-column: 2; }
  #screen-home .home-right > .section-head { margin-top: 0; }
  #screen-add .form-card, #screen-bills .search-card,
  #screen-bills .stats-card, #screen-bills .list, #screen-sync > .card { max-width: 720px; }
}

/* ≥1024px 横屏平板：主从式分栏，绝不是把手机单列拉宽。
   记一笔 = 左表单 + 右最近账目；我页 = 双列卡片网格。 */
@media (min-width: 1024px) {
  #screen-add.active {
    display: grid; grid-template-columns: minmax(0, 1.12fr) minmax(0, .88fr);
    column-gap: 18px; align-items: start;
  }
  #screen-add .page-title, #screen-add #add-book,
  #screen-add .edit-banner { grid-column: 1 / -1; }
  #screen-add .form-card { grid-column: 1; max-width: none; }
  #screen-add .recent-card { grid-column: 2; max-width: none; }
  #screen-sync.active {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 18px; align-items: start;
  }
  #screen-sync .page-title { grid-column: 1 / -1; }
  #screen-sync > .card { min-width: 0; max-width: none; }
}

/* 版本与更新：沿用 .card / .kv / .alert 的主题变量，明暗两套自动适配。 */
.update-status {
  margin: 12px 0 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--brand-soft);
  color: var(--ink-2);
  font-size: 12.5px;
  line-height: 1.65;
}
.update-status.has-update { border-color: var(--brand); color: var(--brand); }
.update-status.is-error { background: transparent; color: var(--warn); }
.update-card .secondary-btn { margin-top: 10px; }

/* ---- 首页统计入口 / 修改横幅 / 收支统计 ----
   与 v0.6.x 一样只用主题变量，不写死颜色，明暗两套与平板宽度自动适配。 */
.hero-link {
  display: block; margin-top: 12px; padding: 0; width: 100%;
  color: var(--brand); font-size: 12.5px; font-weight: 650; text-align: left;
}
.edit-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  flex-wrap: wrap; margin-bottom: 12px; padding: 10px 12px;
  border: 1px solid var(--brand); border-radius: 12px;
  background: var(--brand-soft); color: var(--brand); font-size: 12.5px;
}
.edit-banner[hidden] { display: none; }
.edit-banner .link-btn { font-size: 12px; font-weight: 650; }

.stats-card { padding: 16px; margin-top: 12px; }
.stats-card .section-head { margin: 0 2px 12px; }
.stat-dir { margin-bottom: 12px; }
.stat-dir .seg-btn { font-size: 12.5px; padding: 7px 0; }
.stat-month-field { margin-bottom: 14px; }
.stat-month-field select {
  width: 100%; box-sizing: border-box; background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 11px; font-size: 14px; outline: none;
}
.stats-trend {
  display: flex; align-items: flex-end; gap: 10px;
  min-height: 92px; padding: 6px 2px 4px; overflow: hidden;
}
.trend-col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 5px; }
.trend-bars { display: flex; align-items: flex-end; justify-content: center; gap: 4px; height: 68px; width: 100%; }
.trend-bar { display: block; width: 12px; max-width: 40%; border-radius: 4px 4px 2px 2px; }
.trend-bar.income { background: var(--income); }
.trend-bar.expense { background: var(--expense); }
.trend-label { font-size: 10.5px; color: var(--ink-3); white-space: nowrap; }
.stats-cats { margin-top: 12px; display: flex; flex-direction: column; gap: 9px; }
.cat-row {
  display: grid; grid-template-columns: 68px minmax(0, 1fr) 76px 32px;
  align-items: center; gap: 8px; font-size: 11.5px; min-width: 0;
}
.cat-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.cat-track { display: block; height: 8px; border-radius: 5px; background: var(--bg); overflow: hidden; }
.cat-fill { display: block; height: 100%; border-radius: 5px; background: var(--brand); }
.cat-amount { text-align: right; font-variant-numeric: tabular-nums; font-size: 11.5px; }
.cat-pct { text-align: right; color: var(--ink-3); font-size: 10.5px; }
.stats-empty { width: 100%; text-align: center; padding: 12px 0; font-size: 12px; color: var(--ink-3); }
