/* Markdown 在线编辑器 —— 工具私有样式（颜色全部走 app.css 令牌） */

.me-tool {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    min-width: 0;
}

/* ========== 顶部工具栏 ========== */

.me-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

.me-toolbar-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.me-toolbar-right {
    margin-left: auto;
}

.me-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.me-btn-icon {
    width: 15px;
    height: 15px;
}

.me-btn.is-active {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--accent);
}

.me-save-status {
    font-size: 12px;
    color: var(--text-tertiary);
    white-space: nowrap;
}

.me-save-status.is-saving {
    color: var(--color-warning);
}

/* ---- 工具栏 tooltip（data-tooltip 属性，工具私有，避免与全局冲突） ---- */

.me-tool [data-tooltip] {
    position: relative;
}

.me-tool [data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%) translateY(-3px);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    background: var(--text-primary);
    color: var(--bg-primary);
    font-size: 12px;
    line-height: 1.4;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 500;
}

.me-tool [data-tooltip]:hover::after,
.me-tool [data-tooltip]:focus-visible::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* 右侧按钮组的 tooltip 靠右对齐，防止溢出视口 */
.me-toolbar-right [data-tooltip]::after {
    left: auto;
    right: 0;
    transform: translateY(-3px);
}

.me-toolbar-right [data-tooltip]:hover::after,
.me-toolbar-right [data-tooltip]:focus-visible::after {
    transform: translateY(0);
}

/* ========== 编辑区（Vditor） ========== */

.me-editor-wrap {
    flex: 1;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    background: var(--bg-secondary);
}

.me-editor-wrap .vditor {
    height: 100%;
    border: none;
    border-radius: 0;
    background: transparent;
}

/* 用项目令牌覆盖 Vditor 组件色，保持与站点皮肤一致 */
.me-tool .vditor {
    --border-color: var(--border);
    --panel-background-color: var(--bg-secondary);
    --panel-shadow: var(--shadow-lg);
    --second-color: var(--text-secondary);
    --textarea-background-color: var(--bg-primary);
    --textarea-text-color: var(--text-primary);
    --toolbar-background-color: var(--bg-secondary);
    --toolbar-icon-color: var(--text-secondary);
    --toolbar-icon-hover-color: var(--text-primary);
    --toolbar-height: 38px;
    --toolbar-divider-margin-top: 9px;
    --resize-background-color: var(--bg-hover);
    --resize-icon-color: var(--text-tertiary);
    --resize-hover-background-color: var(--accent);
    --resize-hover-icon-color: var(--text-on-accent);
    --count-background-color: var(--bg-secondary);
    --blockquote-color: var(--text-secondary);
    --ir-heading-color: var(--accent);
    --ir-bi-color: var(--accent);
    --ir-link-color: var(--accent);
    --ir-title-color: var(--text-tertiary);
    --ir-bracket-color: var(--accent);
    --ir-paren-color: var(--text-tertiary);
    font-family: var(--font-sans);
}

.me-tool .vditor-toolbar {
    border-bottom: 1px solid var(--border);
    padding-left: 12px;
}

/* 编辑区「画布 + 纸张」层次：外层画布 --bg-secondary，文档页 --bg-primary。
   保持 Vditor 原生滚动模型（pre 定高 + overflow:auto 内部滚动），仅留出画布边距。 */
.me-tool .vditor .vditor-content {
    background: var(--bg-secondary);
}

