/* 基础样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: #f8f8f8;
    color: #333;
    line-height: 1.6;
}

/* 工作台布局 */
.workspace {
    display: flex;
    height: 100vh;
}

/* 左侧素材栏 */
.materials-panel {
    width: 250px;
    background-color: white;
    border-right: 0; /* 顶部栏打通：移除左栏竖线 */
    display: flex;
    flex-direction: column;
    height: calc(100vh - 60px); /* 🎯 修复：扣除顶部栏高度，避免底部被遮挡 */
    overflow-y: auto; /* 🎯 修复：整个面板可以滚动 */
    /* 🎨 美化整个面板的滚动条样式 */
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f1f5f9;
}

.panel-header {
    padding: 15px;
    border-bottom: 1px solid #e5e5e5;
}

.panel-title {
    font-weight: 600;
    font-size: 16px;
}

.upload-area {
    padding: 15px;
    border: 2px dashed #ccc;
    margin: 15px;
    border-radius: 5px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.upload-area:hover {
    border-color: #60a5fa;
    background-color: #f0f7ff;
}

.upload-icon {
    font-size: 24px;
    margin-bottom: 10px;
}

.upload-text {
    font-size: 14px;
    color: #666;
}

.materials-list {
    /* 🎯 修复：移除独立滚动，让整个面板统一滚动 */
    padding: 10px; /* 从15px减小到10px */
    /* 移除 flex: 1 和 overflow-y: auto，让内容自然流动 */
}

/* 🎨 自定义滚动条样式 - 为整个素材面板 */
.materials-panel::-webkit-scrollbar {
    width: 8px;
}

.materials-panel::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.materials-panel::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.materials-panel::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.material-item {
    display: flex;
    align-items: center;
    padding: 3px 5px 3px 24px; /* 增加左侧内边距，为删除按钮预留空间 */
    border-radius: 3px;
    margin-bottom: 3px;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
    border: none; /* 删除边框 */
    background-color: transparent;
    box-shadow: none;
}

.material-item:hover {
    background-color: #f3f4f6;
    border-color: transparent; /* 确保悬停时也没有边框 */
}

/* 删除点击提示图标的样式 */
/* .material-item::after {
    content: "";
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke-width='1.5' stroke='%233b82f6' class='w-6 h-6'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M12.75 15l3-3m0 0l-3-3m3 3h-7.5M21 12a9 9 0 11-18 0 9 9 0 0118 0z' /%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    opacity: 0.5;
    transition: opacity 0.2s;
} */

/* .material-item:hover::after {
    opacity: 1;
} */

/* 素材删除按钮样式 */
.material-delete-btn {
    position: absolute;
    left: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    border-radius: 0; /* 移除圆角 */
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0; /* 默认隐藏 */
    transition: all 0.2s;
    padding: 0;
    z-index: 2;
}

.material-item:hover .material-delete-btn {
    opacity: 1; /* 鼠标悬停在素材项上时显示删除按钮 */
}

/* 删除按钮悬停效果 */
.material-delete-btn:hover {
    transform: translateY(-50%) scale(1.1); /* 保留轻微放大效果 */
    background-color: transparent; /* 移除悬停时的背景色 */
}

.material-delete-btn:hover .material-delete-icon {
    color: #dc2626; /* 悬停时垃圾桶图标颜色加深 */
}

.material-delete-icon {
    width: 18px;
    height: 18px;
    color: #ef4444; /* 设置垃圾桶图标为红色 */
    flex-shrink: 0;
    transition: color 0.2s; /* 添加颜色过渡效果 */
}

/* 自定义选择框覆盖层：控制点交互与光标样式 */
.custom-selection-overlay .custom-selection-box { pointer-events: none; }
.custom-selection-overlay .control-point { pointer-events: auto; }
/* 与 Fabric 默认一致的光标样式映射 */
.control-point-tl, .control-point-br { cursor: nwse-resize; }
.control-point-tr, .control-point-bl { cursor: nesw-resize; }
.control-point-tm, .control-point-bm { cursor: ns-resize; }
.control-point-ml, .control-point-mr { cursor: ew-resize; }
.control-point-mtr { cursor: crosshair; }

/* 清理：左侧素材的“编辑标签”与相关切换样式已下线 */

.material-thumbnail {
    width: 36px;
    height: 36px;
    object-fit: contain;
    margin-right: 8px;
    margin-left: 0; /* 移除左边距，因为已经在素材项上添加了左侧内边距 */
}

.material-name {
    font-size: 13px; /* 从14px减小到13px */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    margin-right: 0;
}

/* 中间画布区域 - 响应式优化 */
.canvas-area {
    flex: 1;
    padding: 0;
    background-color: #f9fafb;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100vh; /* 使用完整视口高度 */
    min-height: 500px; /* 设置最小高度 */
    position: relative; /* 为子元素提供定位参考 */
}

/* 顶部按钮栏 */
.canvas-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    height: 60px;
    min-height: 60px; /* 确保固定高度 */
    padding: 0 24px;
    background-color: #fff;
    border-bottom: 1px solid #e5e5e5; /* 🎨 添加底边线与左右面板保持一致 */
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    z-index: 10;
    flex-shrink: 0; /* 防止压缩 */
}

