/**
 * 代码高亮和编辑器样式
 * 基于Prism.js的主题和自定义样式
 */

/* 代码高亮主题 - Tomorrow主题 */
.code-highlight, pre[class*="language-"] {
    background: #2d3748;
    color: #f7fafc;
    border-radius: 8px;
    padding: 1.5rem;
    margin: 1rem 0;
    font-family: 'Fira Code', 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9rem;
    line-height: 1.6;
    overflow-x: auto;
    position: relative;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    border: 1px solid #4a5568;
}

.code-highlight pre {
    margin: 0;
    padding: 0;
    background: none;
    border: none;
    color: inherit;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
}

.code-highlight code {
    background: none;
    color: inherit;
    font-family: inherit;
    font-size: inherit;
    padding: 0;
    border: none;
}

/* 代码头部 */
.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #1a202c;
    color: #e2e8f0;
    padding: 0.75rem 1rem;
    border-radius: 8px 8px 0 0;
    margin: -1.5rem -1.5rem 1rem -1.5rem;
    font-size: 0.85rem;
    font-weight: 500;
    border-bottom: 1px solid #4a5568;
}

.code-language {
    background: #4a5568;
    color: #a0aec0;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

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

.code-action-btn {
    background: transparent;
    border: 1px solid #4a5568;
    color: #a0aec0;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.code-action-btn:hover {
    background: #4a5568;
    color: #e2e8f0;
    border-color: #718096;
}

.code-action-btn:active {
    transform: translateY(1px);
}

/* 代码折叠功能 */
.code-fold {
    position: relative;
}

.code-fold.collapsed .code-content {
    max-height: 200px;
    overflow: hidden;
}

.code-fold.collapsed::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: linear-gradient(transparent, #2d3748);
    pointer-events: none;
}

.fold-toggle {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: #4a5568;
    color: #e2e8f0;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    z-index: 10;
    transition: all 0.2s ease;
}

.fold-toggle:hover {
    background: #718096;
}

/* 行号 */
.code-with-lines {
    display: flex;
    background: #2d3748;
    border-radius: 8px;
    overflow: hidden;
}

.line-numbers {
    background: #1a202c;
    color: #718096;
    padding: 1rem 0.75rem;
    margin: -1.5rem 0 -1.5rem -1.5rem;
    border-radius: 8px 0 0 8px;
    font-family: 'Fira Code', 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9rem;
    line-height: 1.6;
    text-align: right;
    user-select: none;
    border-right: 1px solid #4a5568;
    min-width: 3rem;
}

.code-content {
    flex: 1;
    overflow-x: auto;
    padding-left: 1.5rem;
}

.code-fold.collapsed .code-content::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 30px;
    background: linear-gradient(transparent, #2d3748);
}

.fold-toggle {
    position: absolute;
    bottom: 10px;
    right: 15px;
    background: #4a5568;
    color: #e2e8f0;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    z-index: 10;
}

.fold-toggle:hover {
    background: #718096;
}

/* 代码差异显示 */
.code-diff .line-added {
    background: rgba(72, 187, 120, 0.2);
    border-left: 3px solid #48bb78;
}

.code-diff .line-removed {
    background: rgba(245, 101, 101, 0.2);
    border-left: 3px solid #f56565;
}

.code-diff .line-modified {
    background: rgba(246, 173, 85, 0.2);
    border-left: 3px solid #f6ad55;
}

/* 代码搜索高亮 */
.code-search-highlight {
    background: #faf089;
    color: #2d3748;
    padding: 2px 4px;
    border-radius: 2px;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .code-highlight {
        font-size: 12px;
        padding: 10px;
    }
    
    .code-header {
        padding: 6px 10px;
        margin: -10px -10px 10px -10px;
        font-size: 11px;
    }
    
    .line-numbers {
        padding: 10px 8px;
        margin: -10px 0 -10px -10px;
        min-width: 35px;
    }
    
    .code-content {
        padding-left: 10px;
    }
    
    .code-action-btn {
        font-size: 10px;
        padding: 3px 6px;
    }
}

/* 打印样式 */
@media print {
    .code-highlight {
        background: #f8f9fa !important;
        color: #333 !important;
        border: 1px solid #dee2e6;
    }
    
    .code-header {
        background: #e9ecef !important;
        color: #495057 !important;
    }
    
    .line-numbers {
        background: #f8f9fa !important;
        color: #6c757d !important;
    }
    
    .code-actions {
        display: none;
    }
}

/* 主题变体 */
.code-highlight.theme-light {
    background: #f8f9fa;
    color: #333;
}

.code-highlight.theme-light .code-header {
    background: #e9ecef;
    color: #495057;
}

.code-highlight.theme-light .line-numbers {
    background: #f1f3f4;
    color: #6c757d;
}

/* 动画效果 */
.code-highlight {
    transition: all 0.3s ease;
}

.code-highlight:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.code-action-btn {
    transition: all 0.2s ease;
}

.fold-toggle {
    transition: all 0.2s ease;
}

/* 滚动条样式 */
.code-highlight::-webkit-scrollbar {
    height: 8px;
}

.code-highlight::-webkit-scrollbar-track {
    background: #1a202c;
    border-radius: 4px;
}

.code-highlight::-webkit-scrollbar-thumb {
    background: #4a5568;
    border-radius: 4px;
}

.code-highlight::-webkit-scrollbar-thumb:hover {
    background: #718096;
}