/* 银算盘 v2 · 设计变量与基础组件（刀 1.5）
 *
 * 两条规矩：
 *   ① 颜色只从变量取，页面里禁止写死色值（换肤/暗色只改这一层）；
 *   ② 金额只用 .money 一族渲染（等宽数字 + 右对齐），别让数字在列里跳舞。
 * 主题引擎四层模型（鼎工范式）在银算盘一期先落 L0 默认层 + L3 暗色层，
 * 用户自定义色板（L1/L2）留到设置页那一刀，不提前造空壳。
 */

:root {
  color-scheme: dark;

  --bg: #0e1218;
  --bg-soft: #131a23;
  --panel: #161f2a;
  --panel-2: #1b2532;
  --line: #253140;
  --line-soft: #1e2836;

  --text: #e7edf5;
  --text-dim: #93a1b3;
  --text-mute: #6b7a8d;

  /* 银：主色。银算盘不抢眼，靠层次与留白说话 */
  --silver: #c3cedd;
  --silver-dim: #8fa0b5;
  --accent: #7fa7c9;

  --profit: #4fbd8d;
  --cost: #e08a6a;
  --total: #d7b26a;
  --warn: #e0b357;
  --danger: #e06b6b;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 8px 24px rgba(0, 0, 0, .22);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

/* L3 暗色层：浅色主题下用整层覆盖（!important 与鼎工同款，避免局部残留） */
html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6f9;
  --bg-soft: #eef2f7;
  --panel: #ffffff;
  --panel-2: #f7f9fc;
  --line: #dde4ee;
  --line-soft: #e8eef6;
  --text: #1a2430;
  --text-dim: #5a6a7d;
  --text-mute: #8593a5;
  --silver: #4a5b70;
  --silver-dim: #6b7c91;
  --accent: #3f6f96;
  --profit: #1e8e63;
  --cost: #c25f3d;
  --total: #a67c1f;
  --warn: #a8761a;
  --danger: #c0392b;
  --shadow: 0 1px 2px rgba(15, 30, 50, .06), 0 8px 24px rgba(15, 30, 50, .07);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── 登录页 ───────────────────────────────────────────── */
.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(127, 167, 201, .13), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 30px 28px 26px;
}

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  border: 1px solid var(--silver-dim);
  display: grid; place-items: center;
  font: 700 15px/1 var(--font);
  color: var(--silver);
  background: linear-gradient(160deg, rgba(195, 206, 221, .16), rgba(195, 206, 221, .02));
}
.brand-name { font-size: 17px; font-weight: 650; letter-spacing: .3px; }
.brand-sub { margin: 0 0 22px; color: var(--text-mute); font-size: 12.5px; letter-spacing: .2px; }

/* ── 表单 ─────────────────────────────────────────────── */
.field { margin-bottom: 14px; }
.field > label {
  display: block; margin-bottom: 6px;
  color: var(--text-dim); font-size: 12.5px; letter-spacing: .2px;
}

input[type="text"], input[type="password"], input[type="date"], select {
  width: 100%;
  padding: 9px 11px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(127, 167, 201, .16);
}
input::placeholder { color: var(--text-mute); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { border-color: var(--silver-dim); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary {
  width: 100%;
  margin-top: 6px;
  padding: 10px 16px;
  background: linear-gradient(180deg, var(--silver), var(--silver-dim));
  border-color: transparent;
  color: #10161e;
  font-weight: 650;
  letter-spacing: .3px;
}
.btn-primary:hover { filter: brightness(1.04); }
.btn-ghost { background: transparent; }

.form-err {
  display: none;
  margin: 0 0 14px;
  padding: 9px 11px;
  border: 1px solid rgba(224, 107, 107, .4);
  border-radius: var(--radius-sm);
  background: rgba(224, 107, 107, .1);
  color: var(--danger);
  font-size: 13px;
}
.form-err.show { display: block; }

/* ── 应用外壳 ─────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { margin: 0; }
.topbar .spacer { flex: 1; }
.who { color: var(--text-dim); font-size: 13px; }
.who b { color: var(--text); font-weight: 600; }
.tenant-chip {
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--silver);
  font-size: 12px;
  font-family: var(--mono);
}

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

.section-head {
  display: flex; align-items: baseline; gap: 10px;
  margin: 26px 0 12px;
}
.section-head:first-child { margin-top: 4px; }
.section-head h2 {
  margin: 0; font-size: 15px; font-weight: 600; letter-spacing: .3px;
}
.section-head .sub { color: var(--text-mute); font-size: 12.5px; }
.section-head .spacer { flex: 1; }

/* ── 汇总卡 ───────────────────────────────────────────── */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}
.card {
  position: relative;
  padding: 14px 16px 15px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--silver-dim);
  opacity: .45;
}
.card.tone-profit::before { background: var(--profit); }
.card.tone-cost::before { background: var(--cost); }
.card.tone-total::before { background: var(--total); }
.card .k {
  display: flex; align-items: center; gap: 6px;
  color: var(--text-dim); font-size: 12.5px;
}
.card .v {
  margin-top: 6px;
  font: 650 22px/1.25 var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.4px;
}
.card .f { margin-top: 4px; color: var(--text-mute); font-size: 11.5px; }
.card.tone-profit .v { color: var(--profit); }
.card.tone-cost .v { color: var(--cost); }
.card.tone-total .v { color: var(--total); }
.card .neg { color: var(--danger) !important; }

