/* ============================================================
   个人财务管理系统 · 全局样式
   设计语言：浅黄纸张底色 + 黑字 + 克制的强调色，简洁专业，无装饰性 emoji
   ============================================================ */

:root {
  /* 色彩变量 */
  --bg: #f4eedd;            /* 页面背景：浅黄（纸张） */
  --bg-card: #fffdf4;       /* 卡片背景：纸白 */
  --bg-sidebar: #efe6cb;    /* 侧栏背景：稍深的纸色 */
  --ink: #2c2618;           /* 主文字：近黑 */
  --ink-2: #6f6755;         /* 次要文字 */
  --ink-3: #a2977d;         /* 弱化文字 */
  --line: #e2d6b4;          /* 边框 */
  --accent: #7a5c2e;        /* 强调色：深棕 */
  --accent-dark: #5e4520;
  --accent-soft: #efe3c6;
  --pos: #2e7d4f;           /* 正数（收入）绿 */
  --neg: #b03a2e;           /* 负数（支出）红 */
  --transfer: #8a6d3b;      /* 转移中性棕 */
  --danger: #b03a2e;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(70, 55, 20, .10);
  --shadow-lg: 0 8px 28px rgba(60, 45, 15, .22);

  /* 字体 */
  --font: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", "Segoe UI", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

/* ---------- 基础重置 ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }
img { display: block; }

.muted { color: var(--ink-3); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.transfer { color: var(--transfer); }

.hidden { display: none !important; }

/* ---------- 整体布局：左导航 + 右内容 ---------- */
.app {
  display: flex;
  min-height: 100vh;
}

/* ---------- 左侧导航 ---------- */
.sidebar {
  width: 224px;
  flex: 0 0 224px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 22px 18px 18px;
  border-bottom: 1px solid var(--line);
}

.brand-icon {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  color: var(--accent);
}

.brand-icon img { width: 30px; height: 30px; }

/* 系统名称可被用户修改为长文字：弹性收缩 + 超出省略，防止撑破侧栏/顶栏 */
.brand-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .5px;
}

.nav {
  flex: 1;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 11px 13px;
  border: none;
  background: transparent;
  border-radius: 8px;
  color: var(--ink);
  font-size: 14px;
  text-align: left;
  transition: background .15s, color .15s;
}

.nav-item:hover { background: rgba(122, 92, 46, .10); }

.nav-item.active {
  background: var(--accent);
  color: #fdf8ea;
  font-weight: 600;
}

.nav-item.active .nav-icon { filter: brightness(0) invert(1); }

.nav-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--line);
}

/* ---------- 右侧内容区 ---------- */
.content {
  flex: 1;
  min-width: 0;
  padding: 26px 34px 46px;
}

.view { display: none; }
.view.active { display: block; }

.view-header { margin-bottom: 20px; }

.view-header h1 {
  font-size: 21px;
  font-weight: 600;
  letter-spacing: .5px;
}

/* ---------- 钱包卡片 ---------- */
.wallet-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 26px;
}

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

.wallet-card-name {
  font-size: 13px;
  color: var(--ink-2);
  margin-bottom: 8px;
}

.wallet-card-amount {
  font-size: 26px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: .5px;
}

.wallet-card-total {
  background: var(--accent);
  border-color: var(--accent);
  color: #fdf8ea;
}

.wallet-card-total .wallet-card-name { color: rgba(253, 248, 234, .78); }
.wallet-card-total .wallet-card-amount.neg { color: #ffd9d2; }

/* ---------- 操作按钮区 ---------- */
.action-bar {
  display: flex;
  gap: 14px;
  margin-bottom: 30px;
}

.action-btn {
  flex: 1;
  max-width: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-card);
  color: var(--ink);
  box-shadow: var(--shadow);
  transition: transform .12s, box-shadow .12s, border-color .12s;
}

.action-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent);
}

.action-btn img { width: 19px; height: 19px; }

.action-income:hover { border-color: var(--pos); }
.action-expense:hover { border-color: var(--neg); }
.action-transfer:hover { border-color: var(--transfer); }

/* ---------- 账单区块 ---------- */
.bill-section {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px 20px;
}

.bill-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.bill-toolbar h2 { font-size: 16px; font-weight: 600; }

/* 筛选条 */
.filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.filters select,
.filters input[type="date"] {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
}

.filters input[type="date"] { width: 138px; }

.btn {
  padding: 7px 16px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  transition: background .15s, border-color .15s, color .15s;
}

.btn:hover { border-color: var(--accent); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fdf8ea;
}

.btn-primary:hover { background: var(--accent-dark); }

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

