/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #667eea;
    --secondary-color: #764ba2;
    --text-color: #333;
    --bg-color: #ffffff;
    --border-color: #e1e5e9;
    --sidebar-bg: #f8f9fa;
    --code-bg: #f6f8fa;
    --shadow: 0 2px 10px rgba(0,0,0,0.1);
    --header-height: 60px;
}

/* 深色主题 */
[data-theme="dark"] {
    --text-color: #e1e5e9;
    --bg-color: #1a1a1a;
    --border-color: #333;
    --sidebar-bg: #2d2d2d;
    --code-bg: #2d2d2d;
    --shadow: 0 2px 10px rgba(0,0,0,0.3);
}

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

/* 阅读器容器 */
.reader-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 头部 */
.reader-header {
    background: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--header-height);
    box-shadow: var(--shadow);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo a {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary-color);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-actions {
    display: flex;
    gap: 10px;
}

.action-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.action-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* 布局 */
.reader-layout {
    flex: 1;
    display: flex;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* 侧边栏 */
.toc-sidebar {
    width: 280px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    overflow-y: auto;
    transform: translateX(0);
    transition: transform 0.3s ease;
}

.toc-sidebar.show {
    transform: translateX(0);
}

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

.toc-header h3 {
    font-size: 1.1rem;
    color: var(--text-color);
}

.close-toc {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-toc:hover {
    background: var(--border-color);
}

.toc-nav {
    padding: 20px;
}

.toc-nav ul {
    list-style: none;
}

.toc-nav li {
    margin-bottom: 8px;
}

.toc-nav a {
    color: var(--text-color);
    text-decoration: none;
    display: block;
    padding: 8px 12px;
    border-radius: 6px;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.toc-nav a:hover,
.toc-nav a.active {
    background: var(--primary-color);
    color: white;
}

.toc-nav .toc-h2 {
    padding-left: 0;
}

.toc-nav .toc-h3 {
    padding-left: 20px;
    font-size: 0.85rem;
}

.toc-nav .toc-h4 {
    padding-left: 40px;
    font-size: 0.8rem;
}

/* 主内容区 */
.reader-main {
    flex: 1;
    padding: 40px;
    overflow-x: hidden;
}

/* 文档信息 */
.document-info {
    margin-bottom: 30px;
    text-align: center;
}

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 60px 20px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.doc-title {
    font-size: 2rem;
    margin-bottom: 10px;
    color: var(--text-color);
}

.doc-meta {
    color: #666;
    font-size: 0.9rem;
}

/* 文档内容 */
.document-content {
    max-width: 800px;
    margin: 0 auto;
    line-height: 1.8;
}

.document-content h1,
.document-content h2,
.document-content h3,
.document-content h4,
.document-content h5,
.document-content h6 {
    color: var(--text-color);
    margin-top: 2em;
    margin-bottom: 1em;
    font-weight: 600;
    line-height: 1.3;
}

.document-content h1 {
    font-size: 2.2rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.5em;
}

.document-content h2 {
    font-size: 1.8rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3em;
}

.document-content h3 {
    font-size: 1.4rem;
}

.document-content h4 {
    font-size: 1.2rem;
}

.document-content p {
    margin-bottom: 1.2em;
    color: var(--text-color);
}

.document-content a {
    color: var(--primary-color);
    text-decoration: none;
}

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

.document-content ul,
.document-content ol {
    margin-bottom: 1.2em;
    padding-left: 2em;
}

.document-content li {
    margin-bottom: 0.5em;
}

.document-content blockquote {
    border-left: 4px solid var(--primary-color);
    margin: 1.5em 0;
    padding: 1em 1.5em;
    background: var(--code-bg);
    border-radius: 0 8px 8px 0;
}

.document-content code {
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
    color: var(--text-color);
}

.document-content pre {
    background: var(--code-bg);
    padding: 1.5em;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1.5em 0;
    border: 1px solid var(--border-color);
}

.document-content pre code {
    background: none;
    padding: 0;
    border-radius: 0;
}

.document-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5em 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

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

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

.document-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1.5em 0;
    box-shadow: var(--shadow);
}

.document-content hr {
    border: none;
    height: 2px;
    background: var(--border-color);
    margin: 2em 0;
    border-radius: 1px;
}

/* 文档操作 */
.document-actions {
    margin-top: 60px;
    padding-top: 40px;
    border-top: 2px solid var(--border-color);
}

.actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    max-width: 600px;
    margin: 0 auto;
}

.action-card {
    background: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.action-card:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.action-icon {
    font-size: 2rem;
}

.action-text h4 {
    font-size: 1rem;
    margin-bottom: 5px;
}

.action-text p {
    font-size: 0.85rem;
    color: #666;
    margin: 0;
}

/* 阅读进度 */
.reading-progress {
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: 100%;
    height: 3px;
    background: var(--border-color);
    z-index: 99;
}

.progress-bar {
    height: 100%;
    background: var(--border-color);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    width: 0%;
    transition: width 0.1s ease;
}

/* 模态框 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal.show {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--bg-color);
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal.show .modal-content {
    transform: scale(1);
}

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

.modal-header h3 {
    margin: 0;
    color: var(--text-color);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: var(--border-color);
}

.modal-body {
    padding: 20px;
}

.share-url-container {
    display: flex;
    gap: 10px;
    margin: 15px 0;
}

.share-url-container input {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-color);
    color: var(--text-color);
}

.copy-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
}

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

.share-stats {
    margin-top: 20px;
    padding: 15px;
    background: var(--sidebar-bg);
    border-radius: 8px;
    font-size: 0.9rem;
}

/* 通知 */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 25px;
    border-radius: 8px;
    color: white;
    font-weight: 600;
    z-index: 1001;
    transform: translateX(400px);
    transition: all 0.3s ease;
}

.notification.show {
    transform: translateX(0);
}

.notification.success {
    background: #28a745;
}

.notification.error {
    background: #dc3545;
}

.notification.info {
    background: #17a2b8;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .reader-layout {
        flex-direction: column;
    }
    
    .toc-sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        width: 100%;
        height: calc(100vh - var(--header-height));
        z-index: 200;
        transform: translateX(-100%);
    }
    
    .toc-sidebar.show {
        transform: translateX(0);
    }
    
    .reader-main {
        padding: 20px;
    }
    
    .document-content h1 {
        font-size: 1.8rem;
    }
    
    .document-content h2 {
        font-size: 1.5rem;
    }
    
    .actions-grid {
        grid-template-columns: 1fr;
    }
    
    .header-content {
        padding: 0 15px;
    }
    
    .action-btn {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .reader-main {
        padding: 15px;
    }
    
    .document-content {
        font-size: 0.95rem;
    }
    
    .modal-content {
        width: 95%;
        margin: 20px;
    }
}

/* 打印样式 */
@media print {
    .reader-header,
    .toc-sidebar,
    .document-actions,
    .reading-progress,
    .modal,
    .notification {
        display: none !important;
    }
    
    .reader-main {
        padding: 0;
    }
    
    .document-content {
        max-width: none;
        font-size: 12pt;
        line-height: 1.5;
    }
    
    .document-content h1,
    .document-content h2,
    .document-content h3,
    .document-content h4,
    .document-content h5,
    .document-content h6 {
        page-break-after: avoid;
    }
    
    .document-content pre,
    .document-content blockquote {
        page-break-inside: avoid;
    }
}