/* 应用图谱 - 画布式门户样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --bg: #f1f5f9;
    --canvas-bg: #eef2f7;
    --card-bg: #ffffff;
    --text: #111827;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-drag: 0 16px 32px rgba(0,0,0,0.14), 0 4px 12px rgba(0,0,0,0.08);
    --gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --card-w: 240px;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
                 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
}

/* ============ 顶栏 ============ */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    z-index: 100;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.875rem;
}

h1 {
    font-size: 1.25rem;
    font-weight: 700;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    white-space: nowrap;
}

.status {
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding: 0.25rem 0.625rem;
    background: var(--bg);
    border-radius: 6px;
    border: 1px solid var(--border);
    white-space: nowrap;
}

.status.online {
    color: #059669;
    border-color: #a7f3d0;
    background: #ecfdf5;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

#searchInput {
    padding: 0.5rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.875rem;
    width: 180px;
    transition: all 0.2s;
}

#searchInput:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
    width: 230px;
}

.btn {
    padding: 0.5rem 0.875rem;
    background: var(--card-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8125rem;
    white-space: nowrap;
    transition: all 0.15s;
}

.btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #eef2ff;
}

.btn-warn:hover {
    border-color: #dc2626;
    color: #dc2626;
    background: #fef2f2;
}

.btn-icon {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.15s;
}

.btn-icon:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ============ 画布区 ============ */
.canvas-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(circle, #d5dce6 1px, transparent 1px) 0 0 / 24px 24px,
        var(--canvas-bg);
    cursor: grab;
    touch-action: none;
}

.canvas-wrap.panning {
    cursor: grabbing;
}

/* 连线 SVG 层（铺满可视区，坐标由 viewBox 映射，不用 CSS transform）
   —— 必须显式给宽高，否则 SVG 视口只有默认 300x150，
      超出这个范围的连线看得见但点不到（线删不掉的根因） */
#edgeLayer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
    z-index: 1;
}

#edgeLayer .edge-hit {
    pointer-events: stroke;
    cursor: pointer;
}

/* 标签背景也可点（标签文字本身不挡事件，交给背景块） */
#edgeLayer .edge-label-bg {
    pointer-events: fill;
    cursor: pointer;
}

#edgeLayer .edge-label {
    pointer-events: none;
}

.edge-group .edge-path {
    transition: stroke 0.15s, stroke-width 0.15s;
}

.edge-group:hover .edge-path {
    stroke: #4f46e5;
    stroke-width: 3.5;
}

/* 选中的连线：变红加粗，方便确认删哪条 */
.edge-group.selected .edge-path {
    stroke: #dc2626;
    stroke-width: 4;
}

.edge-group.selected .edge-label {
    fill: #b91c1c;
    font-weight: 700;
}

.edge-group.selected .edge-label-bg {
    stroke: #fca5a5;
}

/* 选中连线上的浮动操作条 */
.edge-toolbar {
    position: absolute;
    z-index: 70;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.375rem;
    background: var(--card-bg);
    border: 1px solid var(--primary);
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.16);
    font-size: 0.75rem;
    white-space: nowrap;
    transform: translate(-50%, calc(-100% - 12px));
    pointer-events: auto;
}

.edge-toolbar-title {
    color: var(--text-secondary);
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 0.25rem;
}

.edge-toolbar button {
    border: 1px solid var(--border);
    background: var(--card-bg);
    border-radius: 6px;
    padding: 0.2rem 0.4rem;
    font-size: 0.72rem;
    cursor: pointer;
    transition: all 0.15s;
}

.edge-toolbar button:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #eef2ff;
}

.edge-toolbar-del {
    color: #dc2626;
    border-color: #fecaca !important;
    font-weight: 600;
}

.edge-toolbar-del:hover {
    background: #fef2f2 !important;
    border-color: #dc2626 !important;
}

.edge-toolbar-close {
    color: var(--text-secondary);
}

/* 连线右键菜单 */
.edge-menu {
    position: fixed;
    z-index: 900;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 12px 28px rgba(0,0,0,0.18);
    padding: 0.25rem;
    display: flex;
    flex-direction: column;
    min-width: 150px;
}

.edge-menu button {
    border: none;
    background: none;
    text-align: left;
    padding: 0.45rem 0.6rem;
    font-size: 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text);
}

