/**
 * Navi Mindmap — 思维导图样式
 *
 * 水平树形布局（左→右展开），CSS 连接线，响应式。
 * 无外部依赖，与 Zibll 共存。
 */

/* ── 页面容器 ────────────────────────────── */
.navi-mindmap-page {
    position: relative;
    max-width: 100%;
    overflow: hidden;
}

/* ── 顶部工具栏 ──────────────────────────── */
.navi-toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    flex-wrap: wrap;
}
.navi-title {
    font-size: 1.2em;
    margin: 0;
    color: #1a1a2e;
    white-space: nowrap;
    display: flex;
    align-items: center;
    line-height: 1;
    gap: 0.35em;
}
.navi-title .nv-logo {
    height: 1em;
    width: auto;
    flex-shrink: 0;
    display: block;
    transform: translateY(-2px);
}
.navi-actions {
    display: flex;
    gap: 4px;
    margin-left: auto;
}
.navi-actions button {
    width: 32px;
    height: 32px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
}
.navi-actions button:hover {
    background: #e8e8e8;
}
.navi-legend {
    display: flex;
    gap: 16px;
    font-size: 0.82em;
    color: #888;
    flex-wrap: wrap;
}
.navi-mouse-hint {
    font-size: 0.82em;
    color: #666;
    padding: 4px 10px;
    background: rgba(0,0,0,.04);
    border-radius: 4px;
    white-space: nowrap;
}
.navi-mouse-hint strong {
    color: #333;
}
.navi-legend .dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}

/* ── 操作说明 ────────────────────────────── */
.navi-help {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 10;
}
.help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(0,0,0,.06);
    color: #666;
    font-size: 13px;
    font-weight: 700;
    cursor: help;
    transition: background .15s;
}
.help-icon:hover {
    background: rgba(0,0,0,.12);
}
.navi-help-tip {
    display: none;
    position: absolute;
    right: 0;
    top: 30px;
    width: 240px;
    padding: 12px 16px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,.1);
    font-size: 0.82em;
    line-height: 1.8;
    color: #555;
    white-space: normal;
}
.navi-help:hover .navi-help-tip {
    display: block;
}

/* ── 导图画布 ────────────────────────────── */
.navi-canvas {
    position: relative;
    width: 100%;
    min-height: 1800px;
    overflow: hidden;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    background:
        radial-gradient(circle, #e8ebf0 1px, transparent 1px);
    background-size: 30px 30px;
}
.navi-canvas:active {
    cursor: grabbing;
}
.navi-canvas.dragging .navi-tree .node {
    pointer-events: none;
}
.navi-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.1em;
    color: #999;
}

/* ── 画布内层（用于 transform 变换） ─────── */
.navi-canvas-inner {
    position: absolute;
    top: 40px;
    left: 40px;
    transform-origin: 0 0;
    transition: transform 0.05s linear;
    white-space: nowrap;
}

/* ═══════════════════════════════════════════
   树形布局核心 CSS
   ═══════════════════════════════════════════ */

