/* ====== 简约商务白 · 家庭记账 ====== */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: #1f2937;
  background: #ffffff;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 布局 ---------- */
.layout { display: flex; min-height: 100vh; }
.side {
  width: 216px;
  background: #ffffff;
  border-right: 1px solid #e5e7eb;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand {
  padding: 20px 20px 16px;
  font-size: 16px;
  font-weight: 600;
  color: #111827;
  border-bottom: 1px solid #f3f4f6;
  display: flex;
  align-items: center;
  gap: 9px;
  letter-spacing: .3px;
}
.brand .logo {
  width: 22px; height: 22px;
  background: #1e40af;
  color: #fff;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* 菜单分组 */
.menu { display: flex; flex-direction: column; padding: 8px 8px 6px; flex: 1; }
.menu .grp {
  font-size: 11px;
  color: #9ca3af;
  font-weight: 600;
  padding: 14px 12px 5px;
  letter-spacing: .6px;
  text-transform: uppercase;
}
.menu a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 12px;
  color: #4b5563;
  text-decoration: none;
  border-radius: 4px;
  font-size: 13px;
  margin-bottom: 1px;
  border-left: 2px solid transparent;
  border-right: 1px solid transparent;
  border-top: 1px solid transparent;
  border-bottom: 1px solid transparent;
  transition: background .12s, color .12s;
}
.menu a .ic {
  width: 16px;
  display: inline-block;
  text-align: center;
  color: #9ca3af;
  font-size: 13px;
  flex-shrink: 0;
}
.menu a:hover { background: #f9fafb; color: #111827; }
.menu a:hover .ic { color: #6b7280; }
.menu a.active {
  background: #eff6ff;
  color: #1e40af;
  border-left-color: #1e40af;
  font-weight: 500;
}
.menu a.active .ic { color: #1e40af; }
.menu a.ai {
  color: #4338ca;
}
.menu a.ai .ic { color: #6366f1; }
.menu a.ai:hover { background: #f9fafb; color: #3730a3; }
.menu a.ai.active { background: #eef2ff; color: #4338ca; border-left-color: #4338ca; }
.menu a.ai.active .ic { color: #4338ca; }

.side-foot { padding: 12px 16px 18px; border-top: 1px solid #f3f4f6; }
.side-foot a { color: #9ca3af; text-decoration: none; font-size: 12px; display: inline-flex; align-items: center; gap: 4px; }
.side-foot a:hover { color: #4b5563; }

.main { flex: 1; padding: 26px 34px 80px; min-width: 0; }

/* ---------- Tab 显隐 ---------- */
.tab { display: none; }
.tab.active { display: block; }

/* ---------- 标题栏 ---------- */
.head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid #e5e7eb;
}
.head .title h1 { margin: 0; font-size: 20px; font-weight: 600; color: #111827; letter-spacing: .2px; }
.head .title p { margin: 5px 0 0; font-size: 13px; color: #6b7280; }
.head .actions { display: flex; gap: 8px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 32px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  border: 1px solid #d1d5db;
  background: #ffffff;
  color: #111827;
  cursor: pointer;
  border-radius: 4px;
  transition: border-color .12s, background-color .12s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: #9ca3af; background: #f9fafb; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.btn-sm { height: 26px; padding: 0 10px; font-size: 12px; }
.btn.btn-default {}
.btn.btn-primary {
  background: #1e40af;
  border-color: #1e40af;
  color: #ffffff;
}
.btn.btn-primary:hover { background: #1e3a8a; border-color: #1e3a8a; }
.btn.btn-danger {
  background: #ffffff;
  border-color: #e5e7eb;
  color: #dc2626;
}
.btn.btn-danger:hover { background: #fef2f2; border-color: #fca5a5; }
.btn.btn-ai {
  background: #4338ca;
  border-color: #4338ca;
  color: #ffffff;
}
.btn.btn-ai:hover { background: #3730a3; border-color: #3730a3; }
.btn.btn-link {
  background: transparent;
  border-color: transparent;
  color: #1e40af;
  padding: 0 4px;
  height: auto;
  font-size: 13px;
}
.btn.btn-link:hover { color: #1e3a8a; text-decoration: underline; background: transparent; }

/* ---------- 面板 ---------- */
.panel {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  margin-bottom: 16px;
  border-radius: 4px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid #f3f4f6;
  background: #fcfcfd;
}
.panel-head h3 { margin: 0; font-size: 14px; font-weight: 600; color: #111827; }
.form-panel > .panel-head { padding-bottom: 12px; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .5);
  z-index: 1000; display: none;
}
.modal-mask.show { display: block; }
.form-panel {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1001;
  width: min(720px, 92vw);
  max-height: 88vh; overflow: auto;
  background: #fff;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .28);
}
.form-panel .close { background: none; border: none; font-size: 20px; line-height: 1; color: #6b7280; cursor: pointer; padding: 0 4px; }
.form-panel .close:hover { color: #111827; }
.modal-body { padding: 4px 20px 20px; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 8px 20px; padding: 8px 0 14px; color: #374151; font-size: 13px; }
.detail-meta span b { color: #111827; }
.detail-sub { margin: 14px 0 6px; font-size: 13px; font-weight: 600; color: #6b7280; }

/* ---------- 概览 ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(176px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.cards .card {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  padding: 16px 18px;
  border-radius: 4px;
  transition: border-color .12s;
}
.cards .card:hover { border-color: #9ca3af; }
.cards .card span { display: block; font-size: 12px; color: #6b7280; }
.cards .card strong { display: block; margin-top: 6px; font-size: 22px; color: #1e40af; font-weight: 600; letter-spacing: -.2px; }
.cards .card strong.expense { color: #dc2626; }
.cards .card strong.surplus { color: #059669; }

/* 账户余额网格 */
.acct-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  padding: 14px 20px 18px;
}
.acct-card {
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  padding: 14px 16px;
  background: #ffffff;
  transition: border-color .12s;
  position: relative;
  overflow: hidden;
}
.acct-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 2px; height: 100%;
  background: #1e40af;
}
.acct-card:hover { border-color: #9ca3af; }
.acct-card .acct-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.acct-card .acct-name { font-size: 14px; font-weight: 600; color: #111827; }
.acct-card .acct-type { font-size: 12px; color: #6b7280; margin: 4px 0 8px; }
.acct-card .acct-bal { font-size: 20px; font-weight: 600; color: #1e40af; font-variant-numeric: tabular-nums; letter-spacing: -.2px; }
.acct-card .acct-bal.expense { color: #b91c1c; }
.acct-card .acct-sub { font-size: 12px; color: #6b7280; margin-top: 4px; font-variant-numeric: tabular-nums; }
.acct-grid .empty { grid-column: 1 / -1; }

/* 账户类型管理 */
.acct-types { padding: 0 20px 16px; }
.type-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.type-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  font-size: 13px;
  background: #ffffff;
  color: #374151;
}
.type-chip .badge { margin: 0; }
.type-del {
  background: none;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
  font-family: inherit;
}
.type-del:hover { color: #dc2626; }

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 900px) { .row { grid-template-columns: 1fr; } }

.alert-list { padding: 6px 20px 18px; }
.alert-list:empty { padding: 0; }
.alert-item {
  padding: 10px 12px;
  border: 1px solid #e5e7eb;
  border-left: 3px solid #1e40af;
  margin-top: 8px;
  font-size: 13px;
  background: #f9fafb;
  border-radius: 2px;
}
.alert-item.warning { border-left-color: #d97706; background: #fffbeb; color: #92400e; border-right-color: #fef3c7; border-top-color: #fef3c7; border-bottom-color: #fef3c7; }
.alert-item.overspent { border-left-color: #dc2626; background: #fef2f2; color: #991b1b; border-right-color: #fee2e2; border-top-color: #fee2e2; border-bottom-color: #fee2e2; }
.alert-item strong { margin-right: 6px; color: #111827; }
.alert-list p { color: #9ca3af; margin: 10px 0; padding: 0 4px; }
.alert-item .bud-row { margin: 4px 0 6px; color: #4b5563; font-size: 12.5px; }
.alert-item .bud-bar { height: 6px; background: #e5e7eb; border-radius: 2px; overflow: hidden; margin: 4px 0; }
.alert-item .bud-bar span { display: block; height: 100%; background: #1e40af; border-radius: 2px; }
.alert-item .bud-meta { font-size: 12px; color: #6b7280; margin-top: 2px; }

/* ---------- 表格 ---------- */
.t { width: 100%; border-collapse: collapse; }
.t th, .t td {
  padding: 10px 14px;
  font-size: 13px;
  text-align: left;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: middle;
}
.t thead th {
  background: #f9fafb;
  font-weight: 600;
  color: #374151;
  border-bottom: 1px solid #e5e7eb;
  font-size: 12px;
  letter-spacing: .2px;
}
.t tbody tr:hover { background: #f9fafb; }
.t.sm th, .t.sm td { padding: 8px 14px; }
.t .op { display: inline-flex; gap: 10px; }
.t .op a,
.t .op button {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  cursor: pointer;
  color: #1e40af;
  font-family: inherit;
  text-decoration: underline;
  text-decoration-color: #bfdbfe;
  text-underline-offset: 2px;
}
.t .op a:hover, .t .op button:hover { color: #1e3a8a; text-decoration-color: #1e3a8a; }
.t .op .del { color: #dc2626; text-decoration-color: #fecaca; }
.t .op .del:hover { color: #991b1b; text-decoration-color: #991b1b; }

/* ---------- 表单 ---------- */
.form { padding: 16px 20px 14px; }
.grid3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px 18px;
  margin-bottom: 10px;
}
@media (max-width: 820px) { .grid3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .grid3 { grid-template-columns: 1fr; } }
.form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: #374151;
  font-weight: 500;
}
.form label.block { margin-bottom: 8px; }
.form input, .form select {
  height: 32px;
  padding: 0 10px;
  font-size: 13px;
  color: #111827;
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-family: inherit;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.form input:focus, .form select:focus {
  border-color: #1e40af;
  box-shadow: 0 0 0 3px rgba(30, 64, 175, .1);
}
.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  padding-top: 8px;
}
.form-msg { font-size: 12px; color: #6b7280; }
.form-msg.ok { color: #059669; }
.form-msg.err { color: #dc2626; }

/* ---------- 进度条 / Badge ---------- */
.pbar {
  height: 6px;
  background: #f3f4f6;
  width: 100%;
  border-radius: 2px;
  overflow: hidden;
}
.pbar > i { display: block; height: 100%; background: #1e40af; transition: width .2s; }
.pbar > i.ok { background: #059669; }
.pbar > i.warn { background: #d97706; }
.pbar > i.over { background: #dc2626; }
.pct { font-size: 12px; color: #6b7280; margin-top: 3px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 12px;
  background: #f3f4f6;
  color: #374151;
  font-weight: 500;
  line-height: 1.6;
}
.badge.active { background: #dbeafe; color: #1e40af; }
.badge.settled, .badge.completed { background: #d1fae5; color: #065f46; }
.badge.warning { background: #fef3c7; color: #92400e; }
.badge.overspent { background: #fee2e2; color: #991b1b; }
.badge.normal { background: #f3f4f6; color: #6b7280; }
.badge.income { background: #d1fae5; color: #065f46; }
.badge.expense { background: #fee2e2; color: #991b1b; }
.badge.saving { background: #dbeafe; color: #1e40af; }
.badge.ai { background: #e0e7ff; color: #4338ca; }

.money.income { color: #059669; }
.money.expense { color: #dc2626; }
.money { font-variant-numeric: tabular-nums; }
.money b { font-weight: 600; color: inherit; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  top: 24px;
  right: 28px;
  min-width: 180px;
  padding: 10px 16px;
  background: #111827;
  color: #ffffff;
  font-size: 13px;
  border-radius: 4px;
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  z-index: 9999;
  box-shadow: 0 6px 20px rgba(17, 24, 39, .18);
}
.toast.show { opacity: 1; transform: translateY(0); transition: opacity .15s, transform .15s; }
.toast.ok { background: #059669; }
.toast.err { background: #dc2626; }

/* 预算重算持久状态（不依赖 toast，确保用户能看到重算结果） */
.recalc-status { display: inline-block; margin-left: 10px; font-size: 12px; color: #6b7280; line-height: 32px; max-width: 720px; vertical-align: middle; }
.recalc-status.ok { color: #059669; }
.recalc-status.err { color: #dc2626; }

/* ---------- AI 助手 ---------- */
.ai-wrap { display: flex; flex-direction: column; gap: 12px; }
.ai-hint {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-left: 3px solid #4338ca;
  padding: 12px 16px;
  border-radius: 4px;
  font-size: 13px;
  color: #3730a3;
}
.ai-hint b { color: #312e81; }
.ai-hint .chip {
  display: inline-block;
  background: #fff;
  border: 1px solid #e5e7eb;
  color: #4338ca;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  margin-right: 6px;
  margin-top: 4px;
  cursor: pointer;
}
.ai-hint .chip:hover { background: #eef2ff; }

.ai-thread {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  min-height: 360px;
  max-height: 540px;
  overflow-y: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.ai-thread .empty {
  color: #9ca3af;
  text-align: center;
  margin: auto 0;
  font-size: 13px;
}
.ai-msg { display: flex; gap: 10px; max-width: 88%; }
.ai-msg .av {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: #e5e7eb;
  color: #4b5563;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}
.ai-msg.user { margin-left: auto; flex-direction: row-reverse; }
.ai-msg.user .av { background: #4338ca; color: #fff; }
.ai-msg.bot .av { background: #6366f1; color: #fff; }
.ai-msg .bubble {
  padding: 10px 14px;
  border-radius: 4px;
  font-size: 13px;
  line-height: 1.65;
  border: 1px solid #e5e7eb;
  background: #f9fafb;
  color: #1f2937;
}
.ai-msg.user .bubble { background: #4338ca; color: #fff; border-color: #4338ca; }
.ai-msg.bot .bubble { background: #ffffff; }
.ai-msg .bubble .label {
  display: block;
  font-size: 11px;
  color: #9ca3af;
  margin-bottom: 4px;
  font-weight: 500;
}
.ai-msg.user .bubble .label { color: #c7d2fe; }
.ai-msg .bubble .intent {
  background: #eef2ff;
  border: 1px dashed #a5b4fc;
  border-radius: 3px;
  padding: 8px 10px;
  margin: 6px 0;
  font-size: 12px;
  color: #3730a3;
  white-space: pre-wrap;
}
.ai-msg .bubble .intent b { color: #312e81; }
.ai-msg .bubble .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
  font-size: 12px;
  color: #6b7280;
}
.ai-msg .bubble .meta span { background: #f3f4f6; padding: 1px 7px; border-radius: 2px; }
.ai-msg.bot .bubble .err { color: #dc2626; }

.ai-input {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.ai-input textarea {
  flex: 1;
  min-height: 38px;
  max-height: 110px;
  padding: 9px 12px;
  font-size: 13px;
  font-family: inherit;
  color: #111827;
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  resize: none;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.ai-input textarea:focus {
  border-color: #4338ca;
  box-shadow: 0 0 0 3px rgba(67, 56, 202, .1);
}
.ai-input .btn { align-self: stretch; }

/* 占位/辅助 */
.empty { color: #9ca3af; text-align: center; padding: 22px 0; font-size: 13px; }
.nobr { white-space: nowrap; }
.muted { color: #9ca3af; font-size: 12px; }

/* ---------- AI 对接文档 ---------- */
.doc-view {
  padding: 24px 32px 40px;
  font-size: 13.5px;
  line-height: 1.75;
  color: #1f2937;
  max-width: 980px;
}
.doc-view .empty { padding: 40px 0; }
.doc-view h1 { font-size: 22px; font-weight: 700; color: #111827; margin: 0 0 14px; padding-bottom: 10px; border-bottom: 1px solid #e5e7eb; }
.doc-view h2 { font-size: 17px; font-weight: 700; color: #111827; margin: 26px 0 10px; padding-bottom: 6px; border-bottom: 1px solid #f3f4f6; }
.doc-view h3 { font-size: 15px; font-weight: 600; color: #111827; margin: 20px 0 8px; }
.doc-view h4 { font-size: 14px; font-weight: 600; color: #1e40af; margin: 16px 0 6px; }
.doc-view h5, .doc-view h6 { font-size: 13px; font-weight: 600; color: #374151; margin: 14px 0 6px; }
.doc-view p { margin: 8px 0; }
.doc-view ul, .doc-view ol { margin: 8px 0; padding-left: 22px; }
.doc-view li { margin: 3px 0; }
.doc-view li > ul, .doc-view li > ol { margin: 3px 0; }
.doc-view a { color: #1e40af; text-decoration: none; border-bottom: 1px solid #bfdbfe; }
.doc-view a:hover { color: #1e3a8a; border-bottom-color: #1e3a8a; }
.doc-view strong { font-weight: 600; color: #111827; }
.doc-view code { background: #f3f4f6; color: #be185d; padding: 1px 5px; border-radius: 3px; font-size: 12.5px; font-family: "SFMono-Regular", Consolas, "Microsoft YaHei", monospace; }
.doc-view pre.code { background: #1f2937; color: #e5e7eb; padding: 14px 16px; border-radius: 4px; overflow-x: auto; margin: 12px 0; font-size: 12.5px; line-height: 1.6; }
.doc-view pre.code code { background: transparent; color: inherit; padding: 0; font-size: inherit; }
.doc-view blockquote { border-left: 3px solid #4338ca; background: #eef2ff; color: #3730a3; padding: 8px 14px; margin: 12px 0; border-radius: 0 3px 3px 0; }
.doc-view blockquote code { background: #c7d2fe; color: #1e1b4b; }
.doc-view hr { border: none; border-top: 1px solid #e5e7eb; margin: 22px 0; }
.doc-view table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 13px; }
.doc-view th, .doc-view td { border: 1px solid #e5e7eb; padding: 8px 12px; text-align: left; vertical-align: top; }
.doc-view thead th { background: #f9fafb; font-weight: 600; color: #111827; }
.doc-view tbody tr:nth-child(even) { background: #f9fafb; }
.doc-view td code { white-space: nowrap; }
