/* 思源风格 Markdown 博客样式 - 优化版 */
:root {
    --bg-color: #ffffff;
    --text-color: #2c3e50;
    --sidebar-bg: #f8f9fa;
    --border-color: #e1e5e9;
    --accent-color: #4285f4;
    --hover-color: #e8f0fe;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --radius: 8px;
}

[data-theme="dark"] {
    --bg-color: #1e1e1e;
    --text-color: #e0e0e0;
    --sidebar-bg: #2d2d2d;
    --border-color: #404040;
    --accent-color: #4285f4;
    --hover-color: #3a3a3a;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* 基础重置和过渡效果 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    transition: color 0.3s ease, background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* 排除不需要过渡的元素 */
video, canvas, svg, iframe { transition: none !important; }
img { transition: transform 0.3s ease, box-shadow 0.3s ease !important; }

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

/* 应用容器和布局 */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    position: relative;
}

/* 侧边栏通用样式 */
.sidebar-left, .sidebar-right {
    background-color: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-left {
    width: 280px;
    min-width: 200px;
    max-width: 500px;
    border-right: 1px solid var(--border-color);
}

.sidebar-right {
    width: 240px;
    min-width: 200px;
    max-width: 400px;
    border-left: 1px solid var(--border-color);
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--sidebar-bg);
}

.sidebar-header h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-color);
}

/* 按钮通用样式 */
.btn, .refresh-btn, .code-copy-btn {
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    padding: 6px 12px;
}

.refresh-btn, .code-copy-btn {
    background: var(--accent-color);
    color: white;
}

.refresh-btn:hover, .code-copy-btn:hover {
    background: #3367d6;
}

.btn {
    background: var(--sidebar-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 14px;
}

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

.btn.active {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

/* 按钮微交互效果 */
.btn {
    position: relative;
    overflow: hidden;
}

.btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.3s, height 0.3s;
}

.btn:active::after {
    width: 100px;
    height: 100px;
}

/* 文件树和目录样式 */
.file-tree, .outline-container {
    flex: 1;
    overflow-y: auto;
    padding: 8px 16px;
}

.file-item, .category-header, .note-item, .outline-item {
    cursor: pointer;
    transition: background-color 0.2s;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
}

.file-item, .note-item {
    padding: 6px 12px;
    margin: 2px 0;
    font-size: 13px;
}

.file-item:hover, .note-item:hover, .outline-item:hover, .category-header:hover {
    background-color: var(--hover-color);
}

.file-item.active, .note-item.active {
    background-color: var(--accent-color);
    color: white;
}

.file-item .icon {
    width: 16px;
    height: 16px;
    opacity: 0.7;
}

.file-item.active .icon {
    opacity: 1;
}

/* 目录树样式 */
.category-item {
    margin-bottom: 8px;
}

.category-header {
    padding: 8px 12px;
    user-select: none;
}

.category-icon {
    margin-right: 8px;
    font-size: 14px;
}

.category-name {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-color);
}

.expand-icon {
    font-size: 10px;
    color: #666;
    transition: transform 0.2s;
}

.notes-container {
    display: none;
    margin-left: 20px;
}

.category-item.expanded .notes-container {
    display: block;
}

.category-item.expanded .expand-icon {
    transform: rotate(90deg);
}

.note-icon {
    margin-right: 8px;
    font-size: 12px;
}

.note-name {
    flex: 1;
}

/* 大纲导航样式 */
.outline-item {
    padding: 4px 8px;
    margin: 2px 0;
    font-size: 14px;
}

.outline-item.level-1 {
    font-weight: 600;
    margin-left: 0;
}

.outline-item.level-2 {
    margin-left: 16px;
    font-size: 13px;
}

.outline-item.level-3 {
    margin-left: 32px;
    font-size: 12px;
    opacity: 0.8;
}

/* 主内容区域 */
.main-content {
    flex: 1;
    min-width: 400px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--bg-color);
}

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

.content-header h1 {
    font-size: 24px;
    font-weight: 600;
    margin: 0;
}

.content-actions {
    display: flex;
    gap: 8px;
}

.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background-color: var(--bg-color);
    animation: fadeInUp 0.6s ease-out;
}

/* Markdown 内容样式 */
.markdown-body {
    max-width: 800px;
    margin: 0 auto;
    line-height: 1.7;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
    margin: 24px 0 16px;
    font-weight: 600;
    line-height: 1.25;
    color: var(--text-color);
}

