/* ===== 财务系统设计系统 ===== */
:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-2: #fafbf9;
  --sidebar: #16302b;
  --sidebar-hover: #1f443c;
  --sidebar-active: #276b5c;
  --text: #1a2420;
  --text-2: #5b6b64;
  --text-3: #8b9a94;
  --border: #e3e7e4;
  --border-strong: #cfd6d1;
  --primary: #0f766e;
  --primary-hover: #0d6159;
  --primary-soft: #e6f2f0;
  --income: #0f766e;
  --expense: #c2410c;
  --warn: #b45309;
  --danger: #b91c1c;
  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(22, 48, 43, .06);
  --shadow: 0 2px 8px rgba(22, 48, 43, .08);
  --shadow-lg: 0 12px 32px rgba(22, 48, 43, .14);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ 布局 ============ */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 216px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: #d7e3df;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.brand {
  padding: 20px 18px 16px;
  display: flex;
  align-items: center;
  gap: 9px;
  border-bottom: 1px solid rgba(255, 255, 255, .09);
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #2f9e8a, #0f766e);
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.brand-text { font-size: 15px; font-weight: 600; color: #fff; letter-spacing: .3px; }
.brand-sub { font-size: 11px; color: #7ea49b; margin-top: -2px; }

.nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
}

.nav-group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: #6d928a;
  padding: 12px 10px 6px;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  color: #c5d6d1;
  cursor: pointer;
  font-size: 13.5px;
  transition: background .13s, color .13s;
  user-select: none;
}

.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; font-weight: 500; }
.nav-icon { width: 17px; text-align: center; flex-shrink: 0; opacity: .9; }

.sidebar-foot {
  padding: 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, .09);
  font-size: 12px;
  color: #8fada5;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.topbar {
  height: 58px;
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  gap: 16px;
}

.topbar-title { font-size: 16px; font-weight: 600; letter-spacing: .2px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.view {
  flex: 1;
  overflow-y: auto;
  padding: 22px;
}

/* ============ 排版 ============ */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-title { font-size: 20px; font-weight: 650; letter-spacing: -.2px; margin: 0; }
.page-desc { font-size: 13px; color: var(--text-2); margin: 3px 0 0; }

h3 { font-size: 14.5px; font-weight: 600; margin: 0; }
.muted { color: var(--text-2); }
.dim { color: var(--text-3); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; }
.center { text-align: center; }

/* ============ 卡片 ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-pad { padding: 18px; }
.card-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-body { padding: 16px 18px; }
.card-body.flush { padding: 0; }

/* 统计卡 */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 17px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.stat-label { font-size: 12.5px; color: var(--text-2); display: flex; align-items: center; gap: 5px; }
.stat-value {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -.8px;
  margin-top: 5px;
  line-height: 1.15;
}
.stat-value.sm { font-size: 20px; }
.stat-foot { font-size: 12px; color: var(--text-3); margin-top: 5px; }

.amount-in { color: var(--income); }
.amount-out { color: var(--expense); }
.amount-neg { color: var(--danger); }

/* ============ 按钮 ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: background .13s, border-color .13s, box-shadow .13s;
}
.btn:hover { background: var(--surface-2); border-color: #bcc6c0; }
.btn:active { transform: translateY(.5px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(15, 118, 110, .25);
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: rgba(15, 118, 110, .07); border-color: transparent; }

.btn-danger { color: var(--danger); border-color: #e6c4c4; background: #fdf6f6; }
.btn-danger:hover { background: #fbeaea; border-color: #d9a8a8; }

.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 6px; }
.btn-icon { width: 34px; padding: 0; }
.btn-block { width: 100%; }

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

/* ============ 表单 ============ */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field-label { font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.field-hint { font-size: 11.5px; color: var(--text-3); }

.input, .select, .textarea {
  height: 36px;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  outline: none;
  transition: border-color .13s, box-shadow .13s;
  width: 100%;
}
.textarea { height: auto; padding: 8px 11px; resize: vertical; min-height: 68px; line-height: 1.5; }

.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, .12);
}

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='7' viewBox='0 0 11 7'%3E%3Cpath fill='%235b6b64' d='M1 1l4.5 4.5L10 1'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 30px;
}

