:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #e5e7eb;
  --line-strong: #d5d8de;
  --text: #1c2026;
  --text-2: #5b6270;
  --text-3: #8b93a1;
  --brand: #1f5fa8;
  --brand-soft: #eaf1fa;
  --income: #b4293c;
  --expense: #1f7a5c;
  --warn: #a86413;
  --warn-soft: #fdf3e3;
  --danger: #b4293c;
  --danger-soft: #fbecee;
  --ok-soft: #e8f5ef;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 8px 24px rgba(16,24,40,.04);
}

* { box-sizing: border-box; }

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

#app { display: flex; min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 216px;
  flex: 0 0 216px;
  background: #fbfbfc;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 14px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 18px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 600;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-text strong { font-size: 14px; font-weight: 600; }
.brand-text span { font-size: 11px; color: var(--text-3); }

#nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px;
  color: var(--text-2); text-decoration: none;
  font-size: 13.5px; cursor: pointer;
  border: none; background: none; width: 100%; text-align: left;
  font-family: inherit;
}
.nav-item:hover { background: #f0f1f4; color: var(--text); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 500; }
.nav-item .ico { width: 16px; text-align: center; font-size: 13px; opacity: .85; }
.nav-item .badge {
  margin-left: auto; min-width: 18px; padding: 0 5px; height: 17px;
  border-radius: 9px; background: #e8ebf0; color: var(--text-2);
  font-size: 11px; line-height: 17px; text-align: center; font-weight: 500;
}
.nav-item .badge.hot { background: var(--danger-soft); color: var(--danger); }

.sidebar-foot { border-top: 1px solid var(--line); padding-top: 12px; }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 8px; border-radius: 8px; cursor: pointer;
}
.user-chip:hover { background: #f0f1f4; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; flex: 0 0 26px;
}
.user-chip .name { font-size: 13px; }
.user-chip .role { font-size: 11px; color: var(--text-3); }
.store-hint { font-size: 10.5px; color: var(--text-3); padding: 8px 8px 0; line-height: 1.5; }

/* ---------- main ---------- */
main { flex: 1; min-width: 0; padding: 22px 28px 40px; }

.topbar {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 18px;
}
.topbar h1 { font-size: 19px; font-weight: 600; margin: 0 0 2px; letter-spacing: -.2px; }
.topbar p { margin: 0; font-size: 12.5px; color: var(--text-3); }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: 7px;
  border: 1px solid var(--line-strong); background: #fff; color: var(--text);
  font-size: 13px; font-family: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #b9bec7; background: #fafafb; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #1a5393; border-color: #1a5393; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: #f0f1f4; }
.btn.danger { color: var(--danger); border-color: #eccdd2; background: #fff; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { height: 26px; padding: 0 9px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- cards ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.card-head h2 { font-size: 14px; font-weight: 600; margin: 0; }
.card-head .sub { font-size: 12px; color: var(--text-3); }
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 14px; }
.grid.c4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid.c2 { grid-template-columns: repeat(2, minmax(0,1fr)); }

