:root {
  --radius: 16px;
  --font: "Inter", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, -apple-system,
    "Segoe UI", sans-serif;
}

/* ------------------------------------------------------------------ */
/* 主题：默认深色，light 覆盖变量                                      */
/* ------------------------------------------------------------------ */

:root,
:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0b1019;
  --sticky-bg: rgba(11, 16, 25, 0.82);
  --glow-1: rgba(47, 107, 255, 0.2);
  --glow-2: rgba(15, 157, 132, 0.14);

  --card: #131b29;
  --card-2: #0f1725;
  --input-bg: #0e1522;
  --line: #202b3d;
  --line-strong: #2c3a51;

  --ink: #e9eef7;
  --ink-soft: #a7b3c6;
  --ink-faint: #8492a8;

  --brand: #5b8cff;
  --brand-deep: #3563d8;
  --brand-strong: #3f77ff;

  --income: #35c9a1;
  --income-soft: rgba(53, 201, 161, 0.14);
  --expense: #ff6f6a;
  --expense-soft: rgba(255, 111, 106, 0.14);

  --chip-bg: #0e1522;
  --chip-active-bg: rgba(91, 140, 255, 0.16);
  --chip-active-fg: #a9c3ff;

  --seg-bg: #0f1725;
  --seg-active: #1d2839;

  --bar-track: #1c2739;
  --bar-from: #3a5ea8;
  --bar-to: #5b8cff;
  --bar-in-from: #1f7f6a;
  --bar-in-to: #35c9a1;

  --balance-1: #141f36;
  --balance-2: #1c3a6b;
  --balance-3: #2a5aa6;
  --income-tint: #10231e;
  --expense-tint: #251a1d;

  --hero-pill: rgba(19, 27, 41, 0.72);
  --hover-tint: rgba(91, 140, 255, 0.07);
  --focus-ring: rgba(91, 140, 255, 0.28);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 16px 32px -24px rgba(0, 0, 0, 0.9);

  --toast-bg: #e9eef7;
  --toast-fg: #0b1019;
  --code-bg: #1a2436;
  --icon-hover-border: rgba(255, 111, 106, 0.35);
}

:root[data-theme="light"] {
  color-scheme: light;

  --bg: #f4f6fb;
  --sticky-bg: rgba(244, 246, 251, 0.86);
  --glow-1: #e6edff;
  --glow-2: #e9fbf5;

  --card: #ffffff;
  --card-2: #fbfcff;
  --input-bg: #ffffff;
  --line: #e7ebf2;
  --line-strong: #d8dfea;

  --ink: #1b2434;
  --ink-soft: #5b667a;
  --ink-faint: #8b95a7;

  --brand: #2f6bff;
  --brand-deep: #1f4fd8;
  --brand-strong: #3f77ff;

  --income: #0f9d84;
  --income-soft: #e6f7f2;
  --expense: #e0443f;
  --expense-soft: #fdeceb;

  --chip-bg: #ffffff;
  --chip-active-bg: #eaf0ff;
  --chip-active-fg: #1f4fd8;

  --seg-bg: #f1f4fa;
  --seg-active: #ffffff;

  --bar-track: #eef1f7;
  --bar-from: #9db6ff;
  --bar-to: #2f6bff;
  --bar-in-from: #8fe0cd;
  --bar-in-to: #0f9d84;

  --balance-1: #26365c;
  --balance-2: #32508f;
  --balance-3: #2f6bff;
  --income-tint: #eefaf6;
  --expense-tint: #fdf1f0;

  --hero-pill: rgba(255, 255, 255, 0.7);
  --hover-tint: rgba(47, 107, 255, 0.04);
  --focus-ring: rgba(47, 107, 255, 0.14);
  --shadow: 0 1px 2px rgba(27, 36, 52, 0.04), 0 12px 28px -18px rgba(27, 36, 52, 0.35);

  --toast-bg: rgba(27, 36, 52, 0.92);
  --toast-fg: #ffffff;
  --code-bg: #e9edf5;
  --icon-hover-border: #f6cfcd;
}

/* ------------------------------------------------------------------ */
/* 基础                                                                */
/* ------------------------------------------------------------------ */

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

