/* CSS重置 - 确保完全占满页面 */
html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

/* 确保编辑器页面没有额外边距 */
.editormd-page {
    margin: 0;
    padding: 0;
}

/* Markdown 编辑器样式 */

/* 编辑器页面基础样式 */
.editormd-page {
    background-color: var(--ifm-background-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    /* 使用 100vh 减去导航栏和操作栏的高度 */
    height: 100vh;
    overflow: hidden; /* 防止页面滚动条 */
}

/* 页面根容器 */
#__docblog {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 导航栏 */
.editormd-page .navbar {
    flex-shrink: 0;
    height: 60px; /* 固定导航栏高度 */
    min-height: 60px;
    max-height: 60px;
}

/* 主布局容器 */
.editormd-page .theme-layout-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    /* 使用 calc 计算实际可用高度：100vh - 导航栏高度 */
    height: calc(100vh - 60px);
    max-height: calc(100vh - 60px);
}

/* 编辑器容器 */
.editormd-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* 允许 flex 子项收缩 */
    position: relative;
    padding: 0; /* 移除所有padding */
    margin: 0; /* 移除所有margin */
    /* 减去操作按钮区域的高度 */
    height: calc(100vh - 60px - 1px);
    max-height: calc(100vh - 60px - 2px);
}

/* 编辑器包装器 */
.editormd-wrapper {
    flex: 1;
    background-color: var(--ifm-background-surface-color);
    min-height: 0; /* 允许 flex 子项收缩 */
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 100%;
}

/* 编辑器实例容器 */
.editormd-wrapper #editormd {
    flex: 1;
    min-height: 0; /* 允许 flex 子项收缩 */
    display: flex;
    flex-direction: column;
}

/* 修改说明表单（移到编辑器下方） */
.editormd-footer {
    background-color: var(--ifm-background-surface-color);
    border-top: 1px solid var(--ifm-color-emphasis-200);
    padding: 1rem 0;
    margin-top: 0;
}

.editormd-footer .form-group {
    margin-bottom: 0;
}

.article-form {
    max-width: 100%;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-weight: 600;
    color: var(--ifm-color-emphasis-800);
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--ifm-color-emphasis-300);
    border-radius: 6px;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--ifm-color-emphasis-800);
    background-color: var(--ifm-color-emphasis-0);
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.form-control:focus {
    outline: 0;
    border-color: var(--ifm-color-primary);
    box-shadow: 0 0 0 2px rgba(var(--ifm-color-primary-rgb), 0.25);
}

.form-control::placeholder {
    color: var(--ifm-color-emphasis-500);
}

/* Editor.md 编辑器样式 */
.editormd-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--ifm-background-surface-color);
    min-height: 0; /* 允许 flex 子项收缩 */
}

/* 重写 Editor.md 的基础样式以适配主题 */
.editormd {
    border: none !important;
    background-color: var(--ifm-background-surface-color) !important;
    margin: 0 !important; /* 移除所有margin */
    padding: 0 !important; /* 移除所有padding */
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
}

/* 强制确保编辑器工具栏和内容区域正确布局 */
.editormd > .editormd-toolbar {
    flex-shrink: 0 !important;
    order: -2 !important; /* 使用更小的负数确保在最前面 */
    position: relative !important;
    z-index: 100 !important;
}

.editormd > .editormd-container {
    flex: 1 !important;
    display: flex !important;
    min-height: 0 !important;
    order: 2 !important;
}

.editormd .editormd-toolbar {
    background-color: var(--ifm-color-emphasis-100) !important;
    border-bottom: 1px solid var(--ifm-color-emphasis-200) !important;
    padding: 6px 8px 6px 45px !important;
    margin: 0 !important; /* 移除所有margin */
    z-index: 10 !important; /* 确保工具栏在导航栏之上 */
}

.editormd .editormd-toolbar .fa {
    color: var(--ifm-color-emphasis-700) !important;
}

