/* ============================================================
   edit_article.css - 独立文章编辑器样式（已修复光标跳跃）
   架构：
     #editor-container (flex column, 固定高度)
       ├── .ql-toolbar    (flex: 0 0 auto)          工具栏固定顶部
       └── .ql-container  (flex: 1 1 auto, min-h:0) 内容容器
           └── .ql-editor (height:100%, overflow-y:auto) ← 唯一滚动区
   ★ 关键：.ql-editor 保持正常文档流，禁止 position:absolute
   前置条件：quill.snow.css 必须先于此文件加载
   ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    background: #f5f7fb;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", SimHei, sans-serif;
    font-size: 16px;
    line-height: 1.7;
    color: #333;
    padding: 24px;
}

.editor-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    padding: 24px 30px 30px;
}

.header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}
.header-bar h2 { font-weight: 400; font-size: 22px; }
.header-bar .actions { display: flex; gap: 10px; align-items: center; }

.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-weight: 500;
    font-size: 14px;
    margin-bottom: 4px;
    color: #1a1a1a;
}
.form-group .hint { font-weight: 400; color: #6b7280; font-size: 12px; }
.form-group input[type="text"],
.form-group input[type="url"] {
    width: 100%;
    padding: 8px 14px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: 15px;
    transition: 0.2s;
    background: #fafbfc;
}
/* 文章分类下拉框：与标题/角标输入框风格保持一致 */
.form-group select {
    width: 100%;
    padding: 8px 36px 8px 14px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: 15px;
    font-family: inherit;
    color: #1a1a1a;
    background: #fafbfc url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    cursor: pointer;
    transition: 0.2s;
}
.form-group select:hover { border-color: #d1d5db; }
.form-group select:focus {
    outline: none;
    border-color: #1a1a1a;
    background-color: #fff;
    box-shadow: 0 0 0 3px rgba(0,0,0,0.05);
}
.form-group select option { color: #1a1a1a; background: #fff; }
.form-group input:focus {
    outline: none;
    border-color: #1a1a1a;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(0,0,0,0.05);
}

/* 角标颜色选择器 */
.color-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 0;
}
.color-palette .color-option {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: 0.2s;
    position: relative;
    flex-shrink: 0;
}
.color-palette .color-option:hover { transform: scale(1.1); }
.color-palette .color-option.active {
    border-color: #1a1a1a;
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px #1a1a1a;
}
.color-palette .color-option .check {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: rgba(255,255,255,0.9);
    font-size: 14px;
    font-weight: 700;
    display: none;
}
.color-palette .color-option.active .check { display: block; }
.color-palette .color-option .check.dark { color: rgba(0,0,0,0.6); }

/* ============================================================
   ★ 编辑器容器（已修复光标跳跃）
   ============================================================ */
.editor-group { position: relative; }

/* 编辑模式切换栏 */
.editor-mode-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}
.editor-mode-bar .mode-btn {
    padding: 5px 14px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    color: #4b5563;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: 0.2s;
}
.editor-mode-bar .mode-btn:hover { background: #f3f4f6; }
.editor-mode-bar .mode-btn.active {
    background: #1a1a1a;
    border-color: #1a1a1a;
    color: #fff;
}
.editor-mode-bar .mode-tip {
    font-size: 12px;
    color: #9ca3af;
}

/* 代码编辑器（HTML 源码模式） */
.code-editor {
    display: none;
    width: 100%;
    height: 70vh;
    min-height: 420px;
    max-height: 820px;
    padding: 16px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #fafbfc;
    color: #1f2937;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 14px;
    line-height: 1.6;
    tab-size: 2;
    resize: vertical;
    white-space: pre;
    overflow-wrap: normal;
    overflow-x: auto;
    box-sizing: border-box;
}
.code-editor:focus {
    outline: none;
    border-color: #1a1a1a;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(0,0,0,0.05);
}

#editor-container {
    height: 70vh;
    min-height: 420px;
    max-height: 820px;
    display: flex;
    flex-direction: column;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    overflow: hidden;
    background: #fff;
}

#editor-container .ql-toolbar {
    flex: 0 0 auto;
    background: #fff;
    border: none !important;
    border-bottom: 1px solid #e5e7eb !important;
    padding: 8px 12px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    z-index: 10;
    position: static !important;
}

.ql-toolbar button.ql-gallery-toggle,
.ql-toolbar button.ql-net-image,
.ql-toolbar button.ql-video-code {
    border: 1px solid #ccc;
    border-radius: 3px;
    padding: 4px 10px;
    margin: 0 2px;
    cursor: pointer;
    background: #f9f9f9;
    font-size: 13px;
    flex: 0 0 auto;
    white-space: nowrap;
    height: 30px;
    line-height: 1.2;
}
.ql-toolbar button.ql-gallery-toggle:hover,
.ql-toolbar button.ql-net-image:hover,
.ql-toolbar button.ql-video-code:hover {
    background: #e6e6e6;
}