/* 有些按钮设了 display:inline-flex，会盖掉 UA 的 [hidden]，这里统一兜住 */
[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1100px 460px at 8% -8%, var(--glow-1) 0%, rgba(0, 0, 0, 0) 62%),
    radial-gradient(900px 420px at 96% 0%, var(--glow-2) 0%, rgba(0, 0, 0, 0) 58%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

input,
select,
button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

input,
select {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input::placeholder {
  color: var(--ink-faint);
}

input:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

select option {
  background: var(--card);
  color: var(--ink);
}

.page {
  width: min(1120px, 100% - 40px);
  margin: 0 auto;
  padding: 0 0 96px;
}

/* 底部 Tab 布局 */
.panel[hidden] {
  display: none;
}

.overview-date {
  margin: 0 0 12px;
  font-size: 12.5px;
  color: var(--ink-faint);
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 18px;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  border-top: 1px solid var(--line);
  background: var(--sticky-bg);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  backdrop-filter: blur(18px) saturate(150%);
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav-inner {
  width: min(1120px, 100%);
  margin: 0 auto;
  display: flex;
}

.nav-item {
  flex: 1;
  height: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  background: none;
  color: var(--ink-faint);
  font-size: 11px;
  cursor: pointer;
  transition: color 0.15s ease;
}

.nav-item.is-active {
  color: var(--brand);
}

.nav-icon {
  font-size: 18px;
  line-height: 1;
}

.me-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.me-row .user-avatar {
  width: 40px;
  height: 40px;
  font-size: 16px;
}

.me-name {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.me-role {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--ink-faint);
}

.me-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.me-actions .btn {
  width: auto;
  flex: 1;
  box-shadow: none;
}

/* ------------------------------------------------------------------ */
/* 顶部                                                                */
/* ------------------------------------------------------------------ */

.hero {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 0 14px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--line);
  background: var(--sticky-bg);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  backdrop-filter: blur(18px) saturate(150%);
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--brand);
}

.hero h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.hero h1 .hl {
  background: linear-gradient(92deg, var(--brand), var(--income));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-sub {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--ink-faint);
}

.hero-side {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.hero-account {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hero-date {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--hero-pill);
  font-size: 13px;
  color: var(--ink-soft);
  white-space: nowrap;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 35px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--hero-pill);
  color: var(--ink-soft);
  font-size: 13px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

/* 实时同步状态 */
.sync-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 35px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--hero-pill);
  font-size: 13px;
  color: var(--ink-soft);
  white-space: nowrap;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-faint);
  transition: background 0.2s, box-shadow 0.2s;
}

.sync-status.is-online .sync-dot {
  background: var(--income);
  box-shadow: 0 0 0 3px var(--income-soft);
}

.sync-status.is-offline .sync-dot {
  background: var(--expense);
  box-shadow: 0 0 0 3px var(--expense-soft);
}

.sync-status.is-pulse {
  border-color: var(--income);
  color: var(--income);
  background: var(--income-soft);
}

.theme-toggle:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.theme-toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.theme-toggle svg {
  width: 15px;
  height: 15px;
}

/* 深色下按钮提示“切到浅色”（显示太阳），浅色下提示“切到深色”（显示月亮） */
.theme-toggle .icon-sun,
.theme-toggle .theme-target-light {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

:root[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .theme-target-light {
  display: inline;
}

:root[data-theme="dark"] .theme-toggle .theme-target-dark {
  display: none;
}

/* ------------------------------------------------------------------ */
/* 汇总卡片                                                            */
/* ------------------------------------------------------------------ */

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.stat {
  position: relative;
  overflow: hidden;
  padding: 18px 20px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
}

.stat-label {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}

.stat-value {
  margin: 8px 0 6px;
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat-meta {
  margin: 0;
  font-size: 12px;
  color: var(--ink-faint);
}

.stat-balance {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--balance-1) 0%, var(--balance-2) 58%, var(--balance-3) 130%);
}

.stat-balance .stat-label,
.stat-balance .stat-meta {
  color: rgba(255, 255, 255, 0.74);
}

.stat-balance .stat-value.is-negative {
  color: #ffb4b0;
}

.stat-income {
  background: linear-gradient(160deg, var(--card) 30%, var(--income-tint) 100%);
}

.stat-income .stat-value {
  color: var(--income);
}

.stat-expense {
  background: linear-gradient(160deg, var(--card) 30%, var(--expense-tint) 100%);
}

.stat-expense .stat-value {
  color: var(--expense);
}

/* ------------------------------------------------------------------ */
/* 布局                                                                */
/* ------------------------------------------------------------------ */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, 1fr);
  gap: 18px;
  align-items: start;
}

