/* ===================================
   Markdown 编辑器组件样式
   可复用的Markdown工具栏和编辑器
   =================================== */

/* 链接/图片输入弹窗动画 */
@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* 加载旋转动画 */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* 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-dropdown {
    position: relative;
    display: inline-block;
}

.markdown-toolbar-dropdown .dropdown-arrow {
    transition: transform 0.2s;
}

.markdown-toolbar-dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    margin-top: 4px;
    min-width: 140px;
    padding: 4px;
    display: none;
}

.markdown-toolbar-dropdown-item {
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: white;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #495057;
    border-radius: 4px;
    transition: all 0.2s;
}

.markdown-toolbar-dropdown-item:hover {
    background: #f8f9fa;
    color: #667eea;
}

.markdown-toolbar-dropdown-item:active {
    background: #e9ecef;
    transform: scale(0.98);
}

.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-editor-layout {
    display: flex;
    flex-direction: column;
    gap: 0;
    /* 尽量占用较大的可视高度，由外层容器再做限制 */
    max-height: 80vh;
}

/* 横向布局时左右分栏：通过 JS 添加 .markdown-layout-horizontal 控制 */
.markdown-editor-layout.markdown-layout-horizontal {
    flex-direction: row;
    align-items: stretch;
}

.markdown-editor-layout.markdown-layout-horizontal .markdown-preview-area {
    height: 60vh;
    max-height: 60vh;
    flex: 1 1 50%;
    overflow-y: auto;
}

.markdown-editor-layout.markdown-layout-horizontal textarea.form-control {
    flex: 1 1 50%;
    min-width: 0; /* 避免内容把列撑爆 */
}

.markdown-editor-layout.markdown-layout-horizontal textarea.form-control {
    height: 60vh;
    resize: none;
}

/* 竖屏上下布局时的 splitter：显示为一条可拖动横条 */
.markdown-splitter {
    height: 6px;
    cursor: row-resize;
    background: linear-gradient(to right, #e9ecef, #dee2e6, #e9ecef);
}

/* 横屏左右布局时隐藏中间的横向分隔条 */
.markdown-editor-layout.markdown-layout-horizontal .markdown-splitter {
    display: none;
}

/* 预览区域样式 */
.markdown-preview-area {
    display: none;
    border: 1px solid #dee2e6;
    border-top: none;
    border-bottom: none;
    background: #f8f9fa;
    resize: vertical;
    min-height: 150px;
    max-height: 80vh;
    overflow-y: auto;
}

/* 竖屏（上下布局）下，让预览区高度可由用户拖动，而不是被 flex 拉伸占满 */
.markdown-editor-layout:not(.markdown-layout-horizontal) .markdown-preview-area {
    flex: none;
    height: 260px; /* 初始高度，之后由用户通过拖动调整 */
}

/* 竖屏（上下布局）下，让 textarea 占据剩余高度 */
.markdown-editor-layout:not(.markdown-layout-horizontal) textarea.form-control {
    flex: 1 1 auto;
    min-height: 120px;
}

.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 .markdown-keyword {
    color: #667eea;
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 2px;
    transition: all 0.2s;
    font-weight: 500;
}

.markdown-preview-content .markdown-keyword:hover {
    color: #764ba2;
    text-decoration-style: solid;
    background: rgba(102, 126, 234, 0.1);
    padding: 1px 2px;
    border-radius: 3px;
}

/* 脚注样式 */
.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-toolbar-dropdown-menu {
        min-width: 120px;
        padding: 3px;
    }
    
    .markdown-toolbar-dropdown-item {
        padding: 6px 10px;
        font-size: 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;
    }
}

/* 书签 / 目录工具 */
.markdown-bookmark-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 1000000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
}

