/* ============================================================
 * 思维导图专用样式
 * 依赖 common.css 提供 CSS 变量、导航栏与 toast
 * 说明：common.css 的按钮为胶囊大按钮，此处覆盖为紧凑工具栏样式
 * ============================================================ */

html,
body {
    height: 100%;
}

body {
    overflow: hidden;
}

/* ---------- 页面骨架 ---------- */
.app {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: #fff;
}

/* ---------- 工具栏 ---------- */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.8rem;
    border-bottom: 1px solid #e1e4e8;
    background: #fff;
    flex-shrink: 0;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.toolbar-group.right {
    margin-left: auto;
}

.toolbar button {
    padding: 0.35rem 0.9rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    background: #f6f8fa;
    color: var(--text-color);
    border: 1px solid #e1e4e8;
    transition: all 0.15s ease;
}

.toolbar button:hover {
    transform: none;
    box-shadow: none;
    background: #eef1f4;
    border-color: #d0d7de;
}

.toolbar button:active {
    background: #e6ebef;
}

.toolbar button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    background: #f6f8fa;
    border-color: #e1e4e8;
}

.toolbar button.icon-btn {
    padding: 0.35rem 0.6rem;
    min-width: 30px;
    font-weight: 600;
}

.zoom-label {
    font-size: 0.78rem;
    color: var(--light-text);
    min-width: 48px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* ---------- 当前文件信息 ---------- */
.file-info {
    display: inline-block;
    max-width: 260px;
    padding: 0.2rem 0.6rem;
    font-size: 0.76rem;
    color: var(--light-text);
    background: #f6f8fa;
    border: 1px solid #e1e4e8;
    border-radius: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: default;
}

/* ---------- 画布 ---------- */
.canvas-wrap {
    flex: 1;
    position: relative;
    min-height: 0;
    overflow: hidden;
    background-color: #fafbfc;
    background-image: radial-gradient(#e3e7ec 1px, transparent 1px);
    background-size: 22px 22px;
    cursor: grab;
}

#canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

/* ---------- 节点 ---------- */
.node {
    cursor: pointer;
}

.node rect {
    fill: #fff;
    stroke: #e1e4e8;
    stroke-width: 1px;
}

.node.depth-0 rect {
    fill: #667eea;
    stroke: none;
}

.node.depth-1 rect {
    fill: #eef2ff;
    stroke: #c7d2fe;
}

.node.depth-0 .node-label {
    fill: #fff;
    font-weight: 600;
}

.node.depth-1 .node-label {
    fill: #3730a3;
}

.node.depth-2 .node-label {
    fill: #333;
}

.node.selected rect {
    stroke: var(--accent-color);
    stroke-width: 2px;
}

/* 就地编辑时隐藏原 SVG 文字，避免与编辑框重影 */
.node.editing .node-label {
    visibility: hidden;
}

.node.dragging {
    opacity: 0.45;
}

.node.drop-target rect {
    stroke: var(--success-color);
    stroke-width: 2px;
}

.node-label {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 14px;
    pointer-events: none;
}

/* ---------- 折叠圆点 ---------- */
.node-toggle {
    cursor: pointer;
}

.node-toggle circle {
    fill: #fff;
    stroke: #c7d2fe;
    stroke-width: 1.5px;
}

.node-toggle text {
    fill: var(--primary-color);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 9px;
    text-anchor: middle;
    pointer-events: none;
}

.node-toggle:hover circle {
    stroke: var(--primary-color);
}

.node-toggle.collapsed circle {
    fill: var(--primary-color);
    stroke: var(--primary-color);
}

.node-toggle.collapsed text {
    fill: #fff;
}

/* ---------- 连线 ---------- */
.edge {
    fill: none;
    stroke: #c7d2fe;
    stroke-width: 1.5px;
    pointer-events: none;
}

/* 拖动排序时的兄弟插入提示线 */
.drop-line {
    stroke: var(--accent-color);
    stroke-width: 2px;
    stroke-dasharray: 6 4;
    pointer-events: none;
}

/* ---------- 就地编辑框 ---------- */
.node-editor {
    position: fixed;
    display: none;
    z-index: 50;
    margin: 0;
    border: none;
    border-radius: 8px;
    background: #fff;
    color: var(--text-color);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 14px;
    line-height: 20px;
    box-sizing: border-box;
    resize: none;
    outline: none;
    overflow: hidden;
    text-align: center;
    white-space: pre;
    overflow-wrap: normal;
}

/* ---------- 右键菜单 ---------- */
.node-menu {
    position: fixed;
    z-index: 60;
    min-width: 168px;
    padding: 0.3rem;
    background: #fff;
    border: 1px solid #e1e4e8;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.node-menu[hidden] {
    display: none;
}

.node-menu button {
    padding: 0.35rem 0.6rem;
    background: transparent;
    color: var(--text-color);
    border: none;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    text-align: left;
    transition: background 0.12s ease;
}

.node-menu button:hover:not(:disabled) {
    background: #eef1f4;
    transform: none;
    box-shadow: none;
}

.node-menu button:active:not(:disabled) {
    background: #e6ebef;
    transform: none;
}

.node-menu button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.node-menu button.danger:not(:disabled) {
    color: var(--danger-color);
}

.node-menu button.danger:hover:not(:disabled) {
    background: #fdecea;
}

.menu-sep {
    height: 1px;
    margin: 0.2rem 0.2rem;
    background: #eef1f4;
}

.menu-label {
    padding: 0.15rem 0.6rem;
    font-size: 0.72rem;
    color: #8b94a3;
}

.menu-colors {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.3rem;
    padding: 0 0.5rem 0.2rem;
}

.menu-colors .color-swatch {
    width: 22px;
    height: 22px;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.12s ease;
}

.menu-colors .color-swatch:hover {
    transform: scale(1.12);
    box-shadow: none;
}

/* 提高特异性，避免被 .node-menu button:hover 的通用背景/位移覆盖 */
.node-menu .menu-colors .color-swatch:hover {
    transform: scale(1.12);
    box-shadow: none;
}

.node-menu .menu-colors .default-swatch:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.menu-colors .color-swatch.active {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(255, 107, 53, 0.25);
    transform: none;
}

.menu-colors .default-swatch {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: #cbd5e1;
    position: relative;
}

.menu-colors .default-swatch::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 8px;
    height: 2px;
    background: #fff;
    border-radius: 1px;
    transform: translate(-50%, -50%) rotate(45deg);
}

/* ---------- 操作提示 ---------- */
.hint {
    position: absolute;
    right: 12px;
    bottom: 10px;
    padding: 0.25rem 0.6rem;
    font-size: 0.76rem;
    color: #8b94a3;
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid #e1e4e8;
    border-radius: 6px;
    pointer-events: none;
}

/* ---------- 响应式 ---------- */
@media (max-width: 768px) {
    .toolbar {
        gap: 0.5rem;
        padding: 0.4rem 0.6rem;
    }

    .toolbar button {
        padding: 0.3rem 0.55rem;
        font-size: 0.75rem;
    }

    .hint {
        display: none;
    }
}