.btn-danger:hover { background: #982f24; }

.btn-block { width: 100%; padding: 10px; font-size: 15px; }

/* 账单列表 */
.bill-list { border-top: 1px solid var(--line); }

.bill-row {
  display: grid;
  grid-template-columns: 118px 132px 96px 1fr 138px 104px;
  align-items: center;
  gap: 12px;
  padding: 12px 6px;
  border-bottom: 1px solid var(--line);
  transition: background .12s;
}

.bill-row:hover { background: #faf5e7; }

.bill-amount {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* 转移方向提示（如“生活费 → 存储资产”）：限制宽度并省略，避免与金额互相挤压 */
.bill-dir {
  display: inline-block;
  max-width: 96px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-3);
  margin-right: 5px;
}

.bill-note {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
}

.bill-time {
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* 类型徽标 */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid;
  white-space: nowrap;
}

.badge-type {
  color: var(--ink-2);
  border-color: var(--line);
  background: #faf6ea;
}

/* 分类彩色标签（颜色由前端按 cat_id 映射，--cat 由 JS 注入） */
/* 分类名最长 128 字：限制最大宽度并省略，防止长分类名撑破账单行/卡片 */
.cat-tag {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  color: #fff;
  background: var(--cat, #9a9388);
  white-space: nowrap;
}

/* 账单行内分类列：允许收缩，配合 .cat-tag 的省略 */
.bill-cat { min-width: 0; }

/* 行内图标按钮 */
.icon-btn {
  border: none;
  background: transparent;
  border-radius: 7px;
  padding: 5px;
  color: var(--ink-2);
  transition: background .12s, color .12s;
}

.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.icon-btn.danger:hover { background: #f6ded9; color: var(--danger); }

.icon-btn img { width: 16px; height: 16px; }

.bill-ops {
  display: flex;
  gap: 2px;
  justify-content: flex-end;
}

/* 空态 */
.empty {
  padding: 42px 0;
  text-align: center;
  color: var(--ink-3);
}

/* 分页 */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 16px;
}

.page-btn {
  padding: 6px 15px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
}

.page-btn:hover:not(:disabled) { border-color: var(--accent); }

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

.page-info { color: var(--ink-2); font-size: 13px; }

/* ---------- 分类管理 ---------- */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}

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

.panel-head h2 { font-size: 16px; font-weight: 600; }

.panel-tip { color: var(--ink-2); font-size: 13px; margin-bottom: 12px; }

.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.cat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fffdf8;
}

.cat-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--cat, #9a9388);
  flex: 0 0 14px;
}

.cat-name { font-weight: 500; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-id { font-size: 12px; }
.cat-ops { display: flex; gap: 2px; }

/* ---------- 系统设置 ---------- */
.settings-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  flex-wrap: wrap;
}

.settings-row + .settings-row { border-top: 1px dashed var(--line); }

.settings-label { width: 110px; flex: 0 0 110px; color: var(--ink-2); }

.settings-row input[type="text"],
.settings-row input[type="number"] {
  width: 220px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
}

.ratio-value {
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---------- 弹窗 ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(44, 38, 24, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  width: 440px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  background: var(--bg-card);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

/* 弹窗标题：超长时省略，避免与关闭按钮互相挤压 */
.modal-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  padding: 4px;
  border-radius: 6px;
  color: var(--ink-2);
}

.modal-close:hover { background: var(--accent-soft); color: var(--accent); }
.modal-close img { width: 16px; height: 16px; }

.modal-body { padding: 18px 20px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line);
}

.modal-error {
  margin-top: 12px;
  padding: 9px 12px;
  border-radius: 7px;
  background: #f9e4df;
  color: var(--danger);
  font-size: 13px;
}

/* 表单 */
.form-group { margin-bottom: 14px; }

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--ink-2);
  margin-bottom: 5px;
}

.form-group .req { color: var(--neg); margin-left: 3px; }

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent);
}

/* 二级选择（收入/支出类型） */
.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 6px 0 2px;
}

.choice-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 18px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffdf8;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  transition: border-color .12s, background .12s;
}

.choice-btn:hover { border-color: var(--accent); background: var(--accent-soft); }

.choice-btn small {
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-3);
}

/* 确认框 */
.confirm-msg { color: var(--ink); line-height: 1.7; }

/* 详情 */
.detail-grid { margin-bottom: 6px; }

.detail-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap; /* 内容过长时标签与内容自动换行，避免互相挤压 */
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--line);
}

.detail-label {
  flex: 0 0 86px;
  color: var(--ink-2);
  font-size: 13px;
}

/* 详情内容：占满剩余宽度，长文字（备注/金额等）允许断行而非溢出 */
.detail-row > span:not(.detail-label) {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.detail-title {
  margin: 14px 0 4px;
  font-weight: 600;
  font-size: 14px;
}

.detail-row code {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-2);
  word-break: break-all;
}

/* 登录弹窗：宽度适中，输入框与按钮使用居中的窄列，避免横向撑满 */
.login-modal { width: 320px; }

.login-modal .modal-body { padding: 26px 28px 14px; }

.login-modal .modal-footer { display: none; }

/* 输入框、标签、登录按钮统一限制为居中的窄列（240px），覆盖全局 width:100% */
.login-modal .form-group label {
  display: block;
  max-width: 240px;
  margin: 0 auto 5px;
}

.login-modal .form-group input {
  display: block;
  width: 100%;
  max-width: 240px;
  margin: 0 auto;
  padding: 9px 12px;
}

.login-modal .btn-block {
  display: block;
  width: 100%;
  max-width: 240px;
  margin: 0 auto;
}

.login-tip { text-align: center; font-size: 12px; color: var(--ink-3); margin-top: 14px; }

/* ---------- Toast ---------- */
#toast-root {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  align-items: center;
}

.toast {
  padding: 10px 20px;
  border-radius: 8px;
  background: #3a3427;
  color: #f6efdd;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: toast-in .25s ease;
  max-width: 80vw;
}

.toast-success { background: #2e6b47; }
.toast-error { background: #96352a; }

.toast-out { opacity: 0; transition: opacity .3s; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