.markdown-bookmark-modal {
    width: min(660px, 92%);
    max-height: 86vh;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 18px 38px rgba(15, 22, 36, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.bookmark-modal-header {
    padding: 18px 20px;
    background: linear-gradient(135deg, #6f6df4 0%, #7f87ff 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.bookmark-modal-header h3 {
    margin: 0 0 4px 0;
    font-size: 16px;
    letter-spacing: 0.3px;
}

.bookmark-modal-header p {
    margin: 0;
    opacity: 0.9;
    font-size: 12px;
}

.bookmark-modal-close {
    border: none;
    background: rgba(255,255,255,0.18);
    color: #fff;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    transition: all 0.2s;
}

.bookmark-modal-close:hover {
    background: rgba(255,255,255,0.3);
    transform: scale(1.08);
}

.bookmark-modal-body {
    padding: 18px 20px 16px;
    overflow-y: auto;
    background: #f8f9fd;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.bookmark-modal-section {
    background: #fff;
    border: 1px solid #ecf0fb;
    border-radius: 10px;
    padding: 14px 16px;
    box-shadow: 0 3px 12px rgba(15, 22, 36, 0.06);
}

.bookmark-section-title {
    font-weight: 600;
    color: #39405f;
    margin-bottom: 10px;
    font-size: 14px;
}

.bookmark-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.bookmark-field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 8px 14px;
    margin-bottom: 8px;
    align-items: center;
}

.bookmark-field-grid label {
    font-size: 12px;
    color: #545a76;
    font-weight: 600;
}

.bookmark-field-grid input,
.bookmark-field-grid select {
    width: 100%;
    padding: 7px 9px;
    border-radius: 7px;
    border: 1px solid #d4daf0;
    font-size: 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #fff;
    box-sizing: border-box;
}

.bookmark-field-grid input:focus,
.bookmark-field-grid select:focus {
    border-color: #7b84ff;
    box-shadow: 0 0 0 2px rgba(123, 132, 255, 0.3);
    outline: none;
}

.bookmark-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: #4a4f6b;
    user-select: none;
    margin-bottom: 8px;
}

.bookmark-checkbox input {
    width: 15px;
    height: 15px;
    accent-color: #6f6df4;
}

.bookmark-primary-btn {
    border: none;
    background: linear-gradient(135deg, #6f6df4 0%, #8f7bff 100%);
    color: #fff;
    padding: 9px 18px;
    border-radius: 7px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    box-shadow: 0 6px 16px rgba(111, 109, 244, 0.25);
    transition: transform 0.2s, box-shadow 0.2s;
    margin-top: 4px;
}

.bookmark-primary-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 9px 20px rgba(111, 109, 244, 0.35);
}

.bookmark-secondary-btn {
    border: 1px dashed #c7ceef;
    background: #fff;
    color: #4a4f6b;
    padding: 8px 14px;
    border-radius: 7px;
    cursor: pointer;
    font-weight: 600;
    font-size: 12px;
    margin-top: 10px;
    transition: all 0.2s;
    width: 100%;
    text-align: center;
}

.bookmark-secondary-btn:hover {
    border-color: #7b84ff;
    color: #7b84ff;
    background: #f8f9ff;
}

.bookmark-ghost-btn {
    border: 1px solid #d5dbee;
    background: #fff;
    color: #4f5874;
    border-radius: 7px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.bookmark-ghost-btn:hover {
    border-color: #7b84ff;
    color: #7b84ff;
}

.bookmark-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.bookmark-list-item {
    padding: 10px 12px;
    border: 1px solid #e4e7f8;
    border-radius: 9px;
    background: #fefeff;
    display: flex;
    align-items: center;
    gap: 10px;
}

.bookmark-list-index {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6f6df4 0%, #7f87ff 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 12px;
    flex-shrink: 0;
}

.bookmark-list-detail {
    flex: 1;
}

.bookmark-list-title {
    font-weight: 600;
    color: #2f3253;
    margin-bottom: 1px;
    font-size: 13px;
}

.bookmark-list-id {
    font-size: 11px;
    color: #7a809d;
}

.bookmark-list-actions {
    display: flex;
    gap: 6px;
}

.bookmark-modal-message {
    font-size: 12px;
    margin-top: 4px;
    min-height: 16px;
}

.bookmark-hint {
    font-size: 11px;
    color: #6d7395;
    margin: 5px 0 0 0;
}

.bookmark-message-success {
    color: #2f9e44;
}

.bookmark-message-error {
    color: #d13c4f;
}

.bookmark-message-info {
    color: #4c6ef5;
}

.bookmark-empty {
    text-align: center;
    color: #7a809d;
    font-size: 12px;
    margin: 6px 0 0 0;
}

@media (max-width: 768px) {
    .bookmark-modal-header,
    .bookmark-modal-body {
        padding: 14px 16px;
    }
    
    .bookmark-field-grid {
        grid-template-columns: 1fr;
    }
    
    .bookmark-list-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }
    
    .bookmark-list-actions {
        width: 100%;
        justify-content: flex-end;
    }
}