/* ===== Variables ===== */
:root {
    --bg-primary: #1e1e1e;
    --bg-secondary: #252525;
    --bg-tertiary: #2d2d2d;
    --bg-hover: #383838;
    --bg-active: #404040;
    
    --text-primary: #dcddde;
    --text-secondary: #a0a0a0;
    --text-muted: #707070;
    
    --accent-purple: #9d7cd8;
    --accent-blue: #7aa2f7;
    --accent-green: #9ece6a;
    --accent-red: #f7768e;
    --accent-yellow: #e0af68;
    
    --border-color: #3a3a3a;
    --shadow: rgba(0, 0, 0, 0.3);
    
    --font-main: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'Fira Code', 'Courier New', monospace;
    
    --sidebar-width: 280px;
    --toolbar-height: 50px;
    
    --transition: 0.2s ease;
}

/* Light Mode */
body.light-mode {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-tertiary: #e8e8e8;
    --bg-hover: #e0e0e0;
    --bg-active: #d0d0d0;
    
    --text-primary: #2e3338;
    --text-secondary: #555555;
    --text-muted: #999999;
    
    --border-color: #d0d0d0;
    --shadow: rgba(0, 0, 0, 0.1);
}

/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

/* ===== App Container ===== */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition);
}

.sidebar.collapsed {
    transform: translateX(-100%);
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo i {
    color: var(--accent-purple);
    font-size: 20px;
}

.logo h1 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

/* Search */
.search-container {
    position: relative;
    padding: 12px;
}

.search-container input {
    width: 100%;
    padding: 8px 35px 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    transition: all var(--transition);
}

.search-container input:focus {
    outline: none;
    border-color: var(--accent-purple);
    background: var(--bg-primary);
}

.search-container i {
    position: absolute;
    right: 24px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 14px;
}

/* Sidebar Actions */
.sidebar-actions {
    padding: 12px;
    display: flex;
    gap: 8px;
    border-bottom: 1px solid var(--border-color);
}

/* File Tree */
.file-tree {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.file-tree::-webkit-scrollbar {
    width: 8px;
}

.file-tree::-webkit-scrollbar-track {
    background: transparent;
}

.file-tree::-webkit-scrollbar-thumb {
    background: var(--bg-active);
    border-radius: 4px;
}

.file-tree::-webkit-scrollbar-thumb:hover {
    background: #505050;
}

/* File Tree Items */
.file-item, .folder-item {
    display: flex;
    align-items: center;
    padding: 6px 10px;
    margin: 2px 0;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 14px;
    transition: all var(--transition);
    user-select: none;
}

.file-item:hover, .folder-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.file-item.active {
    background: var(--bg-active);
    color: var(--accent-purple);
}

.file-item i, .folder-item i {
    margin-right: 8px;
    width: 16px;
    text-align: center;
}

.folder-item i.fa-chevron-right {
    margin-right: 4px;
    font-size: 10px;
    transition: transform var(--transition);
}

.folder-item.open > i.fa-chevron-right {
    transform: rotate(90deg);
}

.folder-content {
    margin-left: 20px;
    display: none;
}

.folder-item.open + .folder-content {
    display: block;
}

/* Sidebar Footer */
.sidebar-footer {
    display: flex;
    gap: 4px;
    padding: 12px;
    border-top: 1px solid var(--border-color);
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Toolbar */
.toolbar {
    height: var(--toolbar-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
}

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

.note-title-container {
    margin-left: 15px;
}

#noteTitle {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
    padding: 8px 12px;
    min-width: 200px;
    border-radius: 4px;
    transition: background var(--transition);
}

#noteTitle:hover {
    background: var(--bg-hover);
}

#noteTitle:focus {
    outline: none;
    background: var(--bg-tertiary);
}

/* Editor Container */
.editor-container {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.editor-container.edit-only .preview-pane {
    display: none;
}

.editor-container.edit-only .editor-pane {
    width: 100%;
}

.editor-container.preview-only .editor-pane {
    display: none;
}

.editor-container.preview-only .preview-pane {
    width: 100%;
}

/* Editor Pane */
.editor-pane {
    width: 50%;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.editor-toolbar {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.editor-toolbar .divider {
    width: 1px;
    background: var(--border-color);
    margin: 0 4px;
}

#editor {
    flex: 1;
    padding: 20px;
    background: var(--bg-primary);
    border: none;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 16px;
    line-height: 1.6;
    resize: none;
    outline: none;
}

#editor::placeholder {
    color: var(--text-muted);
}

/* Preview Pane */
.preview-pane {
    width: 50%;
    overflow-y: auto;
    background: var(--bg-primary);
}

.preview-content {
    padding: 20px;
    max-width: 800px;
    margin: 0 auto;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 400px;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: 0.3;
}

/* Markdown Styling */
.preview-content h1,
.preview-content h2,
.preview-content h3,
.preview-content h4,
.preview-content h5,
.preview-content h6 {
    margin: 1.5em 0 0.5em;
    font-weight: 600;
    color: var(--text-primary);
}

.preview-content h1 { font-size: 2em; }
.preview-content h2 { font-size: 1.5em; }
.preview-content h3 { font-size: 1.25em; }

.preview-content p {
    margin: 0.8em 0;
    line-height: 1.7;
}

.preview-content a {
    color: var(--accent-blue);
    text-decoration: none;
}

.preview-content a:hover {
    text-decoration: underline;
}

.preview-content code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 0.9em;
    color: var(--accent-red);
}

.preview-content pre {
    background: var(--bg-tertiary);
    padding: 15px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 1em 0;
}

.preview-content pre code {
    background: none;
    padding: 0;
    color: var(--text-primary);
}

.preview-content blockquote {
    border-left: 4px solid var(--accent-purple);
    padding-left: 15px;
    margin: 1em 0;
    color: var(--text-secondary);
    font-style: italic;
}

.preview-content ul, .preview-content ol {
    margin: 0.8em 0;
    padding-left: 2em;
}

.preview-content li {
    margin: 0.3em 0;
}

.preview-content hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 2em 0;
}

