/* ========== 基础 ========== */
:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --line: #e3e7ec;
  --line-soft: #eef1f4;
  --primary: #3f6ea8;
  --primary-dark: #335b8b;
  --primary-soft: #eaf1f8;
  --in: #2f7d5f;
  --in-soft: #e8f4ee;
  --out: #b4453a;
  --out-soft: #faedeb;
  --warn: #a9721a;
  --warn-soft: #fdf4e3;
  --danger: #b4453a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(24, 39, 56, 0.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
    "PingFang SC", "Hiragino Sans GB", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.spacer { flex: 1; }

/* ========== 登录 ========== */
.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, #eef2f7 0%, #f7f8fa 100%);
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 24px 22px;
  box-shadow: 0 8px 24px rgba(24, 39, 56, 0.07);
}
.login-brand { font-size: 22px; font-weight: 700; letter-spacing: 1px; }
.login-sub { color: var(--muted); font-size: 12px; margin: 4px 0 20px; letter-spacing: .5px; }
.login-card input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  background: #fbfcfd;
}
.login-card input:focus { border-color: var(--primary); background: #fff; }
.login-err { color: var(--danger); font-size: 12px; min-height: 18px; margin: 10px 0 0; }
.btn-block { width: 100%; margin-top: 14px; }

/* ========== 顶部 ========== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 18px;
  height: 54px;
  display: flex;
  align-items: center;
  gap: 22px;
}
.brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
  letter-spacing: .5px;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.tabs {
  display: flex;
  gap: 2px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  padding: 7px 12px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 13.5px;
  white-space: nowrap;
}
.tabs a:hover { background: var(--line-soft); text-decoration: none; color: var(--text); }
.tabs a.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.icon-link { color: var(--muted); font-size: 13px; }
.icon-link.active { color: var(--primary-dark); font-weight: 600; }

/* ========== 布局 ========== */
.view {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 18px 64px;
}
.page-head {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.page-title { font-size: 19px; font-weight: 700; margin: 0; }
.page-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.page-head .spacer { flex: 1; }

.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.card-title { font-size: 13.5px; font-weight: 600; color: var(--text); }
.card-title .muted { font-weight: 400; }

.stat-label { color: var(--muted); font-size: 12px; }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-value.small { font-size: 19px; }
.stat-foot { color: var(--muted); font-size: 11.5px; margin-top: 4px; }

/* ========== 按钮 ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #f7f8fa; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--line-soft); color: var(--text); }
.btn-danger { color: var(--danger); border-color: #edcfcb; background: #fff; }
.btn-danger:hover { background: var(--out-soft); }
.btn-sm { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.btn-icon { padding: 4px 7px; font-size: 12px; }

/* ========== 表单 ========== */
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 13.5px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  outline: none;
  width: 100%;
}
.field textarea { resize: vertical; min-height: 64px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .span-2 { grid-column: span 2; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.toolbar input[type="text"], .toolbar input[type="date"], .toolbar select {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  outline: none;
}
.toolbar input:focus, .toolbar select:focus { border-color: var(--primary); }

/* ========== 表格 ========== */
.table-wrap { overflow-x: auto; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left;
  font-weight: 600;
  font-size: 11.5px;
  color: var(--muted);
  background: #fafbfc;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl tbody tr:hover { background: #fafbfc; }
table.tbl tr.is-done td { color: var(--muted); }
table.tbl tr.is-done .t-title { text-decoration: line-through; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ========== 徽标 ========== */
.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 20px;
  font-size: 11.5px;
  line-height: 18px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-in { background: var(--in-soft); color: var(--in); border-color: #cfe8dc; }
.badge-out { background: var(--out-soft); color: var(--out); border-color: #efd4cf; }
.badge-muted { background: #f2f4f6; color: var(--muted); border-color: var(--line); }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: #f0e0bf; }
.badge-primary { background: var(--primary-soft); color: var(--primary-dark); border-color: #d3e2f1; }
.badge-ok { background: var(--in-soft); color: var(--in); border-color: #cfe8dc; }
.badge-danger { background: var(--out-soft); color: var(--out); border-color: #efd4cf; }

.amount-in { color: var(--in); font-weight: 600; }
.amount-out { color: var(--out); font-weight: 600; }
.amount-neg { color: var(--out); }

/* ========== 进度 ========== */
.progress {
  height: 5px;
  background: var(--line-soft);
  border-radius: 20px;
  overflow: hidden;
  min-width: 60px;
}
.progress > i { display: block; height: 100%; background: var(--primary); border-radius: 20px; }

/* ========== 快捷入口 ========== */
.quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 12px;
}
.quick-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 96px;
  padding: 16px 14px;
  border: 1px solid var(--qi-border, var(--line));
  border-radius: 12px;
  background: var(--qi-bg, #fdfefe);
  color: var(--qi-text, var(--text));
  text-align: center;
  transition: border-color 0.18s ease, background-color 0.18s ease, box-shadow 0.18s ease,
    color 0.18s ease;
}
.quick-item:hover {
  border-color: var(--qi-hover-border, var(--primary));
  background: var(--qi-hover-bg, var(--primary-soft));
  color: var(--qi-text, var(--primary-dark));
  box-shadow: 0 2px 8px rgba(63, 110, 168, 0.1);
  text-decoration: none;
}
.quick-item-name {
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.quick-item-arrow {
  font-size: 12px;
  line-height: 1;
  color: currentColor;
  opacity: 0.5;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.quick-item:hover .quick-item-arrow {
  opacity: 0.85;
  transform: translate(2px, -2px);
}

/* ========== 空状态 / 加载 ========== */
.empty {
  padding: 44px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.empty-title { font-size: 14px; color: var(--text); margin-bottom: 4px; font-weight: 600; }
.loading { padding: 60px 16px; text-align: center; color: var(--muted); font-size: 13px; }

/* ========== 模态 ========== */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(20, 27, 38, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 60;
}
.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 18px 48px rgba(15, 23, 35, 0.22);
}
.modal.wide { max-width: 900px; }
.modal-head {
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
}
.modal-title { font-size: 15px; font-weight: 700; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot {
  padding: 13px 18px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
}

/* ========== Toast ========== */
.toast-wrap {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 90;
  pointer-events: none;
}
.toast {
  background: #232a36;
  color: #fff;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 8px 22px rgba(15, 23, 35, 0.25);
  animation: toast-in .16s ease-out;
  pointer-events: auto;
  max-width: 80vw;
}
.toast.err { background: #8f342b; }
.toast.ok { background: #2b6a52; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ========== 图表 ========== */
.chart-box { width: 100%; overflow-x: auto; }
.chart-box svg { display: block; width: 100%; height: auto; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

/* ========== 导入预览 ========== */
.import-summary { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 14px; }
.import-summary div { font-size: 12px; color: var(--muted); }
.import-summary strong { display: block; font-size: 17px; color: var(--text); font-variant-numeric: tabular-nums; }
.warn-box {
  background: var(--warn-soft);
  border: 1px solid #f0e0bf;
  color: #7a5514;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
  margin-bottom: 12px;
}
.err-box {
  background: var(--out-soft);
  border: 1px solid #efd4cf;
  color: #8f342b;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
  margin-bottom: 12px;
}
.preview-table { max-height: 46vh; overflow-y: auto; }
.preview-table table.tbl th { position: sticky; top: 0; z-index: 1; }
.tag-new { color: var(--in); }
.tag-dup { color: var(--muted); }
.tag-warn { color: var(--warn); }
.tag-error { color: var(--danger); }

/* ========== 响应式 ========== */
@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .topbar-inner { height: auto; padding: 8px 12px; flex-wrap: wrap; gap: 8px; }
  .tabs { order: 3; width: 100%; gap: 1px; }
  .tabs a { padding: 6px 9px; font-size: 13px; }
  .view { padding: 14px 12px 56px; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: span 1; }
  .page-title { font-size: 17px; }
  .stat-value { font-size: 21px; }
  .modal { max-height: 92vh; }
  .modal-body { padding: 14px; }
  .quick-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .quick-item { min-height: 84px; padding: 14px 10px; }
}
