/* ========================================================
   FlowNotes — Premium Design System (Mindmap-First Edition)
   ======================================================== */

:root {
    /* 核心专属暗黑主题调色盘 (Space Obsidian) */
    --bg-main: #0b0f19;
    --bg-surface: #111827;
    --bg-surface-elevated: #1e293b;
    --bg-glass: rgba(17, 24, 39, 0.85);

    --border-color: rgba(255, 255, 255, 0.1);
    --border-glow: rgba(99, 102, 241, 0.4);

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    /* 猫头鹰智慧渐变与 D3 节点主题色 */
    --accent-indigo: #6366f1;
    --accent-violet: #8b5cf6;
    --accent-cyan: #38bdf8;
    --accent-amber: #f59e0b;
    --accent: #7a82ff;
    --danger: #ef5350;
    --success: #10b981;

    --gradient-primary: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #38bdf8 100%);
    --gradient-card: linear-gradient(180deg, rgba(30, 41, 59, 0.4) 0%, rgba(15, 23, 42, 0.6) 100%);

    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 25px rgba(99, 102, 241, 0.25);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.35s cubic-bezier(0.4, 0, 0.2, 1);

    /* D3 Mindmap 变量兼容 */
    --bg-color: #0b0f19;
    --text-color: #f8fafc;
    --hint-color: #94a3b8;
    --panel-bg: #111827;
    --panel-border: rgba(255, 255, 255, 0.1);
    --link-color: #6366f1;
    --node-stroke: #1e293b;
    --node-text: #cbd5e1;
    --node-text-selected: #ffffff;
    --input-bg: #0b0f19;
    --input-text: #f8fafc;
    --status-bg: rgba(17, 24, 39, 0.92);
}

[data-theme="light"] {
    --bg-main: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-elevated: #f1f5f9;
    --bg-glass: rgba(255, 255, 255, 0.9);

    --border-color: rgba(0, 0, 0, 0.08);
    --border-glow: rgba(99, 102, 241, 0.3);

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    --bg-color: #f8fafc;
    --text-color: #0f172a;
    --hint-color: #64748b;
    --panel-bg: #ffffff;
    --panel-border: #e2e8f0;
    --link-color: #8b5cf6;
    --node-stroke: #ffffff;
    --node-text: #475569;
    --node-text-selected: #0f172a;
    --input-bg: #ffffff;
    --input-text: #0f172a;
    --status-bg: rgba(255, 255, 255, 0.92);
}

