/* ==========================================================================
   编辑器
   桌面：左边写作（所见即所得）+ 右边"读者视角"预览
   移动：单栏，格式工具坞钉在底部（软键盘弹出来也不挡）

   正文样式这一块是 post.css 的镜像：写作区里看到的排版 = 帖子里渲染出来的排版。
   变量名对得上（--p-text 对应 --nz-text、--p-accent 对应 --nz-accent-deep …），
   改 post.css 的时候记得这里也过一眼。
   ========================================================================== */

.nz-editor {
    --nz-ed-head-h: 56px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}
.nz-editor-main {
    flex: 1 1 auto;
    width: 100%;
    max-width: 1720px;
    margin: 0 auto;
    padding: 16px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(400px, 600px);
    gap: 16px;
    align-items: start;
}
.nz-editor-left {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
    height: calc(100vh - var(--nz-ed-head-h) - 32px);
    min-height: 560px;
}
.nz-editor-right {
    position: sticky;
    top: calc(var(--nz-ed-head-h) + 16px);
    height: calc(100vh - var(--nz-ed-head-h) - 32px);
    min-height: 560px;
    display: flex;
    flex-direction: column;
}

/* 顶栏 */
.nz-editor-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--nz-border);
    background: var(--nz-panel);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    position: sticky;
    top: 0;
    z-index: 50;
    flex-wrap: wrap;
    min-height: var(--nz-ed-head-h);
}
.nz-editor-head .nz-grow { flex: 1 1 auto; }

/* 顶部那三栏设置 */
.nz-editor-fields { display: flex; flex-flow: row wrap; gap: 12px; flex: 0 0 auto; }
.nz-editor-fields .nz-field { gap: 6px; }

/* ── 写作区 ───────────────────────────────────── */

.nz-write {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    background: var(--nz-surface);
    border: 1px solid var(--nz-border);
    border-radius: var(--nz-radius-md);
    overflow: hidden;
    box-shadow: var(--nz-shadow-xs);
}
.nz-title-input {
    border: 0;
    border-bottom: 1px solid var(--nz-border-soft);
    padding: 14px 18px;
    font-size: var(--nz-fs-xl);
    font-weight: 700;
    color: var(--nz-text-strong);
    background: transparent;
    outline: none;
    flex: 0 0 auto;
}
.nz-title-input::placeholder { color: var(--nz-text-faint); font-weight: 600; }

.nz-write-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
}
.nz-rich-editor { min-height: 100%; }
.nz-textarea-write {
    flex: 1 1 auto;
    min-height: 100%;
    padding: 16px 18px;
    border: 0;
    background: transparent;
    resize: none;
    outline: none;
    font-family: var(--nz-font-mono);
    font-size: 13.5px;
    line-height: 1.9;
    color: var(--nz-text);
    tab-size: 2;
    white-space: pre-wrap;
    word-break: break-word;
}

.nz-write-foot {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 7px 14px;
    border-top: 1px solid var(--nz-border-soft);
    background: var(--nz-surface-2);
    font-size: var(--nz-fs-xs);
    color: var(--nz-text-faint);
    flex-wrap: wrap;
    flex: 0 0 auto;
}
.nz-write.drop-active { outline: 2px dashed var(--nz-accent); outline-offset: -4px; }

.nz-upload-bar { height: 3px; background: var(--nz-surface-3); overflow: hidden; flex: 0 0 auto; }
.nz-upload-bar span { display: block; height: 100%; width: 0; background: var(--nz-accent); transition: width var(--nz-dur) var(--nz-ease); }

/* 附件队列 */
.nz-filelist {
    display: flex; flex-direction: column; gap: 6px;
    padding: 8px 14px;
    border-top: 1px solid var(--nz-border-soft);
    flex: 0 0 auto;
    max-height: 168px;
    overflow-y: auto;
}
.nz-file-sum { font-size: var(--nz-fs-xs); color: var(--nz-text-faint); padding: 0 2px 2px; }
.nz-file-row {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 10px;
    border-radius: var(--nz-radius-xs);
    background: var(--nz-surface-2);
    font-size: var(--nz-fs-xs);
}
.nz-file-row.is-done { background: var(--nz-success-soft); }
.nz-file-row.is-error { background: var(--nz-danger-soft); }

/* ── 工具栏 ───────────────────────────────────── */