/* 画布容器外层包装 - 主控制容器 */
.canvas-container-wrapper,
#canvas-container {
    flex: 1;
    background-color: #f9fafb;
    background-image: 
        radial-gradient(circle, #e1e1e1 1px, transparent 1px),
        radial-gradient(circle, #e1e1e1 1px, transparent 1px);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
    border-radius: 0;
    /* 使用flex-grow确保充分利用可用空间 */
    height: 100%;
    min-height: 400px;
    width: 100%;
    position: relative;
    /* 🔧 修复：外层容器允许滚动，这样放大的画布不会被截断 */
    overflow: auto;
    /* 优化滚动性能 */
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
    /* 自定义滚动条样式 */
    scrollbar-width: thin;
    scrollbar-color: #ccc #f1f1f1;
}

/* 外层容器的滚动条样式 */
.canvas-container-wrapper::-webkit-scrollbar,
#canvas-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.canvas-container-wrapper::-webkit-scrollbar-track,
#canvas-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.canvas-container-wrapper::-webkit-scrollbar-thumb,
#canvas-container::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.canvas-container-wrapper::-webkit-scrollbar-thumb:hover,
#canvas-container::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* 横向画布模式的特殊优化 */
.landscape-canvas .canvas-container-wrapper,
.landscape-canvas #canvas-container {
    /* 横向画布时进一步优化空间利用 */
    min-height: 300px;
}

/* 竖向画布模式保持原有设置 */
.portrait-canvas .canvas-container-wrapper,
.portrait-canvas #canvas-container {
    min-height: 400px;
}

/* 画布外层包装器 - 作为内容容器，不控制滚动 */
.canvas-outer-wrapper {
    width: 100%;
    height: 100%;
    /* 🔧 修复：移除滚动控制，由上级容器处理 */
    overflow: visible;
    position: relative;
    /* 确保足够的空间容纳缩放后的画布 */
    min-width: 100%;
    min-height: 100%;
}

/* 画布内层包装器 - 控制居中和定位 */
.canvas-inner-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    /* 🔧 修复：动态调整尺寸以容纳缩放后的画布 */
    min-width: 100%;
    min-height: 100%;
    /* 确保缩放后的画布有足够空间显示 */
    padding: 20px;
    box-sizing: border-box;
}

/* 画布缩放包装器 - 专业级缩放控制 */
#canvas-wrapper {
    /* 关键：使用绝对定位和transform实现完美居中缩放 */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.5); /* 默认50%缩放，完美居中 */
    transform-origin: center center;
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    will-change: transform;
    
    /* 画布样式 */
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    background: white;
    padding: 0;
    /* 🎯 确保wrapper尺寸与Fabric.js画布逻辑尺寸一致 */
    width: var(--canvas-width, 1200px);
    height: var(--canvas-height, 1800px);
    
    /* 优化渲染性能 */
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
    
    /* 确保画布不会被意外拖动 */
    user-select: none;
    -webkit-user-select: none;
    pointer-events: auto; /* 确保可以接收事件 */
}

/* 横向画布的特殊样式调整 */
.landscape-canvas #canvas-wrapper {
    /* 横向画布可能需要不同的阴影和边框半径 */
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
}

