:root {
  /* 主题：深色（默认） */
  color-scheme: dark;
  --bg: #0E0C0A;
  --card: #17140F;
  --card2: #1D1811;
  --line: #302A21;
  --line2: #3D3320;
  --text: #F4F0E8;
  --sub: #A39C8F;
  --dim: #6E675C;
  --faint: #4C4740;
  --gold: #E9B44C;
  --gold-l: #FAD070;
  --gold-deep: #D79E38;
  --income: #E9B44C;
  --expense: #E2705F;
  --recv: #9B8BEA;
  --paid: #5FBF9F;

  /* 语义色：按钮上的文字 / 弱底色块 / 特殊面 */
  --on-gold: #17140F;
  --on-expense: #2A130E;
  --on-expense-soft: #FFD9D3;
  --gold-weak: #2A2312;
  --expense-weak: #2A1512;
  --violet-weak: #1A1626;
  --violet-line: #3B3355;
  --green-weak: #16241D;
  --hero-a: #2A2214;
  --hero-b: #14110C;
  --sheet: #14110C;
  --field: #241E16;
  --side: #12100D;
  --inset: rgba(0, 0, 0, .28);
  --bar: #3A3020;
  --track: #231D14;
  --mask: rgba(0, 0, 0, .62);
  --glow: rgba(233, 180, 76, .22);
  --gold-shadow: rgba(233, 180, 76, .45);
  --gold-shadow2: rgba(233, 180, 76, .55);
  --fade-submit: rgba(14, 12, 10, .6);
  --fade-nav: rgba(14, 12, 10, .85);

  --r: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

/* 主题：浅色（html[data-theme="light"]，由 app.js + 内联脚本切换） */
html[data-theme="light"] {
  color-scheme: light;
  --bg: #F6F2EA;
  --card: #FFFFFF;
  --card2: #FAF6EE;
  --line: #E8E1D3;
  --line2: #D8CEB9;
  --text: #1E1A13;
  --sub: #5E574B;
  --dim: #8B8377;
  --faint: #B7AF9F;
  --gold: #A9761D;
  --gold-l: #E9B44C;
  --gold-deep: #C8902F;
  --income: #A9761D;
  --expense: #C24A34;
  --recv: #6A55CE;
  --paid: #1C8668;

  --on-gold: #241C0C;
  --on-expense: #FFF6F3;
  --on-expense-soft: #8E2C18;
  --gold-weak: #FBF0D8;
  --expense-weak: #FCEDE9;
  --violet-weak: #F1EEFB;
  --violet-line: #DCD5F4;
  --green-weak: #E9F6F1;
  --hero-a: #FDF4E1;
  --hero-b: #FFFFFF;
  --sheet: #FFFFFF;
  --field: #FFFFFF;
  --side: #FFFFFF;
  --inset: rgba(120, 96, 48, .06);
  --bar: #EDE5D6;
  --track: #EDE5D6;
  --mask: rgba(30, 26, 19, .38);
  --glow: rgba(200, 144, 47, .16);
  --gold-shadow: rgba(169, 118, 29, .22);
  --gold-shadow2: rgba(200, 144, 47, .3);
  --fade-submit: rgba(246, 242, 234, .72);
  --fade-nav: rgba(246, 242, 234, .9);
}

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

html, body {
  margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 15px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
body { min-height: 100vh; }
input, button, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; padding: 0; }
a { color: var(--gold); text-decoration: none; }

.boot { display: flex; height: 100vh; align-items: center; justify-content: center; color: var(--dim); font-size: 13px; }

/* ---------- 外壳 ---------- */
.app { display: flex; flex-direction: column; min-height: 100vh; }
.screen {
  flex: 1; display: flex; flex-direction: column; width: 100%; max-width: 480px;
  margin: 0 auto; padding-bottom: calc(78px + var(--safe-b));
}
.screen.nonav { padding-bottom: 0; }

.hdr {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 18px 8px;
}
.hdr h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: .5px; }
.hdr .sub { font-size: 11px; color: var(--dim); margin-top: 3px; }
.hdr-actions { display: flex; align-items: center; gap: 8px; }

