:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --border: #e5e8ef;
  --text: #1f2733;
  --muted: #7a8494;
  --primary: #1a6bff;
  --primary-weak: #e8f0ff;
  --danger: #e5484d;
  --ok: #1a9e6c;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 50, 0.08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; font-size: 14px; }
input, select, textarea {
  font-family: inherit; font-size: 14px; border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; width: 100%; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  background: var(--primary); color: #fff; transition: opacity .15s;
}
.btn:hover { opacity: .88; }
.btn.ghost { background: var(--primary-weak); color: var(--primary); }
.btn.danger { background: #fdecec; color: var(--danger); }
.btn.gray { background: #eef0f4; color: var(--text); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* 登录 / 初始化 */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 34px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 20px; margin-bottom: 4px; }
.auth-card .sub { color: var(--muted); margin-bottom: 22px; font-size: 13px; }
.auth-card .row { margin-bottom: 14px; }
.auth-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.auth-card .err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* 布局 */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 210px; background: #101828; color: #cdd5e0; flex-shrink: 0; display: flex; flex-direction: column; }
.brand { padding: 18px 18px; font-size: 16px; font-weight: 700; color: #fff; border-bottom: 1px solid #223047; }
.brand small { display: block; font-weight: 400; color: #6f7c90; font-size: 11px; }
.nav { flex: 1; padding: 10px 0; overflow-y: auto; }
.nav-group { font-size: 11px; color: #6f7c90; padding: 14px 18px 6px; letter-spacing: 1px; }
.nav-item { display: flex; align-items: center; gap: 9px; padding: 10px 18px; color: #cdd5e0; cursor: pointer; }
.nav-item:hover { background: #1b2639; color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item .ico { width: 16px; text-align: center; }
.sidebar .foot { padding: 14px 18px; border-top: 1px solid #223047; font-size: 12px; color: #8b97a8; }
.sidebar .foot .who { color: #e7ecf3; margin-bottom: 6px; }

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

/* 工具条 */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .search { width: 240px; padding: 7px 10px; }
.toolbar .spacer { flex: 1; }
.count { color: var(--muted); font-size: 13px; }

/* 表格 */
.table-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { background: #fafbfd; color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
tbody tr:hover { background: #f8faff; }
tbody tr:last-child td { border-bottom: none; }
td .ops { display: flex; gap: 6px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px; background: #eef0f4; color: #4a5568; }
.tag.blue { background: var(--primary-weak); color: var(--primary); }
.tag.green { background: #e4f5ec; color: var(--ok); }
.tag.red { background: #fdecec; color: var(--danger); }
.muted { color: var(--muted); }
.money { font-variant-numeric: tabular-nums; }
.empty { padding: 48px; text-align: center; color: var(--muted); }

/* 弹窗 */
.modal-mask { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 14px; width: 560px; max-width: 100%; box-shadow: 0 10px 40px rgba(0,0,0,.15); }
.modal.wide { width: 720px; }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { font-size: 16px; }
.modal-head .close { font-size: 20px; color: var(--muted); cursor: pointer; }
.modal-body { padding: 20px 22px; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.f-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.req::after { content: " *"; color: var(--danger); }
textarea { resize: vertical; min-height: 60px; }

/* 子表 items */
.items-table { margin-top: 4px; }
.items-table table th, .items-table table td { padding: 7px 8px; }
.items-table input, .items-table select { padding: 6px 8px; }

/* 权限矩阵 */
.perm-table th, .perm-table td { text-align: center; }
.perm-table th:first-child, .perm-table td:first-child { text-align: left; }
.perm-table input[type=checkbox] { width: auto; }
.checkbox-row { display: flex; align-items: center; gap: 6px; }

/* 部门树 */
.dept-node { padding: 6px 0; }
.dept-node .head { display: flex; align-items: center; gap: 8px; }
.dept-node .children { margin-left: 22px; border-left: 1px dashed var(--border); padding-left: 14px; }

.toast { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); background: #1f2733; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 100; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }