:root {
  --bg: #f0f2f6;
  --panel: #ffffff;
  --ink: #1f2733;
  --muted: #607089;
  --line-lead: #dba17e;
  --line-member: #5f6fc9;
  --lead-ribbon: #dea983;
  --lead-ring: #e4af8d;
  --member-ribbon: #5966bb;
  --member-ring: #5f6cc1;
  --party-red: #c7161d;
  --party-gold: #f8c24f;
  --shadow: 0 10px 24px rgba(17, 24, 39, 0.18);
  --surface-shadow: 0 16px 30px rgba(17, 24, 39, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: "Source Han Sans SC", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 10% 10%, rgba(31, 92, 166, 0.12), transparent 22%),
    linear-gradient(180deg, #eef1f7 0%, #e6ebf2 100%);
  color: var(--ink);
}

.app-shell {
  height: 100%;
  padding: 14px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
}

.topbar {
  background: var(--panel);
  border-radius: 14px;
  box-shadow: var(--surface-shadow);
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
  color: #1f5ca6;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(460px, 520px) 1fr;
  gap: 12px;
}

.panel {
  background: var(--panel);
  border-radius: 14px;
  box-shadow: var(--surface-shadow);
  min-height: 0;
}

.editor-panel {
  padding: 12px;
  display: grid;
  grid-template-rows: auto minmax(240px, 1.1fr) auto auto minmax(320px, 1fr) auto;
  gap: 10px;
  min-height: 0;
  overflow: hidden;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 8px;
}

.section-head h2,
.preview-head h2 {
  margin: 0;
  font-size: 15px;
}

.inline-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex: 1;
}

button {
  border: 0;
  border-radius: 9px;
  background: #5b68bf;
  color: #fff;
  height: 32px;
  padding: 0 12px;
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}

button:hover {
  filter: brightness(0.95);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.primary-btn {
  background: #1f5ca6;
}

.ghost-btn {
  background: #edf2fb;
  color: #365280;
}

.danger {
  background: #bd2f2f;
}

.node-list {
  border: 1px solid #d8dfeb;
  border-radius: 10px;
  overflow: auto;
  min-height: 0;
  max-height: 42vh;
  background: #fafcff;
}

.node-list-root-drop {
  position: sticky;
  top: 0;
  z-index: 3;
  margin: 0;
  padding: 8px 10px;
  font-size: 12px;
  color: #4f6182;
  background: #f3f7ff;
  border-bottom: 1px dashed #ccdaef;
}

.node-list-root-drop.drop-target {
  background: #e3eeff;
  color: #1f5ca6;
}

.node-item {
  padding: 8px 10px;
  border-bottom: 1px solid #e4eaf5;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 6px;
  align-items: center;
  cursor: pointer;
}

.node-item:hover {
  background: #f2f6ff;
}

.node-item.selected {
  background: #edf3ff;
}

.node-item.active {
  background: #e6efff;
  border-left: 4px solid #1f5ca6;
  padding-left: 6px;
}

.node-item.drag-source {
  opacity: 0.62;
}

.node-item.drop-target {
  outline: 2px dashed #5d79c9;
  outline-offset: -3px;
  background: #eaf1ff;
}

.node-check-wrap {
  width: 16px;
  display: grid;
  place-items: center;
}

.node-check-wrap input {
  width: 14px;
  height: 14px;
  margin: 0;
}

.node-main {
  min-width: 0;
}

.node-item .meta {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.node-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.drag-handle {
  color: #7990b5;
  font-size: 14px;
  line-height: 1;
  user-select: none;
}

.tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: #eff2fb;
  color: #3d4a61;
  min-width: 58px;
  height: 24px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 700;
}

.batch-panel {
  border: 1px solid #d8dfeb;
  border-radius: 10px;
  background: #f8fbff;
  padding: 8px;
  display: grid;
  gap: 8px;
}

.batch-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: #2f4771;
}

.batch-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 6px;
}

.batch-actions button {
  width: 100%;
}

.batch-parent {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: center;
}

.batch-parent label {
  grid-column: 1 / -1;
  font-size: 12px;
  color: #4f6182;
}