.me-tool .vditor .vditor-ir pre.vditor-reset,
.me-tool .vditor .vditor-ir pre.vditor-reset:focus {
    background-color: var(--bg-primary);
    box-sizing: border-box;
    width: auto;
    max-width: min(960px, calc(100% - 40px));
    margin: 20px auto;
    height: calc(100% - 40px);
    padding: 32px 48px 64px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

@media (min-width: 1400px) {
    .me-tool .vditor .vditor-ir pre.vditor-reset,
    .me-tool .vditor .vditor-ir pre.vditor-reset:focus {
        max-width: min(1200px, calc(100% - 64px));
        padding: 36px 56px 72px;
    }
}

@media (min-width: 1800px) {
    .me-tool .vditor .vditor-ir pre.vditor-reset,
    .me-tool .vditor .vditor-ir pre.vditor-reset:focus {
        max-width: min(1440px, calc(100% - 80px));
        padding: 40px 64px 80px;
    }
}

@media (min-width: 2200px) {
    .me-tool .vditor .vditor-ir pre.vditor-reset,
    .me-tool .vditor .vditor-ir pre.vditor-reset:focus {
        max-width: min(1680px, calc(100% - 96px));
        padding: 44px 72px 88px;
    }
}

.me-tool .vditor .vditor-ir pre.vditor-ir__marker--pre {
    font-family: var(--font-mono);
}

/* 斜杠菜单触发时禁用内容区的多余 outline */
.me-tool .vditor-ir__node--expand[data-type="html-block"] {
    border-radius: var(--radius-sm);
}

/* ---- 内容区颜色全部走令牌（适配暗色模式与全部皮肤） ---- */

.me-tool .vditor-reset {
    color: var(--text-primary);
}

.me-tool .vditor-reset h1,
.me-tool .vditor-reset h2,
.me-tool .vditor-reset h3,
.me-tool .vditor-reset h4,
.me-tool .vditor-reset h5,
.me-tool .vditor-reset h6 {
    color: var(--text-primary);
    border-bottom-color: var(--border);
}

.me-tool .vditor-reset a {
    color: var(--accent);
}

.me-tool .vditor-reset blockquote {
    color: var(--text-secondary);
    border-left-color: var(--border);
    background: transparent;
}

.me-tool .vditor-reset hr {
    background-color: var(--border);
    border-color: var(--border);
}

.me-tool .vditor-reset code:not(.hljs):not(.highlight-chroma) {
    background-color: var(--bg-input);
    color: var(--text-primary);
}

/* 标题左侧 H1~H6 级别徽标颜色 */
.me-tool .vditor-ir .vditor-reset > h1:before,
.me-tool .vditor-ir .vditor-reset > h2:before,
.me-tool .vditor-ir .vditor-reset > h3:before,
.me-tool .vditor-ir .vditor-reset > h4:before,
.me-tool .vditor-ir .vditor-reset > h5:before,
.me-tool .vditor-ir .vditor-reset > h6:before {
    color: var(--text-tertiary);
}

/* ---- 隐藏编辑态的 Markdown 标记符号（类飞书观感） ----
   仅隐藏语法符号（#、**、```、链接括号等），列表/引用标记保留以保证结构可读 */
.me-tool .vditor-ir .vditor-ir__node .vditor-ir__marker--heading,
.me-tool .vditor-ir .vditor-ir__node .vditor-ir__marker--bi,
.me-tool .vditor-ir .vditor-ir__node .vditor-ir__marker--link,
.me-tool .vditor-ir .vditor-ir__node .vditor-ir__marker--bracket,
.me-tool .vditor-ir .vditor-ir__node .vditor-ir__marker--paren,
.me-tool .vditor-ir .vditor-ir__node .vditor-ir__marker--title,
.me-tool .vditor-ir .vditor-ir__node .vditor-ir__marker--info,
.me-tool .vditor-ir .vditor-ir__node .vditor-ir__marker--pre,
.me-tool .vditor-ir .vditor-ir__node--expand .vditor-ir__marker--heading,
.me-tool .vditor-ir .vditor-ir__node--expand .vditor-ir__marker--bi,
.me-tool .vditor-ir .vditor-ir__node--expand .vditor-ir__marker--link,
.me-tool .vditor-ir .vditor-ir__node--expand .vditor-ir__marker--bracket,
.me-tool .vditor-ir .vditor-ir__node--expand .vditor-ir__marker--paren,
.me-tool .vditor-ir .vditor-ir__node--expand .vditor-ir__marker--title,
.me-tool .vditor-ir .vditor-ir__node--expand .vditor-ir__marker--info,
.me-tool .vditor-ir .vditor-ir__node--expand .vditor-ir__marker--pre {
    display: inline-block;
    width: 0;
    height: 0;
    padding: 0 !important;
    overflow: hidden;
    visibility: hidden;
}

/* ========== 预览区（画布 + 纸张层次） ========== */

.me-preview {
    flex: 1;
    min-height: 0;
    min-width: 0;
    overflow-y: auto;
    background: var(--bg-secondary);
}

.me-preview-scroll {
    box-sizing: border-box;
    width: auto;
    max-width: min(960px, calc(100% - 40px));
    margin: 20px auto;
    min-height: calc(100% - 40px);
    padding: 32px 48px 64px;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

@media (min-width: 1400px) {
    .me-preview-scroll {
        max-width: min(1200px, calc(100% - 64px));
        padding: 36px 56px 72px;
    }
}

@media (min-width: 1800px) {
    .me-preview-scroll {
        max-width: min(1440px, calc(100% - 80px));
        padding: 40px 64px 80px;
    }
}

@media (min-width: 2200px) {
    .me-preview-scroll {
        max-width: min(1680px, calc(100% - 96px));
        padding: 44px 72px 88px;
    }
}

.me-preview-doc {
    min-height: 200px;
}

/* 预览与导出 HTML 的固定页脚广告区（高度统一限制） */
.me-footer {
    margin-top: 48px;
    height: 52px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-top: 1px solid var(--border);
    color: var(--text-tertiary);
    font-size: 13px;
    text-align: center;
}

.me-footer a {
    color: var(--accent);
    text-decoration: none;
}

.me-footer a:hover {
    text-decoration: underline;
}

/* ========== 浮动菜单（区块 / 导出） ========== */

.me-menu {
    position: fixed;
    z-index: 500;
    min-width: 200px;
    max-width: 280px;
    max-height: 320px;
    overflow-y: auto;
    padding: 6px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

.me-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font-sans);
    text-align: left;
    cursor: pointer;
    transition: var(--transition);
}

.me-menu-item:hover,
.me-menu-item.is-active {
    background: var(--bg-hover);
}

.me-menu-item-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--text-secondary);
}