.editormd .editormd-toolbar .fa:hover {
    color: var(--ifm-color-primary) !important;
}

/* 强制修复工具栏位置 - 使用flexbox而不是绝对定位 */
.editormd-wrapper .editormd {
    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
}

.editormd-wrapper .editormd .editormd-toolbar {
    flex-shrink: 0 !important;
    order: -2 !important; /* 确保工具栏在最上方 */
    height: auto !important;
    min-height: auto !important;
    max-height: none !important;
    position: relative !important;
    z-index: 100 !important;
}

.editormd-wrapper .editormd .editormd-container {
    flex: 1 !important;
    display: flex !important;
    min-height: 0 !important; /* 允许flex收缩 */
    overflow: hidden !important;
    order: 2 !important;
}

/* 移除之前的 flex order 规则，直接使用定位 */
.editormd > .editormd-container:first-child {
    order: unset !important;
}

.editormd > .editormd-toolbar:last-child {
    /* order: unset !important; */ /* 移除之前的 order 规则 */
    position: relative !important;
}

/* 最强制的工具栏位置修复 - 覆盖所有其他规则 */
.editormd .editormd-toolbar {
    order: -999 !important;
    flex-shrink: 0 !important;
    position: relative !important;
    z-index: 999 !important;
    display: block !important;
}

.editormd .editormd-container {
    order: 999 !important;
    flex: 1 !important;
    display: flex !important;
    margin: 0 !important; /* 移除所有margin */
    padding: 0 !important; /* 移除所有padding */
}

/* 修复行号被左侧导航栏遮挡的问题 */
.editormd .CodeMirror {
    background-color: var(--ifm-background-surface-color) !important;
    color: var(--ifm-color-emphasis-800) !important;
    border: none !important;
    font-family: var(--ifm-font-family-monospace) !important;
    font-size: 14px !important;
    line-height: 1.6 !important;
    height: 100% !important;
    margin: 0 !important; /* 移除所有margin */
    padding: 0 !important; /* 移除所有padding */
}

/* 简化CodeMirror滚动设置 */
.editormd .CodeMirror-scroll {
    overflow-y: auto !important;
    overflow-x: hidden !important;
}

.editormd .CodeMirror-gutters {
    background-color: var(--ifm-color-emphasis-100) !important;
    border-right: 1px solid var(--ifm-color-emphasis-200) !important;
    padding-left: 10px !important;
    width: 50px !important;
}

.editormd .CodeMirror-linenumber {
    color: var(--ifm-color-emphasis-500) !important;
    padding: 0 8px 0 0 !important;
    text-align: right !important;
}

/* 确保代码区域不会被行号区域覆盖 */
.editormd .CodeMirror-lines {
    padding-left: 60px !important;
    padding-top: 10px !important;
    padding-bottom: 20px !important; /* 添加底部间距 */
}

.editormd .editormd-preview {
    background-color: var(--ifm-background-surface-color) !important;
    color: var(--ifm-color-emphasis-800) !important;
    border-left: 1px solid var(--ifm-color-emphasis-200) !important;
    font-family: var(--ifm-font-family-base) !important;
}

.editormd .editormd-preview-container {
    padding: 20px !important;
    flex: 1 !important;
    height: 100% !important;
    overflow-y: auto !important; /* 预览区域可以垂直滚动 */
    overflow-x: auto !important; /* 预览区域可以水平滚动 */
}

/* 预览区域的Markdown样式 */
.editormd-preview h1,
.editormd-preview h2,
.editormd-preview h3,
.editormd-preview h4,
.editormd-preview h5,
.editormd-preview h6 {
    color: var(--ifm-color-emphasis-900) !important;
    margin-top: 1.5rem !important;
    margin-bottom: 1rem !important;
}

.editormd-preview h1 {
    border-bottom: 2px solid var(--ifm-color-emphasis-200) !important;
    padding-bottom: 0.5rem !important;
}