.batch-parent select {
  min-width: 0;
  width: 100%;
  height: 32px;
  border-radius: 8px;
  border: 1px solid #cfd8e8;
  background: #fff;
  padding: 0 10px;
  font-size: 13px;
}

.batch-tip {
  margin: 0;
  color: #5f6f88;
  font-size: 12px;
}

.node-form {
  display: grid;
  gap: 8px;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.node-form label {
  font-size: 12px;
  color: #4d607c;
  display: grid;
  gap: 5px;
}

.node-form input,
.node-form select {
  width: 100%;
  height: 32px;
  border-radius: 8px;
  border: 1px solid #cfd8e8;
  background: #fff;
  padding: 0 10px;
  font-size: 13px;
}

.check-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.check-row.single {
  grid-template-columns: 1fr;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  min-height: 30px;
  height: auto;
  background: #f5f8ff;
  border: 1px solid #d8e2f3;
  border-radius: 8px;
  padding: 6px 8px;
  color: #2f4771;
  line-height: 1.35;
}

.check input {
  width: 14px;
  height: 14px;
  margin-top: 2px;
  flex: 0 0 auto;
}

.help-text {
  color: #5f6f88;
  font-size: 12px;
  line-height: 1.55;
}

.preview-panel {
  padding: 12px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
}

.preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#statusText {
  color: #5f6f88;
  font-size: 12px;
}

.preview-frame {
  min-height: 0;
  background: #e5ebf3;
  border-radius: 12px;
  padding: 10px;
  overflow: hidden;
}

.slide-page {
  width: min(100%, calc((100vh - 180px) * 16 / 9));
  max-width: 100%;
  aspect-ratio: 16 / 9;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 4% 10%, rgba(31, 92, 166, 0.08), transparent 20%),
    radial-gradient(circle at 90% 85%, rgba(90, 103, 186, 0.08), transparent 24%),
    linear-gradient(180deg, #f4f4f4 0%, #e9eaec 100%);
  box-shadow: var(--surface-shadow);
}

.slide-page:fullscreen,
.slide-page:-webkit-full-screen {
  width: 100vw;
  max-width: none;
  height: 100vh;
  aspect-ratio: auto;
  margin: 0;
  border-radius: 0;
  box-shadow: none;
}

.slide-page:fullscreen .chart-layout,
.slide-page:-webkit-full-screen .chart-layout {
  padding: 18px 20px;
}

.slide-page:fullscreen .watermark,
.slide-page:-webkit-full-screen .watermark {
  font-size: clamp(88px, 12vw, 220px);
}

.watermark {
  position: absolute;
  right: 20px;
  bottom: -10px;
  font-size: clamp(40px, 7vw, 120px);
  font-weight: 900;
  line-height: 1;
  color: rgba(31, 92, 166, 0.06);
  pointer-events: none;
}

.chart-layout {
  position: relative;
  z-index: 1;
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 12px 14px;
}

.chart-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.chart-title-row h3 {
  margin: 0;
  color: #1f5ca6;
  font-size: clamp(16px, 2.4vw, 30px);
}

.chart-title-row p {
  margin: 3px 0 0;
  color: #4f6d98;
  font-size: 11px;
}

.badge {
  height: 26px;
  border-radius: 999px;
  background: #eff4fd;
  border: 1px solid #d2dff5;
  display: inline-grid;
  place-items: center;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 800;
  color: #2f5e9e;
}

