:root {
    --primary: #4a90e2;
    --primary-hover: #357abd;
    --primary-light: rgba(74, 144, 226, 0.1);
    --danger: #e74c3c;
    --danger-hover: #c0392b;
    --success: #2ecc71;
    --bg: #f0f2f5;
    --sidebar-bg: #1e293b;
    --sidebar-hover: rgba(255, 255, 255, 0.08);
    --sidebar-active: rgba(74, 144, 226, 0.3);
    --sidebar-text: #e2e8f0;
    --sidebar-muted: rgba(255, 255, 255, 0.5);
    --sidebar-border: rgba(255, 255, 255, 0.1);
    --card-bg: #ffffff;
    --text: #1a1a2e;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --input-bg: #f8fafc;
    --hover-bg: #f1f5f9;
    --code-bg: #f1f5f9;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
    --radius: 10px;
    --radius-sm: 6px;
    --transition: 0.2s ease;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --sidebar-bg: #1e293b;
    --sidebar-hover: rgba(255, 255, 255, 0.06);
    --sidebar-active: rgba(74, 144, 226, 0.25);
    --sidebar-text: #e2e8f0;
    --sidebar-muted: rgba(255, 255, 255, 0.4);
    --card-bg: #1e293b;
    --text: #e2e8f0;
    --text-secondary: #94a3b8;
    --border: #334155;
    --input-bg: #0f172a;
    --hover-bg: #334155;
    --code-bg: #0f172a;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.4);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    transition: background var(--transition), color var(--transition);
}

.btn {
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.btn-primary { background: var(--primary); color: white; padding: 8px 16px; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--hover-bg); color: var(--text); padding: 8px 16px; }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: white; padding: 8px 16px; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-text { background: transparent; color: var(--text-secondary); padding: 6px 10px; }
.btn-text:hover { color: var(--text); background: var(--hover-bg); }
.btn-small { padding: 5px 10px; font-size: 0.8rem; }

.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 1100;
    background: var(--sidebar-bg);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1.3rem;
    width: 38px;
    height: 38px;
    cursor: pointer;
}

.dark-mode-toggle {
    position: fixed;
    top: 14px;
    right: 14px;
    z-index: 1100;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 50%;
    font-size: 1.1rem;
    width: 36px;
    height: 36px;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: all var(--transition);
}
.dark-mode-toggle:hover { transform: scale(1.1); }

.app-container { display: flex; height: 100vh; }

.sidebar {
    width: 320px;
    min-width: 320px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--sidebar-border);
    transition: transform 0.3s ease;
}

.sidebar-header { padding: 20px; border-bottom: 1px solid var(--sidebar-border); }
.sidebar-header h1 { font-size: 1.3rem; font-weight: 700; margin-bottom: 12px; }
.sidebar-actions { display: flex; gap: 8px; margin-bottom: 10px; }
.sidebar-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--sidebar-muted);
}
.sidebar-info .btn { color: var(--sidebar-muted); }
.sidebar-info .btn:hover { color: var(--sidebar-text); }

.search-box { padding: 12px 16px; border-bottom: 1px solid var(--sidebar-border); }
.search-box input {
    width: 100%;
    padding: 9px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.08);
    color: var(--sidebar-text);
    font-size: 0.9rem;
    outline: none;
    transition: all var(--transition);
}
.search-box input::placeholder { color: var(--sidebar-muted); }
.search-box input:focus { background: rgba(255, 255, 255, 0.12); border-color: var(--primary); }

.note-list { flex: 1; overflow-y: auto; padding: 8px; }
.note-list-empty {
    text-align: center;
    color: var(--sidebar-muted);
    padding: 40px 20px;
    font-size: 0.9rem;
}

.note-item {
    padding: 14px 16px;
    margin-bottom: 4px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}
.note-item:hover { background: var(--sidebar-hover); }
.note-item.selected { background: var(--sidebar-active); }
.note-item-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.note-item-preview {
    font-size: 0.82rem;
    color: var(--sidebar-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 6px;
}
.note-item-date { font-size: 0.72rem; color: var(--sidebar-muted); opacity: 0.7; }

.editor-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    min-width: 0;
    transition: background var(--transition);
    position: relative;
}

