:root {
  --bg: #0d1117;
  --bg-soft: #131a23;
  --surface: #161e28;
  --surface-2: #1c2531;
  --surface-3: #222d3b;
  --border: #26313f;
  --border-soft: #1e2733;
  --text: #e6edf3;
  --text-soft: #a9b6c5;
  --muted: #7d8b9c;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.14);
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --debit: #f97316;
  --credit: #38bdf8;
  --radius: 10px;
  --font: "Microsoft YaHei", "PingFang SC", -apple-system, "Segoe UI", sans-serif;
  --mono: "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.block { display: block; }

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(900px 500px at 50% -10%, rgba(59, 130, 246, 0.14), transparent 70%), var(--bg);
  padding: 24px;
}
.login-card {
  width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  display: grid; place-items: center;
  font-weight: 600; color: #fff; flex: 0 0 auto;
}
.brand h1 { font-size: 17px; margin: 0 0 2px; font-weight: 600; }
.brand p { margin: 0; font-size: 12px; }
.brand.small { padding: 4px 2px 16px; }
.brand.small strong { font-size: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-soft); }
.field input, .field select, .field textarea,
input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:not([type="checkbox"]):not([type="radio"]):focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input:disabled, select:disabled { opacity: .55; cursor: not-allowed; }
input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; }

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); border-color: #35455a; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #2f74e0; }
.btn.danger { background: rgba(239, 68, 68, .12); border-color: rgba(239, 68, 68, .35); color: #fca5a5; }
.btn.danger:hover { background: rgba(239, 68, 68, .2); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; }
.btn.link { background: none; border: none; color: var(--accent); padding: 0 6px; }
.btn.link:hover { text-decoration: underline; }

.form-error {
  background: rgba(239, 68, 68, .12);
  border: 1px solid rgba(239, 68, 68, .35);
  color: #fca5a5;
  padding: 8px 11px;
  border-radius: 8px;
  font-size: 13px;
}
.hint { font-size: 12px; color: var(--muted); margin: 0; text-align: center; }

/* ---------- 主框架 ---------- */
.layout { display: grid; grid-template-columns: 216px 1fr; height: 100vh; }
.sidebar {
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 11px;
  border-radius: 8px;
  color: var(--text-soft);
  text-decoration: none;
  font-size: 13.5px;
  cursor: pointer;
  border: 1px solid transparent;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active {
  background: var(--accent-soft);
  color: #93c5fd;
  border-color: rgba(59, 130, 246, .32);
}
.nav-item .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .6; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.user-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; }
.pill {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-soft); border: 1px solid var(--border);
}