.nz-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 5px 8px;
    border-bottom: 1px solid var(--nz-border-soft);
    background: var(--nz-surface-2);
    /* 折行而不是横向滚动：滚动条里的按钮等于"没有这个功能" */
    flex-wrap: wrap;
    flex: 0 0 auto;
}
.nz-toolbar::-webkit-scrollbar { display: none; }
.nz-toolbar.is-hidden { display: none; }
.nz-tool {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: transparent;
    color: var(--nz-text-sub);
    border-radius: var(--nz-radius-xs);
    cursor: pointer;
    transition: background var(--nz-dur-fast) var(--nz-ease), color var(--nz-dur-fast) var(--nz-ease);
}
.nz-tool:hover { background: var(--nz-accent-soft); color: var(--nz-accent-deep); }
.nz-tool:active { transform: scale(.94); }
.nz-tool.is-active { background: var(--nz-accent-soft); color: var(--nz-accent-deep); }
.nz-tool.is-active .nz-icon { fill: color-mix(in srgb, currentColor 18%, transparent); }
.nz-tool-sep { flex: 0 0 auto; width: 1px; height: 20px; background: var(--nz-border); margin: 0 4px; }
.nz-tb-select { flex: 0 0 auto; position: relative; }
.nz-tb-select select {
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid transparent;
    background: transparent;
    color: var(--nz-text-sub);
    font-size: var(--nz-fs-xs);
    font-weight: 600;
    height: 32px;
    padding: 0 22px 0 8px;
    border-radius: var(--nz-radius-xs);
    cursor: pointer;
    max-width: 104px;
}
.nz-tb-select select:hover { background: var(--nz-accent-soft); color: var(--nz-accent-deep); }
.nz-tb-select option { color: var(--nz-text); background: var(--nz-surface); }
.nz-tb-select::after {
    content: '';
    position: absolute; right: 7px; top: 50%;
    width: 6px; height: 6px; margin-top: -4px;
    border-right: 1.6px solid currentColor; border-bottom: 1.6px solid currentColor;
    transform: rotate(45deg);
    color: var(--nz-text-faint);
    pointer-events: none;
}

/* 小弹层（颜色 / 对齐） */
.nz-tb-pop {
    position: fixed;
    z-index: 200;
    background: var(--nz-surface);
    border: 1px solid var(--nz-border);
    border-radius: var(--nz-radius-sm);
    box-shadow: var(--nz-shadow);
    padding: 10px;
    min-width: 172px;
    animation: nz-pop-in var(--nz-dur-fast) var(--nz-ease-out);
}
@keyframes nz-pop-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.nz-pop-title { font-size: var(--nz-fs-xs); color: var(--nz-text-faint); margin-bottom: 8px; }
.nz-swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.nz-swatch {
    width: 18px; height: 18px;
    border-radius: 5px;
    border: 1px solid var(--nz-border);
    cursor: pointer;
    padding: 0;
}
.nz-swatch:hover { transform: scale(1.12); }
.nz-input-sm { height: 30px; font-size: var(--nz-fs-xs); }

/* ── 写作区里的正文（post.css 的镜像）───────────── */

.nz-rich-editor {
    flex: 1 1 auto;
    padding: 16px 20px 48px;
    outline: none;
    color: var(--nz-text);
    font-size: 15px;
    line-height: 1.85;
    word-wrap: break-word;
    overflow-wrap: break-word;
    caret-color: var(--nz-accent-deep);
}
.nz-rich-editor { position: relative; }
/* 占位符绝对定位：不占正文流，光标还是停在第一行 */
.nz-rich-editor.is-empty::before {
    content: attr(data-placeholder);
    position: absolute;
    left: 20px;
    right: 20px;
    top: 16px;
    color: var(--nz-text-faint);
    white-space: pre-wrap;
    pointer-events: none;
}
.nz-rich-editor > *:first-child { margin-top: 0; }
.nz-rich-editor p { margin: 12px 0; }
.nz-rich-editor h1, .nz-rich-editor h2, .nz-rich-editor h3,
.nz-rich-editor h4, .nz-rich-editor h5, .nz-rich-editor h6 {
    color: var(--nz-text-strong); line-height: 1.4; margin: 20px 0 10px; font-weight: 700;
}
.nz-rich-editor h1 { font-size: 1.6em; }
.nz-rich-editor h2 { font-size: 1.36em; padding-bottom: 6px; border-bottom: 1px solid var(--nz-border); }
.nz-rich-editor h3 { font-size: 1.18em; }
.nz-rich-editor h4 { font-size: 1.05em; }
.nz-rich-editor a { color: var(--nz-accent-deep); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--nz-accent-deep) 35%, transparent); }
.nz-rich-editor hr { border: 0; border-top: 1px solid var(--nz-border); margin: 20px 0; }
.nz-rich-editor blockquote {
    margin: 14px 0; padding: 8px 16px;
    border-left: 3px solid var(--nz-accent);
    background: var(--nz-surface-3);
    border-radius: 0 8px 8px 0;
    color: var(--nz-text-sub);
}
.nz-rich-editor code {
    font-family: var(--nz-font-mono);
    font-size: .9em;
    background: var(--nz-surface-2);
    padding: 2px 6px;
    border-radius: 5px;
    border: 1px solid var(--nz-border);
}
.nz-rich-editor pre {
    background: var(--nz-surface-2);
    border: 1px solid var(--nz-border);
    border-radius: 10px;
    padding: 14px 16px;
    overflow-x: auto;
    margin: 14px 0;
    white-space: pre-wrap;
}
.nz-rich-editor pre code { background: transparent; border: 0; padding: 0; font-size: .88em; line-height: 1.7; }
.nz-rich-editor ul, .nz-rich-editor ol { margin: 12px 0; padding-left: 24px; }
.nz-rich-editor ul { list-style: disc; }
.nz-rich-editor ol { list-style: decimal; }
.nz-rich-editor li { margin: 5px 0; }
.nz-rich-editor table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: .95em; }
.nz-rich-editor th, .nz-rich-editor td { border: 1px solid var(--nz-border); padding: 8px 12px; text-align: left; }
.nz-rich-editor th { background: var(--nz-surface-3); color: var(--nz-text-strong); font-weight: 700; }
.nz-rich-editor img {
    max-width: 100%;
    max-height: 60vh;
    height: auto;
    border-radius: 10px;
    object-fit: contain;
    display: block;
}
.nz-rich-editor video { max-width: 100%; max-height: 56vh; border-radius: 10px; display: block; }
.nz-rich-editor audio { width: 100%; }
.nz-rich-editor iframe { width: 100%; border: 0; border-radius: 12px; background: var(--nz-surface-2); }