/* 两栏区：左四右三 */
.split {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 12px;
}
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel > h3 {
  margin: 0;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13.5px; font-weight: 600;
  color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.panel > h3 .spacer { flex: 1; }
.panel > h3 .hint { color: var(--text-mute); font-size: 12px; font-weight: 400; }
.panel-body { padding: 12px 16px 14px; }

/* ── 待办 / 动态 ──────────────────────────────────────── */
.todo { display: flex; flex-direction: column; }
.todo-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0;
  border-bottom: 1px dashed var(--line-soft);
}
.todo-row:last-child { border-bottom: 0; }
.todo-row .label { color: var(--text-dim); }
.todo-row .spacer { flex: 1; }
.todo-row .n {
  min-width: 30px; text-align: right;
  font: 650 15px/1 var(--mono);
  font-variant-numeric: tabular-nums;
}
.todo-row .n.zero { color: var(--text-mute); font-weight: 400; }
.todo-row.warn .n { color: var(--warn); }
.todo-row a { font-size: 12.5px; }

.feed { display: flex; flex-direction: column; gap: 2px; }
.feed-row {
  display: flex; align-items: baseline; gap: 8px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--line-soft);
  font-size: 12.8px;
}
.feed-row:last-child { border-bottom: 0; }
.feed-row .t { color: var(--text-mute); font-family: var(--mono); font-size: 11.5px; white-space: nowrap; }
.feed-row .a { color: var(--text-dim); }
.feed-row .r { color: var(--text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-row .bad { color: var(--danger); font-size: 11.5px; }

/* ── 表格 ─────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.grid th, table.grid td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  white-space: nowrap;
}
table.grid th {
  position: sticky; top: 0;
  background: var(--panel-2);
  color: var(--text-dim);
  font-weight: 500;
  font-size: 12.5px;
  border-bottom: 1px solid var(--line);
}
table.grid tbody tr:hover { background: var(--panel-2); }
table.grid td.num, table.grid th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
table.grid td.money { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-mute);
  font-size: 13px;
}

.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--text-dim);
}
.badge.confirmed { color: var(--profit); border-color: color-mix(in srgb, var(--profit) 45%, transparent); }
.badge.draft { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.badge.voided { color: var(--text-mute); text-decoration: line-through; }
/* 报表自校验徽标：后端 identity.ok 才亮（不平的报表根本到不了前端） */
.badge.ok { color: var(--profit); border-color: color-mix(in srgb, var(--profit) 45%, transparent); }

/* 合计行：数字由后端给，不是页面加的 —— 所以敢用最重的一行压住 */
table.grid tbody tr.rpt-total td {
  font-weight: 700;
  color: var(--text);
  border-top: 1px solid var(--line);
  background: var(--panel-2);
}
table.grid tbody tr.rpt-total td:first-child { color: var(--total); letter-spacing: .02em; }

/* ── 筛选条 ───────────────────────────────────────────── */
.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft);
}
.filters .field { margin: 0; }
.filters .field > label { font-size: 11.5px; }
.filters input, .filters select { padding: 6px 9px; font-size: 13px; }
.filters input[type="date"] { width: 148px; }
.filters input[type="text"] { width: 190px; }
.filters select { width: 118px; }
.filters .spacer { flex: 1; }

/* ── 分页 ─────────────────────────────────────────────── */
.pager {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px;
  border-top: 1px solid var(--line-soft);
  color: var(--text-dim);
  font-size: 12.5px;
}
.pager .spacer { flex: 1; }
.totals { display: flex; flex-wrap: wrap; gap: 16px; color: var(--text-dim); font-size: 12.5px; }
.totals b { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }

.skeleton {
  height: 14px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--panel-2), var(--line-soft), var(--panel-2));
  background-size: 200% 100%;
  animation: sk 1.2s linear infinite;
}
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  padding: 10px 16px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 13px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, bottom .2s;
}
.toast.show { opacity: 1; bottom: 30px; }


/* ── 弹窗与表单（刀 1.7）──────────────────────────────────
 * [hidden] 兜底排在前面：组件自带 display 会盖掉 hidden 属性。
 */
[hidden] { display: none !important; }

.btn-mini {
  padding: 3px 9px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  margin-right: 4px;
  line-height: 1.5;
}
.btn-mini:last-child { margin-right: 0; }
.btn-mini.primary { color: var(--profit); border-color: color-mix(in srgb, var(--profit) 42%, transparent); }
.btn-mini.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 38%, transparent); }
table.grid td.ops { white-space: nowrap; }

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover { filter: brightness(1.06); }