/* 竖向画布保持原有样式 */
.portrait-canvas #canvas-wrapper {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

/* 设计区域容器 - 精确画布边界裁剪 */
#design-area-container {
    /* 🎯 终极修复：让容器自适应canvas尺寸，而不是强制填充 */
    display: inline-block;
    background: white;
    position: relative;
    border-radius: 8px;
    overflow: hidden !important; /* 保持hidden，实现精确的画布边界裁剪 */
    /* 确保容器与画布完全重叠 */
    margin: 0 !important;
    padding: 0 !important;
    /* 确保不会影响到子元素的定位 */
    box-sizing: border-box !important;
    /* 防止任何缩放或变形 */
    transform: none !important;
    /* 让容器大小由内容（canvas）决定 */
    width: auto;
    height: auto;
}

/* 🆕 背景画布透明模式样式 - 提高优先级以覆盖默认样式 */
body #design-area-container.transparent-bg {
    background: transparent !important;
    background-color: transparent !important;
    /* 添加棋盘格背景效果 */
    background-image: 
        linear-gradient(45deg, #f0f0f0 25%, transparent 25%), 
        linear-gradient(-45deg, #f0f0f0 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #f0f0f0 75%), 
        linear-gradient(-45deg, transparent 75%, #f0f0f0 75%) !important;
    background-size: 20px 20px !important;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px !important;
}

/* 🆕 确保canvas在透明模式下也是透明的 */
body #design-area-container.transparent-bg #design-canvas {
    background: transparent !important;
    background-color: transparent !important;
}

/* canvas 样式本体 - 保持原始尺寸，不被CSS缩放 */
#design-canvas {
    display: block;
    background: white;
    border: none;
    box-shadow: none;
    /* 🚨 关键修复：移除width/height设置，让canvas保持HTML属性定义的原始尺寸 */
    /* width: 100%; */
    /* height: 100%; */
    border-radius: 8px;
    /* 确保没有额外的边距或内边距 */
    margin: 0;
    padding: 0;
}

/* 移除旧的canvas-workspace样式 */
.canvas-workspace {
    display: none; /* 不再使用 */
}

/* 缩放比例显示 - 优化 */
#zoom-label {
    position: absolute;
    bottom: 20px;
    left: 20px;
    font-size: 12px;
    background: rgba(255,255,255,0.95);
    color: #666;
    padding: 6px 10px;
    border-radius: 6px;
    z-index: 999;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    font-weight: 500;
    transition: color 0.2s ease;
}

/* 画布容器的滚动条美化 - 移除，现在在canvas-outer-wrapper上 */

.canvas-title {
    font-weight: 600;
    font-size: 18px;
}

.canvas-actions {
    display: flex;
    gap: 10px;
}

.btn {
    padding: 8px 16px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
}

.btn-primary {
    background-color: #3b82f6;
    color: white;
}

.btn-primary:hover {
    background-color: #2563eb;
}

.btn-secondary {
    background-color: #e5e7eb;
    color: #374151;
}

.btn-secondary:hover {
    background-color: #d1d5db;
}

.btn-danger {
    background-color: #ef4444;
    color: white;
}

.btn-danger:hover {
    background-color: #dc2626;
}

.canvas-container {
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* 右侧参数面板 */
.params-panel {
    width: 280px;
    background-color: white;
    border-left: 0; /* 顶部栏打通：移除右栏竖线 */
    height: 100%;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto; /* 🎯 新增：整个面板可滚动 */
    position: relative; /* 使其成为定位元素，建立层叠上下文 */
    z-index: 20; /* 保证右侧面板及其子元素在画布区域之上 */
    overflow-x: visible; /* 允许头像卡片水平溢出显示 */
}

/* 🎯 新增：参数面板滚动条样式 */
.params-panel::-webkit-scrollbar {
    width: 6px;
}

.params-panel::-webkit-scrollbar-track {
    background-color: #f1f5f9;
    border-radius: 3px;
}

.params-panel::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 3px;
    transition: background-color 0.2s ease;
}

.params-panel::-webkit-scrollbar-thumb:hover {
    background-color: #94a3b8;
}

