:root {
  --bg: #f5f7fb;
  --card: #fff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 8px;
  --sidebar: 210px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.container { max-width: 1280px; margin: 0 auto; padding: 20px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 16px; }
.pre { white-space: pre-wrap; word-break: break-word; }
[hidden] { display: none !important; }

/* ---------------- layout ---------------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); flex: 0 0 var(--sidebar); background: #111827; color: #d1d5db;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 40;
}
.sidebar .brand { color: #fff; font-weight: 600; font-size: 16px; padding: 16px 18px; display: block; }
.sidebar .brand:hover { text-decoration: none; }
.sidebar nav { display: flex; flex-direction: column; padding: 4px 8px; gap: 2px; flex: 1; }
.sidebar nav a {
  color: #d1d5db; padding: 8px 12px; border-radius: 6px; display: flex; align-items: center; gap: 8px;
}
.sidebar nav a:hover { background: #1f2937; color: #fff; text-decoration: none; }
.sidebar nav a.active { background: #374151; color: #fff; }
.sidebar nav .sep { height: 1px; background: #374151; margin: 8px 4px; }
.nav-badge {
  margin-left: auto; background: var(--danger); color: #fff; border-radius: 999px; font-size: 11px;
  line-height: 18px; min-width: 18px; padding: 0 6px; text-align: center;
}
.sidebar .me { border-top: 1px solid #374151; padding: 12px 16px; font-size: 13px; }
.sidebar .me .name { color: #fff; font-weight: 500; }
.sidebar .me .roles { font-size: 12px; color: #9ca3af; }
.sidebar .me .links { display: flex; gap: 12px; margin-top: 6px; }
.sidebar .me a, .sidebar .me button { color: #93c5fd; background: none; border: none; padding: 0; font: inherit; cursor: pointer; }
.main-col { flex: 1; min-width: 0; }
.topbar {
  display: none; align-items: center; gap: 12px; background: #111827; color: #fff; padding: 8px 12px;
  position: sticky; top: 0; z-index: 30;
}
.topbar .brand { font-weight: 600; flex: 1; }
.topbar .top-msg { color: #d1d5db; display: inline-flex; gap: 4px; align-items: center; }
.nav-toggle {
  background: none; border: 1px solid #4b5563; color: #fff; border-radius: 6px; font-size: 20px; line-height: 1;
  width: 40px; height: 36px; cursor: pointer;
}
.sidebar-mask { display: none; }
body.no-chrome .sidebar, body.no-chrome .topbar { display: none !important; }

.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin-right: auto; }

/* ---------------- cards / buttons / forms ---------------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border);
  background: #fff; color: var(--text); padding: 6px 14px; border-radius: 6px; cursor: pointer; font: inherit; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-dark); color: #fff; }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover:not(:disabled) { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.success:hover:not(:disabled) { background: #15803d; color: #fff; }
.btn.sm { padding: 2px 8px; font-size: 12px; }
.btn.link { border: none; background: none; color: var(--primary); padding: 0; }

input[type=text], input[type=password], input[type=date], input[type=month], input[type=search], input[type=number], select, textarea {
  font: inherit; padding: 6px 10px; border: 1px solid #d1d5db; border-radius: 6px; background: #fff; color: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
input:read-only { background: #f9fafb; }
textarea { min-height: 90px; resize: vertical; }
.field { margin-bottom: 14px; }
.field > label { display: block; font-weight: 500; margin-bottom: 4px; }
.field .req::after, label.req::after { content: " *"; color: var(--danger); }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }
.field .err, .err-text { color: var(--danger); font-size: 12px; margin-top: 4px; }
.field.has-err input, .field.has-err select, .field.has-err textarea { border-color: var(--danger); }
.field .warn-text { color: var(--warning); font-size: 12px; margin-top: 4px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 16px; }
.inline-opts { display: flex; gap: 16px; flex-wrap: wrap; }
.inline-opts label { display: inline-flex; align-items: center; gap: 4px; font-weight: normal; cursor: pointer; }
.input-prefix { display: flex; align-items: center; }
.input-prefix span { padding: 6px 10px; border: 1px solid #d1d5db; border-right: none; border-radius: 6px 0 0 6px; background: #f9fafb; color: var(--muted); }
.input-prefix input { border-radius: 0 6px 6px 0; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters > *, .filters input, .filters select { width: auto; }
.filters input[type=search] { min-width: 200px; flex: 1 1 220px; }
.filters select { max-width: 200px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--border); background: #fff; border-radius: 999px; padding: 3px 12px; cursor: pointer; font: inherit; color: var(--text);
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip .n { opacity: .8; margin-left: 4px; font-size: 12px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button {
  border: none; background: none; padding: 8px 14px; cursor: pointer; font: inherit; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }

.combo { position: relative; }
.combo-btn {
  font: inherit; padding: 6px 10px; border: 1px solid #d1d5db; border-radius: 6px; background: #fff; color: inherit; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 130px; white-space: nowrap;
}
.combo.open .combo-btn { outline: 2px solid #bfdbfe; border-color: var(--primary); }
.combo-panel {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; min-width: 100%; background: #fff; border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 6px 16px rgba(0,0,0,.12); padding: 4px 0; z-index: 30; white-space: nowrap;
}
.combo.open .combo-panel { display: block; }
.combo-panel label { display: flex; align-items: center; gap: 8px; padding: 6px 14px; cursor: pointer; }
.combo-panel label:hover { background: var(--bg); }

/* ---------------- tables ---------------- */
table.table { width: 100%; border-collapse: collapse; background: #fff; }
.table th, .table td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--muted); font-weight: 500; font-size: 12px; background: #f9fafb; white-space: nowrap; }
.table .right { text-align: right; }
.table td[data-label="申请人"], .table td[data-label="审批"] { white-space: nowrap; }
.table tr.clickable { cursor: pointer; }
.table tr:hover td { background: #fafafa; }
.table tfoot td { font-weight: 600; background: #f9fafb; }
.table td.check, .table th.check { width: 36px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

/* ---------------- badges ---------------- */
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; line-height: 20px; background: #f3f4f6; color: #374151; white-space: nowrap;
}
.badge.st-draft { background: #f3f4f6; color: #4b5563; }
.badge.st-pending { background: #fef3c7; color: #92400e; }
.badge.st-approved { background: #dbeafe; color: #1e40af; }
.badge.st-rejected { background: #fee2e2; color: #991b1b; }
.badge.st-paid { background: #dcfce7; color: #166534; }
.badge.st-voided { background: #e5e7eb; color: #6b7280; text-decoration: line-through; }
.badge.warn { background: #ffedd5; color: #9a3412; }
.badge.danger { background: var(--danger); color: #fff; }
.badge.ok { background: #ccfbf1; color: #115e59; }
.badge.info { background: #e0e7ff; color: #3730a3; }
.badge.muted { background: #f3f4f6; color: var(--muted); }

.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; border: 1px solid; }
.alert.error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert.warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert.info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.alert.success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }

.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast { background: #111827; color: #fff; padding: 10px 16px; border-radius: 6px; max-width: 460px; box-shadow: 0 4px 12px rgba(0,0,0,.15); white-space: pre-wrap; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ---------------- modal ---------------- */
dialog.modal { border: none; border-radius: 10px; padding: 0; width: min(680px, 94vw); max-height: 90vh; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
dialog.modal.wide { width: min(1100px, 96vw); }
dialog.modal::backdrop { background: rgba(17,24,39,.55); }
.modal-head { display: flex; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--border); gap: 8px; }
.modal-head h2 { margin: 0; flex: 1; }
.modal-body { padding: 16px 20px; overflow-y: auto; max-height: calc(90vh - 120px); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }

/* ---------------- viewer ---------------- */
.viewer { text-align: center; background: #374151; border-radius: 6px; padding: 12px; min-height: 300px; }
.viewer img { max-width: 100%; height: auto; background: #fff; cursor: zoom-in; }
.viewer.zoom img { max-width: none; cursor: zoom-out; }
.viewer.zoom { overflow: auto; text-align: left; }
.viewer canvas, .viewer .pdf-page { display: block; margin: 0 auto 12px; max-width: 100%; height: auto; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.viewer .loading { color: #e5e7eb; padding: 40px; }

/* ---------------- attachments ---------------- */
.att-list { display: flex; flex-direction: column; gap: 8px; }
.att-item {
  display: flex; gap: 12px; align-items: flex-start; border: 1px solid var(--border); border-radius: 6px; padding: 8px; background: #fff;
}
.att-item.failed { border-color: #fecaca; background: #fef2f2; }
.att-item.has-err { border-color: var(--danger); }
.att-thumb {
  width: 72px; height: 72px; flex: 0 0 72px; border-radius: 4px; background: #f3f4f6; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; overflow: hidden; cursor: pointer; color: var(--muted); font-size: 12px; font-weight: 600;
}
.att-thumb img { width: 100%; height: 100%; object-fit: cover; }
.att-thumb.pdf { background: #fee2e2; color: #b91c1c; }
.att-main { flex: 1; min-width: 0; }
.att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-meta { font-size: 12px; color: var(--muted); }
.att-inv { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; margin-top: 6px; }
.att-inv label { font-size: 12px; color: var(--muted); display: block; }
.att-inv input { padding: 4px 8px; }
.att-actions { display: flex; flex-direction: column; gap: 4px; }
.bar { height: 4px; background: #e5e7eb; border-radius: 2px; overflow: hidden; margin: 4px 0; }
.bar span { display: block; height: 100%; background: var(--primary); }
.recog { font-size: 12px; }
.recog.ok { color: var(--success); }
.recog.none { color: var(--warning); }
.drop-hint { border: 1px dashed #cbd5e1; border-radius: 6px; padding: 10px; text-align: center; color: var(--muted); font-size: 12px; }

.gallery { display: flex; flex-wrap: wrap; gap: 12px; }
.g-item { width: 150px; font-size: 12px; }
.g-item .att-thumb { width: 150px; height: 110px; }
.g-item .cap { margin-top: 4px; word-break: break-all; }

/* ---------------- detail ---------------- */
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 24px; }
.info-grid .k { color: var(--muted); font-size: 12px; }
.info-grid .v { word-break: break-word; }
.amount-big { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.actions-bar { display: flex; gap: 8px; flex-wrap: wrap; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 16px; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 14px 12px; }
.timeline li::before { content: ""; position: absolute; left: -23px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); border: 2px solid #fff; }
.timeline li.bad::before { background: var(--danger); }
.timeline li.good::before { background: var(--success); }
.timeline li.grey::before { background: #9ca3af; }
.timeline .comment { background: #f9fafb; border-radius: 6px; padding: 4px 10px; margin-top: 4px; white-space: pre-wrap; }
.approve-box { border: 2px solid #bfdbfe; background: #f8fbff; }
.lock-note { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------------- payments ---------------- */
.month-group { margin-bottom: 18px; }
.month-group .mg-head { display: flex; align-items: center; gap: 12px; padding: 8px 4px; flex-wrap: wrap; }
.month-group .mg-head h2 { margin: 0; }
.sticky-foot {
  position: sticky; bottom: 0; background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; box-shadow: 0 -4px 12px rgba(0,0,0,.06); z-index: 5;
}

.stat-bar { height: 8px; background: #dbeafe; border-radius: 4px; overflow: hidden; min-width: 80px; }
.stat-bar span { display: block; height: 100%; background: var(--primary); }

.login-wrap { max-width: 380px; margin: 10vh auto; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
.msg-item { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); align-items: flex-start; }
.msg-item.unread { background: #f8fbff; }
.msg-item.unread .dot { background: var(--primary); }
.msg-item .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 8px; flex: 0 0 8px; background: transparent; }
.msg-item .body { flex: 1; min-width: 0; }

/* ---------------- print ---------------- */
.print-toolbar { margin-bottom: 16px; }
.print-claim { background: #fff; padding: 24px; margin-bottom: 24px; border: 1px solid var(--border); }
.print-claim h2 { text-align: center; font-size: 20px; margin-bottom: 4px; }
.print-claim .sub { text-align: center; color: var(--muted); margin-bottom: 12px; }
.print-head { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.print-head th, .print-head td { border: 1px solid #9ca3af; padding: 6px 10px; text-align: left; vertical-align: top; }
.print-head th { width: 15%; background: #f3f4f6; font-weight: 500; white-space: nowrap; }
.print-att { margin: 0 0 16px; break-inside: avoid; page-break-inside: avoid; text-align: center; }
.print-att .cap { font-size: 12px; color: #374151; text-align: left; margin-bottom: 4px; }
.print-att img { max-width: 100%; max-height: 240mm; border: 1px solid #e5e7eb; }

@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  .sidebar, .topbar, .toasts, .print-toolbar, .no-print { display: none !important; }
  .container { max-width: none; padding: 0; }
  .print-claim { border: none; padding: 0; margin: 0; }
  .print-claim + .print-claim { break-before: page; page-break-before: always; }
}

/* ---------------- mobile ---------------- */
@media (max-width: 860px) {
  .container { padding: 12px; }
  h1 { font-size: 19px; }
  .card { padding: 12px 14px; }
  .topbar { display: flex; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .sidebar-mask { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35; }
  input[type=text], input[type=password], input[type=date], input[type=month], input[type=search], select, textarea { font-size: 16px; padding: 8px 10px; }
  .btn { min-height: 38px; }
  .btn.sm { min-height: 30px; padding: 4px 10px; font-size: 13px; }
  .btn.link { min-height: 0; }
  .filters > * { flex: 1 1 140px; max-width: none !important; }
  .info-grid { grid-template-columns: 1fr 1fr; }
  .att-inv { grid-template-columns: 1fr; }

  /* tables rendered as cards */
  .table-wrap { overflow: visible; border: none; background: transparent; }
  table.cards, table.cards tbody, table.cards tr, table.cards td, table.cards tfoot { display: block; width: 100%; }
  table.cards thead { display: none; }
  table.cards tr { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; padding: 8px 12px; }
  table.cards tr:hover td { background: transparent; }
  table.cards td { border: none; padding: 3px 0 3px 84px; position: relative; min-height: 26px; white-space: normal !important; }
  table.cards td::before { content: attr(data-label); position: absolute; left: 0; top: 3px; width: 78px; color: var(--muted); font-size: 12px; }
  table.cards td:not([data-label]) { padding-left: 0; }
  table.cards td:not([data-label])::before { display: none; }
  table.cards td.card-title { font-weight: 600; font-size: 15px; }
  table.cards tfoot tr { background: #f9fafb; }

  dialog.modal, dialog.modal.wide { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  dialog.modal[open] { display: flex; flex-direction: column; }
  .modal-body { flex: 1; max-height: none; }
  .modal-foot .btn { flex: 1; }
  .toasts { left: 12px; right: 12px; bottom: 12px; }
  .toast { max-width: none; }
  .login-wrap { margin: 6vh auto; }
  .sticky-foot { bottom: 0; border-radius: 0; margin: 0 -12px; }
}
