/**
 * WooCommerce Photo Upload Editor Styles
 */

#wupe-upload-form {
    margin: 20px 0;
}

/* Dropzone Styles */
.wupe-dropzone {
    position: relative;
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    padding: 40px 20px;
    text-align: center;
    background: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.wupe-dropzone:hover {
    border-color: #57B0FF;
    background: #f9fafb;
}

.wupe-dropzone.dragover {
    border-color: #57B0FF;
    background: #f0f9ff;
    border-style: solid;
}

.wupe-dropzone-icons {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
}

.wupe-icon-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
}

.wupe-profile-icon {
    width: 50px;
    height: 50px;
    object-fit: contain;
}

.wupe-folder-icon {
    width: 48px;
    height: 38px;
    object-fit: contain;
}

.wupe-dropzone-text {
    text-align: center;
}

.wupe-main-text {
    font-size: 16px;
    font-weight: 500;
    color: #1f2937;
    margin: 0 0 8px 0;
    line-height: 1.5;
}

.wupe-sub-text {
    font-size: 14px;
    color: #6b7280;
    margin: 0;
    line-height: 1.4;
}

.wupe-title-text {
    font-size: 14px;
    color: #6b7280;
    margin: 12px 0 0 0;
    line-height: 1.4;
    text-align: center;
}

/* Error Message */
.wupe-error-message {
    margin-top: 12px;
    padding: 10px 15px;
    background: #fee;
    border: 1px solid #fcc;
    border-radius: 4px;
    color: #c33;
    font-size: 14px;
    text-align: center;
    display: none;
}

/* Cart Thumbnail Photos */
.wupe-cart-thumbnail-photos {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 5px;
    line-height: 0;
}

.wupe-cart-thumbnail-photo {
    display: inline-block;
    flex: 0 0 auto;
    line-height: 0;
}

.wupe-cart-thumbnail-photo img {
    width: 30px;
    height: 30px;
    object-fit: cover;
    border-radius: 3px;
    border: 1px solid #ddd;
    display: block;
}

#wupe-file-input {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 1;
}

#wupe-success-area {
    text-align: center;
    padding: 20px;
}

#wupe-uploaded-image {
    max-width: 200px;
    height: auto;
    border-radius: 4px;
    margin-bottom: 15px;
    border: 2px solid #46b450;
}

#wupe-success-message {
    color: #46b450;
    font-weight: 500;
    margin-bottom: 15px;
}

#wupe-reselect {
    padding: 8px 16px;
    background: #0073aa;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s;
}

#wupe-reselect:hover {
    background: #005a87;
}

/* Photos Container Styles */
#wupe-photos-container {
    margin-top: 20px;
}

.wupe-photos-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e5e7eb;
}

.wupe-photos-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #1f2937;
}

.wupe-photos-count {
    font-size: 14px;
    color: #6b7280;
    font-weight: 500;
}

.wupe-photos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 15px;
    margin-bottom: 15px;
}

.wupe-photo-item {
    position: relative;
    aspect-ratio: 1;
}

.wupe-photo-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #e5e7eb;
    transition: all 0.3s;
}

.wupe-photo-wrapper:hover {
    border-color: #57B0FF;
    box-shadow: 0 2px 8px rgba(87, 176, 255, 0.2);
}

.wupe-photo-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    image-orientation: from-image;
    /* 确保iOS照片方向正确 */
}

.wupe-photo-delete {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(220, 38, 38, 0.9);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    opacity: 0;
}

.wupe-photo-item:hover .wupe-photo-delete {
    opacity: 1;
}

.wupe-photo-delete:hover {
    background: rgba(220, 38, 38, 1);
    transform: scale(1.1);
}

.wupe-photos-actions {
    text-align: center;
    margin-top: 15px;
}

.wupe-btn-add {
    padding: 10px 20px;
    background: #0073aa;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s;
    font-weight: 500;
}

.wupe-btn-add:hover {
    background: #005a87;
}

.wupe-btn-add:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Modal Styles */
.wupe-modal {
    display: none;
    position: fixed;
    z-index: 99999 !important;
    /* 确保在移动端不被产品gallery遮挡 */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.7);
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* 当模态框打开时，禁止body滚动 */
body.wupe-modal-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
}

/* 确保模态框在所有WooCommerce元素之上 */
.wupe-modal {
    position: fixed !important;
    inset: 0 !important;
}