.layers-header {
    height: 60px; /* 🔧 统一高度与其他两个区域保持一致 */
    min-height: 60px; /* 🔧 确保最小高度 */
    padding: 0 15px; /* 🔧 调整内边距以适应固定高度 */
    border-bottom: 1px solid #e5e5e5;
    display: flex;
    justify-content: space-between;
    align-items: center; /* 垂直居中对齐 */
    background-color: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04); /* 🔧 与其他区域保持一致的阴影 */
}

.layers-title {
    font-weight: 600;
    font-size: 16px;
    color: #1f2937; /* 🔧 与其他区域保持一致的颜色 */
    margin: 0; /* 🔧 清除默认margin，避免影响垂直居中 */
}

.layers-list {
    padding: 15px;
    /* 🎯 移除：flex: 1 和 overflow-y: auto，让父容器统一管理滚动 */
}

/* 旧的图层样式已移动到文件末尾的完整版本中 */

/* 上传文件隐藏的input */
#file-upload {
    display: none;
}

/* 拖放高亮样式 */
.upload-area.dragover {
    border-color: #3b82f6;
    background-color: #e5f2ff;
}

/* 弹窗样式 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background-color: white;
    border-radius: 8px;
    padding: 20px;
    width: 400px;
    max-width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.modal-title {
    font-weight: 600;
    font-size: 18px;
}

.modal-body {
    margin-bottom: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* 通知提示样式已移至JavaScript内联样式管理 */

.layer-type {
    display: inline-block;
    font-size: 11px;
    color: #4b5563;
    background-color: #e5e7eb;
    padding: 1px 4px;
    border-radius: 3px;
    margin-right: 4px;
}

/* 颜色选择器样式 */
.color-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.color-option {
    cursor: pointer;
}

.color-swatch {
    width: 30px;
    height: 30px;
    border-radius: 4px;
    border: 1px solid #ddd;
    transition: all 0.2s;
}

.color-palette {
    background: linear-gradient(to right, 
        hsl(0, 100%, 50%), 
        hsl(60, 100%, 50%), 
        hsl(120, 100%, 50%), 
        hsl(180, 100%, 50%), 
        hsl(240, 100%, 50%), 
        hsl(300, 100%, 50%), 
        hsl(360, 100%, 50%)
    );
}

.color-option.selected .color-swatch {
    transform: scale(1.1);
    box-shadow: 0 0 0 2px #3B82F6;
}

/* 模态框样式增强 */
.modal-content {
    max-width: 500px; /* 增加宽度以适应颜色选择器 */
}

/* 标签输入框样式 */
#template-tags {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    transition: all 0.2s;
}

#template-tags:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
    outline: none;
}

/* 画布底部工具栏 */
.canvas-footer {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    color: #6b7280;
    background-color: white;
    border-top: 1px solid #e5e5e5;
    align-items: center;
}

/* 缩放滑块样式 */
#zoomSlider {
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    border-radius: 2px;
    background: #e5e7eb;
    outline: none;
    transition: all 0.2s;
}

#zoomSlider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #3b82f6;
    cursor: pointer;
    transition: all 0.2s;
}

#zoomSlider::-webkit-slider-thumb:hover {
    background: #2563eb;
    transform: scale(1.2);
}

#zoomSlider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border: none;
    border-radius: 50%;
    background: #3b82f6;
    cursor: pointer;
    transition: all 0.2s;
}

#zoomSlider::-moz-range-thumb:hover {
    background: #2563eb;
    transform: scale(1.2);
}

/* 缩放值显示 */
#zoomValue {
    font-family: monospace;
    font-size: 12px;
    color: #4b5563;
}

/* 重置按钮样式 */
#resetZoomBtn {
    background-color: #f3f4f6;
    color: #4b5563;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

#resetZoomBtn:hover {
    background-color: #e5e7eb;
}

/* 响应式媒体查询 - 针对不同屏幕尺寸优化 */

/* 大屏幕设备 (1440px+) */
@media (min-width: 1440px) {
    .canvas-container-wrapper,
    #canvas-container {
        height: calc(100vh - 140px);
        max-height: none;
    }
    
    .canvas-area {
        min-height: 600px;
    }
}