#editor-container .ql-container {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    overflow: hidden !important;
    border: none !important;
    border-radius: 0 !important;
    font-size: 16px;
    line-height: 1.7;
    color: #333;
    font-family: inherit;
}

/* ★ 禁止 position:absolute —— 这是光标跳跃的元凶 */
#editor-container .ql-editor {
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 16px 40px;
    font-size: 16px;
    line-height: 1.7;
    letter-spacing: 0.5px;
    color: #333;
    font-family: inherit;
    scroll-padding-top: 24px;
}

/* ============================================================
   ★ 视频 / iframe 居中
   ============================================================ */
.ql-editor .ql-video-wrapper {
    display: block !important;
    width: 100% !important;
    margin: 12px 0 !important;
    text-align: center !important;
    white-space: normal !important;
}
.ql-editor .ql-video-wrapper iframe,
.ql-editor .ql-video-wrapper video {
    display: block !important;
    margin: 0 auto !important;
    max-width: 100% !important;
    border-radius: 6px;
    pointer-events: auto !important;
    vertical-align: top;
}
.ql-editor iframe,
.ql-editor video {
    display: block !important;
    margin-left: auto !important;
    margin-right: auto !important;
    margin-top: 8px !important;
    margin-bottom: 8px !important;
    max-width: 100% !important;
    border-radius: 6px;
    pointer-events: auto !important;
}

.ql-editor img {
    max-width: 100% !important;
    height: auto !important;
    display: block !important;
    margin: 8px auto !important;
    border-radius: 6px;
}

.ql-editor .ql-align-center { text-align: center !important; }
.ql-editor .ql-align-right  { text-align: right !important; }
.ql-editor .ql-align-justify { text-align: justify !important; }

.ql-editor p { margin-bottom: 0.5em; }
.ql-editor h1, .ql-editor h2, .ql-editor h3 {
    font-weight: 600;
    margin-top: 1em;
    margin-bottom: 0.5em;
}

/* ============================================================
   浮动图片库
   ============================================================ */
#imageGalleryPanel {
    position: fixed !important;
    right: 20px !important;
    top: 100px !important;
    width: 320px !important;
    max-height: 70vh !important;
    overflow-y: auto !important;
    background: #ffffff !important;
    border: 1px solid #d1d5db !important;
    border-radius: 8px !important;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15) !important;
    padding: 16px !important;
    z-index: 9999 !important;
    display: none;
    box-sizing: border-box;
}
#imageGalleryPanel .gallery-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-weight: 500;
    font-size: 15px;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 8px;
}
#imageGalleryPanel .gallery-header .close-gallery-btn {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #6b7280;
    padding: 0 4px;
}
#imageGalleryPanel .gallery-header .close-gallery-btn:hover { color: #1a1a1a; }
#imageGalleryPanel .image-gallery {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
#imageGalleryPanel .image-gallery .gallery-item {
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 4px;
    background: #fff;
    width: 90px;
    text-align: center;
    position: relative;
    cursor: pointer;
    transition: 0.15s;
}
#imageGalleryPanel .image-gallery .gallery-item:hover {
    border-color: #1a1a1a;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
#imageGalleryPanel .image-gallery .gallery-item img {
    max-width: 100%;
    max-height: 60px;
    object-fit: contain;
    display: block;
    margin: 0 auto;
    pointer-events: none;
}
#imageGalleryPanel .image-gallery .gallery-item .item-actions {
    margin-top: 4px;
    display: flex;
    gap: 2px;
    justify-content: center;
    flex-wrap: wrap;
}
#imageGalleryPanel .image-gallery .gallery-item .item-actions button {
    font-size: 10px;
    padding: 2px 6px;
    border: 1px solid #ddd;
    border-radius: 3px;
    background: #fff;
    cursor: pointer;
    transition: 0.15s;
}
#imageGalleryPanel .image-gallery .gallery-item .item-actions button:hover {
    background: #f0f0f0;
}
#imageGalleryPanel .image-gallery .gallery-item .cover-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #f59e0b;
    color: #fff;
    font-size: 9px;
    padding: 1px 6px;
    border-radius: 10px;
    font-weight: 500;
    pointer-events: none;
}

/* ============================================================
   底部操作栏
   ============================================================ */