.editormd-preview h2 {
    border-bottom: 1px solid var(--ifm-color-emphasis-200) !important;
    padding-bottom: 0.3rem !important;
}

.editormd-preview pre {
    background-color: var(--ifm-color-emphasis-100) !important;
    border: 1px solid var(--ifm-color-emphasis-200) !important;
    border-radius: 6px !important;
    padding: 1rem !important;
}

.editormd-preview code {
    background-color: var(--ifm-color-emphasis-100) !important;
    color: var(--ifm-color-primary) !important;
    padding: 0.2rem 0.4rem !important;
    border-radius: 3px !important;
    font-family: var(--ifm-font-family-monospace) !important;
}

.editormd-preview blockquote {
    border-left: 4px solid var(--ifm-color-primary) !important;
    background-color: var(--ifm-color-primary-lightest) !important;
    padding: 1rem !important;
    margin: 1rem 0 !important;
}

.editormd-preview table {
    border-collapse: collapse !important;
    width: 100% !important;
    margin: 1rem 0 !important;
}

.editormd-preview table th,
.editormd-preview table td {
    border: 1px solid var(--ifm-color-emphasis-200) !important;
    padding: 0.75rem !important;
    text-align: left !important;
}

.editormd-preview table th {
    background-color: var(--ifm-color-emphasis-100) !important;
    font-weight: 600 !important;
}

/* 操作按钮区域 */
.editormd-actions {
    background-color: var(--ifm-color-emphasis-100);
    border-top: 1px solid var(--ifm-color-emphasis-200);
    padding: 0.75rem 0;
    margin-top: 0;
    flex-shrink: 0; /* 防止被压缩 */
    height: auto;
    min-height: 70px; /* 最小高度以保证按钮可见 */
    max-height: 70px; /* 最大高度防止过高 */
    overflow: hidden;
}

.actions-group {
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    align-items: center;
}

.actions-group .word-count {
    color: var(--ifm-color-emphasis-600);
    font-size: 0.875rem;
    font-weight: 500;
}

.actions-group .btn-group {
    display: flex;
    gap: 1rem;
    margin-left: auto;
}

/* 按钮样式 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    min-width: 120px;
}

.btn:hover {
    text-decoration: none;
}

.btn-secondary {
    color: var(--ifm-color-emphasis-700);
    background-color: var(--ifm-color-emphasis-100);
    border-color: var(--ifm-color-emphasis-300);
}

.btn-secondary:hover {
    color: var(--ifm-color-emphasis-800);
    background-color: var(--ifm-color-emphasis-200);
    border-color: var(--ifm-color-emphasis-400);
}

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

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

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

/* 全屏按钮 */
#fullscreen-btn {
    padding: 0.5rem;
    color: var(--ifm-color-emphasis-600);
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease-in-out;
}

#fullscreen-btn:hover {
    color: var(--ifm-color-primary);
    background-color: var(--ifm-color-emphasis-100);
}

/* 消息提示框 */
.message-toast {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 9999;
    min-width: 300px;
    max-width: 500px;
    background-color: var(--ifm-background-surface-color);
    border: 1px solid var(--ifm-color-emphasis-200);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    animation: slideInRight 0.3s ease-out;
}

.toast-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
}

.toast-message {
    color: var(--ifm-color-emphasis-800);
    font-size: 0.875rem;
    flex: 1;
}

.toast-close {
    background: none;
    border: none;
    color: var(--ifm-color-emphasis-500);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0;
    margin-left: 1rem;
    line-height: 1;
}

.toast-close:hover {
    color: var(--ifm-color-emphasis-700);
}

.message-toast.success {
    border-left: 4px solid var(--ifm-color-success);
}

.message-toast.error {
    border-left: 4px solid var(--ifm-color-danger);
}

.message-toast.warning {
    border-left: 4px solid var(--ifm-color-warning);
}

.message-toast.info {
    border-left: 4px solid var(--ifm-color-info);
}