.editor-area.drag-over::after {
    content: "\1F4E5 \62D6\62FD\6587\4EF6\5230\6B64\5904\5BFC\5165";
    position: absolute;
    inset: 20px;
    background: rgba(74, 144, 226, 0.15);
    border: 3px dashed var(--primary);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    color: var(--primary);
    font-weight: 600;
    z-index: 100;
    pointer-events: none;
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    padding: 40px;
    text-align: center;
}
.empty-icon { font-size: 4rem; margin-bottom: 20px; opacity: 0.4; }
.empty-state h2 { font-size: 1.4rem; margin-bottom: 10px; font-weight: 600; }
.empty-state p { font-size: 0.95rem; opacity: 0.7; margin-bottom: 6px; }
.empty-hint { font-size: 0.85rem; opacity: 0.5; margin-top: 8px; }

.editor { flex: 1; display: flex; flex-direction: column; }
.editor-header { padding: 20px 30px; border-bottom: 1px solid var(--border); }
.title-input {
    width: 100%;
    border: none;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    background: transparent;
    outline: none;
    margin-bottom: 8px;
}
.title-input::placeholder { color: var(--text-secondary); opacity: 0.5; }
.editor-meta { display: flex; gap: 16px; font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 12px; }
.editor-toolbar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.editor-body { flex: 1; position: relative; }

#contentArea {
    width: 100%;
    height: 100%;
    padding: 24px 30px;
    border: none;
    resize: none;
    font-size: 1rem;
    line-height: 1.8;
    color: var(--text);
    background: transparent;
    outline: none;
    font-family: inherit;
}
#contentArea::placeholder { color: var(--text-secondary); opacity: 0.4; }

.markdown-preview {
    padding: 24px 30px;
    line-height: 1.8;
    font-size: 1rem;
    overflow-y: auto;
    height: 100%;
}
.markdown-preview h1 { font-size: 1.8rem; margin: 20px 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.markdown-preview h2 { font-size: 1.5rem; margin: 18px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.markdown-preview h3 { font-size: 1.25rem; margin: 14px 0 8px; }
.markdown-preview p { margin: 8px 0; }
.markdown-preview strong { font-weight: 700; }
.markdown-preview em { font-style: italic; }
.markdown-preview code {
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: "Fira Code", Consolas, monospace;
    font-size: 0.9em;
}
.markdown-preview blockquote {
    border-left: 4px solid var(--primary);
    padding: 8px 16px;
    margin: 12px 0;
    color: var(--text-secondary);
    background: var(--primary-light);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.markdown-preview ul, .markdown-preview ol { padding-left: 24px; margin: 8px 0; }
.markdown-preview li { margin: 4px 0; }
.markdown-preview hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

.dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(4px);
}
.dialog {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 28px;
    width: 90%;
    max-width: 480px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.dialog h3 { font-size: 1.2rem; margin-bottom: 16px; }
.dialog p { color: var(--text-secondary); margin-bottom: 20px; line-height: 1.6; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.trash-list { max-height: 300px; overflow-y: auto; margin-bottom: 10px; }
.trash-empty { text-align: center; color: var(--text-secondary); padding: 20px; opacity: 0.6; }
.trash-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    margin-bottom: 8px;
    transition: background var(--transition);
}
.trash-item:hover { background: var(--hover-bg); }
.trash-item-info { flex: 1; min-width: 0; }
.trash-item-title {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.trash-item-date { font-size: 0.75rem; color: var(--text-secondary); }
.trash-item-actions { margin-left: 12px; }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, 0.25); }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); }
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.25); }

@media (max-width: 768px) {
    .mobile-menu-btn { display: block; }
    .dark-mode-toggle { top: 14px; right: 14px; }
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        z-index: 1000;
        box-shadow: none;
        width: 280px;
        min-width: 280px;
    }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .editor-header { padding: 16px 16px 16px 56px; }
    .title-input { font-size: 1.2rem; }
    #contentArea, .markdown-preview { padding: 16px; }
    .editor-toolbar { gap: 4px; }
    .btn-small { padding: 4px 8px; font-size: 0.75rem; }
}

@media (max-width: 480px) {
    .editor-header { padding: 14px 12px 14px 52px; }
    .editor-toolbar { width: 100%; justify-content: flex-end; }
    .editor-meta { flex-wrap: wrap; gap: 8px; }
}
