/**
 * Modal Gallery برای کاربران
 * طراحی شبیه wp.media اما حرفه‌ای‌تر و مدرن‌تر
 */

/* قفل اسکرول body */
body.mlm-modal-open {
	overflow: hidden !important;
}

/* جلوگیری از drag برای تمام element های modal */
.mlm-media-modal * {
	-webkit-user-drag: none;
	-khtml-user-drag: none;
	-moz-user-drag: none;
	-o-user-drag: none;
	user-drag: none;
}

.mlm-media-modal img {
	pointer-events: auto;
	-webkit-user-drag: none;
	-khtml-user-drag: none;
	-moz-user-drag: none;
	-o-user-drag: none;
	user-drag: none;
}

.mlm-media-item {
	-webkit-user-select: none;
	-moz-user-select: none;
	-ms-user-select: none;
	user-select: none;
}

/* مخفی کردن تمام dropdown ها وقتی modal بسته است */
body:not(.mlm-modal-open) .mlm-media-filter-dropdown,
body:not(.mlm-modal-open) .mlm-media-dropdown,
body:not(.mlm-modal-open) .mlm-dropdown-menu {
	display: none !important;
	opacity: 0 !important;
	visibility: hidden !important;
	pointer-events: none !important;
}

/* مخفی کردن کامل تمام element های modal وقتی بسته است */
body:not(.mlm-modal-open) #mlm-media-modal,
body:not(.mlm-modal-open) #mlm-media-modal-backdrop {
	display: none !important;
	opacity: 0 !important;
	visibility: hidden !important;
	pointer-events: none !important;
	z-index: -9999 !important;
}

/* اطمینان از اینکه هیچ element modal در پس‌زمینه فعال نباشد */
#mlm-media-modal:not(.active),
#mlm-media-modal-backdrop:not(.active) {
	display: none !important;
	pointer-events: none !important;
}

/* Overlay */
.mlm-media-modal-backdrop {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.7);
	z-index: 999998;
	opacity: 0;
	transition: opacity 0.2s ease;
}

.mlm-media-modal-backdrop.active {
	opacity: 1;
}

/* Modal Container */
.mlm-media-modal {
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%) scale(0.9);
	width: 90%;
	max-width: 1200px;
	height: 85vh;
	max-height: 800px;
	background: #fff;
	border-radius: 12px;
	box-shadow: 0 10px 50px rgba(0, 0, 0, 0.3);
	z-index: 999999;
	display: flex;
	flex-direction: column;
	opacity: 0;
	transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
	overflow: hidden;
}

.mlm-media-modal.active {
	opacity: 1;
	transform: translate(-50%, -50%) scale(1);
}

/* Header */
.mlm-media-modal-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 20px 30px;
	border-bottom: 2px solid #e0e0e0;
	background: #fff;
	color: #333;
}

.mlm-media-modal-title {
	font-size: 20px;
	font-weight: 700;
	margin: 0;
	display: flex;
	align-items: center;
	gap: 10px;
}

.mlm-media-modal-title i {
	font-size: 24px;
}

.mlm-media-modal-close {
	background: #f5f5f5;
	border: none;
	color: #666;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: all 0.2s;
	font-size: 20px;
}

.mlm-media-modal-close:hover {
	background: #e74c3c;
	color: #fff;
	transform: rotate(90deg);
}

/* Body */
.mlm-media-modal-body {
	display: flex;
	flex: 1;
	overflow: hidden;
}

/* Sidebar */
.mlm-media-modal-sidebar {
	width: 220px;
	background: #f8f9fa;
	border-left: 1px solid #e0e0e0;
	padding: 20px;
	overflow-y: auto;
}

