/* ==========================================
   🎨 1. 主题色彩调度中心 (Variables Switchboard)
   ========================================== */
:root {
    --bg-body: #ffffff;
    --bg-sidebar: #f7f9fa;
    --bg-panel: #f6f8fa;
    --bg-hover: #eef1f2;
    --bg-input: #ffffff;
    --bg-mobile-sidebar: rgba(255, 255, 255, 0.95);
    --border-light: #eef1f2;
    --border-medium: #dcdfe6;
    --border-dark: #d0d7de;
    --text-main: #1a1a1a;
    --text-secondary: #303133;
    --text-muted: #8b949e;
    --text-placeholder: #e4e7ed;
    --color-accent: #1f6feb; 
}

[data-theme="dark"] {
    --bg-body: #0d1117;       
    --bg-sidebar: #161b22;    
    --bg-panel: #21262d;      
    --bg-hover: #30363d;      
    --bg-input: #0d1117;
    --bg-mobile-sidebar: rgba(22, 27, 34, 0.95); 
    --border-light: #30363d;
    --border-medium: #30363d;
    --border-dark: #484f58;
    --text-main: #c9d1d9;     
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --text-placeholder: #484f58;
    --color-accent: #58a6ff;  
}

/* ==========================================
   🏗️ 2. 全局重置与基础骨架 (Global Reset)
   ========================================== */
body { 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; 
    background: var(--bg-body); 
    color: var(--text-main); 
    padding: 0; margin: 0; 
    display: flex; height: 100dvh; overflow: hidden; 
    transition: background 0.3s, color 0.3s; 
}

/* ==========================================
   🧭 3. 侧边栏与导航引擎 (Sidebar & Nav)
   ========================================== */
#sidebar { 
    width: 15px; background: transparent; border-right: 1px solid transparent; 
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); 
    display: flex; flex-direction: column; position: relative; z-index: 100; 
    overflow: hidden; white-space: nowrap; 
}
.sidebar-content { 
    padding: 20px; opacity: 0; transition: opacity 0.2s; 
    display: flex; flex-direction: column; height: 100%; box-sizing: border-box; 
    overflow-y: auto; pointer-events: none;
}
#btn-file-hall, #btn-file-encrypt { 
    cursor: pointer; opacity: 0.6; transition: 0.2s; 
    padding: 4px; border-radius: 4px; display: flex; align-items: center; justify-content: center;
}
#btn-file-hall:hover, #btn-file-encrypt:hover { opacity: 1; background: var(--bg-hover); }
#sidebar.pinned { 
    width: clamp(240px, 20vw, 280px); background: var(--bg-sidebar); 
    border-right: 1px solid var(--border-light); box-shadow: 4px 0 15px rgba(0,0,0,0.03); 
}
#sidebar.pinned .sidebar-content { 
    opacity: 1; pointer-events: auto; transition-delay: 0.1s; 
}
@media (hover: hover) and (pointer: fine) {
    #sidebar:hover { 
        width: clamp(240px, 20vw, 280px); background: var(--bg-sidebar); 
        border-right: 1px solid var(--border-light); box-shadow: 4px 0 15px rgba(0,0,0,0.03); 
    }
    #sidebar:hover .sidebar-content { 
        opacity: 1; pointer-events: auto; transition-delay: 0.1s; 
    }
}

.hamburger-pin { 
    color: var(--text-placeholder); font-size: 20px; cursor: pointer; 
    user-select: none; transition: 0.2s; display: inline-block; 
    padding: 4px; border-radius: 4px;
}
.hamburger-pin:hover { color: var(--text-muted); background: var(--bg-hover);}
#sidebar.pinned .hamburger-pin { color: var(--text-main); font-weight: bold; background: var(--border-medium);}

.theme-toggle-btn { 
    cursor: pointer; font-size: 16px; opacity: 0.6; transition: 0.2s; 
    user-select: none; padding: 4px; border-radius: 4px; 
    display: flex; align-items: center; justify-content: center;
}
.theme-toggle-btn:hover { opacity: 1; background: var(--bg-hover); }

