/* ========================================
   OPC 文档中心 - 样式表
   ======================================== */

:root {
    /* 主题色 - 现代渐变紫蓝 */
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --secondary-color: #06b6d4;
    --accent-color: #f472b6;
    
    /* 背景色 */
    --background: #f1f5f9;
    --background-gradient: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
    --sidebar-bg: #0f172a;
    --sidebar-gradient: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    --sidebar-text: #f1f5f9;
    
    /* 卡片和文字 */
    --card-bg: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    
    /* 状态色 */
    --success: #10b981;
    --warning: #f59e0b;
    --info: #3b82f6;
    --error: #ef4444;
    
    /* 阴影升级 - 更柔和有层次 */
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.12);
    --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.15);
    --glow: 0 0 20px rgba(99, 102, 241, 0.3);
}

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

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

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

/* ========================================
   侧边栏
   ======================================== */

.sidebar {
    width: 280px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    overflow: hidden;
}

.logo {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    background: var(--sidebar-gradient);
}

.logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 30px rgba(99, 102, 241, 0.3);
}

.logo span {
    font-size: 0.875rem;
    color: #94a3b8;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.tree-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
}

.tree-nav::-webkit-scrollbar {
    width: 6px;
}

.tree-nav::-webkit-scrollbar-track {
    background: transparent;
}

.tree-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

/* 目录树样式 */
.tree-item {
    user-select: none;
}

.tree-folder {
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: background 0.2s;
}

.tree-folder:hover {
    background: rgba(255, 255, 255, 0.1);
}

.tree-folder.active {
    background: rgba(79, 70, 229, 0.3);
}

.tree-icon {
    width: 20px;
    height: 20px;
    margin-right: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--secondary-color);
}

.tree-icon.folder {
    color: #fbbf24;
}

.tree-icon.file {
    color: #94a3b8;
}

.tree-icon.md {
    color: #3b82f6;
}

.tree-icon.pdf {
    color: #ef4444;
}

.tree-arrow {
    width: 16px;
    height: 16px;
    margin-right: 0.25rem;
    transition: transform 0.2s;
    color: #64748b;
}

.tree-arrow.expanded {
    transform: rotate(90deg);
}

.tree-name {
    font-size: 0.875rem;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-children {
    padding-left: 1rem;
    display: none;
}

.tree-children.expanded {
    display: block;
}

.tree-file {
    display: flex;
    align-items: center;
    padding: 0.4rem 1rem 0.4rem 2.25rem;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 0.875rem;
}

.tree-file:hover {
    background: rgba(255, 255, 255, 0.1);
}

.tree-file.active {
    background: var(--primary-color);
}

/* ========================================
   主内容区
   ======================================== */

.main-content {
    flex: 1;
    margin-left: 280px;
    display: flex;
    flex-direction: column;
}

.content-header {
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.breadcrumb-item {
    color: var(--text-secondary);
}

.breadcrumb-item:not(:last-child)::after {
    content: '/';
    margin-left: 0.5rem;
    color: var(--border-color);
}

.breadcrumb-item:last-child {
    color: var(--text-primary);
    font-weight: 500;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-icon {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.2s;
}

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

.content-body {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

/* ========================================
   欢迎页面 - 视觉升级
   ======================================== */

.welcome-page {
    max-width: 1000px;
    margin: 0 auto;
}

.welcome-page h2 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.welcome-page .subtitle {
    color: var(--text-secondary);
    font-size: 1.25rem;
    margin-bottom: 2.5rem;
    font-weight: 400;
}

.quick-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.stat-card {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    text-align: center;
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--primary-gradient);
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-xl), var(--glow);
}

.stat-card:hover::before {
    transform: scaleX(1);
}

.stat-number {
    font-size: 3rem;
    font-weight: 800;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1;
    margin-bottom: 0.5rem;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.section-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.section-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 1.75rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.section-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--primary-gradient);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 0;
}

.section-card:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: var(--shadow-xl), var(--glow);
    border-color: transparent;
}

.section-card:hover::after {
    opacity: 0.05;
}

.section-card > * {
    position: relative;
    z-index: 1;
}

.section-card h3 {
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.section-card p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1.25rem;
    line-height: 1.6;
}

