/* ============================================================ */
/* 全局重置                                                    */
/* ============================================================ */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif; background: #f0f2f5; height: 100vh; overflow: hidden; color: #191919; }

/* ============================================================ */
/* 顶部工具栏                                                  */
/* ============================================================ */
.editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 56px;
    background: #ffffff;
    border-bottom: 1px solid #e8ecf0;
    flex-shrink: 0;
    z-index: 10;
}
.header-left,
.header-center,
.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}
.logo { font-size: 18px; font-weight: 700; color: #07c160; text-decoration: none; }
.header-title { font-size: 14px; color: #475569; }
.header-divider { color: #e2e8f0; }
.btn-undo, .btn-redo {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 4px 12px;
    cursor: pointer;
    font-size: 16px;
}
.btn-save, .btn-export {
    padding: 6px 16px;
    border: none;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
}
.btn-save { background: #07c160; color: #fff; }
.btn-export { background: #1989fa; color: #fff; }
.btn-sync { background: #ff6b35; color: #fff; padding: 6px 16px; border: none; border-radius: 20px; font-size: 13px; font-weight: 500; cursor: pointer; }
.btn-sync:hover { background: #e55a2b; }
.btn-logout { font-size: 13px; color: #8a8f99; text-decoration: none; }
#wordCount { font-size: 13px; color: #8a8f99; }

.draft-container {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-draft-toggle {
    padding: 6px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    color: #475569;
    background: #f8fafc;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-draft-toggle:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.draft-dropdown {
    position: relative;
}

.draft-dropdown-content {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 280px;
    max-height: 350px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s, visibility 0.2s;
}

.draft-dropdown-content.show {
    visibility: visible;
    opacity: 1;
}

.draft-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
    transition: background 0.2s;
}

.draft-item:last-child {
    border-bottom: none;
}

.draft-item:hover {
    background: #f8fafc;
}

.draft-item-title {
    flex: 1;
    font-size: 13px;
    color: #334155;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 10px;
}

.draft-item-time {
    font-size: 11px;
    color: #94a3b8;
    white-space: nowrap;
}

.draft-item-delete {
    padding: 2px 8px;
    border: none;
    background: #fef2f2;
    color: #ef4444;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
}

.draft-item:hover .draft-item-delete {
    opacity: 1;
}

.draft-item-delete:hover {
    background: #fee2e2;
}

.draft-empty {
    padding: 20px;
    text-align: center;
    font-size: 13px;
    color: #94a3b8;
}

.draft-dropdown-content.show {
    display: block;
}

/* ============================================================ */
/* 主体布局                                                    */
/* ============================================================ */
.editor-body {
    display: flex;
    height: calc(100vh - 56px);
    overflow: hidden;
}

/* ============================================================ */
/* 左侧面板                                                    */
/* ============================================================ */
.sidebar-left {
    width: 320px;
    background: #ffffff;
    border-right: 1px solid #e8ecf0;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}
.sidebar-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px;
    border-bottom: 1px solid #e8ecf0;
    flex-shrink: 0;
    background: #f9fafb;
}
.tab-content { display: none; flex: 1; overflow-y: auto; padding: 16px; }
.tab-content.active { display: flex; flex-direction: column; }

/* ===== Right Preview Panel ===== */
.sidebar-right {
    width: 360px;
    background: #ffffff;
    border-left: 1px solid #e8ecf0;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}
.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid #e8ecf0;
    background: #f9fafb;
}
.preview-title {
    font-size: 13px;
    font-weight: 600;
    color: #374151;
}
.preview-container {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    background: #f5f5f5;
    display: flex;
    justify-content: center;
}
.preview-canvas {
    width: 375px;
    max-width: 100%;
    background: #ffffff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.preview-canvas > * {
    max-width: 100%;
}

/* ===== Template Column Styles ===== */
.quick-fn-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  color: #4b5563;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  user-select: none;
  line-height: 1.4;
  flex-shrink: 0;
}
.quick-fn-btn:hover {
  background-color: #ecfdf5;
  border-color: #10b981;
  color: #059669;
}
.quick-fn-btn .new-badge {
  display: inline-block;
  font-size: 9px;
  background-color: #ef4444;
  color: white;
  padding: 0 5px;
  border-radius: 8px;
  line-height: 1.4;
  margin-left: 2px;
  font-weight: 600;
}
.quick-fn-tab.active,
.quick-fn-tab[data-active="true"] {
  background-color: #10b981;
  border-color: #10b981;
  color: white;
}
.quick-fn-tab.active:hover,
.quick-fn-tab[data-active="true"]:hover {
  background-color: #059669;
  border-color: #059669;
  color: white;
}

/* 组件网格 */
.component-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.component-item {
    background: #f8f9fc;
    border: 1px solid #e8ecf0;
    border-radius: 12px;
    padding: 12px 8px;
    text-align: center;
    font-size: 12px;
    color: #333;
    cursor: grab;
    transition: all 0.2s;
}
.component-item:hover { background: #eef9f2; border-color: #07c160; transform: translateY(-1px); box-shadow: 0 2px 8px rgba(7,193,96,0.12); }
.component-item:active { cursor: grabbing; transform: scale(0.97); }
.component-item .icon { font-size: 20px; display: block; margin-bottom: 4px; }

/* 素材卡片 */
.material-item { transition: all 0.2s; }
.material-item:hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(7,193,96,0.12); }
.material-item:active { transform: scale(0.97); }

/* 图层树 */
.layer-tree-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    background: #f8f9fc;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 13px;
}
.layer-tree-item:hover { background: #f0f2f5; }
.layer-tree-item.active { background: #e6f7ed; border-color: #07c160; }
.layer-tree-item .layer-actions { display: flex; gap: 4px; opacity: 0; }
.layer-tree-item:hover .layer-actions { opacity: 1; }
.layer-tree-item .layer-actions button {
    background: none; border: none; cursor: pointer; font-size: 13px; padding: 0 4px;
}
.layer-tree-item .tree-drag-handle {
    cursor: grab;
    color: #b0a898;
    font-size: 14px;
    padding: 0 2px;
    user-select: none;
}
.layer-tree-item .tree-drag-handle:active {
    cursor: grabbing;
}

/* ============================================================ */
/* 画布区域                                                    */
/* ============================================================ */
.canvas-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px;
    overflow-y: auto;
    background: #f0f2f5;
    position: relative;
}
/* 画布容器wrapper - 包裹画布和快捷按钮 */
.canvas-wrapper-outer {
    display: flex;
    align-items: center;
    position: relative;
    width: 420px;
    justify-content: center;
}
/* 全局画布背景工具栏 */
.canvas-bg-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: #fff;
    border-radius: 10px;
    margin-bottom: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    flex-shrink: 0;
    width: 420px;
    flex-wrap: wrap;
}
.canvas-wrapper {
    width: 420px;
    min-height: 400px;
    background: #ffffff;
    border-radius: 0;
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
    padding: 0;
    overflow-x: hidden;
    overflow-y: auto;
    word-break: break-word;
    overflow-wrap: break-word;
    position: relative;
}
.canvas-wrapper::-webkit-scrollbar {
    width: 4px;
}
.canvas-wrapper::-webkit-scrollbar-track {
    background: transparent;
}
.canvas-wrapper::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.1);
    border-radius: 2px;
}
.canvas-wrapper::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.2);
}
#canvasContainer {
    padding: 0;
}
/* 画布背景通过伪元素渲染，与图层完全隔离 */
.canvas-wrapper.has-canvas-bg {
    background-image: var(--canvas-bg-image);
    background-size: var(--canvas-bg-size, cover);
    background-position: var(--canvas-bg-position, center);
    background-repeat: var(--canvas-bg-repeat, no-repeat);
    opacity: var(--canvas-bg-opacity, 1);
}
.canvas-status {
    margin-top: 12px;
    font-size: 12px;
    color: #8a8f99;
    display: flex;
    gap: 16px;
}

/* 画布右侧快捷添加按钮 */
.canvas-quick-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
}
.canvas-quick-actions button {
    width: 40px;
    height: 40px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    box-shadow: none;
    transition: all 0.2s;
}
.canvas-quick-actions button:nth-child(1) { color: #07c160; }
.canvas-quick-actions button:nth-child(2) { color: #1989fa; }
.canvas-quick-actions button:nth-child(3) { color: #ff6b35; }
.canvas-quick-actions button:nth-child(4) { color: #8b5cf6; }
.canvas-quick-actions button:hover {
    background: #f8fafc;
    transform: translateY(-2px);
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

/* 画布中的图层 */
.canvas-layer {
    position: relative;
    margin-bottom: 16px;
    border: 2px solid transparent;
    border-radius: 8px;
    padding: 4px 6px 6px 6px;
    min-height: 30px;
    transition: border-color 0.2s;
    overflow: visible;
    word-break: break-word;
    overflow-wrap: break-word;
}
.canvas-layer.layer-simple-template {
    padding: 0;
    margin-bottom: 0;
    min-height: auto;
    border: none;
    border-radius: 0;
    background: transparent !important;
}
.canvas-layer.layer-simple-template:hover {
    background: rgba(7,193,96,0.03) !important;
}
.canvas-layer.layer-simple-template.active {
    border: 2px solid #07c160;
    border-radius: 8px;
}
.canvas-layer.layer-simple-template .layer-content-wrap {
    overflow: visible;
    border-radius: 0;
}
/* 简单模板内的图片可点击 */
.canvas-layer.layer-simple-template img {
    cursor: pointer;
    transition: opacity 0.2s;
}
.canvas-layer.layer-simple-template img:hover {
    opacity: 0.8;
}
/* 简单模板内的文字可编辑 */
.canvas-layer.layer-simple-template .layer-text-content {
    outline: none;
}
.canvas-layer.layer-simple-template .layer-text-content:focus {
    outline: 2px dashed rgba(7,193,96,0.3);
    outline-offset: 2px;
}
.canvas-layer:hover:not(.layer-image-type) { background: rgba(7,193,96,0.04); }
.canvas-layer.active:not(.layer-image-type) { border-color: #07c160; background: rgba(7,193,96,0.06); }
.canvas-layer.layer-absolute { margin-bottom: 0; }
.canvas-layer.layer-image-type {
    padding: 0;
    min-height: auto;
    margin-bottom: 0;
    background: transparent !important;
}
.canvas-layer.layer-image-type:hover { background: transparent !important; }
.canvas-layer.layer-image-type.active { background: rgba(7,193,96,0.06) !important; }
.canvas-layer img { max-width: 100%; height: auto; display: block; }
.canvas-layer table { max-width: 100%; table-layout: fixed; }
.canvas-layer svg { max-width: 100%; height: auto; }
.canvas-layer .layer-handle {
    position: absolute;
    top: -12px;
    left: 8px;
    background: #07c160;
    color: #fff;
    font-size: 10px;
    padding: 0 10px;
    border-radius: 10px;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}
.canvas-layer.active .layer-handle { opacity: 1; }
.canvas-layer .layer-delete-btn {
    position: absolute;
    top: -12px;
    right: 8px;
    background: #ef4444;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 12px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.canvas-layer:hover .layer-delete-btn { opacity: 1; }
.layer-drag-handle {
    position: absolute; top: 4px; right: 28px;
    width: 20px; height: 20px; display: flex; align-items: center; justify-content: center;
    background: #e2e8f0; color: #64748b; border: none; border-radius: 4px;
    font-size: 14px; cursor: grab; opacity: 0; transition: opacity 0.2s;
    z-index: 2; user-select: none;
}
.canvas-layer:hover .layer-drag-handle { opacity: 1; }
.layer-drag-handle:active { cursor: grabbing; }
.canvas-layer .layer-text-content:focus { background: rgba(7,193,96,0.06); }
.canvas-layer .layer-svg-content:focus { background: rgba(7,193,96,0.06); }

/* 自由移动手柄 */
.layer-move-handle {
    position: absolute; top: 4px; right: 52px;
    width: 20px; height: 20px; display: flex; align-items: center; justify-content: center;
    background: #1989fa; color: #fff; border: none; border-radius: 4px;
    font-size: 12px; cursor: move; opacity: 0; transition: opacity 0.2s;
    z-index: 2; user-select: none;
}
.canvas-layer:hover .layer-move-handle { opacity: 1; }
.layer-move-handle:active { cursor: move; }

/* 缩放拖拽手柄 */
.layer-resize-handle {
    position: absolute; bottom: -4px; right: -4px;
    width: 20px; height: 20px;
    cursor: nwse-resize;
    opacity: 0; transition: opacity 0.2s;
    z-index: 100;
    background: #07c160;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(7,193,96,0.4);
}
.canvas-layer:hover .layer-resize-handle { opacity: 1; }
.canvas-layer.active .layer-resize-handle { opacity: 1; }
.layer-dragging { opacity: 0.85; box-shadow: 0 4px 16px rgba(0,0,0,0.15); z-index: 999 !important; }

/* 画布容器需要 relative 定位 */
#canvasContainer { position: relative; overflow: visible; }

/* 图片层覆盖层 */
.canvas-layer .layer-image-wrap:hover .layer-image-overlay {
    opacity: 1 !important;
}
.canvas-layer .layer-image-wrap {
    line-height: 0;
}

/* 图层内联工具栏 */
.canvas-layer .layer-toolbar {
    position: absolute;
    bottom: -22px;
    right: 8px;
    display: none;
    gap: 4px;
    z-index: 5;
}
.canvas-layer.active .layer-toolbar {
    display: flex;
}
.canvas-layer .layer-toolbar button {
    background: #07c160;
    color: #fff;
    border: none;
    border-radius: 3px;
    width: 20px;
    height: 20px;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}
.canvas-layer .layer-toolbar button:last-child {
    background: #1989fa;
}

/* ============================================================ */
/* 右侧属性面板                                                */
/* ============================================================ */
.sidebar-right {
    width: 260px;
    background: #ffffff;
    border-left: 1px solid #e8ecf0;
    padding: 16px 20px;
    overflow-y: auto;
    flex-shrink: 0;
}
.prop-group { margin-bottom: 14px; }
.prop-group label {
    display: block;
    font-size: 12px;
    color: #6b7280;
    margin-bottom: 4px;
    font-weight: 500;
}
.prop-group input[type="text"],
.prop-group input[type="number"] {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 13px;
    background: #fafbfc;
}
.prop-group input:focus { outline: none; border-color: #07c160; }
.prop-group input[type="color"] {
    width: 40px;
    height: 40px;
    padding: 2px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    cursor: pointer;
}

/* ============================================================ */
/* Toast                                                        */
/* ============================================================ */
#toast.success { background: #07c160; }
#toast.error { background: #ef4444; }
#toast.show { display: block; animation: fadeUp 0.3s ease; }
@keyframes fadeUp {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ============================================================ */
/* 同步弹窗                                                    */
/* ============================================================ */
#syncModal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sync-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
}
.sync-dialog {
    position: relative;
    background: #fff;
    border-radius: 16px;
    width: 520px;
    max-width: 90vw;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
    animation: syncIn 0.25s ease;
}
@keyframes syncIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}
.sync-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid #e8ecf0;
}
.sync-header h3 {
    margin: 0;
    font-size: 16px;
    color: #1a1a2e;
}
.sync-close {
    background: none;
    border: none;
    font-size: 18px;
    color: #8a8f99;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}
.sync-close:hover { background: #f1f5f9; }
.sync-body {
    padding: 20px 24px;
}
.sync-field {
    margin-bottom: 16px;
}
.sync-field label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #475569;
    margin-bottom: 6px;
}
.sync-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid #e8ecf0;
}
.btn-sync-cancel {
    padding: 8px 20px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    color: #475569;
    cursor: pointer;
}
.btn-sync-submit {
    padding: 8px 20px;
    background: #ff6b35;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    color: #fff;
    font-weight: 500;
    cursor: pointer;
}
.btn-sync-submit:hover { background: #e55a2b; }
.btn-sync-submit:disabled { opacity: 0.6; cursor: not-allowed; }

/* 图片URL弹窗 */
.img-url-dialog {
    position: relative;
    background: #fff;
    border-radius: 16px;
    width: 460px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
    animation: syncIn 0.25s ease;
}

/* ============================================================ */
/* 图层动画效果（编辑器预览，导出时清洗）                      */
/* ============================================================ */

/* 淡入 */
.canvas-layer.anim-fadeIn {
    animation: editorFadeIn 0.6s ease both;
}
@keyframes editorFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* 上滑进入 */
.canvas-layer.anim-slideUp {
    animation: editorSlideUp 0.6s ease both;
}
@keyframes editorSlideUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 左滑进入 */
.canvas-layer.anim-slideLeft {
    animation: editorSlideLeft 0.6s ease both;
}
@keyframes editorSlideLeft {
    from { opacity: 0; transform: translateX(-30px); }
    to { opacity: 1; transform: translateX(0); }
}

/* 缩放进入 */
.canvas-layer.anim-scaleIn {
    animation: editorScaleIn 0.5s ease both;
}
@keyframes editorScaleIn {
    from { opacity: 0; transform: scale(0.85); }
    to { opacity: 1; transform: scale(1); }
}

/* 弹跳 */
.canvas-layer.anim-bounce {
    animation: editorBounce 0.7s ease both;
}
@keyframes editorBounce {
    0% { opacity: 0; transform: scale(0.6); }
    50% { opacity: 1; transform: scale(1.08); }
    70% { transform: scale(0.95); }
    100% { transform: scale(1); }
}

/* 背景图素材选择模式 */
.material-card.material-bg-pick {
    outline: 2px solid #07c160;
    outline-offset: 2px;
    cursor: copy;
}