/* 图层分离功能样式 */
.layer-split-loader {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #6366f1;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    animation: layer-spin 1s linear infinite;
}
@keyframes layer-spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.layer-glass-panel { background: rgba(255, 255, 255, 0.98); backdrop-filter: blur(10px); }

/* 
body { 
    background-color: #f8fafc; 
    background-image: radial-gradient(#cbd5e1 1px, transparent 1px); 
    background-size: 24px 24px;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    margin: 0;
}
*/

.layer-workspace-area {
    position: relative;
    width: 100%;
    flex: 1;
    background: #e2e8f0;
    border-radius: 1rem;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed #cbd5e1;
}
.layer-workspace-area.has-image { background: #1e293b; border: 2px solid #6366f1; }

#layerCanvasContainer {
    position: relative;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    /* 修正画布大小逻辑，确保不超过容器 */
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
}

#layerMainImage {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    display: block;
    user-select: none;
    -webkit-user-drag: none;
    object-fit: contain;
    z-index: 1;
}

/* 提取主体图层样式 */
.layer-wrapper {
    position: absolute;
    z-index: 150;
    cursor: grab;
    transition: outline 0.1s;
    user-select: none;
    pointer-events: auto;
}
.layer-wrapper:active { cursor: grabbing; }
.layer-wrapper.active {
    outline: 2px solid #6366f1;
    z-index: 160;
}

.layer-img {
    width: 100%;
    height: 100%;
    display: block;
    -webkit-user-drag: none;
}

.layer-close {
    position: absolute;
    top: -36px;
    right: -36px;
    width: 28px;
    height: 28px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
    z-index: 200;
    border: 2px solid white;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}
.layer-wrapper.active .layer-close { opacity: 1; visibility: visible; }
.layer-close:hover { transform: scale(1.1); background: #dc2626; }

.layer-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #fff;
    border: 2px solid #6366f1;
    border-radius: 50%;
    z-index: 180;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s;
}
.layer-wrapper.active .layer-handle { opacity: 1; visibility: visible; }

.h-nw { top: -5px; left: -5px; cursor: nw-resize; }
.h-n  { top: -5px; left: calc(50% - 5px); cursor: n-resize; }
.h-ne { top: -5px; right: -5px; cursor: ne-resize; }
.h-e  { top: calc(50% - 5px); right: -5px; cursor: e-resize; }
.h-se { bottom: -5px; right: -5px; cursor: se-resize; }
.h-s  { bottom: -5px; left: calc(50% - 5px); cursor: s-resize; }
.h-sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.h-w  { top: calc(50% - 5px); left: -5px; cursor: w-resize; }

.layer-click-point {
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    border: 2px solid white;
    box-shadow: 0 0 8px rgba(0,0,0,0.5);
    pointer-events: none;
    z-index: 110;
}
.point-positive { background-color: #ef4444; } 
.point-negative { background-color: #3b82f6; } 

.layer-selection-box {
    position: absolute;
    border: 2px solid #ef4444;
    background-color: rgba(239, 68, 68, 0.15);
    pointer-events: none;
    z-index: 110;
}

/* 笔刷图层 */
#layerBrushLayer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 105;
    pointer-events: none; 
    opacity: 0.3; /* 30%透明度 */
}
/* 当笔刷激活时，我们在JS里控制cursor:none，所以这里不需要强制crosshair */
.brush-active {
    pointer-events: auto !important;
}

/* 笔刷预览光标 */
#layerBrushCursor {
    position: absolute;
    border: 1px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 0 2px rgba(0,0,0,0.5); /* 增加阴影使其在白色背景也可见 */
    background-color: rgba(239, 68, 68, 0.1); /* 淡淡的红色填充提示 */
    border-radius: 50%;
    pointer-events: none;
    z-index: 200;
    transform: translate(-50%, -50%);
    display: none;
}

.layer-sidebar-container {
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1), margin-left 0.5s ease;
    width: 340px;
    height: 100%;
    position: relative;
}
.layer-sidebar-container.collapsed { width: 0px; margin-left: -20px; }

#layerExpandFab {
    position: fixed;
    right: 0;
    top: 24px; 
    background: #1e293b;
    color: white;
    padding: 16px 8px;
    border-radius: 12px 0 0 12px;
    cursor: pointer;
    z-index: 60;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    box-shadow: -4px 0 15px rgba(0,0,0,0.1);
}

.layer-mode-btn.active { background-color: white; color: #6366f1; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }

.layer-history-btn {
    opacity: 0.5;
    transition: all 0.2s;
}
.layer-history-btn.enabled {
    opacity: 1;
    cursor: pointer;
}
.layer-history-btn.enabled:hover { color: #818cf8; }

.layer-eraser-btn.active {
    background-color: #ef4444;
    color: white;
    border-color: #ef4444;
}

#layerControlPanel {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 500px;
    opacity: 1;
    overflow: hidden;
}
#layerControlPanel.collapsed {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    padding-top: 0;
    padding-bottom: 0;
}

#layerFloatingToolbar {
    position: absolute;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s, border-radius 0.3s;
    height: 52px;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    z-index: 300;
    padding: 0;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 26px;
    pointer-events: auto; /* Ensure clickable */
}
#layerFloatingToolbar.collapsed { width: 52px; overflow: hidden; }
#layerToolbarToggleBtn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: move;
    flex-shrink: 0;
    color: white;
    transition: background 0.2s;
}
#layerToolbarToggleBtn:hover { background: rgba(255,255,255,0.1); }

#layerToolbarContent {
    transition: opacity 0.2s, width 0.3s;
    display: flex;
    align-items: center;
    gap: 12px;
    padding-right: 16px;
    opacity: 1;
    width: auto;
    white-space: nowrap;
}
#layerFloatingToolbar.collapsed #layerToolbarContent { opacity: 0; width: 0; padding-right: 0; pointer-events: none; }

/* Range Slider Styling */
.layer-range-input {
    -webkit-appearance: none;
    background: transparent;
}
.layer-range-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 12px;
    width: 12px;
    border-radius: 50%;
    background: #ffffff;
    cursor: pointer;
    margin-top: -4px; 
    box-shadow: 0 0 5px rgba(0,0,0,0.5);
}
.layer-range-input::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: rgba(255,255,255,0.3);
    border-radius: 2px;
}

/* 资产库样式 */
.asset-tag {
    font-size: 8px;
    padding: 2px 4px;
    border-radius: 4px;
    font-weight: bold;
    text-transform: uppercase;
}
.asset-tag.layer { background-color: #e0e7ff; color: #4338ca; }
.asset-tag.layer-full { background-color: #fef3c7; color: #b45309; }
.asset-tag.bg { background-color: #dcfce7; color: #15803d; }
.asset-tag.mask { background-color: #f3f4f6; color: #374151; border: 1px solid #d1d5db; }

/* 提示词输入框 */
.layer-prompt-input {
    width: 100%;
    height: 100%;
    padding: 12px 16px;
    border: none;
    outline: none;
    font-size: 13px;
    color: #000000; /* Pure black */
    background: transparent;
    resize: none;
    font-family: inherit;
    line-height: 1.5;
}
.layer-prompt-input::placeholder {
    color: #94a3b8; /* slate-400 */
}