.modal {
  position: fixed; inset: 0;
  z-index: 60;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 5vh 16px 16px;
  background: rgba(4, 8, 14, .62);
  backdrop-filter: blur(2px);
  overflow: auto;
}
.modal-card {
  width: 100%;
  max-width: 720px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: pop .14s ease-out;
}
.modal-card.wide { max-width: 900px; }
@keyframes pop { from { transform: translateY(-6px); opacity: .6; } to { transform: none; opacity: 1; } }

.modal-head {
  display: flex; align-items: baseline; gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 650; }
.modal-head .sub { color: var(--text-mute); font-size: 12.5px; }
.modal-head .spacer { flex: 1; }
.modal-body { padding: 16px 18px; }
.modal-foot {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px;
  border-top: 1px solid var(--line-soft);
  background: var(--panel-2);
  border-radius: 0 0 var(--radius) var(--radius);
}
.modal-foot .spacer { flex: 1; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0 14px;
}
.form-grid .field { margin-bottom: 12px; }
.form-grid .field > label { display: block; margin-bottom: 5px; color: var(--text-dim); font-size: 12px; }
.form-grid .field > label .req { color: var(--danger); margin-left: 2px; }
.form-grid input, .form-grid select {
  width: 100%;
  padding: 7px 10px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}
.form-grid input:focus, .form-grid select:focus { outline: none; border-color: var(--accent); }
.form-grid input:disabled, .form-grid select:disabled { opacity: .5; }
.form-grid.ext {
  margin-top: 4px;
  padding: 10px 12px 0;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}

.check {
  display: flex; align-items: center; gap: 8px;
  margin: 4px 0 10px;
  color: var(--text-dim);
  font-size: 12.5px;
  cursor: pointer;
}
.check input { width: auto; }

.preview {
  margin-top: 6px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  color: var(--text-dim);
  font-size: 12.5px;
}
.preview b { color: var(--total); font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 14px; }
.preview.bad b { color: var(--danger); }
.preview .mute { color: var(--text-mute); }

.form-err {
  color: var(--danger);
  font-size: 12.5px;
  max-width: 62%;
}
.form-err:empty { display: none; }

.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 0 18px;
}
.kv {
  display: flex; align-items: baseline; gap: 10px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--line-soft);
}
.kv .k { color: var(--text-mute); font-size: 12.5px; min-width: 62px; }
.kv .v { color: var(--text); flex: 1; }
.kv.hl .v { color: var(--total); font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 600; }
.kv.cost .v { color: var(--cost); font-family: var(--mono); font-variant-numeric: tabular-nums; }

.sub-h {
  margin: 18px 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  display: flex; align-items: baseline; gap: 10px;
}
.sub-h .mute, .mute { color: var(--text-mute); font-weight: 400; font-size: 12px; }
.note {
  margin-top: 12px;
  padding: 10px 12px;
  border-left: 3px solid var(--line);
  color: var(--text-mute);
  font-size: 12.5px;
  background: var(--panel-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.warn-line {
  margin: 0 0 12px;
  padding: 9px 12px;
  border-left: 3px solid var(--warn);
  background: color-mix(in srgb, var(--warn) 10%, transparent);
  color: var(--text-dim);
  font-size: 12.5px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.toast.bad {
  border-color: color-mix(in srgb, var(--danger) 55%, transparent);
  color: var(--danger);
}

/* ── 应收 / 应付（刀 1.8）─────────────────────────────────────────
   一格只放一个数：四桶 + 未结清 + 池，全部等宽右对齐。
   桶小计条与表格列同序，人一眼能横着对；不顺序就是给人添麻烦。 */
.bucket-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  align-items: baseline;
  margin: 4px 0 12px;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  color: var(--text-dim);
}
.bucket-strip b {
  color: var(--text);
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  margin-left: 4px;
}
.bucket-strip .bad, .bucket-strip .bad b { color: var(--danger); }

table.grid td.money.hl { color: var(--total); font-weight: 600; }
table.grid td.money.bad { color: var(--danger); }

/* 明细行：挂在户头行下面，不弹窗——催款时要能一边看总数一边看单据 */
table.grid tr.docs-row > td {
  background: var(--bg);
  padding: 10px 12px 12px;
}
table.grid.mini { width: 100%; border: 1px solid var(--line); }
table.grid.mini th, table.grid.mini td { padding: 6px 9px; font-size: 12px; }
table.grid.mini th { background: transparent; }

@media (max-width: 640px) {
  .modal { padding: 0; }
  .modal-card { max-width: none; min-height: 100%; border-radius: 0; border: 0; }
  .modal-body { padding: 14px; }
  .form-err { max-width: 100%; }
}

/* ── 页签（刀 1.9：收付款两个方向在同一块面板里切）──────────────────── */
.tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
}
.tabs .tab {
  padding: 6px 16px;
  font-size: 13px;
  font-family: inherit;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.tabs .tab:hover { color: var(--text); border-color: var(--accent); }
.tabs .tab.on {
  color: var(--text);
  border-color: var(--accent);
  background: var(--line-soft);
  font-weight: 600;
}
.tabs .hint { font-size: 12px; color: var(--muted); }