.kpi { padding: 14px 16px; }
.kpi .label { font-size: 12px; color: var(--text-3); display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 22px; font-weight: 600; margin-top: 6px; letter-spacing: -.4px; font-variant-numeric: tabular-nums; }
.kpi .foot { font-size: 11.5px; color: var(--text-3); margin-top: 4px; }
.kpi.accent { background: linear-gradient(180deg,#f7faff,#fff); border-color: #dbe5f2; }
.amt-in { color: var(--income); }
.amt-out { color: var(--expense); }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; font-weight: 500; color: var(--text-3);
  font-size: 11.5px; padding: 9px 12px; white-space: nowrap;
  background: #fafbfc; border-bottom: 1px solid var(--line);
}
tbody td { padding: 10px 12px; border-bottom: 1px solid #f0f1f4; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--text-2); }
.empty { padding: 44px 16px; text-align: center; color: var(--text-3); font-size: 13px; }

/* ---------- tags ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px; border-radius: 20px; font-size: 11.5px; line-height: 19px;
  border: 1px solid transparent; white-space: nowrap;
}
.tag.pending { background: var(--warn-soft); color: var(--warn); border-color: #f2e0c4; }
.tag.rejected { background: var(--danger-soft); color: var(--danger); border-color: #f0d3d7; }
.tag.checked { background: var(--brand-soft); color: var(--brand); border-color: #d5e3f4; }
.tag.paid { background: var(--ok-soft); color: #1c6b4f; border-color: #cfe8dc; }
.tag.void { background: #f1f2f4; color: var(--text-3); border-color: #e3e5e9; }
.tag.income { background: #fbeef0; color: var(--income); border-color: #f2d5d9; }
.tag.expense { background: #eaf5f0; color: var(--expense); border-color: #cfe8dd; }
.tag.plain { background: #f3f4f6; color: var(--text-2); border-color: #e5e7eb; }

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--text-2); }
.field label .req { color: var(--danger); margin-left: 2px; }
.field .stack { margin-top: 6px; }
input[type=text], input[type=date], input[type=number], input[type=tel], input[type=search], select, textarea {
  height: 34px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 7px;
  font-size: 13.5px; font-family: inherit; color: var(--text); background: #fff; width: 100%;
}
textarea { height: auto; min-height: 68px; padding: 8px 10px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31,95,168,.1); }
input[type=number] { text-align: right; font-variant-numeric: tabular-nums; }
.hint { font-size: 11.5px; color: var(--text-3); }
.err { font-size: 11.5px; color: var(--danger); }

.seg { display: inline-flex; background: #f1f2f4; padding: 3px; border-radius: 8px; gap: 2px; }
.seg button {
  border: none; background: none; padding: 5px 14px; border-radius: 6px;
  font-size: 13px; font-family: inherit; color: var(--text-2); cursor: pointer;
}
.seg button.on { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(16,24,40,.08); font-weight: 500; }
.seg button.on.income { color: var(--income); }
.seg button.on.expense { color: var(--expense); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.toolbar input[type=search] { width: 200px; }
.toolbar select { width: auto; min-width: 110px; }
.toolbar .spacer { flex: 1; }

/* ---------- modal ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(20,26,35,.32);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 56px 16px; z-index: 60; overflow-y: auto;
}
.modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 560px;
  box-shadow: 0 20px 48px rgba(16,24,40,.18); overflow: hidden;
}
.modal.wide { max-width: 760px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.modal-body { padding: 20px; max-height: 62vh; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: #fcfcfd; }
.icon-btn { border: none; background: none; font-size: 18px; color: var(--text-3); cursor: pointer; line-height: 1; padding: 4px; }
.icon-btn:hover { color: var(--text); }

/* ---------- toast ---------- */
#toastRoot { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: #232a33; color: #fff; padding: 8px 16px; border-radius: 8px;
  font-size: 13px; box-shadow: 0 8px 24px rgba(16,24,40,.2); animation: pop .18s ease;
}
.toast.err { background: #8f1f2c; }
/* ---------- supplier ---------- */
.chip {
  display: inline-flex; align-items: center;
  padding: 1px 8px; border-radius: 6px; font-size: 11.5px; line-height: 19px;
  background: #f2f4f7; color: var(--text-2); border: 1px solid var(--line);
  margin: 1px 4px 1px 0; white-space: nowrap;
}
.chip.more { background: var(--brand-soft); color: var(--brand); border-color: #d5e3f4; }

.channel-row {
  display: grid; grid-template-columns: 1.2fr 1fr 30px; gap: 8px; align-items: center;
  margin-bottom: 8px;
}
.channel-row .icon-btn { justify-self: center; font-size: 16px; padding: 2px; }
input[readonly] { background: #f7f8fa; color: var(--text-2); cursor: default; }

@media (max-width: 720px) {
  .channel-row { grid-template-columns: 1fr; }
}

/* ---------- option settings ---------- */
.opt-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 24px; }
.opt-block { min-width: 0; }
.opt-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; min-height: 24px; }
.opt-chips .chip { padding-right: 3px; }
.chip-x {
  border: none; background: none; padding: 0 2px 0 5px; margin: 0; cursor: pointer;
  color: var(--text-3); font-size: 13px; line-height: 1; font-family: inherit;
}
.chip-x:hover { color: var(--danger); }
.opt-add { display: flex; gap: 6px; }
.opt-add input { height: 28px; font-size: 12.5px; }
.field-label-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.link-btn {
  border: none; background: none; padding: 0; color: var(--brand);
  font-size: 11.5px; cursor: pointer; font-family: inherit;
}
.link-btn:hover { text-decoration: underline; }

@media (max-width: 900px) {
  .opt-grid { grid-template-columns: 1fr; }
}

@keyframes pop { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---------- misc ---------- */
.section-title { font-size: 12px; color: var(--text-3); margin: 0 0 8px; font-weight: 500; letter-spacing: .2px; }
.dl { display: grid; grid-template-columns: 96px 1fr; gap: 8px 12px; font-size: 13px; }
.dl dt { color: var(--text-3); }
.dl dd { margin: 0; }
.timeline { display: flex; flex-direction: column; gap: 0; }
.tl-item { display: flex; gap: 10px; padding-bottom: 14px; position: relative; }
.tl-item:not(:last-child)::before {
  content: ""; position: absolute; left: 5px; top: 16px; bottom: 0; width: 1px; background: var(--line);
}
.tl-dot { width: 11px; height: 11px; border-radius: 50%; background: #fff; border: 2px solid var(--line-strong); margin-top: 4px; flex: 0 0 11px; }
.tl-dot.done { border-color: var(--brand); background: var(--brand); }
.tl-main { font-size: 13px; }
.tl-meta { font-size: 11.5px; color: var(--text-3); }

.bar-row { display: grid; grid-template-columns: 90px 1fr 92px; gap: 10px; align-items: center; font-size: 12.5px; padding: 5px 0; }
.bar-track { height: 8px; background: #f1f2f4; border-radius: 4px; overflow: hidden; display: flex; }
.bar-fill { height: 100%; border-radius: 4px; }
.bar-fill.in { background: var(--income); opacity: .75; }
.bar-fill.out { background: var(--expense); opacity: .75; }

.flat-list { list-style: none; margin: 0; padding: 0; }
.flat-list li { padding: 10px 16px; border-bottom: 1px solid #f0f1f4; display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.flat-list li:last-child { border-bottom: none; }

.checkbox { width: 15px; height: 15px; accent-color: var(--brand); cursor: pointer; }

@media (max-width: 1180px) {
  .grid.c4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid.c3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media print {
  .sidebar, .topbar-actions, .toolbar { display: none !important; }
  main { padding: 0; }
  .card { box-shadow: none; border: none; }
}
