/* ===================================
   Markdown 编辑器组件样式
   可复用的Markdown工具栏和编辑器
   =================================== */

/* 链接/图片输入弹窗动画 */
@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Markdown 工具栏样式 */
.markdown-toolbar {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    padding: 6px 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    align-items: center;
}

.markdown-toolbar-btn {
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 3px;
    padding: 4px 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 26px;
    height: 26px;
    color: #495057;
}

.markdown-toolbar-btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.markdown-toolbar-btn.wide {
    min-width: auto;
    padding: 4px 8px;
}

.markdown-toolbar-btn:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.markdown-toolbar-btn:active {
    background: #dee2e6;
    transform: scale(0.95);
}

.markdown-toolbar-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.markdown-toolbar-btn:disabled:hover {
    background: white;
    border-color: #dee2e6;
}

.markdown-toolbar-divider {
    width: 1px;
    height: 20px;
    background: #dee2e6;
    margin: 0 2px;
}

.markdown-toolbar + textarea {
    border-radius: 0 0 6px 6px;
    border-top-color: #dee2e6;
}

/* 颜色选择器样式 */
.color-btn {
    width: 18px;
    height: 18px;
    border: 1.5px solid white;
    border-radius: 2px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
    padding: 0;
}

.color-btn:hover {
    transform: scale(1.2);
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    border-color: #667eea;
    z-index: 1;
}

.color-btn:active {
    transform: scale(1.1);
}

/* 预览区域样式 */
.markdown-preview-area {
    display: none;
    border: 1px solid #dee2e6;
    border-top: none;
    border-bottom: none;
    background: #f8f9fa;
    max-height: 400px;
    overflow-y: auto;
}

.markdown-preview-area.active {
    display: block;
}

.markdown-preview-content {
    background: white;
    border-radius: 6px;
    margin: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    padding: 20px;
    line-height: 1.8;
    color: #333;
    font-size: 15px;
    overflow-y: auto;
    word-wrap: break-word;
    word-break: break-word;
    -webkit-overflow-scrolling: touch;
    min-height: 200px;
    user-select: text;  /* 允许选择文本 */
    cursor: text;  /* 文本光标 */
}

/* 预览区选中文本的样式 */
.markdown-preview-content ::selection {
    background: rgba(102, 126, 234, 0.3);
    color: inherit;
}

.markdown-preview-content ::-moz-selection {
    background: rgba(102, 126, 234, 0.3);
    color: inherit;
}

/* Markdown 渲染内容样式 */
.markdown-preview-content h1,
.markdown-preview-content h2,
.markdown-preview-content h3,
.markdown-preview-content h4,
.markdown-preview-content h5,
.markdown-preview-content h6 {
    margin-top: 1em;
    margin-bottom: 0.5em;
    font-weight: bold;
    color: #667eea;
}

.markdown-preview-content h1 {
    font-size: 1.8em;
    border-bottom: 2px solid #667eea;
    padding-bottom: 0.3em;
}

.markdown-preview-content h2 {
    font-size: 1.5em;
    border-bottom: 1px solid #ddd;
    padding-bottom: 0.3em;
}

.markdown-preview-content h3 {
    font-size: 1.3em;
}

.markdown-preview-content h4 {
    font-size: 1.1em;
}

.markdown-preview-content p {
    margin-bottom: 1em;
}

.markdown-preview-content ul,
.markdown-preview-content ol {
    margin-bottom: 1em;
    padding-left: 2em;
}

.markdown-preview-content li {
    margin-bottom: 0.3em;
}

.markdown-preview-content code {
    background: #f5f5f5;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    color: #e83e8c;
}

.markdown-preview-content pre {
    background: #f5f5f5;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin-bottom: 1em;
    border-left: 4px solid #667eea;
}

.markdown-preview-content pre code {
    background: transparent;
    padding: 0;
    color: #333;
}

.markdown-preview-content blockquote {
    border-left: 4px solid #667eea;
    padding-left: 1em;
    margin: 1em 0;
    color: #666;
    font-style: italic;
    background: #f9f9f9;
    padding: 0.5em 1em;
    border-radius: 4px;
}

.markdown-preview-content a {
    color: #667eea;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s;
}

.markdown-preview-content a:hover {
    border-bottom-color: #667eea;
}

.markdown-preview-content strong {
    font-weight: bold;
    color: #333;
}

.markdown-preview-content em {
    font-style: italic;
}

.markdown-preview-content hr {
    border: none;
    border-top: 2px solid #ddd;
    margin: 1.5em 0;
}

.markdown-preview-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1em;
}