/* 中等屏幕设备 (1024px - 1439px) */
@media (min-width: 1024px) and (max-width: 1439px) {
    .canvas-container-wrapper,
    #canvas-container {
        height: calc(100vh - 150px);
        min-height: 450px;
    }
    
    .canvas-header {
        padding: 0 16px;
    }
    
    .btn {
        padding: 6px 12px;
        font-size: 13px;
    }
}

/* 平板设备 (768px - 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
    .workspace {
        flex-direction: column;
    }
    
    .materials-panel {
        width: 100%;
        height: 200px;
        order: 2;
    }
    
    /* 🎯 修复：平板模式下整个素材面板滚动 */
    .materials-panel {
        overflow-y: auto; /* 确保平板模式下也能滚动 */
    }
    
    .canvas-area {
        order: 1;
        min-height: 400px;
    }
    
    .params-panel {
        width: 100%;
        height: 250px;
        order: 3;
        border-left: none;
        border-top: 1px solid #e5e5e5;
        overflow-y: auto; /* 🎯 确保平板模式下也能滚动 */
    }
    
    .canvas-container-wrapper,
    #canvas-container {
        height: calc(100vh - 200px);
        min-height: 350px;
    }
    
    .canvas-header {
        padding: 0 12px;
        height: 50px;
        min-height: 50px;
    }
    
    .canvas-title {
        font-size: 16px;
    }
    
    .btn {
        padding: 4px 8px;
        font-size: 12px;
    }
    
    #zoom-label {
        bottom: 15px;
        left: 15px;
        font-size: 11px;
        padding: 4px 8px;
    }
}

/* 小屏幕设备 (最大767px) */
@media (max-width: 767px) {
    .workspace {
        flex-direction: column;
    }
    
    .materials-panel {
        width: 100%;
        height: 150px;
        order: 2;
    }
    
    /* 🎯 修复：手机模式下整个素材面板滚动 */
    .materials-panel {
        overflow-y: auto; /* 确保手机模式下也能滚动 */
    }
    
    .canvas-area {
        order: 1;
        min-height: 300px;
    }
    
    .params-panel {
        width: 100%;
        height: 200px;
        order: 3;
        border-left: none;
        border-top: 1px solid #e5e5e5;
        overflow-y: auto; /* 🎯 确保手机模式下也能滚动 */
    }
    
    .canvas-container-wrapper,
    #canvas-container {
        height: calc(100vh - 180px);
        min-height: 280px;
    }
    
    .canvas-header {
        padding: 0 8px;
        height: 45px;
        min-height: 45px;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .canvas-title {
        font-size: 14px;
        font-weight: 500;
    }
    
    .canvas-actions {
        gap: 6px;
    }
    
    .btn {
        padding: 3px 6px;
        font-size: 11px;
        border-radius: 3px;
    }
    
    #zoom-label {
        bottom: 10px;
        left: 10px;
        font-size: 10px;
        padding: 3px 6px;
        border-radius: 4px;
    }
    
    .canvas-footer {
        flex-direction: column;
        gap: 8px;
        padding: 8px 12px;
        font-size: 11px;
    }
    
    #zoomSlider {
        width: 80px;
    }
    
    #resetZoomBtn {
        padding: 1px 6px;
        font-size: 10px;
    }
}

/* 超小屏幕设备 (最大480px) */
@media (max-width: 480px) {
    .canvas-container-wrapper,
    #canvas-container {
        height: calc(100vh - 160px);
        min-height: 250px;
    }
    
    .canvas-header {
        height: 40px;
        min-height: 40px;
    }
    
    .canvas-title {
        font-size: 13px;
    }
    
    .btn {
        padding: 2px 4px;
        font-size: 10px;
    }
    
    .materials-panel {
        height: 120px;
    }
    
    /* 🎯 修复：超小屏幕模式下整个素材面板滚动 */
    .materials-panel {
        overflow-y: auto; /* 确保超小屏幕模式下也能滚动 */
    }
    
    .params-panel {
        height: 180px;
        overflow-y: auto; /* 🎯 确保超小屏幕模式下也能滚动 */
    }
}

/* 图层管理样式 */
.layers-panel {
    width: 300px;
    background-color: white;
    border-left: 1px solid #e5e5e5;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.layers-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid #e5e5e5;
    background-color: #f9fafb;
}

