:root {
  --brand: #3d2bdb; --brand-soft: #efedff; --ink: #1d1d2b; --muted: #6b6b80; --line: #e4e4ef;
  --bg: #f7f6fb; --card: #fff; --ok: #138a4a; --warn: #c62828; --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; color: var(--ink); background: var(--bg); font-size: 15px; }
a { color: var(--brand); text-decoration: none; }
nav { display: flex; align-items: center; gap: 18px; padding: 10px 24px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
nav a { color: var(--ink); font-weight: 500; }
nav .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--brand); }
nav .brand img { height: 26px; }
nav form { margin: 0; }
.grow { flex: 1; }
main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 60px; }
h1 { font-size: 24px; margin: 0 0 16px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h3 { margin: 22px 0 10px; font-size: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.table-wrap { padding: 0; overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list .r, .r { text-align: right; }
tr.inactive { opacity: .55; }
.empty { text-align: center; color: var(--muted); padding: 30px !important; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--warn); }
.btn.small { padding: 5px 10px; font-size: 13px; }
button.link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 4px; }
button.link.danger:hover { color: var(--warn); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eee; color: #555; vertical-align: middle; }
.badge.draft { background: #fff4d6; color: #8a5a00; }
.badge.sent { background: var(--brand-soft); color: var(--brand); }
.badge.paid { background: #dcf5e6; color: var(--ok); }
.badge.overdue { background: #fde3e3; color: var(--warn); }
.badge.void { background: #eee; color: #888; text-decoration: line-through; }
.tag { font-size: 11px; background: var(--brand-soft); color: var(--brand); padding: 1px 6px; border-radius: 4px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat span { display: block; color: var(--muted); font-size: 13px; }
.stat b { font-size: 22px; }
.stat.warn b { color: var(--warn); } .stat.ok b { color: var(--ok); }
.filters { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.filters select { width: auto; min-width: 150px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: #444; margin-bottom: 12px; flex: 1; min-width: 180px; }
label.inline { flex-direction: row; align-items: center; gap: 8px; flex: none; min-width: 0; }
label.grow2 { flex: 2; }
input, select, textarea { font: inherit; font-weight: 400; padding: 8px 10px; border: 1px solid #d5d5e3; border-radius: 7px; background: #fff; color: var(--ink); width: 100%; }
label.inline input { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.hint { font-size: 12px; font-weight: 400; color: var(--muted); }
code { background: var(--brand-soft); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; }
.actions.wrap { flex-wrap: wrap; justify-content: flex-end; }
.actions form { margin: 0; }
.paid-form { display: flex; gap: 6px; }
.paid-form input { width: 150px; }
table.editor td { padding: 8px 6px; }
table.editor input.num { width: 110px; text-align: right; }
table.editor input.sub { margin-top: 5px; font-size: 13px; color: var(--muted); }
table.editor td:first-child { min-width: 260px; }
.items-editor { margin-bottom: 14px; border: 1px solid var(--line); border-radius: 8px; overflow-x: auto; }
.items-editor .hint { padding: 0 12px 10px; margin: 0; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.flash.ok { background: #dcf5e6; color: #0d5e33; }
.flash.error { background: #fde3e3; color: #8e1c1c; }
.view-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.preview { background: #e9e8f1; border-radius: var(--radius); padding: 20px; overflow-x: auto; }
.preview iframe { display: block; margin: 0 auto; width: 210mm; height: 297mm; border: 0; background: #fff; box-shadow: 0 4px 24px rgba(0,0,0,.12); }
.login { max-width: 360px; margin: 80px auto; text-align: center; }
.login img { height: 54px; margin-bottom: 8px; }
.login h1 { justify-content: center; font-size: 20px; }
.login label { text-align: left; }
.login .btn { width: 100%; justify-content: center; }
@media (max-width: 640px) {
  nav { padding: 10px 16px; gap: 12px; }
  .preview { padding: 8px; }
  .preview iframe { width: 100%; height: 140vw; }
  .view-head .actions { justify-content: flex-start; }
}
