* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif; color: #1f2329; background: #f5f6f8; }
a { color: #2b5fd9; text-decoration: none; cursor: pointer; }
button, input, select, textarea { font: inherit; }
.btn { border: 1px solid #d0d3d9; background: #fff; border-radius: 6px; padding: 6px 14px; cursor: pointer; color: #1f2329; }
.btn:hover { background: #f2f3f5; }
.btn.primary { background: #2b5fd9; border-color: #2b5fd9; color: #fff; }
.btn.primary:hover { background: #244fb8; }
.btn.danger { color: #d83931; border-color: #f1b5b1; }
.btn.small { padding: 2px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.topbar { background: #fff; border-bottom: 1px solid #e5e6eb; display: flex; align-items: center; padding: 0 20px; height: 54px; gap: 24px; position: sticky; top: 0; z-index: 5; }
.topbar .brand { font-weight: 600; font-size: 16px; white-space: nowrap; }
.topbar nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topbar nav a { padding: 6px 12px; border-radius: 6px; color: #4e5969; white-space: nowrap; }
.topbar nav a.on { background: #e8efff; color: #2b5fd9; font-weight: 600; }
.topbar .me { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.topbar .me img { width: 28px; height: 28px; border-radius: 50%; }
main { max-width: 1200px; margin: 20px auto; padding: 0 20px; }

.card { background: #fff; border-radius: 10px; padding: 18px 20px; margin-bottom: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.center { max-width: 440px; margin: 12vh auto; text-align: center; }
.center h1 { font-size: 22px; margin: 0 0 8px; }
.muted { color: #86909c; }
.err { color: #d83931; }
code { background: #f2f3f5; padding: 2px 6px; border-radius: 4px; word-break: break-all; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters label { display: flex; flex-direction: column; font-size: 12px; color: #86909c; gap: 2px; }
.filters .spacer { flex: 1; }
input[type=text], input[type=date], input[type=datetime-local], input[type=number], select, textarea {
  border: 1px solid #d0d3d9; border-radius: 6px; padding: 6px 10px; background: #fff; color: #1f2329; min-width: 0; }
input[type=text], input[type=date], input[type=datetime-local], input[type=number], select { height: 34px; }
textarea { width: 100%; min-height: 64px; resize: vertical; }

.summary { margin: 0 0 10px; color: #4e5969; }
.summary b { color: #1f2329; font-size: 16px; }
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid #eef0f3; vertical-align: top; }
th { color: #86909c; font-weight: 500; font-size: 13px; white-space: nowrap; background: #fafbfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.nowrap { white-space: nowrap; }
tr.row { cursor: pointer; }
tr.row:hover td { background: #f7f9ff; }
.tag { display: inline-block; padding: 0 8px; border-radius: 10px; font-size: 12px; line-height: 20px; background: #f2f3f5; color: #4e5969; margin: 0 4px 2px 0; white-space: nowrap; }
.tag.ok { background: #e3f5e8; color: #1a7f37; }
.tag.warn { background: #fff1d6; color: #a85b00; }
.tag.bad { background: #fde4e2; color: #c02a22; }
.tag.blue { background: #e8efff; color: #2b5fd9; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 12px; }
.empty { text-align: center; color: #86909c; padding: 40px 0; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; overflow-y: auto; z-index: 20; }
.modal[hidden] { display: none; }
.dialog { background: #fff; border-radius: 12px; width: 100%; max-width: 720px; padding: 20px 24px; }
.dialog h2 { margin: 0 0 14px; font-size: 17px; display: flex; justify-content: space-between; align-items: center; }
.dialog .x { cursor: pointer; color: #86909c; font-size: 22px; line-height: 1; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #4e5969; }
.form label.full { grid-column: 1 / -1; }
.form .req::after { content: " *"; color: #d83931; }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; margin-bottom: 14px; }
.kv dt { color: #86909c; }
.kv dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.thumbs { display: flex; flex-wrap: wrap; gap: 10px; margin: 6px 0 12px; }
.thumb { border: 1px solid #e5e6eb; border-radius: 8px; padding: 6px; width: 132px; font-size: 12px; text-align: center; }
.thumb img { width: 118px; height: 118px; object-fit: cover; border-radius: 4px; display: block; }
.thumb .pdf { width: 118px; height: 118px; display: flex; align-items: center; justify-content: center; background: #f2f3f5; border-radius: 4px; color: #4e5969; font-weight: 600; }
.thumb .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 4px; }
.section-title { font-weight: 600; margin: 14px 0 4px; display: flex; align-items: center; gap: 10px; }
.history { font-size: 13px; color: #4e5969; max-height: 220px; overflow-y: auto; border-top: 1px solid #eef0f3; padding-top: 8px; }
.history div { padding: 3px 0; }
.perms { display: grid; grid-template-columns: 1fr; gap: 6px; margin: 10px 0; }
.perms label { display: flex; gap: 8px; align-items: flex-start; }
.perms small { color: #86909c; display: block; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.toast { position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%); background: #1f2329; color: #fff; padding: 8px 18px; border-radius: 8px; z-index: 50; max-width: 90vw; }
.toast.err { background: #d83931; color: #fff; }
@media (max-width: 720px) {
  .form, .grid2 { grid-template-columns: 1fr; }
  .topbar { padding: 8px 10px 0; gap: 4px 10px; height: auto; flex-wrap: wrap; }
  .topbar .brand { flex: 1; }
  .topbar nav { order: 3; flex: 0 0 100%; padding-bottom: 6px; }
  .filters label { flex: 1 1 40%; }
  .filters .spacer { display: none; }
  .dialog { padding: 16px; }
  table.cards tr:first-child { display: none; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; }
  table.cards tr { border: 1px solid #eef0f3; border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; position: relative; }
  table.cards td { border: 0; padding: 2px 0; text-align: left; white-space: normal; }
  table.cards td:empty { display: none; }
  table.cards td[data-label]::before { content: attr(data-label) ":"; color: #86909c; margin-right: 6px; }
  table.cards td.main { font-weight: 600; padding-right: 110px; }
  table.cards td.main .muted { font-weight: 400; }
  table.cards td.main::before, table.cards td.amount::before { content: none; }
  table.cards td.amount { position: absolute; right: 12px; top: 8px; font-weight: 600; font-size: 15px; }
  main { padding: 0 10px; }
  .kv { grid-template-columns: 84px 1fr; }
}
