:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --ink: #171a26;
  --ink-2: #4a4f5e;
  --muted: #8b909f;
  --line: #eceef3;
  --accent: #3355d8;
  --accent-soft: #e9edfb;
  --up: #e5473b;
  --down: #24a56e;
  --warn-bg: #fff4e5;
  --warn-ink: #9a5b00;
  --pill-bg: #f0f1f5;
  --ok-bg: #e6f6ee; --ok-ink: #1c7c4f;
  --bad-bg: #fdecea; --bad-ink: #b3261e;
  --shadow: 0 1px 2px rgba(23, 26, 38, .06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1116; --surface: #181b22; --surface-2: #1f232c; --ink: #e9ebf1; --ink-2: #b8bcc8; --muted: #7f8494;
    --line: #262a34; --accent: #6b86f0; --accent-soft: #232b48; --up: #ff6b5e; --down: #3fc98a;
    --warn-bg: #3a2a10; --warn-ink: #f2c56b; --pill-bg: #242832; --shadow: none;
    --ok-bg: #16321f; --ok-ink: #6bd39a; --bad-bg: #3a1a18; --bad-ink: #ff8a80;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1116; --surface: #181b22; --surface-2: #1f232c; --ink: #e9ebf1; --ink-2: #b8bcc8; --muted: #7f8494;
  --line: #262a34; --accent: #6b86f0; --accent-soft: #232b48; --up: #ff6b5e; --down: #3fc98a;
  --warn-bg: #3a2a10; --warn-ink: #f2c56b; --pill-bg: #242832; --shadow: none;
    --ok-bg: #16321f; --ok-ink: #6bd39a; --bad-bg: #3a1a18; --bad-ink: #ff8a80;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
.num { font-variant-numeric: tabular-nums; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }
.muted { color: var(--muted); }
.hidden { display: none !important; }

#app { max-width: 640px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(64px + var(--safe-bottom)); }
.loading { padding: 40vh 0 0; text-align: center; color: var(--muted); }

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + var(--safe-top)) 16px 10px; background: var(--bg);
}
.topbar h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: .02em; }
.topbar .sub { font-size: 12px; color: var(--muted); margin-left: 8px; font-weight: 400; }
.iconbtn {
  border: 0; background: var(--surface); box-shadow: var(--shadow); border-radius: 10px;
  width: 36px; height: 36px; display: inline-grid; place-items: center; color: var(--ink-2);
}
.iconbtn:active { background: var(--surface-2); }
.iconbtn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .iconbtn.spin svg { animation: none; } }

/* 卡片 */
.card { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); margin: 0 12px 12px; }
.hero { padding: 18px 18px 14px; display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; align-items: end; }
.hero .label { font-size: 12px; color: var(--muted); }
.hero .total { font-size: 32px; font-weight: 700; letter-spacing: -.01em; line-height: 1.1; margin-top: 4px; }
.hero .today { text-align: right; }
.hero .today .v { font-size: 22px; font-weight: 600; line-height: 1.1; margin-top: 4px; }
.hero .today .p { font-size: 12px; margin-top: 2px; }
.hero .foot { grid-column: 1 / -1; display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; margin-top: 6px; }

.periods { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 0 12px 12px; }
.period { background: var(--surface); border-radius: 12px; padding: 10px 8px; text-align: center; box-shadow: var(--shadow); }
.period .l { font-size: 11px; color: var(--muted); }
.period .v { font-size: 15px; font-weight: 600; margin-top: 2px; }
.period .r { font-size: 11px; margin-top: 1px; }

/* 提醒 */
.alert { margin: 0 12px 12px; background: var(--warn-bg); color: var(--warn-ink); border-radius: 12px; padding: 10px 14px; font-size: 13px; }
.alert b { display: block; margin-bottom: 2px; }
.alert .t { opacity: .8; font-size: 12px; }

/* 持仓表 */
.holdings { overflow: hidden; }
.thead, .row {
  display: grid; grid-template-columns: 1fr 96px 104px; align-items: center; gap: 8px; padding: 0 14px;
}
.thead { height: 34px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }
.thead .c, .row .c { text-align: right; }
.row { min-height: 66px; padding-top: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); cursor: pointer; }
.row:last-child { border-bottom: 0; }
.row:active { background: var(--surface-2); }
.row .name { font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: 12px; color: var(--muted); margin-top: 3px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row .c .a { font-size: 16px; font-weight: 600; }
.row .c .b { font-size: 12px; margin-top: 2px; }
.tag { display: inline-block; font-size: 10px; line-height: 16px; padding: 0 5px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); }
.tag.est { background: var(--pill-bg); color: var(--muted); }
.tag.sell { background: var(--warn-bg); color: var(--warn-ink); }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); font-size: 14px; }
.empty .cta { margin-top: 10px; }