.markdown-preview-content table th,
.markdown-preview-content table td {
    border: 1px solid #ddd;
    padding: 8px 12px;
    text-align: left;
}

.markdown-preview-content table th {
    background: #667eea;
    color: white;
    font-weight: bold;
}

.markdown-preview-content table tr:nth-child(even) {
    background: #f9f9f9;
}

.markdown-preview-content img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    margin: 1em 0;
}

/* 同步滚动开关容器 */
.sync-scroll-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    padding: 2px 8px;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    height: 26px;
}

.sync-scroll-toggle-label {
    font-size: 11px;
    color: #6c757d;
    white-space: nowrap;
    user-select: none;
}

/* 精致的滑动开关 */
.sync-scroll-switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 18px;
}

.sync-scroll-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.sync-scroll-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .3s;
    border-radius: 18px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}

.sync-scroll-slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.sync-scroll-switch input:checked + .sync-scroll-slider {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.sync-scroll-switch input:focus + .sync-scroll-slider {
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.sync-scroll-switch input:checked + .sync-scroll-slider:before {
    transform: translateX(18px);
}

/* 开关悬停效果 */
.sync-scroll-slider:hover {
    opacity: 0.9;
}

/* 开关图标（可选） */
.sync-scroll-slider:after {
    content: '✕';
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 10px;
    color: white;
    opacity: 0.7;
    transition: opacity 0.3s;
}

.sync-scroll-switch input:checked + .sync-scroll-slider:after {
    content: '✓';
    left: 5px;
    right: auto;
    opacity: 1;
}

/* 脚注样式 */
.markdown-preview-content .footnotes {
    margin-top: 2em;
    padding-top: 1em;
    border-top: 1px solid #e2e8f0;
    font-size: 0.9em;
    color: #64748b;
}

.markdown-preview-content .footnotes ol {
    padding-left: 1.5em;
}

.markdown-preview-content .footnotes li {
    margin-bottom: 0.5em;
}

.markdown-preview-content sup {
    vertical-align: super;
    font-size: 0.75em;
}

.markdown-preview-content sup a {
    text-decoration: none;
    color: #667eea;
    font-weight: bold;
    padding: 0 2px;
}

.markdown-preview-content sup a:hover {
    text-decoration: underline;
}

.markdown-preview-content .footnotes a.footnote-backref {
    text-decoration: none;
    color: #667eea;
    margin-left: 0.5em;
}

.markdown-preview-content .footnotes a.footnote-backref:hover {
    text-decoration: underline;
}

/* 移动端优化 */
@media (max-width: 768px) {
    .markdown-toolbar {
        padding: 4px 6px;
    }
    
    .markdown-toolbar-btn {
        min-width: 24px;
        height: 24px;
        padding: 3px 5px;
    }
    
    .markdown-toolbar-btn svg {
        width: 12px;
        height: 12px;
    }
    
    .markdown-preview-content {
        padding: 16px;
        font-size: 14px;
    }
    
    .markdown-preview-content h1 {
        font-size: 1.5em;
    }
    
    .markdown-preview-content h2 {
        font-size: 1.3em;
    }
    
    .markdown-preview-content h3 {
        font-size: 1.1em;
    }
}

/* 全屏预览弹窗样式 */
.markdown-fullscreen-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 99999;
    animation: fadeIn 0.3s ease;
}

.markdown-fullscreen-overlay.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.markdown-fullscreen-modal {
    background: white;
    width: 90%;
    max-width: 1200px;
    height: 90vh;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.markdown-fullscreen-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 30px;
    border-radius: 12px 12px 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.markdown-fullscreen-title {
    font-size: 20px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0;
}

.markdown-fullscreen-title svg {
    width: 24px;
    height: 24px;
}

.markdown-fullscreen-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.markdown-fullscreen-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.markdown-fullscreen-close svg {
    width: 20px;
    height: 20px;
}

.markdown-fullscreen-body {
    flex: 1;
    overflow-y: auto;
    padding: 40px;
    background: #fafbfc;
}

.markdown-fullscreen-content {
    max-width: 900px;
    margin: 0 auto;
    background: white;
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* 移动端适配 */
@media (max-width: 768px) {
    .markdown-fullscreen-modal {
        width: 95%;
        height: 95vh;
    }
    
    .markdown-fullscreen-header {
        padding: 15px 20px;
    }
    
    .markdown-fullscreen-title {
        font-size: 18px;
    }
    
    .markdown-fullscreen-body {
        padding: 20px;
    }
    
    .markdown-fullscreen-content {
        padding: 20px;
    }
}
