/* 编辑器自定义样式 */

/* 基础样式调整 */
.ql-container {
    font-size: 16px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.ql-editor {
    min-height: 400px;
    padding: 40px 20px 20px 20px; /* 增加顶部内边距 */
    line-height: 1.8;
}

/* 移动端编辑器容器整体布局 */
@media (max-width: 768px) {
    /* 确保编辑器容器有正确的滚动行为 */
    #editor-container {
        position: relative;
        /* 移除顶部外边距，因为不需要 */
        margin-top: 0;
    }
    
    /* 移除editor-wrapper的内边距和边距 */
    .editor-wrapper {
        padding: 0;
        margin: 0;
    }
    
    /* 在工具栏后添加一个空白区域，防止遮挡 */
    .ql-toolbar.ql-snow::after {
        content: '';
        display: block;
        width: 100%;
        height: 25px;
        background: transparent;
        position: absolute;
        bottom: -25px;
        left: 0;
    }
}

.ql-editor.ql-blank::before {
    display: none; /* 隐藏占位符提示 */
}

/* 工具栏优化 - 适合中老年用户 */
.ql-toolbar {
    border: none;
    border-bottom: 1px solid #e5e7eb;
    padding: 12px;
    background-color: #f9fafb;
}

/* 在工具栏下方添加间隔区域 */
.ql-toolbar-spacer {
    height: 30px;
    background: transparent;
    display: block;
}

/* 调试模式 - 在开发时可以临时启用查看布局 */
.debug-mode .ql-toolbar {
    border: 2px solid red !important;
}
.debug-mode .ql-editor {
    border: 2px solid blue !important;
}
.debug-mode .editor-wrapper {
    border: 2px solid green !important;
}
.debug-mode #editor-container {
    border: 2px solid orange !important;
}

/* 放大工具栏按钮 */
.ql-toolbar button {
    width: 44px !important;
    height: 44px !important;
    margin: 0 4px;
    border-radius: 8px;
    transition: all 0.2s;
}

.ql-toolbar button:hover {
    background-color: #e5e7eb !important;
}

.ql-toolbar button.ql-active {
    background-color: #dbeafe !important;
    color: #2563eb !important;
}

/* 字号选择器优化 */
.ql-toolbar .ql-size {
    width: 100px !important;
    height: 44px !important;
    margin: 0 4px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    font-size: 16px;
}

/* 颜色选择器优化 */
.ql-toolbar .ql-color-picker,
.ql-toolbar .ql-background {
    width: 44px !important;
    height: 44px !important;
}

.ql-toolbar .ql-color-picker .ql-picker-label,
.ql-toolbar .ql-background .ql-picker-label {
    padding: 8px;
}

/* 对齐方式选择器优化 */
.ql-toolbar .ql-align {
    width: auto !important;
    min-width: 60px;
}

