/* Markdown 查看器样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    transition: background 0.3s ease;
}

body.drag-over {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.container {
    width: 100%;
    margin: 0;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 头部样式 */
.header {
    display: flex;
    align-items: baseline;
    gap: 16px;
    margin-bottom: 16px;
    background: rgba(255, 255, 255, 0.95);
    padding: 12px 20px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    backdrop-filter: blur(10px);
}

.header h1 {
    font-size: 1.3rem;
    margin-bottom: 0;
    background: linear-gradient(135deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
}

.header-desc {
    color: #999;
    font-size: 0.85rem;
}

.header-formats {
    color: #bbb;
    font-size: 0.8rem;
}

/* 文件输入区域 */
.file-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.file-input-wrapper input[type="file"] {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.btn-file {
    gap: 6px;
    background: rgba(255, 255, 255, 0.9);
    color: #667eea;
    border: 1px solid rgba(102, 126, 234, 0.3);
}

.btn-file:hover {
    background: #667eea;
    color: #fff;
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(102, 126, 234, 0.35);
}

.file-input-icon {
    font-size: 1rem;
}

.file-input-text {
    white-space: nowrap;
}

.file-info {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    font-size: 0.85rem;
    color: #667eea;
    font-weight: 500;
}

.file-info span {
    margin-right: 0;
}

/* 工具栏 */
.toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.btn-primary {
    background: rgba(255, 255, 255, 0.9);
    color: #667eea;
    border: 1px solid rgba(102, 126, 234, 0.3);
}

.btn-primary:hover {
    background: #667eea;
    color: #fff;
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(102, 126, 234, 0.35);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.9);
    color: #667eea;
    border: 1px solid rgba(102, 126, 234, 0.3);
}

.btn-secondary:hover {
    background: #667eea;
    color: #fff;
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(102, 126, 234, 0.35);
}

/* 工具栏 checkbox */
.toolbar-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(102, 126, 234, 0.3);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: #667eea;
    user-select: none;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.toolbar-checkbox:hover {
    background: #667eea;
    color: #fff;
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(102, 126, 234, 0.35);
}

.toolbar-checkbox:hover input[type="checkbox"] {
    accent-color: #fff;
}

.toolbar-checkbox input[type="checkbox"] {
    accent-color: #667eea;
    width: 15px;
    height: 15px;
    cursor: pointer;
}

/* 内容区域 */
.content-section {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.content-wrapper {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    flex: 1;
    min-height: calc(100vh - 200px);
    width: 100%;
}

.editor-panel,
.preview-panel {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 250px);
    width: 100%;
}

.panel-header {
    background: rgba(102, 126, 234, 0.1);
    padding: 15px 20px;
    border-bottom: 1px solid rgba(102, 126, 234, 0.2);
}

.panel-header h3 {
    color: #667eea;
    font-size: 1.1rem;
    font-weight: 600;
}

#markdownEditor {
    flex: 1;
    padding: 20px;
    border: none;
    outline: none;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
    line-height: 1.6;
    resize: none;
    background: transparent;
    color: #333;
    width: 100%;
    min-height: 400px;
    height: 100%;
}

#markdownEditor::placeholder {
    color: #999;
    font-style: italic;
}

#markdownPreview {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: transparent;
}

.empty-preview {
    color: #999;
    font-style: italic;
    text-align: center;
    margin-top: 50px;
}

/* Markdown 内容样式增强 */
.markdown-body {
    font-size: 16px;
    line-height: 1.6;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
    line-height: 1.25;
    color: #24292e;
}

.markdown-body h1 {
    font-size: 2em;
    border-bottom: 1px solid #eaecef;
    padding-bottom: 0.3em;
}

.markdown-body h2 {
    font-size: 1.5em;
    border-bottom: 1px solid #eaecef;
    padding-bottom: 0.3em;
}

/* 标题编号样式（由JavaScript动态添加） */
.markdown-body .heading-number {
    margin-right: 0.3em;
    font-weight: inherit;
}

/* 段落样式 */
.markdown-body p {
}

.markdown-body code {
    background-color: rgba(27, 31, 35, 0.05);
    border-radius: 3px;
    font-size: 85%;
    margin: 0;
    padding: 0.2em 0.4em;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
}

.markdown-body pre {
    background-color: #f6f8fa;
    border-radius: 6px;
    font-size: 85%;
    line-height: 1.45;
    overflow: auto;
    padding: 16px;
    margin: 16px 0;
    position: relative;
}

.code-block-wrapper {
    position: relative;
    margin: 16px 0;
}

.code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #e1e4e8;
    padding: 8px 12px;
    border-radius: 6px 6px 0 0;
    font-size: 12px;
    color: #586069;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
}

.code-block-header .language {
    font-weight: 600;
}

.copy-code-btn {
    background: #0366d6;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 4px;
}

.copy-code-btn:hover {
    background: #0256cc;
    transform: translateY(-1px);
}

.copy-code-btn:active {
    transform: translateY(0);
}

.copy-code-btn.copied {
    background: #28a745;
}

.code-block-wrapper pre {
    margin: 0;
    border-radius: 0 0 6px 6px;
}

.markdown-body pre code {
    background-color: transparent;
    border: 0;
    display: inline;
    line-height: inherit;
    margin: 0;
    max-width: auto;
    overflow: visible;
    padding: 0;
    word-wrap: normal;
}