.markdown-body h1 {
    font-size: 2em;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

.markdown-body h2 { font-size: 1.5em; }
.markdown-body h3 { font-size: 1.25em; }
.markdown-body p { margin: 16px 0; }

.markdown-body code {
    background-color: var(--sidebar-bg);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.9em;
}

.markdown-body pre {
    background-color: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px;
    overflow-x: auto;
    margin: 16px 0;
    position: relative;
}

.markdown-body pre code {
    background: none;
    padding: 0;
    display: block;
    overflow-x: auto;
}

/* 代码块复制按钮 */
.code-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    opacity: 0;
    z-index: 10;
    transition: opacity 0.3s ease, background-color 0.2s ease;
}

.markdown-body pre:hover .code-copy-btn {
    opacity: 1;
}

.copy-success {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #4caf50;
    color: white;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    z-index: 11;
    animation: fadeOut 2s ease forwards;
}

@keyframes fadeOut {
    0% { opacity: 1; }
    70% { opacity: 1; }
    100% { opacity: 0; }
}

/* 暗色模式下代码块优化 */
[data-theme="dark"] .markdown-body pre,
[data-theme="dark"] pre[class*="language-"] {
    background-color: #1a1a1a !important;
    border-color: #333333 !important;
}

[data-theme="dark"] .markdown-body pre code,
[data-theme="dark"] .markdown-body code:not(pre code),
[data-theme="dark"] code[class*="language-"] {
    background: transparent !important;
    color: #e0e0e0 !important;
}

[data-theme="dark"] .markdown-body code:not(pre code) {
    background-color: #333333 !important;
}

