/* ===== 1. 全局与容器 ===== */
body {
    background: #ffffff;
    color: #1d1d1f;
    margin: 0;
    padding: 0;
    font-family:
        "Microsoft YaHei",
        "Noto Sans SC",
        "Inter",
        -apple-system,
        BlinkMacSystemFont,
        "SF Pro Display",
        "Helvetica Neue",
        Arial,
        sans-serif;
    -webkit-font-smoothing: antialiased;
}

.editor-wrap {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 30px 0;
}

.worktop-bar {
    position: fixed;
    top: 12px;
    right: 14px;
    z-index: 5000;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    width: auto;
    max-width: calc(100vw - 28px);
    margin-bottom: 0;
    padding: 6px 10px;
    flex-wrap: wrap;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    background: rgba(13, 13, 15, 0.86);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

#saveStatus {
    margin-left: 0;
    font-size: 12px;
    color: #34c759;
    white-space: nowrap;
}

.worktop-palette-shortcut {
    position: relative;
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.08);
}

.worktop-palette-shortcut::before {
    content: "";
    width: 19px;
    height: 19px;
    border-radius: 50%;
    background: conic-gradient(#ef4444 0 18%, #f59e0b 18% 36%, #22c55e 36% 54%, #06b6d4 54% 72%, #6366f1 72% 88%, #ec4899 88% 100%);
    box-shadow: inset 0 0 0 2px rgba(13, 13, 15, .9), 0 0 0 1px rgba(255, 255, 255, .24);
}

.worktop-palette-shortcut::after {
    content: "";
    position: absolute;
    right: 7px;
    bottom: 7px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(13, 13, 15, .95);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, .28);
}

.standalone-edit-toggle {
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: rgba(255, 255, 255, .72);
    font-size: 17px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: .72;
}

.standalone-edit-toggle:hover,
.standalone-edit-toggle.is-active {
    color: #fff;
    opacity: .95;
}

/* ===== 2. 核心工具栏 ===== */
.toolbar-fixed {
    position: sticky;
    top: 0;
    z-index: 2000;
    display: none;
    flex-wrap: wrap;
    align-items: center !important;
    gap: 8px;
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.8) !important;
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
}

.editor-group {
    display: flex !important;
    align-items: center !important;
    gap: 6px;
    border-right: 1px solid rgba(0, 0, 0, 0.1);
    padding-right: 8px;
    margin: 4px 0;
}

.editor-group:last-child {
    border-right: none;
}

.editor-toolbar-row-break {
    flex-basis: 100% !important;
    width: 100% !important;
    height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    border: 0 !important;
}

.editor-toolbar-ai-row {
    flex: 0 0 100% !important;
    width: 100% !important;
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    gap: 6px !important;
    margin: 4px 0 !important;
    padding: 0 !important;
}

/* ===== 3. 按钮与组件 ===== */
.editor-btn,
.editor-select,
.toolbar-fixed label,
.toolbar-fixed select {
    height: 32px !important;
    line-height: 1 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 12px !important;
    box-sizing: border-box !important;
    border-radius: 8px !important;
    background: #f2f2f7 !important;
    color: #1d1d1f !important;
    border: none !important;
    font-size: 13px !important;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    margin: 0 !important;
}

.color-trigger {
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    margin-left: 5px !important;
    background: transparent !important;
}

.editor-btn:hover,
.toolbar-fixed label:hover {
    background: #e5e5ea !important;
    transform: translateY(-1px);
}

.editor-btn:active,
.toolbar-fixed label:active {
    background: #d1d1d6 !important;
    transform: translateY(0) scale(0.96);
}

.editor-btn.blue {
    background: #007aff !important;
    color: #fff !important;
}

.editor-btn.green {
    background: #34c759 !important;
    color: #fff !important;
}

/* ===== 4. 编辑区内容样式 ===== */
#editable {
    font-size: 15px;
    font-weight: 400;
    line-height: 1.8;
    padding: 30px 10px;
    min-height: 600px;
    outline: none;
    color: #333;
}

#editable[contenteditable="true"] {
    background: #ffffff;
    box-shadow: none;
    border-radius: 0;
}

/* 图片适配 */
#editable img {
    max-width: 100%;
    border-radius: 0;
    display: block;
    margin: 20px auto;
    box-shadow: none;
    height: auto;
}
#editable b,
#editable strong {
    font-weight: 700;
}
/* 一行多图：固定在各自格子内完整显示，避免裁剪和重叠 */
#editable .img-row img,
#editable .img-row-scroll img {
    max-width: none !important;
    width: auto !important;
    height: 100% !important;
    margin: 0 !important;
    object-fit: contain !important;
}

