:root {
  --canvas: #EDF0F3;
  --surface: #FFFFFF;
  --sunk: #F5F7F9;
  --ink: #18202C;
  --muted: #677180;
  --line: #D9DFE6;
  --spend: #3E5C8A;
  --spend-soft: #DCE4F0;
  --rev: #17876B;
  --rev-soft: #D5EDE5;
  --warn: #A86A10;
  --loss: #B4343F;
  --focus: #2F6FDB;
  --r-sm: 6px;
  --r-md: 10px;
  color-scheme: light;
  font-family: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}
@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #12161C; --surface: #1A2029; --sunk: #151A21; --ink: #E5E9EF; --muted: #8A94A3; --line: #2B333F;
    --spend: #84A3D6; --spend-soft: #26324A; --rev: #3EC39B; --rev-soft: #173A31; --warn: #E2AA4D; --loss: #EA6B76; --focus: #6EA0FF;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
[hidden] { display: none !important; }
.num, td.n, .n { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.err { color: var(--loss); min-height: 1.2em; margin: 4px 0; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: 0; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* 标识：三根柱子 + 回本虚线 */
.brand-mark { position: relative; width: 26px; height: 22px; display: flex; align-items: flex-end; gap: 3px; }
.brand-mark span { width: 6px; background: var(--rev); border-radius: 2px 2px 0 0; }
.brand-mark span:nth-child(1) { height: 45%; background: var(--spend); }
.brand-mark span:nth-child(2) { height: 100%; }
.brand-mark span:nth-child(3) { height: 70%; }
.brand-mark::after { content: ""; position: absolute; left: -3px; right: -3px; top: 38%; border-top: 1.5px dashed var(--ink); opacity: .55; }
.brand-mark.big { transform: scale(1.6); transform-origin: left bottom; margin: 0 0 18px 2px; }

/* 登录 */
#auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 32px 28px; }
.auth-card h1 { margin-bottom: 4px; }
.auth-card .muted { margin: 0 0 18px; }

/* 布局 */
#app { display: grid; grid-template-columns: 196px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--surface); padding: 18px 12px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 22px; font-size: 16px; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
nav a { color: var(--ink); text-decoration: none; padding: 8px 10px; border-radius: var(--r-sm); }
nav a:hover { background: var(--sunk); }
nav a.on { background: var(--rev-soft); color: var(--rev); font-weight: 600; }
.me { border-top: 1px solid var(--line); padding: 12px 8px 0; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.me > div { width: 100%; display: flex; gap: 8px; align-items: baseline; }
main { padding: 24px 32px 64px; min-width: 0; max-width: 1280px; outline: none; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; margin-bottom: 18px; }
.page-head h1 { margin-right: auto; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 18px 20px; margin-bottom: 18px; }
.panel-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head h2 { margin-right: auto; }
.cols { display: grid; grid-template-columns: 1.5fr 1fr; gap: 18px; }
.cols > .panel { margin-bottom: 0; min-width: 0; }

/* 控件 */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 6px 9px; min-height: 34px; }
input[type=number] { text-align: right; font-variant-numeric: tabular-nums; }
textarea { width: 100%; min-height: 160px; resize: vertical; font-family: inherit; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { color: var(--muted); font-size: 13px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 34px; padding: 6px 14px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--sunk); }
.btn.primary { background: var(--rev); border-color: var(--rev); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--loss); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.wide { width: 100%; }
.btn.sm { min-height: 28px; padding: 2px 10px; font-size: 13px; }
.link { background: none; border: 0; padding: 0; color: var(--focus); cursor: pointer; }
.link.danger { color: var(--loss); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 6px 12px; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--ink); color: var(--surface); }
.range { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.range .custom { display: inline-flex; gap: 6px; align-items: center; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* 指标条：一行读完的账户汇总 */
.strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(130px, 45%), 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); margin-bottom: 18px; }
.strip > div { padding: 14px 18px; border-right: 1px solid var(--line); }
.strip > div:last-child { border-right: 0; }
.strip small { display: block; color: var(--muted); font-size: 12.5px; }
.strip > div > b { display: block; font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.3; margin-top: 2px; }
.strip .roi { flex-direction: row-reverse; justify-content: flex-end; margin-top: 2px; }
.strip .roi b { font-size: 22px; text-align: left; min-width: 0; }
.rows th.n { width: 150px; }
td.nowrap { white-space: nowrap; }
.strip .k-spend b { color: var(--spend); }
.strip .k-rev b { color: var(--rev); }

/* ROI：回本条，刻度 1.0 处一根竖线 */
.roi { display: inline-flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.roi i { position: relative; width: 64px; height: 6px; border-radius: 3px; background: var(--sunk); box-shadow: inset 0 0 0 1px var(--line); overflow: visible; }
.roi i em { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; }
.roi i::after { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1.5px; background: var(--ink); opacity: .6; }
.roi b { font-weight: 600; min-width: 3.2em; text-align: right; }
.roi.g b { color: var(--rev); } .roi.g em { background: var(--rev); }
.roi.w b { color: var(--warn); } .roi.w em { background: var(--warn); }
.roi.l b { color: var(--loss); } .roi.l em { background: var(--loss); }
.roi.z b { color: var(--muted); font-weight: 400; }

/* 表格 */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 13px; white-space: nowrap; background: var(--sunk); }
th.sort { cursor: pointer; user-select: none; }
th.sort.on::after { content: attr(data-dir); margin-left: 4px; }
td.n, th.n { text-align: right; white-space: nowrap; }
tr.total td { font-weight: 600; background: var(--sunk); }
tbody tr:hover td { background: color-mix(in srgb, var(--sunk) 70%, transparent); }
.code { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.name-cell { max-width: 320px; }
.tag { display: inline-block; font-size: 12px; padding: 0 6px; border-radius: 4px; background: var(--spend-soft); color: var(--spend); margin-right: 6px; }

/* 录入 */
.entry-top { display: grid; grid-template-columns: repeat(3, minmax(140px, 1fr)) 1.4fr; gap: 14px; align-items: end; }
.entry-top .calc { display: flex; flex-direction: column; gap: 6px; padding-bottom: 6px; }
.daypick { display: inline-flex; align-items: center; gap: 6px; }
.daypick input { font-size: 16px; font-weight: 600; }
.rows td input { width: 100%; }
.rows td.del { width: 40px; text-align: center; }
.rows input.name { min-width: 240px; }
.check { margin-top: 12px; padding: 10px 14px; border-radius: var(--r-sm); background: var(--sunk); display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; }
.check.bad { background: color-mix(in srgb, var(--warn) 14%, var(--surface)); }
.savebar { position: sticky; bottom: 0; display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding: 12px 0; background: linear-gradient(transparent, var(--canvas) 30%); }
.savebar .muted { margin-right: auto; }

/* 每日明细 */
.day { padding: 14px 20px; }
.day-head { display: flex; flex-wrap: wrap; gap: 6px 22px; align-items: baseline; margin-bottom: 8px; }
.day-head h2 { min-width: 120px; }
.day-head .kv small { color: var(--muted); margin-right: 6px; }
.day-head .act { margin-left: auto; display: flex; gap: 12px; }
.day table td, .day table th { padding: 6px 10px; }

.chart-box { position: relative; height: 320px; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .btn { margin-top: 12px; }
.pill { display: inline-block; padding: 0 8px; border-radius: 99px; font-size: 12px; background: var(--sunk); border: 1px solid var(--line); }
.pill.warn { color: var(--warn); border-color: currentColor; background: transparent; }
.pill.ok { color: var(--rev); border-color: currentColor; background: transparent; }
.progress { height: 6px; border-radius: 3px; background: var(--sunk); overflow: hidden; margin: 10px 0; }
.progress > div { height: 100%; background: var(--rev); width: 0; transition: width .2s; }

dialog { border: 1px solid var(--line); border-radius: var(--r-md); padding: 0; background: var(--surface); color: var(--ink); width: min(460px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 14, 20, .45); }
dialog form { padding: 22px 24px; }
dialog h2 { margin-bottom: 14px; }
dialog .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; transition: .2s; background: var(--ink); color: var(--surface); padding: 9px 16px; border-radius: var(--r-sm); pointer-events: none; z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--loss); color: #fff; }

@media (max-width: 900px) {
  #app { grid-template-columns: minmax(0, 1fr); }
  .side { position: sticky; top: 0; z-index: 10; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top, 0px)); gap: 6px; }
  .brand { padding: 0 8px 0 0; }
  nav { flex-direction: row; overflow-x: auto; flex: 1 1 100%; order: 3; }
  nav a { white-space: nowrap; padding: 6px 10px; }
  .me { border: 0; padding: 0; margin-left: auto; }
  .me > div { display: none; }
  main { padding: 16px 14px 48px; }
  .cols, .entry-top { grid-template-columns: 1fr; }
  .strip > div { border-bottom: 1px solid var(--line); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
