/* التصميم الأساسي */
* {
    box-sizing: border-box;
}

.cpd-box {
    width: 100%;
    max-width: 1200px;
    margin: 20px auto;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    overflow: hidden;
}

.cpd-title {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    padding: 20px;
    text-align: center;
    font-size: 24px;
    font-weight: 600;
}

.cpd-container {
    display: flex;
    gap: 20px;
    padding: 20px;
}

/* القسم الأيسر - المعاينة */
.cpd-preview-side {
    flex: 1 1 60%;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.cpd-preview-title {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    padding: 10px 0;
}

.cpd-images-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    min-height: 200px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 2px dashed #dee2e6;
}

.cpd-image-box {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s;
    background: #fff;
    border: 2px solid #e9ecef;
}

.cpd-image-box:hover {
    transform: scale(1.05);
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.cpd-image-box img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cpd-image-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}

.cpd-image-box:hover .cpd-image-overlay {
    opacity: 1;
}

/* إظهار الأزرار دائماً على الشاشات الصغيرة (الجوال) */
@media (max-width: 768px) {
    .cpd-image-overlay {
        opacity: 1 !important;
        background: rgba(0,0,0,0.6);
    }
}

.cpd-image-btn {
    padding: 8px 10px !important;
    border: none !important;
    border-radius: 6px !important;
    cursor: pointer;
    font-size: 16px !important;
    transition: all 0.2s !important;
    background: rgba(255, 255, 255, 0.95) !important;
    width: 36px !important;
    min-width: 36px !important;
    height: 36px !important;
    min-height: 36px !important;
    line-height: 1 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    /* منع التحديد على الجوال */
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* تأثير اللمس على الجوال */
.cpd-image-btn:active {
    transform: scale(0.95);
}

.cpd-edit-btn:hover,
.cpd-edit-btn:active {
    background: #667eea !important;
    transform: scale(1.1);
}

.cpd-duplicate-btn:hover,
.cpd-duplicate-btn:active {
    background: #ffc107 !important;
    transform: scale(1.1);
}

.cpd-delete-btn:hover,
.cpd-delete-btn:active {
    background: #dc3545 !important;
    transform: scale(1.1);
}

.cpd-image-number {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(102, 126, 234, 0.9);
    color: #fff;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 12px;
    font-weight: 600;
}

/* منطقة الرفع */
.cpd-upload-area {
    border: 3px dashed #dee2e6;
    border-radius: 12px;
    padding: 40px 20px;
    text-align: center;
    background: #f8f9fa;
    transition: all 0.3s;
    cursor: pointer;
}

.cpd-upload-area:hover,
.cpd-upload-area.drag-over {
    border-color: #667eea;
    background: #f0f3ff;
}

.cpd-upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    color: #495057;
}

.cpd-upload-icon {
    font-size: 48px;
}

.cpd-upload-hint {
    font-size: 14px;
    color: #6c757d;
}

.cpd-images-counter {
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    color: #667eea;
    padding: 10px;
    background: #f0f3ff;
    border-radius: 8px;
}

/* القسم الأيمن - الإجراءات */
.cpd-controls-side {
    flex: 1 1 30%;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.cpd-actions-wrapper {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.cpd-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
}

.cpd-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.cpd-btn-primary {
    background: linear-gradient(135deg, #db8f7b 0%, #b66c58 100%);
    color: #fff;
}

.cpd-btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.cpd-btn-gift {
    background: linear-gradient(135deg, #c1ca92 0%, #a3a96f 100%);
    color: #fff;
}

.cpd-btn-gift:hover:not(:disabled),
.cpd-btn-gift.active {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(245, 87, 108, 0.4);
}

.cpd-btn-secondary {
    background: #6c757d;
    color: #fff;
}

.cpd-btn-secondary:hover {
    background: #5a6268;
}

.cpd-btn-confirm {
    background: #28a745;
    color: #fff;
    margin-top: 20px;
}

.cpd-btn-confirm:hover {
    background: #218838;
}

.cpd-btn-add-more {
    background: #fff;
    color: #667eea;
    border: 2px solid #667eea;
}

.cpd-btn-add-more:hover {
    background: #667eea;
    color: #fff;
}

/* قسم الهدية */
.cpd-gift-section {
    background: #fff3cd;
    border: 2px solid #ffc107;
    border-radius: 12px;
    padding: 20px;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

.cpd-gift-header h3 {
    margin: 0;
    color: #856404;
    font-size: 18px;
}

.cpd-close-btn {
    background: transparent;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #856404;
    transition: transform 0.2s;
}

.cpd-close-btn:hover {
    transform: scale(1.2);
}

.cpd-gift-section label {
    display: block;
    margin-top: 12px;
    margin-bottom: 5px;
    font-weight: 600;
    color: #856404;
}

.cpd-gift-section input,
.cpd-gift-section textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ffc107;
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
}

.cpd-gift-section input:focus,
.cpd-gift-section textarea:focus {
    outline: none;
    border-color: #ff9800;
    box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.2);
}

.cpd-gift-section textarea {
    resize: vertical;
    min-height: 80px;
}

/* النوافذ المنبثقة */
.cpd-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.cpd-modal.active {
    display: flex;
}

.cpd-modal-content {
    background: #fff;
    border-radius: 12px;
    max-width: 90%;
    max-height: 90%;
    overflow: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.cpd-modal-header {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 15px 20px;
    border-bottom: 1px solid #dee2e6;
    background: #f8f9fa;
}

.cpd-modal-header h3 {
    display: none;
}

.cpd-modal-header .cpd-btn {
    margin: 0;
    padding: 10px 24px;
    font-size: 15px;
    min-width: 120px;
}

/* نافذة القص */
.cpd-crop-container {
    padding: 20px;
    max-height: 70vh;
    overflow: auto;
}

#cpd-crop-image {
    max-width: 100%;
    display: block;
}

/* تأثير الـ overlay للمنطقة خارج القص */
.cropper-modal {
    background-color: rgba(255, 255, 255, 0.85) !important;
}

.cropper-crop-box {
    box-shadow: 0 0 0 9999px rgba(255, 255, 255, 0.85) !important;
}

.cpd-crop-buttons {
    display: none;
}

/* الاستجابة للشاشات الصغيرة */
@media (max-width: 992px) {
    .cpd-container {
        flex-direction: column;
    }
    
    .cpd-preview-side,
    .cpd-controls-side {
        flex: 1 1 100%;
    }
    
    .cpd-images-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 576px) {
    .cpd-title {
        font-size: 20px;
        padding: 15px;
    }
    
    .cpd-container {
        padding: 15px;
    }
    
    .cpd-images-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    .cpd-upload-area {
        padding: 30px 15px;
    }
    
    .cpd-upload-icon {
        font-size: 36px;
    }
    
    /* تحسين الأزرار على الجوال */
    .cpd-image-btn {
        width: 40px !important;
        min-width: 40px !important;
        height: 40px !important;
        min-height: 40px !important;
        font-size: 18px !important;
    }
    
    .cpd-image-overlay {
        gap: 6px;
    }
}
