/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #1a1a1a;
    color: #ffffff;
    overflow: hidden;
}

.container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* 左侧操作面板 */
.sidebar {
    width: 320px;
    background: #2d2d2d;
    border-right: 1px solid #404040;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-content {
    flex: 1;
    min-height: 0;
    padding: 24px 24px 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.sidebar h2 {
    color: #ffffff;
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
}

/* 上传区域 */
.upload-section {
    border: 2px dashed #666;
    border-radius: 12px;
    padding: 24px;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
}

.upload-section:hover {
    border-color: #4a9eff;
    background: #1e2a3a;
}

.upload-btn {
    background: #4a9eff;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.3s ease;
    width: 100%;
    justify-content: center;
}

.upload-btn:hover {
    background: #3d85d9;
}

.upload-btn span {
    font-size: 20px;
}

/* 预设尺寸区域 */
.presets-section h3,
.custom-section h3 {
    color: #ffffff;
    font-size: 18px;
    font-weight: 500;
    margin-bottom: 16px;
}

.preset-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.preset-item {
    display: flex;
    justify-content: left;
    align-items: center;
    background: #3a3a3a;
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.preset-item:hover {
    background: #4a4a4a;
}

.preset-item.active {
    border-color: #4a9eff;
    background: #1e2a3a;
}

.preset-text {
    font-size: 14px;
    color: #ffffff;
    font-weight: 500;
}

.lock-btn {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.3s ease;
}

.lock-btn:hover {
    background: #5a5a5a;
}

.lock-btn[data-locked="false"] {
    opacity: 0.6;
}

/* 自定义尺寸区域 */
.custom-inputs {
    display: flex;
    align-items: center;
    gap: 8px;
}

.custom-inputs input {
    flex: 1;
    min-width: 0;
    background: #3a3a3a;
    border: 1px solid #555;
    border-radius: 6px;
    padding: 10px 12px;
    color: #ffffff;
    font-size: 14px;
}

.custom-inputs input:focus {
    outline: none;
    border-color: #4a9eff;
}

.custom-lock-btn {
    background: #3a3a3a;
    border: 1px solid #555;
    border-radius: 6px;
    font-size: 18px;
    cursor: pointer;
    padding: 8px 10px;
    transition: all 0.3s ease;
    min-width: 40px;
    width: 40px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.custom-lock-btn:hover {
    background: #4a4a4a;
    border-color: #4a9eff;
}

.custom-lock-btn[data-locked="false"] {
    opacity: 0.6;
}

/* 导出按钮 */
.export-section {
    margin-top: auto;
}

.export-btn {
    background: #dc3545;
    color: white;
    border: none;
    padding: 14px 24px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    width: 100%;
    transition: all 0.3s ease;
}

.export-btn:hover:not(:disabled) {
    background: #c82333;
}

.export-btn:disabled {
    background: #6c757d;
    cursor: not-allowed;
    opacity: 0.6;
}

.beian-footer {
    border-top: 1px solid #404040;
    flex-shrink: 0;
    padding: 16px 24px 20px;
    text-align: center;
}

.beian-footer a {
    color: #8f8f8f;
    font-size: 12px;
    line-height: 1.5;
    text-decoration: none;
    transition: color 0.2s ease;
}

.beian-footer a:hover {
    color: #4a9eff;
}

/* 右侧预览面板 */
.preview-panel {
    flex: 1;
    background: #1a1a1a;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.preview-container {
    position: relative;
    width: 100%;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* 当有图片时，整个预览区域都可以拖动 */
.preview-container.has-image {
    cursor: move;
}

.preview-container.has-image.dragging {
    cursor: grabbing;
}

/* 占位符 */
.placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.placeholder-content {
    text-align: center;
    color: #666;
}

.placeholder-icon {
    font-size: 64px;
    display: block;
    margin-bottom: 16px;
    opacity: 0.5;
}

.placeholder-content p {
    font-size: 18px;
    margin-bottom: 8px;
}

.placeholder-hint {
    font-size: 14px !important;
    opacity: 0.7;
}

/* 图片容器 */
.image-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    cursor: move;
    user-select: none;
    z-index: 0;
    transition: transform 0.2s cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* 拖拽时禁用图片动画 */
.image-container.dragging {
    transition: none;
    cursor: grabbing;
}

#previewImage {
    display: block;
    max-width: none;
    max-height: none;
    user-select: none;
    cursor: move;
    transition: width 0.2s cubic-bezier(0.4, 0.0, 0.2, 1),
                height 0.2s cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* 拖拽或缩放时禁用图片尺寸动画 */
.image-container.dragging #previewImage,
.image-container.scaling #previewImage {
    transition: none;
}

/* 裁剪框 */
.crop-box {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 2;
    box-sizing: border-box;
    transition: width 0.25s cubic-bezier(0.4, 0.0, 0.2, 1), 
                height 0.25s cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* 拖拽调整时禁用动画 */
.crop-box.resizing {
    transition: none;
}

/* 裁剪遮罩 */
.crop-overlay {
    position: absolute;
    background: rgba(0, 0, 0, 0.6);
    pointer-events: none;
    z-index: 1;
    /* 不使用 CSS transition，完全由 JavaScript requestAnimationFrame 控制，确保与裁剪框同步 */
    transition: none;
}

.crop-overlay-top {
    top: 0;
    left: 0;
    right: 0;
}

.crop-overlay-bottom {
    bottom: 0;
    left: 0;
    right: 0;
}

.crop-overlay-left {
    top: 0;
    bottom: 0;
    left: 0;
}

.crop-overlay-right {
    top: 0;
    bottom: 0;
    right: 0;
}

/* 裁剪框边框 */
.crop-frame {
    width: 100%;
    height: 100%;
    border: 2px solid #4a9eff;
    position: relative;
    pointer-events: auto;
    background: transparent;
    box-sizing: border-box;
}

.crop-frame::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 1px solid rgba(255, 255, 255, 0.3);
    pointer-events: none;
}

/* 裁剪控制点 */
.crop-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #4a9eff;
    border: 2px solid #ffffff;
    border-radius: 50%;
    cursor: pointer;
    transform: translate(-50%, -50%);
    transition: all 0.2s ease;
}

.crop-handle:hover {
    width: 16px;
    height: 16px;
    background: #3d85d9;
}

/* 角点控制 */
.crop-handle-nw {
    top: 0;
    left: 0;
    cursor: nw-resize;
    transform: translate(-50%, -50%);
}

.crop-handle-ne {
    top: 0;
    right: 0;
    cursor: ne-resize;
    transform: translate(50%, -50%);
}

.crop-handle-sw {
    bottom: 0;
    left: 0;
    cursor: sw-resize;
    transform: translate(-50%, 50%);
}

.crop-handle-se {
    bottom: 0;
    right: 0;
    cursor: se-resize;
    transform: translate(50%, 50%);
}

/* 边点控制 */
.crop-handle-n {
    top: 0;
    left: 50%;
    cursor: n-resize;
    transform: translate(-50%, -50%);
}

.crop-handle-s {
    bottom: 0;
    left: 50%;
    cursor: s-resize;
    transform: translate(-50%, 50%);
}

.crop-handle-w {
    left: 0;
    top: 50%;
    cursor: w-resize;
    transform: translate(-50%, -50%);
}

.crop-handle-e {
    right: 0;
    top: 50%;
    cursor: e-resize;
    transform: translate(50%, -50%);
}

/* 网格线 */
.crop-frame::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        linear-gradient(to right, rgba(255, 255, 255, 0.3) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255, 255, 255, 0.3) 1px, transparent 1px);
    background-size: 33.333% 33.333%;
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.3s ease;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid #404040;
    }
    
    .preview-panel {
        height: 60vh;
    }
}

