:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --border: #e6e8ec;
  --text: #1f2430;
  --text-2: #6b7280;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --red: #e5484d;      /* 进账 / 正 */
  --green: #2f9e44;    /* 支出 / 负 */
  --amber: #d97706;    /* 欠款 */
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }
/* 强制 hidden 属性生效，避免被 display:flex 等覆盖 */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }
/* 下拉框统一基线样式（后续所有 select 默认采用） */
select {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text);
}
select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  padding: 20px;
}
.login-card {
  width: 360px; max-width: 100%; background: #fff; border-radius: 16px;
  padding: 36px 32px; box-shadow: 0 20px 50px rgba(0,0,0,.2);
}
.login-logo, .brand-logo {
  width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center;
  justify-content: center; font-size: 24px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
}
.login-logo { margin: 0 auto 14px; }
.login-card h1 { font-size: 20px; text-align: center; margin: 0 0 4px; }
.login-sub { text-align: center; color: var(--text-2); margin: 0 0 24px; font-size: 13px; }
.login-card label { display: block; font-size: 13px; color: var(--text-2); margin: 12px 0 6px; }
.login-card input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
}
.login-card input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* ---------- 布局 ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex: 0 0 232px; background: #fff; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; border-bottom: 1px solid var(--border); }
.brand-logo { width: 36px; height: 36px; font-size: 18px; border-radius: 9px; }
.brand-name { font-weight: 600; font-size: 15px; }
.nav { flex: 1; padding: 14px 10px; display: flex; flex-direction: column; gap: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 12px 14px; border: none; background: transparent; border-radius: 8px;
  font-size: 14px; color: var(--text); transition: background .12s;
}
.nav-item .ic { width: 20px; text-align: center; flex: none; }
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.user-chip { display: flex; align-items: center; justify-content: space-between; }
.user-name { font-weight: 600; font-size: 13px; }

.content { flex: 1; padding: 24px 28px; min-width: 0; }

/* ---------- 通用 ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.page-title { font-size: 20px; font-weight: 700; margin: 0; }
.page-sub { color: var(--text-2); font-size: 13px; margin-top: 2px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card + .card { margin-top: 16px; }
.section-title { font-size: 15px; font-weight: 600; margin: 0 0 12px; }

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

.stat { padding: 16px 18px; min-height: 92px; display: flex; flex-direction: column; justify-content: center; }
.stat-label { font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.stat-value { font-size: 16px; font-weight: 700; }
.stat-value.pos { color: var(--red); }
.stat-value.neg { color: var(--green); }
.stat-value.warn { color: var(--amber); }
.stat-value.ok { color: var(--green); }

/* 卡片内等距数据行（项目/供货商卡片） */
.stat-rows { margin-top: 10px; display: flex; flex-direction: column; }
.stat-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.stat-row:last-child { border-bottom: none; }
.stat-row .k { color: var(--text-2); }

/* 仪表盘右上角摘要 */
.dash-summary { display: flex; gap: 28px; align-items: center; }
.dash-stat { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.35; }
.dash-stat .ds-label { font-size: 12px; color: var(--text-2); }
.dash-stat .ds-value { font-size: 16px; font-weight: 700; }
.dash-stat .ds-value.pos { color: var(--red); }
.dash-stat .ds-value.neg { color: var(--green); }
.dash-stat .ds-value.warn { color: var(--amber); }