.col-main,
.col-side {
  display: grid;
  gap: 18px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.card-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}

.card-tip {
  font-size: 12px;
  color: var(--ink-faint);
}

.card-head-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-head-actions .link-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ------------------------------------------------------------------ */
/* 记账表单                                                            */
/* ------------------------------------------------------------------ */

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 16px;
  border-radius: 12px;
  background: var(--seg-bg);
}

.seg-btn {
  height: 36px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.16s, color 0.16s, box-shadow 0.16s;
}

.seg-btn:hover {
  color: var(--ink);
}

.seg-btn.is-active {
  background: var(--seg-active);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}

.seg-btn.is-active[data-type="expense"] {
  color: var(--expense);
}

.seg-btn.is-active[data-type="income"] {
  color: var(--income);
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field-label {
  display: block;
  margin-bottom: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
}

.field-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
}

.field-label-row .field-label {
  margin-bottom: 0;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 12px;
}

/* 弹窗里的分类/来源类型切换按钮隐藏时不占位 */
.seg[hidden] {
  display: none;
}

.amount-box {
  display: flex;
  align-items: center;
  height: 58px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--card-2);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.amount-box:focus-within {
  border-color: var(--brand);
  background: var(--input-bg);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.currency {
  margin-right: 6px;
  font-size: 22px;
  font-weight: 600;
  color: var(--ink-faint);
}

.amount-box input {
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.01em;
  box-shadow: none;
}

.amount-box input:focus {
  box-shadow: none;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 6px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--chip-bg);
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.14s;
}

.chip:hover {
  border-color: var(--brand);
  color: var(--ink);
}

.chip.is-active {
  border-color: transparent;
  background: var(--chip-active-bg);
  color: var(--chip-active-fg);
  font-weight: 600;
}

.btn {
  height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.06s, background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  width: 100%;
  height: 46px;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-deep));
  box-shadow: 0 10px 20px -12px rgba(47, 107, 255, 0.9);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--brand-strong), var(--brand-deep));
}

.btn-ghost {
  border-color: var(--line-strong);
  background: transparent;
  color: var(--ink-soft);
  font-weight: 500;
}

.btn-ghost:hover {
  border-color: var(--brand);
  color: var(--ink);
}

.form-msg {
  min-height: 18px;
  margin: 0 0 10px;
  font-size: 12.5px;
  color: var(--ink-faint);
}

.form-msg.is-error {
  color: var(--expense);
}

.form-msg.is-ok {
  color: var(--income);
}

/* ------------------------------------------------------------------ */
/* 筛选                                                                */
/* ------------------------------------------------------------------ */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding-bottom: 14px;
  margin-bottom: 6px;
  border-bottom: 1px dashed var(--line);
}

.filter {
  display: flex;
  align-items: center;
  gap: 6px;
}

.filter-label {
  font-size: 12px;
  color: var(--ink-faint);
  white-space: nowrap;
}

.filter input,
.filter select {
  width: auto;
  min-width: 128px;
  height: 36px;
  font-size: 13px;
}

.filter select {
  min-width: 92px;
}

.filters .btn-ghost {
  height: 36px;
  margin-left: auto;
  font-size: 13px;
}

/* ------------------------------------------------------------------ */
/* 明细                                                                */
/* ------------------------------------------------------------------ */

.record-list {
  display: grid;
}

.record {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 4px 13px 2px;
  border-bottom: 1px solid var(--line);
}

.record:last-child {
  border-bottom: 0;
}

.record:hover {
  background: linear-gradient(90deg, var(--hover-tint), transparent);
}

.record-main {
  min-width: 0;
  flex: 1;
}