/* ==========================================
   📂 4. 笔记列表与极客标签 (File List & Tags)
   ========================================== */
.sidebar-title { 
    font-size: 12px; font-weight: 600; color: var(--text-muted); 
    margin-bottom: 10px; margin-top: 20px; letter-spacing: 1px; 
    display: flex; justify-content: space-between; align-items: center; 
}

.file-list { flex: 1; overflow-y: auto; margin-bottom: 20px; }
.file-item-container { 
    display: flex; align-items: center; justify-content: space-between; 
    border-radius: 6px; transition: 0.1s; padding-right: 8px;
}
.file-item-container:hover { background: var(--bg-hover); }
.file-item { 
    padding: 8px 4px 8px 12px; cursor: pointer; color: var(--text-secondary); 
    font-size: 14px; flex: 1; overflow: hidden; text-overflow: ellipsis;
}
.file-item:hover { color: var(--color-accent); font-weight: bold;}
.delete-btn { color: #f85149; font-size: 12px; cursor: pointer; opacity: 0; padding: 4px; border-radius: 4px;}
.delete-btn:hover { background: #ffdce0; }
.file-item-container:hover .delete-btn { opacity: 1; }

/* ==========================================
   📝 6. 主画布与元数据属性面板 (Main Canvas & Meta)
   ========================================== */
#main-canvas { 
    flex: 1; display: flex; flex-direction: column; align-items: center; 
    overflow-y: auto; padding: 0; 
    background: var(--bg-body); transition: 0.3s; width: 100%; box-sizing: border-box;
}
.editor-width-limiter { 
    width: 100%; max-width: 740px; display: flex; flex-direction: column; flex: 1; 
    padding: 20px clamp(15px, 5vw, 20px) 40px; 
}

#note-title { 
    font-size: clamp(24px, 4vw + 10px, 38px); font-weight: 700; color: var(--text-main); 
    border: none; background: transparent; width: 100%; outline: none; padding-bottom: 5px; 
}
#note-title::placeholder { color: var(--text-placeholder); }

.meta-details { margin-bottom: 15px; }
.meta-details summary { 
    font-size: 13px; color: var(--text-muted); cursor: pointer; outline: none; 
    list-style: none; user-select: none; display: inline-flex; align-items: center; gap: 4px;
}
.meta-details summary::-webkit-details-marker { display: none; }
.meta-details summary::before { content: '▸'; font-size: 12px; transition: 0.2s; }
.meta-details[open] summary::before { transform: rotate(90deg); }

.meta-panel { 
    background: var(--bg-panel); border: 1px solid var(--border-dark); 
    border-radius: 6px; padding: 12px 15px; margin-top: 8px; 
    display: grid; grid-template-columns: 80px 1fr; gap: 8px 15px; 
    font-size: 13px; color: var(--text-muted); 
}
.meta-panel input { border: 1px solid transparent; background: transparent; color: var(--text-secondary); font-size: 13px; outline: none; width: 100%;}
.meta-panel input:hover { border-bottom: 1px dashed var(--border-dark); }
.meta-panel input:focus { border-bottom: 1px solid var(--color-accent); }
.meta-label { color: var(--text-muted); font-weight: 500;}

.divider { border-top: 1px solid var(--border-light); margin-bottom: 20px; flex-shrink: 0; }

/* ==========================================
   ✒️ 8. 编辑器基础容器 (Milkdown Ready)
   ========================================== */
#milkdown-editor { flex: 1; font-size: 16px; line-height: 1.8; color: var(--text-secondary); min-height: 400px; cursor: text; outline: none; }