.preview-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
}

.preview-content th,
.preview-content td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
}

.preview-content th {
    background: var(--bg-secondary);
    font-weight: 600;
}

/* Wiki Links */
.wiki-link {
    color: var(--accent-purple);
    text-decoration: none;
    cursor: pointer;
}

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

.wiki-link.broken {
    color: var(--accent-red);
    opacity: 0.7;
}

/* Tags */
.tag {
    display: inline-block;
    background: var(--bg-tertiary);
    color: var(--accent-green);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.9em;
    margin: 2px;
    cursor: pointer;
}

.tag:hover {
    background: var(--bg-active);
}

/* ===== Buttons ===== */
.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-icon:active {
    background: var(--bg-active);
}

.btn-primary,
.btn-secondary,
.btn-danger {
    padding: 8px 14px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all var(--transition);
}

.btn-primary {
    background: var(--accent-purple);
    color: white;
    flex: 1;
}

.btn-primary:hover {
    background: #8b6fc6;
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    flex: 1;
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

.btn-danger {
    background: var(--accent-red);
    color: white;
    margin-top: 10px;
    width: 100%;
}

.btn-danger:hover {
    background: #e5667c;
}

/* ===== Modal ===== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 8px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 50px var(--shadow);
}

.modal-content.graph-modal {
    max-width: 90%;
    max-height: 90vh;
}

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

.modal-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--bg-active);
    border-radius: 4px;
}

/* Settings */
.settings-group {
    margin-bottom: 30px;
}

.settings-group h3 {
    font-size: 16px;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.setting-item {
    margin-bottom: 15px;
}

.setting-item label {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-secondary);
    cursor: pointer;
}

.setting-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.setting-item input[type="range"] {
    flex: 1;
    margin: 0 10px;
}

#fontSizeValue {
    color: var(--accent-purple);
    font-weight: 600;
    min-width: 50px;
}

/* Graph Canvas */
#graphCanvas {
    width: 100%;
    height: 70vh;
    background: var(--bg-primary);
    border-radius: 6px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        height: 100%;
        z-index: 100;
    }
    
    .editor-container {
        flex-direction: column;
    }
    
    .editor-pane,
    .preview-pane {
        width: 100% !important;
        border-right: none;
    }
    
    .editor-pane {
        border-bottom: 1px solid var(--border-color);
    }
}

/* ===== Animations ===== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.file-item,
.folder-item {
    animation: fadeIn 0.2s ease;
}

/* ===== Selection ===== */
::selection {
    background: var(--accent-purple);
    color: white;
}

