* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --green: #16a34a;
  --yellow: #f59e0b;
  --red: #dc2626;
  --sidebar: #0f172a;
}
html, body { height: 100%; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }

/* 登录 */
.login-wrap { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0f172a, #1e3a8a); }
.login-box { background: #fff; padding: 36px 34px; border-radius: 12px; width: 360px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-box h1 { font-size: 20px; text-align: center; margin-bottom: 6px; }
.login-box .sub { text-align: center; color: var(--muted); margin-bottom: 22px; font-size: 13px; }
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px;
  font-family: inherit;
}
.form-row textarea { min-height: 60px; resize: vertical; }
.login-box .hint { margin-top: 14px; font-size: 12px; color: var(--muted); text-align: center; }

/* 布局 */
.app { display: flex; height: 100vh; }
.sidebar { width: 220px; background: var(--sidebar); color: #cbd5e1; display: flex; flex-direction: column; flex-shrink: 0; }
.logo { padding: 20px 18px; font-size: 16px; line-height: 1.5; border-bottom: 1px solid #1e293b; color: #fff; font-weight: 600; }
#nav { flex: 1; overflow-y: auto; padding: 10px 0; }
#nav .nav-item { display: block; width: 100%; text-align: left; padding: 11px 20px; background: none; border: none; color: #cbd5e1; cursor: pointer; font-size: 14px; }
#nav .nav-item:hover { background: #1e293b; color: #fff; }
#nav .nav-item.active { background: var(--primary); color: #fff; }
.user { padding: 14px 18px; border-top: 1px solid #1e293b; font-size: 13px; }
.user button { margin-top: 8px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 56px; background: #fff; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; }
#page-title { font-size: 17px; font-weight: 600; }
.topbar-right { display: flex; gap: 10px; align-items: center; }
.content { flex: 1; overflow: auto; padding: 20px; }

/* 卡片与表格 */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.card h3 { font-size: 15px; margin-bottom: 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.toolbar input, .toolbar select { padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }
.spacer { flex: 1; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 9px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { background: #f8fafc; color: var(--muted); font-weight: 600; position: sticky; top: 0; }
tbody tr:hover { background: #f8fafc; }
td.num, th.num { text-align: right; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; background: #eef2ff; color: var(--primary); }
.tag.green { background: #dcfce7; color: var(--green); }
.tag.yellow { background: #fef9c3; color: #a16207; }
.tag.red { background: #fee2e2; color: var(--red); }
.tag.gray { background: #f1f5f9; color: var(--muted); }
.badge { display: inline-block; margin-left: 6px; padding: 0 6px; background: var(--red); color: #fff; border-radius: 10px; font-size: 11px; line-height: 18px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.link { color: var(--primary); cursor: pointer; text-decoration: none; }
.link:hover { text-decoration: underline; }
.empty { text-align: center; color: var(--muted); padding: 30px; }

/* 按钮 */
.btn { display: inline-block; padding: 8px 14px; border: 1px solid var(--border); border-radius: 6px; background: #fff; cursor: pointer; font-size: 13px; color: var(--text); }
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: #fff; border-color: #fecaca; color: var(--red); }
.btn.danger:hover { background: #fee2e2; }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.small { padding: 4px 9px; font-size: 12px; }

/* 弹窗 */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-box { background: #fff; border-radius: 10px; width: 720px; max-width: 94vw; max-height: 90vh; display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 600; }
.modal-close { border: none; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 3px; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; font-family: inherit; }
.section-label { grid-column: 1 / -1; font-weight: 600; color: var(--text); margin-top: 6px; padding-top: 8px; border-top: 1px dashed var(--border); }

/* 概览统计 */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; }
.stat .k { color: var(--muted); font-size: 13px; }
.stat .v { font-size: 26px; font-weight: 700; margin-top: 4px; }

/* 统计表格高亮 */
.warn { color: var(--red); font-weight: 600; }
.ok { color: var(--green); }

/* toast */
.toast { position: fixed; top: 20px; right: 20px; background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 200; box-shadow: 0 8px 24px rgba(0,0,0,.25); }

.menu-btn { display: none; }
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 290; }
.nav-ico { display: inline-block; width: 22px; text-align: center; margin-right: 8px; font-size: 15px; }

@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 0; }
  .logo { display: none; }
  .menu-btn { display: block; background: #1e293b; border: 1px solid #334155; color: #e2e8f0; padding: 10px 14px; border-radius: 6px; font-size: 14px; margin: 6px; }
  #nav { display: none; width: 100%; flex-direction: column; padding: 0; }
  #nav.open { display: flex; position: fixed; top: 0; left: 0; width: 80vw; max-width: 320px; height: 100%; overflow-y: auto; background: var(--sidebar); z-index: 300; box-shadow: 4px 0 24px rgba(0, 0, 0, .4); padding-top: 16px; }
  #nav .nav-item { display: flex; align-items: center; width: 100%; text-align: left; padding: 14px 18px; border-bottom: 1px solid #1e293b; }
  #nav .nav-item .badge { margin-left: auto; }
  .user { display: flex; flex-direction: row; align-items: center; gap: 8px; padding: 4px 10px; margin-left: auto; border-top: none; white-space: nowrap; }
  .user button { margin-top: 0; }
  .main { min-height: 0; }
  .content { padding: 12px; }
  .login-box { width: 92vw; max-width: 360px; }
  .topbar { height: auto; min-height: 48px; padding: 8px 12px; flex-wrap: wrap; }
  .form-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .card { overflow-x: auto; }
  table { font-size: 12px; }
  th, td { padding: 7px 6px; }
}

/* 变更历史卡片 */
.chg-card { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; background: #fafbfc; }
.chg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.chg-time { font-weight: 600; color: var(--text); }
.chg-line { margin: 2px 0; font-size: 13px; }
.chg-k { color: var(--muted); margin-right: 6px; }
.chg-old { color: var(--muted); text-decoration: line-through; }
.chg-arrow { color: var(--muted); margin: 0 6px; }
.chg-new { color: var(--text); font-weight: 500; }
.chg-mark { color: var(--yellow); margin-left: 4px; cursor: default; }

/* 退费（终止）客户的历史台账行 */
tr.row-terminated { background: #fee2e2; color: #dc2626; }
tr.row-terminated:hover { background: #fecaca; }
tr.row-terminated a.link { color: #dc2626; }