.section-card .card-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.section-card .tag {
    background: var(--background);
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.75rem;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.section-card:hover .tag {
    background: var(--primary-color);
    color: white;
}

.tag.cashflow { background: linear-gradient(135deg, #dcfce7 0%, #86efac 100%); color: #166534; }
.tag.traffic { background: linear-gradient(135deg, #dbeafe 0%, #93c5fd 100%); color: #1e40af; }
.tag.profit { background: linear-gradient(135deg, #fef3c7 0%, #fcd34d 100%); color: #92400e; }
.tag.asset { background: linear-gradient(135deg, #f3e8ff 0%, #d8b4fe 100%); color: #6b21a8; }
.tag.tech { background: linear-gradient(135deg, #fce7f3 0%, #f9a8d4 100%); color: #9d174d; }
.tag.moat { background: linear-gradient(135deg, #e0e7ff 0%, #a5b4fc 100%); color: #3730a3; }

/* ========================================
   文件内容区
   ======================================== */

.file-content {
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.file-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
}

.file-header h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.file-meta {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.file-body {
    padding: 2rem;
    min-height: 400px;
    background: var(--card-bg);
}

.file-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    color: var(--text-secondary);
}

.file-placeholder p {
    margin-bottom: 0.5rem;
}

.file-placeholder .hint {
    font-size: 0.875rem;
    color: var(--text-secondary);
    opacity: 0.7;
}

/* Markdown 内容样式 */
.markdown-body {
    line-height: 1.8;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
}

.markdown-body h1 { font-size: 1.75rem; border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem; }
.markdown-body h2 { font-size: 1.5rem; }
.markdown-body h3 { font-size: 1.25rem; }

.markdown-body p {
    margin-bottom: 1rem;
}

.markdown-body ul, .markdown-body ol {
    margin-bottom: 1rem;
    padding-left: 2rem;
}

.markdown-body code {
    background: var(--background);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'Fira Code', monospace;
    font-size: 0.875em;
}

.markdown-body pre {
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 1rem;
}

.markdown-body pre code {
    background: transparent;
    padding: 0;
}

.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
}

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

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

.markdown-body blockquote {
    border-left: 4px solid var(--primary-color);
    padding-left: 1rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

/* ========================================
   响应式设计
   ======================================== */

@media (max-width: 1024px) {
    .section-cards {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s;
        z-index: 100;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .quick-stats {
        grid-template-columns: 1fr;
    }
}

/* ========================================
   动画效果
   ======================================== */

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

.welcome-page, .file-content {
    animation: fadeIn 0.3s ease;
}

/* 加载状态 */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.loading::after {
    content: '';
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========================================
   PDF 查看器
   ======================================== */

.pdf-viewer {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 120px);
}

.pdf-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: #f1f5f9;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 0.5rem;
}

.pdf-nav, .pdf-zoom, .pdf-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.pdf-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--card-bg);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.2s;
}

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

.pdf-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pdf-page-info {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.pdf-page-info input {
    width: 48px;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    text-align: center;
    font-size: 0.875rem;
}

.pdf-zoom-level {
    font-size: 0.875rem;
    color: var(--text-secondary);
    min-width: 48px;
    text-align: center;
}

.pdf-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 1rem;
    background: #525659;
    overflow: auto;
    min-height: 500px;
}

#pdfCanvas {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    background: white;
}

.pdf-loading, .pdf-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    color: var(--text-secondary);
}

.pdf-loading {
    background: rgba(255, 255, 255, 0.9);
    padding: 2rem 3rem;
    border-radius: 12px;
}

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

.pdf-error {
    background: rgba(255, 255, 255, 0.95);
    padding: 2rem 3rem;
    border-radius: 12px;
}

.error-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

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

.error-detail {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.error-download {
    margin-top: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--primary-color);
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.875rem;
    transition: background 0.2s;
}

.error-download:hover {
    background: var(--primary-hover);
}

/* 全屏模式 */
.pdf-viewer:fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    border-radius: 0;
}

.pdf-viewer:fullscreen .pdf-container {
    height: calc(100vh - 56px);
}

/* ========================================
   搜索功能
   ======================================== */

.search-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: relative;
}

.search-box input {
    width: 200px;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.875rem;
    outline: none;
    transition: all 0.2s;
}

.search-box input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
    width: 280px;
}

.search-results {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    min-width: 320px;
    max-height: 400px;
    overflow-y: auto;
    z-index: 100;
}

.search-empty {
    padding: 1.5rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid var(--border-color);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: var(--background);
}

.search-icon {
    font-size: 1.25rem;
}

.search-name {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.search-path {
    font-size: 0.75rem;
    color: var(--text-secondary);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-match {
    font-size: 0.625rem;
    padding: 0.15rem 0.4rem;
    background: var(--primary-color);
    color: white;
    border-radius: 4px;
    text-transform: uppercase;
    font-weight: 600;
}

/* 错误消息样式 */
.error-message {
    padding: 2rem;
    text-align: center;
    color: #94a3b8;
}

.error-message .hint {
    font-size: 0.875rem;
    color: #64748b;
    margin-top: 0.5rem;
}