.body { flex: 1; padding: 4px 18px 18px; display: flex; flex-direction: column; gap: 12px; }

/* ---------- 通用块 ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); }
.pad { padding: 14px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row-l { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.muted { color: var(--dim); font-size: 11px; }
.sub { color: var(--sub); font-size: 12px; }
.gold { color: var(--gold); }
.income-c { color: var(--income); }
.expense-c { color: var(--expense); }
.recv-c { color: var(--recv); }
.paid-c { color: var(--paid); }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.big { font-size: 30px; font-weight: 700; letter-spacing: -.5px; }
.hr { height: 1px; background: var(--line); margin: 2px 0; }
.empty { padding: 28px 0; text-align: center; color: var(--faint); font-size: 13px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 48px; padding: 0 18px; border-radius: 14px; font-weight: 700; font-size: 15px;
  background: linear-gradient(135deg, var(--gold-l), var(--gold));
  color: var(--on-gold); box-shadow: 0 8px 24px -6px var(--gold-shadow);
  transition: transform .08s ease, opacity .15s;
}
.btn:active { transform: scale(.985); opacity: .92; }
.btn[disabled] { opacity: .45; box-shadow: none; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--card2); border: 1px solid var(--line); color: var(--sub); box-shadow: none; font-weight: 600; }
.btn.line { background: var(--gold-weak); border: 1px solid var(--gold); color: var(--gold); box-shadow: none; }
.btn.danger { background: var(--expense-weak); border: 1px solid var(--expense); color: var(--expense); box-shadow: none; }
.btn.sm { height: 34px; padding: 0 12px; font-size: 12px; border-radius: 10px; }
.iconbtn {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--card); border: 1px solid var(--line); color: var(--sub); font-size: 15px;
}

/* ---------- 表单 ---------- */
.field { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 14px; }
.field label { display: block; font-size: 10px; color: var(--dim); margin-bottom: 2px; }
.field .val { font-size: 15px; font-weight: 600; }
.field.pick { display: flex; align-items: center; justify-content: space-between; gap: 10px; cursor: pointer; }
.field.pick .chev { color: var(--dim); font-size: 13px; }
input.txt, textarea.txt, input[type=date], input[type=datetime-local], input[type=time], input[type=month] {
  width: 100%; background: transparent; border: 0; outline: none; font-size: 15px; font-weight: 600; color: var(--text);
  padding: 0; -webkit-appearance: none;
}
input::placeholder, textarea::placeholder { color: var(--faint); font-weight: 400; }
input[type=datetime-local]::-webkit-calendar-picker-indicator,
input[type=date]::-webkit-calendar-picker-indicator { filter: invert(.7); }

.seg { display: flex; gap: 4px; padding: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
.seg button {
  flex: 1; height: 40px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--dim); transition: .15s;
}
.seg button.on { background: var(--gold); color: var(--on-gold); font-weight: 700; }
.seg.warn button.on { background: var(--expense); color: var(--on-expense); }

.labelrow { display: flex; align-items: center; justify-content: space-between; margin: 2px 2px -6px; }
.labelrow b { font-size: 12px; font-weight: 600; color: var(--sub); }
.labelrow span { font-size: 11px; color: var(--faint); }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.custom-range { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.custom-range input[type='date'] { flex: 1; min-width: 0; height: 38px; }
.chip {
  height: 36px; padding: 0 14px; border-radius: 10px; background: var(--card); border: 1px solid var(--line);
  color: var(--sub); font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 5px;
  transition: .12s;
}
.chip:active { transform: scale(.97); }
.chip.on { background: var(--gold); color: var(--on-gold); border-color: var(--gold); }
.chip.on.warn { background: var(--expense); border-color: var(--expense); color: var(--on-expense); }
.chip.sm { height: 30px; padding: 0 11px; font-size: 12px; border-radius: 9px; }

/* ---------- 登录 ---------- */
.login { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 32px 26px calc(40px + var(--safe-b)); max-width: 480px; margin: 0 auto; width: 100%; position: relative; overflow: hidden; }
.login::before {
  content: ""; position: absolute; top: -180px; left: 50%; width: 460px; height: 460px; margin-left: -230px;
  background: radial-gradient(circle, var(--glow), rgba(233,180,76,0) 65%); pointer-events: none;
}
.login .logo {
  width: 58px; height: 58px; border-radius: 18px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--gold-l), var(--gold-deep)); color: var(--on-gold);
  font-size: 27px; font-weight: 800; box-shadow: 0 12px 30px -8px var(--gold-shadow2); margin-bottom: 22px;
}
.login h1 { font-size: 34px; margin: 0 0 6px; letter-spacing: 2px; }
.login .en { font-size: 10px; letter-spacing: 3px; color: var(--dim); margin-bottom: 10px; }
.login .desc { font-size: 13px; color: var(--sub); margin-bottom: 32px; }
.login .form { display: flex; flex-direction: column; gap: 14px; }

