/* Reset */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: #1A202C;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
a { color: inherit; text-decoration: none; }

.app { display: flex; flex: 1; min-height: 0; }

/* Sidebar */
.sidebar {
    width: 300px;
    min-width: 300px;
    border-right: 1px solid #E2E8F0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background: #fff;
}
.sidebar-header {
    padding: 16px 20px;
}
.btn-refresh {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 20px;
    border: 2px solid #E53E3E;
    border-radius: 20px;
    background: #fff;
    color: #E53E3E;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.btn-refresh:hover { background: #FFF5F5; }
.sidebar-search {
    padding: 0 8px 8px;
}
.search-input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #E2E8F0;
    border-radius: 4px;
    font-size: 13px;
    color: #1A202C;
    background: #FFFFFF;
    outline: none;
    box-sizing: border-box;
}
.search-input:focus {
    border-color: #E53E3E;
}
.search-input::placeholder {
    color: #A0AEC0;
}
.search-results {
    padding-top: 4px;
}
.search-result-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    font-size: 13px;
    color: #4A5568;
    border-radius: 4px;
    cursor: pointer;
}
.search-result-item:hover {
    background: #F7FAFC;
}
.search-result-path {
    margin-left: auto;
    font-size: 11px;
    color: #A0AEC0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}
.search-empty {
    padding: 8px;
    font-size: 13px;
    color: #A0AEC0;
}
.sidebar-tree {
    flex: 1;
    padding: 0 8px 16px;
    overflow-y: auto;
}
.storage-section {
    margin-bottom: 12px;
}
.storage-header {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #718096;
    padding: 10px 8px 4px;
    border-bottom: 1px solid #E2E8F0;
    margin-bottom: 4px;
}
.tree-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.tree-list .tree-list {
    padding-left: 20px;
}
.tree-item { padding: 2px 0; }
.tree-folder-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #1A202C;
    width: 100%;
    text-align: left;
    border-radius: 4px;
}
.tree-folder-toggle:hover { background: #F7FAFC; }
.tree-folder-toggle .arrow {
    display: inline-block;
    width: 16px;
    font-size: 10px;
    color: #718096;
    transition: transform .15s;
    flex-shrink: 0;
}
.tree-folder-toggle.open .arrow { transform: rotate(90deg); }
.tree-note {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px 4px 28px;
    font-size: 14px;
    color: #4A5568;
    border-radius: 4px;
    cursor: pointer;
}
.tree-note:hover { background: #F7FAFC; }
.tree-note.active { background: #EDF2F7; color: #E53E3E; font-weight: 500; }
.tree-note-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    color: #A0AEC0;
}
.tree-children { display: none; }
.tree-children.open { display: block; }

/* Content area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #fff;
}
.content-header {
    border-bottom: 1px solid #E2E8F0;
}
.tab-bar {
    display: flex;
    align-items: center;
    padding: 0;
    background: #F7FAFC;
    border-bottom: 1px solid #E2E8F0;
}
.tab-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    font-size: 14px;
    color: #4A5568;
    background: #fff;
    border-right: 1px solid #E2E8F0;
}
.tab-close {
    width: 16px;
    height: 16px;
    border: none;
    background: none;
    cursor: pointer;
    color: #A0AEC0;
    font-size: 16px;
    line-height: 1;
}
.tab-close:hover { color: #E53E3E; }
.nav-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
}
.nav-arrow {
    width: 28px;
    height: 28px;
    border: 1px solid #E2E8F0;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #718096;
    font-size: 14px;
}
.nav-arrow:hover { background: #F7FAFC; }
.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: #718096;
    margin-left: 8px;
}
.breadcrumbs span { color: #A0AEC0; }
.content-body {
    flex: 1;
    padding: 24px 32px;
    overflow-y: auto;
}
.content-body h1 { font-size: 28px; font-weight: 700; margin-bottom: 12px; }
.tags { display: flex; gap: 8px; margin-bottom: 20px; }
.tag {
    display: inline-block;
    padding: 4px 12px;
    border: 1px solid #E53E3E;
    border-radius: 16px;
    font-size: 13px;
    color: #E53E3E;
}
.content-body p { font-size: 15px; line-height: 1.7; margin-bottom: 8px; }
.content-body h2 { font-size: 22px; font-weight: 600; margin: 20px 0 12px; }
.content-body ul { padding-left: 24px; margin-bottom: 12px; }
.content-body li { font-size: 15px; line-height: 1.7; }
.welcome-message {
    color: #718096;
    font-size: 15px;
    margin-top: 40px;
    text-align: center;
}

/* Footer */
.footer {
    background: #E2E8F0;
    padding: 12px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: #718096;
}
.footer a { color: #718096; }
.footer a:hover { color: #4A5568; }

/* User menu */
.user-menu {
    position: absolute;
    top: 12px;
    right: 16px;
    font-size: 13px;
    color: #718096;
}
.user-menu a {
    color: #E53E3E;
    margin-left: 12px;
}
.user-menu a:hover { text-decoration: underline; }

/* Note content (markdown) */
.content-body .note-title { margin: 0 0 1rem; font-size: 1.5rem; font-weight: 600; color: #1A202C; border-bottom: 2px solid #E2E8F0; padding-bottom: 0.5rem; }
.content-body .note-content h1 { font-size: 1.6rem; margin: 1.5rem 0 0.75rem; color: #1A202C; }
.content-body .note-content h2 { font-size: 1.35rem; margin: 1.25rem 0 0.6rem; color: #1A202C; }
.content-body .note-content h3 { font-size: 1.15rem; margin: 1rem 0 0.5rem; color: #1A202C; }
.content-body .note-content p { margin: 0.5rem 0; line-height: 1.7; }
.content-body .note-content ul,
.content-body .note-content ol { padding-left: 1.5rem; margin: 0.5rem 0; }
.content-body .note-content li { margin: 0.25rem 0; line-height: 1.6; }
.content-body .note-content code { background: #EDF2F7; padding: 0.15rem 0.4rem; border-radius: 3px; font-size: 0.9em; color: #E53E3E; }
.content-body .note-content pre { background: #2D3748; color: #E2E8F0; padding: 1rem; border-radius: 6px; overflow-x: auto; margin: 0.75rem 0; }
.content-body .note-content pre code { background: none; color: inherit; padding: 0; }
.content-body .note-content blockquote { border-left: 4px solid #E53E3E; padding: 0.5rem 1rem; margin: 0.75rem 0; background: #FFF5F5; color: #718096; }
.content-body .note-content table { border-collapse: collapse; width: 100%; margin: 0.75rem 0; }
.content-body .note-content th,
.content-body .note-content td { border: 1px solid #E2E8F0; padding: 0.5rem 0.75rem; text-align: left; }
.content-body .note-content th { background: #F7FAFC; font-weight: 600; }
.content-body .note-content a { color: #E53E3E; text-decoration: none; }
.content-body .note-content a:hover { text-decoration: underline; }
.content-body .note-content img { max-width: 100%; height: auto; border-radius: 4px; }
.content-body .note-content .internal-link { color: #E53E3E; text-decoration: none; cursor: pointer; border-bottom: 1px dashed #E53E3E; }
.content-body .note-content .internal-link:hover { text-decoration: none; border-bottom-style: solid; }
.content-body .note-content .internal-link-broken { color: #A0AEC0; border-bottom: 1px dashed #A0AEC0; }
.content-body .loading { color: #718096; font-style: italic; }
.content-body .error { color: #E53E3E; }

/* Mobile sidebar toggle */
.sidebar-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 1000;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: #E53E3E;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    align-items: center;
    justify-content: center;
}
.sidebar-toggle svg { width: 22px; height: 22px; }
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99;
}

/* Responsive */
@media (max-width: 768px) {
    /* Public layout */
    .app { flex-direction: column; }
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 100;
        width: 280px;
        min-width: 280px;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: none;
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 16px rgba(0,0,0,0.15);
    }
    .sidebar-overlay.open { display: block; }
    .sidebar-toggle { display: flex; }
    .main-content { min-height: 0; }
    .content-body { padding: 16px; }
    .content-body h1 { font-size: 22px; }
    .content-body h2 { font-size: 18px; }
    .user-menu {
        position: static;
        text-align: right;
        padding: 8px 16px;
        border-bottom: 1px solid #E2E8F0;
    }
    .footer {
        flex-direction: column;
        gap: 4px;
        text-align: center;
        padding: 12px 16px;
    }

    /* Note content */
    .content-body .note-title { font-size: 1.2rem; }
    .content-body .note-content pre { font-size: 13px; padding: 0.75rem; }
    .content-body .note-content table { display: block; overflow-x: auto; }
}