.content { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  height: 56px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px;
  gap: 12px;
  background: var(--bg-soft);
  flex: 0 0 auto;
}
.topbar-left { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.inline-field { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.inline-field select { padding: 5px 8px; font-size: 13px; border-radius: 7px; }
.view { padding: 18px; overflow: auto; flex: 1; min-height: 0; }

.badge { font-size: 12px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.badge.ok { color: #86efac; border-color: rgba(34, 197, 94, .35); background: rgba(34, 197, 94, .1); }
.badge.warn { color: #fcd34d; border-color: rgba(245, 158, 11, .35); background: rgba(245, 158, 11, .1); }

/* ---------- 通用块 ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { margin: 0 0 4px; font-size: 18px; font-weight: 600; }
.page-head p { margin: 0; font-size: 13px; color: var(--muted); }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h3 { margin: 0; font-size: 14px; font-weight: 600; }

.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px 16px; }
.stat .label { font-size: 12.5px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.stat .value { font-family: var(--mono); font-size: 23px; margin: 8px 0 6px; font-weight: 600; letter-spacing: -.5px; }
.stat .sub { font-size: 12px; color: var(--muted); display: flex; gap: 12px; flex-wrap: wrap; }
.stat .sub b { color: var(--text-soft); font-weight: 500; font-family: var(--mono); }

/* ---------- 表格 ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  background: var(--surface-2);
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tbody tr:hover { background: rgba(255, 255, 255, .022); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-family: var(--mono); }
td.debit { color: var(--debit); }
td.credit { color: var(--credit); }
td.mono { font-family: var(--mono); }
tr.total-row td { background: var(--surface-2); font-weight: 600; }
tr.emphasize td { background: rgba(59, 130, 246, .06); font-weight: 600; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); font-size: 13px; }

.status { font-size: 12px; padding: 2px 8px; border-radius: 6px; white-space: nowrap; }
.status.draft { background: rgba(148, 163, 184, .16); color: #cbd5e1; }
.status.audited { background: rgba(245, 158, 11, .14); color: #fcd34d; }
.status.posted { background: rgba(34, 197, 94, .14); color: #86efac; }
.status.closed { background: rgba(59, 130, 246, .16); color: #93c5fd; }

/* ---------- 表单 ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.form-row .field { min-width: 140px; }
.toolbar {
  display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px;
}
.toolbar .field { min-width: 120px; }

/* ---------- 凭证分录 ---------- */
.entry-table { width: 100%; border-collapse: collapse; }
.entry-table th { font-size: 12px; color: var(--muted); font-weight: 500; padding: 8px; border-bottom: 1px solid var(--border); text-align: left; background: var(--surface-2); }
.entry-table td { padding: 4px 4px; border-bottom: 1px solid var(--border-soft); }
.entry-table input { width: 100%; padding: 7px 8px; font-size: 13px; border-radius: 6px; }
.entry-table input.amount { text-align: right; font-family: var(--mono); }
.entry-table .line-no { color: var(--muted); font-family: var(--mono); font-size: 12px; text-align: center; width: 34px; }
.entry-foot {
  display: flex; justify-content: flex-end; gap: 26px;
  padding: 10px 14px; background: var(--surface-2);
  border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  font-family: var(--mono); font-size: 13.5px;
}
.entry-foot .diff.bad { color: #fca5a5; }
.entry-foot .diff.ok { color: #86efac; }

.combo { position: relative; }
.combo-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  max-height: 240px; overflow: auto;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; z-index: 30;
  box-shadow: 0 10px 26px rgba(0, 0, 0, .45);
}
.combo-list div { padding: 7px 10px; font-size: 13px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.combo-list div:hover, .combo-list div.active { background: var(--accent-soft); }
.combo-list .code { font-family: var(--mono); color: var(--text-soft); }
.combo-list .name { color: var(--text); }

/* ---------- 结账清单 ---------- */
.check-item {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 9px; background: var(--surface); margin-bottom: 8px;
}
.check-icon {
  width: 20px; height: 20px; border-radius: 50%; flex: 0 0 auto; margin-top: 1px;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.check-icon.ok { background: rgba(34, 197, 94, .16); color: #86efac; }
.check-icon.bad { background: rgba(239, 68, 68, .16); color: #fca5a5; }
.check-icon.warn { background: rgba(245, 158, 11, .16); color: #fcd34d; }
.check-body { flex: 1; min-width: 0; }
.check-body strong { font-size: 13.5px; font-weight: 500; display: block; margin-bottom: 3px; }
.check-body span { font-size: 12.5px; color: var(--muted); }

/* ---------- 报表 ---------- */
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 1100px) { .report-grid { grid-template-columns: 1fr; } }
.report-table tbody td.indent-1 { padding-left: 26px; }
.report-table tbody td.indent-2 { padding-left: 40px; }

/* ---------- 提示 ---------- */
.toast-host { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  padding: 10px 15px; border-radius: 9px; font-size: 13px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); min-width: 200px; max-width: 380px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .45);
  animation: slide-in .18s ease-out;
}
.toast.ok { border-color: rgba(34, 197, 94, .4); color: #bbf7d0; }
.toast.error { border-color: rgba(239, 68, 68, .45); color: #fecaca; }
.toast.info { border-color: rgba(59, 130, 246, .4); color: #bfdbfe; }
@keyframes slide-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.loading { padding: 40px; text-align: center; color: var(--muted); font-size: 13px; }
.section-gap { margin-top: 16px; }
.split-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 1000px) { .split-2 { grid-template-columns: 1fr; } }
textarea.memo { width: 100%; min-height: 60px; resize: vertical; }

/* 预算执行进度条 */
.bar {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
  margin-bottom: 3px;
}
.bar > i {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--ok);
  transition: width 0.2s ease;
}

/* ---------- 审批流节点 ---------- */
.flow-step { align-items: flex-end; }
.flow-step-no {
  width: 24px; height: 24px; flex: 0 0 auto; margin-bottom: 9px;
  border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; font-weight: 600; font-family: var(--mono);
  background: var(--accent-soft); color: #93c5fd; border: 1px solid rgba(59, 130, 246, .35);
}

/* ---------- 打印 ---------- */
@media print {
  :root {
    --bg: #fff;
    --bg-soft: #fff;
    --surface: #fff;
    --surface-2: #fff;
    --surface-3: #f5f5f5;
    --border: #b9b9b9;
    --border-soft: #d2d2d2;
    --text: #111;
    --text-soft: #333;
    --muted: #555;
    --accent: #111;
  }
  @page { size: A4; margin: 14mm 12mm; }

  html, body { background: #fff !important; color: #111 !important; font-size: 11.5pt; }
  .sidebar, .topbar, .topbar-right, .page-head .actions,
  .row-actions, .toast-host, .card-head .btn, #voucher-attach-host,
  .card .actions, .empty-actions, .bar { display: none !important; }
  button, .btn { display: none !important; }

  .layout { display: block !important; }
  .content, .view { padding: 0 !important; margin: 0 !important; max-width: none !important; }
  .card, .table-wrap, table { box-shadow: none !important; }
  .card { border: 1px solid #b9b9b9 !important; break-inside: avoid; margin-bottom: 8mm !important; }
  .card-head { border-bottom: 1px solid #d2d2d2 !important; }
  .page-head h2 { font-size: 16pt !important; margin: 0 0 2mm !important; }
  .page-head p { color: #555 !important; }
  .form-row { display: flex !important; flex-wrap: wrap !important; gap: 8mm !important; }
  .field > span { color: #555 !important; font-size: 9.5pt !important; }
  .entry-foot { display: flex !important; gap: 10mm !important; padding: 3mm 0 !important; color: #111 !important; }
  .entry-foot .diff { color: #111 !important; }

  table { border-collapse: collapse !important; width: 100% !important; }
  th, td { border: 1px solid #cfcfcf !important; padding: 4px 6px !important; color: #111 !important; }
  thead th { background: #eee !important; }
  tbody tr { break-inside: avoid; }

  .status, .pill, .badge { border: 1px solid #999 !important; color: #111 !important; background: #fff !important; }
  .mono { font-family: var(--mono) !important; }
  a { color: #111 !important; text-decoration: none !important; }
  input, select, textarea { border: none !important; color: #111 !important; background: #fff !important; }
  select { appearance: none !important; -webkit-appearance: none !important; }
  .no-print { display: none !important; }
}

/* 仅在打印时出现的凭证抬头 */
.print-only { display: none; }
@media print {
  .print-only { display: block !important; }
  .print-head { display: flex !important; align-items: flex-end; justify-content: space-between; gap: 6mm; border-bottom: 1.5pt solid #111 !important; padding-bottom: 3mm; margin-bottom: 5mm; }
  .print-entity { font-size: 13pt; font-weight: 700; }
  .print-title { font-size: 17pt; font-weight: 700; letter-spacing: 4pt; }
  .print-meta { font-size: 10.5pt; color: #333 !important; font-family: var(--mono) !important; }
  .card > .form-row:first-of-type input,
  .card > .form-row:first-of-type select { font-weight: 600; }
  .entry-table td:last-child, .entry-table th:last-child { border: none !important; }
}

/* ---------- 提示条 ---------- */
.notice {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; border-radius: var(--radius);
  background: rgba(245, 158, 11, .1); border: 1px solid rgba(245, 158, 11, .38);
  color: #fcd34d; font-size: 13px; line-height: 1.55;
}
.notice b { color: #fde68a; }
.notice .btn { flex: 0 0 auto; }