/* 🎨 确保按钮容器使用水平布局 */
.layers-header > div:last-child {
    display: flex;
    align-items: center;
    gap: 4px; /* 按钮之间的间距 */
}

.layers-title {
    font-weight: 600;
    font-size: 16px;
    color: #1f2937;
}

.layers-list {
    padding: 8px;
    /* 🎯 移除：flex: 1, overflow-y: auto, max-height，让父容器统一管理滚动 */
}

/* 图层项样式 - 更新为支持整个区域拖动 */
.layer-item {
    display: flex;
    align-items: center;
    /* 为左侧“添加标签”悬浮按钮预留空间 */
    padding: 8px 8px 8px 36px;
    margin-bottom: 4px;
    background-color: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    /* 避免干扰 Sortable 的 transform 让位动画，仅对视觉属性做过渡 */
    transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    cursor: grab; /* 🆕 整个图层项显示抓手光标 */
    user-select: none; /* 🆕 防止文本选择影响拖动 */
    position: relative;
}

.layer-item:hover {
    background-color: #f0f4f8;
    border-color: #d1d5db;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}



.layer-item.active {
    background-color: #e6f7ff;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(24, 144, 255, 0.15);
}

/* 隐藏图层的样式 */
.layer-item.hidden-layer {
    opacity: 0.5;
    background-color: #f5f5f5;
    border-color: #d9d9d9;
    border-style: dashed;
}

.layer-item.hidden-layer .layer-name {
    color: #8c8c8c;
    font-style: italic;
}

.layer-item.hidden-layer .layer-thumbnail {
    opacity: 0.4;
    filter: grayscale(50%);
}

.layer-item.hidden-layer .layer-thumbnail-placeholder {
    opacity: 0.4;
    background-color: #f0f0f0;
    color: #bfbfbf;
}

/* 拖动时的样式 */
.layer-item.dragging {
    cursor: grabbing !important;
    /* 修复：拖拽时图层项整体半透明，导致背景看起来透明 */
    opacity: 1; /* 保持完全不透明 */
    transform: rotate(2deg) scale(1.02);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    background-color: #ffffff; /* 拖拽时保持白色背景，避免穿透 */
    border: 2px solid #3b82f6;
}

/* 🆕 拖动时隐藏提示 */
.layer-item.dragging::after {
    display: none;
}

/* 🆕 长按激活状态样式 */
.layer-item.long-press-active {
    background-color: #e0f2fe;
    border-color: #0284c7;
    transform: scale(1.01);
    box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.2);
}

/* 🆕 长按激活时的进度指示器 - 已删除进度条效果 */
/* 进度条效果已移除，保留注释作为记录 */

/* 🆕 拖拽手柄样式 */
/* 🗑️ 拖动句柄样式已删除，现在整个图层项都支持拖动 */

/* 🆕 拖拽状态样式 */
.layer-item.dragging {
    /* 修复：拖拽时不要降低不透明度 */
    opacity: 1;
    transform: scale(1.02);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    background-color: #ffffff; /* 明确指定背景避免视觉透明 */
    border: 2px solid #3b82f6;
}

/* 🗑️ 拖动句柄相关样式已删除 */