.chart-stage {
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.chart-canvas {
  position: absolute;
  transform-origin: top left;
}

.structure {
  position: relative;
  width: 100%;
  height: 100%;
  isolation: isolate;
}

.top-links {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
  z-index: 1;
}

.top-link-path {
  fill: none;
  stroke: var(--line-lead);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.96;
}

.root-zone {
  display: flex;
  justify-content: center;
  position: relative;
  padding-bottom: 34px;
  z-index: 2;
}

.departments {
  position: relative;
  display: flex;
  justify-content: center;
  gap: 16px;
  align-items: flex-start;
  padding-top: 34px;
  z-index: 2;
}

.dept-column {
  position: relative;
  width: 196px;
  flex: 0 0 196px;
}

.dept-title {
  text-align: center;
  font-size: 26px;
  margin: 0 0 4px;
  color: rgba(31, 92, 166, 0.05);
  font-weight: 900;
  letter-spacing: 1px;
  line-height: 0.8;
  user-select: none;
}

.dept-label {
  font-size: 13px;
  margin: 0 0 6px;
  text-align: center;
  color: #dfa886;
  font-weight: 900;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lead-wrap {
  position: relative;
  padding-bottom: 16px;
}

.lead-wrap::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 2px;
  width: 4px;
  height: 14px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: var(--line-member);
}

.members {
  position: relative;
  padding-left: 20px;
  display: grid;
  gap: 8px;
}

.members::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 0;
  bottom: 24px;
  width: 4px;
  border-radius: 999px;
  background: var(--line-member);
}

.member-item {
  position: relative;
}

.member-item::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 50%;
  width: 10px;
  height: 4px;
  border-radius: 999px;
  transform: translateY(-50%);
  background: var(--line-member);
}

.org-node {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 72px;
  padding-left: 50px;
  cursor: pointer;
}

.node-avatar {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 68px;
  height: 68px;
  border-radius: 50%;
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 4px;
  background: #fff;
  z-index: 3;
}

.node-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
}

.node-card {
  position: relative;
  min-width: 140px;
  max-width: 164px;
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 8px 12px 8px 28px;
}

.node-ribbon {
  display: inline-flex;
  align-items: center;
  height: 24px;
  margin: -3px 0 2px;
  padding: 0 10px;
  font-size: 16px;
  font-weight: 800;
  color: #fff;
  border-radius: 7px 8px 8px 7px;
  line-height: 1;
  max-width: 104px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
}

.node-ribbon::after {
  content: "";
  position: absolute;
  top: 0;
  right: -8px;
  width: 0;
  height: 0;
  border-left: 8px solid currentColor;
  border-top: 12px solid transparent;
  border-bottom: 12px solid transparent;
  filter: brightness(0.86);
}

.node-role {
  margin-top: 3px;
  font-size: 11px;
  line-height: 1.25;
  font-weight: 700;
  min-height: 28px;
  color: #1f2733;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.node-icon {
  position: absolute;
  right: -8px;
  top: 8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  box-shadow: 0 3px 8px rgba(16, 24, 40, 0.22);
  font-weight: 800;
  z-index: 4;
}

.node-icon.default {
  background: var(--member-ribbon);
}

.node-icon.party {
  background: var(--party-red);
  color: var(--party-gold);
  border: 1.5px solid var(--party-gold);
  font-size: 12px;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}

.node-lead .node-avatar {
  border: 4px solid var(--lead-ring);
}

.node-member .node-avatar {
  border: 4px solid var(--member-ring);
}

.node-lead .node-ribbon {
  background: var(--lead-ribbon);
}

.node-lead .node-ribbon::after {
  color: var(--lead-ribbon);
}

.node-member .node-ribbon {
  background: var(--member-ribbon);
}

.node-member .node-ribbon::after {
  color: var(--member-ribbon);
}

.org-node.preview-selected .node-card {
  box-shadow: 0 0 0 2px #1f5ca6, var(--shadow);
}

.org-node.preview-selected .node-avatar {
  box-shadow: 0 0 0 2px #1f5ca6, var(--shadow);
}

.empty-tip {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: #5e6e87;
  font-size: 14px;
}

@media (max-width: 1320px) {
  .workspace {
    grid-template-columns: 420px 1fr;
  }

  .batch-parent {
    grid-template-columns: 1fr auto;
  }
}

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .editor-panel {
    grid-template-rows: auto minmax(220px, 240px) auto auto minmax(320px, 1fr) auto;
  }

  .node-list {
    max-height: none;
  }

  .batch-actions {
    grid-template-columns: 1fr;
  }

  .batch-parent {
    grid-template-columns: 1fr;
  }

  .check-row {
    grid-template-columns: 1fr;
  }
}