/* 隐藏属性强效重写 (修复 Modal 遮罩 Bug) */
[hidden] {
    display: none !important;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 顶栏导航 */
.navbar {
    height: 64px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-left, .navbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo-group {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}

.owl-mascot {
    width: 38px;
    height: 38px;
    filter: drop-shadow(0 0 10px rgba(99, 102, 241, 0.4));
}

.owl-svg { width: 100%; height: 100%; }

@keyframes owlBlink {
    0%, 92%, 100% { transform: scaleY(1); }
    96% { transform: scaleY(0.1); }
}

.owl-eye { animation: owlBlink 4s infinite; transform-origin: center; }

.logo-text h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.3rem;
    font-weight: 800;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.badge-local {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 6px;
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent-cyan);
    border-radius: 4px;
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.nav-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-surface);
    padding: 4px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.nav-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.85rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.nav-tab:hover { color: var(--text-primary); background: var(--bg-surface-elevated); }
.nav-tab.active { background: var(--gradient-primary); color: #ffffff; box-shadow: var(--shadow-glow); }

.search-box {
    display: flex;
    align-items: center;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 6px 12px;
    width: 220px;
}

.search-box input {
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.82rem;
    width: 100%;
    outline: none;
}

.shortcut-hint {
    font-family: 'Fira Code', monospace;
    font-size: 0.68rem;
    color: var(--text-muted);
    background: var(--bg-surface-elevated);
    padding: 2px 6px;
    border-radius: 4px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-primary { background: var(--gradient-primary); color: #ffffff; }
.btn-secondary { background: var(--bg-surface); border: 1px solid var(--border-color); color: var(--text-primary); }
.btn-github { background: rgba(16, 185, 129, 0.15); border: 1px solid rgba(16, 185, 129, 0.4); color: #a7f3d0; }
.btn-obsidian { background: rgba(168, 85, 247, 0.15); border: 1px solid rgba(168, 85, 247, 0.4); color: #e9d5ff; }

.btn-icon-only {
    width: 36px; height: 36px; border-radius: var(--radius-sm);
    background: var(--bg-surface); border: 1px solid var(--border-color);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--text-primary);
}

.w-100 { width: 100%; justify-content: center; }

.owl-banner {
    background: linear-gradient(90deg, rgba(99, 102, 241, 0.15), rgba(56, 189, 248, 0.1));
    border-bottom: 1px solid rgba(99, 102, 241, 0.25);
    padding: 6px 24px;
    display: flex; align-items: center; justify-content: space-between;
    font-size: 0.82rem; color: var(--text-secondary);
}

.owl-banner-content { display: flex; align-items: center; gap: 8px; }
.btn-close-banner { background: transparent; border: none; color: var(--text-muted); font-size: 1.2rem; cursor: pointer; }

/* 主工作容器 */
.main-container {
    flex: 1;
    position: relative;
    width: 100%;
}

.main-fullbleed {
    padding: 0 !important;
    max-width: 100% !important;
}

.tab-pane {
    display: none;
    height: calc(100vh - 96px);
}

.tab-pane.active { display: block; }

/* ========================================================
   Obsidian 心流图谱 D3 矢量工作台 (Visual Mindmap Workspace)
   ======================================================== */

.obsidian-mindmap-workspace {
    display: flex;
    width: 100vw;
    height: calc(100vh - 96px);
    overflow: hidden;
    position: relative;
    background-color: var(--bg-color);
}

#graph-container {
    flex: 1;
    position: relative;
    height: 100%;
    cursor: grab;
    min-width: 0;
}

#graph-container:active { cursor: grabbing; }

#graph-svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* 浮动控制工具栏 */
#nav-controls {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-width: min(390px, calc(100vw - 450px));
}

.nav-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid var(--panel-border);
    background: var(--panel-bg);
    color: var(--text-color);
    cursor: pointer;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.nav-btn:hover { background: var(--accent-indigo); color: white; border-color: var(--accent-indigo); transform: translateY(-1px); }
.nav-btn[data-active="true"] { background: var(--accent-indigo); color: white; border-color: var(--accent-indigo); }

#io-controls {
    position: absolute;
    bottom: 16px;
    right: 16px;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
}

.io-btn {
    background: var(--panel-bg);
    color: var(--text-color);
    border: 1px solid var(--panel-border);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    transition: all var(--transition-fast);
}

.io-btn:hover { background: var(--accent-indigo); color: white; border-color: var(--accent-indigo); }

.sync-status {
    max-width: 280px;
    min-height: 30px;
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid var(--panel-border);
    background: var(--status-bg);
    color: var(--hint-color);
    font-size: 12px;
}

.sync-status[data-state="ok"] { color: var(--success); }
.sync-status[data-state="error"] { color: var(--danger); }
.sync-status[data-state="busy"], .sync-status[data-state="pending"] { color: var(--accent-cyan); }

/* SVG 图谱 Node/Link 样式 */
.link { stroke: rgba(99, 102, 241, 0.4); stroke-width: 1.8px; opacity: 0.75; }
.relation-link { stroke: var(--accent-cyan); stroke-width: 1.8px; stroke-dasharray: 6 6; opacity: 0.75; }

.node-group { cursor: pointer; }
.node-circle {
    stroke: var(--node-stroke);
    stroke-width: 2px;
    transition: fill 0.3s, stroke 0.3s, transform 0.18s cubic-bezier(0.18, 1.4, 0.38, 1);
    transform-box: fill-box;
    transform-origin: center;
}

.node-group:hover .node-circle { transform: scale(1.12); }
.node-group.multi-selected .node-circle { stroke: var(--accent-cyan) !important; stroke-width: 4px !important; }

@keyframes rewirePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.58; }
}

.node-group.long-press-arming .node-circle {
    stroke: var(--accent-amber) !important;
    stroke-width: 4px !important;
    stroke-dasharray: 5 5;
    animation: rewirePulse 1s ease-in-out infinite;
}

.node-label { fill: var(--node-text); pointer-events: none; font-size: 13px; font-weight: 500; }
.collapse-badge { fill: var(--accent-amber); pointer-events: none; font-size: 11px; font-weight: 700; }