.me-menu-label {
    flex: 1;
    white-space: nowrap;
}

.me-menu-hint {
    font-size: 11px;
    color: var(--text-tertiary);
    white-space: nowrap;
}

/* ========== 弹窗细节 ========== */

.me-modal-desc {
    margin: 0 0 14px;
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.6;
    word-break: break-all;
}

.me-modal-hint {
    margin: 10px 0 0;
    font-size: 12px;
    color: var(--text-tertiary);
    line-height: 1.6;
}

.me-modal-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ========== 媒体缺失占位 ========== */

.me-media-missing {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-tertiary);
    font-size: 12px;
}

/* ========== 导出渲染容器（PNG / PDF / TXT / DOCX 共用） ========== */
/* 说明：以下为「导出的白纸黑字文档页」功能色（参照 screen-marker 功能色先例），
   导出产物固定为 A4 白纸风格，不随站点皮肤变化，故不走令牌。 */

.me-export-render {
    position: fixed;
    left: -10000px;
    top: 0;
    width: 794px; /* A4 @ 96dpi */
    padding: 72px 72px 48px;
    background: #ffffff;
    color: #1f2328;
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.75;
    box-sizing: border-box;
    z-index: -1;
}

.me-export-render img {
    max-width: 100%;
    height: auto;
}

.me-export-render video {
    max-width: 100%;
}

/* 栅格导出（PNG/PDF）中的视频占位卡片 */
.me-video-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    margin: 12px 0;
    border: 1px solid #e1e4e8;
    border-radius: 8px;
    background: #f6f8fa;
    color: #57606a;
    font-size: 14px;
}

.me-video-card svg {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

/* 栅格导出页脚条（固定高度，简化样式） */
.me-export-footer {
    margin-top: 40px;
    height: 52px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border-top: 1px solid #e1e4e8;
    color: #8b949e;
    font-size: 12px;
    text-align: center;
    box-sizing: border-box;
}

/* ========== 响应式 ========== */

@media (max-width: 768px) {
    .me-toolbar {
        padding: 8px 10px;
        gap: 8px;
    }

    .me-btn span {
        display: none;
    }

    .me-save-status {
        font-size: 11px;
    }

    .me-tool .vditor .vditor-ir pre.vditor-reset,
    .me-tool .vditor .vditor-ir pre.vditor-reset:focus,
    .me-preview-scroll {
        padding-left: 20px;
        padding-right: 20px;
    }
}

@media (max-width: 480px) {
    .me-toolbar-right {
        margin-left: 0;
    }

    .me-menu {
        max-width: calc(100vw - 32px);
    }
}