/* 底部标签栏 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.tabbar .inner { max-width: 640px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); }
.tabbar button {
  border: 0; background: none; padding: 8px 0 6px; display: grid; justify-items: center; gap: 2px;
  color: var(--muted); font-size: 11px;
}
.tabbar button.on { color: var(--accent); }
.tabbar svg { width: 24px; height: 24px; }

/* 通用列表 */
.list { padding: 0; }
.item { display: flex; justify-content: space-between; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .l { min-width: 0; flex: 1; }
.item .r { text-align: right; flex-shrink: 0; }
.item .t { font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .s { font-size: 12px; color: var(--muted); margin-top: 3px; }
.item .v { font-size: 16px; font-weight: 600; }
.item .w { font-size: 12px; color: var(--muted); margin-top: 3px; }
.pill { display: inline-block; font-size: 11px; line-height: 18px; padding: 0 7px; border-radius: 9px; background: var(--pill-bg); color: var(--ink-2); vertical-align: middle; }
.pill.ok { background: var(--ok-bg); color: var(--ok-ink); }
.pill.warn { background: var(--warn-bg); color: var(--warn-ink); }
.pill.bad { background: var(--bad-bg); color: var(--bad-ink); }
.pill.info { background: var(--accent-soft); color: var(--accent); }

.section-h { display: flex; justify-content: space-between; align-items: center; padding: 6px 16px 8px; font-size: 13px; color: var(--muted); }
.section-h b { color: var(--ink); font-weight: 600; font-size: 15px; }

/* 按钮与表单 */
.btn { border: 0; border-radius: 10px; padding: 10px 16px; background: var(--accent); color: #fff; font-weight: 600; font-size: 15px; }
.btn.secondary { background: var(--pill-bg); color: var(--ink); }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn.danger { background: transparent; color: var(--up); }
.btn:disabled { opacity: .5; }
.form { padding: 4px 14px 14px; display: grid; gap: 10px; }
.field { display: grid; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 16px;
}
.field input:focus, .field textarea:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field textarea { min-height: 96px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.suggest { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.suggest div { padding: 8px 12px; font-size: 13px; border-bottom: 1px solid var(--line); cursor: pointer; }
.suggest div:last-child { border-bottom: 0; }
.suggest div:active { background: var(--surface-2); }
.actions { display: flex; gap: 10px; justify-content: flex-end; }
.msg { font-size: 13px; padding: 8px 12px; border-radius: 8px; background: var(--surface-2); }
.msg.bad { color: var(--up); }
.msg.ok { color: var(--down); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; word-break: break-all; }
pre.mono { white-space: pre-wrap; background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; padding: 10px 14px; }
.kv .k { color: var(--muted); }
.sms-text { font-size: 13px; color: var(--ink-2); margin-top: 6px; line-height: 1.5; }

/* 详情页(全屏面板) */
.sheet {
  position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch;
  animation: slide .22s ease-out;
}
@keyframes slide { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.sheet .inner { max-width: 640px; margin: 0 auto; padding-bottom: calc(24px + var(--safe-bottom)); }
.sheet .topbar h1 { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 70vw; }
.summary { padding: 16px 18px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 8px; }
.summary .k { font-size: 11px; color: var(--muted); }
.summary .v { font-size: 17px; font-weight: 600; margin-top: 2px; }
.summary .v small { font-size: 11px; font-weight: 400; margin-left: 2px; }
.chart-wrap { padding: 8px 10px 4px; }
canvas.chart { width: 100%; height: 200px; display: block; }
.ranges { display: flex; gap: 6px; padding: 8px 14px 14px; }
.ranges button { flex: 1; border: 0; background: var(--pill-bg); color: var(--ink-2); border-radius: 8px; padding: 6px 0; font-size: 12px; }
.ranges button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chart-legend { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); padding: 0 14px; }

/* 更多页 */
.about p { margin: 0 0 8px; font-size: 13px; color: var(--ink-2); line-height: 1.6; }
.about ol { margin: 0; padding-left: 18px; font-size: 13px; color: var(--ink-2); line-height: 1.7; }
.setup { padding: 20vh 24px 0; text-align: center; }
.setup h2 { margin: 0 0 6px; }
.setup p { color: var(--muted); font-size: 14px; }
.setup .field { text-align: left; margin: 18px 0 12px; }
.toast { position: fixed; left: 50%; bottom: calc(80px + var(--safe-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 10px; font-size: 13px; z-index: 30; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: .95; }