.status-row {
    display: flex;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 16px;
}
.status-row label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 400;
    cursor: pointer;
}
.btn {
    padding: 8px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.btn-primary { background: #1a1a1a; color: #fff; }
.btn-primary:hover { background: #333; }
.btn-outline { background: transparent; border: 1px solid #d1d5db; }
.btn-outline:hover { background: #f3f4f6; }
.btn-success { background: #16a34a; color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-sm { padding: 4px 12px; font-size: 12px; }
.footer-actions {
    margin-top: 20px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* ============================================================
   附件下载（编辑器底部）
   ============================================================ */
.form-group label.attach-label,
.attach-group > label { display: block; margin-bottom: 6px; }
.attach-list { display: flex; flex-direction: column; gap: 8px; }
.attach-list:empty { display: none; }
.attach-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fafbfc;
}
.attach-item .attach-item-icon {
    width: 34px; height: 34px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: 8px; background: #eef1f6; font-size: 16px;
}
.attach-item .attach-item-body { flex: 1; min-width: 0; }
.attach-item .attach-item-title {
    font-size: 13px; font-weight: 600; color: #1a1a1a;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.attach-item .attach-item-meta {
    font-size: 12px; color: #6b7280; margin-top: 2px;
    display: flex; flex-wrap: wrap; gap: 8px;
}
.attach-item .attach-item-text {
    font-size: 12px; color: #4b5563; margin-top: 2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.attach-item .attach-item-ops { display: flex; gap: 4px; flex-shrink: 0; }
.attach-item .attach-item-ops button {
    width: 26px; height: 26px; padding: 0;
    border: 1px solid #e5e7eb; background: #fff; border-radius: 6px;
    cursor: pointer; font-size: 12px; line-height: 1; color: #4b5563;
}
.attach-item .attach-item-ops button:hover { background: #f3f4f6; }
.attach-item .attach-item-ops button.attach-op-del:hover { background: #fee2e2; border-color: #fca5a5; }

.attach-add-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.attach-editor {
    margin-top: 10px; padding: 12px;
    border: 1px solid #e5e7eb; border-radius: 8px; background: #f9fafb;
}
.attach-editor-title { font-size: 12px; color: #6b7280; margin-bottom: 8px; }
.attach-textarea {
    width: 100%; min-height: 92px; padding: 10px 12px;
    border: 1px solid #d1d5db; border-radius: 6px; background: #fff;
    font-size: 14px; font-family: inherit; line-height: 1.6; resize: vertical; box-sizing: border-box;
}
.attach-textarea:focus { outline: none; border-color: #1a1a1a; box-shadow: 0 0 0 3px rgba(26,26,26,0.08); }
.attach-editor-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.attach-picker-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.attach-select, .attach-input {
    padding: 7px 10px; border: 1px solid #d1d5db; border-radius: 6px;
    background: #fff; font-size: 13px; font-family: inherit; box-sizing: border-box;
}
.attach-select { min-width: 140px; }
.attach-input { flex: 1; min-width: 140px; }
.attach-select:focus, .attach-input:focus { outline: none; border-color: #1a1a1a; box-shadow: 0 0 0 3px rgba(26,26,26,0.08); }
.attach-file-list {
    max-height: 260px; overflow-y: auto;
    border: 1px solid #e5e7eb; border-radius: 6px; background: #fff;
}
.attach-file-row {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 12px; border-bottom: 1px solid #f1f3f6; cursor: pointer;
}
.attach-file-row:last-child { border-bottom: none; }
.attach-file-row:hover { background: #f8fafc; }
.attach-file-row input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; flex-shrink: 0; }
.attach-file-row .attach-file-name {
    flex: 1; min-width: 0; font-size: 13px; color: #1a1a1a;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.attach-file-row .attach-file-meta { font-size: 12px; color: #6b7280; flex-shrink: 0; }
.attach-empty { padding: 16px; text-align: center; color: #9ca3af; font-size: 13px; }

@media (max-width: 768px) {
    .attach-textarea, .attach-select, .attach-input { font-size: 16px; }
    .attach-item { flex-wrap: wrap; }
    .attach-item .attach-item-ops { width: 100%; justify-content: flex-end; }
}


.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: #1a1a1a;
    color: #fff;
    padding: 10px 28px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    z-index: 9999;
    max-width: 90%;
    text-align: center;
    animation: fadeInUp 0.3s ease;
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@media (max-width: 640px) {
    body { padding: 12px; }
    .editor-wrapper { padding: 16px; }
    .header-bar h2 { font-size: 18px; }

    /* 手机端输入框字号 ≥16px，避免 iOS 聚焦时页面自动放大 */
    .form-group input[type="text"],
    .form-group input[type="url"],
    .form-group select {
        font-size: 16px;
    }

    #editor-container {
        height: 65vh;
        min-height: 360px;
        max-height: none;
    }
    #editor-container .ql-editor {
        padding: 12px 12px 40px;
    }

    .code-editor {
        height: 60vh;
        min-height: 360px;
        max-height: none;
        font-size: 16px;
    }

    #imageGalleryPanel {
        right: 10px !important;
        top: 60px !important;
        width: 280px !important;
        max-height: 60vh !important;
    }
    #imageGalleryPanel .image-gallery .gallery-item { width: 75px; }

    .color-palette .color-option {
        width: 28px;
        height: 28px;
    }
}