:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --line: #e8eaed;
  --line-strong: #d8dbe0;
  --text: #1f2329;
  --text-2: #646a73;
  --text-3: #8f959e;
  --brand: #e22e2e;
  --brand-soft: #fdecec;
  --blue: #2563eb;
  --green: #12a150;
  --orange: #ed7b2f;
  --purple: #7c5cff;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; font-weight: 600; }

/* ---------- login ---------- */
.login-screen {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(135deg, #fff 0%, #fff4f4 100%);
  display: grid; place-items: center; padding: 20px;
}
.login-screen[hidden] { display: none !important; }
.login-box {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  width: 100%; max-width: 380px; padding: 32px 28px; box-shadow: 0 16px 48px rgba(0,0,0,.08);
}
.login-brand { text-align: center; margin-bottom: 26px; }
.login-brand .logo {
  width: 56px; height: 56px; border-radius: 14px; background: var(--brand);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 26px;
  margin: 0 auto 14px;
}
.login-brand h1 { font-size: 20px; margin-bottom: 4px; }
.login-brand p { margin: 0; font-size: 13px; color: var(--text-3); }
.login-form .field { margin-bottom: 16px; }
.login-form label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.login-form input {
  width: 100%; height: 46px; border: 1px solid var(--line-strong); border-radius: 10px;
  padding: 0 14px; font-size: 15px; outline: none; background: #fff; color: var(--text);
}
.login-form input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.login-tip { text-align: center; font-size: 12px; color: var(--text-3); margin: 14px 0 0; }

/* ---------- topbar ---------- */
.topbar {
  height: 60px; background: var(--card); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 8px; background: var(--brand);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 16px;
}
.brand h1 { font-size: 15px; }
.brand .sub { font-size: 12px; color: var(--text-3); }
.brand-text { display: none; }
.actions { display: flex; gap: 8px; }
.shop-bar { display: flex; align-items: center; gap: 6px; margin-left: auto; margin-right: 14px; }
.shop-bar label { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.shop-bar select { height: 34px; border-radius: 8px; border: 1px solid var(--line-strong); background: #fff; padding: 0 8px; font-size: 13px; min-width: 120px; max-width: 180px; }
.shop-bar .btn { padding: 0 10px; }
.mobile-menu-btn { display: none; }

/* ---------- buttons ---------- */
.btn {
  height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: #fff; color: var(--text); font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; transition: .15s;
}
.btn:hover { border-color: #b9bec6; background: #fafbfc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #cf2525; }
.btn.ghost { background: transparent; border-color: var(--line-strong); color: var(--text-2); }
.btn.ghost:hover { background: #f2f3f5; }
.btn.danger { color: var(--brand); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

main { padding: 18px 20px 40px; max-width: 1280px; margin: 0 auto; }

/* headline */
.headline {
  background: linear-gradient(135deg, #fff 0%, #fff4f4 100%);
  border: 1px solid #f3dada; border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 14px; font-size: 15px; color: var(--text-2);
}
.headline b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.headline .hl-profit { color: var(--brand); font-weight: 700; }
.headline .hl-up { color: var(--green); }

/* kpi */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 15px; }
.kpi .k-label { font-size: 12px; color: var(--text-3); margin-bottom: 5px; }
.kpi .k-value { font-size: 20px; font-weight: 600; letter-spacing: -.2px; font-variant-numeric: tabular-nums; }
.kpi .k-sub { font-size: 11px; color: var(--text-3); margin-top: 3px; }
.kpi.k-main { border-color: #f0c9c9; background: #fffafa; }
.kpi.k-main .k-value { color: var(--brand); }
.kpi .k-value.neg { color: var(--green); }
.kpi .k-value.pos { color: var(--brand); }

/* 资金流向 */
.flow-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.flow-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.flow-head span:first-child { font-size: 13px; color: var(--text-2); font-weight: 500; }
.flow-tip { font-size: 11px; color: var(--text-3); }
.flow-bar { display: flex; height: 26px; border-radius: 6px; overflow: hidden; background: #f0f1f3; }
.flow-seg { position: relative; transition: width .4s; }
.flow-seg + .flow-seg { box-shadow: inset 1px 0 0 rgba(255,255,255,.6); }
.flow-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 10px; }
.flow-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.flow-dot { width: 9px; height: 9px; border-radius: 3px; }
.flow-item b { color: var(--text); font-variant-numeric: tabular-nums; }

/* chart */
.chart-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 8px; margin-bottom: 14px; }
.chart-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.chart-head span { font-size: 13px; color: var(--text-2); font-weight: 500; }
.chart-head select { height: 28px; border: 1px solid var(--line-strong); border-radius: 6px; background: #fff; padding: 0 6px; font-size: 12px; }
.chart { height: 160px; }

/* panel */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.toolbar { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.date-range { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); }
.date-range input {
  height: 32px; border: 1px solid var(--line-strong); border-radius: 8px; padding: 0 8px;
  font-size: 12px; outline: none; background: #fff; color: var(--text); font-family: inherit;
}
.toolbar input[type=search] {
  height: 34px; width: 180px; border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 0 12px; font-size: 13px; outline: none; background: #fff;
}
.toolbar input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.spacer { flex: 1; }
.total { font-size: 12px; color: var(--text-3); }
.toolbar select { height: 34px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; padding: 0 8px; font-size: 13px; }

/* table */
.table-wrap { overflow: auto; max-height: 60vh; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
thead th {
  position: sticky; top: 0; z-index: 5; background: #fafbfc; text-align: left;
  padding: 10px 12px; border-bottom: 1px solid var(--line); color: var(--text-2);
  font-weight: 500; white-space: nowrap; cursor: pointer; user-select: none;
}
thead th:hover { background: #f2f3f5; }
thead th .arw { color: var(--text-3); font-size: 10px; margin-left: 2px; }
thead th.act .arw { color: var(--brand); }
thead th.no-sort { cursor: default; }
thead th.no-sort:hover { background: #fafbfc; }
td { padding: 9px 12px; border-bottom: 1px solid #f0f1f3; white-space: nowrap; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.col-date { font-variant-numeric: tabular-nums; color: var(--text-2); }
td.calc { color: var(--text-2); background: #fcfcfd; }
td.pos { color: var(--brand); }
td.neg { color: var(--green); }
td.col-id { color: var(--text-3); }
tbody tr:hover { background: #fafbfc; }
tbody tr.sel { background: var(--brand-soft); }
tbody tr.empty-row td { color: var(--text-3); }
.ops a { color: var(--blue); cursor: pointer; margin-right: 10px; font-size: 13px; }
.ops a.del { color: var(--brand); }
.empty { padding: 60px 0; text-align: center; color: var(--text-3); }
.empty b { display: block; color: var(--text-2); font-weight: 500; margin-bottom: 6px; }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 6px; padding: 10px 14px; }
.pager button {
  min-width: 30px; height: 30px; border: 1px solid var(--line-strong); background: #fff;
  border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--text-2);
}
.pager button:hover:not(:disabled) { border-color: #b9bec6; }
.pager button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.pager button:disabled { opacity: .4; cursor: not-allowed; }

.foot-note { font-size: 11px; color: var(--text-3); text-align: center; margin-top: 14px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(20,22,26,.4); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal[hidden] { display: none !important; }
.modal-box { background: #fff; border-radius: 12px; width: 560px; max-width: 100%; max-height: 86vh; display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0,0,0,.18); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 15px; }
.modal-head .x { border: 0; background: none; font-size: 22px; color: var(--text-3); cursor: pointer; line-height: 1; }
.modal-body { padding: 16px 18px; overflow: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.form-tip { font-size: 12px; color: var(--text-3); margin: 0 0 12px; }
.form { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.form .field { display: flex; flex-direction: column; gap: 5px; }
.form .field.wide { grid-column: 1 / -1; }
.form label { font-size: 12px; color: var(--text-2); }
.form input {
  height: 34px; border: 1px solid var(--line-strong); border-radius: 8px; padding: 0 10px;
  font-size: 13px; outline: none; font-family: inherit; background: #fff; color: var(--text);
}
.form input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

.calc-preview {
  margin-top: 14px; background: #fafbfc; border: 1px dashed var(--line-strong);
  border-radius: 8px; padding: 10px 14px; font-size: 13px; color: var(--text-2);
  display: flex; gap: 24px; flex-wrap: wrap;
}
.calc-preview b { font-variant-numeric: tabular-nums; }
.calc-preview .cp-loss b { color: var(--orange); }
.calc-preview .cp-net b { color: var(--blue); }
.calc-preview .cp-profit b { color: var(--brand); }

.drop {
  border: 1.5px dashed var(--line-strong); border-radius: 10px; padding: 30px; text-align: center;
  color: var(--text-2); cursor: pointer; background: #fafbfc;
}
.drop:hover { border-color: var(--brand); background: var(--brand-soft); }
.drop p { margin: 0; font-size: 13px; }
.tip { font-size: 12px; color: var(--text-3); margin: 10px 0 0; }

.modal-box .field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.modal-box .field label { font-size: 12px; color: var(--text-2); }
.modal-box .field input, .modal-box .field select { height: 34px; border: 1px solid var(--line-strong); border-radius: 8px; padding: 0 10px; font-size: 13px; outline: none; background: #fff; }
.modal-box .field input:focus, .modal-box .field select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

/* settings tabs */
.settings-tabs { display: flex; gap: 8px; margin-bottom: 16px; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.tab-btn {
  height: 32px; padding: 0 14px; border-radius: 6px; border: 0; background: transparent;
  color: var(--text-2); font-size: 13px; cursor: pointer;
}
.tab-btn.on { background: var(--brand-soft); color: var(--brand); font-weight: 500; }

.shop-list { display: flex; flex-direction: column; gap: 8px; }
.shop-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: #fafbfc;
}
.shop-name { font-weight: 500; color: var(--text); cursor: pointer; }
.shop-name:hover { color: var(--brand); }
.shop-count { font-size: 12px; color: var(--text-3); }

.user-form { display: grid; grid-template-columns: 1.2fr 1fr .8fr auto; gap: 10px; align-items: end; margin-bottom: 16px; }
.user-form .field { margin-bottom: 0; }
.user-form .btn { height: 34px; }
.user-list { display: flex; flex-direction: column; gap: 8px; }
.user-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: #fafbfc;
}
.user-name { font-weight: 500; margin-right: 8px; }
.user-role { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: var(--line); color: var(--text-2); }
.user-role.admin { background: var(--brand-soft); color: var(--brand); }
.user-actions { display: flex; gap: 6px; }
.user-actions .btn { padding: 0 10px; height: 28px; font-size: 12px; }

.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: #1f2329; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 13px; z-index: 99;
  box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
.toast.err { background: var(--brand); }

svg.spark { width: 100%; height: 100%; display: block; overflow: visible; }
.svg-label { font-size: 10px; fill: var(--text-3); }

/* mobile menu */
.mobile-menu { position: fixed; inset: 0; z-index: 80; }
.mobile-menu[hidden] { display: none !important; }
.mobile-menu-mask { position: absolute; inset: 0; background: rgba(0,0,0,.35); }
.mobile-menu-body {
  position: absolute; top: 0; right: 0; width: 220px; height: 100%;
  background: #fff; box-shadow: -6px 0 24px rgba(0,0,0,.12); padding: 16px;
}
.mobile-menu-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.mobile-menu-head span { font-weight: 600; }
.mobile-menu-head .x { border: 0; background: none; font-size: 22px; color: var(--text-3); cursor: pointer; }
.mobile-menu-body button {
  width: 100%; text-align: left; height: 44px; border: 0; background: #fff; border-radius: 8px;
  font-size: 14px; color: var(--text); cursor: pointer; padding: 0 12px; margin-bottom: 4px;
}
.mobile-menu-body button:hover { background: #f6f7f9; }

/* ---------- responsive ---------- */
@media (min-width: 760px) {
  .brand-text { display: block; }
}

@media (max-width: 900px) {
  .form { grid-template-columns: 1fr 1fr; }
  .user-form { grid-template-columns: 1fr 1fr; }
  .user-form .btn { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .topbar { height: auto; min-height: 56px; padding: 8px 12px; flex-wrap: wrap; gap: 8px; }
  .brand-text { display: none; }
  .actions { display: none; }
  .mobile-menu-btn { display: inline-flex; width: 40px; height: 36px; align-items: center; justify-content: center; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; font-size: 18px; cursor: pointer; }
  .shop-bar { margin-left: 0; margin-right: auto; }
  .shop-bar select { min-width: auto; max-width: 140px; }

  main { padding: 12px 12px 30px; }
  .headline { font-size: 14px; padding: 14px; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi { padding: 12px; }
  .kpi .k-value { font-size: 18px; }
  .kpi .k-sub { font-size: 10px; }

  .toolbar { padding: 10px 12px; }
  .toolbar input[type=search] { width: 100%; order: 3; }
  .date-range { width: 100%; order: 2; }
  .toolbar .spacer { display: none; }
  .toolbar select { order: 4; }
  #btnBatchDel { order: 5; }
  .total { order: 1; width: 100%; margin-bottom: 4px; }

  /* table card view */
  .table-wrap { max-height: none; }
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  tbody tr {
    margin-bottom: 10px; border: 1px solid var(--line); border-radius: 10px;
    background: #fff; padding: 10px; position: relative;
  }
  tbody td {
    display: flex; justify-content: space-between; align-items: center;
    padding: 7px 4px; border-bottom: 1px dashed #f0f1f3; white-space: normal;
  }
  tbody td:last-child { border-bottom: 0; }
  tbody td::before { content: attr(data-label); font-size: 12px; color: var(--text-3); }
  tbody td:first-child { position: absolute; top: 10px; left: 10px; width: auto; border: 0; padding: 0; }
  tbody td:first-child::before { display: none; }
  tbody td:nth-child(2) { padding-left: 36px; font-weight: 600; color: var(--text-3); border-bottom: 1px solid var(--line); margin-bottom: 6px; }
  tbody td:nth-child(2)::before { display: none; }
  tbody td.ops { justify-content: flex-start; gap: 16px; margin-top: 4px; }
  tbody td.ops::before { display: none; }
  tbody tr.empty-row td { color: var(--text-3); }
  tbody tr.sel { background: var(--brand-soft); }

  .pager { justify-content: center; padding: 10px; }

  .modal { padding: 0; align-items: flex-end; }
  .modal-box { width: 100%; max-height: 92vh; border-radius: 16px 16px 0 0; }
  .form { grid-template-columns: 1fr; }
  .modal-box[style*="640px"] { width: 100% !important; }

  .login-box { padding: 28px 22px; }
}

@media (max-width: 480px) {
  .kpis { grid-template-columns: 1fr; }
  .flow-legend { flex-direction: column; gap: 6px; }
  .user-form { grid-template-columns: 1fr; }
}