/* Prism.js 暗色模式语法高亮 */
[data-theme="dark"] .token.comment,
[data-theme="dark"] .token.prolog,
[data-theme="dark"] .token.doctype,
[data-theme="dark"] .token.cdata { color: #6a9955; }

[data-theme="dark"] .token.punctuation,
[data-theme="dark"] .token.operator,
[data-theme="dark"] .token.entity,
[data-theme="dark"] .token.url { color: #d4d4d4; }

[data-theme="dark"] .token.property,
[data-theme="dark"] .token.tag,
[data-theme="dark"] .token.boolean,
[data-theme="dark"] .token.number,
[data-theme="dark"] .token.constant,
[data-theme="dark"] .token.symbol,
[data-theme="dark"] .token.deleted { color: #b5cea8; }

[data-theme="dark"] .token.selector,
[data-theme="dark"] .token.attr-name,
[data-theme="dark"] .token.string,
[data-theme="dark"] .token.char,
[data-theme="dark"] .token.builtin,
[data-theme="dark"] .token.inserted { color: #ce9178; }

[data-theme="dark"] .token.atrule,
[data-theme="dark"] .token.attr-value,
[data-theme="dark"] .token.keyword { color: #569cd6; }

[data-theme="dark"] .token.function,
[data-theme="dark"] .token.class-name { color: #dcdcaa; }

[data-theme="dark"] .token.regex,
[data-theme="dark"] .token.important,
[data-theme="dark"] .token.variable { color: #d16969; }

/* Markdown 其他元素 */
.markdown-body blockquote {
    position: relative;
    border-left: 4px solid var(--accent-color);
    padding: 16px 16px 16px 50px;
    margin: 16px 0;
    color: #666;
    background-color: var(--sidebar-bg);
    border-radius: 0 var(--radius) var(--radius) 0;
}

.markdown-body blockquote::before {
    content: '"';
    position: absolute;
    left: 10px;
    top: 10px;
    font-size: 32px;
    color: var(--accent-color);
    opacity: 0.3;
    font-family: serif;
    line-height: 1;
}

.markdown-body table {
    border-collapse: collapse;
    width: 100%;
    margin: 16px 0;
}

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

.markdown-body table th {
    background-color: var(--sidebar-bg);
    font-weight: 600;
}

.markdown-body table tr {
    transition: background-color 0.2s ease;
}

.markdown-body table tr:hover {
    background-color: var(--hover-color);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.markdown-body ul, .markdown-body ol {
    margin: 16px 0;
    padding-left: 24px;
}

.markdown-body li { margin: 4px 0; }

.markdown-body a {
    color: var(--accent-color);
    text-decoration: none;
    position: relative;
    transition: color 0.3s ease;
}

.markdown-body a::after {
    content: '';
    position: absolute;
    width: 0;
    height: 1px;
    bottom: -2px;
    left: 0;
    background: var(--accent-color);
    transition: width 0.3s ease;
}

.markdown-body a:hover::after {
    width: 100%;
}

.markdown-body a:hover {
    color: var(--accent-color);
}

/* 图片样式 */
.markdown-body img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 20px auto;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    background: var(--sidebar-bg);
}

.markdown-body img:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.markdown-body img[width*="50"],
.markdown-body img[style*="width: 50"] { max-width: 50%; }

.markdown-body img[width*="30"],
.markdown-body img[style*="width: 30"] { max-width: 30%; }

.markdown-body .image-caption {
    text-align: center;
    font-style: italic;
    color: #666;
    margin-top: -10px;
    margin-bottom: 20px;
    font-size: 0.9em;
}

.markdown-body img:not([src]) {
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    font-style: italic;
}

.markdown-body img:not([src])::before {
    content: '图片加载中...';
}

/* 编辑器样式 */
.markdown-editor {
    width: 100%;
    height: 100%;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 14px;
    line-height: 1.6;
    background-color: var(--bg-color);
    color: var(--text-color);
    resize: none;
    outline: none;
}

.markdown-editor:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.2);
}

/* 消息和状态样式 */
.empty-message, .error-message, .empty-outline, .welcome-message {
    text-align: center;
    padding: 20px;
    font-size: 14px;
}

.empty-message, .empty-outline, .welcome-message {
    color: #666;
    font-style: italic;
}

.error-message { color: #e74c3c; }

.welcome-message {
    padding: 60px 20px;
}

.welcome-message h2 {
    margin-bottom: 16px;
    color: var(--text-color);
}

/* 加载指示器 */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    color: white;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 拖拽分隔条样式 */
.resizer {
    position: relative;
    background-color: var(--border-color);
    cursor: col-resize;
    transition: all 0.3s ease;
    z-index: 10;
}

.resizer-left, .resizer-right {
    width: 6px;
    min-width: 6px;
    max-width: 6px;
}

.resizer:hover {
    background-color: var(--accent-color);
    box-shadow: 0 0 8px rgba(66, 133, 244, 0.3);
}

.resizer.dragging {
    background-color: var(--accent-color);
    box-shadow: 0 0 12px rgba(66, 133, 244, 0.5);
}

.resizer::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 20px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 1px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.resizer:hover::before {
    opacity: 1;
}

.resizer-mask {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    cursor: col-resize;
}

/* 焦点状态优化 */
.btn:focus, .code-copy-btn:focus, .note-item:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.3);
}

/* 选中文本样式 */
::selection {
    background: rgba(66, 133, 244, 0.3);
    color: inherit;
}

::-moz-selection {
    background: rgba(66, 133, 244, 0.3);
    color: inherit;
}

/* 现代化滚动条样式 */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 5px;
}

::-webkit-scrollbar-track:hover {
    background: rgba(0, 0, 0, 0.05);
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 5px;
    border: 2px solid transparent;
    background-clip: content-box;
    transition: all 0.3s ease;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid transparent;
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:active {
    background: rgba(0, 0, 0, 0.5);
}

::-webkit-scrollbar-corner {
    background: transparent;
}

/* 暗色模式滚动条 */
[data-theme="dark"] ::-webkit-scrollbar-track {
    background: transparent;
}

[data-theme="dark"] ::-webkit-scrollbar-track:hover {
    background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid transparent;
    background-clip: content-box;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.4);
    border: 1px solid transparent;
    background-clip: content-box;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:active {
    background: rgba(255, 255, 255, 0.5);
}

/* 侧边栏专用滚动条 */
.sidebar-left ::-webkit-scrollbar,
.sidebar-right ::-webkit-scrollbar {
    width: 6px;
}

.sidebar-left ::-webkit-scrollbar-track,
.sidebar-right ::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-left ::-webkit-scrollbar-thumb,
.sidebar-right ::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

.sidebar-left ::-webkit-scrollbar-thumb:hover,
.sidebar-right ::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

[data-theme="dark"] .sidebar-left ::-webkit-scrollbar-thumb,
[data-theme="dark"] .sidebar-right ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .sidebar-left ::-webkit-scrollbar-thumb:hover,
[data-theme="dark"] .sidebar-right ::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* 代码块滚动条 */
.markdown-body pre::-webkit-scrollbar {
    height: 8px;
}

.markdown-body pre::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    margin: 4px;
}

.markdown-body pre::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
}

.markdown-body pre::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .markdown-body pre::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .markdown-body pre::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
}

[data-theme="dark"] .markdown-body pre::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* 响应式设计 */
@media (max-width: 1024px) {
    .sidebar-right { display: none; }
    .sidebar-left { width: 240px; }
}

@media (max-width: 768px) {
    .sidebar-left {
        position: absolute;
        left: -280px;
        z-index: 100;
        transition: left 0.3s;
    }
    
    .sidebar-left.active { left: 0; }
    .main-content { margin-left: 0; }
}

/* 目录展开动画 */
.notes-container {
    transition: max-height 0.3s ease;
    max-height: 0;
    overflow: hidden;
}

.category-item.expanded .notes-container {
    max-height: 1000px;
}