/* ==========================================
   🗂️ 9. 文件大厅与标签系统 UI
   ========================================== */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.4); backdrop-filter: blur(2px); z-index: 3000;
    display: none; justify-content: center; align-items: center;
    opacity: 0; transition: opacity 0.2s;
}
.modal-overlay.active { display: flex; opacity: 1; }
.modal-content {
    width: 80%; height: 80%; background: var(--bg-body); border-radius: 12px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    display: flex; flex-direction: column; overflow: hidden;
    transform: scale(0.95); transition: transform 0.2s;
}
.modal-overlay.active .modal-content { transform: scale(1); }

.modal-header {
    height: 50px; border-bottom: 1px solid var(--border-light); display: flex;
    justify-content: space-between; align-items: center; padding: 0 20px;
}
.modal-title { font-size: 16px; font-weight: bold; color: var(--text-main); }
.btn-close { font-size: 24px; color: var(--text-muted); cursor: pointer; transition: color 0.2s; }
.btn-close:hover { color: #f85149; }

.modal-body { display: flex; flex: 1; height: calc(100% - 50px); }
.modal-sidebar { width: 25%; background: var(--bg-sidebar); border-right: 1px solid var(--border-light); }
.modal-main { width: 75%; background: var(--bg-body); padding: 24px; overflow-y: auto; }

.tag-parent { margin-bottom: 2px; }
.tag-item {
    display: flex; align-items: center; padding: 6px 10px; border-radius: 6px; 
    cursor: pointer; font-size: 13px; color: var(--text-secondary); transition: background 0.2s;
}
.tag-item:hover { background-color: var(--bg-hover); }
.tag-item.active { background-color: rgba(31, 111, 235, 0.1); color: var(--color-accent); font-weight: bold; }
.tag-item:hover .tag-actions { opacity: 1; }

.tag-children { padding-left: 20px; }
.tag-color-dot { width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; flex-shrink: 0; }
.tag-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag-actions { opacity: 0; font-size: 12px; transition: opacity 0.2s; padding: 2px; }
.tag-actions:hover { color: #2ea043; }

.file-grid { display: flex; flex-direction: column; gap: 0; }
.file-card {
    display: flex; align-items: center; padding: 10px 16px; cursor: pointer;
    border-bottom: 1px solid var(--border-light); transition: background 0.2s;
}
.file-card:hover { background-color: var(--bg-hover); }
.file-card:last-child { border-bottom: none; }
.file-card-icon { font-size: 20px; margin-right: 12px; }
.file-card-name { font-size: 14px; font-weight: 500; color: var(--text-main); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 8px;}
.file-card-time { font-size: 13px; color: var(--text-muted); width: 150px; text-align: right; }

.file-card-delete {
    width: 40px; text-align: center; font-size: 16px;
    color: var(--text-muted); opacity: 0; 
    transition: opacity 0.2s, color 0.2s; cursor: pointer;
}
.file-card:hover .file-card-delete { opacity: 0.6; }
.file-card-delete:hover { opacity: 1 !important; color: #f85149 !important; }

.color-swatch {
    width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
    border: 2px solid transparent; transition: transform 0.2s, box-shadow 0.2s;
}
.color-swatch:hover { transform: scale(1.1); }
.color-swatch.selected { border-color: var(--border-dark); transform: scale(1.15); box-shadow: 0 0 0 2px var(--bg-body) inset; }

.tag-item { position: relative; transition: background 0.2s, opacity 0.2s; }
.tag-item.dragging { opacity: 0.4; background: var(--border-light); }
.tag-item.drop-before::before { content: ''; position: absolute; top: -2px; left: 0; right: 0; height: 2px; background: var(--color-accent); z-index: 10; border-radius: 2px; }
.tag-item.drop-after::after { content: ''; position: absolute; bottom: -2px; left: 0; right: 0; height: 2px; background: var(--color-accent); z-index: 10; border-radius: 2px; }
.tag-item.drop-inside { background: rgba(31, 111, 235, 0.1) !important; box-shadow: inset 0 0 0 1px var(--color-accent); }

.file-group-header {
    font-size: 14px; font-weight: 600; color: var(--text-main); margin: 24px 0 12px 0; 
    display: flex; justify-content: space-between; align-items: center; 
    border-bottom: 1px solid var(--border-light); padding-bottom: 4px;
}
.file-group-header:first-child { margin-top: 0; }
.file-group-count { font-size: 12px; color: var(--text-muted); font-weight: normal; }

.file-search-input {
    width: 100%; box-sizing: border-box; padding: 10px 16px 10px 36px; 
    border: 1px solid var(--border-medium); border-radius: 8px; font-size: 14px; 
    outline: none; transition: all 0.2s; color: var(--text-main);
    background: var(--bg-input) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="%239ca3af" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>') no-repeat 12px center;
}
.file-search-input:focus { border-color: var(--color-accent); box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.1); }
.inline-tag-container { margin-left: 12px; display: inline-flex; gap: 6px; align-items: center; vertical-align: middle; }
.inline-tag-pill { font-size: 11px; padding: 2px 6px; border-radius: 4px; font-weight: 500; display: inline-block; line-height: 1.2; white-space: nowrap; }

/* ==========================================
   📱 10. 移动端 APP 化装甲 (Mobile PWA Mode)
   ========================================== */
@media (max-width: 768px) {
    #main-canvas { padding-bottom: 80px; }
    #sidebar {
        position: fixed; bottom: 0; left: 0; top: auto;
        width: 100vw !important; height: 60px;
        background: var(--bg-panel); border-top: 1px solid var(--border-light);
        border-right: none; z-index: 2000; flex-direction: row; box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
        backdrop-filter: blur(10px); 
    }
    .sidebar-content {
        padding: 0; opacity: 1; pointer-events: auto;
        flex-direction: row; justify-content: space-around; align-items: center; width: 100%;
    }
    .mobile-menu-btn, .sidebar-title, #cloud-file-list { display: none !important; }
    .sidebar-content > div:first-child {
        width: 100%; justify-content: space-around !important; margin: 0 !important;
    }
    .sidebar-content > div:first-child > div {
        font-size: 22px !important; padding: 10px 15px;
    }
    .new-note-btn { 
        position: fixed !important; 
        z-index: 9999 !important;   
        bottom: 80px; top: auto; right: 25px; 
        background: var(--bg-panel); border-radius: 50%; 
        box-shadow: 0 4px 10px rgba(0,0,0,0.1); 
        width: 45px; height: 45px; display: flex; 
        justify-content: center; align-items: center; 
    }
    .modal-content { width: 100% !important; height: 100% !important; border-radius: 0; transform: scale(1) !important; }
    .modal-body { flex-direction: column; }
    .modal-sidebar { width: 100%; height: 30vh; border-right: none; border-bottom: 1px solid var(--border-light); }
    .modal-main { width: 100%; height: 70vh; padding: 12px; }
    #tagModal .modal-content { width: 90% !important; height: max-content !important; border-radius: 12px; }
    .top-action-bar { padding: max(20px, env(safe-area-inset-top)) 20px 0 20px !important; }
    .action-right { display: none !important; }
}

/* ==========================================
   🎛️ 11. 极简顶部动作栏 (Top Action Bar)
   ========================================== */
.top-action-bar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 20px 20px 0 5px; 
    width: 100%; box-sizing: border-box;
}
.action-left {
    display: flex; align-items: center; gap: 16px; 
}
.action-icon {
    background: transparent; border: none; outline: none; font-size: 16px; 
    cursor: pointer; color: var(--text-placeholder); 
    transition: transform 0.2s, color 0.2s, background 0.2s;
    padding: 4px; border-radius: 4px; display: flex;
    align-items: center; justify-content: center; user-select: none;
}
.action-icon:hover {
    transform: scale(1.1); color: var(--text-muted); background: var(--bg-hover);
}
.status-bar-text { font-size: 13px; color: var(--text-muted); opacity: 0.7; }
