/* 页面基础重置 */
body, div, p, h1, h2, h3, label, input, output, select, span, section, main, aside, textarea, button {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body,
#app {
    height: 100%;
    overflow: hidden;
}

body {
    background: #f3f4f6;
    font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    color: #1f2937;
}

/* 节点外观：由 CSS 变量驱动，供 toolbar 实时调节 */
:root {
    --node-text-color: #000000;
    --node-border-color: #000000;
    --canvas-bg: #ffffff;
    --node-font-size: 14px;
    --node-radius: 3px;
    --node-font-weight: 400;
    --node-line-height: 1.15;
}

.app {
    --demo-toolbar-h: 52px;
    --demo-rail-w: 40px;
    --side-width: 360px;
    /* 简单编辑选中 / JSON 选中统一蓝色 */
    --demo-select-bg: #2563eb;
    --demo-select-border: #1d4ed8;
    --demo-select-fg: #ffffff;
    --demo-select-muted-bg: #eff6ff;
    --demo-select-muted-border: #93c5fd;
    position: relative;
    display: flex;
    height: 100%;
    align-items: stretch;
    overflow: hidden;
}

.app-main {
    flex: 1;
    position: relative;
    z-index: 1;
    min-width: 0;
    min-height: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #fff;
    overflow: hidden;
}

.main-toolbar {
    position: relative;
    z-index: 2;
    flex-shrink: 0;
    height: var(--demo-toolbar-h);
    box-sizing: border-box;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    column-gap: 16px;
    padding: 0 16px;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
}

.main-toolbar-start {
    justify-self: start;
    min-width: 0;
    display: flex;
    align-items: center;
}

.main-toolbar-mid {
    justify-self: center;
    display: flex;
    align-items: center;
    gap: 8px;
}