/* 媒体 / 附件卡片（跟 post.css 里那几套同名） */
.nz-rich-editor .video-container { margin: 14px 0; border-radius: 12px; overflow: hidden; background: #000; }
.nz-rich-editor .video-container video { width: auto; max-width: 100%; max-height: 56vh; margin: 0 auto; }
.nz-rich-editor .audio-card,
.nz-rich-editor .file-card {
    display: flex; align-items: center; gap: 12px;
    margin: 14px 0; padding: 12px 14px;
    border: 1px solid var(--nz-border); border-radius: 12px; background: var(--nz-surface-2);
}
.nz-rich-editor .audio-card audio { flex: 1 1 auto; min-width: 0; }
.nz-rich-editor .file-card-icon {
    width: 40px; height: 40px; border-radius: 10px; flex: 0 0 auto;
    background: var(--nz-surface-3); color: var(--nz-accent-deep);
    display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 12px;
}
.nz-rich-editor .file-card-info { flex: 1 1 auto; min-width: 0; }
.nz-rich-editor .file-card-name { font-weight: 700; color: var(--nz-text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nz-rich-editor .file-card-size { font-size: 12px; color: var(--nz-text-sub); }
.nz-rich-editor .file-card-dl {
    flex: 0 0 auto; padding: 7px 14px; border-radius: 999px;
    background: var(--nz-accent); color: #fff !important; border: 0 !important;
    font-size: 13px; font-weight: 700; text-decoration: none;
}
.nz-rich-editor .spoiler-box {
    margin: 14px 0; padding: 12px 14px;
    border: 1px dashed var(--nz-border); border-radius: 12px;
    background: var(--nz-surface-2);
}
.nz-rich-editor .spoiler-box .spoiler-title { font-weight: 700; color: var(--nz-text-strong); }
.nz-rich-editor .spoiler-box .spoiler-body { margin-top: 8px; }
.nz-rich-editor .nz-mention-chip { cursor: default; }

/* 还没传完的附件块 */
.nz-rt-figure { margin: 14px 0; position: relative; }
.nz-rich-editor [data-nz-file] { position: relative; }
.nz-rich-editor .is-pending { opacity: .62; }
.nz-rich-editor .is-error { outline: 1px dashed var(--nz-danger); outline-offset: 3px; }
.nz-rt-badge {
    position: absolute;
    left: 10px; top: 10px;
    z-index: 2;
    padding: 3px 10px;
    border-radius: 999px;
    background: rgba(15, 28, 44, .74);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    font-family: var(--nz-font-sans, inherit);
    line-height: 1.7;
    pointer-events: none;
}
.nz-rich-editor .is-error > .nz-rt-badge { background: var(--nz-danger); }

/* ── 预览 ─────────────────────────────────────── */

.nz-preview {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--nz-surface);
    border: 1px solid var(--nz-border);
    border-radius: var(--nz-radius-md);
    overflow: hidden;
    box-shadow: var(--nz-shadow-xs);
}
.nz-preview-head {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--nz-border-soft);
    background: var(--nz-surface-2);
    flex: 0 0 auto;
}
.nz-preview-head .nz-btn-icon { width: 30px; height: 30px; padding: 0; }
.nz-preview-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--nz-surface-3);
    padding: 12px;
}
/* 双层沙箱的外层：一圈圆角"屏幕"，里面就是帖子页面本身 */
.nz-preview-screen {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    background: var(--nz-bg);
    border: 1px solid var(--nz-border);
    border-radius: var(--nz-radius-lg);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--nz-surface) 60%, transparent);
}
.nz-preview-page {
    display: flex;
    flex-direction: column;
    gap: var(--nz-gap);
    padding: 14px;
    min-height: 100%;
}
.nz-preview-page .nz-page-head { margin: 0; }
.nz-preview-page .nz-post-title-lg { font-size: clamp(19px, 2.6vw, 24px); }
/* 预览里的帖子卡片不要跟着鼠标变手型（点不动） */
.nz-preview-page a, .nz-preview-page button { cursor: default; }
.nz-preview-frame { width: 100%; border: 0; display: block; background: transparent; }