.record-top {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.tag {
  flex: none;
  padding: 1px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
}

.tag-expense {
  background: var(--expense-soft);
  color: var(--expense);
}

.tag-income {
  background: var(--income-soft);
  color: var(--income);
}

.record-cat {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-date {
  margin-left: auto;
  flex: none;
  font-size: 12px;
  color: var(--ink-faint);
}

.record-source {
  flex: none;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 11px;
  line-height: 16px;
  color: var(--ink-faint);
  white-space: nowrap;
}

.record-note {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--ink-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-amount {
  flex: none;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.record-amount.is-income {
  color: var(--income);
}

.record-amount.is-expense {
  color: var(--ink);
}

/* 记录行内删除确认（不依赖浏览器原生 confirm） */
.record.is-confirming {
  gap: 10px;
  padding-right: 10px;
  padding-left: 10px;
  border-radius: 10px;
  background: var(--expense-soft);
}

.record-confirm-text {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--ink);
}

.record-confirm-actions {
  display: flex;
  flex: none;
  gap: 8px;
}

.record-confirm-actions .btn {
  width: auto;
  box-shadow: none;
}

.icon-btn {
  flex: none;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-faint);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: all 0.14s;
}

.record:hover .icon-btn,
.material-row:hover .icon-btn,
.icon-btn:focus-visible {
  opacity: 1;
}

/* 触屏设备没有 hover，删除按钮常驻显示 */
@media (hover: none) {
  .icon-btn {
    opacity: 0.55;
  }
}

.icon-btn:hover {
  border-color: var(--icon-hover-border);
  background: var(--expense-soft);
  color: var(--expense);
}

/* 编辑按钮：蓝色系，避免和删除的红色混淆 */
.icon-btn.is-edit:hover {
  border-color: var(--line-strong);
  background: var(--chip-active-bg);
  color: var(--brand);
}

.record.is-editing {
  border-radius: 10px;
  background: var(--chip-active-bg);
}

/* 物料清单 */
.material-list {
  display: grid;
  gap: 2px;
}

.material-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 4px;
  border-bottom: 1px solid var(--line);
}

.material-row:last-child {
  border-bottom: 0;
}

.material-main {
  flex: 1;
  min-width: 0;
}

.material-name {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.material-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.material-tag {
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 11px;
  color: var(--ink-faint);
}

.material-tag.is-linked {
  border-color: var(--brand);
  color: var(--brand);
}

.material-meta {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--ink-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.material-amount {
  flex: none;
  font-size: 14px;
  font-weight: 650;
}

.filter-grow {
  flex: 1;
}

.filter-grow input {
  min-width: 120px;
}

/* 疑似重复记录的提示条 */
.duplicate-tip {
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--expense-soft);
}

.duplicate-tip p {
  margin: 0 0 8px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink);
}

.duplicate-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.duplicate-actions .btn {
  width: auto;
  flex: none;
  box-shadow: none;
}

.empty {
  margin: 22px 0;
  text-align: center;
  font-size: 13px;
  color: var(--ink-faint);
}

/* ------------------------------------------------------------------ */
/* 汇总面板                                                            */
/* ------------------------------------------------------------------ */

.summary-body {
  display: grid;
  gap: 18px;
}

.sum-group-title {
  display: flex;
  justify-content: space-between;
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-faint);
}

.sum-group-title .num {
  font-weight: 650;
}

.sum-group-title .num.is-income {
  color: var(--income);
}

.sum-group-title .num.is-expense {
  color: var(--expense);
}

.sum-list {
  display: grid;
  gap: 11px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.sum-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 5px;
  font-size: 13px;
}

.sum-name {
  color: var(--ink-soft);
}

.sum-amount {
  font-weight: 600;
}

.bar {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--bar-track);
}

.bar > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--bar-from), var(--bar-to));
}

.bar.is-income > span {
  background: linear-gradient(90deg, var(--bar-in-from), var(--bar-in-to));
}

.month-row {
  display: grid;
  grid-template-columns: 74px 1fr auto;
  gap: 8px;
  align-items: center;
  padding-bottom: 9px;
  border-bottom: 1px dashed var(--line);
  font-size: 13px;
}

.month-row:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.month-label {
  color: var(--ink-soft);
  font-weight: 600;
}

.month-nums {
  display: flex;
  gap: 10px;
  font-size: 12px;
  color: var(--ink-faint);
}

.month-nums .in {
  color: var(--income);
}