#editable .image-row-wrap .image-row-item,
#editable .img-row,
#editable .img-row-scroll {
    overflow: visible !important;
    width: auto !important;
    flex: 0 0 auto !important;
    background: transparent !important;
}

#editable .image-row-wrap .image-row-item img {
    display: block !important;
    width: auto !important;
    height: 100% !important;
    max-width: none !important;
    max-height: 100% !important;
    object-fit: contain !important;
    margin: 0 auto !important;
}

/* ===== 5. 响应式补丁 ===== */
@media (max-width: 768px) {
    .editor-wrap {
        padding: 15px;
    }

    .worktop-bar {
        top: 10px;
        right: 10px;
        max-width: calc(100vw - 20px);
        align-items: center;
    }

    #saveStatus {
        margin-left: 0;
        width: auto;
    }

    .toolbar-fixed {
        padding: 8px;
        gap: 4px;
        justify-content: center;
    }

    .editor-group {
        border-right: none;
        padding-right: 0;
    }
}

.edit-fab.active {
    background: #007aff;
    color: #fff;
}

.edit-fab {
    position: fixed !important;
    right: 20px !important;
    bottom: 20px !important;
    z-index: 999999 !important;

    width: 40px !important;
    height: 40px !important;
    border-radius: 50% !important;

    background: #f2f2f7 !important;
    color: #1d1d1f !important;

    border: none !important;
    cursor: pointer !important;

    display: flex !important;
    align-items: center !important;
    justify-content: center !important;

    font-size: 16px !important;
    line-height: 1 !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06) !important;

    transition: all 0.2s ease !important;
}

.edit-fab:hover {
    background: #e5e5ea;
    transform: translateY(-1px);
}

.edit-fab:active {
    transform: scale(0.95);
}

/* ===== 手机端：图片按高度显示完整，宽度自动展开 ===== */
@media (max-width: 768px) {
    #editable .image-row-wrap {
        display: flex !important;
        flex-wrap: nowrap !important;
        align-items: stretch !important;
        gap: 8px !important;
        margin: 14px 0 18px !important;
        overflow-x: auto !important;
        overflow-y: visible !important;
    }

    #editable .image-row-item {
        flex: 0 0 auto !important;
        width: auto !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
    }

    #editable .image-row-item img {
        display: block !important;
        width: auto !important;
        height: 100% !important;
        max-width: none !important;
        margin: 0 !important;
        object-fit: contain !important;
        flex: none !important;
    }

    #editable .image-row-item[data-manual-width="1"] {
        flex: 0 0 calc(var(--image-width-pct, 100) * 1vw) !important;
        width: calc(var(--image-width-pct, 100) * 1vw) !important;
        max-width: 100% !important;
    }

    #editable .image-row-item[data-manual-width="1"] img {
        width: 100% !important;
        height: auto !important;
        max-width: 100% !important;
    }

    #editable .image-row-wrap.mobile-single {
        flex-wrap: wrap !important;
        overflow-x: visible !important;
        overflow-y: visible !important;
        padding-bottom: 0 !important;
    }

    #editable .image-row-wrap.mobile-single .image-row-item {
        flex: 0 0 100% !important;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: hidden !important;
    }

    #editable .image-row-wrap.mobile-single .image-row-item img {
        width: 100% !important;
        height: auto !important;
        max-width: 100% !important;
        object-fit: contain !important;
    }

    #editable .image-row-wrap:has(> .image-row-item ~ .image-row-item) {
        display: flex !important;
        flex-wrap: nowrap !important;
        align-items: stretch !important;
        gap: 8px !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        padding-bottom: 8px !important;
        -webkit-overflow-scrolling: touch !important;
    }

    #editable .image-row-wrap:has(> .image-row-item ~ .image-row-item) > .image-row-item {
        flex: 0 0 auto !important;
        width: auto !important;
        max-width: none !important;
        height: clamp(160px, 54vw, 260px) !important;
        min-height: clamp(160px, 54vw, 260px) !important;
        max-height: clamp(160px, 54vw, 260px) !important;
        overflow: hidden !important;
    }

    #editable .image-row-wrap:has(> .image-row-item ~ .image-row-item) > .image-row-item img {
        display: block !important;
        width: auto !important;
        height: 100% !important;
        max-width: none !important;
        max-height: 100% !important;
        object-fit: contain !important;
        margin: 0 !important;
    }
}