/* 手机预览 */
.nz-preview-body.is-phone { align-items: center; justify-content: center; }
.nz-phone {
    width: 320px;
    margin: 0 auto;
    border-radius: 34px;
    border: 10px solid #1f2b3a;
    background: #1f2b3a;
    box-shadow: var(--nz-shadow-modal);
    overflow: hidden;
    position: relative;
    flex: 0 1 auto;
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 880px;
    width: auto;
    aspect-ratio: 390 / 844;
    max-width: 100%;
    border-width: 11px;
    border-radius: 40px;
}
.nz-phone-notch {
    position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 130px; height: 22px; background: #1f2b3a;
    border-radius: 0 0 14px 14px; z-index: 3;
}
.nz-phone-screen {
    background: var(--nz-surface);
    border-radius: 30px;
    overflow: hidden;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.nz-phone-status {
    display: flex; justify-content: space-between; align-items: center;
    padding: 6px 14px; font-size: 10px; color: var(--nz-text-faint);
    border-bottom: 1px solid var(--nz-border-soft);
    flex: 0 0 auto;
}
.nz-phone-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    background: var(--nz-bg);
    overscroll-behavior: contain;
}
.nz-phone-scroll .nz-preview-page { padding: 10px; gap: 10px; }
.nz-phone-scroll .nz-post-title-lg { font-size: 18px; }
.nz-phone-scroll .nz-post-meta-right { gap: 6px; }

/* ── 移动端 ───────────────────────────────────── */

.nz-mobile-toolbar { display: none; }
.nz-editor-mobile-tabs { display: none; }
.nz-mobile-tabs-row { display: flex; gap: 8px; padding: 8px; }
.nz-mobile-tabs-row .nz-btn { flex: 1 1 0; }

@media (max-width: 1180px) {
    .nz-editor-main {
        grid-template-columns: minmax(0, 1fr);
        padding: 10px 10px 168px;
    }
    .nz-editor-left { height: auto; min-height: 0; }
    .nz-editor-right { position: static; height: auto; min-height: 0; }
    .nz-write { min-height: 0; }
    .nz-write-scroll { overflow: visible; }
    .nz-rich-editor, .nz-textarea-write { min-height: 46vh; font-size: 16px; padding: 14px 14px 32px; }
    .nz-preview-body.is-desktop { padding: 8px; }
    .nz-preview-screen { max-height: 74vh; }
    .nz-toolbar { display: none; }
    .nz-editor-main.is-preview .nz-editor-left { display: none; }
    .nz-editor-main:not(.is-preview) .nz-editor-right { display: none; }

    .nz-editor-mobile-tabs {
        display: block;
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: 70;
        background: var(--nz-panel-strong);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border-top: 1px solid var(--nz-border);
        padding-bottom: env(safe-area-inset-bottom, 0px);
        transition: transform var(--nz-dur-fast) var(--nz-ease);
    }
    .nz-mobile-toolbar {
        display: flex;
        align-items: center;
        gap: 2px;
        padding: 6px 8px 2px;
        overflow-x: auto;
        scrollbar-width: none;
    }
    .nz-mobile-toolbar.is-hidden { display: none; }
    .nz-mobile-toolbar::-webkit-scrollbar { display: none; }
    .nz-mobile-toolbar .nz-tool { width: 38px; height: 38px; }
    .nz-editor-main.is-preview .nz-mobile-toolbar { display: none; }
}

@media (max-width: 640px) {
    .nz-editor-fields { flex-direction: column; }
    .nz-editor-fields .nz-field { min-width: 0 !important; }
    .nz-title-input { font-size: var(--nz-fs-lg); padding: 12px 14px; }
    .nz-preview-page { padding: 10px; }
}
