:root {
  --ink: #1c2430;
  --muted: #667085;
  --line: #e6e8ec;
  --bg: #f3f5f7;
  --card: #ffffff;
  --brand: #b42318;
  --brand-dark: #8e1b13;
  --ok: #067647;
  --ok-bg: #e8f6ee;
  --err: #b42318;
  --err-bg: #fdeceb;
  --warn-bg: #fff7e8;
  --sidebar: #1c2430;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  background: var(--sidebar);
  color: #f8fafc;
  padding: 22px 14px;
  flex-shrink: 0;
}
.brand { padding: 0 10px 18px; }
.brand strong { display: block; font-size: 16px; letter-spacing: 0.02em; }
.brand span { display: block; margin-top: 4px; color: #b8c0cc; font-size: 12px; }
.sidebar a {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: #d5dbe3;
  margin-bottom: 4px;
}
.sidebar a.active, .sidebar a:hover { background: rgba(255,255,255,0.08); color: white; }
.main { flex: 1; padding: 28px 32px 48px; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; }
h1 { margin: 0; font-size: 22px; font-weight: 650; }
.sub { margin: 6px 0 0; color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 16px; }
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { margin-top: 6px; font-size: 22px; font-weight: 650; }
.stat .hint { margin-top: 4px; color: var(--muted); font-size: 12px; min-height: 16px; }
.ok { color: var(--ok); }
.bad { color: var(--err); }

.alert { padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.err { background: var(--err-bg); color: var(--err); }
.alert.warn { background: var(--warn-bg); color: #9a6700; }
tr.skip-alert td {
  background: var(--err-bg);
  color: var(--err);
  font-weight: 600;
}
td.skip-alert-text {
  color: var(--err);
  font-weight: 600;
}

.form-grid { display: grid; grid-template-columns: 160px 1fr; gap: 10px 14px; align-items: center; }
label.field { color: var(--muted); }
.alert-type-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
}
.alert-type-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  line-height: 1.4;
}
.alert-type-item input { margin-top: 3px; }
.alert-type-item .muted { display: block; margin-top: 2px; font-size: 12px; }
.axis-pick { display: flex; gap: 8px; align-items: center; }
.axis-pick input { flex: 1; min-width: 0; }
.axis-pick button { flex: 0 0 auto; }
.axis-map-intro { margin: 12px 0 10px; }
.axis-map-scroll { max-height: none; margin-bottom: 4px; }
.axis-map-list td { vertical-align: top; }
.axis-map-list select,
.axis-map-list .dept-axis-id { width: 100%; min-width: 0; }
.axis-map-list select { min-height: 36px; }
.axis-static-source {
  min-height: 36px;
  display: flex;
  align-items: center;
  padding: 0 2px;
  font-weight: 600;
  color: var(--ink);
}
.axis-map-list .axis-static-source + .muted {
  display: block;
  margin-top: 4px;
  line-height: 1.45;
}
.axis-map-mid-cell {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  line-height: 1.45;
}
.axis-map-arrow {
  flex: 0 0 auto;
  color: var(--brand);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.4;
}
.axis-fixed-wrap { margin-top: 8px; }
.axis-scope-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.axis-scope-block .root-org-list { max-height: 180px; }
.root-org-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
  padding: 8px 10px;
  border: 1px solid #d0d5dd;
  border-radius: 8px;
  background: #fff;
}
.root-org-item {
  display: flex;
  gap: 8px;
  align-items: baseline;
  margin: 0;
  color: var(--ink);
  font-weight: 400;
}
.root-org-item input { width: auto; }
.root-org-item.is-virtual {
  color: #667085;
  cursor: not-allowed;
}
.root-org-item.is-virtual input { cursor: not-allowed; }
.root-org-item .virtual-hint { margin-left: 2px; }
.tree-toolbar { display: flex; gap: 8px; margin: 8px 0; }
.modal .tree-scroll { max-height: none; }
.dept-tree { padding: 4px 0 12px; }
.tree-node {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 32px;
}
button.tree-toggle,
.tree-toggle {
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex: 0 0 auto;
  box-shadow: none;
}
button.tree-toggle:hover { background: transparent; color: var(--ink); }
.tree-toggle-empty { cursor: default; visibility: hidden; }
button.tree-label,
.tree-label {
  display: flex;
  flex: 1;
  gap: 10px;
  align-items: baseline;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  box-shadow: none;
  font-weight: 400;
}
button.tree-label:hover,
.tree-label:hover { background: #eef2ff; color: var(--ink); }
.tree-name { font-weight: 600; }
.tree-meta { color: var(--muted); font-size: 12px; }
.tree-hit .tree-name { color: var(--brand); }
input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  border: 1px solid #d0d5dd;
  border-radius: 8px;
  padding: 8px 10px;
  background: white;
}
textarea { min-height: 80px; }
.help { grid-column: 2; color: var(--muted); font-size: 12px; margin-top: -4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
button, .btn {
  border: 0;
  background: var(--brand);
  color: white;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
a.btn { display: inline-block; text-decoration: none; }
button.secondary, .btn.secondary { background: #eef1f4; color: var(--ink); }
button.ghost, a.btn.ghost { background: white; color: var(--ink); border: 1px solid #d0d5dd; }
button:hover, .btn:hover { background: var(--brand-dark); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.secondary:hover, button.ghost:hover, a.btn.secondary:hover, a.btn.ghost:hover { background: #e4e7eb; color: var(--ink); }
.btn.disabled { opacity: 0.45; pointer-events: none; cursor: default; }
.json-view {
  position: relative;
  height: 520px;
  overflow: auto;
  background: #101828;
  color: #e8edf5;
  border-radius: 8px;
  font-family: Consolas, "Sarasa Mono SC", monospace;
  font-size: 12px;
}
.json-spacer { position: relative; width: calc(160ch + 28px); min-width: 100%; }
.json-lines { position: absolute; left: 0; top: 0; right: 0; height: 100%; }
.json-line {
  position: absolute;
  left: 0;
  top: 0;
  height: 18px;
  line-height: 18px;
  padding: 0 14px;
  white-space: pre;
}

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; background: #fafbfc; }
.muted { color: var(--muted); }
.tag {
  display: inline-block;
  background: #f2f4f7;
  border-radius: 999px;
  padding: 2px 8px;
  margin: 0 6px 6px 0;
  font-size: 12px;
}
.scroll { max-height: 460px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  background: #101828;
  color: #e8edf5;
  border-radius: 8px;
  padding: 14px;
  max-height: 520px;
  overflow: auto;
  font-family: Consolas, "Sarasa Mono SC", monospace;
  font-size: 12px;
  line-height: 1.5;
}
.steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.step { padding: 12px; border-radius: 10px; background: #fafbfc; border: 1px solid var(--line); }
.step b { display: block; margin-bottom: 6px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.empty { padding: 28px 8px; color: var(--muted); text-align: center; }
.inline { display: flex; gap: 8px; align-items: center; }
.batch-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.match-pager { margin-top: 12px; margin-bottom: 0; }
.match-pager button:disabled { opacity: 0.45; cursor: not-allowed; }
.batch-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  margin-right: 4px;
  white-space: nowrap;
}
.batch-bar .inline { gap: 6px; }
.batch-bar .inline select { min-width: 140px; }
.ref-line { display: flex; gap: 6px; align-items: center; }
.ref-line input[readonly] { background: #f8fafc; color: var(--ink); }
.ref-line button { width: auto; flex-shrink: 0; white-space: nowrap; }
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 24px;
}
.modal-mask[hidden] { display: none; }
.page-busy-mask {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(16, 24, 40, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.page-busy-mask[hidden] { display: none; }
.page-busy-panel {
  min-width: min(280px, 90vw);
  background: white;
  border-radius: 12px;
  padding: 22px 28px;
  text-align: center;
  border: 1px solid var(--line);
}
.page-busy-panel strong {
  display: block;
  font-size: 16px;
  margin-bottom: 6px;
}
.page-busy-panel .page-busy-step {
  display: block;
  color: var(--text, #1f2937);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}
.page-busy-panel span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  max-width: 360px;
}
body.is-page-busy {
  overflow: hidden;
}
body.is-page-busy button,
body.is-page-busy a.btn,
body.is-page-busy input,
body.is-page-busy select,
body.is-page-busy textarea {
  pointer-events: none;
}
.modal {
  width: min(760px, 100%);
  max-height: min(80vh, 680px);
  background: white;
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(16, 24, 40, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal.modal-wide {
  width: min(1180px, 96vw);
  max-height: min(88vh, 820px);
}
.modal-head, .modal-body { padding: 14px 16px; }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.modal-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-body input { margin-bottom: 10px; flex: 0 0 auto; }
.modal-body .tree-toolbar { flex: 0 0 auto; }
.picker-scroll {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 520px;
  overflow: auto;
}
.modal-wide .picker-scroll { max-height: none; }
.picker-table {
  table-layout: fixed;
  width: 100%;
  min-width: 1080px;
}
.picker-table th,
.picker-table td {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}
.picker-table col.c-name { width: 88px; }
.picker-table col.c-code { width: 150px; }
.picker-table col.c-yht { width: 280px; }
.picker-table col.c-objid { width: 260px; }
.picker-table col.c-dept { width: 300px; }
.picker-table.picker-table-role { min-width: 520px; }
.picker-table.picker-table-role col.c-name { width: 280px; }
.picker-table.picker-table-role col.c-code { width: 240px; }
.picker-row { cursor: pointer; }
.picker-row:hover { background: #f8fafc; }
.multi-select { position: relative; }
.multi-select-toggle {
  min-width: 180px;
  max-width: 260px;
  border: 1px solid #d0d5dd;
  border-radius: 8px;
  padding: 8px 28px 8px 10px;
  background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23667085' d='M1 1l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 10px center;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
button.multi-select-toggle:hover {
  background: #f8fafc url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23667085' d='M1 1l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 10px center;
  color: var(--ink);
}
.multi-select-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 20;
  width: 280px;
  max-height: 320px;
  background: white;
  border: 1px solid #d0d5dd;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.12);
  display: flex;
  flex-direction: column;
}
.multi-select-panel[hidden] { display: none; }
.multi-select-actions {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
}
.multi-select-actions button { padding: 4px 8px; font-size: 12px; }
.multi-select-list { overflow: auto; padding: 6px 8px 10px; }
.multi-select-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  cursor: pointer;
  border-radius: 6px;
}
.multi-select-list label:hover { background: #f8fafc; }
.multi-select-list input { width: auto; min-width: 0; }
.batch-bar select, .batch-bar input[type="text"], .batch-bar input[type="search"] { width: auto; min-width: 160px; }
.batch-bar .role-enabled-filter {
  flex: 0 0 auto;
  width: 120px;
  min-width: 120px;
}
.batch-bar .map-search {
  flex: 0 0 auto;
  width: 320px;
  min-width: 320px;
  max-width: 320px;
  border: 1px solid #d0d5dd;
  border-radius: 8px;
  padding: 8px 10px;
  background: white;
}
.inline input, .inline select { width: auto; min-width: 220px; }
.status-synced {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--ok-bg);
  color: var(--ok);
  font-size: 12px;
  font-weight: 600;
}
.status-unsynced {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--warn-bg);
  color: #b54708;
  font-size: 12px;
  font-weight: 600;
}
.role-page-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 12px;
}
.role-page-block {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafbfc;
  padding: 14px 16px;
}
.role-page-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: baseline;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.role-page-head strong { font-size: 16px; }
.role-page-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding-top: 12px;
}
.role-page-body-single {
  grid-template-columns: 1fr;
}
@media (max-width: 900px) {
  .role-page-body { grid-template-columns: 1fr; }
}
.role-page-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 8px;
  letter-spacing: 0.02em;
}
.role-scope-list,
.role-member-list,
.role-member-scope-list {
  margin: 0;
  padding-left: 18px;
}
.role-scope-list li,
.role-member-list > li {
  margin: 4px 0;
  line-height: 1.45;
}
.role-member-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
}
.role-member-scopes { margin-top: 2px; }
.role-member-scope-list {
  margin-top: 4px;
  color: var(--muted);
}
.role-group-title {
  margin: 18px 0 8px;
  font-size: 15px;
}
.role-member-card:first-of-type .role-group-title { margin-top: 8px; }
@media (max-width: 980px) {
  .layout { display: block; }
  .sidebar { width: auto; }
  .grid, .steps, .split { grid-template-columns: 1fr; }
  .main { padding: 18px; }
}
