:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #1e293b;
  --text-2: #64748b;
  --text-3: #94a3b8;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --shadow: 0 1px 2px rgba(15,23,42,.04), 0 8px 24px rgba(15,23,42,.05);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* ---------------- 登录 ---------------- */
.auth-view { display: flex; min-height: 100vh; }
.auth-brand {
  width: 46%; min-width: 420px;
  background: linear-gradient(150deg, #1e3a8a 0%, #2563eb 55%, #3b82f6 100%);
  color: #fff; position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 56px 60px 40px;
}
.auth-brand::before {
  content: ""; position: absolute; width: 520px; height: 520px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.14); right: -180px; top: -160px;
}
.auth-brand::after {
  content: ""; position: absolute; width: 380px; height: 380px; border-radius: 50%;
  background: rgba(255,255,255,.06); left: -140px; bottom: -120px;
}
.auth-brand-inner, .auth-brand-footer { position: relative; z-index: 1; }
.brand-mark {
  width: 56px; height: 56px; border-radius: 16px; background: rgba(255,255,255,.18);
  border: 1px solid rgba(255,255,255,.3); display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px; letter-spacing: .5px; margin-bottom: 34px;
}
.brand-mark.small { width: 38px; height: 38px; border-radius: 10px; margin: 0; font-size: 14px; background: var(--primary); border: none; }
.auth-brand h1 { font-size: 38px; line-height: 1.3; margin: 0 0 14px; font-weight: 700; letter-spacing: -.5px; }
.auth-brand p { font-size: 15px; opacity: .82; margin: 0; }
.auth-features { margin-top: 48px; display: grid; gap: 14px; }
.auth-feature { display: flex; align-items: center; gap: 10px; font-size: 14px; opacity: .92; }
.auth-feature span { width: 30px; height: 30px; border-radius: 8px; background: rgba(255,255,255,.15); display: grid; place-items: center; }
.auth-brand-footer { font-size: 12px; opacity: .6; letter-spacing: .5px; }

.auth-panel { flex: 1; display: grid; place-items: center; padding: 40px; }
.auth-form-wrap { width: 100%; max-width: 400px; }
.auth-tabs { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 10px; margin-bottom: 30px; }
.auth-tab { flex: 1; border: none; background: transparent; padding: 9px; border-radius: 8px; color: var(--text-2); font-weight: 600; transition: .15s; }
.auth-tab.active { background: var(--surface); color: var(--primary); box-shadow: 0 1px 3px rgba(15,23,42,.08); }
.auth-form h2 { font-size: 26px; margin: 0 0 6px; }
.auth-sub { color: var(--text-2); margin: 0 0 26px; }
.field { display: block; margin-bottom: 18px; }
.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 7px; color: var(--text); }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 9px;
  background: #fff; color: var(--text); outline: none; transition: .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.field textarea { resize: vertical; min-height: 78px; }
.form-error { color: var(--danger); font-size: 13px; min-height: 20px; margin-bottom: 6px; }
.auth-tip { margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--border); color: var(--text-3); font-size: 12px; text-align: center; }