/* 根 ul — L1 层，纵向排列 */
.navi-tree {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* 每个 li 是一个节点容器 */
.navi-tree li {
    position: relative;
    list-style: none;
    margin: 0;
    padding: 0;
}

/* ── 节点卡片 ────────────────────────────── */
.navi-tree .node {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 7px;
    border: 1px solid #dde;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
    line-height: 1.5;
    white-space: nowrap;
    transition: background .15s, box-shadow .15s, transform .1s;
    min-width: 140px;
    margin: 2px 0;
}
.navi-tree .node:hover {
    background: #e8f0fe;
    box-shadow: 0 2px 8px rgba(0,0,0,.10);
    transform: translateY(-1px);
}
.navi-tree .node.root-node {
    background: #ebf2fa;
    border-color: #84a9d6;
    font-weight: 700;
    font-size: 13px;
    min-width: 180px;
}

/* ── 行业大类调色板（6 色循环） ── */
.navi-tree .node[data-color-idx="0"] { background: #e8f0fe; border-color: #9cb4d8; }
.navi-tree .node[data-color-idx="0"]:hover { background: #d2e3fc; }
.navi-tree .node[data-color-idx="1"] { background: #e6f4ea; border-color: #97c4a0; }
.navi-tree .node[data-color-idx="1"]:hover { background: #ceead6; }
.navi-tree .node[data-color-idx="2"] { background: #fef7e0; border-color: #ebd77a; }
.navi-tree .node[data-color-idx="2"]:hover { background: #fdf0c2; }
.navi-tree .node[data-color-idx="3"] { background: #fce8ee; border-color: #e895a9; }
.navi-tree .node[data-color-idx="3"]:hover { background: #f9d2de; }
.navi-tree .node[data-color-idx="4"] { background: #f3e8f6; border-color: #c49bd0; }
.navi-tree .node[data-color-idx="4"]:hover { background: #e9d2ef; }
.navi-tree .node[data-color-idx="5"] { background: #fef0db; border-color: #ecb45a; }
.navi-tree .node[data-color-idx="5"]:hover { background: #fce4ba; }

.navi-tree .node.leaf-node {
    opacity: 0.7;
}
/* 含"本行业"节点加粗 */
.navi-tree .node.is-benhangye {
    font-weight: 700;
}

/* ── 展开/折叠按钮 ───────────────────────── */
.navi-tree .toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1.5px solid #bbb;
    background: #f8f9fa;
    cursor: pointer;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    flex-shrink: 0;
    transition: all .15s;
    color: #666;
}
.navi-tree .toggle:hover {
    background: #d0d4e0;
    border-color: #999;
    color: #222;
}
.navi-tree .toggle::after {
    content: '+';
    font-weight: 700;
    font-size: 13px;
    line-height: 1;
}
.navi-tree .toggle.expand::after {
    content: '−';
}
.navi-tree .toggle.loading {
    animation: navi-spin 0.6s linear infinite;
    border-color: #2563eb;
}
.navi-tree .toggle.loading::after {
    content: '↻';
}
.navi-tree .toggle.no-children {
    visibility: hidden;
}
@keyframes navi-spin {
    to { transform: rotate(360deg); }
}

/* ── 节点名称 ────────────────────────────── */
.navi-tree .name {
    white-space: nowrap;
}

/* ── 文章计数标识 ─────────────────────────── */
.navi-tree .count {
    font-size: 0.78em;
    color: #999;
    flex-shrink: 0;
}

/* ── 文章列表链接按钮 ──────────────────────── */
.navi-tree .navi-link-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 4px;
    font-size: 13px;
    line-height: 1;
    color: #6e8bb8;
    text-decoration: none;
    flex-shrink: 0;
    opacity: 0.4;
    transition: opacity .15s, background .15s, color .15s;
}
.navi-tree .node:hover .navi-link-btn {
    opacity: 1;
    color: #2563eb;
}
.navi-tree .navi-link-btn:hover {
    background: rgba(37,99,235,.1);
    color: #1d4ed8;
}

/* ── 子节点列表（L2+） ─────────────────────── */
.navi-tree .children {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* ── 连接线：使用 ::before 伪元素 ───────── */
/* 水平线：每个子节点的 li 前置 */
.navi-tree .children li::before {
    content: '';
    position: absolute;
    border-top: 1.5px solid #c8c8c8;
}

/* ── 树布局展开方向 ───────────────────────── */
/* 水平展开：node 和 children 并排 */
.navi-tree.tree-horizontal > li {
    display: flex;
    align-items: center;
    gap: 0;
}
.navi-tree.tree-horizontal > li > .node {
    flex-shrink: 0;
    margin-right: 28px; /* 水平间距 */
    position: relative;
}
.navi-tree.tree-horizontal > li > .children {
    flex-shrink: 0;
    position: relative;
}

/* ── 连接线：仅在节点展开时显示 ─────────── */
.navi-tree > li:not(.is-expanded) > .node::after,
.navi-tree > li:not(.is-expanded) > .children::before,
.navi-tree .children > li:not(.is-expanded) > .node::after,
.navi-tree .children > li:not(.is-expanded) > .children::before {
    display: none;
}

/* 父节点到子节点的水平连接线 + 交汇圆点 */
.navi-tree.tree-horizontal > li > .node::after {
    content: '';
    position: absolute;
    right: -28px;
    top: 50%;
    width: 28px;
    border-top: 1.5px solid #ccc;
    /* 交汇点小圆 */
    background:
        radial-gradient(circle at 28px 0, #ccc 3px, transparent 3px);
    background-repeat: no-repeat;
    background-position: right center;
}

/* 子区域顶部的垂直连接线 */
.navi-tree.tree-horizontal > li > .children::before {
    content: '';
    position: absolute;
    left: -28px;
    top: 0;
    bottom: 0;
    border-left: 1.5px solid #ccc;
}

/* L2+ 内部子节点同理 */
.navi-tree.tree-horizontal .children .children {
    /* 嵌套子级也用水平布局 */
}
.navi-tree.tree-horizontal .children > li {
    display: flex;
    align-items: center;
    position: relative;
}
.navi-tree.tree-horizontal .children > li > .children {
    margin-left: 28px;
    position: relative;
}
/* 每个子节点右端的 28px 小横线原本是连接到自身孙子节点用的，
   但折叠时会形成"悬空"短线视觉冗余。统一隐藏，由左侧 ± 按钮表明可展开。 */
.navi-tree.tree-horizontal .children > li > .node::after {
    display: none;
}
.navi-tree.tree-horizontal .children > li > .children::before {
    content: '';
    position: absolute;
    left: -28px;
    top: 0;
    bottom: 0;
    border-left: 1.5px solid #ccc;
}

/* ── 侧边栏 ───────────────────────────────── */
.navi-sidebar {
    position: fixed;
    right: 0;
    top: 0;
    width: 380px;
    max-width: 90vw;
    height: 100vh;
    background: #fff;
    border-left: 1px solid #e0e0e0;
    box-shadow: -4px 0 20px rgba(0,0,0,.08);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease;
}
.navi-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e0e0e0;
}
.navi-sidebar-header h3 {
    margin: 0;
    font-size: 1.05em;
}
.navi-sidebar-header button {
    background: none;
    border: none;
    font-size: 1.2em;
    cursor: pointer;
    color: #666;
}
.navi-sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

/* ── 响应式 ────────────────────────────────── */
@media (max-width: 768px) {
    .navi-toolbar {
        gap: 8px;
        padding: 8px 12px;
    }
    .navi-legend,
    .navi-mouse-hint {
        display: none;
    }
    .navi-title {
        font-size: 1em;
    }
    .navi-sidebar {
        width: 100vw;
    }
    .navi-tree .node {
        min-width: 90px;
        font-size: 12px;
        padding: 5px 8px;
    }
    .navi-tree .toggle {
        width: 24px;
        height: 24px;
        font-size: 14px;
    }
    .navi-actions button {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }
    .navi-tree .navi-link-btn {
        width: 28px;
        height: 28px;
        opacity: 0.8;
    }
    .navi-canvas {
        min-height: 80vh;
        cursor: default;
    }
}
