:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --line: #e6e9f1;
  --line-2: #f1f3f8;
  --ink: #141a2e;
  --ink-2: #5a657c;
  --ink-3: #8c96ac;
  --brand: #2b4fd8;
  --brand-2: #3f63f0;
  --brand-soft: #edf1ff;
  --up: #d93a2b;
  --up-soft: #fdeeeb;
  --down: #129a5f;
  --down-soft: #e9f7f0;
  --c1: #2f6bff;
  --c2: #12a594;
  --c3: #7c5cfc;
  --c4: #f2994a;
  --c5: #e5484d;
  --c6: #0ea5e9;
  --c7: #16a34a;
  --c8: #c026d3;
  --c9: #64748b;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 26, 46, .05), 0 10px 30px -18px rgba(20, 26, 46, .3);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }

.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

/* ---------- boot ---------- */
.boot {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--ink-3); font-size: 14px; letter-spacing: .04em;
}

/* ---------- layout ---------- */
.app { max-width: 900px; margin: 0 auto; padding: 0 16px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 2px 12px;
}
.topbar .brand { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.topbar .company { font-size: 17px; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { font-size: 12px; color: var(--ink-3); letter-spacing: .02em; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--brand-soft); color: var(--brand);
  display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600;
  border: none; cursor: pointer; flex: 0 0 auto;
}

.main { padding-bottom: 24px; display: flex; flex-direction: column; gap: 14px; }

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex; gap: 2px; padding: 6px;
  background: rgba(255, 255, 255, .92); backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow);
  z-index: 40;
}
.tabbar button {
  border: none; background: transparent; color: var(--ink-3);
  font-size: 13px; font-weight: 500; padding: 9px 15px; border-radius: 999px;
  cursor: pointer; white-space: nowrap; font-family: inherit;
}
.tabbar button.on { background: var(--brand); color: #fff; }

/* ---------- card ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-head h3 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: .01em; }
.card-head .hint { font-size: 12px; color: var(--ink-3); }

/* ---------- hero ---------- */
.hero {
  position: relative; overflow: hidden; border: none; color: #fff;
  background: linear-gradient(135deg, #1a2456 0%, #2b4fd8 58%, #4a6bf5 100%);
  padding: 22px 20px 18px;
}
.hero::after {
  content: ''; position: absolute; right: -46px; top: -70px; width: 200px; height: 200px;
  background: radial-gradient(circle, rgba(255, 255, 255, .22), rgba(255, 255, 255, 0) 68%);
  border-radius: 50%; pointer-events: none;
}
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; position: relative; }
.hero-top .label { font-size: 13px; color: rgba(255, 255, 255, .75); letter-spacing: .02em; }
.hero-num { font-size: 40px; font-weight: 600; letter-spacing: -.03em; line-height: 1.16; margin: 8px 0 2px; color: #fff; position: relative; }
.hero-num .cur { font-size: 22px; font-weight: 500; color: rgba(255, 255, 255, .72); margin-right: 2px; }
.hero-meta { font-size: 12px; color: rgba(255, 255, 255, .72); display: flex; flex-wrap: wrap; gap: 10px; position: relative; }
.hero-meta b { color: #fff; font-weight: 500; }
.hero .badge.up { background: rgba(255, 255, 255, .18); color: #ffd9d4; }
.hero .badge.down { background: rgba(255, 255, 255, .18); color: #c6f2da; }
.hero .badge.flat { background: rgba(255, 255, 255, .16); color: #e8ecff; }

.badge {
  font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 7px;
  display: inline-flex; align-items: center; gap: 3px; font-variant-numeric: tabular-nums;
}
.badge.up { color: var(--up); background: var(--up-soft); }
.badge.down { color: var(--down); background: var(--down-soft); }
.badge.flat { color: var(--ink-3); background: var(--line-2); }

/* ---------- range pills ---------- */
.pills { display: flex; gap: 6px; overflow-x: auto; padding: 2px; scrollbar-width: none; }
.pills::-webkit-scrollbar { display: none; }
.pills button {
  border: 1px solid var(--line); background: var(--card); color: var(--ink-2);
  font-size: 13px; padding: 7px 14px; border-radius: 999px; cursor: pointer; white-space: nowrap;
  font-family: inherit; font-weight: 500;
}
.pills button.on { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 4px 12px -6px rgba(43, 79, 216, .8); }

/* ---------- tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.tile {
  position: relative; overflow: hidden;
  background: var(--card); border: 1px solid var(--line); border-radius: 13px;
  padding: 14px 12px 11px; display: flex; flex-direction: column; gap: 4px; min-width: 0;
  box-shadow: 0 1px 2px rgba(20, 26, 46, .04);
}
.tile::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--dot, var(--brand)); opacity: .9;
}
.tile .t-label { font-size: 12px; color: var(--ink-3); }
.tile .t-num { font-size: 19px; font-weight: 600; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .t-sub { font-size: 11px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 560px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .hero-num { font-size: 34px; }
}

/* ---------- bars ---------- */
.bars { display: flex; flex-direction: column; gap: 13px; }
.bar-row { display: flex; flex-direction: column; gap: 6px; cursor: pointer; }
.bar-row.static { cursor: default; }
.bar-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.bar-name { font-size: 13.5px; font-weight: 500; display: flex; align-items: center; gap: 6px; min-width: 0; }
.bar-name .caret { color: var(--ink-3); font-size: 10px; transition: transform .15s; }
.bar-name.open .caret { transform: rotate(90deg); }
.bar-amt { font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-amt small { font-weight: 400; color: var(--ink-3); font-size: 11px; margin-left: 5px; }
.bar-track { height: 7px; background: var(--line-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--bar, var(--brand)); border-radius: 999px; }
.bar-fill.dim { opacity: .45; }
.cat-dot {
  width: 7px; height: 7px; border-radius: 2px; flex: 0 0 auto;
  background: var(--bar, var(--brand)); display: inline-block; margin-right: 7px;
  vertical-align: 1px;
}
.subrows { display: flex; flex-direction: column; gap: 8px; padding: 10px 0 2px 12px; border-left: 2px solid var(--line-2); margin-top: 2px; }

/* ---------- trend ---------- */
.trend { width: 100%; overflow: visible; display: block; }
.trend .line { fill: none; stroke: var(--brand); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.trend .area { fill: var(--brand); opacity: .07; }
.trend .dot { fill: var(--brand); }
.trend .axis { fill: var(--ink-3); font-size: 9px; }

/* ---------- list ---------- */
.list { display: flex; flex-direction: column; }
.day-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 14px 2px 6px; font-size: 12px; color: var(--ink-3);
}
.day-head b { color: var(--ink-2); font-weight: 600; font-variant-numeric: tabular-nums; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 12px 2px;
  border-bottom: 1px solid var(--line-2); cursor: pointer;
}
.item:last-child { border-bottom: none; }
.item .i-main { flex: 1; min-width: 0; }
.item .i-name { font-size: 14px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.item .i-sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .i-amt { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tag {
  font-size: 11px; color: var(--ink-3); background: var(--line-2);
  padding: 1px 6px; border-radius: 5px; font-weight: 400;
}

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label { font-size: 12px; color: var(--ink-2); font-weight: 500; }
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.label-row > label { font-size: 12px; color: var(--ink-2); font-weight: 500; }
.mini {
  border: none; background: var(--brand-soft); color: var(--brand); font-family: inherit;
  font-size: 12px; font-weight: 500; padding: 4px 9px; border-radius: 7px; cursor: pointer;
}
.mini.plain { background: transparent; color: var(--ink-2); border: 1px solid var(--line); }
.mini.danger { background: var(--up-soft); color: var(--up); }
.sub-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 0; border-bottom: 1px dashed var(--line-2); font-size: 13px;
}
.sub-item:last-child { border-bottom: none; }
.sub-item .acts { display: flex; gap: 6px; flex: 0 0 auto; }
.log-item { padding: 13px 0; border-bottom: 1px solid var(--line-2); }
.log-item:last-child { border-bottom: none; }
.log-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 13px; }
.log-top b { font-weight: 600; }
.log-what { color: var(--ink-2); margin-left: 6px; }
.log-time { color: var(--ink-3); font-size: 11.5px; white-space: nowrap; }
.diff { margin-top: 8px; display: flex; flex-direction: column; gap: 5px; }
.diff-row { display: flex; gap: 8px; font-size: 12.5px; line-height: 1.55; }
.diff-k { color: var(--ink-3); min-width: 54px; flex: 0 0 auto; }
.diff-from { color: var(--ink-3); text-decoration: line-through; }
.diff-arrow { color: var(--ink-3); margin: 0 5px; }
.diff-to { color: var(--ink); font-weight: 600; }
.log-empty { color: var(--ink-3); font-size: 12.5px; }
input, select, textarea {
  font-family: inherit; font-size: 15px; color: var(--ink);
  border: 1px solid var(--line); background: #fff; border-radius: 11px;
  padding: 11px 12px; width: 100%; outline: none; transition: border-color .15s;
  -webkit-appearance: none; appearance: none;
}
select { 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) 50%, calc(100% - 12px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); }
input::placeholder, textarea::placeholder { color: #b6bec6; }

.amount-input {
  font-size: 34px; font-weight: 600; letter-spacing: -.02em; padding: 10px 14px;
  text-align: left; font-variant-numeric: tabular-nums;
}
.amount-wrap { position: relative; }
.amount-wrap .cur { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); font-size: 22px; color: var(--ink-3); font-weight: 500; }
.amount-wrap input { padding-left: 36px; }

.btn {
  border: none; background: var(--brand); color: #fff; font-family: inherit;
  font-size: 15px; font-weight: 500; padding: 13px 18px; border-radius: 12px; cursor: pointer;
  width: 100%; letter-spacing: .02em;
}
.btn:active { opacity: .88; }
.btn.ghost { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.btn.soft { background: var(--brand-soft); color: var(--brand); }
.btn.danger { background: var(--up-soft); color: var(--up); }
.btn.sm { width: auto; padding: 8px 13px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { width: auto; flex: 1; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 28px 22px 60px; max-width: 420px; margin: 0 auto; }
.auth h1 { font-size: 26px; font-weight: 600; letter-spacing: -.02em; margin: 0 0 6px; }
.auth p.sub { color: var(--ink-3); font-size: 13.5px; margin: 0 0 26px; }
.auth .err { color: var(--up); font-size: 13px; margin: -6px 0 12px; }

/* ---------- report ---------- */
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.metric { background: var(--card); border: 1px solid var(--line); border-radius: 13px; padding: 13px; }
.metric .m-label { font-size: 12px; color: var(--ink-3); }
.metric .m-num { font-size: 20px; font-weight: 600; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
@media (max-width: 560px) { .metrics { grid-template-columns: repeat(2, 1fr); } }

.narrative { font-size: 14px; line-height: 1.78; color: #263038; white-space: pre-wrap; }
.narrative strong { font-weight: 600; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line-2); font-size: 13.5px; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--ink-2); }
.kv .v { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- misc ---------- */
.empty { text-align: center; color: var(--ink-3); font-size: 13.5px; padding: 34px 10px; }
.seg { display: flex; gap: 4px; background: var(--line-2); padding: 4px; border-radius: 11px; }
.seg button { flex: 1; border: none; background: transparent; font-family: inherit; font-size: 13px; padding: 8px 4px; border-radius: 8px; color: var(--ink-2); cursor: pointer; }
.seg button.on { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.06); }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.muted { color: var(--ink-3); font-size: 12.5px; }
.section-title { font-size: 12px; color: var(--ink-3); letter-spacing: .06em; text-transform: uppercase; margin: 6px 2px 0; }

/* toast */
.toast {
  position: fixed; left: 50%; transform: translate(-50%, 20px);
  bottom: calc(92px + env(safe-area-inset-bottom)); background: #1b2228; color: #fff;
  font-size: 13.5px; padding: 11px 16px; border-radius: 11px; opacity: 0; pointer-events: none;
  transition: all .22s; z-index: 90; max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(18, 22, 26, .34); display: flex; align-items: flex-end; justify-content: center; z-index: 80; padding: 0; }
.modal-body {
  background: #fff; width: 100%; max-width: 480px; border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
  animation: sheet .22s ease-out;
}
@keyframes sheet { from { transform: translateY(14px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-head button { border: none; background: transparent; font-size: 20px; color: var(--ink-3); cursor: pointer; line-height: 1; padding: 4px; }

@media print {
  body { padding: 0; background: #fff; }
  .tabbar, .topbar, .pills, .btn, .no-print { display: none !important; }
  .card { box-shadow: none; border-color: #ddd; break-inside: avoid; }
}