.edge-menu button:hover {
    background: var(--bg);
}

.edge-menu button.danger {
    color: #dc2626;
}

.edge-menu button.danger:hover {
    background: #fef2f2;
}

/* 右键卡片时的连线列表 */
.edge-menu-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text);
    padding: 0.35rem 0.6rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.2rem;
    white-space: nowrap;
}

.edge-menu .edge-menu-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 320px;
}

.edge-menu-conn {
    display: flex !important;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.1rem;
    max-width: 350px;
}

.edge-menu-route {
    font-size: 0.78rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 330px;
}

.edge-menu-del {
    font-size: 0.72rem;
    color: #dc2626;
    font-weight: 600;
}

.edge-menu-conn:hover .edge-menu-del {
    text-decoration: underline;
}

.edge-menu-empty {
    font-size: 0.75rem;
    color: var(--text-secondary);
    padding: 0.4rem 0.6rem;
    white-space: nowrap;
}

.edge-menu-sep {
    height: 1px;
    background: var(--border);
    margin: 0.25rem 0;
}

/* 底栏版本号：用来确认浏览器跑的是哪一版文件 */
.build-tag {
    display: inline-block;
    margin-top: 0.25rem;
    font-size: 0.68rem;
    color: var(--text-secondary);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.05rem 0.45rem;
}

/* 连线管理列表 */
.conn-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 0.625rem;
    line-height: 1.5;
}

.conn-list {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    max-height: 52vh;
    overflow-y: auto;
}

.conn-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.625rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.8rem;
}

.conn-row:hover {
    border-color: var(--primary);
    background: #f8faff;
}

