/* ===== 组织架构查看器 · 样式 ===== */
:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --accent: #0d9488;        /* teal-600，专业且不刺眼 */
  --accent-soft: #ccfbf1;
  --accent-bg: #f0fdfa;
  --accent-ink: #0f766e;
  --warn: #b45309;
  --mark-bg: #fde68a;
  --mark-text: #78350f;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.08);
  --shadow-md: 0 4px 16px rgba(15,23,42,.10);
  --radius: 12px;
  --line: #e2e8f0;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
           "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ===== 布局 ===== */
.app { display: flex; flex-direction: column; height: 100dvh; }

/* 顶栏 */
.topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 18px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm); z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-ink));
  display: grid; place-items: center; color: #fff; flex: none;
}
.brand h1 { font-size: 16px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
.brand .sub { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

.stats { display: flex; gap: 8px; margin-left: 4px; }
.src-badge { font-size: 12px; line-height: 1; padding: 5px 10px; border-radius: 999px; white-space: nowrap; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-muted); flex: none; }
.src-badge.imported { color: var(--accent-ink); background: var(--accent-soft); border-color: #99f6e4; }
.stat {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 5px 11px; text-align: center; min-width: 64px;
}
.stat b { display: block; font-size: 16px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--text-muted); }

.spacer { flex: 1 1 auto; }

/* 搜索 */
.search { position: relative; flex: 0 1 320px; min-width: 200px; }
.search input {
  width: 100%; padding: 9px 34px 9px 34px; border: 1px solid var(--border-strong);
  border-radius: 10px; font-size: 14px; background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
.search .ico-search { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-faint); }
.search .count {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  font-size: 11px; color: var(--accent-ink); background: var(--accent-soft);
  border-radius: 999px; padding: 1px 8px; font-variant-numeric: tabular-nums;
}

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px;
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); border-radius: 9px; font-size: 13px; font-weight: 550;
  transition: background .15s, border-color .15s, transform .08s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.ghost { border-style: dashed; color: var(--text-muted); background: transparent; }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn svg { width: 16px; height: 16px; }

/* ===== 主体 ===== */
.main { position: relative; flex: 1 1 auto; overflow: hidden; display: flex; }
.tree-scroll {
  flex: 1 1 auto; overflow: auto; padding: 16px 18px 60px;
  scroll-behavior: smooth;
}
.tree { max-width: 1100px; margin: 0 auto; }

/* 节点 */
.node { position: relative; }
.node-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 9px; cursor: default;
  transition: background .12s;
}
.node-row:hover { background: var(--surface-2); }
.node.org > .node-row { cursor: pointer; }
.toggle {
  flex: none; width: 22px; height: 22px; border: none; background: transparent;
  color: var(--text-muted); border-radius: 6px; display: grid; place-items: center;
  font-size: 11px; transition: background .12s, color .12s;
}
.toggle:hover { background: var(--border); color: var(--text); }
.toggle.leaf { visibility: hidden; }
.ico { flex: none; display: grid; place-items: center; color: var(--text-muted); }
.ico.org { color: var(--accent); }
.node-row .label { font-weight: 550; color: var(--text); }
.node-row .sub { color: var(--text-muted); font-size: 12.5px; margin-left: 2px; }
.node-row .pill {
  margin-left: auto; font-size: 11px; color: var(--text-faint);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 8px; font-variant-numeric: tabular-nums;
}
.person .node-row { cursor: pointer; }
.person .node-row .label { font-weight: 500; }
.person .node-row .title { color: var(--text-muted); font-size: 12.5px; margin-left: 6px; }

/* 子级连接线 */
.children { margin-left: 17px; padding-left: 15px; border-left: 1px solid var(--line); }
.children.collapsed { display: none; }

mark { background: var(--mark-bg); color: var(--mark-text); border-radius: 3px; padding: 0 1px; }