.input-sm { height: 30px; font-size: 13px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

/* 金额分段选择 */
.seg {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
}
.seg-btn {
  padding: 0 15px;
  height: 34px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text-2);
  font-weight: 500;
  border-right: 1px solid var(--border);
  transition: background .12s, color .12s;
}
.seg-btn:last-child { border-right: none; }
.seg-btn:hover { background: var(--surface-2); }
.seg-btn.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.seg-btn.active.expense { background: #fdeee7; color: var(--expense); }
.seg-btn.active.transfer { background: #eef2f8; color: #2f5b9c; }

/* ============ 表格 ============ */
.table-wrap { overflow-x: auto; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
table.data th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
table.data td {
  padding: 10px 14px;
  border-bottom: 1px solid #eef1ef;
  vertical-align: middle;
}
table.data tbody tr:hover { background: #fafcfb; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data .num { text-align: right; }

.row-actions { display: flex; gap: 4px; justify-content: flex-end; opacity: .35; transition: opacity .13s; }
tr:hover .row-actions { opacity: 1; }

/* ============ 徽章 ============ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 21px;
  padding: 0 8px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge-in { background: #e7f4f1; color: #0b5d56; border-color: #cbe7e2; }
.badge-out { background: #fdeee7; color: #9a3412; border-color: #f6d9cb; }
.badge-move { background: #eef2f8; color: #2f5b9c; border-color: #d8e1ef; }
.badge-warn { background: #fdf3e3; color: var(--warn); border-color: #f4e0bd; }
.badge-danger { background: #fbeaea; color: var(--danger); border-color: #efd0d0; }
.badge-ok { background: #e8f5ec; color: #186b3a; border-color: #cfe8d8; }

/* ============ 空状态 ============ */
.empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-3);
}
.empty-icon { font-size: 30px; margin-bottom: 10px; opacity: .55; }
.empty-text { font-size: 13.5px; }
.empty-sub { font-size: 12.5px; margin-top: 4px; }

/* ============ 弹窗 ============ */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(18, 34, 30, .48);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn .13s ease;
  backdrop-filter: blur(2px);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  animation: slideUp .17s cubic-bezier(.2, .8, .3, 1);
}
@keyframes slideUp { from { opacity: 0; transform: translateY(10px) scale(.99); } to { opacity: 1; transform: none; } }

.modal.modal-lg { max-width: 780px; }
.modal.modal-xl { max-width: 960px; }

.modal-head {
  padding: 17px 20px 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title { font-size: 15.5px; font-weight: 600; }
.modal-close {
  width: 28px; height: 28px;
  border: none; background: transparent;
  border-radius: 6px; cursor: pointer;
  color: var(--text-3); font-size: 17px; line-height: 1;
  display: grid; place-items: center;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }

.modal-body { padding: 18px 20px; overflow-y: auto; flex: 1; }
.modal-foot {
  padding: 13px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  flex-shrink: 0;
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ============ 提示 ============ */
.toast-host {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: #16302b;
  color: #fff;
  padding: 9px 17px;
  border-radius: 9px;
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  animation: toastIn .19s ease;
  max-width: 460px;
}
.toast.error { background: #96201f; }
.toast.success { background: #0d6b4f; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

.alert {
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 14px;
  border: 1px solid;
}
.alert-error { background: #fdf6f6; border-color: #efd0d0; color: #9b1c1c; }
.alert-info { background: #f0f7f6; border-color: #cbe3df; color: #0b5d56; }
.alert-warn { background: #fdf8ee; border-color: #f2e2bd; color: #8a5a08; }

/* ============ 登录页 ============ */
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 22% 18%, #2a5b52 0%, #16302b 42%, #0e211d 100%);
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 396px;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .34);
  padding: 30px 28px 26px;
}
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, #2f9e8a, #0f766e);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 18px;
  box-shadow: 0 3px 10px rgba(15, 118, 110, .35);
}
.auth-title { font-size: 17px; font-weight: 650; }
.auth-sub { font-size: 12px; color: var(--text-3); margin-top: -1px; }
.auth-tabs { display: flex; gap: 4px; margin-bottom: 18px; background: var(--bg); padding: 3px; border-radius: 9px; }
.auth-tab {
  flex: 1; height: 31px; border: none; background: transparent; border-radius: 7px;
  cursor: pointer; font-size: 13.5px; color: var(--text-2); font-weight: 500;
}
.auth-tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); font-weight: 600; }
.auth-foot { text-align: center; font-size: 12px; color: var(--text-3); margin-top: 18px; }

/* ============ 图表 ============ */
.chart-box { position: relative; height: 250px; }
.chart-box.tall { height: 300px; }
.chart-box.short { height: 200px; }

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

/* 分类图例 */
.legend { display: flex; flex-direction: column; gap: 2px; }
.legend-row {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 4px; border-radius: 6px; font-size: 13px;
}
.legend-row:hover { background: var(--surface-2); }
.legend-dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
.legend-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-val { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 12.5px; }
.legend-pct { font-family: var(--mono); font-size: 11.5px; color: var(--text-3); width: 42px; text-align: right; }

/* 预算条 */
.budget-row { padding: 11px 0; border-bottom: 1px solid #eef1ef; }
.budget-row:last-child { border-bottom: none; }
.budget-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 7px; font-size: 13px; }
.budget-name { display: flex; align-items: center; gap: 7px; font-weight: 500; }
.budget-nums { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--text-2); }
.bar { height: 7px; background: #eef1ef; border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; transition: width .35s cubic-bezier(.3, .9, .4, 1); }
.bar-fill.ok { background: linear-gradient(90deg, #34a894, #0f766e); }
.bar-fill.warn { background: linear-gradient(90deg, #e5a13c, #cf7d10); }
.bar-fill.over { background: linear-gradient(90deg, #e06060, #b91c1c); }

/* ============ 工具条 ============ */
.toolbar {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.toolbar .spacer { flex: 1; }
.toolbar .input, .toolbar .select { width: auto; min-width: 120px; }

.pill-nav {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
  flex-wrap: wrap;
}
.pill {
  height: 29px; padding: 0 13px;
  border: none; background: transparent;
  border-radius: 7px; cursor: pointer;
  font-size: 13px; color: var(--text-2); font-weight: 500;
  white-space: nowrap;
}
.pill:hover { background: rgba(255, 255, 255, .7); }
.pill.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); font-weight: 600; }

/* 分页 */
.pager {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 16px; border-top: 1px solid var(--border);
  font-size: 12.5px; color: var(--text-2);
  gap: 12px; flex-wrap: wrap;
}
.pager-btns { display: flex; gap: 5px; align-items: center; }

/* 科目选择 */
.coa-pick { position: relative; }
.coa-list {
  position: absolute; top: calc(100% + 3px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  max-height: 240px; overflow-y: auto; z-index: 30;
}
.coa-opt { padding: 7px 11px; cursor: pointer; font-size: 13px; display: flex; gap: 8px; }
.coa-opt:hover, .coa-opt.hl { background: var(--primary-soft); }
.coa-code { font-family: var(--mono); font-size: 12px; color: var(--text-3); width: 52px; flex-shrink: 0; }

/* 凭证分录表 */
.entry-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.entry-table th {
  font-size: 11.5px; color: var(--text-2); font-weight: 600;
  padding: 7px 6px; text-align: left; border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.entry-table td { padding: 4px 5px; border-bottom: 1px solid #f1f4f2; vertical-align: top; }
.entry-table .input { height: 32px; font-size: 13px; }
.entry-table tr.entry-foot td {
  border-top: 1.5px solid var(--border-strong);
  border-bottom: none;
  padding-top: 8px;
  font-weight: 600;
  background: var(--surface-2);
}
.balance-ok { color: var(--income); }
.balance-bad { color: var(--danger); }

/* 报表打印 */
.report-sheet {
  background: var(--surface);
  padding: 26px 30px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.report-title { text-align: center; font-size: 17px; font-weight: 650; margin-bottom: 4px; }
.report-sub { text-align: center; font-size: 12.5px; color: var(--text-2); margin-bottom: 18px; }
table.report {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
table.report th {
  background: #f2f5f3; border: 1px solid var(--border-strong);
  padding: 7px 9px; font-size: 12px; font-weight: 600;
}
table.report td {
  border: 1px solid var(--border); padding: 6px 9px;
}
table.report td.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
table.report tr.total td { font-weight: 650; background: #f7f9f8; }
table.report tr.section td { background: #eef3f1; font-weight: 600; font-size: 12.5px; }

/* 加载 */
.spinner {
  width: 17px; height: 17px;
  border: 2px solid rgba(15, 118, 110, .2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-pane { display: grid; place-items: center; padding: 60px; }

/* 移动端 */
.mobile-only { display: none; }
@media (max-width: 860px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 200;
    transform: translateX(-100%); transition: transform .2s ease;
    width: 236px;
  }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .mobile-only { display: inline-flex; }
  .grid-2, .grid-2-1, .grid-1-2, .grid-3 { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .view { padding: 14px; }
  .topbar { padding: 0 14px; }
  .stat-value { font-size: 22px; }
}

@media print {
  .sidebar, .topbar, .toolbar, .page-head .btn-group, .btn { display: none !important; }
  .app-shell { display: block; height: auto; }
  .view { overflow: visible; padding: 0; }
  .report-sheet { border: none; padding: 0; }
  body { background: #fff; }
}