.markdown-body blockquote {
    border-left: 0.25em solid #dfe2e5;
    color: #6a737d;
    padding: 0 1em;
    margin: 16px 0;
}

.markdown-body table {
    border-collapse: collapse;
    border-spacing: 0;
    width: 100%;
    margin: 16px 0;
}

.markdown-body table th,
.markdown-body table td {
    border: 1px solid #dfe2e5;
    padding: 6px 13px;
}

.markdown-body table th {
    background-color: #f6f8fa;
    font-weight: 600;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    .header {
        flex-direction: column;
        gap: 4px;
        padding: 10px 16px;
    }

    .header h1 {
        font-size: 1.1rem;
    }
    
    .content-wrapper {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .toolbar {
        flex-direction: column;
        align-items: center;
    }
    
    .btn {
        width: 200px;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1rem;
    }
    
    .btn-file .file-input-text {
        font-size: 0.85rem;
    }
    
    .panel-header {
        padding: 10px 15px;
    }
    
    #markdownEditor,
    #markdownPreview {
        padding: 15px;
    }
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.5);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.7);
}

/* 动画效果 */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.editor-panel,
.preview-panel {
    animation: fadeIn 0.5s ease-out;
}

/* 加载状态 */
.loading {
    position: relative;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #667eea;
    border-top: 2px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Mermaid 图表样式 */
.mermaid {
    text-align: center;
    margin: 20px 0;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
    overflow-x: auto;
}

.mermaid svg {
    max-width: 100%;
    height: auto;
}

/* ===== 目录面板样式 ===== */

/* 目录面板 */
.toc-panel {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 250px);
    width: 100%;
    animation: fadeIn 0.5s ease-out;
}

.toc-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
}

.toc-empty {
    text-align: center;
    color: #999;
    padding: 30px 16px;
    font-size: 0.9rem;
}

.toc-item {
    display: block;
    padding: 6px 16px;
    color: #444;
    text-decoration: none;
    font-size: 0.85rem;
    line-height: 1.5;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toc-item:hover {
    background: rgba(102, 126, 234, 0.08);
    color: #667eea;
}

.toc-item.active {
    background: rgba(102, 126, 234, 0.12);
    border-left-color: #667eea;
    color: #667eea;
    font-weight: 600;
}

/* 目录缩进层级 */
.toc-item[data-level="1"] { padding-left: 16px; font-weight: 600; font-size: 0.9rem; }
.toc-item[data-level="2"] { padding-left: 28px; }
.toc-item[data-level="3"] { padding-left: 40px; }
.toc-item[data-level="4"] { padding-left: 52px; font-size: 0.82rem; }
.toc-item[data-level="5"] { padding-left: 64px; font-size: 0.82rem; }
.toc-item[data-level="6"] { padding-left: 76px; font-size: 0.82rem; }

/* 目录与预览之间的分割条悬停区域 */
.toc-resizer-zone {
    width: 16px;
    flex-shrink: 0;
    align-self: stretch;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: col-resize;
    position: relative;
}

/* 分割条本体：默认透明不可见 */
.toc-resizer {
    width: 4px;
    background: transparent;
    border-radius: 2px;
    transition: background 0.25s, width 0.2s;
    height: 100%;
    position: relative;
}

/* 悬停时显示 */
.toc-resizer-zone:hover .toc-resizer,
.toc-resizer.active {
    background: #667eea;
    width: 5px;
}

.toc-resizer::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 30px;
    background: transparent;
    border-radius: 1px;
    transition: background 0.25s;
}

.toc-resizer-zone:hover .toc-resizer::before,
.toc-resizer.active::before {
    background: rgba(255, 255, 255, 0.6);
}

/* 预览模式（仅预览时）的布局 */
.content-wrapper.preview-only {
    display: flex;
    gap: 0;
}

.content-wrapper.preview-only .toc-panel {
    flex: 0 0 33.33%;
    min-width: 160px;
}

.content-wrapper.preview-only .toc-resizer-zone {
    display: flex;
}

.content-wrapper.preview-only .preview-panel {
    flex: 1;
    min-width: 0;
    min-height: calc(100vh - 250px);
}

/* 拖拽时禁止选中文字 */
body.toc-resizing {
    cursor: col-resize;
    user-select: none;
}

body.toc-resizing * {
    pointer-events: none;
}

/* 目录列表滚动条 */
.toc-list::-webkit-scrollbar {
    width: 6px;
}

.toc-list::-webkit-scrollbar-track {
    background: transparent;
}

.toc-list::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.3);
    border-radius: 3px;
}

.toc-list::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.5);
}

/* ===== 手机端：仅预览模式上下布局 ===== */
@media (max-width: 768px) {
    .content-wrapper.preview-only {
        flex-direction: column;
        gap: 10px;
    }

    .content-wrapper.preview-only .toc-panel {
        flex: 0 0 auto;
        width: 100% !important;
        height: 35vh;
        min-height: 120px;
        max-height: 45vh;
        min-width: unset;
        resize: vertical;
        overflow: auto;
    }

    .content-wrapper.preview-only .toc-resizer-zone {
        display: none;
    }

    .content-wrapper.preview-only .preview-panel {
        flex: 1;
        min-height: 0;
    }
}