/* 图片裁剪器样式 */
.image-cropper-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.cropper-container {
    background: white;
    border-radius: 20px;
    width: 90%;
    max-width: 900px;
    height: 85vh;
    max-height: 700px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
}

.cropper-header {
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.cropper-header h3 {
    margin: 0;
    font-size: 20px;
}

.cropper-close {
    font-size: 28px;
    cursor: pointer;
    opacity: 0.9;
    transition: opacity 0.2s;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
}

.cropper-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.3);
}

@media (max-width: 768px) {
    .cropper-close {
        font-size: 32px;
        width: 40px;
        height: 40px;
        background: rgba(255, 255, 255, 0.3);
    }
}

.cropper-body {
    padding: 20px;
    display: flex;
    gap: 20px;
    align-items: stretch;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.cropper-image-wrapper {
    position: relative;
    flex: 1;
    min-width: 0;
    background: #f0f0f0;
    border-radius: 10px;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

#cropperImage {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    display: block;
    object-fit: contain;
}

.cropper-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    pointer-events: none;
}

.cropper-box {
    position: absolute;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1000px rgba(0, 0, 0, 0.5);
    cursor: move;
    background: transparent;
    z-index: 10;
    touch-action: none;
}

.cropper-box::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 1px dashed rgba(255, 255, 255, 0.5);
}

/* 网格线 */
.cropper-box::after {
    content: '';
    position: absolute;
    top: 33.33%;
    left: 0;
    width: 100%;
    height: 33.33%;
    border-top: 1px dashed rgba(255, 255, 255, 0.3);
    border-bottom: 1px dashed rgba(255, 255, 255, 0.3);
    pointer-events: none;
}

.cropper-resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #667eea;
    border: 2px solid white;
    border-radius: 50%;
    z-index: 11;
    touch-action: none;
}

.cropper-resize-handle.nw {
    top: -5px;
    left: -5px;
    cursor: nw-resize;
}

.cropper-resize-handle.ne {
    top: -5px;
    right: -5px;
    cursor: ne-resize;
}

.cropper-resize-handle.sw {
    bottom: -5px;
    left: -5px;
    cursor: sw-resize;
}

.cropper-resize-handle.se {
    bottom: -5px;
    right: -5px;
    cursor: se-resize;
}

.cropper-preview {
    flex-shrink: 0;
    text-align: center;
    width: 200px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.cropper-preview h4 {
    margin: 0 0 10px 0;
    color: #666;
    font-size: 14px;
}

.preview-box {
    width: 150px;
    height: 150px;
    border: 2px solid #e9ecef;
    border-radius: 15px;
    overflow: hidden;
    background: white;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

#previewCanvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* 裁剪控制 */
.cropper-controls {
    margin-top: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 10px;
}

.size-label {
    display: block;
    color: #666;
    font-size: 12px;
    margin-bottom: 10px;
    font-weight: 500;
}

.size-slider {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: #e9ecef;
    border-radius: 3px;
    outline: none;
    margin-bottom: 15px;
}

.size-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
}

.size-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.size-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    border: none;
    transition: transform 0.2s;
}

.size-slider::-moz-range-thumb:hover {
    transform: scale(1.2);
}

.size-buttons {
    display: flex;
    gap: 10px;
}

.size-btn {
    flex: 1;
    padding: 8px 12px;
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    color: #666;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.size-btn:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
    transform: translateY(-1px);
}

.size-btn:active {
    transform: translateY(0);
}

.cropper-footer {
    padding: 20px;
    background: #f8f9fa;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.cropper-footer .btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 44px;
    touch-action: manipulation;
}

.cropper-footer .btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 500;
}

.cropper-footer .btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.cropper-footer .btn-secondary {
    background: #e9ecef;
    color: #666;
}

.cropper-footer .btn-secondary:hover {
    background: #dee2e6;
}

@media (max-width: 768px) {
    .cropper-footer .btn {
        padding: 12px 20px;
        font-size: 16px;
        font-weight: 500;
        min-height: 48px;
        flex: 1;
        max-width: 150px;
    }
    
    .cropper-footer .btn-primary {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    }
}

/* 手势提示 */
.gesture-hint {
    display: none;
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 12px;
    pointer-events: none;
    z-index: 12;
}

@media (pointer: coarse) {
    .gesture-hint {
        display: block;
    }
}

/* 移动端适配 - 优化为上下布局 */
@media (max-width: 768px) {
    .cropper-container {
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
    
    .cropper-header {
        padding: 15px;
        flex: 0 0 auto;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    }
    
    .cropper-body {
        flex-direction: column;
        padding: 10px;
        gap: 10px;
        flex: 1 1 auto;
        overflow-y: auto;
        overflow-x: hidden;
        min-height: 0;
        -webkit-overflow-scrolling: touch;
    }
    
    .cropper-image-wrapper {
        flex: 0 0 auto;
        height: 35vh;
        min-height: 200px;
        max-height: 350px;
        width: 100%;
    }
    
    .cropper-preview {
        width: 100%;
        flex-direction: row;
        align-items: center;
        gap: 15px;
        padding: 10px;
        background: #f8f9fa;
        border-radius: 10px;
        margin-bottom: 10px;
    }
    
    .preview-box {
        flex-shrink: 0;
        width: 100px;
        height: 100px;
    }
    
    #previewCanvas {
        width: 100px;
        height: 100px;
    }
    
    .cropper-controls {
        flex: 1;
        margin: 0;
        padding: 10px;
        background: transparent;
    }
    
    .cropper-footer {
        position: relative;
        padding: 15px;
        padding-bottom: calc(15px + env(safe-area-inset-bottom, 20px));
        flex: 0 0 auto;
        background: white;
        border-top: 2px solid #e9ecef;
        display: flex;
        justify-content: flex-end;
        gap: 10px;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
    }
}

/* 安全区域适配（iPhone X 及以上） */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 768px) {
        .cropper-header {
            padding-top: calc(15px + env(safe-area-inset-top, 0px));
        }
        
        .cropper-footer {
            padding-bottom: calc(15px + env(safe-area-inset-bottom, 20px));
            min-height: calc(60px + env(safe-area-inset-bottom, 20px));
        }
    }
}

/* 触摸设备优化 */
@media (pointer: coarse) {
    /* 移动端隐藏调整手柄 */
    .cropper-resize-handle {
        display: none !important;
    }
    
    .cropper-box {
        border-width: 3px;
    }
    
    .size-slider {
        height: 8px;
    }
    
    .size-slider::-webkit-slider-thumb {
        width: 28px;
        height: 28px;
    }
    
    .cropper-resize-handle.nw,
    .cropper-resize-handle.ne,
    .cropper-resize-handle.sw,
    .cropper-resize-handle.se {
        top: -10px;
        left: -10px;
    }
    
    .cropper-resize-handle.ne {
        left: auto;
        right: -10px;
    }
    
    .cropper-resize-handle.sw {
        top: auto;
        bottom: -10px;
    }
    
    .cropper-resize-handle.se {
        top: auto;
        left: auto;
        bottom: -10px;
        right: -10px;
    }
}