/* ========== 富文本编辑器组件 rich-editor ==========
   依赖 lib/quill/quill.snow.css；默认暗金主题，
   news.html 浅色主题通过 body[data-theme="light"] 覆盖变量生效 */

.rich-editor {
    --re-border: rgba(255,255,255,0.14);
    --re-icon: rgba(255,255,255,0.65);
    --re-sub: rgba(255,255,255,0.45);
    --re-text: rgba(255,255,255,0.85);
    --re-strong: #F0EDE6;
    --re-gold: #d4a853;
    --re-top-bg: #1E1928;
    --re-select-bg: rgba(255,255,255,0.06);
    --re-picker-bg: #26202f;
    --re-source-bg: #171320;
    --re-code-text: #e6e1d6;
    --re-th-bg: rgba(255,255,255,0.06);
    --re-zebra: rgba(255,255,255,0.03);
    position: relative;
    color: var(--re-text);
}

/* ---- 顶部（模式标签+源码按钮+工具栏），可随宿主页面吸顶 ---- */
.rich-editor .re-top {
    position: sticky;
    top: var(--re-top, 0px);
    z-index: 30;
    background: var(--re-top-bg);
    padding-top: 2px;
}
.rich-editor .re-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0;
}
.rich-editor .re-mode-label {
    font-size: 12px;
    color: var(--re-sub);
    opacity: 0.8;
}
.rich-editor .re-src-btn {
    border: 1px solid var(--re-border);
    background: transparent;
    color: var(--re-icon);
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all .2s;
}
.rich-editor .re-src-btn:hover {
    border-color: rgba(212,168,83,0.5);
    color: var(--re-gold);
}
.rich-editor .re-src-btn.active {
    background: var(--re-gold);
    border-color: var(--re-gold);
    color: #26201a;
    font-weight: 600;
}

/* ---- 工具栏（Quill snow 覆盖） ---- */
.rich-editor .re-toolbar.ql-toolbar.ql-snow {
    border: none;
    background: transparent;
    padding: 2px 0 8px;
}
.rich-editor .re-tb-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 4px;
}
.rich-editor .re-tb-row + .re-tb-row { margin-top: 4px; }
.rich-editor .re-toolbar button {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    flex: none;
}
.rich-editor .re-toolbar button:hover,
.rich-editor .re-toolbar button.ql-active {
    background: var(--re-select-bg);
}
.rich-editor .re-toolbar .ql-stroke { stroke: var(--re-icon); }
.rich-editor .re-toolbar .ql-fill,
.rich-editor .re-toolbar .ql-stroke.ql-fill { fill: var(--re-icon); }
.rich-editor .re-toolbar button:hover .ql-stroke,
.rich-editor .re-toolbar button.ql-active .ql-stroke,
.rich-editor .re-toolbar .ql-picker-label:hover .ql-stroke,
.rich-editor .re-toolbar .ql-picker-label.ql-active .ql-stroke { stroke: var(--re-gold); }
.rich-editor .re-toolbar button:hover .ql-fill,
.rich-editor .re-toolbar button.ql-active .ql-fill,
.rich-editor .re-toolbar .ql-picker-label:hover .ql-fill,
.rich-editor .re-toolbar .ql-picker-label.ql-active .ql-fill { fill: var(--re-gold); }
.rich-editor .re-toolbar button:hover,
.rich-editor .re-toolbar button.ql-active { color: var(--re-gold); }
.rich-editor .re-toolbar .ql-picker {
    color: var(--re-icon);
    height: 30px;
    flex: none;
}
.rich-editor .re-toolbar .ql-picker-label {
    border-color: transparent;
    border-radius: 6px;
}
.rich-editor .re-toolbar .ql-picker-label:hover { background: var(--re-select-bg); }
.rich-editor .re-toolbar .ql-picker.ql-expanded .ql-picker-label {
    background: var(--re-select-bg);
    border-color: var(--re-border);
}
.rich-editor .re-toolbar .ql-picker-options {
    background: var(--re-picker-bg);
    border-color: var(--re-border);
    border-radius: 8px;
}
.rich-editor .re-toolbar .ql-picker-item { color: var(--re-text); }
.rich-editor .re-toolbar .ql-picker-item:hover { color: var(--re-gold); }
.rich-editor .re-toolbar .ql-picker.ql-font,
.rich-editor .re-toolbar .ql-picker.ql-header { width: auto; min-width: 88px; }
/* 自定义表格按钮图标 */
.rich-editor .re-toolbar button.ql-re-table::before {
    content: '▦';
    font-size: 17px;
    line-height: 1;
    color: var(--re-icon);
}
.rich-editor .re-toolbar button.ql-re-table:hover::before,
.rich-editor .re-toolbar button.ql-re-table.ql-active::before { color: var(--re-gold); }

