/* 布局：顶部汇总，下方左侧固定录入表单、右侧账目明细；手机上表单收进“记一笔”。系统字体，不加载外部资源。 */
:root {
  --bg: #f1f5f4;
  --surface: #ffffff;
  --surface-2: #e8efed;
  --fg: #14211f;
  --muted: #566763;
  --line: #d6e0de;
  --accent: #0f5c55;
  --accent-fg: #ffffff;
  --in: #17743f;
  --out: #b0412a;
  --void: #8a9693;
  --focus: #0f5c55;
  --font-body: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1514;
    --surface: #152120;
    --surface-2: #1d2d2b;
    --fg: #e5eeec;
    --muted: #92a5a1;
    --line: #263634;
    --accent: #4fc2b5;
    --accent-fg: #06201d;
    --in: #55c98a;
    --out: #f0896f;
    --void: #6f807c;
    --focus: #4fc2b5;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1514;
  --surface: #152120;
  --surface-2: #1d2d2b;
  --fg: #e5eeec;
  --muted: #92a5a1;
  --line: #263634;
  --accent: #4fc2b5;
  --accent-fg: #06201d;
  --in: #55c98a;
  --out: #f0896f;
  --void: #6f807c;
  --focus: #4fc2b5;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  padding-block: 20px 40px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.wrap { max-width: 1080px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.num { font-variant-numeric: tabular-nums; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

header.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
h1 { font-size: 24px; line-height: 1.2; margin: 0; font-weight: 700; text-wrap: balance; }
.sub { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.who { color: var(--muted); font-size: 13px; }

.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; font-weight: 500; min-height: 38px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn.danger { color: var(--out); }
.only-mobile { display: none; }

.notice { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; font-size: 13px; color: var(--muted); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters select, .filters input {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-height: 38px; min-width: 0;
}
.filters input[type=search] { flex: 1 1 160px; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; min-width: 0; }
.tile .label { font-size: 12px; color: var(--muted); letter-spacing: .04em; }
.tile .value { font-size: 26px; font-weight: 600; margin-top: 2px; overflow-wrap: anywhere; }
.tile.in .value { color: var(--in); }
.tile.out .value { color: var(--out); }
.tile .value.neg { color: var(--out); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; min-width: 0; }
.panel h2 { font-size: 15px; margin: 0 0 10px; font-weight: 600; }
.panel .hint { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.hand { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.hand-item { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; min-width: 0; }
.hand-item .who2 { font-weight: 600; }
.hand-item .bal { font-size: 18px; font-weight: 600; margin: 2px 0; overflow-wrap: anywhere; }
.hand-item .det { font-size: 12px; color: var(--muted); }

.cols { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; align-items: start; }
.form-panel { position: sticky; top: 16px; }
form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label, .field .lab { font-size: 12.5px; color: var(--muted); }
.field input[type=text], .field input[type=password], .field input[type=date], .field select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 40px; width: 100%; min-width: 0;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg label { margin: 0; cursor: pointer; position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 9px 8px; font-weight: 500; color: var(--fg); background: var(--bg); }
.seg input:checked + span { background: var(--accent); color: var(--accent-fg); }
.seg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: -2px; }
.form-actions { display: flex; gap: 8px; }
.form-actions .primary { flex: 1; }
.msg { font-size: 13px; min-height: 18px; color: var(--out); }
.msg.ok { color: var(--in); }

.list-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.list-head h2 { margin: 0; }
.count { font-size: 12.5px; color: var(--muted); }
ul.entries, ul.audit { list-style: none; margin: 0; padding: 0; }
.entry {
  display: grid; grid-template-columns: 92px minmax(0, 1fr) auto; gap: 4px 12px;
  padding: 12px 0; border-top: 1px solid var(--line); align-items: start;
}
.entry:first-child { border-top: 0; }
.entry .date { color: var(--muted); font-size: 13px; padding-top: 1px; }
.entry .main { min-width: 0; }
.entry .cat { font-weight: 600; overflow-wrap: anywhere; }
.entry .meta { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.entry .amt { font-weight: 600; text-align: right; font-size: 16px; white-space: nowrap; }
.entry.in .amt { color: var(--in); }
.entry.out .amt { color: var(--out); }
.entry .acts { grid-column: 2 / 4; display: flex; gap: 6px; flex-wrap: wrap; }
.entry.void .cat, .entry.void .amt { text-decoration: line-through; color: var(--void); }
.badge { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); margin-left: 6px; font-weight: 500; }
.entry.void .badge { text-decoration: none; }
.empty { padding: 28px 8px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--fg); font-size: 16px; margin-bottom: 4px; }

details.panel summary { cursor: pointer; font-weight: 600; font-size: 15px; }
ul.audit { margin-top: 10px; }
ul.audit li { padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; overflow-wrap: anywhere; }
ul.audit li:first-child { border-top: 0; }
ul.audit .when { color: var(--muted); margin-right: 8px; }

.login { min-height: 70vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 24px; display: flex; flex-direction: column; gap: 14px;
}

@media (max-width: 899px) {
  .cols { grid-template-columns: minmax(0, 1fr); }
  .form-panel { position: static; }
  .form-panel:not(.open) { display: none; }
  .only-mobile { display: inline-block; }
  .hand { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .tiles { grid-template-columns: 1fr; }
  .tile { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
  .tile .value { font-size: 22px; margin: 0; }
  .entry { grid-template-columns: minmax(0, 1fr) auto; }
  .entry .date { grid-column: 1 / 3; }
  .entry .acts { grid-column: 1 / 3; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