#hint {
    position: absolute;
    top: 16px;
    right: 16px;
    color: var(--hint-color);
    pointer-events: none;
    line-height: 1.6;
    font-size: 12px;
    max-width: 320px;
    background: var(--bg-glass);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

#edit-input {
    position: absolute;
    display: none;
    background: var(--input-bg);
    border: 1px solid var(--accent-indigo);
    border-radius: 4px;
    outline: none;
    color: var(--input-text);
    font-family: inherit;
    font-size: 13px;
    text-align: center;
    width: 140px;
    padding: 4px;
    transform: translate(-50%, -50%);
    z-index: 20;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

/* 右侧深度编辑器面板 */
#editor-panel {
    width: 420px;
    background-color: var(--panel-bg);
    border-left: 1px solid var(--panel-border);
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 20px rgba(0,0,0,0.3);
    z-index: 10;
}

#editor-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    align-items: center;
}

#title-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-color);
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1.25rem;
}

#format-toolbar {
    padding: 8px 12px;
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    background: var(--bg-surface);
}

.format-btn {
    min-width: 28px;
    height: 28px;
    padding: 0 6px;
    border: 1px solid var(--panel-border);
    border-radius: 4px;
    background: transparent;
    color: var(--text-color);
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
}

.format-btn:hover { background: rgba(99, 102, 241, 0.2); border-color: var(--accent-indigo); }
.format-btn[data-active="true"] { background: var(--accent-indigo); color: #ffffff; }

.format-separator { width: 1px; height: 18px; background: var(--panel-border); margin: 0 4px; }
#md-color { width: 26px; height: 26px; border: none; background: transparent; cursor: pointer; }

#note-workspace {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--panel-bg);
}

#rich-editor, #preview-panel {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    font-size: 0.95rem;
    line-height: 1.7;
    outline: none;
}

#md-textarea {
    flex: 1;
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-color);
    padding: 20px;
    font-family: 'Fira Code', monospace;
    font-size: 0.92rem;
    line-height: 1.7;
    resize: none;
    outline: none;
}

#note-workspace[data-preview-mode="edit"] #rich-editor,
#note-workspace[data-preview-mode="edit"] #preview-panel { display: none; }
#note-workspace[data-preview-mode="live"] #md-textarea,
#note-workspace[data-preview-mode="live"] #preview-panel { display: none; }
#note-workspace[data-preview-mode="preview"] #rich-editor,
#note-workspace[data-preview-mode="preview"] #md-textarea { display: none; }

/* 大纲与文章库抽屉 */
#outline-panel, #article-library-panel {
    position: absolute;
    z-index: 30;
    top: 60px;
    left: 16px;
    bottom: 60px;
    width: 320px;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-lg);
    box-shadow: 0 14px 32px rgba(0,0,0,0.4);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.outline-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 700;
}

.outline-close { background: transparent; border: none; color: var(--text-muted); font-size: 1.4rem; cursor: pointer; }

#outline-filter, #article-library-filter {
    padding: 8px 12px;
    border: none;
    border-bottom: 1px solid var(--panel-border);
    background: var(--input-bg);
    color: var(--input-text);
    outline: none;
}

#outline-tree, #article-library-list { flex: 1; overflow-y: auto; padding: 8px; }

.outline-row {
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
}

.outline-row:hover { background: rgba(99, 102, 241, 0.15); }

/* Quick Open 搜素面板 */
#quick-open {
    position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,0.5);
    display: flex; align-items: flex-start; justify-content: center; padding-top: 80px;
}

.quick-card {
    width: 540px; border-radius: var(--radius-lg);
    background: var(--panel-bg); border: 1px solid var(--border-glow);
    box-shadow: var(--shadow-glow); overflow: hidden;
}

#quick-input {
    width: 100%; height: 50px; border: none; border-bottom: 1px solid var(--panel-border);
    background: transparent; color: var(--text-color); padding: 0 20px; outline: none; font-size: 1rem;
}

#quick-results { max-height: 380px; overflow-y: auto; padding: 8px; }

.quick-result {
    padding: 10px 14px; border-radius: 6px; cursor: pointer; margin-bottom: 4px;
}

.quick-result:hover { background: rgba(99, 102, 241, 0.2); }

/* AI 文章模态框 */
#article-modal {
    position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,0.7);
    display: flex; align-items: center; justify-content: center; padding: 20px;
}