/* ---- 编辑区 ---- */
.rich-editor .ql-container.ql-snow {
    border: none;
    background: transparent;
    font-size: 16px;
    font-family: inherit;
    color: var(--re-text);
}
.rich-editor .ql-editor {
    line-height: 1.9;
    min-height: 240px;
    padding-left: 2px;
    padding-right: 2px;
}
.rich-editor .ql-editor.ql-blank::before {
    color: var(--re-sub);
    opacity: 0.6;
    font-style: normal;
}
.rich-editor .ql-editor img { max-width: 100%; border-radius: 6px; }
.rich-editor .ql-editor a { color: var(--re-gold); }
.rich-editor .ql-editor blockquote {
    border-left: 3px solid var(--re-gold);
    background: var(--re-zebra);
    color: var(--re-sub);
}

/* 编辑区内表格（嵌入块） */
.rich-editor .ql-editor table {
    border-collapse: separate;
    border-spacing: 0;
    margin: 14px 0;
    width: 100%;
    font-size: 14px;
    border: 1px solid var(--re-border);
    border-radius: 8px;
    overflow: hidden;
}
.rich-editor .ql-editor td,
.rich-editor .ql-editor th {
    border-bottom: 1px solid var(--re-border);
    border-right: 1px solid var(--re-border);
    padding: 8px 12px;
    min-width: 40px;
    cursor: text;
}
.rich-editor .ql-editor td:focus,
.rich-editor .ql-editor th:focus {
    outline: 2px solid var(--re-gold);
    outline-offset: -2px;
    background: rgba(212,168,83,0.06);
}
.rich-editor .ql-editor td:last-child,
.rich-editor .ql-editor th:last-child { border-right: none; }
.rich-editor .ql-editor tr:last-child td { border-bottom: none; }
.rich-editor .ql-editor th {
    background: var(--re-th-bg);
    color: var(--re-strong);
    font-weight: 600;
    text-align: left;
}
.rich-editor .ql-editor tbody tr:nth-child(even) { background: var(--re-zebra); }

/* 代码块（连续行视觉合并为一个块） */
.rich-editor .ql-editor .ql-code-block {
    background: var(--re-source-bg);
    color: var(--re-code-text);
    font-family: Consolas, Monaco, 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.7;
    padding: 2px 14px;
    margin: 0;
    border-radius: 0;
    overflow-x: auto;
}
.rich-editor .ql-editor :not(.ql-code-block) + .ql-code-block {
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    padding-top: 10px;
    margin-top: 10px;
}
.rich-editor .ql-editor .ql-code-block:not(:has(+ .ql-code-block)) {
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    padding-bottom: 10px;
    margin-bottom: 10px;
}

/* ---- HTML 源码编辑区 ---- */
.rich-editor .re-source {
    width: 100%;
    min-height: 240px;
    box-sizing: border-box;
    border: 1px solid var(--re-border);
    border-radius: 8px;
    background: var(--re-source-bg);
    color: var(--re-code-text);
    font-family: Consolas, Monaco, 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.7;
    padding: 12px 14px;
    resize: vertical;
    outline: none;
}
.rich-editor .re-source:focus { border-color: rgba(212,168,83,0.5); }