.main-toolbar-end {
    justify-self: end;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.main-toolbar-tip {
    display: inline-block;
    max-width: min(420px, 100%);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.35;
    color: #b45309;
    background: #fffbeb;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: text;
    outline: none;
}

.main-toolbar-tip.is-editing {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    background: #fffbeb;
    box-shadow: inset 0 0 0 1px #f59e0b;
}

.main-toolbar-label {
    font-size: 12px;
    color: #6b7280;
    margin-right: 4px;
}

.main-toolbar-sep {
    width: 1px;
    height: 20px;
    background: #d1d5db;
    margin: 0 4px;
}

.zoom-cluster {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    background: #fff;
}

.zoom-cluster .zoom-btn {
    height: 28px;
    min-width: 28px;
    padding: 0 8px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #111827;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;
}

.zoom-cluster .zoom-btn:hover {
    background: #f3f4f6;
}

.zoom-cluster .zoom-btn.is-reset {
    padding: 0 10px;
    font-size: 12px;
    font-weight: 600;
    color: #374151;
}

.zoom-cluster .zoom-value {
    min-width: 44px;
    padding: 0 4px;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: #111827;
    font-variant-numeric: tabular-nums;
}

.zoom-btn {
    height: 30px;
    min-width: 30px;
    padding: 0 8px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    color: #111827;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;
}

.zoom-btn:hover {
    background: #f3f4f6;
}

.zoom-btn.is-primary {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
}

.zoom-btn.is-primary:hover {
    background: #1d4ed8;
}

.zoom-value {
    min-width: 48px;
    text-align: center;
    font-size: 12px;
    color: #374151;
    font-variant-numeric: tabular-nums;
}

.main-viewport {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    position: relative;
    /* 纯色背景，避免手动截图带上网格 */
    background: var(--canvas-bg);
    cursor: grab;
    user-select: none;
}

.main-viewport.is-panning {
    cursor: grabbing;
}

/* 画布舞台：平移 + 缩放 */
.canvas-stage {
    position: absolute;
    left: 0;
    top: 0;
    transform-origin: 0 0;
}

/* 尚未完成居中计算时隐藏，避免从左上角闪到中央 */
.canvas-stage.is-pending {
    visibility: hidden;
}

/* 四周间距虚线预览（仅画布展示，导出不截入） */
.padding-guide {
    position: absolute;
    z-index: 8;
    pointer-events: none;
    box-sizing: border-box;
}

.padding-guide-frame {
    position: absolute;
    inset: 0;
    border: 2px dashed #2563eb;
    box-sizing: border-box;
    background: rgba(37, 99, 235, 0.04);
}

.padding-guide-label {
    position: absolute;
    padding: 2px 6px;
    border-radius: 3px;
    background: #2563eb;
    color: #fff;
    font-size: 11px;
    line-height: 1.3;
    white-space: nowrap;
    font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.padding-guide-label.is-top {
    left: 50%;
    top: 4px;
    transform: translateX(-50%);
}

.padding-guide-label.is-bottom {
    left: 50%;
    bottom: 4px;
    transform: translateX(-50%);
}

.padding-guide-label.is-left {
    left: 4px;
    top: 50%;
    transform: translateY(-50%);
    writing-mode: vertical-rl;
    text-orientation: mixed;
    letter-spacing: 0.08em;
}

.padding-guide-label.is-right {
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    writing-mode: vertical-rl;
    text-orientation: mixed;
    letter-spacing: 0.08em;
}

.padding-guide-tip {
    position: absolute;
    left: 50%;
    top: -26px;
    transform: translateX(-50%);
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(17, 24, 39, 0.88);
    color: #e5e7eb;
    font-size: 11px;
    white-space: nowrap;
    font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.chart {
    min-height: 200px;
    overflow: visible !important;
    background: var(--canvas-bg);
    /* 尽量保持文字锐利（配合 CSS zoom 缩放） */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: geometricPrecision;
}

.chart .node,
.chart .node-name {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: geometricPrecision;
}

.Treant {
    overflow: visible !important;
}

.node-name {
    margin: 0;
    color: var(--node-text-color);
    font-size: var(--node-font-size);
    font-weight: var(--node-font-weight);
    line-height: var(--node-line-height);
}

/* 纯文字节点：仅姓名，带边框（默认水平） */
.nodeExample1 {
    padding: 4px 8px;
    border: 1px solid var(--node-border-color);
    border-radius: var(--node-radius);
    background-color: #fff;
    font-family: Tahoma, "Microsoft YaHei", sans-serif;
    font-size: var(--node-font-size);
    color: var(--node-text-color);
    white-space: nowrap;
}

.nodeExample1.is-editable {
    cursor: text;
}

/* 画布双击就地改字（fixed，不受画布缩放坐标系影响） */
.node-inline-editor {
    position: fixed;
    z-index: 10000;
    box-sizing: border-box;
    margin: 0;
    padding: 5px 10px;
    border: 1.5px solid var(--demo-select-bg, #2563eb);
    border-radius: 6px;
    background: var(--demo-select-muted-bg, #eff6ff);
    font-family: Tahoma, "Microsoft YaHei", sans-serif;
    line-height: 1.3;
    box-shadow:
        0 0 0 3px rgba(37, 99, 235, 0.22),
        0 8px 20px rgba(15, 23, 42, 0.12);
    outline: none;
    caret-color: var(--demo-select-border, #1d4ed8);
}

.node-inline-editor:focus {
    border-color: var(--demo-select-border, #1d4ed8);
    background: #fff;
    box-shadow:
        0 0 0 3px rgba(37, 99, 235, 0.28),
        0 8px 20px rgba(15, 23, 42, 0.14);
}

/* 文字垂直布局：单列竖排，禁止换行；顶对齐 */
.nodeExample1.node-text-vertical {
    padding: 8px 4px;
    white-space: nowrap;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.nodeExample1.node-text-vertical .node-name {
    writing-mode: vertical-rl;
    text-orientation: upright;
    /* 竖排用 letter-spacing 控制字距；行高只影响列宽，避免与横排行高混用导致测高偏小 */
    line-height: 1.15;
    letter-spacing: calc((var(--node-line-height) - 1) * 1em);
    white-space: nowrap;
    word-break: keep-all;
}

/* ========== 左右侧栏：40px 槽位 + 悬浮抽屉 ========== */
.toolbar-slot {
    position: relative;
    z-index: 20;
    flex: 0 0 var(--demo-rail-w);
    width: var(--demo-rail-w);
    align-self: stretch;
}

.toolbar {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
    background: #111827;
    color: #e5e7eb;
    padding: 10px 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: none;
    transition: width 0.2s ease, padding 0.2s ease, box-shadow 0.2s ease;
}

.toolbar-slot-left .toolbar {
    left: 0;
    border-right: 1px solid #374151;
}

.toolbar-slot-right .toolbar {
    right: 0;
    border-left: 1px solid #374151;
}

.toolbar.is-collapsed {
    width: 100%;
    padding: 10px 0;
    overflow: hidden;
    align-items: center;
    box-shadow: none;
}

.toolbar.is-drawer {
    width: var(--side-width);
    padding: 16px 14px 0;
    align-items: stretch;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.28);
    z-index: 40;
}

.toolbar.is-collapsed .toolbar-body {
    display: none;
}

.toolbar.is-collapsed .toolbar-header-title {
    display: none;
}

.toolbar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.toolbar.is-collapsed .toolbar-header {
    margin-bottom: 0;
    flex-direction: column;
    justify-content: flex-start;
    height: 100%;
}

.toolbar-header-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.toolbar-toggle {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border: 1px solid #4b5563;
    border-radius: 6px;
    background: #1f2937;
    color: #e5e7eb;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
}

.toolbar-toggle:hover {
    background: #374151;
}

.toolbar.is-collapsed .toolbar-toggle {
    writing-mode: horizontal-tb;
}

.toolbar-collapsed-label {
    display: none;
    margin-top: 12px;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: 13px;
    letter-spacing: 0.2em;
    color: #9ca3af;
    cursor: pointer;
    user-select: none;
}

.toolbar.is-collapsed .toolbar-collapsed-label {
    display: block;
}

.toolbar-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* 可滚动内容区：底部按钮固定在面板下方 */
.toolbar-scroll {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding-right: 2px;
    display: flex;
    flex-direction: column;
}

.toolbar-footer {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 0 16px;
    margin-top: 4px;
    border-top: 1px solid #374151;
    background: #111827;
}

.toolbar-footer .data-status {
    margin: 0;
    min-height: 20px;
}

.toolbar-footer-row {
    display: flex;
    gap: 8px;
}

.toolbar-footer-row .toolbar-btn {
    flex: 1;
    width: auto;
}

.toolbar-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 16px;
    letter-spacing: 0.02em;
}

.toolbar-section {
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid #374151;
}

.toolbar-section:last-child {
    border-bottom: none;
}

.toolbar-section-title {
    font-size: 12px;
    font-weight: 600;
    color: #9ca3af;
    margin-bottom: 10px;
}

.toolbar-hint {
    font-size: 11px;
    color: #9ca3af;
    line-height: 1.5;
    margin-bottom: 10px;
}

.toolbar-row {
    display: grid;
    grid-template-columns: 72px 1fr auto;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 12px;
}

.toolbar-row span:first-child {
    color: #d1d5db;
}

.toolbar-row input[type="range"] {
    width: 100%;
    accent-color: #2563eb;
}

.toolbar-row input[type="color"] {
    width: 36px;
    height: 24px;
    padding: 0;
    border: 1px solid #4b5563;
    background: transparent;
    cursor: pointer;
    grid-column: 2 / 4;
    justify-self: start;
}

.toolbar-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    justify-self: start;
    grid-column: 2 / 4;
}

.toolbar-row output {
    min-width: 36px;
    text-align: right;
    color: #9ca3af;
    font-variant-numeric: tabular-nums;
}

.toolbar-row select {
    grid-column: 2 / 4;
    height: 28px;
    border: 1px solid #4b5563;
    border-radius: 4px;
    background: #1f2937;
    color: #e5e7eb;
    padding: 0 8px;
    font-size: 12px;
}

/* 左侧数据编辑 */
.editor-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.editor-tab {
    flex: 1;
    height: 32px;
    border: 1px solid #4b5563;
    border-radius: 6px;
    background: #1f2937;
    color: #9ca3af;
    font-size: 12px;
    cursor: pointer;
}

.editor-tab.is-active {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
    font-weight: 600;
}

.editor-pane {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: 10px;
}

.simple-editor {
    flex: 1;
    min-height: 220px;
    overflow: auto;
    border: 1px solid #374151;
    border-radius: 6px;
    background: #0b1220;
    padding: 8px 6px;
}

.simple-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
    border-left: 3px solid transparent;
    border-radius: 4px;
    padding-top: 2px;
    padding-bottom: 2px;
    padding-right: 4px;
    background: rgba(255, 255, 255, 0.02);
    transition: background 0.2s ease, box-shadow 0.2s ease;
}

.simple-row.is-selected {
    background: var(--demo-select-bg);
    box-shadow: inset 0 0 0 1px var(--demo-select-border);
}

.simple-row.is-selected .simple-badge {
    background: #1e40af;
    color: #dbeafe;
}

.simple-row.is-selected .simple-name-input {
    background: var(--demo-select-muted-bg);
    border-color: var(--demo-select-muted-border);
    color: #111827;
}

/* 各级颜色区分（超过 6 级循环） */
.simple-level-1 {
    border-left-color: #3b82f6;
}
.simple-level-1 .simple-badge {
    background: #1e3a8a;
    color: #93c5fd;
}

.simple-level-2 {
    border-left-color: #10b981;
}
.simple-level-2 .simple-badge {
    background: #064e3b;
    color: #6ee7b7;
}

.simple-level-3 {
    border-left-color: #f59e0b;
}
.simple-level-3 .simple-badge {
    background: #78350f;
    color: #fcd34d;
}

.simple-level-4 {
    border-left-color: #a855f7;
}
.simple-level-4 .simple-badge {
    background: #581c87;
    color: #e9d5ff;
}

.simple-level-5 {
    border-left-color: #ef4444;
}
.simple-level-5 .simple-badge {
    background: #7f1d1d;
    color: #fecaca;
}

.simple-level-6 {
    border-left-color: #06b6d4;
}
.simple-level-6 .simple-badge {
    background: #164e63;
    color: #a5f3fc;
}

.simple-toggle {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 1px solid #4b5563;
    border-radius: 4px;
    background: #1f2937;
    color: #e5e7eb;
    font-size: 10px;
    line-height: 1;
    cursor: pointer;
}

.simple-toggle:hover:not(:disabled) {
    background: #374151;
}

.simple-toggle.is-empty {
    opacity: 0.35;
    cursor: default;
    border-color: transparent;
    background: transparent;
}

.simple-badge {
    flex-shrink: 0;
    min-width: 32px;
    text-align: center;
    font-size: 11px;
    border-radius: 4px;
    padding: 2px 4px;
}

.simple-name-input {
    flex: 1;
    min-width: 0;
    height: 28px;
    border: 1px solid #4b5563;
    border-radius: 4px;
    background: #111827;
    color: #e5e7eb;
    padding: 0 8px;
    font-size: 12px;
}

.simple-name-input:focus {
    outline: none;
    border-color: #60a5fa;
}

.simple-actions {
    display: flex;
    flex-shrink: 0;
    gap: 4px;
}

.simple-btn {
    height: 26px;
    padding: 0 6px;
    border: 1px solid #4b5563;
    border-radius: 4px;
    background: #1f2937;
    color: #e5e7eb;
    font-size: 11px;
    cursor: pointer;
    white-space: nowrap;
}

.simple-btn:hover:not(:disabled) {
    background: #374151;
}

.simple-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.simple-btn-danger {
    color: #fca5a5;
    border-color: #7f1d1d;
}

.data-editor-shell {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 200px;
    border: 1px solid #374151;
    border-radius: 6px;
    background: #0b1220;
    overflow: hidden;
}

.data-editor-line-hl {
    position: absolute;
    z-index: 0;
    display: none;
    pointer-events: none;
    border-radius: 2px;
    background: var(--demo-select-bg, #2563eb);
    box-shadow: inset 0 0 0 1px var(--demo-select-border, #1d4ed8);
}

.data-editor {
    position: relative;
    z-index: 1;
    flex: 1;
    width: 100%;
    min-height: 200px;
    resize: vertical;
    background: transparent;
    color: #e5e7eb;
    border: none;
    border-radius: 6px;
    padding: 10px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.45;
    white-space: pre;
    tab-size: 2;
    outline: none;
}

.data-editor.is-invalid {
    box-shadow: inset 0 0 0 1px #f87171;
}

/* 原生选区仍保持主题蓝（无画布编辑时可用） */
.data-editor::selection {
    background: var(--demo-select-bg);
    color: var(--demo-select-fg);
}

.data-editor::-moz-selection {
    background: var(--demo-select-bg);
    color: var(--demo-select-fg);
}

.data-status {
    min-height: 36px;
    margin: 10px 0;
    font-size: 12px;
    line-height: 1.45;
    color: #9ca3af;
}

.data-status.is-ok {
    color: #34d399;
}

.data-status.is-error {
    color: #f87171;
}

.toolbar-btn {
    width: 100%;
    height: 36px;
    border: none;
    border-radius: 6px;
    background: #2563eb;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.toolbar-btn:hover {
    background: #1d4ed8;
}

.toolbar-btn:active {
    background: #1e40af;
}

.toolbar-btn-reset {
    background: #374151;
}

.toolbar-btn-reset:hover {
    background: #4b5563;
}

.toolbar-btn-reset:active {
    background: #6b7280;
}

.toolbar-btn-danger {
    background: #7f1d1d;
}

.toolbar-btn-danger:hover {
    background: #991b1b;
}

.toolbar-btn-danger:active {
    background: #b91c1c;
}