.wupe-modal-content {
    background-color: #fff;
    margin: 5% auto;
    padding: 0;
    border: 1px solid #888;
    border-radius: 8px;
    width: 90%;
    max-width: 700px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.wupe-modal-header {
    padding: 20px;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
    border-radius: 8px 8px 0 0;
}

.wupe-modal-header h3 {
    margin: 0;
    font-size: 20px;
    color: #333;
}

.wupe-modal-close {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 20px;
    transition: color 0.3s;
}

.wupe-modal-close:hover,
.wupe-modal-close:focus {
    color: #000;
}

.wupe-modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

#wupe-crop-container {
    max-width: 100%;
    margin: 0 auto;
    position: relative;
    min-height: 400px;
    max-height: 60vh;
    background: #f0f0f0;
    border-radius: 4px;
    overflow: hidden;
}

#wupe-crop-image {
    max-width: 100%;
    height: auto;
    display: block;
}

.wupe-crop-controls {
    position: absolute;
    top: 15px;
    right: 15px;
    display: flex;
    gap: 8px;
    z-index: 10;
}

.wupe-icon-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.wupe-icon-btn:hover {
    background: rgba(255, 255, 255, 1);
    border-color: #0073aa;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transform: scale(1.05);
}

.wupe-icon-btn:active {
    transform: scale(0.95);
}

.wupe-icon-btn svg {
    width: 20px;
    height: 20px;
    stroke: #333;
}

.wupe-icon-btn:hover svg {
    stroke: #0073aa;
}

.wupe-modal-footer {
    padding: 20px;
    border-top: 1px solid #ddd;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: #f8f9fa;
    border-radius: 0 0 8px 8px;
}

.wupe-btn-primary,
.wupe-btn-secondary {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
    font-weight: 500;
}

.wupe-btn-primary {
    background: #46b450;
    color: #fff;
}

.wupe-btn-primary:hover:not(:disabled) {
    background: #3a9e42;
}

.wupe-btn-primary:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.wupe-btn-secondary {
    background: #dc3232;
    color: #fff;
}

.wupe-btn-secondary:hover {
    background: #c12a2a;
}

/* Cart and Order Photo Display */
.woocommerce-cart .wupe-cart-photo,
.woocommerce-checkout .wupe-cart-photo,
.woocommerce-order .wupe-order-photo {
    margin-top: 10px;
}

/* Cart Photos Display */
.wupe-cart-photos {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.wupe-cart-photo {
    flex: 0 0 auto;
}

.wupe-cart-photo img {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #ddd;
    display: block;
}

/* Mini Cart (Sidebar) Photos */
.wupe-mini-cart-photos {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
    clear: both;
    line-height: 0;
}

.wupe-mini-cart-photo {
    display: inline-block;
    flex: 0 0 auto;
    line-height: 0;
}

.wupe-mini-cart-photo img {
    width: 35px;
    height: 35px;
    object-fit: cover;
    border-radius: 3px;
    border: 1px solid #ddd;
    display: block;
}

/* Cart Page Photos */
.woocommerce-cart .wupe-cart-page-photos {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    line-height: 0;
    clear: both;
}

.wupe-cart-page-photos {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    line-height: 0;
}

.wupe-cart-page-photo {
    display: inline-block;
    flex: 0 0 auto;
    line-height: 0;
}

.wupe-cart-page-photo img {
    width: 45px;
    height: 45px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #ddd;
    display: block;
}

/* Checkout Photos */
.wupe-checkout-photos,
.wupe-checkout-item-photos {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    line-height: 0;
}

.wupe-checkout-photo {
    display: inline-block;
    flex: 0 0 auto;
    line-height: 0;
}

.wupe-checkout-photo img {
    width: 45px;
    height: 45px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #ddd;
    display: block;
}

/* Ensure photos are visible in cart and checkout tables */
.woocommerce-cart .cart .cart_item .wupe-cart-page-photos,
.woocommerce-checkout .shop_table .wupe-checkout-photos,
.woocommerce-checkout .shop_table .wupe-checkout-item-photos {
    display: flex !important;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

/* Order Photos */
.wupe-order-photo img,
.wupe-order-photos-grid img {
    max-width: 80px;
    height: auto;
    border-radius: 4px;
    border: 1px solid #ddd;
}

/* Responsive Design */
@media (max-width: 768px) {
    .wupe-dropzone {
        padding: 30px 15px;
        min-height: 180px;
    }

    .wupe-dropzone-icons {
        gap: 15px;
        margin-bottom: 15px;
    }

    .wupe-profile-icon {
        width: 40px;
        height: 40px;
    }

    .wupe-folder-icon {
        width: 38px;
        height: 30px;
    }

    .wupe-main-text {
        font-size: 14px;
    }

    .wupe-sub-text {
        font-size: 12px;
    }

    .wupe-modal {
        padding: 0;
        align-items: center;
        justify-content: center;
    }

    body.wupe-modal-open .wupe-modal {
        display: flex !important;
    }

    .wupe-modal-content {
        width: 100%;
        margin: auto;
        /* 配合flex居中 */
        max-width: 100%;
        max-height: 90vh;
        /* 留出一些边距 */
        border-radius: 0;
        height: auto;
        /* 改为auto，让内容自适应 */
        display: flex;
        flex-direction: column;
    }

    .wupe-modal-header {
        padding: 12px 15px;
        /* 减小padding */
    }

    .wupe-modal-header h3 {
        font-size: 16px;
        /* 减小字体 */
    }

    .wupe-modal-body {
        padding: 10px;
        flex: 1;
        display: flex;
        align-items: center;
        position: relative;
        z-index: 1;
        overflow: hidden;
        /* 防止内容溢出 */
    }

    #wupe-crop-container {
        min-height: 250px;
        /* 进一步减小 */
        max-height: 50vh;
        /* 使用更小的vh值 */
        width: 100%;
        position: relative;
        z-index: 1;
        touch-action: none;
        /* 优化触摸操作 */
    }

    .wupe-crop-controls {
        top: 10px;
        right: 10px;
        gap: 6px;
        z-index: 100 !important;
        /* 确保控制按钮在最上层 */
    }

    .wupe-icon-btn {
        width: 36px;
        height: 36px;
    }

    .wupe-icon-btn svg {
        width: 18px;
        height: 18px;
    }

    .wupe-modal-footer {
        flex-direction: column;
        padding: 10px;
        /* 减小padding */
        gap: 8px;
        /* 减小按钮间距 */
    }

    .wupe-btn-primary,
    .wupe-btn-secondary {
        width: 100%;
    }

    .wupe-photos-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 10px;
    }

    .wupe-photos-title {
        font-size: 14px;
    }

    .wupe-photos-count {
        font-size: 12px;
    }

    .wupe-mini-cart-photo img {
        width: 30px;
        height: 30px;
    }

    .wupe-cart-page-photo img,
    .wupe-checkout-photo img {
        width: 40px;
        height: 40px;
    }

    .wupe-cart-photo img {
        width: 45px;
        height: 45px;
    }
}