.article-card {
    width: 1000px; height: 720px; background: var(--panel-bg); border: 1px solid var(--border-glow);
    border-radius: var(--radius-xl); display: flex; flex-direction: column; overflow: hidden;
}

.article-header { padding: 16px 24px; border-bottom: 1px solid var(--panel-border); display: flex; justify-content: space-between; }
.article-body { flex: 1; display: grid; grid-template-columns: 1fr 340px; }
#article-output { background: var(--input-bg); color: var(--input-text); padding: 20px; border: none; outline: none; resize: none; font-family: 'Fira Code', monospace; }
.article-chat-panel { border-left: 1px solid var(--panel-border); display: flex; flex-direction: column; }
#article-chat-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
#article-chat-input { height: 80px; border: none; border-top: 1px solid var(--panel-border); background: var(--input-bg); color: var(--input-text); padding: 10px; outline: none; }
.article-chat-actions, .article-actions { padding: 12px; display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--panel-border); }
.article-action { padding: 6px 12px; border-radius: 6px; border: 1px solid var(--panel-border); background: var(--bg-surface-elevated); color: var(--text-color); cursor: pointer; }

/* 通用弹窗与 Toast */
.modal-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(8px); display: none; align-items: center; justify-content: center; z-index: 1000; }
.modal-card { background: var(--bg-surface); border: 1px solid var(--border-glow); border-radius: var(--radius-xl); width: 90%; max-width: 520px; box-shadow: var(--shadow-md); overflow: hidden; }
.modal-card.modal-lg { max-width: 620px; }
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; }
.btn-close-modal { background: transparent; border: none; color: var(--text-muted); font-size: 1.5rem; cursor: pointer; }
.modal-body { padding: 24px; font-size: 0.95rem; line-height: 1.7; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; gap: 12px; }
.modal-actions-between { justify-content: space-between !important; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.input-field { width: 100%; padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-color); background: var(--bg-main); color: var(--text-primary); outline: none; }
.input-with-button { display: flex; gap: 10px; }
.margin-top-sm { margin-top: 10px; }
.margin-top-md { margin-top: 16px; }
.sync-status-box { background: var(--bg-main); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 14px 16px; }
.code-preview-box { background: var(--bg-main); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 16px; margin-top: 14px; font-size: 0.85rem; }

.toast { position: fixed; bottom: 24px; right: 24px; background: var(--bg-surface-elevated); border: 1px solid var(--accent-indigo); color: var(--text-primary); padding: 12px 24px; border-radius: var(--radius-md); box-shadow: var(--shadow-glow); font-weight: 600; font-size: 0.9rem; z-index: 2000; opacity: 0; transform: translateY(20px); transition: all 0.3s; pointer-events: none; }
.toast.show { opacity: 1; transform: translateY(0); }

/* 心流与常规列表兼容样式 */
.flow-container { max-width: 800px; margin: 24px auto; display: flex; flex-direction: column; gap: 20px; }
.flow-input-card { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-lg); padding: 20px; }
.flow-textarea { width: 100%; min-height: 100px; background: var(--bg-main); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 12px; color: var(--text-primary); outline: none; }
.flow-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }
.flow-card { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 16px; margin-bottom: 12px; }

.editor-layout { display: grid; grid-template-columns: 260px 1fr 280px; gap: 16px; height: calc(100vh - 96px); padding: 16px; }
.sidebar-notes, .sidebar-backlinks { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-lg); overflow: hidden; display: flex; flex-direction: column; }
.notes-list-items { flex: 1; overflow-y: auto; padding: 10px; }
.note-item { padding: 10px 12px; border-radius: 6px; cursor: pointer; margin-bottom: 4px; }
.note-item:hover { background: var(--bg-surface-elevated); }
.note-item.active { background: rgba(99, 102, 241, 0.2); border-left: 3px solid var(--accent-indigo); }
.editor-main { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-lg); display: flex; flex-direction: column; overflow: hidden; }
.editor-top-bar { padding: 12px 20px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; }
.note-meta-bar { padding: 8px 20px; background: var(--bg-main); border-bottom: 1px solid var(--border-color); font-size: 0.8rem; }
.editor-body { flex: 1; padding: 20px; display: flex; }
.markdown-textarea { width: 100%; height: 100%; background: transparent; border: none; color: var(--text-primary); font-family: 'Fira Code', monospace; resize: none; outline: none; }