.month-nums .out {
  color: var(--expense);
}

.month-balance {
  font-weight: 650;
}

.month-balance.is-negative {
  color: var(--expense);
}

/* ------------------------------------------------------------------ */
/* 页脚与提示                                                          */
/* ------------------------------------------------------------------ */

.foot {
  margin-top: 26px;
  text-align: center;
  font-size: 12px;
  color: var(--ink-faint);
}

.foot code {
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--code-bg);
  font-size: 11.5px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--toast-bg);
  color: var(--toast-fg);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
}

.toast.is-show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ------------------------------------------------------------------ */
/* 分类管理弹窗                                                        */
/* ------------------------------------------------------------------ */

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--brand);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
}

.link-btn:hover {
  text-decoration: underline;
}

.chips-empty {
  font-size: 12.5px;
  color: var(--ink-faint);
}

body.modal-open {
  overflow: hidden;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 7, 12, 0.58);
  backdrop-filter: blur(2px);
}

.modal-panel {
  position: relative;
  width: min(460px, 100%);
  max-height: min(86vh, 720px);
  display: flex;
  flex-direction: column;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  box-shadow: 0 30px 70px -24px rgba(0, 0, 0, 0.65);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
}

.modal-close {
  opacity: 1;
  font-size: 18px;
}

.modal-close:hover {
  border-color: var(--line-strong);
  background: var(--card-2);
  color: var(--ink);
}

.modal-tip {
  margin: 4px 0 0;
  font-size: 11.5px;
  color: var(--ink-faint);
}

.cat-list {
  display: grid;
  gap: 2px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 4px 0 0;
  padding-right: 4px;
}

.cat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 6px;
  border-bottom: 1px solid var(--line);
}

.cat-grip {
  flex: none;
  display: grid;
  place-items: center;
  width: 18px;
  height: 24px;
  border-radius: 5px;
  color: var(--ink-faint);
  cursor: grab;
  touch-action: none;
  transition: color 0.15s, background 0.15s;
}

.cat-grip:hover {
  color: var(--ink-soft);
  background: var(--card-2);
}

.cat-grip:active {
  cursor: grabbing;
}

.cat-grip.is-locked {
  cursor: default;
  opacity: 0.35;
}

.cat-grip.is-locked:hover {
  background: transparent;
  color: var(--ink-faint);
}

.cat-fixed {
  flex: none;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 11px;
  line-height: 16px;
  color: var(--ink-faint);
  white-space: nowrap;
}

.cat-row.is-dragging {
  border-radius: 10px;
  background: var(--chip-active-bg);
  box-shadow: inset 0 0 0 1px var(--brand);
}

.cat-list.is-sorting .cat-row {
  transition: none;
}

body.cat-sorting {
  user-select: none;
  -webkit-user-select: none;
}

.cat-row:last-child {
  border-bottom: 0;
}

.cat-name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cat-count {
  flex: none;
  font-size: 12px;
  color: var(--ink-faint);
}

.cat-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
}

.cat-row .icon-btn {
  opacity: 1;
  font-size: 14px;
}

.cat-row .icon-btn[data-edit]:hover {
  border-color: var(--brand);
  background: var(--chip-active-bg);
  color: var(--brand);
}

.cat-input {
  flex: 1;
  height: 34px;
}

.btn-mini {
  height: 30px;
  padding: 0 10px;
  font-size: 12.5px;
  border-radius: 8px;
}

.cat-actions .btn {
  width: auto;
}

.cat-row .btn-mini {
  width: auto;
  box-shadow: none;
}

/* 删除使用中的分类：先把记录转移到别的分类 */
.cat-row.is-deleting {
  display: block;
  margin: 6px 0;
  padding: 12px 10px;
  border: 1px solid var(--icon-hover-border);
  border-radius: 10px;
  background: var(--expense-soft);
}

.cat-delete-text {
  margin: 0 0 9px;
  font-size: 13px;
  color: var(--ink);
}

.cat-delete-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.cat-delete-actions select {
  width: auto;
  flex: 1;
  min-width: 120px;
  height: 34px;
  font-size: 13px;
}

.btn-danger {
  background: var(--expense);
  border-color: transparent;
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  filter: brightness(1.06);
}