@media (max-width: 480px) {
    .wupe-dropzone {
        padding: 25px 10px;
        min-height: 160px;
    }

    .wupe-dropzone-icons {
        gap: 12px;
        margin-bottom: 12px;
    }

    .wupe-profile-icon {
        width: 35px;
        height: 35px;
    }

    .wupe-folder-icon {
        width: 32px;
        height: 25px;
    }

    .wupe-main-text {
        font-size: 13px;
    }

    .wupe-sub-text {
        font-size: 11px;
    }

    .wupe-photos-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 8px;
    }
}

/* Mapping Mode Specific Styles */
.wupe-mapping-container {
    scrollbar-width: thin;
    scrollbar-color: #a0d4d4 #f0fafa;
    -webkit-overflow-scrolling: touch;
}

.wupe-mapping-container::-webkit-scrollbar {
    height: 6px;
}

.wupe-mapping-container::-webkit-scrollbar-track {
    background: #f0fafa;
    border-radius: 10px;
}

.wupe-mapping-container::-webkit-scrollbar-thumb {
    background: #a0d4d4;
    border-radius: 10px;
}

.wupe-mapping-slot {
    transition: transform 0.2s ease;
}

.wupe-mapping-slot:hover {
    transform: translateY(-5px);
}

.wupe-slot-target {
    transition: all 0.3s ease;
}

.wupe-slot-target:hover {
    border-color: #4a9090 !important;
    background: #e6f7f7 !important;
    box-shadow: 0 0 10px rgba(74, 144, 144, 0.2);
}

.wupe-mapping-arrow {
    display: flex;
    justify-content: center;
    align-items: center;
    animation: bounce 2s infinite;
}

@keyframes bounce {

    0%,
    20%,
    50%,
    80%,
    100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-5px);
    }

    60% {
        transform: translateY(-3px);
    }
}

.wupe-slot-reference {
    transition: box-shadow 0.3s ease;
}

.wupe-mapping-slot:hover .wupe-slot-reference {
    box-shadow: 0 6px 12px rgba(160, 212, 212, 0.4);
}

.wupe-slot-preview {
    animation: fadeIn 0.4s ease;
    image-orientation: from-image;
    /* 确保iOS照片方向正确 */
}

/* Cart & Checkout Circle Icons */
.wupe-cart-photo-line img {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease;
}

.wupe-cart-photo-line img:hover {
    transform: scale(1.1);
    z-index: 10;
}

/* Mini-cart Avatar Stack Effect */
.wupe-mini-cart-gallery img {
    transition: transform 0.2s ease, margin 0.2s ease;
}

.wupe-mini-cart-gallery img:hover {
    transform: scale(1.2) translateY(-2px);
    z-index: 50 !important;
}