/* 图表右上角图例（HTML 版，字号可控、固定在角落） */
.chart-legend { display: flex; gap: 14px; align-items: center; font-size: 12px; color: var(--text-2); }
.chart-legend .cl-item { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend .cl-item i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; color: var(--text); font-size: 14px; transition: all .12s;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: #fff; border-color: #fecaca; color: var(--red); }
.btn-danger:hover { background: #fef2f2; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- 表单 ---------- */
.form-row { display: flex; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.form-field { flex: 1; min-width: 160px; }
.form-field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.form-field label .req { color: var(--red); }
.form-field input, .form-field select, .form-field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.form-error { color: var(--red); font-size: 13px; min-height: 18px; margin: 4px 0; }

.seg { display: inline-flex; background: var(--bg); border-radius: 8px; padding: 3px; gap: 2px; }
.seg button {
  border: none; background: transparent; padding: 7px 16px; border-radius: 6px; font-size: 14px; color: var(--text-2);
}
.seg button.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.seg button.active.income { color: var(--red); }
.seg button.active.expense { color: var(--green); }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table.tbl {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-size: 13px; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
table.tbl th, table.tbl td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); }
table.tbl th {
  color: var(--text-2); font-weight: 600; font-size: 12px;
  background: #f7f8fa; text-transform: uppercase; letter-spacing: 0.4px;
  border-bottom: 2px solid var(--border); white-space: nowrap;
}
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tbody tr:nth-child(even) { background: #fafbfc; }
table.tbl tbody tr { transition: background .1s; }
table.tbl tbody tr:hover { background: var(--primary-soft); }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-action { color: var(--primary); cursor: pointer; margin-right: 10px; font-size: 13px; }
.row-action.danger { color: var(--red); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.income { background: #fef2f2; color: var(--red); }
.badge.expense { background: #e6f4ea; color: var(--green); }
.badge.warn { background: #fff4e5; color: var(--amber); }
.badge.ok { background: #e6f4ea; color: var(--green); }

.money-income { color: var(--red); font-weight: 600; }
.money-expense { color: var(--green); font-weight: 600; }
.money-neutral { font-weight: 600; }

.empty { text-align: center; color: var(--text-2); padding: 40px 0; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }

/* ---------- 附件 ---------- */
.att-list { display: flex; flex-direction: column; gap: 6px; }
.att-item { display: flex; align-items: center; gap: 10px; font-size: 13px; flex-wrap: wrap; }
.att-item a { color: var(--primary); text-decoration: none; }
.att-item a:hover { text-decoration: underline; }

/* ---------- 账单展开明细 ---------- */
.bill-detail-cell { padding: 14px 20px 14px 48px; background: #eceef4; border-left: 3px solid var(--primary); }

/* ---------- 项目资料：文件夹树 ---------- */
.doc-layout { display: flex; gap: 16px; align-items: flex-start; }
.doc-tree { width: 280px; flex: 0 0 280px; }
.doc-main { flex: 1; min-width: 0; }
.tree { font-size: 14px; }
.tree-node { display: flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.tree-node:hover { background: var(--bg); }
.tree-node.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.tree-node .fold { width: 16px; text-align: center; color: var(--text-2); font-size: 12px; }
.tree-node .fold-del { margin-left: auto; font-size: 12px; opacity: .5; }
.tree-node .fold-del:hover { opacity: 1; }
.tree-children { margin-left: 18px; border-left: 1px dashed var(--border); padding-left: 6px; }
.file-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.file-row:last-child { border-bottom: none; }
.file-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.file-name .fn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { color: var(--text-2); font-size: 12px; white-space: nowrap; }
.file-actions { display: flex; gap: 8px; white-space: nowrap; }
.file-actions a, .file-actions span { cursor: pointer; color: var(--primary); font-size: 13px; text-decoration: none; }
.file-actions .danger { color: var(--red); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tab {
  padding: 9px 16px; border: none; background: transparent; font-size: 14px; color: var(--text-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ---------- 明细行 ---------- */
.items-table input { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; }
.items-table select { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: #fff; font-size: 13px; }
.items-table input:focus { outline: none; border-color: var(--primary); }
.items-table select:focus { outline: none; border-color: var(--primary); }
.items-table td { padding: 6px 6px; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(16,24,40,.5); display: flex;
  align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal {
  background: #fff; border-radius: 12px; width: 680px; max-width: 100%; max-height: 90vh;
  overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }
.modal-close { border: none; background: transparent; font-size: 20px; color: var(--text-2); cursor: pointer; }

/* ---------- Toast ---------- */
.toast-root { position: fixed; top: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: #1f2430; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: slidein .18s ease;
}
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }
@keyframes slidein { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ---------- 响应式 ---------- */
@media (max-width: 860px) {
  .sidebar { width: 64px; flex-basis: 64px; }
  .brand-name, .nav-item span, .user-name { display: none; }
  .nav-item { text-align: center; padding: 12px 0; }
  .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 16px; }
}
