:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --border: #dfe4ea;
  --text: #22303c;
  --muted: #718096;
  --primary: #10b981;
  --primary-dark: #059669;
  --danger: #e11d48;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-size: 18px; font-weight: 700; white-space: nowrap; }
.brand .sub { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 6px; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button {
  border: none;
  background: transparent;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
}
.tabs button:hover { background: #eef2f6; }
.tabs button.active { background: #e7f7f1; color: var(--primary-dark); font-weight: 600; }

main { max-width: 1180px; margin: 20px auto; padding: 0 20px; }
.tab { display: none; }
.tab.active { display: block; }

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}
.panel.narrow { max-width: 560px; }
.panel-title { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.store-panel { margin-bottom: 16px; }
.qr-upload { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; margin: 4px 0 12px; }
.qr-upload label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.qr-upload input[type="file"] { max-width: 220px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.form-grid.single { grid-template-columns: 1fr; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }

input, select, textarea {
  font: inherit;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #b8eadb; border-color: var(--primary); }

.block { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); margin: 14px 0; }

button {
  font: inherit;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
}
button:hover { background: #f6f8fa; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--primary-dark); }
button.ghost { border-style: dashed; color: var(--primary-dark); margin-top: 8px; }
button.small { padding: 6px 12px; font-size: 13px; }
button.icon { padding: 2px 8px; border: none; background: transparent; color: var(--muted); }
button.icon:hover { color: var(--danger); background: #fde8ef; }

.items { width: 100%; border-collapse: collapse; }
.items th {
  background: #f0f4f8;
  text-align: center;
  border: 1px solid var(--border);
  padding: 8px 6px;
  font-weight: 600;
}
.items td { border: 1px solid var(--border); padding: 2px; }
.items td.thin { border: none; width: 36px; background: transparent; }
.items input { border: none; padding: 8px 6px; border-radius: 0; }
.items input:focus { outline: 2px solid #b8eadb; }
.items .amount { display: block; text-align: right; padding: 8px 8px; color: var(--text); }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
  align-items: center;
}
.summary-grid > div {
  background: #f7faf9;
  border: 1px solid #e3efe9;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.summary-grid b { font-size: 16px; color: var(--text); }
.summary-grid .wide { grid-column: span 2; }
.summary-grid input { padding: 6px 8px; }

.actions { display: flex; gap: 10px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.badge { font-size: 13px; color: var(--muted); }
.badge a { margin-left: 8px; color: var(--primary-dark); }

.filters { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.filters input { width: 180px; }
.filters .sep { color: var(--muted); }
.count { color: var(--muted); font-size: 13px; margin-left: auto; }

.table-wrap { overflow-x: auto; }
.records { width: 100%; border-collapse: collapse; }
.records th, .records td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; white-space: nowrap; }
.records th { background: #f0f4f8; font-weight: 600; }
.records tbody tr:hover { background: #f8fbfa; }
.records .num { text-align: right; }
.records .ops { white-space: nowrap; }
.records .ops a { margin-right: 8px; color: var(--primary-dark); text-decoration: none; }
.records .ops a.danger { color: var(--danger); }
.records td a.cname-link { color: var(--text); text-decoration: none; font-weight: 600; }
.records td a.cname-link:hover { color: var(--primary-dark); text-decoration: underline; }
.records .empty { text-align: center; color: var(--muted); padding: 24px; }

.inline-form { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.inline-form input { width: 180px; }
.hint { color: var(--muted); font-size: 12px; }

.hidden { display: none !important; }
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 210; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-box { background: #fff; border-radius: 12px; width: 560px; max-width: 100%; max-height: 80vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-x { cursor: pointer; font-size: 20px; color: var(--muted); }
.modal-body { padding: 14px 16px; overflow-y: auto; }
.modal-body .hitem { padding: 6px 0; border-bottom: 1px dashed #eef2f6; font-size: 13px; }
.modal-body .hitem b { color: var(--primary-dark); }
.modal-body .prow { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px dashed #eef2f6; font-size: 13px; flex-wrap: wrap; }
.modal-body .prow > span { flex: 1; min-width: 160px; }
.modal-body .prow input { width: 110px; }
.modal-body .prow button { padding: 5px 10px; }
.records tr.overdue-row td { color: #b91c1c; font-weight: 600; }
#dashTrend { display: flex; gap: 18px; align-items: flex-end; padding: 10px 4px; }
.trend-item { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.trend-label { font-size: 11px; color: var(--muted); text-align: center; }
.trend-bar-wrap { height: 130px; display: flex; align-items: flex-end; }
.trend-bar { width: 34px; background: linear-gradient(180deg, #34d399, #059669); border-radius: 4px 4px 0 0; }
.login-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-box { background: #fff; border-radius: 14px; padding: 26px; width: 340px; max-width: 100%; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-box h2 { font-size: 18px; }
.login-box label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.user-badge { font-size: 13px; color: var(--muted); white-space: nowrap; }
.user-badge b { color: var(--text); }
.app-footer { text-align: center; font-size: 12px; color: var(--muted); padding: 14px; }
.stats-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.stat-card { flex: 1; min-width: 130px; background: #f7faf9; border: 1px solid #e3efe9; border-radius: 10px; padding: 10px 12px; }
.stat-card .k { font-size: 12px; color: var(--muted); }
.stat-card .v { font-size: 20px; font-weight: 700; margin-top: 2px; }
.delbox { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.delbox input { width: auto; }
.receipts-box { border: 1px dashed #cfe4da; border-radius: 10px; padding: 10px 12px; margin: 12px 0; }
.receipts-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.receipt-item { display: flex; gap: 8px; align-items: center; font-size: 13px; padding: 6px 8px; background: #f6faf8; border-radius: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.receipt-item b { color: var(--primary-dark); }
.receipt-item .rm { color: var(--danger); cursor: pointer; margin-left: auto; }
.receipt-item .thumb img { height: 46px; width: 46px; object-fit: cover; border-radius: 6px; cursor: zoom-in; display: block; }
.form-grid .wide2 { grid-column: span 2; }
.records tr.deleted-row td { color: #9ca3af; text-decoration: line-through; }
select.st-select { padding: 4px 6px; font-size: 12px; width: auto; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  z-index: 100;
}
#toast.error { background: var(--danger); }

@media (max-width: 860px) {
  .form-grid, .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 640px) {
  main { padding: 0 10px; margin: 10px auto; }
  .topbar { padding: 10px 12px; }
  .brand { font-size: 16px; }
  .brand .sub { display: none; }
  .tabs { width: 100%; overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .tabs button { flex: 0 0 auto; padding: 10px 12px; }
  .form-grid, .summary-grid { grid-template-columns: 1fr; }
  .form-grid label { font-size: 13px; }
  input, select, textarea { font-size: 16px; padding: 10px; }
  button { min-height: 44px; padding: 10px 14px; }
  .items-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .items { min-width: 880px; }
  .items input { font-size: 16px; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters input { width: 100%; }
  .filters .count { margin-left: 0; }
  .inline-form { flex-direction: column; align-items: stretch; }
  .inline-form input { width: 100%; }
  .qr-upload { flex-direction: column; align-items: stretch; }
  .qr-upload input[type="file"] { max-width: none; }
  .actions { flex-direction: column; align-items: stretch; }
  .actions button { width: 100%; }
  .table-wrap { margin: 0 -10px; padding: 0 10px; }
  .panel { padding: 14px; }
  .form-grid .wide2 { grid-column: span 1; }
  .stats-bar { flex-direction: row; }
  .stat-card { min-width: 42%; }
}