.cat-add {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.cat-add input {
  flex: 1;
  height: 40px;
}

.cat-add .btn-primary {
  width: auto;
  height: 40px;
  padding: 0 18px;
  box-shadow: none;
  flex: none;
}

/* 登录页 */
.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px 0;
}

.login-wrap {
  width: min(360px, 100% - 32px);
}

.login-card {
  padding: 28px 24px 24px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.login-logo {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--brand), var(--income));
  color: #fff;
  font-size: 24px;
  font-weight: 700;
}

.login-card h1 {
  margin: 0;
  font-size: 22px;
}

.login-sub {
  margin: 6px 0 20px;
  font-size: 13px;
  color: var(--ink-faint);
}

.login-foot {
  margin: 16px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--ink-faint);
}

.user-chip {
  max-width: 100px;
  overflow: hidden;
  font-size: 13px;
  color: var(--ink-soft);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.settings-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.settings-section {
  margin: 20px 0 10px;
  font-size: 13px;
  font-weight: 650;
  color: var(--ink-soft);
}

.settings-section:first-child {
  margin-top: 4px;
}

.settings-line {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--ink-soft);
}

.settings-line b {
  color: var(--ink);
}

.role-tag {
  margin-left: 6px;
  padding: 1px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  font-size: 11px;
  color: var(--ink-faint);
}

/* 设置：标签页 */
.settings-tabs {
  display: flex;
  gap: 4px;
  margin: 2px 0 14px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--seg-bg);
}

.settings-tab {
  flex: 1;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.settings-tab:hover {
  color: var(--ink);
}

.settings-tab.is-active {
  background: var(--seg-active);
  color: var(--ink);
  font-weight: 600;
}

.settings-pane[hidden] {
  display: none;
}

.pane-intro {
  margin: 2px 0 14px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-soft);
}

.pane-hint {
  margin: 12px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink-faint);
}

.user-list {
  display: grid;
  gap: 6px;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px;
}

.user-avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--chip-active-bg);
  color: var(--chip-active-fg);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}

.user-name {
  font-weight: 500;
}

.user-row .user-role {
  margin-left: auto;
  font-size: 11px;
  color: var(--ink-faint);
}

.user-add-card {
  margin-top: 14px;
  padding: 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
}

.user-add-title {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--ink-faint);
}

.user-add {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.user-add input {
  flex: 1;
  min-width: 140px;
  height: 38px;
}

.user-add .btn {
  width: auto;
  flex: none;
  height: 38px;
  box-shadow: none;
}

/* 设置弹窗 */
.field-hint {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--ink-faint);
}

/* 页内拍照 */
.camera-panel {
  max-width: 460px;
}

#cameraVideo {
  width: 100%;
  max-height: 58vh;
  border-radius: 12px;
  background: #000;
  object-fit: cover;
}

.camera-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.camera-actions .btn {
  width: auto;
  flex: 1;
  box-shadow: none;
}

.settings-actions {
  display: flex;
  gap: 10px;
  margin: 16px 0 6px;
}

.settings-actions .btn {
  width: auto;
  flex: 1;
  box-shadow: none;
}

.settings-actions .btn-primary {
  height: 40px;
}

/* ------------------------------------------------------------------ */
/* 响应式                                                              */
/* ------------------------------------------------------------------ */

@media (max-width: 940px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .col-side {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .page {
    width: 100%;
    padding: 0 12px 92px;
  }

  .summary-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .hero {
    display: block;
    margin: 0 -12px 16px;
    padding: 12px 12px 10px;
  }

  .hero .eyebrow,
  .hero .hero-sub {
    display: none;
  }

  .hero h1 {
    font-size: 20px;
    line-height: 1.25;
    padding-right: 150px;
  }

  .hero-account {
    position: absolute;
    top: 12px;
    right: 0;
  }

  .hero-side {
    margin-top: 10px;
    gap: 8px;
    flex-wrap: nowrap;
    justify-content: flex-start;
  }

  .hero-date {
    display: none;
  }

  .stats {
    grid-template-columns: 1fr 1fr;
  }

  .stat-balance {
    grid-column: 1 / -1;
  }

  .col-side {
    grid-template-columns: 1fr;
  }

  .field-row {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .filters .btn-ghost {
    margin-left: 0;
  }
}
