/* 富文本编辑器样式 */
.rich-text-editor-wrapper {
    width: 100%;
    /* border: 1px solid #e0e0e0; */
    border-radius: 8px;
    background: #fff;
    overflow: visible;
    position: relative;
}

.rich-text-toolbar {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 12px;
    background: #f7f7f7;
    border: 1px solid #e0e0e0;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
    z-index: 100;
    border-radius: 8px 8px 0 0;
}

.toolbar-btn.media-upload-btn,
.toolbar-btn.emoji-picker-btn {
    display: inline-flex !important;
    flex-shrink: 0;
}

.toolbar-group {
    display: flex;
    align-items: flex-start;
    gap: 4px;
    padding-right: 12px;
    border-right: 1px solid #ddd;
}

.toolbar-group:last-child {
    border-right: none;
    padding-right: 0;
}

.toolbar-btn {
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    color: #333;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.toolbar-btn.fontsize-picker-btn,
.toolbar-btn.color-picker-btn,
.toolbar-btn.bg-color-picker-btn,
.toolbar-btn.media-upload-btn,
.toolbar-btn.emoji-picker-btn {
    background: transparent;
    border: none;
    padding: 8px;
    align-items: flex-start;
    justify-content: center;
}

.toolbar-btn .fontsize-icon,
.toolbar-btn .color-icon,
.toolbar-btn .bg-color-icon,
.toolbar-btn .media-upload-icon,
.toolbar-btn .emoji-icon {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    color: #999;
    display: block;
    margin: 0;
}

.toolbar-btn:hover {
    background: #f0f0f0;
    border-color: #813f91;
    color: #813f91;
}

.toolbar-btn:active {
    transform: scale(0.98);
}

.toolbar-btn.active {
    background: #813f91;
    color: #fff;
    border-color: #813f91;
}

.toolbar-btn.media-upload-btn.active .media-upload-icon,
.toolbar-btn.emoji-picker-btn.active .emoji-icon {
    color: #fff;
}

.color-picker-btn,
.bg-color-picker-btn {
    display: flex;
    align-items: center;
    gap: 6px;
}

.color-indicator,
.bg-color-indicator {
    width: 16px;
    height: 16px;
    border: 1px solid #ddd;
    border-radius: 3px;
    background-color: #333;
    display: inline-block;
}

.bg-color-indicator {
    background-color: #fff;
}

.color-picker-input,
.bg-color-picker-input {
    width: 0;
    height: 0;
    opacity: 0;
    position: absolute;
    pointer-events: none;
}

/* 颜色选择器弹出框 */
.color-picker-popup {
    position: absolute !important;
    background: #fff !important;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 8px 0;
    z-index: 1000 !important;
    min-width: 180px;
    width: 180px;
    max-height: 265px;
    overflow-y: auto;
    overflow-x: hidden;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* 颜色列表 */
.color-picker-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* 颜色选项 */
.color-picker-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.color-picker-item:hover {
    background-color: #f5f5f5;
}

.color-picker-item.selected {
    background-color: #f0e6f5;
}

/* 颜色色块 */
.color-picker-swatch {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid #ddd;
    flex-shrink: 0;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.color-picker-swatch.transparent-color {
    background-image: 
        linear-gradient(45deg, #ccc 25%, transparent 25%),
        linear-gradient(-45deg, #ccc 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #ccc 75%),
        linear-gradient(-45deg, transparent 75%, #ccc 75%);
    background-size: 8px 8px;
    background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
    background-color: #fff;
}

/* 选中标记 SVG */
.color-checkmark {
    width: 12px;
    height: 12px;
    color: #fff;
    stroke: currentColor;
    stroke-width: 2;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
    flex-shrink: 0;
}

/* 白色或透明背景时，打勾使用黑色 */
.color-picker-swatch.transparent-color .color-checkmark,
.color-picker-item.selected .color-picker-swatch[style*="background-color: rgb(255, 255, 255)"],
.color-picker-item.selected .color-picker-swatch[style*="background-color:#ffffff"],
.color-picker-item.selected .color-picker-swatch[style*="background-color: #ffffff"] {
    color: #000000 !important;
    filter: drop-shadow(0 1px 2px rgba(255, 255, 255, 0.5));
}

/* 颜色标签 */
.color-picker-label {
    font-size: 14px;
    color: #333;
    flex: 1;
    user-select: none;
}

.color-picker-item.selected .color-picker-label {
    color: #813f91;
    font-weight: 500;
}

.color-picker-input-container {
    position: relative;
    width: 100%;
    height: 50px;
    border: 2px solid #813f91;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.2s ease;
}

.color-picker-input-container:hover {
    border-color: #5d2d6a;
    box-shadow: 0 2px 4px rgba(129, 63, 145, 0.2);
}

.color-picker-preview {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #000;
    pointer-events: none;
    border-radius: 2px;
    /* 确保颜色可见 */
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* 添加渐变效果，让颜色更明显 */
    background-image: 
        linear-gradient(45deg, rgba(255,255,255,.1) 25%, transparent 25%),
        linear-gradient(-45deg, rgba(255,255,255,.1) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, rgba(255,255,255,.1) 75%),
        linear-gradient(-45deg, transparent 75%, rgba(255,255,255,.1) 75%);
    background-size: 10px 10px;
    background-position: 0 0, 0 5px, 5px -5px, -5px 0px;
}

.color-picker-preview-text {
    font-size: 13px;
    font-weight: 500;
    color: #fff;
    pointer-events: none;
    user-select: none;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    z-index: 1;
}

.color-picker-native-input {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 10;
}

.rich-text-editor {
    min-height: 200px;
    height: auto;
    max-height: none;
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.6;
    color: #333;
    overflow-x: hidden;
    overflow-y: visible;
    outline: none;
    word-wrap: break-word;
    word-break: break-word;
    position: relative;
    z-index: 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* 确保可以选中文字（包括鼠标长按选择） */
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
    /* 允许触摸选择 */
    -webkit-touch-callout: default;
    /* 允许所有触摸操作，包括长按选择 */
    touch-action: auto;
    /* 确保可以长按选择 */
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    /* 确保鼠标事件可以正常选择 */
    cursor: text;
    border: 1px solid #e0e0e0;
    border-top: 0;
    border-radius: 0 0 8px 8px;
    padding-bottom: 30px;
}

/* 确保编辑器内所有元素都可以选择文字 */
.rich-text-editor * {
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
}

.rich-text-editor span {
    /* 确保span元素不会导致额外的重排 */
    display: inline;
    vertical-align: baseline;
    /* 确保移动端可以选中文字 */
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
}

/* 确保 p 标签可以选择 */
.rich-text-editor p {
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
    margin: 0;
    padding: 0;
}

/* 有背景色的span使用inline-block，确保高度正确 */
.rich-text-editor span[style*="background-color"] {
    display: inline-block;
    line-height: 1.2;
    padding: 0 2px;
    vertical-align: baseline;
    /* 确保移动端可以选中文字 */
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
}

/* 确保背景色高度适应字体大小 */
.rich-text-editor span[style*="background-color"]:not([style*="background-color: transparent"]):not([style*="background-color: rgba(0, 0, 0, 0)"]) {
    min-height: 1em;
}

.rich-text-editor:empty:before {
    content: attr(data-placeholder);
    color: #999;
    pointer-events: none;
    /* 占位符文字不可选择 */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.rich-text-editor:focus {
    outline: none;
}

.rich-text-editor p {
    margin: 0 0 8px 0;
}

.rich-text-editor p:last-child {
    margin-bottom: 0;
}

.rich-text-counter {
    padding: 8px 12px;
    text-align: right;
    font-size: 12px;
    color: #999;
    background: #f7f7f7;
    border-top: 1px solid #e0e0e0;
}

.rich-text-counter .char-count {
    color: #666;
    font-weight: 500;
}

.rich-text-counter .char-count.over-limit {
    color: #d81e06;
    font-weight: 600;
}

/* 表情选择器弹出框 */
.emoji-picker-popup {
    position: absolute !important;
    background: #fff !important;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 12px;
    z-index: 1000 !important;
    max-width: 300px;
    max-height: 265px;
    overflow-x: hidden;
    overflow-y: scroll;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.color-picker-popup:not(.fontsize-picker-popup),
.emoji-picker-popup {
    overflow-x: hidden;
    overflow-y: scroll;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: #b7a0c2 #f4f4f4;
}

.color-picker-popup:not(.fontsize-picker-popup)::-webkit-scrollbar,
.emoji-picker-popup::-webkit-scrollbar {
    width: 8px;
    height: 0;
    display: block;
}

.color-picker-popup:not(.fontsize-picker-popup)::-webkit-scrollbar-track,
.emoji-picker-popup::-webkit-scrollbar-track {
    background: #f4f4f4;
    border-radius: 8px;
}

.color-picker-popup:not(.fontsize-picker-popup)::-webkit-scrollbar-thumb,
.emoji-picker-popup::-webkit-scrollbar-thumb {
    background: #b7a0c2;
    border-radius: 8px;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.emoji-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    min-width: 50px;
}

.emoji-item:hover {
    background-color: #f0e6f5;
}

.emoji-item .emoji-icon {
    font-size: 24px;
    line-height: 1;
    margin-bottom: 4px;
}

.emoji-image {
    width: 48px;
    height: 48px;
    object-fit: contain;
    margin-bottom: 4px;
    display: block;
}

.emoji-label {
    font-size: 10px;
    color: #666;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* 编辑器内联媒体 */
.rich-text-editor .rte-inline-media {
    display: block;
    position: relative;
    margin: 12px 0;
    max-width: 100%;
    line-height: 0;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
}

.rich-text-editor .rte-media-default-slot {
    display: block;
    margin: 8px 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    cursor: grab;
    touch-action: none;
}

.rich-text-editor .rte-inline-media.rte-media-dragging,
.rich-text-editor .rte-media-default-slot.rte-media-dragging {
    opacity: 0.45;
    cursor: grabbing;
    pointer-events: none;
}

.rich-text-editor .rte-media-actions,
.rich-text-editor .rte-media-actions button {
    cursor: pointer;
}

body.rte-media-drag-active {
    user-select: none;
    cursor: grabbing;
}

body.rte-media-touch-drag-active {
    overscroll-behavior: none;
}

.rich-text-editor .rte-media-drop-indicator {
    position: absolute;
    height: 3px;
    background: #813f91;
    border-radius: 2px;
    z-index: 20;
    pointer-events: none;
    display: none;
    box-shadow: 0 0 6px rgba(129, 63, 145, 0.45);
}

.rich-text-editor .rte-inline-media img,
.rich-text-editor .rte-inline-media video {
    display: block;
    max-width: 100%;
    width: auto;
    height: auto;
    border-radius: 8px;
    background: #f5f5f5;
    -webkit-user-drag: none;
    user-drag: none;
    pointer-events: auto;
}

.rich-text-editor .rte-media-default-view-in-editor img,
.rich-text-editor .rte-media-default-view-in-editor video {
    -webkit-user-drag: none;
    user-drag: none;
}

.rich-text-editor .rte-inline-media .video-badge {
    position: absolute;
    bottom: 8px;
    left: 8px;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    border-radius: 4px;
    font-size: 12px;
    line-height: 1.2;
    z-index: 2;
}

/* 正在编辑的图片：透明遮罩 + 虚线边框（分层，边框不随遮罩透明） */
.rich-text-editor .rte-media-focus-overlay,
.rich-text-editor .rte-media-focus-border {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    border-radius: 8px;
    pointer-events: none;
    box-sizing: border-box;
}

.rich-text-editor .rte-media-focus-overlay {
    background: rgba(0, 0, 0, 0.50);
    z-index: 1;
}

.rich-text-editor .rte-media-focus-border {
    /* border: 3px dashed #813f91; */
    border: 3px dashed rgba(255, 255, 255, 0.8);
    background: transparent;
    z-index: 2;
    margin: 3px;
}

.rich-text-editor .rte-inline-media.rte-media-active .rte-media-focus-overlay,
.rich-text-editor .rte-inline-media.rte-media-active .rte-media-focus-border,
.rich-text-editor .rte-media-default-slot.rte-media-active .rte-media-focus-overlay,
.rich-text-editor .rte-media-default-slot.rte-media-active .rte-media-focus-border {
    display: block;
}

/* 编辑器内上传模块（默认隐藏，点击工具栏按钮后在光标处显示） */
.rich-text-editor .rte-media-upload-block {
    display: block;
    position: relative;
    margin: 12px 0;
    max-width: 100%;
}

.rich-text-editor .rte-media-upload-close {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.45);
    color: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}

.rich-text-editor .rte-media-upload-area {
    position: relative;
    width: 100%;
    min-height: 140px;
    border: 2px dashed #d0d0d0;
    border-radius: 8px;
    background: #fafafa;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rich-text-editor .rte-media-upload-area:hover,
.rich-text-editor .rte-media-upload-area.dragover {
    border-color: #813f91;
    background: #f5f0f8;
}

.rich-text-editor .rte-media-upload-area .upload-placeholder {
    text-align: center;
    padding: 24px 16px;
    color: #999;
    pointer-events: none;
}

.rich-text-editor .rte-media-upload-area .upload-placeholder svg {
    margin: 0 auto 12px;
    color: #813f91;
    display: block;
}

.rich-text-editor .rte-media-upload-area .upload-placeholder p {
    margin: 0 0 6px 0;
    font-size: 14px;
    color: #666;
}

.rich-text-editor .rte-media-upload-area .upload-hint {
    font-size: 12px;
    color: #999;
}

.rich-text-editor .rte-media-file-input {
    display: none;
}

/* 编辑器内的默认图片视图 */
.rich-text-editor .rte-media-default-view-in-editor {
    position: relative;
    width: 100%;
    border-radius: 8px;
    overflow: hidden;
    background: #f0f0f0;
}

.rich-text-editor .rte-media-default-view-in-editor .media-default-image {
    width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
    max-height: 400px;
}

/* 编辑器内媒体不参与高层级堆叠，避免遮挡工具栏下拉 */
.rich-text-editor .rte-inline-media,
.rich-text-editor .rte-media-default-slot,
.rich-text-editor .rte-media-default-view-in-editor,
.rich-text-editor .rte-media-upload-block {
    position: relative;
    z-index: 0;
}

.rich-text-editor .rte-media-actions {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
    max-width: calc(100% - 24px);
    z-index: 3;
    pointer-events: auto;
}

.rich-text-editor .rte-media-actions button {
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    /* background: rgba(255, 255, 255, 0.95); */
    background:#813f91;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    pointer-events: auto;
    -webkit-user-select: none;
    user-select: none;
    white-space: nowrap;
    border: 1px solid rgba(255, 255, 255, 0.48); 
}

.rich-text-editor .rte-media-actions button:hover {
    background: #fff;
    color: #813f91;
}

.rich-text-editor .rte-media-drag-hint {
    display: none;
    position: absolute;
    left: 50%;
    bottom: 16px;
    z-index: 4;
    max-width: calc(100% - 24px);
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.68);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.4;
    text-align: center;
    white-space: nowrap;
    pointer-events: none;
    transform: translateX(-50%);
    box-sizing: border-box;
}

.rich-text-editor .rte-inline-media:hover .rte-media-drag-hint,
.rich-text-editor .rte-media-default-slot:hover .rte-media-drag-hint {
    display: block;
}

.rich-text-editor .rte-inline-media:has(.rte-media-actions:hover) .rte-media-drag-hint,
.rich-text-editor .rte-media-default-slot:has(.rte-media-actions:hover) .rte-media-drag-hint,
.rich-text-editor .rte-inline-media.rte-media-dragging .rte-media-drag-hint,
.rich-text-editor .rte-media-default-slot.rte-media-dragging .rte-media-drag-hint {
    display: none;
}

/* 移动端适配 */
    @media screen and (max-width: 768px) {
    .rich-text-toolbar {
        padding: 8px 10px;
        gap: 8px;
        flex-wrap: nowrap;
    }

    .toolbar-group {
        gap: 3px;
        padding-right: 8px;
    }

    .toolbar-btn {
        padding: 5px 10px;
        font-size: 12px;
    }

    .emoji-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
    }

    .emoji-item {
        min-width: 45px;
        padding: 6px 2px;
    }

    .emoji-item .emoji-icon {
        font-size: 20px;
        margin-bottom: 3px;
    }

    .emoji-label {
        font-size: 9px;
    }

    .toolbar-btn .fontsize-icon,
    .toolbar-btn .color-icon,
    .toolbar-btn .bg-color-icon,
    .toolbar-btn .media-upload-icon,
    .toolbar-btn .emoji-icon {
        width: 24px;
        height: 24px;
    }

    .rich-text-editor {
        min-height: 150px;
        max-height: none;
        padding: 10px 12px;
        font-size: 14px;
        /* 确保移动端可以选中文字 */
        -webkit-user-select: text !important;
        -moz-user-select: text !important;
        -ms-user-select: text !important;
        user-select: text !important;
        -webkit-touch-callout: default !important;
        /* 允许所有触摸操作，包括长按选择 */
        touch-action: auto !important;
        /* 确保可以长按选择 */
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }

    .emoji-picker-popup {
        max-width: 280px;
        max-height: 250px;
    }

    .emoji-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 3px;
    }

    .emoji-item {
        width: 28px;
        height: 28px;
        font-size: 18px;
    }

    .rich-text-editor .rte-media-actions {
        top: 8px;
        right: 8px;
        gap: 4px;
    }

    .rich-text-editor .rte-media-actions button {
        padding: 4px 8px;
        font-size: 11px;
    }

    .rich-text-editor .rte-media-drag-hint {
        bottom: 10px;
        font-size: 12px;
        white-space: normal;
    }
}

/* publish 页面：隐藏顶部搜索、工具栏滚动吸附 */
body.page-publish #index-header .input-box,
body.page-publish #index-header .mobile-search-btn {
    display: none !important;
}

body.page-publish .publish-post-container {
    overflow: visible !important;
}

body.page-publish .rich-text-editor-wrapper {
    overflow: visible;
}

body.page-publish .rte-toolbar-sticky-placeholder {
    display: none;
    width: 100%;
    flex-shrink: 0;
}

.qg-publish-page .rich-text-toolbar,
body.page-publish .rich-text-toolbar {
    z-index: 90;
}

body.page-publish .rich-text-toolbar.is-toolbar-floating,
.qg-publish-page .rich-text-toolbar.is-toolbar-floating {
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
    border-radius: 8px 8px 0 0;
    z-index: 90;
}