/* 命中高亮 */
.node-row.hit { background: var(--accent-soft); }
.node-row.hit:hover { background: #b6f0e6; }

/* ===== 空 / 加载 / 错误 ===== */
.placeholder {
  max-width: 560px; margin: 8vh auto; text-align: center; color: var(--text-muted);
  background: var(--surface); border: 1px dashed var(--border-strong);
  border-radius: var(--radius); padding: 40px 28px; box-shadow: var(--shadow-sm);
}
.placeholder h2 { color: var(--text); margin: 14px 0 6px; font-size: 18px; }
.placeholder p { margin: 4px 0; font-size: 13.5px; }
.placeholder .drop {
  margin-top: 18px; border: 1.5px dashed var(--accent); border-radius: 10px;
  padding: 22px; color: var(--accent-ink); background: var(--accent-soft);
  transition: background .15s;
}
.placeholder .drop.over { background: #b6f0e6; }
.banner {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%);
  z-index: 60; max-width: 92vw; padding: 9px 16px; border-radius: 9px;
  font-size: 13px; display: flex; align-items: center; gap: 8px;
  box-shadow: var(--shadow-md);
}
.banner.error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.banner.info { background: var(--accent-soft); color: var(--accent-ink); border: 1px solid #99f6e4; }

/* ===== 人员详情卡 ===== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: grid; place-items: center; z-index: 50; padding: 20px;
  animation: fade .15s ease-out;
}
.modal {
  background: var(--surface); border-radius: 16px; width: min(420px, 100%);
  box-shadow: var(--shadow-md); overflow: hidden; animation: pop .18s cubic-bezier(.16,1,.3,1);
}
.modal .head { padding: 20px 22px 16px; display: flex; gap: 14px; align-items: center;
  background: linear-gradient(135deg, var(--accent-soft), #fff); }
.modal .avatar {
  width: 52px; height: 52px; border-radius: 14px; flex: none; color: #fff;
  display: grid; place-items: center; font-size: 20px; font-weight: 650;
  background: linear-gradient(135deg, var(--accent), var(--accent-ink));
}
.modal .head .nm { font-size: 18px; font-weight: 650; }
.modal .head .tt { font-size: 13px; color: var(--text-muted); }
.modal .head .lead-badge { display: inline-block; margin-top: 6px; font-size: 11px; font-weight: 600; color: var(--accent-ink); background: var(--accent-soft); border: 1px solid var(--accent-soft); border-radius: 999px; padding: 1px 9px; }
.modal .close { margin-left: auto; border: none; background: rgba(255,255,255,.6);
  width: 30px; height: 30px; border-radius: 8px; color: var(--text-muted); font-size: 16px; }
.modal .body { padding: 8px 22px 20px; }
.field { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.field:last-child { border-bottom: none; }
.field .k { width: 64px; flex: none; color: var(--text-muted); font-size: 12.5px; padding-top: 1px; }
.field .v { color: var(--text); word-break: break-all; }
.field .v a { color: var(--accent-ink); text-decoration: none; }
.field .v a:hover { text-decoration: underline; }
.modal .dept { margin-top: 10px; font-size: 12px; color: var(--text-muted); }

/* ===== 全局导航抽屉 ===== */
.drawer {
  position: absolute; top: 0; left: 0; bottom: 0; width: 300px; max-width: 86vw;
  background: var(--surface); border-right: 1px solid var(--border);
  box-shadow: var(--shadow-md); transform: translateX(-100%);
  transition: transform .22s cubic-bezier(.16,1,.3,1); z-index: 30;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer .dh { padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 650; display: flex; align-items: center; }
.drawer .dh .sub { font-weight: 400; font-size: 12px; color: var(--text-muted); margin-left: 8px; }
.drawer .dbody { overflow: auto; padding: 10px 8px 20px; }
.drawer .node-row { padding: 6px 8px; }
.drawer .closeb { margin-left: auto; border: none; background: transparent; color: var(--text-muted); font-size: 18px; width: 30px; height: 30px; border-radius: 8px; }
.drawer .closeb:hover { background: var(--surface-2); }
.scrim { position: absolute; inset: 0; background: rgba(15,23,42,.25); z-index: 25; opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrim.show { opacity: 1; pointer-events: auto; }

/* ===== 缩略图 minimap ===== */
.minimap {
  position: absolute; right: 14px; bottom: 14px; width: 200px; height: 150px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px;
  box-shadow: var(--shadow-md); overflow: hidden; z-index: 28; display: flex; flex-direction: column;
}
.minimap .mh { font-size: 11px; color: var(--text-muted); padding: 5px 9px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.minimap .mh .mtoggle { margin-left: auto; border: none; background: transparent; color: var(--text-faint); font-size: 13px; }
.minimap .mview { position: relative; flex: 1; overflow: hidden; }
.minimap .mscale { position: absolute; top: 0; left: 0; transform-origin: top left; padding: 6px; pointer-events: none; }
.minimap .mscale .mnode { font-size: 11px; line-height: 1.35; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.minimap .viewport {
  position: absolute; border: 2px solid var(--accent); background: rgba(13,148,136,.12);
  border-radius: 3px; pointer-events: none; transition: top .05s linear, height .05s linear;
}

/* ===== 动画 / 无障碍 ===== */
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* 小屏 */
@media (max-width: 720px) {
  .stats { order: 3; width: 100%; justify-content: flex-start; }
  .search { order: 4; flex: 1 1 100%; }
  .topbar { gap: 10px; }
}

/* ===== 视图切换分段控件 ===== */
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 9px; overflow: hidden; background: var(--surface); }
.seg-btn {
  border: none; background: transparent; color: var(--text-muted);
  padding: 8px 14px; font-size: 13px; font-weight: 550; transition: background .15s, color .15s;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn:hover { background: var(--surface-2); color: var(--text); }
.seg-btn.active { background: var(--accent); color: #fff; }

/* ===== 树形视图 org chart ===== */
.tree-chart { padding: 18px 18px 50px; min-width: min-content; }
.tree-chart .tree-head { font-size: 13px; color: var(--text-muted); margin: 0 0 6px 2px; }
.tree-chart .tree-empty { color: var(--text-muted); padding: 24px 4px; }

.tree-chart ul { position: relative; padding-top: 24px; display: flex; justify-content: center; list-style: none; margin: 0; }
.tree-chart > ul { padding-top: 0; }
.tree-chart li {
  list-style: none; position: relative; padding: 24px 7px 0;
  display: flex; flex-direction: column; align-items: center;
}
/* 连接线：父到子的横线 + 竖线 */
.tree-chart li::before, .tree-chart li::after {
  content: ''; position: absolute; top: 0; right: 50%;
  border-top: 2px solid var(--line); width: 50%; height: 24px;
}
.tree-chart li::after { right: auto; left: 50%; border-left: 2px solid var(--line); }
.tree-chart li::before { border-right: 2px solid var(--line); }
/* 子级 ul 顶部向下的竖线 */
.tree-chart ul ul::before {
  content: ''; position: absolute; top: 0; left: 50%;
  border-left: 2px solid var(--line); width: 0; height: 24px;
}
.tree-chart li:only-child::before, .tree-chart li:only-child::after { display: none; }
.tree-chart li:only-child { padding-top: 24px; }
/* 根级 li 无上方连接线 */
.tree-chart > ul > li::before, .tree-chart > ul > li::after { display: none; }
.tree-chart > ul > li { padding-top: 0; }
/* 首/末 子节点圆角处理 */
.tree-chart li:first-child::before, .tree-chart li:last-child::after { border: 0; }
.tree-chart li:last-child::before { border-right: 2px solid var(--line); border-radius: 0 6px 0 0; }
.tree-chart li:first-child::after { border-radius: 6px 0 0 0; }

/* 树形节点卡片：三行居中（部门名称 / 负责人名称 / 人数），长度(176px)不变 */
.tree-chart .node-row {
  position: relative; width: 176px; max-width: 200px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  margin: 0 auto; padding: 8px 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-sm); cursor: pointer;
  overflow: hidden;
}
.tree-chart .org > .node-row { border-color: var(--accent-soft); background: var(--accent-bg); }
.tree-chart .node-row:hover { border-color: var(--accent); box-shadow: var(--shadow-md); }
.tree-chart .node-row .toggle { position: static; flex: none; align-self: flex-end; margin: -2px -4px 0 0; }
.tree-chart .node-row .label { font-weight: 600; flex: none; text-align: center; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100%; }
.tree-chart .node-row .card-body { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; width: 100%; }
.tree-chart .node-row .c-lead { font-size: 12px; color: var(--text-muted); text-align: center; }
.tree-chart .node-row .c-count { font-size: 11px; color: var(--text-muted); text-align: center; }
.tree-chart .node-row .lead { color: var(--accent-ink); font-weight: 550; cursor: pointer; }
.tree-chart .node-row .lead:hover { text-decoration: underline; }
.tree-chart .node-row .ltag {
  display: inline-block; margin-left: 4px; font-size: 10px; font-weight: 600;
  border-radius: 999px; padding: 0 6px; line-height: 15px; vertical-align: middle;
}
.tree-chart .node-row .ltag.zhu { color: #0f766e; background: #ccfbf1; border: 1px solid #99f6e4; }
.tree-chart .node-row .ltag.jian { color: #b45309; background: #fef3c7; border: 1px solid #fde68a; }
.tree-chart .person > .node-row .label { font-weight: 500; }
.tree-chart .node-row .title { color: var(--text-muted); font-size: 12px; margin-left: 0; flex: none; }
.tree-chart .node-row .pill { margin-left: 0; flex: none; }
.tree-chart .node-row.hit { background: var(--accent-soft); border-color: var(--accent); }
.tree-chart .node-row.hit:hover { background: #b6f0e6; }

/* 编辑模式：拖动排序部门 */
.btn.save { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.save:hover { background: var(--accent-ink); }
.tree-scroll.editing { cursor: default; }
.tree-chart.edit .node-row.draggable { cursor: grab; }
.tree-chart.edit .node-row.draggable:active { cursor: grabbing; }
.tree-chart.edit .tnode.org > .node-row.draggable::before {
  content: '\2630'; position: absolute; left: 6px; top: 6px;
  font-size: 12px; line-height: 1; color: var(--text-faint);
}
.tree-chart.edit .node-row.draggable:hover { border-color: var(--accent); box-shadow: var(--shadow-md); }
.tree-chart .node-row.dragging { opacity: .4; }
.tree-chart li > .node-row.drag-before { box-shadow: 0 -3px 0 0 var(--accent); }
.tree-chart li > .node-row.drag-after { box-shadow: 0 3px 0 0 var(--accent); }