/* ---------- 记账 ---------- */
.items-card { background: var(--card2); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; display: flex; flex-direction: column; gap: 9px; }
.items-card .ih { display: flex; justify-content: space-between; font-size: 11px; color: var(--dim); }
.itemline { display: flex; align-items: center; gap: 10px; }
.itemline .nm { flex: 1; font-size: 13px; color: var(--sub); }
.itemline .amt { width: 108px; text-align: right; font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; background: transparent; border: 0; border-bottom: 1px dashed var(--line2); outline: none; padding: 3px 0; color: var(--text); }
.itemline .amt:focus { border-bottom-color: var(--gold); }
.itemline .del { color: var(--faint); font-size: 15px; padding: 0 2px; }
.total-row { display: flex; justify-content: space-between; align-items: baseline; padding-top: 9px; border-top: 1px solid var(--line); }

.submitbar {
  position: sticky; bottom: 0; margin-top: auto; display: flex; align-items: center; gap: 14px;
  padding: 12px 18px calc(12px + var(--safe-b)); background: linear-gradient(180deg, var(--fade-submit), var(--bg) 40%);
  backdrop-filter: blur(8px); border-top: 1px solid var(--line);
}
.submitbar .sum { flex: 1; }
.submitbar .sum b { display: block; font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.submitbar .btn { min-width: 140px; }

/* ---------- 驾驶舱 ---------- */
.hero {
  background: linear-gradient(150deg, var(--hero-a), var(--hero-b) 70%); border: 1px solid var(--line2);
  border-radius: 18px; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px;
}
.hero .badge { font-size: 10px; padding: 2px 8px; border-radius: 10px; background: var(--gold-weak); color: var(--gold); font-weight: 700; }
.split { display: flex; gap: 9px; }
.split > div { flex: 1; background: var(--inset); border-radius: 12px; padding: 8px 11px; display: flex; align-items: center; gap: 8px; }
.dot { width: 6px; height: 6px; border-radius: 3px; flex: none; }
.kpi { display: flex; gap: 9px; }
.kpi > div { flex: 1; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px; display: flex; flex-direction: column; gap: 3px; }
.kpi .v { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.grid2 > .card { padding: 11px 13px; display: flex; flex-direction: column; gap: 3px; }
.grid2 .v { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bars { display: flex; align-items: flex-end; gap: 7px; height: 64px; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; height: 100%; justify-content: flex-end; }
.bars .b i { width: 100%; max-width: 20px; border-radius: 5px 5px 3px 3px; background: var(--bar); display: block; min-height: 3px; }
.bars .b.today i { background: linear-gradient(180deg, var(--gold-l), var(--gold)); }
.bars .b span { font-size: 9px; color: var(--faint); }

/* ---------- 统计 ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.filters .chip { height: 31px; font-size: 12px; padding: 0 11px; border-radius: 15px; }
.filters .chip.on { background: var(--gold); }
.sumcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 13px 15px; display: flex; flex-direction: column; gap: 9px; }
.sumcard .cols { display: flex; gap: 10px; }
.sumcard .cols > div { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.sumcard .cols .v { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.dayhead { display: flex; justify-content: space-between; font-size: 12px; padding: 4px 2px; }
.rec { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 13px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.rec.void { opacity: .5; }
.rec.credit { background: var(--violet-weak); border-color: var(--violet-line); }
.rec .t { font-size: 13px; font-weight: 600; }
.rec .m { font-size: 10px; color: var(--dim); margin-top: 2px; }
.rec .v { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; gap: 4px; max-width: 480px; margin: 0 auto;
  padding: 8px 14px calc(10px + var(--safe-b));
  background: linear-gradient(180deg, var(--fade-nav), var(--bg) 45%);
  backdrop-filter: blur(12px);
}
.tabbar button {
  flex: 1; height: 52px; border-radius: 26px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; color: var(--dim); font-size: 10px; font-weight: 600;
}
.tabbar button .ti { font-size: 17px; line-height: 1; }
.tabbar button.on { background: var(--card); border: 1px solid var(--line); color: var(--gold); }
.tabbar.mine { background: none; backdrop-filter: none; padding-bottom: 6px; }

/* ---------- 管理 ---------- */
.mg-tabs { display: flex; gap: 4px; padding: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 13px; overflow-x: auto; }
.mg-tabs button { flex: none; padding: 0 14px; height: 36px; border-radius: 9px; font-size: 12px; font-weight: 600; color: var(--dim); }
.mg-tabs button.on { background: var(--gold); color: var(--on-gold); }
.prow { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.prow .nm { font-size: 13px; font-weight: 600; }
.prow .mt { font-size: 10px; color: var(--dim); margin-top: 2px; }
.tag { font-size: 10px; padding: 2px 8px; border-radius: 9px; background: var(--gold-weak); color: var(--gold); font-weight: 700; white-space: nowrap; }
.tag.gray { background: var(--card2); color: var(--dim); }
.tag.red { background: var(--expense-weak); color: var(--expense); }
.tag.violet { background: var(--violet-weak); color: var(--recv); }
.tag.green { background: var(--green-weak); color: var(--paid); }
.off { opacity: .45; }

/* ---------- 弹层 ---------- */
.sheet-mask { position: fixed; inset: 0; background: var(--mask); z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
/* 关键：display:flex 会压过 hidden 的默认 display:none，必须显式补一条 */
.sheet-mask[hidden] { display: none; }
.sheet {
  width: 100%; max-width: 480px; background: var(--sheet); border: 1px solid var(--line);
  border-radius: 22px 22px 0 0; padding: 18px 18px calc(18px + var(--safe-b));
  display: flex; flex-direction: column; gap: 12px; max-height: 86vh; overflow-y: auto;
  animation: up .22s cubic-bezier(.2,.8,.3,1);
}
@keyframes up { from { transform: translateY(30px); opacity: .4 } to { transform: none; opacity: 1 } }
.sheet h3 { margin: 0; font-size: 16px; font-weight: 700; }
.sheet .close { position: absolute; right: 0; top: 0; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 12px); z-index: 200;
  background: var(--field); border: 1px solid var(--line2); color: var(--text); font-size: 13px;
  padding: 10px 18px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .22s; max-width: 84vw; text-align: center;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: var(--expense); color: var(--on-expense-soft); }

/* ---------- PC 宽屏 ---------- */
@media (min-width: 900px) {
  body { padding-left: 220px; }
  .screen { max-width: 720px; padding-bottom: 32px; }
  .tabbar {
    left: 0; top: 0; bottom: 0; right: auto; width: 220px; max-width: none; margin: 0;
    flex-direction: column; justify-content: flex-start; gap: 6px; padding: 28px 16px;
    background: var(--side); border-right: 1px solid var(--line); backdrop-filter: none;
  }
  .tabbar::before {
    content: "夜账"; display: block; font-size: 20px; font-weight: 800; color: var(--gold);
    letter-spacing: 4px; padding: 0 8px 22px;
  }
  .tabbar button { flex: none; height: 46px; flex-direction: row; justify-content: flex-start; gap: 10px; padding: 0 14px; border-radius: 11px; font-size: 13px; }
  .tabbar button.on { border: 1px solid var(--line); }
  .tabbar button .ti { font-size: 15px; }
  .grid2 { grid-template-columns: repeat(4, 1fr); }
  .submitbar { border-radius: 14px; border: 1px solid var(--line); }
  .login { max-width: 420px; }
  .sheet-mask { align-items: center; }
  .sheet { border-radius: 18px; max-width: 460px; }
}
