:root {
  --red: #C62828;
  --red-dark: #B71C1C;
  --red-light: #D32F2F;
  --accent: #D32F2F;
  --bg: #f5f5f7;
  --card: #ffffff;
  --border: #e5e5e8;
  --muted: #888;
  --text: #222;
  --green: #2d8c6e;
  --void: #c0392b;
  --cor: #e67e22;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--text); font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif; }

/* 顶部：直角贴顶 */
.topbar {
  background: linear-gradient(135deg, #C62828, #D32F2F);
  color: #fff;
  padding: 14px 16px 12px;
  border-radius: 0;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.topbar h1 { font-size: 20px; font-weight: 700; letter-spacing: 0.5px; margin-bottom: 12px; }
.topbar h1, .filters { max-width: 860px; margin-left: auto; margin-right: auto; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: center; }
.filters select, .filters input[type="month"] {
  padding: 7px 10px; border: none; border-radius: 5px; font-size: 13px; background: rgba(255,255,255,0.95); color: #333;
  outline: none; max-width: 200px;
}
.filters .sep { color: rgba(255,255,255,0.9); }
.filters button {
  padding: 7px 14px; border: 1px solid rgba(255,255,255,0.5); background: transparent; color: #fff;
  border-radius: 5px; cursor: pointer; font-size: 13px;
}
.filters button:hover { background: rgba(255,255,255,0.15); }

/* 主体 */
main { max-width: 860px; margin: 0 auto; padding: 16px; }
.stats { color: var(--muted); font-size: 13px; margin-bottom: 12px; }

.results { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 14px 16px; cursor: pointer; transition: box-shadow .15s, border-color .15s;
}
.card:hover { border-color: var(--accent); box-shadow: 0 2px 10px rgba(0,0,0,0.06); }
.card-main { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.card-kind { font-size: 15px; font-weight: 600; color: #333; }
.card-company { font-size: 13px; color: #666; flex-shrink: 0; }
.card-sub { display: flex; align-items: center; gap: 12px; margin-top: 8px; flex-wrap: wrap; }
.period { font-size: 13px; color: #555; background: #f0f0f2; padding: 2px 8px; border-radius: 4px; }
.amt { font-size: 15px; font-weight: 700; color: var(--red-dark); }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 4px; font-weight: 600; }
.badge-ver { background: #eef2ff; color: #3b5bdb; }
.badge-cor { background: #fff4e6; color: var(--cor); }
.badge-void { background: #fdecea; color: var(--void); }

.empty { text-align: center; color: #aaa; padding: 60px 0; font-size: 15px; }

/* 明细弹窗 */
.modal { position: fixed; inset: 0; z-index: 999; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.45); }
.modal-body {
  position: absolute; inset: 0 0 0 auto; width: min(1120px, 96vw);
  background: #fff; display: flex; flex-direction: column; box-shadow: -4px 0 24px rgba(0,0,0,0.2);
}
.resize-handle { position: absolute; left: 0; top: 0; bottom: 0; width: 7px; cursor: ew-resize; z-index: 10; }
.resize-handle:hover { background: rgba(211, 47, 47, 0.25); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 16px 18px 0; }
.modal-title { flex: 1; }
.m-kind { font-size: 16px; font-weight: 700; color: #222; line-height: 1.4; }
.m-meta { font-size: 13px; color: #777; margin-top: 4px; }
.m-close { border: none; background: #eee; color: #555; width: 32px; height: 32px; border-radius: 6px; cursor: pointer; font-size: 15px; flex-shrink: 0; }
.m-close:hover { background: #ddd; }

.m-toolbar { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.btn { display: inline-block; padding: 8px 16px; background: var(--accent); color: #fff; border-radius: 6px; text-decoration: none; font-size: 14px; font-weight: 600; }
.btn:hover { background: var(--red-dark); }
.btn-ghost { background: #fff; color: var(--accent); border: 1px solid var(--accent); }
.btn-ghost:hover { background: #fdf0f0; }
.m-ver { font-size: 12px; color: #999; }
.merge-toggle { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: 13px; color: #555; cursor: pointer; user-select: none; white-space: nowrap; }
.merge-toggle input { cursor: pointer; vertical-align: middle; }

.m-body { flex: 1; overflow-y: auto; padding: 16px 18px; }
.loading { color: #999; text-align: center; padding: 40px 0; }

.verbar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.vertab { border: 1px solid var(--border); background: #fff; color: #555; border-radius: 6px; padding: 6px 12px; cursor: pointer; font-size: 12px; line-height: 1.3; }
.vertab small { color: #999; }
.vertab.active { border-color: var(--accent); color: var(--accent); background: #fdf3f3; font-weight: 600; }

/* 附表页签 */
.sheettabs { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--border); margin-bottom: 12px; position: sticky; top: 0; background: #fff; z-index: 5; }
.sheettab { padding: 6px 12px; font-size: 13px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: #555; cursor: pointer; white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.sheettab:hover { border-color: var(--accent); color: var(--accent); }
.sheettab.active { border-color: var(--accent); color: var(--accent); background: #fdf3f3; font-weight: 600; }

.sheet-title { font-size: 14px; font-weight: 700; color: #333; margin-bottom: 8px; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12px; table-layout: fixed; }
table td { border: 1px solid #e8e8ea; padding: 6px 8px; color: #444; word-break: break-word; vertical-align: top; }
table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table tr:first-child td { font-weight: 600; background: #f7f7f9; }

/* 移动端 */
@media (max-width: 600px) {
  .topbar { padding: 14px 12px 12px; }
  .topbar h1 { font-size: 17px; }
  .filters select, .filters input[type="month"] { max-width: 46%; flex: 1; }
  main { padding: 12px; }
  .card-main { flex-direction: column; align-items: flex-start; gap: 2px; }
  .card-company { font-size: 12px; }
  .modal-body { width: 100%; }
  .m-body { padding: 12px; }
}