/* ---- 表格格选器 ---- */
.rich-editor .re-table-picker {
    position: absolute;
    z-index: 40;
    background: var(--re-picker-bg);
    border: 1px solid var(--re-border);
    border-radius: 10px;
    padding: 10px;
    box-shadow: 0 6px 24px rgba(0,0,0,0.35);
}
.rich-editor .re-tp-grid {
    display: grid;
    grid-template-columns: repeat(6, 22px);
    gap: 4px;
}
.rich-editor .re-tp-cell {
    width: 22px;
    height: 22px;
    border: 1px solid var(--re-border);
    border-radius: 4px;
    cursor: pointer;
    transition: background .1s;
}
.rich-editor .re-tp-cell.active {
    background: var(--re-gold);
    border-color: var(--re-gold);
}
.rich-editor .re-tp-label {
    margin-top: 8px;
    font-size: 12px;
    color: var(--re-sub);
    text-align: center;
    white-space: nowrap;
}

/* ---- 表格右键菜单 ---- */
.re-ctx-menu {
    position: fixed;
    z-index: 50;
    background: var(--re-picker-bg, #26202f);
    border: 1px solid var(--re-border, rgba(255,255,255,0.14));
    border-radius: 8px;
    padding: 4px 0;
    box-shadow: 0 4px 16px rgba(0,0,0,0.35);
    min-width: 140px;
}
.re-ctx-item {
    padding: 7px 16px;
    font-size: 13px;
    color: var(--re-icon, rgba(255,255,255,0.65));
    cursor: pointer;
    white-space: nowrap;
    transition: background .12s, color .12s;
}
.re-ctx-item:hover {
    background: var(--re-select-bg, rgba(255,255,255,0.06));
    color: var(--re-gold, #d4a853);
}

/* ---- 单元格选中高亮 ---- */
.rich-editor .ql-editor td.re-tcell-active,
.rich-editor .ql-editor th.re-tcell-active {
    outline: 2px solid var(--re-gold);
    outline-offset: -2px;
    background: rgba(212,168,83,0.1) !important;
}

/* ---- 浅色主题（news.html 明暗切换） ---- */
body[data-theme="light"] .rich-editor {
    --re-border: #E3DDCF;
    --re-icon: #7a7161;
    --re-sub: #9a917f;
    --re-text: #2F2B24;
    --re-strong: #1F1A12;
    --re-gold: #A87E2F;
    --re-top-bg: #FBFAF6;
    --re-select-bg: rgba(0,0,0,0.045);
    --re-picker-bg: #FFFFFF;
    --re-source-bg: #F0EBDD;
    --re-code-text: #4a4234;
    --re-th-bg: #F5F1E6;
    --re-zebra: rgba(0,0,0,0.02);
}
body[data-theme="light"] .rich-editor .re-table-picker {
    box-shadow: 0 6px 24px rgba(90,70,30,0.18);
}
body[data-theme="light"] .re-ctx-menu {
    box-shadow: 0 4px 16px rgba(90,70,30,0.18);
}

/* ---- 移动端 ---- */
@media (max-width: 768px) {
    .rich-editor .re-tb-row {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }
    .rich-editor .re-toolbar button { width: 34px; height: 34px; }
    .rich-editor .re-toolbar .ql-picker { height: 34px; }
    .rich-editor .ql-container.ql-snow { font-size: 15px; }
    .rich-editor .ql-editor { line-height: 1.8; }
    /* 宽表格横向滑动 */
    .rich-editor .ql-editor table {
        display: block;
        overflow-x: auto;
        max-width: 100%;
    }
    .rich-editor .re-source { font-size: 12px; }
    .re-ctx-menu {
        max-width: calc(100vw - 16px);
    }
    .re-ctx-item { font-size: 12px; padding: 6px 12px; }
}