/* ---------------- 按钮 ---------------- */
.btn { border: 1px solid transparent; border-radius: 9px; padding: 9px 15px; font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: .15s; white-space: nowrap; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-block { width: 100%; padding: 12px; font-size: 14px; }
.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-soft { background: var(--primary-soft); color: var(--primary); }
.btn-soft:hover { background: #dbeafe; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-danger-soft { background: var(--danger-soft); color: var(--danger); }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 7px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { border: none; background: transparent; color: var(--text-2); width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; font-size: 17px; }
.icon-btn:hover { background: var(--surface-2); color: var(--primary); }
.link-btn { border: none; background: none; color: var(--primary); padding: 0; font-size: 13px; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }

/* ---------------- 布局 ---------------- */
.app-view { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.side-head { display: flex; align-items: center; gap: 11px; padding: 20px 20px 22px; }
.brand-title { font-weight: 700; font-size: 16px; line-height: 1.2; }
.brand-sub { font-size: 11px; color: var(--text-3); }
.side-nav { padding: 0 12px; display: grid; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; border: none; background: transparent;
  padding: 10px 12px; border-radius: 8px; color: var(--text-2); font-weight: 500; text-align: left;
}
.nav-item span { font-size: 16px; width: 20px; text-align: center; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.side-section { flex: 1; overflow: auto; padding: 22px 12px 10px; border-top: 1px solid var(--border); margin-top: 18px; }
.side-section-title { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 10px; color: var(--text-3); font-size: 11px; font-weight: 700; letter-spacing: .8px; }
.side-ledgers { display: grid; gap: 3px; }
.ledger-nav {
  display: flex; align-items: center; gap: 9px; width: 100%; border: none; background: transparent;
  padding: 9px 10px; border-radius: 8px; text-align: left; color: var(--text-2);
}
.ledger-nav:hover { background: var(--surface-2); }
.ledger-nav.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.ledger-nav-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.ledger-nav-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.ledger-nav-count { font-size: 11px; color: var(--text-3); }
.side-empty { padding: 12px 8px; color: var(--text-3); font-size: 12px; line-height: 1.7; }
.side-foot { padding: 14px 16px 20px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.user-chip-name { font-weight: 600; font-size: 13px; }
.user-chip-role { font-size: 11px; color: var(--text-3); }

.main { flex: 1; min-width: 0; padding: 32px 38px 60px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 26px; flex-wrap: wrap; }
.page-title { font-size: 24px; font-weight: 700; margin: 0 0 4px; }
.page-desc { color: var(--text-2); margin: 0; font-size: 13px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------- 卡片 / 表格 ---------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 22px; }
.ledger-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.ledger-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; cursor: pointer; transition: .18s; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.ledger-card:hover { transform: translateY(-2px); border-color: var(--border-strong); box-shadow: 0 12px 30px rgba(15,23,42,.09); }
.ledger-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent, var(--primary)); }
.ledger-card-top { display: flex; align-items: center; gap: 11px; margin-bottom: 12px; }
.ledger-icon { width: 40px; height: 40px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; font-size: 20px; }
.ledger-card h3 { margin: 0; font-size: 16px; }
.ledger-card p { color: var(--text-2); font-size: 12px; margin: 0 0 16px; min-height: 34px; }
.ledger-card-foot { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--border); padding-top: 12px; font-size: 12px; color: var(--text-3); }
.badge { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 20px; padding: 2px 9px; font-size: 11px; color: var(--text-2); }
.badge.blue { background: var(--primary-soft); color: var(--primary); border-color: #dbeafe; }
.badge.green { background: var(--success-soft); color: var(--success); border-color: #d1fae5; }
.badge.red { background: var(--danger-soft); color: var(--danger); border-color: #fee2e2; }

.table-toolbar { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.search-box { position: relative; flex: 1; min-width: 200px; max-width: 360px; }
.search-box input { width: 100%; padding: 8px 12px 8px 34px; border: 1px solid var(--border-strong); border-radius: 8px; outline: none; }
.search-box input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.search-box::before { content: "🔍"; position: absolute; left: 10px; top: 7px; font-size: 13px; opacity: .6; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  background: var(--surface-2); text-align: left; padding: 11px 14px; font-size: 12px;
  color: var(--text-2); font-weight: 600; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0;
}
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; max-width: 260px; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: #fafcff; }
.cell-clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cell-empty { color: var(--text-3); }
.row-actions { display: flex; gap: 6px; white-space: nowrap; }
.table-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; color: var(--text-2); font-size: 12px; }
.empty-state { padding: 70px 20px; text-align: center; color: var(--text-2); }
.empty-state .empty-icon { font-size: 42px; margin-bottom: 12px; }
.empty-state h3 { margin: 0 0 6px; color: var(--text); font-size: 16px; }
.empty-state p { margin: 0 0 18px; font-size: 13px; }

/* ---------------- 表单 / 弹窗 ---------------- */
.modal-mask { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 620px; box-shadow: 0 24px 60px rgba(15,23,42,.25); }
.modal.wide { max-width: 920px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 22px; position: relative; }

/* 干部人事字段库选择器 */
.field-picker {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  z-index: 150; width: min(740px, 94vw); height: min(660px, 84vh);
  background: var(--surface); border-radius: 14px;
  display: flex; flex-direction: column; padding: 18px 20px;
  box-shadow: 0 24px 60px rgba(15,23,42,.3);
}
.fp-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.fp-head strong { font-size: 15px; }
.fp-head .hint { margin-right: auto; }
.fp-presets { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.fp-search {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: 8px;
  outline: none; margin-bottom: 10px;
}
.fp-search:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.fp-cats { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.fp-cat { border: 1px solid var(--border); background: #fff; border-radius: 20px; padding: 4px 11px; font-size: 12px; color: var(--text-2); }
.fp-cat:hover { border-color: var(--primary); color: var(--primary); }
.fp-cat.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); font-weight: 600; }
.fp-fields {
  flex: 1; overflow-y: auto; min-height: 160px; max-height: 320px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 8px; align-content: start; padding-right: 4px;
}
.fp-field {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px;
  background: #fff; text-align: left; transition: .15s;
}
.fp-field:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-soft); }
.fp-field.selected { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 2px rgba(37,99,235,.12); }
.fp-field:disabled { opacity: .5; cursor: not-allowed; }
.fp-name { font-size: 13px; font-weight: 600; }
.fp-type { font-size: 11px; color: var(--text-3); }
.fp-dup { font-size: 10px; color: var(--danger); }
.fp-foot {
  display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--border);
  padding-top: 12px; margin-top: 12px;
}
.fp-foot .hint { margin-right: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 22px; border-top: 1px solid var(--border); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.hint { font-size: 12px; color: var(--text-3); margin-top: 5px; }
.section-title { font-size: 13px; font-weight: 700; margin: 4px 0 12px; display: flex; justify-content: space-between; align-items: center; }

.col-editor { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; background: var(--surface-2); transition: opacity .12s, border-color .12s; }
.col-editor.dragging { opacity: .4; border-style: dashed; }
.col-editor.drop-before { border-top: 2px solid var(--primary); }
.col-editor.drop-after { border-bottom: 2px solid var(--primary); }
.col-grip { width: 20px; height: 24px; display: grid; place-items: center; cursor: grab; color: var(--text-3); font-size: 15px; flex-shrink: 0; user-select: none; }
.col-grip:hover { color: var(--primary); }
.col-grip:active { cursor: grabbing; }
.col-editor-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.col-editor-head .num { width: 24px; height: 24px; border-radius: 6px; background: var(--surface); border: 1px solid var(--border); display: grid; place-items: center; font-size: 11px; color: var(--text-2); flex-shrink: 0; }
.col-editor input[type=text], .col-editor select { padding: 7px 9px; border: 1px solid var(--border-strong); border-radius: 7px; background: #fff; outline: none; }
.col-editor input[type=text]:focus, .col-editor select:focus { border-color: var(--primary); }
.col-name { flex: 1; min-width: 120px; }
.col-type { width: 108px; }
.col-check { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-2); white-space: nowrap; }
.col-editor-foot { display: flex; align-items: center; gap: 8px; padding-left: 32px; }
.col-editor-foot input { flex: 1; padding: 7px 9px; border: 1px solid var(--border-strong); border-radius: 7px; outline: none; }
.mini-btn { border: 1px solid var(--border); background: #fff; border-radius: 6px; width: 26px; height: 26px; display: grid; place-items: center; color: var(--text-2); font-size: 12px; }
.mini-btn:hover { border-color: var(--primary); color: var(--primary); }
.mini-btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.template-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.template-card { border: 1px solid var(--border); border-radius: 9px; padding: 12px; cursor: pointer; background: #fff; text-align: left; transition: .15s; }
.template-card:hover { border-color: var(--primary); background: var(--primary-soft); }
.template-card.active { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 2px rgba(37,99,235,.1); }
.template-card .t-icon { font-size: 20px; }
.template-card .t-name { font-weight: 600; font-size: 13px; margin-top: 5px; }
.template-card .t-desc { color: var(--text-3); font-size: 11px; margin-top: 2px; line-height: 1.4; }

.toast-root { position: fixed; top: 20px; right: 20px; z-index: 200; display: grid; gap: 8px; }
.toast { background: #fff; border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 9px; padding: 11px 16px; box-shadow: 0 10px 30px rgba(15,23,42,.13); font-size: 13px; min-width: 220px; animation: slideIn .2s ease; }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
@keyframes slideIn { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

.role-select { padding: 5px 8px; border: 1px solid var(--border-strong); border-radius: 6px; background: #fff; }
.log-list { display: grid; }
.log-item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.log-item:last-child { border-bottom: none; }
.log-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--primary); flex-shrink: 0; }
.log-time { color: var(--text-3); font-size: 12px; margin-left: auto; }

@media (max-width: 900px) {
  .auth-brand { display: none; }
  .sidebar { width: 64px; }
  .side-head > div:last-child, .nav-item, .side-section, .user-chip, .side-foot .btn { font-size: 0; }
  .brand-title, .brand-sub { display: none; }
  .nav-item { justify-content: center; }
  .nav-item span { font-size: 18px; }
  .main { padding: 22px 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .template-grid { grid-template-columns: 1fr 1fr; }
}