/* 保存状态指示器 */
.save-status {
    display: inline-block;
    margin-left: 10px;
    padding: 4px 8px;
    font-size: 0.75rem;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.save-status.success {
    background-color: var(--ifm-color-success-lightest);
    color: var(--ifm-color-success-dark);
    border: 1px solid var(--ifm-color-success-light);
}

.save-status.info {
    background-color: var(--ifm-color-info-lightest);
    color: var(--ifm-color-info-dark);
    border: 1px solid var(--ifm-color-info-light);
}

.save-status.error {
    background-color: var(--ifm-color-danger-lightest);
    color: var(--ifm-color-danger-dark);
    border: 1px solid var(--ifm-color-danger-light);
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* 全屏模式样式 */
.editormd-fullscreen .editormd-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    z-index: 9999;
    padding-top: 0;
    background-color: var(--ifm-background-surface-color);
}

.editormd-fullscreen .editormd-header,
.editormd-fullscreen .editormd-actions {
    display: none;
}

.editormd-fullscreen .editormd-wrapper {
    height: 100vh;
}

.editormd-fullscreen .editormd {
    height: 100vh !important;
}

/* 提交审核对话框样式 */
.submit-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background-color: var(--ifm-background-surface-color);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

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

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--ifm-color-emphasis-800);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--ifm-color-emphasis-600);
    cursor: pointer;
    padding: 0.25rem;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background-color: var(--ifm-color-emphasis-200);
    color: var(--ifm-color-emphasis-800);
}

.modal-body {
    padding: 1.5rem;
}

.modal-body .form-group {
    margin-bottom: 1rem;
}

.modal-body .form-group:last-child {
    margin-bottom: 0;
}

.modal-body label {
    display: block;
    font-weight: 600;
    color: var(--ifm-color-emphasis-800);
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.modal-body .required {
    color: var(--ifm-color-danger);
}

.modal-body textarea.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--ifm-color-emphasis-300);
    border-radius: 6px;
    background-color: var(--ifm-background-color);
    color: var(--ifm-color-emphasis-800);
    font-size: 0.875rem;
    line-height: 1.5;
    resize: vertical;
    min-height: 80px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.modal-body textarea.form-control:focus {
    outline: none;
    border-color: var(--ifm-color-primary);
    box-shadow: 0 0 0 2px rgba(var(--ifm-color-primary-rgb), 0.25);
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1.5rem;
    border-top: 1px solid var(--ifm-color-emphasis-200);
    background-color: var(--ifm-color-emphasis-100);
}

.modal-footer .btn {
    padding: 0.5rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    min-width: 80px;
}

.modal-footer .btn-secondary {
    background-color: var(--ifm-color-emphasis-200);
    color: var(--ifm-color-emphasis-700);
    border-color: var(--ifm-color-emphasis-300);
}

.modal-footer .btn-secondary:hover {
    background-color: var(--ifm-color-emphasis-300);
}

.modal-footer .btn-primary {
    background-color: var(--ifm-color-primary);
    color: white;
    border-color: var(--ifm-color-primary);
}

.modal-footer .btn-primary:hover {
    background-color: var(--ifm-color-primary-dark);
    border-color: var(--ifm-color-primary-dark);
}