/* 🆕 拖拽占位符样式 */
.layer-placeholder {
    height: 60px;
    background: linear-gradient(45deg, #e5f2ff 25%, transparent 25%), 
                linear-gradient(-45deg, #e5f2ff 25%, transparent 25%), 
                linear-gradient(45deg, transparent 75%, #e5f2ff 75%), 
                linear-gradient(-45deg, transparent 75%, #e5f2ff 75%);
    background-size: 8px 8px;
    background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
    border: 2px dashed #3b82f6;
    border-radius: 6px;
    margin: 2px 0;
    opacity: 0.7;
    animation: placeholderPulse 1.5s ease-in-out infinite;
}

/* ====== 仅手柄可拖拽：新增手柄样式（不改变现有布局） ====== */
.layer-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 40px;
    margin-right: 8px;
    color: #9ca3af;
    cursor: grab;
    flex-shrink: 0;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}
.layer-handle:hover { color: #6b7280; }
.layer-chosen { 
    /* 修复：被 Sortable 选中项在拖拽开始会降低不透明度 */
    opacity: 1; /* 保持不透明 */
    background-color: #ffffff; /* 与拖拽态一致，防止底色透出 */
}
.layer-ghost, .blue-background-class {
    /* 统一幽灵项外观：浅蓝背景 + 实线边框，便于识别 */
    opacity: 1;
    background-color: rgba(59, 130, 246, 0.15);
    border: 1px solid #60a5fa;
}
.layer-dragging { cursor: grabbing; }

@keyframes placeholderPulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 0.9; }
}

/* 图层缩略图样式 */
.layer-thumbnail {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
    margin-right: 10px;
    border: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.layer-thumbnail-placeholder {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f3f4f6;
    border-radius: 4px;
    margin-right: 10px;
    border: 1px solid #e5e7eb;
    font-size: 18px;
    flex-shrink: 0;
}

/* 图层内容区域 - 包含缩略图和信息 */
.layer-content {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0; /* 防止flex子项溢出 */
}

.layer-info {
    flex: 1;
    min-width: 0; /* 防止文字溢出 */
}

.layer-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.layer-position {
    font-size: 12px;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.layer-type {
    color: #3b82f6;
    font-weight: 500;
    margin-right: 4px;
}

/* 图层操作按钮区域 - 始终显示 */
.layer-actions {
    display: flex;
    gap: 10px; /* 🔧 进一步增加图标间距 */
    opacity: 1; /* 🔧 始终显示，不再隐藏 */
    flex-shrink: 0;
    align-items: center;
    margin-left: 4px; /* 🔧 进一步减少左边距 */
    margin-right: 8px; /* 🔧 增加右边距 */
    position: relative;
    z-index: 10;
}

/* 🔧 移除悬停显示逻辑，图标始终可见 */

/* 拖拽时隐藏操作按钮 */
.layer-item.dragging .layer-actions {
    opacity: 0;
}

/* 🔧 拖拽时确保删除图标隐藏 */
.layer-item.dragging .layer-delete-icon {
    opacity: 0;
}

/* 🔧 移除旧的按钮样式，使用新的SVG图标样式 */

/* 图层操作图标通用样式 - 只针对SVG图标 */
.layer-actions svg {
    width: 18px; /* 🔧 调整图标尺寸到18px */
    height: 18px;
    cursor: pointer !important; /* 强制指针光标，覆盖父元素的grab光标 */
    transition: all 0.2s ease;
    position: relative;
    z-index: 11; /* 确保图标在最顶层 */
    flex-shrink: 0;
}

/* 右侧图层项的“添加标签”按钮，复用左侧素材面板的样式布局 */
.layer-item .layer-tag-btn {
    position: absolute;
    left: 8px; /* 避开分类色条 */
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    padding: 0;
    margin: 0;
    border-radius: 0;
    opacity: 1;
    z-index: 12;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: transparent;
}

.layer-item .layer-tag-btn svg {
    width: 19px;
    height: 19px;
}

/* 🔧 移除通用SVG hover缩放效果，改为仅针对删除图标 */
.layer-actions .layer-delete-icon:hover {
    transform: scale(1.2); /* 🔧 悬停时放大效果 - 仅针对删除图标 */
}

/* 图层删除图标样式 - 默认隐藏，悬停显示 */
.layer-delete-icon {
    color: #ef4444; /* 红色 */
    opacity: 0; /* 🔧 默认隐藏 */
    transition: all 0.2s ease; /* 包含opacity和color的过渡 */
}

.layer-delete-icon:hover {
    color: #dc2626; /* 深红色 */
}

/* 🔧 图层项悬停时显示删除图标 */
.layer-item:hover .layer-delete-icon {
    opacity: 1; /* 悬停时显示 */
}

/* 图层可见性图标样式 - 使用emoji */
.layer-visibility-icon {
    font-size: 18px; /* 🔧 调整emoji大小到18px */
    cursor: pointer !important; /* 强制指针光标 */
    transition: all 0.2s ease;
    position: relative;
    z-index: 11; /* 确保图标在最顶层 */
    flex-shrink: 0;
    display: inline-block;
    line-height: 1;
}

/* 🔧 移除图层可见性图标的hover缩放效果 - 根据用户要求保持原本大小 */
.layer-visibility-icon:hover {
    /* 移除缩放效果，保持原本大小 */
}

/* 图层上下移动按钮样式 - 悬停时显示灰色背景 */
.layers-header .layer-btn {
    width: 36px; /* 🎨 增大按钮宽度，提升可点击性 */
    height: 36px; /* 🎨 增大按钮高度，提升可点击性 */
    background-color: transparent; /* 🎨 默认透明背景 */
    border: none; /* 🎨 去除边框 */
    border-radius: 6px; /* 🎨 稍微增大圆角以适应更大的按钮 */
    padding: 0; /* 🎨 去除内边距 */
    margin: 0 2px; /* 🎨 增加左右外边距，让按钮之间有适当间隔 */
    color: #6b7280; /* 🎨 设置图标颜色为中性灰色 */
    cursor: pointer; /* 🎨 鼠标悬停时显示手形光标 */
    transition: all 0.2s ease; /* 🎨 所有属性的过渡动画 */
    display: inline-flex; /* 🎨 使用inline-flex让图标自然排列 */
    align-items: center; /* 🎨 垂直居中 */
    justify-content: center; /* 🎨 水平居中 */
}

/* 图层按钮内的SVG图标样式 */
.layers-header .layer-btn svg {
    width: 22px; /* 🎨 增大SVG图标宽度，与按钮尺寸成比例 */
    height: 22px; /* 🎨 增大SVG图标高度，与按钮尺寸成比例 */
    fill: currentColor; /* 🎨 继承按钮的文字颜色 */
    transition: all 0.2s ease; /* 🎨 添加过渡动画 */
}

.layers-header .layer-btn:hover {
    background-color: #f3f4f6; /* 🎨 悬停时显示浅灰色背景 */
    color: #374151; /* 🎨 悬停时图标颜色变深 */
}

.layers-header .layer-btn:hover svg {
    transform: scale(1.05); /* 🎨 悬停时图标轻微放大，减少放大幅度 */
}

.layers-header .layer-btn:active {
    transform: scale(0.95);
}

/* 参数表单样式 */
.params-form {
    padding: 16px;
    border-top: 1px solid #e5e5e5;
    /* 🎨 移除灰色背景，让视觉更统一 */
    background-color: transparent;
    /* 🎯 移除：max-height 和 overflow-y: auto，让父容器统一管理滚动 */
}

.form-group {
    margin-bottom: 12px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 4px;
    color: #374151;
}

.form-control {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 13px;
    transition: border-color 0.2s ease;
}

.form-control:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-row {
    display: flex;
    gap: 8px;
}

.form-row .form-group {
    flex: 1;
}

/* 响应式调整 */
@media (max-width: 1400px) {
    .layers-panel {
        width: 280px;
    }
    
    .layer-item {
        padding: 6px;
    }
    
    .layer-thumbnail,
    .layer-thumbnail-placeholder {
        width: 36px;
        height: 36px;
    }
    
    .layer-name {
        font-size: 13px;
    }
    
    .layer-position {
        font-size: 11px;
    }
}

@media (max-width: 1200px) {
    .layers-panel {
        width: 260px;
    }
    
    .layers-header {
        padding: 12px;
    }
    
    .layers-title {
        font-size: 15px;
    }
    
    .layer-item {
        padding: 5px;
    }
    
    .layer-thumbnail,
    .layer-thumbnail-placeholder {
        width: 32px;
        height: 32px;
        margin-right: 8px;
    }
    
    .layer-drag-handle {
        width: 18px;
        height: 18px;
        margin-right: 6px;
    }
    
    .layer-drag-handle .drag-icon {
        width: 12px;
        height: 12px;
    }
}

/* 上传文件隐藏的input */
#file-upload {
    display: none;
}

/* 拖放高亮样式 */
.upload-area.dragover {
    border-color: #3b82f6;
    background-color: #e5f2ff;
}

/* 弹窗样式 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background-color: white;
    border-radius: 8px;
    padding: 20px;
    width: 400px;
    max-width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.modal-title {
    font-weight: 600;
    font-size: 18px;
}

.modal-body {
    margin-bottom: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
} 