/* 滚动条样式 */
.sidebar-content::-webkit-scrollbar {
    width: 6px;
}

.sidebar-content::-webkit-scrollbar-track {
    background: #2d2d2d;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 3px;
}

.sidebar-content::-webkit-scrollbar-thumb:hover {
    background: #666;
}

/* 图片列表区域 */
.image-list-container {
    position: relative;
    width: 100%;
    background: rgba(0, 0, 0, 0.9);
    border-top: 1px solid #404040;
    padding: 12px;
    max-height: 150px;
    z-index: 10;
    flex-shrink: 0;
}

.image-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding: 0 4px;
}

.image-count {
    color: #cccccc;
    font-size: 14px;
}

.image-count span {
    color: #4a9eff;
    font-weight: 600;
}

.clear-all-btn {
    background: #dc3545;
    color: white;
    border: none;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.3s ease;
}

.clear-all-btn:hover {
    background: #c82333;
}

.image-list {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 0;
}

.image-list::-webkit-scrollbar {
    height: 6px;
}

.image-list::-webkit-scrollbar-track {
    background: #2d2d2d;
}

.image-list::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 3px;
}

.image-list::-webkit-scrollbar-thumb:hover {
    background: #666;
}

.image-list-item {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.image-list-item:hover {
    border-color: #4a9eff;
    transform: translateY(-2px);
}

.image-list-item.active {
    border-color: #4a9eff;
    box-shadow: 0 0 0 2px rgba(74, 158, 255, 0.3);
}

.image-list-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-list-item .remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    background: rgba(220, 53, 69, 0.9);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.image-list-item:hover .remove-btn {
    opacity: 1;
}

.image-list-item .remove-btn:hover {
    background: #dc3545;
}