.mlm-media-modal-tabs {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.mlm-media-modal-tab {
	padding: 12px 16px;
	background: white;
	border: 1px solid #e0e0e0;
	border-radius: 8px;
	cursor: pointer;
	transition: all 0.2s;
	display: flex;
	align-items: center;
	gap: 10px;
	font-weight: 500;
	color: #555;
}

.mlm-media-modal-tab i {
	font-size: 18px;
	width: 24px;
	text-align: center;
}

.mlm-media-modal-tab:hover {
	background: #667eea;
	color: white;
	border-color: #667eea;
}

.mlm-media-modal-tab.active {
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	color: white;
	border-color: transparent;
	box-shadow: 0 4px 10px rgba(102, 126, 234, 0.3);
}

/* Content */
.mlm-media-modal-content {
	flex: 1;
	display: flex;
	flex-direction: column;
	overflow-y: auto;
	overflow-x: hidden;
}

/* Custom Scrollbar */
.mlm-media-modal-content::-webkit-scrollbar {
	width: 8px;
}

.mlm-media-modal-content::-webkit-scrollbar-track {
	background: #f1f1f1;
	border-radius: 10px;
}

.mlm-media-modal-content::-webkit-scrollbar-thumb {
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	border-radius: 10px;
}

.mlm-media-modal-content::-webkit-scrollbar-thumb:hover {
	background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}

/* Toolbar */
.mlm-media-modal-toolbar {
	padding: 15px 20px;
	border-bottom: 1px solid #e0e0e0;
	display: flex;
	align-items: center;
	gap: 15px;
	background: white;
}

.mlm-media-modal-search {
	flex: 1;
	position: relative;
}

.mlm-media-modal-search input {
	width: 100%;
	padding: 10px 15px 10px 40px;
	border: 1px solid #ddd;
	border-radius: 8px;
	font-size: 14px;
	transition: all 0.2s;
}

.mlm-media-modal-search input:focus {
	outline: none;
	border-color: #667eea;
	box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.mlm-media-modal-search i {
	position: absolute;
	right: 15px;
	top: 50%;
	transform: translateY(-50%);
	color: #999;
}

.mlm-media-modal-filter {
	display: flex;
	gap: 10px;
}

.mlm-media-modal-filter select {
	padding: 10px 15px;
	border: 1px solid #ddd;
	border-radius: 8px;
	font-size: 14px;
	background: white;
	cursor: pointer;
	transition: all 0.2s;
}

.mlm-media-modal-filter select:focus {
	outline: none;
	border-color: #667eea;
	box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Grid/List View */
.mlm-media-modal-view-toggle {
	display: flex;
	gap: 5px;
	background: #f0f0f0;
	padding: 4px;
	border-radius: 8px;
}

.mlm-media-modal-view-btn {
	padding: 8px 12px;
	background: transparent;
	border: none;
	border-radius: 6px;
	cursor: pointer;
	transition: all 0.2s;
	color: #666;
}

.mlm-media-modal-view-btn:hover {
	background: rgba(102, 126, 234, 0.1);
	color: #667eea;
}

.mlm-media-modal-view-btn.active {
	background: white;
	color: #667eea;
	box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

/* Gallery Grid */
.mlm-media-modal-gallery {
	flex: 1;
	overflow-y: auto;
	padding: 20px;
	background: #fafafa;
}

.mlm-media-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
	gap: 15px;
}

/* Media Item */
.mlm-media-item {
	position: relative;
	aspect-ratio: 1;
	background: white;
	border: 2px solid #e0e0e0;
	border-radius: 10px;
	cursor: pointer;
	overflow: hidden;
	transition: all 0.2s;
	display: flex;
	align-items: center;
	justify-content: center;
}

.mlm-media-item:hover {
	border-color: #667eea;
	transform: translateY(-2px);
	box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.mlm-media-item.selected {
	border-color: #667eea;
	box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.2);
}

.mlm-media-item-inner {
	width: 100%;
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	position: relative;
}

.mlm-media-item img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.mlm-media-item-icon {
	font-size: 48px;
	color: #667eea;
}

.mlm-media-item-info {
	position: absolute;
	bottom: 0;
	left: 0;
	right: 0;
	background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
	color: white;
	padding: 8px;
	font-size: 12px;
	opacity: 0;
	transition: opacity 0.2s;
}

.mlm-media-item:hover .mlm-media-item-info {
	opacity: 1;
}

.mlm-media-item-name {
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	font-weight: 500;
}

.mlm-media-item-size {
	font-size: 10px;
	opacity: 0.8;
	margin-top: 2px;
}

.mlm-media-item-checkbox {
	position: absolute;
	top: 8px;
	right: 8px;
	width: 24px;
	height: 24px;
	background: rgba(255, 255, 255, 0.9);
	border: 2px solid #ddd;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	opacity: 0;
	transition: all 0.2s;
	z-index: 10;
}

.mlm-media-item:hover .mlm-media-item-checkbox,
.mlm-media-item.selected .mlm-media-item-checkbox {
	opacity: 1;
}

.mlm-media-item.selected .mlm-media-item-checkbox {
	background: #667eea;
	border-color: #667eea;
	color: white;
}

/* Upload Area */
.mlm-media-upload-area {
	padding: 40px;
	text-align: center;
	background: white;
	border: 3px dashed #ddd;
	border-radius: 12px;
	margin: 20px;
	cursor: pointer;
	transition: all 0.3s;
}

.mlm-media-upload-area:hover {
	border-color: #667eea;
	background: #f8f9ff;
}

.mlm-media-upload-area.dragover {
	border-color: #667eea;
	background: #f0f3ff;
	transform: scale(1.02);
}

.mlm-media-upload-icon {
	font-size: 64px;
	color: #667eea;
	margin-bottom: 15px;
}

.mlm-media-upload-text {
	font-size: 18px;
	color: #333;
	margin-bottom: 8px;
	font-weight: 600;
}

.mlm-media-upload-hint {
	font-size: 14px;
	color: #999;
}

/* Footer */
.mlm-media-modal-footer {
	padding: 15px 30px;
	border-top: 1px solid #e0e0e0;
	display: flex;
	align-items: center;
	justify-content: space-between;
	background: #fafafa;
}

.mlm-media-modal-info {
	color: #666;
	font-size: 14px;
}

.mlm-media-modal-actions {
	display: flex;
	gap: 10px;
}

.mlm-media-modal-btn {
	padding: 12px 24px;
	border: none;
	border-radius: 8px;
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
	transition: all 0.2s;
	display: flex;
	align-items: center;
	gap: 8px;
}

.mlm-media-modal-btn-secondary {
	background: #e0e0e0;
	color: #666;
}

.mlm-media-modal-btn-secondary:hover {
	background: #d0d0d0;
}

.mlm-media-modal-btn-primary {
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	color: white;
	box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.mlm-media-modal-btn-primary:hover {
	transform: translateY(-2px);
	box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.mlm-media-modal-btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
	transform: none !important;
}

/* Loading */
.mlm-media-modal-loading {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 60px;
	color: #999;
}

.mlm-media-modal-loading i {
	font-size: 48px;
	margin-bottom: 15px;
	animation: spin 1s linear infinite;
}

@keyframes spin {
	from { transform: rotate(0deg); }
	to { transform: rotate(360deg); }
}

/* Empty State */
.mlm-media-modal-empty {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 60px;
	color: #999;
}

.mlm-media-modal-empty i {
	font-size: 64px;
	margin-bottom: 15px;
	opacity: 0.5;
}

.mlm-media-modal-empty-text {
	font-size: 18px;
	margin-bottom: 8px;
	color: #666;
}

.mlm-media-modal-empty-hint {
	font-size: 14px;
	color: #999;
}

/* Responsive */
@media (max-width: 768px) {
	.mlm-media-modal {
		width: 95%;
		height: 90vh;
	}
	
	.mlm-media-modal-sidebar {
		display: none;
	}
	
	.mlm-media-grid {
		grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
		gap: 10px;
	}
	
	.mlm-media-modal-toolbar {
		flex-wrap: wrap;
	}
	
	.mlm-media-modal-filter {
		width: 100%;
	}
}

/* RTL Support */
[dir="rtl"] .mlm-media-modal-sidebar {
	border-left: none;
	border-right: 1px solid #e0e0e0;
}

[dir="rtl"] .mlm-media-modal-search i {
	right: auto;
	left: 15px;
}

[dir="rtl"] .mlm-media-item-checkbox {
	right: auto;
	left: 8px;
}

/* Dark Mode Support (اختیاری) */
@media (prefers-color-scheme: dark) {
	.mlm-media-modal {
		background: #1e1e1e;
		color: #e0e0e0;
	}
	
	.mlm-media-modal-sidebar {
		background: #2a2a2a;
		border-color: #444;
	}
	
	.mlm-media-modal-tab {
		background: #333;
		color: #e0e0e0;
		border-color: #444;
	}
	
	.mlm-media-modal-gallery {
		background: #252525;
	}
	
	.mlm-media-item {
		background: #333;
		border-color: #444;
	}
	
	.mlm-media-upload-area {
		background: #2a2a2a;
		border-color: #444;
	}
}