.ql-toolbar .ql-align .ql-picker-label {
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 对齐选项样式 - 修复z-index和位置问题 */
.ql-toolbar .ql-align .ql-picker-options {
    min-width: 140px;
    background: white;
    border: 1px solid #d1d5db;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    z-index: 1000 !important; /* 降低z-index避免遮挡其他下拉菜单 */
    position: absolute !important;
    left: 0 !important; /* 确保从左边开始 */
    margin-left: 0 !important;
}

.ql-toolbar .ql-align .ql-picker-item {
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ql-toolbar .ql-align .ql-picker-item:hover {
    background-color: #f3f4f6;
}

/* 格式刷按钮样式 */
.ql-toolbar .ql-format-painter {
    position: relative;
}

.ql-toolbar .ql-format-painter svg {
    width: 18px;
    height: 18px;
}

/* 格式刷激活时的光标样式 */
body.format-painter-active {
    cursor: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTYuNSwyIEwxMS41LDIgQzExLjc3NiwyIDEyLDIuMjI0IDEyLDIuNSBMMTIsNiBMNiw2IEw2LDIuNSBDNiwyLjIyNCA2LjIyNCwyIDYuNSwyIFogTTEyLDcgTDEyLDguNSBDMTIsOC43NzYgMTEuNzc2LDkgMTEuNSw5IEwxMCw5IEwxMCwxNS41IEMxMCwxNS43NzYgOS43NzYsMTYgOS41LDE2IEw4LjUsMTYgQzguMjI0LDE2IDgsMTUuNzc2IDgsMTUuNSBMOCw5IEw2LjUsOSBDNi4yMjQsOSA2LDguNzc2IDYsOC41IEw2LDcgTDEyLDcgWiIgZmlsbD0iIzI1NjNlYiIvPjwvc3ZnPg==') 12 12, auto;
}

body.format-painter-active .ql-editor {
    cursor: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTYuNSwyIEwxMS41LDIgQzExLjc3NiwyIDEyLDIuMjI0IDEyLDIuNSBMMTIsNiBMNiw2IEw2LDIuNSBDNiwyLjIyNCA2LjIyNCwyIDYuNSwyIFogTTEyLDcgTDEyLDguNSBDMTIsOC43NzYgMTEuNzc2LDkgMTEuNSw5IEwxMCw5IEwxMCwxNS41IEMxMCwxNS43NzYgOS43NzYsMTYgOS41LDE2IEw4LjUsMTYgQzguMjI0LDE2IDgsMTUuNzc2IDgsMTUuNSBMOCw5IEw2LjUsOSBDNi4yMjQsOSA2LDguNzc2IDYsOC41IEw2LDcgTDEyLDcgWiIgZmlsbD0iIzI1NjNlYiIvPjwvc3ZnPg==') 12 12, auto;
}

/* 工具提示 - 中文提示 */
.ql-toolbar button {
    position: relative;
}

/* 移除之前的伪元素提示，改用JavaScript创建的提示元素 */
.ql-toolbar .ql-tooltip {
    /* 样式由JavaScript内联设置 */
}

/* 下拉选择器容器需要相对定位 */
.ql-toolbar .ql-picker {
    position: relative;
}

/* 修复下拉菜单z-index问题 - 使用合理的层级值 */
.ql-toolbar .ql-picker-options {
    z-index: 1001 !important; /* 使用适中的z-index值 */
    position: absolute !important;
    background: white !important;
    border: 1px solid #d1d5db !important;
    border-radius: 4px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15) !important;
    padding: 4px 0 !important;
}

/* 确保编辑器容器不会遮挡下拉菜单 */
.ql-container {
    z-index: 1 !important;
}

/* 确保工具栏和下拉菜单在最上层 */
.ql-toolbar {
    z-index: 100 !important;
    position: relative !important;
}

/* 特别处理展开的下拉菜单 - 字号选择器应该在最上层 */
.ql-toolbar .ql-size.ql-expanded .ql-picker-options {
    z-index: 1002 !important; /* 字号选择器优先级更高 */
}

.ql-toolbar .ql-align.ql-expanded .ql-picker-options {
    z-index: 1000 !important; /* 对齐选择器z-index较低 */
}

/* 确保Quill的picker容器正确定位 */
.ql-toolbar .ql-picker {
    position: relative !important;
    z-index: 101 !important;
}

/* 确保下拉菜单项可点击 */
.ql-toolbar .ql-picker-item {
    display: block !important;
    padding: 8px 16px !important;
    cursor: pointer !important;
    white-space: nowrap !important;
}

.ql-toolbar .ql-picker-item:hover {
    background-color: #f3f4f6 !important;
}

/* 对齐方式选择器特殊处理 */
.ql-toolbar .ql-align .ql-picker-label {
    display: inline-flex !important;
    align-items: center !important;
}

.ql-toolbar .ql-align .ql-picker-options {
    min-width: 120px !important;
}

/* 字号选择器下拉菜单优化 */
.ql-toolbar .ql-size .ql-picker-options {
    min-width: 100px !important;
}

/* 修复下拉菜单显示问题 - 额外的层级控制 */
.ql-snow .ql-picker-options {
    z-index: 9999 !important;
    position: absolute !important;
    top: 100% !important;
    left: 0 !important;
    margin-top: 1px !important;
}

/* 确保下拉菜单在编辑器上方 - 合理的层级管理 */
.ql-toolbar.ql-snow .ql-picker-options {
    z-index: 1001 !important;
}

/* 字号下拉菜单特殊处理 - 确保在最上层 */
.ql-toolbar.ql-snow .ql-size .ql-picker-options {
    z-index: 1002 !important;
}

/* 编辑器容器降低z-index避免遮挡 */
.ql-editor {
    position: relative !important;
    z-index: 1 !important;
}

/* 防止overflow hidden遮挡下拉菜单 */
.ql-toolbar.ql-snow {
    overflow: visible !important;
}

.ql-toolbar .ql-formats {
    overflow: visible !important;
}


/* 移动端适配 */
@media (max-width: 768px) {
    /* 确保编辑器容器正确布局 */
    .ql-container.ql-snow {
        border: 1px solid #ccc;
        width: 100%;
        box-sizing: border-box;
    }
    
    /* 工具栏容器 - 改为多行自动换行 */
    .ql-toolbar.ql-snow {
        position: sticky;
        top: 60px; /* header高度 */
        z-index: 30;
        background-color: #f9fafb;
        border: 1px solid #ccc;
        border-bottom: 1px solid #e5e7eb;
        width: 100%;
        box-sizing: border-box;
        /* 取消横向滚动，改为自动换行 */
        overflow-x: visible;
        overflow-y: visible;
        white-space: normal;
        padding: 8px;
        /* 使用flex布局并允许换行 */
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        /* 添加阴影增强层次感 */
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    
    /* 工具栏格式组 */
    .ql-toolbar .ql-formats {
        display: inline-flex;
        flex-wrap: nowrap;
        align-items: center;
        margin: 0;
        padding: 4px;
        background: white;
        border-radius: 6px;
        border: 1px solid #e5e7eb;
    }
    
    /* 编辑器容器 - 增加顶部内边距避免被工具栏遮挡 */
    .ql-editor {
        padding: 60px 16px 16px 16px; /* 大幅增加顶部内边距 */
        font-size: 16px;
        min-height: 300px;
        width: 100%;
        box-sizing: border-box;
        /* 防止内容溢出 */
        overflow-wrap: break-word;
        word-wrap: break-word;
    }
    
    /* 隐藏编辑器占位符 */
    .ql-editor.ql-blank::before {
        display: none;
    }
    
    /* 工具栏按钮尺寸优化 */
    .ql-toolbar button {
        width: 35px !important;
        height: 35px !important;
        margin: 0 2px;
        flex-shrink: 0;
    }
    
    /* 下拉选择器优化 */
    .ql-toolbar .ql-picker {
        flex-shrink: 0;
    }
    
    /* 对齐选择器移动端优化 */
    .ql-toolbar .ql-align .ql-picker-options {
        position: fixed;
        left: 50%;
        transform: translateX(-50%);
        max-width: 90vw;
    }
    
}

/* 特别针对竖屏手机的优化 */
@media (max-width: 480px) and (orientation: portrait) {
    /* 工具栏在窄屏幕下的布局优化 */
    .ql-toolbar.ql-snow {
        padding: 6px;
        gap: 6px;
    }
    
    /* 格式组更紧凑 */
    .ql-toolbar .ql-formats {
        padding: 2px;
    }
    
    /* 按钮尺寸稍微缩小以适应更多内容 */
    .ql-toolbar button {
        width: 32px !important;
        height: 32px !important;
        margin: 0 1px;
    }
    
    /* 下拉选择器也相应缩小 */
    .ql-toolbar .ql-size,
    .ql-toolbar .ql-align {
        height: 32px !important;
    }
    
    /* 字号选择器宽度优化 */
    .ql-toolbar .ql-size {
        width: 80px !important;
    }
    
    /* 编辑器顶部额外空间，确保不被多行工具栏遮挡 */
    .ql-editor {
        padding-top: 65px; /* 增加更多顶部空间 */
    }
    
    /* 隐藏占位符 */
    .ql-editor.ql-blank::before {
        display: none;
    }
}

/* 横屏手机优化 */
@media (max-width: 768px) and (orientation: landscape) {
    /* 横屏下工具栏可以保持单行 */
    .ql-toolbar.ql-snow {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }
    
    /* 恢复格式组的flex-shrink设置 */
    .ql-toolbar .ql-formats {
        flex-shrink: 0;
    }
}

/* 字号选项自定义 */
.ql-snow .ql-picker.ql-size .ql-picker-label::before,
.ql-snow .ql-picker.ql-size .ql-picker-label[data-value="16px"]::before {
    content: '标准';
}
.ql-snow .ql-picker.ql-size .ql-picker-label[data-value="14px"]::before {
    content: '小号';
}
.ql-snow .ql-picker.ql-size .ql-picker-label[data-value="18px"]::before {
    content: '中号';
}
.ql-snow .ql-picker.ql-size .ql-picker-label[data-value="20px"]::before {
    content: '大号';
}
.ql-snow .ql-picker.ql-size .ql-picker-label[data-value="24px"]::before {
    content: '特大';
}

/* 字号下拉选项显示 */
.ql-snow .ql-picker.ql-size .ql-picker-item::before {
    content: '标准';
}
.ql-snow .ql-picker.ql-size .ql-picker-item[data-value="14px"]::before {
    content: '小号';
}
.ql-snow .ql-picker.ql-size .ql-picker-item[data-value="16px"]::before {
    content: '标准';
}
.ql-snow .ql-picker.ql-size .ql-picker-item[data-value="18px"]::before {
    content: '中号';
}
.ql-snow .ql-picker.ql-size .ql-picker-item[data-value="20px"]::before {
    content: '大号';
}
.ql-snow .ql-picker.ql-size .ql-picker-item[data-value="24px"]::before {
    content: '特大';
}

/* 编辑器内容样式 */
.ql-editor h2 {
    font-size: 24px;
    font-weight: bold;
    margin: 20px 0 10px;
}

.ql-editor h3 {
    font-size: 20px;
    font-weight: bold;
    margin: 16px 0 8px;
}

.ql-editor p {
    margin: 12px 0;
}

.ql-editor img {
    display: inline-block;
    margin: 8px 0;
    border-radius: 8px;
    vertical-align: bottom;
}

.ql-editor ul,
.ql-editor ol {
    padding-left: 24px;
    margin: 12px 0;
}

.ql-editor li {
    margin: 6px 0;
}

/* 模板样式 */
.template-content {
    padding: 20px;
    background: #f9fafb;
    border-radius: 8px;
    margin: 16px 0;
}

/* 自动保存指示器 */
.auto-save-indicator {
    position: fixed;
    bottom: 80px;
    right: 20px;
    background: #10b981;
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s;
}

.auto-save-indicator.show {
    opacity: 1;
    transform: translateY(0);
}

/* 视频插入模态框 */
.video-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.video-modal .modal-content {
    background: white;
    border-radius: 12px;
    padding: 24px;
    max-width: 500px;
    width: 100%;
}

.video-modal h3 {
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 12px;
}

.video-modal p {
    color: #666;
    margin-bottom: 16px;
}

.video-modal input {
    width: 100%;
    padding: 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 16px;
    margin-bottom: 20px;
}

.video-modal .modal-buttons {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.video-modal button {
    padding: 8px 20px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    transition: all 0.2s;
}

.video-modal .cancel-btn {
    background: #f3f4f6;
    color: #374151;
}

.video-modal .cancel-btn:hover {
    background: #e5e7eb;
}

.video-modal .confirm-btn {
    background: #2563eb;
    color: white;
}

.video-modal .confirm-btn:hover {
    background: #1d4ed8;
}

/* 提示和反馈样式 */
.editor-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 12px 24px;
    border-radius: 24px;
    font-size: 14px;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s;
}

.editor-toast.show {
    opacity: 1;
}

.editor-toast.success {
    background: #10b981;
}

.editor-toast.error {
    background: #ef4444;
}

/* 美化按钮动画 */
#beautifyBtn {
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}