.conn-route {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conn-route b { color: var(--primary); }

.conn-label {
    color: var(--text-secondary);
    max-width: 34%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conn-actions {
    display: flex;
    gap: 0.25rem;
    flex-shrink: 0;
}

.conn-actions .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.72rem;
}

.conn-empty {
    padding: 1.25rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* 底部“关系数”可点击 */
.link-metric {
    cursor: pointer;
    color: var(--primary);
    font-weight: 600;
    text-decoration: underline dotted;
}

.link-metric:hover { color: var(--primary-hover); }

/* 卡片层压在连线层之上 */
.cards-layer {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    z-index: 2;
}

/* ============ 应用卡片 ============ */
.app-card {
    position: absolute;
    width: var(--card-w);
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.875rem 1rem;
    box-shadow: var(--shadow);
    cursor: grab;
    user-select: none;
    transition: box-shadow 0.15s, border-color 0.15s, opacity 0.2s;
}

.app-card:active {
    cursor: grabbing;
}

.app-card.dragging {
    box-shadow: var(--shadow-drag);
    border-color: var(--primary);
    cursor: grabbing;
    z-index: 50;
}

.app-card.dimmed {
    opacity: 0.25;
}

.app-card.connecting {
    border-color: #f59e0b;
    box-shadow: 0 0 0 3px rgba(245,158,11,0.2);
}

.app-card.link-target {
    border-color: #10b981;
    box-shadow: 0 0 0 4px rgba(16,185,129,0.25);
}

.app-card-header {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    margin-bottom: 0.5rem;
}

.app-icon {
    font-size: 1.75rem;
    line-height: 1;
}

.app-name {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text);
    text-decoration: none;
    display: block;
}

a.app-name:hover {
    color: var(--primary);
    text-decoration: underline;
}

.app-category {
    font-size: 0.6875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.app-desc {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.45;
    margin-bottom: 0.5rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.app-tags {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.tag {
    font-size: 0.6875rem;
    padding: 0.0625rem 0.4375rem;
    background: #f3f4f6;
    border-radius: 4px;
    color: var(--text-secondary);
}

/* ============ 资质条（卡片底部） ============ */
.app-qual {
    margin-top: 0.375rem;
    padding: 0.3125rem 0.5rem;
    border-top: 1px dashed var(--border);
    font-size: 0.72rem;
    text-align: center;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s;
    user-select: none;
}

.app-qual:hover {
    background: #eef2ff;
}

.q-miss { color: #dc2626; font-weight: 600; }
.q-req  { color: #059669; font-weight: 600; }
.q-empty { color: var(--text-secondary); }

/* 资质条上的"✏️ 编辑"（只有管理员会渲染这段）—— 让"这里能点"一眼可见 */
.app-qual .q-edit {
    color: var(--primary);
    font-weight: 600;
    border-bottom: 1px dashed currentColor;
    white-space: nowrap;
}
/* 管理员：资质条做成"能点"的样子 */
.is-admin .app-qual { background: rgba(99, 102, 241, 0.05); }
.is-admin .app-qual:hover { background: #eef2ff; border-color: var(--primary); }
/* 游客：资质条只是信息展示，不做成按钮的样子 */
.is-guest .app-qual { cursor: default; background: none; }

/* ============ 卡片底部的技术栈 ============ */
.app-stack {
    margin-top: 0.375rem;
    padding-top: 0.375rem;
    border-top: 1px solid var(--border);
    font-size: 0.7rem;
    line-height: 1.5;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}

.app-stack b {
    color: var(--primary);
    margin-right: 0.25rem;
    font-weight: 700;
}

.app-name.nolink { cursor: default; }
.app-name.nolink:hover { color: var(--text); text-decoration: none; }

/* ============ 部署细节（数据库/库用户/后端端口）—— 仅管理员可见 ============ */
.app-infra {
    margin-top: 0.3rem;
    padding-top: 0.3rem;
    border-top: 1px dashed var(--border);
    font-size: 0.68rem;
    line-height: 1.5;
    color: #7c2d12;
    background: #fffbeb;
    border-radius: 6px;
    padding: 0.3rem 0.4rem;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}

.app-infra b {
    color: #b45309;
    margin-right: 0.25rem;
    font-weight: 700;
}

/* 游客态：双重保险（数据本身也不会下发） */
.is-guest .app-infra,
.is-guest .tree-infra { display: none !important; }

/* ============ 资质编辑弹窗 ============ */
.modal-mask {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 500;
    padding: 1rem;
}

.modal {
    background: var(--card-bg);
    border-radius: 14px;
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 24px 48px rgba(0,0,0,0.25);
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1.05rem;
    font-weight: 600;
}

.modal-close {
    border: none;
    background: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: 6px;
    padding: 0 0.375rem;
}

.modal-close:hover {
    background: var(--bg);
    color: var(--text);
}

.modal-body {
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.modal-label {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.125rem;
}

.q-miss-label { color: #dc2626; }
.q-req-label  { color: #059669; }

.modal textarea {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: inherit;
    line-height: 1.55;
    resize: vertical;
    margin-bottom: 0.5rem;
}

.modal textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

.modal-footer {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.875rem 1.25rem;
    border-top: 1px solid var(--border);
}

.modal-spacer { flex: 1; }

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-hover);
    color: white;
    border-color: var(--primary-hover);
}

/* 连线锚点（圆点） */
.anchor {
    position: absolute;
    top: 50%;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--card-bg);
    border: 2px solid #94a3b8;
    transform: translateY(-50%);
    cursor: crosshair;
    transition: all 0.15s;
    z-index: 5;
}

.anchor:hover {
    border-color: var(--primary);
    background: var(--primary);
    transform: translateY(-50%) scale(1.35);
}

.anchor.out {
    right: -8px;
}

.anchor.in {
    left: -8px;
}

/* 上下两个连接点：横向居中、贴上下边 */
.anchor.up,
.anchor.down {
    left: 50%;
    transform: translateX(-50%);
    cursor: crosshair;
}

.anchor.up {
    top: -8px;
}

.anchor.down {
    top: auto;
    bottom: -8px;
}

.anchor.up:hover,
.anchor.down:hover {
    transform: translateX(-50%) scale(1.35);
}

/* ============ 连线标签 ============ */
.edge-label-bg {
    fill: #ffffff;
    stroke: #c7d2fe;
    stroke-width: 1;
}

.edge-label {
    font-size: 12px;
    fill: #4338ca;
    font-weight: 500;
    font-family: -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

.edge-label-hit {
    cursor: pointer;
}

/* ============ 空状态 ============ */
.empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 1.125rem;
}

/* ============ 底栏 ============ */
.bottombar {
    padding: 0.5rem 1.25rem;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    font-size: 0.78rem;
    color: var(--text-secondary);
    text-align: center;
    z-index: 100;
}

.bottombar b { color: var(--text); }

.bottombar code {
    background: #f3f4f6;
    padding: 0.0625rem 0.375rem;
    border-radius: 4px;
    font-size: 0.72rem;
}

.footer-meta {
    margin-top: 0.25rem;
    font-size: 0.72rem;
    opacity: 0.75;
}

/* ============ 只读模式横幅（改了不会保存，必须让人看见）============ */
.readonly-banner {
    margin: 0.5rem 1rem 0;
    padding: 0.55rem 0.9rem;
    border-radius: 8px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    font-size: 0.82rem;
    line-height: 1.5;
}
.readonly-banner b { color: #991b1b; }

/* ============ 布局保存状态（改动自动写进数据库）============ */
.sync-state {
    font-size: 0.72rem;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.35);
    white-space: nowrap;
}
.sync-state.sync-ok {
    color: #4ade80;
    border-color: rgba(74, 222, 128, 0.45);
    background: rgba(74, 222, 128, 0.08);
}
.sync-state.sync-pending {
    color: #fbbf24;
    border-color: rgba(251, 191, 36, 0.45);
    background: rgba(251, 191, 36, 0.08);
}
.sync-state.sync-bad {
    color: #f87171;
    border-color: rgba(248, 113, 113, 0.5);
    background: rgba(248, 113, 113, 0.1);
}

/* ============ 缩放指示 ============ */
.zoom-indicator {
    position: absolute;
    right: 1rem;
    bottom: 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.375rem 0.625rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    box-shadow: var(--shadow);
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.zoom-indicator button {
    border: none;
    background: none;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text);
    padding: 0 0.25rem;
    border-radius: 4px;
}

.zoom-indicator button:hover {
    background: var(--bg);
}

/* toast 提示 */
.toast {
    position: fixed;
    left: 50%;
    bottom: 4.5rem;
    transform: translateX(-50%) translateY(20px);
    background: #111827;
    color: white;
    padding: 0.625rem 1.25rem;
    border-radius: 8px;
    font-size: 0.875rem;
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s;
    z-index: 999;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============ TAB 栏 ============ */
.tabbar {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1.25rem 0;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    z-index: 90;
}

.tab-btn {
    border: 1px solid var(--border);
    border-bottom: none;
    background: var(--bg);
    color: var(--text-secondary);
    border-radius: 8px 8px 0 0;
    padding: 0.4rem 1rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
}

.tab-btn:hover { color: var(--primary); border-color: var(--primary); }

.tab-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    font-weight: 600;
}

.tabbar-note {
    margin-left: auto;
    font-size: 0.72rem;
    color: var(--text-secondary);
    padding-bottom: 0.35rem;
}

/* ============ 链接树视图 ============ */
.tree-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
}

.tree-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 0.6rem 1.25rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
}

.tree-toolbar input[type="text"] {
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    width: 260px;
}

.tree-toolbar input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

.tree-body {
    flex: 1;
    overflow: auto;
    padding: 0.875rem 1.25rem 3rem;
}

.tree-summary {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.tree-group { margin-bottom: 1.25rem; }

.tree-group-title {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text);
    padding: 0.3rem 0;
    border-bottom: 1px dashed var(--border);
    margin-bottom: 0.35rem;
}

.tree-count {
    font-weight: 400;
    font-size: 0.72rem;
    color: var(--text-secondary);
}

.tree-node { position: relative; }

.tree-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.5rem 0.3rem calc(var(--depth, 0) * 18px + 0.5rem);
    border-radius: 8px;
    min-height: 32px;
}

.tree-row:hover {
    background: #fff;
    box-shadow: var(--shadow);
}

.tree-toggle {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1;
    border-radius: 4px;
}

.tree-toggle:hover { background: var(--bg); color: var(--primary); }
.tree-toggle.leaf { color: var(--border); cursor: default; }

.tree-icon { font-size: 1.05rem; line-height: 1; }

.tree-link {
    color: var(--primary);
    font-weight: 600;
    font-size: 0.9rem;
    text-decoration: none;
}

.tree-link:hover { text-decoration: underline; }

.tree-link.nolink {
    color: var(--text-secondary);
    font-weight: 500;
    cursor: default;
}

.tree-link.nolink:hover { text-decoration: none; }

.tree-host {
    font-size: 0.68rem;
    color: var(--text-secondary);
    background: var(--bg);
    border-radius: 4px;
    padding: 0.05rem 0.35rem;
}

.tree-tag {
    font-size: 0.68rem;
    color: var(--text-secondary);
    background: #f3f4f6;
    border-radius: 4px;
    padding: 0.05rem 0.35rem;
}

.tree-miss { font-size: 0.7rem; color: #dc2626; font-weight: 600; }

/* 链接树行尾的技术栈 */
.tree-stack {
    font-size: 0.68rem;
    color: var(--text-secondary);
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.05rem 0.4rem;
    max-width: 46%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-shrink: 1;
}

.tree-stack b {
    color: var(--primary);
    font-weight: 700;
    margin-right: 0.25rem;
}

/* 链接树行尾的部署细节（仅管理员可见） */
.tree-infra {
    font-size: 0.68rem;
    color: #7c2d12;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 4px;
    padding: 0.05rem 0.4rem;
    max-width: 40%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-shrink: 1;
}

.tree-infra b {
    color: #b45309;
    font-weight: 700;
    margin-right: 0.25rem;
}

.tree-actions {
    margin-left: auto;
    display: flex;
    gap: 0.2rem;
    opacity: 0;
    transition: opacity 0.15s;
}

.tree-row:hover .tree-actions { opacity: 1; }

.tree-actions button {
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 6px;
    padding: 0.1rem 0.35rem;
    cursor: pointer;
    font-size: 0.72rem;
    line-height: 1.4;
}

.tree-actions button:hover { border-color: var(--primary); background: #eef2ff; }
.tree-actions button.del:hover { border-color: #dc2626; background: #fef2f2; }

/* 子节点的缩进导线 */
.tree-kids { position: relative; }

.tree-kids::before {
    content: '';
    position: absolute;
    left: calc(var(--depth, 0) * 18px + 12px);
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--border);
}

.tree-node.orphan > .tree-row { background: #fffbeb; }

.tree-empty {
    padding: 2.5rem 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.8;
}

/* 应用编辑表单 */
.app-form { display: flex; flex-direction: column; gap: 0.25rem; }

.app-form input[type="text"],
.app-form select {
    width: 100%;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: inherit;
    background: #fff;
}

.app-form input[type="text"]:focus,
.app-form select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

.app-form-row { display: flex; gap: 0.75rem; }
.app-form-row > div { flex: 1; }

/* 链接地址：服务器（可改）+ 端口/路径（应用可能不都在同一台机器上） */
.url-group {
    display: flex;
    align-items: stretch;
    gap: 0.4rem;
}

.url-group:focus-within {
    /* 两栏各自有自己的边框/焦点环，这里不再整体描边 */
}

.url-host {
    flex: 0 0 13.5rem;
    min-width: 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.url-port {
    flex: 1;
    min-width: 0;
}

.label-hint {
    font-weight: 400;
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-left: 0.4rem;
}

/* 不在默认服务器上的应用：卡片上标出实际主机（例：🌐 8.137.178.15:8060） */
.app-host {
    display: inline-block;
    margin-left: 0.35rem;
    padding: 0 0.3rem;
    border-radius: 4px;
    background: #eef2ff;
    color: #4338ca;
    font-size: 0.68rem;
    font-weight: 500;
}

/* ============ 登录 / 权限 ============ */
.modal-sm { max-width: 420px; }

.auth-state {
    font-size: 0.75rem;
    padding: 0.22rem 0.55rem;
    border-radius: 6px;
    white-space: nowrap;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-secondary);
}

.auth-state.admin {
    color: #047857;
    background: #ecfdf5;
    border-color: #a7f3d0;
    font-weight: 600;
}

.login-msg {
    font-size: 0.78rem;
    color: #dc2626;
    min-height: 1.1rem;
    padding: 0.15rem 0;
}

.login-note {
    font-size: 0.72rem;
    color: var(--text-secondary);
    line-height: 1.6;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 0.6rem;
    margin-top: 0.25rem;
}

.login-note code {
    background: #e5e7eb;
    padding: 0 0.25rem;
    border-radius: 4px;
}

/* 游客（未登录）：所有编辑入口一律隐藏 */
.is-guest .admin-only { display: none !important; }
.is-guest .anchor { display: none !important; }
.is-guest .tree-actions { display: none !important; }
.is-guest .edge-toolbar { display: none !important; }
.is-guest .app-card { cursor: default; }
.is-guest .app-card:active { cursor: default; }
.is-guest #canvasWrap { cursor: grab; }

/* 查重弹窗 */
.dupe-group {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 0.6rem;
    margin-bottom: 0.5rem;
}

.dupe-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px dashed var(--border);
    margin-bottom: 0.35rem;
    flex-wrap: wrap;
}

.dupe-count { font-size: 0.75rem; color: #dc2626; font-weight: 600; }
.dupe-head .btn { margin-left: auto; padding: 0.2rem 0.45rem; font-size: 0.7rem; }

.dupe-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    padding: 0.22rem 0;
}

.dupe-name { font-weight: 600; }
.dupe-name em { font-weight: 400; color: var(--text-secondary); font-style: normal; font-size: 0.72rem; }
.dupe-cat { font-size: 0.7rem; color: var(--text-secondary); }
.dupe-url {
    font-size: 0.7rem;
    color: var(--text-secondary);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.dupe-row .btn { padding: 0.15rem 0.4rem; font-size: 0.7rem; flex-shrink: 0; }
.dupe-ok { font-size: 0.75rem; }
.edge-menu-conn.readonly { cursor: default; }
.edge-menu-conn.readonly:hover { background: none; }

/* CSV 编码损坏提示（导入被拦下时弹的那个窗） */
.csv-damage-lead { font-size: 0.85rem; margin: 0 0 0.5rem; }
.csv-damage-list {
    list-style: none;
    margin: 0 0 0.6rem;
    padding: 0.4rem 0.55rem;
    background: rgba(220, 38, 38, 0.08);
    border-left: 3px solid #dc2626;
    border-radius: 4px;
    font-size: 0.78rem;
    line-height: 1.6;
    max-height: 40vh;
    overflow: auto;
}
.csv-damage-list li { color: #b91c1c; }
.csv-damage-fix {
    font-size: 0.8rem;
    line-height: 1.6;
    margin: 0;
    color: var(--text-secondary);
}
.hint-warn { color: #f59e0b; }

/* 布局历史（回滚）面板 */
.hist-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.78rem;
    padding: 0.3rem 0;
    border-bottom: 1px dashed var(--border);
    flex-wrap: wrap;
}
.hist-row:last-child { border-bottom: none; }
.hist-rev { font-weight: 600; min-width: 3.2rem; }
.hist-bad { color: #dc2626; font-weight: 600; }
.hist-ok { color: #16a34a; }
.hist-at, .hist-by, .hist-count { color: var(--text-secondary); font-size: 0.72rem; }
.hist-row .btn { margin-left: auto; padding: 0.15rem 0.45rem; font-size: 0.7rem; flex-shrink: 0; }
.hist-empty { font-size: 0.8rem; color: var(--text-secondary); }

@media (max-width: 640px) {
    .tabbar-note { display: none; }
    .tree-toolbar input[type="text"] { width: 100%; }
    .tree-actions { opacity: 1; }
}

@media (max-width: 640px) {
    #searchInput { width: 130px; }
    #searchInput:focus { width: 160px; }
    .btn { padding: 0.4rem 0.6rem; font-size: 0.75rem; }
}

/* ============ Knocket 在线接待悬浮球：钉在页脚带里，绝不压卡片 ============
   SDK 自己往 body 里插 #contact-widget-auto（position:static、0 高），球是它 shadow DOM 里
   一个 position:fixed 的 .trtc-float-card，默认 right/bottom 各 20px、z-index 999。
   问题：默认位置正好落在画布右下角，会压住拖到那里的卡片。
   做法：用它支持的 CSS 变量把球挪到页脚那条带子里（画布到 y=826 结束，页脚 826–900，
   1440×900 实测：球 48×48，bottom 6px → y 846–894，完全在卡片区之外），
   页脚文字右侧让出球的宽度；z-index 降到 120，让弹窗（500/900）盖住它。
   变量是在宿主元素上设的，CSS 自定义属性会继承进 shadow DOM；用 !important 是因为
   SDK 会往宿主写 inline `--contact-widget-*: `（空值），否则盖不过 inline 样式。 */
#contact-widget-auto {
    --contact-widget-right: 12px !important;
    --contact-widget-bottom: 6px !important;
    --contact-widget-z-index: 120 !important;
}

/* 页脚给球让位：球 48px + 右边距 12px + 余量 → 右侧留 76px，文字不再压到球下面 */
.bottombar { padding-right: 76px; }

/* 窄屏：页脚会换行变高，球跟着往上抬一点，仍然不出页脚带 */
@media (max-width: 640px) {
    #contact-widget-auto { --contact-widget-bottom: 10px !important; }
    .bottombar { padding-right: 64px; }
}

/* ============ 接待后台（腾讯 TRTC Knocket 控制台）iframe 面板 ============ */
.modal-wide { max-width: 1120px; }

.knocket-hint {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.knocket-hint code {
    background: #f3f4f6;
    padding: 0.0625rem 0.3rem;
    border-radius: 4px;
    font-size: 0.72rem;
}

.knocket-frame {
    width: 100%;
    height: min(72vh, 760px);
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
}

.knocket-frame[hidden] { display: none; }

.knocket-fallback {
    padding: 1.25rem;
    border: 1px dashed var(--border);
    border-radius: 10px;
    background: var(--bg);
    font-size: 0.82rem;
    line-height: 1.7;
    color: var(--text-secondary);
}
/* ============ AI 助手（百炼多模型自动轮换）面板 ============ */
.btn-mini {
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
    border-radius: 7px;
}

.modal-ai {
    max-width: 1240px;
    height: min(90vh, 900px);
    overflow: hidden;
}

/* 全屏模式：遮罩去掉内边距，面板铺满整个视口（右上角 ⛶ 切换，Ctrl+Shift+F 也行） */
.modal-mask.is-max { padding: 0; }
.modal-ai.is-max {
    max-width: none;
    max-height: none;
    width: 100vw;
    height: 100vh;
    border-radius: 0;
    box-shadow: none;
}

.ai-max-btn {
    margin-left: auto;
    margin-right: 0.35rem;
    font-size: 0.95rem;
    line-height: 1;
    padding: 0.15rem 0.45rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
}
.ai-max-btn:hover { color: var(--accent); border-color: var(--accent); }

.ai-sub {
    font-size: 0.72rem;
    font-weight: 400;
    color: var(--text-secondary);
    margin-left: 0.5rem;
}

.ai-body {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 232px 1fr;
}

/* 左侧会话列表 */
.ai-side {
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: #fbfcfe;
}

.ai-side-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    padding: 0.6rem 0.7rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

.ai-sessions {
    flex: 1;
    overflow-y: auto;
    padding: 0.4rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.ai-side-empty {
    padding: 1rem 0.6rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
    text-align: center;
}

.ai-sess {
    display: flex;
    align-items: stretch;
    gap: 0.2rem;
    border-radius: 8px;
    border: 1px solid transparent;
}

.ai-sess:hover { background: #eef2ff; }

.ai-sess.active {
    background: #eef2ff;
    border-color: #c7d2fe;
}

.ai-sess-open {
    flex: 1;
    min-width: 0;
    border: none;
    background: none;
    cursor: pointer;
    text-align: left;
    padding: 0.4rem 0.45rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    font-family: inherit;
    color: var(--text);
}

.ai-sess-title {
    font-size: 0.78rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-sess-meta {
    font-size: 0.68rem;
    color: var(--text-secondary);
}

.ai-sess-del {
    border: none;
    background: none;
    cursor: pointer;
    color: #cbd5e1;
    font-size: 0.95rem;
    line-height: 1;
    padding: 0 0.35rem;
    border-radius: 6px;
}

.ai-sess-del:hover { color: #dc2626; background: #fef2f2; }

/* 右侧对话区 */
.ai-main {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}

.ai-msgs {
    flex: 1;
    overflow-y: auto;
    padding: 0.9rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    background: #fff;
}

.ai-empty {
    margin: auto;
    max-width: 30rem;
    padding: 1.2rem;
    font-size: 0.84rem;
    line-height: 1.8;
    color: var(--text-secondary);
    text-align: center;
    background: var(--bg);
    border-radius: 12px;
}

.ai-msg {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    max-width: 100%;
}

.ai-role {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.ai-msg.user { align-items: flex-end; }

.ai-msg.user .ai-text {
    background: var(--primary);
    color: #fff;
    border-radius: 12px 12px 3px 12px;
    padding: 0.5rem 0.7rem;
    max-width: 82%;
}

.ai-msg.assistant .ai-text {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px 12px 12px 3px;
    padding: 0.55rem 0.75rem;
    max-width: 96%;
}

.ai-text {
    font-size: 0.85rem;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-para { margin: 0 0 0.45rem; }
.ai-para:last-child { margin-bottom: 0; }

.ai-text code {
    background: rgba(79,70,229,0.1);
    color: #4338ca;
    padding: 0.05rem 0.25rem;
    border-radius: 4px;
    font-size: 0.8em;
}

.ai-msg.user .ai-text code { background: rgba(255,255,255,0.22); color: #fff; }

.ai-code {
    background: #0f172a;
    color: #e2e8f0;
    padding: 0.55rem 0.7rem;
    border-radius: 8px;
    font-size: 0.78rem;
    line-height: 1.5;
    overflow-x: auto;
    margin: 0.35rem 0;
    white-space: pre;
}

.ai-notes {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    margin-top: 0.15rem;
}

.ai-note {
    font-size: 0.72rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

.ai-note.ok { color: #059669; }
.ai-note.warn { color: #b45309; }
.ai-note.bad { color: #dc2626; }
.ai-note.dim { color: #94a3b8; }
.ai-note.busy { color: var(--primary); }

/* 输入区 */
.ai-compose {
    border-top: 1px solid var(--border);
    padding: 0.6rem 0.8rem 0.7rem;
    background: #fbfcfe;
}

.ai-compose textarea {
    width: 100%;
    min-height: 3.2rem;
    max-height: 9rem;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 9px;
    font-size: 0.85rem;
    font-family: inherit;
    line-height: 1.55;
    resize: vertical;
    margin-bottom: 0.45rem;
}

.ai-compose textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

.ai-row {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    font-size: 0.78rem;
}

.ai-chk {
    display: inline-flex;
    align-items: center;
    gap: 0.28rem;
    cursor: pointer;
    color: var(--text-secondary);
    user-select: none;
}

.ai-chk input { cursor: pointer; }

.ai-spacer { flex: 1; }

.ai-stat {
    font-size: 0.72rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

.ai-stat b { color: var(--text); }

/* ---------------- 📊 今日花费 / ⚙ 额度设置（从 AI 面板里点开） ---------------- */
.modal-ai-report { max-width: 860px; }
.modal-ai-cfg { max-width: 620px; }

.ai-kpi {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 12px;
}
.ai-kpi-item {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    background: #fbfcfe;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.ai-kpi-item span { font-size: 0.72rem; color: var(--text-secondary); }
.ai-kpi-item b { font-size: 1.12rem; color: var(--text); }
.ai-kpi-item small { font-size: 0.68rem; color: #94a3b8; }

.ai-bar {
    height: 8px;
    border-radius: 999px;
    background: #eef2f7;
    overflow: hidden;
    margin: 0 0 14px;
}
.ai-bar i {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #6366f1, #8b5cf6);
    border-radius: 999px;
}

.ai-h4 {
    font-size: 0.82rem;
    margin: 14px 0 6px;
    color: var(--text);
}

.ai-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}
.ai-table th, .ai-table td {
    padding: 6px 8px;
    border-bottom: 1px solid #eef2f7;
    text-align: left;
    vertical-align: top;
}
.ai-table th { color: var(--text-secondary); font-weight: 600; background: #fafbfd; }
.ai-table .num { text-align: right; white-space: nowrap; }
.ai-table .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.74rem; }
.ai-table .dim { color: #94a3b8; }
.ai-empty.bad { color: #dc2626; }

.ai-cfg-note {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin: 0 0 12px;
    line-height: 1.6;
}
.ai-cfg-row {
    display: grid;
    grid-template-columns: 168px 1fr;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}
.ai-cfg-row span { font-size: 0.8rem; color: var(--text); }
.ai-cfg-row input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.84rem;
    font-family: inherit;
    background: #fff;
}
.ai-cfg-row small {
    grid-column: 2 / 3;
    font-size: 0.7rem;
    color: #94a3b8;
}

@media (max-width: 820px) {
    .ai-kpi { grid-template-columns: repeat(2, 1fr); }
    .ai-cfg-row { grid-template-columns: 1fr; }
    .ai-cfg-row small { grid-column: 1 / 2; }
}

@media (max-width: 820px) {
    .ai-body { grid-template-columns: 1fr; }
    .ai-side { display: none; }
}