.modal-footer .btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* 深色主题下的对话框样式 */
[data-theme='dark'] .modal-content {
    background-color: var(--ifm-background-surface-color);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

[data-theme='dark'] .modal-header {
    border-bottom-color: var(--ifm-color-emphasis-300);
}

[data-theme='dark'] .modal-footer {
    border-top-color: var(--ifm-color-emphasis-300);
    background-color: var(--ifm-color-emphasis-200);
}

[data-theme='dark'] .modal-body textarea.form-control {
    background-color: var(--ifm-color-emphasis-100);
    border-color: var(--ifm-color-emphasis-400);
    color: var(--ifm-color-emphasis-800);
}

[data-theme='dark'] .modal-body textarea.form-control:focus {
    border-color: var(--ifm-color-primary);
    box-shadow: 0 0 0 2px rgba(var(--ifm-color-primary-rgb), 0.25);
}

/* 确保编辑器及其内部组件正确填充可用空间 */
.editormd .editormd-container,
.editormd .CodeMirror-scroll,
.editormd .editormd-preview-container {
    flex: 1 !important;
    height: auto !important;
}

/* 确保 CodeMirror 编辑器占满可用高度 */
.editormd .CodeMirror {
    height: 100% !important;
    flex: 1 !important;
}

/* 确保预览区域也正确填充 */
.editormd .editormd-preview {
    height: 100% !important;
    flex: 1 !important;
}

/* 防止编辑器工具栏影响布局 */
.editormd .editormd-toolbar {
    position: relative !important;
    height: auto !important;
}

/* 确保分割条不影响布局 */
.editormd .editormd-resize {
    height: 100% !important;
}

/* 确保编辑器左侧和预览区域都能独立滚动 */
.editormd .editormd-editor-container {
    flex: 1 !important;
    position: relative !important;
    overflow: hidden !important;
}

.editormd .editormd-preview-container {
    flex: 1 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
}

/* 简化CodeMirror高度设置 */
.editormd .CodeMirror {
    height: 100% !important;
}

.editormd .CodeMirror-scroll {
    height: 100% !important;
}

/* 确保编辑器分割器不影响滚动 */
.editormd .editormd-resize {
    position: absolute !important;
    top: 0 !important;
    bottom: 0 !important;
    width: 5px !important;
    cursor: col-resize !important;
    z-index: 10 !important;
}

/* 响应式设计 */
@media (max-width: 996px) {
    .editormd-container {
        padding-top: 1px;
    }
    
    .editormd-header {
        padding: 1rem 0;
    }
    
    .form-group {
        margin-bottom: 0.75rem;
    }
    
    .actions-group {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .btn {
        width: 100%;
        justify-content: center;
    }
    
    .editormd-wrapper {
        min-height: 0; /* 使用 flexbox 而不是固定高度 */
    }
}

@media (max-width: 768px) {
    .editormd-container {
        padding-top: 2px;
    }
    
    .editormd-footer {
        padding: 0.75rem 0;
    }
    
    .editormd-actions {
        padding: 0.75rem 0;
    }
    
    .message-toast {
        right: 10px;
        left: 10px;
        min-width: auto;
        max-width: none;
    }
    
    .editormd-wrapper {
        min-height: 0; /* 使用 flexbox 而不是固定高度 */
    }
    
    .editormd .editormd-toolbar {
        padding: 6px 8px 6px 45px !important;
    }
    
    .editormd .editormd-preview-container {
        padding: 15px !important;
    }
    
    /* 移动端优化行号显示 */
    .editormd .CodeMirror-gutters {
        width: 40px !important;
    }
    
    .editormd .CodeMirror-lines {
        padding-left: 50px !important;
    }
    
    .editormd .CodeMirror-linenumber {
        font-size: 12px !important;
        padding: 0 4px 0 0 !important;
    }
}

/* 深色主题适配 */
[data-theme='dark'] .editormd-page {
    background-color: var(--ifm-background-color);
}

[data-theme='dark'] .form-control {
    background-color: var(--ifm-color-emphasis-100);
    border-color: var(--ifm-color-emphasis-300);
    color: var(--ifm-color-emphasis-800);
}

[data-theme='dark'] .form-control:focus {
    border-color: var(--ifm-color-primary);
    box-shadow: 0 0 0 2px rgba(var(--ifm-color-primary-rgb), 0.25);
}

[data-theme='dark'] .message-toast {
    background-color: var(--ifm-background-surface-color);
    border-color: var(--ifm-color-emphasis-300);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* 防止背景滚动 */
body.modal-open {
    overflow: hidden;
}
